fix account selector visibility

Make sure its not shown when there is only one account in all cases.
Also don't show during migration or account wizard.

Change-Id: I21c8809a8219cb71a5c326a733c31e31ad0550f2
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
index 1f6a623..c529f98 100644
--- a/src/ringmainwindow.cpp
+++ b/src/ringmainwindow.cpp
@@ -727,6 +727,16 @@
 }
 
 static void
+show_combobox_account_selector(RingMainWindow *self, gboolean show)
+{
+    auto priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
+    /* we only want to show the account selector when there is more than 1 eneabled account; so
+     * every time we want to show it, we should preform this check */
+    gtk_widget_set_visible(priv->combobox_account_selector,
+        show && AvailableAccountModel::instance().rowCount() > 1);
+}
+
+static void
 on_account_creation_completed(RingMainWindow *win)
 {
     g_return_if_fail(IS_RING_MAIN_WINDOW(win));
@@ -745,7 +755,7 @@
     gtk_widget_show(priv->ring_settings);
 
     /* show the account selector */
-    gtk_widget_show(priv->combobox_account_selector);
+    show_combobox_account_selector(win, TRUE);
 
     /* init the selection for the account selector */
     gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), 0);
@@ -769,7 +779,7 @@
 
     /* hide settings button until account creation is complete */
     gtk_widget_hide(priv->ring_settings);
-    gtk_widget_hide(priv->combobox_account_selector);
+    show_combobox_account_selector(win, FALSE);
 
     gtk_widget_show(priv->account_creation_wizard);
 
@@ -1072,7 +1082,7 @@
         g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", G_CALLBACK(handle_account_migrations), win);
 
         gtk_widget_hide(priv->ring_settings);
-        gtk_widget_hide(priv->combobox_account_selector);
+        show_combobox_account_selector(win, FALSE);
         gtk_widget_show(priv->account_migration_view);
         gtk_stack_add_named(
             GTK_STACK(priv->stack_main_view),
@@ -1087,7 +1097,7 @@
     else
     {
         gtk_widget_show(priv->ring_settings);
-        gtk_widget_show(priv->combobox_account_selector);
+        show_combobox_account_selector(win, TRUE);
 
         /* init the selection for the account selector */
         gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), 0);
@@ -1256,11 +1266,14 @@
 
     });
 
-    QObject::connect(&AccountModel::instance(), &AccountModel::accountEnabledChanged, [win, priv](Account* a){
-        Q_UNUSED(a)
-        gtk_widget_set_visible(priv->combobox_account_selector,
-                                            (AvailableAccountModel::instance().rowCount() > 1)? TRUE : FALSE);
-    });
+    auto available_accounts_changed = [win, priv] {
+        /* if we're hiding the settings it means we're in the migration or wizard view and we don't
+         * want to show the combo box */
+        if (gtk_widget_get_visible(priv->ring_settings))
+            show_combobox_account_selector(win, TRUE);
+    };
+    QObject::connect(&AvailableAccountModel::instance(), &QAbstractItemModel::rowsRemoved, available_accounts_changed);
+    QObject::connect(&AvailableAccountModel::instance(), &QAbstractItemModel::rowsInserted, available_accounts_changed);
 
     priv->treeview_contact_requests = pending_contact_requests_view_new();
     gtk_container_add(GTK_CONTAINER(priv->scrolled_window_contact_requests), priv->treeview_contact_requests);
@@ -1336,8 +1349,7 @@
     auto *renderer = gtk_cell_renderer_text_new();
 
     /* set visibility */
-    gtk_widget_set_visible(priv->combobox_account_selector,
-                                            (AvailableAccountModel::instance().rowCount() > 1)? TRUE : FALSE);
+    show_combobox_account_selector(win, TRUE);
 
     /* layout */
     gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(priv->combobox_account_selector), renderer, FALSE);