banshee r3127 - in trunk/banshee: . src/Backends/Banshee.GStreamer/Banshee.GStreamer src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.ServiceStack src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue



Author: abock
Date: Fri Feb  1 01:08:15 2008
New Revision: 3127
URL: http://svn.gnome.org/viewvc/banshee?rev=3127&view=rev

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

    * src/Core/Banshee.Services/Banshee.ServiceStack/IExtensionService.cs:
    Added a simple method that extension services must implement; extension
    services should do nothing in their constructors so we can get type
    information from them at runtime at a minimum

    * src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs:
    Require extension services to be IExtensionService; catch all exceptions
    from them, do not bail if an extension explodes and log the error

    * src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys/MultimediaKeysService.cs:
    Extreme hack to support both GNOME Settings Daemon 2.20 and 2.22; I just
    love how pointless API breakage is a common theme in GNOME - the price
    of being an ISV and not 'in GNOME' is high - too high

    * src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs:
    Use 'q' as a shortcut for adding stuff to the play queue

    * src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs:
    * src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler/AudioscrobblerService.cs:
    * src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs:
    Implement IExtensionService



Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/IExtensionService.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler/AudioscrobblerService.cs
   trunk/banshee/src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys/MultimediaKeysService.cs
   trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
   trunk/banshee/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs

