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/sound-service-dbus.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'src/sound-service-dbus.c') 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; +} -- cgit v1.2.3 From 6da3712d5eda504073689da98eccba020d57a5cd Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 31 Jan 2011 15:26:06 -0600 Subject: blacklist / interested players work done --- src/sound-service-dbus.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 0fc2f50..f29fab4 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -458,7 +458,6 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, 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); -- cgit v1.2.3 From 43b7e22a13692edbba02c987975747a069881814 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 31 Jan 2011 19:33:46 -0600 Subject: moved builder and iter to the stack in blacklist method --- src/sound-service-dbus.c | 61 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index f29fab4..9ae0fd7 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -427,68 +427,77 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, gboolean blacklist) { gboolean result = FALSE; - GSettings* our_settings = g_settings_new ("com.canonical.indicators.sound"); + 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; + 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")); + 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); + while (g_variant_iter_loop (&iter, "s", &str)){ + g_variant_builder_add (&builder, "s", str); } - - g_variant_get (the_black_list, "as", &iter); + g_variant_iter_init (&iter, the_black_list); if (blacklist == TRUE){ - while (g_variant_iter_loop (iter, "s", &str)){ + 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"); + g_debug ("we have this already blacklisted, no need to do anything"); + g_variant_builder_end (&builder); + g_object_unref (our_settings); return result; } } // Otherwise blacklist it ! g_debug ("about to blacklist %s", player_name); - g_variant_builder_add (builder, "s", player_name); + g_variant_builder_add (&builder, "s", player_name); } else{ gboolean present = FALSE; - g_variant_get (the_black_list, "as", &iter); - - while (g_variant_iter_loop (iter, "s", &str)){ + 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) + if (present == FALSE){ + g_debug ("it was not blacklisted ?, no need to do anything"); + g_variant_builder_end (&builder); + g_object_unref (our_settings); 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_builder_end (&builder); + g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY); - g_variant_get (the_black_list, "as", &iter); + g_variant_iter_init (&iter, the_black_list); - while (g_variant_iter_loop (iter, "s", &str)){ + while (g_variant_iter_loop (&iter, "s", &str)){ if (g_strcmp0 (player_name, str) != 0){ - g_variant_builder_add (builder, "s", str); + g_variant_builder_add (&builder, "s", str); } } } - GVariant* value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - g_variant_iter_free (iter); + GVariant* value = g_variant_builder_end (&builder); + g_variant_ref (value); result = g_settings_set_value (our_settings, "blacklisted-media-players", value); + g_variant_unref (value); + g_object_unref (our_settings); + return result; } -- cgit v1.2.3 From 2ea739c1cc14bbfdafbebec79aeae78cbf440145 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 1 Feb 2011 09:50:29 -0600 Subject: fixes applied --- src/sound-service-dbus.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 9ae0fd7..7f5afdc 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -450,8 +450,9 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, 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_end (&builder); + g_variant_builder_clear (&builder); g_object_unref (our_settings); + g_object_unref (the_black_list); return result; } } @@ -472,17 +473,18 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, // It was not there anyway, return false if (present == FALSE){ g_debug ("it was not blacklisted ?, no need to do anything"); - g_variant_builder_end (&builder); + 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_end (&builder); + 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); @@ -490,13 +492,12 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, } } GVariant* value = g_variant_builder_end (&builder); - g_variant_ref (value); result = g_settings_set_value (our_settings, "blacklisted-media-players", value); - g_variant_unref (value); g_object_unref (our_settings); + g_object_unref (the_black_list); return result; } -- cgit v1.2.3