]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-gobject/user.c
Revert r2392 - it seems to have broken ABI in liblightdm-gobject
[sojka/lightdm.git] / liblightdm-gobject / user.c
index 4fb5f0449bb698d6ce47c494aab81f469f328dda..e47d563be7932e8ca2220d8d951df76d62c480f2 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2014 Canonical, Ltd.
  * Authors: Robert Ancell <robert.ancell@canonical.com>
  *          Michael Terry <michael.terry@canonical.com>
- * 
+ *
  * This library is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation; either version 2 or version 3 of the License.
 
 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,
@@ -38,7 +37,8 @@ enum
     USER_PROP_LAYOUTS,
     USER_PROP_SESSION,
     USER_PROP_LOGGED_IN,
-    USER_PROP_HAS_MESSAGES
+    USER_PROP_HAS_MESSAGES,
+    USER_PROP_UID,
 };
 
 enum
@@ -103,7 +103,7 @@ static LightDMUser *
 wrap_common_user (CommonUser *user)
 {
     LightDMUser *lightdm_user = g_object_new (LIGHTDM_TYPE_USER, "common-user", user, NULL);
-    g_signal_connect (user, "changed", G_CALLBACK (user_changed_cb), lightdm_user);
+    g_signal_connect (user, USER_SIGNAL_CHANGED, G_CALLBACK (user_changed_cb), lightdm_user);
     return lightdm_user;
 }
 
@@ -166,9 +166,9 @@ initialize_user_list_if_needed (LightDMUserList *user_list)
     priv->lightdm_list = g_list_reverse (priv->lightdm_list);
 
     CommonUserList *common_list = common_user_list_get_instance ();
-    g_signal_connect (common_list, "user-added", G_CALLBACK (user_list_added_cb), user_list);
-    g_signal_connect (common_list, "user-changed", G_CALLBACK (user_list_changed_cb), user_list);
-    g_signal_connect (common_list, "user-removed", G_CALLBACK (user_list_removed_cb), user_list);
+    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;
 }
@@ -239,10 +239,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);
 }
@@ -260,6 +260,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:
@@ -296,7 +297,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
@@ -305,7 +322,7 @@ lightdm_user_list_class_init (LightDMUserListClass *klass)
      * The ::user-added signal gets emitted when a user account is created.
      **/
     list_signals[USER_ADDED] =
