[gnome-control-center/wip/enterprise-login: 5/15] user-accounts: User to cancel long actions in UmAccountDialog



commit ede1e89d2b452bd0586482e3312ef631cefdb12e
Author: Stef Walter <stefw gnome org>
Date:   Wed Jun 6 23:01:25 2012 +0200

    user-accounts: User to cancel long actions in UmAccountDialog
    
    Allow the user to cancel long actions in UmAccountDialog by
    pressing the cancel button.
    
    This is relevant in later commits when we merge 'enterprise login'
    support.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677548

 panels/user-accounts/um-account-dialog.c |   33 ++++++++++++++++++++++++++++++
 panels/user-accounts/um-user-manager.c   |    3 +-
 panels/user-accounts/um-user-manager.h   |    1 +
 3 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index 8a4b803..eecde0a 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -39,6 +39,7 @@ struct _UmAccountDialog {
         GtkDialog parent;
         GtkWidget *widgets;
         GSimpleAsyncResult *async;
+        GCancellable *cancellable;
 
         GtkWidget *username_combo;
         GtkWidget *name_entry;
@@ -148,6 +149,7 @@ accept_account_dialog (UmAccountDialog *self)
                                      username,
                                      name,
                                      account_type,
+                                     self->cancellable,
                                      (GAsyncReadyCallback)create_user_done,
                                      self,
                                      NULL);
@@ -271,6 +273,7 @@ um_account_dialog_response (GtkDialog *dialog,
                 break;
         case GTK_RESPONSE_CANCEL:
         case GTK_RESPONSE_DELETE_EVENT:
+                g_cancellable_cancel (self->cancellable);
                 complete_dialog (self, NULL);
                 break;
         default:
@@ -280,10 +283,36 @@ um_account_dialog_response (GtkDialog *dialog,
 }
 
 static void
+um_account_dialog_dispose (GObject *obj)
+{
+        UmAccountDialog *self = UM_ACCOUNT_DIALOG (obj);
+
+        if (self->cancellable)
+                g_cancellable_cancel (self->cancellable);
+
+        G_OBJECT_CLASS (um_account_dialog_parent_class)->dispose (obj);
+}
+
+static void
+um_account_dialog_finalize (GObject *obj)
+{
+        UmAccountDialog *self = UM_ACCOUNT_DIALOG (obj);
+
+        if (self->cancellable)
+                g_object_unref (self->cancellable);
+
+        G_OBJECT_CLASS (um_account_dialog_parent_class)->finalize (obj);
+}
+
+static void
 um_account_dialog_class_init (UmAccountDialogClass *klass)
 {
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
         GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
 
+        object_class->dispose = um_account_dialog_dispose;
+        object_class->finalize = um_account_dialog_finalize;
+
         dialog_class->response = um_account_dialog_response;
 }
 
@@ -309,6 +338,10 @@ um_account_dialog_perform (UmAccountDialog     *self,
         self->async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
                                                  um_account_dialog_perform);
 
+        if (self->cancellable)
+                g_object_unref (self->cancellable);
+        self->cancellable = g_cancellable_new ();
+
         gtk_entry_set_text (GTK_ENTRY (self->name_entry), "");
         gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (self->username_combo))), "");
         model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->username_combo));
diff --git a/panels/user-accounts/um-user-manager.c b/panels/user-accounts/um-user-manager.c
index d59b263..a9c629d 100644
--- a/panels/user-accounts/um-user-manager.c
+++ b/panels/user-accounts/um-user-manager.c
@@ -515,6 +515,7 @@ um_user_manager_create_user (UmUserManager       *manager,
                              const char          *user_name,
                              const char          *real_name,
                              gint                 account_type,
+                             GCancellable        *cancellable,
                              GAsyncReadyCallback  done,
                              gpointer             done_data,
                              GDestroyNotify       destroy)
@@ -533,7 +534,7 @@ um_user_manager_create_user (UmUserManager       *manager,
                            g_variant_new ("(ssi)", user_name, real_name, account_type),
                            G_DBUS_CALL_FLAGS_NONE,
                            -1,
-                           NULL,
+                           cancellable,
                            create_user_done,
                            data);
 }
diff --git a/panels/user-accounts/um-user-manager.h b/panels/user-accounts/um-user-manager.h
index abf6e42..c47ecb5 100644
--- a/panels/user-accounts/um-user-manager.h
+++ b/panels/user-accounts/um-user-manager.h
@@ -88,6 +88,7 @@ void               um_user_manager_create_user           (UmUserManager       *m
                                                           const char          *user_name,
                                                           const char          *real_name,
                                                           gint                 account_type,
+                                                          GCancellable        *cancellable,
                                                           GAsyncReadyCallback  done,
                                                           gpointer             user_data,
                                                           GDestroyNotify       destroy);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]