From 2ad97fd722286b1e9780c10efc3a87e42a0796c4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Sep 2009 12:24:16 -0500 Subject: Adding disconnected to the telepathy handler. --- src/status-provider-telepathy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/status-provider-telepathy.c') diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index e22c27d..31da224 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -55,7 +55,8 @@ 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; @@ -258,10 +259,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]; -- cgit v1.2.3 From d97e28df45374c687c60529b5e868e2910187571 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Sep 2009 13:52:12 -0500 Subject: Function to build the telepathy proxy. --- src/status-provider-telepathy.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/status-provider-telepathy.c') diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index 31da224..4430a8e 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -75,6 +75,7 @@ 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 set_status (StatusProvider * sp, StatusProviderStatus status); static StatusProviderStatus get_status (StatusProvider * sp); static void changed_status (DBusGProxy * proxy, guint status, gchar * message, StatusProvider * sp); @@ -110,6 +111,16 @@ status_provider_telepathy_init (StatusProviderTelepathy *self) priv->proxy = NULL; priv->mc_status = MC_STATUS_OFFLINE; + build_telepathy_proxy(self); + + return; +} + +static void +build_telepathy_proxy (StatusProviderTelepathy * self) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(self); + GError * error = NULL; DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); -- cgit v1.2.3 From ff14ae64765101fc90581d5b927d68ce2b15297c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Sep 2009 13:58:24 -0500 Subject: Checking to see if we have the proxy already. --- src/status-provider-telepathy.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/status-provider-telepathy.c') diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index 4430a8e..58bc6ca 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -121,8 +121,14 @@ build_telepathy_proxy (StatusProviderTelepathy * self) { 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); @@ -130,7 +136,7 @@ build_telepathy_proxy (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", @@ -138,10 +144,13 @@ build_telepathy_proxy (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, -- cgit v1.2.3 From b93e75aaa4634ac8f995ac3ea7596e3946a59e18 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Sep 2009 14:04:51 -0500 Subject: Watching for Mission Control comming on the bus. --- src/status-provider-telepathy.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/status-provider-telepathy.c') diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index 58bc6ca..f33e26f 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -62,6 +62,7 @@ static mc_status_t sp_to_mc_map[] = { typedef struct _StatusProviderTelepathyPrivate StatusProviderTelepathyPrivate; struct _StatusProviderTelepathyPrivate { DBusGProxy * proxy; + DBusGProxy * dbus_proxy; mc_status_t mc_status; }; @@ -76,6 +77,7 @@ 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); @@ -109,8 +111,39 @@ 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; @@ -184,6 +217,19 @@ build_telepathy_proxy (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) { -- cgit v1.2.3 From a275332bb21be6dab623738366aaeeff6afc7687 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Sep 2009 14:09:43 -0500 Subject: Adding in a debug message for Telepathy proxy. --- src/status-provider-telepathy.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/status-provider-telepathy.c') diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c index f33e26f..f2815fb 100644 --- a/src/status-provider-telepathy.c +++ b/src/status-provider-telepathy.c @@ -149,9 +149,13 @@ status_provider_telepathy_init (StatusProviderTelepathy *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) { -- cgit v1.2.3