[gnome-control-center] online-accounts: Use a dialog to manage the online account



commit 1a427a8ac3d899555f2a907a69825e47a6c2afc1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Nov 9 15:38:53 2016 -0200

    online-accounts: Use a dialog to manage the online account
    
    Following the mockups, the Online Accounts panel shall use a modal
    dialog to edit online accounts.
    
    This commit moves the current widgets to a dialog, and shows this
    dialog whenever an account is selected.
    
    Some changes by Debarshi Ray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774222

 panels/online-accounts/cc-online-accounts-panel.c |   97 ++++++++++++---------
 panels/online-accounts/online-accounts.ui         |   94 ++++++---------------
 2 files changed, 81 insertions(+), 110 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c 
b/panels/online-accounts/cc-online-accounts-panel.c
index bdf222a..43fb559 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -44,7 +44,8 @@ struct _CcGoaPanel
   GtkWidget *accounts_notebook;
   GtkWidget *accounts_tree_box;
   GtkWidget *accounts_tree_label;
-  GtkWidget *add_account_button;
+  GtkWidget *edit_account_dialog;
+  GtkWidget *edit_account_headerbar;
   GtkWidget *toolbar;
   GtkWidget *toolbar_add_button;
   GtkWidget *toolbar_remove_button;
@@ -59,9 +60,6 @@ static void on_toolbar_add_button_clicked (GtkToolButton *button,
 static void on_toolbar_remove_button_clicked (GtkToolButton *button,
                                               gpointer       user_data);
 
-static void on_add_button_clicked (GtkButton *button,
-                                   gpointer   user_data);
-
 static void fill_accounts_listbox (CcGoaPanel *self);
 
 static void on_account_added (GoaClient  *client,
@@ -197,6 +195,20 @@ cc_goa_panel_set_property (GObject *object,
 }
 
 static void
+cc_goa_panel_dispose (GObject *object)
+{
+  CcGoaPanel *panel = CC_GOA_PANEL (object);
+
+  if (panel->accounts_listbox != NULL)
+    {
+      g_signal_handlers_disconnect_by_func (panel->accounts_listbox, on_listbox_selection_changed, panel);
+      panel->accounts_listbox = NULL;
+    }
+
+  G_OBJECT_CLASS (cc_goa_panel_parent_class)->dispose (object);
+}
+
+static void
 cc_goa_panel_finalize (GObject *object)
 {
   CcGoaPanel *panel = CC_GOA_PANEL (object);
@@ -226,9 +238,6 @@ cc_goa_panel_init (CcGoaPanel *panel)
   g_object_bind_property (monitor, "network-available",
                           panel->toolbar_add_button, "sensitive",
                           G_BINDING_SYNC_CREATE);
-  g_object_bind_property (monitor, "network-available",
-                          panel->add_account_button, "sensitive",
-                          G_BINDING_SYNC_CREATE);
 
   /* TODO: probably want to avoid _sync() ... */
   error = NULL;
@@ -269,6 +278,20 @@ cc_goa_panel_get_help_uri (CcPanel *panel)
 }
 
 static void
+cc_goa_panel_constructed (GObject *object)
+{
+  CcGoaPanel *self = CC_GOA_PANEL (object);
+  GtkWindow *parent;
+
+  /* Setup account editor dialog */
+  parent = GTK_WINDOW (cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self))));
+
+  gtk_window_set_transient_for (GTK_WINDOW (self->edit_account_dialog), parent);
+
+  G_OBJECT_CLASS (cc_goa_panel_parent_class)->constructed (object);
+}
+
+static void
 cc_goa_panel_class_init (CcGoaPanelClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
@@ -278,7 +301,9 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
   panel_class->get_help_uri = cc_goa_panel_get_help_uri;
 
   object_class->set_property = cc_goa_panel_set_property;
+  object_class->dispose = cc_goa_panel_dispose;
   object_class->finalize = cc_goa_panel_finalize;
+  object_class->constructed = cc_goa_panel_constructed;
 
   g_object_class_override_property (object_class, PROP_PARAMETERS, "parameters");
 
@@ -289,12 +314,12 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_tree_box);
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_tree_label);
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_vbox);
-  gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, add_account_button);
+  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, toolbar);
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_add_button);
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_remove_button);
 
-  gtk_widget_class_bind_template_callback (widget_class, on_add_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_selection_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_toolbar_add_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_toolbar_remove_button_clicked);
@@ -312,9 +337,7 @@ show_page (CcGoaPanel *panel,
 static void
 show_page_nothing_selected (CcGoaPanel *panel)
 {
-  show_page (panel, 0);
-
-  gtk_widget_set_sensitive (panel->accounts_tree_box, FALSE);
+  gtk_widget_set_sensitive (panel->toolbar_remove_button, FALSE);
   gtk_widget_show (panel->accounts_tree_label);
 }
 
@@ -326,11 +349,13 @@ show_page_account (CcGoaPanel  *panel,
   GList *l;
   GoaProvider *provider;
   GoaAccount *account;
+  const gchar *provider_name;
   const gchar *provider_type;
+  gchar *title;
 
   provider = NULL;
 
-  show_page (panel, 1);
+  show_page (panel, 0);
   gtk_widget_set_sensitive (panel->accounts_tree_box, TRUE);
   gtk_widget_hide (panel->accounts_tree_label);
 
@@ -354,7 +379,15 @@ show_page_account (CcGoaPanel  *panel,
                                  NULL);
     }
 
+  provider_name = goa_account_get_provider_name (account);
+  /* translators: This is the title of the "Show Account" dialog. The
+   * %s is the name of the provider. e.g., 'Google'. */
+  title = g_strdup_printf (_("%s Account"), provider_name);
+  gtk_header_bar_set_title (GTK_HEADER_BAR (panel->edit_account_headerbar), title);
+  g_free (title);
+
   gtk_widget_show_all (panel->accounts_vbox);
+  gtk_widget_show (panel->edit_account_dialog);
 
   g_clear_object (&provider);
 }
