Commit d46a23a5 authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Ray Strode
Browse files

user-accounts: port to libaccountsservice

This removes a bunch of duplicated code, and also drops
a direct dependency on libsystemd-login.

https://bugzilla.gnome.org/show_bug.cgi?id=671858
parent db97299e
......@@ -107,6 +107,7 @@ SCHEMAS_REQUIRED_VERSION=3.7.2.2
LIBWACOM_REQUIRED_VERSION=0.7
CLUTTER_REQUIRED_VERSION=1.11.3
GOA_REQUIRED_VERSION=3.5.90
ACCOUNTSSERVICE_REQUIRED_VERSION=0.6.30
COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
glib-2.0 >= $GLIB_REQUIRED_VERSION
......@@ -161,7 +162,7 @@ PKG_CHECK_MODULES(USER_ACCOUNTS_PANEL, $COMMON_MODULES
gnome-desktop-3.0
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION
pwquality
libsystemd-login)
accountsservice >= $ACCOUNTSSERVICE_REQUIRED_VERSION)
PKG_CHECK_MODULES(GVC, gobject-2.0 libpulse libpulse-mainloop-glib)
AM_CONDITIONAL(HAVE_INTROSPECTION, false)
......
......@@ -29,10 +29,6 @@ BUILT_SOURCES = \
libuser_accounts_la_SOURCES = \
um-account-type.h \
um-account-type.c \
um-user.h \
um-user.c \
um-user-manager.h \
um-user-manager.c \
um-account-dialog.h \
um-account-dialog.c \
um-password-dialog.h \
......@@ -87,10 +83,6 @@ frob_account_dialog_SOURCES = \
um-account-dialog.c \
um-realm-manager.c \
um-realm-manager.h \
um-user.h \
um-user.c \
um-user-manager.c \
um-user-manager.h \
um-utils.h \
um-utils.c \
$(BUILT_SOURCES)
......
......@@ -27,13 +27,13 @@ on_dialog_complete (GObject *object,
gpointer user_data)
{
GMainLoop *loop = user_data;
UmUser *user;
ActUser *user;
user = um_account_dialog_finish (UM_ACCOUNT_DIALOG (object), result);
if (user == NULL) {
g_printerr ("No user created\n");
} else {
g_printerr ("User created: %s\n", um_user_get_user_name (user));
g_printerr ("User created: %s\n", act_user_get_user_name (user));
g_object_unref (user);
}
......
......@@ -24,10 +24,10 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <act/act.h>
#include "um-account-dialog.h"
#include "um-realm-manager.h"
#include "um-user-manager.h"
#include "um-utils.h"
typedef enum {
......@@ -149,7 +149,7 @@ finish_action (UmAccountDialog *self)
static void
complete_dialog (UmAccountDialog *self,
UmUser *user)
ActUser *user)
{
if (user != NULL) {
g_simple_async_result_set_op_res_gpointer (self->async,
......@@ -162,11 +162,11 @@ complete_dialog (UmAccountDialog *self,
}
static void
create_user_done (UmUserManager *manager,
create_user_done (ActUserManager *manager,
GAsyncResult *res,
UmAccountDialog *self)
{
UmUser *user;
ActUser *user;
GError *error;
finish_action (self);
......@@ -174,14 +174,16 @@ create_user_done (UmUserManager *manager,
/* Note that user is returned without an extra reference */
error = NULL;
if (!um_user_manager_create_user_finish (manager, res, &user, &error)) {
user = act_user_manager_create_user_finish (manager, res, &error);
if (user == NULL) {
g_debug ("Failed to create user: %s", error->message);
if (!g_error_matches (error, UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR_PERMISSION_DENIED))
if (!g_error_matches (error, ACT_USER_MANAGER_ERROR, ACT_USER_MANAGER_ERROR_PERMISSION_DENIED))
show_error_dialog (self, _("Failed to add account"), error);
g_error_free (error);
gtk_widget_grab_focus (self->local_name);
} else {
g_debug ("Created user: %s", um_user_get_user_name (user));
g_debug ("Created user: %s", act_user_get_user_name (user));
complete_dialog (self, user);
}
}
......@@ -189,7 +191,7 @@ create_user_done (UmUserManager *manager,
static void
local_create_user (UmAccountDialog *self)
{
UmUserManager *manager;
ActUserManager *manager;
const gchar *username;
const gchar *name;
gint account_type;
......@@ -206,16 +208,14 @@ local_create_user (UmAccountDialog *self)
g_debug ("Creating local user: %s", username);
manager = um_user_manager_ref_default ();
um_user_manager_create_user (manager,
username,
name,
account_type,
self->cancellable,
(GAsyncReadyCallback)create_user_done,
self,
NULL);
g_object_unref (manager);
manager = act_user_manager_get_default ();
act_user_manager_create_user_async (manager,
username,
name,
account_type,
self->cancellable,
(GAsyncReadyCallback)create_user_done,
self);
}
static gboolean
......@@ -389,14 +389,13 @@ on_register_user (GObject *source,
{
UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
GError *error = NULL;
UmUser *user = NULL;
ActUser *user;
um_user_manager_cache_user_finish (UM_USER_MANAGER (source),
result, &user, &error);
user = act_user_manager_cache_user_finish (ACT_USER_MANAGER (source), result, &error);
/* This is where we're finally done */
if (error == NULL) {
g_debug ("Successfully cached remote user: %s", um_user_get_user_name (user));
if (user != NULL) {
g_debug ("Successfully cached remote user: %s", act_user_get_user_name (user));
finish_action (self);
complete_dialog (self, user);
......@@ -406,6 +405,8 @@ on_register_user (GObject *source,
finish_action (self);
g_error_free (error);
}
g_object_unref (self);
}
static void
......@@ -415,7 +416,7 @@ on_permit_user_login (GObject *source,
{
UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
UmRealmCommon *common;
UmUserManager *manager;
ActUserManager *manager;
GError *error = NULL;
gchar *login;
......@@ -428,18 +429,16 @@ on_permit_user_login (GObject *source,
* should also lookup information about this via the realm and make
* sure all that is functional.
*/
manager = um_user_manager_ref_default ();
manager = act_user_manager_get_default ();
login = um_realm_calculate_login (common, gtk_entry_get_text (self->enterprise_login));
g_return_if_fail (login != NULL);
g_debug ("Caching remote user: %s", login);
um_user_manager_cache_user (manager, login, self->cancellable,
on_register_user, g_object_ref (self),
g_object_unref);
act_user_manager_cache_user_async (manager, login, self->cancellable,
on_register_user, g_object_ref (self));
g_free (login);
g_object_unref (manager);
} else {
show_error_dialog (self, _("Failed to register account"), error);
......@@ -1192,11 +1191,11 @@ um_account_dialog_show (UmAccountDialog *self,
gtk_widget_grab_focus (self->local_name);
}
UmUser *
ActUser *
um_account_dialog_finish (UmAccountDialog *self,
GAsyncResult *result)
{
UmUser *user;
ActUser *user;
g_return_val_if_fail (UM_IS_ACCOUNT_DIALOG (self), NULL);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
......
......@@ -22,8 +22,8 @@
#ifndef __UM_ACCOUNT_DIALOG_H__
#define __UM_ACCOUNT_DIALOG_H__
#include <act/act.h>
#include <gtk/gtk.h>
#include "um-user.h"
G_BEGIN_DECLS
......@@ -40,7 +40,7 @@ void um_account_dialog_show (UmAccountDialog *self,
GtkWindow *parent,
GAsyncReadyCallback callback,
gpointer user_data);
UmUser * um_account_dialog_finish (UmAccountDialog *self,
ActUser * um_account_dialog_finish (UmAccountDialog *self,
GAsyncResult *result);
G_END_DECLS
......
......@@ -256,7 +256,7 @@ static void
delete_fingerprints_question (GtkWindow *parent,
GtkWidget *label1,
GtkWidget *label2,
UmUser *user)
ActUser *user)
{
GtkWidget *question;
GtkWidget *button;
......@@ -628,7 +628,7 @@ static void
enroll_fingerprints (GtkWindow *parent,
GtkWidget *label1,
GtkWidget *label2,
UmUser *user)
ActUser *user)
{
GDBusProxy *device;
GtkBuilder *dialog;
......@@ -766,7 +766,7 @@ void
fingerprint_button_clicked (GtkWindow *parent,
GtkWidget *label1,
GtkWidget *label2,
UmUser *user)
ActUser *user)
{
bindtextdomain ("fprintd", GNOMELOCALEDIR);
bind_textdomain_codeset ("fprintd", "UTF-8");
......
......@@ -18,11 +18,11 @@
*/
#include <gtk/gtk.h>
#include "um-user.h"
#include <act/act.h>
gboolean set_fingerprint_label (GtkWidget *label1,
GtkWidget *label2);
void fingerprint_button_clicked (GtkWindow *parent,
GtkWidget *label1,
GtkWidget *label2,
UmUser *user);
ActUser *user);
......@@ -29,9 +29,9 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <act/act.h>
#include "um-password-dialog.h"
#include "um-user-manager.h"
#include "um-utils.h"
#include "run-passwd.h"
#include "pw-utils.h"
......@@ -51,7 +51,7 @@ struct _UmPasswordDialog {
GtkWidget *show_password_button;
GtkWidget *ok_button;
UmUser *user;
ActUser *user;
GtkWidget *old_password_label;
GtkWidget *old_password_entry;
......@@ -205,26 +205,51 @@ accept_password_dialog (GtkButton *button,
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
hint = gtk_entry_get_text (GTK_ENTRY (um->normal_hint_entry));
if (mode == UM_PASSWORD_DIALOG_MODE_NORMAL && um_user_get_uid (um->user) == getuid ()) {
GdkDisplay *display;
GdkCursor *cursor;
/* When setting a password for the current user,
* use passwd directly, to preserve the audit trail
* and to e.g. update the keyring password.
*/
passwd_change_password (um->passwd_handler, password, (PasswdCallback) password_changed_cb, um);
gtk_widget_set_sensitive (um->dialog, FALSE);
display = gtk_widget_get_display (um->dialog);
cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
gdk_window_set_cursor (gtk_widget_get_window (um->dialog), cursor);
gdk_display_flush (display);
g_object_unref (cursor);
}
else {
um_user_set_password (um->user, mode, password, hint);
finish_password_change (um);
switch (mode) {
case UM_PASSWORD_DIALOG_MODE_NORMAL:
if (act_user_get_uid (um->user) == getuid ()) {
GdkDisplay *display;
GdkCursor *cursor;
/* When setting a password for the current user,
* use passwd directly, to preserve the audit trail
* and to e.g. update the keyring password.
*/
passwd_change_password (um->passwd_handler, password,
(PasswdCallback) password_changed_cb, um);
gtk_widget_set_sensitive (um->dialog, FALSE);
display = gtk_widget_get_display (um->dialog);
cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
gdk_window_set_cursor (gtk_widget_get_window (um->dialog), cursor);
gdk_display_flush (display);
g_object_unref (cursor);
return;
}
act_user_set_password (um->user, password, hint);
break;
case UM_PASSWORD_DIALOG_MODE_SET_AT_LOGIN:
act_user_set_password_mode (um->user, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN);
break;
case UM_PASSWORD_DIALOG_MODE_NO_PASSWORD:
act_user_set_password_mode (um->user, ACT_USER_PASSWORD_MODE_NONE);
break;
case UM_PASSWORD_DIALOG_MODE_LOCK_ACCOUNT:
act_user_set_locked (um->user, TRUE);
break;
case UM_PASSWORD_DIALOG_MODE_UNLOCK_ACCOUNT:
act_user_set_locked (um->user, FALSE);
break;
default:
g_assert_not_reached ();
}
finish_password_change (um);
}
static void
......@@ -330,7 +355,7 @@ update_password_strength (UmPasswordDialog *um)
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
username = um_user_get_user_name (um->user);
username = act_user_get_user_name (um->user);
pw_strength (password, old_password, username,
&hint, &long_hint, &strength_level);
......@@ -625,7 +650,7 @@ visible_func (GtkTreeModel *model,
{
if (um->user) {
gint mode;
gboolean locked = um_user_get_locked (um->user);
gboolean locked = act_user_get_locked (um->user);
gtk_tree_model_get (model, iter, 1, &mode, -1);
......@@ -643,7 +668,7 @@ visible_func (GtkTreeModel *model,
void
um_password_dialog_set_user (UmPasswordDialog *um,
UmUser *user)
ActUser *user)
{
GdkPixbuf *pixbuf;
GtkTreeModel *model;
......@@ -655,20 +680,20 @@ um_password_dialog_set_user (UmPasswordDialog *um,
if (user) {
um->user = g_object_ref (user);
pixbuf = um_user_render_icon (user, UM_ICON_STYLE_NONE, 48);
pixbuf = render_user_icon (user, UM_ICON_STYLE_NONE, 48);
gtk_image_set_from_pixbuf (GTK_IMAGE (um->user_icon), pixbuf);
g_object_unref (pixbuf);
gtk_label_set_label (GTK_LABEL (um->user_name),
um_user_get_real_name (user));
act_user_get_real_name (user));
gtk_entry_set_text (GTK_ENTRY (um->password_entry), "");
gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
gtk_entry_set_text (GTK_ENTRY (um->normal_hint_entry), "");
gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), "");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->show_password_button), FALSE);
if (um_user_get_uid (um->user) == getuid () &&
um_user_get_password_mode (um->user) == UM_PASSWORD_MODE_REGULAR) {
if (act_user_get_uid (um->user) == getuid () &&
act_user_get_password_mode (um->user) == ACT_USER_PASSWORD_MODE_REGULAR) {
gtk_widget_show (um->old_password_label);
gtk_widget_show (um->old_password_entry);
um->old_password_ok = FALSE;
......@@ -678,7 +703,7 @@ um_password_dialog_set_user (UmPasswordDialog *um,
gtk_widget_hide (um->old_password_entry);
um->old_password_ok = TRUE;
}
if (um_user_get_uid (um->user) == getuid()) {
if (act_user_get_uid (um->user) == getuid()) {
if (um->passwd_handler != NULL)
passwd_destroy (um->passwd_handler);
um->passwd_handler = passwd_init ();
......
......@@ -23,7 +23,7 @@
#define __UM_PASSWORD_DIALOG_H__
#include <gtk/gtk.h>
#include "um-user.h"
#include <act/act.h>
G_BEGIN_DECLS
......@@ -32,7 +32,7 @@ typedef struct _UmPasswordDialog UmPasswordDialog;
UmPasswordDialog *um_password_dialog_new (void);
void um_password_dialog_free (UmPasswordDialog *dialog);
void um_password_dialog_set_user (UmPasswordDialog *dialog,
UmUser *user);
ActUser *user);
void um_password_dialog_set_privileged (UmPasswordDialog *dialog,
gboolean privileged);
void um_password_dialog_show (UmPasswordDialog *dialog,
......
......@@ -26,6 +26,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <act/act.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
......@@ -36,7 +37,6 @@
#endif /* HAVE_CHEESE */
#include "um-photo-dialog.h"
#include "um-user-manager.h"
#include "um-crop-area.h"
#include "um-utils.h"
......@@ -55,7 +55,7 @@ struct _UmPhotoDialog {
GnomeDesktopThumbnailFactory *thumb_factory;
UmUser *user;
ActUser *user;
};
static void
......@@ -74,7 +74,7 @@ crop_dialog_response (GtkWidget *dialog,
pb = um_crop_area_get_picture (UM_CROP_AREA (um->crop_area));
pb2 = gdk_pixbuf_scale_simple (pb, 96, 96, GDK_INTERP_BILINEAR);
um_user_set_icon_data (um->user, pb2);
set_user_icon_data (um->user, pb2);
g_object_unref (pb2);
g_object_unref (pb);
......@@ -247,7 +247,7 @@ static void
none_icon_selected (GtkMenuItem *menuitem,
UmPhotoDialog *um)
{
um_user_set_icon_file (um->user, "");
act_user_set_icon_file (um->user, "");
}
static void
......@@ -276,7 +276,7 @@ webcam_response_cb (GtkDialog *dialog,
g_object_get (G_OBJECT (dialog), "pixbuf", &pb, NULL);
pb2 = gdk_pixbuf_scale_simple (pb, 96, 96, GDK_INTERP_BILINEAR);
um_user_set_icon_data (um->user, pb2);
set_user_icon_data (um->user, pb2);
g_object_unref (pb2);
g_object_unref (pb);
......@@ -337,7 +337,7 @@ stock_icon_selected (GtkMenuItem *menuitem,
const char *filename;
filename = g_object_get_data (G_OBJECT (menuitem), "filename");
um_user_set_icon_file (um->user, filename);
act_user_set_icon_file (um->user, filename);
}
static GtkWidget *
......@@ -652,11 +652,11 @@ set_tip (GtkWidget *item,
void
um_photo_dialog_set_user (UmPhotoDialog *um,
UmUser *user)
ActUser *user)
{
UmUserManager *manager;
ActUserManager *manager;
GSList *list, *l;
UmUser *u;
ActUser *u;
GIcon *icon;
GEmblem *emblem;
GList *children, *c;
......@@ -675,9 +675,8 @@ um_photo_dialog_set_user (UmPhotoDialog *um,
children = gtk_container_get_children (GTK_CONTAINER (um->photo_popup));
g_list_foreach (children, (GFunc) clear_tip, NULL);
manager = um_user_manager_ref_default ();
list = um_user_manager_list_users (manager);
g_object_unref (manager);
manager = act_user_manager_get_default ();
list = act_user_manager_list_users (manager);
icon = g_themed_icon_new ("avatar-default");
emblem = g_emblem_new (icon);
......@@ -689,7 +688,7 @@ um_photo_dialog_set_user (UmPhotoDialog *um,
u = l->data;
if (u == user)
continue;
filename = um_user_get_icon_file (u);
filename = act_user_get_icon_file (u);
if (filename == NULL)
continue;
for (c = children; c; c = c->next) {
......@@ -702,7 +701,7 @@ um_photo_dialog_set_user (UmPhotoDialog *um,
char *tip;
tip = g_strdup_printf (_("Used by %s"),
um_user_get_real_name (u));
act_user_get_real_name (u));
set_tip (GTK_WIDGET (c->data), tip, emblem);
g_free (tip);
break;
......
......@@ -23,7 +23,7 @@
#define __UM_PHOTO_DIALOG_H__
#include <gtk/gtk.h>
#include "um-user.h"
#include <act/act.h>
G_BEGIN_DECLS
......@@ -32,7 +32,7 @@ typedef struct _UmPhotoDialog UmPhotoDialog;
UmPhotoDialog *um_photo_dialog_new (GtkWidget *button);
void um_photo_dialog_free (UmPhotoDialog *dialog);
void um_photo_dialog_set_user (UmPhotoDialog *dialog,
UmUser *user);
ActUser *user);
G_END_DECLS
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2009-2010 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __UM_USER_MANAGER__
#define __UM_USER_MANAGER__
#include <glib-object.h>
#include <gio/gio.h>
#include "um-user.h"
G_BEGIN_DECLS
#define UM_TYPE_USER_MANAGER (um_user_manager_get_type ())
#define UM_USER_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UM_TYPE_USER_MANAGER, UmUserManager))
#define UM_USER_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UM_TYPE_USER_MANAGER, UmUserManagerClass))
#define UM_IS_USER_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UM_TYPE_USER_MANAGER))
#define UM_IS_USER_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UM_TYPE_USER_MANAGER))
#define UM_USER_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UM_TYPE_USER_MANAGER, UmUserManagerClass))
typedef struct
{
GObject parent;
GDBusProxy *proxy;
GHashTable *user_by_object_path;
GHashTable *user_by_name;
gboolean no_service;
} UmUserManager;