banshee r3260 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Query src/Core/Banshee.Services/Banshee.SmartPlaylist src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio src/Libraries/Hyena.Gui/Hyena.Query.Gui



Author: gburt
Date: Sun Feb 17 22:03:09 2008
New Revision: 3260
URL: http://svn.gnome.org/viewvc/banshee?rev=3260&view=rev

Log:
2008-02-17  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs: Change
	LastPlayed and DateAdded order names.

	* src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs: Wrap the
	migration in a transaction, print error message if it fails.

	* src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs:
	Only initialize if the migration was successful.

	* src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs: BansheeQuery's
	Orders array has nulls in it to indicate where separators would be nice -
	actually implement those in the ComboBox.

	* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs:
	Improve comment.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	Sun Feb 17 22:03:09 2008
@@ -57,11 +57,11 @@
             CreateQueryOrder ("PlayCount",  desc, Catalog.GetString ("Most Often Played")),
             CreateQueryOrder ("PlayCount",  asc,  Catalog.GetString ("Least Often Played")),
             null,
-            CreateQueryOrder ("LastPlayed", desc, Catalog.GetString ("Most Recently Played")),
-            CreateQueryOrder ("LastPlayed", asc,  Catalog.GetString ("Least Recently Played")),
+            CreateQueryOrder ("LastPlayedStamp", desc, Catalog.GetString ("Most Recently Played")),
+            CreateQueryOrder ("LastPlayedStamp", asc,  Catalog.GetString ("Least Recently Played")),
             null,
