2
A small wrapper utility to load indicators and put them as menu items
3
into the gnome-panel using it's applet interface.
5
Copyright 2010 Canonical Ltd.
8
Conor Curran <conor.curra@canonical.com>
9
Ted Gould <ted@canonical.com>
11
This program is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License version 3, as published
13
by the Free Software Foundation.
15
This program is distributed in the hope that it will be useful, but
16
WITHOUT ANY WARRANTY; without even the implied warranties of
17
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18
PURPOSE. See the GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License along
21
with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include <glib-object.h>
27
#include <libdbusmenu-gtk/menu.h>
28
/*#include <idoscalemenuitem.h>*/
30
#include <dbus/dbus-glib.h>
31
#include <dbus/dbus-glib-bindings.h>
33
#include <libindicator/indicator.h>
34
#include <libindicator/indicator-object.h>
35
#include <libindicator/indicator-service-manager.h>
38
#include "dbus-shared-names.h"
39
#include "sound-service-client.h"
40
#include "common-defs.h"
41
#include "sound-service-marshal.h"
44
#define INDICATOR_SOUND_TYPE (indicator_sound_get_type ())
45
#define INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SOUND_TYPE, IndicatorSound))
46
#define INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SOUND_TYPE, IndicatorSoundClass))
47
#define IS_INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SOUND_TYPE))
48
#define IS_INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SOUND_TYPE))
49
#define INDICATOR_SOUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SOUND_TYPE, IndicatorSoundClass))
51
typedef struct _IndicatorSound IndicatorSound;
52
typedef struct _IndicatorSoundClass IndicatorSoundClass;
54
struct _IndicatorSoundClass {
55
IndicatorObjectClass parent_class;
58
struct _IndicatorSound {
59
IndicatorObject parent;
60
IndicatorServiceManager * service;
63
GType indicator_sound_get_type (void);
68
INDICATOR_SET_TYPE(INDICATOR_SOUND_TYPE)
71
static GtkLabel * get_label (IndicatorObject * io);
72
static GtkImage * get_icon (IndicatorObject * io);
73
static GtkMenu * get_menu (IndicatorObject * io);
74
//static GtkWidget *volume_item;
75
static DBusGProxy * sound_dbus_proxy = NULL;
78
static void indicator_sound_class_init (IndicatorSoundClass *klass);
79
static void indicator_sound_init (IndicatorSound *self);
80
static void indicator_sound_dispose (GObject *object);
81
static void indicator_sound_finalize (GObject *object);
83
G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE);
85
static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata);
86
static void catch_signal(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata);
89
indicator_sound_class_init (IndicatorSoundClass *klass)
91
GObjectClass *object_class = G_OBJECT_CLASS (klass);
93
object_class->dispose = indicator_sound_dispose;
94
object_class->finalize = indicator_sound_finalize;
96
IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);
97
io_class->get_label = get_label;
98
io_class->get_image = get_icon;
99
io_class->get_menu = get_menu;
101
dbus_g_object_register_marshaller (_sound_service_marshal_VOID__INT_BOOLEAN,
110
static void indicator_sound_init (IndicatorSound *self)
112
/* Set good defaults */
113
self->service = NULL;
115
/* Now let's fire these guys up. */
116
self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION);
118
g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self);
125
connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata)
128
if (sound_dbus_proxy == NULL) {
129
GError * error = NULL;
131
DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
133
sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus,
134
INDICATOR_SOUND_DBUS_NAME,
135
INDICATOR_SOUND_SERVICE_DBUS_OBJECT,
136
INDICATOR_SOUND_SERVICE_DBUS_INTERFACE,
140
g_warning("Unable to get status proxy: %s", error->message);
143
g_debug("about to connect to the signals");
144
dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID);
145
dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal), NULL, NULL);
149
//TODO : will need to handle this scenario
155
static void catch_signal (DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata)
157
g_debug("signal caught - i don't believe it !");
162
indicator_sound_dispose (GObject *object)
164
IndicatorSound * self = INDICATOR_SOUND(object);
166
if (self->service != NULL) {
167
g_object_unref(G_OBJECT(self->service));
168
self->service = NULL;
172
G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object);
177
indicator_sound_finalize (GObject *object)
180
G_OBJECT_CLASS (indicator_sound_parent_class)->finalize (object);
185
get_label (IndicatorObject * io)
191
get_icon (IndicatorObject * io)
193
GtkImage * status_image = GTK_IMAGE(gtk_image_new_from_icon_name("audio-volume-high", GTK_ICON_SIZE_MENU));
194
gtk_widget_show(GTK_WIDGET(status_image));
198
/* Indicator based function to get the menu for the whole
199
applet. This starts up asking for the parts of the menu
200
from the various services. */
202
get_menu (IndicatorObject * io)
204
//volume_item = ido_scale_menu_item_new_with_range ("Volume", 0, 100, 1);
205
//gtk_menu_shell_append (GTK_MENU_SHELL (menu), volume_item);
206
return GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT));