Blame SOURCES/0011-lib-simplify-code-dramatically.patch

baf615
From 1e2385077256bd5156d4269becc3a9e0a2d29c58 Mon Sep 17 00:00:00 2001
baf615
From: Ray Strode <rstrode@redhat.com>
baf615
Date: Tue, 3 Oct 2017 13:48:52 -0400
baf615
Subject: [PATCH 11/13] lib: simplify code dramatically
baf615
baf615
ActUser is a wrapper over the accountsservice daemon's
baf615
managed user objects.  There's a nearly 1-to-1 correspondence
baf615
between properties on the proxy to the daemon and properties
baf615
on the ActUser object.
baf615
baf615
This commit dramatically reduces the code, by leveraging the
baf615
proxies properties directly, rather than duplicating the values
baf615
on the ActUser object.
baf615
baf615
At the same time, it drops manual GetAll() calls for synchronizing
baf615
the proxies properties, since it's completely redundant with the
baf615
work the proxy is doing under the hood anyway.
baf615
---
baf615
 src/libaccountsservice/act-user.c | 676 ++++++++------------------------------
baf615
 1 file changed, 143 insertions(+), 533 deletions(-)
baf615
baf615
diff --git a/src/libaccountsservice/act-user.c b/src/libaccountsservice/act-user.c
baf615
index 17acacb..94884a1 100644
baf615
--- a/src/libaccountsservice/act-user.c
baf615
+++ b/src/libaccountsservice/act-user.c
baf615
@@ -81,94 +81,66 @@ enum {
baf615
         PROP_PASSWORD_HINT,
baf615
         PROP_HOME_DIR,
baf615
         PROP_SHELL,
baf615
         PROP_EMAIL,
baf615
         PROP_LOCATION,
baf615
         PROP_LOCKED,
baf615
         PROP_AUTOMATIC_LOGIN,
baf615
         PROP_SYSTEM_ACCOUNT,
baf615
         PROP_NONEXISTENT,
baf615
         PROP_LOCAL_ACCOUNT,
baf615
         PROP_LOGIN_FREQUENCY,
baf615
         PROP_LOGIN_TIME,
baf615
         PROP_LOGIN_HISTORY,
baf615
         PROP_ICON_FILE,
baf615
         PROP_LANGUAGE,
baf615
         PROP_X_SESSION,
baf615
         PROP_IS_LOADED
baf615
 };
baf615
 
baf615
 enum {
baf615
         CHANGED,
baf615
         SESSIONS_CHANGED,
baf615
         LAST_SIGNAL
baf615
 };
baf615
 
baf615
 struct _ActUser {
baf615
         GObject         parent;
baf615
 
baf615
         GDBusConnection *connection;
baf615
         AccountsUser    *accounts_proxy;
baf615
-        GDBusProxy      *object_proxy;
baf615
-        GCancellable    *get_all_cancellable;
baf615
-        char            *object_path;
baf615
-
baf615
-        uid_t           uid;
baf615
-        char           *user_name;
baf615
-        char           *real_name;
baf615
-        char           *password_hint;
baf615
-        char           *home_dir;
baf615
-        char           *shell;
baf615
-        char           *email;
baf615
-        char           *location;
baf615
-        char           *icon_file;
baf615
-        char           *language;
baf615
-        char           *x_session;
baf615
+
baf615
         GList          *our_sessions;
baf615
         GList          *other_sessions;
baf615
-        int             login_frequency;
baf615
-        gint64          login_time;
baf615
-        GVariant       *login_history;
baf615
-
baf615
-        ActUserAccountType  account_type;
baf615
-        ActUserPasswordMode password_mode;
baf615
-
baf615
-        guint           uid_set : 1;
baf615
 
baf615
         guint           is_loaded : 1;
baf615
-        guint           locked : 1;
baf615
-        guint           automatic_login : 1;
baf615
-        guint           system_account : 1;
baf615
-        guint           local_account : 1;
baf615
         guint           nonexistent : 1;
baf615
-
baf615
-        guint           update_info_timeout_id;
baf615
 };
baf615
 
baf615
 struct _ActUserClass
baf615
 {
baf615
         GObjectClass parent_class;
baf615
 };
baf615
 
baf615
 static void act_user_finalize     (GObject      *object);
baf615
 
baf615
 static guint signals[LAST_SIGNAL] = { 0 };
baf615
 
baf615
 G_DEFINE_TYPE (ActUser, act_user, G_TYPE_OBJECT)
baf615
 
baf615
 static int
baf615
 session_compare (const char *a,
baf615
                  const char *b)
baf615
 {
baf615
         if (a == NULL) {
baf615
                 return 1;
baf615
         } else if (b == NULL) {
baf615
                 return -1;
baf615
         }
baf615
 
baf615
         return strcmp (a, b);
baf615
 }
baf615
 
baf615
 void
baf615
 _act_user_add_session (ActUser    *user,
baf615
                        const char *ssid,
baf615
                        gboolean    is_ours)
baf615
@@ -238,128 +210,75 @@ act_user_get_num_sessions (ActUser    *user)
baf615
 /**
baf615
  * act_user_get_num_sessions_anywhere:
baf615
  * @user: a user
baf615
  *
baf615
  * Get the number of sessions for a user on any seat of any type.
baf615
  * See also act_user_get_num_sessions().
baf615
  *
baf615
  * (Currently, this function is only implemented for systemd-logind.
baf615
  * For ConsoleKit, it is equivalent to act_user_get_num_sessions.)
baf615
  *
baf615
  * Returns: the number of sessions
baf615
  */
baf615
 guint
baf615
 act_user_get_num_sessions_anywhere (ActUser    *user)
baf615
 {
baf615
         return (g_list_length (user->our_sessions)
baf615
                 + g_list_length (user->other_sessions));
baf615
 }
baf615
 
baf615
 static void
baf615
 act_user_get_property (GObject    *object,
baf615
                        guint       param_id,
baf615
                        GValue     *value,
baf615
                        GParamSpec *pspec)
