Code review comment for lp:~alexlauni/do-plugins/bansheeplugin

Revision history for this message
Alex Launi (alexlauni) wrote :

Alex Launi proposed lp:~alexlauni/do-plugins/bansheeplugin for merging into lp:do-plugins

The full version of the banshee plugin complete with collection indexing, and playback control. STD free and ready for action.

=== modified file 'Banshee/Resources/Banshee.addin.xml'
--- a/Banshee/Resources/Banshee.addin.xml 2009-03-02 19:58:39 +0000
+++ b/Banshee/Resources/Banshee.addin.xml 2009-03-13 21:55:50 +0000
@@ -1,16 +1,21 @@
 <Addin
  id="Banshee"
  namespace= "Do"
+<<<<<<< TREE
  version="0.9"
  name="Banshee (beta)"
  description="Search your music library and control playback."
+=======
+ version="1.0"
+ name="Banshee Media Player"
+ description="Search your media collection and control playback."
+>>>>>>> MERGE-SOURCE
  author="Alex Launi"
  category="Official"
 >

  <Runtime>
   <Import assembly="Banshee.dll"/>
- <Import assembly="Banshee.CollectionIndexer.dll"/>
  </Runtime>

  <Dependencies>
@@ -18,6 +23,10 @@
  </Dependencies>

  <!-- Extensions included in this assembly -->
+ <!-- Itemsources -->
+ <Extension path = "/Do/ItemSource">
+ <ItemSource type = "Banshee.MediaItemSource" />
+ </Extension>

  <!-- Actions -->
  <Extension path = "/Do/Action">
@@ -25,5 +34,7 @@
   <Action type = "Banshee.PauseAction" />
   <Action type = "Banshee.NextAction" />
   <Action type = "Banshee.PreviousAction" />
+ <Action type = "Banshee.EnqueueAction" />
+ <Action type = "Banshee.SearchCollectionAction" />
  </Extension>
 </Addin>

