Merge lp:~ken-vandine/indicator-me/gdbus into lp:indicator-me
- gdbus
- Merge into trunk
Proposed by
Ken VanDine
Status: | Merged |
---|---|
Merged at revision: | 121 |
Proposed branch: | lp:~ken-vandine/indicator-me/gdbus |
Merge into: | lp:indicator-me |
Diff against target: |
1018 lines (+434/-224) 8 files modified
.bzrignore (+2/-2) configure.ac (+7/-3) src/Makefile.am (+14/-17) src/entry-menu-item.c (+10/-3) src/indicator-me.c (+184/-64) src/me-service-dbus.c (+202/-102) src/me-service-gwibber.c (+14/-32) src/me-service-gwibber.h (+1/-1) |
To merge this branch: | bzr merge lp:~ken-vandine/indicator-me/gdbus |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email: mp+46178@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 120. By Ken VanDine
-
Ported to libgwibber 0.0.7
- 121. By Ken VanDine
-
* check status_proxy_cancel for NULL to prevents dupes
* cast user_data after checking for error from the dbus proxy
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2010-01-11 14:41:00 +0000 | |||
3 | +++ .bzrignore 2011-01-14 17:27:04 +0000 | |||
4 | @@ -59,5 +59,5 @@ | |||
5 | 59 | src/libme.la | 59 | src/libme.la |
6 | 60 | src/libme_la-indicator-me.lo | 60 | src/libme_la-indicator-me.lo |
7 | 61 | po/indicator-me.pot | 61 | po/indicator-me.pot |
10 | 62 | src/me-service-client.h | 62 | src/gen-me-service.xml.c |
11 | 63 | src/me-service-server.h | 63 | src/gen-me-service.xml.h |
12 | 64 | 64 | ||
13 | === modified file 'configure.ac' | |||
14 | --- configure.ac 2011-01-10 21:16:11 +0000 | |||
15 | +++ configure.ac 2011-01-14 17:27:04 +0000 | |||
16 | @@ -6,7 +6,7 @@ | |||
17 | 6 | AC_PREREQ(2.53) | 6 | AC_PREREQ(2.53) |
18 | 7 | 7 | ||
19 | 8 | AM_CONFIG_HEADER(config.h) | 8 | AM_CONFIG_HEADER(config.h) |
21 | 9 | AM_INIT_AUTOMAKE(indicator-me, 0.2.10) | 9 | AM_INIT_AUTOMAKE(indicator-me, 0.2.11) |
22 | 10 | 10 | ||
23 | 11 | AM_MAINTAINER_MODE | 11 | AM_MAINTAINER_MODE |
24 | 12 | 12 | ||
25 | @@ -29,21 +29,25 @@ | |||
26 | 29 | 29 | ||
27 | 30 | GTK_REQUIRED_VERSION=2.12 | 30 | GTK_REQUIRED_VERSION=2.12 |
28 | 31 | INDICATOR_REQUIRED_VERSION=0.3.0 | 31 | INDICATOR_REQUIRED_VERSION=0.3.0 |
30 | 32 | GWIBBER_REQUIRED_VERSION=0.0.4 | 32 | GWIBBER_REQUIRED_VERSION=0.0.7 |
31 | 33 | DBUSMENUGLIB_REQUIRED_VERSION=0.3.90 | 33 | DBUSMENUGLIB_REQUIRED_VERSION=0.3.90 |
32 | 34 | DBUSMENUGTK_REQUIRED_VERSION=0.3.90 | ||
33 | 34 | TELEPATHYGLIB_REQUIRED_VERSION=0.9.0 | 35 | TELEPATHYGLIB_REQUIRED_VERSION=0.9.0 |
34 | 35 | GCONF_REQUIRED_VERSION=2.0.0 | 36 | GCONF_REQUIRED_VERSION=2.0.0 |
35 | 36 | INDICATOR_DISPLAY_OBJECTS=0.1 | 37 | INDICATOR_DISPLAY_OBJECTS=0.1 |
36 | 38 | GIO_UNIX_REQUIRED_VERSION=2.22 | ||
37 | 37 | 39 | ||
38 | 38 | PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION | 40 | PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION |
39 | 39 | indicator >= $INDICATOR_REQUIRED_VERSION | 41 | indicator >= $INDICATOR_REQUIRED_VERSION |
40 | 40 | libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS | 42 | libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS |
41 | 41 | dbus-glib-1 | 43 | dbus-glib-1 |
43 | 42 | dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION) | 44 | dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION |
44 | 45 | dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) | ||
45 | 43 | PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION | 46 | PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION |
46 | 44 | gconf-2.0 >= $GCONF_REQUIRED_VERSION | 47 | gconf-2.0 >= $GCONF_REQUIRED_VERSION |
47 | 45 | indicator >= $INDICATOR_REQUIRED_VERSION | 48 | indicator >= $INDICATOR_REQUIRED_VERSION |
48 | 46 | gwibber >= $GWIBBER_REQUIRED_VERSION | 49 | gwibber >= $GWIBBER_REQUIRED_VERSION |
49 | 50 | gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION | ||
50 | 47 | telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION) | 51 | telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION) |
51 | 48 | 52 | ||
52 | 49 | ########################### | 53 | ########################### |
53 | 50 | 54 | ||
54 | === modified file 'src/Makefile.am' | |||
55 | --- src/Makefile.am 2010-02-17 22:52:43 +0000 | |||
56 | +++ src/Makefile.am 2011-01-14 17:27:04 +0000 | |||
57 | @@ -12,7 +12,8 @@ | |||
58 | 12 | about-me-menu-item.h \ | 12 | about-me-menu-item.h \ |
59 | 13 | indicator-me.c \ | 13 | indicator-me.c \ |
60 | 14 | dbus-shared-names.h \ | 14 | dbus-shared-names.h \ |
62 | 15 | me-service-client.h | 15 | gen-me-service.xml.h \ |
63 | 16 | gen-me-service.xml.c | ||
64 | 16 | libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror | 17 | libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror |
65 | 17 | libme_la_LIBADD = $(APPLET_LIBS) | 18 | libme_la_LIBADD = $(APPLET_LIBS) |
66 | 18 | libme_la_LDFLAGS = -module -avoid-version | 19 | libme_la_LDFLAGS = -module -avoid-version |
67 | @@ -27,7 +28,8 @@ | |||
68 | 27 | me-service.c \ | 28 | me-service.c \ |
69 | 28 | me-service-dbus.h \ | 29 | me-service-dbus.h \ |
70 | 29 | me-service-dbus.c \ | 30 | me-service-dbus.c \ |
72 | 30 | me-service-server.h \ | 31 | gen-me-service.xml.h \ |
73 | 32 | gen-me-service.xml.c \ | ||
74 | 31 | me-service-gwibber.c \ | 33 | me-service-gwibber.c \ |
75 | 32 | me-service-gwibber.h \ | 34 | me-service-gwibber.h \ |
76 | 33 | status-provider.h \ | 35 | status-provider.h \ |
77 | @@ -47,19 +49,15 @@ | |||
78 | 47 | indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror | 49 | indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror |
79 | 48 | indicator_me_service_LDADD = $(MESERVICE_LIBS) | 50 | indicator_me_service_LDADD = $(MESERVICE_LIBS) |
80 | 49 | 51 | ||
87 | 50 | me-service-client.h: $(srcdir)/me-service.xml | 52 | gen-%.xml.h: %.xml |
88 | 51 | dbus-binding-tool \ | 53 | @echo "Building $@ from $<" |
89 | 52 | --prefix=_me_service_client \ | 54 | @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ |
84 | 53 | --mode=glib-client \ | ||
85 | 54 | --output=me-service-client.h \ | ||
86 | 55 | $(srcdir)/me-service.xml | ||
90 | 56 | 55 | ||
97 | 57 | me-service-server.h: $(srcdir)/me-service.xml | 56 | gen-%.xml.c: %.xml |
98 | 58 | dbus-binding-tool \ | 57 | @echo "Building $@ from $<" |
99 | 59 | --prefix=_me_service_server \ | 58 | @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ |
100 | 60 | --mode=glib-server \ | 59 | @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ |
101 | 61 | --output=me-service-server.h \ | 60 | @echo ";" >> $@ |
96 | 62 | $(srcdir)/me-service.xml | ||
102 | 63 | 61 | ||
103 | 64 | status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list | 62 | status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list |
104 | 65 | glib-genmarshal --header \ | 63 | glib-genmarshal --header \ |
105 | @@ -96,8 +94,8 @@ | |||
106 | 96 | ############### | 94 | ############### |
107 | 97 | 95 | ||
108 | 98 | BUILT_SOURCES = \ | 96 | BUILT_SOURCES = \ |
111 | 99 | me-service-client.h \ | 97 | gen-me-service.xml.h \ |
112 | 100 | me-service-server.h \ | 98 | gen-me-service.xml.c \ |
113 | 101 | status-provider-mc5-marshal.h \ | 99 | status-provider-mc5-marshal.h \ |
114 | 102 | status-provider-mc5-marshal.c \ | 100 | status-provider-mc5-marshal.c \ |
115 | 103 | status-provider-pidgin-marshal.h \ | 101 | status-provider-pidgin-marshal.h \ |
116 | @@ -113,4 +111,3 @@ | |||
117 | 113 | 111 | ||
118 | 114 | CLEANFILES = \ | 112 | CLEANFILES = \ |
119 | 115 | $(BUILT_SOURCES) | 113 | $(BUILT_SOURCES) |
120 | 116 | |||
121 | 117 | 114 | ||
122 | === modified file 'src/entry-menu-item.c' | |||
123 | --- src/entry-menu-item.c 2011-01-10 20:54:13 +0000 | |||
124 | +++ src/entry-menu-item.c 2011-01-14 17:27:04 +0000 | |||
125 | @@ -124,11 +124,18 @@ | |||
126 | 124 | GVariant *value, guint timestamp) | 124 | GVariant *value, guint timestamp) |
127 | 125 | { | 125 | { |
128 | 126 | /* EntryMenuItemPrivate * priv = ENTRY_MENU_ITEM_GET_PRIVATE(self); */ | 126 | /* EntryMenuItemPrivate * priv = ENTRY_MENU_ITEM_GET_PRIVATE(self); */ |
129 | 127 | |||
130 | 128 | g_debug ("handle_event"); | ||
131 | 129 | if (g_strcmp0 (name, "send") == 0) { | 127 | if (g_strcmp0 (name, "send") == 0) { |
132 | 128 | gchar * msg = NULL; | ||
133 | 129 | if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) { | ||
134 | 130 | msg = g_strdup(g_variant_get_string(g_variant_get_variant (value), NULL)); | ||
135 | 131 | |||
136 | 132 | } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { | ||
137 | 133 | msg = g_strdup(g_variant_get_string(value, NULL)); | ||
138 | 134 | |||
139 | 135 | } | ||
140 | 136 | |||
141 | 130 | MeGwibberService *me_gwibber_service = me_gwibber_service_get (); | 137 | MeGwibberService *me_gwibber_service = me_gwibber_service_get (); |
143 | 131 | me_gwibber_service_send (me_gwibber_service, g_variant_get_string (value, NULL)); | 138 | me_gwibber_service_send (me_gwibber_service, g_strdup(msg)); |
144 | 132 | dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, ""); | 139 | dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, ""); |
145 | 133 | } | 140 | } |
146 | 134 | 141 | ||
147 | 135 | 142 | ||
148 | === modified file 'src/indicator-me.c' | |||
149 | --- src/indicator-me.c 2011-01-10 21:16:11 +0000 | |||
150 | +++ src/indicator-me.c 2011-01-14 17:27:04 +0000 | |||
151 | @@ -25,12 +25,10 @@ | |||
152 | 25 | #include <glib.h> | 25 | #include <glib.h> |
153 | 26 | #include <glib-object.h> | 26 | #include <glib-object.h> |
154 | 27 | #include <gtk/gtk.h> | 27 | #include <gtk/gtk.h> |
155 | 28 | #include <gio/gio.h> | ||
156 | 28 | #include <libdbusmenu-glib/menuitem.h> | 29 | #include <libdbusmenu-glib/menuitem.h> |
157 | 29 | #include <libdbusmenu-gtk/menu.h> | 30 | #include <libdbusmenu-gtk/menu.h> |
158 | 30 | 31 | ||
159 | 31 | #include <dbus/dbus-glib.h> | ||
160 | 32 | #include <dbus/dbus-glib-bindings.h> | ||
161 | 33 | |||
162 | 34 | #include <libindicator/indicator.h> | 32 | #include <libindicator/indicator.h> |
163 | 35 | #include <libindicator/indicator-object.h> | 33 | #include <libindicator/indicator-object.h> |
164 | 36 | #include <libindicator/indicator-service-manager.h> | 34 | #include <libindicator/indicator-service-manager.h> |
165 | @@ -40,7 +38,7 @@ | |||
166 | 40 | #include "about-me-menu-item.h" | 38 | #include "about-me-menu-item.h" |
167 | 41 | 39 | ||
168 | 42 | #include "dbus-shared-names.h" | 40 | #include "dbus-shared-names.h" |
170 | 43 | #include "me-service-client.h" | 41 | #include "gen-me-service.xml.h" |
171 | 44 | 42 | ||
172 | 45 | #define INDICATOR_ME_TYPE (indicator_me_get_type ()) | 43 | #define INDICATOR_ME_TYPE (indicator_me_get_type ()) |
173 | 46 | #define INDICATOR_ME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_ME_TYPE, IndicatorMe)) | 44 | #define INDICATOR_ME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_ME_TYPE, IndicatorMe)) |
174 | @@ -72,7 +70,9 @@ | |||
175 | 72 | /* Globals */ | 70 | /* Globals */ |
176 | 73 | static GtkImage * status_image = NULL; | 71 | static GtkImage * status_image = NULL; |
177 | 74 | static GtkLabel *label = NULL; | 72 | static GtkLabel *label = NULL; |
179 | 75 | static DBusGProxy * status_proxy = NULL; | 73 | static GDBusProxy * status_proxy = NULL; |
180 | 74 | |||
181 | 75 | static GCancellable * status_proxy_cancel = NULL; | ||
182 | 76 | 76 | ||
183 | 77 | static IdoEntryMenuItem *ido_entry = NULL; | 77 | static IdoEntryMenuItem *ido_entry = NULL; |
184 | 78 | 78 | ||
185 | @@ -86,13 +86,19 @@ | |||
186 | 86 | static void indicator_me_dispose (GObject *object); | 86 | static void indicator_me_dispose (GObject *object); |
187 | 87 | static void indicator_me_finalize (GObject *object); | 87 | static void indicator_me_finalize (GObject *object); |
188 | 88 | static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); | 88 | static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); |
190 | 89 | static void status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata); | 89 | static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); |
191 | 90 | |||
192 | 90 | static gboolean new_entry_item (DbusmenuMenuitem * newitem, | 91 | static gboolean new_entry_item (DbusmenuMenuitem * newitem, |
193 | 91 | DbusmenuMenuitem * parent, | 92 | DbusmenuMenuitem * parent, |
194 | 92 | DbusmenuClient * client); | 93 | DbusmenuClient * client); |
195 | 93 | static void entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi); | 94 | static void entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi); |
196 | 94 | static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry); | 95 | static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry); |
197 | 95 | static gboolean entry_hint_is_shown (GtkWidget *widget); | 96 | static gboolean entry_hint_is_shown (GtkWidget *widget); |
198 | 97 | static void status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); | ||
199 | 98 | static void status_icon_changed (IndicatorMe * self, gchar * icon); | ||
200 | 99 | static void status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data); | ||
201 | 100 | static void username_changed (IndicatorMe * self, gchar * username); | ||
202 | 101 | static void username_cb (GObject * object, GAsyncResult * res, gpointer user_data); | ||
203 | 96 | 102 | ||
204 | 97 | G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE); | 103 | G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE); |
205 | 98 | 104 | ||
206 | @@ -129,21 +135,65 @@ | |||
207 | 129 | static void | 135 | static void |
208 | 130 | indicator_me_dispose (GObject *object) | 136 | indicator_me_dispose (GObject *object) |
209 | 131 | { | 137 | { |
210 | 138 | IndicatorMe * self = INDICATOR_ME(object); | ||
211 | 139 | |||
212 | 140 | if (self->service != NULL) { | ||
213 | 141 | g_object_unref(G_OBJECT(self->service)); | ||
214 | 142 | self->service = NULL; | ||
215 | 143 | } | ||
216 | 144 | |||
217 | 145 | if (status_proxy != NULL) { | ||
218 | 146 | g_object_unref(status_proxy); | ||
219 | 147 | status_proxy = NULL; | ||
220 | 148 | } | ||
221 | 149 | |||
222 | 150 | if (status_proxy_cancel != NULL) { | ||
223 | 151 | g_cancellable_cancel(status_proxy_cancel); | ||
224 | 152 | g_object_unref(status_proxy_cancel); | ||
225 | 153 | status_proxy_cancel = NULL; | ||
226 | 154 | } | ||
227 | 132 | 155 | ||
228 | 133 | G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object); | 156 | G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object); |
229 | 157 | |||
230 | 134 | return; | 158 | return; |
231 | 135 | } | 159 | } |
232 | 136 | 160 | ||
233 | 137 | static void | 161 | static void |
234 | 138 | indicator_me_finalize (GObject *object) | 162 | indicator_me_finalize (GObject *object) |
235 | 139 | { | 163 | { |
236 | 140 | |||
237 | 141 | G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object); | 164 | G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object); |
238 | 142 | return; | 165 | return; |
239 | 143 | } | 166 | } |
240 | 144 | 167 | ||
241 | 145 | static void | 168 | static void |
243 | 146 | username_cb (DBusGProxy * proxy, char * username, GError *error, gpointer userdata) | 169 | username_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
244 | 170 | { | ||
245 | 171 | GError * error = NULL; | ||
246 | 172 | gchar * username; | ||
247 | 173 | GVariant * result; | ||
248 | 174 | |||
249 | 175 | IndicatorMe * self = INDICATOR_ME (user_data); | ||
250 | 176 | g_return_if_fail(self != NULL); | ||
251 | 177 | |||
252 | 178 | result = g_dbus_proxy_call_finish(status_proxy, res, &error); | ||
253 | 179 | g_return_if_fail(status_proxy != NULL); | ||
254 | 180 | |||
255 | 181 | if (error != NULL) { | ||
256 | 182 | g_error("Could not get the username %s", error->message); | ||
257 | 183 | g_error_free(error); | ||
258 | 184 | return; | ||
259 | 185 | } | ||
260 | 186 | |||
261 | 187 | g_variant_get(result, "(&s)", &username); | ||
262 | 188 | |||
263 | 189 | if (username != NULL) { | ||
264 | 190 | username_changed (self, username); | ||
265 | 191 | } | ||
266 | 192 | |||
267 | 193 | } | ||
268 | 194 | |||
269 | 195 | static void | ||
270 | 196 | username_changed (IndicatorMe * self, gchar * username) | ||
271 | 147 | { | 197 | { |
272 | 148 | if (label == NULL) { | 198 | if (label == NULL) { |
273 | 149 | label = GTK_LABEL(gtk_label_new(NULL)); | 199 | label = GTK_LABEL(gtk_label_new(NULL)); |
274 | @@ -163,11 +213,10 @@ | |||
275 | 163 | static GtkLabel * | 213 | static GtkLabel * |
276 | 164 | get_label (IndicatorObject * io) | 214 | get_label (IndicatorObject * io) |
277 | 165 | { | 215 | { |
279 | 166 | if (label == NULL) { | 216 | if (label == NULL) { |
280 | 167 | /* Create the label if it doesn't exist already */ | 217 | /* Create the label if it doesn't exist already */ |
284 | 168 | username_cb (NULL, NULL, NULL, NULL); | 218 | username_changed (NULL, NULL); |
285 | 169 | } | 219 | } |
283 | 170 | |||
286 | 171 | return label; | 220 | return label; |
287 | 172 | } | 221 | } |
288 | 173 | 222 | ||
289 | @@ -176,35 +225,74 @@ | |||
290 | 176 | { | 225 | { |
291 | 177 | if (status_image == NULL) { | 226 | if (status_image == NULL) { |
292 | 178 | /* Will create the status icon if it doesn't exist already */ | 227 | /* Will create the status icon if it doesn't exist already */ |
294 | 179 | status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL); | 228 | status_icon_changed(NULL, DEFAULT_ICON); |
295 | 180 | } | 229 | } |
296 | 181 | return status_image; | 230 | return status_image; |
297 | 182 | } | 231 | } |
298 | 183 | 232 | ||
299 | 184 | static void | 233 | static void |
304 | 185 | status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata) | 234 | status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
305 | 186 | { | 235 | { |
306 | 187 | g_return_if_fail(icons != NULL); | 236 | GError * error = NULL; |
307 | 188 | g_return_if_fail(icons[0] != '\0'); | 237 | gchar * icon = NULL; |
308 | 238 | GVariant * result; | ||
309 | 239 | |||
310 | 240 | IndicatorMe * self = INDICATOR_ME (user_data); | ||
311 | 241 | g_return_if_fail(self != NULL); | ||
312 | 242 | |||
313 | 243 | result = g_dbus_proxy_call_finish(status_proxy, res, &error); | ||
314 | 244 | g_return_if_fail(status_proxy != NULL); | ||
315 | 245 | |||
316 | 246 | if (error != NULL) { | ||
317 | 247 | g_error("Could not get the username %s", error->message); | ||
318 | 248 | g_error_free(error); | ||
319 | 249 | return; | ||
320 | 250 | } | ||
321 | 251 | |||
322 | 252 | g_variant_get(result, "(&s)", &icon); | ||
323 | 253 | |||
324 | 254 | if (icon != NULL) { | ||
325 | 255 | status_icon_changed (self, icon); | ||
326 | 256 | } | ||
327 | 257 | |||
328 | 258 | } | ||
329 | 259 | |||
330 | 260 | static void | ||
331 | 261 | status_icon_changed (IndicatorMe * self, gchar * icon) | ||
332 | 262 | { | ||
333 | 263 | g_return_if_fail(icon != NULL); | ||
334 | 264 | g_return_if_fail(icon[0] != '\0'); | ||
335 | 189 | 265 | ||
336 | 190 | if (status_image == NULL) { | 266 | if (status_image == NULL) { |
338 | 191 | status_image = indicator_image_helper (DEFAULT_ICON "-panel"); | 267 | status_image = indicator_image_helper (DEFAULT_ICON "-panel"); |
339 | 192 | gtk_widget_show(GTK_WIDGET(status_image)); | 268 | gtk_widget_show(GTK_WIDGET(status_image)); |
340 | 193 | } | 269 | } |
341 | 194 | 270 | ||
345 | 195 | gchar *panel_icon = g_strconcat (icons, "-panel", NULL); | 271 | gchar *panel_icon = g_strconcat (icon, "-panel", NULL); |
346 | 196 | indicator_image_helper_update (status_image, panel_icon); | 272 | indicator_image_helper_update (status_image, panel_icon); |
347 | 197 | g_free (panel_icon); | 273 | g_free (panel_icon); |
348 | 198 | 274 | ||
349 | 199 | return; | 275 | return; |
350 | 200 | } | 276 | } |
351 | 201 | 277 | ||
352 | 278 | /* Receives all signals from the service, routed to the appropriate functions */ | ||
353 | 202 | static void | 279 | static void |
355 | 203 | status_icon_changed (DBusGProxy * proxy, gchar * icon, gpointer userdata) | 280 | receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, |
356 | 281 | GVariant * parameters, gpointer user_data) | ||
357 | 204 | { | 282 | { |
359 | 205 | g_debug("Changing status icon: '%s'", icon); | 283 | IndicatorMe * self = INDICATOR_ME(user_data); |
360 | 206 | 284 | ||
362 | 207 | return status_icon_cb(proxy, icon, NULL, NULL); | 285 | if (g_strcmp0(signal_name, "StatusIconsChanged") == 0) { |
363 | 286 | gchar * icon; | ||
364 | 287 | g_variant_get (parameters, "(&s)", &icon); | ||
365 | 288 | status_icon_changed (self, icon); | ||
366 | 289 | } | ||
367 | 290 | else if (g_strcmp0(signal_name, "UserChanged") == 0) { | ||
368 | 291 | gchar * username; | ||
369 | 292 | g_variant_get (parameters, "(&s)", &username); | ||
370 | 293 | username_changed(self, username); | ||
371 | 294 | } | ||
372 | 295 | return; | ||
373 | 208 | } | 296 | } |
374 | 209 | 297 | ||
375 | 210 | static void | 298 | static void |
376 | @@ -221,61 +309,93 @@ | |||
377 | 221 | } | 309 | } |
378 | 222 | 310 | ||
379 | 223 | static void | 311 | static void |
381 | 224 | connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) | 312 | connection_changed (IndicatorServiceManager * self, gboolean connected, gpointer userdata) |
382 | 225 | { | 313 | { |
383 | 226 | if (connected) { | 314 | if (connected) { |
384 | 227 | if (status_proxy == NULL) { | 315 | if (status_proxy == NULL) { |
398 | 228 | GError * error = NULL; | 316 | if (status_proxy_cancel == NULL) { |
399 | 229 | 317 | status_proxy_cancel = g_cancellable_new(); | |
387 | 230 | DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); | ||
388 | 231 | |||
389 | 232 | status_proxy = dbus_g_proxy_new_for_name_owner(sbus, | ||
390 | 233 | INDICATOR_ME_DBUS_NAME, | ||
391 | 234 | INDICATOR_ME_SERVICE_DBUS_OBJECT, | ||
392 | 235 | INDICATOR_ME_SERVICE_DBUS_INTERFACE, | ||
393 | 236 | &error); | ||
394 | 237 | |||
395 | 238 | if (error != NULL) { | ||
396 | 239 | g_warning("Unable to get status proxy: %s", error->message); | ||
397 | 240 | g_error_free(error); | ||
400 | 241 | } | 318 | } |
409 | 242 | 319 | g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, | |
410 | 243 | if (status_proxy == NULL) return; | 320 | G_DBUS_PROXY_FLAGS_NONE, |
411 | 244 | 321 | NULL, | |
412 | 245 | dbus_g_proxy_add_signal(status_proxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID); | 322 | INDICATOR_ME_DBUS_NAME, |
413 | 246 | dbus_g_proxy_connect_signal(status_proxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), NULL, NULL); | 323 | INDICATOR_ME_SERVICE_DBUS_OBJECT, |
414 | 247 | 324 | INDICATOR_ME_SERVICE_DBUS_INTERFACE, | |
415 | 248 | dbus_g_proxy_add_signal(status_proxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID); | 325 | status_proxy_cancel, |
416 | 249 | dbus_g_proxy_connect_signal(status_proxy, "UserChanged", G_CALLBACK(username_cb), NULL, NULL); | 326 | status_proxy_cb, |
417 | 327 | userdata); | ||
418 | 328 | |||
419 | 250 | } | 329 | } |
420 | 251 | |||
421 | 252 | org_ayatana_indicator_me_service_status_icons_async(status_proxy, status_icon_cb, NULL); | ||
422 | 253 | |||
423 | 254 | /* query the service for the username to display */ | ||
424 | 255 | org_ayatana_indicator_me_service_pretty_user_name_async(status_proxy, username_cb, NULL); | ||
425 | 256 | } else { | 330 | } else { |
427 | 257 | DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry), | 331 | DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry), |
428 | 258 | "dbusmenuitem"); | 332 | "dbusmenuitem"); |
429 | 259 | 333 | ||
431 | 260 | g_signal_handlers_disconnect_by_func (ido_entry, | 334 | g_signal_handlers_disconnect_by_func (ido_entry, |
432 | 261 | G_CALLBACK (entry_activate_cb), | 335 | G_CALLBACK (entry_activate_cb), |
433 | 262 | mi); | 336 | mi); |
434 | 263 | 337 | ||
436 | 264 | g_signal_handlers_disconnect_by_func (ido_entry, | 338 | g_signal_handlers_disconnect_by_func (ido_entry, |
437 | 265 | G_CALLBACK (entry_prop_change_cb), | 339 | G_CALLBACK (entry_prop_change_cb), |
438 | 266 | mi); | 340 | mi); |
439 | 267 | 341 | ||
440 | 268 | /* If we're disconnecting, go back to offline */ | 342 | /* If we're disconnecting, go back to offline */ |
451 | 269 | status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL); | 343 | status_icon_changed(NULL, DEFAULT_ICON); |
452 | 270 | 344 | ||
453 | 271 | g_object_unref (status_proxy); | 345 | g_object_unref (status_proxy); |
454 | 272 | status_proxy = NULL; | 346 | status_proxy = NULL; |
455 | 273 | 347 | ||
456 | 274 | if (ido_entry != NULL) { | 348 | if (ido_entry != NULL) { |
457 | 275 | gtk_widget_destroy (GTK_WIDGET (ido_entry)); | 349 | gtk_widget_destroy (GTK_WIDGET (ido_entry)); |
458 | 276 | ido_entry = NULL; | 350 | ido_entry = NULL; |
459 | 277 | } | 351 | } |
460 | 278 | } | 352 | } |
461 | 353 | |||
462 | 354 | return; | ||
463 | 355 | } | ||
464 | 356 | |||
465 | 357 | /* Callback from trying to create the proxy for the service, this | ||
466 | 358 | could include starting the service. Sometimes it'll fail and | ||
467 | 359 | we'll try to start that dang service again! */ | ||
468 | 360 | static void | ||
469 | 361 | status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) | ||
470 | 362 | { | ||
471 | 363 | GError * error = NULL; | ||
472 | 364 | |||
473 | 365 | g_return_if_fail(object != NULL); | ||
474 | 366 | |||
475 | 367 | GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); | ||
476 | 368 | |||
477 | 369 | if (status_proxy_cancel != NULL) { | ||
478 | 370 | g_object_unref(status_proxy_cancel); | ||
479 | 371 | status_proxy_cancel = NULL; | ||
480 | 372 | } | ||
481 | 373 | |||
482 | 374 | if (error != NULL) { | ||
483 | 375 | g_error("Could not grab DBus proxy for %s: %s", INDICATOR_ME_DBUS_NAME, error->message); | ||
484 | 376 | g_error_free(error); | ||
485 | 377 | return; | ||
486 | 378 | } | ||
487 | 379 | |||
488 | 380 | IndicatorMe * self = INDICATOR_ME (user_data); | ||
489 | 381 | |||
490 | 382 | /* Okay, we're good to grab the proxy at this point, we're | ||
491 | 383 | sure that it's ours. */ | ||
492 | 384 | status_proxy = proxy; | ||
493 | 385 | |||
494 | 386 | g_signal_connect(status_proxy, "g-signal", G_CALLBACK(receive_signal), self); | ||
495 | 387 | |||
496 | 388 | /* Query to get the username */ | ||
497 | 389 | g_debug("Get the username"); | ||
498 | 390 | g_dbus_proxy_call(status_proxy, "PrettyUserName", NULL, | ||
499 | 391 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, | ||
500 | 392 | (GAsyncReadyCallback) username_cb, self); | ||
501 | 393 | |||
502 | 394 | /* Query to get the status icon */ | ||
503 | 395 | g_debug("Get the status icon"); | ||
504 | 396 | g_dbus_proxy_call(status_proxy, "StatusIcons", NULL, | ||
505 | 397 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, | ||
506 | 398 | (GAsyncReadyCallback) status_icon_cb, self); | ||
507 | 279 | 399 | ||
508 | 280 | return; | 400 | return; |
509 | 281 | } | 401 | } |
510 | 282 | 402 | ||
511 | === modified file 'src/me-service-dbus.c' | |||
512 | --- src/me-service-dbus.c 2010-02-24 19:54:33 +0000 | |||
513 | +++ src/me-service-dbus.c 2011-01-14 17:27:04 +0000 | |||
514 | @@ -24,8 +24,9 @@ | |||
515 | 24 | #include "config.h" | 24 | #include "config.h" |
516 | 25 | #endif | 25 | #endif |
517 | 26 | 26 | ||
519 | 27 | #include <dbus/dbus-glib.h> | 27 | #include <gio/gio.h> |
520 | 28 | 28 | ||
521 | 29 | #include "gen-me-service.xml.h" | ||
522 | 29 | #include "dbus-shared-names.h" | 30 | #include "dbus-shared-names.h" |
523 | 30 | #include "me-service-dbus.h" | 31 | #include "me-service-dbus.h" |
524 | 31 | 32 | ||
525 | @@ -33,16 +34,28 @@ | |||
526 | 33 | static void status_service_dbus_init (StatusServiceDbus *self); | 34 | static void status_service_dbus_init (StatusServiceDbus *self); |
527 | 34 | static void status_service_dbus_dispose (GObject *object); | 35 | static void status_service_dbus_dispose (GObject *object); |
528 | 35 | static void status_service_dbus_finalize (GObject *object); | 36 | static void status_service_dbus_finalize (GObject *object); |
536 | 36 | static gboolean _me_service_server_watch (StatusServiceDbus * service, GError ** error); | 37 | static GVariant * get_icon (StatusServiceDbus * service); |
537 | 37 | static gboolean _me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error); | 38 | static GVariant * get_username (StatusServiceDbus * service); |
538 | 38 | static gboolean _me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error); | 39 | static GVariant * status_service_dbus_watch (StatusServiceDbus * service); |
539 | 39 | 40 | static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data); | |
540 | 40 | #include "me-service-server.h" | 41 | 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); |
541 | 41 | 42 | ||
542 | 42 | /* Private */ | 43 | |
543 | 44 | |||
544 | 45 | /** | ||
545 | 46 | StatusServiceDbusPrivate: | ||
546 | 47 | @dbus_registration: The handle for this object being registered | ||
547 | 48 | on dbus. | ||
548 | 49 | |||
549 | 50 | Structure to define the memory for the private area | ||
550 | 51 | of the status service dbus instance. | ||
551 | 52 | */ | ||
552 | 43 | typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate; | 53 | typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate; |
553 | 44 | struct _StatusServiceDbusPrivate | 54 | struct _StatusServiceDbusPrivate |
554 | 45 | { | 55 | { |
555 | 56 | GDBusConnection * bus; | ||
556 | 57 | GCancellable * bus_cancel; | ||
557 | 58 | guint dbus_registration; | ||
558 | 46 | gchar * name; | 59 | gchar * name; |
559 | 47 | gchar * icon; | 60 | gchar * icon; |
560 | 48 | }; | 61 | }; |
561 | @@ -50,15 +63,15 @@ | |||
562 | 50 | #define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \ | 63 | #define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \ |
563 | 51 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate)) | 64 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate)) |
564 | 52 | 65 | ||
570 | 53 | /* Signals */ | 66 | /* GDBus Stuff */ |
571 | 54 | enum { | 67 | static GDBusNodeInfo * node_info = NULL; |
572 | 55 | USER_CHANGED, | 68 | static GDBusInterfaceInfo * interface_info = NULL; |
573 | 56 | STATUS_ICONS_CHANGED, | 69 | static GDBusInterfaceVTable interface_table = { |
574 | 57 | LAST_SIGNAL | 70 | method_call: bus_method_call, |
575 | 71 | get_property: NULL, /* No properties */ | ||
576 | 72 | set_property: NULL /* No properties */ | ||
577 | 58 | }; | 73 | }; |
578 | 59 | 74 | ||
579 | 60 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
580 | 61 | |||
581 | 62 | /* GObject Boilerplate */ | 75 | /* GObject Boilerplate */ |
582 | 63 | G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT); | 76 | G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT); |
583 | 64 | 77 | ||
584 | @@ -72,64 +85,135 @@ | |||
585 | 72 | object_class->dispose = status_service_dbus_dispose; | 85 | object_class->dispose = status_service_dbus_dispose; |
586 | 73 | object_class->finalize = status_service_dbus_finalize; | 86 | object_class->finalize = status_service_dbus_finalize; |
587 | 74 | 87 | ||
624 | 75 | /** | 88 | /* Setting up the DBus interfaces */ |
625 | 76 | StatusServiceDbus::user-changed: | 89 | if (node_info == NULL) { |
626 | 77 | @arg0: The #StatusServiceDbus object. | 90 | GError * error = NULL; |
627 | 78 | @arg1: The place to put the new user name | 91 | |
628 | 79 | 92 | node_info = g_dbus_node_info_new_for_xml(_me_service, &error); | |
629 | 80 | Signals that the user name has changed and gives the | 93 | if (error != NULL) { |
630 | 81 | new user name. | 94 | g_error("Unable to parse Me Service Interface description: %s", error->message); |
631 | 82 | */ | 95 | g_error_free(error); |
632 | 83 | signals[USER_CHANGED] = g_signal_new("user-changed", | 96 | } |
633 | 84 | G_TYPE_FROM_CLASS(klass), | 97 | } |
634 | 85 | G_SIGNAL_RUN_LAST, | 98 | |
635 | 86 | G_STRUCT_OFFSET(StatusServiceDbusClass, user_changed), | 99 | if (interface_info == NULL) { |
636 | 87 | NULL, NULL, | 100 | interface_info = g_dbus_node_info_lookup_interface(node_info, INDICATOR_ME_SERVICE_DBUS_INTERFACE); |
637 | 88 | g_cclosure_marshal_VOID__STRING, | 101 | |
638 | 89 | G_TYPE_NONE, 1, G_TYPE_STRING); | 102 | if (interface_info == NULL) { |
639 | 90 | 103 | g_error("Unable to find interface '" INDICATOR_ME_SERVICE_DBUS_INTERFACE "'"); | |
640 | 91 | /** | 104 | } |
641 | 92 | StatusServiceDbus::status-icons-changed: | 105 | } |
642 | 93 | @arg0: The #StatusServiceDbus object. | 106 | |
607 | 94 | @arg1: The list of icon names representing the statuses in | ||
608 | 95 | the order they should be displayed. Left to right. | ||
609 | 96 | |||
610 | 97 | Signals that the user status set has changed and that | ||
611 | 98 | new icons may need to be loaded. The list of icons will | ||
612 | 99 | always be complete. | ||
613 | 100 | */ | ||
614 | 101 | signals[STATUS_ICONS_CHANGED] = g_signal_new("status-icons-changed", | ||
615 | 102 | G_TYPE_FROM_CLASS(klass), | ||
616 | 103 | G_SIGNAL_RUN_LAST, | ||
617 | 104 | G_STRUCT_OFFSET(StatusServiceDbusClass, status_icons_changed), | ||
618 | 105 | NULL, NULL, | ||
619 | 106 | g_cclosure_marshal_VOID__STRING, | ||
620 | 107 | G_TYPE_NONE, 1, G_TYPE_STRING); | ||
621 | 108 | |||
622 | 109 | dbus_g_object_type_install_info(STATUS_SERVICE_DBUS_TYPE, &dbus_glib__me_service_server_object_info); | ||
623 | 110 | |||
643 | 111 | return; | 107 | return; |
644 | 112 | } | 108 | } |
645 | 113 | 109 | ||
646 | 114 | static void | 110 | static void |
647 | 115 | status_service_dbus_init (StatusServiceDbus *self) | 111 | status_service_dbus_init (StatusServiceDbus *self) |
648 | 116 | { | 112 | { |
649 | 117 | |||
650 | 118 | DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); | ||
651 | 119 | dbus_g_connection_register_g_object(connection, | ||
652 | 120 | INDICATOR_ME_SERVICE_DBUS_OBJECT, | ||
653 | 121 | G_OBJECT(self)); | ||
654 | 122 | |||
655 | 123 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); | 113 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
656 | 124 | priv->name = NULL; | 114 | priv->name = NULL; |
657 | 125 | priv->icon = NULL; | 115 | priv->icon = NULL; |
658 | 126 | 116 | ||
661 | 127 | return; | 117 | priv->bus = NULL; |
662 | 128 | } | 118 | priv->bus_cancel = NULL; |
663 | 119 | priv->dbus_registration = 0; | ||
664 | 120 | |||
665 | 121 | priv->bus_cancel = g_cancellable_new(); | ||
666 | 122 | g_bus_get(G_BUS_TYPE_SESSION, | ||
667 | 123 | priv->bus_cancel, | ||
668 | 124 | bus_get_cb, | ||
669 | 125 | self); | ||
670 | 126 | |||
671 | 127 | return; | ||
672 | 128 | } | ||
673 | 129 | |||
674 | 130 | static void | ||
675 | 131 | bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data) | ||
676 | 132 | { | ||
677 | 133 | GError * error = NULL; | ||
678 | 134 | GDBusConnection * connection = g_bus_get_finish(res, &error); | ||
679 | 135 | |||
680 | 136 | if (error != NULL) { | ||
681 | 137 | g_error("OMG! Unable to get a connection to DBus: %s", error->message); | ||
682 | 138 | g_error_free(error); | ||
683 | 139 | return; | ||
684 | 140 | } | ||
685 | 141 | |||
686 | 142 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(user_data); | ||
687 | 143 | |||
688 | 144 | g_warn_if_fail(priv->bus == NULL); | ||
689 | 145 | priv->bus = connection; | ||
690 | 146 | |||
691 | 147 | if (priv->bus_cancel != NULL) { | ||
692 | 148 | g_object_unref(priv->bus_cancel); | ||
693 | 149 | priv->bus_cancel = NULL; | ||
694 | 150 | } | ||
695 | 151 | |||
696 | 152 | /* Now register our object on our new connection */ | ||
697 | 153 | priv->dbus_registration = g_dbus_connection_register_object(connection, | ||
698 | 154 | INDICATOR_ME_SERVICE_DBUS_OBJECT, | ||
699 | 155 | interface_info, | ||
700 | 156 | &interface_table, | ||
701 | 157 | user_data, | ||
702 | 158 | NULL, | ||
703 | 159 | &error); | ||
704 | 160 | |||
705 | 161 | if (error != NULL) { | ||
706 | 162 | g_error("Unable to register the object to DBus: %s", error->message); | ||
707 | 163 | g_error_free(error); | ||
708 | 164 | return; | ||
709 | 165 | } | ||
710 | 166 | |||
711 | 167 | return; | ||
712 | 168 | } | ||
713 | 169 | |||
714 | 170 | /* A method has been called from our dbus inteface. Figure out what it | ||
715 | 171 | is and dispatch it. */ | ||
716 | 172 | static void | ||
717 | 173 | bus_method_call (GDBusConnection * connection, const gchar * sender, | ||
718 | 174 | const gchar * path, const gchar * interface, | ||
719 | 175 | const gchar * method, GVariant * params, | ||
720 | 176 | GDBusMethodInvocation * invocation, gpointer user_data) | ||
721 | 177 | { | ||
722 | 178 | StatusServiceDbus * service = STATUS_SERVICE_DBUS(user_data); | ||
723 | 179 | GVariant * retval = NULL; | ||
724 | 180 | |||
725 | 181 | if (g_strcmp0(method, "PrettyUserName") == 0) { | ||
726 | 182 | retval = get_username(service); | ||
727 | 183 | } else if (g_strcmp0(method, "StatusIcons") == 0) { | ||
728 | 184 | retval = get_icon(service); | ||
729 | 185 | } else if (g_strcmp0(method, "Watch") == 0) { | ||
730 | 186 | retval = status_service_dbus_watch(service); | ||
731 | 187 | } else { | ||
732 | 188 | g_warning("Calling method '%s' on the indicator service and it's unknown", method); | ||
733 | 189 | } | ||
734 | 190 | |||
735 | 191 | g_dbus_method_invocation_return_value(invocation, retval); | ||
736 | 192 | return; | ||
737 | 193 | } | ||
738 | 194 | |||
739 | 129 | 195 | ||
740 | 130 | static void | 196 | static void |
741 | 131 | status_service_dbus_dispose (GObject *object) | 197 | status_service_dbus_dispose (GObject *object) |
742 | 132 | { | 198 | { |
743 | 199 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(object); | ||
744 | 200 | |||
745 | 201 | if (priv->dbus_registration != 0) { | ||
746 | 202 | g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); | ||
747 | 203 | /* Don't care if it fails, there's nothing we can do */ | ||
748 | 204 | priv->dbus_registration = 0; | ||
749 | 205 | } | ||
750 | 206 | |||
751 | 207 | if (priv->bus != NULL) { | ||
752 | 208 | g_object_unref(priv->bus); | ||
753 | 209 | priv->bus = NULL; | ||
754 | 210 | } | ||
755 | 211 | |||
756 | 212 | if (priv->bus_cancel != NULL) { | ||
757 | 213 | g_cancellable_cancel(priv->bus_cancel); | ||
758 | 214 | g_object_unref(priv->bus_cancel); | ||
759 | 215 | priv->bus_cancel = NULL; | ||
760 | 216 | } | ||
761 | 133 | 217 | ||
762 | 134 | G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object); | 218 | G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object); |
763 | 135 | return; | 219 | return; |
764 | @@ -143,47 +227,25 @@ | |||
765 | 143 | return; | 227 | return; |
766 | 144 | } | 228 | } |
767 | 145 | 229 | ||
809 | 146 | static gboolean | 230 | static GVariant * |
810 | 147 | _me_service_server_watch (StatusServiceDbus * service, GError ** error) | 231 | status_service_dbus_watch (StatusServiceDbus * service) |
811 | 148 | { | 232 | { |
812 | 149 | 233 | return g_variant_new("(b)", TRUE); | |
813 | 150 | return TRUE; | 234 | } |
814 | 151 | } | 235 | |
815 | 152 | 236 | ||
816 | 153 | static gboolean | 237 | static GVariant * |
817 | 154 | _me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error) | 238 | get_username (StatusServiceDbus * service) |
818 | 155 | { | 239 | { |
819 | 156 | if (!IS_STATUS_SERVICE_DBUS(service)) { | 240 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
820 | 157 | g_warning("NO BAD EVIL!"); | 241 | return g_variant_new("(s)", priv->name); |
821 | 158 | return FALSE; | 242 | } |
822 | 159 | } | 243 | |
823 | 160 | 244 | static GVariant * | |
824 | 161 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); | 245 | get_icon (StatusServiceDbus * service) |
825 | 162 | if (priv->icon == NULL) { | 246 | { |
826 | 163 | *icon = g_strdup(""); | 247 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
827 | 164 | } else { | 248 | return g_variant_new("(s)", priv->icon); |
787 | 165 | *icon = g_strdup(priv->icon); | ||
788 | 166 | } | ||
789 | 167 | |||
790 | 168 | return TRUE; | ||
791 | 169 | } | ||
792 | 170 | |||
793 | 171 | static gboolean | ||
794 | 172 | _me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error) | ||
795 | 173 | { | ||
796 | 174 | if (!IS_STATUS_SERVICE_DBUS(service)) { | ||
797 | 175 | g_warning("NO BAD EVIL!"); | ||
798 | 176 | return FALSE; | ||
799 | 177 | } | ||
800 | 178 | |||
801 | 179 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); | ||
802 | 180 | if (priv->name == NULL) { | ||
803 | 181 | *username = g_strdup(""); | ||
804 | 182 | } else { | ||
805 | 183 | *username = g_strdup(priv->name); | ||
806 | 184 | } | ||
807 | 185 | |||
808 | 186 | return TRUE; | ||
828 | 187 | } | 249 | } |
829 | 188 | 250 | ||
830 | 189 | void | 251 | void |
831 | @@ -195,12 +257,31 @@ | |||
832 | 195 | 257 | ||
833 | 196 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); | 258 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
834 | 197 | 259 | ||
835 | 260 | GError * error = NULL; | ||
836 | 261 | |||
837 | 198 | if (priv->icon != NULL) { | 262 | if (priv->icon != NULL) { |
838 | 199 | g_free(priv->icon); | 263 | g_free(priv->icon); |
839 | 200 | } | 264 | } |
840 | 201 | priv->icon = g_strdup(icon); | 265 | priv->icon = g_strdup(icon); |
841 | 202 | 266 | ||
843 | 203 | g_signal_emit(G_OBJECT(self), signals[STATUS_ICONS_CHANGED], 0, priv->icon, TRUE); | 267 | if (priv->bus == NULL) { |
844 | 268 | return; | ||
845 | 269 | } | ||
846 | 270 | |||
847 | 271 | g_dbus_connection_emit_signal (priv->bus, | ||
848 | 272 | NULL, | ||
849 | 273 | INDICATOR_ME_SERVICE_DBUS_OBJECT, | ||
850 | 274 | INDICATOR_ME_SERVICE_DBUS_INTERFACE, | ||
851 | 275 | "StatusIconsChanged", | ||
852 | 276 | g_variant_new("(s)", icon), | ||
853 | 277 | &error); | ||
854 | 278 | |||
855 | 279 | if (error != NULL) { | ||
856 | 280 | g_error("Unable to send StatusIconsChanged signal: %s", error->message); | ||
857 | 281 | g_error_free(error); | ||
858 | 282 | return; | ||
859 | 283 | } | ||
860 | 284 | |||
861 | 204 | return; | 285 | return; |
862 | 205 | } | 286 | } |
863 | 206 | 287 | ||
864 | @@ -213,11 +294,30 @@ | |||
865 | 213 | 294 | ||
866 | 214 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); | 295 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
867 | 215 | 296 | ||
868 | 297 | GError * error = NULL; | ||
869 | 298 | |||
870 | 216 | if (priv->name != NULL) { | 299 | if (priv->name != NULL) { |
871 | 217 | g_free(priv->name); | 300 | g_free(priv->name); |
872 | 218 | } | 301 | } |
873 | 219 | priv->name = g_strdup(username); | 302 | priv->name = g_strdup(username); |
874 | 220 | 303 | ||
876 | 221 | g_signal_emit(G_OBJECT(self), signals[USER_CHANGED], 0, priv->name, TRUE); | 304 | if (priv->bus == NULL) { |
877 | 305 | return; | ||
878 | 306 | } | ||
879 | 307 | |||
880 | 308 | g_dbus_connection_emit_signal (priv->bus, | ||
881 | 309 | NULL, | ||
882 | 310 | INDICATOR_ME_SERVICE_DBUS_OBJECT, | ||
883 | 311 | INDICATOR_ME_SERVICE_DBUS_INTERFACE, | ||
884 | 312 | "UserChanged", | ||
885 | 313 | NULL, | ||
886 | 314 | &error); | ||
887 | 315 | |||
888 | 316 | if (error != NULL) { | ||
889 | 317 | g_error("Unable to send UserChanged signal: %s", error->message); | ||
890 | 318 | g_error_free(error); | ||
891 | 319 | return; | ||
892 | 320 | } | ||
893 | 321 | |||
894 | 222 | return; | 322 | return; |
895 | 223 | } | 323 | } |
896 | 224 | 324 | ||
897 | === modified file 'src/me-service-gwibber.c' | |||
898 | --- src/me-service-gwibber.c 2010-09-15 21:07:40 +0000 | |||
899 | +++ src/me-service-gwibber.c 2011-01-14 17:27:04 +0000 | |||
900 | @@ -130,21 +130,13 @@ | |||
901 | 130 | return; | 130 | return; |
902 | 131 | } | 131 | } |
903 | 132 | 132 | ||
904 | 133 | static gboolean | ||
905 | 134 | check_account_send_enabled (GHashTable * account_table) { | ||
906 | 135 | return g_value_get_boolean(g_hash_table_lookup(account_table, "send_enabled")); | ||
907 | 136 | } | ||
908 | 137 | |||
909 | 138 | static void | 133 | static void |
910 | 139 | query_account_manager (MeGwibberService *self) | 134 | query_account_manager (MeGwibberService *self) |
911 | 140 | { | 135 | { |
912 | 141 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); | 136 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
913 | 142 | 137 | ||
919 | 143 | gpointer accounts_table; | 138 | GList* accounts_list; |
920 | 144 | gpointer account_table; | 139 | GwibberAccount* account; |
916 | 145 | GHashTableIter accounts_iter; | ||
917 | 146 | gpointer account; | ||
918 | 147 | gboolean send_enabled; | ||
921 | 148 | 140 | ||
922 | 149 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); | 141 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
923 | 150 | 142 | ||
924 | @@ -152,26 +144,25 @@ | |||
925 | 152 | g_warning ("no accounts, can't query for accounts"); | 144 | g_warning ("no accounts, can't query for accounts"); |
926 | 153 | goto reset_accounts_string; | 145 | goto reset_accounts_string; |
927 | 154 | } | 146 | } |
928 | 147 | accounts_list = gwibber_accounts_list (priv->me_gwibber_accounts); | ||
929 | 155 | 148 | ||
932 | 156 | accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts); | 149 | if (accounts_list == NULL) { |
931 | 157 | if (accounts_table == NULL) { | ||
933 | 158 | g_warning ("failed to get accounts list"); | 150 | g_warning ("failed to get accounts list"); |
934 | 159 | goto reset_accounts_string; | 151 | goto reset_accounts_string; |
935 | 160 | } | 152 | } |
936 | 161 | 153 | ||
937 | 162 | g_hash_table_iter_init (&accounts_iter, accounts_table); | ||
938 | 163 | |||
939 | 164 | priv->has_configured_accounts = FALSE; | 154 | priv->has_configured_accounts = FALSE; |
940 | 165 | GList *list = NULL; | 155 | GList *list = NULL; |
941 | 166 | 156 | ||
945 | 167 | while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) { | 157 | GList* account_it; |
946 | 168 | send_enabled = check_account_send_enabled (account_table); | 158 | for (account_it = accounts_list; account_it != NULL; account_it = account_it->next) { |
947 | 169 | if (send_enabled) { | 159 | account = g_object_ref ((GwibberAccount*) account_it->data); |
948 | 160 | if (g_strcmp0(gwibber_account_get_send_enabled (account), "1") == 0) { | ||
949 | 170 | priv->has_configured_accounts = TRUE; | 161 | priv->has_configured_accounts = TRUE; |
954 | 171 | GValue *value = g_hash_table_lookup (account_table, "service"); | 162 | const gchar * service_name = gwibber_account_get_service (account); |
955 | 172 | if (value != NULL) | 163 | if (service_name != NULL) { |
956 | 173 | list = g_list_append (list, | 164 | list = g_list_append (list, g_strdup (service_name)); |
957 | 174 | g_strdup (g_value_get_string (value))); | 165 | } |
958 | 175 | } | 166 | } |
959 | 176 | } | 167 | } |
960 | 177 | 168 | ||
961 | @@ -206,8 +197,6 @@ | |||
962 | 206 | ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, | 197 | ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, |
963 | 207 | 0, priv->status, TRUE); | 198 | 0, priv->status, TRUE); |
964 | 208 | 199 | ||
965 | 209 | g_hash_table_destroy(accounts_table); | ||
966 | 210 | |||
967 | 211 | return; | 200 | return; |
968 | 212 | 201 | ||
969 | 213 | reset_accounts_string: | 202 | reset_accounts_string: |
970 | @@ -280,7 +269,6 @@ | |||
971 | 280 | me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata) | 269 | me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata) |
972 | 281 | { | 270 | { |
973 | 282 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata)); | 271 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata)); |
974 | 283 | |||
975 | 284 | if (exists) { | 272 | if (exists) { |
976 | 285 | if (priv->me_gwibber_accounts == NULL) { | 273 | if (priv->me_gwibber_accounts == NULL) { |
977 | 286 | priv->me_gwibber_accounts = gwibber_accounts_new ();; | 274 | priv->me_gwibber_accounts = gwibber_accounts_new ();; |
978 | @@ -304,16 +292,12 @@ | |||
979 | 304 | } | 292 | } |
980 | 305 | 293 | ||
981 | 306 | void | 294 | void |
983 | 307 | me_gwibber_service_send (MeGwibberService *self, const gchar *msg) | 295 | me_gwibber_service_send (MeGwibberService *self, gchar * msg) |
984 | 308 | { | 296 | { |
985 | 309 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); | 297 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
986 | 310 | 298 | ||
987 | 311 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); | 299 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
988 | 312 | 300 | ||
989 | 313 | GValue value = {0}; | ||
990 | 314 | g_value_init(&value, G_TYPE_STRING); | ||
991 | 315 | g_value_set_string(&value, msg); | ||
992 | 316 | |||
993 | 317 | if (priv->me_gwibber_service == NULL) { | 301 | if (priv->me_gwibber_service == NULL) { |
994 | 318 | setup_service_proxies (self); | 302 | setup_service_proxies (self); |
995 | 319 | if (priv->me_gwibber_service == NULL) { | 303 | if (priv->me_gwibber_service == NULL) { |
996 | @@ -322,9 +306,7 @@ | |||
997 | 322 | } | 306 | } |
998 | 323 | } | 307 | } |
999 | 324 | 308 | ||
1003 | 325 | gwibber_service_send_message (priv->me_gwibber_service, g_value_get_string (&value)); | 309 | gwibber_service_send_message (priv->me_gwibber_service, msg); |
1001 | 326 | |||
1002 | 327 | g_value_unset(&value); | ||
1004 | 328 | 310 | ||
1005 | 329 | return; | 311 | return; |
1006 | 330 | } | 312 | } |
1007 | 331 | 313 | ||
1008 | === modified file 'src/me-service-gwibber.h' | |||
1009 | --- src/me-service-gwibber.h 2010-09-15 21:07:40 +0000 | |||
1010 | +++ src/me-service-gwibber.h 2011-01-14 17:27:04 +0000 | |||
1011 | @@ -66,7 +66,7 @@ | |||
1012 | 66 | GType me_gwibber_service_get_type (void) G_GNUC_CONST; | 66 | GType me_gwibber_service_get_type (void) G_GNUC_CONST; |
1013 | 67 | MeGwibberService * me_gwibber_service_new (void); | 67 | MeGwibberService * me_gwibber_service_new (void); |
1014 | 68 | MeGwibberService * me_gwibber_service_get (void); | 68 | MeGwibberService * me_gwibber_service_get (void); |
1016 | 69 | void me_gwibber_service_send (MeGwibberService *self, const gchar *msg); | 69 | void me_gwibber_service_send (MeGwibberService *self, gchar *msg); |
1017 | 70 | gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self); | 70 | gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self); |
1018 | 71 | const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self); | 71 | const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self); |
1019 | 72 | 72 |
conncetion_ changed( )
Should really check to see if status_proxy_cancel is NULL as well so that you don't allocate two of them.
status_proxy_cb()
You shouldn't cast the user_data to self before checking the error. There is a few cases where the indicator could be deallocated before this function is called and therefore user_data would be a random pointer.