[gnome-control-center] online-accounts: Consolidate the row modification code a bit



commit af7c214aaf24ea85082076a91eb0863b98daa820
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 22 13:21:03 2017 +0100

    online-accounts: Consolidate the row modification code a bit
    
    We have different variants of the same code that iterates over all the
    rows in a GtkListBox to find the one that corresponds to a given
    account. Some action is then performed on the row, depending on the use
    case at hand. In future we might want to look at the other rows in the
    list to decide whether to hide the entire GtkFrame or not.
    
    Let's consolidate this to reduce some duplication.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774222

 panels/online-accounts/cc-online-accounts-panel.c |   66 ++++++++++-----------
 1 files changed, 32 insertions(+), 34 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c 
b/panels/online-accounts/cc-online-accounts-panel.c
index 589139f..da11362 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -656,14 +656,33 @@ fill_accounts_listbox (CcGoaPanel *self)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static GtkWidget *
-get_row_for_account (CcGoaPanel *self,
-                     GoaObject *object)
+typedef void (*RowForAccountCallback) (CcGoaPanel *self, GtkWidget *row, GList *other_rows);
+
+static void
+hide_row_for_account (CcGoaPanel *self, GtkWidget *row, GList *other_rows)
+{
+  gtk_widget_hide (row);
+}
+
+static void
+remove_row_for_account (CcGoaPanel *self, GtkWidget *row, GList *other_rows)
+{
+  gtk_widget_destroy (row);
+}
+
+static void
+show_row_for_account (CcGoaPanel *self, GtkWidget *row, GList *other_rows)
+{
+  gtk_widget_show (row);
+}
+
+static void
+modify_row_for_account (CcGoaPanel *self,
+                        GoaObject *object,
+                        RowForAccountCallback callback)
 {
-  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)
@@ -673,13 +692,16 @@ get_row_for_account (CcGoaPanel *self,
       row_object = g_object_get_data (G_OBJECT (l->data), "goa-object");
       if (row_object == object)
         {
-          row = l->data;
+          GtkWidget *row = GTK_WIDGET (l->data);
+
+          children = g_list_remove_link (children, l);
+          callback (self, row, children);
+          g_list_free (l);
           break;
         }
     }
 
   g_list_free (children);
-  return row;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -782,24 +804,7 @@ on_account_removed (GoaClient *client,
                     gpointer   user_data)
 {
   CcGoaPanel *self = user_data;
-  GList *children, *l;
-
-  children = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
-
-  for (l = children; l != NULL; l = l->next)
-    {
-      GoaObject *row_object;
-
-      row_object = GOA_OBJECT (g_object_get_data (l->data, "goa-object"));
-
-      if (row_object == object)
-        {
-          gtk_widget_destroy (l->data);
-          break;
-        }
-    }
-
-  g_list_free (children);
+  modify_row_for_account (self, object, remove_row_for_account);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -889,12 +894,8 @@ 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, self->removed_object);
-  gtk_widget_show (row);
-
+  modify_row_for_account (self, self->removed_object, show_row_for_account);
   gtk_revealer_set_reveal_child (GTK_REVEALER (self->notification_revealer), FALSE);
 
   cancel_notification_timeout (self);
@@ -912,7 +913,6 @@ static void
 on_remove_button_clicked (CcGoaPanel *panel)
 {
   GoaAccount *account;
-  GtkWidget *row;
   gchar *label;
 
   if (panel->active_object == NULL)
@@ -932,10 +932,8 @@ on_remove_button_clicked (CcGoaPanel *panel)
   gtk_label_set_markup (GTK_LABEL (panel->notification_label), label);
   gtk_revealer_set_reveal_child (GTK_REVEALER (panel->notification_revealer), TRUE);
 
-  row = get_row_for_account (panel, panel->removed_object);
-
+  modify_row_for_account (panel, panel->removed_object, hide_row_for_account);
   gtk_widget_hide (panel->edit_account_dialog);
-  gtk_widget_hide (row);
 
   panel->remove_account_timeout_id = g_timeout_add_seconds (10, on_remove_account_timeout, panel);
 


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