banshee r4529 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Playlist src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue



Author: abock
Date: Fri Sep 12 03:49:19 2008
New Revision: 4529
URL: http://svn.gnome.org/viewvc/banshee?rev=4529&view=rev

Log:
2008-09-11  Aaron Bockover  <abock gnome org>

    * src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs:
    Implement playlist loading into the FSQ

    * src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs:
    Allow playlist importing to work against any PrimarySource

    * configure.ac: Disable the DEVEL_BUILD



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/configure.ac
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
   trunk/banshee/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs

Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac	(original)
+++ trunk/banshee/configure.ac	Fri Sep 12 03:49:19 2008
@@ -2,7 +2,7 @@
 
 AC_INIT([banshee-1], [1.3.0]) 
 ASM_DISPLAY_VERSION="1.3.0"
-DEVEL_BUILD=yes
+DEVEL_BUILD=no
 
 AC_CANONICAL_SYSTEM
 AC_PREREQ(2.13)

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	Fri Sep 12 03:49:19 2008
@@ -12,9 +12,9 @@
 using Banshee.ServiceStack;
 using Banshee.Database;
 using Banshee.Sources;
-using Banshee.Library;
 using Banshee.Playlists.Formats;
 using Banshee.Collection;
+using Banshee.Collection.Database;
 
 namespace Banshee.Playlist
 {
@@ -121,6 +121,20 @@
             }
             return uris.ToArray ();
         }
+        
+        public static bool PathHasPlaylistExtension (string playlistUri)
+        {
+            if (System.IO.Path.HasExtension (playlistUri)) {
+                string extension = System.IO.Path.GetExtension (playlistUri).ToLower ();
+                foreach (PlaylistFormatDescription format in PlaylistFileUtil.ExportFormats) {
+                    if (extension.Equals ("." + format.FileExtension)) {
+                        return true;
+                    }
+                }
+            }
+            
+            return false;
+        }
 
         public static IPlaylistFormat Load (string playlistUri, Uri baseUri)
         {
@@ -163,6 +177,11 @@
         
         public static void ImportPlaylistToLibrary (string path)
         {
+            ImportPlaylistToLibrary (path, ServiceManager.SourceManager.MusicLibrary, null);
+        }
+        
+        public static void ImportPlaylistToLibrary (string path, PrimarySource source, DatabaseImportManager importer)
+        {
             try {
                 SafeUri uri = new SafeUri (path);
                 PlaylistParser parser = new PlaylistParser ();
@@ -177,7 +196,9 @@
                         uris.Add (((Uri)element["uri"]).LocalPath);
                     }
                     
-                    ImportPlaylistWorker worker = new ImportPlaylistWorker (System.IO.Path.GetFileNameWithoutExtension (uri.LocalPath), uris.ToArray ());
+                    ImportPlaylistWorker worker = new ImportPlaylistWorker (
+                        System.IO.Path.GetFileNameWithoutExtension (uri.LocalPath), 
+                        uris.ToArray (), source, importer);
                     worker.Import ();
                 }
             } catch (Exception e) {
@@ -190,18 +211,24 @@
     {
         private string [] uris;
         private string name;
-        private LibraryImportManager importer;
         
-        public ImportPlaylistWorker (string name, string [] uris)
+        private PrimarySource source;
+        private DatabaseImportManager importer;
+        
+        public ImportPlaylistWorker (string name, string [] uris, PrimarySource source, DatabaseImportManager importer)
         {
             this.name = name;
             this.uris = uris;
+            this.source = source;
+            this.importer = importer;
         }
         
         public void Import ()
         {
             try {
-                importer = new LibraryImportManager ();
+                if (importer == null) {
+                    importer = new Banshee.Library.LibraryImportManager ();
+                }
                 importer.Finished += CreatePlaylist;
                 importer.Enqueue (uris);
             } catch (PlaylistImportCanceledException e) {
@@ -212,16 +239,17 @@
         private void CreatePlaylist (object o, EventArgs args)
         {
             try {
-                PlaylistSource playlist = new PlaylistSource (name, ServiceManager.SourceManager.MusicLibrary.DbId);
+                PlaylistSource playlist = new PlaylistSource (name, source.DbId);
                 playlist.Save ();
-                ServiceManager.SourceManager.MusicLibrary.AddChildSource (playlist);
+                source.AddChildSource (playlist);
 
                 HyenaSqliteCommand insert_command = new HyenaSqliteCommand (String.Format (
                     @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES ({0}, ?)", playlist.DbId));
 
                 //ServiceManager.DbConnection.BeginTransaction ();
                 foreach (string uri in uris) {
-                    int track_id = LibrarySource.GetTrackIdForUri (uri);
+                    // FIXME: Does the following call work if the source is just a PrimarySource (not LibrarySource)?
+                    int track_id = Banshee.Library.LibrarySource.GetTrackIdForUri (uri);
                     if (track_id > 0) {
                         ServiceManager.DbConnection.Execute (insert_command, track_id);
                     }

Modified: trunk/banshee/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs	Fri Sep 12 03:49:19 2008
@@ -39,6 +39,8 @@
 using Banshee.Collection;
 using Banshee.Collection.Database;
 using Banshee.Configuration;
+using Banshee.Kernel;
+using Banshee.Playlist;
 
 using Banshee.Gui;
 
@@ -137,7 +139,11 @@
                     };
                 }
             
-                importer.Enqueue (path);
+                if (PlaylistFileUtil.PathHasPlaylistExtension (path)) {
+                    PlaylistFileUtil.ImportPlaylistToLibrary (path, this, importer);
+                } else {
+                    importer.Enqueue (path);
+                }
             }
         }
         



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