baf615
 {
baf615
         ActUser *user;
baf615
 
baf615
         user = ACT_USER (object);
baf615
 
baf615
         switch (param_id) {
baf615
-        case PROP_UID:
baf615
-                g_value_set_int (value, user->uid);
baf615
-                break;
baf615
-        case PROP_USER_NAME:
baf615
-                g_value_set_string (value, user->user_name);
baf615
-                break;
baf615
-        case PROP_REAL_NAME:
baf615
-                g_value_set_string (value, user->real_name);
baf615
-                break;
baf615
-        case PROP_ACCOUNT_TYPE:
baf615
-                g_value_set_int (value, user->account_type);
baf615
-                break;
baf615
-        case PROP_PASSWORD_MODE:
baf615
-                g_value_set_int (value, user->password_mode);
baf615
-                break;
baf615
-        case PROP_PASSWORD_HINT:
baf615
-                g_value_set_string (value, user->password_hint);
baf615
-                break;
baf615
-        case PROP_HOME_DIR:
baf615
-                g_value_set_string (value, user->home_dir);
baf615
-                break;
baf615
-        case PROP_LOGIN_FREQUENCY:
baf615
-                g_value_set_int (value, user->login_frequency);
baf615
-                break;
baf615
-        case PROP_LOGIN_TIME:
baf615
-                g_value_set_int64 (value, user->login_time);
baf615
-                break;
baf615
-        case PROP_LOGIN_HISTORY:
baf615
-                g_value_set_variant (value, user->login_history);
baf615
-                break;
baf615
-        case PROP_SHELL:
baf615
-                g_value_set_string (value, user->shell);
baf615
-                break;
baf615
-        case PROP_EMAIL:
baf615
-                g_value_set_string (value, user->email);
baf615
-                break;
baf615
-        case PROP_LOCATION:
baf615
-                g_value_set_string (value, user->location);
baf615
-                break;
baf615
-        case PROP_ICON_FILE:
baf615
-                g_value_set_string (value, user->icon_file);
baf615
-                break;
baf615
-        case PROP_LANGUAGE:
baf615
-                g_value_set_string (value, user->language);
baf615
-                break;
baf615
-        case PROP_X_SESSION:
baf615
-                g_value_set_string (value, user->x_session);
baf615
-                break;
baf615
-        case PROP_LOCKED:
baf615
-                g_value_set_boolean (value, user->locked);
baf615
-                break;
baf615
-        case PROP_AUTOMATIC_LOGIN:
baf615
-                g_value_set_boolean (value, user->automatic_login);
baf615
-                break;
baf615
-        case PROP_SYSTEM_ACCOUNT:
baf615
-                g_value_set_boolean (value, user->system_account);
baf615
-                break;
baf615
-        case PROP_LOCAL_ACCOUNT:
baf615
-                g_value_set_boolean (value, user->local_account);
baf615
-                break;
baf615
         case PROP_NONEXISTENT:
baf615
                 g_value_set_boolean (value, user->nonexistent);
baf615
                 break;
baf615
         case PROP_IS_LOADED:
baf615
                 g_value_set_boolean (value, user->is_loaded);
baf615
                 break;
baf615
         default:
baf615
-                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
baf615
+                if (user->accounts_proxy != NULL) {
baf615
+                        const char *property_name;
baf615
+
baf615
+                        property_name = g_param_spec_get_name (pspec);
baf615
+
baf615
+                        g_object_get_property (G_OBJECT (user->accounts_proxy), property_name, value);
baf615
+
baf615
+                }
baf615
                 break;
baf615
         }
baf615
 }
baf615
 
baf615
 
baf615
 static void
baf615
 act_user_class_init (ActUserClass *class)
