Merge lp:~ken-vandine/indicator-me/libgwibber-port into lp:indicator-me
- libgwibber-port
- Merge into trunk
Proposed by
Ken VanDine
on 2010-08-16
| Status: | Merged |
|---|---|
| Approved by: | David Barth on 2010-08-17 |
| Approved revision: | 105 |
| Merge reported by: | David Barth |
| Merged at revision: | not available |
| Proposed branch: | lp:~ken-vandine/indicator-me/libgwibber-port |
| Merge into: | lp:indicator-me |
| Diff against target: |
768 lines (+240/-352) 5 files modified
configure.ac (+2/-0) src/entry-menu-item.c (+2/-2) src/me-service-gwibber.c (+199/-302) src/me-service-gwibber.h (+31/-32) src/me-service.c (+6/-16) |
| To merge this branch: | bzr merge lp:~ken-vandine/indicator-me/libgwibber-port |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| David Barth | 2010-08-16 | Approve on 2010-08-17 | |
| Ken VanDine | Resubmit on 2010-08-17 | ||
|
Review via email:
|
|||
Commit Message
Description of the Change
Port to libgwibber
To post a comment you must log in.
lp:~ken-vandine/indicator-me/libgwibber-port
updated
on 2010-08-17
- 102. By Ken VanDine on 2010-08-17
-
remove a noop
- 103. By Ken VanDine on 2010-08-17
-
Don't set status to NOT_RUNNING if we get a response from gwibber
- 104. By Ken VanDine on 2010-08-17
-
Don't set status based on configured accounts
| Ken VanDine (ken-vandine) wrote : | # |
OK, I think I addressed all of those. It will no longer hide the entry if the service shuts down, but it does hide if you disable all the accounts.
review:
Resubmit
lp:~ken-vandine/indicator-me/libgwibber-port
updated
on 2010-08-17
- 105. By Ken VanDine on 2010-08-17
-
check for send_enabled even if configured_accounts was TRUE before
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'configure.ac' |
| 2 | --- configure.ac 2010-03-24 09:42:26 +0000 |
| 3 | +++ configure.ac 2010-08-17 14:44:43 +0000 |
| 4 | @@ -28,6 +28,7 @@ |
| 5 | |
| 6 | GTK_REQUIRED_VERSION=2.12 |
| 7 | INDICATOR_REQUIRED_VERSION=0.3.0 |
| 8 | +GWIBBER_REQUIRED_VERSION=0.0.4 |
| 9 | DBUSMENUGTK_REQUIRED_VERSION=0.2.2 |
| 10 | DBUSMENUGLIB_REQUIRED_VERSION=0.2.2 |
| 11 | TELEPATHYGLIB_REQUIRED_VERSION=0.9.0 |
| 12 | @@ -41,6 +42,7 @@ |
| 13 | PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION |
| 14 | gconf-2.0 >= $GCONF_REQUIRED_VERSION |
| 15 | indicator >= $INDICATOR_REQUIRED_VERSION |
| 16 | + gwibber >= $GWIBBER_REQUIRED_VERSION |
| 17 | telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION) |
| 18 | |
| 19 | ########################### |
| 20 | |
| 21 | === modified file 'src/entry-menu-item.c' |
| 22 | --- src/entry-menu-item.c 2010-03-17 16:19:44 +0000 |
| 23 | +++ src/entry-menu-item.c 2010-08-17 14:44:43 +0000 |
| 24 | @@ -128,8 +128,8 @@ |
| 25 | |
| 26 | g_debug ("handle_event"); |
| 27 | if (g_strcmp0 (name, "send") == 0) { |
| 28 | - GwibberService *gwibber = gwibber_service_get (); |
| 29 | - gwibber_service_send (gwibber, g_value_get_string (value)); |
| 30 | + MeGwibberService *me_gwibber_service = me_gwibber_service_get (); |
| 31 | + me_gwibber_service_send (me_gwibber_service, g_value_get_string (value)); |
| 32 | dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, ""); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | === modified file 'src/me-service-gwibber.c' |
| 37 | --- src/me-service-gwibber.c 2010-03-24 09:38:22 +0000 |
| 38 | +++ src/me-service-gwibber.c 2010-08-17 14:44:43 +0000 |
| 39 | @@ -24,23 +24,14 @@ |
| 40 | |
| 41 | #include <glib.h> |
| 42 | |
| 43 | -#include <dbus/dbus-glib.h> |
| 44 | -#include <dbus/dbus-glib-bindings.h> |
| 45 | - |
| 46 | -#define DBUS_SERVICE_ADDRESS "com.Gwibber.Service" |
| 47 | -#define DBUS_SERVICE_SERVICE_OBJECT "/com/gwibber/Service" |
| 48 | -#define DBUS_SERVICE_SERVICE_INTERFACE "com.Gwibber.Service" |
| 49 | - |
| 50 | -#define DBUS_SERVICE_ACCOUNTS_OBJECT "/com/gwibber/Accounts" |
| 51 | -#define DBUS_SERVICE_ACCOUNTS_INTERFACE "com.Gwibber.Accounts" |
| 52 | +#include <gwibber.h> |
| 53 | |
| 54 | /* gobject infrastructure */ |
| 55 | |
| 56 | -typedef struct _GwibberServicePrivate GwibberServicePrivate; |
| 57 | -struct _GwibberServicePrivate { |
| 58 | - DBusGProxy * dbus_proxy; |
| 59 | - DBusGProxy * service_proxy; |
| 60 | - DBusGProxy * accounts_proxy; |
| 61 | +typedef struct _MeGwibberServicePrivate MeGwibberServicePrivate; |
| 62 | +struct _MeGwibberServicePrivate { |
| 63 | + GwibberService * me_gwibber_service; |
| 64 | + GwibberAccounts * me_gwibber_accounts; |
| 65 | int status; |
| 66 | gboolean has_configured_accounts; |
| 67 | }; |
| 68 | @@ -54,35 +45,35 @@ |
| 69 | static guint signals[LAST_SIGNAL] = { 0 }; |
| 70 | |
| 71 | /* Prototypes */ |
| 72 | -static void gwibber_service_class_init (GwibberServiceClass *klass); |
| 73 | -static void gwibber_service_init (GwibberService *self); |
| 74 | -static void gwibber_service_dispose (GObject *object); |
| 75 | -static void gwibber_service_finalize (GObject *object); |
| 76 | - |
| 77 | -static void dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, GwibberService * self); |
| 78 | -static void gwibber_exists_cb (DBusGProxy * proxy, gboolean exists, GError * error, gpointer userdata); |
| 79 | -static void setup_service_proxies (GwibberService *self); |
| 80 | -static void query_account_manager (GwibberService *self); |
| 81 | - |
| 82 | -G_DEFINE_TYPE (GwibberService, gwibber_service, G_TYPE_OBJECT); |
| 83 | - |
| 84 | -#define GWIBBER_SERVICE_GET_PRIVATE(o) \ |
| 85 | -(G_TYPE_INSTANCE_GET_PRIVATE ((o), GWIBBER_SERVICE_TYPE, GwibberServicePrivate)) |
| 86 | +static void me_gwibber_service_class_init (MeGwibberServiceClass *klass); |
| 87 | +static void me_gwibber_service_init (MeGwibberService *self); |
| 88 | +static void me_gwibber_service_dispose (GObject *object); |
| 89 | +static void me_gwibber_service_finalize (GObject *object); |
| 90 | + |
| 91 | +static void me_gwibber_service_exists_cb (GwibberService * me_gwibber_service, gboolean exists, gpointer userdata); |
| 92 | +static void me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata); |
| 93 | +static void setup_service_proxies (MeGwibberService *self); |
| 94 | +static void query_account_manager (MeGwibberService *self); |
| 95 | + |
| 96 | +G_DEFINE_TYPE (MeGwibberService, me_gwibber_service, G_TYPE_OBJECT); |
| 97 | + |
| 98 | +#define ME_GWIBBER_SERVICE_GET_PRIVATE(o) \ |
| 99 | +(G_TYPE_INSTANCE_GET_PRIVATE ((o), ME_GWIBBER_SERVICE_TYPE, MeGwibberServicePrivate)) |
| 100 | |
| 101 | static void |
| 102 | -gwibber_service_class_init (GwibberServiceClass *klass) |
| 103 | +me_gwibber_service_class_init (MeGwibberServiceClass *klass) |
| 104 | { |
| 105 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 106 | |
| 107 | - g_type_class_add_private (klass, sizeof (GwibberServicePrivate)); |
| 108 | - |
| 109 | - object_class->dispose = gwibber_service_dispose; |
| 110 | - object_class->finalize = gwibber_service_finalize; |
| 111 | - |
| 112 | - signals[STATUS_CHANGED] = g_signal_new(GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, |
| 113 | + g_type_class_add_private (klass, sizeof (MeGwibberServicePrivate)); |
| 114 | + |
| 115 | + object_class->dispose = me_gwibber_service_dispose; |
| 116 | + object_class->finalize = me_gwibber_service_finalize; |
| 117 | + |
| 118 | + signals[STATUS_CHANGED] = g_signal_new(ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, |
| 119 | G_TYPE_FROM_CLASS(klass), |
| 120 | G_SIGNAL_RUN_LAST, |
| 121 | - G_STRUCT_OFFSET(GwibberServiceClass, status_changed), |
| 122 | + G_STRUCT_OFFSET(MeGwibberServiceClass, status_changed), |
| 123 | NULL, NULL, |
| 124 | g_cclosure_marshal_VOID__UINT, |
| 125 | G_TYPE_NONE, 1, G_TYPE_UINT); |
| 126 | @@ -90,316 +81,222 @@ |
| 127 | } |
| 128 | |
| 129 | static void |
| 130 | -gwibber_service_init (GwibberService *self) |
| 131 | -{ |
| 132 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 133 | - |
| 134 | - priv->dbus_proxy = NULL; |
| 135 | - priv->service_proxy = NULL; |
| 136 | - priv->accounts_proxy = NULL; |
| 137 | - priv->status = GWIBBER_SERVICE_STATUS_NOT_RUNNING; |
| 138 | - priv->has_configured_accounts = FALSE; |
| 139 | - |
| 140 | - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
| 141 | - g_return_if_fail(bus != NULL); /* Can't do anymore DBus stuff without this, |
| 142 | - all non-DBus stuff should be done */ |
| 143 | - |
| 144 | - GError * error = NULL; |
| 145 | - |
| 146 | - /* Set up the dbus Proxy */ |
| 147 | - priv->dbus_proxy = dbus_g_proxy_new_for_name_owner (bus, |
| 148 | - DBUS_SERVICE_DBUS, |
| 149 | - DBUS_PATH_DBUS, |
| 150 | - DBUS_INTERFACE_DBUS, |
| 151 | - &error); |
| 152 | - if (error != NULL) { |
| 153 | - g_warning("Unable to connect to DBus events: %s", error->message); |
| 154 | - g_error_free(error); |
| 155 | - return; |
| 156 | - } |
| 157 | - |
| 158 | - /* Configure the name owner changing */ |
| 159 | - dbus_g_proxy_add_signal(priv->dbus_proxy, "NameOwnerChanged", |
| 160 | - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
| 161 | - G_TYPE_INVALID); |
| 162 | - dbus_g_proxy_connect_signal(priv->dbus_proxy, "NameOwnerChanged", |
| 163 | - G_CALLBACK(dbus_namechange), |
| 164 | - self, NULL); |
| 165 | - |
| 166 | - org_freedesktop_DBus_name_has_owner_async(priv->dbus_proxy, DBUS_SERVICE_ADDRESS, gwibber_exists_cb, self); |
| 167 | - |
| 168 | - return; |
| 169 | -} |
| 170 | - |
| 171 | -static void |
| 172 | -gwibber_service_dispose (GObject *object) |
| 173 | -{ |
| 174 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(object); |
| 175 | - |
| 176 | - if (priv->dbus_proxy != NULL) { |
| 177 | - g_object_unref(priv->dbus_proxy); |
| 178 | - priv->dbus_proxy = NULL; |
| 179 | - } |
| 180 | - |
| 181 | - if (priv->service_proxy != NULL) { |
| 182 | - g_object_unref(priv->service_proxy); |
| 183 | - priv->service_proxy = NULL; |
| 184 | - } |
| 185 | - |
| 186 | - if (priv->accounts_proxy != NULL) { |
| 187 | - g_object_unref(priv->accounts_proxy); |
| 188 | - priv->accounts_proxy = NULL; |
| 189 | - } |
| 190 | - |
| 191 | - G_OBJECT_CLASS (gwibber_service_parent_class)->dispose (object); |
| 192 | - return; |
| 193 | -} |
| 194 | - |
| 195 | -static void |
| 196 | -gwibber_service_finalize (GObject *object) |
| 197 | -{ |
| 198 | - G_OBJECT_CLASS (gwibber_service_parent_class)->finalize (object); |
| 199 | - return; |
| 200 | -} |
| 201 | - |
| 202 | - |
| 203 | -/* Watch for Gwibber coming on and off the bus. */ |
| 204 | -static void |
| 205 | -dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, GwibberService * self) |
| 206 | -{ |
| 207 | - g_return_if_fail (IS_GWIBBER_SERVICE (self)); |
| 208 | - |
| 209 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 210 | - |
| 211 | - if (prev[0] == '\0' && g_strcmp0(name, DBUS_SERVICE_ADDRESS) == 0) { |
| 212 | - g_debug("Gwibber Service coming online"); |
| 213 | - priv->status = GWIBBER_SERVICE_STATUS_RUNNING; |
| 214 | - if (priv->service_proxy == NULL || |
| 215 | - priv->accounts_proxy == NULL) |
| 216 | - setup_service_proxies (self); |
| 217 | - query_account_manager (self); |
| 218 | - } |
| 219 | - |
| 220 | - if (new[0] == '\0' && g_strcmp0(name, DBUS_SERVICE_ADDRESS) == 0) { |
| 221 | - g_debug("Gwibber Service going offline"); |
| 222 | - priv->status = GWIBBER_SERVICE_STATUS_NOT_RUNNING; |
| 223 | - g_signal_emit (G_OBJECT (self), GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, 0, priv->status, TRUE); |
| 224 | - if (priv->service_proxy != NULL) { |
| 225 | - g_object_unref(priv->service_proxy); |
| 226 | - priv->service_proxy = NULL; |
| 227 | - } |
| 228 | - if (priv->accounts_proxy != NULL) { |
| 229 | - g_object_unref(priv->accounts_proxy); |
| 230 | - priv->accounts_proxy = NULL; |
| 231 | - } |
| 232 | - } |
| 233 | - |
| 234 | - return; |
| 235 | -} |
| 236 | - |
| 237 | -static void |
| 238 | -get_accounts_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
| 239 | -{ |
| 240 | - GError *error = NULL; |
| 241 | - gchar *accounts_string = NULL; |
| 242 | - |
| 243 | - dbus_g_proxy_end_call (proxy, call, &error, |
| 244 | - G_TYPE_STRING, &accounts_string, |
| 245 | - G_TYPE_INVALID); |
| 246 | - |
| 247 | - if (error != NULL) { |
| 248 | - g_warning ("GetAccounts: %s", error->message); |
| 249 | - g_error_free (error); |
| 250 | - g_free (accounts_string); |
| 251 | - return; |
| 252 | - } |
| 253 | - |
| 254 | - /* don't print the accounts string, it contains passwords */ |
| 255 | - /* g_debug ("GetAccounts: %s", accounts_string); */ |
| 256 | - |
| 257 | - g_return_if_fail (IS_GWIBBER_SERVICE (data)); |
| 258 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(data); |
| 259 | - g_return_if_fail (priv != NULL); |
| 260 | - /* Note: not free'ing accounts_string here, but g_return_if_fail are |
| 261 | - meant to catch design errors, not runtime ones */ |
| 262 | - |
| 263 | - priv->status = GWIBBER_SERVICE_STATUS_RUNNING; |
| 264 | - priv->has_configured_accounts = g_strrstr (accounts_string, " \"send_enabled\": true,") ? TRUE : FALSE; |
| 265 | - |
| 266 | - /* trigger a status update */ |
| 267 | - g_signal_emit (G_OBJECT (data), |
| 268 | - GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, |
| 269 | +me_gwibber_service_init (MeGwibberService *self) |
| 270 | +{ |
| 271 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
| 272 | + |
| 273 | + priv->me_gwibber_service = NULL; |
| 274 | + priv->me_gwibber_accounts = NULL; |
| 275 | + priv->status = ME_GWIBBER_SERVICE_STATUS_NOT_RUNNING; |
| 276 | + priv->has_configured_accounts = FALSE; |
| 277 | + |
| 278 | + setup_service_proxies(self); |
| 279 | + return; |
| 280 | +} |
| 281 | + |
| 282 | +static void |
| 283 | +me_gwibber_service_dispose (GObject *object) |
| 284 | +{ |
| 285 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(object); |
| 286 | + |
| 287 | + if (priv->me_gwibber_service != NULL) { |
| 288 | + g_object_unref(priv->me_gwibber_service); |
| 289 | + priv->me_gwibber_service = NULL; |
| 290 | + } |
| 291 | + |
| 292 | + if (priv->me_gwibber_accounts != NULL) { |
| 293 | + g_object_unref(priv->me_gwibber_accounts); |
| 294 | + priv->me_gwibber_accounts = NULL; |
| 295 | + } |
| 296 | + |
| 297 | + G_OBJECT_CLASS (me_gwibber_service_parent_class)->dispose (object); |
| 298 | + return; |
| 299 | +} |
| 300 | + |
| 301 | +static void |
| 302 | +me_gwibber_service_finalize (GObject *object) |
| 303 | +{ |
| 304 | + G_OBJECT_CLASS (me_gwibber_service_parent_class)->finalize (object); |
| 305 | + return; |
| 306 | +} |
| 307 | + |
| 308 | +static gboolean |
| 309 | +check_account_send_enabled (GHashTable * account_table) { |
| 310 | + return g_value_get_boolean(g_hash_table_lookup(account_table, "send_enabled")); |
| 311 | +} |
| 312 | + |
| 313 | +static void |
| 314 | +query_account_manager (MeGwibberService *self) |
| 315 | +{ |
| 316 | + g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
| 317 | + |
| 318 | + gpointer accounts_table; |
| 319 | + gpointer account_table; |
| 320 | + GHashTableIter accounts_iter; |
| 321 | + gpointer account; |
| 322 | + gboolean send_enabled; |
| 323 | + |
| 324 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
| 325 | + |
| 326 | + if (priv->me_gwibber_accounts == NULL) { |
| 327 | + g_warning ("no accounts, can't query for accounts"); |
| 328 | + return; |
| 329 | + } |
| 330 | + |
| 331 | + accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts); |
| 332 | + if (accounts_table == NULL) { |
| 333 | + g_warning ("failed to get accounts list"); |
| 334 | + return; |
| 335 | + } |
| 336 | + |
| 337 | + g_hash_table_iter_init (&accounts_iter, accounts_table); |
| 338 | + |
| 339 | + priv->has_configured_accounts = FALSE; |
| 340 | + |
| 341 | + while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) { |
| 342 | + send_enabled = check_account_send_enabled (account_table); |
| 343 | + if (send_enabled) { |
| 344 | + priv->has_configured_accounts = TRUE; |
| 345 | + } |
| 346 | + } |
| 347 | + |
| 348 | + g_signal_emit (G_OBJECT (self), |
| 349 | + ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, |
| 350 | 0, priv->status, TRUE); |
| 351 | |
| 352 | - g_free (accounts_string); |
| 353 | - |
| 354 | + g_hash_table_destroy(accounts_table); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | static void |
| 359 | -query_account_manager (GwibberService *self) |
| 360 | -{ |
| 361 | - g_return_if_fail (IS_GWIBBER_SERVICE (self)); |
| 362 | - |
| 363 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 364 | - |
| 365 | - if (priv->service_proxy == NULL) { |
| 366 | - g_warning ("no service_proxy, can't query for accounts"); |
| 367 | - return; |
| 368 | - } |
| 369 | - |
| 370 | - dbus_g_proxy_begin_call(priv->service_proxy, |
| 371 | - "GetAccounts", |
| 372 | - get_accounts_response, |
| 373 | - self, |
| 374 | - NULL, |
| 375 | - G_TYPE_INVALID); |
| 376 | -} |
| 377 | - |
| 378 | -static void |
| 379 | -accounts_changed (DBusGProxy *proxy, const gchar *id, GwibberService *self) |
| 380 | -{ |
| 381 | - g_return_if_fail (IS_GWIBBER_SERVICE (self)); |
| 382 | - |
| 383 | - g_debug ("accounts_changed"); |
| 384 | +accounts_changed (GwibberAccounts *me_gwibber_accounts, GHashTable *account_table, MeGwibberService *self) |
| 385 | +{ |
| 386 | + g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
| 387 | |
| 388 | query_account_manager (self); |
| 389 | |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | -static void |
| 394 | -setup_service_proxies (GwibberService *self) |
| 395 | -{ |
| 396 | - g_return_if_fail (IS_GWIBBER_SERVICE (self)); |
| 397 | - |
| 398 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 399 | - |
| 400 | - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
| 401 | - g_return_if_fail(bus != NULL); /* Can't do anymore DBus stuff without this, |
| 402 | - all non-DBus stuff should be done */ |
| 403 | - |
| 404 | - if (priv->service_proxy == NULL) { |
| 405 | - priv->service_proxy = dbus_g_proxy_new_for_name( |
| 406 | - bus, |
| 407 | - DBUS_SERVICE_ADDRESS, |
| 408 | - DBUS_SERVICE_SERVICE_OBJECT, |
| 409 | - DBUS_SERVICE_SERVICE_INTERFACE); |
| 410 | - if (priv->service_proxy == NULL) { |
| 411 | - g_warning ("can't setup service_proxy"); |
| 412 | - return; |
| 413 | - } |
| 414 | - } |
| 415 | - |
| 416 | - if (priv->accounts_proxy == NULL) { |
| 417 | - priv->accounts_proxy = |
| 418 | - dbus_g_proxy_new_for_name(bus, |
| 419 | - DBUS_SERVICE_ADDRESS, |
| 420 | - DBUS_SERVICE_ACCOUNTS_OBJECT, |
| 421 | - DBUS_SERVICE_ACCOUNTS_INTERFACE); |
| 422 | - if (priv->accounts_proxy == NULL) { |
| 423 | - g_warning ("can't setup accounts_proxy"); |
| 424 | - return; |
| 425 | - } |
| 426 | - } |
| 427 | - |
| 428 | - /* Monitor signals about account changes */ |
| 429 | - dbus_g_proxy_add_signal(priv->accounts_proxy, "AccountChanged", |
| 430 | - G_TYPE_STRING, |
| 431 | - G_TYPE_INVALID); |
| 432 | - dbus_g_proxy_connect_signal(priv->accounts_proxy, "AccountChanged", |
| 433 | - G_CALLBACK(accounts_changed), |
| 434 | - self, NULL); |
| 435 | - dbus_g_proxy_add_signal(priv->accounts_proxy, "AccountDeleted", |
| 436 | - G_TYPE_STRING, |
| 437 | - G_TYPE_INVALID); |
| 438 | - dbus_g_proxy_connect_signal(priv->accounts_proxy, "AccountDeleted", |
| 439 | - G_CALLBACK(accounts_changed), |
| 440 | - self, NULL); |
| 441 | - |
| 442 | -} |
| 443 | - |
| 444 | -static void |
| 445 | -gwibber_exists_cb (DBusGProxy * proxy, gboolean exists, GError * error, gpointer userdata) |
| 446 | -{ |
| 447 | - if (error) { |
| 448 | - g_warning ("Unable to check if Gwibber is running: %s", error->message); |
| 449 | - return; |
| 450 | - } |
| 451 | - |
| 452 | - if (exists) { |
| 453 | - setup_service_proxies (GWIBBER_SERVICE (userdata)); |
| 454 | - query_account_manager (GWIBBER_SERVICE (userdata)); |
| 455 | - } |
| 456 | - |
| 457 | - return; |
| 458 | -} |
| 459 | - |
| 460 | -GwibberService * gwibber_service_new (void){ |
| 461 | - return GWIBBER_SERVICE (g_object_new (GWIBBER_SERVICE_TYPE, NULL)); |
| 462 | -} |
| 463 | - |
| 464 | -static void |
| 465 | -send_message_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
| 466 | -{ |
| 467 | - g_debug ("send_message_response"); |
| 468 | - |
| 469 | - return; |
| 470 | + |
| 471 | +static void |
| 472 | +setup_service_proxies (MeGwibberService *self) |
| 473 | +{ |
| 474 | + g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
| 475 | + |
| 476 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
| 477 | + |
| 478 | + if (priv->me_gwibber_service == NULL) { |
| 479 | + priv->me_gwibber_service = gwibber_service_new (); |
| 480 | + if (priv->me_gwibber_service == NULL) { |
| 481 | + g_warning ("can't setup me_gwibber_service"); |
| 482 | + return; |
| 483 | + } |
| 484 | + } |
| 485 | + |
| 486 | + g_signal_connect (priv->me_gwibber_service, "is-available", |
| 487 | + G_CALLBACK(me_gwibber_service_exists_cb), ME_GWIBBER_SERVICE (self)); |
| 488 | + |
| 489 | + if (priv->me_gwibber_accounts == NULL) { |
| 490 | + priv->me_gwibber_accounts = gwibber_accounts_new ();; |
| 491 | + if (priv->me_gwibber_accounts == NULL) { |
| 492 | + g_warning ("can't setup me_gwibber_accounts"); |
| 493 | + return; |
| 494 | + } |
| 495 | + } |
| 496 | + |
| 497 | + g_signal_connect (priv->me_gwibber_accounts, "is-available", |
| 498 | + G_CALLBACK(me_gwibber_accounts_exists_cb), ME_GWIBBER_SERVICE (self)); |
| 499 | +} |
| 500 | + |
| 501 | +static void |
| 502 | +me_gwibber_service_exists_cb (GwibberService * me_gwibber_service, gboolean exists, gpointer userdata) |
| 503 | +{ |
| 504 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata)); |
| 505 | + |
| 506 | + if (exists) { |
| 507 | + priv->status = ME_GWIBBER_SERVICE_STATUS_RUNNING; |
| 508 | + } |
| 509 | + |
| 510 | + |
| 511 | + if (!exists) { |
| 512 | + priv->status = ME_GWIBBER_SERVICE_STATUS_NOT_RUNNING; |
| 513 | + g_signal_emit (G_OBJECT (ME_GWIBBER_SERVICE (userdata)), ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, 0, priv->status, TRUE); |
| 514 | + } |
| 515 | + return; |
| 516 | +} |
| 517 | + |
| 518 | +static void |
| 519 | +me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata) |
| 520 | +{ |
| 521 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata)); |
| 522 | + |
| 523 | + if (exists) { |
| 524 | + if (priv->me_gwibber_accounts == NULL) { |
| 525 | + priv->me_gwibber_accounts = gwibber_accounts_new ();; |
| 526 | + if (priv->me_gwibber_accounts == NULL) { |
| 527 | + g_warning ("can't setup me_gwibber_accounts"); |
| 528 | + return; |
| 529 | + } |
| 530 | + } |
| 531 | + |
| 532 | + query_account_manager (ME_GWIBBER_SERVICE (userdata)); |
| 533 | + g_signal_emit (G_OBJECT (ME_GWIBBER_SERVICE (userdata)), ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, 0, priv->status, TRUE); |
| 534 | + g_signal_connect (priv->me_gwibber_accounts, "account-updated", |
| 535 | + G_CALLBACK(accounts_changed), ME_GWIBBER_SERVICE (userdata)); |
| 536 | + } |
| 537 | + return; |
| 538 | +} |
| 539 | + |
| 540 | + |
| 541 | +MeGwibberService * me_gwibber_service_new (void){ |
| 542 | + return ME_GWIBBER_SERVICE (g_object_new (ME_GWIBBER_SERVICE_TYPE, NULL)); |
| 543 | } |
| 544 | |
| 545 | void |
| 546 | -gwibber_service_send (GwibberService *self, const gchar *msg) |
| 547 | +me_gwibber_service_send (MeGwibberService *self, const gchar *msg) |
| 548 | { |
| 549 | - g_return_if_fail (IS_GWIBBER_SERVICE (self)); |
| 550 | + g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
| 551 | |
| 552 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 553 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
| 554 | |
| 555 | GValue value = {0}; |
| 556 | g_value_init(&value, G_TYPE_STRING); |
| 557 | g_value_set_string(&value, msg); |
| 558 | |
| 559 | - g_debug ("gwibber_send: %s\n", msg); |
| 560 | - |
| 561 | - if (priv->service_proxy == NULL) { |
| 562 | + if (priv->me_gwibber_service == NULL) { |
| 563 | setup_service_proxies (self); |
| 564 | - if (priv->service_proxy == NULL) { |
| 565 | - g_warning ("can't setup service_proxy"); |
| 566 | + if (priv->me_gwibber_service == NULL) { |
| 567 | + g_warning ("can't setup me_gwibber_service"); |
| 568 | return; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | - dbus_g_proxy_begin_call(priv->service_proxy, |
| 573 | - "SendMessage", |
| 574 | - send_message_response, |
| 575 | - NULL, |
| 576 | - NULL, |
| 577 | - G_TYPE_VALUE, |
| 578 | - &value, |
| 579 | - G_TYPE_INVALID); |
| 580 | + gwibber_service_send_message (priv->me_gwibber_service, g_value_get_string (&value)); |
| 581 | |
| 582 | g_value_unset(&value); |
| 583 | |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | -GwibberService * |
| 588 | -gwibber_service_get (void) |
| 589 | +MeGwibberService * |
| 590 | +me_gwibber_service_get (void) |
| 591 | { |
| 592 | - static GwibberService *singleton = NULL; |
| 593 | + static MeGwibberService *singleton = NULL; |
| 594 | |
| 595 | if (! singleton) { |
| 596 | - singleton = gwibber_service_new (); |
| 597 | + singleton = me_gwibber_service_new (); |
| 598 | } |
| 599 | |
| 600 | return singleton; |
| 601 | } |
| 602 | |
| 603 | gboolean |
| 604 | -gwibber_service_has_configured_accounts (GwibberService *self) |
| 605 | +me_gwibber_service_has_configured_accounts (MeGwibberService *self) |
| 606 | { |
| 607 | - g_return_val_if_fail (IS_GWIBBER_SERVICE (self), FALSE); |
| 608 | + g_return_val_if_fail (IS_ME_GWIBBER_SERVICE (self), FALSE); |
| 609 | |
| 610 | - GwibberServicePrivate * priv = GWIBBER_SERVICE_GET_PRIVATE(self); |
| 611 | + MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
| 612 | |
| 613 | return priv->has_configured_accounts; |
| 614 | } |
| 615 | |
| 616 | === modified file 'src/me-service-gwibber.h' |
| 617 | --- src/me-service-gwibber.h 2010-03-17 16:19:44 +0000 |
| 618 | +++ src/me-service-gwibber.h 2010-08-17 14:44:43 +0000 |
| 619 | @@ -20,57 +20,56 @@ |
| 620 | with this program. If not, see <http://www.gnu.org/licenses/>. |
| 621 | */ |
| 622 | |
| 623 | -#ifndef __GWIBBER_SERVICE_H__ |
| 624 | -#define __GWIBBER_SERVICE_H__ |
| 625 | +#ifndef __ME_GWIBBER_SERVICE_H__ |
| 626 | +#define __ME_GWIBBER_SERVICE_H__ |
| 627 | |
| 628 | #include <glib.h> |
| 629 | #include <glib-object.h> |
| 630 | |
| 631 | +#include <gwibber.h> |
| 632 | + |
| 633 | G_BEGIN_DECLS |
| 634 | |
| 635 | -#define GWIBBER_SERVICE_TYPE (gwibber_service_get_type ()) |
| 636 | -#define GWIBBER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GWIBBER_SERVICE_TYPE, GwibberService)) |
| 637 | -#define GWIBBER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GWIBBER_SERVICE_TYPE, GwibberServiceClass)) |
| 638 | -#define IS_GWIBBER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GWIBBER_SERVICE_TYPE)) |
| 639 | -#define IS_GWIBBER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GWIBBER_SERVICE_TYPE)) |
| 640 | -#define GWIBBER_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GWIBBER_SERVICE_TYPE, GwibberServiceClass)) |
| 641 | +#define ME_GWIBBER_SERVICE_TYPE (me_gwibber_service_get_type ()) |
| 642 | +#define ME_GWIBBER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ME_GWIBBER_SERVICE_TYPE, MeGwibberService)) |
| 643 | +#define ME_GWIBBER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ME_GWIBBER_SERVICE_TYPE, MeGwibberServiceClass)) |
| 644 | +#define IS_ME_GWIBBER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ME_GWIBBER_SERVICE_TYPE)) |
| 645 | +#define IS_ME_GWIBBER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ME_GWIBBER_SERVICE_TYPE)) |
| 646 | +#define ME_GWIBBER_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ME_GWIBBER_SERVICE_TYPE, MeGwibberServiceClass)) |
| 647 | |
| 648 | typedef enum |
| 649 | { |
| 650 | - GWIBBER_SERVICE_STATUS_NOT_RUNNING, |
| 651 | - /* GWIBBER_SERVICE_STATUS_LOADING_STARTED, |
| 652 | - GWIBBER_SERVICE_STATUS_LOADING_COMPLETE, */ |
| 653 | - GWIBBER_SERVICE_STATUS_RUNNING, |
| 654 | - GWIBBER_SERVICE_STATUS_LAST |
| 655 | + ME_GWIBBER_SERVICE_STATUS_NOT_RUNNING, |
| 656 | + /* ME_GWIBBER_SERVICE_STATUS_LOADING_STARTED, |
| 657 | + ME_GWIBBER_SERVICE_STATUS_LOADING_COMPLETE, */ |
| 658 | + ME_GWIBBER_SERVICE_STATUS_RUNNING, |
| 659 | + ME_GWIBBER_SERVICE_STATUS_LAST |
| 660 | } |
| 661 | -GwibberServiceStatus; |
| 662 | - |
| 663 | -#define GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED "status-changed" |
| 664 | -#define GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID (g_signal_lookup(GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, GWIBBER_SERVICE_TYPE)) |
| 665 | - |
| 666 | -typedef struct _GwibberServiceClass GwibberServiceClass; |
| 667 | -struct _GwibberServiceClass { |
| 668 | +MeGwibberServiceStatus; |
| 669 | + |
| 670 | +#define ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED "status-changed" |
| 671 | +#define ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID (g_signal_lookup(ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, ME_GWIBBER_SERVICE_TYPE)) |
| 672 | + |
| 673 | +typedef struct _MeGwibberServiceClass MeGwibberServiceClass; |
| 674 | +struct _MeGwibberServiceClass { |
| 675 | GObjectClass parent_class; |
| 676 | |
| 677 | /* Signals */ |
| 678 | - void (*status_changed) (GwibberServiceStatus newstatus); |
| 679 | + void (*status_changed) (MeGwibberServiceStatus newstatus); |
| 680 | }; |
| 681 | |
| 682 | -typedef struct _GwibberService GwibberService; |
| 683 | -struct _GwibberService { |
| 684 | +typedef struct _MeGwibberService MeGwibberService; |
| 685 | +struct _MeGwibberService { |
| 686 | GObject parent; |
| 687 | }; |
| 688 | |
| 689 | -GType gwibber_service_get_type (void) G_GNUC_CONST; |
| 690 | -GwibberService * gwibber_service_new (void); |
| 691 | -GwibberService * gwibber_service_get (void); |
| 692 | -void gwibber_service_send (GwibberService *self, const gchar *msg); |
| 693 | -gboolean gwibber_service_has_configured_accounts (GwibberService *self); |
| 694 | - |
| 695 | -/* old API */ |
| 696 | -void gwibber_send (const gchar *msg); |
| 697 | +GType me_gwibber_service_get_type (void) G_GNUC_CONST; |
| 698 | +MeGwibberService * me_gwibber_service_new (void); |
| 699 | +MeGwibberService * me_gwibber_service_get (void); |
| 700 | +void me_gwibber_service_send (MeGwibberService *self, const gchar *msg); |
| 701 | +gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self); |
| 702 | |
| 703 | G_END_DECLS |
| 704 | |
| 705 | -#endif /* __GWIBBER_SERVICE_H__ */ |
| 706 | +#endif /* __ME_GWIBBER_SERVICE_H__ */ |
| 707 | |
| 708 | |
| 709 | === modified file 'src/me-service.c' |
| 710 | --- src/me-service.c 2010-03-25 20:25:31 +0000 |
| 711 | +++ src/me-service.c 2010-08-17 14:44:43 +0000 |
| 712 | @@ -81,7 +81,7 @@ |
| 713 | /* STATUS_PROVIDER_STATUS_DISCONNECTED */"user-offline" |
| 714 | }; |
| 715 | |
| 716 | -static GwibberService * gwibber = NULL; |
| 717 | +static MeGwibberService * me_gwibber_service = NULL; |
| 718 | |
| 719 | static DbusmenuMenuitem * root_menuitem = NULL; |
| 720 | static DbusmenuMenuitem * status_menuitems[STATUS_PROVIDER_STATUS_LAST] = {0}; |
| 721 | @@ -170,7 +170,7 @@ |
| 722 | } |
| 723 | |
| 724 | static void |
| 725 | -gwibber_status_update (GwibberService *instance, GwibberServiceStatus status, gpointer data) { |
| 726 | +me_gwibber_status_update (MeGwibberService *instance, MeGwibberServiceStatus status, gpointer data) { |
| 727 | g_return_if_fail (instance != NULL); |
| 728 | |
| 729 | g_debug ("gwibber service status changed to: %d", status); |
| 730 | @@ -180,7 +180,7 @@ |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | - if (! gwibber_service_has_configured_accounts (instance)) { |
| 735 | + if (! me_gwibber_service_has_configured_accounts (instance)) { |
| 736 | g_debug ("no configured accounts detected, so hiding the broadcast field"); |
| 737 | dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); |
| 738 | return; |
| 739 | @@ -189,16 +189,6 @@ |
| 740 | if (! dbusmenu_menuitem_property_get_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE)) |
| 741 | dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); |
| 742 | |
| 743 | -#if 0 |
| 744 | - if (status == GWIBBER_SERVICE_STATUS_RUNNING) { |
| 745 | - g_debug ("enabling the broadcast field"); |
| 746 | - dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); |
| 747 | - } else { |
| 748 | - g_debug ("disabling the broadcast field"); |
| 749 | - dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); |
| 750 | - } |
| 751 | -#endif |
| 752 | - |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | @@ -287,9 +277,9 @@ |
| 757 | |
| 758 | status_update(); |
| 759 | |
| 760 | - gwibber = gwibber_service_new (); |
| 761 | - if (gwibber != NULL) { |
| 762 | - g_signal_connect (G_OBJECT (gwibber), GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, G_CALLBACK (gwibber_status_update), NULL); |
| 763 | + me_gwibber_service = me_gwibber_service_get (); |
| 764 | + if (me_gwibber_service != NULL) { |
| 765 | + g_signal_connect (G_OBJECT (me_gwibber_service), ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED, G_CALLBACK (me_gwibber_status_update), NULL); |
| 766 | } |
| 767 | |
| 768 | return FALSE; |

Sounds good to me and works well on my test build. There are a few changes required though:
Line 343: the test for priv->send_enabled should probably be removed, ie toggling the boolean to true on each loop iteration; what matters is the end result
Line 350: the STATUS_RUNNING flag should be set in all cases, as a reply from gwibber implies that it is available for sending messages; the state name is a bit misleading though, it should be more about gwibber being "available" as a gateway service, but I chose running to make the distinction with the "availability" status of other online/chat services
Line 545: not sure about the void if (!exists), i don't think there is anything particular to do in this case either
Line 625: has_configured_ accounts should return a positive value even if the service is temporarily down, ie a send would restart it anyway; i found it difficult to understand as a user that the entry is "sometimes" not there, for no apparent reason; it's better to have it always there, whatever the state of the service; the visibility criteria is only that gwibber is "configured".