banshee r3118 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Playlist src/Core/Banshee.Services/Banshee.ServiceStack src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Gui src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue src/Extensions/Banshee.PlayQueue/Resources



Author: abock
Date: Thu Jan 31 06:53:34 2008
New Revision: 3118
URL: http://svn.gnome.org/viewvc/banshee?rev=3118&view=rev

Log:
2008-01-31  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs:
    Push IDisposable services into a dispose stack on startup; unwind this
    stack on shutdown, disposing services in the proper (safe) order

    * src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs: Make
    IDisposable and dispose all sources if they are in turn IDisposable

    * src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs:
    * src/Extensions/Banshee.PlayQueue/Resources/GlobalUI.xml:
    Added 'clear on quit' support; make IDisposable, clearing the queue
    if set on Dipose

    * src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs: Finish
    porting the naming utility stuff to create proper playlist names; not
    actually in use yet

    * src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs: Get
    rid of the params Add method since there are many more ActionEntry
    arrays that won't work with params



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs
   trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
   trunk/banshee/src/Extensions/Banshee.PlayQueue/Resources/GlobalUI.xml

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	Thu Jan 31 06:53:34 2008
@@ -132,13 +132,13 @@
 
         protected override void Create ()
         {
-            Console.WriteLine ("Creating playlist");
             DbId = ServiceManager.DbConnection.Execute (new HyenaSqliteCommand (
                 @"INSERT INTO CorePlaylists (PlaylistID, Name, SortColumn, SortType)
                     VALUES (NULL, ?, ?, ?)",
                 Name, -1, 1 //SortColumn, SortType
             ));
-            Console.WriteLine ("Done Creating playlist");
+            
+            OnUserNotifyUpdated ();
         }
 
 #endregion
@@ -236,38 +236,33 @@
                 }
             }
         }
-    }
-
-    internal static class PlaylistUtil
-    {
-        /*internal static int GetPlaylistID(string name)
-        {
-            try {
-                return Convert.ToInt32(Globals.Library.Db.QuerySingle(new DbCommand(
-                @"SELECT PlaylistID
-                    FROM Playlists
-                    WHERE Name = :name
-                    LIMIT 1",
-                    "name", name
-                )));
-            } catch(Exception) {
-                return 0;
+        
+        public static int GetPlaylistId (string name)
+        {
+            object result = ServiceManager.DbConnection.ExecuteScalar (new HyenaSqliteCommand (
+                "SELECT PlaylistID FROM Playlists WHERE Name = ? LIMIT 1", name));
+            
+            if (result != null) {
+                return Convert.ToInt32 (result);
             }
-        }*/
+            
+            return 0;
+        }
         
-        /*internal static bool PlaylistExists(string name)
+        public static bool PlaylistExists (string name)
         {
-            return GetPlaylistID(name) > 0;
-        }*/
+            return GetPlaylistId (name) > 0;
+        }
         
-        /*public static string UniqueName {
-            get { return NamingUtil.PostfixDuplicate(Catalog.GetString("New Playlist"), PlaylistExists); }
+        public static string CreateUniqueName () 
+        {
+            return NamingUtil.PostfixDuplicate (Catalog.GetString ("New Playlist"), PlaylistExists);
         }
         
-        public static string GoodUniqueName(IEnumerable tracks)
+        public static string CreateUniqueName (IEnumerable tracks)
         {
-            return NamingUtil.PostfixDuplicate(NamingUtil.GenerateTrackCollectionName(
-                tracks, Catalog.GetString("New Playlist")), PlaylistExists);
-        }*/
+            return NamingUtil.PostfixDuplicate (NamingUtil.GenerateTrackCollectionName (
+                tracks, Catalog.GetString ("New Playlist")), PlaylistExists);
+        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs	Thu Jan 31 06:53:34 2008
@@ -46,6 +46,7 @@
     public static class ServiceManager
     {
         private static Dictionary<string, IService> services = new Dictionary<string, IService> ();
+        private static Stack<IService> dispose_services = new Stack<IService> ();
         private static List<Type> service_types = new List<Type> ();
         private static ExtensionNodeList extension_nodes;
         
@@ -90,18 +91,30 @@
                     uint timer_id = Log.DebugTimerStart (); 
                     IService service = (IService)Activator.CreateInstance (type);
                     RegisterService (service);
+                    
                     Log.DebugTimerPrint (timer_id, String.Format (
                         "Core service started ({0}, {{0}})", service.ServiceName));
+                    
                     OnServiceStarted (service);
+                    
+                    if (service is IDisposable) {
+                        dispose_services.Push (service);
+                    }
                 }
                 
                 foreach (TypeExtensionNode node in extension_nodes) {
                     uint timer_id = Log.DebugTimerStart ();
                     IService service = (IService)node.CreateInstance (typeof (IService));
                     RegisterService (service);
+                    
                     Log.DebugTimerPrint (timer_id, String.Format (
                         "Extension service started ({0}, {{0}})", service.ServiceName));
+                    
                     OnServiceStarted (service);
+                    
+                    if (service is IDisposable) {
+                        dispose_services.Push (service);
+                    }
                 }
                 
                 is_initialized = true;
