user-accounts: Port to GDBus (excluding fingerprint code)

https://bugzilla.gnome.org/show_bug.cgi?id=622875
This commit is contained in:
Robert Ancell 2012-02-08 10:50:09 +11:00 committed by Bastien Nocera
parent 01f7545df2
commit bbef732913
4 changed files with 288 additions and 299 deletions

View file

@ -202,11 +202,9 @@ user_changed_handler (UmUser *user,
} }
static void static void
user_added_handler (DBusGProxy *proxy, user_added_handler (UmUserManager *manager,
const char *object_path, const char *object_path)
gpointer user_data)
{ {
UmUserManager *manager = UM_USER_MANAGER (user_data);
UmUser *user; UmUser *user;
if (g_hash_table_lookup (manager->user_by_object_path, object_path)) if (g_hash_table_lookup (manager->user_by_object_path, object_path))
@ -233,11 +231,9 @@ user_added_handler (DBusGProxy *proxy,
} }
static void static void
user_deleted_handler (DBusGProxy *proxy, user_deleted_handler (UmUserManager *manager,
const char *object_path, const char *object_path)
gpointer user_data)
{ {
UmUserManager *manager = UM_USER_MANAGER (user_data);
UmUser *user; UmUser *user;
user = g_hash_table_lookup (manager->user_by_object_path, object_path); user = g_hash_table_lookup (manager->user_by_object_path, object_path);
@ -255,35 +251,51 @@ user_deleted_handler (DBusGProxy *proxy,
} }
static void static void
add_user (const gchar *object_path, manager_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, UmUserManager *manager)
UmUserManager *manager)
{ {
user_added_handler (NULL, object_path, manager); if (strcmp (signal_name, "UserAdded") == 0) {
if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(o)"))) {
gchar *object_path;
g_variant_get (parameters, "(&o)", &object_path);
user_added_handler (manager, object_path);
}
}
else if (strcmp (signal_name, "UserDeleted") == 0) {
if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(o)"))) {
gchar *object_path;
g_variant_get (parameters, "(&o)", &object_path);
user_deleted_handler (manager, object_path);
}
}
} }
static void static void
got_users (DBusGProxy *proxy, got_users (GObject *object,
DBusGProxyCall *call_id, GAsyncResult *res,
gpointer data) gpointer data)
{ {
UmUserManager *manager = data; UmUserManager *manager = data;
GVariant *result;
GError *error = NULL; GError *error = NULL;
GPtrArray *paths;
if (!dbus_g_proxy_end_call (proxy, result = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error);
call_id, if (!result) {
&error,
dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &paths,
G_TYPE_INVALID)) {
manager->no_service = TRUE; manager->no_service = TRUE;
g_error_free (error); g_error_free (error);
goto done; goto done;
} }
g_ptr_array_foreach (paths, (GFunc)add_user, manager); if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(ao)"))) {
GVariantIter *iter;
gchar *object_path;
g_ptr_array_foreach (paths, (GFunc)g_free, NULL); g_variant_get (result, "(ao)", &iter);
g_ptr_array_free (paths, TRUE); while (g_variant_iter_loop (iter, "&o", &object_path))
user_added_handler (manager, object_path);
g_variant_iter_free (iter);
}
g_variant_unref (result);
done: done:
g_signal_emit (G_OBJECT (manager), signals[USERS_LOADED], 0); g_signal_emit (G_OBJECT (manager), signals[USERS_LOADED], 0);
@ -293,19 +305,21 @@ static void
get_users (UmUserManager *manager) get_users (UmUserManager *manager)
{ {
g_debug ("calling 'ListCachedUsers'"); g_debug ("calling 'ListCachedUsers'");
dbus_g_proxy_begin_call (manager->proxy, g_dbus_proxy_call (manager->proxy,
"ListCachedUsers", "ListCachedUsers",
got_users, g_variant_new ("()"),
manager, G_DBUS_CALL_FLAGS_NONE,
NULL, -1,
G_TYPE_INVALID); NULL,
got_users,
manager);
} }
static void static void
um_user_manager_init (UmUserManager *manager) um_user_manager_init (UmUserManager *manager)
{ {
GError *error = NULL; GError *error = NULL;
DBusGConnection *bus; GDBusConnection *bus;
manager->user_by_object_path = g_hash_table_new_full (g_str_hash, manager->user_by_object_path = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
@ -316,29 +330,30 @@ um_user_manager_init (UmUserManager *manager)
g_free, g_free,
g_object_unref); g_object_unref);
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (bus == NULL) { if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message); g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error); g_error_free (error);
goto error; return;
} }
manager->proxy = dbus_g_proxy_new_for_name (bus, manager->proxy = g_dbus_proxy_new_sync (bus,
"org.freedesktop.Accounts", G_DBUS_PROXY_FLAGS_NONE,
"/org/freedesktop/Accounts", NULL,
"org.freedesktop.Accounts"); "org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
"org.freedesktop.Accounts",
NULL,
&error);
if (manager->proxy == NULL) {
g_warning ("Couldn't get accounts proxy: %s", error->message);
g_error_free (error);
return;
}
dbus_g_proxy_add_signal (manager->proxy, "UserAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); g_signal_connect (manager->proxy, "g-signal", G_CALLBACK (manager_signal_cb), manager);
dbus_g_proxy_add_signal (manager->proxy, "UserDeleted", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (manager->proxy, "UserAdded",
G_CALLBACK (user_added_handler), manager, NULL);
dbus_g_proxy_connect_signal (manager->proxy, "UserDeleted",
G_CALLBACK (user_deleted_handler), manager, NULL);
get_users (manager); get_users (manager);
error: ;
} }
static void static void
@ -413,37 +428,35 @@ async_user_op_data_free (gpointer d)
} }
static void static void
create_user_done (DBusGProxy *proxy, create_user_done (GObject *proxy,
DBusGProxyCall *call_id, GAsyncResult *r,
gpointer user_data) gpointer user_data)
{ {
AsyncUserOpData *data = user_data; AsyncUserOpData *data = user_data;
gchar *path;
GError *error;
GSimpleAsyncResult *res; GSimpleAsyncResult *res;
GVariant *result;
GError *error = NULL;
res = g_simple_async_result_new (G_OBJECT (data->manager), res = g_simple_async_result_new (G_OBJECT (data->manager),
data->callback, data->callback,
data->data, data->data,
um_user_manager_create_user); um_user_manager_create_user);
error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), r, &error);
if (!dbus_g_proxy_end_call (proxy, if (!result) {
call_id,
&error,
DBUS_TYPE_G_OBJECT_PATH, &path,
G_TYPE_INVALID)) {
/* dbus-glib fail: /* dbus-glib fail:
* We have to translate the errors manually here, since * We have to translate the errors manually here, since
* calling dbus_g_error_has_name on the error returned in * calling dbus_g_error_has_name on the error returned in
* um_user_manager_create_user_finish doesn't work. * um_user_manager_create_user_finish doesn't work.
*/ */
if (dbus_g_error_has_name (error, "org.freedesktop.Accounts.Error.PermissionDenied")) { if (g_dbus_error_is_remote_error (error) &&
strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.PermissionDenied") == 0) {
g_simple_async_result_set_error (res, g_simple_async_result_set_error (res,
UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR,
UM_USER_MANAGER_ERROR_PERMISSION_DENIED, UM_USER_MANAGER_ERROR_PERMISSION_DENIED,
"Not authorized"); "Not authorized");
} }
else if (dbus_g_error_has_name (error, "org.freedesktop.Accounts.Error.UserExists")) { if (g_dbus_error_is_remote_error (error) &&
strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.UserExists") == 0) {
g_simple_async_result_set_error (res, g_simple_async_result_set_error (res,
UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR,
UM_USER_MANAGER_ERROR_USER_EXISTS, UM_USER_MANAGER_ERROR_USER_EXISTS,
@ -456,10 +469,21 @@ create_user_done (DBusGProxy *proxy,
g_error_free (error); g_error_free (error);
} }
else { else {
g_simple_async_result_set_op_res_gpointer (res, path, g_free); if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)"))) {
gchar *path;
g_variant_get (result, "(o)", &path);
g_simple_async_result_set_op_res_gpointer (res, path, g_free);
}
else
g_simple_async_result_set_error (res,
UM_USER_MANAGER_ERROR,
UM_USER_MANAGER_ERROR_FAILED,
"Got invalid response from AccountsService");
g_variant_unref (result);
} }
data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data); data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
async_user_op_data_free (data);
g_object_unref (res); g_object_unref (res);
} }
@ -504,42 +528,41 @@ um_user_manager_create_user (UmUserManager *manager,
data->data = done_data; data->data = done_data;
data->destroy = destroy; data->destroy = destroy;
dbus_g_proxy_begin_call (manager->proxy, g_dbus_proxy_call (manager->proxy,
"CreateUser", "CreateUser",
create_user_done, g_variant_new ("(ssi)", user_name, real_name, account_type),
data, G_DBUS_CALL_FLAGS_NONE,
async_user_op_data_free, -1,
G_TYPE_STRING, user_name, NULL,
G_TYPE_STRING, real_name, create_user_done,
G_TYPE_INT, account_type, data);
G_TYPE_INVALID);
} }
static void static void
delete_user_done (DBusGProxy *proxy, delete_user_done (GObject *proxy,
DBusGProxyCall *call_id, GAsyncResult *r,
gpointer user_data) gpointer user_data)
{ {
AsyncUserOpData *data = user_data; AsyncUserOpData *data = user_data;
GError *error;
GSimpleAsyncResult *res; GSimpleAsyncResult *res;
GVariant *result;
GError *error = NULL;
res = g_simple_async_result_new (G_OBJECT (data->manager), res = g_simple_async_result_new (G_OBJECT (data->manager),
data->callback, data->callback,
data->data, data->data,
um_user_manager_delete_user); um_user_manager_delete_user);
error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), r, &error);
if (!dbus_g_proxy_end_call (proxy, if (!result) {
call_id, if (g_dbus_error_is_remote_error (error) &&
&error, strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.PermissionDenied") == 0) {
G_TYPE_INVALID)) {
if (dbus_g_error_has_name (error, "org.freedesktop.Accounts.Error.PermissionDenied")) {
g_simple_async_result_set_error (res, g_simple_async_result_set_error (res,
UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR,
UM_USER_MANAGER_ERROR_PERMISSION_DENIED, UM_USER_MANAGER_ERROR_PERMISSION_DENIED,
"Not authorized"); "Not authorized");
} }
else if (dbus_g_error_has_name (error, "org.freedesktop.Accounts.Error.UserDoesntExists")) { if (g_dbus_error_is_remote_error (error) &&
strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.UserExists") == 0) {
g_simple_async_result_set_error (res, g_simple_async_result_set_error (res,
UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR,
UM_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST, UM_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST,
@ -550,8 +573,11 @@ delete_user_done (DBusGProxy *proxy,
g_error_free (error); g_error_free (error);
} }
} }
else
g_variant_unref (result);
data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data); data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
async_user_op_data_free (data);
g_object_unref (res); g_object_unref (res);
} }
@ -587,14 +613,14 @@ um_user_manager_delete_user (UmUserManager *manager,
data->data = done_data; data->data = done_data;
data->destroy = destroy; data->destroy = destroy;
dbus_g_proxy_begin_call (manager->proxy, g_dbus_proxy_call (manager->proxy,
"DeleteUser", "DeleteUser",
delete_user_done, g_variant_new ("(xb)", (gint64) um_user_get_uid (user), remove_files),
data, G_DBUS_CALL_FLAGS_NONE,
async_user_op_data_free, -1,
G_TYPE_INT64, (gint64) um_user_get_uid (user), NULL,
G_TYPE_BOOLEAN, remove_files, delete_user_done,
G_TYPE_INVALID); data);
} }
GSList * GSList *