-        g_signal_new ("user-added",
+        g_signal_new (LIGHTDM_USER_LIST_SIGNAL_USER_ADDED,
                       G_TYPE_FROM_CLASS (klass),
                       G_SIGNAL_RUN_LAST,
                       G_STRUCT_OFFSET (LightDMUserListClass, user_added),
@@ -321,7 +338,7 @@ lightdm_user_list_class_init (LightDMUserListClass *klass)
      * The ::user-changed signal gets emitted when a user account is modified.
      **/
     list_signals[USER_CHANGED] =
-        g_signal_new ("user-changed",
+        g_signal_new (LIGHTDM_USER_LIST_SIGNAL_USER_CHANGED,
                       G_TYPE_FROM_CLASS (klass),
                       G_SIGNAL_RUN_LAST,
                       G_STRUCT_OFFSET (LightDMUserListClass, user_changed),
@@ -337,7 +354,7 @@ lightdm_user_list_class_init (LightDMUserListClass *klass)
      * The ::user-removed signal gets emitted when a user account is removed.
      **/
     list_signals[USER_REMOVED] =
-        g_signal_new ("user-removed",
+        g_signal_new (LIGHTDM_USER_LIST_SIGNAL_USER_REMOVED,
                       G_TYPE_FROM_CLASS (klass),
                       G_SIGNAL_RUN_LAST,
                       G_STRUCT_OFFSET (LightDMUserListClass, user_removed),
@@ -349,9 +366,9 @@ lightdm_user_list_class_init (LightDMUserListClass *klass)
 /**
  * lightdm_user_get_name:
  * @user: A #LightDMUser
- * 
+ *
  * Get the name of a user.
- * 
+ *
  * Return value: The name of the given user
  **/
 const gchar *
@@ -364,7 +381,7 @@ lightdm_user_get_name (LightDMUser *user)
 /**
  * lightdm_user_get_real_name:
  * @user: A #LightDMUser
- * 
+ *
  * Get the real name of a user.
  *
  * Return value: The real name of the given user
@@ -379,9 +396,9 @@ lightdm_user_get_real_name (LightDMUser *user)
 /**
  * lightdm_user_get_display_name:
  * @user: A #LightDMUser
- * 
+ *
  * Get the display name of a user.
- * 
+ *
  * Return value: The display name of the given user
  **/
 const gchar *
@@ -394,9 +411,9 @@ lightdm_user_get_display_name (LightDMUser *user)
 /**
  * lightdm_user_get_home_directory:
  * @user: A #LightDMUser
- * 
+ *
  * Get the home directory for a user.
- * 
+ *
  * Return value: The users home directory
  */
 const gchar *
@@ -409,10 +426,10 @@ lightdm_user_get_home_directory (LightDMUser *user)
 /**
  * lightdm_user_get_image:
  * @user: A #LightDMUser
- * 
+ *
  * 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)
@@ -424,10 +441,10 @@ lightdm_user_get_image (LightDMUser *user)
 /**
  * lightdm_user_get_background:
  * @user: A #LightDMUser
- * 
+ *
  * 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)
@@ -439,10 +456,10 @@ lightdm_user_get_background (LightDMUser *user)
 /**
  * lightdm_user_get_language:
  * @user: A #LightDMUser
- * 
+ *
  * 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)
@@ -454,10 +471,10 @@ lightdm_user_get_language (LightDMUser *user)
 /**
  * lightdm_user_get_layout:
  * @user: A #LightDMUser
- * 
+ *
  * 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)
@@ -469,9 +486,9 @@ lightdm_user_get_layout (LightDMUser *user)
 /**
  * lightdm_user_get_layouts:
  * @user: A #LightDMUser
- * 
+ *
  * Get the configured keyboard layouts for a user.
- * 
+ *
  * Return value: (transfer none): A NULL-terminated array of keyboard layouts for the given user.  Copy the values if you want to use them long term.
  **/
 const gchar * const *
@@ -484,10 +501,10 @@ lightdm_user_get_layouts (LightDMUser *user)
 /**
  * lightdm_user_get_session:
  * @user: A #LightDMUser
- * 
+ *
  * 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)
@@ -499,9 +516,9 @@ lightdm_user_get_session (LightDMUser *user)
 /**
  * lightdm_user_get_logged_in:
  * @user: A #LightDMUser
- * 
+ *
  * Check if a user is logged in.
- * 
+ *
  * Return value: #TRUE if the user is currently logged in.
  **/
 gboolean
@@ -514,9 +531,9 @@ lightdm_user_get_logged_in (LightDMUser *user)
 /**
  * lightdm_user_get_has_messages:
  * @user: A #LightDMUser
- * 
+ *
  * Check if a user has waiting messages.
- * 
+ *
  * Return value: #TRUE if the user has waiting messages.
  **/
 gboolean
@@ -526,6 +543,21 @@ lightdm_user_get_has_messages (LightDMUser *user)
     return common_user_get_has_messages (GET_USER_PRIVATE (user)->common_user);
 }
 
+/**
+ * lightdm_user_get_uid:
+ * @user: A #LightDMUser
+ *
+ * Get the uid of a user.
+ *
+ * Return value: The uid of the given user
+ **/
+uid_t
+lightdm_user_get_uid (LightDMUser *user)
+{
+    g_return_val_if_fail (LIGHTDM_IS_USER (user), (uid_t)-1);
+    return common_user_get_uid (GET_USER_PRIVATE (user)->common_user);
+}
+
 static void
 lightdm_user_init (LightDMUser *user)
 {
@@ -599,6 +631,9 @@ lightdm_user_get_property (GObject    *object,
     case USER_PROP_HAS_MESSAGES:
         g_value_set_boolean (value, lightdm_user_get_has_messages (self));
         break;
+    case USER_PROP_UID:
+        g_value_set_uint64 (value, lightdm_user_get_uid (self));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -620,7 +655,7 @@ static void
 lightdm_user_class_init (LightDMUserClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
     g_type_class_add_private (klass, sizeof (LightDMUserPrivate));
 
     object_class->set_property = lightdm_user_set_property;
@@ -640,14 +675,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",
@@ -661,21 +696,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",
@@ -710,14 +745,21 @@ 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_uint64 ("uid",
+                                                          "uid",
+                                                          "User UID",
+                                                          0, G_MAXUINT64, 0,
+                                                          G_PARAM_READABLE));
 
     /**
      * LightDMUser::changed:
@@ -726,7 +768,7 @@ lightdm_user_class_init (LightDMUserClass *klass)
      * The ::changed signal gets emitted this user account is modified.
      **/
     user_signals[CHANGED] =
-        g_signal_new ("changed",
+        g_signal_new (LIGHTDM_SIGNAL_USER_CHANGED,
                       G_TYPE_FROM_CLASS (klass),
                       G_SIGNAL_RUN_LAST,
                       G_STRUCT_OFFSET (LightDMUserClass, changed),