Modified: trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs	Fri Feb  1 01:08:15 2008
@@ -33,10 +33,14 @@
 
 namespace Banshee.GStreamer
 {
-    public class Service : IService
+    public class Service : IExtensionService
     {
         public Service ()
         {
+        }
+        
+        void IExtensionService.Initialize ()
+        {
             gstreamer_initialize ();
         }
         

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/IExtensionService.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/IExtensionService.cs	Fri Feb  1 01:08:15 2008
@@ -0,0 +1,37 @@
+//
+// IExtensionService.cs
+//
+// Author:
+//   Aaron Bockover <abockover 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;
+
+namespace Banshee.ServiceStack
+{
+    public interface IExtensionService : IService
+    {
+        void Initialize ();
+    }
+}

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	Fri Feb  1 01:08:15 2008
@@ -103,17 +103,26 @@
                 }
                 
                 foreach (TypeExtensionNode node in extension_nodes) {
-                    uint timer_id = Log.DebugTimerStart ();
-                    IService service = (IService)node.CreateInstance (typeof (IService));
-                    RegisterService (service);
+                    IExtensionService service = null;
                     
-                    Log.DebugTimerPrint (timer_id, String.Format (
-                        "Extension service started ({0}, {{0}})", service.ServiceName));
+                    try {
+                        uint timer_id = Log.DebugTimerStart ();
+                        
+                        service = (IExtensionService)node.CreateInstance (typeof (IExtensionService));
+                        service.Initialize ();
+                        RegisterService (service);
                     
-                    OnServiceStarted (service);
+                        Log.DebugTimerPrint (timer_id, String.Format (
+                            "Extension service started ({0}, {{0}})", service.ServiceName));
                     
-                    if (service is IDisposable) {
-                        dispose_services.Push (service);
+                        OnServiceStarted (service);
+                    
+                        if (service is IDisposable) {
+                            dispose_services.Push (service);
+                        }
+                    } catch (Exception e) {
+                        Log.Warning (String.Format ("Extension `{0}' not started: {1}", 
+                            service == null ? node.Path : service.GetType ().FullName, e.Message));
                     }
                 }
                 

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	Fri Feb  1 01:08:15 2008
@@ -117,6 +117,7 @@
     <File name="Banshee.PlaybackController/IBasicPlaybackController.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/IDurationAggregator.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/IFileSizeAggregator.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.ServiceStack/IExtensionService.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

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	Fri Feb  1 01:08:15 2008
@@ -86,6 +86,7 @@
 	Banshee.ServiceStack/Application.cs \
 	Banshee.ServiceStack/DBusServiceManager.cs \
 	Banshee.ServiceStack/IDBusExportable.cs \
+	Banshee.ServiceStack/IExtensionService.cs \
 	Banshee.ServiceStack/IService.cs \
 	Banshee.ServiceStack/IUserJob.cs \
 	Banshee.ServiceStack/ServiceManager.cs \

Modified: trunk/banshee/src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler/AudioscrobblerService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler/AudioscrobblerService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Audioscrobbler/Banshee.Audioscrobbler/AudioscrobblerService.cs	Fri Feb  1 01:08:15 2008
@@ -33,12 +33,16 @@
 
 namespace Banshee.Audioscrobbler 
 {
-    public class AudioscrobblerService : IService
+    public class AudioscrobblerService : IExtensionService
     {
         public AudioscrobblerService ()
         {
         }
         
+        void IExtensionService.Initialize ()
+        {
+        }
+        
         string IService.ServiceName {
             get { return "AudioscrobblerService"; }
         }

Modified: trunk/banshee/src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys/MultimediaKeysService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys/MultimediaKeysService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.MultimediaKeys/Banshee.MultimediaKeys/MultimediaKeysService.cs	Fri Feb  1 01:08:15 2008
@@ -2,8 +2,8 @@
 // MultimediaKeyService.cs
 //
 // Authors:
+//   Aaron Bockover <abockover novell com>
 //   Alexander Hixon <hixon alexander mediati org>
-//   Aaron Bockover <aaron abock org>
 //   Jan Arne Petersen <jap gnome org>
 //
 // Copyright (C) 2007-2008 Novell, Inc.
@@ -31,56 +31,111 @@
 using System;
 using Mono.Unix;
 
-using Banshee.ServiceStack;
-using Banshee.Configuration;
 using NDesk.DBus;
 
+using Banshee.Base;
+using Banshee.ServiceStack;
+
 namespace Banshee.MultimediaKeys
 {
-    public class MultimediaKeysService : IService, IDisposable
+    public class MultimediaKeysService : IExtensionService, IDisposable
     {
         private const string BusName = "org.gnome.SettingsDaemon";
         private const string ObjectPath = "/org/gnome/SettingsDaemon";
-        private ISettingsDaemon settings_daemon;
         
         private delegate void MediaPlayerKeyPressedHandler (string application, string key);
+
+        // GNOME 2.20
+        [Interface ("org.gnome.SettingsDaemon")]
+        private interface ISettingsDaemon220
+        {
+            void GrabMediaPlayerKeys (string application, uint time);
+            void ReleaseMediaPlayerKeys (string application);
+            event MediaPlayerKeyPressedHandler MediaPlayerKeyPressed;
+        }
         
-        [Interface("org.gnome.SettingsDaemon")]
-        private interface ISettingsDaemon
+        // GNOME 2.22
+        [Interface ("org.gnome.SettingsDaemon.MediaKeys")]
+        private interface ISettingsDaemon222
         {
             void GrabMediaPlayerKeys (string application, uint time);
             void ReleaseMediaPlayerKeys (string application);
             event MediaPlayerKeyPressedHandler MediaPlayerKeyPressed;
         }
-                
-        private const string app_name = "Banshee";
+        
+        private ISettingsDaemon222 settings_daemon_222;
+        private ISettingsDaemon220 settings_daemon_220;
     
         public MultimediaKeysService ()
         {
-            Initialize ();
         }
         
-        private void Initialize ()
+        void IExtensionService.Initialize ()
         {
-            settings_daemon = Bus.Session.GetObject<ISettingsDaemon> (BusName, new ObjectPath (ObjectPath));
-            settings_daemon.GrabMediaPlayerKeys (app_name, 0);
-            settings_daemon.MediaPlayerKeyPressed += OnMediaPlayerKeyPressed;
+            // It's a common theme in GNOME for APIs to change every 6 months
+            // We are essentially an ISV, and actually care about backwards 
+            // compatibility! Therefore, fall back to the interface for GNOME 2.20
+            // if the GNOME 2.22 interface cannot be found.
+            //
+            // Additionally, there is a design limitation in Managed DBus that restricts
+            // it from flattening/following managed interfaces, therefore we must 
+            // explicitly handle two different GSD objects as if they had nothing in
+            // common at this point. This at least will be fixed in Managed DBus.
+            //
+            // For instance, we can't do this currently (semi-pseudo-code):
+            //
+            //    interface IGsdBase { void Food (); }
+            //    [Interface ("org.gnome.SettingsDaemon")] interface IGsd220 : IGsdBase { }
+            //    [Interface ("org.gnome.SettingsDaemon.MediaKeys")] interface IGsd222 : IGsdBase { }
+            //
+            //    IGsdBase gsd = bus.GetObject<IGsd222> (name, path_222) 
+            //    if (gsd == null) 
+            //        gsd = bus.GetObject<IGsd220> (name, path_220)
+            //    gsd.Foo ();
+            //
+            
+            try {
+                settings_daemon_222 = Bus.Session.GetObject<ISettingsDaemon222> (BusName, 
+                    new ObjectPath (ObjectPath + "/MediaKeys"));
+                settings_daemon_222.GrabMediaPlayerKeys (Application.InternalName, 0);
+                settings_daemon_222.MediaPlayerKeyPressed += OnMediaPlayerKeyPressed;
+                
+                Log.Debug ("Using GNOME 2.22 API for Multimedia Keys");
+            } catch {
+                settings_daemon_222 = null;
+                
+                try {
+                    settings_daemon_220 = Bus.Session.GetObject<ISettingsDaemon220> (BusName, 
+                        new ObjectPath (ObjectPath));
+                    settings_daemon_220.GrabMediaPlayerKeys (Application.InternalName, 0);
+                    settings_daemon_220.MediaPlayerKeyPressed += OnMediaPlayerKeyPressed;
+                
+                    Log.Debug ("Using GNOME 2.20 API for Multimedia keys");
+                } catch {
+                    settings_daemon_220 = null;
+                    throw new ApplicationException ("No support GNOME Settings Daemon could be reached.");
+                }
+            }
         }
   
-        public void Dispose()
+        public void Dispose ()
         {
-            if (settings_daemon == null) {
-                return;
+            if (settings_daemon_222 != null) {
+                settings_daemon_222.MediaPlayerKeyPressed -= OnMediaPlayerKeyPressed;
+                settings_daemon_222.ReleaseMediaPlayerKeys (Application.InternalName);
+                settings_daemon_222 = null;
             }
             
-            settings_daemon.MediaPlayerKeyPressed -= OnMediaPlayerKeyPressed;
-            settings_daemon.ReleaseMediaPlayerKeys (app_name);
-            settings_daemon = null;
+            if (settings_daemon_220 != null) {
+                settings_daemon_220.MediaPlayerKeyPressed -= OnMediaPlayerKeyPressed;
+                settings_daemon_220.ReleaseMediaPlayerKeys (Application.InternalName);
+                settings_daemon_220 = null;
+            }
         }
         
         private void OnMediaPlayerKeyPressed (string application, string key)
         {
-            if (application != app_name) {
+            if (application != Application.InternalName) {
                 return;
             }
             

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	Fri Feb  1 01:08:15 2008
@@ -42,31 +42,30 @@
 
 namespace Banshee.NotificationArea 
 {
-    public class NotificationAreaService : IService
+    public class NotificationAreaService : IExtensionService
     {
         private NotificationAreaIcon notif_area;
         private EventBox event_box;
     
         public NotificationAreaService ()
         {
+        }
+        
+        void IExtensionService.Initialize ()
+        {
             // TODO: Add something like ServiceManager.NotifyStartup ("InterfaceActionService", Initialize);
             
             if (ServiceManager.Contains ("InterfaceActionService")) {
-                Initialize ();
+                BuildNotificationArea ();
             } else {
                 ServiceManager.ServiceStarted += delegate (ServiceStartedArgs args) {
                    if (args.Service is Banshee.Gui.InterfaceActionService) {
-                       Initialize ();
+                       BuildNotificationArea ();
                    }
                 };
             }
         }
         
-        private void Initialize ()
-        {
-            BuildNotificationArea ();
-        }
-        
         private void BuildNotificationArea () 
         {
             notif_area = new NotificationAreaIcon (Catalog.GetString ("Banshee"));

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	Fri Feb  1 01:08:15 2008
@@ -73,7 +73,7 @@
             InterfaceActionService uia_service = ServiceManager.Get<InterfaceActionService> ();
             uia_service.TrackActions.Add (new ActionEntry [] {
                 new ActionEntry ("AddToPlayQueueAction", Stock.Add,
-                    Catalog.GetString ("Add to Play Queue"), null,
+                    Catalog.GetString ("Add to Play Queue"), "q",
                     Catalog.GetString ("Append selected songs to the play queue"),
                     OnAddToPlayQueue)
             });



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