diff options
Diffstat (limited to 'src/session-service.c')
-rw-r--r-- | src/session-service.c | 161 |
1 files changed, 77 insertions, 84 deletions
diff --git a/src/session-service.c b/src/session-service.c index 289bff8..eb1966e 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -68,9 +68,6 @@ static UsersServiceDbus *dbus_interface = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; static DbusmenuMenuitem *switch_menuitem = NULL; -static gint count; -static GList *users; - static DbusmenuMenuitem * root_menuitem = NULL; static GMainLoop * mainloop = NULL; static DBusGProxy * up_main_proxy = NULL; @@ -406,7 +403,15 @@ compare_users_by_username (const gchar *a, UserData *user1 = (UserData *)a; UserData *user2 = (UserData *)b; - return g_strcmp0 (user1->user_name, user2->user_name); + gint retval = g_strcmp0 (user1->real_name, user2->real_name); + + /* If they're the same, they're both in conflict. */ + if (retval == 0) { + user1->real_name_conflict = TRUE; + user2->real_name_conflict = TRUE; + } + + return retval; } /* Builds up the menu for us */ @@ -415,6 +420,7 @@ rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service) { DbusmenuMenuitem *mi = NULL; + DbusmenuMenuitem * guest_mi = NULL; GList *u; UserData *user; gboolean can_activate; @@ -444,12 +450,12 @@ rebuild_items (DbusmenuMenuitem *root, if (check_guest_session ()) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, _("Guest Session")); - dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, FALSE); - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); + guest_mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (guest_mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); + dbusmenu_menuitem_property_set (guest_mi, USER_ITEM_PROP_NAME, _("Guest Session")); + dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, FALSE); + dbusmenu_menuitem_child_append (root, guest_mi); + g_signal_connect (G_OBJECT (guest_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL); } if (check_new_session ()) @@ -472,39 +478,55 @@ rebuild_items (DbusmenuMenuitem *root, } } - 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); - - users = g_list_sort (users, (GCompareFunc)compare_users_by_username); - - for (u = users; u != NULL; u = g_list_next (u)) - { - user = u->data; - - user->service = service; - - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); - dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); - } - } - } + GList * users = NULL; + users = users_service_dbus_get_user_list (service); + guint user_count = g_list_length(users); + + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + } + + for (u = users; u != NULL; u = g_list_next (u)) { + user = u->data; + user->service = service; + + if (user->uid == getuid()) { + /* Hide me from the list */ + continue; + } + + if (g_strcmp0(user->user_name, "guest") == 0) { + /* Check to see if the guest has sessions and so therefore should + get a check mark. */ + if (user->sessions != NULL) { + dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, TRUE); + } + /* If we're showing user accounts, keep going through the list */ + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + continue; + } + /* If not, we can stop here */ + break; + } + + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); + if (user->real_name_conflict) { + gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); + g_free(conflictedname); + } else { + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); + } + dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); + } + } + + g_list_free(users); + } DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); @@ -521,7 +543,7 @@ rebuild_items (DbusmenuMenuitem *root, suspend_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set_bool(suspend_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Suspend")); + dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sleep")); dbusmenu_menuitem_child_append(root, suspend_mi); g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend"); @@ -542,9 +564,9 @@ rebuild_items (DbusmenuMenuitem *root, shutdown_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { - dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down")); + dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch Off")); } else { - dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down...")); + dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch Off...")); } dbusmenu_menuitem_child_append(root, shutdown_mi); g_signal_connect(G_OBJECT(shutdown_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "shutdown"); @@ -562,42 +584,13 @@ rebuild_items (DbusmenuMenuitem *root, /* Signal called when a user is added. It updates the count and rebuilds the menu */ static void -user_added (UsersServiceDbus *service, - UserData *user, - gpointer user_data) +user_change (UsersServiceDbus *service, + UserData *user, + gpointer user_data) { - DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - - count++; - - rebuild_items (root, service); -} - -/* Signal called when a user is deleted. It updates the count and - rebuilds the menu */ -static void -user_removed (UsersServiceDbus *service, - UserData *user, - gpointer user_data) -{ - DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - - count--; - - rebuild_items (root, service); -} - -/* Wrapper around rebuild_items that is used on the first call - so that we can initialize the count variable. */ -static void -create_items (DbusmenuMenuitem *root, - UsersServiceDbus *service) -{ - g_return_if_fail (IS_USERS_SERVICE_DBUS (service)); - - count = users_service_dbus_get_user_count (service); - - rebuild_items (root, service); + DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + rebuild_items (root, service); + return; } /* When the service interface starts to shutdown, we @@ -638,15 +631,15 @@ main (int argc, char ** argv) dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); - create_items (root_menuitem, dbus_interface); + rebuild_items (root_menuitem, dbus_interface); g_signal_connect (G_OBJECT (dbus_interface), "user-added", - G_CALLBACK (user_added), + G_CALLBACK (user_change), root_menuitem); g_signal_connect (G_OBJECT (dbus_interface), "user-removed", - G_CALLBACK (user_removed), + G_CALLBACK (user_change), root_menuitem); setup_up(); |