aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-10-08 15:01:45 -0400
committerTed Gould <ted@canonical.com>2009-10-08 15:01:45 -0400
commit4799c2910fe5056c2333f65f171fd7e2bf4557fc (patch)
treeadf2a8ebf07b659aff8f1f038c3a775168dcbb38
parent5ff6b510c9be9df8bb30a00e0795af2d9dcc78ae (diff)
parent7c7df5ba849f15cb2772a8370d02506e4fc5f91c (diff)
downloadayatana-indicator-session-4799c2910fe5056c2333f65f171fd7e2bf4557fc.tar.gz
ayatana-indicator-session-4799c2910fe5056c2333f65f171fd7e2bf4557fc.tar.bz2
ayatana-indicator-session-4799c2910fe5056c2333f65f171fd7e2bf4557fc.zip
MC5 Fix testing.
-rw-r--r--debian/changelog6
-rw-r--r--src/status-provider-mc5.c76
-rw-r--r--src/status-provider-mc5.h4
3 files changed, 80 insertions, 6 deletions
diff --git a/debian/changelog b/debian/changelog
index 69924f9..b0a7659 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+indicator-session (0.1.7-0ubuntu1~ppa2~mc5fix1) UNRELEASED; urgency=low
+
+ * MC5 Fix testing.
+
+ -- Ted Gould <ted@ubuntu.com> Thu, 08 Oct 2009 15:01:27 -0400
+
indicator-session (0.1.7-0ubuntu1~ppa1) karmic; urgency=low
* Upstream release 0.1.7
diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c
index 671e459..46d5562 100644
--- a/src/status-provider-mc5.c
+++ b/src/status-provider-mc5.c
@@ -66,6 +66,7 @@ typedef struct _StatusProviderMC5Private StatusProviderMC5Private;
struct _StatusProviderMC5Private {
EmpathyAccountManager * manager;
StatusProviderStatus status;
+ DBusGProxy * dbus_proxy;
};
#define STATUS_PROVIDER_MC5_GET_PRIVATE(o) \
@@ -81,6 +82,7 @@ static void status_provider_mc5_finalize (GObject *object);
static void set_status (StatusProvider * sp, StatusProviderStatus status);
static StatusProviderStatus get_status (StatusProvider * sp);
static void presence_changed (EmpathyAccountManager * eam, guint type, const gchar * type_str, const gchar * message, StatusProviderMC5 * sp);
+static void dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, StatusProviderMC5 * self);
G_DEFINE_TYPE (StatusProviderMC5, status_provider_mc5, STATUS_PROVIDER_TYPE);
@@ -104,6 +106,23 @@ status_provider_mc5_class_init (StatusProviderMC5Class *klass)
return;
}
+/* Build our empathy account manager instance if we don't
+ have one. */
+static void
+build_eam (StatusProviderMC5 * self)
+{
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(self);
+
+ if (priv->manager != NULL) {
+ return;
+ }
+
+ priv->manager = EMPATHY_ACCOUNT_MANAGER(g_object_new(EMPATHY_TYPE_ACCOUNT_MANAGER, NULL));
+ g_signal_connect(G_OBJECT(priv->manager), "global-presence-changed", G_CALLBACK(presence_changed), self);
+
+ return;
+}
+
/* Creating an instance of the status provider. We set the variables
and create an EmpathyAccountManager object. It does all the hard
work in this module of tracking MissionControl and enumerating the
@@ -116,7 +135,31 @@ status_provider_mc5_init (StatusProviderMC5 *self)
priv->status = STATUS_PROVIDER_STATUS_DISCONNECTED;
priv->manager = NULL;
- g_signal_connect(G_OBJECT(priv->manager), "global-presence-changed", G_CALLBACK(presence_changed), self);
+ DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ g_return_if_fail(bus != NULL); /* Can't do anymore DBus stuff without this,
+ all non-DBus stuff should be done */
+
+ GError * error = NULL;
+
+ /* 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);
return;
}
@@ -133,6 +176,11 @@ status_provider_mc5_dispose (GObject *object)
priv->manager = NULL;
}
+ if (priv->dbus_proxy != NULL) {
+ g_object_unref(priv->dbus_proxy);
+ priv->dbus_proxy = NULL;
+ }
+
G_OBJECT_CLASS (status_provider_mc5_parent_class)->dispose (object);
return;
}
@@ -146,6 +194,27 @@ status_provider_mc5_finalize (GObject *object)
return;
}
+#define MC5_WELL_KNOWN_NAME "org.freedesktop.Telepathy.MissionControl5"
+/* Watch for MC5 Coming on and off the bus. */
+static void
+dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, StatusProviderMC5 * self)
+{
+ if (new != NULL && g_strcmp0(name, MC5_WELL_KNOWN_NAME) == 0) {
+ g_debug("MC5 Coming online");
+ build_eam(self);
+ }
+ if (prev != NULL && g_strcmp0(name, MC5_WELL_KNOWN_NAME) == 0) {
+ g_debug("MC5 going offline");
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(self);
+ if (priv->manager != NULL) {
+ g_object_unref(priv->manager);
+ priv->manager = NULL;
+ }
+ }
+
+ return;
+}
+
/**
status_provider_mc5_new:
@@ -168,9 +237,8 @@ static void
set_status (StatusProvider * sp, StatusProviderStatus status)
{
StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
- if (priv->manager == NULL) {
- priv->manager = EMPATHY_ACCOUNT_MANAGER(g_object_new(EMPATHY_TYPE_ACCOUNT_MANAGER, NULL));
- }
+
+ build_eam(STATUS_PROVIDER_MC5(sp));
empathy_account_manager_request_global_presence(priv->manager, sp_to_tp_map[status], sp_to_mc_map[status], "");
diff --git a/src/status-provider-mc5.h b/src/status-provider-mc5.h
index 2c03729..4d5659d 100644
--- a/src/status-provider-mc5.h
+++ b/src/status-provider-mc5.h
@@ -31,8 +31,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
G_BEGIN_DECLS
#define STATUS_PROVIDER_MC5_TYPE (status_provider_mc5_get_type ())
-#define STATUS_PROVIDER_MC5(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STATUS_PROVIDER_MC5_TYPE, StatusProviderTelepathy))
-#define STATUS_PROVIDER_MC5_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STATUS_PROVIDER_MC5_TYPE, StatusProviderTelepathyClass))
+#define STATUS_PROVIDER_MC5(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STATUS_PROVIDER_MC5_TYPE, StatusProviderMC5))
+#define STATUS_PROVIDER_MC5_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STATUS_PROVIDER_MC5_TYPE, StatusProviderMC5Class))
#define IS_STATUS_PROVIDER_MC5(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STATUS_PROVIDER_MC5_TYPE))
#define IS_STATUS_PROVIDER_MC5_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STATUS_PROVIDER_MC5_TYPE))
#define STATUS_PROVIDER_MC5_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STATUS_PROVIDER_MC5_TYPE, StatusProviderMC5Class))