Merge lp:~3v1n0/indicator-sound/mute-on-secondary-activate into lp:indicator-sound/fourth

Proposed by Marco Trevisan (Treviño)
Status: Merged
Merged at revision: 254
Proposed branch: lp:~3v1n0/indicator-sound/mute-on-secondary-activate
Merge into: lp:indicator-sound/fourth
Prerequisite: lp:~3v1n0/indicator-sound/compile-with-new-API
Diff against target: 367 lines (+269/-0)
5 files modified
src/Makefile.am (+2/-0)
src/indicator-sound.c (+54/-0)
src/mute-menu-item.c (+5/-0)
src/mute-widget.c (+141/-0)
src/mute-widget.h (+67/-0)
To merge this branch: bzr merge lp:~3v1n0/indicator-sound/mute-on-secondary-activate
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Indicator Applet Developers Pending
Review via email: mp+68399@code.launchpad.net

Description of the change

When the "secondary-activate" event is emitted, the indicator-sound should toggle the volume on/off.

This branch performs this using a new mute-widget that is used by indicator-sound to control the mute-menu-item dbus menuitem.

The code needs the libindicator support (available in lp:~3v1n0/libindicator/secondary-activate-support) and unity/unity-2d support (available in lp:~3v1n0/unity/secondary-activate-support and in lp:~3v1n0/unity-2d/secondary-activate-support)

To post a comment you must log in.
257. By Marco Trevisan (Treviño)

X and Y pointer position aren't exported anymore by libindicator

Dropping them!

