banshee r4001 - in trunk/banshee: . build src/Clients src/Clients/Halie src/Clients/Halie/Halie src/Clients/Nereid src/Clients/Nereid/Nereid src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.PlaybackController src/Core/Banshee.Services/Banshee.ServiceStack src/Extensions src/Libraries/Hyena/Hyena.CommandLine



Author: abock
Date: Wed May 28 17:27:30 2008
New Revision: 4001
URL: http://svn.gnome.org/viewvc/banshee?rev=4001&view=rev

Log:
2008-05-28  Aaron Bockover  <abock gnome org>

    * src/Clients/Halie/Halie/Client.cs: A new Banshee client that runs only
    only the console and proxies command line arguments into DBus calls to
    communicate with and control an already running Banshee client

    * src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs: Moved
    the connection logic out of the service since it needs to be used before
    any services start at the client level for single instance reasons

    * src/Core/Banshee.Services/Banshee.ServiceStack/DBusServiceManager.cs:
    Cleaned up, use DBusConnection

    * src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs:
    * src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackController.cs:
    * src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerService.cs:
    Worked around stupid issues in NDesk dbus so the controller actually works
    as a remote object now

    * src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs: Added
    an Arguments property and added internal logic to keep sort order preserved
    on the arguments so they can be iterated over in proper order



Added:
   trunk/banshee/src/Clients/Halie/
   trunk/banshee/src/Clients/Halie/Halie/
   trunk/banshee/src/Clients/Halie/Halie.mdp
   trunk/banshee/src/Clients/Halie/Halie/Client.cs
   trunk/banshee/src/Clients/Halie/Makefile.am
   trunk/banshee/src/Clients/banshee-1.in   (props changed)
      - copied unchanged from r3998, /trunk/banshee/src/Clients/Nereid/banshee-1.in
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerService.cs   (contents, props changed)
      - copied, changed from r3998, /trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerExportable.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
Removed:
   trunk/banshee/src/Clients/Nereid/banshee-1.in
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerExportable.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/build/build.environment.mk
   trunk/banshee/configure.ac
   trunk/banshee/src/Clients/Clients.mds
   trunk/banshee/src/Clients/Makefile.am
   trunk/banshee/src/Clients/Nereid/Makefile.am
   trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackController.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusServiceManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Extensions/Makefile.am
   trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs

Modified: trunk/banshee/build/build.environment.mk
==============================================================================
--- trunk/banshee/build/build.environment.mk	(original)
+++ trunk/banshee/build/build.environment.mk	Wed May 28 17:27:30 2008
@@ -90,8 +90,7 @@
 	$(LINK_BANSHEE_THICKCLIENT)
 
 REF_NEREID = $(LINK_BANSHEE_THICKCLIENT_DEPS)
-LINK_NEREID = -r:$(DIR_BIN)/Nereid.exe
-LINK_NEREID_DEPS = $(REF_NEREID) $(LINK_NEREID)
+REF_HALIE = $(LINK_BANSHEE_SERVICES_DEPS)
 
 # Dap
 REF_DAP = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_BANSHEE_THICKCLIENT_DEPS)

Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac	(original)
+++ trunk/banshee/configure.ac	Wed May 28 17:27:30 2008
@@ -122,8 +122,9 @@
 src/AssemblyInfo.cs
 
 src/Clients/Makefile
+src/Clients/banshee-1
+src/Clients/Halie/Makefile
 src/Clients/Nereid/Makefile
-src/Clients/Nereid/banshee-1
 
 src/Core/Makefile
 src/Core/Banshee.Core/Makefile

Modified: trunk/banshee/src/Clients/Clients.mds
==============================================================================
--- trunk/banshee/src/Clients/Clients.mds	(original)
+++ trunk/banshee/src/Clients/Clients.mds	Wed May 28 17:27:30 2008
@@ -2,12 +2,15 @@
   <Configurations active="Debug">
     <Configuration name="Debug" ctype="CombineConfiguration">
       <Entry build="True" name="Nereid" configuration="Debug" />
