diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-03-02 19:36:53 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-03-02 19:36:53 +0000 |
commit | 4bde209ef0f8ad381d70b2ade7eb3cf834eed074 (patch) | |
tree | 389a1d11d72ff8566ae83000e24579138c454733 /src/sound-service.c | |
parent | be2b2e73044d5ba0c656431f0d19723af6b55946 (diff) | |
download | ayatana-indicator-sound-4bde209ef0f8ad381d70b2ade7eb3cf834eed074.tar.gz ayatana-indicator-sound-4bde209ef0f8ad381d70b2ade7eb3cf834eed074.tar.bz2 ayatana-indicator-sound-4bde209ef0f8ad381d70b2ade7eb3cf834eed074.zip |
one big refactor
Diffstat (limited to 'src/sound-service.c')
-rw-r--r-- | src/sound-service.c | 134 |
1 files changed, 12 insertions, 122 deletions
diff --git a/src/sound-service.c b/src/sound-service.c index 61bf702..815fcdc 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -19,107 +19,22 @@ 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 <http://www.gnu.org/licenses/>. */ + #include "sound-service.h" -#include "sound-service-dbus.h" +#include "dbus-menu-manager.h" #include "pulse-manager.h" -#include "slider-menu-item.h" -#include "common-defs.h" - -// GTK + DBUS static GMainLoop *mainloop = NULL; -static DbusmenuMenuitem *root_menuitem = NULL; -static DbusmenuMenuitem *mute_all_menuitem = NULL; -static SliderMenuItem *volume_slider_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 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); - /**********************************************************************************************************************/ -// Init functions (GTK and DBUS) +// Init and exit functions /**********************************************************************************************************************/ -/** -Pass to the g_idle_add method - returning False will ensure that this method is never called again as it is removed as an event source. -**/ -static gboolean idle_routine (gpointer data) -{ - return FALSE; -} - - -static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data) -{ - GError * error = NULL; - if (!g_spawn_command_line_async("gnome-volume-control", &error)) - { - g_warning("Unable to show dialog: %s", error->message); - g_error_free(error); - } -} -/** -Build the DBus menu items. For now Mute all/Unmute is the only available option -**/ -static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service) -{ - // Mute button - mute_all_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _(b_all_muted == FALSE ? "Mute All" : "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); - - // Slider - volume_slider_menuitem = slider_menu_item_new(b_sink_available, volume_percent); - dbusmenu_menuitem_child_append(root, mute_all_menuitem); - dbusmenu_menuitem_child_append(root, DBUSMENU_MENUITEM(volume_slider_menuitem)); - - DbusmenuMenuitem *separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, - _("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_mute_ui: -'public' method allowing the server to update the mute UI +service_shutdown: +When the service interface starts to shutdown, we +should follow it. **/ -void update_mute_ui(gboolean incoming_mute_value) -{ - b_all_muted = incoming_mute_value; - dbusmenu_menuitem_property_set(mute_all_menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - _(b_all_muted == FALSE ? "Mute All" : "Unmute")); -} -/** -set_global_mute_from_ui: -Callback for the dbusmenuitem button -**/ -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 All" : "Unmute")); -} - - -/* When the service interface starts to shutdown, we - should follow it. - -*/ void service_shutdown (IndicatorService *service, gpointer user_data) { @@ -127,31 +42,15 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - // TODO free the dbus interface !! - close_pulse_activites(); - g_main_loop_quit(mainloop); +/* close_pulse_activites();*/ +/* g_main_loop_quit(mainloop);*/ } return; } -void 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); - sound_service_dbus_update_sink_volume(dbus_interface, percent); - sound_service_dbus_update_sink_mute(dbus_interface, sink_muted); - - // Only rebuild the menu on start up... - if(volume_slider_menuitem == NULL) - rebuild_sound_menu(root_menuitem, dbus_interface); -} - - -/* Main, is well, main. It brings everything up and throws - us into the mainloop of no return. Some refactoring needed.*/ +/** +main: +**/ int main (int argc, char ** argv) { @@ -167,16 +66,7 @@ main (int argc, char ** argv) INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), NULL); - 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_DBUS_OBJECT); - dbusmenu_server_set_root(server, root_menuitem); - establish_pulse_activities(dbus_interface); + dbus_menu_manager_setup(); // Run the loop mainloop = g_main_loop_new(NULL, FALSE); |