@@ -409,7 +442,15 @@ on_listbox_selection_changed (CcGoaPanel    *self,
     }
   else
     {
-      show_page_nothing_selected (self);
+      GList *children;
+
+      children = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
+      if (children == NULL)
+        show_page_nothing_selected (self);
+      else
+        gtk_widget_set_sensitive (self->toolbar_remove_button, FALSE);
+
+      g_list_free (children);
     }
 }
 
@@ -417,7 +458,6 @@ static void
 fill_accounts_listbox (CcGoaPanel *self)
 {
   GList *accounts, *l;
-  GtkListBoxRow *first_row;
 
   accounts = goa_client_get_accounts (self->client);
 
@@ -429,10 +469,6 @@ fill_accounts_listbox (CcGoaPanel *self)
     {
       for (l = accounts; l != NULL; l = l->next)
         on_account_added (self->client, l->data, self);
-
-      /* Select the first row */
-      first_row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->accounts_listbox), 0);
-      gtk_list_box_select_row (GTK_LIST_BOX (self->accounts_listbox), first_row);
     }
 
   g_list_free_full (accounts, g_object_unref);
@@ -551,14 +587,6 @@ on_account_removed (GoaClient *client,
 
       if (row_object == object)
         {
-          GtkListBoxRow *row = NULL;
-
-          if (l->next != NULL)
-            row = GTK_LIST_BOX_ROW (l->next->data);
-          else if (l->prev != NULL)
-            row = GTK_LIST_BOX_ROW (l->prev->data);
-
-          gtk_list_box_select_row (GTK_LIST_BOX (self->accounts_listbox), row);
           gtk_widget_destroy (l->data);
           break;
         }
@@ -621,10 +649,7 @@ get_all_providers_cb (GObject      *source,
    */
 
   if (object != NULL)
-    {
-      GoaAccount *account = goa_object_peek_account (object);
-      select_account_by_id (data->panel, goa_account_get_id (account));
-    }
+    gtk_widget_hide (data->panel->accounts_tree_label);
 
   if (error != NULL)
     {
@@ -742,13 +767,3 @@ on_toolbar_remove_button_clicked (GtkToolButton *button,
                                g_object_ref (panel));
     }
 }
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static void
-on_add_button_clicked (GtkButton *button,
-                       gpointer   user_data)
-{
-  CcGoaPanel *panel = CC_GOA_PANEL (user_data);
-  add_account (panel, NULL, NULL);
-}
diff --git a/panels/online-accounts/online-accounts.ui b/panels/online-accounts/online-accounts.ui
index df192f2..3316eec 100644
--- a/panels/online-accounts/online-accounts.ui
+++ b/panels/online-accounts/online-accounts.ui
@@ -105,6 +105,28 @@
             </child>
           </object>
         </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkDialog" id="edit_account_dialog">
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <property name="use_header_bar">1</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no" />
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="edit_account_headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+      </object>
+    </child>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="margin">18</property>
         <child>
           <object class="GtkNotebook" id="accounts_notebook">
             <property name="visible">True</property>
@@ -112,71 +134,6 @@
             <property name="show_tabs">False</property>
             <property name="show_border">False</property>
             <child>
-              <object class="GtkAlignment" id="alignment2">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="bottom_padding">18</property>
-                <child>
-                  <object class="GtkBox" id="box1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="valign">center</property>
-                    <property name="vexpand">True</property>
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">6</property>
-                    <child>
-                      <object class="GtkButton" id="add_account_button">
-                        <property name="label" translatable="yes">Add an online account</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="halign">center</property>
-                        <property name="use_action_appearance">False</property>
-                        <signal name="clicked" handler="on_add_button_clicked" object="CcGoaPanel" 
swapped="no" />
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Adding an account allows your applications 
to access it for documents, mail, contacts, calendar, chat and more.</property>
-                        <property name="justify">center</property>
-                        <property name="wrap">True</property>
-                        <property name="max_width_chars">40</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label">page 1</property>
-              </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkBox" id="accounts_vbox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -196,13 +153,12 @@
               </packing>
             </child>
             <child type="tab">
-              <object class="GtkLabel" id="label2">
+              <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label">page 2</property>
+                <property name="label">page 1</property>
               </object>
               <packing>
-                <property name="position">1</property>
                 <property name="tab_fill">False</property>
               </packing>
             </child>
@@ -219,5 +175,5 @@
         </child>
       </object>
     </child>
-  </template>
+  </object>
 </interface>


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