From a4637ac0f922a3df3e31c19a0a86eebb6a8b4994 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 19 Jan 2011 15:25:18 -0600 Subject: further consolidation on the service side --- src/sound-service-dbus.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 6057a29..f14e7c6 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -24,11 +24,18 @@ #include #include +#include +#include + +#include "sound-service-dbus.h" + #include "gen-sound-service.xml.h" #include "dbus-shared-names.h" -#include "sound-service-dbus.h" #include "common-defs.h" #include "pulse-manager.h" +#include "slider-menu-item.h" +#include "mute-menu-item.h" + // DBUS methods static void bus_method_call (GDBusConnection * connection, @@ -50,9 +57,12 @@ static GDBusInterfaceVTable interface_table = { typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { - GDBusConnection *connection; - gboolean mute; - gboolean sink_availability; + GDBusConnection* connection; + gboolean mute; + gboolean sink_availability; + DbusmenuMenuitem* root_menuitem; + SliderMenuItem* volume_slider_menuitem; + MuteMenuItem* mute_menuitem; }; static GDBusNodeInfo * node_info = NULL; @@ -65,7 +75,6 @@ static void sound_service_dbus_init (SoundServiceDbus *self); static void sound_service_dbus_dispose (GObject *object); static void sound_service_dbus_finalize (GObject *object); -/* GObject Boilerplate */ G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); static void @@ -108,6 +117,7 @@ sound_service_dbus_init (SoundServiceDbus *self) SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); priv->connection = NULL; + priv->mute = FALSE; priv->sink_availability = FALSE; @@ -134,6 +144,17 @@ sound_service_dbus_init (SoundServiceDbus *self) } } +DbusmenuMenuitem* sound_service_dbus_construct_menu (SoundServiceDbus* self) +{ + SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); + priv->root_menuitem = dbusmenu_menuitem_new(); + g_debug("Root ID: %d", dbusmenu_menuitem_get_id(priv->root_menuitem)); + DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH); + dbusmenu_server_set_root(server, priv->root_menuitem); + establish_pulse_activities(self); + return priv->root_menuitem; +} + static void sound_service_dbus_dispose (GObject *object) { -- cgit v1.2.3 From 5f6cebbcfffa32bffada62659e750ab7d362802e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Sat, 22 Jan 2011 22:15:44 -0600 Subject: service signals and methods re worked plus removed dbus-menu-manager.c and h and moved what was needed into the sound-service-dbus --- src/sound-service-dbus.c | 204 +++++++++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 85 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index f14e7c6..c0e02ab 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -3,7 +3,6 @@ * * Authors: * Conor Curran - * Ted Gould * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -23,6 +22,8 @@ #endif #include +#include +#include #include #include #include @@ -36,7 +37,6 @@ #include "slider-menu-item.h" #include "mute-menu-item.h" - // DBUS methods static void bus_method_call (GDBusConnection * connection, const gchar * sender, @@ -58,16 +58,15 @@ typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { GDBusConnection* connection; - gboolean mute; - gboolean sink_availability; DbusmenuMenuitem* root_menuitem; SliderMenuItem* volume_slider_menuitem; MuteMenuItem* mute_menuitem; + SoundState current_sound_state; }; static GDBusNodeInfo * node_info = NULL; static GDBusInterfaceInfo * interface_info = NULL; - +static gboolean b_startup = TRUE; #define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate)) static void sound_service_dbus_class_init (SoundServiceDbusClass *klass); @@ -75,6 +74,15 @@ static void sound_service_dbus_init (SoundServiceDbus *self); static void sound_service_dbus_dispose (GObject *object); static void sound_service_dbus_finalize (GObject *object); +static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* root, + gboolean mute_update, + gboolean availability, + gdouble volume ); +static void show_sound_settings_dialog (DbusmenuMenuitem *mi, + gpointer user_data); +static void sound_service_dbus_set_state_from_volume (SoundServiceDbus* self); + + G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); static void @@ -118,8 +126,7 @@ sound_service_dbus_init (SoundServiceDbus *self) priv->connection = NULL; - priv->mute = FALSE; - priv->sink_availability = FALSE; + priv->current_sound_state = UNAVAILABLE; /* Fetch the session bus */ priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); @@ -144,7 +151,7 @@ sound_service_dbus_init (SoundServiceDbus *self) } } -DbusmenuMenuitem* sound_service_dbus_construct_menu (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(); @@ -155,6 +162,89 @@ DbusmenuMenuitem* sound_service_dbus_construct_menu (SoundServiceDbus* self) return priv->root_menuitem; } +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); + + // Mute button + priv->mute_menuitem = mute_menu_item_new ( mute_update, availability); + dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM(priv->mute_menuitem)); + + // Slider + priv->volume_slider_menuitem = slider_menu_item_new ( availability, volume ); + dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM ( priv->volume_slider_menuitem )); + + // Separator + DbusmenuMenuitem* separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set( separator, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(priv->root_menuitem, separator); + + // Sound preferences dialog + DbusmenuMenuitem* settings_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set( settings_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Sound Preferences...")); + dbusmenu_menuitem_child_append(priv->root_menuitem, settings_mi); + g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_sound_settings_dialog), NULL); +} + +/** +show_sound_settings_dialog: +Bring up the gnome volume preferences dialog +**/ +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) && + !g_spawn_command_line_async("xfce4-mixer", &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } +} + +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); + + if (b_startup == TRUE) { + sound_service_dbus_build_sound_menu ( self, + mute_update, + availability, + volume ); + b_startup = FALSE; + return; + } + + mute_menu_item_update ( priv->mute_menuitem, + mute_update ); + slider_menu_item_update ( priv->volume_slider_menuitem, + volume ); + + mute_menu_item_enable ( priv->mute_menuitem, availability); + slider_menu_item_enable ( priv->volume_slider_menuitem, + availability ); + + // Emit the signals after the menus are setup/torn down + // preserve ordering ! + /*sound_service_dbus_update_sink_availability(dbus_interface, sink_available); + dbus_menu_manager_update_volume(percent); + sound_service_dbus_update_sink_mute(dbus_interface, sink_muted); + dbus_menu_manager_update_mute_ui(b_all_muted);*/ +} + + static void sound_service_dbus_dispose (GObject *object) { @@ -183,97 +273,41 @@ bus_method_call (GDBusConnection * connection, { SoundServiceDbus* service = SOUND_SERVICE_DBUS(user_data); g_return_if_fail ( IS_SOUND_SERVICE_DBUS(service) ); - GVariant * retval = NULL; - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); - - if (g_strcmp0(method, "GetSinkMute") == 0) { - g_debug("Get sink mute - sound service dbus!,about to send over mute_value of %i", priv->mute); - retval = g_variant_new ( "(b)", priv->mute); - } - else if (g_strcmp0(method, "GetSinkAvailability") == 0) { - g_debug("Get sink availability - sound service dbus!, about to send over availability_value of %i", priv->sink_availability); - retval = g_variant_new ( "(b)", priv->sink_availability); - } - else { - g_warning("Calling method '%s' on the sound service but it's unknown", method); - } - g_dbus_method_invocation_return_value(invocation, retval); + //GVariant * retval = NULL; + //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); + // TODO we will need to implement the black_list and state fetch. } - -/** -SIGNALS -Utility methods to emit signals from the service into the ether. -**/ -void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, - gboolean block_value) +// TODO until the pulsemanager has been refactored keep in place the consistent api +// for it to talk to the UI. +void sound_service_dbus_update_volume(SoundServiceDbus* obj, + gdouble volume) { - g_debug("Emitting signal: SINK_INPUT_WHILE_MUTED, with block_value: %i", - block_value); SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); - GVariant* v_output = g_variant_new("(b)", block_value); - - GError * error = NULL; - - g_dbus_connection_emit_signal( priv->connection, - NULL, - INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH, - INDICATOR_SOUND_DBUS_INTERFACE, - INDICATOR_SOUND_SIGNAL_SINK_INPUT_WHILE_MUTED, - v_output, - &error ); - if (error != NULL) { - g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); - g_error_free(error); - return; - } + slider_menu_item_update (priv->volume_slider_menuitem, volume); } void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, - gboolean sink_mute) + gboolean mute_update) { - g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute); SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); - priv->mute = sink_mute; + mute_menu_item_update (priv->mute_menuitem, mute_update); +} +// TODO: this will be a bit messy until the pa_manager is sorted. +void sound_service_dbus_update_sound_state (SoundServiceDbus* self, + SoundState new_state) +{ + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - GVariant* v_output = g_variant_new("(b)", sink_mute); - GError * error = NULL; - g_dbus_connection_emit_signal( priv->connection, - NULL, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, - INDICATOR_SOUND_DBUS_INTERFACE, - INDICATOR_SOUND_SIGNAL_SINK_MUTE_UPDATE, - v_output, - &error ); - if (error != NULL) { - g_error("Unable to emit signal 'sinkmuteupdate' because : %s", error->message); - g_error_free(error); - return; + if (new_state == AVAILABLE && + dbusmenu_menuitem_property_get_bool (priv->mute_menuitem, DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE){ + sound_service_dbus_set_state_from_volume (self); } } -void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, - gboolean sink_availability) +static void sound_service_dbus_set_state_from_volume (SoundServiceDbus* self) { - g_debug("Emitting signal: SinkAvailableUpdate, with %i", sink_availability); - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); - priv->sink_availability = sink_availability; - - GVariant* v_output = g_variant_new("(b)", priv->sink_availability); - GError * error = NULL; - - g_dbus_connection_emit_signal( priv->connection, - NULL, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, - INDICATOR_SOUND_DBUS_INTERFACE, - INDICATOR_SOUND_SIGNAL_SINK_AVAILABLE_UPDATE, - v_output, - &error ); - if (error != NULL) { - g_error("Unable to emit signal 'SinkAvailableUpdate' because : %s", error->message); - g_error_free(error); - return; - } + //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); } -- cgit v1.2.3 From 1ccf02c850145706776fd2c79a30a33a02df50b3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Sat, 22 Jan 2011 23:37:45 -0600 Subject: signals and methods cut down to size, next the indicator --- src/sound-service-dbus.c | 54 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index c0e02ab..20546fc 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -32,7 +32,6 @@ #include "gen-sound-service.xml.h" #include "dbus-shared-names.h" -#include "common-defs.h" #include "pulse-manager.h" #include "slider-menu-item.h" #include "mute-menu-item.h" @@ -80,7 +79,7 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* root, gdouble volume ); static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data); -static void sound_service_dbus_set_state_from_volume (SoundServiceDbus* self); +static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self); G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -293,21 +292,62 @@ void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); mute_menu_item_update (priv->mute_menuitem, mute_update); } + // 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) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - + SoundState update = new_state; if (new_state == AVAILABLE && - dbusmenu_menuitem_property_get_bool (priv->mute_menuitem, DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE){ - sound_service_dbus_set_state_from_volume (self); + dbusmenu_menuitem_property_get_bool ( DBUSMENU_MENUITEM(priv->mute_menuitem), + DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE ){ + update = sound_service_dbus_get_state_from_volume (self); + } + + GVariant* v_output = g_variant_new("(i)", (int)update); + + GError * error = NULL; + + g_dbus_connection_emit_signal( priv->connection, + NULL, + INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH, + INDICATOR_SOUND_DBUS_INTERFACE, + INDICATOR_SOUND_SIGNAL_SOUND_STATE_UPDATE, + v_output, + &error ); + if (error != NULL) { + g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); + g_error_free(error); + return; } + + } -static void sound_service_dbus_set_state_from_volume (SoundServiceDbus* self) +static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) { - //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + GVariant* v = dbusmenu_menuitem_get_variant (DBUSMENU_MENUITEM(priv->volume_menuitem), + DBUSMENU_VOLUME_MENUITEM_LEVEL); + gdouble volume_percent = g_variant_get_double (v); + + SoundState state = LOW_LEVEL; + + if (volume_percent < 30.0 && volume_percent > 0) { + state = LOW_LEVEL; + } + else if (volume_percent < 70.0 && volume_percent >= 30.0) { + state = MEDIUM_LEVEL; + } + else if (volume_percent >= 70.0) { + state = HIGH_LEVEL; + } + else if (volume_percent == 0.0) { + state = ZERO_LEVEL; + } + return state; } -- cgit v1.2.3 From 9a0a7255bfdcc1441277e211b4d45dffedb34e1f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 09:24:42 -0600 Subject: refactoring the indicator --- src/sound-service-dbus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 20546fc..176ea87 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -279,11 +279,13 @@ bus_method_call (GDBusConnection * connection, // TODO until the pulsemanager has been refactored keep in place the consistent api // for it to talk to the UI. -void sound_service_dbus_update_volume(SoundServiceDbus* obj, +void sound_service_dbus_update_volume(SoundServiceDbus* self, gdouble volume) { - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); slider_menu_item_update (priv->volume_slider_menuitem, volume); + sound_service_dbus_update_sound_state (self, + sound_service_dbus_get_state_from_volume (self)); } void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, -- cgit v1.2.3 From 729ff587783dcf571b4a94132b57bce695a5e30f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 17:29:31 -0600 Subject: compiling ... --- src/sound-service-dbus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 176ea87..ad4ac71 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -331,8 +331,8 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self, static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - GVariant* v = dbusmenu_menuitem_get_variant (DBUSMENU_MENUITEM(priv->volume_menuitem), - DBUSMENU_VOLUME_MENUITEM_LEVEL); + GVariant* v = dbusmenu_menuitem_property_get_variant (DBUSMENU_MENUITEM(priv->volume_slider_menuitem), + DBUSMENU_VOLUME_MENUITEM_LEVEL); gdouble volume_percent = g_variant_get_double (v); SoundState state = LOW_LEVEL; -- cgit v1.2.3 From d20e8f85ca28589e486fd395bd2071d63b2069ae Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 25 Jan 2011 19:28:29 -0600 Subject: tidy up --- src/sound-service-dbus.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index ad4ac71..1e7b6d5 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -312,20 +312,19 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self, GError * error = NULL; + g_debug ("emitting signal with value %i", (int)update); g_dbus_connection_emit_signal( priv->connection, NULL, INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH, INDICATOR_SOUND_DBUS_INTERFACE, INDICATOR_SOUND_SIGNAL_SOUND_STATE_UPDATE, - v_output, - &error ); + v_output, + &error ); if (error != NULL) { g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); g_error_free(error); return; } - - } static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) -- cgit v1.2.3 From 7ff9e0aafc0562c8d07f8f5dae96780c7e5c01c3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 25 Jan 2011 21:24:25 -0600 Subject: on the pigs back ... --- src/sound-service-dbus.c | 64 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 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 1e7b6d5..ec802f7 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -80,7 +80,10 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* root, static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data); static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self); - +static void sound_service_dbus_determine_state (SoundServiceDbus* self, + gboolean availability, + gboolean mute, + gdouble volume); G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -191,6 +194,7 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, dbusmenu_menuitem_child_append(priv->root_menuitem, settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); + sound_service_dbus_determine_state (self, availability, mute_update, volume); } /** @@ -234,6 +238,7 @@ void sound_service_dbus_update_pa_state ( SoundServiceDbus* self, mute_menu_item_enable ( priv->mute_menuitem, availability); slider_menu_item_enable ( priv->volume_slider_menuitem, availability ); + sound_service_dbus_determine_state (self, availability, mute_update, volume); // Emit the signals after the menus are setup/torn down // preserve ordering ! @@ -260,6 +265,7 @@ sound_service_dbus_finalize (GObject *object) /* A method has been called from our dbus inteface. Figure out what it is and dispatch it. */ + // TODO we will need to implement the black_list method. static void bus_method_call (GDBusConnection * connection, const gchar * sender, @@ -272,9 +278,17 @@ bus_method_call (GDBusConnection * connection, { SoundServiceDbus* service = SOUND_SERVICE_DBUS(user_data); g_return_if_fail ( IS_SOUND_SERVICE_DBUS(service) ); - //GVariant * retval = NULL; - //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); - // TODO we will need to implement the black_list and state fetch. + GVariant * retval = NULL; + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); + + if (g_strcmp0(method, "GetSoundState") == 0) { + g_debug("Get state - %i", priv->current_sound_state ); + retval = g_variant_new ( "(i)", priv->current_sound_state); + } + else { + g_warning("Calling method '%s' on the sound service but it's unknown", method); + } + g_dbus_method_invocation_return_value (invocation, retval); } // TODO until the pulsemanager has been refactored keep in place the consistent api @@ -315,9 +329,9 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self, g_debug ("emitting signal with value %i", (int)update); g_dbus_connection_emit_signal( priv->connection, NULL, - INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, INDICATOR_SOUND_DBUS_INTERFACE, - INDICATOR_SOUND_SIGNAL_SOUND_STATE_UPDATE, + INDICATOR_SOUND_SIGNAL_STATE_UPDATE, v_output, &error ); if (error != NULL) { @@ -351,5 +365,43 @@ 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) +{ + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + + if (availability == FALSE) { + priv->current_sound_state = AVAILABLE; + } + else if (mute == TRUE) { + priv->current_sound_state = MUTED; + } + else{ + priv->current_sound_state = sound_service_dbus_get_state_from_volume (self); + } + + GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state); + + GError * error = NULL; + + g_debug ("emitting signal with value %i", (int)priv->current_sound_state); + g_dbus_connection_emit_signal( priv->connection, + NULL, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, + INDICATOR_SOUND_DBUS_INTERFACE, + INDICATOR_SOUND_SIGNAL_STATE_UPDATE, + v_output, + &error ); + if (error != NULL) { + g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); + g_error_free(error); + return; + } + +} + + -- cgit v1.2.3 From a31cd4c1759ff5b8cc75a0d43e6a45a4a5573b3a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 13:24:20 -0600 Subject: refactor complete --- src/sound-service-dbus.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index ec802f7..1bdb2cf 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -173,7 +173,8 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, // Mute button priv->mute_menuitem = mute_menu_item_new ( mute_update, availability); - dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM(priv->mute_menuitem)); + dbusmenu_menuitem_child_append (priv->root_menuitem, + mute_menu_item_get_button (priv->mute_menuitem)); // Slider priv->volume_slider_menuitem = slider_menu_item_new ( availability, volume ); @@ -240,12 +241,6 @@ void sound_service_dbus_update_pa_state ( SoundServiceDbus* self, availability ); sound_service_dbus_determine_state (self, availability, mute_update, volume); - // Emit the signals after the menus are setup/torn down - // preserve ordering ! - /*sound_service_dbus_update_sink_availability(dbus_interface, sink_available); - dbus_menu_manager_update_volume(percent); - sound_service_dbus_update_sink_mute(dbus_interface, sink_muted); - dbus_menu_manager_update_mute_ui(b_all_muted);*/ } @@ -302,11 +297,16 @@ void sound_service_dbus_update_volume(SoundServiceDbus* self, sound_service_dbus_get_state_from_volume (self)); } -void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, +void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, gboolean mute_update) { - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); mute_menu_item_update (priv->mute_menuitem, mute_update); + SoundState state = sound_service_dbus_get_state_from_volume (self); + if (mute_update == TRUE){ + state = MUTED; + } + sound_service_dbus_update_sound_state (self, state); } // TODO: this will be a bit messy until the pa_manager is sorted. @@ -316,11 +316,14 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self, { 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 ){ update = sound_service_dbus_get_state_from_volume (self); } + + priv->current_sound_state = update; GVariant* v_output = g_variant_new("(i)", (int)update); @@ -370,19 +373,20 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, gboolean mute, gdouble volume) { - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - + //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + SoundState update; if (availability == FALSE) { - priv->current_sound_state = AVAILABLE; + update = UNAVAILABLE; } else if (mute == TRUE) { - priv->current_sound_state = MUTED; + update = MUTED; } else{ - priv->current_sound_state = sound_service_dbus_get_state_from_volume (self); + update = sound_service_dbus_get_state_from_volume (self); } - GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state); + sound_service_dbus_update_sound_state (self, update); + /*GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state); GError * error = NULL; @@ -398,7 +402,7 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); g_error_free(error); return; - } + }*/ } -- cgit v1.2.3 From 39089ee365c3c36db7cd42f53d782ee938424b5a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 13:27:55 -0600 Subject: tidy up --- src/sound-service-dbus.c | 119 ++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 69 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 1bdb2cf..2c1dc4f 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -258,34 +258,6 @@ sound_service_dbus_finalize (GObject *object) return; } -/* A method has been called from our dbus inteface. Figure out what it - is and dispatch it. */ - // TODO we will need to implement the black_list method. -static void -bus_method_call (GDBusConnection * connection, - const gchar * sender, - const gchar * path, - const gchar * interface, - const gchar * method, - GVariant * params, - GDBusMethodInvocation * invocation, - gpointer user_data) -{ - SoundServiceDbus* service = SOUND_SERVICE_DBUS(user_data); - g_return_if_fail ( IS_SOUND_SERVICE_DBUS(service) ); - GVariant * retval = NULL; - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); - - if (g_strcmp0(method, "GetSoundState") == 0) { - g_debug("Get state - %i", priv->current_sound_state ); - retval = g_variant_new ( "(i)", priv->current_sound_state); - } - else { - g_warning("Calling method '%s' on the sound service but it's unknown", method); - } - g_dbus_method_invocation_return_value (invocation, retval); -} - // TODO until the pulsemanager has been refactored keep in place the consistent api // for it to talk to the UI. void sound_service_dbus_update_volume(SoundServiceDbus* self, @@ -309,41 +281,6 @@ void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, sound_service_dbus_update_sound_state (self, state); } -// 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) -{ - 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 ){ - update = sound_service_dbus_get_state_from_volume (self); - } - - priv->current_sound_state = update; - - GVariant* v_output = g_variant_new("(i)", (int)update); - - GError * error = NULL; - - g_debug ("emitting signal with value %i", (int)update); - g_dbus_connection_emit_signal( priv->connection, - NULL, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, - INDICATOR_SOUND_DBUS_INTERFACE, - INDICATOR_SOUND_SIGNAL_STATE_UPDATE, - v_output, - &error ); - if (error != NULL) { - g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); - g_error_free(error); - return; - } -} - static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); @@ -373,7 +310,6 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, gboolean mute, gdouble volume) { - //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); SoundState update; if (availability == FALSE) { update = UNAVAILABLE; @@ -384,13 +320,32 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, else{ update = sound_service_dbus_get_state_from_volume (self); } + sound_service_dbus_update_sound_state (self, update); +} - sound_service_dbus_update_sound_state (self, update); - /*GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state); +// EMIT STATE SIGNAL + +// 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) +{ + 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 ){ + update = sound_service_dbus_get_state_from_volume (self); + } + + priv->current_sound_state = update; + + GVariant* v_output = g_variant_new("(i)", (int)update); GError * error = NULL; - g_debug ("emitting signal with value %i", (int)priv->current_sound_state); + g_debug ("emitting signal with value %i", (int)update); g_dbus_connection_emit_signal( priv->connection, NULL, INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, @@ -402,8 +357,34 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message); g_error_free(error); return; - }*/ - + } +} + +//HANDLE DBUS METHOD CALLS +// TODO we will need to implement the black_list method. +static void +bus_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * path, + const gchar * interface, + const gchar * method, + GVariant * params, + GDBusMethodInvocation * invocation, + gpointer user_data) +{ + SoundServiceDbus* service = SOUND_SERVICE_DBUS(user_data); + g_return_if_fail ( IS_SOUND_SERVICE_DBUS(service) ); + GVariant * retval = NULL; + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service); + + if (g_strcmp0(method, "GetSoundState") == 0) { + g_debug("Get state - %i", priv->current_sound_state ); + retval = g_variant_new ( "(i)", priv->current_sound_state); + } + else { + g_warning("Calling method '%s' on the sound service but it's unknown", method); + } + g_dbus_method_invocation_return_value (invocation, retval); } -- cgit v1.2.3 From 8bbf7ea5805ed69a2d7450065a558398a623525f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 16:08:46 -0600 Subject: blocking state now workings as expected --- src/sound-service-dbus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 2c1dc4f..3ecca38 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -258,8 +258,6 @@ sound_service_dbus_finalize (GObject *object) return; } -// TODO until the pulsemanager has been refactored keep in place the consistent api -// for it to talk to the UI. void sound_service_dbus_update_volume(SoundServiceDbus* self, gdouble volume) { @@ -323,6 +321,7 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, sound_service_dbus_update_sound_state (self, update); } + // EMIT STATE SIGNAL // TODO: this will be a bit messy until the pa_manager is sorted. @@ -338,8 +337,9 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self, DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE ){ update = sound_service_dbus_get_state_from_volume (self); } - - priv->current_sound_state = update; + if (update != BLOCKED){ + priv->current_sound_state = update; + } GVariant* v_output = g_variant_new("(i)", (int)update); -- cgit v1.2.3 From b21fd65d6bc0dee49a39fb18f585cbe75acc5e52 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 20:27:23 -0600 Subject: applied fixes --- src/sound-service-dbus.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 3ecca38..336ee1f 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -159,8 +159,9 @@ DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self) priv->root_menuitem = dbusmenu_menuitem_new(); g_debug("Root ID: %d", dbusmenu_menuitem_get_id(priv->root_menuitem)); DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH); - dbusmenu_server_set_root(server, priv->root_menuitem); - establish_pulse_activities(self); + dbusmenu_server_set_root (server, priv->root_menuitem); + g_object_unref (priv->root_menuitem); + establish_pulse_activities (self); return priv->root_menuitem; } @@ -175,12 +176,15 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, priv->mute_menuitem = mute_menu_item_new ( mute_update, availability); dbusmenu_menuitem_child_append (priv->root_menuitem, mute_menu_item_get_button (priv->mute_menuitem)); - + g_object_unref (priv->mute_menuitem); + // Slider priv->volume_slider_menuitem = slider_menu_item_new ( availability, volume ); dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM ( priv->volume_slider_menuitem )); + g_object_unref (priv->volume_slider__menuitem); // Separator + DbusmenuMenuitem* separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set( separator, DBUSMENU_MENUITEM_PROP_TYPE, @@ -195,6 +199,7 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, dbusmenu_menuitem_child_append(priv->root_menuitem, settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); + sound_service_dbus_determine_state (self, availability, mute_update, volume); } -- cgit v1.2.3 From b7086f82e50f8c95c0d213b45c54a603f7e58f01 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 20:46:26 -0600 Subject: more fixes --- src/sound-service-dbus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 336ee1f..78b5e93 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -176,27 +176,30 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, priv->mute_menuitem = mute_menu_item_new ( mute_update, availability); dbusmenu_menuitem_child_append (priv->root_menuitem, mute_menu_item_get_button (priv->mute_menuitem)); - g_object_unref (priv->mute_menuitem); // Slider priv->volume_slider_menuitem = slider_menu_item_new ( availability, volume ); dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM ( priv->volume_slider_menuitem )); - g_object_unref (priv->volume_slider__menuitem); // Separator DbusmenuMenuitem* separator = dbusmenu_menuitem_new(); + g_object_ref (separator); + dbusmenu_menuitem_property_set( separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(priv->root_menuitem, separator); + g_object_unref (separator); // Sound preferences dialog DbusmenuMenuitem* settings_mi = dbusmenu_menuitem_new(); + g_object_ref(settings_mi); dbusmenu_menuitem_property_set( settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); dbusmenu_menuitem_child_append(priv->root_menuitem, settings_mi); + g_object_unref (settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); -- cgit v1.2.3 From 2015246e5146a5a03b6b0497aa8ce18a705bd724 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 20:53:34 -0600 Subject: removed unnecessary g_object_refs() --- src/sound-service-dbus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/sound-service-dbus.c') diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 78b5e93..b444a91 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -184,7 +184,6 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, // Separator DbusmenuMenuitem* separator = dbusmenu_menuitem_new(); - g_object_ref (separator); dbusmenu_menuitem_property_set( separator, DBUSMENU_MENUITEM_PROP_TYPE, @@ -194,7 +193,7 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, // Sound preferences dialog DbusmenuMenuitem* settings_mi = dbusmenu_menuitem_new(); - g_object_ref(settings_mi); + dbusmenu_menuitem_property_set( settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); -- cgit v1.2.3