[gnome-control-center/wip/add-account: 5/7] Show spinner when running



commit d75bf372d9bea2986f4a6adbb01b76e45bab9079
Author: Stef Walter <stefw gnome org>
Date:   Fri Jun 1 10:56:01 2012 +0200

    Show spinner when running
    
     * Keep dialog up while adding users, disable controls, show spinner
     * Show errors as children of current dialog.

 panels/user-accounts/um-account-dialog.c |   79 ++++++++++++++++++++++++------
 1 files changed, 64 insertions(+), 15 deletions(-)
---
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index 7574c10..4907426 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -44,12 +44,14 @@ typedef enum {
 
 struct _UmAccountDialog {
 	GtkDialog parent;
-	GtkNotebook *notebook;
 	GSimpleAsyncResult *async;
 	GCancellable *cancellable;
 
+	/* Common widgets */
+	GtkNotebook *notebook;
 	GtkWidget *bar;
 	gboolean bar_updating;
+	GtkSpinner *spinner;
 
 	/* Local users */
 	GtkWidget *local_login;
@@ -78,6 +80,21 @@ get_account_mode (UmAccountDialog *self)
 	return gtk_notebook_get_current_page (self->notebook);
 }
 
+static void
+action_in_progress (UmAccountDialog *self,
+                    gboolean processing)
+{
+	gtk_widget_set_sensitive (GTK_WIDGET (self->notebook), !processing);
+	gtk_widget_set_sensitive (self->bar, !processing);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, !processing);
+
+	gtk_widget_set_visible (GTK_WIDGET (self->spinner), processing);
+	if (processing)
+		gtk_spinner_start (self->spinner);
+	else
+		gtk_spinner_stop (self->spinner);
+}
+
 static gboolean
 local_validate (UmAccountDialog *self)
 {
@@ -336,11 +353,13 @@ on_create_local_user (GObject         *object,
 	GError *error = NULL;
 	UmUser *user;
 
+	action_in_progress (self, FALSE);
+
 	if (!um_user_manager_create_user_finish (UM_USER_MANAGER (object), res, &user, &error)) {
 		if (!g_error_matches (error, UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR_PERMISSION_DENIED)) {
 			GtkWidget *dialog;
 
-			dialog = gtk_message_dialog_new (gtk_window_get_transient_for (GTK_WINDOW (self)),
+			dialog = gtk_message_dialog_new (GTK_WINDOW (self),
 			                                 GTK_DIALOG_DESTROY_WITH_PARENT,
 			                                 GTK_MESSAGE_ERROR,
 			                                 GTK_BUTTONS_CLOSE,
@@ -354,13 +373,15 @@ on_create_local_user (GObject         *object,
 			gtk_window_present (GTK_WINDOW (dialog));
 		}
 		g_error_free (error);
+		gtk_widget_grab_focus (self->local_name);
+
 	} else {
 		g_simple_async_result_set_op_res_gpointer (self->async,
 		                                           g_object_ref (user),
 		                                           g_object_unref);
+		g_simple_async_result_complete_in_idle (self->async);
+		gtk_widget_hide (GTK_WIDGET (self));
 	}
-
-	g_simple_async_result_complete_in_idle (self->async);
 }
 
 static void
@@ -379,6 +400,7 @@ local_add (UmAccountDialog *self)
 	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->local_account_type), &iter);
 	gtk_tree_model_get (model, &iter, 1, &account_type, -1);
 
+	action_in_progress (self, TRUE);
 	manager = um_user_manager_ref_default ();
 	um_user_manager_create_user (manager,
 	                             username,
@@ -390,12 +412,22 @@ local_add (UmAccountDialog *self)
 	g_object_unref (manager);
 }
 
+static gboolean
+on_create_enterprise (gpointer data)
+{
+	UmAccountDialog *self = UM_ACCOUNT_DIALOG (data);
+	action_in_progress (self, FALSE);
+	return FALSE;
+}
+
 static void
 enterprise_add (UmAccountDialog *self)
 {
 	/* TODO: Implement adding of users */
+	action_in_progress (self, TRUE);
 
-	g_simple_async_result_complete_in_idle (self->async);
+	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 3, on_create_enterprise,
+	                            g_object_ref (self), g_object_unref);
 }
 
 static void
@@ -591,7 +623,10 @@ um_account_dialog_constructed (GObject *obj)
 	UmAccountDialog *self;
 	const gchar *filename;
 	GError *error = NULL;
+	GtkDialog *dialog;
 	GtkWidget *content;
+	GtkWidget *actions;
+	GtkWidget *box;
 
 	G_OBJECT_CLASS (um_account_dialog_parent_class)->constructed (obj);
 
@@ -607,14 +642,29 @@ um_account_dialog_constructed (GObject *obj)
 		return;
 	}
 
-	widget = gtk_dialog_add_button (GTK_DIALOG (self),
-	                                _("Add"), GTK_RESPONSE_OK);
+	dialog = GTK_DIALOG (self);
+	actions = gtk_dialog_get_action_area (dialog);
+	content = gtk_dialog_get_content_area (dialog);
+
+	/* Rearrange the bottom of dialog, so we can have spinner */
+	g_object_ref (actions);
+	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+	gtk_container_remove (GTK_CONTAINER (content), actions);
+	gtk_box_pack_end (GTK_BOX (box), actions, FALSE, TRUE, 0);
+	gtk_box_pack_end (GTK_BOX (content), box, TRUE, TRUE, 0);
+	gtk_widget_show (box);
+	g_object_unref (actions);
+
+	self->spinner = GTK_SPINNER (gtk_spinner_new ());
+	widget = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
+	gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 0, 0, 12, 6);
+	gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
+	gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (self->spinner));
+	gtk_widget_show (widget);
+
+	widget = gtk_dialog_add_button (dialog, _("Add"), GTK_RESPONSE_OK);
 	gtk_widget_grab_default (widget);
-
-	gtk_dialog_add_button (GTK_DIALOG (self),
-	                       _("Cancel"), GTK_RESPONSE_CANCEL);
-
-	content = gtk_dialog_get_content_area (GTK_DIALOG (self));
+	gtk_dialog_add_button (dialog, _("Cancel"), GTK_RESPONSE_CANCEL);
 
 	widget = (GtkWidget *) gtk_builder_get_object (builder, "account-dialog");
 	gtk_container_add (GTK_CONTAINER (content), widget);
@@ -651,16 +701,15 @@ um_account_dialog_response (GtkDialog *dialog,
 		break;
 	case GTK_RESPONSE_CANCEL:
 	case GTK_RESPONSE_DELETE_EVENT:
+		g_cancellable_cancel (self->cancellable);
 		g_simple_async_result_set_op_res_gpointer (self->async, NULL, NULL);
 		g_simple_async_result_complete_in_idle (self->async);
+		gtk_widget_hide (GTK_WIDGET (self));
 		break;
 	default:
 		g_warn_if_reached ();
 		break;
 	}
-
-	g_cancellable_cancel (self->cancellable);
-	gtk_widget_hide (GTK_WIDGET (self));
 }
 
 static void



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