[banshee: 47/61] [InternetArchive] Add preferred media types list
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee: 47/61] [InternetArchive] Add preferred media types list
- Date: Tue, 3 Nov 2009 06:31:47 +0000 (UTC)
commit 5640be016703dcee385965a0417b9a3c39256657
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Oct 13 19:22:09 2009 -0700
[InternetArchive] Add preferred media types list
Is user-editable in Preferences, and is used to sort the media type
dropdown, select the default (the top choice), and to separate media
types that aren't mentioned in the preference.
.../Banshee.InternetArchive/DetailsView.cs | 30 +++++++--
.../Banshee.InternetArchive/SearchSource.cs | 63 ++++++++++++++++++++
.../Resources/SearchSourceActiveUI.xml | 1 +
3 files changed, 87 insertions(+), 7 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/DetailsView.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/DetailsView.cs
index 6a7f17d..60d4c0b 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/DetailsView.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/DetailsView.cs
@@ -360,9 +360,27 @@ namespace Banshee.InternetArchive
file_list.ColumnController = file_columns;
file_list.SetModel (files_model);
+ // Order the formats according to the preferences
+ string format_order = String.Format ("{0}{1}{2}", SearchSource.VideoTypes.Get (), SearchSource.AudioTypes.Get (), SearchSource.TextTypes.Get ()).ToLower ();
+
+ var sorted_formats = formats.Select (f => new { Format = f, Order = format_order.IndexOf (f.ToLower ()) })
+ .OrderBy (o => o.Order == -1 ? Int32.MaxValue : o.Order);
+
var format_list = ComboBox.NewText ();
- foreach (var fmt in formats) {
- format_list.AppendText (fmt);
+ format_list.RowSeparatorFunc = (model, iter) => {
+ return (string)model.GetValue (iter, 0) == "---";
+ };
+
+ bool have_sep = false;
+ foreach (var fmt in sorted_formats) {
+ if (fmt.Order == -1 && !have_sep) {
+ have_sep = true;
+ if (format_list.Model.IterNChildren () > 0) {
+ format_list.AppendText ("---");
+ }
+ }
+
+ format_list.AppendText (fmt.Format);
}
format_list.Changed += (o, a) => {
@@ -378,10 +396,7 @@ namespace Banshee.InternetArchive
files_model.Reload ();
};
- // TODO replace this with a user-configurable format weighting preference
- if (formats.IndexOf ("VBR MP3") != -1) {
- format_list.Active = formats.IndexOf ("VBR MP3");
- } else if (formats.Count > 0) {
+ if (formats.Count > 0) {
format_list.Active = 0;
}
@@ -394,12 +409,13 @@ namespace Banshee.InternetArchive
target_list_width += file_sw.VScrollbar.Allocation.Width + 2;
}
+ target_list_width = Math.Min (target_list_width, Allocation.Width / 2);
+
if (a.Allocation.Width != target_list_width && target_list_width > 0) {
file_sw.SetSizeRequest (target_list_width, -1);
}
};
- //PackStart (vbox, true, true, 0);
PackStart (vbox, false, false, 0);
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
index 524bebc..a25d13f 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
@@ -86,6 +86,8 @@ namespace Banshee.InternetArchive
IA.Search.UserAgent = Banshee.Web.Browser.UserAgent;
IA.Search.TimeoutMs = 12*1000;
+ InstallPreferences ();
+
search = new IA.Search ();
//Properties.SetStringList ("Icon.Name", "video-x-generic", "video", "source-library");
@@ -222,6 +224,8 @@ namespace Banshee.InternetArchive
if (actions != null) {
actions.Dispose ();
}
+
+ UninstallPreferences ();
}
private void ShowIntroText ()
@@ -243,5 +247,64 @@ namespace Banshee.InternetArchive
}
private SchemaEntry<bool> show_intro = new SchemaEntry<bool> ("plugins.internetarchive", "show_intro", true, null, null);
+
+#region Preferences
+
+ private SourcePage pref_page;
+ private Section pref_section;
+
+ private void InstallPreferences ()
+ {
+ PreferenceService service = ServiceManager.Get<PreferenceService> ();
+ if (service == null) {
+ return;
+ }
+
+ pref_page = new Banshee.Preferences.SourcePage (this);
+
+ pref_section = pref_page.Add (new Section ("mediatypes", Catalog.GetString ("Preferred Media Types"), 20));
+
+ pref_section.Add (new SchemaPreference<string> (AudioTypes,
+ Catalog.GetString ("_Audio"), Catalog.GetString ("")));
+
+ pref_section.Add (new SchemaPreference<string> (VideoTypes,
+ Catalog.GetString ("_Video"), Catalog.GetString ("")));
+
+ pref_section.Add (new SchemaPreference<string> (TextTypes,
+ Catalog.GetString ("_Text"), Catalog.GetString ("")));
+ }
+
+ private void UninstallPreferences ()
+ {
+ PreferenceService service = ServiceManager.Get<PreferenceService> ();
+ if (service == null || pref_page == null) {
+ return;
+ }
+
+ pref_page.Dispose ();
+ pref_page = null;
+ pref_section = null;
+ }
+
+ public override string PreferencesPageId {
+ get { return pref_page.Id; }
+ }
+
+ public static readonly SchemaEntry<string> AudioTypes = new SchemaEntry<string> (
+ "plugins.internetarchive", "audio_types",
+ "Audio, VBR Mp3, Ogg Vorbis, 64Kbps MP3, Flac, VBR ZIP, 64Kbps MP3 ZIP",
+ "Ordered list of preferred mediatypes for audio items", null);
+
+ public static readonly SchemaEntry<string> VideoTypes = new SchemaEntry<string> (
+ "plugins.internetarchive", "video_types",
+ "Ogg Video, *Ogg*, 512Kb MPEG4, MPEG2",
+ "Ordered list of preferred mediatypes for video items", null);
+
+ public static readonly SchemaEntry<string> TextTypes = new SchemaEntry<string> (
+ "plugins.internetarchive", "text_types",
+ "Text PDF, Standard LuraTech PDF, *PDF*, ZIP, Text, Hypertext",
+ "Ordered list of preferred mediatypes for text items", null);
+
+#endregion
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Resources/SearchSourceActiveUI.xml b/src/Extensions/Banshee.InternetArchive/Resources/SearchSourceActiveUI.xml
index 1a4478c..52812c7 100644
--- a/src/Extensions/Banshee.InternetArchive/Resources/SearchSourceActiveUI.xml
+++ b/src/Extensions/Banshee.InternetArchive/Resources/SearchSourceActiveUI.xml
@@ -22,6 +22,7 @@
<popup action="IaSearchSourcePopup">
<menuitem action="VisitInternetArchive" />
+ <menuitem name="SourcePreferences" action="SourcePreferencesAction"/>
</popup>
<popup action="IaResultPopup">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]