Blame SOURCES/0007-lib-use-new-has-multiple-users-property-from-account.patch

34a24a
From 7849fa559cdcc197524135295bdb8e8aa13e2c13 Mon Sep 17 00:00:00 2001
34a24a
From: Ray Strode <rstrode@redhat.com>
34a24a
Date: Mon, 2 Oct 2017 16:17:43 -0400
34a24a
Subject: [PATCH 07/13] lib: use new has-multiple-users property from
34a24a
 accountsservice
34a24a
34a24a
This commit changes accountsservice to use the new has-multiple-users
34a24a
property provided by the daemon.
34a24a
---
34a24a
 src/libaccountsservice/act-user-manager.c | 27 ++++++++++-----------------
34a24a
 1 file changed, 10 insertions(+), 17 deletions(-)
34a24a
34a24a
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
34a24a
index ac06e24..30bbd78 100644
34a24a
--- a/src/libaccountsservice/act-user-manager.c
34a24a
+++ b/src/libaccountsservice/act-user-manager.c
34a24a
@@ -856,146 +856,130 @@ add_user (ActUserManager *manager,
34a24a
 {
34a24a
         const char *object_path;
34a24a
 
34a24a
         g_debug ("ActUserManager: tracking user '%s'", act_user_get_user_name (user));
34a24a
         if (act_user_is_system_account (user)) {
34a24a
                 g_hash_table_insert (manager->priv->system_users_by_name,
34a24a
                                      g_strdup (act_user_get_user_name (user)),
34a24a
                                      g_object_ref (user));
34a24a
         } else {
34a24a
                 g_hash_table_insert (manager->priv->normal_users_by_name,
34a24a
                                      g_strdup (act_user_get_user_name (user)),
34a24a
                                      g_object_ref (user));
34a24a
         }
34a24a
 
34a24a
         object_path = act_user_get_object_path (user);
34a24a
         if (object_path != NULL) {
34a24a
                 g_hash_table_replace (manager->priv->users_by_object_path,
34a24a
                                       (gpointer) object_path,
34a24a
                                       g_object_ref (user));
34a24a
         }
34a24a
 
34a24a
         g_signal_connect_object (user,
34a24a
                                  "sessions-changed",
34a24a
                                  G_CALLBACK (on_user_sessions_changed),
34a24a
                                  manager, 0);
34a24a
         g_signal_connect_object (user,
34a24a
                                  "changed",
34a24a
                                  G_CALLBACK (on_user_changed),
34a24a
                                  manager, 0);
34a24a
 
34a24a
-        if (g_hash_table_size (manager->priv->normal_users_by_name) > 1) {
34a24a
-                set_has_multiple_users (manager, TRUE);
34a24a
-        }
34a24a
-
34a24a
         if (manager->priv->is_loaded) {
34a24a
                 g_debug ("ActUserManager: loaded, so emitting user-added signal");
34a24a
                 g_signal_emit (manager, signals[USER_ADDED], 0, user);
34a24a
         } else {
34a24a
                 g_debug ("ActUserManager: not yet loaded, so not emitting user-added signal");
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 remove_user (ActUserManager *manager,
34a24a
              ActUser        *user)
34a24a
 {
34a24a
         g_debug ("ActUserManager: no longer tracking user '%s' (with object path %s)",
34a24a
                  act_user_get_user_name (user),
34a24a
                  act_user_get_object_path (user));
34a24a
 
34a24a
         g_object_ref (user);
34a24a
 
34a24a
         g_signal_handlers_disconnect_by_func (user, on_user_changed, manager);
34a24a
         g_signal_handlers_disconnect_by_func (user, on_user_sessions_changed, manager);
34a24a
         if (act_user_get_object_path (user) != NULL) {
34a24a
                 g_hash_table_remove (manager->priv->users_by_object_path, act_user_get_object_path (user));
34a24a
         }
34a24a
         if (act_user_get_user_name (user) != NULL) {
34a24a
                 g_hash_table_remove (manager->priv->normal_users_by_name, act_user_get_user_name (user));
34a24a
                 g_hash_table_remove (manager->priv->system_users_by_name, act_user_get_user_name (user));
34a24a
 
34a24a
         }
34a24a
 
34a24a
-        if (g_hash_table_size (manager->priv->normal_users_by_name) <= 1) {
34a24a
-                set_has_multiple_users (manager, FALSE);
34a24a
-        }
34a24a
-
34a24a
         if (manager->priv->is_loaded) {
34a24a
                 g_debug ("ActUserManager: loaded, so emitting user-removed signal");
34a24a
                 g_signal_emit (manager, signals[USER_REMOVED], 0, user);
34a24a
         } else {
34a24a
                 g_debug ("ActUserManager: not yet loaded, so not emitting user-removed signal");
34a24a
         }
34a24a
 
34a24a
         g_debug ("ActUserManager: user '%s' (with object path %s) now removed",
34a24a
                  act_user_get_user_name (user),
34a24a
                  act_user_get_object_path (user));
34a24a
         g_object_unref (user);
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 update_user (ActUserManager *manager,
34a24a
              ActUser        *user)
34a24a
 {
34a24a
         const char *username;
34a24a
 
34a24a
         g_debug ("ActUserManager: updating %s", describe_user (user));
34a24a
 
34a24a
         username = act_user_get_user_name (user);
34a24a
         if (g_hash_table_lookup (manager->priv->system_users_by_name, username) != NULL) {
34a24a
                 if (!act_user_is_system_account (user)) {
34a24a
                         g_debug ("ActUserManager: %s is no longer a system account, treating as normal user",
34a24a
                                  describe_user (user));
34a24a
                         g_hash_table_insert (manager->priv->normal_users_by_name,
34a24a
                                              g_strdup (act_user_get_user_name (user)),
34a24a
                                              g_object_ref (user));
34a24a
                         g_hash_table_remove (manager->priv->system_users_by_name, username);
34a24a
                         g_signal_emit (manager, signals[USER_ADDED], 0, user);
34a24a
-
34a24a
-                        if (g_hash_table_size (manager->priv->normal_users_by_name) > 1) {
34a24a
-                                set_has_multiple_users (manager, TRUE);
34a24a
-                        }
34a24a
                 }
34a24a
         } else {
34a24a
                 if (act_user_is_system_account (user)) {
34a24a
                         g_debug ("ActUserManager: %s is no longer a normal account, treating as system user",
34a24a
                                  describe_user (user));
34a24a
                         g_hash_table_insert (manager->priv->system_users_by_name,
34a24a
                                              g_strdup (act_user_get_user_name (user)),
34a24a
                                              g_object_ref (user));
34a24a
                         g_hash_table_remove (manager->priv->normal_users_by_name, username);
34a24a
                         g_signal_emit (manager, signals[USER_REMOVED], 0, user);
34a24a
-
34a24a
-                        if (g_hash_table_size (manager->priv->normal_users_by_name) <= 1) {
34a24a
-                                set_has_multiple_users (manager, FALSE);
34a24a
-                        }
34a24a
                 }
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 static ActUser *
34a24a
 lookup_user_by_name (ActUserManager *manager,
34a24a
                      const char     *username)
34a24a
 {
34a24a
         ActUser *user;
34a24a
 
34a24a
         user = g_hash_table_lookup (manager->priv->normal_users_by_name, username);
34a24a
 
34a24a
         if (user == NULL) {
34a24a
                 user = g_hash_table_lookup (manager->priv->system_users_by_name, username);
34a24a
         }
34a24a
 
34a24a
         return user;
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 on_new_user_loaded (ActUser        *user,
34a24a
                     GParamSpec     *pspec,
34a24a
                     ActUserManager *manager)
34a24a
 {
34a24a
         const char *username;
34a24a
         ActUser *old_user;
34a24a
 
34a24a
         if (!act_user_is_loaded (user)) {
34a24a
                 g_debug ("ActUserManager: %s loaded function called when not loaded",
34a24a
                          describe_user (user));
34a24a
@@ -2682,89 +2666,92 @@ set_include_usernames (ActUserManager *manager,
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 set_exclude_usernames (ActUserManager *manager,
34a24a
                        GSList         *list)
34a24a
 {
34a24a
         if (manager->priv->exclude_usernames != NULL) {
34a24a
                 g_slist_foreach (manager->priv->exclude_usernames, (GFunc) g_free, NULL);
34a24a
                 g_slist_free (manager->priv->exclude_usernames);
34a24a
         }
34a24a
         manager->priv->exclude_usernames = slist_deep_copy (list);
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 act_user_manager_set_property (GObject        *object,
34a24a
                                guint           prop_id,
34a24a
                                const GValue   *value,
34a24a
                                GParamSpec     *pspec)
34a24a
 {
34a24a
         ActUserManager *self;
34a24a
 
34a24a
         self = ACT_USER_MANAGER (object);
34a24a
 
34a24a
         switch (prop_id) {
34a24a
         case PROP_INCLUDE_USERNAMES_LIST:
34a24a
                 set_include_usernames (self, g_value_get_pointer (value));
34a24a
                 break;
34a24a
         case PROP_EXCLUDE_USERNAMES_LIST:
34a24a
                 set_exclude_usernames (self, g_value_get_pointer (value));
34a24a
                 break;
34a24a
+        case PROP_HAS_MULTIPLE_USERS:
34a24a
+                set_has_multiple_users (self, g_value_get_boolean (value));
34a24a
+                break;
34a24a
         default:
34a24a
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
34a24a
                 break;
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 act_user_manager_class_init (ActUserManagerClass *klass)
34a24a
 {
34a24a
         GObjectClass   *object_class = G_OBJECT_CLASS (klass);
34a24a
 
34a24a
         object_class->finalize = act_user_manager_finalize;
34a24a
         object_class->get_property = act_user_manager_get_property;
34a24a
         object_class->set_property = act_user_manager_set_property;
34a24a
 
34a24a
         g_object_class_install_property (object_class,
34a24a
                                          PROP_IS_LOADED,
34a24a
                                          g_param_spec_boolean ("is-loaded",
34a24a
                                                                "Is loaded",
34a24a
                                                                "Determines whether or not the manager object is loaded and ready to read from.",
34a24a
                                                                FALSE,
34a24a
                                                                G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
34a24a
         g_object_class_install_property (object_class,
34a24a
                                          PROP_HAS_MULTIPLE_USERS,
34a24a
                                          g_param_spec_boolean ("has-multiple-users",
34a24a
                                                                "Has multiple users",
34a24a
                                                                "Whether more than one normal user is present",
34a24a
                                                                FALSE,
34a24a
-                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
34a24a
+                                                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
34a24a
         g_object_class_install_property (object_class,
34a24a
                                          PROP_INCLUDE_USERNAMES_LIST,
34a24a
                                          g_param_spec_pointer ("include-usernames-list",
34a24a
                                                                "Include usernames list",
34a24a
                                                                "Usernames who are specifically included",
34a24a
                                                                G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
34a24a
 
34a24a
         g_object_class_install_property (object_class,
34a24a
                                          PROP_EXCLUDE_USERNAMES_LIST,
34a24a
                                          g_param_spec_pointer ("exclude-usernames-list",
34a24a
                                                                "Exclude usernames list",
34a24a
                                                                "Usernames who are specifically excluded",
34a24a
                                                                G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
34a24a
 
34a24a
         /**
34a24a
          * ActUserManager::user-added:
34a24a
          * @gobject: the object which received the signal
34a24a
          * @user: the #ActUser that was added
34a24a
          *
34a24a
          * Emitted when a user is added to the user manager.
34a24a
          */
34a24a
         signals [USER_ADDED] =
34a24a
                 g_signal_new ("user-added",
34a24a
                               G_TYPE_FROM_CLASS (klass),
34a24a
                               G_SIGNAL_RUN_LAST,
34a24a
                               G_STRUCT_OFFSET (ActUserManagerClass, user_added),
34a24a
                               NULL, NULL,
34a24a
                               g_cclosure_marshal_VOID__OBJECT,
34a24a
                               G_TYPE_NONE, 1, ACT_TYPE_USER);
34a24a
         /**
34a24a
@@ -2865,60 +2852,66 @@ act_user_manager_init (ActUserManager *manager)
34a24a
 
34a24a
         error = NULL;
34a24a
         manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
34a24a
         if (manager->priv->connection == NULL) {
34a24a
                 if (error != NULL) {
34a24a
                         g_warning ("Failed to connect to the D-Bus daemon: %s", error->message);
34a24a
                         g_error_free (error);
34a24a
                 } else {
34a24a
                         g_warning ("Failed to connect to the D-Bus daemon");
34a24a
                 }
34a24a
                 return;
34a24a
         }
34a24a
 
34a24a
         manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
34a24a
                                                                           G_DBUS_PROXY_FLAGS_NONE,
34a24a
                                                                           ACCOUNTS_NAME,
34a24a
                                                                           ACCOUNTS_PATH,
34a24a
                                                                           NULL,
34a24a
                                                                           &error);
34a24a
         if (manager->priv->accounts_proxy == NULL) {
34a24a
                 if (error != NULL) {
34a24a
                         g_warning ("Failed to create accounts proxy: %s", error->message);
34a24a
                         g_error_free (error);
34a24a
                 } else {
34a24a
                         g_warning ("Failed to create_accounts_proxy");
34a24a
                 }
34a24a
                 return;
34a24a
         }
34a24a
         g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
34a24a
 
34a24a
+        g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
34a24a
+                                "has-multiple-users",
34a24a
+                                G_OBJECT (manager),
34a24a
+                                "has-multiple-users",
34a24a
+                                G_BINDING_SYNC_CREATE);
34a24a
+
34a24a
         g_signal_connect (manager->priv->accounts_proxy,
34a24a
                           "user-added",
34a24a
                           G_CALLBACK (on_new_user_in_accounts_service),
34a24a
                           manager);
34a24a
         g_signal_connect (manager->priv->accounts_proxy,
34a24a
                           "user-deleted",
34a24a
                           G_CALLBACK (on_user_removed_in_accounts_service),
34a24a
                           manager);
34a24a
 
34a24a
         manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 act_user_manager_finalize (GObject *object)
34a24a
 {
34a24a
         ActUserManager *manager;
34a24a
         GSList         *node;
34a24a
 
34a24a
         g_debug ("ActUserManager: finalizing user manager");
34a24a
 
34a24a
         g_return_if_fail (object != NULL);
34a24a
         g_return_if_fail (ACT_IS_USER_MANAGER (object));
34a24a
 
34a24a
         manager = ACT_USER_MANAGER (object);
34a24a
 
34a24a
         g_return_if_fail (manager->priv != NULL);
34a24a
 
34a24a
         g_slist_foreach (manager->priv->new_sessions,
34a24a
                          (GFunc) unload_new_session, NULL);
34a24a
         g_slist_free (manager->priv->new_sessions);
34a24a
-- 
34a24a
2.14.1
34a24a