@@ -115,10 +128,10 @@
         public static void Shutdown ()
         {
             lock (self_mutex) {
-                foreach (IService service in services.Values) {
-                    if (service is IDisposable) {
-                        ((IDisposable)service).Dispose ();
-                    }
+                while (dispose_services.Count > 0) {
+                    IService service = dispose_services.Pop ();
+                    ((IDisposable)service).Dispose ();
+                    Log.DebugFormat ("Service disposed ({0})", service.ServiceName);
                 }
                 
                 services.Clear ();

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	Thu Jan 31 06:53:34 2008
@@ -48,7 +48,7 @@
         public int Position;
     }
     
-    public class SourceManager : ISourceManager
+    public class SourceManager : ISourceManager, IDisposable
     {
         private List<Source> sources = new List<Source>();
         private Source active_source;
@@ -67,6 +67,15 @@
             }
         }
         
+        public void Dispose ()
+        {
+            foreach (Source source in sources) {
+                if (source is IDisposable) {
+                    ((IDisposable)source).Dispose ();
+                }
+            }
+        }
+        
         public void AddSource(Source source, bool isDefault)
         {
             if(source == null || ContainsSource (source)) {

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs	Thu Jan 31 06:53:34 2008
@@ -45,11 +45,6 @@
         {
         }
         
-        public new void Add (params ActionEntry [] action_entries)
-        {
-            base.Add (action_entries);
-        }
-
         public void AddImportant (params ActionEntry [] action_entries)
         {
             base.Add (action_entries);

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	Thu Jan 31 06:53:34 2008
@@ -41,12 +41,13 @@
 using Banshee.Collection.Database;
 using Banshee.PlaybackController;
 using Banshee.MediaEngine;
+using Banshee.Configuration;
 
 using Banshee.Gui;
 
 namespace Banshee.PlayQueue
 {
-    public class PlayQueueSource : PlaylistSource, IBasicPlaybackController
+    public class PlayQueueSource : PlaylistSource, IBasicPlaybackController, IDisposable
     {
         private static string special_playlist_name = typeof (PlayQueueSource).ToString ();
 
@@ -70,12 +71,12 @@
             ServiceManager.SourceManager.AddSource (this);
             
             InterfaceActionService uia_service = ServiceManager.Get<InterfaceActionService> ();
-            uia_service.TrackActions.Add (
+            uia_service.TrackActions.Add (new ActionEntry [] {
                 new ActionEntry ("AddToPlayQueueAction", Stock.Add,
                     Catalog.GetString ("Add to Play Queue"), null,
                     Catalog.GetString ("Append selected songs to the play queue"),
                     OnAddToPlayQueue)
-            );
+            });
             
             actions = new BansheeActionGroup ("PlayQueueSource");
             uia_service.GlobalActions.AddImportant (
@@ -85,6 +86,13 @@
                     OnClearPlayQueue)
             );
             
+            uia_service.GlobalActions.Add (new ToggleActionEntry [] {
+                new ToggleActionEntry ("ClearPlayQueueOnQuitAction", null,
+                    Catalog.GetString ("Clear on Quit"), null, 
+                    Catalog.GetString ("Clear the play queue when quitting"), 
+                    OnClearPlayQueueOnQuit, ClearOnQuitSchema.Get ())
+            });
+            
             uia_service.UIManager.AddUiFromResource ("GlobalUI.xml");
             
             Properties.SetString ("ActiveSourceUIResource", "ActiveSourceUI.xml");
@@ -96,6 +104,13 @@
             ServiceManager.SourceManager.ActiveSourceChanged += delegate { UpdateActions (); };
         }
         
+        public void Dispose ()
+        {
+            if (ClearOnQuitSchema.Get ()) {
+                OnClearPlayQueue (this, EventArgs.Empty);
+            }
+        }
+        
         private void BindToDatabase ()
         {
             object result = ServiceManager.DbConnection.ExecuteScalar (new HyenaSqliteCommand (@"
@@ -147,9 +162,20 @@
             Reload ();
         }
         
+        private void OnClearPlayQueueOnQuit (object o, EventArgs args)
+        {
+            InterfaceActionService uia_service = ServiceManager.Get<InterfaceActionService> ();
+            if (uia_service == null) {
+                return;
+            }
+            
+            ToggleAction action = (ToggleAction)uia_service.GlobalActions["ClearPlayQueueOnQuitAction"];
+            ClearOnQuitSchema.Set (action.Active);
+        }
+        
         private void UpdateActions ()
         {   
-            InterfaceActionService uia_service = ServiceManager.Get <InterfaceActionService> ();
+            InterfaceActionService uia_service = ServiceManager.Get<InterfaceActionService> ();
             if (uia_service == null) {
                 return;
             }
@@ -206,5 +232,12 @@
         public override bool CanUnmap {
             get { return false; }
         }
+        
+        public static readonly SchemaEntry<bool> ClearOnQuitSchema = new SchemaEntry<bool> (
+            "plugins.play_queue", "clear_on_quit",
+            false,
+            "Clear on Quit",
+            "Clear the play queue when quitting"
+        );
     }
 }

Modified: trunk/banshee/src/Extensions/Banshee.PlayQueue/Resources/GlobalUI.xml
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.PlayQueue/Resources/GlobalUI.xml	(original)
+++ trunk/banshee/src/Extensions/Banshee.PlayQueue/Resources/GlobalUI.xml	Thu Jan 31 06:53:34 2008
@@ -1,6 +1,7 @@
 <ui>
     <popup name="PlayQueueContextMenu">
         <menuitem action="ClearPlayQueueAction"></menuitem>
+        <menuitem action="ClearPlayQueueOnQuitAction"></menuitem>
     </popup>
     <popup name="TrackContextMenu" action="TrackContextMenuAction">
         <placeholder name="AboveAddToPlaylist">



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