banshee r3286 - in trunk/banshee: . src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Base src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.Playlist src/Core/Banshee.Services/Banshee.SmartPlaylist src/Core/Banshee.Services/Banshee.Sources src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue src/Libraries/Hyena/Hyena.Data.Sqlite



Author: gburt
Date: Wed Feb 20 21:58:49 2008
New Revision: 3286
URL: http://svn.gnome.org/viewvc/banshee?rev=3286&view=rev

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

	This commit adds a CorePrimarySources table and a SourceID column to the
	CoreTracks table, allowing non-Library tracks to be stored there (and
	therefore benefit from our searching, playlist, smart playlist, and view
	code).

	* src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs:
	* src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs: Allow specifying
	a min_interval on each rate-limited execute.

	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	Rename to DatabaseTrackInfo, add SourceId property.

	* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs:
	Add new CorePrimarySources table, add SourceID to CoreTracks, remove
	unique constraint on CorePlaylistEntries.

	* src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs: When
	importing set the SourceId on the new DatabaseTrackInfos.

	* src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs: Refactor
	a lot of logic into PrimarySource, and inherit from it.

	* src/Core/Banshee.Services/Banshee.Library/HomeDirectoryImportSource.cs:
	* src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs: Use
	shorter way of getting a specific service from the ServiceManager.

	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: New class
	to be subclassed by LibrarySource, DaapSource, DapSource, etc - a way of
	reusing CoreTracks and all associated goodness for non-Library tracks.

	* src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs: Add Library
	convenience property.

	* src/Core/Banshee.Services/Banshee.Services.mdp:
	* src/Core/Banshee.Services/Makefile.am: Updated

	* src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs:
	* src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs:
	* src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs:
	* src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs:
	Use DatabaseTrackInfo.

	* src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs: Avoid problem
	in Mono.Data.Sqlite in getting Int64 value.

	* src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs: Add
	convience methods for Query, Execute, ExecuteReader that accept the same
	parameters as the HyenaSqliteCommand ctor does, allowing
	Query<int>("select x from y where ?", z) instead of Query<int>(new
	HyenaSqliteCommand ("select x from y where ?", z)).

	* src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs: Add
	try/catch around Load method to avoid crashing and provide debugging if
	there are issues loading a row into an object.


Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs   (contents, props changed)
      - copied, changed from r3283, /trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
Removed:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/HomeDirectoryImportSource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
   trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs	Wed Feb 20 21:58:49 2008
@@ -48,6 +48,11 @@
 
         public void Execute ()
         {
+            Execute (min_interval_ms);
+        }
+
+        public void Execute (double min_interval_ms)
+        {
             if (timeout_id != 0)
                 return;
 
@@ -57,7 +62,7 @@
                 last_executed = DateTime.Now;
             } else {
                 //Console.WriteLine ("Method rate limited, setting timeout");
-                timeout_id = GLib.Timeout.Add((uint)min_interval_ms, OnRateLimitTimer);
+                timeout_id = GLib.Timeout.Add ((uint) min_interval_ms, OnRateLimitTimer);
             }
         }
 

Copied: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs (from r3283, /trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs)
==============================================================================
--- /trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Wed Feb 20 21:58:49 2008
@@ -1,5 +1,5 @@
 //
-// LibraryTrackInfo.cs
+// DatabaseTrackInfo.cs
 //
 // Author:
 //   Aaron Bockover <abockover novell com>