baf615
 {
baf615
         GObjectClass *gobject_class;
baf615
 
baf615
         gobject_class = G_OBJECT_CLASS (class);
baf615
 
baf615
         gobject_class->finalize = act_user_finalize;
baf615
         gobject_class->get_property = act_user_get_property;
baf615
 
baf615
         g_object_class_install_property (gobject_class,
baf615
                                          PROP_REAL_NAME,
baf615
                                          g_param_spec_string ("real-name",
baf615
                                                               "Real Name",
baf615
                                                               "The real name to display for this user.",
baf615
                                                               NULL,
baf615
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
baf615
 
baf615
         g_object_class_install_property (gobject_class,
baf615
                                          PROP_ACCOUNT_TYPE,
baf615
                                          g_param_spec_int ("account-type",
baf615
                                                            "Account Type",
baf615
                                                            "The account type for this user.",
baf615
                                                            ACT_USER_ACCOUNT_TYPE_STANDARD,
baf615
                                                            ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR,
baf615
@@ -525,1082 +444,773 @@ act_user_class_init (ActUserClass *class)
baf615
          * Emitted when the user accounts changes in some way.
baf615
          */
baf615
         signals [CHANGED] =
baf615
                 g_signal_new ("changed",
baf615
                               G_TYPE_FROM_CLASS (class),
baf615
                               G_SIGNAL_RUN_LAST,
baf615
                               0,
baf615
                               NULL, NULL,
baf615
                               g_cclosure_marshal_VOID__VOID,
baf615
                               G_TYPE_NONE, 0);
baf615
         /**
baf615
          * ActUser::sessions-changed:
baf615
          *
baf615
          * Emitted when the list of sessions for this user changes.
baf615
          */
baf615
         signals [SESSIONS_CHANGED] =
baf615
                 g_signal_new ("sessions-changed",
baf615
                               G_TYPE_FROM_CLASS (class),
baf615
                               G_SIGNAL_RUN_LAST,
baf615
                               0,
baf615
                               NULL, NULL,
baf615
                               g_cclosure_marshal_VOID__VOID,
baf615
                               G_TYPE_NONE, 0);
baf615
 }
baf615
 
baf615
 static void
baf615
 act_user_init (ActUser *user)
baf615
 {
baf615
         GError *error = NULL;
baf615
 
baf615
-        user->local_account = TRUE;
baf615
-        user->user_name = NULL;
baf615
-        user->real_name = NULL;
baf615
         user->our_sessions = NULL;
baf615
         user->other_sessions = NULL;
baf615
-        user->login_history = NULL;
baf615
 
baf615
         user->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
baf615
         if (user->connection == NULL) {
baf615
                 g_warning ("Couldn't connect to system bus: %s", error->message);
baf615
                 g_error_free (error);
baf615
         }
baf615
 }
baf615
 
baf615
 static void
baf615
 act_user_finalize (GObject *object)
baf615
 {
baf615
         ActUser *user;
baf615
 
baf615
         user = ACT_USER (object);
baf615
 
baf615
-        g_free (user->user_name);
baf615
-        g_free (user->real_name);
baf615
-        g_free (user->icon_file);
baf615
-        g_free (user->language);
baf615
-        g_free (user->object_path);
baf615
-        g_free (user->password_hint);
baf615
-        g_free (user->home_dir);
baf615
-        g_free (user->shell);
baf615
-        g_free (user->email);
baf615
-        g_free (user->location);
baf615
-        if (user->login_history)
baf615
-          g_variant_unref (user->login_history);
baf615
-
baf615
         if (user->accounts_proxy != NULL) {
baf615
                 g_object_unref (user->accounts_proxy);
baf615
         }
baf615
 
baf615
-        if (user->object_proxy != NULL) {
baf615
-                g_object_unref (user->object_proxy);
baf615
-        }
baf615
-
baf615
-        if (user->get_all_cancellable != NULL) {
baf615
-                g_object_unref (user->get_all_cancellable);
baf615
-        }
baf615
-
baf615
         if (user->connection != NULL) {
baf615
                 g_object_unref (user->connection);
baf615
         }
baf615
 
baf615
-        if (user->update_info_timeout_id != 0) {
baf615
-                g_source_remove (user->update_info_timeout_id);
baf615
-        }
baf615
-
baf615
         if (G_OBJECT_CLASS (act_user_parent_class)->finalize)
baf615
                 (*G_OBJECT_CLASS (act_user_parent_class)->finalize) (object);
baf615
 }
baf615
 
baf615
 static void
baf615
 set_is_loaded (ActUser  *user,
baf615
                gboolean  is_loaded)
baf615
 {
baf615
         if (user->is_loaded != is_loaded) {
baf615
                 user->is_loaded = is_loaded;
baf615
                 g_object_notify (G_OBJECT (user), "is-loaded");
baf615
         }
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_uid:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the ID of @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 
baf615
 uid_t
baf615
 act_user_get_uid (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), -1);
baf615
 
baf615
-        return user->uid;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return -1;
baf615
+
baf615
+        return accounts_user_get_uid (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_real_name:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the display name of @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_real_name (ActUser *user)
baf615
 {
baf615
+        const char *real_name = NULL;
baf615
+
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        if (user->real_name == NULL ||
baf615
-            user->real_name[0] == '\0') {
baf615
-                return user->user_name;
baf615
+        real_name = accounts_user_get_real_name (user->accounts_proxy);
baf615
+
baf615
+        if (real_name == NULL || real_name[0] == '\0') {
baf615
+                real_name = accounts_user_get_user_name (user->accounts_proxy);
baf615
         }
baf615
 
baf615
-        return user->real_name;
baf615
+        return real_name;
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_account_type:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the account type of @user.
baf615
  *
baf615
  * Returns: a #ActUserAccountType
baf615
  **/
baf615
 ActUserAccountType
baf615
 act_user_get_account_type (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_ACCOUNT_TYPE_STANDARD);
baf615
 
baf615
-        return user->account_type;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return ACT_USER_ACCOUNT_TYPE_STANDARD;
baf615
+
baf615
+        return accounts_user_get_account_type (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_password_mode:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the password mode of @user.
baf615
  *
baf615
  * Returns: a #ActUserPasswordMode
baf615
  **/
baf615
 ActUserPasswordMode
baf615
 act_user_get_password_mode (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_PASSWORD_MODE_REGULAR);
baf615
 
baf615
-        return user->password_mode;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return ACT_USER_PASSWORD_MODE_REGULAR;
baf615
+
baf615
+        return accounts_user_get_password_mode (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_password_hint:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the password hint set by @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_password_hint (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->password_hint;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_password_hint (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_home_dir:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the home directory for @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_home_dir (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->home_dir;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_home_directory (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_shell:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the shell assigned to @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_shell (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->shell;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_shell (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_email:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the email address set by @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_email (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->email;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_email (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_location:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the location set by @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 const char *
baf615
 act_user_get_location (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->location;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_location (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_user_name:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves the login name of @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
baf615
  *  freed, or %NULL.
baf615
  **/
baf615
 
baf615
 const char *
baf615
 act_user_get_user_name (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->user_name;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_user_name (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_login_frequency:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the number of times @user has logged in.
baf615
  *
baf615
  * Returns: the login frequency
baf615
  */
baf615
 int
baf615
 act_user_get_login_frequency (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), 0);
baf615
 
baf615
-        return user->login_frequency;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return 0;
baf615
+
baf615
+        return accounts_user_get_login_frequency (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_login_time:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the last login time for @user.
baf615
  *
baf615
  * Returns: (transfer none): the login time
baf615
  */
baf615
 gint64
baf615
-act_user_get_login_time (ActUser *user) {
baf615
+act_user_get_login_time (ActUser *user)
baf615
+{
baf615
         g_return_val_if_fail (ACT_IS_USER (user), 0);
baf615
 
baf615
-        return user->login_time;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return 0;
baf615
+
baf615
+        return accounts_user_get_login_time (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_login_history:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the login history for @user.
baf615
  *
baf615
  * Returns: (transfer none): a pointer to GVariant of type "a(xxa{sv})"
baf615
  * which must not be modified or freed, or %NULL.
baf615
  */
baf615
 const GVariant *
baf615
-act_user_get_login_history (ActUser *user) {
baf615
+act_user_get_login_history (ActUser *user)
baf615
+{
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->login_history;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_login_history (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_collate:
baf615
  * @user1: a user
baf615
  * @user2: a user
baf615
  *
baf615
  * Organize the user by login frequency and names.
baf615
  *
baf615
  * Returns: negative if @user1 is before @user2, zero if equal
baf615
  *    or positive if @user1 is after @user2
baf615
  */
baf615
 int
baf615
 act_user_collate (ActUser *user1,
baf615
                   ActUser *user2)
baf615
 {
baf615
         const char *str1;
baf615
         const char *str2;
baf615
         int         num1;
baf615
         int         num2;
baf615
         guint       len1;
baf615
         guint       len2;
baf615
 
baf615
         g_return_val_if_fail (ACT_IS_USER (user1), 0);
baf615
         g_return_val_if_fail (ACT_IS_USER (user2), 0);
baf615
 
baf615
-        num1 = user1->login_frequency;
baf615
-        num2 = user2->login_frequency;
baf615
+        num1 = act_user_get_login_frequency (user1);
baf615
+        num2 = act_user_get_login_frequency (user2);
baf615
 
baf615
         if (num1 > num2) {
baf615
                 return -1;
baf615
         }
baf615
 
baf615
         if (num1 < num2) {
baf615
                 return 1;
baf615
         }
baf615
 
baf615
 
baf615
         len1 = g_list_length (user1->our_sessions);
baf615
         len2 = g_list_length (user2->our_sessions);
baf615
 
baf615
         if (len1 > len2) {
baf615
                 return -1;
baf615
         }
baf615
 
baf615
         if (len1 < len2) {
baf615
                 return 1;
baf615
         }
baf615
 
baf615
         /* if login frequency is equal try names */
baf615
-        if (user1->real_name != NULL) {
baf615
-                str1 = user1->real_name;
baf615
-        } else {
baf615
-                str1 = user1->user_name;
baf615
-        }
baf615
-
baf615
-        if (user2->real_name != NULL) {
baf615
-                str2 = user2->real_name;
baf615
-        } else {
baf615
-                str2 = user2->user_name;
baf615
-        }
baf615
+        str1 = act_user_get_real_name (user1);
baf615
+        str2 = act_user_get_real_name (user2);
baf615
 
baf615
         if (str1 == NULL && str2 != NULL) {
baf615
                 return -1;
baf615
         }
baf615
 
baf615
         if (str1 != NULL && str2 == NULL) {
baf615
                 return 1;
baf615
         }
baf615
 
baf615
         if (str1 == NULL && str2 == NULL) {
baf615
                 return 0;
baf615
         }
baf615
 
baf615
         return g_utf8_collate (str1, str2);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_logged_in:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns whether or not #ActUser is currently graphically logged in
baf615
  * on the same seat as the seat of the session of the calling process.
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_is_logged_in (ActUser *user)
baf615
 {
baf615
         return user->our_sessions != NULL;
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_logged_in_anywhere:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns whether or not #ActUser is currently logged in in any way
baf615
  * whatsoever.  See also act_user_is_logged_in().
baf615
  *
baf615
  * (Currently, this function is only implemented for systemd-logind.
baf615
  * For ConsoleKit, it is equivalent to act_user_is_logged_in.)
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_is_logged_in_anywhere (ActUser *user)
baf615
 {
baf615
         return user->our_sessions != NULL || user->other_sessions != NULL;
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_locked:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns whether or not the #ActUser account is locked.
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_get_locked (ActUser *user)
baf615
 {
baf615
-        return user->locked;;
baf615
+        return accounts_user_get_locked (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_automatic_login:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns whether or not #ActUser is automatically logged in at boot time.
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_get_automatic_login (ActUser *user)
baf615
 {
baf615
-        return user->automatic_login;
baf615
+        g_return_val_if_fail (ACT_IS_USER (user), FALSE);
baf615
+
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return FALSE;
baf615
+
baf615
+       return accounts_user_get_automatic_login (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_system_account:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns whether or not #ActUser represents a 'system account' like
baf615
  * 'root' or 'nobody'.
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_is_system_account (ActUser *user)
baf615
 {
baf615
-        return user->system_account;
baf615
+        g_return_val_if_fail (ACT_IS_USER (user), TRUE);
baf615
+
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return TRUE;
baf615
+
baf615
+        return accounts_user_get_system_account (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_local_account:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves whether the user is a local account or not.
baf615
  *
baf615
  * Returns: (transfer none): %TRUE if the user is local
baf615
  **/
baf615
 gboolean
baf615
 act_user_is_local_account (ActUser   *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), FALSE);
baf615
 
baf615
-        return user->local_account;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return FALSE;
baf615
+
baf615
+        return accounts_user_get_local_account (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_nonexistent:
baf615
  * @user: the user object to examine.
baf615
  *
baf615
  * Retrieves whether the user is nonexistent or not.
baf615
  *
baf615
  * Returns: (transfer none): %TRUE if the user is nonexistent
baf615
  **/
baf615
 gboolean
baf615
 act_user_is_nonexistent (ActUser   *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), FALSE);
baf615
 
baf615
         return user->nonexistent;
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_icon_file:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the path to the account icon belonging to @user.
baf615
  *
baf615
  * Returns: (transfer none): a path to an icon
baf615
  */
baf615
 const char *
baf615
 act_user_get_icon_file (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->icon_file;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_icon_file (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_language:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the path to the configured locale of @user.
baf615
  *
baf615
  * Returns: (transfer none): a path to an icon
baf615
  */
baf615
 const char *
baf615
 act_user_get_language (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->language;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_language (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_x_session:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the path to the configured X session for @user.
baf615
  *
baf615
  * Returns: (transfer none): a path to an icon
baf615
  */
baf615
 const char *
baf615
 act_user_get_x_session (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->x_session;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return accounts_user_get_xsession (user->accounts_proxy);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_object_path:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the user accounts service object path of @user,
baf615
  * or %NULL if @user doesn't have an object path associated
baf615
  * with it.
baf615
  *
baf615
  * Returns: (transfer none): the object path of the user
baf615
  */
baf615
 const char *
baf615
 act_user_get_object_path (ActUser *user)
baf615
 {
baf615
         g_return_val_if_fail (ACT_IS_USER (user), NULL);
baf615
 
baf615
-        return user->object_path;
baf615
+        if (user->accounts_proxy == NULL)
baf615
+                return NULL;
baf615
+
baf615
+        return g_dbus_proxy_get_object_path (G_DBUS_PROXY (user->accounts_proxy));
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_primary_session_id:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Returns the id of the primary session of @user, or %NULL if @user
baf615
  * has no primary session.  The primary session will always be
baf615
  * graphical and will be chosen from the sessions on the same seat as
baf615
  * the seat of the session of the calling process.
baf615
  *
baf615
  * Returns: (transfer none): the id of the primary session of the user
baf615
  */
baf615
 const char *
baf615
 act_user_get_primary_session_id (ActUser *user)
baf615
 {
baf615
         if (user->our_sessions == NULL) {
baf615
                 g_debug ("User %s is not logged in here, so has no primary session",
baf615
                          act_user_get_user_name (user));
baf615
                 return NULL;
baf615
         }
baf615
 
baf615
         /* FIXME: better way to choose? */
baf615
         return user->our_sessions->data;
baf615
 }
baf615
 
baf615
-static void
baf615
-collect_props (const gchar *key,
baf615
-               GVariant    *value,
baf615
-               ActUser     *user)
baf615
-{
baf615
-        gboolean handled = TRUE;
baf615
-
baf615
-        if (strcmp (key, "Uid") == 0) {
baf615
-                guint64 new_uid;
baf615
-
baf615
-                new_uid = g_variant_get_uint64 (value);
baf615
-                if (!user->uid_set || (guint64) user->uid != new_uid) {
baf615
-                        user->uid = (uid_t) new_uid;
baf615
-                        user->uid_set = TRUE;
baf615
-                        g_object_notify (G_OBJECT (user), "uid");
baf615
-                }
baf615
-        } else if (strcmp (key, "UserName") == 0) {
baf615
-                const char *new_user_name;
baf615
-
baf615
-                new_user_name = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->user_name, new_user_name) != 0) {
baf615
-                        g_free (user->user_name);
baf615
-                        user->user_name = g_strdup (new_user_name);
baf615
-                        g_object_notify (G_OBJECT (user), "user-name");
baf615
-                }
baf615
-        } else if (strcmp (key, "RealName") == 0) {
baf615
-                const char *new_real_name;
baf615
-
baf615
-                new_real_name = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->real_name, new_real_name) != 0) {
baf615
-                        g_free (user->real_name);
baf615
-                        user->real_name = g_strdup (new_real_name);
baf615
-                        g_object_notify (G_OBJECT (user), "real-name");
baf615
-                }
baf615
-        } else if (strcmp (key, "AccountType") == 0) {
baf615
-                int new_account_type;
baf615
-
baf615
-                new_account_type = g_variant_get_int32 (value);
baf615
-                if ((int) user->account_type != new_account_type) {
baf615
-                        user->account_type = (ActUserAccountType) new_account_type;
baf615
-                        g_object_notify (G_OBJECT (user), "account-type");
baf615
-                }
baf615
-        } else if (strcmp (key, "PasswordMode") == 0) {
baf615
-                int new_password_mode;
baf615
-
baf615
-                new_password_mode = g_variant_get_int32 (value);
baf615
-                if ((int) user->password_mode != new_password_mode) {
baf615
-                        user->password_mode = (ActUserPasswordMode) new_password_mode;
baf615
-                        g_object_notify (G_OBJECT (user), "password-mode");
baf615
-                }
baf615
-        } else if (strcmp (key, "PasswordHint") == 0) {
baf615
-                const char *new_password_hint;
baf615
-
baf615
-                new_password_hint = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->password_hint, new_password_hint) != 0) {
baf615
-                        g_free (user->password_hint);
baf615
-                        user->password_hint = g_strdup (new_password_hint);
baf615
-                        g_object_notify (G_OBJECT (user), "password-hint");
baf615
-                }
baf615
-        } else if (strcmp (key, "HomeDirectory") == 0) {
baf615
-                const char *new_home_dir;
baf615
-
baf615
-                new_home_dir = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->home_dir, new_home_dir) != 0) {
baf615
-                        g_free (user->home_dir);
baf615
-                        user->home_dir = g_strdup (new_home_dir);
baf615
-                        g_object_notify (G_OBJECT (user), "home-directory");
baf615
-                }
baf615
-        } else if (strcmp (key, "Shell") == 0) {
baf615
-                const char *new_shell;
baf615
-
baf615
-                new_shell = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->shell, new_shell) != 0) {
baf615
-                        g_free (user->shell);
baf615
-                        user->shell = g_strdup (new_shell);
baf615
-                        g_object_notify (G_OBJECT (user), "shell");
baf615
-                }
baf615
-        } else if (strcmp (key, "Email") == 0) {
baf615
-                const char *new_email;
baf615
-
baf615
-                new_email = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->email, new_email) != 0) {
baf615
-                        g_free (user->email);
baf615
-                        user->email = g_strdup (new_email);
baf615
-                        g_object_notify (G_OBJECT (user), "email");
baf615
-                }
baf615
-        } else if (strcmp (key, "Location") == 0) {
baf615
-                const char *new_location;
baf615
-
baf615
-                new_location = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->location, new_location) != 0) {
baf615
-                        g_free (user->location);
baf615
-                        user->location = g_strdup (new_location);
baf615
-                        g_object_notify (G_OBJECT (user), "location");
baf615
-                }
baf615
-        } else if (strcmp (key, "Locked") == 0) {
baf615
-                gboolean new_locked_state;
baf615
-
baf615
-                new_locked_state = g_variant_get_boolean (value);
baf615
-                if (new_locked_state != user->locked) {
baf615
-                        user->locked = new_locked_state;
baf615
-                        g_object_notify (G_OBJECT (user), "locked");
baf615
-                }
baf615
-        } else if (strcmp (key, "AutomaticLogin") == 0) {
baf615
-                gboolean new_automatic_login_state;
baf615
-
baf615
-                new_automatic_login_state = g_variant_get_boolean (value);
baf615
-                if (new_automatic_login_state != user->automatic_login) {
baf615
-                        user->automatic_login = new_automatic_login_state;
baf615
-                        g_object_notify (G_OBJECT (user), "automatic-login");
baf615
-                }
baf615
-        } else if (strcmp (key, "SystemAccount") == 0) {
baf615
-                gboolean new_system_account_state;
baf615
-
baf615
-                new_system_account_state = g_variant_get_boolean (value);
baf615
-                if (new_system_account_state != user->system_account) {
baf615
-                        user->system_account = new_system_account_state;
baf615
-                        g_object_notify (G_OBJECT (user), "system-account");
baf615
-                }
baf615
-        } else if (strcmp (key, "LocalAccount") == 0) {
baf615
-                gboolean new_local;
baf615
-
baf615
-                new_local = g_variant_get_boolean (value);
baf615
-                if (user->local_account != new_local) {
baf615
-                        user->local_account = new_local;
baf615
-                        g_object_notify (G_OBJECT (user), "local-account");
baf615
-                }
baf615
-        } else if (strcmp (key, "LoginFrequency") == 0) {
baf615
-                int new_login_frequency;
baf615
-
baf615
-                new_login_frequency = (int) g_variant_get_uint64 (value);
baf615
-                if ((int) user->login_frequency != (int) new_login_frequency) {
baf615
-                        user->login_frequency = new_login_frequency;
baf615
-                        g_object_notify (G_OBJECT (user), "login-frequency");
baf615
-                }
baf615
-        } else if (strcmp (key, "LoginTime") == 0) {
baf615
-                gint64 new_login_time = g_variant_get_int64 (value);
baf615
-
baf615
-                if (user->login_time != new_login_time) {
baf615
-                        user->login_time = new_login_time;
baf615
-                        g_object_notify (G_OBJECT (user), "login-time");
baf615
-                }
baf615
-        } else if (strcmp (key, "LoginHistory") == 0) {
baf615
-                GVariant *new_login_history = value;
baf615
-
baf615
-                if (user->login_history == NULL ||
baf615
-                    !g_variant_equal (user->login_history, new_login_history)) {
baf615
-                        if (user->login_history)
baf615
-                          g_variant_unref (user->login_history);
baf615
-                        user->login_history = g_variant_ref (new_login_history);
baf615
-                        g_object_notify (G_OBJECT (user), "login-history");
baf615
-                }
baf615
-        } else if (strcmp (key, "IconFile") == 0) {
baf615
-                const char *new_icon_file;
baf615
-
baf615
-                new_icon_file = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->icon_file, new_icon_file) != 0) {
baf615
-                        g_free (user->icon_file);
baf615
-                        user->icon_file = g_strdup (new_icon_file);
baf615
-                        g_object_notify (G_OBJECT (user), "icon-file");
baf615
-                }
baf615
-        } else if (strcmp (key, "Language") == 0) {
baf615
-                const char *new_language;
baf615
-
baf615
-                new_language = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->language, new_language) != 0) {
baf615
-                        g_free (user->language);
baf615
-                        user->language = g_strdup (new_language);
baf615
-                        g_object_notify (G_OBJECT (user), "language");
baf615
-                }
baf615
-        } else if (strcmp (key, "XSession") == 0) {
baf615
-                const char *new_x_session;
baf615
-
baf615
-                new_x_session = g_variant_get_string (value, NULL);
baf615
-                if (g_strcmp0 (user->x_session, new_x_session) != 0) {
baf615
-                        g_free (user->x_session);
baf615
-                        user->x_session = g_strdup (new_x_session);
baf615
-                        g_object_notify (G_OBJECT (user), "x-session");
baf615
-                }
baf615
-        } else {
baf615
-                handled = FALSE;
baf615
-        }
baf615
-
baf615
-        if (!handled) {
baf615
-                g_debug ("unhandled property %s", key);
baf615
-        }
baf615
-}
baf615
-
baf615
-static void
baf615
-on_get_all_finished (GObject        *object,
baf615
-                     GAsyncResult   *result,
baf615
-                     gpointer data)
baf615
-{
baf615
-        GDBusProxy  *proxy = G_DBUS_PROXY (object);
baf615
-        ActUser     *user = data;
baf615
-        GError      *error;
baf615
-        GVariant    *res;
baf615
-        GVariantIter *iter;
baf615
-        gchar       *key;
baf615
-        GVariant    *value;
baf615
-
baf615
-        g_assert (G_IS_DBUS_PROXY (user->object_proxy));
baf615
-        g_assert (user->object_proxy == proxy);
baf615
-
baf615
-        error = NULL;
baf615
-        res = g_dbus_proxy_call_finish (proxy, result, &error);
baf615
-
baf615
-        g_clear_object (&user->get_all_cancellable);
baf615
-
baf615
-        if (! res) {
baf615
-                g_debug ("Error calling GetAll() when retrieving properties for %s: %s",
baf615
-                         user->object_path, error->message);
baf615
-                g_error_free (error);
baf615
-
baf615
-                if (!user->is_loaded) {
baf615
-                        set_is_loaded (user, TRUE);
baf615
-                }
baf615
-                return;
baf615
-        }
baf615
-
baf615
-        g_variant_get (res, "(a{sv})", &iter);
baf615
-        while (g_variant_iter_next (iter, "{sv}", &key, &value)) {
baf615
-                collect_props (key, value, user);
baf615
-                g_free (key);
baf615
-                g_variant_unref (value);
baf615
-        }
baf615
-        g_variant_iter_free (iter);
baf615
-        g_variant_unref (res);
baf615
-
baf615
-        if (!user->is_loaded) {
baf615
-                set_is_loaded (user, TRUE);
baf615
-        }
baf615
-
baf615
-        g_signal_emit (user, signals[CHANGED], 0);
baf615
-}
baf615
-
baf615
-static void
baf615
-update_info (ActUser *user)
baf615
-{
baf615
-        g_assert (G_IS_DBUS_PROXY (user->object_proxy));
baf615
-
baf615
-        if (user->get_all_cancellable != NULL) {
baf615
-                g_cancellable_cancel (user->get_all_cancellable);
baf615
-                g_clear_object (&user->get_all_cancellable);
baf615
-        }
baf615
-
baf615
-        user->get_all_cancellable = g_cancellable_new ();
baf615
-        g_dbus_proxy_call (user->object_proxy,
baf615
-                           "GetAll",
baf615
-                           g_variant_new ("(s)", ACCOUNTS_USER_INTERFACE),
baf615
-                           G_DBUS_CALL_FLAGS_NONE,
baf615
-                           -1,
baf615
-                           user->get_all_cancellable,
baf615
-                           on_get_all_finished,
baf615
-                           user);
baf615
-}
baf615
-
baf615
-static gboolean
baf615
-on_timeout_update_info (ActUser *user)
baf615
-{
baf615
-        update_info (user);
baf615
-        user->update_info_timeout_id = 0;
baf615
-
baf615
-        return G_SOURCE_REMOVE;
baf615
-}
baf615
-
baf615
-static void
baf615
-changed_handler (AccountsUser *object,
baf615
-                 gpointer   *data)
baf615
-{
baf615
-        ActUser *user = ACT_USER (data);
baf615
-
baf615
-        if (user->update_info_timeout_id != 0)
baf615
-                return;
baf615
-
baf615
-        user->update_info_timeout_id = g_timeout_add (250, (GSourceFunc) on_timeout_update_info, user);
baf615
-}
baf615
-
baf615
 /**
baf615
  * _act_user_update_as_nonexistent:
baf615
  * @user: the user object to update.
baf615
  *
baf615
  * Set's the 'non-existent' property of @user to #TRUE
baf615
  * Can only be called before the user is loaded.
baf615
  **/
baf615
 void
baf615
 _act_user_update_as_nonexistent (ActUser *user)
baf615
 {
baf615
         g_return_if_fail (ACT_IS_USER (user));
baf615
         g_return_if_fail (!act_user_is_loaded (user));
baf615
-        g_return_if_fail (user->object_path == NULL);
baf615
+        g_return_if_fail (act_user_get_object_path (user) == NULL);
baf615
 
baf615
         user->nonexistent = TRUE;
baf615
         g_object_notify (G_OBJECT (user), "nonexistent");
baf615
 
baf615
         set_is_loaded (user, TRUE);
baf615
 }
baf615
 
baf615
+static void
baf615
+on_accounts_proxy_changed (ActUser *user)
baf615
+{
baf615
+        g_signal_emit (user, signals[CHANGED], 0);
baf615
+}
baf615
+
baf615
 /**
baf615
  * _act_user_update_from_object_path:
baf615
  * @user: the user object to update.
baf615
  * @object_path: the object path of the user to use.
baf615
  *
baf615
  * Updates the properties of @user from the accounts service via
baf615
  * the object path in @object_path.
baf615
  **/
baf615
 void
baf615
 _act_user_update_from_object_path (ActUser    *user,
baf615
                                    const char *object_path)
baf615
 {
baf615
-        GError *error = NULL;
baf615
+        AccountsUser    *accounts_proxy;
baf615
+        GError          *error = NULL;
baf615
 
baf615
         g_return_if_fail (ACT_IS_USER (user));
baf615
         g_return_if_fail (object_path != NULL);
baf615
-        g_return_if_fail (user->object_path == NULL);
baf615
-
baf615
-        user->object_path = g_strdup (object_path);
baf615
-
baf615
-        user->accounts_proxy = accounts_user_proxy_new_sync (user->connection,
baf615
-                                                             G_DBUS_PROXY_FLAGS_NONE,
baf615
-                                                             ACCOUNTS_NAME,
baf615
-                                                             user->object_path,
baf615
-                                                             NULL,
baf615
-                                                             &error);
baf615
-        if (!user->accounts_proxy) {
baf615
+        g_return_if_fail (act_user_get_object_path (user) == NULL);
baf615
+
baf615
+        accounts_proxy = accounts_user_proxy_new_sync (user->connection,
baf615
+                                                       G_DBUS_PROXY_FLAGS_NONE,
baf615
+                                                       ACCOUNTS_NAME,
baf615
+                                                       object_path,
baf615
+                                                       NULL,
baf615
+                                                       &error);
baf615
+        if (!accounts_proxy) {
baf615
                 g_warning ("Couldn't create accounts proxy: %s", error->message);
baf615
                 g_error_free (error);
baf615
                 return;
baf615
         }
baf615
-        g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (user->accounts_proxy), INT_MAX);
baf615
 
baf615
-        g_signal_connect (user->accounts_proxy, "changed", G_CALLBACK (changed_handler), user);
baf615
+        user->accounts_proxy = accounts_proxy;
baf615
 
baf615
-        user->object_proxy = g_dbus_proxy_new_sync (user->connection,
baf615
-                                                    G_DBUS_PROXY_FLAGS_NONE,
baf615
-                                                    0,
baf615
-                                                    ACCOUNTS_NAME,
baf615
-                                                    user->object_path,
baf615
-                                                    "org.freedesktop.DBus.Properties",
baf615
-                                                    NULL,
baf615
-                                                    &error);
baf615
-        if (!user->object_proxy) {
baf615
-                g_warning ("Couldn't create accounts property proxy: %s", error->message);
baf615
-                g_error_free (error);
baf615
-                return;
baf615
-        }
baf615
+        g_signal_connect_object (user->accounts_proxy,
baf615
+                                 "changed",
baf615
+                                 G_CALLBACK (on_accounts_proxy_changed),
baf615
+                                 user,
baf615
+                                 G_CONNECT_SWAPPED);
baf615
 
baf615
-       update_info (user);
baf615
+        g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (user->accounts_proxy), INT_MAX);
baf615
+
baf615
+        set_is_loaded (user, TRUE);
baf615
 }
baf615
 
baf615
 void
baf615
 _act_user_update_login_frequency (ActUser    *user,
baf615
                                   int         login_frequency)
baf615
 {
baf615
-        if (user->login_frequency != login_frequency) {
baf615
-                user->login_frequency = login_frequency;
baf615
-                g_object_notify (G_OBJECT (user), "login-frequency");
baf615
+        if (act_user_get_login_frequency (user) == login_frequency) {
baf615
+                return;
baf615
         }
baf615
+
baf615
+        accounts_user_set_login_frequency (user->accounts_proxy,
baf615
+                                           login_frequency);
baf615
 }
baf615
 
baf615
 static void
baf615
 copy_sessions_lists (ActUser *user,
baf615
                      ActUser *user_to_copy)
baf615
 {
baf615
         GList *node;
baf615
 
baf615
         for (node = g_list_last (user_to_copy->our_sessions);
baf615
              node != NULL;
baf615
              node = node->prev) {
baf615
                 user->our_sessions = g_list_prepend (user->our_sessions, g_strdup (node->data));
baf615
         }
baf615
 
baf615
         for (node = g_list_last (user_to_copy->other_sessions);
baf615
              node != NULL;
baf615
              node = node->prev) {
baf615
                 user->other_sessions = g_list_prepend (user->other_sessions, g_strdup (node->data));
baf615
         }
baf615
 }
baf615
 
baf615
 void
baf615
 _act_user_load_from_user (ActUser    *user,
baf615
                           ActUser    *user_to_copy)
baf615
 {
baf615
         if (!user_to_copy->is_loaded) {
baf615
                 return;
baf615
         }
baf615
 
baf615
-        /* loading users may already have a uid, user name, or session list
baf615
-         * from creation, so only update them if necessary
baf615
-         */
baf615
-        if (!user->uid_set) {
baf615
-                user->uid = user_to_copy->uid;
baf615
-                g_object_notify (G_OBJECT (user), "uid");
baf615
-        }
baf615
+        user->accounts_proxy = g_object_ref (user_to_copy->accounts_proxy);
baf615
 
baf615
-        if (user->user_name == NULL) {
baf615
-                user->user_name = g_strdup (user_to_copy->user_name);
baf615
-                g_object_notify (G_OBJECT (user), "user-name");
baf615
-        }
baf615
+        g_signal_connect_object (user->accounts_proxy,
baf615
+                                 "changed",
baf615
+                                 G_CALLBACK (on_accounts_proxy_changed),
baf615
+                                 user,
baf615
+                                 G_CONNECT_SWAPPED);
baf615
 
baf615
         if (user->our_sessions == NULL && user->other_sessions == NULL) {
baf615
                 copy_sessions_lists (user, user_to_copy);
baf615
                 g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
baf615
         }
baf615
 
baf615
-        g_free (user->real_name);
baf615
-        user->real_name = g_strdup (user_to_copy->real_name);
baf615
-        g_object_notify (G_OBJECT (user), "real-name");
baf615
-
baf615
-        g_free (user->password_hint);
baf615
-        user->password_hint = g_strdup (user_to_copy->password_hint);
baf615
-        g_object_notify (G_OBJECT (user), "password-hint");
baf615
-
baf615
-        g_free (user->home_dir);
baf615
-        user->home_dir = g_strdup (user_to_copy->home_dir);
baf615
-        g_object_notify (G_OBJECT (user), "home-directory");
baf615
-
baf615
-        g_free (user->shell);
baf615
-        user->shell = g_strdup (user_to_copy->shell);
baf615
-        g_object_notify (G_OBJECT (user), "shell");
baf615
-
baf615
-        g_free (user->email);
baf615
-        user->email = g_strdup (user_to_copy->email);
baf615
-        g_object_notify (G_OBJECT (user), "email");
baf615
-
baf615
-        g_free (user->location);
baf615
-        user->location = g_strdup (user_to_copy->location);
baf615
-        g_object_notify (G_OBJECT (user), "location");
baf615
-
baf615
-        g_free (user->icon_file);
baf615
-        user->icon_file = g_strdup (user_to_copy->icon_file);
baf615
-        g_object_notify (G_OBJECT (user), "icon-file");
baf615
-
baf615
-        g_free (user->language);
baf615
-        user->language = g_strdup (user_to_copy->language);
baf615
-        g_object_notify (G_OBJECT (user), "language");
baf615
-
baf615
-        g_free (user->x_session);
baf615
-        user->x_session = g_strdup (user_to_copy->x_session);
baf615
-        g_object_notify (G_OBJECT (user), "x-session");
baf615
-
baf615
-        user->login_frequency = user_to_copy->login_frequency;
baf615
-        g_object_notify (G_OBJECT (user), "login-frequency");
baf615
-
baf615
-        user->login_time = user_to_copy->login_time;
baf615
-        g_object_notify (G_OBJECT (user), "login-time");
baf615
-
baf615
-        user->login_history = user_to_copy->login_history ? g_variant_ref (user_to_copy->login_history) : NULL;
baf615
-        g_object_notify (G_OBJECT (user), "login-history");
baf615
-
baf615
-        user->account_type = user_to_copy->account_type;
baf615
-        g_object_notify (G_OBJECT (user), "account-type");
baf615
-
baf615
-        user->password_mode = user_to_copy->password_mode;
baf615
-        g_object_notify (G_OBJECT (user), "password-mode");
baf615
-
baf615
-        user->nonexistent = user_to_copy->nonexistent;
baf615
-        g_object_notify (G_OBJECT (user), "nonexistent");
baf615
-
baf615
         set_is_loaded (user, TRUE);
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_is_loaded:
baf615
  * @user: a #ActUser
baf615
  *
baf615
  * Determines whether or not the user object is loaded and ready to read from.
baf615
  * #ActUserManager:is-loaded property must be %TRUE before calling
baf615
  * act_user_manager_list_users()
baf615
  *
baf615
  * Returns: %TRUE or %FALSE
baf615
  */
baf615
 gboolean
baf615
 act_user_is_loaded (ActUser *user)
baf615
 {
baf615
         return user->is_loaded;
baf615
 }
baf615
 
baf615
 /**
baf615
  * act_user_get_login_history:
baf615
  * @user: the user object to query.
baf615
  * @expiration_time: time users passwor expires
baf615
  * @last_change_time,
baf615
  * @min_days_between_changes,
baf615
  * @max_days_between_changes,
baf615
  * @days_to_warn,
baf615
  * @days_after_expiration_until_lock)
baf615
  *
baf615
  * Assigns a new email to @user.
baf615
-- 
baf615
2.14.1
baf615