diff options
-rw-r--r-- | src/indicator-sound.c | 178 | ||||
-rw-r--r-- | src/sound-state-manager.c | 45 |
2 files changed, 29 insertions, 194 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c index b3f19bc..59b9c92 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -172,7 +172,6 @@ static GtkImage * get_icon (IndicatorObject * io) { IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - //speaker_image = 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); @@ -391,183 +390,6 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, return TRUE; } -/*static void fetch_state (IndicatorSound* self) -{ - - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - if(priv->volume_widget != NULL){ - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); - } - - g_dbus_proxy_call ( priv->dbus_proxy, - "GetSinkMute", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback)get_sink_mute_cb, - self); - - g_dbus_proxy_call ( priv->dbus_proxy, - "GetSinkAvailability", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback)get_sink_availability_cb, - self); - -} - -static void get_sink_availability_cb ( GObject *object, - GAsyncResult *res, - gpointer user_data ) -{ - IndicatorSound* self = INDICATOR_SOUND(user_data); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_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_sink_availability call failed: %s", error->message); - g_error_free(error); - return; - } - - value = g_variant_get_child_value(result, 0); - device_available = g_variant_get_boolean(value); - - if (device_available == FALSE) { - update_state(STATE_SINKS_NONE); - } - - if(priv->volume_widget != NULL){ - GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); - gtk_widget_set_sensitive(slider_widget, device_available); - } - - g_variant_unref(value); - g_variant_unref(result); -} - - -static void get_sink_mute_cb ( GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - IndicatorSound* self = INDICATOR_SOUND(user_data); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - - GVariant *result, *value; - GError *error = NULL; - gboolean is_muted; - result = g_dbus_proxy_call_finish ( priv->dbus_proxy, - res, - &error ); - - if (error != NULL) { - g_debug("get_sink_mute call failed: %s", error->message); - g_error_free(error); - return; - } - - value = g_variant_get_child_value(result, 0); - is_muted = g_variant_get_boolean(value); - - if ( is_muted == TRUE ){ - update_state(STATE_MUTED); - } - - g_variant_unref(value); - g_variant_unref(result); -}*/ - -/*******************************************************************/ -// DBUS Signal reactions -/*******************************************************************/ -/*static void g_signal_cb ( GDBusProxy* proxy, - gchar* sender_name, - gchar* signal_name, - GVariant* parameters, - gpointer user_data) -{ - IndicatorSound *self = INDICATOR_SOUND(user_data); - g_return_if_fail ( IS_INDICATOR_SOUND(self) ); - - g_variant_ref (parameters); - GVariant *value = g_variant_get_child_value (parameters, 0); - gboolean input = g_variant_get_boolean (value); - g_variant_unref (parameters); - - g_debug ( "!!! signal_cb with value %i", input); - - if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_AVAILABLE_UPDATE) == 0){ - react_to_signal_sink_availability_update ( input, self ); - } - else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_MUTE_UPDATE) == 0){ - react_to_signal_sink_mute_update ( input, self ); - } - else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_INPUT_WHILE_MUTED) == 0){ - react_to_signal_sink_input_while_muted ( input, self ); - } -} - -static void -react_to_signal_sink_input_while_muted(gboolean block_value, IndicatorSound* self) -{ - //g_debug("signal caught - sink input while muted with value %i", block_value); - if (block_value == 1 && blocked_id == 0 && animation_id == 0 && blocked_animation_list != NULL) { - gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); - indicator_image_helper_update(speaker_image, image_name); - blocked_id = g_timeout_add_seconds(5, start_animation, NULL); - } -} -*/ -/* - We can be sure the service won't send a mute signal unless it has changed ! - UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. -*/ -/*static void -react_to_signal_sink_mute_update(gboolean mute_value, IndicatorSound* self) -{ - if (mute_value == TRUE && device_available == TRUE) { - update_state(STATE_MUTED); - } else { - reset_mute_blocking_animation(); - } - //g_debug("signal caught - sink mute update with mute value: %i", mute_value); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - - if(priv->volume_widget == NULL){ - return; - } - GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); - gtk_widget_set_sensitive(slider_widget, !mute_value); - if(mute_value == FALSE){ - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); - } -} - - -static void -react_to_signal_sink_availability_update(gboolean available_value, IndicatorSound* self) -{ - device_available = available_value; - if (device_available == FALSE) { - update_state(STATE_SINKS_NONE); - return; - } - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); - //g_debug("signal caught - sink availability update with value: %i", available_value); -} -*/ /*******************************************************************/ //UI callbacks /******************************************************************/ diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 004e011..83fb952 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -22,7 +22,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate; -// TODO ensure all the relevant below are initialized to null in init struct _SoundStateManagerPrivate { GDBusProxy* dbus_proxy; @@ -46,6 +45,11 @@ static gboolean sound_state_manager_fade_back_to_mute_image (gpointer user_data) static void sound_state_manager_reset_mute_blocking_animation (SoundStateManager* self); static void sound_state_manager_free_the_animation_list (SoundStateManager* self); static void sound_state_manager_prepare_state_image_names (SoundStateManager* self); +static void sound_state_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data ); static void @@ -53,6 +57,11 @@ sound_state_manager_init (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + priv->dbus_proxy = NULL; + priv->volume_states = NULL; + priv->speaker_image = NULL; + priv->blocked_animation_list = NULL; + sound_state_manager_prepare_state_image_names (self); sound_state_manager_prepare_blocked_animation (self); @@ -170,6 +179,23 @@ sound_state_manager_get_current_state (SoundStateManager* self) return priv->current_state; } +/** + * sound_state_manager_connect_to_dbus: + * @returns: void + * When ready the indicator-sound calls this method to enable state communication + * between the indicator and the service. + **/ +void +sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + priv->dbus_proxy = proxy; + g_debug (" here about to register for signal callback"); + g_signal_connect (priv->dbus_proxy, "g-signal", + G_CALLBACK (sound_state_signal_cb), self); + +} + static void sound_state_signal_cb ( GDBusProxy* proxy, gchar* sender_name, @@ -177,6 +203,8 @@ sound_state_signal_cb ( GDBusProxy* proxy, GVariant* parameters, gpointer user_data) { + g_debug ( "!!! signal_cb with value" ); + 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); @@ -281,18 +309,3 @@ sound_state_manager_fade_back_to_mute_image (gpointer user_data) } } -/** - * sound_state_manager_connect_to_dbus: - * @returns: void - * When ready the indicator-sound calls this method to enable state communication - * between the indicator and the service. - **/ -void -sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy) -{ - SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); - priv->dbus_proxy = proxy; - g_signal_connect (priv->dbus_proxy, "g-signal", - G_CALLBACK (sound_state_signal_cb), self); - -} |