aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore2
-rw-r--r--src/Makefile.am17
-rw-r--r--src/status-provider-mc5.c383
-rw-r--r--src/status-provider-mc5.h56
-rw-r--r--src/status-provider-mc5.list1
5 files changed, 459 insertions, 0 deletions
diff --git a/.bzrignore b/.bzrignore
index 22ecc23..dd58cdf 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -44,3 +44,5 @@ src/status-provider-pidgin-marshal.c
src/status-provider-pidgin-marshal.h
src/status-provider-telepathy-marshal.c
src/status-provider-telepathy-marshal.h
+src/status-provider-mc5-marshal.c
+src/status-provider-mc5-marshal.h
diff --git a/src/Makefile.am b/src/Makefile.am
index e2f0008..ae941e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,10 @@ indicator_status_service_SOURCES = \
status-service-server.h \
status-provider.h \
status-provider.c \
+ status-provider-mc5.h \
+ status-provider-mc5.c \
+ status-provider-mc5-marshal.h \
+ status-provider-mc5-marshal.c \
status-provider-pidgin.h \
status-provider-pidgin.c \
status-provider-pidgin-marshal.h \
@@ -72,6 +76,16 @@ status-provider-telepathy-marshal.c: $(srcdir)/status-provider-telepathy.list
--prefix=_status_provider_telepathy_marshal $(srcdir)/status-provider-telepathy.list \
> status-provider-telepathy-marshal.c
+status-provider-mc5-marshal.h: $(srcdir)/status-provider-mc5.list
+ glib-genmarshal --header \
+ --prefix=_status_provider_mc5_marshal $(srcdir)/status-provider-mc5.list \
+ > status-provider-mc5-marshal.h
+
+status-provider-mc5-marshal.c: $(srcdir)/status-provider-mc5.list
+ glib-genmarshal --body \
+ --prefix=_status_provider_mc5_marshal $(srcdir)/status-provider-mc5.list \
+ > status-provider-mc5-marshal.c
+
###############
# Users Stuff
###############
@@ -95,6 +109,8 @@ indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS)
BUILT_SOURCES = \
status-service-client.h \
status-service-server.h \
+ status-provider-mc5-marshal.h \
+ status-provider-mc5-marshal.c \
status-provider-pidgin-marshal.h \
status-provider-pidgin-marshal.c \
status-provider-telepathy-marshal.h \
@@ -102,6 +118,7 @@ BUILT_SOURCES = \
EXTRA_DIST = \
status-service.xml \
+ status-provider-mc5.list \
status-provider-pidgin.list \
status-provider-telepathy.list
diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c
new file mode 100644
index 0000000..300818d
--- /dev/null
+++ b/src/status-provider-mc5.c
@@ -0,0 +1,383 @@
+/*
+A small wrapper utility to load indicators and put them as menu items
+into the gnome-panel using it's applet interface.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "status-provider.h"
+#include "status-provider-mc5.h"
+#include "status-provider-mc5-marshal.h"
+
+#include <dbus/dbus-glib.h>
+
+typedef enum {
+ MC_STATUS_UNSET,
+ MC_STATUS_OFFLINE,
+ MC_STATUS_AVAILABLE,
+ MC_STATUS_AWAY,
+ MC_STATUS_EXTENDED_AWAY,
+ MC_STATUS_HIDDEN,
+ MC_STATUS_DND
+} mc_status_t;
+
+static StatusProviderStatus mc_to_sp_map[] = {
+ /* MC_STATUS_UNSET, */ STATUS_PROVIDER_STATUS_OFFLINE,
+ /* MC_STATUS_OFFLINE, */ STATUS_PROVIDER_STATUS_OFFLINE,
+ /* MC_STATUS_AVAILABLE, */ STATUS_PROVIDER_STATUS_ONLINE,
+ /* MC_STATUS_AWAY, */ STATUS_PROVIDER_STATUS_AWAY,
+ /* MC_STATUS_EXTENDED_AWAY, */ STATUS_PROVIDER_STATUS_AWAY,
+ /* MC_STATUS_HIDDEN, */ STATUS_PROVIDER_STATUS_INVISIBLE,
+ /* MC_STATUS_DND */ STATUS_PROVIDER_STATUS_DND
+};
+
+static mc_status_t sp_to_mc_map[] = {
+ /* STATUS_PROVIDER_STATUS_ONLINE, */ MC_STATUS_AVAILABLE,
+ /* 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_DISCONNECTED*/MC_STATUS_OFFLINE
+};
+
+typedef struct _StatusProviderMC5Private StatusProviderMC5Private;
+struct _StatusProviderMC5Private {
+ DBusGProxy * proxy;
+ DBusGProxy * dbus_proxy;
+ mc_status_t mc_status;
+};
+
+#define STATUS_PROVIDER_MC5_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_PROVIDER_MC5_TYPE, StatusProviderMC5Private))
+
+/* Prototypes */
+/* GObject stuff */
+static void status_provider_mc5_class_init (StatusProviderMC5Class *klass);
+static void status_provider_mc5_init (StatusProviderMC5 *self);
+static void status_provider_mc5_dispose (GObject *object);
+static void status_provider_mc5_finalize (GObject *object);
+/* Internal Funcs */
+static void build_mc5_proxy (StatusProviderMC5 * self);
+static void dbus_namechange (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, StatusProviderMC5 * 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);
+static void proxy_destroy (DBusGProxy * proxy, StatusProvider * sp);
+static void get_status_async (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata);
+
+G_DEFINE_TYPE (StatusProviderMC5, status_provider_mc5, STATUS_PROVIDER_TYPE);
+
+static void
+status_provider_mc5_class_init (StatusProviderMC5Class *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (StatusProviderMC5Private));
+
+ object_class->dispose = status_provider_mc5_dispose;
+ object_class->finalize = status_provider_mc5_finalize;
+
+ StatusProviderClass * spclass = STATUS_PROVIDER_CLASS(klass);
+
+ spclass->set_status = set_status;
+ spclass->get_status = get_status;
+
+ return;
+}
+
+
+static void
+status_provider_mc5_init (StatusProviderMC5 *self)
+{
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_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_mc5_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_mc5_proxy (StatusProviderMC5 * self)
+{
+ g_debug("Building MC5 Proxy");
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_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);
+ g_error_free(error);
+ return;
+ }
+
+ /* Get the proxy to Mission Control */
+ priv->proxy = dbus_g_proxy_new_for_name_owner(session_bus,
+ "org.freedesktop.Telepathy.MissionControl5",
+ "/org/freedesktop/Telepathy/MissionControl5",
+ "org.freedesktop.Telepathy.MissionControl5",
+ &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_mc5_marshal_VOID__UINT_STRING,
+ G_TYPE_NONE,
+ G_TYPE_UINT,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (priv->proxy,
+ "PresenceChanged",
+ G_TYPE_UINT,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal(priv->proxy,
+ "PresenceChanged",
+ G_CALLBACK(changed_status),
+ (void *)self,
+ NULL);
+
+ /* Do a get here, to init the status */
+ dbus_g_proxy_begin_call(priv->proxy,
+ "GetStatus",
+ get_status_async,
+ self,
+ NULL,
+ G_TYPE_INVALID);
+ } else {
+ g_warning("Unable to connect to Mission Control");
+ if (error != NULL) {
+ g_error_free(error);
+ }
+ }
+
+ 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, StatusProviderMC5 * self)
+{
+ g_return_if_fail(name != NULL);
+ g_return_if_fail(new != NULL);
+
+ if (g_strcmp0(name, "org.freedesktop.Telepathy.MissionControl5") == 0) {
+ build_mc5_proxy(self);
+ }
+ return;
+}
+
+static void
+status_provider_mc5_dispose (GObject *object)
+{
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(object);
+
+ if (priv->proxy != NULL) {
+ g_object_unref(priv->proxy);
+ priv->proxy = NULL;
+ }
+
+ G_OBJECT_CLASS (status_provider_mc5_parent_class)->dispose (object);
+ return;
+}
+
+static void
+status_provider_mc5_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (status_provider_mc5_parent_class)->finalize (object);
+ return;
+}
+
+/**
+ status_provider_mc5_new:
+
+ Creates a new #StatusProviderMC5 object. No parameters or anything
+ like that. Just a convience function.
+
+ Return value: A new instance of #StatusProviderMC5
+*/
+StatusProvider *
+status_provider_mc5_new (void)
+{
+ return STATUS_PROVIDER(g_object_new(STATUS_PROVIDER_MC5_TYPE, NULL));
+}
+
+static void
+set_status (StatusProvider * sp, StatusProviderStatus status)
+{
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
+ if (priv->proxy == NULL) {
+ priv->mc_status = MC_STATUS_OFFLINE;
+ return;
+ }
+
+ priv->mc_status = sp_to_mc_map[status];
+
+ guint mcstatus = MC_STATUS_UNSET;
+ gboolean ret = FALSE;
+ GError * error = NULL;
+
+ ret = dbus_g_proxy_call(priv->proxy,
+ "GetPresence", &error,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &priv->mc_status,
+ G_TYPE_INVALID);
+
+ /* If we can't get the get call to work, let's not set */
+ if (!ret) {
+ if (error != NULL) {
+ g_error_free(error);
+ }
+ return;
+ }
+
+ /* If the get call doesn't return a status, that means that there
+ are no clients connected. We don't want to connect them by telling
+ MC that we're going online -- we'd like to be more passive than that. */
+ if (mcstatus == MC_STATUS_UNSET) {
+ return;
+ }
+
+ ret = dbus_g_proxy_call(priv->proxy,
+ "SetPresence", &error,
+ G_TYPE_UINT, priv->mc_status,
+ G_TYPE_STRING, "",
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ if (!ret) {
+ if (error != NULL) {
+ g_warning("Unable to set Mission Control Presence: %s", error->message);
+ g_error_free(error);
+ } else {
+ g_warning("Unable to set Mission Control Presence");
+ }
+ return;
+ }
+
+ return;
+}
+
+static StatusProviderStatus
+get_status (StatusProvider * sp)
+{
+ g_return_val_if_fail(IS_STATUS_PROVIDER_MC5(sp), STATUS_PROVIDER_STATUS_DISCONNECTED);
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
+
+ if (priv->proxy == NULL) {
+ return STATUS_PROVIDER_STATUS_DISCONNECTED;
+ }
+
+ return mc_to_sp_map[priv->mc_status];
+}
+
+static void
+changed_status (DBusGProxy * proxy, guint status, gchar * message, StatusProvider * sp)
+{
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
+ priv->mc_status = status;
+ g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, mc_to_sp_map[priv->mc_status], TRUE);
+}
+
+static void
+proxy_destroy (DBusGProxy * proxy, StatusProvider * sp)
+{
+ g_debug("Signal: Mission Control proxy destroyed");
+ g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, STATUS_PROVIDER_STATUS_OFFLINE, TRUE);
+ return;
+}
+
+static void
+get_status_async (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata)
+{
+ GError * error = NULL;
+ guint status = 0;
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_UINT, &status, G_TYPE_INVALID)) {
+ g_warning("Unable to get type from Mission Control: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(userdata);
+
+ gboolean changed = FALSE;
+ if (status != priv->mc_status) {
+ changed = TRUE;
+ }
+
+ priv->mc_status = status;
+
+ if (changed) {
+ g_signal_emit(G_OBJECT(userdata), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, mc_to_sp_map[priv->mc_status], TRUE);
+ }
+
+ return;
+}
diff --git a/src/status-provider-mc5.h b/src/status-provider-mc5.h
new file mode 100644
index 0000000..2c03729
--- /dev/null
+++ b/src/status-provider-mc5.h
@@ -0,0 +1,56 @@
+/*
+A small wrapper utility to load indicators and put them as menu items
+into the gnome-panel using it's applet interface.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __STATUS_PROVIDER_MC5_H__
+#define __STATUS_PROVIDER_MC5_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "status-provider.h"
+
+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 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))
+
+
+typedef struct _StatusProviderMC5Class StatusProviderMC5Class;
+struct _StatusProviderMC5Class {
+ StatusProviderClass parent_class;
+};
+
+typedef struct _StatusProviderMC5 StatusProviderMC5;
+struct _StatusProviderMC5 {
+ StatusProvider parent;
+};
+
+GType status_provider_mc5_get_type (void);
+StatusProvider * status_provider_mc5_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/status-provider-mc5.list b/src/status-provider-mc5.list
new file mode 100644
index 0000000..5ab45bf
--- /dev/null
+++ b/src/status-provider-mc5.list
@@ -0,0 +1 @@
+VOID:UINT,STRING