[gnome-control-center/wip/gbsneto/new-goa-panel: 66/76] online-accounts: bring back account removal
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/new-goa-panel: 66/76] online-accounts: bring back account removal
- Date: Wed, 25 Jan 2017 22:53:22 +0000 (UTC)
commit 072b486af1ac69f07693278a23695a76ec797b8e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Nov 10 13:01:02 2016 -0200
online-accounts: bring back account removal
Following the previous commit, this commit effectively brings
back the account removal feature that was temporarily removed
by efa03cfa57b.
This is now reimplemented as an in-app notification, and users
now have the option to undo an accidentally removed account.
https://bugzilla.gnome.org/show_bug.cgi?id=774222
panels/online-accounts/cc-online-accounts-panel.c | 170 +++++++++++++++++++++
panels/online-accounts/online-accounts.ui | 65 ++++++++
2 files changed, 235 insertions(+), 0 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c
b/panels/online-accounts/cc-online-accounts-panel.c
index 743cce6..c7306c1 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -41,13 +41,20 @@ struct _CcGoaPanel
GoaClient *client;
GoaObject *active_object;
+ GoaObject *edited_object;
+ GoaObject *removed_object;
+
GtkWidget *accounts_listbox;
GtkWidget *edit_account_dialog;
GtkWidget *edit_account_headerbar;
GtkWidget *new_account_vbox;
+ GtkWidget *notification_label;
+ GtkWidget *notification_revealer;
GtkWidget *providers_listbox;
GtkWidget *stack;
GtkWidget *accounts_vbox;
+
+ guint remove_account_timeout_id;
};
static gboolean on_edit_account_dialog_delete_event (CcGoaPanel *self);
@@ -82,6 +89,15 @@ static void add_provider_row (CcGoaPanel *self,
static void show_page_account (CcGoaPanel *panel,
GoaObject *object);
+static void on_remove_button_clicked (GtkButton *button,
+ gpointer user_data);
+
+static void on_notification_closed (GtkButton *button,
+ CcGoaPanel *self);
+
+static void on_undo_button_clicked (GtkButton *button,
+ CcGoaPanel *self);
+
CC_PANEL_REGISTER (CcGoaPanel, cc_goa_panel);
enum {
@@ -400,12 +416,17 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, edit_account_dialog);
gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, edit_account_headerbar);
gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, new_account_vbox);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, notification_label);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, notification_revealer);
gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, providers_listbox);
gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, stack);
gtk_widget_class_bind_template_callback (widget_class, on_edit_account_dialog_delete_event);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, on_notification_closed);
gtk_widget_class_bind_template_callback (widget_class, on_provider_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, on_remove_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_undo_button_clicked);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -432,6 +453,9 @@ show_page_account (CcGoaPanel *panel,
panel->active_object = object;
reset_headerbar (panel);
+ /* Store the current object being edited */
+ panel->edited_object = object;
+
/* Move to the account editor page */
gtk_stack_set_visible_child_name (GTK_STACK (panel->stack), "editor");
@@ -674,3 +698,149 @@ get_all_providers_cb (GObject *source,
g_list_free_full (providers, g_object_unref);
}
+
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+
+static GtkWidget *
+get_row_for_account (CcGoaPanel *self,
+ GoaAccount *account)
+{
+ GtkWidget *row;
+ GList *children, *l;
+
+ row = NULL;
+ children = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
+
+ for (l = children; l != NULL; l = l->next)
+ {
+ GoaObject *row_object = g_object_get_data (l->data, "goa-object");
+
+ if (goa_object_peek_account (row_object) == account)
+ {
+ row = l->data;
+ break;
+ }
+ }
+
+ g_list_free (children);
+
+ return row;
+}
+
+static void
+cancel_notification_timeout (CcGoaPanel *self)
+{
+ if (self->remove_account_timeout_id == 0)
+ return;
+
+ g_source_remove (self->remove_account_timeout_id);
+
+ self->remove_account_timeout_id = 0;
+}
+
+static void
+remove_account_cb (GoaAccount *account,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ CcGoaPanel *panel = CC_GOA_PANEL (user_data);
+ GError *error;
+
+ error = NULL;
+ if (!goa_account_call_remove_finish (account, res, &error))
+ {
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new (GTK_WINDOW (cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL
(panel)))),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Error removing account"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s",
+ error->message);
+ gtk_widget_show_all (dialog);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_error_free (error);
+ }
+ g_object_unref (panel);
+}
+
+static void
+on_notification_closed (GtkButton *button,
+ CcGoaPanel *self)
+{
+ goa_account_call_remove (goa_object_peek_account (self->removed_object),
+ NULL, /* GCancellable */
+ (GAsyncReadyCallback) remove_account_cb,
+ g_object_ref (self));
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->notification_revealer), FALSE);
+
+ cancel_notification_timeout (self);
+ self->removed_object = NULL;
+}
+
+static void
+on_undo_button_clicked (GtkButton *button,
+ CcGoaPanel *self)
+{
+ GtkWidget *row;
+
+ /* Simply show the account row and hide the notification */
+ row = get_row_for_account (self, goa_object_peek_account (self->removed_object));
+ gtk_widget_show (row);
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->notification_revealer), FALSE);
+
+ cancel_notification_timeout (self);
+ self->removed_object = NULL;
+}
+
+static gboolean
+on_remove_account_timeout (gpointer user_data)
+{
+ on_notification_closed (NULL, user_data);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+on_remove_button_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ CcGoaPanel *panel = CC_GOA_PANEL (user_data);
+ GoaAccount *account;
+ GtkWidget *row;
+ gchar *label;
+
+ if (!panel->edited_object)
+ return;
+
+ /* If there is a pending account to be removed, remove it now */
+ if (panel->removed_object)
+ on_notification_closed (NULL, panel);
+
+ panel->removed_object = panel->edited_object;
+ panel->edited_object = NULL;
+
+ account = goa_object_peek_account (panel->removed_object);
+
+ /* Show the notification... */
+ label = g_strdup_printf (_("Account <b>%s</b> removed"), goa_account_get_presentation_identity (account));
+
+ gtk_label_set_markup (GTK_LABEL (panel->notification_label), label);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (panel->notification_revealer), TRUE);
+
+ /* ... and hide both the account row and the account dialog */
+ row = get_row_for_account (panel, account);
+
+ gtk_widget_hide (panel->edit_account_dialog);
+ gtk_widget_hide (row);
+
+ /* Fire up a timer to remove the account */
+ panel->remove_account_timeout_id = g_timeout_add_seconds (7, on_remove_account_timeout, panel);
+
+ g_free (label);
+}
diff --git a/panels/online-accounts/online-accounts.ui b/panels/online-accounts/online-accounts.ui
index 537236d..746195d 100644
--- a/panels/online-accounts/online-accounts.ui
+++ b/panels/online-accounts/online-accounts.ui
@@ -5,6 +5,68 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
+ <object class="GtkOverlay">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child type="overlay">
+ <object class="GtkRevealer" id="notification_revealer">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <property name="transition_type">slide-down</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="notification_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="undo_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Undo</property>
+ <signal name="clicked" handler="on_undo_button_clicked" object="CcGoaPanel"
swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <signal name="clicked" handler="on_notification_closed" object="CcGoaPanel"
swapped="no" />
+ <style>
+ <class name="flat" />
+ <class name="image-button" />
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon-name">window-close-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="app-notification" />
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -72,6 +134,8 @@
</child>
</object>
</child>
+ </object>
+ </child>
</template>
<object class="GtkDialog" id="edit_account_dialog">
<property name="can_focus">False</property>
@@ -129,6 +193,7 @@
<property name="halign">end</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Remove Account</property>
+ <signal name="clicked" handler="on_remove_button_clicked" object="CcGoaPanel"
swapped="no" />
<style>
<class name="destructive-action" />
</style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]