View file

@ -23,7 +23,6 @@
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <dbus/dbus-glib.h>
#include "um-user.h" #include "um-user.h"
@ -40,7 +39,7 @@ typedef struct
{ {
GObject parent; GObject parent;
DBusGProxy *proxy; GDBusProxy *proxy;
GHashTable *user_by_object_path; GHashTable *user_by_object_path;
GHashTable *user_by_name; GHashTable *user_by_name;

View file

@ -32,14 +32,11 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <polkit/polkit.h> #include <polkit/polkit.h>
#include <dbus/dbus-glib-bindings.h>
#ifdef HAVE_CHEESE #ifdef HAVE_CHEESE
#include <gst/gst.h> #include <gst/gst.h>
#endif /* HAVE_CHEESE */ #endif /* HAVE_CHEESE */
#include "marshal.h"
#include "shell/cc-editable-entry.h" #include "shell/cc-editable-entry.h"
#include "um-user.h" #include "um-user.h"
@ -1244,9 +1241,6 @@ um_user_panel_init (UmUserPanel *self)
GtkWidget *button; GtkWidget *button;
GtkStyleContext *context; GtkStyleContext *context;
dbus_g_object_register_marshaller (fprintd_marshal_VOID__STRING_BOOLEAN,
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
d = self->priv = UM_USER_PANEL_PRIVATE (self); d = self->priv = UM_USER_PANEL_PRIVATE (self);
/* register types that the builder might need */ /* register types that the builder might need */

View file

@ -37,8 +37,6 @@
#include <gio/gunixoutputstream.h> #include <gio/gunixoutputstream.h>
#include <dbus/dbus-glib.h>
#include "um-user.h" #include "um-user.h"
#include "um-account-type.h" #include "um-account-type.h"
#include "um-utils.h" #include "um-utils.h"
@ -67,69 +65,6 @@ typedef struct {
gboolean system_account; gboolean system_account;
} UserProperties; } UserProperties;
static void
collect_props (const gchar *key,
const GValue *value,
UserProperties *props)
{
gboolean handled = TRUE;
if (strcmp (key, "Uid") == 0) {
props->uid = g_value_get_uint64 (value);
}
else if (strcmp (key, "UserName") == 0) {
props->user_name = g_value_dup_string (value);
}
else if (strcmp (key, "RealName") == 0) {
props->real_name = g_value_dup_string (value);
}
else if (strcmp (key, "AccountType") == 0) {
props->account_type = g_value_get_int (value);
}
else if (strcmp (key, "Email") == 0) {
props->email = g_value_dup_string (value);
}
else if (strcmp (key, "Language") == 0) {
props->language = g_value_dup_string (value);
}
else if (strcmp (key, "Location") == 0) {
props->location = g_value_dup_string (value);
}
else if (strcmp (key, "LoginFrequency") == 0) {
props->login_frequency = g_value_get_uint64 (value);
}
else if (strcmp (key, "IconFile") == 0) {
props->icon_file = g_value_dup_string (value);
}
else if (strcmp (key, "Locked") == 0) {
props->locked = g_value_get_boolean (value);
}
else if (strcmp (key, "AutomaticLogin") == 0) {
props->automatic_login = g_value_get_boolean (value);
}
else if (strcmp (key, "SystemAccount") == 0) {
props->system_account = g_value_get_boolean (value);
}
else if (strcmp (key, "PasswordMode") == 0) {
props->password_mode = g_value_get_int (value);
}
else if (strcmp (key, "PasswordHint") == 0) {
props->password_hint = g_value_dup_string (value);
}
else if (strcmp (key, "HomeDirectory") == 0) {
/* ignore */
}
else if (strcmp (key, "Shell") == 0) {
/* ignore */
}
else {
handled = FALSE;
}
if (!handled)
g_debug ("unhandled property %s", key);
}
static void static void
user_properties_free (UserProperties *props) user_properties_free (UserProperties *props)
{ {
@ -144,41 +79,92 @@ user_properties_free (UserProperties *props)
} }
static UserProperties * static UserProperties *
user_properties_get (DBusGConnection *bus, user_properties_get (GDBusConnection *bus,
const gchar *object_path) const gchar *object_path)
{ {
GVariant *result;
GVariantIter *iter;
gchar *key;
GVariant *value;
UserProperties *props; UserProperties *props;
GError *error; GError *error = NULL;
DBusGProxy *proxy;
GHashTable *hash_table;
props = g_new0 (UserProperties, 1); result = g_dbus_connection_call_sync (bus,
"org.freedesktop.Accounts",
proxy = dbus_g_proxy_new_for_name (bus, object_path,
"org.freedesktop.Accounts", "org.freedesktop.DBus.Properties",
object_path, "GetAll",
"org.freedesktop.DBus.Properties"); g_variant_new ("(s)", "org.freedesktop.Accounts.User"),
error = NULL; G_VARIANT_TYPE ("(a{sv})"),
if (!dbus_g_proxy_call (proxy, G_DBUS_CALL_FLAGS_NONE,
"GetAll", -1,
&error, NULL,
G_TYPE_STRING, &error);
"org.freedesktop.Accounts.User", if (!result) {
G_TYPE_INVALID,
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
&hash_table,
G_TYPE_INVALID)) {
g_debug ("Error calling GetAll() when retrieving properties for %s: %s", object_path, error->message); g_debug ("Error calling GetAll() when retrieving properties for %s: %s", object_path, error->message);
g_error_free (error); g_error_free (error);
g_free (props); return NULL;
props = NULL;
goto out;
} }
g_hash_table_foreach (hash_table, (GHFunc) collect_props, props);
g_hash_table_unref (hash_table);
out: props = g_new0 (UserProperties, 1);
g_object_unref (proxy); g_variant_get (result, "(a{sv})", &iter);
while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
if (strcmp (key, "Uid") == 0) {
g_variant_get (value, "t", &props->uid);
}
else if (strcmp (key, "UserName") == 0) {
g_variant_get (value, "s", &props->user_name);
}
else if (strcmp (key, "RealName") == 0) {
g_variant_get (value, "s", &props->real_name);
}
else if (strcmp (key, "AccountType") == 0) {
g_variant_get (value, "i", &props->account_type);
}
else if (strcmp (key, "Email") == 0) {
g_variant_get (value, "s", &props->email);
}
else if (strcmp (key, "Language") == 0) {
g_variant_get (value, "s", &props->language);
}
else if (strcmp (key, "Location") == 0) {
g_variant_get (value, "s", &props->location);
}
else if (strcmp (key, "LoginFrequency") == 0) {
g_variant_get (value, "t", &props->login_frequency);
}
else if (strcmp (key, "IconFile") == 0) {
g_variant_get (value, "s", &props->icon_file);
}
else if (strcmp (key, "Locked") == 0) {
g_variant_get (value, "b", &props->locked);
}
else if (strcmp (key, "AutomaticLogin") == 0) {
g_variant_get (value, "b", &props->automatic_login);
}
else if (strcmp (key, "SystemAccount") == 0) {
g_variant_get (value, "b", &props->system_account);
}
else if (strcmp (key, "PasswordMode") == 0) {
g_variant_get (value, "i", &props->password_mode);
}
else if (strcmp (key, "PasswordHint") == 0) {
g_variant_get (value, "s", &props->password_hint);
}
else if (strcmp (key, "HomeDirectory") == 0) {
/* ignore */
}
else if (strcmp (key, "Shell") == 0) {
/* ignore */
}
else {
g_debug ("unhandled property %s", key);
}
}
g_variant_iter_free (iter);
g_variant_unref (result);
return props; return props;
} }
@ -186,8 +172,8 @@ user_properties_get (DBusGConnection *bus,
struct _UmUser { struct _UmUser {
GObject parent; GObject parent;
DBusGConnection *bus; GDBusConnection *bus;
DBusGProxy *proxy; GDBusProxy *proxy;
gchar *object_path; gchar *object_path;
UserProperties *props; UserProperties *props;
@ -244,7 +230,7 @@ um_user_finalize (GObject *object)
g_free (user->display_name); g_free (user->display_name);
dbus_g_connection_unref (user->bus); g_object_unref (user->bus);
g_free (user->object_path); g_free (user->object_path);
if (user->proxy != NULL) if (user->proxy != NULL)
@ -719,17 +705,15 @@ update_info (UmUser *user)
} }
static void static void
changed_handler (DBusGProxy *proxy, user_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, UmUser *user)
gpointer *data)
{ {
UmUser *user = UM_USER (data); if (strcmp (signal_name, "Changed") == 0) {
if (update_info (user)) {
if (update_info (user)) { if (user->display_name != NULL) {
if (user->display_name != NULL) { um_user_show_full_display_name (user);
um_user_show_full_display_name (user); }
g_signal_emit (user, signals[CHANGED], 0);
} }
g_signal_emit (user, signals[CHANGED], 0);
} }
} }
@ -737,27 +721,33 @@ UmUser *
um_user_new_from_object_path (const gchar *object_path) um_user_new_from_object_path (const gchar *object_path)
{ {
UmUser *user; UmUser *user;
GError *error; GError *error = NULL;
user = (UmUser *)g_object_new (UM_TYPE_USER, NULL); user = (UmUser *)g_object_new (UM_TYPE_USER, NULL);
user->object_path = g_strdup (object_path); user->object_path = g_strdup (object_path);
error = NULL; user->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
user->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (user->bus == NULL) { if (user->bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message); g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto error; goto error;
} }
user->proxy = dbus_g_proxy_new_for_name (user->bus, user->proxy = g_dbus_proxy_new_sync (user->bus,
"org.freedesktop.Accounts", G_DBUS_PROXY_FLAGS_NONE,
user->object_path, NULL,
"org.freedesktop.Accounts.User"); "org.freedesktop.Accounts",
dbus_g_proxy_set_default_timeout (user->proxy, INT_MAX); user->object_path,
dbus_g_proxy_add_signal (user->proxy, "Changed", G_TYPE_INVALID); "org.freedesktop.Accounts.User",
NULL,
dbus_g_proxy_connect_signal (user->proxy, "Changed", &error);
G_CALLBACK (changed_handler), user, NULL); if (user->proxy == NULL) {
g_warning ("Couldn't get user proxy: %s", error->message);
g_error_free (error);
goto error;
}
g_dbus_proxy_set_default_timeout (user->proxy, INT_MAX);
g_signal_connect (user->proxy, "g-signal", G_CALLBACK (user_signal_cb), user);
if (!update_info (user)) if (!update_info (user))
goto error; goto error;
@ -773,108 +763,96 @@ void
um_user_set_email (UmUser *user, um_user_set_email (UmUser *user,
const gchar *email) const gchar *email)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetEmail", g_variant_new ("(s)", email), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetEmail", if (!result) {
&error,
G_TYPE_STRING, email,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetEmail call failed: %s", error->message); g_warning ("SetEmail call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
um_user_set_language (UmUser *user, um_user_set_language (UmUser *user,
const gchar *language) const gchar *language)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetLanguage", g_variant_new ("(s)", language), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetLanguage", if (!result) {
&error,
G_TYPE_STRING, language,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetLanguage call failed: %s", error->message); g_warning ("SetLanguage call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
um_user_set_location (UmUser *user, um_user_set_location (UmUser *user,
const gchar *location) const gchar *location)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetLocation", g_variant_new ("(s)", location), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetLocation", if (!result) {
&error,
G_TYPE_STRING, location,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetLocation call failed: %s", error->message); g_warning ("SetLocation call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
um_user_set_user_name (UmUser *user, um_user_set_user_name (UmUser *user,
const gchar *user_name) const gchar *user_name)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetUserName", g_variant_new ("(s)", user_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetUserName", if (!result) {
&error,
G_TYPE_STRING, user_name,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetUserName call failed: %s", error->message); g_warning ("SetUserName call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
um_user_set_real_name (UmUser *user, um_user_set_real_name (UmUser *user,
const gchar *real_name) const gchar *real_name)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetRealName", g_variant_new ("(s)", real_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetRealName", if (!result) {
&error,
G_TYPE_STRING, real_name,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetRealName call failed: %s", error->message); g_warning ("SetRealName call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
um_user_set_icon_file (UmUser *user, um_user_set_icon_file (UmUser *user,
const gchar *icon_file) const gchar *icon_file)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetIconFile", g_variant_new ("(s)", icon_file), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetIconFile", if (!result) {
&error,
G_TYPE_STRING, icon_file,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetIconFile call failed: %s", error->message); g_warning ("SetIconFile call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
void void
@ -921,18 +899,16 @@ void
um_user_set_account_type (UmUser *user, um_user_set_account_type (UmUser *user,
gint account_type) gint account_type)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetAccountType", g_variant_new ("(i)", account_type), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetAccountType", if (!result) {
&error,
G_TYPE_INT, account_type,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetAccountType call failed: %s", error->message); g_warning ("SetAccountType call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return; return;
} }
g_variant_unref (result);
} }
static gchar static gchar
@ -981,21 +957,22 @@ um_user_set_password (UmUser *user,
gchar *crypted; gchar *crypted;
if (password_mode == 0) { if (password_mode == 0) {
GVariant *result;
crypted = make_crypted (password); crypted = make_crypted (password);
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetPassword", g_variant_new ("(ss)", crypted, hint), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetPassword", if (!result) {
&error,
G_TYPE_STRING, crypted,
G_TYPE_STRING, hint,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetPassword call failed: %s", error->message); g_warning ("SetPassword call failed: %s", error->message);
g_error_free (error); g_error_free (error);
} }
else
g_variant_unref (result);
memset (crypted, 0, strlen (crypted)); memset (crypted, 0, strlen (crypted));
g_free (crypted); g_free (crypted);
} }
else if (password_mode == 3 || password_mode == 4) { else if (password_mode == 3 || password_mode == 4) {
GVariant *result;
/* FIXME: this is a slightly odd side-effect: /* FIXME: this is a slightly odd side-effect:
* you disable the account, and autologin flips * you disable the account, and autologin flips
* we should remove that once gdm knows to * we should remove that once gdm knows to
@ -1005,26 +982,24 @@ um_user_set_password (UmUser *user,
um_user_get_automatic_login (user)) { um_user_get_automatic_login (user)) {
um_user_set_automatic_login (user, FALSE); um_user_set_automatic_login (user, FALSE);
} }
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetLocked", g_variant_new ("(b)", password_mode == 3), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetLocked", if (!result) {
&error,
G_TYPE_BOOLEAN, (password_mode == 3),
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetLocked call failed: %s", error->message); g_warning ("SetLocked call failed: %s", error->message);
g_error_free (error); g_error_free (error);
} }
else
g_variant_unref (result);
} }
else { else {
if (!dbus_g_proxy_call (user->proxy, GVariant *result;
"SetPasswordMode",
&error, result = g_dbus_proxy_call_sync (user->proxy, "SetPasswordMode", g_variant_new ("(i)", password_mode), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
G_TYPE_INT, password_mode, if (!result) {
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetPasswordMode call failed: %s", error->message); g_warning ("SetPasswordMode call failed: %s", error->message);
g_error_free (error); g_error_free (error);
} }
else
g_variant_unref (result);
} }
} }
@ -1047,36 +1022,32 @@ um_user_is_logged_in (UmUser *user)
gboolean gboolean
um_user_is_logged_in (UmUser *user) um_user_is_logged_in (UmUser *user)
{ {
DBusGProxy *proxy; GVariant *result;
GPtrArray *array; GVariantIter *iter;
GError *error;
gint n_sessions; gint n_sessions;
GError *error = NULL;
proxy = dbus_g_proxy_new_for_name (user->bus, result = g_dbus_connection_call_sync (user->bus,
"org.freedesktop.ConsoleKit", "org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager", "/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager"); "org.freedesktop.ConsoleKit.Manager",
"GetSessionsForUnixUser",
array = NULL; g_variant_new ("(u)", um_user_get_uid (user)),
error = NULL; G_VARIANT_TYPE ("(ao)"),
if (!dbus_g_proxy_call (proxy, G_DBUS_CALL_FLAGS_NONE,
"GetSessionsForUnixUser", -1,
&error, NULL,
G_TYPE_UINT, um_user_get_uid (user), &error);
G_TYPE_INVALID, if (!result) {
dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &array,
G_TYPE_INVALID)) {
g_warning ("GetSessionsForUnixUser failed: %s", error->message); g_warning ("GetSessionsForUnixUser failed: %s", error->message);
g_error_free (error); g_error_free (error);
return FALSE; return FALSE;
} }
n_sessions = array->len; g_variant_get (result, "(ao)", &iter);
n_sessions = g_variant_iter_n_children (iter);
g_ptr_array_foreach (array, (GFunc)g_free, NULL); g_variant_iter_free (iter);
g_ptr_array_free (array, TRUE); g_variant_unref (result);
g_object_unref (proxy);
return n_sessions > 0; return n_sessions > 0;
} }
@ -1087,17 +1058,16 @@ void
um_user_set_automatic_login (UmUser *user, um_user_set_automatic_login (UmUser *user,
gboolean enabled) gboolean enabled)
{ {
GVariant *result;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_call (user->proxy, result = g_dbus_proxy_call_sync (user->proxy, "SetAutomaticLogin", g_variant_new ("(b)", enabled), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
"SetAutomaticLogin", if (!result) {
&error,
G_TYPE_BOOLEAN, enabled,
G_TYPE_INVALID,
G_TYPE_INVALID)) {
g_warning ("SetAutomaticLogin call failed: %s", error->message); g_warning ("SetAutomaticLogin call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return;
} }
g_variant_unref (result);
} }
void void