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.c154
1 files changed, 130 insertions, 24 deletions
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index b444a91..7f5afdc 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -35,6 +35,7 @@
#include "pulse-manager.h"
#include "slider-menu-item.h"
#include "mute-menu-item.h"
+#include "pulse-manager.h"
// DBUS methods
static void bus_method_call (GDBusConnection * connection,
@@ -84,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);
@@ -153,7 +158,8 @@ sound_service_dbus_init (SoundServiceDbus *self)
}
}
-DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self)
+DbusmenuMenuitem*
+sound_service_dbus_create_root_item (SoundServiceDbus* self)
{
SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
priv->root_menuitem = dbusmenu_menuitem_new();
@@ -165,10 +171,11 @@ DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self)
return priv->root_menuitem;
}
-static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
- gboolean mute_update,
- gboolean availability,
- gdouble volume )
+static void
+sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
+ gboolean mute_update,
+ gboolean availability,
+ gdouble volume )
{
SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
@@ -209,8 +216,9 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
show_sound_settings_dialog:
Bring up the gnome volume preferences dialog
**/
-static void show_sound_settings_dialog (DbusmenuMenuitem *mi,
- gpointer user_data)
+static void
+show_sound_settings_dialog (DbusmenuMenuitem *mi,
+ gpointer user_data)
{
GError * error = NULL;
if (!g_spawn_command_line_async("gnome-volume-control --page=applications", &error) &&
@@ -221,10 +229,11 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi,
}
}
-void sound_service_dbus_update_pa_state ( SoundServiceDbus* self,
- gboolean availability,
- gboolean mute_update,
- gdouble volume )
+void
+sound_service_dbus_update_pa_state ( SoundServiceDbus* self,
+ gboolean availability,
+ gboolean mute_update,
+ gdouble volume )
{
g_debug("update pa state with availability of %i, mute value of %i and a volume percent is %f", availability, mute_update, volume);
SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
@@ -265,8 +274,11 @@ sound_service_dbus_finalize (GObject *object)
return;
}
-void sound_service_dbus_update_volume(SoundServiceDbus* self,
- gdouble volume)
+// UNTIL PA-MANAGER IS REFACTORED AND THE ACTIVESINK CLASS IS CREATED LEAVE
+// THE UI ELEMENTS SEPARATELY HANDLED LIKE THIS.
+void
+sound_service_dbus_update_volume (SoundServiceDbus* self,
+ gdouble volume)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
slider_menu_item_update (priv->volume_slider_menuitem, volume);
@@ -274,8 +286,9 @@ void sound_service_dbus_update_volume(SoundServiceDbus* self,
sound_service_dbus_get_state_from_volume (self));
}
-void sound_service_dbus_update_sink_mute(SoundServiceDbus* self,
- gboolean mute_update)
+void
+sound_service_dbus_update_sink_mute (SoundServiceDbus* self,
+ gboolean mute_update)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
mute_menu_item_update (priv->mute_menuitem, mute_update);
@@ -286,7 +299,9 @@ void sound_service_dbus_update_sink_mute(SoundServiceDbus* self,
sound_service_dbus_update_sound_state (self, state);
}
-static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self)
+/*------- State calculators ------------------*/
+static SoundState
+sound_service_dbus_get_state_from_volume (SoundServiceDbus* self)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
GVariant* v = dbusmenu_menuitem_property_get_variant (DBUSMENU_MENUITEM(priv->volume_slider_menuitem),
@@ -310,10 +325,11 @@ static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* se
return state;
}
-static void sound_service_dbus_determine_state (SoundServiceDbus* self,
- gboolean availability,
- gboolean mute,
- gdouble volume)
+static void
+sound_service_dbus_determine_state (SoundServiceDbus* self,
+ gboolean availability,
+ gboolean mute,
+ gdouble volume)
{
SoundState update;
if (availability == FALSE) {
@@ -333,15 +349,15 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self,
// TODO: this will be a bit messy until the pa_manager is sorted.
// And we figure out all of the edge cases.
-void sound_service_dbus_update_sound_state (SoundServiceDbus* self,
- SoundState new_state)
+void
+sound_service_dbus_update_sound_state (SoundServiceDbus* self,
+ SoundState new_state)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
SoundState update = new_state;
// Ensure that after it has become available update the state with the current volume level
if (new_state == AVAILABLE &&
- dbusmenu_menuitem_property_get_bool ( DBUSMENU_MENUITEM(priv->mute_menuitem),
- DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE ){
+ mute_menu_item_is_muted (priv->mute_menuitem) == FALSE){
update = sound_service_dbus_get_state_from_volume (self);
}
if (update != BLOCKED){
@@ -388,12 +404,102 @@ 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 = 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;
+
+ 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);
+ }
+ g_variant_iter_init (&iter, the_black_list);
+
+ 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, no need to do anything");
+ g_variant_builder_clear (&builder);
+ g_object_unref (our_settings);
+ g_object_unref (the_black_list);
+ return result;
+ }
+ }
+ // Otherwise blacklist it !
+ g_debug ("about to blacklist %s", player_name);
+ g_variant_builder_add (&builder, "s", player_name);
+ }
+ else{
+ gboolean present = FALSE;
+ 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){
+ g_debug ("it was not blacklisted ?, no need to do anything");
+ 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_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);
+ }
+ }
+ }
+ GVariant* value = g_variant_builder_end (&builder);
+ result = g_settings_set_value (our_settings,
+ "blacklisted-media-players",
+ value);
+ g_object_unref (our_settings);
+ g_object_unref (the_black_list);
+
+ return result;
+}