From 5f1d857f263edd696fe1d9af793a26e9bbd5a6c3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 12 Jan 2011 12:44:27 -0600 Subject: moving towards an encapsulated mute --- src/Makefile.am | 2 + src/common-defs.h | 3 ++ src/mute-menu-item.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/mute-menu-item.h | 55 +++++++++++++++++++++++++ src/sound-service.c | 4 +- 5 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 src/mute-menu-item.c create mode 100644 src/mute-menu-item.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 32b6928..f880662 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -95,6 +95,8 @@ indicator_sound_service_SOURCES = \ sound-service-dbus.c \ slider-menu-item.h \ slider-menu-item.c \ + mute-menu-item.h \ + mute-menu-item.c \ gen-sound-service.xml.h \ gen-sound-service.xml.c \ $(music_bridge_VALASOURCES:.vala=.c) diff --git a/src/common-defs.h b/src/common-defs.h index 8ec69e8..c7d497a 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -30,6 +30,9 @@ with this program. If not, see . #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" #define DBUSMENU_VOLUME_MENUITEM_LEVEL "x-canonical-ido-volume-level" +#define DBUSMENU_MUTE_MENUITEM_TYPE "x-canonical-sound-menu-mute-type" +#define DBUSMENU_MUTE_MENUITEM_VALUE "x-canonical-sound-menu-mute-value" + #define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-sound-menu-player-transport-type" #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c new file mode 100644 index 0000000..bdb14a6 --- /dev/null +++ b/src/mute-menu-item.c @@ -0,0 +1,114 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +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 +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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 . +*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common-defs.h" +#include +#include "mute-menu-item.h" +#include "common-defs.h" + + +typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate; + +struct _MuteMenuItemPrivate { + gboolean mute_all; +}; + +#define MUTE_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_MENU_ITEM_TYPE, MuteMenuItemPrivate)) + +/* Prototypes */ +static void mute_menu_item_class_init (MuteMenuItemClass *klass); +static void mute_menu_item_init (MuteMenuItem *self); +static void mute_menu_item_dispose (GObject *object); +static void mute_menu_item_finalize (GObject *object); +static void handle_event (DbusmenuMenuitem * mi, const gchar * name, + GVariant * value, guint timestamp); + +G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, DBUSMENU_TYPE_MENUITEM); + +static void mute_menu_item_class_init (MuteMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (MuteMenuItemPrivate)); + + object_class->dispose = mute_menu_item_dispose; + object_class->finalize = mute_menu_item_finalize; + + DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); + mclass->handle_event = handle_event; + return; +} + +static void mute_menu_item_init (MuteMenuItem *self) +{ + g_debug("Building new Mute Menu Item"); + return; +} + +static void mute_menu_item_dispose (GObject *object) +{ + G_OBJECT_CLASS (mute_menu_item_parent_class)->dispose (object); + return; +} + +static void +mute_menu_item_finalize (GObject *object) +{ + G_OBJECT_CLASS (mute_menu_item_parent_class)->finalize (object); +} + + +static void +handle_event (DbusmenuMenuitem * mi, + const gchar * name, + GVariant * value, + guint timestamp) +{ + /*g_debug ( "handle-event in the mute at the backend, input is of type %s", + g_variant_get_type_string(value));*/ + + GVariant* input = NULL; + input = value; + g_variant_ref (input); + + // 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); + } + + gboolean mute_input = g_variant_get_boolean(input); + g_variant_unref (input); +} + +MuteMenuItem* mute_menu_item_new(gboolean sinks_available, gdouble start_volume) +{ + MuteMenuItem *self = g_object_new(MUTE_MENU_ITEM_TYPE, NULL); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MUTE_MENUITEM_TYPE); + + //dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); + //dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); + return self; +} + + + + diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h new file mode 100644 index 0000000..36f5e69 --- /dev/null +++ b/src/mute-menu-item.h @@ -0,0 +1,55 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +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 +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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 __MUTE_MENU_ITEM_H__ +#define __MUTE_MENU_ITEM_H__ + +#include +#include + +#include + +G_BEGIN_DECLS + +#define MUTE_MENU_ITEM_TYPE (mute_menu_item_get_type ()) +#define MUTE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MUTE_MENU_ITEM_TYPE, MuteMenuItem)) +#define MUTE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUTE_MENU_ITEM_TYPE, MuteMenuItemClass)) +#define IS_MUTE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MUTE_MENU_ITEM_TYPE)) +#define IS_MUTE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MUTE_MENU_ITEM_TYPE)) +#define MUTE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MUTE_MENU_ITEM_TYPE, MuteMenuItemClass)) + +typedef struct _MuteMenuItem MuteMenuItem; +typedef struct _MuteMenuItemClass MuteMenuItemClass; + +struct _MuteMenuItemClass { + DbusmenuMenuitemClass parent_class; +}; + +struct _MuteMenuItem { + DbusmenuMenuitem parent; +}; + +GType mute_menu_item_get_type (void); + +MuteMenuItem* mute_menu_item_new(); + +G_END_DECLS + +#endif + diff --git a/src/sound-service.c b/src/sound-service.c index 98f1881..defcb94 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 055df674f70f7961c6d47e3b031881e142f6dea8 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 12 Jan 2011 14:33:30 -0600 Subject: rf underway --- src/dbus-menu-manager.c | 71 ++++++++++++++++++++++++++++++++----------------- src/dbus-menu-manager.h | 2 +- src/mute-menu-item.c | 38 ++++++++++++++++++-------- src/mute-menu-item.h | 2 ++ 4 files changed, 77 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 92bfba5..8c255e3 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -1,5 +1,4 @@ /* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. Copyright 2010 Canonical Ltd. Authors: @@ -18,6 +17,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/** + *TODO: + * Makes this a proper GObject + **/ + #include #include @@ -28,19 +32,20 @@ with this program. If not, see . #include "sound-service-dbus.h" #include "pulse-manager.h" #include "slider-menu-item.h" +#include "mute-menu-item.h" + #include "common-defs.h" #include "dbus-shared-names.h" -// DBUS items +// DBUS related static DbusmenuMenuitem *root_menuitem = NULL; -static DbusmenuMenuitem *mute_all_menuitem = NULL; static SliderMenuItem *volume_slider_menuitem = NULL; +static MuteMenuItem *mute_menuitem = NULL; static SoundServiceDbus *dbus_interface = NULL; // PULSEAUDIO static gboolean b_sink_available = FALSE; -static gboolean b_all_muted = FALSE; static gboolean b_pulse_ready = FALSE; static gboolean b_startup = TRUE; static gdouble volume_percent = 0.0; @@ -48,7 +53,9 @@ static gdouble volume_percent = 0.0; static void set_global_mute_from_ui(); static gboolean idle_routine (gpointer data); static void rebuild_sound_menu(DbusmenuMenuitem *root, - SoundServiceDbus *service); + gboolean mute_update, + gboolean availability, + gdouble volume); static void refresh_menu(); @@ -86,10 +93,12 @@ void dbus_menu_manager_update_volume(gdouble volume) /** update_pa_state: **/ -void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_muted, gdouble percent) +void dbus_menu_manager_update_pa_state (gboolean pa_state, + gboolean sink_available, + gboolean sink_muted, + gdouble percent) { b_sink_available = sink_available; - b_all_muted = sink_muted; b_pulse_ready = pa_state; volume_percent = percent; g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent); @@ -114,8 +123,8 @@ update_mute_ui: **/ void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value) { - b_all_muted = incoming_mute_value; - dbusmenu_menuitem_property_set(mute_all_menuitem, + + dbusmenu_menuitem_property_set(DBUSMENUITEM(mute_all_menuitem), DBUSMENU_MENUITEM_PROP_LABEL, b_all_muted == FALSE ? _("Mute") : _("Unmute")); } @@ -181,36 +190,39 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data } /** -rebuild_sound_menu: -Build the DBus menu items, mute/unmute, slider, separator and sound preferences 'link' +build_sound_menu's default items (without the any player items): **/ -static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service) +static void build_sound_menu (DbusmenuMenuitem *root, + gboolean mute_update, + gboolean availability, + gdouble volume); + { // Mute button - mute_all_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, b_all_muted == FALSE ? _("Mute") : _("Unmute")); - g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute_from_ui), NULL); - dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available); + mute_all_menuitem = mute_menu_item_new ( mute_update, availability); + dbusmenu_menuitem_child_append(root, mute_all_menuitem); // Slider - volume_slider_menuitem = slider_menu_item_new(b_sink_available, volume_percent); - dbusmenu_menuitem_child_append(root, mute_all_menuitem); + volume_slider_menuitem = slider_menu_item_new(available, volume); dbusmenu_menuitem_child_append(root, DBUSMENU_MENUITEM(volume_slider_menuitem)); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available && !b_all_muted); - g_debug("!!!!!!**in the rebuild sound menu - slider active = %i", b_sink_available && !b_all_muted); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, b_sink_available); // Separator DbusmenuMenuitem *separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_property_set( separator, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); // Sound preferences dialog DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); + dbusmenu_menuitem_property_set( settings_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Sound Preferences...")); //_("Sound Preferences...")); dbusmenu_menuitem_child_append(root, settings_mi); @@ -226,9 +238,20 @@ static void set_global_mute_from_ui() { b_all_muted = !b_all_muted; toggle_global_mute(b_all_muted); - dbusmenu_menuitem_property_set(mute_all_menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - b_all_muted == FALSE ? _("Mute") : _("Unmute")); + dbusmenu_menuitem_property_set((DBUSMENU_MENUITEM)mute_all_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + b_all_muted == FALSE ? _("Mute") : _("Unmute")); +} + + +/* + TODO: use these temporary wrappers around pulsemanager for the short term + Until I get to the point where I can refactor it entirely. +*/ + +void dbmm_pa_wrapper_toggle_mute(gboolean update) +{ + toggle_global_mute (update); } diff --git a/src/dbus-menu-manager.h b/src/dbus-menu-manager.h index ec2b2e2..5b6544e 100644 --- a/src/dbus-menu-manager.h +++ b/src/dbus-menu-manager.h @@ -29,6 +29,6 @@ void dbus_menu_manager_update_volume(gdouble volume); void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_muted, gdouble current_vol); // TODO update pa_state should incorporate the method below ! void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value); - +void dbmm_pa_wrapper_toggle_mute(gboolean update); #endif diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index bdb14a6..bc96a2a 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -1,5 +1,5 @@ /* -Copyright 2010 Canonical Ltd. +Copyright 2011 Canonical Ltd. Authors: Conor Curran @@ -25,6 +25,7 @@ with this program. If not, see . #include "mute-menu-item.h" #include "common-defs.h" +#include "dbus-menu-manager.h" typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate; @@ -76,7 +77,6 @@ mute_menu_item_finalize (GObject *object) G_OBJECT_CLASS (mute_menu_item_parent_class)->finalize (object); } - static void handle_event (DbusmenuMenuitem * mi, const gchar * name, @@ -96,19 +96,35 @@ handle_event (DbusmenuMenuitem * mi, } gboolean mute_input = g_variant_get_boolean(input); + dbmm_pa_wrapper_toggle_mute (input); g_variant_unref (input); } -MuteMenuItem* mute_menu_item_new(gboolean sinks_available, gdouble start_volume) -{ - MuteMenuItem *self = g_object_new(MUTE_MENU_ITEM_TYPE, NULL); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MUTE_MENUITEM_TYPE); - - //dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); - //dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); - return self; +void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) +{ + dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(item), + DBUSMENU_MUTE_MENUITEM_VALUE, + update); + dbusmenu_menuitem_property_set (DBUSMENUITEM(item), + DBUSMENU_MENUITEM_PROP_LABEL, + update == FALSE ? _("Mute") : _("Unmute")); } +void mute_menu_item_enable(MuteMenuItem* item, gboolean active) +{ + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(item), + DBUSMENU_MENUITEM_PROP_ENABLED, + active); +} - +MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled) +{ + MuteMenuItem *self = g_object_new(MUTE_MENU_ITEM_TYPE, NULL); + dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(self), + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_MUTE_MENUITEM_TYPE); + mute_menu_item_enable (self, enabled); + mute_menu_item_update (self, initial_update); + return self; +} diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h index 36f5e69..d7232d0 100644 --- a/src/mute-menu-item.h +++ b/src/mute-menu-item.h @@ -49,6 +49,8 @@ GType mute_menu_item_get_type (void); MuteMenuItem* mute_menu_item_new(); +void mute_menu_item_update(MuteMenuItem* item, gboolean update); + G_END_DECLS #endif -- cgit v1.2.3 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/dbus-menu-manager.c | 204 ++++++++++++++++-------------------------------- src/dbus-menu-manager.h | 22 +++--- src/mute-menu-item.c | 16 ++-- src/mute-menu-item.h | 1 + src/pulse-manager.c | 2 +- src/slider-menu-item.c | 39 ++++++--- src/slider-menu-item.h | 8 +- src/sound-service.xml | 5 ++ 8 files changed, 125 insertions(+), 172 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 8c255e3..7de5844 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -22,6 +22,7 @@ with this program. If not, see . * Makes this a proper GObject **/ + #include #include @@ -44,24 +45,15 @@ static SliderMenuItem *volume_slider_menuitem = NULL; static MuteMenuItem *mute_menuitem = NULL; static SoundServiceDbus *dbus_interface = NULL; -// PULSEAUDIO -static gboolean b_sink_available = FALSE; -static gboolean b_pulse_ready = FALSE; static gboolean b_startup = TRUE; -static gdouble volume_percent = 0.0; -static void set_global_mute_from_ui(); static gboolean idle_routine (gpointer data); -static void rebuild_sound_menu(DbusmenuMenuitem *root, +static void build_sound_menu(DbusmenuMenuitem *root, gboolean mute_update, gboolean availability, gdouble volume); -static void refresh_menu(); - - -/*-------------------------------------------------------------------------*/ -// Public Methods -/*-------------------------------------------------------------------------*/ +static void show_sound_settings_dialog (DbusmenuMenuitem *mi, + gpointer user_data); /** setup: @@ -81,104 +73,96 @@ DbusmenuMenuitem* dbus_menu_manager_setup() return root_menuitem; } -void dbus_menu_manager_update_volume(gdouble volume) +/** +build_sound_menu's default items (without the any player items): +**/ +static void build_sound_menu (DbusmenuMenuitem *root, + gboolean mute_update, + gboolean availability, + gdouble volume) { - GVariant* new_volume = g_variant_new_double(volume); - dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_VOLUME_MENUITEM_LEVEL, - new_volume); + // Mute button + mute_menuitem = mute_menu_item_new ( mute_update, availability); + dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM(mute_menuitem)); + + // Slider + volume_slider_menuitem = slider_menu_item_new ( availability, volume ); + dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM ( 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(root, separator); + + // Sound preferences dialog + DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set( settings_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Sound Preferences...")); + + //_("Sound Preferences...")); + dbusmenu_menuitem_child_append(root, settings_mi); + g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_sound_settings_dialog), NULL); } - /** update_pa_state: **/ void dbus_menu_manager_update_pa_state (gboolean pa_state, - gboolean sink_available, + gboolean pulse_available, gboolean sink_muted, gdouble percent) { - b_sink_available = sink_available; - b_pulse_ready = pa_state; - volume_percent = percent; - g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent); - // Only rebuild the menu on start up... + g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, pulse_available, sink_muted, percent); + if (b_startup == TRUE) { - rebuild_sound_menu(root_menuitem, dbus_interface); + build_sound_menu(root_menuitem, sink_muted, pulse_available, percent); b_startup = FALSE; - } else { - refresh_menu(); + return; } + + mute_menu_item_update ( mute_menuitem, + sink_muted ); + slider_menu_item_update ( volume_slider_menuitem, + percent ); + + mute_menu_item_enable ( mute_menuitem, pulse_available); + slider_menu_item_enable ( volume_slider_menuitem, + pulse_available ); + // Emit the signals after the menus are setup/torn down // preserve ordering ! - sound_service_dbus_update_sink_availability(dbus_interface, sink_available); + /*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); + dbus_menu_manager_update_mute_ui(b_all_muted);*/ } /** update_mute_ui: 'public' method allowing the pa manager to update the mute menu item. + These are wrappers until we figure out this refactor **/ -void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value) -{ - - dbusmenu_menuitem_property_set(DBUSMENUITEM(mute_all_menuitem), - DBUSMENU_MENUITEM_PROP_LABEL, - b_all_muted == FALSE ? _("Mute") : _("Unmute")); +void dbus_menu_manager_update_mute(gboolean incoming_mute_value) +{ + mute_menu_item_update (mute_menuitem, incoming_mute_value); } - -/*-------------------------------------------------------------------------*/ -// Private Methods -/*-------------------------------------------------------------------------*/ -static void refresh_menu() -{ - g_debug("in the refresh menu method"); - if (b_sink_available == FALSE || b_pulse_ready == FALSE) { - - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_ENABLED, - FALSE); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_VISIBLE, - FALSE); - dbusmenu_menuitem_property_set_bool(mute_all_menuitem, - DBUSMENU_MENUITEM_PROP_ENABLED, - FALSE); - - } else if (b_sink_available == TRUE && b_pulse_ready == TRUE) { - - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_ENABLED, - TRUE); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_VISIBLE, - TRUE); - dbusmenu_menuitem_property_set_bool(mute_all_menuitem, - DBUSMENU_MENUITEM_PROP_ENABLED, - TRUE); - } -} - - -/** -idle_routine: -Something for glip mainloop to do when idle -**/ -static gboolean idle_routine (gpointer data) +void dbus_menu_manager_update_volume(gdouble volume) { - return FALSE; + slider_menu_item_update (volume_slider_menuitem, volume); } - /** 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) && @@ -190,68 +174,12 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data } /** -build_sound_menu's default items (without the any player items): -**/ -static void build_sound_menu (DbusmenuMenuitem *root, - gboolean mute_update, - gboolean availability, - gdouble volume); - -{ - // Mute button - mute_all_menuitem = mute_menu_item_new ( mute_update, availability); - dbusmenu_menuitem_child_append(root, mute_all_menuitem); - - // Slider - volume_slider_menuitem = slider_menu_item_new(available, volume); - dbusmenu_menuitem_child_append(root, DBUSMENU_MENUITEM(volume_slider_menuitem)); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_ENABLED, - b_sink_available && !b_all_muted); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), - DBUSMENU_MENUITEM_PROP_VISIBLE, - b_sink_available); - // Separator - DbusmenuMenuitem *separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set( separator, - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - - // Sound preferences dialog - DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set( settings_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Sound Preferences...")); - - //_("Sound Preferences...")); - dbusmenu_menuitem_child_append(root, settings_mi); - g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_sound_settings_dialog), NULL); -} - -/** -set_global_mute_from_ui: -Callback for the dbusmenuitem button +TODO: what are you doing with this +idle_routine: +Something for glip mainloop to do when idle **/ -static void set_global_mute_from_ui() -{ - b_all_muted = !b_all_muted; - toggle_global_mute(b_all_muted); - dbusmenu_menuitem_property_set((DBUSMENU_MENUITEM)mute_all_menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - b_all_muted == FALSE ? _("Mute") : _("Unmute")); -} - - -/* - TODO: use these temporary wrappers around pulsemanager for the short term - Until I get to the point where I can refactor it entirely. -*/ - -void dbmm_pa_wrapper_toggle_mute(gboolean update) +static gboolean idle_routine (gpointer data) { - toggle_global_mute (update); + return FALSE; } - diff --git a/src/dbus-menu-manager.h b/src/dbus-menu-manager.h index 5b6544e..27976b3 100644 --- a/src/dbus-menu-manager.h +++ b/src/dbus-menu-manager.h @@ -1,10 +1,7 @@ #ifndef __INCLUDE_DBUS_MENU_MANAGER_H__ #define __INCLUDE_DBUS_MENU_MANAGER_H__ -#include - /* -This handles the management of the dbusmeneu items. Copyright 2010 Canonical Ltd. Authors: @@ -23,12 +20,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + +// Entry point DbusmenuMenuitem* dbus_menu_manager_setup(); -void dbus_menu_manager_teardown(); -void dbus_menu_manager_update_volume(gdouble volume); -void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_muted, gdouble current_vol); -// TODO update pa_state should incorporate the method below ! -void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value); -void dbmm_pa_wrapper_toggle_mute(gboolean update); + +void dbus_menu_manager_update_pa_state (gboolean pa_state, + gboolean sink_available, + gboolean sink_muted, + gdouble current_vol); + +// Temporary wrappers on the pulsemanager inward calls +// until the refactor is complete +void dbus_menu_manager_update_mute (gboolean incoming_mute_value); +void dbus_menu_manager_update_volume (gdouble volume); #endif diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index bc96a2a..9e79dd1 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -23,14 +23,11 @@ with this program. If not, see . #include "common-defs.h" #include #include "mute-menu-item.h" -#include "common-defs.h" - -#include "dbus-menu-manager.h" +#include "pulse-manager.h" typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate; struct _MuteMenuItemPrivate { - gboolean mute_all; }; #define MUTE_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_MENU_ITEM_TYPE, MuteMenuItemPrivate)) @@ -96,7 +93,8 @@ handle_event (DbusmenuMenuitem * mi, } gboolean mute_input = g_variant_get_boolean(input); - dbmm_pa_wrapper_toggle_mute (input); + // TODO: use the pulse wrapper directly + toggle_global_mute (mute_input); g_variant_unref (input); } @@ -104,10 +102,10 @@ void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) { dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(item), DBUSMENU_MUTE_MENUITEM_VALUE, - update); - dbusmenu_menuitem_property_set (DBUSMENUITEM(item), + value_update); + dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(item), DBUSMENU_MENUITEM_PROP_LABEL, - update == FALSE ? _("Mute") : _("Unmute")); + value_update == FALSE ? _("Mute") : _("Unmute")); } void mute_menu_item_enable(MuteMenuItem* item, gboolean active) @@ -124,7 +122,7 @@ MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled) dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MUTE_MENUITEM_TYPE); - mute_menu_item_enable (self, enabled); mute_menu_item_update (self, initial_update); + mute_menu_item_enable (self, enabled); return self; } diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h index d7232d0..1432de1 100644 --- a/src/mute-menu-item.h +++ b/src/mute-menu-item.h @@ -50,6 +50,7 @@ GType mute_menu_item_get_type (void); MuteMenuItem* mute_menu_item_new(); void mute_menu_item_update(MuteMenuItem* item, gboolean update); +void mute_menu_item_enable(MuteMenuItem* item, gboolean active); G_END_DECLS 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; diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 0f2f07b..d41ff85 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -29,7 +29,6 @@ with this program. If not, see . typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate; struct _SliderMenuItemPrivate { - gdouble slider_value; }; #define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate)) @@ -76,14 +75,12 @@ slider_menu_item_finalize (GObject *object) G_OBJECT_CLASS (slider_menu_item_parent_class)->finalize (object); } - static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp) { - gdouble volume_input = 0; /*g_debug ( "handle-event in the slider at the backend, input is of type %s", g_variant_get_type_string(value));*/ @@ -96,25 +93,41 @@ handle_event (DbusmenuMenuitem * mi, input = g_variant_get_variant(value); } - volume_input = g_variant_get_double(input); + gboolean volume_input = g_variant_get_double(input); if (value != NULL){ set_sink_volume(volume_input); } g_variant_unref (input); } +void slider_menu_item_update (SliderMenuItem* item, + gdouble update) +{ + // TODO + // Check if that variant below will leak !!! + GVariant* new_volume = g_variant_new_double(update); + dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(item), + DBUSMENU_VOLUME_MENUITEM_LEVEL, + new_volume); +} +void slider_menu_item_enable (SliderMenuItem* item, + gboolean active) +{ + dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item), + DBUSMENU_MENUITEM_PROP_ENABLED, + active ); +} -SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_volume) +SliderMenuItem* slider_menu_item_new (gboolean sinks_available, + gdouble start_volume) { SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_VOLUME_MENUITEM_TYPE); + dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self), + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_VOLUME_MENUITEM_TYPE ); + slider_menu_item_update (self, start_volume); + slider_menu_item_enable (self, sinks_available); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); return self; -} - - - - +} \ No newline at end of file diff --git a/src/slider-menu-item.h b/src/slider-menu-item.h index 763944f..51336ae 100644 --- a/src/slider-menu-item.h +++ b/src/slider-menu-item.h @@ -45,8 +45,12 @@ struct _SliderMenuItem { }; GType slider_menu_item_get_type (void); -// TODO for now the volume percent param is not being used - remove once init mystery is solved -SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble current_vol); + +void slider_menu_item_update(SliderMenuItem* item, gdouble update); +void slider_menu_item_enable(SliderMenuItem* item, gboolean active); + +SliderMenuItem* slider_menu_item_new (gboolean sinks_available, + gdouble current_vol); G_END_DECLS diff --git a/src/sound-service.xml b/src/sound-service.xml index a552d52..da3ac18 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -6,6 +6,11 @@ + + + + + -- cgit v1.2.3 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/pulse-manager.h | 3 --- src/sound-service-dbus.c | 31 ++++++++++++++++++++++++++----- src/sound-service-dbus.h | 4 +++- src/sound-service.c | 10 ++++++---- src/sound-service.h | 3 --- src/sound-service.xml | 9 +++++++++ 6 files changed, 44 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/pulse-manager.h b/src/pulse-manager.h index fc01f1c..dfe1256 100644 --- a/src/pulse-manager.h +++ b/src/pulse-manager.h @@ -1,9 +1,6 @@ #ifndef __INCLUDE_PULSE_MANAGER_H__ #define __INCLUDE_PULSE_MANAGER_H__ /* -A small wrapper utility to load indicators and put them as menu items -into the gnome-panel using it's applet interface. - Copyright 2010 Canonical Ltd. Authors: 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) { diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 0d1573b..b0e6dd3 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -3,7 +3,6 @@ * * Authors: * Conor Curran - * Cody Russell * * 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 @@ #include #include +#include + G_BEGIN_DECLS @@ -55,6 +56,7 @@ GType sound_service_dbus_get_type (void) G_GNUC_CONST; 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); G_END_DECLS diff --git a/src/sound-service.c b/src/sound-service.c index defcb94..73b03b6 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -1,5 +1,4 @@ /* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. Copyright 2010 Canonical Ltd. Authors: @@ -19,8 +18,9 @@ with this program. If not, see . */ #include "sound-service.h" -#include "dbus-menu-manager.h" -#include "pulse-manager.h" +//#include "dbus-menu-manager.h" +//#include "pulse-manager.h" +#include "sound-service-dbus.h" #include "music-player-bridge.h" static GMainLoop *mainloop = NULL; @@ -64,7 +64,9 @@ main (int argc, char ** argv) INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), NULL); - DbusmenuMenuitem* root_menuitem = dbus_menu_manager_setup(); + SoundServiceDbus* sound_service = g_object_new(SOUND_SERVICE_DBUS_TYPE, NULL); + + DbusmenuMenuitem* root_menuitem = sound_service_dbus_construct_menu(sound_service); MusicPlayerBridge* server = music_player_bridge_new(); music_player_bridge_set_root_menu_item(server, root_menuitem); diff --git a/src/sound-service.h b/src/sound-service.h index e95d4c7..7c5d0c3 100644 --- a/src/sound-service.h +++ b/src/sound-service.h @@ -2,13 +2,10 @@ #define __INCLUDE_SOUND_SERVICE_H__ /* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. Copyright 2010 Canonical Ltd. Authors: Conor Curran - Ted Gould - Cody Russell 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 diff --git a/src/sound-service.xml b/src/sound-service.xml index da3ac18..44ecc2b 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -16,12 +16,21 @@ + + + + + + + + + -- 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') 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') 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 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/indicator-sound.c | 138 +++++------------------------------ src/sound-service-dbus.c | 6 +- src/sound-state-manager.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++ src/sound-state-manager.h | 53 ++++++++++++++ 4 files changed, 252 insertions(+), 123 deletions(-) create mode 100644 src/sound-state-manager.c create mode 100644 src/sound-state-manager.h (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index e0d2209..33e1d60 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -1,12 +1,8 @@ /* -A small wrapper utility to load indicators and put them as menu items -into the gnome-panel using it's applet interface. - Copyright 2010 Canonical Ltd. 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 @@ -20,6 +16,7 @@ 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 . */ + #include #include #include @@ -40,6 +37,7 @@ with this program. If not, see . #include "gen-sound-service.xml.h" #include "common-defs.h" +#include "sound-state-manager.h" typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; @@ -115,33 +113,9 @@ static void get_sink_availability_cb ( GObject *object, /****Volume States 'members' ***/ static void update_state(const gint state); -static const gint STATE_MUTED = 0; -static const gint STATE_ZERO = 1; -static const gint STATE_LOW = 2; -static const gint STATE_MEDIUM = 3; -static const gint STATE_HIGH = 4; -static const gint STATE_MUTED_WHILE_INPUT = 5; -static const gint STATE_SINKS_NONE = 6; - -static GHashTable *volume_states = NULL; -static GtkImage *speaker_image = NULL; -static gint current_state = 0; -static gint previous_state = 0; - static gboolean initial_mute ; static gboolean device_available; -static GtkIconSize design_team_size; -static gint blocked_id; -static gint animation_id; - -static GList * blocked_animation_list = NULL; -static GList * blocked_iter = NULL; -static void prepare_blocked_animation(); -static gboolean fade_back_to_mute_image(); -static gboolean start_animation(); -static void reset_mute_blocking_animation(); -static void free_the_animation_list(); static void @@ -170,7 +144,6 @@ indicator_sound_init (IndicatorSound *self) self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); - prepare_state_machine(); prepare_blocked_animation(); animation_id = 0; blocked_id = 0; @@ -226,11 +199,12 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - gchar* current_name = g_hash_table_lookup(volume_states, - GINT_TO_POINTER(current_state)); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + // TODO query the sound state manager for the current relevant image + //g_debug("At start-up attempting to set the image to %s", // current_name); - speaker_image = indicator_image_helper(current_name); + speaker_image = indicator_image_helper(sound_state_manager_get_current_icon_name(priv->sound_state_manager)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; @@ -377,7 +351,7 @@ connection_changed (IndicatorServiceManager * sm, GError *error = NULL; if (connected == FALSE){ - update_state (STATE_SINKS_NONE); + //update_state (STATE_SINKS_NONE); return; //TODO: Gracefully handle disconnection // do a timeout to wait for reconnection @@ -388,7 +362,7 @@ connection_changed (IndicatorServiceManager * sm, // we don't need to anything, gdbus takes care of the rest - bless. // just fetch the state. if (priv->dbus_proxy != NULL){ - fetch_state (indicator); + //fetch_state (indicator); return; } @@ -440,14 +414,16 @@ static void create_connection_to_service (GObject *source_object, g_error_free(error); return; } - + + priv->sound_state_manager = sound_state_manager_new(priv->dbus_proxy); + g_signal_connect(priv->dbus_proxy, "g-signal", G_CALLBACK(g_signal_cb), self); fetch_state (self); } -static void fetch_state (IndicatorSound* self) +/*static void fetch_state (IndicatorSound* self) { IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); @@ -541,61 +517,9 @@ static void get_sink_mute_cb ( GObject *object, g_variant_unref(value); g_variant_unref(result); -} - -/* -Prepare states Array. -*/ -void -prepare_state_machine() -{ - volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-low-zero-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel")); -} - -/* -prepare_blocked_animation: -Prepares the array of images to be used in the blocked animation. -Only called at startup. -*/ -static void -prepare_blocked_animation() -{ - gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); - gchar* muted_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)); +}*/ - GtkImage* temp_image = indicator_image_helper(muted_name); - GdkPixbuf* mute_buf = gtk_image_get_pixbuf(temp_image); - temp_image = indicator_image_helper(blocked_name); - GdkPixbuf* blocked_buf = gtk_image_get_pixbuf(temp_image); - - if (mute_buf == NULL || blocked_buf == NULL) { - //g_debug("Don bother with the animation, the theme aint got the goods !"); - return; - } - - int i; - - // sample 51 snapshots - range : 0-256 - for (i = 0; i < 51; i++) { - gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, - gdk_pixbuf_get_width(mute_buf), - gdk_pixbuf_get_height(mute_buf), - 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5)); - blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); - } - g_object_ref_sink(mute_buf); - g_object_unref(mute_buf); - g_object_ref_sink(blocked_buf); - g_object_unref(blocked_buf); -} gint get_state() @@ -632,24 +556,6 @@ update_state(const gint state) } -void -determine_state_from_volume(gdouble volume_percent) -{ - if (device_available == FALSE) -v return; - gint state = previous_state; - if (volume_percent < 30.0 && volume_percent > 0) { - state = STATE_LOW; - } else if (volume_percent < 70.0 && volume_percent >= 30.0) { - state = STATE_MEDIUM; - } else if (volume_percent >= 70.0) { - state = STATE_HIGH; - } else if (volume_percent == 0.0) { - state = STATE_ZERO; - } - update_state(state); -} - static gboolean start_animation() @@ -694,7 +600,7 @@ reset_mute_blocking_animation() /*******************************************************************/ // DBUS Signal reactions /*******************************************************************/ -static void g_signal_cb ( GDBusProxy* proxy, +/*static void g_signal_cb ( GDBusProxy* proxy, gchar* sender_name, gchar* signal_name, GVariant* parameters, @@ -731,12 +637,12 @@ react_to_signal_sink_input_while_muted(gboolean block_value, IndicatorSound* sel 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 +/*static void react_to_signal_sink_mute_update(gboolean mute_value, IndicatorSound* self) { if (mute_value == TRUE && device_available == TRUE) { @@ -771,7 +677,7 @@ react_to_signal_sink_availability_update(gboolean available_value, IndicatorSoun 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 /******************************************************************/ @@ -930,16 +836,6 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) return digested; } -static void -style_changed_cb(GtkWidget *widget, gpointer user_data) -{ - //g_debug("Just caught a style change event"); - update_state(current_state); - reset_mute_blocking_animation(); - update_state(current_state); - free_the_animation_list(); - prepare_blocked_animation(); -} static void indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) 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, diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c new file mode 100644 index 0000000..a2121ad --- /dev/null +++ b/src/sound-state-manager.c @@ -0,0 +1,178 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran + +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 +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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 . +*/ + +#include "sound-state-manager.h" + +typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate; + +struct _SoundStateManagerPrivate +{ + GDBusProxy* dbus_proxy; + GHashTable* volume_states; + GList* blocked_animation_list; +}; + +#define SOUND_STATE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_TYPE_STATE_MANAGER, SoundStateManagerPrivate)) + +static GtkImage *speaker_image = NULL; +static gint current_state = 0; +static gint previous_state = 0; +static GtkIconSize design_team_size; +static gint blocked_id; +static gint animation_id; + +static GList * blocked_animation_list = NULL; +static GList * blocked_iter = NULL; +static void prepare_blocked_animation(); +static gboolean fade_back_to_mute_image(); +static gboolean start_animation(); +static void reset_mute_blocking_animation(); +static void free_the_animation_list(); + +G_DEFINE_TYPE (SoundStateManager, sound_state_manager, G_TYPE_OBJECT); + +static void +sound_state_manager_init (SoundStateManager *object) +{ + /* TODO: Add initialization code here */ +} + +static void +sound_state_manager_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + + G_OBJECT_CLASS (sound_state_manager_parent_class)->finalize (object); +} + +static void +sound_state_manager_class_init (SoundStateManagerClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sound_state_manager_finalize; +} + +/* +Prepare states Array. +*/ +void +sound_state_manager_prepare_state_machine(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")); +} + +/* +prepare_blocked_animation: +Prepares the array of images to be used in the blocked animation. +Only called at startup. +*/ +static void +sound_state_manager_prepare_blocked_animation(SoundStateManager* self) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + gchar* blocked_name = g_hash_table_lookup(priv->volume_states, + GINT_TO_POINTER(BLOCKED)); + gchar* muted_name = g_hash_table_lookup(priv->volume_states, + GINT_TO_POINTER(MUTED)); + + GtkImage* temp_image = indicator_image_helper(muted_name); + GdkPixbuf* mute_buf = gtk_image_get_pixbuf(temp_image); + + temp_image = indicator_image_helper(blocked_name); + GdkPixbuf* blocked_buf = gtk_image_get_pixbuf(temp_image); + + if (mute_buf == NULL || blocked_buf == NULL) { + //g_debug("Don bother with the animation, the theme aint got the goods !"); + return; + } + + int i; + + // sample 51 snapshots - range : 0-256 + for (i = 0; i < 51; i++) { + gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, + gdk_pixbuf_get_width(mute_buf), + gdk_pixbuf_get_height(mute_buf), + 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5)); + priv->blocked_animation_list = g_list_append(priv->blocked_animation_list, + gdk_pixbuf_copy(blocked_buf)); + } + g_object_ref_sink(mute_buf); + g_object_unref(mute_buf); + g_object_ref_sink(blocked_buf); + g_object_unref(blocked_buf); +} + +void +sound_state_manager_tidy_up_hash() +{ + g_hash_table_destroy(volume_states); +} + +gchar* +sound_state_manager_get_current_icon_name (SoundStateManager* self) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + return g_hash_table_lookup (priv->volume_states, + GINT_TO_POINTER(priv->current_state)); + +} + +static void g_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data) +{ +} + +static void +sound_state_manager_style_changed_cb(GtkWidget *widget, gpointer user_data) +{ + //g_debug("Just caught a style change event"); + update_state(current_state); + reset_mute_blocking_animation(); + update_state(current_state); + free_the_animation_list(); + prepare_blocked_animation(); +} + +/** + * volume_widget_new: + * @returns: a new #VolumeWidget. + **/ +SoundStateManager* +sound_state_manager_new (GDProxy* proxy) +{ + SoundStateManager* manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(manager); + priv->dbus_proxy = proxy; + return manager; +} diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h new file mode 100644 index 0000000..5f26682 --- /dev/null +++ b/src/sound-state-manager.h @@ -0,0 +1,53 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran + +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 +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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 _SOUND_STATE_MANAGER_H_ +#define _SOUND_STATE_MANAGER_H_ + +#include + +G_BEGIN_DECLS + +#define SOUND_TYPE_STATE_MANAGER (sound_state_manager_get_type ()) +#define SOUND_STATE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUND_TYPE_STATE_MANAGER, SoundStateManager)) +#define SOUND_STATE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUND_TYPE_STATE_MANAGER, SoundStateManagerClass)) +#define SOUND_IS_STATE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUND_TYPE_STATE_MANAGER)) +#define SOUND_IS_STATE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOUND_TYPE_STATE_MANAGER)) +#define SOUND_STATE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUND_TYPE_STATE_MANAGER, SoundStateManagerClass)) + +typedef struct _SoundStateManagerClass SoundStateManagerClass; +typedef struct _SoundStateManager SoundStateManager; + +struct _SoundStateManagerClass +{ + GObjectClass parent_class; +}; + +struct _SoundStateManager +{ + GObject parent_instance; +}; + +GType sound_state_manager_get_type (void) G_GNUC_CONST; +void sound_state_manager_prepare_state_machine(SoundStateManager* self); +SoundStateManager* sound_state_manager_new (GDProxy* proxy); +gchar* sound_state_manager_get_current_icon_name (SoundStateManager* self); +G_END_DECLS + +#endif /* _SOUND_STATE_MANAGER_H_ */ -- cgit v1.2.3 From 49df0fb3ea29693bdb8decf51f4da055c8e1a7cb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 16:26:21 -0600 Subject: indicator side almost up and going --- src/common-defs.h | 4 +- src/indicator-sound.c | 361 +++++++++++++++++----------------------------- src/indicator-sound.h | 1 - src/sound-state-manager.c | 191 ++++++++++++++++++------ src/sound-state-manager.h | 11 +- 5 files changed, 290 insertions(+), 278 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 3e6b004..5458dc5 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -38,8 +38,8 @@ typedef enum { #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" #define DBUSMENU_VOLUME_MENUITEM_LEVEL "x-canonical-ido-volume-level" -#define DBUSMENU_MUTE_MENUITEM_TYPE "x-canonical-sound-menu-mute-type" -#define DBUSMENU_MUTE_MENUITEM_VALUE "x-canonical-sound-menu-mute-value" +#define DBUSMENU_MUTE_MENUITEM_TYPE "x-canonical-sound-menu-mute-type" +#define DBUSMENU_MUTE_MENUITEM_VALUE "x-canonical-sound-menu-mute-value" #define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-sound-menu-player-transport-type" #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 33e1d60..97a4c07 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -45,7 +45,8 @@ struct _IndicatorSoundPrivate { GtkWidget* volume_widget; GList* transport_widgets_list; - GDBusProxy *dbus_proxy; + GDBusProxy *dbus_proxy; + SoundStateManager* state_manager; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -65,18 +66,27 @@ G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE); static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); -static void indicator_sound_scroll (IndicatorObject* io, gint delta, IndicatorScrollDirection direction); +static void indicator_sound_scroll (IndicatorObject* io, + gint delta, + IndicatorScrollDirection direction); -//Slider related -static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +//key/moust event handlers static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); static gboolean key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); -static void style_changed_cb(GtkWidget *widget, gpointer user_data); -//player widget realisation methods -static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +//custom widget realisation methods +static gboolean new_volume_slider_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client); +static gboolean new_transport_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client); +static gboolean new_metadata_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client); +static gboolean new_title_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client); // DBUS communication @@ -94,28 +104,6 @@ static void g_signal_cb ( GDBusProxy* proxy, GVariant* parameters, gpointer user_data); -static void react_to_signal_sink_input_while_muted (gboolean value, - IndicatorSound* self); -static void react_to_signal_sink_mute_update (gboolean value, - IndicatorSound* self); -static void react_to_signal_sink_availability_update (gboolean value, - IndicatorSound* self); -static void fetch_state ( IndicatorSound* self ); - -static void get_sink_mute_cb ( GObject *object, - GAsyncResult *res, - gpointer user_data ); - -static void get_sink_availability_cb ( GObject *object, - GAsyncResult *res, - gpointer user_data ); - -/****Volume States 'members' ***/ -static void update_state(const gint state); - -static gboolean initial_mute ; -static gboolean device_available; - static void @@ -134,7 +122,6 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_image = get_icon; io_class->get_menu = get_menu; io_class->scroll = indicator_sound_scroll; - design_team_size = gtk_icon_size_register("design-team-size", 22, 22); } static void @@ -143,22 +130,18 @@ indicator_sound_init (IndicatorSound *self) self->service = NULL; self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); - - prepare_blocked_animation(); - animation_id = 0; - blocked_id = 0; - initial_mute = FALSE; - device_available = TRUE; IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); priv->volume_widget = NULL; priv->dbus_proxy = NULL; GList* t_list = NULL; priv->transport_widgets_list = t_list; + // create our state manager which will handle all icon changing etc. + priv->state_manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); - g_signal_connect(G_OBJECT(self->service), - INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, - G_CALLBACK(connection_changed), self); + g_signal_connect ( G_OBJECT(self->service), + INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, + G_CALLBACK(connection_changed), self ); } static void @@ -182,7 +165,6 @@ indicator_sound_dispose (GObject *object) return; } - static void indicator_sound_finalize (GObject *object) { @@ -200,11 +182,7 @@ static GtkImage * get_icon (IndicatorObject * io) { IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - // TODO query the sound state manager for the current relevant image - - //g_debug("At start-up attempting to set the image to %s", - // current_name); - speaker_image = indicator_image_helper(sound_state_manager_get_current_icon_name(priv->sound_state_manager)); + speaker_image = sound_state_manager_get_current_icon (priv->state_manager)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; @@ -225,25 +203,98 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); - // register Key-press listening on the menu widget as the slider does not allow this. - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); - g_signal_connect(menu, "key-release-event", G_CALLBACK(key_release_cb), io); + // Note: Not ideal but all key handling needs to be managed here and then + // delegated to the appropriate widget. + g_signal_connect (menu, "key-press-event", G_CALLBACK(key_press_cb), io); + g_signal_connect (menu, "key-release-event", G_CALLBACK(key_release_cb), io); return GTK_MENU(menu); } static void -free_the_animation_list() +connection_changed (IndicatorServiceManager * sm, + gboolean connected, + gpointer user_data) { - if (blocked_animation_list != NULL) { - g_list_foreach (blocked_animation_list, (GFunc)g_object_unref, NULL); - g_list_free(blocked_animation_list); - blocked_animation_list = NULL; + IndicatorSound* indicator = INDICATOR_SOUND(user_data); + g_return_if_fail ( IS_INDICATOR_SOUND (indicator) ); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE (indicator); + GError *error = NULL; + + if (connected == FALSE){ + //update_state (STATE_SINKS_NONE); + return; + //TODO: Gracefully handle disconnection + // do a timeout to wait for reconnection + // for 5 seconds and then if no connection message + // is received put the state at 'sink not available' + } + // If the proxy is not null and connected is true => its a reconnect, + // we don't need to anything, gdbus takes care of the rest - bless. + // just fetch the state. + if (priv->dbus_proxy != NULL){ + //fetch_state (indicator); + return; + } + + if ( node_info == NULL ){ + node_info = g_dbus_node_info_new_for_xml ( _sound_service, + &error ); + if (error != NULL) { + g_warning( "Failed to get create interface info from xml: %s", + error->message ); + g_error_free(error); + return; + } } + + if (interface_info == NULL) { + interface_info = g_dbus_node_info_lookup_interface (node_info, + INDICATOR_SOUND_DBUS_INTERFACE); + if (interface_info == NULL) { + g_error("Unable to find interface '" INDICATOR_SOUND_DBUS_INTERFACE "'"); + } + } + + g_dbus_proxy_new_for_bus( G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + interface_info, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, + INDICATOR_SOUND_DBUS_INTERFACE, + NULL, + create_connection_to_service, + indicator ); } +static void create_connection_to_service (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + IndicatorSound *self = INDICATOR_SOUND(user_data); + GError *error = NULL; + + g_return_if_fail( IS_INDICATOR_SOUND(self) ); + + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + + priv->dbus_proxy = g_dbus_proxy_new_finish(res, &error); + + if (error != NULL) { + g_warning("Failed to get dbus proxy: %s", error->message); + g_error_free(error); + return; + } + + sound_state_manager_connect_to_dbus (priv->state_manager, + priv->dbus_proxy); +} + + static gboolean -new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_transport_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client) { g_debug("indicator-sound: new_transport_bar() called "); @@ -261,13 +312,18 @@ new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar); gtk_widget_show_all(bar); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_transport_bar, parent); + dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client), + newitem, + menu_transport_bar, + parent); return TRUE; } static gboolean -new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_metadata_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client) { g_debug("indicator-sound: new_metadata_widget"); @@ -280,13 +336,16 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm GtkMenuItem *menu_metadata_widget = GTK_MENU_ITEM(metadata); gtk_widget_show_all(metadata); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_metadata_widget, parent); + dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client), + newitem, menu_metadata_widget, parent); return TRUE; } static gboolean -new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_title_widget(DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); @@ -307,7 +366,9 @@ new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu } static gboolean -new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_volume_slider_widget(DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client) { g_debug("indicator-sound: new_volume_slider_widget"); @@ -324,105 +385,22 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); - g_signal_connect(ido_slider_widget, "style-set", G_CALLBACK(style_changed_cb), NULL); - gtk_widget_set_sensitive(ido_slider_widget, - !initial_mute); gtk_widget_show_all(ido_slider_widget); + // register the style callback on this widget with state manager's style change + // handler (needs to remake the blocking animation for each style). + g_signal_connect (ido_slider_widget, "style-set", + G_CALLBACK(sound_state_manager_style_changed_cb), + priv->state_manager); - GtkMenuItem *menu_volume_item = GTK_MENU_ITEM(ido_slider_widget); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_item, parent); - fetch_state(INDICATOR_SOUND (io)); + //fetch_state(INDICATOR_SOUND (io)); return TRUE; } - -static void -connection_changed (IndicatorServiceManager * sm, - gboolean connected, - gpointer user_data) -{ - IndicatorSound* indicator = INDICATOR_SOUND(user_data); - g_return_if_fail ( IS_INDICATOR_SOUND (indicator) ); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE (indicator); - GError *error = NULL; - - if (connected == FALSE){ - //update_state (STATE_SINKS_NONE); - return; - //TODO: Gracefully handle disconnection - // do a timeout to wait for reconnection - // for 5 seconds and then if no connection message - // is received put the state at 'sink not available' - } - // If the proxy is not null and connected is true => its a reconnect, - // we don't need to anything, gdbus takes care of the rest - bless. - // just fetch the state. - if (priv->dbus_proxy != NULL){ - //fetch_state (indicator); - return; - } - - if ( node_info == NULL ){ - node_info = g_dbus_node_info_new_for_xml ( _sound_service, - &error ); - if (error != NULL) { - g_warning( "Failed to get create interface info from xml: %s", - error->message ); - g_error_free(error); - return; - } - } - - if (interface_info == NULL) { - interface_info = g_dbus_node_info_lookup_interface (node_info, - INDICATOR_SOUND_DBUS_INTERFACE); - if (interface_info == NULL) { - g_error("Unable to find interface '" INDICATOR_SOUND_DBUS_INTERFACE "'"); - } - } - - g_dbus_proxy_new_for_bus( G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - interface_info, - INDICATOR_SOUND_DBUS_NAME, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, - INDICATOR_SOUND_DBUS_INTERFACE, - NULL, - create_connection_to_service, - indicator ); -} - -static void create_connection_to_service (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - IndicatorSound *self = INDICATOR_SOUND(user_data); - GError *error = NULL; - - g_return_if_fail( IS_INDICATOR_SOUND(self) ); - - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - - priv->dbus_proxy = g_dbus_proxy_new_finish(res, &error); - - if (error != NULL) { - g_warning("Failed to get dbus proxy: %s", error->message); - g_error_free(error); - return; - } - - priv->sound_state_manager = sound_state_manager_new(priv->dbus_proxy); - - g_signal_connect(priv->dbus_proxy, "g-signal", - G_CALLBACK(g_signal_cb), self); - - fetch_state (self); -} - /*static void fetch_state (IndicatorSound* self) { @@ -519,84 +497,6 @@ static void get_sink_mute_cb ( GObject *object, g_variant_unref(result); }*/ - - -gint -get_state() -{ - return current_state; -} - -gchar* -get_state_image_name(gint state) -{ - return g_hash_table_lookup(volume_states, GINT_TO_POINTER(state)); -} - -void -prepare_for_tests(IndicatorObject *io) -{ - prepare_state_machine(); - get_icon(io); -} - -void -tidy_up_hash() -{ - g_hash_table_destroy(volume_states); -} - -static void -update_state(const gint state) -{ - previous_state = current_state; - current_state = state; - gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - indicator_image_helper_update(speaker_image, image_name); -} - - - -static gboolean -start_animation() -{ - blocked_iter = blocked_animation_list; - blocked_id = 0; - animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL); - return FALSE; -} - -static gboolean -fade_back_to_mute_image() -{ - if (blocked_iter != NULL) { - gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); - blocked_iter = blocked_iter->next; - return TRUE; - } else { - animation_id = 0; - //g_debug("exit from animation now\n"); - return FALSE; - } -} - -static void -reset_mute_blocking_animation() -{ - if (animation_id != 0) { - //g_debug("about to remove the animation_id callback from the mainloop!!**"); - g_source_remove(animation_id); - animation_id = 0; - } - if (blocked_id != 0) { - //g_debug("about to remove the blocked_id callback from the mainloop!!**"); - g_source_remove(blocked_id); - blocked_id = 0; - } -} - - - /*******************************************************************/ // DBUS Signal reactions /*******************************************************************/ @@ -739,7 +639,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) break; } new_value = CLAMP(new_value, 0, 100); - if (new_value != current_value && current_state != STATE_MUTED) { + if (new_value != current_value && sound_state_manager_get_current_state (priv->state_manager) != MUTED) { //g_debug("Attempting to set the range from the key listener to %f", new_value); volume_widget_update(VOLUME_WIDGET(priv->volume_widget), new_value); } @@ -838,7 +738,8 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) static void -indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) +indicator_sound_scroll (IndicatorObject *io, gint delta, + IndicatorScrollDirection direction) { //g_debug("indicator-sound-scroll - current slider value"); diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 9f829bb..ecc38fb 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -26,7 +26,6 @@ with this program. If not, see . #include #include #include -#include #define INDICATOR_SOUND_TYPE (indicator_sound_get_type ()) #define INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SOUND_TYPE, IndicatorSound)) diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index a2121ad..1eecaf0 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -17,40 +17,50 @@ You should have received a copy of the GNU General Public License along 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 struct _SoundStateManagerPrivate { GDBusProxy* dbus_proxy; GHashTable* volume_states; GList* blocked_animation_list; + SoundState current_state; + GtkImage* speaker_image; }; #define SOUND_STATE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_TYPE_STATE_MANAGER, SoundStateManagerPrivate)) -static GtkImage *speaker_image = NULL; -static gint current_state = 0; -static gint previous_state = 0; static GtkIconSize design_team_size; static gint blocked_id; static gint animation_id; +static GList* blocked_iter = NULL; -static GList * blocked_animation_list = NULL; -static GList * blocked_iter = NULL; -static void prepare_blocked_animation(); -static gboolean fade_back_to_mute_image(); -static gboolean start_animation(); -static void reset_mute_blocking_animation(); -static void free_the_animation_list(); +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 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_prepare_state_image_names (SoundStateManager* self); G_DEFINE_TYPE (SoundStateManager, sound_state_manager, G_TYPE_OBJECT); static void -sound_state_manager_init (SoundStateManager *object) +sound_state_manager_init (SoundStateManager* self) { - /* TODO: Add initialization code here */ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + sound_state_manager_prepare_state_image_names (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)); } static void @@ -68,13 +78,14 @@ sound_state_manager_class_init (SoundStateManagerClass *klass) GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = sound_state_manager_finalize; + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); } /* -Prepare states Array. +Prepare states versus images names hash. */ -void -sound_state_manager_prepare_state_machine(SoundStateManager* self) +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); @@ -93,7 +104,7 @@ Prepares the array of images to be used in the blocked animation. Only called at startup. */ static void -sound_state_manager_prepare_blocked_animation(SoundStateManager* self) +sound_state_manager_prepare_blocked_animation (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); @@ -130,49 +141,145 @@ sound_state_manager_prepare_blocked_animation(SoundStateManager* self) g_object_unref(blocked_buf); } -void -sound_state_manager_tidy_up_hash() + +GtkImage* +sound_state_manager_get_current_icon (SoundStateManager* self) { - g_hash_table_destroy(volume_states); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + return priv->speaker_image; } -gchar* -sound_state_manager_get_current_icon_name (SoundStateManager* self) +SoundState +sound_state_manager_get_current_state (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); - return g_hash_table_lookup (priv->volume_states, - GINT_TO_POINTER(priv->current_state)); - + return priv->current_state; } -static void g_signal_cb ( GDBusProxy* proxy, - gchar* sender_name, - gchar* signal_name, - GVariant* parameters, - gpointer user_data) +static void +sound_state_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + 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); + + g_variant_ref (parameters); + GVariant *value = g_variant_get_child_value (parameters, 0); + gint update = g_variant_get_int (value); + + g_debug ( "!!! signal_cb with value %i", update); + + priv->current_state = (SoundState)update; + + g_variant_unref (parameters); + + + /*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 +void sound_state_manager_style_changed_cb(GtkWidget *widget, gpointer user_data) { //g_debug("Just caught a style change event"); - update_state(current_state); - reset_mute_blocking_animation(); - update_state(current_state); - free_the_animation_list(); - prepare_blocked_animation(); + 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_prepare_blocked_animation (self); +} + +static void +sound_state_manager_reset_mute_blocking_animation (SoundStateManager* self) +{ + if (animation_id != 0) { + //g_debug("about to remove the animation_id callback from the mainloop!!**"); + g_source_remove(animation_id); + animation_id = 0; + } + if (blocked_id != 0) { + //g_debug("about to remove the blocked_id callback from the mainloop!!**"); + g_source_remove(blocked_id); + blocked_id = 0; + } +} + +static void +sound_state_mananger_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; + } +} + +/*static void +update_state(const gint state) +{ + previous_state = current_state; + current_state = state; + gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + indicator_image_helper_update(speaker_image, image_name); +}*/ + +static gboolean +sound_state_manager_start_animation (SoundStateManager* self) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + blocked_iter = priv->blocked_animation_list; + blocked_id = 0; + animation_id = g_timeout_add (50, + sound_state_manager_fade_back_to_mute_image, + self); + return FALSE; +} + +static gboolean +sound_state_manager_fade_back_to_mute_image (gpointer user_data) +{ + g_return_if_fail (SOUND_IS_STATE_MANAGER (user_data)); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE( SOUND_STATE_MANAGER (user_data) ); + + if (blocked_iter != NULL) { + gtk_image_set_from_pixbuf (priv->speaker_image, blocked_iter->data); + blocked_iter = blocked_iter->next; + return TRUE; + } else { + animation_id = 0; + //g_debug("exit from animation now\n"); + return FALSE; + } } /** - * volume_widget_new: - * @returns: a new #VolumeWidget. + * 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. **/ -SoundStateManager* -sound_state_manager_new (GDProxy* proxy) +void +sound_state_manager_connect_to_dbus (SoundStateManager* self, GDProxy* proxy) { - SoundStateManager* manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); - SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(manager); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); priv->dbus_proxy = proxy; - return manager; + g_signal_connect (priv->dbus_proxy, "g-signal", + G_CALLBACK (sound_state_signal_cb), self); + } diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h index 5f26682..1799822 100644 --- a/src/sound-state-manager.h +++ b/src/sound-state-manager.h @@ -21,6 +21,7 @@ with this program. If not, see . #define _SOUND_STATE_MANAGER_H_ #include +#include "common-defs.h" G_BEGIN_DECLS @@ -45,9 +46,13 @@ struct _SoundStateManager }; GType sound_state_manager_get_type (void) G_GNUC_CONST; -void sound_state_manager_prepare_state_machine(SoundStateManager* self); -SoundStateManager* sound_state_manager_new (GDProxy* proxy); -gchar* sound_state_manager_get_current_icon_name (SoundStateManager* self); + +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); + G_END_DECLS #endif /* _SOUND_STATE_MANAGER_H_ */ -- cgit v1.2.3 From eb2c1d7fc7ba7f8d2ae35141b2bf13ef69795b1d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 16:27:02 -0600 Subject: deleted the dbus-menu-manager c and h --- src/dbus-menu-manager.c | 170 ------------------------------------------------ src/dbus-menu-manager.h | 38 ----------- 2 files changed, 208 deletions(-) delete mode 100644 src/dbus-menu-manager.c delete mode 100644 src/dbus-menu-manager.h (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c deleted file mode 100644 index 2a2982e..0000000 --- a/src/dbus-menu-manager.c +++ /dev/null @@ -1,170 +0,0 @@ -/* -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran - -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 -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -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 . -*/ - -/** - *TODO: - * Makes this a proper GObject - **/ - - -#include -#include - -#include -#include - -#include "dbus-menu-manager.h" -#include "sound-service-dbus.h" -#include "pulse-manager.h" -#include "slider-menu-item.h" -#include "mute-menu-item.h" - -#include "common-defs.h" - -#include "dbus-shared-names.h" - -// DBUS related -static DbusmenuMenuitem *root_menuitem = NULL; -static SliderMenuItem *volume_slider_menuitem = NULL; -static MuteMenuItem *mute_menuitem = NULL; -static SoundServiceDbus *dbus_interface = NULL; - -static gboolean b_startup = TRUE; - -static gboolean idle_routine (gpointer data); -static void build_sound_menu(DbusmenuMenuitem *root, - gboolean mute_update, - gboolean availability, - gdouble volume); -static void show_sound_settings_dialog (DbusmenuMenuitem *mi, - gpointer user_data); - -/** -setup: -**/ -DbusmenuMenuitem* dbus_menu_manager_setup() -{ - root_menuitem = dbusmenu_menuitem_new(); - g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem)); - - g_idle_add(idle_routine, root_menuitem); - - dbus_interface = g_object_new(SOUND_SERVICE_DBUS_TYPE, NULL); - - DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH); - dbusmenu_server_set_root(server, root_menuitem); - establish_pulse_activities(dbus_interface); - return root_menuitem; -} - -/** -build_sound_menu's default items (without the any player items): -**/ -static void build_sound_menu (DbusmenuMenuitem *root, - gboolean mute_update, - gboolean availability, - gdouble volume) -{ - // Mute button - mute_menuitem = mute_menu_item_new ( mute_update, availability); - dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM(mute_menuitem)); - - // Slider - volume_slider_menuitem = slider_menu_item_new ( availability, volume ); - dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM ( 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(root, separator); - - // Sound preferences dialog - DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set( settings_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Sound Preferences...")); - - //_("Sound Preferences...")); - dbusmenu_menuitem_child_append(root, settings_mi); - g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_sound_settings_dialog), NULL); -} - -/** -update_pa_state: -**/ -void dbus_menu_manager_update_pa_state (gboolean pa_state, - gboolean pulse_available, - gboolean sink_muted, - gdouble percent) -{ - g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, pulse_available, sink_muted, percent); - - if (b_startup == TRUE) { - build_sound_menu(root_menuitem, sink_muted, pulse_available, percent); - b_startup = FALSE; - return; - } - - mute_menu_item_update ( mute_menuitem, - sink_muted ); - slider_menu_item_update ( volume_slider_menuitem, - percent ); - - mute_menu_item_enable ( mute_menuitem, pulse_available); - slider_menu_item_enable ( volume_slider_menuitem, - pulse_available ); - - // 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);*/ -} - -/** -update_mute_ui: -'public' method allowing the pa manager to update the mute menu item. - These are wrappers until we figure out this refactor -**/ -void dbus_menu_manager_update_mute(gboolean incoming_mute_value) -{ - mute_menu_item_update (mute_menuitem, incoming_mute_value); -} - -void dbus_menu_manager_update_volume(gdouble volume) -{ - slider_menu_item_update (volume_slider_menuitem, volume); -} - - - -/** -TODO: what are you doing with this -idle_routine: -Something for glip mainloop to do when idle -**/ -static gboolean idle_routine (gpointer data) -{ - return FALSE; -} - diff --git a/src/dbus-menu-manager.h b/src/dbus-menu-manager.h deleted file mode 100644 index 27976b3..0000000 --- a/src/dbus-menu-manager.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __INCLUDE_DBUS_MENU_MANAGER_H__ -#define __INCLUDE_DBUS_MENU_MANAGER_H__ - -/* -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran - -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 -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -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 . -*/ - -#include - -// Entry point -DbusmenuMenuitem* dbus_menu_manager_setup(); - -void dbus_menu_manager_update_pa_state (gboolean pa_state, - gboolean sink_available, - gboolean sink_muted, - gdouble current_vol); - -// Temporary wrappers on the pulsemanager inward calls -// until the refactor is complete -void dbus_menu_manager_update_mute (gboolean incoming_mute_value); -void dbus_menu_manager_update_volume (gdouble volume); -#endif - -- 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') 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 72165a8281fe45defba8a2b834ec6698b6d116b1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 19:05:05 -0600 Subject: operational --- src/Makefile.am | 2 +- src/sound-state-manager.c | 4 +++- src/volume-widget.c | 3 --- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b5c9fc3..79786af 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,7 +97,7 @@ indicator_sound_service_SOURCES = \ slider-menu-item.c \ mute-menu-item.h \ mute-menu-item.c \ - gen-sound-service.xml.h \ + gen-sound-service.xml.h \ gen-sound-service.xml.c \ $(music_bridge_VALASOURCES:.vala=.c) diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index bd2140a..004e011 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -86,10 +86,12 @@ static void sound_state_manager_class_init (SoundStateManagerClass *klass) { GObjectClass* object_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; + + g_type_class_add_private (klass, sizeof (SoundStateManagerPrivate)); + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); } diff --git a/src/volume-widget.c b/src/volume-widget.c index 38dc9bb..ceebec5 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -137,7 +137,6 @@ volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, gdouble update = g_variant_get_double (value); //g_debug("volume-widget - update level with value %f", update); gtk_range_set_value(range, update); - determine_state_from_volume(update); } } } @@ -157,7 +156,6 @@ volume_widget_set_twin_item(VolumeWidget* self, GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; gtk_range_set_value(range, initial_level); - determine_state_from_volume(initial_level); } static gboolean @@ -169,7 +167,6 @@ volume_widget_change_value_cb (GtkRange *range, g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); volume_widget_update(mitem, new_value); - determine_state_from_volume(new_value); return FALSE; } -- cgit v1.2.3 From 9643b10b825c13fe46d211b6ab1cd2230392f299 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 24 Jan 2011 19:50:10 -0600 Subject: tidy up --- src/indicator-sound.c | 178 ---------------------------------------------- src/sound-state-manager.c | 45 +++++++----- 2 files changed, 29 insertions(+), 194 deletions(-) (limited to 'src') 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 . 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); - -} -- cgit v1.2.3 From 329fda69862c649131c22fbac7e410c2af3603ae Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 25 Jan 2011 10:30:58 -0600 Subject: --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 98f1881..defcb94 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 24c234dcd513f99beddd4e022d049f498d39322e Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 25 Jan 2011 13:38:51 -0500 Subject: avoid critical warnings in metadata widget --- src/metadata-widget.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 09365d5..afc8a2d 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -101,8 +101,7 @@ metadata_widget_init (MetadataWidget *self) // image priv->album_art = gtk_image_new(); - priv->image_path = g_string_new(dbusmenu_menuitem_property_get(priv->twin_item, - DBUSMENU_METADATA_MENUITEM_ARTURL)); + priv->image_path = g_string_new(""); priv->old_image_path = g_string_new(""); g_signal_connect(priv->album_art, "expose-event", @@ -120,8 +119,7 @@ metadata_widget_init (MetadataWidget *self) // artist GtkWidget* artist; - artist = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, - DBUSMENU_METADATA_MENUITEM_ARTIST)); + artist = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); gtk_misc_set_padding (GTK_MISC(artist), (gfloat)10, (gfloat)0); gtk_widget_set_size_request (artist, 140, 15); @@ -131,8 +129,7 @@ metadata_widget_init (MetadataWidget *self) // title GtkWidget* piece; - piece = gtk_label_new(dbusmenu_menuitem_property_get( priv->twin_item, - DBUSMENU_METADATA_MENUITEM_TITLE) ); + piece = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); gtk_misc_set_padding (GTK_MISC(piece), (gfloat)10, (gfloat)-5); gtk_widget_set_size_request (piece, 140, 15); @@ -142,8 +139,7 @@ metadata_widget_init (MetadataWidget *self) // container GtkWidget* container; - container = gtk_label_new(dbusmenu_menuitem_property_get( priv->twin_item, - DBUSMENU_METADATA_MENUITEM_ALBUM) ); + container = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); gtk_misc_set_padding (GTK_MISC(container), (gfloat)10, (gfloat)0); gtk_widget_set_size_request (container, 140, 15); @@ -480,16 +476,18 @@ metadata_widget_set_twin_item(MetadataWidget* self, metadata_widget_style_labels( self, GTK_LABEL(priv->artist_label)); g_string_erase(priv->image_path, 0, -1); - g_string_overwrite( priv->image_path, - 0, - dbusmenu_menuitem_property_get( priv->twin_item, - DBUSMENU_METADATA_MENUITEM_ARTURL )); + const gchar *arturl = dbusmenu_menuitem_property_get( priv->twin_item, + DBUSMENU_METADATA_MENUITEM_ARTURL ); + if (arturl != NULL){ + g_string_overwrite( priv->image_path, + 0, + arturl); - // if its a remote image queue a redraw incase the download took too long - if (g_str_has_prefix (dbusmenu_menuitem_property_get (priv->twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL ), - g_get_user_cache_dir())){ - gtk_widget_queue_draw(GTK_WIDGET(self)); - } + // if its a remote image queue a redraw incase the download took too long + if (g_str_has_prefix (arturl, g_get_user_cache_dir())){ + gtk_widget_queue_draw(GTK_WIDGET(self)); + } + } } /** -- cgit v1.2.3 From d45fd344a30bc917c45aa07458e8961ba3018f69 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 25 Jan 2011 14:55:25 -0600 Subject: spotify crasher fixed --- src/mpris2-controller.vala | 62 ++++++++++++++++++++++++++++---------------- src/sound-service.c | 4 +-- src/transport-menu-item.vala | 3 ++- 3 files changed, 43 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index fc61c12..1c9258c 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -93,6 +93,16 @@ public class Mpris2Controller : GLib.Object if ( playlist_v != null && this.owner.use_playlists == true ){ this.fetch_active_playlist(); } + Variant? playlist_count_v = changed_properties.lookup("PlaylistCount"); + if ( playlist_count_v != null && this.owner.use_playlists == true ){ + this.fetch_playlists(); + this.fetch_active_playlist(); + } + Variant? playlist_orderings_v = changed_properties.lookup("Orderings"); + if ( playlist_orderings_v != null && this.owner.use_playlists == true ){ + this.fetch_playlists(); + this.fetch_active_playlist(); + } } private bool ensure_correct_playback_status(){ @@ -107,16 +117,21 @@ public class Mpris2Controller : GLib.Object GLib.HashTable changed_updates = this.player.Metadata; Variant? artist_v = this.player.Metadata.lookup("xesam:artist"); if(artist_v != null){ - string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); - string display_artists = string.joinv(", ", artists); + Variant? v_artists = this.player.Metadata.lookup("xesam:artist"); + debug("artists is of type %s", v_artists.get_type_string ()); + string display_artists; + if(v_artists.get_type_string() == "s"){ + debug("SPOTIFY YOU BASTARD"); + display_artists = v_artists.get_string(); + } + else{ + debug ("conforms with the spec" ); + string[] artists = v_artists.dup_strv(); + display_artists = string.joinv(", ", artists); + } changed_updates.replace("xesam:artist", display_artists); debug("artist : %s", (string)changed_updates.lookup("xesam:artist")); } - Variant? length_v = this.player.Metadata.lookup("mpris:length"); - if(length_v != null){ - int64 duration = this.player.Metadata.lookup("mpris:length").get_int64(); - changed_updates.replace("mpris:length", duration/1000000); - } return changed_updates; } @@ -161,7 +176,20 @@ public class Mpris2Controller : GLib.Object } } - public void fetch_playlists() + + public bool connected() + { + return (this.player != null && this.mpris2_root != null); + } + + public void expose() + { + if(this.connected() == true){ + this.mpris2_root.Raise.begin(); + } + } + + public bool fetch_playlists() { PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, 10, @@ -176,29 +204,17 @@ public class Mpris2Controller : GLib.Object warning(" Playlists are on but its returning no current_playlists" ); this.owner.use_playlists = false; } - return; + return false; } - private void fetch_active_playlist() + private bool fetch_active_playlist() { if (this.playlists.ActivePlaylist.valid == false){ debug("We don't have an active playlist"); } PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; playlists_item.update_active_playlist ( this.playlists.ActivePlaylist.details ); - } - - - public bool connected() - { - return (this.player != null && this.mpris2_root != null); - } - - public void expose() - { - if(this.connected() == true){ - this.mpris2_root.Raise.begin(); - } + return false; } public void activate_playlist (ObjectPath path) diff --git a/src/sound-service.c b/src/sound-service.c index defcb94..98f1881 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index e93f0bb..b8f55b5 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -44,7 +44,8 @@ public class TransportMenuitem : PlayerItem { debug("UPDATING THE TRANSPORT DBUSMENUITEM PLAY STATE WITH VALUE %i", (int)update); - this.property_set_int(MENUITEM_PLAY_STATE, update); + int temp = (int)update; + this.property_set_int(MENUITEM_PLAY_STATE, temp); } public override void handle_event(string name, -- cgit v1.2.3 From f19af83dd99f095ad5ebe317000ac5bf2031a038 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 25 Jan 2011 15:14:22 -0600 Subject: tidy up --- src/mpris2-controller.vala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 1c9258c..a7b3de1 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -121,12 +121,11 @@ public class Mpris2Controller : GLib.Object debug("artists is of type %s", v_artists.get_type_string ()); string display_artists; if(v_artists.get_type_string() == "s"){ - debug("SPOTIFY YOU BASTARD"); + debug("SPOTIFY is that you ?"); display_artists = v_artists.get_string(); } else{ - debug ("conforms with the spec" ); - string[] artists = v_artists.dup_strv(); + string[] artists = v_artists.dup_strv(); display_artists = string.joinv(", ", artists); } changed_updates.replace("xesam:artist", display_artists); @@ -189,7 +188,7 @@ public class Mpris2Controller : GLib.Object } } - public bool fetch_playlists() + public void fetch_playlists() { PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, 10, @@ -204,17 +203,15 @@ public class Mpris2Controller : GLib.Object warning(" Playlists are on but its returning no current_playlists" ); this.owner.use_playlists = false; } - return false; } - private bool fetch_active_playlist() + private void fetch_active_playlist() { if (this.playlists.ActivePlaylist.valid == false){ debug("We don't have an active playlist"); } PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; playlists_item.update_active_playlist ( this.playlists.ActivePlaylist.details ); - return false; } public void activate_playlist (ObjectPath path) -- 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/dbus-shared-names.h | 2 +- src/indicator-sound.c | 21 ++++++++++++++++++++- src/sound-service-dbus.c | 7 +++---- src/sound-service.list | 2 -- src/sound-state-manager.c | 4 ++-- 5 files changed, 26 insertions(+), 10 deletions(-) delete mode 100644 src/sound-service.list (limited to 'src') diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index b90d7a2..385a997 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -23,7 +23,7 @@ with this program. If not, see . #ifndef __DBUS_SHARED_NAMES_H__ -#define __DBUS_SHARED_NAMES_H__ 1 +#define __DBUS_SHARED_NAMES_H__ #define INDICATOR_SOUND_DBUS_NAME "com.canonical.indicators.sound" #define INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH "/com/canonical/indicators/sound/menu" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 59b9c92..ea67011 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -99,6 +99,11 @@ 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) @@ -274,12 +279,26 @@ 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); + 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, 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) diff --git a/src/sound-service.list b/src/sound-service.list deleted file mode 100644 index ee376e9..0000000 --- a/src/sound-service.list +++ /dev/null @@ -1,2 +0,0 @@ -VOID:INT,BOOLEAN - diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 83fb952..f6d39d0 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -190,7 +190,7 @@ 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_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); @@ -203,7 +203,7 @@ sound_state_signal_cb ( GDBusProxy* proxy, GVariant* parameters, gpointer user_data) { - g_debug ( "!!! signal_cb with value" ); + g_debug ( "!!! sound state manager signal_cb" ); g_return_if_fail (SOUND_IS_STATE_MANAGER (user_data)); SoundStateManager* self = SOUND_STATE_MANAGER (user_data); -- 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/dbus-shared-names.h | 2 +- src/indicator-sound.c | 25 +----------------- src/sound-service-dbus.c | 64 ++++++++++++++++++++++++++++++++++++++++++----- src/sound-state-manager.c | 59 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 111 insertions(+), 39 deletions(-) (limited to 'src') 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 . #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 . #include #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 ); - }*/ } -- 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/mute-menu-item.c | 72 ++++++++++++++++++++++++++---------------------- src/mute-menu-item.h | 13 +++++---- src/sound-service-dbus.c | 36 +++++++++++++----------- 3 files changed, 66 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index 2c5af6d..344c17e 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -20,14 +20,16 @@ with this program. If not, see . #include "config.h" #endif -#include "common-defs.h" #include + +#include "common-defs.h" #include "mute-menu-item.h" #include "pulse-manager.h" typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate; struct _MuteMenuItemPrivate { + DbusmenuMenuitem* button; }; #define MUTE_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_MENU_ITEM_TYPE, MuteMenuItemPrivate)) @@ -39,8 +41,10 @@ static void mute_menu_item_dispose (GObject *object); static void mute_menu_item_finalize (GObject *object); static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); +static void +mute_menu_item_set_global_mute_from_ui (gpointer user_data); -G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, DBUSMENU_TYPE_MENUITEM); +G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, G_TYPE_OBJECT); static void mute_menu_item_class_init (MuteMenuItemClass *klass) { @@ -51,14 +55,19 @@ static void mute_menu_item_class_init (MuteMenuItemClass *klass) object_class->dispose = mute_menu_item_dispose; object_class->finalize = mute_menu_item_finalize; - DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); - mclass->handle_event = handle_event; return; } static void mute_menu_item_init (MuteMenuItem *self) { g_debug("Building new Mute Menu Item"); + MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self); + priv->button = dbusmenu_menuitem_new(); + + g_signal_connect (G_OBJECT (priv->button), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (mute_menu_item_set_global_mute_from_ui), + self); return; } @@ -74,53 +83,50 @@ mute_menu_item_finalize (GObject *object) G_OBJECT_CLASS (mute_menu_item_parent_class)->finalize (object); } -static void -handle_event (DbusmenuMenuitem * mi, - const gchar * name, - GVariant * value, - guint timestamp) +static void +mute_menu_item_set_global_mute_from_ui (gpointer user_data) { - /*g_debug ( "handle-event in the mute at the backend, input is of type %s", - g_variant_get_type_string(value));*/ - - GVariant* input = NULL; - input = value; - g_variant_ref (input); - - // 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); - } - - gboolean mute_input = g_variant_get_boolean(input); - toggle_global_mute (mute_input); - g_variant_unref (input); + g_return_if_fail (DBUSMENU_IS_MENUITEM (user_data)); + DbusmenuMenuitem* button = DBUSMENU_MENUITEM (user_data); + gboolean current_value = dbusmenu_menuitem_property_get_bool (button, + DBUSMENU_MUTE_MENUITEM_VALUE); + + gboolean new_value = !current_value; + // pa manager api - to be refactored + toggle_global_mute (new_value); } + void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) { - dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(item), + MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); + + dbusmenu_menuitem_property_set_bool (priv->button, DBUSMENU_MUTE_MENUITEM_VALUE, value_update); - dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(item), + dbusmenu_menuitem_property_set (priv->button, DBUSMENU_MENUITEM_PROP_LABEL, value_update == FALSE ? _("Mute") : _("Unmute")); } void mute_menu_item_enable(MuteMenuItem* item, gboolean active) { - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(item), - DBUSMENU_MENUITEM_PROP_ENABLED, - active); + MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); + + dbusmenu_menuitem_property_set_bool (priv->button, + DBUSMENU_MENUITEM_PROP_ENABLED, + active); } +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) { - MuteMenuItem *self = g_object_new(MUTE_MENU_ITEM_TYPE, NULL); - dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(self), - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_MUTE_MENUITEM_TYPE); + MuteMenuItem *self = g_object_new (MUTE_MENU_ITEM_TYPE, NULL); mute_menu_item_update (self, initial_update); mute_menu_item_enable (self, enabled); return self; diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h index 1432de1..8240441 100644 --- a/src/mute-menu-item.h +++ b/src/mute-menu-item.h @@ -22,7 +22,6 @@ with this program. If not, see . #include #include - #include G_BEGIN_DECLS @@ -38,19 +37,21 @@ typedef struct _MuteMenuItem MuteMenuItem; typedef struct _MuteMenuItemClass MuteMenuItemClass; struct _MuteMenuItemClass { - DbusmenuMenuitemClass parent_class; + GObjectClass parent_class; }; struct _MuteMenuItem { - DbusmenuMenuitem parent; + GObject parent; }; GType mute_menu_item_get_type (void); -MuteMenuItem* mute_menu_item_new(); +MuteMenuItem* mute_menu_item_new (); + +void mute_menu_item_update (MuteMenuItem* item, gboolean update); +void mute_menu_item_enable (MuteMenuItem* item, gboolean active); -void mute_menu_item_update(MuteMenuItem* item, gboolean update); -void mute_menu_item_enable(MuteMenuItem* item, gboolean active); +DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item); G_END_DECLS 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 ++++++++++++++++++++--------------------------- src/sound-service.c | 4 +- 2 files changed, 52 insertions(+), 71 deletions(-) (limited to 'src') 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); } diff --git a/src/sound-service.c b/src/sound-service.c index e72a917..9a5c6fe 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- 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/Makefile.am | 2 +- src/indicator-sound.c | 1 - src/sound-service-dbus.c | 8 +++--- src/sound-state-manager.c | 64 +++++++++++++++++++++++++++++++++-------------- src/sound-state-manager.h | 4 ++- 5 files changed, 53 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 79786af..ed64aeb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,7 @@ libsoundmenu_la_SOURCES = \ gen-sound-service.xml.c \ dbus-shared-names.h -libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -DG_LOG_DOMAIN=\"Indicator-Sound\" +libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror -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 71310f1..b47290c 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -382,7 +382,6 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, newitem, menu_volume_item, parent); - //fetch_state(INDICATOR_SOUND (io)); return TRUE; } 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); diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 0fce9a8..4a8dbe2 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -39,9 +39,10 @@ static GtkIconSize design_team_size; static gint blocked_id; static gint animation_id; static GList* blocked_iter = NULL; +static gboolean can_animate = FALSE; static void sound_state_manager_prepare_blocked_animation(SoundStateManager* self); -static gboolean sound_state_manager_start_animation (SoundStateManager* self); +static gboolean sound_state_manager_start_animation (gpointer user_data); 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); @@ -54,8 +55,7 @@ static void sound_state_signal_cb ( GDBusProxy* proxy, static void sound_state_manager_get_state_cb (GObject *object, GAsyncResult *res, gpointer user_data); - - +static gboolean sound_state_manager_can_proceed_with_blocking_animation (SoundStateManager* self); static void sound_state_manager_init (SoundStateManager* self) @@ -163,6 +163,7 @@ sound_state_manager_prepare_blocked_animation (SoundStateManager* self) priv->blocked_animation_list = g_list_append(priv->blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); } + can_animate = TRUE; g_object_ref_sink(mute_buf); g_object_unref(mute_buf); g_object_ref_sink(blocked_buf); @@ -248,7 +249,7 @@ sound_state_signal_cb ( GDBusProxy* proxy, GVariant* parameters, gpointer user_data) { - g_debug ( "!!! sound state manager signal_cb" ); + //g_debug ( "!!! sound state manager signal_cb" ); g_return_if_fail (SOUND_IS_STATE_MANAGER (user_data)); SoundStateManager* self = SOUND_STATE_MANAGER (user_data); @@ -258,27 +259,40 @@ sound_state_signal_cb ( GDBusProxy* proxy, GVariant *value = g_variant_get_child_value (parameters, 0); gint update = g_variant_get_int32 (value); - g_debug ( "!!! signal_cb with value %i", update); + //g_debug ( "!!! signal_cb with value %i", update); priv->current_state = (SoundState)update; g_variant_unref (parameters); 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); + if (priv->current_state == BLOCKED && + sound_state_manager_can_proceed_with_blocking_animation (self) == TRUE) { + blocked_id = g_timeout_add_seconds (4, + sound_state_manager_start_animation, + self); + indicator_image_helper_update (priv->speaker_image, image_name); + + } + else{ + indicator_image_helper_update (priv->speaker_image, image_name); + } } else { - g_debug ("sorry don't know what signal this is - %s", signal_name); + g_warning ("sorry don't know what signal this is - %s", signal_name); } } void -sound_state_manager_style_changed_cb(GtkWidget *widget, gpointer user_data) +sound_state_manager_style_changed_cb (GtkWidget *widget, + GtkStyle *previous_style, + gpointer user_data) { - //g_debug("Just caught a style change event"); + 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); sound_state_manager_reset_mute_blocking_animation (self); @@ -313,18 +327,12 @@ sound_state_manager_free_the_animation_list (SoundStateManager* self) } } -/*static void -update_state(const gint state) -{ - previous_state = current_state; - current_state = state; - gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - indicator_image_helper_update(speaker_image, image_name); -}*/ static gboolean -sound_state_manager_start_animation (SoundStateManager* self) +sound_state_manager_start_animation (gpointer userdata) { + g_return_val_if_fail (SOUND_IS_STATE_MANAGER (userdata), FALSE); + SoundStateManager* self = SOUND_STATE_MANAGER (userdata); SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); blocked_iter = priv->blocked_animation_list; @@ -339,7 +347,8 @@ static gboolean sound_state_manager_fade_back_to_mute_image (gpointer 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) ); + SoundStateManager* self = SOUND_STATE_MANAGER (user_data); + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE (self); if (blocked_iter != NULL) { gtk_image_set_from_pixbuf (priv->speaker_image, blocked_iter->data); @@ -348,7 +357,24 @@ sound_state_manager_fade_back_to_mute_image (gpointer user_data) } else { animation_id = 0; //g_debug("exit from animation now\n"); + g_dbus_proxy_call ( priv->dbus_proxy, + "GetSoundState", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback)sound_state_manager_get_state_cb, + self); + return FALSE; } } + +// Simple static helper to determine if the coast is clear to animate +static +gboolean sound_state_manager_can_proceed_with_blocking_animation (SoundStateManager* self) +{ + return (can_animate && blocked_id == 0 && animation_id == 0 ); +} + diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h index ef8fc40..76264e2 100644 --- a/src/sound-state-manager.h +++ b/src/sound-state-manager.h @@ -47,7 +47,9 @@ struct _SoundStateManager GType sound_state_manager_get_type (void) G_GNUC_CONST; -void sound_state_manager_style_changed_cb (GtkWidget *widget, gpointer user_data); +void sound_state_manager_style_changed_cb (GtkWidget *widget, + GtkStyle *previous_style, + 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, -- cgit v1.2.3 From 46cbdc7d1607b20c1bba67df4471f8e5d1243c3d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 16:40:38 -0600 Subject: last minute tidy up --- src/indicator-sound.c | 12 +++++++++--- src/mute-menu-item.c | 5 +---- src/sound-service.c | 4 ++-- src/sound-state-manager.c | 16 ++++++++++++---- src/sound-state-manager.h | 6 ++++++ 5 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index b47290c..3c65a90 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -129,7 +129,6 @@ indicator_sound_init (IndicatorSound *self) priv->dbus_proxy = NULL; GList* t_list = NULL; priv->transport_widgets_list = t_list; - // create our state manager which will handle all icon changing etc. priv->state_manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); g_signal_connect ( G_OBJECT(self->service), @@ -209,7 +208,7 @@ connection_changed (IndicatorServiceManager * sm, GError *error = NULL; if (connected == FALSE){ - //update_state (STATE_SINKS_NONE); + sound_state_manager_deal_with_disconnect (priv->state_manager); return; //TODO: Gracefully handle disconnection // do a timeout to wait for reconnection @@ -220,7 +219,14 @@ connection_changed (IndicatorServiceManager * sm, // we don't need to anything, gdbus takes care of the rest - bless. // just fetch the state. if (priv->dbus_proxy != NULL){ - //fetch_state (indicator); + g_dbus_proxy_call ( priv->dbus_proxy, + "GetSoundState", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback)sound_state_manager_get_state_cb, + priv->state_manager); return; } diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index 344c17e..2f40177 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -39,10 +39,7 @@ static void mute_menu_item_class_init (MuteMenuItemClass *klass); static void mute_menu_item_init (MuteMenuItem *self); static void mute_menu_item_dispose (GObject *object); static void mute_menu_item_finalize (GObject *object); -static void handle_event (DbusmenuMenuitem * mi, const gchar * name, - GVariant * value, guint timestamp); -static void -mute_menu_item_set_global_mute_from_ui (gpointer user_data); +static void mute_menu_item_set_global_mute_from_ui (gpointer user_data); G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, G_TYPE_OBJECT); diff --git a/src/sound-service.c b/src/sound-service.c index 9a5c6fe..2cb33d3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -18,8 +18,8 @@ with this program. If not, see . */ #include "sound-service.h" -//#include "dbus-menu-manager.h" -//#include "pulse-manager.h" + +#include "pulse-manager.h" #include "sound-service-dbus.h" #include "music-player-bridge.h" diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 4a8dbe2..2ea9b1a 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -52,9 +52,6 @@ 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 gboolean sound_state_manager_can_proceed_with_blocking_animation (SoundStateManager* self); static void @@ -210,7 +207,7 @@ sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy) self); } -static void +void sound_state_manager_get_state_cb (GObject *object, GAsyncResult *res, gpointer user_data) @@ -242,6 +239,17 @@ sound_state_manager_get_state_cb (GObject *object, g_variant_unref(result); } +void +sound_state_manager_deal_with_disconnect (SoundStateManager* self) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + priv->current_state = UNAVAILABLE; + + 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); +} + static void sound_state_signal_cb ( GDBusProxy* proxy, gchar* sender_name, diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h index 76264e2..d73d5d9 100644 --- a/src/sound-state-manager.h +++ b/src/sound-state-manager.h @@ -54,6 +54,12 @@ 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, GDBusProxy* proxy); +void sound_state_manager_deal_with_disconnect (SoundStateManager* self); +void sound_state_manager_get_state_cb (GObject *object, + GAsyncResult *res, + gpointer user_data); + + G_END_DECLS -- 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/slider-menu-item.c | 3 --- src/sound-service-dbus.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index d41ff85..64db277 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -86,8 +86,6 @@ handle_event (DbusmenuMenuitem * mi, GVariant* input = NULL; input = value; - g_variant_ref (input); - // 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); @@ -97,7 +95,6 @@ handle_event (DbusmenuMenuitem * mi, if (value != NULL){ set_sink_volume(volume_input); } - g_variant_unref (input); } void slider_menu_item_update (SliderMenuItem* item, 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') 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') 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 From 38d1512ec2621598cba84c6caf5df2e7d8914cf9 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 26 Jan 2011 21:09:45 -0600 Subject: temporarily disable tests --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 98f1881..defcb94 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From b6b241d47f33a67b6f61f9860a278a6582113835 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 27 Jan 2011 12:11:32 -0600 Subject: button flickering fixed --- src/sound-service.c | 4 ++-- src/transport-widget.c | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 2cb33d3..c1bb9b4 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index a276a31..6ddd4bc 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -289,11 +289,7 @@ transport_widget_motion_notify_event (GtkWidget *menuitem, event); priv->motion_event = result; - cairo_t *cr; - cr = gdk_cairo_create (menuitem->window); - draw ( menuitem, cr ); - cairo_destroy ( cr ); - + gtk_widget_queue_draw (menuitem); return TRUE; } -- 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') 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 From b03499a823ded3f262aa065ee24b3e30a4cf0ca3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 27 Jan 2011 17:08:08 -0600 Subject: playlist fetching is now async and some compilation warnings sorted --- src/mpris2-controller.vala | 25 +++++++++++++++++-------- src/mpris2-interfaces.vala | 8 ++++---- src/music-player-bridge.vala | 4 ++-- src/player-controller.vala | 14 -------------- 4 files changed, 23 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index a7b3de1..03571e6 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -95,12 +95,12 @@ public class Mpris2Controller : GLib.Object } Variant? playlist_count_v = changed_properties.lookup("PlaylistCount"); if ( playlist_count_v != null && this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } Variant? playlist_orderings_v = changed_properties.lookup("Orderings"); if ( playlist_orderings_v != null && this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } } @@ -156,7 +156,7 @@ public class Mpris2Controller : GLib.Object MetadataMenuitem.attributes_format()); if ( this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } } @@ -188,12 +188,21 @@ public class Mpris2Controller : GLib.Object } } - public void fetch_playlists() + public async void fetch_playlists() { - PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, - 10, - "Alphabetical", - false); + PlaylistDetails[] current_playlists = null; + + try{ + current_playlists = yield this.playlists.GetPlaylists (0, + 10, + "Alphabetical", + false); + } + catch (IOError e){ + debug("Could not fetch playlists because %s", e.message); + return; + } + if( current_playlists != null ){ debug( "Size of the playlist array = %i", current_playlists.length ); PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index 9d0b8c9..0a0909f 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -68,8 +68,8 @@ public interface MprisPlaylists : Object { //methods public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; - public abstract PlaylistDetails[] GetPlaylists ( uint32 index, - uint32 max_count, - string order, - bool reverse_order ) throws IOError; + public abstract async PlaylistDetails[] GetPlaylists ( uint32 index, + uint32 max_count, + string order, + bool reverse_order ) throws IOError; } \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 7587684..c167e08 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -141,8 +141,8 @@ public class MusicPlayerBridge : GLib.Object this.root_menu = menu; this.try_to_add_inactive_familiar_clients(); this.watcher = new Mpris2Watcher (); - this.watcher.client_appeared += this.client_has_become_available; - this.watcher.client_disappeared += this.client_has_vanished; + this.watcher.client_appeared.connect (this.client_has_become_available); + this.watcher.client_disappeared.connect (this.client_has_vanished); } private static AppInfo? create_app_info ( string desktop ) diff --git a/src/player-controller.vala b/src/player-controller.vala index adefb65..024b88b 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -189,20 +189,6 @@ public class PlayerController : GLib.Object } } - private static string format_player_name(owned string app_info_name) - { - string result = app_info_name.down().strip(); - var tokens = result.split(" "); - if(tokens.length > 1){ - result = tokens[0]; - } - if(result.length > 1){ - result = result.up(1).concat(result.slice(1, result.length)); - } - debug("PlayerController->format_player_name - : %s", result); - return result; - } - private void determine_state() { if(this.mpris_bridge.connected() == true){ -- cgit v1.2.3 From 378302145a86c96a664935e5a5f27721c560aed7 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 27 Jan 2011 17:15:10 -0600 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index c1bb9b4..2cb33d3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3