diff options
author | Conor Curran <conor.curran@canonical.com> | 2011-03-07 15:19:28 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2011-03-07 15:19:28 +0000 |
commit | 10f404afef79bcf5fe3bb4bdc8a82d0cff08d87a (patch) | |
tree | 908446b67697d177180560f0aa1aadfdfac573e7 | |
parent | f4ed658ce1ea0b2bc0eaa47d9aa95a5585cba533 (diff) | |
download | ayatana-indicator-sound-10f404afef79bcf5fe3bb4bdc8a82d0cff08d87a.tar.gz ayatana-indicator-sound-10f404afef79bcf5fe3bb4bdc8a82d0cff08d87a.tar.bz2 ayatana-indicator-sound-10f404afef79bcf5fe3bb4bdc8a82d0cff08d87a.zip |
rewrote the method with the help of mikkel
-rw-r--r-- | src/sound-service-dbus.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 249a054..43d7360 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -307,17 +307,18 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, gboolean blacklist) { g_return_val_if_fail (player_name != NULL, FALSE); + g_return_val_if_fail (IS_SOUND_SERVICE_DBUS (self), FALSE); + GVariant* the_black_list; 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"); + GSettings* our_settings; GVariantIter iter; gchar *str; - // Firstly prep new array which will be set on the key. GVariantBuilder builder; - + + our_settings = g_settings_new ("com.canonical.indicators.sound"); + the_black_list = g_settings_get_value (our_settings, + "blacklisted-media-players"); g_variant_iter_init (&iter, the_black_list); g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY); @@ -384,41 +385,33 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, return result; } -static gboolean sound_service_dbus_is_blacklisted (SoundServiceDbus* self, - gchar* player_name) +static gboolean sound_service_dbus_is_blacklisted (SoundServiceDbus *self, + gchar *player_name) { - g_return_val_if_fail (player_name != NULL, FALSE); - - 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; + GSettings *our_settings; + GVariant *the_black_list; + GVariantIter iter; + gchar *str; + gboolean result = FALSE; - g_variant_iter_init (&iter, the_black_list); - g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY); + g_return_val_if_fail (player_name != NULL, FALSE); + g_return_val_if_fail (IS_SOUND_SERVICE_DBUS (self), FALSE); - while (g_variant_iter_loop (&iter, "s", &str)){ - g_variant_builder_add (&builder, "s", str); - } + our_settings = g_settings_new ("com.canonical.indicators.sound"); + the_black_list = g_settings_get_value (our_settings, + "blacklisted-media-players"); g_variant_iter_init (&iter, the_black_list); - - while (g_variant_iter_loop (&iter, "s", &str)){ - if (g_strcmp0 (player_name, str) == 0){ - // Return if its already there - g_debug ("Yes it is blacklisted !"); + while (g_variant_iter_next (&iter, "s", &str)){ + if (g_strcmp0 (player_name, str) == 0) { result = TRUE; + g_free (str); break; } + g_free (str); } - g_variant_builder_clear (&builder); + g_object_unref (our_settings); g_variant_unref (the_black_list); - g_debug ("Is it blacklisted ? %i", result); return result; } |