summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/user-list.c239
-rw-r--r--tests/src/test-runner.c47
2 files changed, 94 insertions, 192 deletions
diff --git a/common/user-list.c b/common/user-list.c
index 636ac778..f501c368 100644
--- a/common/user-list.c
+++ b/common/user-list.c
@@ -117,9 +117,6 @@ typedef struct
/* Shell for user */
gchar *shell;
- /* TRUE if a system account */
- gboolean system_account;
-
/* Image for user */
gchar *image;
@@ -454,110 +451,7 @@ passwd_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileM
}
}
-static gboolean
-update_user_property (CommonUser *user, const gchar *name, GVariant *value)
-{
- CommonUserPrivate *priv = GET_USER_PRIVATE (user);
-
- if (strcmp (name, "UserName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->name);
- priv->name = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "RealName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->real_name);
- priv->real_name = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "HomeDirectory") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->home_directory);
- priv->home_directory = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "Shell") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->shell);
- priv->shell = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "SystemAccount") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
- {
- priv->system_account = g_variant_get_boolean (value);
- return TRUE;
- }
-
- if (strcmp (name, "Language") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- if (priv->language)
- g_free (priv->language);
- priv->language = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "IconFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->image);
- priv->image = g_variant_dup_string (value, NULL);
- if (strcmp (priv->image, "") == 0)
- {
- g_free (priv->image);
- priv->image = NULL;
- }
- return TRUE;
- }
-
- if (strcmp (name, "XSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->session);
- priv->session = g_variant_dup_string (value, NULL);
- return TRUE;
- }
-
- if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- {
- g_free (priv->background);
- priv->background = g_variant_dup_string (value, NULL);
- if (strcmp (priv->background, "") == 0)
- {
- g_free (priv->background);
- priv->background = NULL;
- }
- return TRUE;
- }
-
- if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
- {
- g_strfreev (priv->layouts);
- priv->layouts = g_variant_dup_strv (value, NULL);
- if (!priv->layouts)
- {
- priv->layouts = g_malloc (sizeof (gchar *) * 1);
- priv->layouts[0] = NULL;
- }
- return TRUE;
- }
-
- if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
- {
- priv->has_messages = g_variant_get_boolean (value);
- return TRUE;
- }
-
- if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
- {
- priv->uid = g_variant_get_uint64 (value);
- return TRUE;
- }
-
- return FALSE;
-}
+static gboolean load_accounts_user (CommonUser *user);
static void
accounts_user_changed_cb (GDBusConnection *connection,
@@ -569,57 +463,11 @@ accounts_user_changed_cb (GDBusConnection *connection,
gpointer data)
{
CommonUser *user = data;
- CommonUserPrivate *priv = GET_USER_PRIVATE (user);
- gboolean changed = FALSE;
- GVariantIter *iter;
- GVariantIter *invalidated_properties;
- gchar *name;
- GVariant *value;
-
- g_variant_get (parameters, "(sa{sv}as)", NULL, &iter, &invalidated_properties);
- while (g_variant_iter_loop (iter, "{&sv}", &name, &value))
- {
- if (update_user_property (user, name, value))
- changed = TRUE;
- }
- g_variant_iter_free (iter);
- while (g_variant_iter_loop (invalidated_properties, "&s", &name))
- {
- GVariant *result;
- GError *error = NULL;
-
- result = g_dbus_connection_call_sync (connection,
- "org.freedesktop.Accounts",
- priv->path,
- "org.freedesktop.DBus.Properties",
- "Get",
- g_variant_new ("(ss)", "org.freedesktop.Accounts.User", name),
- G_VARIANT_TYPE ("(v)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (error)
- g_warning ("Error updating user property %s: %s", name, error->message);
- g_clear_error (&error);
-
- if (result)
- {
- GVariant *value;
+ CommonUserPrivate *priv = GET_USER_PRIVATE (user);
- g_variant_get (result, "(v)", &value);
- if (update_user_property (user, name, value))
- changed = TRUE;
- g_variant_unref (value);
- g_variant_unref (result);
- }
- }
-
- if (changed)
- {
- g_debug ("User %s changed", priv->path);
+ g_debug ("User %s changed", priv->path);
+ if (load_accounts_user (user))
g_signal_emit (user, user_signals[CHANGED], 0);
- }
}
static gboolean
@@ -629,16 +477,17 @@ load_accounts_user (CommonUser *user)
GVariant *result, *value;
GVariantIter *iter;
gchar *name;
+ gboolean system_account = FALSE;
GError *error = NULL;
/* Get the properties for this user */
if (!priv->changed_signal)
priv->changed_signal = g_dbus_connection_signal_subscribe (GET_LIST_PRIVATE (priv->user_list)->bus,
"org.freedesktop.Accounts",
- "org.freedesktop.DBus.Properties",
- "PropertiesChanged",
- priv->path,
"org.freedesktop.Accounts.User",
+ "Changed",
+ priv->path,
+ NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
accounts_user_changed_cb,
user,
@@ -663,12 +512,80 @@ load_accounts_user (CommonUser *user)
/* Store the properties we need */
g_variant_get (result, "(a{sv})", &iter);
while (g_variant_iter_loop (iter, "{&sv}", &name, &value))
- update_user_property (user, name, value);
+ {
+ if (strcmp (name, "UserName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->name);
+ priv->name = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "RealName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->real_name);
+ priv->real_name = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "HomeDirectory") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->home_directory);
+ priv->home_directory = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "Shell") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->shell);
+ priv->shell = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "SystemAccount") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
+ system_account = g_variant_get_boolean (value);
+ else if (strcmp (name, "Language") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ if (priv->language)
+ g_free (priv->language);
+ priv->language = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "IconFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->image);
+ priv->image = g_variant_dup_string (value, NULL);
+ if (strcmp (priv->image, "") == 0)
+ {
+ g_free (priv->image);
+ priv->image = NULL;
+ }
+ }
+ else if (strcmp (name, "XSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->session);
+ priv->session = g_variant_dup_string (value, NULL);
+ }
+ else if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
+ {
+ g_free (priv->background);
+ priv->background = g_variant_dup_string (value, NULL);
+ if (strcmp (priv->background, "") == 0)
+ {
+ g_free (priv->background);
+ priv->background = NULL;
+ }
+ }
+ else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
+ {
+ g_strfreev (priv->layouts);
+ priv->layouts = g_variant_dup_strv (value, NULL);
+ if (!priv->layouts)
+ {
+ priv->layouts = g_malloc (sizeof (gchar *) * 1);
+ priv->layouts[0] = NULL;
+ }
+ }
+ else if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
+ priv->has_messages = g_variant_get_boolean (value);
+ else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
+ priv->uid = g_variant_get_uint64 (value);
+ }
g_variant_iter_free (iter);
g_variant_unref (result);
- return !priv->system_account;
+ return !system_account;
}
static void
diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c
index c9ef7689..dc12d475 100644
--- a/tests/src/test-runner.c
+++ b/tests/src/test-runner.c
@@ -828,6 +828,7 @@ handle_command (const gchar *command)
GString *status_text;
gchar *username;
AccountsUser *user;
+ GError *error = NULL;
status_text = g_string_new ("RUNNER UPDATE-USER USERNAME=");
@@ -836,81 +837,67 @@ handle_command (const gchar *command)
user = get_accounts_user_by_name (username);
if (user)
{
- GVariantBuilder invalidated_properties;
- GError *error = NULL;
-
- g_variant_builder_init (&invalidated_properties, G_VARIANT_TYPE_ARRAY);
-
if (g_hash_table_lookup (params, "NAME"))
{
user->user_name = g_strdup (g_hash_table_lookup (params, "NAME"));
g_string_append_printf (status_text, " NAME=%s", user->user_name);
- g_variant_builder_add (&invalidated_properties, "s", "UserName");
}
if (g_hash_table_lookup (params, "REAL-NAME"))
{
user->real_name = g_strdup (g_hash_table_lookup (params, "REAL-NAME"));
g_string_append_printf (status_text, " REAL-NAME=%s", user->real_name);
- g_variant_builder_add (&invalidated_properties, "s", "RealName");
}
if (g_hash_table_lookup (params, "HOME-DIRECTORY"))
{
user->home_directory = g_strdup (g_hash_table_lookup (params, "HOME-DIRECTORY"));
g_string_append_printf (status_text, " HOME-DIRECTORY=%s", user->home_directory);
- g_variant_builder_add (&invalidated_properties, "s", "HomeDirectory");
}
if (g_hash_table_lookup (params, "IMAGE"))
{
user->image = g_strdup (g_hash_table_lookup (params, "IMAGE"));
g_string_append_printf (status_text, " IMAGE=%s", user->image);
- g_variant_builder_add (&invalidated_properties, "s", "IconFile");
}
if (g_hash_table_lookup (params, "BACKGROUND"))
{
user->background = g_strdup (g_hash_table_lookup (params, "BACKGROUND"));
g_string_append_printf (status_text, " BACKGROUND=%s", user->background);
- g_variant_builder_add (&invalidated_properties, "s", "BackgroundFile");
}
if (g_hash_table_lookup (params, "LANGUAGE"))
{
user->language = g_strdup (g_hash_table_lookup (params, "LANGUAGE"));
g_string_append_printf (status_text, " LANGUAGE=%s", user->language);
- g_variant_builder_add (&invalidated_properties, "s", "Language");
}
if (g_hash_table_lookup (params, "LAYOUTS"))
{
const gchar *value = g_hash_table_lookup (params, "LAYOUTS");
user->layouts = g_strsplit (value, ";", -1);
g_string_append_printf (status_text, " LAYOUTS=%s", value);
- g_variant_builder_add (&invalidated_properties, "s", "XKeyboardLayouts");
}
if (g_hash_table_lookup (params, "HAS-MESSAGES"))
{
user->has_messages = g_strcmp0 (g_hash_table_lookup (params, "HAS-MESSAGES"), "TRUE") == 0;
g_string_append_printf (status_text, " HAS-MESSAGES=%s", user->has_messages ? "TRUE" : "FALSE");
- g_variant_builder_add (&invalidated_properties, "s", "XHasMessages");
}
if (g_hash_table_lookup (params, "SESSION"))
{
user->xsession = g_strdup (g_hash_table_lookup (params, "SESSION"));
g_string_append_printf (status_text, " SESSION=%s", user->xsession);
- g_variant_builder_add (&invalidated_properties, "s", "XSession");
}
-
- g_dbus_connection_emit_signal (accounts_connection,
- NULL,
- user->path,
- "org.freedesktop.DBus.Properties",
- "PropertiesChanged",
- g_variant_new ("(sa{sv}as)", "org.freedesktop.Accounts.User", NULL, &invalidated_properties),
- &error);
- if (error)
- g_warning ("Failed to emit PropertiesChanged: %s", error->message);
- g_clear_error (&error);
}
else
g_warning ("Unknown user %s", username);
+ g_dbus_connection_emit_signal (accounts_connection,
+ NULL,
+ user->path,
+ "org.freedesktop.Accounts.User",
+ "Changed",
+ g_variant_new ("()"),
+ &error);
+ if (error)
+ g_warning ("Failed to emit Changed: %s", error->message);
+ g_clear_error (&error);
+
check_status (status_text->str);
g_string_free (status_text, TRUE);
}
@@ -2174,7 +2161,6 @@ handle_user_call (GDBusConnection *connection,
if (strcmp (method_name, "SetXSession") == 0)
{
gchar *xsession;
- GVariantBuilder invalidated_properties;
g_variant_get (parameters, "(&s)", &xsession);
@@ -2184,14 +2170,12 @@ handle_user_call (GDBusConnection *connection,
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
/* And notify others that it took */
- g_variant_builder_init (&invalidated_properties, G_VARIANT_TYPE_ARRAY);
- g_variant_builder_add (&invalidated_properties, "s", "XSession");
g_dbus_connection_emit_signal (accounts_connection,
NULL,
user->path,
- "org.freedesktop.DBus.Properties",
- "PropertiesChanged",
- g_variant_new ("(sa{sv}as)", "org.freedesktop.Accounts.User", NULL, &invalidated_properties),
+ "org.freedesktop.Accounts.User",
+ "Changed",
+ g_variant_new ("()"),
NULL);
}
else
@@ -2287,6 +2271,7 @@ accounts_name_acquired_cb (GDBusConnection *connection,
" <property name='XSession' type='s' access='read'/>"
" <property name='XKeyboardLayouts' type='as' access='read'/>"
" <property name='XHasMessages' type='b' access='read'/>"
+ " <signal name='Changed' />"
" </interface>"
"</node>";
GError *error = NULL;