-            CreateQueryOrder ("DateAdded",  desc, Catalog.GetString ("Most Recently Added")),
-            CreateQueryOrder ("DateAdded",  asc,  Catalog.GetString ("Least Recently Added"))
+            CreateQueryOrder ("DateAddedStamp",  desc, Catalog.GetString ("Most Recently Added")),
+            CreateQueryOrder ("DateAddedStamp",  asc,  Catalog.GetString ("Least Recently Added"))
         };
 
         public static QueryLimit [] Limits = new QueryLimit [] {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs	Sun Feb 17 22:03:09 2008
@@ -32,7 +32,9 @@
 using System.Text.RegularExpressions;
 using System.Collections;
 using System.Collections.Generic;
+using Mono.Unix;
 
+using Hyena;
 using Hyena.Data;
 using Hyena.Query;
 using Hyena.Data.Sqlite;
@@ -48,25 +50,37 @@
         private string [] criteria = new string [] { "songs", "minutes", "hours", "MB" };
         private Dictionary<string, QueryOrder> order_hash = new Dictionary<string, QueryOrder> ();
 
-        public static void MigrateAll ()
+        public static bool MigrateAll ()
         {
             int version = ServiceManager.DbConnection.Query<int> ("SELECT Value FROM CoreConfiguration WHERE Key = 'SmartPlaylistVersion'");
             if (version == 1)
-                return;
+                return true;
 
-            Migrator m = new Migrator ();
-            using (IDataReader reader = ServiceManager.DbConnection.ExecuteReader (
-                "SELECT SmartPlaylistID, Name, Condition, OrderBy, LimitNumber, LimitCriterion FROM CoreSmartPlaylists")) {
-                while (reader.Read ()) {
-                    m.Migrate (
-                        Convert.ToInt32 (reader[0]), reader[1] as string,
-                        reader[2] as string, reader[3] as string,
-                        reader[4] as string, reader[5] as string
-                    );
+            try {
+                ServiceManager.DbConnection.Execute ("BEGIN");
+                Migrator m = new Migrator ();
+                using (IDataReader reader = ServiceManager.DbConnection.ExecuteReader (
+                    "SELECT SmartPlaylistID, Name, Condition, OrderBy, LimitNumber, LimitCriterion FROM CoreSmartPlaylists")) {
+                    while (reader.Read ()) {
+                        m.Migrate (
+                            Convert.ToInt32 (reader[0]), reader[1] as string,
+                            reader[2] as string, reader[3] as string,
+                            reader[4] as string, reader[5] as string
+                        );
+                    }
                 }
-            }
 
-            ServiceManager.DbConnection.Execute ("INSERT INTO CoreConfiguration (Key, Value) Values ('SmartPlaylistVersion', 1)");
+                ServiceManager.DbConnection.Execute ("INSERT INTO CoreConfiguration (Key, Value) Values ('SmartPlaylistVersion', 1)");
+                ServiceManager.DbConnection.Execute ("COMMIT");
+                return true;
+            } catch (Exception e) {
+                ServiceManager.DbConnection.Execute ("ROLLBACK");
+                Log.Error (
+                    Catalog.GetString ("Unable to Migrate Smart Playlists"),
+                    String.Format (Catalog.GetString ("Please file a bug with this error: {0}"), e.ToString ())
+                );
+                return false;
+            }
         }
 
         public Migrator ()
@@ -88,7 +102,6 @@
 
         private void Migrate (int dbid, string Name, string Condition, string OrderBy, string LimitNumber, string LimitCriterion)
         {
-            Console.WriteLine ("migrating {0}, cond = {1}, order = {2}", Name, Condition, OrderBy);
             if (OrderBy != null && OrderBy != String.Empty) {
                 QueryOrder order = order_hash [OrderBy];
                 OrderBy = order.Name;
@@ -107,11 +120,15 @@
                     WHERE SmartPlaylistID = ?",
                 Name, ConditionXml, OrderBy, LimitNumber, LimitCriterion, dbid
             ));
-            Console.WriteLine ("migrated {0}, cond = {1}, order = {2}", Name, ConditionXml, OrderBy);
+
+            Log.Debug (String.Format ("Migrated Smart Playlist {0}", Name));
         }
 
         private string ParseCondition (string value)
         {
+            if (String.IsNullOrEmpty (value))
+                return null;
+
             // Check for ANDs or ORs and split into conditions as needed
             string [] conditions;
             bool ands = true;

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs	Sun Feb 17 22:03:09 2008
@@ -47,16 +47,15 @@
 
         public SmartPlaylistCore()
         {
-            Migrator.MigrateAll ();
-
-            // Listen for added/removed sources and added/changed songs
-            ServiceManager.SourceManager.SourceAdded += HandleSourceAdded;
-            ServiceManager.SourceManager.SourceRemoved += HandleSourceRemoved;
-
-            //ServiceManager.SourceManager.DefaultSource.Reloaded += HandleLibraryReloaded;
-            //Globals.Library.TrackAdded += HandleTrackAdded;
-            //Globals.Library.TrackRemoved += HandleTrackRemoved;
-
+            if (Migrator.MigrateAll ()) {
+                // Listen for added/removed sources and added/changed songs
+                ServiceManager.SourceManager.SourceAdded += HandleSourceAdded;
+                ServiceManager.SourceManager.SourceRemoved += HandleSourceRemoved;
+
+                //ServiceManager.SourceManager.DefaultSource.Reloaded += HandleLibraryReloaded;
+                //Globals.Library.TrackAdded += HandleTrackAdded;
+                //Globals.Library.TrackRemoved += HandleTrackRemoved;
+            }
         }
 
         private void HandleLibraryReloaded (object sender, EventArgs args)

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	Sun Feb 17 22:03:09 2008
@@ -370,7 +370,7 @@
                 CurrentTrack = ServiceManager.PlayerEngine.CurrentTrack;
 
                 lock (track_model) {
-                    // Remove up to the 5 most-recent tracks
+                    // Remove all but 5 played or skipped tracks
                     if (current_track > 5) {
                         for (int i = 0; i < (current_track - 5); i++) {
                             track_model.Remove (track_model[0]);

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs	Sun Feb 17 22:03:09 2008
@@ -67,8 +67,11 @@
             }
                 
             order_combo = ComboBox.NewText ();
+            order_combo.RowSeparatorFunc = IsRowSeparator;
             foreach (QueryOrder order in orders) {
-                if (order != null) {
+                if (order == null) {
+                    order_combo.AppendText (String.Empty);
+                } else {
                     order_combo.AppendText (order.Label);
                 }
             }
@@ -88,6 +91,11 @@
             ShowAll ();
         }
 
+        private bool IsRowSeparator (TreeModel model, TreeIter iter)
+        {
+            return model.GetValue (iter, 0) == String.Empty;
+        }
+
         public QueryLimit Limit {
             get { return Enabled ? limits [limit_combo.Active] : null; }
             set {
@@ -115,8 +123,9 @@
         public QueryOrder Order {
             get { return Enabled ? orders [order_combo.Active] : null; }
             set {
-                if (value != null)
+                if (value != null) {
                     order_combo.Active = Array.IndexOf (orders, value);
+                }
             }
         }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]