aboutsummaryrefslogtreecommitdiff
path: root/src/sound-service-dbus.c
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-01-31 19:33:46 -0600
committerConor Curran <conor.curran@canonical.com>2011-01-31 19:33:46 -0600
commit43b7e22a13692edbba02c987975747a069881814 (patch)
treef3563c223c6f927e7b5c997b8cf92365a92c9626 /src/sound-service-dbus.c
parent6da3712d5eda504073689da98eccba020d57a5cd (diff)
downloadayatana-indicator-sound-43b7e22a13692edbba02c987975747a069881814.tar.gz
ayatana-indicator-sound-43b7e22a13692edbba02c987975747a069881814.tar.bz2
ayatana-indicator-sound-43b7e22a13692edbba02c987975747a069881814.zip
moved builder and iter to the stack in blacklist method
Diffstat (limited to 'src/sound-service-dbus.c')
-rw-r--r--src/sound-service-dbus.c61
1 files changed, 35 insertions, 26 deletions
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;
}