+      <Entry build="True" name="Halie" configuration="Debug" />
     </Configuration>
   </Configurations>
   <StartMode startupentry="Nereid" single="True">
     <Execute type="None" entry="Nereid" />
+    <Execute type="None" entry="Halie" />
   </StartMode>
   <Entries>
     <Entry filename="Nereid/Nereid.mdp" />
+    <Entry filename="Halie/Halie.mdp" />
   </Entries>
 </Combine>
\ No newline at end of file

Added: trunk/banshee/src/Clients/Halie/Halie.mdp
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Clients/Halie/Halie.mdp	Wed May 28 17:27:30 2008
@@ -0,0 +1,28 @@
+<Project name="Halie" fileversion="2.0" language="C#" clr-version="Net_2_0" UseParentDirectoryAsNamespace="True" ctype="DotNetProject">
+  <Configurations active="Debug">
+    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+      <Output directory="../../../bin" assemblyKeyFile="." assembly="Halie" />
+      <Build debugmode="True" target="Exe" />
+      <Execution runwithwarnings="True" externalconsole="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" generatexmldocumentation="False" win32Icon="." ctype="CSharpCompilerParameters" />
+    </Configuration>
+  </Configurations>
+  <Contents>
+    <File name="Halie/Client.cs" subtype="Code" buildaction="Compile" />
+  </Contents>
+  <References>
+    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+    <ProjectReference type="Project" localcopy="False" refto="Banshee.Services" />
+    <ProjectReference type="Project" localcopy="False" refto="Banshee.Core" />
+    <ProjectReference type="Project" localcopy="False" refto="Hyena" />
+  </References>
+  <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am" ExecuteTargetName="run">
+    <BuildFilesVar Sync="True" Name="SOURCES" />
+    <DeployFilesVar />
+    <ResourcesVar />
+    <OthersVar />
+    <GacRefVar />
+    <AsmRefVar />
+    <ProjectRefVar />
+  </MonoDevelop.Autotools.MakefileInfo>
+</Project>
\ No newline at end of file

Added: trunk/banshee/src/Clients/Halie/Halie/Client.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Clients/Halie/Halie/Client.cs	Wed May 28 17:27:30 2008
@@ -0,0 +1,111 @@
+//
+// Client.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;
+using System.Collections.Generic;
+
+using Hyena;
+using Banshee.Base;
+using Banshee.ServiceStack;
+using Banshee.MediaEngine;
+using Banshee.PlaybackController;
+
+namespace Halie
+{
+    public static class Client
+    {
+        public static void Main ()
+        {
+            if (!DBusConnection.ConnectTried) {
+                DBusConnection.Connect ();
+            }
+            
+            if (!DBusConnection.Enabled) {
+                Error ("All commands ignored, DBus support is disabled");
+                return;
+            } else if (!DBusConnection.InstanceAlreadyRunning) {
+                Error ("Banshee does not seem to be running");
+                return;
+            }
+            
+            HandlePlayerCommands ();
+        }
+        
+        private static void HandlePlayerCommands ()
+        {
+            IPlayerEngineService player = DBusServiceManager.FindInstance<IPlayerEngineService> ("/PlayerEngine");
+            IPlaybackControllerService controller = DBusServiceManager.FindInstance<IPlaybackControllerService> ("/PlaybackController");
+            
+            foreach (KeyValuePair<string, string> arg in ApplicationContext.CommandLine.Arguments) {
+                switch (arg.Key) {
+                    // For the player engine
+                    case "play":           player.Play ();          break;
+                    case "pause":          player.Pause ();         break;
+                    case "stop":           player.Close ();         break;
+                    case "toggle-playing": player.TogglePlaying (); break;
+                    
+                    // For the playback controller
+                    case "first":    controller.First ();                                    break;
+                    case "next":     controller.Next (ParseBool (arg.Value, "restart"));     break;
+                    case "previous": controller.Previous (ParseBool (arg.Value, "restart")); break;
+                    case "stop-when-finished": 
+                        controller.StopWhenFinished = !ParseBool (arg.Value);
+                        break;
+                }
+            }
+        }
+        
+        private static bool ParseBool (string value)
+        {
+            return ParseBool (value, "true", "yes");
+        }
+        
+        private static bool ParseBool (string value, params string [] trueValues)
+        {
+            if (String.IsNullOrEmpty (value)) {
+                return false;
+            }
+            
+            value = value.ToLower ();
+            
+            foreach (string trueValue in trueValues) {
+                if (value == trueValue) {
+                    return true;
+                }
+            }
+            
+            return false;
+        }
+        
+        private static void Error (string error, params object [] args)
+        {
+            Console.WriteLine ("Error: {0}", String.Format (error, args));
+        }
+    }
+}
+

