From 8a1dae9a1e1ce8cb59bca4196f1cfc41ea4338df Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 16 Sep 2009 17:08:31 -0500 Subject: Creating a status provider object for Mission Control 5 based on the Telepathy one. --- .bzrignore | 2 + src/Makefile.am | 17 ++ src/status-provider-mc5.c | 383 +++++++++++++++++++++++++++++++++++++++++++ src/status-provider-mc5.h | 56 +++++++ src/status-provider-mc5.list | 1 + 5 files changed, 459 insertions(+) create mode 100644 src/status-provider-mc5.c create mode 100644 src/status-provider-mc5.h create mode 100644 src/status-provider-mc5.list 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 + +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 . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "status-provider.h" +#include "status-provider-mc5.h" +#include "status-provider-mc5-marshal.h" + +#include + +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 + +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 . +*/ + +#ifndef __STATUS_PROVIDER_MC5_H__ +#define __STATUS_PROVIDER_MC5_H__ + +#include +#include + +#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 -- cgit v1.2.3 From d099f107194dd103d79a73cdbe5660bf7e8d1d3b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 16 Sep 2009 17:09:30 -0500 Subject: Linking in the MC5 provider --- src/status-service.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/status-service.c b/src/status-service.c index fe02dd0..37ae7c4 100644 --- a/src/status-service.c +++ b/src/status-service.c @@ -40,12 +40,14 @@ with this program. If not, see . #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 }; -- cgit v1.2.3 From 52f5e42c44f8b2359d5e9a4fe639ba9cfe956100 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Sep 2009 14:07:29 -0500 Subject: Ignoring GConf schemas --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index dd58cdf..8c2c2c7 100644 --- a/.bzrignore +++ b/.bzrignore @@ -46,3 +46,4 @@ 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 -- cgit v1.2.3 From 4c0e277688134ff411c98ff0ac39028c67ac8f3f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 17:16:10 -0500 Subject: Adding in a libempathy dependency. --- configure.ac | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index fa7a941..33923e8 100644 --- a/configure.ac +++ b/configure.ac @@ -36,8 +36,10 @@ AC_SUBST(APPLET_CFLAGS) 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) -- cgit v1.2.3 From 649bb7471958f9c43945d5ceacb1e913d3743818 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 17:17:25 -0500 Subject: Oh, got the header and it works too! Nice. --- src/status-provider-mc5.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 300818d..43a52f5 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -24,6 +24,8 @@ with this program. If not, see . #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" -- cgit v1.2.3 From 79e497d685774b2dbb310c54b7e587bd082f07d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Sep 2009 17:06:01 -0500 Subject: Turning over to Empathy Account Manager. --- src/status-provider-mc5.c | 271 +++++----------------------------------------- 1 file changed, 27 insertions(+), 244 deletions(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 43a52f5..5252e17 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -32,40 +32,28 @@ with this program. If not, see . #include -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 gchar * sp_to_mc_map[] = { + /* STATUS_PROVIDER_STATUS_ONLINE, */ "available", + /* STATUS_PROVIDER_STATUS_AWAY, */ "away", + /* STATUS_PROVIDER_STATUS_DND */ "busy", + /* STATUS_PROVIDER_STATUS_INVISIBLE*/ "invisible", + /* STATUS_PROVIDER_STATUS_OFFLINE */ "offline", + /* STATUS_PROVIDER_STATUS_DISCONNECTED*/NULL }; -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 +static TpConnectionPresenceType sp_to_tp_map[] = { + /* 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 }; typedef struct _StatusProviderMC5Private StatusProviderMC5Private; struct _StatusProviderMC5Private { - DBusGProxy * proxy; - DBusGProxy * dbus_proxy; - mc_status_t mc_status; + EmpathyAccountManager * manager; + StatusProviderStatus status; }; #define STATUS_PROVIDER_MC5_GET_PRIVATE(o) \ @@ -78,13 +66,8 @@ 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); @@ -112,127 +95,9 @@ 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; + priv->status = STATUS_PROVIDER_STATUS_OFFLINE; + priv->manager = EMPATHY_ACCOUNT_MANAGER(g_object_new(EMPATHY_TYPE_ACCOUNT_MANAGER, NULL)); - 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; } @@ -241,9 +106,9 @@ 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; + if (priv->manager != NULL) { + g_object_unref(priv->manager); + priv->manager = NULL; } G_OBJECT_CLASS (status_provider_mc5_parent_class)->dispose (object); @@ -276,54 +141,14 @@ 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; + if (priv->manager == NULL) { + priv->status = STATUS_PROVIDER_STATUS_DISCONNECTED; return; } - priv->mc_status = sp_to_mc_map[status]; + priv->status = 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; - } + empathy_account_manager_request_global_presence(priv->manager, sp_to_tp_map[status], sp_to_mc_map[status], ""); return; } @@ -334,52 +159,10 @@ 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) { + if (priv->manager == 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; + return priv->status; } -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; -} -- cgit v1.2.3 From 4ec8c425cac932ff2d30f7e46f6bd79142384a50 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Sep 2009 17:22:04 -0500 Subject: Connecting to change signal --- src/status-provider-mc5.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 5252e17..8ee174b 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -68,6 +68,7 @@ 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); @@ -98,6 +99,8 @@ status_provider_mc5_init (StatusProviderMC5 *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; } @@ -166,3 +169,14 @@ get_status (StatusProvider * sp) return priv->status; } +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); + + priv->status = type; + + return; +} -- cgit v1.2.3 From 4b30518d4f8b96d95e004829e7a4ebed4b67930c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Sep 2009 17:26:36 -0500 Subject: Putting in the TP Connection enum map --- src/status-provider-mc5.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 8ee174b..0251675 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -32,7 +32,7 @@ with this program. If not, see . #include -static gchar * sp_to_mc_map[] = { +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", @@ -41,7 +41,7 @@ static gchar * sp_to_mc_map[] = { /* STATUS_PROVIDER_STATUS_DISCONNECTED*/NULL }; -static TpConnectionPresenceType sp_to_tp_map[] = { +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, @@ -50,6 +50,18 @@ static TpConnectionPresenceType sp_to_tp_map[] = { /* 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; @@ -176,7 +188,7 @@ presence_changed (EmpathyAccountManager * eam, guint type, const gchar * type_st g_debug("MC5 Status changed: %d %s %s", type, type_str, message); - priv->status = type; + priv->status = tp_to_sp_map[type]; return; } -- cgit v1.2.3 From 62fbd1f460c253a9a9770ec37a916dd2f55335dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Sep 2009 17:28:19 -0500 Subject: If the global status changes then we need to signal everyone else about it. --- src/status-provider-mc5.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 0251675..a9342a1 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -188,7 +188,10 @@ presence_changed (EmpathyAccountManager * eam, guint type, const gchar * type_st g_debug("MC5 Status changed: %d %s %s", type, type_str, message); - priv->status = tp_to_sp_map[type]; + 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; } -- cgit v1.2.3 From 62c31bdc05a8084428133282dd78f9672f876b67 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Sep 2009 20:43:19 -0500 Subject: Comments are good. --- src/status-provider-mc5.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index a9342a1..45690ba 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -84,6 +84,8 @@ static void presence_changed (EmpathyAccountManager * eam, guint type, const gch 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) { @@ -102,7 +104,10 @@ status_provider_mc5_class_init (StatusProviderMC5Class *klass) 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) { @@ -116,6 +121,8 @@ status_provider_mc5_init (StatusProviderMC5 *self) return; } +/* Unref the account manager and move on. Sadly, we're + leaving the show. */ static void status_provider_mc5_dispose (GObject *object) { @@ -130,6 +137,7 @@ status_provider_mc5_dispose (GObject *object) return; } +/* Pass to superclass */ static void status_provider_mc5_finalize (GObject *object) { @@ -152,6 +160,10 @@ 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) { @@ -168,6 +180,8 @@ set_status (StatusProvider * sp, StatusProviderStatus status) return; } +/* Gets the status, uses the cached value that we have. Asking + would just be painful. */ static StatusProviderStatus get_status (StatusProvider * sp) { @@ -181,6 +195,9 @@ get_status (StatusProvider * sp) 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) { @@ -195,3 +212,4 @@ presence_changed (EmpathyAccountManager * eam, guint type, const gchar * type_st return; } + -- cgit v1.2.3 From 65a22368f4214bc9b22f65a212bc776c2e4c295a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 08:08:05 -0500 Subject: Bad string, should have been hidden. --- src/status-provider-mc5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 45690ba..42e8e0f 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -36,7 +36,7 @@ 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*/ "invisible", + /* STATUS_PROVIDER_STATUS_INVISIBLE*/ "hidden", /* STATUS_PROVIDER_STATUS_OFFLINE */ "offline", /* STATUS_PROVIDER_STATUS_DISCONNECTED*/NULL }; -- cgit v1.2.3 From a3fffae0121c46aad258f15f0bc4c8c3012536fc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 14:04:06 -0500 Subject: Don't set the status so that we notice when it comes back to us. --- src/status-provider-mc5.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/status-provider-mc5.c b/src/status-provider-mc5.c index 42e8e0f..813ce3e 100644 --- a/src/status-provider-mc5.c +++ b/src/status-provider-mc5.c @@ -173,8 +173,6 @@ set_status (StatusProvider * sp, StatusProviderStatus status) return; } - priv->status = status; - empathy_account_manager_request_global_presence(priv->manager, sp_to_tp_map[status], sp_to_mc_map[status], ""); return; -- cgit v1.2.3 From 73f4d4e7e1c6a5db370848797923481a7ee4ef43 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 11:25:58 -0500 Subject: Don't check range twice here --- src/users-service.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/users-service.c b/src/users-service.c index 51c6c5d..9ebf5f5 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -204,25 +204,22 @@ rebuild_items (DbusmenuMenuitem *root, g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); } - if (count > 1 && count < 7) + if (count > MINIMUM_USERS && count < MAXIMUM_USERS) { - if (count > MINIMUM_USERS && count < MAXIMUM_USERS) + if (users != NULL) { - if (users != NULL) - { - GList *l = NULL; - - for (l = users; l != NULL; l = l->next) - { - users = g_list_delete_link (users, l); - } + GList *l = NULL; - users = NULL; + for (l = users; l != NULL; l = l->next) + { + users = g_list_delete_link (users, l); } - users = users_service_dbus_get_user_list (service); + users = NULL; } + users = users_service_dbus_get_user_list (service); + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); for (u = users; u != NULL; u = g_list_next (u)) -- cgit v1.2.3