[gdm] Add has-multiple-users property



commit f3dba34a201e2e31fe6f8c64ff532d749f8a52b9
Author: William Jon McCann <jmccann redhat com>
Date:   Wed Jun 9 11:45:55 2010 -0400

    Add has-multiple-users property
    
    Clients that only want to take action when this changes don't have to
    list all users and watch for add/remove events.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621131

 gui/simple-greeter/gdm-user-manager.c |   46 ++++++++++++++++++++++++++++++---
 1 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/gui/simple-greeter/gdm-user-manager.c b/gui/simple-greeter/gdm-user-manager.c
index 30343ea..8e225c1 100644
--- a/gui/simple-greeter/gdm-user-manager.c
+++ b/gui/simple-greeter/gdm-user-manager.c
@@ -97,11 +97,13 @@ struct GdmUserManagerPrivate
         guint                  ck_history_id;
 
         gboolean               is_loaded;
+        gboolean               has_multiple_users;
 };
 
 enum {
         PROP_0,
-        PROP_IS_LOADED
+        PROP_IS_LOADED,
+        PROP_HAS_MULTIPLE_USERS
 };
 
 enum {
@@ -613,6 +615,16 @@ create_user (GdmUserManager *manager)
 }
 
 static void
+set_has_multiple_users (GdmUserManager *manager,
+                        gboolean        has_multiple_users)
+{
+        if (manager->priv->has_multiple_users != has_multiple_users) {
+                manager->priv->has_multiple_users = has_multiple_users;
+                g_object_notify (G_OBJECT (manager), "has-multiple-users");
+        }
+}
+
+static void
 add_user (GdmUserManager *manager,
           GdmUser        *user)
 {
@@ -623,6 +635,10 @@ add_user (GdmUserManager *manager,
         if (manager->priv->is_loaded) {
                 g_signal_emit (manager, signals[USER_ADDED], 0, user);
         }
+
+        if (g_hash_table_size (manager->priv->users_by_name) > 1) {
+                set_has_multiple_users (manager, TRUE);
+        }
 }
 
 static GdmUser *
@@ -641,6 +657,20 @@ add_new_user_for_pwent (GdmUserManager *manager,
         return user;
 }
 
+static void
+remove_user (GdmUserManager *manager,
+             GdmUser        *user)
+{
+        g_signal_handlers_disconnect_by_func (user, on_user_changed, manager);
+        g_signal_handlers_disconnect_by_func (user, on_user_sessions_changed, manager);
+        g_hash_table_remove (manager->priv->users_by_name, gdm_user_get_user_name (user));
+        g_signal_emit (manager, signals[USER_REMOVED], 0, user);
+
+        if (g_hash_table_size (manager->priv->users_by_name) > 1) {
+                set_has_multiple_users (manager, FALSE);
+        }
+}
+
 static char *
 get_current_seat_id (DBusGConnection *connection)
 {
@@ -1356,9 +1386,7 @@ reload_passwd (GdmUserManager *manager)
         /* Go through and handle removed users */
         for (list = old_users; list; list = list->next) {
                 if (! g_slist_find (new_users, list->data)) {
-                        g_signal_emit (manager, signals[USER_REMOVED], 0, list->data);
-                        g_hash_table_remove (manager->priv->users_by_name,
-                                             gdm_user_get_user_name (list->data));
+                        remove_user (manager, list->data);
                 }
         }
 
@@ -1541,6 +1569,9 @@ gdm_user_manager_get_property (GObject        *object,
         case PROP_IS_LOADED:
                 g_value_set_boolean (value, manager->priv->is_loaded);
                 break;
+        case PROP_HAS_MULTIPLE_USERS:
+                g_value_set_boolean (value, manager->priv->has_multiple_users);
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -1611,6 +1642,13 @@ gdm_user_manager_class_init (GdmUserManagerClass *klass)
                                                                NULL,
                                                                FALSE,
                                                                G_PARAM_READABLE));
+        g_object_class_install_property (object_class,
+                                         PROP_HAS_MULTIPLE_USERS,
+                                         g_param_spec_boolean ("has-multiple-users",
+                                                               NULL,
+                                                               NULL,
+                                                               FALSE,
+                                                               G_PARAM_READABLE));
 
         signals [USER_ADDED] =
                 g_signal_new ("user-added",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]