[gnome-todo] todoist: Show accounts page only if todoist account is present



commit 3bfc0a5fdaf40a175f13474dcd30bfb863dc1bbe
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date:   Fri Jun 9 18:40:54 2017 +0530

    todoist: Show accounts page only if todoist account is present
    
    This patch enable empty page as default intial page and switches
    the stack child to accounts page if any todoist account was added.
    Incase, an account was removed, we need to check if no account is
    present after this removal and switch to empty page, if true.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772278

 plugins/todoist/gtd-todoist-preferences-panel.c |   28 ++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/plugins/todoist/gtd-todoist-preferences-panel.c b/plugins/todoist/gtd-todoist-preferences-panel.c
index f1d2641..049548b 100644
--- a/plugins/todoist/gtd-todoist-preferences-panel.c
+++ b/plugins/todoist/gtd-todoist-preferences-panel.c
@@ -129,10 +129,12 @@ on_goa_account_added (GoaClient                   *client,
   GtkWidget *box;
   GtkWidget *logo;
   GtkWidget *desc;
+  GList *child;
   const gchar *provider_name;
   const gchar *identity;
   goa_account = goa_object_get_account (object);
 
+  child = NULL;
   provider_name = goa_account_get_provider_name (goa_account);
 
   if (g_strcmp0 (provider_name, "Todoist") != 0)
@@ -153,7 +155,18 @@ on_goa_account_added (GoaClient                   *client,
   gtk_container_add (GTK_CONTAINER (row), box);
 
   gtk_widget_show_all (row);
+
+  child = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
+
+  /* If List Box was empty before this addition, the preferences
+   * panel should change to accounts_page.
+   */
+  if (!child)
+    gtk_stack_set_visible_child (GTK_STACK (self), self->accounts_page);
+
   gtk_list_box_insert (GTK_LIST_BOX (self->accounts_listbox), GTK_WIDGET (row), -1);
+
+  g_list_free (child);
 }
 
 static void
@@ -165,6 +178,7 @@ on_goa_account_removed (GoaClient                   *client,
   GList *child;
   GList *l;
   const gchar *provider;
+  guint todoist_accounts;
 
   goa_account = goa_object_get_account (object);
   provider = goa_account_get_provider_name (goa_account);
@@ -175,6 +189,7 @@ on_goa_account_removed (GoaClient                   *client,
     return;
 
   child = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
+  todoist_accounts = g_list_length (child);
 
   for (l = child; l != NULL; l = l->next)
     {
@@ -185,10 +200,19 @@ on_goa_account_removed (GoaClient                   *client,
       if (row_account == object)
         {
           gtk_container_remove (GTK_CONTAINER (self->accounts_listbox),l->data);
-
+          todoist_accounts--;
           break;
         }
     }
+
+  /* Check if ListBox becomes empty after this removal.
+   * If true change to empty_page of preference panel.
+   */
+
+  if (!todoist_accounts)
+    gtk_stack_set_visible_child (GTK_STACK (self), self->empty_page);
+
+  g_list_free (child);
 }
 
 void
@@ -277,7 +301,9 @@ gtd_todoist_preferences_panel_init (GtdTodoistPreferencesPanel *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  /* Set Empty Page as the default initial preferences page */
   gtk_stack_set_visible_child (GTK_STACK (self), self->empty_page);
+
   label = gtk_label_new ("No Todoist account configured");
   gtk_widget_show (label);
   gtk_list_box_set_placeholder (GTK_LIST_BOX (self->accounts_listbox), GTK_WIDGET (label));


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