From 6db28ce9134db40a0808a3c67df5f9dd223303b5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 12 Jan 2011 17:55:05 -0600 Subject: stage one of the refactor on the server side complete --- src/pulse-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulse-manager.c') diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 4443044..15a449b 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -414,7 +414,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v if (mute_changed == TRUE) { /* g_debug("Updating Mute from PA manager with mute = %i", s->mute);*/ sound_service_dbus_update_sink_mute(dbus_service, s->mute); - dbus_menu_manager_update_mute_ui(s->mute); + dbus_menu_manager_update_mute(s->mute); if (s->mute == FALSE) { pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; -- 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/Makefile.am | 2 - src/common-defs.h | 14 +++- src/dbus-menu-manager.c | 15 ---- src/metadata-widget.c | 1 - src/mute-menu-item.c | 1 - src/pulse-manager.c | 45 ++++++----- src/sound-service-dbus.c | 204 +++++++++++++++++++++++++++-------------------- src/sound-service-dbus.h | 13 +-- src/sound-service.c | 2 +- 9 files changed, 165 insertions(+), 132 deletions(-) (limited to 'src/pulse-manager.c') diff --git a/src/Makefile.am b/src/Makefile.am index f880662..667293f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -87,8 +87,6 @@ indicator_sound_service_SOURCES = \ common-defs.h \ sound-service.h \ sound-service.c \ - dbus-menu-manager.c \ - dbus-menu-manager.h \ pulse-manager.h \ pulse-manager.c \ sound-service-dbus.h \ diff --git a/src/common-defs.h b/src/common-defs.h index c7d497a..5b5c418 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -24,6 +24,18 @@ with this program. If not, see . #define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" +typedef enum { + MUTED, + ZERO_LEVEL, + LOW_LEVEL, + MEDIUM_LEVEL, + HIGH_LEVEL, + BLOCKED, + UNAVAILABLE, + AVAILABLE +}SoundState; + + #define DBUSMENU_PROPERTY_EMPTY -1 /* DBUS Custom Items */ @@ -54,4 +66,4 @@ with this program. If not, see . #define DBUSMENU_PLAYLISTS_MENUITEM_TYPE "x-canonical-sound-menu-player-playlists-type" #define DBUSMENU_PLAYLISTS_MENUITEM_TITLE "x-canonical-sound-menu-player-playlists-title" -#define DBUSMENU_PLAYLISTS_MENUITEM_PLAYLISTS "x-canonical-sound-menu-player-playlists-playlists" \ No newline at end of file +#define DBUSMENU_PLAYLISTS_MENUITEM_PLAYLISTS "x-canonical-sound-menu-player-playlists-playlists" diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 7de5844..2a2982e 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -157,21 +157,6 @@ void dbus_menu_manager_update_volume(gdouble volume) } -/** -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); - } -} /** TODO: what are you doing with this diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 09365d5..d37c39f 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -397,7 +397,6 @@ metadata_widget_button_press_event (GtkWidget *menuitem, return FALSE; } -// TODO: Manage empty/mangled music details etc. static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, GVariant* value, gpointer userdata) diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index 9e79dd1..2c5af6d 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -93,7 +93,6 @@ handle_event (DbusmenuMenuitem * mi, } gboolean mute_input = g_variant_get_boolean(input); - // TODO: use the pulse wrapper directly toggle_global_mute (mute_input); g_variant_unref (input); } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 15a449b..21b78b2 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -75,7 +75,7 @@ void establish_pulse_activities(SoundServiceDbus *service) // Establish event callback registration pa_context_set_state_callback (pulse_context, context_state_callback, NULL); - dbus_menu_manager_update_pa_state (FALSE, FALSE, FALSE, 0); + sound_service_dbus_update_pa_state (dbus_service, FALSE, FALSE, 0); pa_context_connect (pulse_context, NULL, PA_CONTEXT_NOFAIL, NULL); } @@ -199,7 +199,7 @@ static void check_sink_input_while_muted_event(gint sink_index) /* g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER - check trace for value");*/ if (default_sink_is_muted(sink_index) == TRUE) { - sound_service_dbus_sink_input_while_muted (dbus_service, TRUE); + sound_service_dbus_sink_input_while_muted(dbus_service, TRUE); } else { sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); } @@ -223,10 +223,8 @@ static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) if (GPOINTER_TO_INT(user_data) == 1) { sound_service_dbus_update_sink_mute(dbus_service, TRUE); } else { - dbus_menu_manager_update_volume(get_default_sink_volume()); + sound_service_dbus_update_volume(dbus_service, get_default_sink_volume()); } - - /* g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data));*/ } void toggle_global_mute(gboolean mute_value) @@ -309,14 +307,17 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in gboolean device_available = determine_sink_availability(); if (device_available == TRUE) { - dbus_menu_manager_update_pa_state(TRUE, - device_available, - default_sink_is_muted(), - get_default_sink_volume()); + sound_service_dbus_update_pa_state( dbus_service, + device_available, + default_sink_is_muted(), + get_default_sink_volume() ); } else { //Update the indicator to show PA either is not ready or has no available sink g_warning("Cannot find a suitable default sink ..."); - dbus_menu_manager_update_pa_state(FALSE, device_available, default_sink_is_muted(), get_default_sink_volume()); + sound_service_dbus_update_pa_state( dbus_service, + device_available, + default_sink_is_muted(), + get_default_sink_volume() ); } } else { /* g_debug("About to add an item to our hash");*/ @@ -346,7 +347,10 @@ static void pulse_default_sink_info_callback(pa_context *c, const pa_sink_info * if (position < 0) { pa_operation_unref(pa_context_get_sink_info_list(c, pulse_sink_info_callback, NULL)); } else { - dbus_menu_manager_update_pa_state(TRUE, determine_sink_availability(), default_sink_is_muted(), get_default_sink_volume()); + sound_service_dbus_update_pa_state(dbus_service, + determine_sink_availability(), + default_sink_is_muted(), + get_default_sink_volume()); } } } @@ -408,18 +412,17 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - dbus_menu_manager_update_volume(volume_percent); + sound_service_dbus_update_volume(dbus_service, volume_percent); } if (mute_changed == TRUE) { /* g_debug("Updating Mute from PA manager with mute = %i", s->mute);*/ sound_service_dbus_update_sink_mute(dbus_service, s->mute); - dbus_menu_manager_update_mute(s->mute); if (s->mute == FALSE) { pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; - /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - dbus_menu_manager_update_volume(volume_percent); + /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ + sound_service_dbus_update_volume(dbus_service, volume_percent); } } } @@ -434,7 +437,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v value->base_volume = info->base_volume; g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value); /* g_debug("pulse-manager:update_sink_info -> After adding a new sink to our hash");*/ - sound_service_dbus_update_sink_availability(dbus_service, TRUE); + sound_service_dbus_update_sound_state(dbus_service, TRUE); } } @@ -463,7 +466,7 @@ static void pulse_server_info_callback(pa_context *c, pa_operation *operation; if (info == NULL) { g_warning("No server - get the hell out of here"); - dbus_menu_manager_update_pa_state(FALSE, FALSE, TRUE, 0); + sound_service_dbus_update_pa_state(dbus_service, FALSE, TRUE, 0); pa_server_available = FALSE; return; } @@ -548,10 +551,10 @@ static void context_state_callback(pa_context *c, void *userdata) case PA_CONTEXT_FAILED: g_warning("PA_CONTEXT_FAILED - Is PulseAudio Daemon running ?"); pa_server_available = FALSE; - dbus_menu_manager_update_pa_state(TRUE, - pa_server_available, - default_sink_is_muted(), - get_default_sink_volume()); + sound_service_dbus_update_pa_state( dbus_service, + pa_server_available, + default_sink_is_muted(), + get_default_sink_volume() ); if (reconnect_idle_id == 0){ reconnect_idle_id = g_timeout_add_seconds (RECONNECT_DELAY, 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); } diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index b0e6dd3..127ede2 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -52,11 +52,14 @@ struct _SoundServiceDbusClass { GType sound_service_dbus_get_type (void) G_GNUC_CONST; -// Utility methods to get the SIGNAL messages across into the sound-service-dbus -void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gboolean block_value); -void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); -void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, gboolean sink_availibity); -DbusmenuMenuitem* sound_service_dbus_construct_menu (SoundServiceDbus* self); +DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self); +void sound_service_dbus_update_sound_state (SoundServiceDbus* self, SoundState new_state); +void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, gboolean sink_mute); +void sound_service_dbus_update_volume(SoundServiceDbus* self, gdouble volume); +void sound_service_dbus_update_pa_state ( SoundServiceDbus* root, + gboolean availability, + gboolean mute_update, + gdouble volume ); G_END_DECLS diff --git a/src/sound-service.c b/src/sound-service.c index 73b03b6..e72a917 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -66,7 +66,7 @@ main (int argc, char ** argv) SoundServiceDbus* sound_service = g_object_new(SOUND_SERVICE_DBUS_TYPE, NULL); - DbusmenuMenuitem* root_menuitem = sound_service_dbus_construct_menu(sound_service); + DbusmenuMenuitem* root_menuitem = sound_service_dbus_create_root_item(sound_service); MusicPlayerBridge* server = music_player_bridge_new(); music_player_bridge_set_root_menu_item(server, root_menuitem); -- 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/common-defs.h | 10 ++++----- src/dbus-shared-names.h | 5 ++--- src/indicator-sound.c | 2 +- src/pulse-manager.c | 12 ++++++----- src/sound-service-dbus.c | 54 +++++++++++++++++++++++++++++++++++++++++------- src/sound-service-dbus.h | 1 + src/sound-service.xml | 32 ++-------------------------- 7 files changed, 64 insertions(+), 52 deletions(-) (limited to 'src/pulse-manager.c') diff --git a/src/common-defs.h b/src/common-defs.h index 5b5c418..3e6b004 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -16,14 +16,10 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef __COMMON_DEFS_H__ +#define __COMMON_DEFS_H__ -/* constants used for signals on the dbus. This file is shared between client and server implementation */ -#define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" -#define SIGNAL_SINK_VOLUME_UPDATE "SinkVolumeUpdate" -#define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" -#define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" - typedef enum { MUTED, ZERO_LEVEL, @@ -67,3 +63,5 @@ typedef enum { #define DBUSMENU_PLAYLISTS_MENUITEM_TYPE "x-canonical-sound-menu-player-playlists-type" #define DBUSMENU_PLAYLISTS_MENUITEM_TITLE "x-canonical-sound-menu-player-playlists-title" #define DBUSMENU_PLAYLISTS_MENUITEM_PLAYLISTS "x-canonical-sound-menu-player-playlists-playlists" + +#endif diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index bdc40cb..b90d7a2 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -30,9 +30,8 @@ with this program. If not, see . #define INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH "/com/canonical/indicators/sound/service" #define INDICATOR_SOUND_DBUS_INTERFACE "com.canonical.indicators.sound" #define INDICATOR_SOUND_DBUS_VERSION 0 -#define INDICATOR_SOUND_SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" -#define INDICATOR_SOUND_SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" -#define INDICATOR_SOUND_SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" + +#define INDICATOR_SOUND_SIGNAL_SOUND_STATE_UPDATE "SoundStateUpdate" #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3867f27..e0d2209 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -636,7 +636,7 @@ void determine_state_from_volume(gdouble volume_percent) { if (device_available == FALSE) - return; +v return; gint state = previous_state; if (volume_percent < 30.0 && volume_percent > 0) { state = STATE_LOW; diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 21b78b2..40bfc13 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -199,10 +199,12 @@ static void check_sink_input_while_muted_event(gint sink_index) /* g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER - check trace for value");*/ if (default_sink_is_muted(sink_index) == TRUE) { - sound_service_dbus_sink_input_while_muted(dbus_service, TRUE); - } else { - sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); + sound_service_dbus_update_sound_state(dbus_service, BLOCKED); } +// Why do you need to send a false for a blocked event, it times out after 5 secs anyway +//} else { + // sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); + //} } static gdouble get_default_sink_volume() @@ -437,7 +439,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v value->base_volume = info->base_volume; g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value); /* g_debug("pulse-manager:update_sink_info -> After adding a new sink to our hash");*/ - sound_service_dbus_update_sound_state(dbus_service, TRUE); + sound_service_dbus_update_sound_state(dbus_service, AVAILABLE); } } @@ -496,7 +498,7 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event case PA_SUBSCRIPTION_EVENT_SINK: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { if (index == DEFAULT_SINK_INDEX) - sound_service_dbus_update_sink_availability(dbus_service, FALSE); + sound_service_dbus_update_sound_state(dbus_service, UNAVAILABLE); /* g_debug("Subscribed_events_callback - removing sink of index %i from our sink hash - keep the cache tidy !", index);*/ g_hash_table_remove(sink_hash, GINT_TO_POINTER(index)); 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; } diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 127ede2..fab3549 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -23,6 +23,7 @@ #include #include #include +#include "common-defs.h" G_BEGIN_DECLS diff --git a/src/sound-service.xml b/src/sound-service.xml index 44ecc2b..07c9c3d 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -1,45 +1,17 @@ - - - - - - - - - - - - + - - - - - - - - + - - - - - - - - - -- 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/Makefile.am | 6 +++-- src/indicator-sound.c | 23 ++++++------------ src/pulse-manager.c | 1 - src/sound-service-dbus.c | 4 ++-- src/sound-state-manager.c | 61 ++++++++++++++++++++++++++++------------------- src/sound-state-manager.h | 4 ++-- 6 files changed, 51 insertions(+), 48 deletions(-) (limited to 'src/pulse-manager.c') diff --git a/src/Makefile.am b/src/Makefile.am index 667293f..b5c9fc3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,11 +9,13 @@ soundmenulib_LTLIBRARIES = libsoundmenu.la libsoundmenu_la_SOURCES = \ common-defs.h \ indicator-sound.h \ + indicator-sound.c \ + sound-state-manager.c \ + sound-state-manager.h \ transport-widget.c \ transport-widget.h \ metadata-widget.c \ metadata-widget.h \ - indicator-sound.c \ title-widget.c \ title-widget.h \ volume-widget.c \ @@ -22,7 +24,7 @@ libsoundmenu_la_SOURCES = \ gen-sound-service.xml.c \ dbus-shared-names.h -libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror -DG_LOG_DOMAIN=\"Indicator-Sound\" +libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -DG_LOG_DOMAIN=\"Indicator-Sound\" libsoundmenu_la_LIBADD = $(APPLET_LIBS) libsoundmenu_la_LDFLAGS = -module -avoid-version diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 97a4c07..b3f19bc 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -98,12 +98,6 @@ static void create_connection_to_service (GObject *source_object, 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 @@ -148,16 +142,12 @@ static void indicator_sound_dispose (GObject *object) { IndicatorSound * self = INDICATOR_SOUND(object); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); if (self->service != NULL) { g_object_unref(G_OBJECT(self->service)); self->service = NULL; } - g_hash_table_destroy(volume_states); - - free_the_animation_list(); - - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (self)); g_list_free ( priv->transport_widgets_list ); @@ -182,10 +172,10 @@ 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(speaker_image)); + //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 speaker_image; + return sound_state_manager_get_current_icon (priv->state_manager); } /* Indicator based function to get the menu for the whole @@ -742,10 +732,11 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) { //g_debug("indicator-sound-scroll - current slider value"); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + SoundState current_state = sound_state_manager_get_current_state (priv->state_manager); - if (device_available == FALSE || current_state == STATE_MUTED) + if (current_state == UNAVAILABLE || current_state == MUTED) return; - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 40bfc13..ca008a7 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -25,7 +25,6 @@ with this program. If not, see . #include #include "pulse-manager.h" -#include "dbus-menu-manager.h" #define RECONNECT_DELAY 5 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; diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 1eecaf0..bd2140a 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -18,10 +18,8 @@ with this program. If not, see . */ #include - #include "sound-state-manager.h" - typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate; // TODO ensure all the relevant below are initialized to null in init @@ -35,6 +33,7 @@ struct _SoundStateManagerPrivate }; #define SOUND_STATE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_TYPE_STATE_MANAGER, SoundStateManagerPrivate)) +G_DEFINE_TYPE (SoundStateManager, sound_state_manager, G_TYPE_OBJECT); static GtkIconSize design_team_size; static gint blocked_id; @@ -42,13 +41,12 @@ static gint animation_id; static GList* blocked_iter = NULL; static void sound_state_manager_prepare_blocked_animation(SoundStateManager* self); -static gboolean sound_state_manager_start_animation (SoundStateManager* self) -static gboolean sound_state_manager_fade_back_to_mute_image (gpointer user_data) +static gboolean sound_state_manager_start_animation (SoundStateManager* self); +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_mananger_free_the_animation_list (SoundStateManager* self); +static void sound_state_manager_free_the_animation_list (SoundStateManager* self); static void sound_state_manager_prepare_state_image_names (SoundStateManager* self); -G_DEFINE_TYPE (SoundStateManager, sound_state_manager, G_TYPE_OBJECT); static void sound_state_manager_init (SoundStateManager* self) @@ -59,8 +57,8 @@ sound_state_manager_init (SoundStateManager* self) sound_state_manager_prepare_blocked_animation (self); priv->current_state = UNAVAILABLE; - priv->speaker_image = indicator_image_helper(g_hash_table_lookup (priv->volume_states, - GINT_TO_POINTER(priv->current_state)); + priv->speaker_image = indicator_image_helper (g_hash_table_lookup (priv->volume_states, + GINT_TO_POINTER(priv->current_state))); } static void @@ -71,13 +69,27 @@ sound_state_manager_finalize (GObject *object) G_OBJECT_CLASS (sound_state_manager_parent_class)->finalize (object); } +static void +sound_state_manager_dispose (GObject *object) +{ + SoundStateManager* self = SOUND_STATE_MANAGER (object); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + g_hash_table_destroy (priv->volume_states); + + sound_state_manager_free_the_animation_list (self); + G_OBJECT_CLASS (sound_state_manager_parent_class)->dispose (object); +} + + static void sound_state_manager_class_init (SoundStateManagerClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - GObjectClass* parent_class = G_OBJECT_CLASS (klass); + //GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = sound_state_manager_finalize; + object_class->dispose = sound_state_manager_dispose; design_team_size = gtk_icon_size_register("design-team-size", 22, 22); } @@ -88,14 +100,14 @@ static void sound_state_manager_prepare_state_image_names (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); - priv->volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(MUTED), g_strdup("audio-volume-muted-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(ZERO_LEVEL), g_strdup("audio-volume-low-zero-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(LOW_LEVEL), g_strdup("audio-volume-low-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(MEDIUM_LEVEL), g_strdup("audio-volume-medium-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(HIGH_LEVEL), g_strdup("audio-volume-high-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(BLOCKED), g_strdup("audio-volume-muted-blocking-panel")); - g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(UNAVAILABLE), g_strdup("audio-output-none-panel")); + priv->volume_states = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(MUTED), g_strdup("audio-volume-muted-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(ZERO_LEVEL), g_strdup("audio-volume-low-zero-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(LOW_LEVEL), g_strdup("audio-volume-low-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(MEDIUM_LEVEL), g_strdup("audio-volume-medium-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(HIGH_LEVEL), g_strdup("audio-volume-high-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(BLOCKED), g_strdup("audio-volume-muted-blocking-panel")); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(UNAVAILABLE), g_strdup("audio-output-none-panel")); } /* @@ -169,7 +181,7 @@ sound_state_signal_cb ( GDBusProxy* proxy, g_variant_ref (parameters); GVariant *value = g_variant_get_child_value (parameters, 0); - gint update = g_variant_get_int (value); + gint update = g_variant_get_int32 (value); g_debug ( "!!! signal_cb with value %i", update); @@ -196,9 +208,8 @@ sound_state_manager_style_changed_cb(GtkWidget *widget, gpointer user_data) //g_debug("Just caught a style change event"); 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); - sound_state_manager_reset_mute_blocking_animation (self) - sound_state_mananger_free_the_animation_list (self); + sound_state_manager_reset_mute_blocking_animation (self); + sound_state_manager_free_the_animation_list (self); sound_state_manager_prepare_blocked_animation (self); } @@ -218,14 +229,14 @@ sound_state_manager_reset_mute_blocking_animation (SoundStateManager* self) } static void -sound_state_mananger_free_the_animation_list (SoundStateManager* self) +sound_state_manager_free_the_animation_list (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); if (priv->blocked_animation_list != NULL) { g_list_foreach (priv->blocked_animation_list, (GFunc)g_object_unref, NULL); g_list_free (priv->blocked_animation_list); - blocked_animation_list = NULL; + priv->blocked_animation_list = NULL; } } @@ -254,7 +265,7 @@ sound_state_manager_start_animation (SoundStateManager* self) static gboolean sound_state_manager_fade_back_to_mute_image (gpointer user_data) { - g_return_if_fail (SOUND_IS_STATE_MANAGER (user_data)); + g_return_val_if_fail (SOUND_IS_STATE_MANAGER (user_data), FALSE); SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE( SOUND_STATE_MANAGER (user_data) ); if (blocked_iter != NULL) { @@ -275,7 +286,7 @@ sound_state_manager_fade_back_to_mute_image (gpointer user_data) * between the indicator and the service. **/ void -sound_state_manager_connect_to_dbus (SoundStateManager* self, GDProxy* proxy) +sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); priv->dbus_proxy = proxy; diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h index 1799822..ef8fc40 100644 --- a/src/sound-state-manager.h +++ b/src/sound-state-manager.h @@ -20,7 +20,7 @@ with this program. If not, see . #ifndef _SOUND_STATE_MANAGER_H_ #define _SOUND_STATE_MANAGER_H_ -#include +#include #include "common-defs.h" G_BEGIN_DECLS @@ -51,7 +51,7 @@ void sound_state_manager_style_changed_cb (GtkWidget *widget, gpointer user_data GtkImage* sound_state_manager_get_current_icon (SoundStateManager* self); SoundState sound_state_manager_get_current_state (SoundStateManager* self); void sound_state_manager_connect_to_dbus (SoundStateManager* self, - GDProxy* proxy); + GDBusProxy* proxy); G_END_DECLS -- cgit v1.2.3 From 4e0d98ea31ff315c03d2a297af0743cd92acfedf Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 27 Jan 2011 16:10:48 -0600 Subject: sink automatically unmuted now when slider is manually changed in accordance with the spec revision, plus some tidy ups --- src/indicator-sound.c | 1 - src/mute-menu-item.c | 30 +++++++++++++++++------- src/mute-menu-item.h | 4 ++-- src/pulse-manager.c | 2 +- src/pulse-manager.h | 2 +- src/slider-menu-item.c | 9 +++---- src/sound-service-dbus.c | 60 ++++++++++++++++++++++++++++------------------- src/sound-service.xml | 1 + src/sound-state-manager.c | 3 +-- 9 files changed, 69 insertions(+), 43 deletions(-) (limited to 'src/pulse-manager.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3c65a90..42560c8 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -278,7 +278,6 @@ static void create_connection_to_service (GObject *source_object, g_error_free(error); return; } - 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); diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index 2f40177..f7f3824 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -43,7 +43,8 @@ static void mute_menu_item_set_global_mute_from_ui (gpointer user_data); G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, G_TYPE_OBJECT); -static void mute_menu_item_class_init (MuteMenuItemClass *klass) +static void +mute_menu_item_class_init (MuteMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -55,7 +56,8 @@ static void mute_menu_item_class_init (MuteMenuItemClass *klass) return; } -static void mute_menu_item_init (MuteMenuItem *self) +static void +mute_menu_item_init (MuteMenuItem *self) { g_debug("Building new Mute Menu Item"); MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self); @@ -68,7 +70,8 @@ static void mute_menu_item_init (MuteMenuItem *self) return; } -static void mute_menu_item_dispose (GObject *object) +static void +mute_menu_item_dispose (GObject *object) { G_OBJECT_CLASS (mute_menu_item_parent_class)->dispose (object); return; @@ -93,8 +96,8 @@ mute_menu_item_set_global_mute_from_ui (gpointer user_data) toggle_global_mute (new_value); } - -void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) +void +mute_menu_item_update (MuteMenuItem* item, gboolean value_update) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); @@ -106,7 +109,8 @@ void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) value_update == FALSE ? _("Mute") : _("Unmute")); } -void mute_menu_item_enable(MuteMenuItem* item, gboolean active) +void +mute_menu_item_enable (MuteMenuItem* item, gboolean active) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); @@ -115,13 +119,23 @@ void mute_menu_item_enable(MuteMenuItem* item, gboolean active) active); } -DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item) +DbusmenuMenuitem* +mute_menu_item_get_button (MuteMenuItem* item) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); return priv->button; } -MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled) +gboolean +mute_menu_item_is_muted (MuteMenuItem* item) +{ + MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); + return dbusmenu_menuitem_property_get_bool (priv->button, + DBUSMENU_MUTE_MENUITEM_VALUE); +} + +MuteMenuItem* +mute_menu_item_new (gboolean initial_update, gboolean enabled) { MuteMenuItem *self = g_object_new (MUTE_MENU_ITEM_TYPE, NULL); mute_menu_item_update (self, initial_update); diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h index 8240441..81a4b33 100644 --- a/src/mute-menu-item.h +++ b/src/mute-menu-item.h @@ -50,10 +50,10 @@ MuteMenuItem* mute_menu_item_new (); void mute_menu_item_update (MuteMenuItem* item, gboolean update); void mute_menu_item_enable (MuteMenuItem* item, gboolean active); +gboolean mute_menu_item_is_muted (MuteMenuItem* item); DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item); G_END_DECLS -#endif - +#endif \ No newline at end of file diff --git a/src/pulse-manager.c b/src/pulse-manager.c index ca008a7..457992b 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -183,7 +183,7 @@ static gboolean determine_sink_availability() return available; } -static gboolean default_sink_is_muted() +gboolean default_sink_is_muted() { if (DEFAULT_SINK_INDEX < 0) return FALSE; diff --git a/src/pulse-manager.h b/src/pulse-manager.h index dfe1256..5895aeb 100644 --- a/src/pulse-manager.h +++ b/src/pulse-manager.h @@ -40,6 +40,6 @@ void establish_pulse_activities(SoundServiceDbus *service); void set_sink_volume(gdouble percent); void toggle_global_mute(gboolean mute_value); void close_pulse_activites(); - +gboolean default_sink_is_muted(); #endif diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 64db277..a20bb00 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -81,12 +81,8 @@ handle_event (DbusmenuMenuitem * mi, GVariant * value, guint timestamp) { - /*g_debug ( "handle-event in the slider at the backend, input is of type %s", - g_variant_get_type_string(value));*/ - GVariant* input = NULL; input = value; - // Please note: Subject to change in future DBusmenu revisions if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT) == TRUE) { input = g_variant_get_variant(value); } @@ -94,6 +90,11 @@ handle_event (DbusmenuMenuitem * mi, gboolean volume_input = g_variant_get_double(input); if (value != NULL){ set_sink_volume(volume_input); + // TODO -when the ACTIVESINK instance exists this will be handled nicely + // PA MANAGER will be refactored first. + if (default_sink_is_muted () == TRUE){ + toggle_global_mute (FALSE); + } } } diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index b444a91..a532c0e 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, @@ -153,7 +154,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 +167,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 +212,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 +225,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 +270,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 +282,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 +295,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 +321,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 +345,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){ diff --git a/src/sound-service.xml b/src/sound-service.xml index 07c9c3d..18e47fc 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -4,6 +4,7 @@ + diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 2ea9b1a..e8865d8 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -193,7 +193,6 @@ 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 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); @@ -223,7 +222,7 @@ sound_state_manager_get_state_cb (GObject *object, &error ); if (error != NULL) { - g_debug("get_sound_state call failed: %s", error->message); + g_warning("get_sound_state call failed: %s", error->message); g_error_free(error); return; } -- cgit v1.2.3