[gnome-control-center] user-accounts: Reacquire permissions before adding account
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: Reacquire permissions before adding account
- Date: Wed, 24 Apr 2013 07:02:10 +0000 (UTC)
commit e84bb4983c67355e5a40d326e01c20014e89dcdd
Author: Stef Walter <stefw gnome org>
Date: Thu Apr 18 17:50:42 2013 +0200
user-accounts: Reacquire permissions before adding account
If necessary, reacquire permissions before starting to add an
account.
https://bugzilla.gnome.org/show_bug.cgi?id=698276
panels/user-accounts/frob-account-dialog.c | 2 +-
panels/user-accounts/um-account-dialog.c | 39 ++++++++++++++++++++++++++++
panels/user-accounts/um-account-dialog.h | 1 +
panels/user-accounts/um-user-panel.c | 2 +-
4 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/panels/user-accounts/frob-account-dialog.c b/panels/user-accounts/frob-account-dialog.c
index 410eb44..5c6e3bb 100644
--- a/panels/user-accounts/frob-account-dialog.c
+++ b/panels/user-accounts/frob-account-dialog.c
@@ -52,7 +52,7 @@ main (int argc,
dialog = um_account_dialog_new ();
loop = g_main_loop_new (NULL, FALSE);
- um_account_dialog_show (dialog, NULL, on_dialog_complete, loop);
+ um_account_dialog_show (dialog, NULL, NULL, on_dialog_complete, loop);
g_main_loop_run (loop);
g_main_loop_unref (loop);
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index 88dff99..4f07d71 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -49,6 +49,9 @@ static void on_realm_joined (GObject *source,
GAsyncResult *result,
gpointer user_data);
+static void um_account_dialog_response (GtkDialog *dialog,
+ gint response_id);
+
#define UM_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_ACCOUNT_DIALOG, \
UmAccountDialogClass))
#define UM_IS_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UM_TYPE_ACCOUNT_DIALOG))
@@ -60,6 +63,7 @@ struct _UmAccountDialog {
GtkWidget *container_widget;
GSimpleAsyncResult *async;
GCancellable *cancellable;
+ GPermission *permission;
GtkSpinner *spinner;
/* Buttons to switch modes between local/enterprise */
@@ -1081,6 +1085,28 @@ um_account_dialog_init (UmAccountDialog *self)
}
static void
+on_permission_acquired (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
+ GError *error = NULL;
+
+ /* Paired with begin_action in um_account_dialog_response () */
+ finish_action (self);
+
+ if (g_permission_acquire_finish (self->permission, res, &error)) {
+ g_return_if_fail (g_permission_get_allowed (self->permission));
+ um_account_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+ } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_warning ("Failed to acquire permission: %s", error->message);
+ }
+
+ g_clear_error (&error);
+ g_object_unref (self);
+}
+
+static void
um_account_dialog_response (GtkDialog *dialog,
gint response_id)
{
@@ -1088,6 +1114,14 @@ um_account_dialog_response (GtkDialog *dialog,
switch (response_id) {
case GTK_RESPONSE_OK:
+ /* We don't (or no longer) have necessary permissions */
+ if (self->permission && !g_permission_get_allowed (self->permission)) {
+ begin_action (self);
+ g_permission_acquire_async (self->permission, self->cancellable,
+ on_permission_acquired, g_object_ref (self));
+ return;
+ }
+
switch (self->mode) {
case UM_LOCAL:
local_create_user (self);
@@ -1137,6 +1171,7 @@ um_account_dialog_finalize (GObject *obj)
if (self->cancellable)
g_object_unref (self->cancellable);
+ g_clear_object (&self->permission);
g_object_unref (self->enterprise_realms);
G_OBJECT_CLASS (um_account_dialog_parent_class)->finalize (obj);
@@ -1163,6 +1198,7 @@ um_account_dialog_new (void)
void
um_account_dialog_show (UmAccountDialog *self,
GtkWindow *parent,
+ GPermission *permission,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1178,6 +1214,9 @@ um_account_dialog_show (UmAccountDialog *self,
g_object_unref (self->cancellable);
self->cancellable = g_cancellable_new ();
+ g_clear_object (&self->permission);
+ self->permission = permission ? g_object_ref (permission) : NULL;
+
local_prepare (self);
enterprise_prepare (self);
mode_change (self, UM_LOCAL);
diff --git a/panels/user-accounts/um-account-dialog.h b/panels/user-accounts/um-account-dialog.h
index f246766..c69df2d 100644
--- a/panels/user-accounts/um-account-dialog.h
+++ b/panels/user-accounts/um-account-dialog.h
@@ -38,6 +38,7 @@ GType um_account_dialog_get_type (void) G_GNUC_CONST;
UmAccountDialog *um_account_dialog_new (void);
void um_account_dialog_show (UmAccountDialog *self,
GtkWindow *parent,
+ GPermission *permission,
GAsyncReadyCallback callback,
gpointer user_data);
ActUser * um_account_dialog_finish (UmAccountDialog *self,
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 2b10a9a..786fae9 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -354,7 +354,7 @@ add_user (GtkButton *button, CcUserPanelPrivate *d)
dialog = um_account_dialog_new ();
um_account_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_toplevel (d->main_box)),
- select_created_user, d);
+ d->permission, select_created_user, d);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]