@@ -48,13 +48,13 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryTrackInfo : TrackInfo
+    public class DatabaseTrackInfo : TrackInfo
     {
-        private static BansheeModelProvider<LibraryTrackInfo> provider = new BansheeModelProvider<LibraryTrackInfo> (
+        private static BansheeModelProvider<DatabaseTrackInfo> provider = new BansheeModelProvider<DatabaseTrackInfo> (
             ServiceManager.DbConnection, "CoreTracks"
         );
 
-        public static BansheeModelProvider<LibraryTrackInfo> Provider {
+        public static BansheeModelProvider<DatabaseTrackInfo> Provider {
             get { return provider; }
         }
 
@@ -64,7 +64,7 @@
             AbsoluteUri
         }
         
-        public LibraryTrackInfo () : base ()
+        public DatabaseTrackInfo () : base ()
         {
         }
 
@@ -79,6 +79,13 @@
             get { return dbid; }
         }
 
+        [DatabaseColumn ("SourceID", Index = "CoreTracksSourceIndex")]
+        private int source_id;
+        public int SourceId {
+            get { return source_id; }
+            set { source_id = value; }
+        }
+
         [DatabaseColumn ("ArtistID", Index = "CoreTracksArtistIndex")]
         private int artist_id;
         public int ArtistId {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs	Wed Feb 20 21:58:49 2008
@@ -48,8 +48,8 @@
         ICacheableDatabaseModel, IFilterable, ISortable, ICareAboutView
     {
         private readonly BansheeDbConnection connection;
-        private readonly BansheeModelProvider<LibraryTrackInfo> provider;
-        private readonly BansheeModelCache<LibraryTrackInfo> cache;
+        private readonly BansheeModelProvider<DatabaseTrackInfo> provider;
+        private readonly BansheeModelCache<DatabaseTrackInfo> cache;
         private int count;
         private TimeSpan duration;
         private long filesize;
@@ -75,8 +75,8 @@
         public TrackListDatabaseModel (BansheeDbConnection connection, string uuid)
         {
             this.connection = connection;
-            provider = LibraryTrackInfo.Provider;
-            cache = new BansheeModelCache <LibraryTrackInfo> (connection, uuid, this, provider);
+            provider = DatabaseTrackInfo.Provider;
+            cache = new BansheeModelCache <DatabaseTrackInfo> (connection, uuid, this, provider);
             cache.AggregatesUpdated += HandleCacheAggregatesUpdated;
             Refilter ();
         }
@@ -215,7 +215,7 @@
 
         public override int IndexOf (TrackInfo track)
         {
-            LibraryTrackInfo library_track = track as LibraryTrackInfo;
+            DatabaseTrackInfo library_track = track as DatabaseTrackInfo;
             return library_track == null ? -1 : cache.IndexOf ((int)library_track.DbId);
         }
 

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	Wed Feb 20 21:58:49 2008
@@ -231,11 +231,20 @@
                 )
             ");
             
-            Execute(String.Format(@"
-                INSERT INTO CoreConfiguration 
-                    VALUES (null, 'DatabaseVersion', '{0}')
-            ", CURRENT_VERSION));
+            Execute (String.Format (
+                "INSERT INTO CoreConfiguration VALUES (null, 'DatabaseVersion', '{0}')",
+                CURRENT_VERSION
+            ));
             
+            
+            Execute(@"
+                CREATE TABLE CorePrimarySources (
+                    SourceID            INTEGER PRIMARY KEY,
+                    StringID            TEXT UNIQUE
+                )
+            ");
+            Execute ("INSERT INTO CorePrimarySources (StringID) VALUES ('Library')");
+
             // TODO add these:
             // Comment
             // Composer
@@ -246,9 +255,9 @@
             // AlbumArtist (TPE2) (in CoreAlbums?)
             // Conductor (TPE3)
             // Remixer (TPE4)
-            
             Execute(@"
                 CREATE TABLE CoreTracks (
+                    SourceID            INTEGER NOT NULL,
                     TrackID             INTEGER PRIMARY KEY,
                     ArtistID            INTEGER,
                     AlbumID             INTEGER,
@@ -274,8 +283,10 @@
                     SkipCount           INTEGER,
                     LastPlayedStamp     INTEGER,
                     DateAddedStamp      INTEGER
+                    DateUpdatedStamp    INTEGER
                 )
             ");
+            Execute("CREATE INDEX CoreTracksSourceIndex ON CoreTracks(SourceID)");
             Execute("CREATE INDEX CoreTracksArtistIndex ON CoreTracks(ArtistID)");
             Execute("CREATE INDEX CoreTracksAlbumIndex  ON CoreTracks(AlbumID)");
             Execute("CREATE INDEX CoreTracksRatingIndex ON CoreTracks(Rating)");
@@ -327,8 +338,7 @@
                     EntryID             INTEGER PRIMARY KEY,
                     PlaylistID          INTEGER NOT NULL,
                     TrackID             INTEGER NOT NULL ON CONFLICT IGNORE,
-                    ViewOrder           INTEGER NOT NULL DEFAULT 0,
-                    UNIQUE (PlaylistID, TrackID) ON CONFLICT IGNORE
+                    ViewOrder           INTEGER NOT NULL DEFAULT 0
                 )
             ");
             
@@ -393,6 +403,7 @@
             Execute(@"
                 INSERT INTO CoreTracks
                     SELECT 
+                        1,
                         TrackID, 
                         (SELECT ArtistID 
                             FROM CoreArtists 

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/HomeDirectoryImportSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/HomeDirectoryImportSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/HomeDirectoryImportSource.cs	Wed Feb 20 21:58:49 2008
@@ -39,8 +39,9 @@
 
         public void Import ()
         {
-            Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ("LibraryImportManager").QueueSource (
-                Environment.GetFolderPath(Environment.SpecialFolder.Personal));                                                                                                                
+            Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ().QueueSource (
+                Environment.GetFolderPath (Environment.SpecialFolder.Personal)
+            );
         }
         
         public string Name {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs	Wed Feb 20 21:58:49 2008
@@ -82,12 +82,18 @@
                 path.Substring (index + 1).ToLower ()) >= 0;
         }
     
+        private int library_source_id;
+
         public LibraryImportManager ()
         {
         }
         
         protected override void OnImportRequested (string path)
         {
+            if (library_source_id == 0) {
+                library_source_id = ServiceManager.SourceManager.Library.SourceId;
+            }
+
             if (!IsWhiteListedFile (path)) {
                 IncrementProcessedCount (null);
                 return;
@@ -96,15 +102,15 @@
             try {            
                 SafeUri uri = new SafeUri (path);
 
-                LibraryTrackInfo track = null;
+                DatabaseTrackInfo track = null;
                 
-                /*if (LibraryTrackInfo.ContainsUri (uri)) {
+                /*if (DatabaseTrackInfo.ContainsUri (uri)) {
                     IncrementProcessedCount (null);
                     return;
                 }*/
 
                 TagLib.File file = StreamTagger.ProcessUri (uri);
-                track = new LibraryTrackInfo ();
+                track = new DatabaseTrackInfo ();
                 StreamTagger.TrackInfoMerge (track, file);
                 
                 SafeUri newpath = track.CopyToLibrary ();
@@ -120,8 +126,9 @@
 
                     artist.Save ();
 
+                    track.SourceId = library_source_id;
                     track.Save ();
-                    (ServiceManager.SourceManager.DefaultSource as LibrarySource).Reload ();
+                    ServiceManager.SourceManager.Library.Reload (200);
                 });
                 
                 if (track != null && track.DbId > 0) {
@@ -140,7 +147,7 @@
 
         private void LogError (string path, string msg)
         {
-            ErrorSource error_source = ((LibrarySource)ServiceManager.SourceManager.DefaultSource).ErrorSource;
+            ErrorSource error_source = ServiceManager.SourceManager.Library.ErrorSource;
             error_source.AddMessage (Path.GetFileName (path), msg);
             
             Log.Error (path, msg, false);

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	Wed Feb 20 21:58:49 2008
@@ -42,29 +42,8 @@
 
 namespace Banshee.Library
 {
-    public class LibrarySource : DatabaseSource
+    public class LibrarySource : PrimarySource
     {
-        private ErrorSource error_source = new ErrorSource (Catalog.GetString ("Import Errors"));
-        private bool error_source_visible = false;
-
-        private HyenaSqliteCommand remove_range_command = new HyenaSqliteCommand (@"
-            DELETE FROM CoreTracks WHERE TrackID IN
-                (SELECT ItemID FROM CoreCache
-                    WHERE ModelID = ? LIMIT ?, ?);
-            DELETE FROM CorePlaylistEntries WHERE TrackID IN
-                (SELECT ItemID FROM CoreCache
-                    WHERE ModelID = ? LIMIT ?, ?);
-            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID IN
-                (SELECT ItemID FROM CoreCache
-                    WHERE ModelID = ? LIMIT ?, ?)"
-        );
-
-        private HyenaSqliteCommand remove_track_command = new HyenaSqliteCommand (@"
-            DELETE FROM CoreTracks WHERE TrackID = ?;
-            DELETE FROM CorePlaylistEntries WHERE TrackID = ?;
-            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID = ?"
-        );
-    
         public LibrarySource () : base (Catalog.GetString ("Library"), Catalog.GetString ("Library"), "Library", 1)
         {
             Properties.SetStringList ("Icon.Name", "go-home", "user-home", "source-library");
@@ -72,83 +51,12 @@
             AfterInitialized ();
 
             Properties.SetString ("RemoveTracksActionLabel", Catalog.GetString ("Remove From Library"));
-            
-            error_source.Updated += OnErrorSourceUpdated;
-            OnErrorSourceUpdated (null, null);
         }
         
-        private void OnErrorSourceUpdated (object o, EventArgs args)
-        {
-            if (error_source.Count > 0 && !error_source_visible) {
-                AddChildSource (error_source);
-                error_source_visible = true;
-            } else if (error_source.Count <= 0 && error_source_visible) {
-                RemoveChildSource (error_source);
-                error_source_visible = false;
-            }
-        }
-
-        public override void RemoveTrack (LibraryTrackInfo track)
-        {
-            remove_track_command.ApplyValues (track.DbId);
-            ServiceManager.DbConnection.Execute (remove_track_command);
-            Reload ();
-            ReloadChildren ();
-        }
-
-        /*public override void RemoveTracks (IEnumerable<TrackInfo> tracks)
-        {
-
-            // BEGIN transaction
-
-            int i = 0;
-            LibraryTrackInfo ltrack;
-            foreach (TrackInfo track in tracks) {
-                ltrack = track as LibraryTrackInfo;
-                if (ltrack == null)
-                    continue;
-
-                command.ApplyValues (ltrack.DbId, ltrack.DbId, ltrack.DbId);
-                ServiceManager.DbConnection.Execute (command);
-
-                if (++i % 100 == 0) {
-                    // COMMIT and BEGIN new transaction
-                }
-            }
-
-            // COMMIT transaction
-
-            // Reload the library, all playlists, etc
-            Reload ();
-            ReloadChildren ();
-        }*/
-
-        public override void RemoveSelectedTracks (TrackListDatabaseModel model)
-        {
-            base.RemoveSelectedTracks (model);
-            ReloadChildren ();
-        }
-
-        protected override void RemoveTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)
-        {
-            remove_range_command.ApplyValues (
-                    model.CacheId, range.Start, range.End - range.Start + 1,
-                    model.CacheId, range.Start, range.End - range.Start + 1,
-                    model.CacheId, range.Start, range.End - range.Start + 1
-            );
-            ServiceManager.DbConnection.Execute (remove_range_command);
-        }
-
-        public override void DeleteSelectedTracks (TrackListDatabaseModel model)
-        {
-            base.DeleteSelectedTracks (model);
-            ReloadChildren ();
-        }
-
         protected override void DeleteTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)
         {
             for (int i = range.Start; i <= range.End; i++) {
-                LibraryTrackInfo track = model [i] as LibraryTrackInfo;
+                DatabaseTrackInfo track = model [i] as DatabaseTrackInfo;
                 if (track == null)
                     continue;
 
@@ -169,15 +77,6 @@
             }
         }
 
-        private void ReloadChildren ()
-        {
-            foreach (Source child in Children) {
-                if (child is ITrackModelSource) {
-                    (child as ITrackModelSource).Reload ();
-                }
-            }
-        }
-        
         public override bool AcceptsInputFromSource (Source source)
         {
             return source is IImportSource;
@@ -192,10 +91,6 @@
             ((IImportSource)source).Import ();
         }
         
-        public ErrorSource ErrorSource {
-            get { return error_source; }
-        }
-
         public override bool CanRename {
             get { return false; }
         }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs	Wed Feb 20 21:58:49 2008
@@ -159,11 +159,11 @@
         public void Import ()
         {    
             try {
-                Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ("LibraryImportManager").ImportFinished += delegate {
+                Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ().ImportFinished += delegate {
                     CreatePlaylist ();
                 };
 
-                Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ("LibraryImportManager").QueueSource (uris);
+                Banshee.ServiceStack.ServiceManager.Get<LibraryImportManager> ().QueueSource (uris);
             } catch (PlaylistImportCanceledException) {
                 // Do nothing, user canceled import.
             }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs	Wed Feb 20 21:58:49 2008
@@ -220,7 +220,7 @@
 
 #endregion
 
-        /*public override void AddTrack (LibraryTrackInfo track)
+        /*public override void AddTrack (DatabaseTrackInfo track)
         {
             add_track_command.ApplyValues (DbId, track.DbId);
             ServiceManager.DbConnection.Execute (add_track_command);
@@ -242,7 +242,7 @@
             ServiceManager.DbConnection.Execute (add_track_range_command);
         }
 
-        public override void RemoveTrack (LibraryTrackInfo track)
+        public override void RemoveTrack (DatabaseTrackInfo track)
         {
             remove_track_command.ApplyValues (DbId, track.DbId);
             ServiceManager.DbConnection.Execute (remove_track_command);

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	Wed Feb 20 21:58:49 2008
@@ -14,11 +14,12 @@
     <File name="Banshee.Collection.Database/ArtistListDatabaseModel.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection.Database/LibraryAlbumInfo.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection.Database/LibraryArtistInfo.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.Collection.Database/LibraryTrackInfo.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Collection.Database/DatabaseTrackInfo.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection.Database/TrackListDatabaseModel.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/Source.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/SourceManager.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/DatabaseSource.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Sources/PrimarySource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Playlist/PlaylistSource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Library/LibrarySource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.ServiceStack/Application.cs" subtype="Code" buildaction="Compile" />
@@ -145,4 +146,4 @@
     <AsmRefVar />
     <ProjectRefVar />
   </MonoDevelop.Autotools.MakefileInfo>
-</Project>
\ No newline at end of file
+</Project>

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	Wed Feb 20 21:58:49 2008
@@ -127,7 +127,7 @@
 
         private void HandleTrackChanged (object sender, EventArgs args)
         {
-            //LibraryTrackInfo track = sender as LibraryTrackInfo;
+            //DatabaseTrackInfo track = sender as DatabaseTrackInfo;
 
             //if (track != null)
                 //CheckTrack (track);
@@ -259,7 +259,7 @@
             return true;
         }
 
-        private void CheckTrack (LibraryTrackInfo track)
+        private void CheckTrack (DatabaseTrackInfo track)
         {
             if (RateLimit())
                 return;

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	Wed Feb 20 21:58:49 2008
@@ -132,9 +132,14 @@
 
 #region Public Methods
 
+        public void Reload (double min_interval_ms)
+        {
+            reload_limiter.Execute (min_interval_ms);
+        }
+
         public void Reload ()
         {
-            reload_limiter.Execute ();
+            reload_limiter.Execute (50.0);
         }
 
         protected virtual void RateLimitedReload ()
@@ -147,10 +152,10 @@
 
         public virtual void RemoveTrack (int index)
         {
-            RemoveTrack (track_model [index] as LibraryTrackInfo);
+            RemoveTrack (track_model [index] as DatabaseTrackInfo);
         }
 
-        public virtual void RemoveTrack (LibraryTrackInfo track)
+        public virtual void RemoveTrack (DatabaseTrackInfo track)
         {
             throw new NotImplementedException(); 
         }

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	Wed Feb 20 21:58:49 2008
@@ -0,0 +1,166 @@
+//
+// PrimarySource.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 System;
+using System.Collections.Generic;
+
+using Mono.Unix;
+using Hyena.Data;
+using Hyena.Data.Sqlite;
+using Hyena.Collections;
+
+using Banshee.Base;
+using Banshee.ServiceStack;
+using Banshee.Sources;
+using Banshee.Collection;
+using Banshee.Collection.Database;
+
+namespace Banshee.Sources
+{
+    public abstract class PrimarySource : DatabaseSource
+    {
+        protected ErrorSource error_source = new ErrorSource (Catalog.GetString ("Import Errors"));
+        protected bool error_source_visible = false;
+
+        protected HyenaSqliteCommand remove_range_command = new HyenaSqliteCommand (@"
+            DELETE FROM CoreTracks WHERE TrackID IN
+                (SELECT ItemID FROM CoreCache
+                    WHERE ModelID = ? LIMIT ?, ?);
+            DELETE FROM CorePlaylistEntries WHERE TrackID IN
+                (SELECT ItemID FROM CoreCache
+                    WHERE ModelID = ? LIMIT ?, ?);
+            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID IN
+                (SELECT ItemID FROM CoreCache
+                    WHERE ModelID = ? LIMIT ?, ?)"
+        );
+
+        protected HyenaSqliteCommand remove_track_command = new HyenaSqliteCommand (@"
+            DELETE FROM CoreTracks WHERE TrackID = ?;
+            DELETE FROM CorePlaylistEntries WHERE TrackID = ?;
+            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID = ?"
+        );
+
+        protected int source_id;
+        public int SourceId {
+            get { return source_id; }
+        }
+
+        protected PrimarySource (string generic_name, string name, string id, int order) : base (generic_name, name, id, order)
+        {
+            source_id = ServiceManager.DbConnection.Query<int> ("SELECT SourceID FROM CorePrimarySources WHERE StringID = ?", id);
+            if (source_id == 0) {
+                source_id = ServiceManager.DbConnection.Execute ("INSERT INTO CorePrimarySources (StringID) VALUES (?)", id);
+            }
+
+            track_model.Condition = String.Format ("CoreTracks.SourceID = {0}", source_id);;
+            error_source.Updated += OnErrorSourceUpdated;
+            OnErrorSourceUpdated (null, null);
+        }
+
+        public ErrorSource ErrorSource {
+            get { return error_source; }
+        }
+
+        protected void OnErrorSourceUpdated (object o, EventArgs args)
+        {
+            if (error_source.Count > 0 && !error_source_visible) {
+                AddChildSource (error_source);
+                error_source_visible = true;
+            } else if (error_source.Count <= 0 && error_source_visible) {
+                RemoveChildSource (error_source);
+                error_source_visible = false;
+            }
+        }
+
+        public override void RemoveTrack (DatabaseTrackInfo track)
+        {
+            remove_track_command.ApplyValues (track.DbId);
+            ServiceManager.DbConnection.Execute (remove_track_command);
+            Reload ();
+            ReloadChildren ();
+        }
+
+        /*public override void RemoveTracks (IEnumerable<TrackInfo> tracks)
+        {
+
+            // BEGIN transaction
+
+            int i = 0;
+            DatabaseTrackInfo ltrack;
+            foreach (TrackInfo track in tracks) {
+                ltrack = track as DatabaseTrackInfo;
+                if (ltrack == null)
+                    continue;
+
+                command.ApplyValues (ltrack.DbId, ltrack.DbId, ltrack.DbId);
+                ServiceManager.DbConnection.Execute (command);
+
+                if (++i % 100 == 0) {
+                    // COMMIT and BEGIN new transaction
+                }
+            }
+
+            // COMMIT transaction
+
+            // Reload the library, all playlists, etc
+            Reload ();
+            ReloadChildren ();
+        }*/
+
+        public override void RemoveSelectedTracks (TrackListDatabaseModel model)
+        {
+            base.RemoveSelectedTracks (model);
+            ReloadChildren ();
+        }
+
+        protected override void RemoveTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)
+        {
+            remove_range_command.ApplyValues (
+                    model.CacheId, range.Start, range.End - range.Start + 1,
+                    model.CacheId, range.Start, range.End - range.Start + 1,
+                    model.CacheId, range.Start, range.End - range.Start + 1
+            );
+            ServiceManager.DbConnection.Execute (remove_range_command);
+        }
+
+        public override void DeleteSelectedTracks (TrackListDatabaseModel model)
+        {
+            base.DeleteSelectedTracks (model);
+            ReloadChildren ();
+        }
+
+        private void ReloadChildren ()
+        {
+            foreach (Source child in Children) {
+                if (child is ITrackModelSource) {
+                    (child as ITrackModelSource).Reload ();
+                }
+            }
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs	Wed Feb 20 21:58:49 2008
@@ -32,6 +32,7 @@
 using Mono.Addins;
 
 using Banshee.ServiceStack;
+using Banshee.Library;
 
 namespace Banshee.Sources
 {
@@ -53,6 +54,7 @@
         private List<Source> sources = new List<Source>();
         private Source active_source;
         private Source default_source;
+        private LibrarySource library_source;
         
         public event SourceEventHandler SourceUpdated;
         public event SourceAddedHandler SourceAdded;
@@ -74,6 +76,11 @@
                 }
             }
         }
+
+        public void AddSource(Source source)
+        {
+            AddSource(source, false);
+        }
         
         public void AddSource(Source source, bool isDefault)
         {
@@ -99,6 +106,10 @@
                 args.Source = source;
                 handler(args);
             }
+
+            if (source is LibrarySource) {
+                library_source = source as LibrarySource;
+            }
             
             ServiceManager.DBusServiceManager.RegisterObject(source);
             
@@ -111,11 +122,6 @@
             }
         }
         
-        public void AddSource(Source source)
-        {
-            AddSource(source, false);
-        }
-        
         public void RemoveSource(Source source)
         {
             if(source == null || !ContainsSource (source)) {
@@ -209,7 +215,11 @@
             get { return default_source; }
             set { default_source = value; }
         }
-        
+
+        public LibrarySource Library {
+            get { return library_source; }
+        }
+
         public Source ActiveSource {
             get { return active_source; }
         }

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Wed Feb 20 21:58:49 2008
@@ -14,7 +14,7 @@
 	Banshee.Collection.Database/ArtistListDatabaseModel.cs \
 	Banshee.Collection.Database/LibraryAlbumInfo.cs \
 	Banshee.Collection.Database/LibraryArtistInfo.cs \
-	Banshee.Collection.Database/LibraryTrackInfo.cs \
+	Banshee.Collection.Database/DatabaseTrackInfo.cs \
 	Banshee.Collection.Database/TrackListDatabaseModel.cs \
 	Banshee.Collection/AlbumListModel.cs \
 	Banshee.Collection/ArtistListModel.cs \
@@ -109,6 +109,7 @@
 	Banshee.Sources/ISourceManager.cs \
 	Banshee.Sources/ITrackModelSource.cs \
 	Banshee.Sources/IUnmapableSource.cs \
+	Banshee.Sources/PrimarySource.cs \
 	Banshee.Sources/Source.cs \
 	Banshee.Sources/SourceManager.cs \
 	Banshee.Sources/SourceMergeType.cs \

Modified: trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs	Wed Feb 20 21:58:49 2008
@@ -291,7 +291,7 @@
         
         private void ToggleRatingMenuSensitive () 
         {
-            if (ServiceManager.PlayerEngine.CurrentTrack is LibraryTrackInfo) {
+            if (ServiceManager.PlayerEngine.CurrentTrack is DatabaseTrackInfo) {
                 rating_menu_item.Reset ((int)ServiceManager.PlayerEngine.CurrentTrack.Rating);
                 rating_menu_item.Show ();
             } else {

Modified: trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs	Wed Feb 20 21:58:49 2008
@@ -52,7 +52,7 @@
     {
         private static string special_playlist_name = typeof (PlayQueueSource).ToString ();
 
-        private LibraryTrackInfo playing_track;
+        private DatabaseTrackInfo playing_track;
         private BansheeActionGroup actions;
         private bool actions_loaded = false;
         
@@ -204,7 +204,7 @@
                 return;
             }
             
-            playing_track = (LibraryTrackInfo)TrackModel[0];
+            playing_track = (DatabaseTrackInfo)TrackModel[0];
             ServiceManager.PlayerEngine.OpenPlay (playing_track);
         }
         

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs	Wed Feb 20 21:58:49 2008
@@ -95,7 +95,7 @@
                     : 0;
             } else {
                 result = !reader.IsDBNull (column)
-                    ? reader.GetInt64 (column)
+                    ? (long) reader.GetValue (column)
                     : 0;
             }
             result = SqliteUtils.FromDbFormat (type, result);

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	Wed Feb 20 21:58:49 2008
@@ -178,6 +178,11 @@
             return ExecuteReader (command.Command);
         }
 
+        public IDataReader ExecuteReader (string command_str, params object [] param_values)
+        {
+            return ExecuteReader (new HyenaSqliteCommand (command_str, param_values));
+        }
+
         public IDataReader ExecuteReader (object command)
         {
             return ExecuteReader (new SqliteCommand (command.ToString ()));
@@ -205,6 +210,11 @@
             return ExecuteScalar (command.Command);
         }
 
+        public object ExecuteScalar (string command_str, params object [] param_values)
+        {
+            return ExecuteScalar (new HyenaSqliteCommand (command_str, param_values));
+        }
+
         public object ExecuteScalar (object command)
         {
             return ExecuteScalar (new SqliteCommand (command.ToString ()));
@@ -223,6 +233,11 @@
             return Query<T> (command.Command);
         }
 
+        public T Query<T> (string command_str, params object [] param_values)
+        {
+            return Query<T> (new HyenaSqliteCommand (command_str, param_values));
+        }
+
         public T Query<T> (object command)
         {
             return Query<T> (new SqliteCommand (command.ToString ()));
@@ -251,6 +266,11 @@
             return Execute (command.Command);
         }
 
+        public int Execute (string command_str, params object [] param_values)
+        {
+            return Execute (new HyenaSqliteCommand (command_str, param_values));
+        }
+
         public int Execute (object command)
         {
             return Execute (new SqliteCommand (command.ToString ()));

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	Wed Feb 20 21:58:49 2008
@@ -284,12 +284,22 @@
         {
             int i = 0;
             
-            foreach (DatabaseColumn column in columns) {
-                column.SetValue (target, reader, i++);
-            }
-            
-            foreach (VirtualDatabaseColumn column in virtual_columns) {
-                column.SetValue (target, reader, i++);
+            AbstractDatabaseColumn bad_column = null;
+            try {
+                foreach (DatabaseColumn column in columns) {
+                    bad_column = column;
+                    column.SetValue (target, reader, i++);
+                }
+                
+                foreach (VirtualDatabaseColumn column in virtual_columns) {
+                    bad_column = column;
+                    column.SetValue (target, reader, i++);
+                }
+            } catch (Exception e) {
+                Log.Debug (
+                    String.Format ("Caught exception trying to load database column {0}", bad_column == null ? "[unknown]" : bad_column.Name),
+                    e.ToString ()
+                );
             }
         }
         



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