diff options
author | Conor Curran <conor.curran@canonical.com> | 2011-08-08 17:51:23 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2011-08-08 17:51:23 +0100 |
commit | 4300a124d6959f8bfad9393530de587fefe828be (patch) | |
tree | 0e3b2e3d6b96e0473a7ccc729b133aa3ad89217c /src/indicator-sound.c | |
parent | d0727964e78fd5174402e4732731ad11ad0d7ef3 (diff) | |
parent | c60b7f972eb8faa1b06366dfebdb4a220d565f1e (diff) | |
download | ayatana-indicator-sound-4300a124d6959f8bfad9393530de587fefe828be.tar.gz ayatana-indicator-sound-4300a124d6959f8bfad9393530de587fefe828be.tar.bz2 ayatana-indicator-sound-4300a124d6959f8bfad9393530de587fefe828be.zip |
added missing marshaller and merged in tip to keep things up to date for oneiric
Diffstat (limited to 'src/indicator-sound.c')
-rw-r--r-- | src/indicator-sound.c | 120 |
1 files changed, 99 insertions, 21 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c index f2ec0a2..7c72900 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -23,7 +23,11 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib/gi18n.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#if GTK_CHECK_VERSION(3, 0, 0) +#include <libdbusmenu-gtk3/menu.h> +#else #include <libdbusmenu-gtk/menu.h> +#endif #include <libido/idoscalemenuitem.h> #include <gio/gio.h> @@ -35,6 +39,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "voip-input-widget.h" #include "dbus-shared-names.h" #include "sound-state-manager.h" +#include "mute-widget.h" #include "gen-sound-service.xml.h" #include "common-defs.h" @@ -45,6 +50,7 @@ struct _IndicatorSoundPrivate { GtkWidget* volume_widget; GtkWidget* voip_widget; + MuteWidget *mute_widget; GList* transport_widgets_list; GDBusProxy *dbus_proxy; SoundStateManager* state_manager; @@ -68,9 +74,12 @@ static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static const gchar * get_accessible_desc (IndicatorObject * io); -static void indicator_sound_scroll (IndicatorObject* io, - gint delta, +static void indicator_sound_scroll (IndicatorObject * io, + IndicatorObjectEntry * entry, gint delta, IndicatorScrollDirection direction); +static void indicator_sound_middle_click (IndicatorObject * io, + IndicatorObjectEntry * entry, + guint time, gpointer data); //key/moust event handlers static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); @@ -93,6 +102,10 @@ static gboolean new_metadata_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_mute_widget (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data); // DBUS communication static GDBusNodeInfo *node_info = NULL; @@ -120,7 +133,8 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_image = get_icon; io_class->get_menu = get_menu; io_class->get_accessible_desc = get_accessible_desc; - io_class->scroll = indicator_sound_scroll; + io_class->entry_scrolled = indicator_sound_scroll; + io_class->secondary_activate = indicator_sound_middle_click; } static void @@ -133,6 +147,7 @@ indicator_sound_init (IndicatorSound *self) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); priv->volume_widget = NULL; priv->voip_widget = NULL; + priv->mute_widget = NULL; priv->dbus_proxy = NULL; GList* t_list = NULL; priv->transport_widgets_list = t_list; @@ -203,6 +218,9 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); + dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), + DBUSMENU_MUTE_MENUITEM_TYPE, + new_mute_widget); // 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); @@ -455,10 +473,60 @@ new_voip_slider_widget (DbusmenuMenuitem * newitem, return TRUE; } +static gboolean +new_mute_widget(DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data) +{ + IndicatorObject *io = NULL; + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + io = g_object_get_data (G_OBJECT (client), "indicator"); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + + if (priv->mute_widget != NULL){ + g_object_unref (priv->mute_widget); + priv->mute_widget = NULL; + } + + priv->mute_widget = mute_widget_new(newitem); + GtkMenuItem *item = mute_widget_get_menu_item (priv->mute_widget); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), + newitem, + item, + parent); + + return TRUE; +} + /*******************************************************************/ //UI callbacks /******************************************************************/ +static GtkWidget * +get_current_item (GtkContainer * container) +{ + GList *children = gtk_container_get_children (container); + GList *iter; + GtkWidget *rv = NULL; + + /* Suprisingly, GTK+ doesn't really let us query "what is the currently + selected item?". But it does note it internally by prelighting the + widget, so we watch for that. */ + for (iter = children; iter; iter = iter->next) { + if (gtk_widget_get_state (GTK_WIDGET (iter->data)) & GTK_STATE_PRELIGHT) { + rv = GTK_WIDGET (iter->data); + break; + } + } + + return rv; +} + /** key_press_cb: **/ @@ -473,7 +541,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); GtkWidget *menuitem; - menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + menuitem = get_current_item (GTK_CONTAINER (widget)); if (IDO_IS_SCALE_MENU_ITEM(menuitem) == TRUE){ gdouble current_value = 0; @@ -502,19 +570,19 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: digested = TRUE; new_value = current_value + five_percent; break; - case GDK_Left: + case GDK_KEY_Left: digested = TRUE; new_value = current_value - five_percent; break; - case GDK_plus: + case GDK_KEY_plus: digested = TRUE; new_value = current_value + five_percent; break; - case GDK_minus: + case GDK_KEY_minus: digested = TRUE; new_value = current_value - five_percent; break; @@ -542,12 +610,12 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: transport_widget_react_to_key_press_event ( transport_widget, TRANSPORT_ACTION_NEXT ); digested = TRUE; break; - case GDK_Left: + case GDK_KEY_Left: transport_widget_react_to_key_press_event ( transport_widget, TRANSPORT_ACTION_PREVIOUS ); digested = TRUE; @@ -557,8 +625,8 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) TRANSPORT_ACTION_PLAY_PAUSE ); digested = TRUE; break; - case GDK_Up: - case GDK_Down: + case GDK_KEY_Up: + case GDK_KEY_Down: digested = FALSE; break; default: @@ -585,7 +653,7 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) GtkWidget *menuitem; - menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + menuitem = get_current_item (GTK_CONTAINER (widget)); if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { TransportWidget* transport_widget = NULL; GList* elem; @@ -597,12 +665,12 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: transport_widget_react_to_key_release_event ( transport_widget, TRANSPORT_ACTION_NEXT ); digested = TRUE; break; - case GDK_Left: + case GDK_KEY_Left: transport_widget_react_to_key_release_event ( transport_widget, TRANSPORT_ACTION_PREVIOUS ); digested = TRUE; @@ -612,8 +680,8 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) TRANSPORT_ACTION_PLAY_PAUSE ); digested = TRUE; break; - case GDK_Up: - case GDK_Down: + case GDK_KEY_Up: + case GDK_KEY_Down: digested = FALSE; break; default: @@ -624,8 +692,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, IndicatorObjectEntry * entry, + gint delta, IndicatorScrollDirection direction) { //g_debug("indicator-sound-scroll - current slider value"); IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); @@ -643,9 +711,9 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider)); //g_debug("indicator-sound-scroll - current slider value %f", value); if (direction == INDICATOR_OBJECT_SCROLL_UP) { - value += adj->step_increment; + value += gtk_adjustment_get_step_increment (adj); } else { - value -= adj->step_increment; + value -= gtk_adjustment_get_step_increment (adj); } //g_debug("indicator-sound-scroll - update slider with value %f", value); volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value, "scroll updates"); @@ -653,6 +721,16 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, sound_state_manager_show_notification (priv->state_manager, value); } +static void +indicator_sound_middle_click (IndicatorObject * io, IndicatorObjectEntry * entry, + guint time, gpointer data) +{ + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + g_return_if_fail (priv); + + mute_widget_toggle(priv->mute_widget); +} + void update_accessible_desc (IndicatorObject * io) { |