[banshee] SoundMenu: Implement the new registration process
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] SoundMenu: Implement the new registration process
- Date: Sun, 30 Jan 2011 21:08:46 +0000 (UTC)
commit 586ec5ab1a7c1a48db5bccbb45acb9b94691d4bd
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date: Sun Jan 30 21:39:08 2011 +0100
SoundMenu: Implement the new registration process
The sound menu included in Ubuntu Natty (indicator-sound > 0.5.8)
now automatically detects MPRIS applications appearing on the bus. So we
don't have to register explicitly anymore.
Unregistering is done by adding ourselves in a black-list of players
which won't appear in the sound menu. This should be done through
GSettings, but indicator-sound kindly provides us with a d-bus method
for that.
This means that the build dependency on indicate-sharp is now optional
and can be substituted by a runtime dependency on indicator-sound >
0.5.8.
For compatibility with Ubuntu Maverick, we still do the explicit
registration with indicate-sharp. This will just be ignored by
indicator-sound provided on Natty.
This is all hidden away in a new SoundMenuProxy class, to keep things
reasonably sane.
build/m4/banshee/soundmenu.m4 | 4 +-
configure.ac | 2 +-
.../Banshee.SoundMenu/Banshee.SoundMenu.csproj | 3 +-
.../Banshee.SoundMenu/SoundMenuProxy.cs | 112 ++++++++++++++++++++
.../Banshee.SoundMenu/SoundMenuService.cs | 28 +----
src/Extensions/Banshee.SoundMenu/Makefile.am | 8 ++-
6 files changed, 128 insertions(+), 29 deletions(-)
---
diff --git a/build/m4/banshee/soundmenu.m4 b/build/m4/banshee/soundmenu.m4
index afcd33e..9522feb 100644
--- a/build/m4/banshee/soundmenu.m4
+++ b/build/m4/banshee/soundmenu.m4
@@ -12,11 +12,9 @@ AC_DEFUN([BANSHEE_CHECK_SOUNDMENU],
PKG_CHECK_MODULES(INDICATESHARP,
indicate-sharp-0.1 >= $LIBINDICATESHARP_REQUIRED,
has_indicatesharp=yes, has_indicatesharp=no)
- if test "x$has_indicatesharp" = "xno"; then
- AC_MSG_ERROR([indicate-sharp was not found or is not up to date. Please install indicate-sharp of at least version $LIBINDICATESHARP_REQUIRED, or disable sound menu support by passing --disable-soundmenu])
- fi
fi
+ AM_CONDITIONAL(HAVE_INDICATESHARP, test "x$has_indicatesharp" = "xyes")
AM_CONDITIONAL(ENABLE_SOUNDMENU, test "x$enable_soundmenu" = "xyes")
])
diff --git a/configure.ac b/configure.ac
index 55d502d..40e724a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -425,7 +425,7 @@ ${PACKAGE}-${VERSION}
Podcasts: ${enable_podcast}
Gapless playback: ${ENABLE_GAPLESS} (gstreamer-plugins-base > 0.10.25.2)
YouTube extension: ${enable_youtube} (gdata-sharp >= 1.4)
- Sound menu: ${enable_soundmenu} (indicate-sharp >= 0.4.1)
+ Sound menu: ${enable_soundmenu}
Ubuntu One Store: ${enable_ubuntuone} (ubuntuone-sharp)
Build/Development:
diff --git a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu.csproj b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu.csproj
index 5e0dc85..f8c1ec1 100644
--- a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu.csproj
+++ b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu.csproj
@@ -42,8 +42,6 @@
</Reference>
<Reference Include="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756">
</Reference>
- <Reference Include="indicate-sharp, Version=0.4.1.0, Culture=neutral, PublicKeyToken=2e8e49ba7d172cb0">
- </Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Banshee.SoundMenu.addin.xml">
@@ -52,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Banshee.SoundMenu\SoundMenuService.cs" />
+ <Compile Include="Banshee.SoundMenu\SoundMenuProxy.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
diff --git a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuProxy.cs b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuProxy.cs
new file mode 100644
index 0000000..8d2ae96
--- /dev/null
+++ b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuProxy.cs
@@ -0,0 +1,112 @@
+//
+// SoundMenu.cs
+//
+// Author:
+// Bertrand Lorentz <bertrand lorentz gmail com>
+//
+// Copyright 2011 Bertrand Lorentz
+//
+// 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 Hyena;
+
+namespace Banshee.SoundMenu
+{
+ public class SoundMenuProxy
+ {
+ private const string DBusInterface = "com.canonical.indicators.sound";
+ private const string DBusPath = "/com/canonical/indicators/sound/service";
+ private const string desktop_name = "banshee-1";
+
+ private delegate void SoundStateUpdateHandler (int new_state);
+
+ private ISoundMenu sound_menu;
+
+ [Interface("com.canonical.indicators.sound")]
+ private interface ISoundMenu
+ {
+ void BlacklistMediaPlayer (string player_desktop_name, bool blacklist);
+ int GetSoundState ();
+ event SoundStateUpdateHandler SoundStateUpdate;
+ }
+
+ public SoundMenuProxy ()
+ {
+ }
+
+ private ISoundMenu SoundMenu {
+ get {
+ if (sound_menu == null) {
+ if (!Bus.Session.NameHasOwner (DBusInterface)) {
+ return null;
+ }
+
+ sound_menu = Bus.Session.GetObject<ISoundMenu> (DBusInterface, new ObjectPath (DBusPath));
+
+ if (sound_menu == null) {
+ Log.WarningFormat ("The {0} object could not be located on the DBus interface {1}",
+ DBusPath, DBusInterface);
+ }
+ }
+ return sound_menu;
+ }
+ }
+
+
+ public void Register ()
+ {
+ Log.Debug ("Registering with sound indicator");
+#if HAVE_INDICATESHARP
+ var server = Indicate.Server.RefDefault ();
+ server.SetType ("music.banshee");
+ string desktop_file = Paths.Combine (Paths.InstalledApplicationDataRoot,
+ "applications", desktop_name + ".desktop");
+ server.DesktopFile (desktop_file);
+ server.Show ();
+#endif
+ if (SoundMenu != null) {
+ try {
+ SoundMenu.BlacklistMediaPlayer (desktop_name, false);
+ } catch (Exception e) {
+ Log.Exception (e);
+ }
+ }
+ }
+
+ public void Unregister ()
+ {
+#if HAVE_INDICATESHARP
+ var server = Indicate.Server.RefDefault ();
+ server.Hide ();
+#endif
+ if (SoundMenu != null) {
+ try {
+ SoundMenu.BlacklistMediaPlayer (desktop_name, true);
+ } catch (Exception e) {
+ Log.Exception (e);
+ }
+ }
+ }
+ }
+}
+
diff --git a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
index 113e6c7..00ea129 100644
--- a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
+++ b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
@@ -44,8 +44,6 @@ using Banshee.MediaEngine;
using Banshee.ServiceStack;
using Banshee.Preferences;
-using Indicate;
-
namespace Banshee.SoundMenu
{
public class SoundMenuService : IExtensionService
@@ -58,8 +56,8 @@ namespace Banshee.SoundMenu
private InterfaceActionService interface_action_service;
private string notify_last_artist;
private string notify_last_title;
- private Server server;
private uint ui_manager_id;
+ private SoundMenuProxy sound_menu;
private const int icon_size = 42;
@@ -126,9 +124,9 @@ namespace Banshee.SoundMenu
interface_action_service.GlobalActions.UpdateAction ("QuitAction", false);
InstallPreferences ();
- server = Server.RefDefault ();
+ sound_menu = new SoundMenuProxy ();
if (Enabled) {
- Register ();
+ sound_menu.Register ();
}
ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent,
@@ -170,6 +168,7 @@ namespace Banshee.SoundMenu
AddinManager.AddinLoaded -= OnAddinLoaded;
+ sound_menu = null;
elements_service = null;
interface_action_service = null;
}
@@ -182,20 +181,6 @@ namespace Banshee.SoundMenu
}
}
- public void Register ()
- {
- Log.Debug ("Registering with sound indicator");
- server.SetType ("music.banshee");
- string desktop_file = Paths.Combine (Paths.InstalledApplicationDataRoot,
- "applications", "banshee-1.desktop");
- server.DesktopFile (desktop_file);
- server.Show ();
- }
-
- public void Unregister ()
- {
- server.Hide ();
- }
#region Notifications
private bool ActionsSupported {
@@ -393,12 +378,11 @@ namespace Banshee.SoundMenu
public bool Enabled {
get { return EnabledSchema.Get (); }
set {
- EnabledSchema.Set (value);
if (value) {
- Register ();
+ sound_menu.Register ();
RegisterCloseHandler ();
} else {
- Unregister ();
+ sound_menu.Unregister ();
UnregisterCloseHandler ();
}
}
diff --git a/src/Extensions/Banshee.SoundMenu/Makefile.am b/src/Extensions/Banshee.SoundMenu/Makefile.am
index 2ec47d4..cbe504c 100644
--- a/src/Extensions/Banshee.SoundMenu/Makefile.am
+++ b/src/Extensions/Banshee.SoundMenu/Makefile.am
@@ -5,12 +5,18 @@ GMCS_FLAGS+="-define:INTERNAL_NOTIFY_SHARP"
NOTIFY_SHARP_LIBS =
endif
+if HAVE_INDICATESHARP
+GMCS_FLAGS+= "-define:HAVE_INDICATESHARP"
+endif
+
ASSEMBLY = Banshee.SoundMenu
TARGET = library
LINK = $(REF_EXTENSION_SOUNDMENU) $(NOTIFY_SHARP_LIBS)
INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
-SOURCES = Banshee.SoundMenu/SoundMenuService.cs
+SOURCES = \
+ Banshee.SoundMenu/SoundMenuProxy.cs \
+ Banshee.SoundMenu/SoundMenuService.cs
RESOURCES = Banshee.SoundMenu.addin.xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]