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

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