banshee r3411 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Gui src/Libraries/Hyena src/Libraries/Hyena/Hyena.Data.Sqlite



Author: gburt
Date: Tue Mar 11 02:13:41 2008
New Revision: 3411
URL: http://svn.gnome.org/viewvc/banshee?rev=3411&view=rev

Log:
2008-03-10  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs:
	Add CacheId property that can be used to uniqued ID an item within a list.

	* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs:
	Notify the Library about the metadata-refreshed tracks after closing the
	user job so it doesn't look like it's hung.

	* src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs:
	* src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs: SpawnFromMain
	a few methods.

	* src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs:
	* src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs:
	* src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs:
	* src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs:
	* src/Libraries/Hyena/Makefile.am:
	* src/Libraries/Hyena/Hyena.Data.Sqlite/ICacheableItem.cs: New interface
	containing CacheId property that *ModelCache and *ModelProvider classes
	require.


Added:
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/ICacheableItem.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs
   trunk/banshee/src/Libraries/Hyena/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Tue Mar 11 02:13:41 2008
@@ -49,7 +49,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class DatabaseTrackInfo : TrackInfo
+    public class DatabaseTrackInfo : TrackInfo, ICacheableItem
     {
         private static BansheeModelProvider<DatabaseTrackInfo> provider = new BansheeModelProvider<DatabaseTrackInfo> (
             ServiceManager.DbConnection, "CoreTracks"
@@ -114,6 +114,12 @@
             get { return track_id; }
         }
 
+        private long cache_id;
+        public long CacheId {
+            get { return cache_id; }
+            set { cache_id = value; }
+        }
+
         [DatabaseColumn ("SourceID", Index = "CoreTracksSourceIndex")]
         private int source_id;
         public int SourceId {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	Tue Mar 11 02:13:41 2008
@@ -38,7 +38,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryAlbumInfo : AlbumInfo
+    public class LibraryAlbumInfo : AlbumInfo, ICacheableItem
     {
         private static BansheeModelProvider<LibraryAlbumInfo> provider = new BansheeModelProvider<LibraryAlbumInfo> (
             ServiceManager.DbConnection, "CoreAlbums"
@@ -106,6 +106,12 @@
             get { return dbid; }
         }
 
+        private long cache_id;
+        public long CacheId {
+            get { return cache_id; }
+            set { cache_id = value; }
+        }
+
         [DatabaseColumn("ArtistID")]
         private int artist_id;
         public int ArtistId {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	Tue Mar 11 02:13:41 2008
@@ -38,7 +38,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryArtistInfo : ArtistInfo
+    public class LibraryArtistInfo : ArtistInfo, ICacheableItem
     {
         private static BansheeModelProvider<LibraryArtistInfo> provider = new BansheeModelProvider<LibraryArtistInfo> (
             ServiceManager.DbConnection, "CoreArtists"
@@ -102,6 +102,12 @@
             get { return dbid; }
         }
 
+        private long cache_id;
+        public long CacheId {
+            get { return cache_id; }
+            set { cache_id = value; }
+        }
+
         [DatabaseColumn]
         public override string Name {
             get { return base.Name; }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	Tue Mar 11 02:13:41 2008
@@ -559,9 +559,9 @@
                     job.Progress = (double)++count / (double)total;
                 }
             }
-            ServiceManager.SourceManager.Library.NotifyTracksChanged ();
 
             job.Finish ();
+            ServiceManager.SourceManager.Library.NotifyTracksChanged ();
         }
         
 #endregion

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs	Tue Mar 11 02:13:41 2008
@@ -34,7 +34,7 @@
 
 namespace Banshee.Database
 {
-    public class BansheeModelCache <T> : SqliteModelCache <T> where T : new ()
+    public class BansheeModelCache <T> : SqliteModelCache <T> where T : ICacheableItem, new ()
     {
         public BansheeModelCache (HyenaSqliteConnection connection,
                                   string uuid,

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs	Tue Mar 11 02:13:41 2008
@@ -36,7 +36,7 @@
 
 namespace Banshee.Database
 {
-    public class BansheeModelProvider<T> : SqliteModelProvider<T> where T : new ()
+    public class BansheeModelProvider<T> : SqliteModelProvider<T> where T : ICacheableItem, new ()
     {
         private string table_name;
 

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs	Tue Mar 11 02:13:41 2008
@@ -94,7 +94,9 @@
             set {
                 base.FilterQuery = value;
                 track_model.Filter = FilterQuery;
-                reload_limiter.Execute ();
+                ThreadAssist.SpawnFromMain (delegate {
+                    Reload ();
+                });
             }
         }
 
@@ -139,7 +141,7 @@
             reload_limiter.Execute ();
         }
 
-        protected virtual void RateLimitedReload ()
+        protected void RateLimitedReload ()
         {
             lock (track_model) {
                 // First, reload the track model w/o the artist/album filter
@@ -317,8 +319,11 @@
         protected void AfterInitialized ()
         {
             track_model.Initialize (artist_model, album_model);
-            Reload ();
-            OnSetupComplete ();
+
+            ThreadAssist.SpawnFromMain (delegate {
+                Reload ();
+                OnSetupComplete ();
+            });
         }
 
         protected virtual void RemoveTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs	Tue Mar 11 02:13:41 2008
@@ -98,7 +98,7 @@
                 new ActionEntry ("AddToPlaylistAction", null,
                     Catalog.GetString ("Add _to Playlist"), null,
                     Catalog.GetString ("Append selected songs to playlist or create new playlist from selection"),
-                    OnAddToPlaylist),
+                    OnAddToPlaylistMenu),
 
                 new ActionEntry ("AddToNewPlaylistAction", Stock.New,
                     Catalog.GetString ("New Playlist"), null,
@@ -281,7 +281,7 @@
 
         // Called when the Add to Playlist action is highlighted.
         // Generates the menu of playlists to which you can add the selected tracks.
-        private void OnAddToPlaylist (object o, EventArgs args)
+        private void OnAddToPlaylistMenu (object o, EventArgs args)
         {
             Gdk.Pixbuf pl_pb = Gdk.Pixbuf.LoadFromResource ("source-playlist-16.png");
             Source active_source = ServiceManager.SourceManager.ActiveSource;
@@ -320,12 +320,16 @@
             PlaylistSource playlist = new PlaylistSource ("New Playlist");
             playlist.Save ();
             ServiceManager.SourceManager.DefaultSource.AddChildSource (playlist);
-            playlist.AddSelectedTracks (TrackSelector.TrackModel);
+            ThreadAssist.SpawnFromMain (delegate {
+                playlist.AddSelectedTracks (TrackSelector.TrackModel);
+            });
         }
 
         private void OnAddToExistingPlaylist (object o, EventArgs args)
         {
-            ((PlaylistMenuItem)o).Playlist.AddSelectedTracks (TrackSelector.TrackModel);
+            ThreadAssist.SpawnFromMain (delegate {
+                ((PlaylistMenuItem)o).Playlist.AddSelectedTracks (TrackSelector.TrackModel);
+            });
         }
 
         private void OnRemoveTracks (object o, EventArgs args)
@@ -336,7 +340,9 @@
                 return;
 
             if (source != null && source.CanRemoveTracks) {
-                source.RemoveSelectedTracks ();
+                ThreadAssist.SpawnFromMain (delegate {
+                    source.RemoveSelectedTracks ();
+                });
             }
         }
 
@@ -347,9 +353,13 @@
             if (source != null) {
                 LibrarySource library = source.Parent as LibrarySource;
                 if (library != null) {
-                    if (!ConfirmRemove (library, false, source.TrackModel.Selection.Count))
+                    if (!ConfirmRemove (library, false, source.TrackModel.Selection.Count)) {
                         return;
-                    library.RemoveSelectedTracks (source.TrackModel as TrackListDatabaseModel);
+                    }
+
+                    ThreadAssist.SpawnFromMain (delegate {
+                        library.RemoveSelectedTracks (source.TrackModel as TrackListDatabaseModel);
+                    });
                 }
             }
         }
@@ -376,7 +386,9 @@
                 }
             }
 
-            (ActiveSource as DatabaseSource).RateSelectedTracks (rating_proxy.LastRating);
+            ThreadAssist.SpawnFromMain (delegate {
+                (ActiveSource as DatabaseSource).RateSelectedTracks (rating_proxy.LastRating);
+            });
         }
 
         private void OnSearchForSameArtist (object o, EventArgs args)

Added: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/ICacheableItem.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/ICacheableItem.cs	Tue Mar 11 02:13:41 2008
@@ -0,0 +1,37 @@
+//
+// ICacheableItem.cs
+//
+// Author:
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Hyena.Data;
+
+namespace Hyena.Data.Sqlite
+{
+    public interface ICacheableItem
+    {
+        long CacheId { get; set; }
+    }
+}

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	Tue Mar 11 02:13:41 2008
@@ -32,7 +32,7 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public class SqliteModelCache<T> : DictionaryModelCache<T>
+    public class SqliteModelCache<T> : DictionaryModelCache<T> where T : ICacheableItem
     {
         private HyenaSqliteConnection connection;
         private ICacheableDatabaseModel model;
@@ -100,10 +100,10 @@
             if (model.CachesJoinTableEntries) {
                 select_range_command = new HyenaSqliteCommand (
                     String.Format (@"
-                        SELECT {0} FROM {1}
+                        SELECT {0}, cache.ItemID  FROM {1}
                             INNER JOIN {2}
                                 ON {3} = {2}.{4}
-                            INNER JOIN {5}
+                            INNER JOIN {5} cache
                                 ON {2}.{6} = {5}.ItemID
                             WHERE
                                 {5}.ModelID = {7} {8}
@@ -135,11 +135,11 @@
             } else {
                 select_range_command = new HyenaSqliteCommand (
                     String.Format (@"
-                        SELECT {0} FROM {1}
-                            INNER JOIN {2}
-                                ON {3} = {2}.ItemID
+                        SELECT {0}, cache.ItemID FROM {1}
+                            INNER JOIN {2} cache
+                                ON {3} = cache.ItemID
                             WHERE
-                                {2}.ModelID = {4} {5}
+                                cache.ModelID = {4} {5}
                                 {6}
                             LIMIT ?, ?",
                         provider.Select, provider.From, CacheTableName,

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	Tue Mar 11 02:13:41 2008
@@ -34,7 +34,7 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public abstract class SqliteModelProvider<T>
+    public abstract class SqliteModelProvider<T> where T : ICacheableItem
     {
         private readonly List<DatabaseColumn> columns = new List<DatabaseColumn> ();
         private readonly List<VirtualDatabaseColumn> virtual_columns = new List<VirtualDatabaseColumn> ();
@@ -298,6 +298,10 @@
                     bad_column = column;
                     column.SetValue (target, reader, i++);
                 }
+
+                if (i < reader.FieldCount) {
+                    target.CacheId = Convert.ToInt64 (reader[i]);
+                }
             } catch (Exception e) {
                 Log.Debug (
                     String.Format ("Caught exception trying to load database column {0}", bad_column == null ? "[unknown]" : bad_column.Name),

Modified: trunk/banshee/src/Libraries/Hyena/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Makefile.am	(original)
+++ trunk/banshee/src/Libraries/Hyena/Makefile.am	Tue Mar 11 02:13:41 2008
@@ -16,6 +16,7 @@
 	Hyena.Data.Sqlite/HyenaSqliteCommand.cs \
 	Hyena.Data.Sqlite/HyenaSqliteConnection.cs \
 	Hyena.Data.Sqlite/ICacheableDatabaseModel.cs \
+	Hyena.Data.Sqlite/ICacheableItem.cs \
 	Hyena.Data.Sqlite/SqliteModelCache.cs \
 	Hyena.Data.Sqlite/SqliteModelProvider.cs \
 	Hyena.Data.Sqlite/SqliteUtils.cs \



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