banshee r5086 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Gui src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r5086 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Gui src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio
- Date: Fri, 27 Feb 2009 23:23:02 +0000 (UTC)
Author: gburt
Date: Fri Feb 27 23:23:02 2009
New Revision: 5086
URL: http://svn.gnome.org/viewvc/banshee?rev=5086&view=rev
Log:
2009-02-27 Gabriel Burt <gabriel burt gmail com>
* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: Rename
SortTypes to ChildSortTypes.
* src/Core/Banshee.Services/Banshee.Sources/Source.cs: Add configuration
for separate children by type, get rid of "Ascending" in Name sort option,
add a TypeName property that defaults to GetType ().Name that is used by
the separate-by-type sort option.
* src/Core/Banshee.Services/Banshee.Sources/SourceSortType.cs: Add a Sort
method that uses an internal IComparer to separate by type if desired,
sort by the main function (size, etc), and then fallback to sorting by
name.
* src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs: Add
separate-by-type option.
* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs: Get
rid of 'Station Type' sort option since now redundant.
* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs:
Override TypeName to replicate old Station Type sort behavior.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceSortType.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs Fri Feb 27 23:23:02 2009
@@ -181,7 +181,7 @@
SortSizeDescending
};
- public override SourceSortType[] SortTypes {
+ public override SourceSortType[] ChildSortTypes {
get { return sort_types; }
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs Fri Feb 27 23:23:02 2009
@@ -58,6 +58,7 @@
private SourceSortType child_sort;
private bool sort_children = true;
private SchemaEntry<string> child_sort_schema;
+ private SchemaEntry<bool> separate_by_type_schema;
public event EventHandler Updated;
public event EventHandler UserNotifyUpdated;
@@ -236,16 +237,7 @@
}
}
- public class NameComparer : IComparer<Source>
- {
- static IComparer inner_cmp = new CaseInsensitiveComparer ();
- public int Compare (Source a, Source b)
- {
- return inner_cmp.Compare (a.Name, b.Name);
- }
- }
-
- public class SizeComparer : IComparer<Source>
+ private class SizeComparer : IComparer<Source>
{
public int Compare (Source a, Source b)
{
@@ -271,10 +263,7 @@
if (child_sort.SortType != SortType.None) {
lock (Children) {
- child_sources.Sort (child_sort.Comparer);
- if (child_sort.SortType == SortType.Descending) {
- child_sources.Reverse ();
- }
+ child_sort.Sort (child_sources, SeparateChildrenByType);
int i = 0;
foreach (Source child in child_sources) {
@@ -287,7 +276,7 @@
private void LoadSortSchema ()
{
- if (SortTypes.Length == 0) {
+ if (ChildSortTypes.Length == 0) {
return;
}
@@ -298,12 +287,14 @@
child_sort_schema = CreateSchema<string> ("child_sort_id", DefaultChildSort.Id, "", "");
string child_sort_id = child_sort_schema.Get ();
- foreach (SourceSortType sort_type in SortTypes) {
+ foreach (SourceSortType sort_type in ChildSortTypes) {
if (sort_type.Id == child_sort_id) {
child_sort = sort_type;
break;
}
}
+
+ separate_by_type_schema = CreateSchema<bool> ("separate_by_type", false, "", "");
SortChildSources ();
}
@@ -543,6 +534,10 @@
public Source Parent {
get { return parent; }
}
+
+ public virtual string TypeName {
+ get { return GetType ().Name; }
+ }
private string unique_id;
public string UniqueId {
@@ -657,8 +652,8 @@
public static readonly SourceSortType SortNameAscending = new SourceSortType (
"NameAsc",
- Catalog.GetString ("Name Ascending"),
- SortType.Ascending, new NameComparer ());
+ Catalog.GetString ("Name"),
+ SortType.Ascending, null); // null comparer b/c we already fall back to sorting by name
public static readonly SourceSortType SortSizeAscending = new SourceSortType (
"SizeAsc",
@@ -671,7 +666,7 @@
SortType.Descending, new SizeComparer ());
private static SourceSortType[] sort_types = new SourceSortType[] {};
- public virtual SourceSortType[] SortTypes {
+ public virtual SourceSortType[] ChildSortTypes {
get { return sort_types; }
}
@@ -682,6 +677,14 @@
public virtual SourceSortType DefaultChildSort {
get { return null; }
}
+
+ public bool SeparateChildrenByType {
+ get { return separate_by_type_schema.Get (); }
+ set {
+ separate_by_type_schema.Set (value);
+ SortChildSources ();
+ }
+ }
#endregion
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceSortType.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceSortType.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceSortType.cs Fri Feb 27 23:23:02 2009
@@ -48,17 +48,26 @@
{
public class SourceSortType
{
+ private SourceComparer comparer;
private string id;
private string label;
private SortType sort_type;
- private IComparer<Source> comparer;
-
+
public SourceSortType (string id, string label, SortType sortType, IComparer<Source> comparer)
{
this.id = id;
this.label = label;
this.sort_type = sortType;
- this.comparer = comparer;
+
+ this.comparer = new SourceComparer ();
+ this.comparer.Comparer = comparer;
+ this.comparer.Descending = sort_type == SortType.Descending;
+ }
+
+ public void Sort (List<Source> sources, bool separateTypes)
+ {
+ this.comparer.SeparateTypes = separateTypes;
+ sources.Sort (comparer);
}
public string Id {
@@ -73,8 +82,35 @@
get { return sort_type; }
}
- public IComparer<Source> Comparer {
- get { return comparer; }
+ private class SourceComparer : IComparer<Source>
+ {
+ private IComparer name_comparer = new CaseInsensitiveComparer ();
+
+ public bool SeparateTypes;
+ public bool Descending;
+ public IComparer<Source> Comparer;
+
+ public int Compare (Source a, Source b)
+ {
+ int comp;
+
+ // First separate out by type
+ if (SeparateTypes) {
+ comp = a.TypeName.CompareTo (b.TypeName);
+ if (comp != 0)
+ return comp;
+ }
+
+ // Compare by the special comparer, if any
+ if (Comparer != null) {
+ comp = Comparer.Compare (a, b);
+ if (comp != 0)
+ return Descending ? -comp : comp;
+ }
+
+ // If still equal, then order by name
+ return name_comparer.Compare (a.Name, b.Name);
+ }
}
}
}
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs Fri Feb 27 23:23:02 2009
@@ -375,7 +375,7 @@
}
if (source != null) {
- UpdateAction ("SortChildrenAction", source.SortTypes.Length > 0 && source.Children.Count > 1, true, source);
+ UpdateAction ("SortChildrenAction", source.ChildSortTypes.Length > 0 && source.Children.Count > 1, true, source);
}
Action<Source> handler = Updated;
@@ -427,20 +427,36 @@
}
}
- private static Menu BuildSortMenu (Source source)
+ private Menu BuildSortMenu (Source source)
{
Menu menu = new Menu ();
GLib.SList group = null;
- foreach (SourceSortType sort_type in source.SortTypes) {
+ foreach (SourceSortType sort_type in source.ChildSortTypes) {
RadioMenuItem item = new RadioMenuItem (group, sort_type.Label);
group = item.Group;
item.Active = (sort_type == source.ActiveChildSort);
item.Toggled += BuildSortChangedHandler (source, sort_type);
menu.Append (item);
}
+
+ menu.Append (new SeparatorMenuItem ());
+
+ CheckMenuItem sort_types_item = new CheckMenuItem (Catalog.GetString ("Separate by Type"));
+ sort_types_item.Active = source.SeparateChildrenByType;
+ sort_types_item.Toggled += OnSeparateTypesChanged;
+ menu.Append (sort_types_item);
+
return menu;
}
+ private void OnSeparateTypesChanged (object o, EventArgs args)
+ {
+ CheckMenuItem item = o as CheckMenuItem;
+ if (item != null) {
+ ActionSource.SeparateChildrenByType = item.Active;
+ }
+ }
+
private static EventHandler BuildSortChangedHandler (Source source, SourceSortType sort_type)
{
return delegate (object sender, EventArgs args) {
Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs Fri Feb 27 23:23:02 2009
@@ -145,36 +145,19 @@
{
StationSource a = sa as StationSource;
StationSource b = sb as StationSource;
- int c = a.PlayCount.CompareTo (b.PlayCount);
- return c == 0 ? -(a.Name.CompareTo (b.Name)) : c;
+ return a.PlayCount.CompareTo (b.PlayCount);
}
}
- // Order by the type of station, then by the station name
- public class TypeComparer : IComparer<Source>
- {
- public int Compare (Source sa, Source sb)
- {
- StationSource a = sa as StationSource;
- StationSource b = sb as StationSource;
- int c = a.Type.Name.CompareTo (b.Type.Name);
- return c == 0 ? (a.Name.CompareTo (b.Name)) : c;
- }
- }
-
private static SourceSortType[] sort_types = new SourceSortType[] {
SortNameAscending,
new SourceSortType (
"LastfmTotalPlayCount",
Catalog.GetString ("Total Play Count"),
- SortType.Descending, new PlayCountComparer ()),
- new SourceSortType (
- "LastfmStationType",
- Catalog.GetString ("Station Type"),
- SortType.Ascending, new TypeComparer ())
+ SortType.Descending, new PlayCountComparer ())
};
- public override SourceSortType[] SortTypes {
+ public override SourceSortType[] ChildSortTypes {
get { return sort_types; }
}
Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs Fri Feb 27 23:23:02 2009
@@ -96,6 +96,10 @@
}
}
+ public override string TypeName {
+ get { return Type.Name; }
+ }
+
private string arg;
public string Arg {
get { return arg; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]