Added: trunk/banshee/src/Clients/Halie/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Clients/Halie/Makefile.am	Wed May 28 17:27:30 2008
@@ -0,0 +1,7 @@
+ASSEMBLY = Halie
+TARGET = exe
+LINK = $(REF_HALIE)
+SOURCES = Halie/Client.cs 
+
+include $(top_srcdir)/build/build.mk
+

Modified: trunk/banshee/src/Clients/Makefile.am
==============================================================================
--- trunk/banshee/src/Clients/Makefile.am	(original)
+++ trunk/banshee/src/Clients/Makefile.am	Wed May 28 17:27:30 2008
@@ -1,5 +1,8 @@
 SUBDIRS = \
+	Halie \
 	Nereid
 
+bin_SCRIPTS = banshee-1
+
 MAINTAINERCLEANFILES = Makefile.in
 

Modified: trunk/banshee/src/Clients/Nereid/Makefile.am
==============================================================================
--- trunk/banshee/src/Clients/Nereid/Makefile.am	(original)
+++ trunk/banshee/src/Clients/Nereid/Makefile.am	Wed May 28 17:27:30 2008
@@ -6,11 +6,5 @@
 	Nereid/PlayerInterface.cs \
 	Nereid/ViewContainer.cs
 
-bin_SCRIPTS = banshee-1
-
 include $(top_srcdir)/build/build.mk
 
-run:
-	pushd $(top_srcdir)/src/Core; \
-	make run; \
-	popd

Modified: trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
==============================================================================
--- trunk/banshee/src/Clients/Nereid/Nereid/Client.cs	(original)
+++ trunk/banshee/src/Clients/Nereid/Nereid/Client.cs	Wed May 28 17:27:30 2008
@@ -4,7 +4,7 @@
 // Author:
 //   Aaron Bockover <abockover novell com>
 //
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -28,6 +28,11 @@
 
 using System;
 using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+
