[gnome-control-center] online-accounts: Add a bottom row to display non-branded providers



commit e9198bdb4d3657f6c88b61834b545dbe63084267
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 10 14:46:38 2016 -0200

    online-accounts: Add a bottom row to display non-branded providers
    
    As per the mockups, and mimicking the dialog behavior, add a bottom
    row that shows non-branded providers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774222

 panels/online-accounts/cc-online-accounts-panel.c |   79 ++++++++++++++++++++-
 panels/online-accounts/online-accounts.ui         |   15 ++++
 2 files changed, 92 insertions(+), 2 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c 
b/panels/online-accounts/cc-online-accounts-panel.c
index b711416..4a2b40e 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -45,6 +45,7 @@ struct _CcGoaPanel
   GtkWidget *accounts_listbox;
   GtkWidget *edit_account_dialog;
   GtkWidget *edit_account_headerbar;
+  GtkWidget *more_providers_row;
   GtkWidget *new_account_vbox;
   GtkWidget *notification_label;
   GtkWidget *notification_revealer;
@@ -123,6 +124,7 @@ add_provider_row (CcGoaPanel  *self,
                   GoaProvider *provider)
 {
   GIcon *icon;
+  GoaProviderFeatures features;
   GtkWidget *image;
   GtkWidget *label;
   GtkWidget *row;
@@ -131,7 +133,6 @@ add_provider_row (CcGoaPanel  *self,
   gchar *name;
 
   row = gtk_list_box_row_new ();
-  gtk_container_add (GTK_CONTAINER (self->providers_listbox), row);
 
   row_grid = gtk_grid_new ();
   gtk_orientable_set_orientation (GTK_ORIENTABLE (row_grid), GTK_ORIENTATION_HORIZONTAL);
@@ -160,13 +161,75 @@ add_provider_row (CcGoaPanel  *self,
   gtk_label_set_markup (GTK_LABEL (label), markup);
   gtk_container_add (GTK_CONTAINER (row_grid), label);
 
-  gtk_widget_show_all (row);
+  /* Check if the row should be shown initially */
+  features = goa_provider_get_provider_features (provider);
+
+  if ((features & GOA_PROVIDER_FEATURE_BRANDED) != 0)
+    gtk_widget_show_all (row);
+
+  gtk_container_add (GTK_CONTAINER (self->providers_listbox), row);
 
   g_free (markup);
   g_free (name);
   g_object_unref (icon);
 }
 
+static gint
+sort_providers_func (GtkListBoxRow *a,
+                     GtkListBoxRow *b,
+                     gpointer       user_data)
+{
+  GoaProvider *a_provider, *b_provider;
+  CcGoaPanel *self;
+  gboolean a_branded, b_branded;
+
+  self = user_data;
+
+  if (a == GTK_LIST_BOX_ROW (self->more_providers_row))
+    return 1;
+  else if (b == GTK_LIST_BOX_ROW (self->more_providers_row))
+    return -1;
+
+  a_provider = g_object_get_data (G_OBJECT (a), "goa-provider");
+  b_provider = g_object_get_data (G_OBJECT (b), "goa-provider");
+
+  a_branded = (goa_provider_get_provider_features (a_provider) & GOA_PROVIDER_FEATURE_BRANDED) != 0;
+  b_branded = (goa_provider_get_provider_features (b_provider) & GOA_PROVIDER_FEATURE_BRANDED) != 0;
+
+  if (a_branded != b_branded)
+    {
+      if (a_branded)
+        return -1;
+      else
+        return 1;
+    }
+
+  return gtk_list_box_row_get_index (b) - gtk_list_box_row_get_index (a);
+}
+
+static void
+show_non_branded_providers (CcGoaPanel *self)
+{
+  GList *children, *l;
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->providers_listbox));
+
+  for (l = children; l != NULL; l = l->next)
+    {
+      GoaProvider *provider = g_object_get_data (l->data, "goa-provider");
+
+      if (!provider)
+        continue;
+
+      if ((goa_provider_get_provider_features (provider) & GOA_PROVIDER_FEATURE_BRANDED) == 0)
+        gtk_widget_show_all (l->data);
+    }
+
+  gtk_widget_hide (self->more_providers_row);
+
+  g_list_free (children);
+}
+
 static void
 on_provider_row_activated (CcGoaPanel    *self,
                            GtkListBoxRow *activated_row)
@@ -175,6 +238,13 @@ on_provider_row_activated (CcGoaPanel    *self,
   GoaObject *object;
   GError *error;
 
+  /* Show More row */
+  if (activated_row == GTK_LIST_BOX_ROW (self->more_providers_row))
+    {
+      show_non_branded_providers (self);
+      return;
+    }
+
   error = NULL;
   provider = g_object_get_data (G_OBJECT (activated_row), "goa-provider");
 
@@ -343,6 +413,10 @@ cc_goa_panel_init (CcGoaPanel *panel)
                                 cc_list_box_update_header_func,
                                 NULL,
                                 NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (panel->providers_listbox),
+                              sort_providers_func,
+                              panel,
+                              NULL);
 
   monitor = g_network_monitor_get_default();
 
@@ -424,6 +498,7 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_vbox);
   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, more_providers_row);
   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);
diff --git a/panels/online-accounts/online-accounts.ui b/panels/online-accounts/online-accounts.ui
index 7022ca3..97a2d1f 100644
--- a/panels/online-accounts/online-accounts.ui
+++ b/panels/online-accounts/online-accounts.ui
@@ -127,6 +127,21 @@
                         <property name="can_focus">True</property>
                         <property name="selection_mode">none</property>
                         <signal name="row-activated" handler="on_provider_row_activated" object="CcGoaPanel" 
swapped="yes" />
+                        <child>
+                          <object class="GtkListBoxRow" id="more_providers_row">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <child>
+                              <object class="GtkImage">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="hexpand">True</property>
+                                <property name="margin">12</property>
+                                <property name="icon-name">view-more-symbolic</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>


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