Revision history for this message
Conor Curran (cjcurran) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-06-22 19:19:49 +0000
+++ src/Makefile.am 2011-07-21 16:14:32 +0000
@@ -18,6 +18,8 @@
18 transport-widget.h \18 transport-widget.h \
19 metadata-widget.c \19 metadata-widget.c \
20 metadata-widget.h \20 metadata-widget.h \
21 mute-widget.c \
22 mute-widget.h \
21 volume-widget.c \23 volume-widget.c \
22 volume-widget.h \24 volume-widget.h \
23 voip-input-widget.c \25 voip-input-widget.c \
2426
=== modified file 'src/indicator-sound.c'
--- src/indicator-sound.c 2011-07-02 03:32:23 +0000
+++ src/indicator-sound.c 2011-07-21 16:14:32 +0000
@@ -39,6 +39,7 @@
39#include "voip-input-widget.h"39#include "voip-input-widget.h"
40#include "dbus-shared-names.h"40#include "dbus-shared-names.h"
41#include "sound-state-manager.h"41#include "sound-state-manager.h"
42#include "mute-widget.h"
4243
43#include "gen-sound-service.xml.h"44#include "gen-sound-service.xml.h"
44#include "common-defs.h"45#include "common-defs.h"
@@ -49,6 +50,7 @@
49{50{
50 GtkWidget* volume_widget;51 GtkWidget* volume_widget;
51 GtkWidget* voip_widget;52 GtkWidget* voip_widget;
53 MuteWidget *mute_widget;
52 GList* transport_widgets_list;54 GList* transport_widgets_list;
53 GDBusProxy *dbus_proxy; 55 GDBusProxy *dbus_proxy;
54 SoundStateManager* state_manager;56 SoundStateManager* state_manager;
@@ -75,6 +77,9 @@
75static void indicator_sound_scroll (IndicatorObject * io,77static void indicator_sound_scroll (IndicatorObject * io,
76 IndicatorObjectEntry * entry, gint delta,78 IndicatorObjectEntry * entry, gint delta,
77 IndicatorScrollDirection direction);79 IndicatorScrollDirection direction);
80static void indicator_sound_middle_click (IndicatorObject * io,
81 IndicatorObjectEntry * entry,
82 guint time, gpointer data);
7883
79//key/moust event handlers84//key/moust event handlers
80static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data);85static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data);
@@ -97,6 +102,10 @@
97 DbusmenuMenuitem * parent,102 DbusmenuMenuitem * parent,
98 DbusmenuClient * client,103 DbusmenuClient * client,
99 gpointer user_data);104 gpointer user_data);
105static gboolean new_mute_widget (DbusmenuMenuitem * newitem,
106 DbusmenuMenuitem * parent,
107 DbusmenuClient * client,
108 gpointer user_data);
100109
101// DBUS communication110// DBUS communication
102static GDBusNodeInfo *node_info = NULL;111static GDBusNodeInfo *node_info = NULL;
@@ -125,6 +134,7 @@
125 io_class->get_menu = get_menu;134 io_class->get_menu = get_menu;
126 io_class->get_accessible_desc = get_accessible_desc;135 io_class->get_accessible_desc = get_accessible_desc;
127 io_class->entry_scrolled = indicator_sound_scroll;136 io_class->entry_scrolled = indicator_sound_scroll;
137 io_class->secondary_activate = indicator_sound_middle_click;
128}138}
129139
130static void140static void
@@ -137,6 +147,7 @@
137 IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self);147 IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self);
138 priv->volume_widget = NULL;148 priv->volume_widget = NULL;
139 priv->voip_widget = NULL;149 priv->voip_widget = NULL;
150 priv->mute_widget = NULL;
140 priv->dbus_proxy = NULL;151 priv->dbus_proxy = NULL;
141 GList* t_list = NULL;152 GList* t_list = NULL;
142 priv->transport_widgets_list = t_list;153 priv->transport_widgets_list = t_list;
@@ -207,6 +218,9 @@
207 dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client),218 dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client),
208 DBUSMENU_METADATA_MENUITEM_TYPE,219 DBUSMENU_METADATA_MENUITEM_TYPE,
209 new_metadata_widget);220 new_metadata_widget);
221 dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client),
222 DBUSMENU_MUTE_MENUITEM_TYPE,
223 new_mute_widget);
210 // Note: Not ideal but all key handling needs to be managed here and then 224 // Note: Not ideal but all key handling needs to be managed here and then
211 // delegated to the appropriate widget. 225 // delegated to the appropriate widget.
212 g_signal_connect (menu, "key-press-event", G_CALLBACK(key_press_cb), io);226 g_signal_connect (menu, "key-press-event", G_CALLBACK(key_press_cb), io);
@@ -459,6 +473,36 @@
459 return TRUE;473 return TRUE;
460}474}
461475
476static gboolean
477new_mute_widget(DbusmenuMenuitem * newitem,
478 DbusmenuMenuitem * parent,
479 DbusmenuClient * client,
480 gpointer user_data)
481{
482 IndicatorObject *io = NULL;
483
484 g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
485 g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
486
487 io = g_object_get_data (G_OBJECT (client), "indicator");
488 IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));
489
490 if (priv->mute_widget != NULL){
491 g_object_unref (priv->mute_widget);
492 priv->mute_widget = NULL;
493 }
494
495 priv->mute_widget = mute_widget_new(newitem);
496 GtkMenuItem *item = mute_widget_get_menu_item (priv->mute_widget);
497
498 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
499 newitem,
500 item,
501 parent);
502
503 return TRUE;
504}
505
462/*******************************************************************/506/*******************************************************************/
463//UI callbacks507//UI callbacks
464/******************************************************************/508/******************************************************************/
@@ -677,6 +721,16 @@
677 sound_state_manager_show_notification (priv->state_manager, value);721 sound_state_manager_show_notification (priv->state_manager, value);
678}722}
679723
724static void
725indicator_sound_middle_click (IndicatorObject * io, IndicatorObjectEntry * entry,
726 guint time, gpointer data)
727{
728 IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));
729 g_return_if_fail (priv);
730
731 mute_widget_toggle(priv->mute_widget);
732}
733
680void734void
681update_accessible_desc (IndicatorObject * io)735update_accessible_desc (IndicatorObject * io)
682{736{
683737
=== modified file 'src/mute-menu-item.c'
--- src/mute-menu-item.c 2011-02-18 13:05:58 +0000
+++ src/mute-menu-item.c 2011-07-21 16:14:32 +0000
@@ -63,6 +63,11 @@
63 MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self);63 MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self);
64 priv->button = NULL;64 priv->button = NULL;
65 priv->button = dbusmenu_menuitem_new();65 priv->button = dbusmenu_menuitem_new();
66
67 dbusmenu_menuitem_property_set(priv->button,
68 DBUSMENU_MENUITEM_PROP_TYPE,
69 DBUSMENU_MUTE_MENUITEM_TYPE);
70
66 dbusmenu_menuitem_property_set_bool (priv->button,71 dbusmenu_menuitem_property_set_bool (priv->button,
67 DBUSMENU_MENUITEM_PROP_VISIBLE,72 DBUSMENU_MENUITEM_PROP_VISIBLE,
68 TRUE);73 TRUE);
6974
=== added file 'src/mute-widget.c'
--- src/mute-widget.c 1970-01-01 00:00:00 +0000
+++ src/mute-widget.c 2011-07-21 16:14:32 +0000
@@ -0,0 +1,141 @@
1/*
2Copyright 2011 Canonical Ltd.
3
4Authors:
5 Marco Trevisan (Treviño) <mail@3v1n0.net>
6
7This program is free software: you can redistribute it and/or modify it
8under the terms of the GNU General Public License version 3, as published
9by the Free Software Foundation.
10
11This program is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranties of
13MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along
17with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <glib/gi18n.h>
25#include <glib.h>
26#include "mute-widget.h"
27#include "common-defs.h"
28#include "indicator-sound.h"
29
30typedef struct _MuteWidgetPrivate MuteWidgetPrivate;
31
32struct _MuteWidgetPrivate
33{
34 DbusmenuMenuitem *item;
35 GtkMenuItem *gitem;
36};
37
38#define MUTE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_WIDGET_TYPE, MuteWidgetPrivate))
39
40/* Prototypes */
41static void mute_widget_class_init (MuteWidgetClass *klass);
42static void mute_widget_init (MuteWidget *self);
43static void mute_widget_dispose (GObject *object);
44static void mute_widget_finalize (GObject *object);
45
46G_DEFINE_TYPE (MuteWidget, mute_widget, G_TYPE_OBJECT);
47
48static void
49mute_widget_class_init (MuteWidgetClass *klass)
50{
51 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
52 gobject_class->dispose = mute_widget_dispose;
53 gobject_class->finalize = mute_widget_finalize;
54 g_type_class_add_private (klass, sizeof (MuteWidgetPrivate));
55}
56
57static void
58mute_widget_init (MuteWidget *self)
59{
60 MuteWidgetPrivate *priv = MUTE_WIDGET_GET_PRIVATE(self);
61 priv->item = NULL;
62 priv->gitem = GTK_MENU_ITEM(gtk_menu_item_new ());
63}
64
65static void
66mute_widget_dispose (GObject *object)
67{
68 G_OBJECT_CLASS (mute_widget_parent_class)->dispose (object);
69}
70
71static void
72mute_widget_finalize (GObject *object)
73{
74 MuteWidget *self = MUTE_WIDGET (object);
75 MuteWidgetPrivate *priv = MUTE_WIDGET_GET_PRIVATE(self);
76
77 g_object_unref (priv->item);
78 g_object_unref (G_OBJECT (priv->gitem));
79 G_OBJECT_CLASS (mute_widget_parent_class)->finalize (object);
80}
81
82GtkMenuItem *
83mute_widget_get_menu_item(MuteWidget *self)
84{
85 MuteWidgetPrivate *priv = MUTE_WIDGET_GET_PRIVATE(self);
86 return priv->gitem;
87}
88
89MuteStatus
90mute_widget_get_status (MuteWidget *self)
91{
92 g_return_val_if_fail(self, MUTE_STATUS_UNAVAILABLE);
93 MuteStatus status = MUTE_STATUS_UNAVAILABLE;
94 MuteWidgetPrivate *priv = MUTE_WIDGET_GET_PRIVATE(self);
95
96 GVariant *vstatus = dbusmenu_menuitem_property_get_variant(priv->item,
97 DBUSMENU_MUTE_MENUITEM_VALUE);
98
99 if (g_variant_is_of_type (vstatus, G_VARIANT_TYPE_BOOLEAN))
100 {
101 if (g_variant_get_boolean (vstatus))
102 status = MUTE_STATUS_MUTED;
103 else
104 status = MUTE_STATUS_UNMUTED;
105 }
106
107 return status;
108}
109
110void mute_widget_toggle (MuteWidget *self)
111{
112 g_return_if_fail (self);
113 MuteWidgetPrivate *priv = MUTE_WIDGET_GET_PRIVATE(self);
114 gtk_menu_item_activate (priv->gitem);
115}
116
117/**
118 * mute_widget_new:
119 * @returns: a new #MuteWidget.
120 **/
121MuteWidget *
122mute_widget_new (DbusmenuMenuitem *item)
123{
124 MuteWidget* widget = g_object_new(MUTE_WIDGET_TYPE, NULL);
125 MuteWidgetPrivate* priv = MUTE_WIDGET_GET_PRIVATE(widget);
126 priv->item = g_object_ref(item);
127
128 GVariant *label = dbusmenu_menuitem_property_get_variant(priv->item,
129 DBUSMENU_MENUITEM_PROP_LABEL);
130
131 if (g_variant_is_of_type(label, G_VARIANT_TYPE_STRING))
132 gtk_menu_item_set_label(priv->gitem, g_variant_get_string(label, NULL));
133
134 if (label)
135 {
136 g_debug("Added a new Mute Widget %s", g_variant_print(label, FALSE));
137 g_variant_unref(label);
138 }
139
140 return widget;
141}
0142
=== added file 'src/mute-widget.h'
--- src/mute-widget.h 1970-01-01 00:00:00 +0000
+++ src/mute-widget.h 2011-07-21 16:14:32 +0000
@@ -0,0 +1,67 @@
1/*
2Copyright 2011 Canonical Ltd.
3
4Authors:
5 Marco Trevisan (Treviño) <mail@3v1n0.net>
6
7This program is free software: you can redistribute it and/or modify it
8under the terms of the GNU General Public License version 3, as published
9by the Free Software Foundation.
10
11This program is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranties of
13MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along
17with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef __MUTE_WIDGET_H__
20#define __MUTE_WIDGET_H__
21
22#include <glib.h>
23#include <glib-object.h>
24#include <gtk/gtk.h>
25#if GTK_CHECK_VERSION(3, 0, 0)
26#include <libdbusmenu-gtk3/menuitem.h>
27#else
28#include <libdbusmenu-gtk/menuitem.h>
29#endif
30#include <libindicator/indicator-object.h>
31
32G_BEGIN_DECLS
33
34#define MUTE_WIDGET_TYPE (mute_widget_get_type ())
35#define MUTE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MUTE_WIDGET_TYPE, MuteWidget))
36#define MUTE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUTE_WIDGET_TYPE, MuteWidgetClass))
37#define IS_MUTE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MUTE_WIDGET_TYPE))
38#define IS_MUTE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MUTE_WIDGET_TYPE))
39#define MUTE_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MUTE_WIDGET_TYPE, MuteWidgetClass))
40
41typedef struct _MuteWidget MuteWidget;
42typedef struct _MuteWidgetClass MuteWidgetClass;
43
44struct _MuteWidgetClass {
45 GObjectClass parent_class;
46};
47
48struct _MuteWidget {
49 GObject parent;
50};
51
52typedef enum {
53 MUTE_STATUS_UNAVAILABLE,
54 MUTE_STATUS_MUTED,
55 MUTE_STATUS_UNMUTED
56} MuteStatus;
57
58GType mute_widget_get_type (void) G_GNUC_CONST;
59MuteWidget* mute_widget_new (DbusmenuMenuitem *item);
60MuteStatus mute_widget_get_status (MuteWidget *self);
61void mute_widget_toggle (MuteWidget *self);
62GtkMenuItem *mute_widget_get_menu_item (MuteWidget *self);
63
64G_END_DECLS
65
66#endif
67

Subscribers

People subscribed via source and target branches