+using Banshee.Base;
+using Banshee.ServiceStack;
 
 namespace Nereid
 {
@@ -35,11 +40,21 @@
     {
         public static void Main ()
         {
+            // Check for single instance
+            DBusConnection.Connect ();
+            if (DBusConnection.InstanceAlreadyRunning) {
+                // Try running our friend Halie, the DBus command line client
+                AppDomain.CurrentDomain.ExecuteAssembly (Path.Combine (Path.GetDirectoryName (
+                    Assembly.GetEntryAssembly ().Location), "Halie.exe"));
+                return;
+            }
+                    
             Hyena.Log.InformationFormat ("Running Banshee {0}", Banshee.ServiceStack.Application.Version);
+            
             // This could go into GtkBaseClient, but it's probably something we
             // should really only support at each client level
-            string user_gtkrc = Path.Combine (Banshee.Base.Paths.ApplicationData, "gtkrc"); 
-            if (File.Exists (user_gtkrc) && !Banshee.Base.ApplicationContext.CommandLine.Contains ("no-gtkrc")) {
+            string user_gtkrc = Path.Combine (Paths.ApplicationData, "gtkrc"); 
+            if (File.Exists (user_gtkrc) && !ApplicationContext.CommandLine.Contains ("no-gtkrc")) {
                 Gtk.Rc.AddDefaultFile (user_gtkrc);
             } 
 
@@ -50,7 +65,7 @@
         protected override void OnRegisterServices ()
         {
             // Register the main interface
-            Banshee.ServiceStack.ServiceManager.RegisterService <PlayerInterface> ();
+            ServiceManager.RegisterService <PlayerInterface> ();
         }
         
         public override string ClientId {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackController.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackController.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackController.cs	Wed May 28 17:27:30 2008
@@ -28,12 +28,8 @@
 
 namespace Banshee.PlaybackController
 {
-    public delegate void PlaybackControllerStoppedHandler ();
-
     public interface IPlaybackController : IBasicPlaybackController
     {
-        event PlaybackControllerStoppedHandler Stopped;
-    
         PlaybackShuffleMode ShuffleMode { get; set; }
         PlaybackRepeatMode RepeatMode { get; set; }
         bool StopWhenFinished { get; set; }

Copied: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerService.cs (from r3998, /trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerExportable.cs)
==============================================================================
--- /trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerExportable.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/IPlaybackControllerService.cs	Wed May 28 17:27:30 2008
@@ -33,8 +33,24 @@
 
 namespace Banshee.PlaybackController
 {
+    public delegate void PlaybackControllerStoppedHandler ();
+    
     [Interface ("org.bansheeproject.Banshee.PlaybackController")]
-    public interface IPlaybackControllerExportable : IPlaybackController, IDBusExportable
+    public interface IPlaybackControllerService : IDBusExportable
     {
+        // FIXME: IPlaybackControllerExportable : IPlaybackController
+        // but NDesk DBus has a design flaw where it only exports 
+        // members of the top level interface where the [Interface] 
+        // attribute is applied
+        
+        event PlaybackControllerStoppedHandler Stopped;
+        
+        void First ();
+        void Next (bool restart);
+        void Previous (bool restart);
+        
+        PlaybackShuffleMode ShuffleMode { get; set; }
+        PlaybackRepeatMode RepeatMode { get; set; }
+        bool StopWhenFinished { get; set; }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	Wed May 28 17:27:30 2008
@@ -39,7 +39,8 @@
 
 namespace Banshee.PlaybackController
 {
-    public class PlaybackControllerService : IRequiredService, ICanonicalPlaybackController, IPlaybackControllerExportable
+    public class PlaybackControllerService : IRequiredService, ICanonicalPlaybackController, 
+        IPlaybackController, IPlaybackControllerService
     {
         private enum Direction
         {
@@ -66,7 +67,7 @@
         private ITrackModelSource next_source;
         
         private event PlaybackControllerStoppedHandler dbus_stopped;
-        event PlaybackControllerStoppedHandler IPlaybackController.Stopped {
+        event PlaybackControllerStoppedHandler IPlaybackControllerService.Stopped {
             add { dbus_stopped += value; }
             remove { dbus_stopped -= value; }
         }

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs	Wed May 28 17:27:30 2008
@@ -0,0 +1,88 @@
+//
+// DBusConnection.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;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+using Hyena;
+using Banshee.Base;
+
+namespace Banshee.ServiceStack
+{
+    public static class DBusConnection
+    {
+        public const string BusName = "org.bansheeproject.Banshee";
+        
+        private static bool enabled;
+        public static bool Enabled {
+            get { return enabled; }
+        }
+        
+        private static bool instance_already_running;
+        public static bool InstanceAlreadyRunning {
+            get { return instance_already_running; }
+        }
+        
+        private static bool connect_tried;
+        public static bool ConnectTried {
+            get { return connect_tried; }
+        }
+        
+        public static void Connect ()
+        {
+            connect_tried = true;
+            
+            enabled = !ApplicationContext.CommandLine.Contains ("disable-dbus");
+            if (!enabled) {
+                return;
+            }
+            
+            try {
+                instance_already_running = Connect (true) != RequestNameReply.PrimaryOwner;
+            } catch {
+                Log.Warning ("DBus support could not be started. Disabling for this session.");
+                enabled = false;
+            }
+        }
+        
+        public static RequestNameReply Connect (bool init)
+        {
+            connect_tried = true;
+            
+            if (init) {
+                BusG.Init ();
+            }
+            
+            RequestNameReply name_reply = Bus.Session.RequestName (BusName);
+            Log.DebugFormat ("NDesk.DBus.Bus.Session.RequestName ('{0}') => {1}", BusName, name_reply);
+            return name_reply;
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusServiceManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusServiceManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/DBusServiceManager.cs	Wed May 28 17:27:30 2008
@@ -4,7 +4,7 @@
 // Author:
 //   Aaron Bockover <abockover novell com>
 //
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -28,6 +28,7 @@
 
 using System;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Collections.Generic;
     
 using NDesk.DBus;
@@ -40,111 +41,87 @@
 {
     public class DBusServiceManager : IService
     {
-        public const string BusName = "org.bansheeproject.Banshee";
         public const string ObjectRoot = "/org/bansheeproject/Banshee";
-
-        private static bool dbus_enabled;
         
-        public DBusServiceManager()
+        public DBusServiceManager ()
         {
-            dbus_enabled = !Banshee.Base.ApplicationContext.CommandLine.Contains ("disable-dbus");
-            if (!dbus_enabled) {
-                return;
-            }
-            
-            try {
-                BusG.Init();
-            } catch {
-                Log.Warning ("DBus support could not be started. Disabling for this session.");
-                dbus_enabled = false;
-                return;
-            }
-            
-            try {
-                RequestNameReply name_reply = Bus.Session.RequestName(BusName);
-                Log.DebugFormat ("NDesk.DBus.Bus.Session.RequestName ('{0}') => {1}", BusName, name_reply);
-                // TODO: error handling based on nameReply. should probably throw if 
-                // nameReply is anything other than NameReply.PrimaryOwner
-            } catch(Exception e) {
-                throw e;
+            if (!DBusConnection.ConnectTried) {
+                DBusConnection.Connect ();
             }
         }
-
-        public static string MakeDBusSafeString(string str)
+        
+        public static string MakeDBusSafeString (string str)
         {
-            return System.Text.RegularExpressions.Regex.Replace(str, @"[^A-Za-z0-9]*", String.Empty);
+            return Regex.Replace (str, @"[^A-Za-z0-9]*", String.Empty);
         }
         
-        public static string MakeObjectPath(IDBusExportable o)
+        public static string MakeObjectPath (IDBusExportable o)
         {
-            StringBuilder object_path = new StringBuilder();
+            StringBuilder object_path = new StringBuilder ();
             
-            object_path.Append(ObjectRoot);
-            object_path.Append('/');
+            object_path.Append (ObjectRoot);
+            object_path.Append ('/');
             
-            Stack<string> paths = new Stack<string>();
+            Stack<string> paths = new Stack<string> ();
             
             IDBusExportable p = o.Parent;
             
-            while(p != null) {
-                paths.Push(String.Format("{0}/", p.ServiceName));
+            while (p != null) {
+                paths.Push (String.Format ("{0}/", p.ServiceName));
                 p = p.Parent;
             }
             
-            while(paths.Count > 0) {
-                object_path.Append(paths.Pop());
+            while (paths.Count > 0) {
+                object_path.Append (paths.Pop ());
             }
             
-            object_path.Append(o.ServiceName);
+            object_path.Append (o.ServiceName);
             
-            return object_path.ToString();
+            return object_path.ToString ();
         }
         
-        public static string [] MakeObjectPathArray<T>(IEnumerable<T> collection) where T : IDBusExportable
+        public static string [] MakeObjectPathArray<T> (IEnumerable<T> collection) where T : IDBusExportable
         {
-            List<string> paths = new List<string>();
+            List<string> paths = new List<string> ();
             
-            foreach(IDBusExportable item in collection) {
-                paths.Add(MakeObjectPath(item));
+            foreach (IDBusExportable item in collection) {
+                paths.Add (MakeObjectPath (item));
             }
             
-            return paths.ToArray();
+            return paths.ToArray ();
         }
         
-        public void RegisterObject(IDBusExportable o)
+        public void RegisterObject (IDBusExportable o)
         {
-            RegisterObject(o, MakeObjectPath(o));
+            RegisterObject (o, MakeObjectPath (o));
         }
         
-        public void RegisterObject(object o, string objectName)
+        public void RegisterObject (object o, string objectName)
         {
-            if(dbus_enabled && Bus.Session != null) {
-#pragma warning disable 0618
-                Bus.Session.Register(BusName, new ObjectPath(objectName), o);
-#pragma warning restore 0618
-                /*if (Banshee.Base.ApplicationContext.Debugging) {
-                    Banshee.Base.Log.DebugFormat ("Registered {0} on {1}", objectName, BusName);
-                }*/
+            if (DBusConnection.Enabled && Bus.Session != null) {
+                #pragma warning disable 0618
+                Bus.Session.Register (DBusConnection.BusName, new ObjectPath (objectName), o);
+                #pragma warning restore 0618
             }
         }
 
-        public void UnregisterObject(object o)
+        public void UnregisterObject (object o)
         {
             //TODO: unregistering objects with managed dbus
         }
         
-        public static T FindInstance<T>(string objectPath) where T : class
+        public static T FindInstance<T> (string objectPath) where T : class
         {
-            if(!dbus_enabled || !Bus.Session.NameHasOwner(BusName)) {
+            if (!DBusConnection.Enabled || !Bus.Session.NameHasOwner (DBusConnection.BusName)) {
                 return null;
             }
             
             string full_object_path = objectPath;
-            if(!objectPath.StartsWith(ObjectRoot)) {
+            if (!objectPath.StartsWith (ObjectRoot)) {
                 full_object_path = ObjectRoot + objectPath;
             }
 
-            return Bus.Session.GetObject<T>(BusName, new ObjectPath(full_object_path));
+            return Bus.Session.GetObject<T> (DBusConnection.BusName, new ObjectPath (full_object_path));
         }
         
         string IService.ServiceName {

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 May 28 17:27:30 2008
@@ -94,7 +94,7 @@
     <File name="Banshee.PlaybackController/PlaybackRepeatMode.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.PlaybackController/PlaybackControllerDatabaseStack.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.PlaybackController/PlaybackControllerService.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.PlaybackController/IPlaybackControllerExportable.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.PlaybackController/IPlaybackControllerService.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.PlaybackController/ICanonicalPlaybackController.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.PlaybackController/IBasicPlaybackController.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/IDurationAggregator.cs" subtype="Code" buildaction="Compile" />
@@ -169,6 +169,7 @@
     <File name="Banshee.Collection/FilterListModel.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Playlists.Formats/Tests/PlaylistFormatTests.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection/IFilterListModel.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.ServiceStack/DBusConnection.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -182,6 +183,8 @@
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.2.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
     <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Gac" localcopy="True" refto="TagLib, Version=0.0.0.0, Culture=neutral" />
+    <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
+    <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus.GLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
   </References>
   <Deployment.LinuxDeployData generateScript="False" />
   <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am">

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 May 28 17:27:30 2008
@@ -88,7 +88,7 @@
 	Banshee.PlaybackController/IBasicPlaybackController.cs \
 	Banshee.PlaybackController/ICanonicalPlaybackController.cs \
 	Banshee.PlaybackController/IPlaybackController.cs \
-	Banshee.PlaybackController/IPlaybackControllerExportable.cs \
+	Banshee.PlaybackController/IPlaybackControllerService.cs \
 	Banshee.PlaybackController/PlaybackControllerDatabaseStack.cs \
 	Banshee.PlaybackController/PlaybackControllerService.cs \
 	Banshee.PlaybackController/PlaybackRepeatMode.cs \
@@ -125,6 +125,7 @@
 	Banshee.ServiceStack/Application.cs \
 	Banshee.ServiceStack/BatchUserJob.cs \
 	Banshee.ServiceStack/Client.cs \
+	Banshee.ServiceStack/DBusConnection.cs \
 	Banshee.ServiceStack/DBusServiceManager.cs \
 	Banshee.ServiceStack/IDBusExportable.cs \
 	Banshee.ServiceStack/IDelayedInitializeService.cs \

Modified: trunk/banshee/src/Extensions/Makefile.am
==============================================================================
--- trunk/banshee/src/Extensions/Makefile.am	(original)
+++ trunk/banshee/src/Extensions/Makefile.am	Wed May 28 17:27:30 2008
@@ -2,7 +2,6 @@
 	Banshee.AudioCd \
 	Banshee.Bookmarks \
 	Banshee.BooScript \
-	Banshee.CoverArt \
 	Banshee.Daap \
 	Banshee.Lastfm \
 	Banshee.MiniMode \

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs	Wed May 28 17:27:30 2008
@@ -34,10 +34,25 @@
 {
     public class CommandLineParser
     {
+        private struct Argument
+        {
+            public int Order;
+            public string Value;
+            
+            public Argument (int order, string value)
+            {
+                Order = order;
+                Value = value;
+            }
+        }
+    
+        private int generation;
+        private int sorted_args_generation;
         private int offset;
         private string enqueue_arg;
         private string [] arguments;
-        private Dictionary<string, string> parsed_arguments = new Dictionary<string, string> ();
+        private KeyValuePair<string, Argument> [] sorted_args;
+        private Dictionary<string, Argument> parsed_arguments = new Dictionary<string, Argument> ();
         private List<string> file_list = new List<string> ();
         
         public CommandLineParser () : this (null, Environment.GetCommandLineArgs (), 1)
@@ -82,9 +97,9 @@
                 }
                  
                 if (parsed_arguments.ContainsKey (name)) {
-                    parsed_arguments[name] = value;
+                    parsed_arguments[name] = new Argument (i, value);
                 } else {
-                    parsed_arguments.Add (name, value);
+                    parsed_arguments.Add (name, new Argument (i, value));
                 }
             }
         }
@@ -105,8 +120,36 @@
         }
         
         public string this[string name] {
-            get { return Contains (name) ? parsed_arguments[name] : String.Empty; }
-            set { parsed_arguments[name] = value; }
+            get { return Contains (name) ? parsed_arguments[name].Value : String.Empty; }
+            set { 
+                Argument arg = parsed_arguments[name];
+                arg.Value = value;
+                parsed_arguments[name] = arg;
+                generation++;
+            }
+        }
+        
+        public IEnumerable<KeyValuePair<string, string>> Arguments {
+            get {
+                if (sorted_args == null || sorted_args_generation != generation) {                
+                    sorted_args = new KeyValuePair<string, Argument>[parsed_arguments.Count];
+                    int i = 0;
+                    
+                    foreach (KeyValuePair<string, Argument> arg in parsed_arguments) {
+                        sorted_args[i++] = arg;
+                    }
+                    
+                    Array.Sort (sorted_args, delegate (KeyValuePair<string, Argument> a, KeyValuePair<string, Argument> b) {
+                        return a.Value.Order.CompareTo (b.Value.Order);
+                    });
+                    
+                    sorted_args_generation = generation;
+                }
+                
+                foreach (KeyValuePair<string, Argument> arg in sorted_args) {
+                    yield return new KeyValuePair<string, string> (arg.Key, arg.Value.Value);
+                }
+            }
         }
 
         public ReadOnlyCollection<string> Files {
@@ -118,8 +161,8 @@
             System.Text.StringBuilder builder = new System.Text.StringBuilder ();
 
             builder.Append ("Parsed Arguments\n");
-            foreach (KeyValuePair<string, string> argument in parsed_arguments) {
-                builder.AppendFormat ("  {0} = [{1}]\n", argument.Key, argument.Value); 
+            foreach (KeyValuePair<string, Argument> argument in parsed_arguments) {
+                builder.AppendFormat ("  {0} = [{1}]\n", argument.Key, argument.Value.Value); 
             }
             
             builder.Append ("\nFile List\n");



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