From 4b8d78328fb58bd101802108e8da46cfb82cd1b4 Mon Sep 17 00:00:00 2001
From: Hugo Lefeuvre <hle@owl.eu.com>
Date: Tue, 2 Oct 2018 22:23:32 -0400
Subject: [PATCH] ringmainwindow: update account status on signal

+ Update account status indicators when receiving accountStatusChanged.
+ Remove unused old_view variable.
+ Remove useless on_show_add_account function (replaced by
enterAccountCreationWizard)
+ Fix status label context switching

Change-Id: Iceae3da15d787540331b068c2eae2eebe95c3c43
Gitlab: #922
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
---
 src/newaccountsettingsview.cpp |  2 +-
 src/ringmainwindow.cpp         | 37 ++++++----------------------------
 2 files changed, 7 insertions(+), 32 deletions(-)

diff --git a/src/newaccountsettingsview.cpp b/src/newaccountsettingsview.cpp
index 4e60cdc1..9a4efc5d 100644
--- a/src/newaccountsettingsview.cpp
+++ b/src/newaccountsettingsview.cpp
@@ -1951,7 +1951,7 @@ new_account_settings_view_update(NewAccountSettingsView *view, gboolean reset_vi
         return;
     }
 
-    auto& label_status = priv->label_status;
+    auto label_status = priv->label_status;
     if ((*priv->accountInfo_)->profileInfo.type != lrc::api::profile::Type::RING) {
         label_status = priv->sip_label_status;
     }
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
index 71bef467..cafca54a 100644
--- a/src/ringmainwindow.cpp
+++ b/src/ringmainwindow.cpp
@@ -400,34 +400,6 @@ on_account_creation_completed(RingMainWindow* self)
     priv->cpp->leaveAccountCreationWizard();
 }
 
-static void
-on_show_add_account(RingMainWindow* self)
-{
-    g_return_if_fail(IS_RING_MAIN_WINDOW(self));
-    auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
-
-    if (priv->cpp->show_settings) {
-        auto old_view = gtk_stack_get_visible_child(GTK_STACK(priv->stack_main_view));
-        if(IS_ACCOUNT_CREATION_WIZARD(old_view)) {
-            gtk_stack_set_visible_child(GTK_STACK(priv->cpp->widgets->stack_main_view), priv->cpp->widgets->last_settings_view);
-        } else {
-            if (!priv->cpp->widgets->account_creation_wizard) {
-                priv->cpp->widgets->account_creation_wizard = account_creation_wizard_new(false);
-                g_object_add_weak_pointer(G_OBJECT(priv->cpp->widgets->account_creation_wizard),
-                                          reinterpret_cast<gpointer*>(&priv->cpp->widgets->account_creation_wizard));
-                g_signal_connect_swapped(priv->cpp->widgets->account_creation_wizard, "account-creation-completed",
-                                         G_CALLBACK(on_account_creation_completed), self);
-
-                gtk_stack_add_named(GTK_STACK(priv->cpp->widgets->stack_main_view),
-                                    priv->cpp->widgets->account_creation_wizard,
-                                    ACCOUNT_CREATION_WIZARD_VIEW_NAME);
-            }
-            gtk_widget_show(priv->cpp->widgets->account_creation_wizard);
-            gtk_stack_set_visible_child(GTK_STACK(priv->cpp->widgets->stack_main_view), priv->cpp->widgets->account_creation_wizard);
-        }
-    }
-}
-
 static void
 on_account_changed(RingMainWindow* self)
 {
@@ -1739,6 +1711,12 @@ CppImpl::slotAccountStatusChanged(const std::string& id)
         updateLrc(id);
         ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view));
         return;
+    } else {
+        new_account_settings_view_update(NEW_ACCOUNT_SETTINGS_VIEW(widgets->new_account_settings_view), false);
+        auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
+        if (currentIdx == -1)
+            currentIdx = 0; // If no account selected, select the first account
+        refreshAccountSelectorWidget(currentIdx, id);
     }
 }
 
@@ -2085,9 +2063,6 @@ CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation:
 {
     changeAccountSelection(id);
 
-    // Change the view if we want a different view.
-    auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
-
     /* call changeView even if we are already in an incoming call view, since
        the incoming call view holds a copy of the conversation info which has
        the be updated */
-- 
GitLab