[banshee/moblin: 1/11] Add helper to export command-line arguments again.



commit 1f1bf56879318c9c6133b8aa266fec115bb2c8f7
Author: Michael Meeks <michael meeks novell com>
Date:   Thu Aug 6 18:09:49 2009 +0100

    Add helper to export command-line arguments again.
    Add code to update ~/.recently-used.xbel with tracks played

 .../Banshee.GnomeBackend/GnomeService.cs           |   38 +++++++++++++++++++-
 .../Hyena/Hyena.CommandLine/CommandLineParser.cs   |   13 +++++++
 2 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
index 8c8cd43..9d3db52 100644
--- a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
+++ b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
@@ -28,8 +28,11 @@
 
 using System;
 
-using Banshee.ServiceStack;
 using Banshee.Web;
+using Banshee.Base;
+using Banshee.Collection;
+using Banshee.MediaEngine;
+using Banshee.ServiceStack;
 
 namespace Banshee.GnomeBackend
 {
@@ -56,10 +59,16 @@ namespace Banshee.GnomeBackend
             if (Browser.OpenHandler == null) {
                 Browser.OpenHandler = OpenUrl;
             }
+
+            ServiceManager.PlayerEngine.ConnectEvent
+	        (UpdateRecentFilesHandler, PlayerEvent.StateChange);
         }
         
         public void Dispose ()
         {
+            ServiceManager.PlayerEngine.DisconnectEvent
+	        (UpdateRecentFilesHandler);
+
             if (brasero != null) {
                 brasero.Dispose ();
                 brasero = null;
@@ -79,5 +88,32 @@ namespace Banshee.GnomeBackend
         string IService.ServiceName {
             get { return "GnomeService"; }
         }
+
+	private void UpdateRecentFilesHandler (PlayerEventArgs args)
+	{
+	    if (!(args is PlayerEventStateChangeArgs) ||
+		(args as PlayerEventStateChangeArgs).Current != PlayerState.Playing)
+	        return;
+	    TrackInfo t = ServiceManager.PlayerEngine.CurrentTrack;
+	    if (t == null)
+	        return;
+	    var data = new Gtk.RecentData();
+
+	    // We can surely improve this to make it prettier
+	    data.DisplayName = t.TrackTitle;
+	    data.Description = t.AlbumArtist;
+	    
+	    // Make mutter-moblin's mime handling happier
+	    data.MimeType = t.MimeType;
+	    if (data.MimeType == "application/ogg")
+	        data.MimeType = "audio/ogg";
+	      
+	    data.AppName = "Banshee";
+	    data.AppExec = "banshee-1 " + ApplicationContext.CommandLine.GetOptions() + " --play-enqueued %U";
+//	    data.Groups = "Media"; - set this to add a crasher bug via a broken gtk-sharp binding.
+	    data.IsPrivate = false;
+	    
+	    Gtk.RecentManager.Default.AddFull (t.Uri.AbsoluteUri, data);
+	}
     }
 }
diff --git a/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs b/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
index 91325d2..5c24e5a 100644
--- a/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
+++ b/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
@@ -152,6 +152,19 @@ namespace Hyena.CommandLine
         public ReadOnlyCollection<string> Files {
             get { return new ReadOnlyCollection<string> (file_list); }
         }
+
+	public string GetOptions ()
+	{
+            System.Text.StringBuilder builder = new System.Text.StringBuilder ();
+
+            foreach (KeyValuePair<string, Argument> argument in parsed_arguments) {
+	        builder.AppendFormat (" --{0}", argument.Key);
+		if (argument.Value.Value != String.Empty)
+		    builder.AppendFormat ("={0}", argument.Value.Value);
+            }
+
+            return builder.ToString ();
+	}
             
         public override string ToString ()
         {



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