=== modified file 'Banshee/src/Banshee.cs'
--- a/Banshee/src/Banshee.cs 2009-01-23 07:32:12 +0000
+++ b/Banshee/src/Banshee.cs 2009-03-13 21:55:50 +0000
@@ -53,10 +53,11 @@
   {
    if (index_mutex.ThreadState == ThreadState.Running)
     return;
- if (index_mutex.ThreadState == ThreadState.Unstarted)
+ else if (index_mutex.ThreadState == ThreadState.Unstarted)
     index_mutex.Start ();
- else
+ else {
     index_mutex = MakeIndexerThread ();
+ }
   }

   public static bool IsPlaying {

=== modified file 'Banshee/src/BansheeDBus.cs'
--- a/Banshee/src/BansheeDBus.cs 2009-01-22 04:17:45 +0000
+++ b/Banshee/src/BansheeDBus.cs 2009-03-13 21:55:50 +0000
@@ -20,6 +20,7 @@

 using System;
 using System.Linq;
+using System.Threading;
 using System.Collections.Generic;

 using NDesk.DBus;
@@ -45,6 +46,7 @@
  [Interface ("org.bansheeproject.Banshee.PlaybackController")]
  interface IBansheeController
  {
+ void First ();
   void Next (bool restart);
   void Previous (bool restart);
   int ShuffleMode { get; set; }
@@ -53,12 +55,14 @@
  public class BansheeDBus
  {
   const string BusName = "org.bansheeproject.Banshee";
+ const string SessionBusName = "org.freedesktop.DBus";
   const string ErrorMessage = "Banshee encountered an error in {0}; {1}";

   # region static Banshee d-bus members

   static Dictionary<Type, string> object_paths;

+ static IBus session_bus;
   static IBansheePlayer player;
   static IBansheePlayQueue play_queue;
   static IBansheeController controller;
@@ -66,18 +70,39 @@
   static BansheeDBus ()
   {
    BuildObjectPathsDict ();
- }
-
- static T GetIBansheeObject<T> (string object_path)
- {
- if (!Bus.Session.NameHasOwner (BusName)) {
- Bus.Session.StartServiceByName (BusName);
- System.Threading.Thread.Sleep (5000);
- if (!Bus.Session.NameHasOwner (BusName))
- throw new Exception (string.Format("Name {0} has no owner.", BusName));
- }
+ session_bus = Bus.Session.GetObject<IBus> (SessionBusName, new ObjectPath (object_paths[typeof (IBus)]));
+ session_bus.NameOwnerChanged += HandleNameOwnerChanged;
+ }
+
+ static void HandleNameOwnerChanged(string name, string old_owner, string new_owner)
+ {
+ // when the owner changes on this path, we release our dbus objects.
+ if (name == BusName) {
+ player = null;
+ controller = null;
+ play_queue = null;
+ }
+ }
+
+ static bool FullApplicationAvailable {
+ get { return Bus.Session.NameHasOwner (BusName); }
+ }
+
+ static void MaybeStartFullApplication ()
+ {
+ if (FullApplicationAvailable) return;

- return Bus.Session.GetObject<T> (BusName, new ObjectPath (object_path));
+ Bus.Session.StartServiceByName (BusName);
+ Thread.Sleep (5000);
+
+ if (!FullApplicationAvailable)
+ throw new Exception (string.Format("Name {0} has no owner.", BusName));
+ }
+
+ static T GetIBansheeObject<T> (string objectPath)
+ {
+ MaybeStartFullApplication ();
+ return Bus.Session.GetObject<T> (BusName, new ObjectPath (objectPath));
   }

   static IBansheePlayer Player {
@@ -115,9 +140,9 @@
   }

   public bool IsPlaying ()
- {
+ {
    try {
- return player != null && Player.CurrentState == "playing";
+ return (player != null || FullApplicationAvailable) && Player.CurrentState == "playing";
    } catch (Exception e) {
     LogError ("IsPlaying", e);
    }
@@ -135,13 +160,13 @@

   public void Play ()
   {
- Player.Play ();
+ First ();
   }

   public void Play (IEnumerable<IMediaFile> media)
   {
    Enqueue (media, true);
- Next ();
+ First ();
   }

   public void Enqueue (IEnumerable<IMediaFile> media)
@@ -152,8 +177,11 @@
   void Enqueue (IEnumerable<IMediaFile> media, bool prepend)
   {
    try {
+ MaybeStartFullApplication (); //if banshee isn't already started the enqueue seems to fail
+
     // if we're prepending to the queue we need to queue in the uris in reverse order
- if (prepend) media = media.Reverse ();
+ if (prepend)
+ media = media.Reverse ();

     media.ForEach (item => PlayQueue.EnqueueUri (item.Path, prepend));

@@ -161,7 +189,7 @@
     LogError ("Enqueue", e);
    }
   }
-
+
   public void Next ()
   {
    try {
@@ -180,9 +208,19 @@
    }
   }

+ void First ()
+ {
+ try {
+ Controller.First ();
+ } catch (Exception e) {
+ LogError ("First", e);
+ }
+ }
+
   static void BuildObjectPathsDict ()
   {
    object_paths = new Dictionary<Type, string> ();
+ object_paths.Add (typeof (IBus), "/org/freedesktop/DBus");
    object_paths.Add (typeof (IBansheePlayer), "/org/bansheeproject/Banshee/PlayerEngine");
    object_paths.Add (typeof (IBansheeController), "/org/bansheeproject/Banshee/PlaybackController");
    object_paths.Add (typeof (IBansheePlayQueue), "/org/bansheeproject/Banshee/SourceManager/PlayQueue");

=== modified file 'Banshee/src/PauseAction.cs'
--- a/Banshee/src/PauseAction.cs 2009-01-22 03:02:27 +0000
+++ b/Banshee/src/PauseAction.cs 2009-03-13 21:55:50 +0000
@@ -22,6 +22,7 @@

 using Mono.Unix;

+using Do.Platform;
 using Do.Universe;

 namespace Banshee

=== modified file 'Banshee/src/PlayAction.cs'
--- a/Banshee/src/PlayAction.cs 2009-01-22 01:04:35 +0000
+++ b/Banshee/src/PlayAction.cs 2009-03-13 21:55:50 +0000
@@ -63,11 +63,16 @@
   public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
   {
    if (items.First () is MediaItem)
- Banshee.Play (items.Cast<MediaItem> ().First ());
+ Banshee.Play (items.OfType<MediaItem> ().First ());
    else
     Banshee.Play ();

    yield break;
   }
+
+ protected override bool IsAvailable ()
+ {
+ return !Banshee.IsPlaying;
+ }
  }
 }
\ No newline at end of file

review: Approve

« Back to merge proposal