From efd24605727ee979b35053397463246456cf0ed0 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 10 Sep 2009 16:26:01 -0500 Subject: work in progress --- src/Makefile.am | 22 ++- src/dbus-shared-names.h | 14 +- src/status-service.c | 16 +- src/users-service-dbus.c | 379 +++++++++++++++++++++++++++++++++++++++++++++++ src/users-service-dbus.h | 73 +++++++++ src/users-service.c | 144 +++++++++++++----- src/users-service.xml | 56 +++++++ 7 files changed, 656 insertions(+), 48 deletions(-) create mode 100644 src/users-service-dbus.c create mode 100644 src/users-service-dbus.h create mode 100644 src/users-service.xml diff --git a/src/Makefile.am b/src/Makefile.am index e2f0008..f7fa7a7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,8 @@ sessionlib_LTLIBRARIES = libsession.la libsession_la_SOURCES = \ indicator-session.c \ dbus-shared-names.h \ - status-service-client.h + status-service-client.h \ + users-service-client.h libsession_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror libsession_la_LIBADD = $(APPLET_LIBS) libsession_la_LDFLAGS = -module -avoid-version @@ -25,6 +26,9 @@ indicator_status_service_SOURCES = \ status-service-dbus.h \ status-service-dbus.c \ status-service-server.h \ + users-service-dbus.h \ + users-service-dbus.c \ + users-service-server.h \ status-provider.h \ status-provider.c \ status-provider-pidgin.h \ @@ -38,6 +42,20 @@ indicator_status_service_SOURCES = \ indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror indicator_status_service_LDADD = $(STATUSSERVICE_LIBS) +users-service-client.h: $(srcdir)/users-service.xml + dbus-binding-tool \ + --prefix=_users_service_client \ + --mode=glib-client \ + --output=users-service-client.h \ + $(srcdir)/users-service.xml + +users-service-server.h: $(srcdir)/users-service.xml + dbus-binding-tool \ + --prefix=_users_service_server \ + --mode=glib-server \ + --output=users-service-server.h \ + $(srcdir)/users-service.xml + status-service-client.h: $(srcdir)/status-service.xml dbus-binding-tool \ --prefix=_status_service_client \ @@ -93,6 +111,8 @@ indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS) ############### BUILT_SOURCES = \ + users-service-client.h \ + users-service-server.h \ status-service-client.h \ status-service-server.h \ status-provider-pidgin-marshal.h \ diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index a645830..7e7d456 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -7,16 +7,16 @@ 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 +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 +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 +You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -31,6 +31,8 @@ with this program. If not, see . #define INDICATOR_USERS_DBUS_NAME "org.ayatana.indicator.users" #define INDICATOR_USERS_DBUS_OBJECT "/org/ayatana/indicator/users/menu" +#define INDICATOR_USERS_SERVICE_DBUS_OBJECT "/org/gnome/DisplayManager/UserManager" +#define INDICATOR_USERS_SERVICE_DBUS_INTERFACE "org.gnome.DisplayManager.UserManager" #define INDICATOR_SESSION_DBUS_NAME "org.ayatana.indicator.session" #define INDICATOR_SESSION_DBUS_OBJECT "/org/ayatana/indicator/session/menu" diff --git a/src/status-service.c b/src/status-service.c index b210dcd..542317a 100644 --- a/src/status-service.c +++ b/src/status-service.c @@ -7,16 +7,16 @@ 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 +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 +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 +You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -228,12 +228,12 @@ main (int argc, char ** argv) if (!org_freedesktop_DBus_request_name(bus_proxy, INDICATOR_STATUS_DBUS_NAME, 0, &nameret, &error)) { g_error("Unable to call to request name"); return 1; - } + } if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { g_error("Unable to get name"); return 1; - } + } g_idle_add(build_providers, NULL); diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c new file mode 100644 index 0000000..95b0f49 --- /dev/null +++ b/src/users-service-dbus.c @@ -0,0 +1,379 @@ +/* + * Copyright 2009 Canonical Ltd. + * + * Authors: + * Cody Russell + * + * 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 + +#include "dbus-shared-names.h" +#include "users-service-dbus.h" +#include "users-service-client.h" + +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); +static gboolean _users_service_server_count_users (UsersServiceDbus *service, + gint *count, + GError **error); +static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error); +static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + char **icon_url, + GError **error); +static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error); +static void users_loaded (DBusGProxy *proxy, + gpointer user_data); +static void user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data); + +#include "users-service-server.h" + +/* Private */ +typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; + +struct _UsersServiceDbusPrivate +{ + GList *users; + gint count; + + DBusGConnection *session_bus; + DBusGConnection *system_bus; + DBusGProxy *dbus_proxy_session; + DBusGProxy *dbus_proxy_system; +}; + +#define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) + +/* Signals */ +enum { + USERS_LOADED, + USER_ADDED, + USER_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +/* GObject Boilerplate */ +G_DEFINE_TYPE (UsersServiceDbus, users_service_dbus, G_TYPE_OBJECT); + +static void +users_service_dbus_class_init (UsersServiceDbusClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (UsersServiceDbusPrivate)); + + object_class->dispose = users_service_dbus_dispose; + object_class->finalize = users_service_dbus_finalize; + + signals[USERS_LOADED] = g_signal_new ("users-loaded", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, users_loaded), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[USER_ADDED] = g_signal_new ("user-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_added), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); + + signals[USER_REMOVED] = g_signal_new ("user-removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); + + dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); +} + +static void +users_service_dbus_init (UsersServiceDbus *self) +{ + GError *error = NULL; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + priv->users = NULL; + priv->count = 0; + + /* Get the buses */ + priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_error ("Unable to get session bus: %s", error->message); + g_error_free (error); + + return; + } + + priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (error != NULL) { + g_error("Unable to get system bus: %s", error->message); + g_error_free(error); + + return; + } + + dbus_g_connection_register_g_object (priv->session_bus, + INDICATOR_USERS_SERVICE_DBUS_OBJECT, + G_OBJECT (self)); + + /* Set up the DBUS service proxies */ + priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error ("Unable to get dbus proxy on session bus: %s", error->message); + g_error_free (error); + + return; + } + + priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); + + return; + } + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UsersLoaded", + G_CALLBACK (users_loaded), + self, + NULL); + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UserAdded", + G_CALLBACK (user_added), + self, + NULL); + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UserRemoved", + G_CALLBACK (user_removed), + self, + NULL); +} + +static void +users_service_dbus_dispose (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); +} + +static void +users_service_dbus_finalize (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); +} + +static void +users_loaded (DBusGProxy *proxy, + gpointer user_data) +{ + UsersServiceDbus *service; + UsersServiceDbusPrivate *priv; + GError *error = NULL; + GArray *uids; + GPtrArray *users_info; + gint count; + int i; + + service = (UsersServiceDbus *)user_data; + priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + + if (!org_gnome_DisplayManager_UserManager_count_users (proxy, + &count, + &error)) + { + g_warning ("failed to retrieve user count: %s", error->message); + g_error_free (error); + + return; + } + + priv->count = count; + + if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, + &uids, + &error)) + { + g_warning ("failed to retrieve user list: %s", error->message); + g_error_free (error); + + return; + } + + if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, + uids, + &users_info, + &error)) + { + g_warning ("failed to retrieve user info: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < users_info->len; i++) + { + UserData *data = g_ptr_array_index (users_info, i); + + priv->users = g_list_prepend (priv->users, data); + } +} + +gint +users_service_dbus_get_user_count (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->count; +} + +GList * +users_service_dbus_get_user_list (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->users; +} + +static void +user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + UserData *user = g_new0 (UserData, 1); + GError *error = NULL; + + priv->count++; + + if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, + uid, + &user->user_name, + &user->real_name, + &user->shell, + &user->icon_url, + &error)) + { + g_warning ("unable to retrieve user info: %s", error->message); + g_error_free (error); + + g_free (user); + + return; + } + + user->uid = uid; + + priv->users = g_list_prepend (priv->users, user); + + g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); +} + +static void +user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GList *l; + + priv->count--; + + for (l = priv->users; l != NULL; l = g_list_next (l)) + { + UserData *user = (UserData *)l->data; + + if (user->uid == uid) + { + priv->users = g_list_remove (priv->users, l->data); + g_signal_emit (G_OBJECT (service), signals[USER_REMOVED], 0, user, TRUE); + } + } +} + +static gboolean +_users_service_server_count_users (UsersServiceDbus *service, + gint *uids, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + char **icon_url, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error) +{ + return TRUE; +} diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h new file mode 100644 index 0000000..df07e61 --- /dev/null +++ b/src/users-service-dbus.h @@ -0,0 +1,73 @@ +/* + * Copyright 2009 Canonical Ltd. + * + * Authors: + * Cody Russell + * + * 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 __USERS_SERVICE_DBUS_H__ +#define __USERS_SERVICE_DBUS_H__ + +#include +#include + +G_BEGIN_DECLS + +#define USERS_SERVICE_DBUS_TYPE (users_service_dbus_get_type ()) +#define USERS_SERVICE_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbus)) +#define USERS_SERVICE_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusClass)) +#define IS_USERS_SERVICE_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), USERS_SERVICE_DBUS_TYPE)) +#define IS_USERS_SERVICE_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), USERS_SERVICE_DBUS_TYPE)) +#define USERS_SERVICE_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusClass)) + +typedef struct _UsersServiceDbus UsersServiceDbus; +typedef struct _UsersServiceDbusClass UsersServiceDbusClass; +typedef struct _UserData UserData; + +struct _UserData +{ + guint64 uid; + gchar *user_name; + gchar *real_name; + gchar *shell; + gchar *icon_url; +}; + +struct _UsersServiceDbus { + GObject parent; +}; + +struct _UsersServiceDbusClass { + GObjectClass parent_class; + + /* Signals */ + gboolean (*user_changed) (UsersServiceDbus *self, gchar **name, gpointer user_data); + gboolean (*users_icons_changed) (UsersServiceDbus *self, GArray **icons, gpointer user_data); + + void (* users_loaded) (UsersServiceDbus *self, gpointer user_data); + + void (* user_added) (UsersServiceDbus *self, gint64 uid, gpointer user_data); + void (* user_removed) (UsersServiceDbus *self, gint64 uid, gpointer user_data); + void (* user_updated) (UsersServiceDbus *self, gint64 uid, gpointer user_data); +}; + +GType users_service_dbus_get_type (void) G_GNUC_CONST; + +gint users_service_dbus_get_user_count (UsersServiceDbus *self); +GList *users_service_dbus_get_user_list (UsersServiceDbus *self); + +G_END_DECLS + +#endif diff --git a/src/users-service.c b/src/users-service.c index 5db832b..77b5f95 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -7,16 +7,16 @@ 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 +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 +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 +You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -31,15 +31,22 @@ with this program. If not, see . #include #include "dbus-shared-names.h" +#include "users-service-dbus.h" #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" +#define MINIMUM_USERS 1 +#define MAXIMUM_USERS 7 -static DBusGConnection * session_bus = NULL; -static DBusGConnection * system_bus = NULL; -static DBusGProxy * bus_proxy = NULL; -static DBusGProxy * gdm_proxy = NULL; -static DbusmenuMenuitem * root_menuitem = NULL; -static GMainLoop * mainloop = NULL; +static DBusGConnection *session_bus = NULL; +static DBusGConnection *system_bus = NULL; +static DBusGProxy *bus_proxy = NULL; +static DBusGProxy *gdm_proxy = NULL; +static DbusmenuMenuitem *root_menuitem = NULL; +static GMainLoop *mainloop = NULL; +static UsersServiceDbus *dbus_interface = NULL; + +static gint count; +static GList *users; static gboolean check_guest_session (void) @@ -108,24 +115,84 @@ activate_new_session (DbusmenuMenuitem * mi, gpointer user_data) } static void -create_items (DbusmenuMenuitem * root) { - DbusmenuMenuitem * mi = NULL; - - if (check_guest_session()) { - mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Guest Session")); - dbusmenu_menuitem_child_append(root, mi); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_guest_session), NULL); - } +activate_user_session (DbusmenuMenuitem *mi, gpointer user_data) +{ +} - if (check_new_session()) { - mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); - dbusmenu_menuitem_child_append(root, mi); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_new_session), NULL); - } +static void +remove_menu_item (DbusmenuMenuitem *root, gpointer user_data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)user_data; - return; + dbusmenu_menuitem_child_delete (root, child); +} + +static void +rebuild_items (DbusmenuMenuitem *root, + UsersServiceDbus *service) +{ + DbusmenuMenuitem *mi = NULL; + GList *u; + UserData *user; + + if (check_guest_session ()) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Guest Session")); + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); + } + + if (count > 1 && count < 7) + { + for (u = users; u != NULL; u = g_list_next (u)) + { + user = u->data; + + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); + } + } + + if (check_new_session ()) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + } +} + +static void +create_items (DbusmenuMenuitem *root, + UsersServiceDbus *service) +{ + g_return_if_fail (IS_USERS_SERVICE_DBUS (service)); + + dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); + + count = users_service_dbus_get_user_count (service); + if (count > 1 && count < 7) + { + users = users_service_dbus_get_user_list (service); + } + + rebuild_items (root, service); +} + +static void +user_added (UsersServiceDbus *service, + gpointer user_data) +{ + /* Never thought you'd see a gpointer user_data get casted to a UserData* did you? */ + users = g_list_append (users, (UserData *) user_data); +} + +static void +user_removed (UsersServiceDbus *service, + gpointer user_data) +{ + users = g_list_remove (users, (UserData *) user_data); } int @@ -134,28 +201,39 @@ main (int argc, char ** argv) g_type_init(); session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + bus_proxy = dbus_g_proxy_new_for_name (session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); GError * error = NULL; guint nameret = 0; if (!org_freedesktop_DBus_request_name(bus_proxy, INDICATOR_USERS_DBUS_NAME, 0, &nameret, &error)) { g_error("Unable to call to request name"); return 1; - } + } if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { g_error("Unable to get name"); return 1; - } + } + + dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); root_menuitem = dbusmenu_menuitem_new(); - g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem)); + g_debug ("Root ID: %d", dbusmenu_menuitem_get_id (root_menuitem)); - create_items(root_menuitem); + create_items (root_menuitem, dbus_interface); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_USERS_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); + g_signal_connect (G_OBJECT (dbus_interface), + "user-added", + G_CALLBACK (user_added), + root_menuitem); + g_signal_connect (G_OBJECT (dbus_interface), + "user-removed", + G_CALLBACK (user_removed), + root_menuitem); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/src/users-service.xml b/src/users-service.xml new file mode 100644 index 0000000..9eccf5d --- /dev/null +++ b/src/users-service.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From a29d1126f86a164d598cda4e4bf000c8afc675c7 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 10 Sep 2009 16:33:12 -0500 Subject: fix link problem --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index f7fa7a7..ffce9b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,7 +94,7 @@ status-provider-telepathy-marshal.c: $(srcdir)/status-provider-telepathy.list # Users Stuff ############### -indicator_users_service_SOURCES = users-service.c +indicator_users_service_SOURCES = users-service.c users-service-dbus.c indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror indicator_users_service_LDADD = $(USERSSERVICE_LIBS) -- cgit v1.2.3 From 51bdf6d04ac6b98019c760c7f12f4315c09cdcb8 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 10 Sep 2009 19:49:40 -0500 Subject: fixes for adding/removing users --- src/users-service-dbus.h | 4 ++-- src/users-service.c | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index df07e61..5889aba 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -58,8 +58,8 @@ struct _UsersServiceDbusClass { void (* users_loaded) (UsersServiceDbus *self, gpointer user_data); - void (* user_added) (UsersServiceDbus *self, gint64 uid, gpointer user_data); - void (* user_removed) (UsersServiceDbus *self, gint64 uid, gpointer user_data); + void (* user_added) (UsersServiceDbus *self, UserData *user, gpointer user_data); + void (* user_removed) (UsersServiceDbus *self, UserData *user, gpointer user_data); void (* user_updated) (UsersServiceDbus *self, gint64 uid, gpointer user_data); }; diff --git a/src/users-service.c b/src/users-service.c index 77b5f95..7c8ab01 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -6,6 +6,7 @@ Copyright 2009 Canonical Ltd. Authors: Ted Gould + Cody Russell 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 @@ -135,6 +136,8 @@ rebuild_items (DbusmenuMenuitem *root, GList *u; UserData *user; + dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); + if (check_guest_session ()) { mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Guest Session")); @@ -169,8 +172,6 @@ create_items (DbusmenuMenuitem *root, { g_return_if_fail (IS_USERS_SERVICE_DBUS (service)); - dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); - count = users_service_dbus_get_user_count (service); if (count > 1 && count < 7) { @@ -182,17 +183,26 @@ create_items (DbusmenuMenuitem *root, static void user_added (UsersServiceDbus *service, + UserData *user, gpointer user_data) { - /* Never thought you'd see a gpointer user_data get casted to a UserData* did you? */ - users = g_list_append (users, (UserData *) user_data); + DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + + users = g_list_append (users, user); + + rebuild_items (root, service); } static void user_removed (UsersServiceDbus *service, + UserData *user, gpointer user_data) { - users = g_list_remove (users, (UserData *) user_data); + DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + + users = g_list_remove (users, user); + + rebuild_items (root, service); } int @@ -217,7 +227,7 @@ main (int argc, char ** argv) dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); - root_menuitem = dbusmenu_menuitem_new(); + root_menuitem = dbusmenu_menuitem_new (); g_debug ("Root ID: %d", dbusmenu_menuitem_get_id (root_menuitem)); create_items (root_menuitem, dbus_interface); -- cgit v1.2.3 From 91c2993398771ca1ff5a65003c681724291d9e2f Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 14:52:45 -0500 Subject: dbus fu updates --- src/Makefile.am | 16 +++- src/users-service-dbus.c | 221 +++++++++++++++++++++++++++++++++++++---------- src/users-service-dbus.h | 10 ++- src/users-service.c | 19 ++++ src/users-service.list | 1 + src/users-service.xml | 24 ++--- 6 files changed, 226 insertions(+), 65 deletions(-) create mode 100644 src/users-service.list diff --git a/src/Makefile.am b/src/Makefile.am index ffce9b3..6404af0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,8 @@ indicator_status_service_SOURCES = \ users-service-dbus.h \ users-service-dbus.c \ users-service-server.h \ + users-service-marshal.c \ + users-service-marshal.h \ status-provider.h \ status-provider.c \ status-provider-pidgin.h \ @@ -70,6 +72,16 @@ status-service-server.h: $(srcdir)/status-service.xml --output=status-service-server.h \ $(srcdir)/status-service.xml +users-service-marshal.h: $(srcdir)/users-service.list + glib-genmarshal --header \ + --prefix=_users_service_marshal $(srcdir)/users-service.list \ + > users-service-marshal.h + +users-service-marshal.c: $(srcdir)/users-service.list + glib-genmarshal --body \ + --prefix=_users_service_marshal $(srcdir)/users-service.list \ + > users-service-marshal.c + status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list glib-genmarshal --header \ --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ @@ -94,7 +106,7 @@ status-provider-telepathy-marshal.c: $(srcdir)/status-provider-telepathy.list # Users Stuff ############### -indicator_users_service_SOURCES = users-service.c users-service-dbus.c +indicator_users_service_SOURCES = users-service.c users-service-dbus.c users-service-marshal.c indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror indicator_users_service_LDADD = $(USERSSERVICE_LIBS) @@ -115,6 +127,8 @@ BUILT_SOURCES = \ users-service-server.h \ status-service-client.h \ status-service-server.h \ + users-service-marshal.h \ + users-service-marshal.c \ status-provider-pidgin-marshal.h \ status-provider-pidgin-marshal.c \ status-provider-telepathy-marshal.h \ diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 95b0f49..ce22e6f 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -26,36 +26,44 @@ #include "dbus-shared-names.h" #include "users-service-dbus.h" #include "users-service-client.h" - -static void users_service_dbus_class_init (UsersServiceDbusClass *klass); -static void users_service_dbus_init (UsersServiceDbus *self); -static void users_service_dbus_dispose (GObject *object); -static void users_service_dbus_finalize (GObject *object); -static gboolean _users_service_server_count_users (UsersServiceDbus *service, - gint *count, - GError **error); -static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error); -static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - char **icon_url, - GError **error); -static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error); -static void users_loaded (DBusGProxy *proxy, - gpointer user_data); -static void user_added (DBusGProxy *proxy, - guint uid, - gpointer user_data); -static void user_removed (DBusGProxy *proxy, - guint uid, - gpointer user_data); +#include "users-service-marshal.h" + +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); +static gboolean _users_service_server_count_users (UsersServiceDbus *service, + gint *count, + GError **error); +static gboolean _users_service_server_get_users_loaded (UsersServiceDbus *self, + gboolean *is_loaded, + GError **error); +static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error); +static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + gint *login_count, + gchar **icon_url, + GError **error); +static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error); +static void users_loaded (DBusGProxy *proxy, + gpointer user_data); +static void user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_updated (DBusGProxy *proxy, + guint uid, + gpointer user_data); #include "users-service-server.h" @@ -71,6 +79,9 @@ struct _UsersServiceDbusPrivate DBusGConnection *system_bus; DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; + DBusGProxy *gdm_proxy; + + gchar *error; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -80,6 +91,7 @@ enum { USERS_LOADED, USER_ADDED, USER_REMOVED, + USER_UPDATED, LAST_SIGNAL }; @@ -111,16 +123,24 @@ users_service_dbus_class_init (UsersServiceDbusClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UsersServiceDbusClass, user_added), NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); signals[USER_REMOVED] = g_signal_new ("user-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed), NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); + + signals[USER_UPDATED] = g_signal_new ("user-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_updated), + NULL, NULL, + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); } @@ -140,6 +160,8 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get session bus: %s", error->message); g_error_free (error); + priv->error = g_strdup ("Failed to get session bus"); + return; } @@ -148,6 +170,8 @@ users_service_dbus_init (UsersServiceDbus *self) g_error("Unable to get system bus: %s", error->message); g_error_free(error); + priv->error = g_strdup ("Failed to get system bus"); + return; } @@ -161,42 +185,89 @@ users_service_dbus_init (UsersServiceDbus *self) DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) { - g_error ("Unable to get dbus proxy on session bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on session bus: %s", error->message); + g_error_free (error); - return; - } + priv->error = g_strdup ("Failed to get session proxy"); + + return; + } priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); - return; - } + priv->error = g_strdup ("Failed to get system proxy"); + + return; + } + + priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, // XXX ? + "org.gnome.DisplayManager", + "/org/gnome/DisplayManager/UserManager", + "org.gnome.DisplayManager.UserManager", + &error); + + if (error != NULL) + { + g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); + g_error_free (error); + + priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); + } + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UsersLoaded", + G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserAdded", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserRemoved", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserUpdated", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UsersLoaded", G_CALLBACK (users_loaded), self, NULL); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UserAdded", G_CALLBACK (user_added), self, NULL); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UserRemoved", G_CALLBACK (user_removed), self, NULL); + + dbus_g_proxy_connect_signal (priv->gdm_proxy, + "UserUpdated", + G_CALLBACK (user_updated), + self, + NULL); + + users_loaded (priv->gdm_proxy, self); } static void @@ -231,6 +302,7 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user count: %s", error->message); + priv->error = g_strdup_printf ("Failed to retrieve user count: %s", error->message); g_error_free (error); return; @@ -243,6 +315,8 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user list: %s", error->message); + priv->error = g_strdup_printf ("Failed to retrieve user list: %s", error->message); + g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -254,6 +328,8 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user info: %s", error->message); + priv->error = g_strdup_printf ("Failed to get user info: %s", error->message); + g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -261,7 +337,13 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { - UserData *data = g_ptr_array_index (users_info, i); + UserData *data; + + g_print (" -> setting up user %d\n", i); + + data = g_ptr_array_index (users_info, i); + + g_print (" * user_name: %s\n", data->user_name); priv->users = g_list_prepend (priv->users, data); } @@ -280,6 +362,11 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + g_print ("users_service_dbus_get_user_list()\n"); + + if (!priv->users) + g_print ("users_service_dbus_get_user_list(): priv->users is NULL\n"); + return priv->users; } @@ -300,6 +387,7 @@ user_added (DBusGProxy *proxy, &user->user_name, &user->real_name, &user->shell, + &user->login_count, &user->icon_url, &error)) { @@ -341,6 +429,26 @@ user_removed (DBusGProxy *proxy, } } +static void +user_updated (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GList *l; + + for (l = priv->users; l != NULL; l = g_list_next (l)) + { + UserData *user = (UserData *)l->data; + + if (user->uid == uid) + { + // XXX - update user data + } + } +} + static gboolean _users_service_server_count_users (UsersServiceDbus *service, gint *uids, @@ -357,12 +465,21 @@ _users_service_server_get_user_list (UsersServiceDbus *service, return TRUE; } +static gboolean +_users_service_server_get_users_loaded (UsersServiceDbus *self, + gboolean *is_loaded, + GError **error) +{ + return TRUE; +} + static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, const gint64 uid, gchar **username, gchar **real_name, gchar **shell, + gint *login_count, char **icon_url, GError **error) { @@ -377,3 +494,11 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } + +gchar * +users_service_dbus_get_error (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->error; +} diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 5889aba..370df2e 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -38,10 +38,11 @@ typedef struct _UserData UserData; struct _UserData { - guint64 uid; + uid_t uid; gchar *user_name; gchar *real_name; gchar *shell; + gint login_count; gchar *icon_url; }; @@ -58,15 +59,16 @@ struct _UsersServiceDbusClass { void (* users_loaded) (UsersServiceDbus *self, gpointer user_data); - void (* user_added) (UsersServiceDbus *self, UserData *user, gpointer user_data); - void (* user_removed) (UsersServiceDbus *self, UserData *user, gpointer user_data); + void (* user_added) (UsersServiceDbus *self, gint64 uid, gpointer user_data); + void (* user_removed) (UsersServiceDbus *self, gint64 uid, gpointer user_data); void (* user_updated) (UsersServiceDbus *self, gint64 uid, gpointer user_data); }; GType users_service_dbus_get_type (void) G_GNUC_CONST; gint users_service_dbus_get_user_count (UsersServiceDbus *self); -GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +gchar *users_service_dbus_get_error (UsersServiceDbus *self); G_END_DECLS diff --git a/src/users-service.c b/src/users-service.c index 7c8ab01..c7c2a53 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -135,6 +135,7 @@ rebuild_items (DbusmenuMenuitem *root, DbusmenuMenuitem *mi = NULL; GList *u; UserData *user; + gchar *error; dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); @@ -145,12 +146,26 @@ rebuild_items (DbusmenuMenuitem *root, g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); } + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, g_strdup_printf ("START (count is %d)", count)); + dbusmenu_menuitem_child_append (root, mi); + + error = users_service_dbus_get_error (service); + + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, g_strdup_printf ("ERROR: %s", error)); + dbusmenu_menuitem_child_append (root, mi); + + g_print ("count == %d\n", count); + if (count > 1 && count < 7) { for (u = users; u != NULL; u = g_list_next (u)) { user = u->data; + g_print ("user->real_name == %s\n", user->real_name); + mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); dbusmenu_menuitem_child_append (root, mi); @@ -158,6 +173,10 @@ rebuild_items (DbusmenuMenuitem *root, } } + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, "END"); + dbusmenu_menuitem_child_append (root,mi); + if (check_new_session ()) { mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); diff --git a/src/users-service.list b/src/users-service.list new file mode 100644 index 0000000..36f34ba --- /dev/null +++ b/src/users-service.list @@ -0,0 +1 @@ +VOID:INT64 diff --git a/src/users-service.xml b/src/users-service.xml index 9eccf5d..c90f1e8 100644 --- a/src/users-service.xml +++ b/src/users-service.xml @@ -18,6 +18,7 @@ + @@ -25,23 +26,17 @@ - + - - + + + + - + - - - - - @@ -52,5 +47,10 @@ + + + + + -- cgit v1.2.3 From 15e2e5192dce211e3d6d8f4dfa0bf1690ca3a77d Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 15:42:19 -0500 Subject: register marshallers --- src/users-service-dbus.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index ce22e6f..18a1b2a 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -224,23 +224,28 @@ users_service_dbus_init (UsersServiceDbus *self) priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); } + dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, + G_TYPE_NONE, + G_TYPE_INT64, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->gdm_proxy, "UsersLoaded", G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserAdded", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserRemoved", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserUpdated", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->gdm_proxy, -- cgit v1.2.3 From c4ff339c7576c83000b1a3695918d70e0124c098 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 16:57:01 -0500 Subject: fix dbus fu --- src/users-service-dbus.c | 47 ++++++++++++++++------------------------------- src/users-service-dbus.h | 3 +-- src/users-service.c | 7 ------- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 18a1b2a..e044fe8 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -80,8 +80,6 @@ struct _UsersServiceDbusPrivate DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; - - gchar *error; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -160,8 +158,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get session bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get session bus"); - return; } @@ -170,8 +166,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error("Unable to get system bus: %s", error->message); g_error_free(error); - priv->error = g_strdup ("Failed to get system bus"); - return; } @@ -190,8 +184,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get dbus proxy on session bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get session proxy"); - return; } @@ -205,12 +197,10 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get dbus proxy on system bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get system proxy"); - return; } - priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, // XXX ? + priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.gnome.DisplayManager", "/org/gnome/DisplayManager/UserManager", "org.gnome.DisplayManager.UserManager", @@ -220,8 +210,6 @@ users_service_dbus_init (UsersServiceDbus *self) { g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); g_error_free (error); - - priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); } dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, @@ -294,8 +282,8 @@ users_loaded (DBusGProxy *proxy, UsersServiceDbus *service; UsersServiceDbusPrivate *priv; GError *error = NULL; - GArray *uids; - GPtrArray *users_info; + GArray *uids = NULL; + GPtrArray *users_info = NULL; gint count; int i; @@ -307,7 +295,6 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user count: %s", error->message); - priv->error = g_strdup_printf ("Failed to retrieve user count: %s", error->message); g_error_free (error); return; @@ -315,26 +302,26 @@ users_loaded (DBusGProxy *proxy, priv->count = count; + uids = g_array_new (FALSE, FALSE, sizeof (gint64)); + if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, &uids, &error)) { g_warning ("failed to retrieve user list: %s", error->message); - priv->error = g_strdup_printf ("Failed to retrieve user list: %s", error->message); - g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; } + users_info = g_ptr_array_new (); + if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, uids, &users_info, &error)) { g_warning ("failed to retrieve user info: %s", error->message); - priv->error = g_strdup_printf ("Failed to get user info: %s", error->message); - g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -342,13 +329,19 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { + GValueArray *values; UserData *data; - g_print (" -> setting up user %d\n", i); + values = g_ptr_array_index (users_info, i); - data = g_ptr_array_index (users_info, i); + data = g_new0 (UserData, 1); - g_print (" * user_name: %s\n", data->user_name); + data->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + data->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + data->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + data->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + data->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + data->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); priv->users = g_list_prepend (priv->users, data); } @@ -499,11 +492,3 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } - -gchar * -users_service_dbus_get_error (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return priv->error; -} diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 370df2e..ecfaf6d 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -38,7 +38,7 @@ typedef struct _UserData UserData; struct _UserData { - uid_t uid; + gint64 uid; gchar *user_name; gchar *real_name; gchar *shell; @@ -68,7 +68,6 @@ GType users_service_dbus_get_type (void) G_GNUC_CONST; gint users_service_dbus_get_user_count (UsersServiceDbus *self); GList *users_service_dbus_get_user_list (UsersServiceDbus *self); -gchar *users_service_dbus_get_error (UsersServiceDbus *self); G_END_DECLS diff --git a/src/users-service.c b/src/users-service.c index c7c2a53..0a98983 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -135,7 +135,6 @@ rebuild_items (DbusmenuMenuitem *root, DbusmenuMenuitem *mi = NULL; GList *u; UserData *user; - gchar *error; dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); @@ -150,12 +149,6 @@ rebuild_items (DbusmenuMenuitem *root, dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, g_strdup_printf ("START (count is %d)", count)); dbusmenu_menuitem_child_append (root, mi); - error = users_service_dbus_get_error (service); - - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, g_strdup_printf ("ERROR: %s", error)); - dbusmenu_menuitem_child_append (root, mi); - g_print ("count == %d\n", count); if (count > 1 && count < 7) -- cgit v1.2.3 From 0e5b24c9c86750f4ce10f9a53846da049caeb179 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 16:58:03 -0500 Subject: cleanup --- src/users-service-dbus.c | 5 ----- src/users-service.c | 8 -------- 2 files changed, 13 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index e044fe8..8685105 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -360,11 +360,6 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - g_print ("users_service_dbus_get_user_list()\n"); - - if (!priv->users) - g_print ("users_service_dbus_get_user_list(): priv->users is NULL\n"); - return priv->users; } diff --git a/src/users-service.c b/src/users-service.c index 0a98983..4e36a56 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -145,20 +145,12 @@ rebuild_items (DbusmenuMenuitem *root, g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); } - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, g_strdup_printf ("START (count is %d)", count)); - dbusmenu_menuitem_child_append (root, mi); - - g_print ("count == %d\n", count); - if (count > 1 && count < 7) { for (u = users; u != NULL; u = g_list_next (u)) { user = u->data; - g_print ("user->real_name == %s\n", user->real_name); - mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); dbusmenu_menuitem_child_append (root, mi); -- cgit v1.2.3 From de28377d3ad3797516826f287f554dfefb7fdb47 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 17:31:31 -0500 Subject: some refactoring --- src/users-service-dbus.c | 89 ++++++++++++++++++++++++++++++++---------------- src/users-service.c | 4 --- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 8685105..acc3f7d 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -53,6 +53,9 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi const GArray *uids, GPtrArray **user_info, GError **error); +static void create_session_proxy (UsersServiceDbus *self); +static void create_system_proxy (UsersServiceDbus *self); +static void create_gdm_proxy (UsersServiceDbus *self); static void users_loaded (DBusGProxy *proxy, gpointer user_data); static void user_added (DBusGProxy *proxy, @@ -154,26 +157,57 @@ users_service_dbus_init (UsersServiceDbus *self) /* Get the buses */ priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error ("Unable to get session bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get session bus: %s", error->message); + g_error_free (error); - return; - } + return; + } priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (error != NULL) { - g_error("Unable to get system bus: %s", error->message); - g_error_free(error); + if (error != NULL) + { + g_error("Unable to get system bus: %s", error->message); + g_error_free(error); - return; - } + return; + } dbus_g_connection_register_g_object (priv->session_bus, INDICATOR_USERS_SERVICE_DBUS_OBJECT, G_OBJECT (self)); - /* Set up the DBUS service proxies */ + dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, + G_TYPE_NONE, + G_TYPE_INT64, + G_TYPE_INVALID); + + create_session_proxy (self); + create_system_proxy (self); + create_gdm_proxy (self); + + users_loaded (priv->gdm_proxy, self); +} + +static void +users_service_dbus_dispose (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); +} + +static void +users_service_dbus_finalize (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); +} + +static void +create_session_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, @@ -186,6 +220,13 @@ users_service_dbus_init (UsersServiceDbus *self) return; } +} + +static void +create_system_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, DBUS_SERVICE_DBUS, @@ -199,6 +240,13 @@ users_service_dbus_init (UsersServiceDbus *self) return; } +} + +static void +create_gdm_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.gnome.DisplayManager", @@ -212,11 +260,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error_free (error); } - dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, - G_TYPE_NONE, - G_TYPE_INT64, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->gdm_proxy, "UsersLoaded", G_TYPE_INVALID); @@ -259,20 +302,6 @@ users_service_dbus_init (UsersServiceDbus *self) G_CALLBACK (user_updated), self, NULL); - - users_loaded (priv->gdm_proxy, self); -} - -static void -users_service_dbus_dispose (GObject *object) -{ - G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); -} - -static void -users_service_dbus_finalize (GObject *object) -{ - G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } static void diff --git a/src/users-service.c b/src/users-service.c index 4e36a56..7c8ab01 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -158,10 +158,6 @@ rebuild_items (DbusmenuMenuitem *root, } } - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, "END"); - dbusmenu_menuitem_child_append (root,mi); - if (check_new_session ()) { mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); -- cgit v1.2.3 From 541259b2cb86b7393232f59e4f61366e52fe5cea Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 10:01:58 -0500 Subject: ck fu --- src/users-service-dbus.c | 458 ++++++++++++++++++++++++++++++++++++++++++----- src/users-service-dbus.h | 2 + 2 files changed, 419 insertions(+), 41 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index acc3f7d..b9e9391 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -21,6 +21,10 @@ #include "config.h" #endif +#include +#include +#include + #include #include "dbus-shared-names.h" @@ -56,6 +60,10 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi static void create_session_proxy (UsersServiceDbus *self); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); +static void create_seat_proxy (UsersServiceDbus *self); +static void create_ck_proxy (UsersServiceDbus *self); +static void create_cksession_proxy (UsersServiceDbus *self); +static gchar *get_seat (UsersServiceDbus *service); static void users_loaded (DBusGProxy *proxy, gpointer user_data); static void user_added (DBusGProxy *proxy, @@ -67,6 +75,16 @@ static void user_removed (DBusGProxy *proxy static void user_updated (DBusGProxy *proxy, guint uid, gpointer user_data); +static void seat_proxy_session_added (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service); +static void seat_proxy_session_removed (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service); +static gboolean maybe_add_session_for_user (UsersServiceDbus *service, + UserData *user, + const gchar *ssid); +static gchar * get_seat_internal (UsersServiceDbus *self); #include "users-service-server.h" @@ -75,14 +93,23 @@ typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; struct _UsersServiceDbusPrivate { - GList *users; - gint count; + GHashTable *users; + gint count; + gchar *seat; + gchar *ssid; DBusGConnection *session_bus; DBusGConnection *system_bus; + DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; + DBusGProxy *ck_proxy; + DBusGProxy *seat_proxy; + DBusGProxy *session_proxy; + + GHashTable *exclusions; + GHashTable *sessions; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -174,6 +201,16 @@ users_service_dbus_init (UsersServiceDbus *self) return; } + priv->exclusions = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); + + priv->users = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); + dbus_g_connection_register_g_object (priv->session_bus, INDICATOR_USERS_SERVICE_DBUS_OBJECT, G_OBJECT (self)); @@ -186,6 +223,8 @@ users_service_dbus_init (UsersServiceDbus *self) create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); + create_seat_proxy (self); + create_ck_proxy (self); users_loaded (priv->gdm_proxy, self); } @@ -233,12 +272,16 @@ create_system_proxy (UsersServiceDbus *self) DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) + + if (!priv->dbus_proxy_system) { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); - return; + return; + } } } @@ -254,10 +297,15 @@ create_gdm_proxy (UsersServiceDbus *self) "org.gnome.DisplayManager.UserManager", &error); - if (error != NULL) + if (!priv->gdm_proxy) { - g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); + g_error_free (error); + } + + return; } dbus_g_proxy_add_signal (priv->gdm_proxy, @@ -304,6 +352,329 @@ create_gdm_proxy (UsersServiceDbus *self) NULL); } +static void +create_ck_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + priv->ck_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager"); + + if (!priv->ck_proxy) + { + g_warning ("Failed to setup ConsoleKit proxy."); + return; + } +} + +static void +create_seat_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + + priv->seat = get_seat (self); + if (priv->seat == NULL) + { + return; + } + + priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, + "org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + &error); + + if (!priv->seat_proxy) + { + if (error != NULL) + { + g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); + g_error_free (error); + } + + return; + } + + dbus_g_proxy_add_signal (priv->seat_proxy, + "SessionAdded", + DBUS_TYPE_G_OBJECT_PATH, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->seat_proxy, + "SessionRemoved", + DBUS_TYPE_G_OBJECT_PATH, + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (priv->seat_proxy, + "SessionAdded", + G_CALLBACK (seat_proxy_session_added), + self, + NULL); + dbus_g_proxy_connect_signal (priv->seat_proxy, + "SessionRemoved", + G_CALLBACK (seat_proxy_session_removed), + self, + NULL); +} + +static void +create_cksession_proxy (UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + + priv->session_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + priv->ssid, + "org.freedesktop.ConsoleKit.Session"); + + if (!priv->session_proxy) + { + g_warning ("Failed to connect to ConsoleKit session"); + return; + } +} + +static gchar * +get_seat (UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error = NULL; + gchar *ssid = NULL; + gchar *seat; + + if (!dbus_g_proxy_call (priv->ck_proxy, + "GetCurrentSession", + &error, + G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, + &ssid, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to get session: %s", error->message); + g_error_free (error); + } + + if (ssid) + g_free (ssid); + + return NULL; + } + + priv->ssid = ssid; + create_cksession_proxy (service); + + if (ssid) + g_free (ssid); + + seat = get_seat_internal (service); + + return seat; +} + +static gchar * +get_seat_internal (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + gchar *seat; + + if (!dbus_g_proxy_call (priv->session_proxy, + "GetSeatId", + &error, + G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, &seat, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to identify the current seat: %s", error->message); + } + } + + return seat; +} + +static gboolean +get_uid_from_session_id (UsersServiceDbus *service, + const gchar *session_id, + uid_t *uidp) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error; + guint uid; + + if (dbus_g_proxy_call (priv->session_proxy, + "GetUnixUser", + &error, + G_TYPE_INVALID, + G_TYPE_UINT, &uid, + G_TYPE_INVALID)) + { + if (error) + { + g_warning ("Failed to get the session: %s", error->message); + g_error_free (error); + } + + return FALSE; + } + + if (uidp != NULL) + { + *uidp = (uid_t)uid; + } + + return TRUE; +} + +static gint +session_compare (const gchar *a, + const gchar *b) +{ + if (a == NULL) + return 1; + else if (b == NULL) + return -1; + + return strcmp (a, b); +} + +static gboolean +maybe_add_session_for_user (UsersServiceDbus *service, + UserData *user, + const gchar *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error = NULL; + gchar *seat = NULL; + gchar *xdisplay = NULL; + GList *l; + + seat = get_seat_internal (service); + if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) + return FALSE; + + if (!dbus_g_proxy_call (priv->session_proxy, + "GetX11Display", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &xdisplay, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to get X11 display: %s", error->message); + g_error_free (error); + } + + return FALSE; + } + + if (!xdisplay || xdisplay[0] == '\0') + return FALSE; + + if (g_hash_table_lookup (priv->exclusions, user->user_name)) + return FALSE; + + g_hash_table_insert (priv->sessions, + g_strdup (ssid), + g_strdup (user->user_name)); + + l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare); + if (l == NULL) + { + g_debug ("Adding session %s", ssid); + + user->sessions = g_list_prepend (user->sessions, g_strdup (ssid)); + } + else + { + g_debug ("User %s already has session %s", user->user_name, ssid); + } + + return TRUE; +} + +static void +seat_proxy_session_added (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + uid_t uid; + gboolean res; + struct passwd *pwent; + UserData *user; + + if (!get_uid_from_session_id (service, session_id, &uid)) + { + g_warning ("Failed to lookup user for session"); + return; + } + + errno = 0; + pwent = getpwuid (uid); + if (!pwent) + { + g_warning ("Failed to lookup user id %d: %s", (int)uid, g_strerror (errno)); + return; + } + + if (g_hash_table_lookup (priv->exclusions, pwent->pw_name)) + { + g_debug ("Excluding user %s", pwent->pw_name); + return; + } + + user = g_hash_table_lookup (priv->users, pwent->pw_name); + if (!user) + { + return; + } + + res = maybe_add_session_for_user (service, user, session_id); +} + +static void +seat_proxy_session_removed (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + UserData *user; + gchar *username; + GList *l; + + username = g_hash_table_lookup (priv->sessions, session_id); + if (!username) + return; + + user = g_hash_table_lookup (priv->users, username); + if (!user) + return; + + //_user_remove_session (user, session_id); + + l = g_list_find_custom (user->sessions, + session_id, + (GCompareFunc)session_compare); + if (l) + { + g_debug ("Removing session %s", session_id); + + g_free (l->data); + user->sessions = g_list_delete_link (user->sessions, l); + } + else + { + g_debug ("Session not found: %s", session_id); + } +} + static void users_loaded (DBusGProxy *proxy, gpointer user_data) @@ -359,20 +730,22 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { GValueArray *values; - UserData *data; + UserData *user; values = g_ptr_array_index (users_info, i); - data = g_new0 (UserData, 1); + user = g_new0 (UserData, 1); - data->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); - data->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); - data->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); - data->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); - data->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); - data->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - priv->users = g_list_prepend (priv->users, data); + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); } } @@ -389,7 +762,7 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - return priv->users; + return g_hash_table_get_values (priv->users); } static void @@ -423,11 +796,21 @@ user_added (DBusGProxy *proxy, user->uid = uid; - priv->users = g_list_prepend (priv->users, user); + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); } +static gboolean +compare_users_by_uid (gpointer key, + gpointer value, + gpointer user_data) +{ + return (GPOINTER_TO_UINT (value) == GPOINTER_TO_UINT (user_data)); +} + static void user_removed (DBusGProxy *proxy, guint uid, @@ -435,20 +818,16 @@ user_removed (DBusGProxy *proxy, { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GList *l; + UserData *user; - priv->count--; + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); - for (l = priv->users; l != NULL; l = g_list_next (l)) - { - UserData *user = (UserData *)l->data; + g_hash_table_remove (priv->users, + user->user_name); - if (user->uid == uid) - { - priv->users = g_list_remove (priv->users, l->data); - g_signal_emit (G_OBJECT (service), signals[USER_REMOVED], 0, user, TRUE); - } - } + priv->count--; } static void @@ -456,19 +835,16 @@ user_updated (DBusGProxy *proxy, guint uid, gpointer user_data) { +#if 0 + // XXX - TODO UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GList *l; + UserData *user; - for (l = priv->users; l != NULL; l = g_list_next (l)) - { - UserData *user = (UserData *)l->data; - - if (user->uid == uid) - { - // XXX - update user data - } - } + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); +#endif } static gboolean diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index ecfaf6d..f43abe8 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -44,6 +44,8 @@ struct _UserData gchar *shell; gint login_count; gchar *icon_url; + + GList *sessions; }; struct _UsersServiceDbus { -- cgit v1.2.3 From a3ca139c3e39765da2a295b1d7261268f94f020b Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 12:40:16 -0500 Subject: user activation wip --- src/users-service-dbus.c | 154 +++++++++++++++++++++++++++++++++++++++++++---- src/users-service-dbus.h | 8 ++- src/users-service.c | 15 +++++ 3 files changed, 163 insertions(+), 14 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index b9e9391..593ef83 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -26,6 +26,8 @@ #include #include +#include +#include #include "dbus-shared-names.h" #include "users-service-dbus.h" @@ -81,7 +83,7 @@ static void seat_proxy_session_added (DBusGProxy *seat_ static void seat_proxy_session_removed (DBusGProxy *seat_proxy, const gchar *session_id, UsersServiceDbus *service); -static gboolean maybe_add_session_for_user (UsersServiceDbus *service, +static gboolean do_add_session (UsersServiceDbus *service, UserData *user, const gchar *ssid); static gchar * get_seat_internal (UsersServiceDbus *self); @@ -464,12 +466,11 @@ get_seat (UsersServiceDbus *service) return NULL; } + g_print ("get_seat(): ssid is %s\n", ssid); + priv->ssid = ssid; create_cksession_proxy (service); - if (ssid) - g_free (ssid); - seat = get_seat_internal (service); return seat; @@ -495,13 +496,15 @@ get_seat_internal (UsersServiceDbus *self) } } + g_print ("get_seat_internal: %s\n", seat); + return seat; } static gboolean -get_uid_from_session_id (UsersServiceDbus *service, - const gchar *session_id, - uid_t *uidp) +get_unix_user (UsersServiceDbus *service, + const gchar *session_id, + uid_t *uidp) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); GError *error; @@ -543,10 +546,65 @@ session_compare (const gchar *a, return strcmp (a, b); } +static gchar * +get_session_for_user (UsersServiceDbus *service, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + gboolean can_activate; + GError *error = NULL; + GList *l; + + if (!priv->seat_proxy) + create_seat_proxy (service); + + if (priv->seat == NULL || priv->seat[0] == '\0') + { + return NULL; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to determine if seat can activate sessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + if (!can_activate) { + return NULL; + } + + if (!user->sessions || g_list_length (user->sessions) == 0) + { + return NULL; + } + + for (l = user->sessions; l != NULL; l = l->next) + { + const char *ssid; + + ssid = l->data; + + /* FIXME: better way to choose? */ + if (ssid != NULL) + { + return g_strdup (ssid); + } + } + + return NULL; +} + static gboolean -maybe_add_session_for_user (UsersServiceDbus *service, - UserData *user, - const gchar *ssid) +do_add_session (UsersServiceDbus *service, + UserData *user, + const gchar *ssid) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); GError *error = NULL; @@ -577,6 +635,8 @@ maybe_add_session_for_user (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; + g_print ("xdisplay is %s\n", xdisplay); + if (g_hash_table_lookup (priv->exclusions, user->user_name)) return FALSE; @@ -610,7 +670,7 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, struct passwd *pwent; UserData *user; - if (!get_uid_from_session_id (service, session_id, &uid)) + if (!get_unix_user (service, session_id, &uid)) { g_warning ("Failed to lookup user for session"); return; @@ -636,7 +696,7 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, return; } - res = maybe_add_session_for_user (service, user, session_id); + res = do_add_session (service, user, session_id); } static void @@ -765,6 +825,76 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +gboolean +users_service_dbus_activate_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + gchar *ssid; + + dbus_error_init (&error); + + if (!priv->seat) + priv->seat = get_seat (self); + + ssid = get_session_for_user (self, user); + + g_print ("users_service_dbus_activate_user_session...\n"); + g_print ("seat is %s\n", priv->seat); + g_print ("ssid is %s\n", ssid); + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + g_warning ("failed to create new message"); + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, + &ssid, + DBUS_TYPE_INVALID)) + { + g_warning ("failed to append args"); + return FALSE; + } + + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + g_warning ("send_with_reply_and_block failed"); + + if (dbus_error_is_set (&error)) + { + g_warning ("Unable to activate session: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + g_print ("freeing shit up..\n"); + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} + static void user_added (DBusGProxy *proxy, guint uid, diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index f43abe8..95db35d 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -46,6 +46,8 @@ struct _UserData gchar *icon_url; GList *sessions; + + UsersServiceDbus *service; }; struct _UsersServiceDbus { @@ -68,8 +70,10 @@ struct _UsersServiceDbusClass { GType users_service_dbus_get_type (void) G_GNUC_CONST; -gint users_service_dbus_get_user_count (UsersServiceDbus *self); -GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +gint users_service_dbus_get_user_count (UsersServiceDbus *self); +GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, + UserData *user); G_END_DECLS diff --git a/src/users-service.c b/src/users-service.c index 7c8ab01..4d1b367 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -38,6 +38,13 @@ with this program. If not, see . #define MINIMUM_USERS 1 #define MAXIMUM_USERS 7 +typedef struct _ActivateData ActivateData; +struct _ActivateData +{ + UsersServiceDbus *service; + UserData *user; +}; + static DBusGConnection *session_bus = NULL; static DBusGConnection *system_bus = NULL; static DBusGProxy *bus_proxy = NULL; @@ -118,6 +125,12 @@ activate_new_session (DbusmenuMenuitem * mi, gpointer user_data) static void activate_user_session (DbusmenuMenuitem *mi, gpointer user_data) { + UserData *user = (UserData *)user_data; + UsersServiceDbus *service = user->service; + + g_print ("activating user session for %s\n", user->user_name); + + users_service_dbus_activate_user_session (service, user); } static void @@ -151,6 +164,8 @@ rebuild_items (DbusmenuMenuitem *root, { user = u->data; + user->service = service; + mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); dbusmenu_menuitem_child_append (root, mi); -- cgit v1.2.3 From 9a12a13ccda5cbcce28f6913fd29bd47a61c6762 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 13:49:17 -0500 Subject: session adding --- src/users-service-dbus.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 593ef83..d369833 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -181,6 +181,8 @@ users_service_dbus_init (UsersServiceDbus *self) GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + g_print ("INIT\n"); + priv->users = NULL; priv->count = 0; @@ -225,8 +227,8 @@ users_service_dbus_init (UsersServiceDbus *self) create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); - create_seat_proxy (self); create_ck_proxy (self); + create_seat_proxy (self); users_loaded (priv->gdm_proxy, self); } @@ -377,12 +379,16 @@ create_seat_proxy (UsersServiceDbus *self) UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; + g_print ("create_seat_proxy ()\n"); + priv->seat = get_seat (self); if (priv->seat == NULL) { + g_print (" ** no priv->seat, returning\n"); return; } + g_print ("setup priv->seat_proxy...\n"); priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.freedesktop.ConsoleKit", priv->seat, @@ -391,6 +397,8 @@ create_seat_proxy (UsersServiceDbus *self) if (!priv->seat_proxy) { + g_print ("some error...\n"); + if (error != NULL) { g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); @@ -400,10 +408,12 @@ create_seat_proxy (UsersServiceDbus *self) return; } + g_print ("... SessionAdded\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); + g_print ("... SessionRemoved\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, @@ -577,11 +587,13 @@ get_session_for_user (UsersServiceDbus *service, } if (!can_activate) { + g_warning ("Can't activate sessions"); return NULL; } if (!user->sessions || g_list_length (user->sessions) == 0) { + g_print (" *** no user sessions\n"); return NULL; } @@ -594,6 +606,7 @@ get_session_for_user (UsersServiceDbus *service, /* FIXME: better way to choose? */ if (ssid != NULL) { + g_print (" ==== ssid is %s\n", ssid); return g_strdup (ssid); } } @@ -612,7 +625,10 @@ do_add_session (UsersServiceDbus *service, gchar *xdisplay = NULL; GList *l; + g_print ("DO_ADD_SESSION (ssid is %s)\n", ssid); + seat = get_seat_internal (service); + g_print (" *** seat is %s\n", seat); if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) return FALSE; @@ -659,6 +675,44 @@ do_add_session (UsersServiceDbus *service, return TRUE; } +static void +add_sessions_for_user (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error; + GPtrArray *sessions; + int i; + + error = NULL; + if (!dbus_g_proxy_call (priv->ck_proxy, + "GetSessionsForUnixUser", + &error, + G_TYPE_UINT, user->uid, + G_TYPE_INVALID, + dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), + &sessions, + G_TYPE_INVALID)) + { + g_debug ("Failed to find sessions for user: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < sessions->len; i++) + { + char *ssid; + + ssid = g_ptr_array_index (sessions, i); + do_add_session (self, user, ssid); + } + + g_ptr_array_foreach (sessions, (GFunc)g_free, NULL); + g_ptr_array_free (sessions, TRUE); +} + + static void seat_proxy_session_added (DBusGProxy *seat_proxy, const gchar *session_id, @@ -787,6 +841,9 @@ users_loaded (DBusGProxy *proxy, return; } + g_print ("***************\n"); + g_print ("*** users_info->len is %d\n", users_info->len); + for (i = 0; i < users_info->len; i++) { GValueArray *values; @@ -803,9 +860,15 @@ users_loaded (DBusGProxy *proxy, user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + g_print ("*** username is %s\n", user->user_name); + g_hash_table_insert (priv->users, g_strdup (user->user_name), user); + + g_print (" ... adding sessions for %s\n", user->user_name); + add_sessions_for_user (service, user); + g_print ("***************\n"); } } -- cgit v1.2.3 From 3de7117e82eb5d0b39fd17532852f27dcd555dfe Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 17:09:07 -0500 Subject: cleanups and more session fu --- src/users-service-dbus.c | 300 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 247 insertions(+), 53 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index d369833..15da3d2 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -180,8 +180,31 @@ users_service_dbus_init (UsersServiceDbus *self) { GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - g_print ("INIT\n"); + gint i = 0; + const gchar *excludes[] = + { "bin", + "root", /* excludes taken from gdm */ + "daemon", + "adm", + "lp", + "sync", + "shutdown", + "halt", + "mail", + "news", + "uucp", + "operator", + "nobody", + "nobody4", + "noaccess", + "gdm", + "postgres", + "pvm", + "rpm", + "nfsnobody", + "pcap", + NULL + }; priv->users = NULL; priv->count = 0; @@ -199,7 +222,7 @@ users_service_dbus_init (UsersServiceDbus *self) priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error != NULL) { - g_error("Unable to get system bus: %s", error->message); + g_error ("Unable to get system bus: %s", error->message); g_error_free(error); return; @@ -210,6 +233,18 @@ users_service_dbus_init (UsersServiceDbus *self) g_free, NULL); + for (i = 0; excludes[i] != NULL; i++) + { + g_hash_table_insert (priv->exclusions, + g_strdup (excludes [i]), + GUINT_TO_POINTER (TRUE)); + } + + priv->sessions = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + priv->users = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -368,7 +403,7 @@ create_ck_proxy (UsersServiceDbus *self) if (!priv->ck_proxy) { - g_warning ("Failed to setup ConsoleKit proxy."); + g_warning ("Failed to get ConsoleKit proxy."); return; } } @@ -379,16 +414,12 @@ create_seat_proxy (UsersServiceDbus *self) UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; - g_print ("create_seat_proxy ()\n"); - priv->seat = get_seat (self); if (priv->seat == NULL) { - g_print (" ** no priv->seat, returning\n"); return; } - g_print ("setup priv->seat_proxy...\n"); priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.freedesktop.ConsoleKit", priv->seat, @@ -397,8 +428,6 @@ create_seat_proxy (UsersServiceDbus *self) if (!priv->seat_proxy) { - g_print ("some error...\n"); - if (error != NULL) { g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); @@ -408,12 +437,10 @@ create_seat_proxy (UsersServiceDbus *self) return; } - g_print ("... SessionAdded\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - g_print ("... SessionRemoved\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, @@ -443,7 +470,7 @@ create_cksession_proxy (UsersServiceDbus *service) if (!priv->session_proxy) { - g_warning ("Failed to connect to ConsoleKit session"); + g_warning ("Failed to get ConsoleKit session proxy"); return; } } @@ -466,7 +493,7 @@ get_seat (UsersServiceDbus *service) { if (error) { - g_debug ("Failed to get session: %s", error->message); + g_debug ("Failed to call GetCurrentSession: %s", error->message); g_error_free (error); } @@ -476,8 +503,6 @@ get_seat (UsersServiceDbus *service) return NULL; } - g_print ("get_seat(): ssid is %s\n", ssid); - priv->ssid = ssid; create_cksession_proxy (service); @@ -491,7 +516,7 @@ get_seat_internal (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; - gchar *seat; + gchar *seat = NULL; if (!dbus_g_proxy_call (priv->session_proxy, "GetSeatId", @@ -502,12 +527,12 @@ get_seat_internal (UsersServiceDbus *self) { if (error) { - g_debug ("Failed to identify the current seat: %s", error->message); + g_debug ("Failed to call GetSeatId: %s", error->message); + + return NULL; } } - g_print ("get_seat_internal: %s\n", seat); - return seat; } @@ -517,7 +542,7 @@ get_unix_user (UsersServiceDbus *service, uid_t *uidp) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GError *error; + GError *error = NULL; guint uid; if (dbus_g_proxy_call (priv->session_proxy, @@ -529,7 +554,7 @@ get_unix_user (UsersServiceDbus *service, { if (error) { - g_warning ("Failed to get the session: %s", error->message); + g_warning ("Failed to call GetUnixUser: %s", error->message); g_error_free (error); } @@ -586,14 +611,13 @@ get_session_for_user (UsersServiceDbus *service, return NULL; } - if (!can_activate) { - g_warning ("Can't activate sessions"); - return NULL; - } + if (!can_activate) + { + return NULL; + } if (!user->sessions || g_list_length (user->sessions) == 0) { - g_print (" *** no user sessions\n"); return NULL; } @@ -603,10 +627,8 @@ get_session_for_user (UsersServiceDbus *service, ssid = l->data; - /* FIXME: better way to choose? */ - if (ssid != NULL) + if (ssid) { - g_print (" ==== ssid is %s\n", ssid); return g_strdup (ssid); } } @@ -625,10 +647,8 @@ do_add_session (UsersServiceDbus *service, gchar *xdisplay = NULL; GList *l; - g_print ("DO_ADD_SESSION (ssid is %s)\n", ssid); - seat = get_seat_internal (service); - g_print (" *** seat is %s\n", seat); + if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) return FALSE; @@ -641,7 +661,7 @@ do_add_session (UsersServiceDbus *service, { if (error) { - g_debug ("Failed to get X11 display: %s", error->message); + g_debug ("Failed to call GetX11Display: %s", error->message); g_error_free (error); } @@ -651,8 +671,6 @@ do_add_session (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; - g_print ("xdisplay is %s\n", xdisplay); - if (g_hash_table_lookup (priv->exclusions, user->user_name)) return FALSE; @@ -694,7 +712,7 @@ add_sessions_for_user (UsersServiceDbus *self, &sessions, G_TYPE_INVALID)) { - g_debug ("Failed to find sessions for user: %s", error->message); + g_debug ("Failed to call GetSessionsForUnixUser: %s", error->message); g_error_free (error); return; @@ -771,7 +789,7 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, if (!user) return; - //_user_remove_session (user, session_id); + // remove_session_from_user (user, session_id); ?? l = g_list_find_custom (user->sessions, session_id, @@ -841,9 +859,6 @@ users_loaded (DBusGProxy *proxy, return; } - g_print ("***************\n"); - g_print ("*** users_info->len is %d\n", users_info->len); - for (i = 0; i < users_info->len; i++) { GValueArray *values; @@ -860,15 +875,11 @@ users_loaded (DBusGProxy *proxy, user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - g_print ("*** username is %s\n", user->user_name); - g_hash_table_insert (priv->users, g_strdup (user->user_name), user); - g_print (" ... adding sessions for %s\n", user->user_name); add_sessions_for_user (service, user); - g_print ("***************\n"); } } @@ -888,6 +899,192 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +static gboolean +session_is_login_window (UsersServiceDbus *self, + const char *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusGProxy *proxy = NULL; + GError *error = NULL; + char *type = NULL; + + if (!(proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + ssid, + "org.freedesktop.ConsoleKit.Session"))) + { + g_warning ("Failed to get ConsoleKit proxy"); + + return FALSE; + } + + if (!dbus_g_proxy_call (proxy, + "GetSessionType", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &type, + G_TYPE_INVALID)) + { + g_warning ("Can't call GetSessionType: %s", error->message); + g_error_free (error); + + if (proxy) + g_object_unref (proxy); + + return FALSE; + } + + if (proxy) + g_object_unref (proxy); + + return (type && type[0] != '\0' && strcmp (type, "LoginWindow") == 0); +} + +static char * +get_login_session (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + gboolean can_activate; + GError *error = NULL; + GPtrArray *sessions = NULL; + char *ssid = NULL; + int i; + + if (!priv->seat || priv->seat[0] == '\0') + { + return NULL; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to call CanActivateSessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + if (!can_activate) + { + return NULL; + } + + error = NULL; + if (!dbus_g_proxy_call (priv->seat_proxy, + "GetSessions", + &error, + G_TYPE_INVALID, + dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &sessions, + G_TYPE_INVALID)) + { + g_warning ("Failed to call GetSessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + for (i = 0; i < sessions->len; i++) + { + char *s = g_ptr_array_index (sessions, i); + + if (session_is_login_window (self, s)) + { + ssid = g_strdup (s); + break; + } + } + + g_ptr_array_foreach (sessions, (GFunc)g_free, NULL); + g_ptr_array_free (sessions, TRUE); + + return ssid; +} + +static gboolean +activate_user_session (UsersServiceDbus *self, + const char *seat, + const char *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, &ssid, + DBUS_TYPE_INVALID)) + { + return FALSE; + } + + dbus_error_init (&error); + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + if (dbus_error_is_set (&error)) + { + g_warning ("Can't activate session: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} + +gboolean +start_new_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + char *ssid; + + ssid = get_login_session (self); + if (ssid) + { + if (!activate_user_session (self, priv->seat, ssid)) + { + return FALSE; + } + } + + if (!g_spawn_command_line_async ("gdmflexiserver -s", &error)) + { + g_warning ("Failed to start new login session: %s", error->message); + g_error_free (error); + + return FALSE; + } + + return TRUE; +} + gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user) @@ -905,9 +1102,10 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, ssid = get_session_for_user (self, user); - g_print ("users_service_dbus_activate_user_session...\n"); - g_print ("seat is %s\n", priv->seat); - g_print ("ssid is %s\n", ssid); + if (!ssid) + { + return start_new_user_session (self, user); + } if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", priv->seat, @@ -932,19 +1130,15 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, -1, &error))) { - g_warning ("send_with_reply_and_block failed"); - if (dbus_error_is_set (&error)) { - g_warning ("Unable to activate session: %s", error.message); + g_warning ("Failed to send message: %s", error.message); dbus_error_free (&error); return FALSE; } } - g_print ("freeing shit up..\n"); - if (message) { dbus_message_unref (message); -- cgit v1.2.3 From 8888a1aa1b4ca13be5028561f4b0adf21d392719 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 18:00:35 -0500 Subject: move stuff around --- src/users-service-dbus.c | 166 +++++++++++++++++++++++------------------------ src/users-service.c | 42 ++++++------ 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 15da3d2..fac689d 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -883,22 +883,6 @@ users_loaded (DBusGProxy *proxy, } } -gint -users_service_dbus_get_user_count (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return priv->count; -} - -GList * -users_service_dbus_get_user_list (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return g_hash_table_get_values (priv->users); -} - static gboolean session_is_login_window (UsersServiceDbus *self, const char *ssid) @@ -1085,73 +1069,6 @@ start_new_user_session (UsersServiceDbus *self, return TRUE; } -gboolean -users_service_dbus_activate_user_session (UsersServiceDbus *self, - UserData *user) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - DBusMessage *message = NULL; - DBusMessage *reply = NULL; - DBusError error; - gchar *ssid; - - dbus_error_init (&error); - - if (!priv->seat) - priv->seat = get_seat (self); - - ssid = get_session_for_user (self, user); - - if (!ssid) - { - return start_new_user_session (self, user); - } - - if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", - priv->seat, - "org.freedesktop.ConsoleKit.Seat", - "ActivateSession"))) - { - g_warning ("failed to create new message"); - return FALSE; - } - - if (!dbus_message_append_args (message, - DBUS_TYPE_OBJECT_PATH, - &ssid, - DBUS_TYPE_INVALID)) - { - g_warning ("failed to append args"); - return FALSE; - } - - if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), - message, - -1, - &error))) - { - if (dbus_error_is_set (&error)) - { - g_warning ("Failed to send message: %s", error.message); - dbus_error_free (&error); - - return FALSE; - } - } - - if (message) - { - dbus_message_unref (message); - } - - if (reply) - { - dbus_message_unref (reply); - } - - return TRUE; -} - static void user_added (DBusGProxy *proxy, guint uid, @@ -1279,3 +1196,86 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } + +gint +users_service_dbus_get_user_count (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->count; +} + +GList * +users_service_dbus_get_user_list (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return g_hash_table_get_values (priv->users); +} + +gboolean +users_service_dbus_activate_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + gchar *ssid; + + dbus_error_init (&error); + + if (!priv->seat) + priv->seat = get_seat (self); + + ssid = get_session_for_user (self, user); + + if (!ssid) + { + return start_new_user_session (self, user); + } + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + g_warning ("failed to create new message"); + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, + &ssid, + DBUS_TYPE_INVALID)) + { + g_warning ("failed to append args"); + return FALSE; + } + + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + if (dbus_error_is_set (&error)) + { + g_warning ("Failed to send message: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} diff --git a/src/users-service.c b/src/users-service.c index 9fd123f..9884a56 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -1,25 +1,25 @@ /* -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 - Cody Russell - -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 . -*/ + * 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 + * Cody Russell + * + * 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 . + */ #include -- cgit v1.2.3 From cbcbcc64d025aae5b3fa6d1a9b4a8839a95842f6 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 18:05:39 -0500 Subject: add todo comment --- src/users-service-dbus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index fac689d..937ce30 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -1213,6 +1213,17 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +/* + * XXX - TODO: Right now we switch to a session that another user + * already has open, but if there are no open sessions + * for this user we go to the login screen and the + * user at the seat must select a user and enter a + * password. This kind of defeats the purpose of + * actually selecting a username, since selecting any + * user will do the same thing here. We need to change + * it so you only need to enter a password for the + * specified user. + */ gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user) -- cgit v1.2.3 From 61d73835f3f9b4bc1970587e172f228c3474bdb1 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 19:12:14 -0500 Subject: cleanup --- src/users-service-dbus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 937ce30..bcd5a03 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -789,8 +789,6 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, if (!user) return; - // remove_session_from_user (user, session_id); ?? - l = g_list_find_custom (user->sessions, session_id, (GCompareFunc)session_compare); -- cgit v1.2.3 From b712e3b2d2b4394d351a9c9b36a9e7c655f774cf Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 19:14:01 -0500 Subject: add names --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index e69de29..a1771e3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1,2 @@ +Ted Gould +Cody Russell -- cgit v1.2.3 From afc84307f4de2b54bd680c9fe77afcc7f4fd9c58 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:01:20 -0500 Subject: modify count in user_added()/user_removed() --- src/users-service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/users-service.c b/src/users-service.c index 9884a56..9dbf218 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -223,6 +223,7 @@ user_added (UsersServiceDbus *service, DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; users = g_list_append (users, user); + count++; rebuild_items (root, service); } @@ -235,6 +236,7 @@ user_removed (UsersServiceDbus *service, DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; users = g_list_remove (users, user); + count--; rebuild_items (root, service); } -- cgit v1.2.3 From fec2a3548f53572ed24ee675c5f16e65dd35a299 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:05:38 -0500 Subject: don't need to dbus_g_object_type_install_info() --- src/users-service-dbus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index bcd5a03..261c4c7 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -171,8 +171,6 @@ users_service_dbus_class_init (UsersServiceDbusClass *klass) NULL, NULL, _users_service_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); - - dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); } static void -- cgit v1.2.3 From d9caa21356ea1b220018f37163e1ede65a37c945 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:08:05 -0500 Subject: remove unnecessary stuff --- src/users-service-dbus.c | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 261c4c7..649bbbf 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -178,31 +178,6 @@ users_service_dbus_init (UsersServiceDbus *self) { GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - gint i = 0; - const gchar *excludes[] = - { "bin", - "root", /* excludes taken from gdm */ - "daemon", - "adm", - "lp", - "sync", - "shutdown", - "halt", - "mail", - "news", - "uucp", - "operator", - "nobody", - "nobody4", - "noaccess", - "gdm", - "postgres", - "pvm", - "rpm", - "nfsnobody", - "pcap", - NULL - }; priv->users = NULL; priv->count = 0; @@ -226,18 +201,6 @@ users_service_dbus_init (UsersServiceDbus *self) return; } - priv->exclusions = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - NULL); - - for (i = 0; excludes[i] != NULL; i++) - { - g_hash_table_insert (priv->exclusions, - g_strdup (excludes [i]), - GUINT_TO_POINTER (TRUE)); - } - priv->sessions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -669,9 +632,6 @@ do_add_session (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; - if (g_hash_table_lookup (priv->exclusions, user->user_name)) - return FALSE; - g_hash_table_insert (priv->sessions, g_strdup (ssid), g_strdup (user->user_name)); @@ -754,12 +714,6 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, return; } - if (g_hash_table_lookup (priv->exclusions, pwent->pw_name)) - { - g_debug ("Excluding user %s", pwent->pw_name); - return; - } - user = g_hash_table_lookup (priv->users, pwent->pw_name); if (!user) { -- cgit v1.2.3 From 7fa88e1e36df5efdf8c7d6d7b874d4e4e92a1d28 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:10:31 -0500 Subject: remove session proxy fu --- src/users-service-dbus.c | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 649bbbf..0ae0170 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -59,7 +59,6 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi const GArray *uids, GPtrArray **user_info, GError **error); -static void create_session_proxy (UsersServiceDbus *self); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); @@ -100,10 +99,8 @@ struct _UsersServiceDbusPrivate gchar *seat; gchar *ssid; - DBusGConnection *session_bus; DBusGConnection *system_bus; - DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; DBusGProxy *ck_proxy; @@ -182,16 +179,7 @@ users_service_dbus_init (UsersServiceDbus *self) priv->users = NULL; priv->count = 0; - /* Get the buses */ - priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) - { - g_error ("Unable to get session bus: %s", error->message); - g_error_free (error); - - return; - } - + /* Get the system bus */ priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error != NULL) { @@ -211,16 +199,11 @@ users_service_dbus_init (UsersServiceDbus *self) g_free, NULL); - dbus_g_connection_register_g_object (priv->session_bus, - INDICATOR_USERS_SERVICE_DBUS_OBJECT, - G_OBJECT (self)); - dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, G_TYPE_NONE, G_TYPE_INT64, G_TYPE_INVALID); - create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); create_ck_proxy (self); @@ -241,26 +224,6 @@ users_service_dbus_finalize (GObject *object) G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } -static void -create_session_proxy (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - GError *error = NULL; - - priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - &error); - if (error != NULL) - { - g_error ("Unable to get dbus proxy on session bus: %s", error->message); - g_error_free (error); - - return; - } -} - static void create_system_proxy (UsersServiceDbus *self) { -- cgit v1.2.3 From c608393d5e0650f348fc39769531cb0a1e7c95a0 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:15:56 -0500 Subject: remove the server code --- src/Makefile.am | 9 ------- src/users-service-dbus.c | 69 ------------------------------------------------ 2 files changed, 78 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 6404af0..239a943 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,6 @@ indicator_status_service_SOURCES = \ status-service-server.h \ users-service-dbus.h \ users-service-dbus.c \ - users-service-server.h \ users-service-marshal.c \ users-service-marshal.h \ status-provider.h \ @@ -51,13 +50,6 @@ users-service-client.h: $(srcdir)/users-service.xml --output=users-service-client.h \ $(srcdir)/users-service.xml -users-service-server.h: $(srcdir)/users-service.xml - dbus-binding-tool \ - --prefix=_users_service_server \ - --mode=glib-server \ - --output=users-service-server.h \ - $(srcdir)/users-service.xml - status-service-client.h: $(srcdir)/status-service.xml dbus-binding-tool \ --prefix=_status_service_client \ @@ -124,7 +116,6 @@ indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS) BUILT_SOURCES = \ users-service-client.h \ - users-service-server.h \ status-service-client.h \ status-service-server.h \ users-service-marshal.h \ diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 0ae0170..5a9b874 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -38,27 +38,6 @@ static void users_service_dbus_class_init (UsersServiceDbusClass *k static void users_service_dbus_init (UsersServiceDbus *self); static void users_service_dbus_dispose (GObject *object); static void users_service_dbus_finalize (GObject *object); -static gboolean _users_service_server_count_users (UsersServiceDbus *service, - gint *count, - GError **error); -static gboolean _users_service_server_get_users_loaded (UsersServiceDbus *self, - gboolean *is_loaded, - GError **error); -static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error); -static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - gint *login_count, - gchar **icon_url, - GError **error); -static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); @@ -87,8 +66,6 @@ static gboolean do_add_session (UsersServiceDbus *servi const gchar *ssid); static gchar * get_seat_internal (UsersServiceDbus *self); -#include "users-service-server.h" - /* Private */ typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; @@ -1064,52 +1041,6 @@ user_updated (DBusGProxy *proxy, #endif } -static gboolean -_users_service_server_count_users (UsersServiceDbus *service, - gint *uids, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_users_loaded (UsersServiceDbus *self, - gboolean *is_loaded, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - gint *login_count, - char **icon_url, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error) -{ - return TRUE; -} - gint users_service_dbus_get_user_count (UsersServiceDbus *self) { -- cgit v1.2.3 From f8e0ff04840fe4842c5c3ebeef396b530d6f1995 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:18:51 -0500 Subject: remove system proxy --- src/users-service-dbus.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 5a9b874..499182b 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -34,11 +34,10 @@ #include "users-service-client.h" #include "users-service-marshal.h" -static void users_service_dbus_class_init (UsersServiceDbusClass *klass); -static void users_service_dbus_init (UsersServiceDbus *self); -static void users_service_dbus_dispose (GObject *object); -static void users_service_dbus_finalize (GObject *object); -static void create_system_proxy (UsersServiceDbus *self); +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); static void create_ck_proxy (UsersServiceDbus *self); @@ -78,7 +77,6 @@ struct _UsersServiceDbusPrivate DBusGConnection *system_bus; - DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; DBusGProxy *ck_proxy; DBusGProxy *seat_proxy; @@ -181,7 +179,6 @@ users_service_dbus_init (UsersServiceDbus *self) G_TYPE_INT64, G_TYPE_INVALID); - create_system_proxy (self); create_gdm_proxy (self); create_ck_proxy (self); create_seat_proxy (self); @@ -201,30 +198,6 @@ users_service_dbus_finalize (GObject *object) G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } -static void -create_system_proxy (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - GError *error = NULL; - - priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - &error); - - if (!priv->dbus_proxy_system) - { - if (error != NULL) - { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); - - return; - } - } -} - static void create_gdm_proxy (UsersServiceDbus *self) { -- cgit v1.2.3 From 2bb61203e78626f51bdbfbc8fb1440a046bab7be Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:21:21 -0500 Subject: use g_strcmp0 --- src/users-service-dbus.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 499182b..96f5cd5 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -443,18 +443,6 @@ get_unix_user (UsersServiceDbus *service, return TRUE; } -static gint -session_compare (const gchar *a, - const gchar *b) -{ - if (a == NULL) - return 1; - else if (b == NULL) - return -1; - - return strcmp (a, b); -} - static gchar * get_session_for_user (UsersServiceDbus *service, UserData *user) @@ -549,7 +537,7 @@ do_add_session (UsersServiceDbus *service, g_strdup (ssid), g_strdup (user->user_name)); - l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare); + l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)g_strcmp0); if (l == NULL) { g_debug ("Adding session %s", ssid); @@ -656,7 +644,7 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, l = g_list_find_custom (user->sessions, session_id, - (GCompareFunc)session_compare); + (GCompareFunc)g_strcmp0); if (l) { g_debug ("Removing session %s", session_id); -- cgit v1.2.3 From 3427b4a7054aa66f1aaa20aed56ad445aecd5ec4 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:30:48 -0500 Subject: expose users_service_dbus_can_activate_session() --- src/users-service-dbus.c | 61 +++++++++++++++++++++++++++--------------------- src/users-service-dbus.h | 1 + 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 96f5cd5..6051e4e 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -447,33 +447,9 @@ static gchar * get_session_for_user (UsersServiceDbus *service, UserData *user) { - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - gboolean can_activate; - GError *error = NULL; - GList *l; - - if (!priv->seat_proxy) - create_seat_proxy (service); - - if (priv->seat == NULL || priv->seat[0] == '\0') - { - return NULL; - } - - if (!dbus_g_proxy_call (priv->seat_proxy, - "CanActivateSessions", - &error, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &can_activate, - G_TYPE_INVALID)) - { - g_warning ("Failed to determine if seat can activate sessions: %s", error->message); - g_error_free (error); - - return NULL; - } + GList *l; - if (!can_activate) + if (!users_service_dbus_can_activate_session (service)) { return NULL; } @@ -1095,3 +1071,36 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, return TRUE; } + +gboolean +users_service_dbus_can_activate_session (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + gboolean can_activate = FALSE; + GError *error = NULL; + + if (!priv->seat_proxy) + { + create_seat_proxy (self); + } + + if (!priv->seat || priv->seat[0] == '\0') + { + return FALSE; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to determine if seat can activate sessions: %s", error->message); + g_error_free (error); + + return FALSE; + } + + return can_activate; +} diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 95db35d..e156520 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -72,6 +72,7 @@ GType users_service_dbus_get_type (void) G_GNUC_CONST; gint users_service_dbus_get_user_count (UsersServiceDbus *self); GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +gboolean users_service_dbus_can_activate_session (UsersServiceDbus *self); gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user); -- cgit v1.2.3 From 7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 01:21:50 -0500 Subject: don't load all the users unless needed --- src/users-service-dbus.c | 197 ++++++++++++++++++++++++++++------------------- src/users-service-dbus.h | 3 + src/users-service.c | 23 ++++-- 3 files changed, 140 insertions(+), 83 deletions(-) diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 6051e4e..018469c 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -634,6 +634,73 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, } } +static void +sync_users (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + if (g_hash_table_size (priv->users) > 0) + { + return; + } + + if (priv->count > MINIMUM_USERS && priv->count < MAXIMUM_USERS) + { + GArray *uids = NULL; + GPtrArray *users_info = NULL; + GError *error = NULL; + gint i; + + uids = g_array_new (FALSE, FALSE, sizeof (gint64)); + + if (!org_gnome_DisplayManager_UserManager_get_user_list (priv->gdm_proxy, + &uids, + &error)) + { + g_warning ("failed to retrieve user list: %s", error->message); + g_error_free (error); + + return; + } + + users_info = g_ptr_array_new (); + + if (!org_gnome_DisplayManager_UserManager_get_users_info (priv->gdm_proxy, + uids, + &users_info, + &error)) + { + g_warning ("failed to retrieve user info: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < users_info->len; i++) + { + GValueArray *values; + UserData *user; + + values = g_ptr_array_index (users_info, i); + + user = g_new0 (UserData, 1); + + user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); + + add_sessions_for_user (self, user); + } + } +} + static void users_loaded (DBusGProxy *proxy, gpointer user_data) @@ -641,10 +708,7 @@ users_loaded (DBusGProxy *proxy, UsersServiceDbus *service; UsersServiceDbusPrivate *priv; GError *error = NULL; - GArray *uids = NULL; - GPtrArray *users_info = NULL; gint count; - int i; service = (UsersServiceDbus *)user_data; priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); @@ -661,53 +725,7 @@ users_loaded (DBusGProxy *proxy, priv->count = count; - uids = g_array_new (FALSE, FALSE, sizeof (gint64)); - - if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, - &uids, - &error)) - { - g_warning ("failed to retrieve user list: %s", error->message); - g_error_free (error); - - return; - } - - users_info = g_ptr_array_new (); - - if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, - uids, - &users_info, - &error)) - { - g_warning ("failed to retrieve user info: %s", error->message); - g_error_free (error); - - return; - } - - for (i = 0; i < users_info->len; i++) - { - GValueArray *values; - UserData *user; - - values = g_ptr_array_index (users_info, i); - - user = g_new0 (UserData, 1); - - user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); - user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); - user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); - user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); - user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); - user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - - g_hash_table_insert (priv->users, - g_strdup (user->user_name), - user); - - add_sessions_for_user (service, user); - } + sync_users (service); } static gboolean @@ -908,30 +926,40 @@ user_added (DBusGProxy *proxy, priv->count++; - if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, - uid, - &user->user_name, - &user->real_name, - &user->shell, - &user->login_count, - &user->icon_url, - &error)) + if (priv->count < MAXIMUM_USERS) { - g_warning ("unable to retrieve user info: %s", error->message); - g_error_free (error); - - g_free (user); - - return; + if ((priv->count - g_hash_table_size (priv->users)) > 1) + { + sync_users (service); + } + else + { + if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, + uid, + &user->user_name, + &user->real_name, + &user->shell, + &user->login_count, + &user->icon_url, + &error)) + { + g_warning ("unable to retrieve user info: %s", error->message); + g_error_free (error); + + g_free (user); + + return; + } + + user->uid = uid; + + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); + + g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); + } } - - user->uid = uid; - - g_hash_table_insert (priv->users, - g_strdup (user->user_name), - user); - - g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); } static gboolean @@ -950,15 +978,28 @@ user_removed (DBusGProxy *proxy, UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); UserData *user; + gint size; - user = g_hash_table_find (priv->users, - compare_users_by_uid, - GUINT_TO_POINTER (uid)); - - g_hash_table_remove (priv->users, - user->user_name); + size = g_hash_table_size (priv->users); priv->count--; + + if (size == 0 || (size - priv->count) > 1) + { + sync_users (service); + } + else + { + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); + + if (user != NULL) + { + g_hash_table_remove (priv->users, + user->user_name); + } + } } static void diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index e156520..201445e 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -50,6 +50,9 @@ struct _UserData UsersServiceDbus *service; }; +#define MINIMUM_USERS 1 +#define MAXIMUM_USERS 7 + struct _UsersServiceDbus { GObject parent; }; diff --git a/src/users-service.c b/src/users-service.c index 9dbf218..9f240da 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -37,8 +37,6 @@ #include "users-service-dbus.h" #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" -#define MINIMUM_USERS 1 -#define MAXIMUM_USERS 7 typedef struct _ActivateData ActivateData; struct _ActivateData @@ -193,6 +191,23 @@ rebuild_items (DbusmenuMenuitem *root, if (count > 1 && count < 7) { + if (count > MINIMUM_USERS && count < MAXIMUM_USERS) + { + if (users != NULL) + { + GList *l = NULL; + + for (l = users; l != NULL; l = l->next) + { + users = g_list_delete_link (users, l); + } + + users = NULL; + } + + users = users_service_dbus_get_user_list (service); + } + for (u = users; u != NULL; u = g_list_next (u)) { user = u->data; @@ -222,7 +237,6 @@ user_added (UsersServiceDbus *service, { DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - users = g_list_append (users, user); count++; rebuild_items (root, service); @@ -235,7 +249,6 @@ user_removed (UsersServiceDbus *service, { DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - users = g_list_remove (users, user); count--; rebuild_items (root, service); @@ -248,7 +261,7 @@ create_items (DbusmenuMenuitem *root, g_return_if_fail (IS_USERS_SERVICE_DBUS (service)); count = users_service_dbus_get_user_count (service); - if (count > 1 && count < 7) + if (count > MINIMUM_USERS && count < MAXIMUM_USERS) { users = users_service_dbus_get_user_list (service); } -- cgit v1.2.3 From 4b357f8f4e604aa6587929c1993cba1a1b972fe4 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 01:23:13 -0500 Subject: cleanup --- src/users-service.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/users-service.c b/src/users-service.c index 9f240da..9e940ed 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -261,10 +261,6 @@ create_items (DbusmenuMenuitem *root, g_return_if_fail (IS_USERS_SERVICE_DBUS (service)); count = users_service_dbus_get_user_count (service); - if (count > MINIMUM_USERS && count < MAXIMUM_USERS) - { - users = users_service_dbus_get_user_list (service); - } rebuild_items (root, service); } -- cgit v1.2.3 From 997dd272496ef0071c227448a5320d42e437c421 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 01:27:22 -0500 Subject: sort users --- src/users-service.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/users-service.c b/src/users-service.c index 9e940ed..1fb8d36 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -166,6 +166,16 @@ remove_menu_item (DbusmenuMenuitem *root, gpointer user_data) dbusmenu_menuitem_child_delete (root, child); } +static gint +compare_users_by_username (const gchar *a, + const gchar *b) +{ + UserData *user1 = (UserData *)a; + UserData *user2 = (UserData *)b; + + return g_strcmp0 (user1->user_name, user2->user_name); +} + static void rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service) @@ -208,6 +218,8 @@ rebuild_items (DbusmenuMenuitem *root, 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)) { user = u->data; -- cgit v1.2.3 From 3e9432a11979cc8909c8a4db3c0b22651e11e638 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 10:18:23 -0500 Subject: Remove user_changed and users_icons_changed from the class --- src/users-service-dbus.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 201445e..fc14beb 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -61,9 +61,6 @@ struct _UsersServiceDbusClass { GObjectClass parent_class; /* Signals */ - gboolean (*user_changed) (UsersServiceDbus *self, gchar **name, gpointer user_data); - gboolean (*users_icons_changed) (UsersServiceDbus *self, GArray **icons, gpointer user_data); - void (* users_loaded) (UsersServiceDbus *self, gpointer user_data); void (* user_added) (UsersServiceDbus *self, gint64 uid, gpointer user_data); -- cgit v1.2.3 From 62f44cf97e38da112c70afeb8545d87042d251e2 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 10:31:55 -0500 Subject: only add menuitems if the current seat can activate new sessions --- src/users-service.c | 70 +++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/users-service.c b/src/users-service.c index 1fb8d36..51c6c5d 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -183,6 +183,9 @@ rebuild_items (DbusmenuMenuitem *root, DbusmenuMenuitem *mi = NULL; GList *u; UserData *user; + gboolean can_activate; + + can_activate = users_service_dbus_can_activate_session (service); dbusmenu_menuitem_foreach (root, remove_menu_item, NULL); @@ -191,55 +194,58 @@ rebuild_items (DbusmenuMenuitem *root, g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); dbusmenu_menuitem_child_append(root, mi); - if (check_guest_session ()) + if (can_activate == TRUE) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Guest Session")); - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); - } + if (check_guest_session ()) + { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Guest Session")); + dbusmenu_menuitem_child_append (root, mi); + 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 > 1 && count < 7) { - if (users != NULL) + if (count > MINIMUM_USERS && count < MAXIMUM_USERS) { - GList *l = NULL; - - for (l = users; l != NULL; l = l->next) + if (users != NULL) { - users = g_list_delete_link (users, l); + GList *l = NULL; + + for (l = users; l != NULL; l = l->next) + { + users = g_list_delete_link (users, l); + } + + users = NULL; } - users = NULL; + users = users_service_dbus_get_user_list (service); } - users = users_service_dbus_get_user_list (service); - } + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); - users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + for (u = users; u != NULL; u = g_list_next (u)) + { + user = u->data; - for (u = users; u != NULL; u = g_list_next (u)) - { - user = u->data; + user->service = service; - user->service = service; + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); + } + } + if (check_new_session ()) + { mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, user->real_name); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); } } - - if (check_new_session ()) - { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("New Session...")); - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); - } } static void -- 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