← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-session/mc5 into lp:indicator-session

 

Ted Gould has proposed merging lp:~ted/indicator-session/mc5 into lp:indicator-session.

Requested reviews:
    Indicator Applet Developers (indicator-applet-developers)

This links to libempathy to get MC5 support.
-- 
https://code.launchpad.net/~ted/indicator-session/mc5/+merge/12306
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file '.bzrignore'
--- .bzrignore	2009-08-25 21:21:44 +0000
+++ .bzrignore	2009-09-17 19:07:29 +0000
@@ -44,3 +44,6 @@
 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
+data/indicator-session.schemas

=== modified file 'configure.ac'
--- configure.ac	2009-09-10 22:10:37 +0000
+++ configure.ac	2009-09-21 22:16:10 +0000
@@ -36,8 +36,10 @@
 AC_SUBST(APPLET_LIBS)
 
 DBUSMENUGLIB_REQUIRED_VERSION=0.1.1
+LIBEMPATHY_REQUIRED_VERSION=2.27.0
 
-PKG_CHECK_MODULES(STATUSSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION)
+PKG_CHECK_MODULES(STATUSSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION
+                                 libempathy >= $LIBEMPATHY_REQUIRED_VERSION)
 
 AC_SUBST(STATUSERVICE_CFLAGS)
 AC_SUBST(STATUSERVICE_LIBS)

=== modified file 'src/Makefile.am'
--- src/Makefile.am	2009-09-02 14:17:44 +0000
+++ src/Makefile.am	2009-09-16 22:08:31 +0000
@@ -27,6 +27,10 @@
 	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 @@
 		--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 @@
 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 @@
 
 EXTRA_DIST = \
 	status-service.xml \
+	status-provider-mc5.list \
 	status-provider-pidgin.list \
 	status-provider-telepathy.list
 

