diff options
-rw-r--r-- | .bzrignore | 32 | ||||
-rw-r--r-- | configure.ac | 19 | ||||
-rw-r--r-- | src/Makefile.am | 59 | ||||
-rw-r--r-- | src/dbus-menu-manager.c | 13 | ||||
-rw-r--r-- | src/dbus-shared-names.h | 10 | ||||
-rw-r--r-- | src/indicator-sound.c | 384 | ||||
-rw-r--r-- | src/metadata-widget.c | 23 | ||||
-rw-r--r-- | src/scrub-widget.c | 376 | ||||
-rw-r--r-- | src/scrub-widget.h | 53 | ||||
-rw-r--r-- | src/settings-manager.vala | 4 | ||||
-rw-r--r-- | src/slider-menu-item.c | 26 | ||||
-rw-r--r-- | src/sound-service-dbus.c | 225 | ||||
-rw-r--r-- | src/sound-service-dbus.h | 1 | ||||
-rw-r--r-- | src/title-menu-item.vala | 2 | ||||
-rw-r--r-- | src/title-widget.c | 17 | ||||
-rw-r--r-- | src/transport-menu-item.vala | 21 | ||||
-rw-r--r-- | src/transport-widget.c | 24 | ||||
-rw-r--r-- | src/volume-widget.c | 25 |
18 files changed, 557 insertions, 757 deletions
@@ -50,3 +50,35 @@ src/libsoundmenu_la-indicator-sound.lo src/libsoundmenu_la-sound-service-marshal.lo ruby_dbus_scripts/dbus_monitor.rb +.anjuta +.anjuta_sym_db.db +TODO.tasks +make_output.txt +swap-over.anjuta +src/fetch-file.c +src/freedesktop-interfaces.c +src/gen-sound-service.xml.c +src/gen-sound-service.xml.h +src/libsoundmenu_la-metadata-widget.lo +src/libsoundmenu_la-title-widget.lo +src/libsoundmenu_la-transport-widget.lo +src/libsoundmenu_la-volume-widget.lo +src/metadata-menu-item.c +src/mpris2-controller.c +src/mpris2-interfaces.c +src/mpris2-watcher.c +src/music-player-bridge.c +src/music-player-bridge.h +src/music_bridge_vala.stamp +src/player-controller.c +src/player-item.c +src/playlists-menu-item.c +src/settings-manager.c +src/title-menu-item.c +src/transport-menu-item.c +modified: +src/indicator-sound.c +data/com.canonical.indicators.sound.gschema.valid +tests/libmockpulse.la +tests/libmockpulse_la-mockpulse.lo +src/libsoundmenu_la-gen-sound-service.xml.lo diff --git a/configure.ac b/configure.ac index 1297120..aeeb41f 100644 --- a/configure.ac +++ b/configure.ac @@ -28,18 +28,17 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) ########################### GTK_REQUIRED_VERSION=2.12 -INDICATOR_REQUIRED_VERSION=0.3.6 -DBUSMENUGTK_REQUIRED_VERSION=0.2.2 +INDICATOR_REQUIRED_VERSION=0.3.15 +DBUSMENUGTK_REQUIRED_VERSION=0.3.9 POLKIT_REQUIRED_VERSION=0.92 PULSE_AUDIO_REQUIRED_VERSION=0.9.19 INDICATOR_DISPLAY_OBJECTS=0.1.11 -INDICATE_REQUIRED_VERSION=0.4.1 -DBUSMENUGLIB_REQUIRED_VERSION=0.3.1 +DBUSMENUGLIB_REQUIRED_VERSION=0.3.9 GIO_2_0_REQUIRED_VERSION=2.25.13 -PKG_CHECK_MODULES(APPLET,gtk+-2.0 >= $GTK_REQUIRED_VERSION +PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION indicator >= $INDICATOR_REQUIRED_VERSION - dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION + dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS) AC_SUBST(APPLET_CFLAGS) @@ -51,15 +50,13 @@ PKG_CHECK_MODULES(PULSEAUDIO, libpulse-mainloop-glib >= $PULSE_AUDIO_REQUIRED_VE AC_SUBST(PULSEAUDIO_CFLAGS) AC_SUBST(PULSEAUDIO_LIBS) -PKG_CHECK_MODULES(SOUNDSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION +PKG_CHECK_MODULES(SOUNDSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION indicator >= $INDICATOR_REQUIRED_VERSION - indicate >= $INDICATE_REQUIRED_VERSION - gee-1.0 + gee-1.0 gio-unix-2.0 libxml-2.0) - AC_SUBST(SOUNDSERVICE_CFLAGS) -AC_SUBST(SOUNDERVICE_LIBS) +AC_SUBST(SOUNDSERVICE_LIBS) AC_PATH_PROG(GCONFTOOL, gconftool-2) dnl Specify the gconf configuration source, diff --git a/src/Makefile.am b/src/Makefile.am index 7fe7e0f..32b6928 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,10 +18,11 @@ libsoundmenu_la_SOURCES = \ title-widget.h \ volume-widget.c \ volume-widget.h \ - dbus-shared-names.h \ - sound-service-client.h + gen-sound-service.xml.h \ + 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 @@ -29,30 +30,14 @@ checkxml: $(srcdir)/sound-service.xml @xmllint -valid -noout $< @echo $< checks out ok -sound-service-client.h: $(srcdir)/sound-service.xml - dbus-binding-tool \ - --prefix=_sound_service_client \ - --mode=glib-client \ - --output=sound-service-client.h \ - $(srcdir)/sound-service.xml - #################################################################### # Sound Service #################################################################### -################# -# dbus interface -################# -sound-service-server.h: $(srcdir)/sound-service.xml - dbus-binding-tool \ - --prefix=_sound_service_server \ - --mode=glib-server \ - --output=sound-service-server.h \ - $(srcdir)/sound-service.xml ##################### -# libsoundmenu vala +# Sound service vala ##################### music_bridge_VALASOURCES = \ music-player-bridge.vala \ @@ -78,7 +63,7 @@ music_bridge_VALAFLAGS = \ --vapidir=./ \ --thread \ --pkg gee-1.0 \ - --pkg Dbusmenu-Glib-0.2 \ + --pkg Dbusmenu-Glib-0.4 \ --pkg common-defs \ --pkg gio-2.0 \ --pkg gio-unix-2.0 \ @@ -96,7 +81,7 @@ music_bridge_vala.stamp $(music_bridge_APIFILES): $(music_bridge_VALASOURCES) touch music_bridge_vala.stamp ############################### -# libsoundmenu C +# Sound Service C ############################### indicator_sound_service_SOURCES = \ common-defs.h \ @@ -108,33 +93,47 @@ indicator_sound_service_SOURCES = \ pulse-manager.c \ sound-service-dbus.h \ sound-service-dbus.c \ - sound-service-server.h \ slider-menu-item.h \ slider-menu-item.c \ + gen-sound-service.xml.h \ + gen-sound-service.xml.c \ $(music_bridge_VALASOURCES:.vala=.c) indicator_sound_service_CFLAGS = $(PULSEAUDIO_CFLAGS) $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall indicator_sound_service_LDADD = $(PULSEAUDIO_LIBS) $(SOUNDSERVICE_LIBS) $(GCONF_LIBS) ######################### -# Extra stuff to package +# Service xml compilation ######################### +DBUS_SPECS = \ + sound-service.xml + +gen-%.xml.h: %.xml + @echo "Building $@ from $<" + @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ + +gen-%.xml.c: %.xml + @echo "Building $@ from $<" + @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ + @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ + @echo ";" >> $@ + + EXTRA_DIST = \ + $(DBUS_SPECS) \ sound-service.xml \ - sound-service.list \ $(music_bridge_APIFILES) \ $(music_bridge_VALASOURCES) - + ####################### # Stuff to clean Stuff ####################### BUILT_SOURCES = \ music_bridge_vala.stamp \ - sound-service-client.h \ - sound-service-server.h \ $(music_bridge_APIFILES) \ + gen-sound-service.xml.h \ + gen-sound-service.xml.c \ $(music_bridge_VALASOURCES:.vala=.c) - + CLEANFILES = \ $(BUILT_SOURCES) - diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index f92c324..92bfba5 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -21,9 +21,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <unistd.h> #include <glib/gi18n.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-bindings.h> - #include <libdbusmenu-glib/server.h> #include <libdbusmenu-glib/client.h> @@ -71,7 +68,7 @@ DbusmenuMenuitem* dbus_menu_manager_setup() dbus_interface = g_object_new(SOUND_SERVICE_DBUS_TYPE, NULL); - DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_DBUS_OBJECT); + 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; @@ -79,10 +76,10 @@ DbusmenuMenuitem* dbus_menu_manager_setup() void dbus_menu_manager_update_volume(gdouble volume) { - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, volume); - dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_VOLUME_MENUITEM_LEVEL, &value); + GVariant* new_volume = g_variant_new_double(volume); + dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(volume_slider_menuitem), + DBUSMENU_VOLUME_MENUITEM_LEVEL, + new_volume); } diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 9d1e875..bdc40cb 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -26,9 +26,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define __DBUS_SHARED_NAMES_H__ 1 #define INDICATOR_SOUND_DBUS_NAME "com.canonical.indicators.sound" -#define INDICATOR_SOUND_DBUS_OBJECT "/com/canonical/indicators/sound/menu" -#define INDICATOR_SOUND_SERVICE_DBUS_OBJECT "/com/canonical/indicators/sound/service" -#define INDICATOR_SOUND_SERVICE_DBUS_INTERFACE "com.canonical.indicators.sound" +#define INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH "/com/canonical/indicators/sound/menu" +#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" + #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 34f5ed9..cdcc723 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -7,7 +7,6 @@ Copyright 2010 Canonical Ltd. Authors: Conor Curran <conor.curran@canonical.com> Ted Gould <ted@canonical.com> - Cody Russell <cody.russell@canonical.com> 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 @@ -29,8 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libdbusmenu-gtk/menu.h> #include <libido/idoscalemenuitem.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-bindings.h> +#include <gio/gio.h> #include "indicator-sound.h" #include "transport-widget.h" @@ -39,7 +37,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "volume-widget.h" #include "dbus-shared-names.h" -#include "sound-service-client.h" + +#include "gen-sound-service.xml.h" #include "common-defs.h" typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; @@ -48,6 +47,7 @@ struct _IndicatorSoundPrivate { GtkWidget* volume_widget; GList* transport_widgets_list; + GDBusProxy *dbus_proxy; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -81,13 +81,36 @@ static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); // DBUS communication -static DBusGProxy *sound_dbus_proxy = NULL; -static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); -static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata); -static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); -static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata); -static void fetch_mute_value_from_dbus(); -static void fetch_sink_availability_from_dbus(IndicatorSound* self); + +static GDBusNodeInfo *node_info = NULL; +static GDBusInterfaceInfo *interface_info = NULL; +static void create_connection_to_service (GObject *source_object, + GAsyncResult *res, + gpointer user_data); +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 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); @@ -138,15 +161,15 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_menu = get_menu; io_class->scroll = indicator_sound_scroll; design_team_size = gtk_icon_size_register("design-team-size", 22, 22); - - return; } static void indicator_sound_init (IndicatorSound *self) { self->service = NULL; - self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); + self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_DBUS_VERSION); + prepare_state_machine(); prepare_blocked_animation(); animation_id = 0; @@ -156,13 +179,13 @@ indicator_sound_init (IndicatorSound *self) 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; - + g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); - return; } static void @@ -219,7 +242,8 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_MENU_DBUS_OBJECT_PATH); DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); @@ -247,7 +271,7 @@ free_the_animation_list() static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - //g_debug("indicator-sound: new_transport_bar() called "); + g_debug("indicator-sound: new_transport_bar() called "); GtkWidget* bar = NULL; IndicatorObject *io = NULL; @@ -271,7 +295,7 @@ new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - //g_debug("indicator-sound: new_metadata_widget"); + g_debug("indicator-sound: new_metadata_widget"); GtkWidget* metadata = NULL; @@ -290,11 +314,10 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - //g_debug("indicator-sound: new_title_widget"); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - //g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, DBUSMENU_TITLE_MENUITEM_NAME)); + g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, DBUSMENU_TITLE_MENUITEM_NAME)); GtkWidget* title = NULL; @@ -312,7 +335,7 @@ new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - //g_debug("indicator-sound: new_volume_slider_widget"); + g_debug("indicator-sound: new_volume_slider_widget"); GtkWidget* volume_widget = NULL; IndicatorObject *io = NULL; @@ -337,70 +360,190 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_item, - parent); - fetch_mute_value_from_dbus(); - fetch_sink_availability_from_dbus(INDICATOR_SOUND (io)); + parent); + fetch_state(INDICATOR_SOUND (io)); return TRUE; } static void -connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) -{ - if (connected) { - gboolean service_restart = FALSE; - if (sound_dbus_proxy != NULL) { - g_object_unref (sound_dbus_proxy); - sound_dbus_proxy = NULL; - service_restart = TRUE; - } - GError * error = NULL; - - DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - - sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus, - INDICATOR_SOUND_DBUS_NAME, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT, - INDICATOR_SOUND_SERVICE_DBUS_INTERFACE, - &error); +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("Unable to get status proxy: %s", error->message); + g_warning( "Failed to get create interface info from xml: %s", + error->message ); g_error_free(error); + return; } - //g_debug("about to connect to the signals"); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), user_data, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); - - if( service_restart == TRUE){ - fetch_mute_value_from_dbus(); - // Ensure UI is in sync with service again. - IndicatorSound* indicator = INDICATOR_SOUND(user_data); - fetch_sink_availability_from_dbus(indicator); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); - if(priv->volume_widget != NULL){ - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); - } + } + + 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 "'"); } - } - else{ - g_warning("Indicator has been disconnected from the service -> SHOCK HORROR"); - IndicatorSound* indicator = INDICATOR_SOUND(user_data); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); - - if(priv->volume_widget != NULL){ - g_warning("indicator still has a slider, service must have crashed"); - volume_widget_tidy_up(priv->volume_widget); - g_object_unref(G_OBJECT(priv->volume_widget)); - priv->volume_widget = NULL; - } - device_available = FALSE; + } + + g_dbus_proxy_new_for_bus( G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + interface_info, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_MENU_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; + } + + g_debug ( "about to connect to g-signal "); + g_signal_connect(priv->dbus_proxy, "g-signal", + G_CALLBACK(g_signal_cb), self); + g_debug ( "after attempting to connect to g-signal "); + + fetch_state (self); +} + +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); } /* @@ -550,69 +693,39 @@ reset_mute_blocking_animation() } + /*******************************************************************/ -//DBus method handlers +// DBUS Signal reactions /*******************************************************************/ -static void -fetch_sink_availability_from_dbus(IndicatorSound* self) +static void g_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data) { - g_return_if_fail(IS_INDICATOR_SOUND(self)); - - GError * error = NULL; - gboolean * available_input; - available_input = g_new0(gboolean, 1); - com_canonical_indicators_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); - if (error != NULL) { - g_warning("Unable to fetch AVAILABILITY at indicator start up: %s", error->message); - g_error_free(error); - g_free(available_input); - return; - } - - device_available = *available_input; - if (device_available == FALSE) { - update_state(STATE_SINKS_NONE); - //g_debug("NO DEVICE AVAILABLE"); - } + IndicatorSound *self = INDICATOR_SOUND(user_data); + g_return_if_fail ( IS_INDICATOR_SOUND(self) ); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(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); - 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_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 ); } - - g_free(available_input); - //g_debug("IndicatorSound::fetch_sink_availability_from_dbus ->%i", device_available); -} - - -static void -fetch_mute_value_from_dbus() -{ - GError * error = NULL; - gboolean *mute_input; - mute_input = g_new0(gboolean, 1); - com_canonical_indicators_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); - if (error != NULL) { - g_warning("Unable to fetch MUTE at indicator start up: %s", error->message); - g_error_free(error); - g_free(mute_input); - return; + else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_MUTE_UPDATE) == 0){ + react_to_signal_sink_mute_update ( input, self ); } - initial_mute = *mute_input; - if (initial_mute == TRUE){ - update_state(STATE_MUTED); + else if (g_strcmp0(signal_name, INDICATOR_SOUND_SIGNAL_SINK_INPUT_WHILE_MUTED) == 0){ + react_to_signal_sink_input_while_muted ( input, self ); } - g_free(mute_input); - //g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } -/*******************************************************************/ -//DBus signal catchers -/*******************************************************************/ static void -catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) +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) { @@ -627,7 +740,7 @@ catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gp UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. */ static void -catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) +react_to_signal_sink_mute_update(gboolean mute_value, IndicatorSound* self) { if (mute_value == TRUE && device_available == TRUE) { update_state(STATE_MUTED); @@ -635,25 +748,30 @@ catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer u reset_mute_blocking_animation(); } //g_debug("signal caught - sink mute update with mute value: %i", mute_value); - g_return_if_fail(IS_INDICATOR_SOUND(userdata)); - IndicatorSound* indicator = INDICATOR_SOUND(userdata); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + 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 -catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) +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); } @@ -724,7 +842,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } } else if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { - TransportWidget* transport_widget; + TransportWidget* transport_widget = NULL; GList* elem; for ( elem = priv->transport_widgets_list; elem; elem = elem->next ) { @@ -779,7 +897,7 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) menuitem = GTK_MENU_SHELL (widget)->active_menu_item; if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { - TransportWidget* transport_widget; + TransportWidget* transport_widget = NULL; GList* elem; for(elem = priv->transport_widgets_list; elem; elem = elem->next) { diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 191e134..09365d5 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -61,7 +61,7 @@ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, // Dbusmenuitem properties update callback static void metadata_widget_property_update (DbusmenuMenuitem* item, gchar* property, - GValue* value, + GVariant* value, gpointer userdata); static void metadata_widget_style_labels ( MetadataWidget* self, GtkLabel* label); @@ -400,38 +400,37 @@ metadata_widget_button_press_event (GtkWidget *menuitem, // TODO: Manage empty/mangled music details <unknown artist> etc. static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) + GVariant* value, gpointer userdata) { g_return_if_fail (IS_METADATA_WIDGET (userdata)); - if(g_value_get_int(value) == DBUSMENU_PROPERTY_EMPTY){ + if(g_variant_is_of_type(value, G_VARIANT_TYPE_INT32) == TRUE && + g_variant_get_int32(value) == DBUSMENU_PROPERTY_EMPTY){ //g_debug("Metadata widget: property update - reset"); - GValue new_value = {0}; - g_value_init(&new_value, G_TYPE_STRING); - g_value_set_string(&new_value, g_strdup("")); - value = &new_value; + GVariant* new_value = g_variant_new_string (""); + value = new_value; } MetadataWidget* mitem = METADATA_WIDGET(userdata); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(mitem); if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTIST, property) == 0){ - gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value)); + gtk_label_set_text(GTK_LABEL(priv->artist_label), g_variant_get_string(value, NULL)); metadata_widget_style_labels(mitem, GTK_LABEL(priv->artist_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TITLE, property) == 0){ - gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); + gtk_label_set_text(GTK_LABEL(priv->piece_label), g_variant_get_string(value, NULL)); metadata_widget_style_labels(mitem, GTK_LABEL(priv->piece_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ALBUM, property) == 0){ - gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); + gtk_label_set_text(GTK_LABEL(priv->container_label), g_variant_get_string(value, NULL)); metadata_widget_style_labels(mitem, GTK_LABEL(priv->container_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); - g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); + g_string_overwrite(priv->image_path, 0, g_variant_get_string (value, NULL)); // if its a remote image queue a redraw incase the download took too long - if (g_str_has_prefix(g_value_get_string (value), g_get_user_cache_dir())){ + if (g_str_has_prefix(g_variant_get_string (value, NULL), g_get_user_cache_dir())){ //g_debug("the image update is a download so redraw"); gtk_widget_queue_draw(GTK_WIDGET(mitem)); } diff --git a/src/scrub-widget.c b/src/scrub-widget.c deleted file mode 100644 index edc65de..0000000 --- a/src/scrub-widget.c +++ /dev/null @@ -1,376 +0,0 @@ -/* -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran <conor.curran@canonical.com> - -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 <http://www.gnu.org/licenses/>. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib/gi18n.h> -#include "scrub-widget.h" -#include "common-defs.h" -#include <libido/idoscalemenuitem.h> -#include <libido/idotimeline.h> - -typedef struct _ScrubWidgetPrivate ScrubWidgetPrivate; - -struct _ScrubWidgetPrivate -{ - DbusmenuMenuitem* twin_item; - GtkWidget* ido_scrub_bar; - IdoTimeline* time_line; - gboolean scrubbing; -}; - -#define SCRUB_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SCRUB_WIDGET_TYPE, ScrubWidgetPrivate)) - -/* Prototypes */ -static void scrub_widget_class_init (ScrubWidgetClass *klass); -static void scrub_widget_init (ScrubWidget *self); -static void scrub_widget_dispose (GObject *object); -static void scrub_widget_finalize (GObject *object); -static void scrub_widget_property_update( DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata); -static void scrub_widget_set_twin_item( ScrubWidget* self, - DbusmenuMenuitem* twin_item); -static gchar* scrub_widget_format_time(gint time); -static void scrub_widget_set_ido_position(ScrubWidget* self, - gint position, - gint duration); -static gboolean scrub_widget_change_value_cb (GtkRange *range, - GtkScrollType scroll, - gdouble value, - gpointer user_data); - -static void scrub_widget_timeline_frame_cb(IdoTimeline *timeline, - gdouble progress, - gpointer userdata); -static void scrub_widget_timeline_started_cb(IdoTimeline *timeline, - gpointer userdata); -static void scrub_widget_timeline_finished_cb(IdoTimeline *timeline, - gpointer userdata); -static gdouble scrub_widget_calculate_progress(ScrubWidget* widget); -static void scrub_widget_check_play_state(ScrubWidget* self); -static void scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); -static void scrub_widget_slider_released(GtkWidget *widget, gpointer user_data); - - - -G_DEFINE_TYPE (ScrubWidget, scrub_widget, G_TYPE_OBJECT); - -static void -scrub_widget_class_init (ScrubWidgetClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ScrubWidgetPrivate)); - - gobject_class->dispose = scrub_widget_dispose; - gobject_class->finalize = scrub_widget_finalize; -} - -static void -scrub_widget_init (ScrubWidget *self) -{ - g_debug("ScrubWidget::scrub_widget_init"); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); - - priv->ido_scrub_bar = ido_scale_menu_item_new_with_range ("Scrub", IDO_RANGE_STYLE_SMALL, 0, 0, 100, 1); - priv->time_line = ido_timeline_new(0); - - ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), IDO_SCALE_MENU_ITEM_STYLE_LABEL); - - g_object_set(priv->ido_scrub_bar, "reverse-scroll-events", TRUE, NULL); - priv->scrubbing = FALSE; - - gtk_widget_set_size_request(GTK_WIDGET(priv->ido_scrub_bar), 100, 25); - - // register slider changes listening on the range - GtkWidget* scrub_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); - g_signal_connect(scrub_widget, "change-value", G_CALLBACK(scrub_widget_change_value_cb), self); - g_signal_connect(priv->time_line, "frame", G_CALLBACK(scrub_widget_timeline_frame_cb), self); - g_signal_connect(priv->time_line, "started", G_CALLBACK(scrub_widget_timeline_started_cb), self); - g_signal_connect(priv->time_line, "finished", G_CALLBACK(scrub_widget_timeline_finished_cb), self); - g_signal_connect(priv->ido_scrub_bar, "slider-grabbed", G_CALLBACK(scrub_widget_slider_grabbed), self); - g_signal_connect(priv->ido_scrub_bar, "slider-released", G_CALLBACK(scrub_widget_slider_released), self); - -} - -static void -scrub_widget_dispose (GObject *object) -{ - G_OBJECT_CLASS (scrub_widget_parent_class)->dispose (object); -} - -static void -scrub_widget_finalize (GObject *object) -{ - G_OBJECT_CLASS (scrub_widget_parent_class)->finalize (object); -} - -static void -scrub_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) -{ - g_debug("scrub-widget::property_update"); - - g_return_if_fail (IS_SCRUB_WIDGET (userdata)); - ScrubWidget* mitem = SCRUB_WIDGET(userdata); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); - - if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_DURATION, property) == 0){ - g_debug("scrub-widget::update length = %i", g_value_get_int(value)); - - ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), - scrub_widget_format_time(g_value_get_int(value))); - - ido_timeline_set_duration(priv->time_line, g_value_get_int(value) * 1000); - ido_timeline_rewind(priv->time_line); - scrub_widget_check_play_state(mitem); - //g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line)); - //g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line)); - - scrub_widget_set_ido_position(mitem, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); - } - else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_POSITION, property) == 0){ - g_debug("scrub-widget::update position = %i", g_value_get_int(value)); - ido_timeline_pause(priv->time_line); - ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), - scrub_widget_format_time(g_value_get_int(value)/1000)); - - g_debug("scrub-widget::update progress = %f", scrub_widget_calculate_progress(mitem)*100); - - ido_timeline_set_progress(priv->time_line, scrub_widget_calculate_progress(mitem)); - scrub_widget_set_ido_position(mitem, g_value_get_int(value)/1000, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); - - scrub_widget_check_play_state(mitem); - } - else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_PLAY_STATE, property) == 0){ - scrub_widget_check_play_state(mitem); - } -} - -static void -scrub_widget_check_play_state(ScrubWidget* self) -{ - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); - gint play_state = dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_PLAY_STATE); - g_debug("play-state = %i", play_state); - if(play_state == 0){ - g_debug("START TIMELINE"); - ido_timeline_start(priv->time_line); - } - else{ - g_debug("PAUSE TIMELINE"); - ido_timeline_pause(priv->time_line); - } -} - -static void -scrub_widget_set_twin_item(ScrubWidget* self, - DbusmenuMenuitem* twin_item) -{ - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); - priv->twin_item = twin_item; - - g_signal_connect(G_OBJECT(twin_item), "property-changed", - G_CALLBACK(scrub_widget_property_update), self); - - gchar* left_text = scrub_widget_format_time(dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_POSITION)/1000); - gchar* right_text = scrub_widget_format_time(dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_DURATION)); - scrub_widget_set_ido_position(self, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); - - ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), left_text); - ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), right_text); - g_free(left_text); - g_free(right_text); -} - -static gboolean -scrub_widget_change_value_cb (GtkRange *range, - GtkScrollType scroll, - gdouble new_value, - gpointer user_data) -{ - g_return_val_if_fail (IS_SCRUB_WIDGET (user_data), FALSE); - ScrubWidget* mitem = SCRUB_WIDGET(user_data); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); - - // Don't bother when the slider is grabbed - if(priv->scrubbing == TRUE) - return FALSE; - - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - gdouble clamped = CLAMP(new_value, 0, 100); - g_value_set_double(&value, clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0); - return TRUE; -} - -GtkWidget* -scrub_widget_get_ido_bar(ScrubWidget* self) -{ - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); - return priv->ido_scrub_bar; -} - -static gchar* -scrub_widget_format_time(gint time) -{ -// Assuming its in seconds for now ... - gchar* prefix = "-"; - gchar* seconds_prefix = "-"; - - if(time != DBUSMENU_PROPERTY_EMPTY){ - gint minutes = time/60; - gint seconds = time % 60; - prefix="0"; - seconds_prefix="0"; - if(minutes > 9) - prefix=""; - if(seconds > 9) - seconds_prefix=""; - return g_strdup_printf("%s%i:%s%i", prefix, minutes, seconds_prefix, seconds); - - } - else{ - return g_strdup_printf("%s-:%s-", prefix, seconds_prefix); - } -} - -static void -scrub_widget_set_ido_position(ScrubWidget* self, - gint position, - gint duration) -{ - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); - gdouble ido_position = position/(gdouble)duration * 100.0; - g_debug("scrub_widget_set_ido_position - pos: %i, duration: %i, ido_pos: %f", position, duration, ido_position); - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); - GtkRange *range = (GtkRange*)slider; - if(duration == 0) - ido_position = 0.0; - gtk_range_set_value(range, ido_position); -} - -static gdouble -scrub_widget_calculate_progress(ScrubWidget* widget) -{ - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(widget); - gint position = dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_POSITION)/1000; - gint duration = dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_DURATION); - gdouble ido_position = position/(gdouble)duration; - g_debug("scrub_widget_calculate_progress %f", ido_position); - - return ido_position; -} - - -static void -scrub_widget_timeline_frame_cb( IdoTimeline *timeline, - gdouble progress, - gpointer user_data) -{ - - //g_debug("Timeline CB : %f", progress); - g_return_if_fail (IS_SCRUB_WIDGET (user_data)); - ScrubWidget* mitem = SCRUB_WIDGET(user_data); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); - if(priv->scrubbing == TRUE) - { - g_debug("don't update the slider or timeline, slider is being scrubbed"); - return; - } - gint position = progress * dbusmenu_menuitem_property_get_int(priv->twin_item, - DBUSMENU_SCRUB_MENUITEM_DURATION); - gchar* left_text = scrub_widget_format_time(position); - ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), left_text); - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); - GtkRange *range = (GtkRange*)slider; - gtk_range_set_value(range, progress * 100); - /*g_debug("position in seconds %i and in words %s", position, left_text); - g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line)); - g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line)); - */ - //g_debug("timeline-update - progress = %f", progress); - g_free(left_text); -} - - -static void -scrub_widget_slider_released(GtkWidget *widget, gpointer user_data) -{ - ScrubWidget* mitem = SCRUB_WIDGET(user_data); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); - priv->scrubbing = FALSE; - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); - gdouble new_value = gtk_range_get_value(GTK_RANGE(slider)); - g_debug("okay set the scrub position with %f", new_value); - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - gdouble clamped = CLAMP(new_value, 0, 100); - g_value_set_double(&value, clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0); -} - -static void -scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data) -{ - ScrubWidget* mitem = SCRUB_WIDGET(user_data); - ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); - priv->scrubbing = TRUE; -} - -static void -scrub_widget_timeline_started_cb( IdoTimeline *timeline, - gpointer user_data) -{ - g_debug("Timeline Started!"); -} - -static void -scrub_widget_timeline_finished_cb(IdoTimeline *timeline, - gpointer user_data) -{ - g_debug("Timeline Finished!"); -} - -/** - * scrub_widget_new: - * @returns: a new #ScrubWidget. - **/ -GtkWidget* -scrub_widget_new(DbusmenuMenuitem *item) -{ - GtkWidget* widget = g_object_new(SCRUB_WIDGET_TYPE, NULL); - scrub_widget_set_twin_item((ScrubWidget*)widget, item); - return widget; -} - - diff --git a/src/scrub-widget.h b/src/scrub-widget.h deleted file mode 100644 index cf6cc5e..0000000 --- a/src/scrub-widget.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran <conor.curran@canonical.com> - -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 <http://www.gnu.org/licenses/>. -*/ -#ifndef __SCRUB_WIDGET_H__ -#define __SCRUB_WIDGET_H__ - -#include <glib.h> -#include <glib-object.h> -#include <libdbusmenu-gtk/menuitem.h> - -G_BEGIN_DECLS - -#define SCRUB_WIDGET_TYPE (scrub_widget_get_type ()) -#define SCRUB_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SCRUB_WIDGET_TYPE, ScrubWidget)) -#define SCRUB_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SCRUB_WIDGET_TYPE, ScrubWidgetClass)) -#define IS_SCRUB_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SCRUB_WIDGET_TYPE)) -#define IS_SCRUB_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SCRUB_WIDGET_TYPE)) -#define SCRUB_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SCRUB_WIDGET_TYPE, ScrubWidgetClass)) - -typedef struct _ScrubWidget ScrubWidget; -typedef struct _ScrubWidgetClass ScrubWidgetClass; - -struct _ScrubWidgetClass { - GObjectClass parent_class; -}; - -struct _ScrubWidget { - GObject parent; -}; - -GType scrub_widget_get_type (void) G_GNUC_CONST; -GtkWidget* scrub_widget_new(DbusmenuMenuitem* twin_item); -GtkWidget* scrub_widget_get_ido_bar(ScrubWidget* self); - -G_END_DECLS - -#endif - diff --git a/src/settings-manager.vala b/src/settings-manager.vala index 57b4487..380e442 100644 --- a/src/settings-manager.vala +++ b/src/settings-manager.vala @@ -55,7 +55,7 @@ public class SettingsManager : GLib.Object public void add_interested(string app_desktop_name) { var already_interested = this.settings.get_strv ("interested-media-players"); - foreach ( var s in already_interested){ + foreach (var s in already_interested){ if ( s == app_desktop_name ) return; } already_interested += (app_desktop_name); @@ -68,4 +68,4 @@ public class SettingsManager : GLib.Object { this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); } -}
\ No newline at end of file +} diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index d0d2050..0f2f07b 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -39,7 +39,8 @@ static void slider_menu_item_class_init (SliderMenuItemClass *klass); static void slider_menu_item_init (SliderMenuItem *self); static void slider_menu_item_dispose (GObject *object); static void slider_menu_item_finalize (GObject *object); -static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); +static void handle_event (DbusmenuMenuitem * mi, const gchar * name, + GVariant * value, guint timestamp); G_DEFINE_TYPE (SliderMenuItem, slider_menu_item, DBUSMENU_TYPE_MENUITEM); @@ -77,12 +78,29 @@ slider_menu_item_finalize (GObject *object) static void -handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) +handle_event (DbusmenuMenuitem * mi, + const gchar * name, + GVariant * value, + guint timestamp) { gdouble volume_input = 0; - volume_input = g_value_get_double(value); - if (value != NULL) + /*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; + 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); + } + + volume_input = g_variant_get_double(input); + if (value != NULL){ set_sink_volume(volume_input); + } + g_variant_unref (input); } diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 0760247..9490df8 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -3,7 +3,7 @@ * * Authors: * Conor Curran <conor.curran@canonical.com> - * Cody Russell <crussell@canonical.com> + * Ted Gould <ted.gould@canonical.com> * * 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 @@ -22,36 +22,41 @@ #include "config.h" #endif -#include <dbus/dbus-glib.h> +#include <gio/gio.h> +#include <libindicator/indicator-service.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" // DBUS methods -static gboolean sound_service_dbus_get_sink_mute(SoundServiceDbus* service, gboolean* mute_input, GError** gerror); -static gboolean sound_service_dbus_get_sink_availability(SoundServiceDbus* service, gboolean* availability_input, GError** gerror); +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); + +static GDBusInterfaceVTable interface_table = { + method_call: bus_method_call, + get_property: NULL, /* No properties */ + set_property: NULL /* No properties */ +}; -#include "sound-service-server.h" typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { - DBusGConnection *connection; - gboolean mute; - gboolean sink_availability; -}; - -/* Signals */ -enum { - SINK_INPUT_WHILE_MUTED, - SINK_MUTE_UPDATE, - SINK_AVAILABLE_UPDATE, - LAST_SIGNAL + GDBusConnection *connection; + gboolean mute; + gboolean sink_availability; }; - -static guint signals[LAST_SIGNAL] = { 0 }; +static GDBusNodeInfo * node_info = NULL; +static GDBusInterfaceInfo * interface_info = NULL; #define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate)) @@ -74,31 +79,26 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) object_class->finalize = sound_service_dbus_finalize; g_assert(klass != NULL); - dbus_g_object_type_install_info(SOUND_SERVICE_DBUS_TYPE, - &dbus_glib__sound_service_server_object_info); - - signals[SINK_INPUT_WHILE_MUTED] = g_signal_new("sink-input-while-muted", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - - signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - signals[SINK_AVAILABLE_UPDATE] = g_signal_new("sink-available-update", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + + if (node_info == NULL) { + GError * error = NULL; + + node_info = g_dbus_node_info_new_for_xml(_sound_service, &error); + if (error != NULL) { + g_error("Unable to parse Indicator Service Interface description: %s", + error->message); + g_error_free(error); + } + } + + 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 "'"); + } + } } static void @@ -112,7 +112,7 @@ sound_service_dbus_init (SoundServiceDbus *self) priv->sink_availability = FALSE; /* Fetch the session bus */ - priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_error("sound-service-dbus:Unable to connect to the session bus when creating indicator sound service : %s", error->message); @@ -120,12 +120,20 @@ sound_service_dbus_init (SoundServiceDbus *self) return; } /* register the service on it */ - dbus_g_connection_register_g_object(priv->connection, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT, - G_OBJECT(self)); + g_dbus_connection_register_object (priv->connection, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH, + interface_info, + &interface_table, + self, + NULL, + &error); + if (error != NULL) { + g_error("Unable to register the object to DBus: %s", error->message); + g_error_free(error); + return; + } } - static void sound_service_dbus_dispose (GObject *object) { @@ -140,60 +148,111 @@ sound_service_dbus_finalize (GObject *object) return; } - -static gboolean sound_service_dbus_get_sink_mute (SoundServiceDbus *self, gboolean *mute_input, GError** gerror) -{ - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - g_debug("Get sink mute - sound service dbus!, about to send over mute_value of %i", priv->mute); - *mute_input = priv->mute; - return TRUE; +/* A method has been called from our dbus inteface. Figure out what it + is and dispatch it. */ +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, "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); } -static gboolean sound_service_dbus_get_sink_availability (SoundServiceDbus *self, gboolean *availability_input, GError** gerror) -{ - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - g_debug("Get sink availability - sound service dbus!, about to send over availability_value of %i", priv->sink_availability); - *availability_input = priv->sink_availability; - return TRUE; -} /** 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) +void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, + gboolean block_value) { - /* g_debug("Emitting signal: SINK_INPUT_WHILE_MUTED, with block_value: %i", block_value);*/ - g_signal_emit(obj, - signals[SINK_INPUT_WHILE_MUTED], - 0, - block_value); + 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; + } } -void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute) +void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, + gboolean sink_mute) { - /* g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);*/ - + 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; - g_signal_emit(obj, - signals[SINK_MUTE_UPDATE], - 0, - priv->mute); + GVariant* v_output = g_variant_new("(b)", sink_mute); + GError * error = NULL; + g_dbus_connection_emit_signal( priv->connection, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_MENU_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; + } } -void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, gboolean sink_availability) +void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, + gboolean sink_availability) { - /* g_debug("Emitting signal: SINK_AVAILABILITY_UPDATE, with value %i", sink_availability);*/ - + g_debug("Emitting signal: SinkAvailableUpdate, with %i", sink_availability); SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); priv->sink_availability = sink_availability; - - g_signal_emit(obj, - signals[SINK_AVAILABLE_UPDATE], - 0, - priv->sink_availability); + + GVariant* v_output = g_variant_new("(b)", priv->sink_availability); + GError * error = NULL; + + g_dbus_connection_emit_signal( priv->connection, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_MENU_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; + } } diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index b6e8193..0d1573b 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -48,6 +48,7 @@ struct _SoundServiceDbus { struct _SoundServiceDbusClass { GObjectClass parent_class; }; + GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the SIGNAL messages across into the sound-service-dbus diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index 0b99ae3..6ed24d8 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -31,7 +31,7 @@ public class TitleMenuitem : PlayerItem this.property_set_bool(MENUITEM_RUNNING, false); } - public override void handle_event(string name, GLib.Value input_value, uint timestamp) + public override void handle_event(string name, Variant input_value, uint timestamp) { if(this.owner.current_state == PlayerController.state.OFFLINE) { diff --git a/src/title-widget.c b/src/title-widget.c index 08b4b81..675c59f 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -49,7 +49,7 @@ static gboolean title_widget_button_press_event (GtkWidget *menuitem, // Dbusmenuitem properties update callback static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata); + GVariant* value, gpointer userdata); static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, @@ -138,24 +138,23 @@ title_widget_button_press_event (GtkWidget *menuitem, //g_debug("TitleWidget::menu_press_event"); TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(menuitem); - GValue value = {0}; - g_value_init(&value, G_TYPE_BOOLEAN); - - g_value_set_boolean(&value, TRUE); - dbusmenu_menuitem_handle_event (priv->twin_item, "Title menu event", &value, 0); - + GVariant* new_title_event = g_variant_new_boolean(TRUE); + dbusmenu_menuitem_handle_event (priv->twin_item, + "Title menu event", + new_title_event, + 0); return FALSE; } static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) + GVariant* value, gpointer userdata) { g_return_if_fail (IS_TITLE_WIDGET (userdata)); TitleWidget* mitem = TITLE_WIDGET(userdata); if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), - g_value_get_string(value)); + g_variant_get_string(value, NULL)); } else if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_ICON, property) == 0){ title_widget_set_icon (mitem); diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 0e4e6ee..e93f0bb 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -36,8 +36,8 @@ public class TransportMenuitem : PlayerItem public TransportMenuitem(PlayerController parent) { - Object(item_type: MENUITEM_TYPE, owner: parent); - this.property_set_int(MENUITEM_PLAY_STATE, 1); + Object(item_type: MENUITEM_TYPE, owner: parent); + this.property_set_int(MENUITEM_PLAY_STATE, 1); } public void change_play_state(state update) @@ -47,11 +47,20 @@ public class TransportMenuitem : PlayerItem this.property_set_int(MENUITEM_PLAY_STATE, update); } - public override void handle_event(string name, GLib.Value input_value, uint timestamp) + public override void handle_event(string name, + Variant input_value, + uint timestamp) { - int input = input_value.get_int(); - debug("handle_event with value %s", input.to_string()); - debug("transport owner name = %s", this.owner.app_info.get_name()); + /*debug ( "Handle event in transport menu item - input variant is of type %s", + input_value.get_type_string() );*/ + Variant v = input_value; + if ( input_value.is_of_type ( VariantType.VARIANT) ){ + v = input_value.get_variant(); + } + + int32 input = v.get_int32(); + debug("transport menu item -> handle_event with value %s", input.to_string()); + //debug("transport owner name = %s", this.owner.app_info.get_name()); this.owner.mpris_bridge.transport_update((action)input); } diff --git a/src/transport-widget.c b/src/transport-widget.c index d7f4b75..a276a31 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -112,8 +112,8 @@ static gboolean transport_widget_leave_notify_event (GtkWidget *menuitem GdkEventCrossing *event); static void transport_widget_property_update ( DbusmenuMenuitem* item, gchar * property, - GValue * value, - gpointer userdata ); + GVariant * value, + gpointer userdata ); static void transport_widget_menu_hidden ( GtkWidget *menu, TransportWidget *transport); static void transport_widget_notify ( GObject *item, @@ -344,13 +344,11 @@ transport_widget_button_release_event (GtkWidget *menuitem, TransportWidgetEvent result = transport_widget_determine_button_event ( transport, event ); if(result != TRANSPORT_NADA){ - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); //g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); - g_value_set_int(&value, (int)result); + GVariant* new_transport_state = g_variant_new_int32 ((int)result); dbusmenu_menuitem_handle_event ( priv->twin_item, "Transport state change", - &value, + new_transport_state, 0 ); } transport_widget_react_to_button_release ( transport, @@ -402,13 +400,11 @@ transport_widget_react_to_key_release_event ( TransportWidget* transport, { if(transport_event != TRANSPORT_NADA){ TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); //g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); - g_value_set_int(&value, (int)transport_event); + GVariant* new_transport_event = g_variant_new_int32((int)transport_event); dbusmenu_menuitem_handle_event ( priv->twin_item, "Transport state change", - &value, + new_transport_event, 0 ); } transport_widget_react_to_button_release ( transport, @@ -761,7 +757,9 @@ _color_rgb_to_hls (gdouble *r, gdouble red; gdouble green; gdouble blue; - gdouble h, l, s; + gdouble h = 0; + gdouble l; + gdouble s; gdouble delta; red = *r; @@ -1700,7 +1698,7 @@ transport_widget_set_twin_item(TransportWidget* self, **/ static void transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) + GVariant* value, gpointer userdata) { //g_debug("transport_widget_update_state - with property %s", property); TransportWidget* bar = (TransportWidget*)userdata; @@ -1708,7 +1706,7 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_ascii_strcasecmp(DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE, property) == 0) { - int update_value = g_value_get_int(value); + int update_value = g_variant_get_int32(value); //g_debug("transport_widget_update_state - with value %i", update_value); transport_widget_toggle_play_pause(bar, (TransportWidgetState)update_value); } diff --git a/src/volume-widget.c b/src/volume-widget.c index c37f9c7..38dc9bb 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -28,6 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "volume-widget.h" #include "common-defs.h" #include <libido/idoscalemenuitem.h> +#include "indicator-sound.h" typedef struct _VolumeWidgetPrivate VolumeWidgetPrivate; @@ -48,7 +49,7 @@ static void volume_widget_finalize (GObject *object); static void volume_widget_set_twin_item( VolumeWidget* self, DbusmenuMenuitem* twin_item); static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata); + GVariant* value, gpointer userdata ); static gboolean volume_widget_change_value_cb (GtkRange *range, GtkScrollType scroll, @@ -122,8 +123,8 @@ volume_widget_finalize (GObject *object) } static void -volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) +volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, + GVariant* value, gpointer userdata) { g_return_if_fail (IS_VOLUME_WIDGET (userdata)); VolumeWidget* mitem = VOLUME_WIDGET(userdata); @@ -133,10 +134,10 @@ volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(priv->grabbed == FALSE){ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; - gdouble update = g_value_get_double (value); + 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); + determine_state_from_volume(update); } } } @@ -150,8 +151,8 @@ volume_widget_set_twin_item(VolumeWidget* self, g_object_ref(priv->twin_item); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(volume_widget_property_update), self); - gdouble initial_level = g_value_get_double (dbusmenu_menuitem_property_get_value(twin_item, - DBUSMENU_VOLUME_MENUITEM_LEVEL)); + gdouble initial_level = g_variant_get_double (dbusmenu_menuitem_property_get_variant(twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); //g_debug("volume_widget_set_twin_item initial level = %f", initial_level); GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; @@ -195,11 +196,9 @@ void volume_widget_update(VolumeWidget* self, gdouble update) { VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); gdouble clamped = CLAMP(update, 0, 100); - g_value_set_double(&value, clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "update", &value, 0); + GVariant* new_volume = g_variant_new_double(clamped); + dbusmenu_menuitem_handle_event (priv->twin_item, "update", new_volume, 0); } GtkWidget* @@ -246,8 +245,8 @@ volume_widget_get_current_volume ( GtkWidget *widget ) { VolumeWidget* mitem = VOLUME_WIDGET(widget); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - gdouble vol = g_value_get_double ( dbusmenu_menuitem_property_get_value( priv->twin_item, - DBUSMENU_VOLUME_MENUITEM_LEVEL)); + gdouble vol = g_variant_get_double( dbusmenu_menuitem_property_get_variant( priv->twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); return vol; } |