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/users-service.c | 144 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 33 deletions(-) (limited to 'src/users-service.c') 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); -- 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.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/users-service.c') 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/users-service.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/users-service.c') 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...")); -- 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.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/users-service.c') 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.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/users-service.c') 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.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/users-service.c') 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 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.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/users-service.c') 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 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.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/users-service.c') 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 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(+) (limited to 'src/users-service.c') 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 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.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/users-service.c') 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(-) (limited to 'src/users-service.c') 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(+) (limited to 'src/users-service.c') 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 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(-) (limited to 'src/users-service.c') 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