=== added file 'src/status-provider-mc5.c'
--- src/status-provider-mc5.c	1970-01-01 00:00:00 +0000
+++ src/status-provider-mc5.c	2009-09-23 19:04:06 +0000
@@ -0,0 +1,213 @@
+/*
+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@xxxxxxxxxxxxx>
+
+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 "libempathy/empathy-account-manager.h"
+
+#include "status-provider.h"
+#include "status-provider-mc5.h"
+#include "status-provider-mc5-marshal.h"
+
+#include <dbus/dbus-glib.h>
+
+static gchar * sp_to_mc_map[STATUS_PROVIDER_STATUS_LAST] = {
+	/* STATUS_PROVIDER_STATUS_ONLINE,  */  "available",
+	/* STATUS_PROVIDER_STATUS_AWAY,    */  "away",
+	/* STATUS_PROVIDER_STATUS_DND      */  "busy",
+	/* STATUS_PROVIDER_STATUS_INVISIBLE*/  "hidden",
+	/* STATUS_PROVIDER_STATUS_OFFLINE  */  "offline",
+	/* STATUS_PROVIDER_STATUS_DISCONNECTED*/NULL
+};
+
+static TpConnectionPresenceType sp_to_tp_map[STATUS_PROVIDER_STATUS_LAST] = {
+	/* STATUS_PROVIDER_STATUS_ONLINE,  */    TP_CONNECTION_PRESENCE_TYPE_AVAILABLE,
+	/* STATUS_PROVIDER_STATUS_AWAY,    */    TP_CONNECTION_PRESENCE_TYPE_AWAY,
+	/* STATUS_PROVIDER_STATUS_DND      */    TP_CONNECTION_PRESENCE_TYPE_BUSY,
+	/* STATUS_PROVIDER_STATUS_INVISIBLE*/    TP_CONNECTION_PRESENCE_TYPE_HIDDEN,
+	/* STATUS_PROVIDER_STATUS_OFFLINE  */    TP_CONNECTION_PRESENCE_TYPE_OFFLINE,
+	/* STATUS_PROVIDER_STATUS_DISCONNECTED*/ TP_CONNECTION_PRESENCE_TYPE_UNSET
+};
+
+static StatusProviderStatus tp_to_sp_map[TP_CONNECTION_PRESENCE_TYPE_ERROR + 1] = {
+	/* TP_CONNECTION_PRESENCE_TYPE_UNSET          */  STATUS_PROVIDER_STATUS_DISCONNECTED,
+	/* TP_CONNECTION_PRESENCE_TYPE_OFFLINE        */  STATUS_PROVIDER_STATUS_OFFLINE,
+	/* TP_CONNECTION_PRESENCE_TYPE_AVAILABLE      */  STATUS_PROVIDER_STATUS_ONLINE,
+	/* TP_CONNECTION_PRESENCE_TYPE_AWAY           */  STATUS_PROVIDER_STATUS_AWAY,
+	/* TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY  */  STATUS_PROVIDER_STATUS_AWAY,
+	/* TP_CONNECTION_PRESENCE_TYPE_HIDDEN         */  STATUS_PROVIDER_STATUS_INVISIBLE,
+	/* TP_CONNECTION_PRESENCE_TYPE_BUSY           */  STATUS_PROVIDER_STATUS_DND,
+	/* TP_CONNECTION_PRESENCE_TYPE_UNKNOWN        */  STATUS_PROVIDER_STATUS_DISCONNECTED,
+	/* TP_CONNECTION_PRESENCE_TYPE_ERROR          */  STATUS_PROVIDER_STATUS_DISCONNECTED
+};
+
+typedef struct _StatusProviderMC5Private StatusProviderMC5Private;
+struct _StatusProviderMC5Private {
+	EmpathyAccountManager * manager;
+	StatusProviderStatus 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 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);
+
+G_DEFINE_TYPE (StatusProviderMC5, status_provider_mc5, STATUS_PROVIDER_TYPE);
+
+/* Create the class.  We over ride a few functions but nothing
+   really shocking.  Most interesting is the set and get status. */
+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;
+}
+
+/* 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
+   accounts and all that jazz. */
+static void
+status_provider_mc5_init (StatusProviderMC5 *self)
+{
+	StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(self);
+
+	priv->status = STATUS_PROVIDER_STATUS_OFFLINE;
+	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;
+}
+
+/* Unref the account manager and move on.  Sadly, we're
+   leaving the show. */
+static void
+status_provider_mc5_dispose (GObject *object)
+{
+	StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(object);
+
+	if (priv->manager != NULL) {
+		g_object_unref(priv->manager);
+		priv->manager = NULL;
+	}
+
+	G_OBJECT_CLASS (status_provider_mc5_parent_class)->dispose (object);
+	return;
+}
+
+/* Pass to superclass */
+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));
+}
+
+/* Setting the status in the empathy account manager.  We're
+   basically requesting a global status.  This may or may not
+   get applied to all accounts.  It's really the best we can
+   hope to do. */
+static void
+set_status (StatusProvider * sp, StatusProviderStatus status)
+{
+	StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
+	if (priv->manager == NULL) {
+		priv->status = STATUS_PROVIDER_STATUS_DISCONNECTED;
+		return;
+	}
+
+	empathy_account_manager_request_global_presence(priv->manager, sp_to_tp_map[status], sp_to_mc_map[status], "");
+
+	return;
+}
+
+/* Gets the status, uses the cached value that we have.  Asking
+   would just be painful. */
+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->manager == NULL) {
+		return STATUS_PROVIDER_STATUS_DISCONNECTED;
+	}
+
+	return priv->status;
+}
+
+/* A signal handler for when the EmpatyAccountManager believes
+   that the global status has changed.  It roughly calculates this
+   by finding the most available of all accounts that are active. */
+static void
+presence_changed (EmpathyAccountManager * eam, guint type, const gchar * type_str, const gchar * message, StatusProviderMC5 * sp)
+{
+	StatusProviderMC5Private * priv = STATUS_PROVIDER_MC5_GET_PRIVATE(sp);
+
+	g_debug("MC5 Status changed: %d %s %s", type, type_str, message);
+
+	if (priv->status != tp_to_sp_map[type]) {
+		priv->status = tp_to_sp_map[type];
+		g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, priv->status, TRUE);
+	}
+
+	return;
+}
+

=== added file 'src/status-provider-mc5.h'
--- src/status-provider-mc5.h	1970-01-01 00:00:00 +0000
+++ src/status-provider-mc5.h	2009-09-16 22:08:31 +0000
@@ -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@xxxxxxxxxxxxx>
+
+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

=== added file 'src/status-provider-mc5.list'
--- src/status-provider-mc5.list	1970-01-01 00:00:00 +0000
+++ src/status-provider-mc5.list	2009-09-16 22:08:31 +0000
@@ -0,0 +1,1 @@
+VOID:UINT,STRING

=== modified file 'src/status-service.c'
--- src/status-service.c	2009-09-16 16:34:26 +0000
+++ src/status-service.c	2009-09-16 22:09:30 +0000
@@ -40,12 +40,14 @@
 #include "status-service-dbus.h"
 
 #include "status-provider.h"
+#include "status-provider-mc5.h"
 #include "status-provider-pidgin.h"
 #include "status-provider-telepathy.h"
 
 typedef StatusProvider * (*newfunc) (void);
-#define STATUS_PROVIDER_CNT   2
+#define STATUS_PROVIDER_CNT   3
 static newfunc status_provider_newfuncs[STATUS_PROVIDER_CNT] = {
+	status_provider_mc5_new,
 	status_provider_pidgin_new,
 	status_provider_telepathy_new
 };


Follow ups