aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dbus-shared-names.h2
-rw-r--r--src/indicator-sound.c25
-rw-r--r--src/sound-service-dbus.c64
-rw-r--r--src/sound-state-manager.c59
4 files changed, 111 insertions, 39 deletions
diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h
index 385a997..346a031 100644
--- a/src/dbus-shared-names.h
+++ b/src/dbus-shared-names.h
@@ -31,7 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define INDICATOR_SOUND_DBUS_INTERFACE "com.canonical.indicators.sound"
#define INDICATOR_SOUND_DBUS_VERSION 0
-#define INDICATOR_SOUND_SIGNAL_SOUND_STATE_UPDATE "SoundStateUpdate"
+#define INDICATOR_SOUND_SIGNAL_STATE_UPDATE "SoundStateUpdate"
#endif /* __DBUS_SHARED_NAMES_H__ */
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index ea67011..71310f1 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -99,12 +99,6 @@ static void connection_changed (IndicatorServiceManager * sm,
gboolean connected,
gpointer userdata);
-static void g_signal_cb ( GDBusProxy* proxy,
- gchar* sender_name,
- gchar* signal_name,
- GVariant* parameters,
- gpointer user_data);
-
static void
indicator_sound_class_init (IndicatorSoundClass *klass)
{
@@ -177,8 +171,7 @@ static GtkImage *
get_icon (IndicatorObject * io)
{
IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));
- gtk_widget_show( GTK_WIDGET(sound_state_manager_get_current_icon (priv->state_manager)) );
-
+ gtk_widget_show( GTK_WIDGET(sound_state_manager_get_current_icon (priv->state_manager)) );
return sound_state_manager_get_current_icon (priv->state_manager);
}
@@ -282,23 +275,9 @@ static void create_connection_to_service (GObject *source_object,
g_debug ("Connection to dbus seemed to work fine from the indicator side");
sound_state_manager_connect_to_dbus (priv->state_manager,
priv->dbus_proxy);
- g_signal_connect (priv->dbus_proxy, "g-signal",
- G_CALLBACK (g_signal_cb), self);
}
-static void
-g_signal_cb ( GDBusProxy* proxy,
- gchar* sender_name,
- gchar* signal_name,
- GVariant* parameters,
- gpointer user_data)
-{
- g_debug ( "!!! indicator-sound signal_cb" );
-}
-
-
-
static gboolean
new_transport_widget (DbusmenuMenuitem * newitem,
DbusmenuMenuitem * parent,
@@ -324,7 +303,6 @@ new_transport_widget (DbusmenuMenuitem * newitem,
newitem,
menu_transport_bar,
parent);
-
return TRUE;
}
@@ -346,7 +324,6 @@ new_metadata_widget (DbusmenuMenuitem * newitem,
gtk_widget_show_all(metadata);
dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client),
newitem, menu_metadata_widget, parent);
-
return TRUE;
}
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;
+ }
+
+}
+
+
diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c
index f6d39d0..0fce9a8 100644
--- a/src/sound-state-manager.c
+++ b/src/sound-state-manager.c
@@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libindicator/indicator-image-helper.h>
#include "sound-state-manager.h"
+#include "dbus-shared-names.h"
typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate;
@@ -50,6 +51,10 @@ static void sound_state_signal_cb ( GDBusProxy* proxy,
gchar* signal_name,
GVariant* parameters,
gpointer user_data );
+static void sound_state_manager_get_state_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data);
+
static void
@@ -193,7 +198,47 @@ sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy)
g_debug (" here about to register for signal callback on %s", g_dbus_proxy_get_name (priv->dbus_proxy));
g_signal_connect (priv->dbus_proxy, "g-signal",
G_CALLBACK (sound_state_signal_cb), self);
+
+ g_dbus_proxy_call ( priv->dbus_proxy,
+ "GetSoundState",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback)sound_state_manager_get_state_cb,
+ self);
+}
+
+static void
+sound_state_manager_get_state_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_return_if_fail (SOUND_IS_STATE_MANAGER (user_data));
+ SoundStateManager* self = SOUND_STATE_MANAGER (user_data);
+ SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self);
+ GVariant *result, *value;
+ GError *error = NULL;
+ result = g_dbus_proxy_call_finish ( priv->dbus_proxy,
+ res,
+ &error );
+
+ if (error != NULL) {
+ g_debug("get_sound_state call failed: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ value = g_variant_get_child_value(result, 0);
+ priv->current_state = (SoundState)g_variant_get_int32(value);
+
+ gchar* image_name = g_hash_table_lookup (priv->volume_states,
+ GINT_TO_POINTER(priv->current_state) );
+ indicator_image_helper_update (priv->speaker_image, image_name);
+
+ g_variant_unref(value);
+ g_variant_unref(result);
}
static void
@@ -219,16 +264,14 @@ sound_state_signal_cb ( GDBusProxy* proxy,
g_variant_unref (parameters);
-
- /*if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_AVAILABLE_UPDATE) == 0){
- react_to_signal_sink_availability_update ( input, self );
+ if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_STATE_UPDATE) == 0){
+ gchar* image_name = g_hash_table_lookup (priv->volume_states,
+ GINT_TO_POINTER(priv->current_state) );
+ indicator_image_helper_update (priv->speaker_image, image_name);
}
- else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_MUTE_UPDATE) == 0){
- react_to_signal_sink_mute_update ( input, self );
+ else {
+ g_debug ("sorry don't know what signal this is - %s", signal_name);
}
- else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_INPUT_WHILE_MUTED) == 0){
- react_to_signal_sink_input_while_muted ( input, self );
- }*/
}