From cf9b03167ed12086acbd74b97404b082f8e018a8 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 31 Jan 2011 13:14:47 -0600 Subject: players in menu now dynamically controllable from new dbus api --- src/mpris2-watcher.vala | 2 +- src/music-player-bridge.vala | 11 ++++++ src/player-controller.vala | 10 +++--- src/sound-service-dbus.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ src/sound-service.c | 4 +-- src/sound-service.xml | 5 +-- 6 files changed, 107 insertions(+), 10 deletions(-) (limited to 'src') 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..d24eaa0 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -119,10 +119,10 @@ 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); } } @@ -180,7 +180,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 +188,7 @@ public class PlayerController : GLib.Object } } } - + private void determine_state() { if(this.mpris_bridge.connected() == true){ diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index a532c0e..0fc2f50 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,93 @@ 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 = 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_get (the_black_list, "as", &iter); + builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + + while (g_variant_iter_loop (iter, "s", &str)){ + g_variant_builder_add (builder, "s", str); + } + + g_variant_get (the_black_list, "as", &iter); + + 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"); + return result; + } + } + // Otherwise blacklist it ! + g_debug ("about to blacklist %s", player_name); + g_variant_builder_add (builder, "s", player_name); + } + else{ + //g_variant_builder_clear (builder); + gboolean present = FALSE; + g_variant_get (the_black_list, "as", &iter); + + 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) + return result; + + // Otherwise free the builder and reconstruct ensuring no duplicates. + g_variant_builder_unref (builder); + builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + + g_variant_get (the_black_list, "as", &iter); + 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_new ("as", builder); + g_variant_builder_unref (builder); + g_variant_iter_free (iter); + result = g_settings_set_value (our_settings, + "blacklisted-media-players", + value); + g_variant_unref (value); + return result; +} diff --git a/src/sound-service.c b/src/sound-service.c index 2cb33d3..c1bb9b4 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } 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 @@ - + + - + -- cgit v1.2.3