diff options
author | Cody Russell <crussell@canonical.com> | 2009-09-23 17:48:38 -0500 |
---|---|---|
committer | Cody Russell <crussell@canonical.com> | 2009-09-23 17:48:38 -0500 |
commit | 9a6f594c7f63158a7b93adff62b1f9c62aed967f (patch) | |
tree | 0eedcea34e6c8397cd46ea078db65b17e9be382b /src/status-provider-telepathy.c | |
parent | 3de7117e82eb5d0b39fd17532852f27dcd555dfe (diff) | |
parent | 9703540eaf33ac50e99f04e9eddf5816557868e1 (diff) | |
download | ayatana-indicator-session-9a6f594c7f63158a7b93adff62b1f9c62aed967f.tar.gz ayatana-indicator-session-9a6f594c7f63158a7b93adff62b1f9c62aed967f.tar.bz2 ayatana-indicator-session-9a6f594c7f63158a7b93adff62b1f9c62aed967f.zip |
merge up from trunk
Diffstat (limited to 'src/status-provider-telepathy.c')
-rw-r--r-- | src/status-provider-telepathy.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index e22c27d..f2815fb 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -55,12 +55,14 @@ static mc_status_t sp_to_mc_map[] = { /* STATUS_PROVIDER_STATUS_AWAY, */ MC_STATUS_AWAY, /* STATUS_PROVIDER_STATUS_DND */ MC_STATUS_DND, /* STATUS_PROVIDER_STATUS_INVISIBLE*/ MC_STATUS_HIDDEN, - /* STATUS_PROVIDER_STATUS_OFFLINE */ MC_STATUS_OFFLINE + /* STATUS_PROVIDER_STATUS_OFFLINE */ MC_STATUS_OFFLINE, + /* STATUS_PROVIDER_STATUS_DISCONNECTED*/MC_STATUS_OFFLINE }; typedef struct _StatusProviderTelepathyPrivate StatusProviderTelepathyPrivate; struct _StatusProviderTelepathyPrivate { DBusGProxy * proxy; + DBusGProxy * dbus_proxy; mc_status_t mc_status; }; @@ -74,6 +76,8 @@ static void status_provider_telepathy_init (StatusProviderTelepathy *self) static void status_provider_telepathy_dispose (GObject *object); static void status_provider_telepathy_finalize (GObject *object); /* Internal Funcs */ +static void build_telepathy_proxy (StatusProviderTelepathy * self); +static void dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, StatusProviderTelepathy * self); static void set_status (StatusProvider * sp, StatusProviderStatus status); static StatusProviderStatus get_status (StatusProvider * sp); static void changed_status (DBusGProxy * proxy, guint status, gchar * message, StatusProvider * sp); @@ -107,10 +111,61 @@ status_provider_telepathy_init (StatusProviderTelepathy *self) StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(self); priv->proxy = NULL; + priv->dbus_proxy = NULL; priv->mc_status = MC_STATUS_OFFLINE; GError * error = NULL; + /* Grabbing the session bus */ + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (bus == NULL) { + g_warning("Unable to connect to Session Bus: %s", error == NULL ? "No message" : error->message); + g_error_free(error); + return; + } + + /* Set up the dbus Proxy */ + priv->dbus_proxy = dbus_g_proxy_new_for_name_owner (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_warning("Unable to connect to DBus events: %s", error->message); + g_error_free(error); + return; + } + + /* Configure the name owner changing */ + dbus_g_proxy_add_signal(priv->dbus_proxy, "NameOwnerChanged", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(priv->dbus_proxy, "NameOwnerChanged", + G_CALLBACK(dbus_namechange), + self, NULL); + + build_telepathy_proxy(self); + + return; +} + +/* Builds up the proxy to Mission Control and configures all of the + signals for getting info from the proxy. Also does a call to get + the inital value of the status. */ +static void +build_telepathy_proxy (StatusProviderTelepathy * self) +{ + g_debug("Building Telepathy Proxy"); + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(self); + + if (priv->proxy != NULL) { + g_debug("Hmm, being asked to build a proxy we alredy have."); + return; + } + + GError * error = NULL; + + /* Grabbing the session bus */ DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (session_bus == NULL) { g_warning("Unable to connect to Session Bus: %s", error == NULL ? "No message" : error->message); @@ -118,7 +173,7 @@ status_provider_telepathy_init (StatusProviderTelepathy *self) return; } - priv->proxy = NULL; + /* Get the proxy to Mission Control */ priv->proxy = dbus_g_proxy_new_for_name_owner(session_bus, "org.freedesktop.Telepathy.MissionControl", "/org/freedesktop/Telepathy/MissionControl", @@ -126,10 +181,13 @@ status_provider_telepathy_init (StatusProviderTelepathy *self) &error); if (priv->proxy != NULL) { + /* If it goes, we set the proxy to NULL */ g_object_add_weak_pointer (G_OBJECT(priv->proxy), (gpointer *)&priv->proxy); + /* And we clean up other variables associated */ g_signal_connect(G_OBJECT(priv->proxy), "destroy", G_CALLBACK(proxy_destroy), self); + /* Set up the signal handler for watching when status changes. */ dbus_g_object_register_marshaller(_status_provider_telepathy_marshal_VOID__UINT_STRING, G_TYPE_NONE, G_TYPE_UINT, @@ -163,6 +221,19 @@ status_provider_telepathy_init (StatusProviderTelepathy *self) return; } +/* Watch to see if the Mission Control comes up on Dbus */ +static void +dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, StatusProviderTelepathy * self) +{ + g_return_if_fail(name != NULL); + g_return_if_fail(new != NULL); + + if (g_strcmp0(name, "org.freedesktop.Telepathy.MissionControl") == 0) { + build_telepathy_proxy(self); + } + return; +} + static void status_provider_telepathy_dispose (GObject *object) { @@ -258,10 +329,11 @@ set_status (StatusProvider * sp, StatusProviderStatus status) static StatusProviderStatus get_status (StatusProvider * sp) { + g_return_val_if_fail(IS_STATUS_PROVIDER_TELEPATHY(sp), STATUS_PROVIDER_STATUS_DISCONNECTED); StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(sp); if (priv->proxy == NULL) { - return mc_to_sp_map[MC_STATUS_OFFLINE]; + return STATUS_PROVIDER_STATUS_DISCONNECTED; } return mc_to_sp_map[priv->mc_status]; |