1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
An indicator to show information that is in messaging applications
that the user is using.
Copyright 2009 Canonical Ltd.
Authors:
Ted Gould <ted@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 <dbus/dbus-glib.h>
#include "messages-service-dbus.h"
#include "dbus-data.h"
enum {
ATTENTION_CHANGED,
ICON_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct _MessageServiceDbusPrivate MessageServiceDbusPrivate;
struct _MessageServiceDbusPrivate
{
gboolean dot;
gboolean hidden;
};
#define MESSAGE_SERVICE_DBUS_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), MESSAGE_SERVICE_DBUS_TYPE, MessageServiceDbusPrivate))
static void message_service_dbus_class_init (MessageServiceDbusClass *klass);
static void message_service_dbus_init (MessageServiceDbus *self);
static void message_service_dbus_dispose (GObject *object);
static void message_service_dbus_finalize (GObject *object);
static void _messages_service_server_watch (void);
static gboolean _messages_service_server_attention_requested (MessageServiceDbus * self, gboolean * dot, GError ** error);
static gboolean _messages_service_server_icon_shown (MessageServiceDbus * self, gboolean * hidden, GError ** error);
#include "messages-service-server.h"
G_DEFINE_TYPE (MessageServiceDbus, message_service_dbus, G_TYPE_OBJECT);
static void
message_service_dbus_class_init (MessageServiceDbusClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (MessageServiceDbusPrivate));
object_class->dispose = message_service_dbus_dispose;
object_class->finalize = message_service_dbus_finalize;
signals[ATTENTION_CHANGED] = g_signal_new(MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MessageServiceDbusClass, attention_changed),
NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
signals[ICON_CHANGED] = g_signal_new(MESSAGE_SERVICE_DBUS_SIGNAL_ICON_CHANGED,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MessageServiceDbusClass, icon_changed),
NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
dbus_g_object_type_install_info(MESSAGE_SERVICE_DBUS_TYPE, &dbus_glib__messages_service_server_object_info);
return;
}
static void
message_service_dbus_init (MessageServiceDbus *self)
{
DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
dbus_g_connection_register_g_object(connection,
INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT,
G_OBJECT(self));
MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
priv->dot = FALSE;
priv->hidden = FALSE;
return;
}
static void
message_service_dbus_dispose (GObject *object)
{
G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object);
return;
}
static void
message_service_dbus_finalize (GObject *object)
{
G_OBJECT_CLASS (message_service_dbus_parent_class)->finalize (object);
return;
}
MessageServiceDbus *
message_service_dbus_new (void)
{
return MESSAGE_SERVICE_DBUS(g_object_new(MESSAGE_SERVICE_DBUS_TYPE, NULL));
}
/* DBus function to say that someone is watching */
static void
_messages_service_server_watch (void)
{
}
/* DBus interface to request the private variable to know
whether there is a green dot. */
static gboolean
_messages_service_server_attention_requested (MessageServiceDbus * self, gboolean * dot, GError ** error)
{
MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
*dot = priv->dot;
return TRUE;
}
/* DBus interface to request the private variable to know
whether the icon is hidden. */
static gboolean
_messages_service_server_icon_shown (MessageServiceDbus * self, gboolean * hidden, GError ** error)
{
MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
*hidden = priv->hidden;
return TRUE;
}
void
message_server_dbus_set_attention (MessageServiceDbus * self, gboolean attention)
{
MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
/* Do signal */
if (attention != priv->dot) {
priv->dot = attention;
g_signal_emit(G_OBJECT(self), signals[ATTENTION_CHANGED], 0, priv->dot, TRUE);
}
return;
}
void
message_server_dbus_set_icon (MessageServiceDbus * self, gboolean hidden)
{
MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
/* Do signal */
if (hidden != priv->hidden) {
priv->hidden = hidden;
g_signal_emit(G_OBJECT(self), signals[ICON_CHANGED], 0, priv->hidden, TRUE);
}
return;
}
|