banshee r3381 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Library



Author: gburt
Date: Wed Mar  5 02:20:18 2008
New Revision: 3381
URL: http://svn.gnome.org/viewvc/banshee?rev=3381&view=rev

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

	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs:
	Replace confusing constructors with static FindOrCreate methods.  Should
	fix an issue with finding/creating/associating new albums too.

	* src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs: Use
	new FindOrCreate methods.


Modified:
   trunk/banshee/ChangeLog
   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.Library/LibraryImportManager.cs

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	Wed Mar  5 02:20:18 2008
@@ -58,26 +58,41 @@
             ArtistName
         }
 
-        public LibraryAlbumInfo () : base (null)
+        public static LibraryAlbumInfo FindOrCreate (LibraryArtistInfo artist, string title)
         {
-        }
+            LibraryAlbumInfo album;
 
-        public LibraryAlbumInfo (LibraryArtistInfo artist, string title) : base (null)
-        {
             if (title == null || title.Trim () == String.Empty)
                 title = Catalog.GetString ("Unknown Album");
 
-            using (IDataReader reader = ServiceManager.DbConnection.Query (select_command.ApplyValues (artist.DbId, title))) {
+            using (IDataReader reader = ServiceManager.DbConnection.Query (select_command, artist.DbId, title)) {
                 if (reader.Read ()) {
-                    dbid = Convert.ToInt32 (reader[(int) Column.AlbumID]);
-                    Title = reader[(int) Column.Title] as string;
-                    ArtistName = artist.Name;
+                    album = new LibraryAlbumInfo (reader);
+                    album.ArtistName = artist.Name;
                 } else {
-                    artist_id = artist.DbId;
-                    Title = title;
-                    Save ();
+                    album = new LibraryAlbumInfo ();
+                    album.Title = title;
+                    album.ArtistId = artist.DbId;
+                    album.ArtistName = artist.Name;
+                    album.Save ();
                 }
             }
+            return album;
+        }
+
+        public LibraryAlbumInfo () : base (null)
+        {
+        }
+
+        protected LibraryAlbumInfo (IDataReader reader) : base (null)
+        {
+            LoadFromReader (reader);
+        }
+
+        private void LoadFromReader (IDataReader reader)
+        {
+            dbid = Convert.ToInt32 (reader[(int) Column.AlbumID]);
+            Title = reader[(int) Column.Title] as string;
         }
 
         public void Save ()

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	Wed Mar  5 02:20:18 2008
@@ -56,29 +56,33 @@
             ArtistID,
             Name
         }
-        
-        public LibraryArtistInfo () : base (null)
-        {
-        }
 
-        public LibraryArtistInfo (string artistName) : base (null)
+        public static LibraryArtistInfo FindOrCreate (string artistName)
         {
+            LibraryArtistInfo artist;
+
             if (artistName == null || artistName.Trim () == String.Empty)
                 artistName = Catalog.GetString ("Unknown Artist");
 
-            using (IDataReader reader = ServiceManager.DbConnection.Query (select_command.ApplyValues (artistName))) {
+            using (IDataReader reader = ServiceManager.DbConnection.Query (select_command, artistName)) {
                 if (reader.Read ()) {
-                    LoadFromReader (reader);
+                    artist = new LibraryArtistInfo (reader);
                 } else {
-                    Name = artistName;
-                    Save ();
+                    artist = new LibraryArtistInfo ();
+                    artist.Name = artistName;
+                    artist.Save ();
                 }
             }
+            return artist;
+        }
+        
+        public LibraryArtistInfo () : base (null)
+        {
         }
 
-        public LibraryArtistInfo(IDataReader reader) : base(null)
+        protected LibraryArtistInfo (IDataReader reader) : base (null)
         {
-            LoadFromReader(reader);
+            LoadFromReader (reader);
         }
 
         public void Save ()
@@ -86,9 +90,9 @@
             Provider.Save (this);
         }
 
-        private void LoadFromReader(IDataReader reader)
+        private void LoadFromReader (IDataReader reader)
         {
-            dbid = Convert.ToInt32(reader[(int)Column.ArtistID]);
+            dbid = Convert.ToInt32 (reader[(int)Column.ArtistID]);
             Name = reader[(int)Column.Name] as string;
         }
 

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 Mar  5 02:20:18 2008
@@ -133,17 +133,13 @@
                     track.Uri = newpath;
                 }
 
-                LibraryArtistInfo artist = new LibraryArtistInfo (track.ArtistName);
-                LibraryAlbumInfo album = new LibraryAlbumInfo (artist, track.AlbumTitle);
-
-                track.ArtistId = artist.DbId;
-                track.AlbumId = album.DbId;
+                LibraryArtistInfo artist = LibraryArtistInfo.FindOrCreate (track.ArtistName);
+                LibraryAlbumInfo album = LibraryAlbumInfo.FindOrCreate (artist, track.AlbumTitle);
 
                 track.DateAdded = DateTime.Now;
                 track.Source = ServiceManager.SourceManager.Library;
-
-                album.Save ();
-                artist.Save ();
+                track.ArtistId = artist.DbId;
+                track.AlbumId = album.DbId;
                 track.Save (false);
 
                 ServiceManager.DbConnection.CommitTransaction ();



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