aboutsummaryrefslogtreecommitdiff
path: root/src/sound-service-dbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound-service-dbus.c')
-rw-r--r--src/sound-service-dbus.c85
1 files changed, 85 insertions, 0 deletions
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;
+}