diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2009-08-27 14:52:00 -0400 |
---|---|---|
committer | Ken VanDine <ken.vandine@canonical.com> | 2009-08-27 14:52:00 -0400 |
commit | f6d0564a4d48f60e52959eeb0cdc64c6170e0372 (patch) | |
tree | faac1c5ff643a6aba420f2248ac0390f317ad685 | |
parent | 3a18ed4b656b9ee146e6f3fd5fdd56416d335724 (diff) | |
parent | 94f3cd1c8817d7203c5ba2b9abb57992f577f3a0 (diff) | |
download | ayatana-indicator-session-f6d0564a4d48f60e52959eeb0cdc64c6170e0372.tar.gz ayatana-indicator-session-f6d0564a4d48f60e52959eeb0cdc64c6170e0372.tar.bz2 ayatana-indicator-session-f6d0564a4d48f60e52959eeb0cdc64c6170e0372.zip |
* Upstream version 0.1
* debian/control: Looking for libdbusmenu* >= 0.1.0
* debian/control: Shortening the short description and lengthening
the long one. Fixes a bug (LP: #412024)
-rw-r--r-- | .bzrignore | 4 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | debian/changelog | 11 | ||||
-rw-r--r-- | debian/control | 14 | ||||
-rw-r--r-- | src/Makefile.am | 38 | ||||
-rw-r--r-- | src/indicator-session.c | 33 | ||||
-rw-r--r-- | src/status-provider-pidgin.c | 175 | ||||
-rw-r--r-- | src/status-provider-pidgin.list | 1 | ||||
-rw-r--r-- | src/status-provider-telepathy.c | 311 | ||||
-rw-r--r-- | src/status-provider-telepathy.h | 56 | ||||
-rw-r--r-- | src/status-provider-telepathy.list | 1 | ||||
-rw-r--r-- | src/status-provider.c | 7 | ||||
-rw-r--r-- | src/status-provider.h | 2 | ||||
-rw-r--r-- | src/status-service.c | 10 |
14 files changed, 642 insertions, 25 deletions
@@ -40,3 +40,7 @@ gtk-logout-helper .libs src/libsession.la src/libsession_la-indicator-session.lo +src/status-provider-pidgin-marshal.c +src/status-provider-pidgin-marshal.h +src/status-provider-telepathy-marshal.c +src/status-provider-telepathy-marshal.h diff --git a/configure.ac b/configure.ac index 0baf030..28b2c8b 100644 --- a/configure.ac +++ b/configure.ac @@ -17,13 +17,15 @@ AC_PROG_LIBTOOL AC_SUBST(VERSION) AC_CONFIG_MACRO_DIR([m4]) +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) + ########################### # Dependencies ########################### GTK_REQUIRED_VERSION=2.12 INDICATOR_REQUIRED_VERSION=0.2.0 -DBUSMENUGTK_REQUIRED_VERSION=0.0.0 +DBUSMENUGTK_REQUIRED_VERSION=0.1.0 PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION indicator >= $INDICATOR_REQUIRED_VERSION diff --git a/debian/changelog b/debian/changelog index 3bdbaf0..31f3624 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,13 @@ -indicator-session (0.1~bzr17-0ubuntu1) UNRELEASED; urgency=low +indicator-session (0.1-0ubuntu1) UNRELEASD; urgency=low + + * Upstream version 0.1 + * debian/control: Looking for libdbusmenu* >= 0.1.0 + * debian/control: Shortening the short description and lengthening + the long one. Fixes a bug (LP: #412024) + + -- Ted Gould <ted@ubuntu.com> Thu, 27 Aug 2009 13:46:29 -0500 + +indicator-session (0.1~bzr17-0ubuntu1) UNRELEASE; urgency=low * New snapshot (LP: #417035) * Package rename from 'indicator-sus' to 'indicator-session' diff --git a/debian/control b/debian/control index e794657..b9ad314 100644 --- a/debian/control +++ b/debian/control @@ -9,8 +9,8 @@ Build-Depends: debhelper (>= 5.0), gnome-doc-utils, scrollkeeper, libindicator-dev, - libdbusmenu-glib-dev, - libdbusmenu-gtk-dev, + libdbusmenu-glib-dev (>= 0.1.0), + libdbusmenu-gtk-dev (>= 0.1.0), libpolkit-gnome-dev, intltool Standards-Version: 3.8.2 @@ -23,4 +23,12 @@ Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, indicator-applet (>= 0.2), devicekit-power, gdm Conflicts: gdm (<= 2.27.4-0ubuntu9), indicator-sus Replaces: indicator-sus -Description: An indicator providing session management, status control and user switching. +Description: An indicator showing session management, status and user switching. + . + This indicator is designed to be placed on the right side of a panel and + give the user easy control for changing their instant message status. Switching + to another user. Starting a guest session. Or controlling the status of + their own session. + . + It requires some way to be hosted into a panel. For the GNOME Panel the + appropriate package is indicator-applet-session. diff --git a/src/Makefile.am b/src/Makefile.am index bd35910..599b70a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,13 @@ indicator_status_service_SOURCES = \ status-provider.h \ status-provider.c \ status-provider-pidgin.h \ - status-provider-pidgin.c + status-provider-pidgin.c \ + status-provider-pidgin-marshal.h \ + status-provider-pidgin-marshal.c \ + status-provider-telepathy.h \ + status-provider-telepathy.c \ + status-provider-telepathy-marshal.h \ + status-provider-telepathy-marshal.c indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror indicator_status_service_LDADD = $(STATUSSERVICE_LIBS) @@ -46,6 +52,26 @@ status-service-server.h: $(srcdir)/status-service.xml --output=status-service-server.h \ $(srcdir)/status-service.xml +status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list + glib-genmarshal --header \ + --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ + > status-provider-pidgin-marshal.h + +status-provider-pidgin-marshal.c: $(srcdir)/status-provider-pidgin.list + glib-genmarshal --body \ + --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ + > status-provider-pidgin-marshal.c + +status-provider-telepathy-marshal.h: $(srcdir)/status-provider-telepathy.list + glib-genmarshal --header \ + --prefix=_status_provider_telepathy_marshal $(srcdir)/status-provider-telepathy.list \ + > status-provider-telepathy-marshal.h + +status-provider-telepathy-marshal.c: $(srcdir)/status-provider-telepathy.list + glib-genmarshal --body \ + --prefix=_status_provider_telepathy_marshal $(srcdir)/status-provider-telepathy.list \ + > status-provider-telepathy-marshal.c + ############### # Users Stuff ############### @@ -68,10 +94,16 @@ indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) BUILT_SOURCES = \ status-service-client.h \ - status-service-server.h + status-service-server.h \ + status-provider-pidgin-marshal.h \ + status-provider-pidgin-marshal.c \ + status-provider-telepathy-marshal.h \ + status-provider-telepathy-marshal.c EXTRA_DIST = \ - status-service.xml + status-service.xml \ + status-provider-pidgin.list \ + status-provider-telepathy.list CLEANFILES = \ $(BUILT_SOURCES) diff --git a/src/indicator-session.c b/src/indicator-session.c index 07efc86..43c568f 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -61,6 +61,7 @@ static void child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, gu static guint status_menu_pos_offset (void); static guint users_menu_pos_offset (void); static guint session_menu_pos_offset (void); +static void child_realized (DbusmenuMenuitem * child, gpointer userdata); GtkLabel * get_label (void) @@ -79,14 +80,44 @@ get_icon (void) return status_image; } +typedef struct _realized_data_t realized_data_t; +struct _realized_data_t { + guint position; + section_t section; +}; + static void child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer section) { + realized_data_t * data = g_new0(realized_data_t, 1); + if (data == NULL) { + g_warning("Unable to allocate data for realization of item"); + return; + } + + data->position = position; + data->section = GPOINTER_TO_UINT(section); + + g_signal_connect(G_OBJECT(child), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), data); + return; +} + +static void +child_realized (DbusmenuMenuitem * child, gpointer userdata) +{ + g_return_if_fail(userdata != NULL); + g_return_if_fail(DBUSMENU_IS_MENUITEM(child)); + + realized_data_t * data = (realized_data_t *)userdata; + guint position = data->position; + section_t section = data->section; + g_free(data); + DbusmenuGtkClient * client = NULL; gchar * errorstr = NULL; guint (*posfunc) (void) = NULL; - switch (GPOINTER_TO_UINT(section)) { + switch (section) { case STATUS_SECTION: client = status_client; errorstr = "Status"; diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index aaa8732..052ce12 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -26,6 +26,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "status-provider.h" #include "status-provider-pidgin.h" +#include "status-provider-pidgin-marshal.h" #include <dbus/dbus-glib.h> @@ -101,6 +102,75 @@ status_provider_pidgin_class_init (StatusProviderPidginClass *klass) } static void +type_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + GError * error = NULL; + gint status = 0; + if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INT, &status, G_TYPE_INVALID)) { + g_warning("Unable to get type from Pidgin: %s", error->message); + g_error_free(error); + return; + } + + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(userdata); + if (status != priv->pg_status) { + priv->pg_status = status; + + g_signal_emit(G_OBJECT(userdata), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); + } + + return; +} + +static void +saved_status_to_type (StatusProviderPidgin * spp, gint savedstatus) +{ + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(spp); + + g_debug("Pidgin figuring out type for %d", savedstatus); + dbus_g_proxy_begin_call(priv->proxy, + "PurpleSavedstatusGetType", type_cb, spp, NULL, + G_TYPE_INT, savedstatus, G_TYPE_INVALID); + + return; +} + +static void +savedstatus_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + GError * error = NULL; + gint status = 0; + if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INT, &status, G_TYPE_INVALID)) { + g_warning("Unable to get saved status from Pidgin: %s", error->message); + g_error_free(error); + return; + } + + saved_status_to_type(STATUS_PROVIDER_PIDGIN(userdata), status); + return; +} + + +static void +changed_status (DBusGProxy * proxy, gint savedstatus, GError ** error, StatusProviderPidgin * spp) +{ + saved_status_to_type(spp, savedstatus); + return; +} + +static void +proxy_destroy (DBusGProxy * proxy, StatusProviderPidgin * spp) +{ + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(spp); + + priv->proxy = NULL; + priv->pg_status = PG_STATUS_OFFLINE; + + g_signal_emit(G_OBJECT(spp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); + return; +} + +static void status_provider_pidgin_init (StatusProviderPidgin *self) { StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(self); @@ -121,6 +191,37 @@ status_provider_pidgin_init (StatusProviderPidgin *self) if (error != NULL) { g_debug("Unable to get Pidgin proxy: %s", error->message); g_error_free(error); + return; + } + + if (priv->proxy != NULL) { + g_object_add_weak_pointer (G_OBJECT(priv->proxy), (gpointer *)&priv->proxy); + g_signal_connect(G_OBJECT(priv->proxy), "destroy", + G_CALLBACK(proxy_destroy), self); + + g_debug("Adding Pidgin Signals"); + dbus_g_object_register_marshaller(_status_provider_pidgin_marshal_VOID__INT_INT, + G_TYPE_NONE, + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->proxy, + "SavedstatusChanged", + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(priv->proxy, + "SavedstatusChanged", + G_CALLBACK(changed_status), + (void *)self, + NULL); + + dbus_g_proxy_begin_call(priv->proxy, + "PurpleSavedstatusGetCurrent", + savedstatus_cb, + self, + NULL, + G_TYPE_INVALID); } return; @@ -167,11 +268,79 @@ status_provider_pidgin_new (void) static void set_status (StatusProvider * sp, StatusProviderStatus status) { - g_debug("\tSetting Pidgin Status: %d", status); + gchar * message = ""; + g_return_if_fail(IS_STATUS_PROVIDER_PIDGIN(sp)); StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(sp); - pg_status_t pg_status = sp_to_pg_map[status]; - priv->pg_status = pg_status; + + g_debug("\tPidgin set status to %d", status); + if (priv->proxy == NULL) { + return; + } + + priv->pg_status = sp_to_pg_map[status]; + gint status_val = 0; + gboolean ret = FALSE; + GError * error = NULL; + + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusFindTransientByTypeAndMessage", &error, + G_TYPE_INT, priv->pg_status, + G_TYPE_STRING, message, + G_TYPE_INVALID, + G_TYPE_INT, &status_val, + G_TYPE_INVALID); + + if (!ret) { + if (error != NULL) { + g_error_free(error); + } + error = NULL; + status_val = 0; + g_debug("No Pidgin saved status to apply"); + } + + if (status_val == 0) { + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusNew", &error, + G_TYPE_STRING, message, + G_TYPE_INT, priv->pg_status, + G_TYPE_INVALID, + G_TYPE_INT, &status_val, + G_TYPE_INVALID); + + if (!ret) { + status_val = 0; + if (error != NULL) { + g_warning("Unable to create Pidgin status for %d: %s", status, error->message); + g_error_free(error); + } else { + g_warning("Unable to create Pidgin status for %d", status); + } + error = NULL; + } + } + + if (status_val == 0) { + return; + } + + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusActivate", &error, + G_TYPE_INT, status_val, + G_TYPE_INVALID, + G_TYPE_INVALID); + + if (!ret) { + if (error != NULL) { + g_warning("Pidgin unable to change to status: %s", error->message); + g_error_free(error); + } else { + g_warning("Pidgin unable to change to status"); + } + error = NULL; + } + g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); return; } diff --git a/src/status-provider-pidgin.list b/src/status-provider-pidgin.list new file mode 100644 index 0000000..1f953dd --- /dev/null +++ b/src/status-provider-pidgin.list @@ -0,0 +1 @@ +VOID:INT,INT diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c new file mode 100644 index 0000000..e22c27d --- /dev/null +++ b/src/status-provider-telepathy.c @@ -0,0 +1,311 @@ +/* +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-telepathy.h" +#include "status-provider-telepathy-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 +}; + +typedef struct _StatusProviderTelepathyPrivate StatusProviderTelepathyPrivate; +struct _StatusProviderTelepathyPrivate { + DBusGProxy * proxy; + mc_status_t mc_status; +}; + +#define STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyPrivate)) + +/* Prototypes */ +/* GObject stuff */ +static void status_provider_telepathy_class_init (StatusProviderTelepathyClass *klass); +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 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 (StatusProviderTelepathy, status_provider_telepathy, STATUS_PROVIDER_TYPE); + +static void +status_provider_telepathy_class_init (StatusProviderTelepathyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (StatusProviderTelepathyPrivate)); + + object_class->dispose = status_provider_telepathy_dispose; + object_class->finalize = status_provider_telepathy_finalize; + + StatusProviderClass * spclass = STATUS_PROVIDER_CLASS(klass); + + spclass->set_status = set_status; + spclass->get_status = get_status; + + return; +} + + +static void +status_provider_telepathy_init (StatusProviderTelepathy *self) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(self); + + priv->proxy = NULL; + priv->mc_status = MC_STATUS_OFFLINE; + + GError * error = NULL; + + 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; + } + + priv->proxy = NULL; + priv->proxy = dbus_g_proxy_new_for_name_owner(session_bus, + "org.freedesktop.Telepathy.MissionControl", + "/org/freedesktop/Telepathy/MissionControl", + "org.freedesktop.Telepathy.MissionControl", + &error); + + if (priv->proxy != NULL) { + g_object_add_weak_pointer (G_OBJECT(priv->proxy), (gpointer *)&priv->proxy); + g_signal_connect(G_OBJECT(priv->proxy), "destroy", + G_CALLBACK(proxy_destroy), self); + + dbus_g_object_register_marshaller(_status_provider_telepathy_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; +} + +static void +status_provider_telepathy_dispose (GObject *object) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(object); + + if (priv->proxy != NULL) { + g_object_unref(priv->proxy); + priv->proxy = NULL; + } + + G_OBJECT_CLASS (status_provider_telepathy_parent_class)->dispose (object); + return; +} + +static void +status_provider_telepathy_finalize (GObject *object) +{ + + G_OBJECT_CLASS (status_provider_telepathy_parent_class)->finalize (object); + return; +} + +/** + status_provider_telepathy_new: + + Creates a new #StatusProviderTelepathy object. No parameters or anything + like that. Just a convience function. + + Return value: A new instance of #StatusProviderTelepathy +*/ +StatusProvider * +status_provider_telepathy_new (void) +{ + return STATUS_PROVIDER(g_object_new(STATUS_PROVIDER_TELEPATHY_TYPE, NULL)); +} + +static void +set_status (StatusProvider * sp, StatusProviderStatus status) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_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) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(sp); + + if (priv->proxy == NULL) { + return mc_to_sp_map[MC_STATUS_OFFLINE]; + } + + return mc_to_sp_map[priv->mc_status]; +} + +static void +changed_status (DBusGProxy * proxy, guint status, gchar * message, StatusProvider * sp) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_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; + } + + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_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-telepathy.h b/src/status-provider-telepathy.h new file mode 100644 index 0000000..a67ee40 --- /dev/null +++ b/src/status-provider-telepathy.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_TELEPATHY_H__ +#define __STATUS_PROVIDER_TELEPATHY_H__ + +#include <glib.h> +#include <glib-object.h> + +#include "status-provider.h" + +G_BEGIN_DECLS + +#define STATUS_PROVIDER_TELEPATHY_TYPE (status_provider_telepathy_get_type ()) +#define STATUS_PROVIDER_TELEPATHY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathy)) +#define STATUS_PROVIDER_TELEPATHY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyClass)) +#define IS_STATUS_PROVIDER_TELEPATHY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STATUS_PROVIDER_TELEPATHY_TYPE)) +#define IS_STATUS_PROVIDER_TELEPATHY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STATUS_PROVIDER_TELEPATHY_TYPE)) +#define STATUS_PROVIDER_TELEPATHY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyClass)) + + +typedef struct _StatusProviderTelepathyClass StatusProviderTelepathyClass; +struct _StatusProviderTelepathyClass { + StatusProviderClass parent_class; +}; + +typedef struct _StatusProviderTelepathy StatusProviderTelepathy; +struct _StatusProviderTelepathy { + StatusProvider parent; +}; + +GType status_provider_telepathy_get_type (void); +StatusProvider * status_provider_telepathy_new (void); + +G_END_DECLS + +#endif diff --git a/src/status-provider-telepathy.list b/src/status-provider-telepathy.list new file mode 100644 index 0000000..5ab45bf --- /dev/null +++ b/src/status-provider-telepathy.list @@ -0,0 +1 @@ +VOID:UINT,STRING diff --git a/src/status-provider.c b/src/status-provider.c index 83d44ac..1139e54 100644 --- a/src/status-provider.c +++ b/src/status-provider.c @@ -99,10 +99,3 @@ status_provider_get_status (StatusProvider * sp) return class->get_status(sp); } -void -status_provider_emit_status_changed (StatusProvider * sp, StatusProviderStatus newstatus) -{ - g_return_if_fail(IS_STATUS_PROVIDER(sp)); - g_signal_emit(sp, signals[STATUS_CHANGED], 0, newstatus, TRUE); - return; -} diff --git a/src/status-provider.h b/src/status-provider.h index 9cc9885..522e61b 100644 --- a/src/status-provider.h +++ b/src/status-provider.h @@ -72,8 +72,6 @@ GType status_provider_get_type (void); void status_provider_set_status (StatusProvider * sp, StatusProviderStatus status); StatusProviderStatus status_provider_get_status (StatusProvider * sp); -void status_provider_emit_status_changed (StatusProvider * sp, StatusProviderStatus newstatus); - G_END_DECLS #endif diff --git a/src/status-service.c b/src/status-service.c index 5a9d9b5..14d8a34 100644 --- a/src/status-service.c +++ b/src/status-service.c @@ -39,11 +39,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "status-provider.h" #include "status-provider-pidgin.h" +#include "status-provider-telepathy.h" typedef StatusProvider * (*newfunc) (void); -#define STATUS_PROVIDER_CNT 1 +#define STATUS_PROVIDER_CNT 2 static newfunc status_provider_newfuncs[STATUS_PROVIDER_CNT] = { - status_provider_pidgin_new + status_provider_pidgin_new, + status_provider_telepathy_new }; static StatusProvider * status_providers[STATUS_PROVIDER_CNT] = { 0 }; @@ -73,12 +75,12 @@ static StatusProviderStatus global_status = STATUS_PROVIDER_STATUS_OFFLINE; static void status_update (void) { StatusProviderStatus oldglobal = global_status; - global_status = STATUS_PROVIDER_STATUS_ONLINE; + global_status = STATUS_PROVIDER_STATUS_OFFLINE; int i; for (i = 0; i < STATUS_PROVIDER_CNT; i++) { StatusProviderStatus localstatus = status_provider_get_status(status_providers[i]); - if (localstatus > global_status) { + if (localstatus < global_status) { global_status = localstatus; } } |