]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-gobject/user.c
Load all users only when really needed
[sojka/lightdm.git] / liblightdm-gobject / user.c
index f8355df2f600f21d0d972d52af31f1ec9e314850..75f65438e8fc6799cb0e05ed715dad16c1789054 100644 (file)
 
 enum
 {
-    LIST_PROP_0,
-    LIST_PROP_NUM_USERS,
+    LIST_PROP_NUM_USERS = 1,
+    LIST_PROP_LENGTH,  
     LIST_PROP_USERS,
 };
 
 enum
 {
-    USER_PROP_0,
-    USER_PROP_COMMON_USER,
+    USER_PROP_COMMON_USER = 1,
     USER_PROP_NAME,
     USER_PROP_REAL_NAME,
     USER_PROP_DISPLAY_NAME,
@@ -148,7 +147,7 @@ user_list_removed_cb (CommonUserList *common_list, CommonUser *common_user, Ligh
 }
 
 static void
-initialize_user_list_if_needed (LightDMUserList *user_list)
+initialize_user_list_if_needed (LightDMUserList *user_list, const gchar *username)
 {
     LightDMUserListPrivate *priv = GET_LIST_PRIVATE (user_list);
     GList *common_users;
@@ -157,21 +156,30 @@ initialize_user_list_if_needed (LightDMUserList *user_list)
     if (priv->initialized)
         return;
 
-    common_users = common_user_list_get_users (common_user_list_get_instance ());
-    for (link = common_users; link; link = link->next)
+    if (!username)
     {
-        CommonUser *user = link->data;
+        common_users = common_user_list_get_users (common_user_list_get_instance ());
+        for (link = common_users; link; link = link->next)
+        {
+            CommonUser *user = link->data;
+            LightDMUser *lightdm_user = wrap_common_user (user);
+            priv->lightdm_list = g_list_prepend (priv->lightdm_list, lightdm_user);
+        }
+        priv->lightdm_list = g_list_reverse (priv->lightdm_list);
+
+        priv->initialized = TRUE;
+    }
+    else
+    {
+        CommonUser *user = common_user_list_get_user_by_name (common_user_list_get_instance (), username);
         LightDMUser *lightdm_user = wrap_common_user (user);
-        priv->lightdm_list = g_list_prepend (priv->lightdm_list, lightdm_user);
+        priv->lightdm_list = g_list_append (priv->lightdm_list, lightdm_user);
     }
-    priv->lightdm_list = g_list_reverse (priv->lightdm_list);
 
     CommonUserList *common_list = common_user_list_get_instance ();
     g_signal_connect (common_list, USER_LIST_SIGNAL_USER_ADDED, G_CALLBACK (user_list_added_cb), user_list);
     g_signal_connect (common_list, USER_LIST_SIGNAL_USER_CHANGED, G_CALLBACK (user_list_changed_cb), user_list);
     g_signal_connect (common_list, USER_LIST_SIGNAL_USER_REMOVED, G_CALLBACK (user_list_removed_cb), user_list);
-
-    priv->initialized = TRUE;
 }
 
 /**
@@ -184,7 +192,7 @@ gint
 lightdm_user_list_get_length (LightDMUserList *user_list)
 {
     g_return_val_if_fail (LIGHTDM_IS_USER_LIST (user_list), 0);
-    initialize_user_list_if_needed (user_list);
+    initialize_user_list_if_needed (user_list, NULL);
     return g_list_length (GET_LIST_PRIVATE (user_list)->lightdm_list);
 }
 
@@ -201,7 +209,7 @@ GList *
 lightdm_user_list_get_users (LightDMUserList *user_list)
 {
     g_return_val_if_fail (LIGHTDM_IS_USER_LIST (user_list), NULL);
-    initialize_user_list_if_needed (user_list);
+    initialize_user_list_if_needed (user_list, NULL);
     return GET_LIST_PRIVATE (user_list)->lightdm_list;
 }
 
@@ -222,7 +230,7 @@ lightdm_user_list_get_user_by_name (LightDMUserList *user_list, const gchar *use
     g_return_val_if_fail (LIGHTDM_IS_USER_LIST (user_list), NULL);
     g_return_val_if_fail (username != NULL, NULL);
 
-    initialize_user_list_if_needed (user_list);
+    initialize_user_list_if_needed (user_list, username);
 
     for (link = GET_LIST_PRIVATE (user_list)->lightdm_list; link; link = link->next)
     {
@@ -240,10 +248,10 @@ lightdm_user_list_init (LightDMUserList *user_list)
 }
 
 static void
-lightdm_user_list_set_property (GObject    *object,
-                                guint       prop_id,
+lightdm_user_list_set_property (GObject      *object,
+                                guint         prop_id,
                                 const GValue *value,
-                                GParamSpec *pspec)
+                                GParamSpec   *pspec)
 {
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 }
@@ -261,6 +269,7 @@ lightdm_user_list_get_property (GObject    *object,
     switch (prop_id)
     {
     case LIST_PROP_NUM_USERS:
+    case LIST_PROP_LENGTH:      
         g_value_set_int (value, lightdm_user_list_get_length (self));
         break;
     default:
@@ -297,7 +306,23 @@ lightdm_user_list_class_init (LightDMUserListClass *klass)
                                                        "num-users",
                                                        "Number of login users",
                                                        0, G_MAXINT, 0,
+                                                       G_PARAM_DEPRECATED | G_PARAM_READABLE));
+
+    g_object_class_install_property (object_class,
+                                     LIST_PROP_LENGTH,
+                                     g_param_spec_int ("length",
+                                                       "length",
+                                                       "Number of login users",
+                                                       0, G_MAXINT, 0,
                                                        G_PARAM_READABLE));
+
+    /*g_object_class_install_property (object_class,
+                                     LIST_PROP_USERS,
+                                     g_param_spec_int ("users",
+                                                       "users",
+                                                       "Users to present to user",
+                                                       0, G_MAXINT, 0,
+                                                       G_PARAM_READABLE));*/
     /**
      * LightDMUserList::user-added:
      * @user_list: A #LightDMUserList
@@ -413,7 +438,7 @@ lightdm_user_get_home_directory (LightDMUser *user)
  *
  * Get the image URI for a user.
  *
- * Return value: The image URI for the given user or #NULL if no URI
+ * Return value: (nullable): The image URI for the given user or #NULL if no URI
  **/
 const gchar *
 lightdm_user_get_image (LightDMUser *user)
@@ -428,7 +453,7 @@ lightdm_user_get_image (LightDMUser *user)
  *
  * Get the background file path for a user.
  *
- * Return value: The background file path for the given user or #NULL if no path
+ * Return value: (nullable): The background file path for the given user or #NULL if no path
  **/
 const gchar *
 lightdm_user_get_background (LightDMUser *user)
@@ -443,7 +468,7 @@ lightdm_user_get_background (LightDMUser *user)
  *
  * Get the language for a user.
  *
- * Return value: The language in the form of a local specification (e.g. "de_DE.UTF-8") for the given user or #NULL if using the system default locale.
+ * Return value: (nullable): The language in the form of a local specification (e.g. "de_DE.UTF-8") for the given user or #NULL if using the system default locale.
  **/
 const gchar *
 lightdm_user_get_language (LightDMUser *user)
@@ -458,7 +483,7 @@ lightdm_user_get_language (LightDMUser *user)
  *
  * Get the keyboard layout for a user.
  *
- * Return value: The keyboard layout for the given user or #NULL if using system defaults.  Copy the value if you want to use it long term.
+ * Return value: (nullable): The keyboard layout for the given user or #NULL if using system defaults.  Copy the value if you want to use it long term.
  **/
 const gchar *
 lightdm_user_get_layout (LightDMUser *user)
@@ -488,7 +513,7 @@ lightdm_user_get_layouts (LightDMUser *user)
  *
  * Get the session for a user.
  *
- * Return value: The session for the given user or #NULL if using system defaults.
+ * Return value: (nullable): The session for the given user or #NULL if using system defaults.
  **/
 const gchar *
 lightdm_user_get_session (LightDMUser *user)
@@ -659,14 +684,14 @@ lightdm_user_class_init (LightDMUserClass *klass)
                                                           "name",
                                                           "Username",
                                                           NULL,
-                                                          G_PARAM_READWRITE));
+                                                          G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_REAL_NAME,
                                      g_param_spec_string ("real-name",
                                                           "real-name",
                                                           "Users real name",
                                                           NULL,
-                                                          G_PARAM_READWRITE));
+                                                          G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_DISPLAY_NAME,
                                      g_param_spec_string ("display-name",
@@ -680,21 +705,21 @@ lightdm_user_class_init (LightDMUserClass *klass)
                                                           "home-directory",
                                                           "Home directory",
                                                           NULL,
-                                                          G_PARAM_READWRITE));
+                                                          G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_IMAGE,
                                      g_param_spec_string ("image",
                                                           "image",
                                                           "Avatar image",
                                                           NULL,
-                                                          G_PARAM_READWRITE));
+                                                          G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_BACKGROUND,
                                      g_param_spec_string ("background",
                                                           "background",
                                                           "User background",
                                                           NULL,
-                                                          G_PARAM_READWRITE));
+                                                          G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_LANGUAGE,
                                      g_param_spec_string ("language",
@@ -729,20 +754,20 @@ lightdm_user_class_init (LightDMUserClass *klass)
                                                            "logged-in",
                                                            "TRUE if the user is currently in a session",
                                                            FALSE,
-                                                           G_PARAM_READWRITE));
+                                                           G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_LOGGED_IN,
                                      g_param_spec_boolean ("has-messages",
                                                            "has-messages",
                                                            "TRUE if the user is has waiting messages",
                                                            FALSE,
-                                                           G_PARAM_READWRITE));
+                                                           G_PARAM_READABLE));
     g_object_class_install_property (object_class,
                                      USER_PROP_UID,
-                                     g_param_spec_string ("uid",
+                                     g_param_spec_uint64 ("uid",
                                                           "uid",
                                                           "User UID",
-                                                          NULL,
+                                                          0, G_MAXUINT64, 0,
                                                           G_PARAM_READABLE));
 
     /**