aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mpris2-watcher.vala2
-rw-r--r--src/music-player-bridge.vala11
-rw-r--r--src/player-controller.vala14
-rw-r--r--src/playlists-menu-item.vala2
-rw-r--r--src/settings-manager.vala23
-rw-r--r--src/sound-service-dbus.c94
-rw-r--r--src/sound-service.xml5
7 files changed, 140 insertions, 11 deletions
diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala
index c20b04b..0b37506 100644
--- a/src/mpris2-watcher.vala
+++ b/src/mpris2-watcher.vala
@@ -50,7 +50,7 @@ public class Mpris2Watcher : GLib.Object
// At startup check to see if there are clients up that we are interested in
// More relevant for development and daemon's like mpd.
- private async void check_for_active_clients()
+ public async void check_for_active_clients()
{
string[] interfaces;
try{
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index c167e08..c6c9913 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -41,6 +41,17 @@ public class MusicPlayerBridge : GLib.Object
private void on_blacklist_update ( string[] blacklist )
{
debug("some blacklist update");
+
+ foreach(var s in blacklist){
+ string key = this.determine_key (s);
+ if (this.registered_clients.has_key (key)){
+ debug ("Apparently %s is now blacklisted - remove thy self", key);
+ this.registered_clients[key].remove_from_menu();
+ this.registered_clients.unset (key);
+ }
+ }
+ // double check present players to ensure dynamic removal/addition
+ this.watcher.check_for_active_clients.begin();
}
private void try_to_add_inactive_familiar_clients()
diff --git a/src/player-controller.vala b/src/player-controller.vala
index 024b88b..3ce121e 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -119,10 +119,14 @@ public class PlayerController : GLib.Object
this.determine_state();
}
- public void vanish()
+ public void remove_from_menu()
{
- foreach(Dbusmenu.Menuitem item in this.custom_items){
- root_menu.child_delete(item);
+ foreach(PlayerItem item in this.custom_items){
+ this.root_menu.child_delete(item);
+ }
+ if (this.use_playlists == true){
+ PlaylistsMenuitem playlists_menuitem = this.custom_items[widget_order.PLAYLISTS] as PlaylistsMenuitem;
+ this.root_menu.child_delete (playlists_menuitem.root_item);
}
}
@@ -180,7 +184,7 @@ public class PlayerController : GLib.Object
foreach(PlayerItem item in this.custom_items){
if (this.custom_items.index_of(item) != 4) {
- root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item));
+ root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item));
}
else{
PlaylistsMenuitem playlists_menuitem = item as PlaylistsMenuitem;
@@ -188,7 +192,7 @@ public class PlayerController : GLib.Object
}
}
}
-
+
private void determine_state()
{
if(this.mpris_bridge.connected() == true){
diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala
index 024839c..b8c6e7d 100644
--- a/src/playlists-menu-item.vala
+++ b/src/playlists-menu-item.vala
@@ -50,7 +50,7 @@ public class PlaylistsMenuitem : PlayerItem
this.root_item.child_append( menuitem );
}
}
-
+
private bool already_observed (PlaylistDetails new_detail)
{
foreach ( PlaylistDetails detail in this.current_playlists.values ){
diff --git a/src/settings-manager.vala b/src/settings-manager.vala
index 380e442..057a47b 100644
--- a/src/settings-manager.vala
+++ b/src/settings-manager.vala
@@ -52,7 +52,7 @@ public class SettingsManager : GLib.Object
this.settings.reset("interested-media-players");
}
- public void add_interested(string app_desktop_name)
+ public void add_interested (string app_desktop_name)
{
var already_interested = this.settings.get_strv ("interested-media-players");
foreach (var s in already_interested){
@@ -67,5 +67,24 @@ public class SettingsManager : GLib.Object
private void on_blacklist_event()
{
this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players"));
- }
+ }
+
+ // Convenient debug method inorder to provide visability over
+ // the contents of both interested and blacklisted containers in its gsettings
+ private void reveal_contents()
+ {
+ var already_interested = this.settings.get_strv ("interested-media-players");
+ foreach (var s in already_interested)
+ {
+ debug ("client %s is in interested array", s);
+ }
+ var blacklisted = this.settings.get_strv ("blacklisted-media-players");
+ foreach (var s in blacklisted)
+ {
+ debug ("client %s is in blacklisted array", s);
+ }
+
+ debug ("interested array size = %i", already_interested.length);
+ debug ("blacklisted array size = %i", blacklisted.length);
+ }
}
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index a532c0e..7f5afdc 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -85,6 +85,10 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self,
gboolean availability,
gboolean mute,
gdouble volume);
+static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self,
+ gchar* player_name,
+ gboolean blacklist);
+
G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT);
@@ -400,12 +404,102 @@ bus_method_call (GDBusConnection * connection,
g_debug("Get state - %i", priv->current_sound_state );
retval = g_variant_new ( "(i)", priv->current_sound_state);
}
+ else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) {
+ gboolean blacklist;
+ gchar* player_name;
+ g_variant_get (params, "(sb)", &player_name, &blacklist);
+
+ g_debug ("BlacklistMediaPlayer - bool %i", blacklist);
+ g_debug ("BlacklistMediaPlayer - name %s", player_name);
+ gboolean result = sound_service_dbus_blacklist_player (service,
+ player_name,
+ blacklist);
+ retval = g_variant_new ("(b)", result);
+ }
else {
g_warning("Calling method '%s' on the sound service but it's unknown", method);
}
g_dbus_method_invocation_return_value (invocation, retval);
}
+static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self,
+ gchar* player_name,
+ gboolean blacklist)
+{
+ gboolean result = FALSE;
+ GSettings* our_settings = NULL;
+ our_settings = g_settings_new ("com.canonical.indicators.sound");
+ GVariant* the_black_list = g_settings_get_value (our_settings,
+ "blacklisted-media-players");
+ GVariantIter iter;
+ gchar *str;
+ // Firstly prep new array which will be set on the key.
+ GVariantBuilder builder;
+
+ g_variant_iter_init (&iter, the_black_list);
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY);
+
+ while (g_variant_iter_loop (&iter, "s", &str)){
+ g_variant_builder_add (&builder, "s", str);
+ }
+ g_variant_iter_init (&iter, the_black_list);
+
+ if (blacklist == TRUE){
+ while (g_variant_iter_loop (&iter, "s", &str)){
+ g_print ("first pass to check if %s is present\n", str);
+ if (g_strcmp0 (player_name, str) == 0){
+ // Return if its already there
+ g_debug ("we have this already blacklisted, no need to do anything");
+ g_variant_builder_clear (&builder);
+ g_object_unref (our_settings);
+ g_object_unref (the_black_list);
+ return result;
+ }
+ }
+ // Otherwise blacklist it !
+ g_debug ("about to blacklist %s", player_name);
+ g_variant_builder_add (&builder, "s", player_name);
+ }
+ else{
+ gboolean present = FALSE;
+ g_variant_iter_init (&iter, the_black_list);
+ g_debug ("attempting to UN-blacklist %s", player_name);
+
+ while (g_variant_iter_loop (&iter, "s", &str)){
+ if (g_strcmp0 (player_name, str) == 0){
+ present = TRUE;
+ }
+ }
+ // It was not there anyway, return false
+ if (present == FALSE){
+ g_debug ("it was not blacklisted ?, no need to do anything");
+ g_variant_builder_clear (&builder);
+ g_object_unref (our_settings);
+ g_object_unref (the_black_list);
+ return result;
+ }
+
+ // Otherwise free the builder and reconstruct ensuring no duplicates.
+ g_variant_builder_clear (&builder);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
+
+ g_variant_iter_init (&iter, the_black_list);
+
+ while (g_variant_iter_loop (&iter, "s", &str)){
+ if (g_strcmp0 (player_name, str) != 0){
+ g_variant_builder_add (&builder, "s", str);
+ }
+ }
+ }
+ GVariant* value = g_variant_builder_end (&builder);
+ result = g_settings_set_value (our_settings,
+ "blacklisted-media-players",
+ value);
+ g_object_unref (our_settings);
+ g_object_unref (the_black_list);
+
+ return result;
+}
diff --git a/src/sound-service.xml b/src/sound-service.xml
index 18e47fc..81ebc2d 100644
--- a/src/sound-service.xml
+++ b/src/sound-service.xml
@@ -2,12 +2,13 @@
<node name="/com/canonical/indicators/sound">
<interface name="com.canonical.indicators.sound">
<method name = "BlacklistMediaPlayer">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_blacklist_media_player"/>
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type='s' name='player_desktop_name' direction="in"/>
<arg type='b' name='blacklist' direction="in"/>
+ <arg type='b' name='result' direction="out"/>
</method>
<method name = "GetSoundState">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_state"/>
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type='i' name='current_state' direction="out"/>
</method>
<signal name="SoundStateUpdate">