ui: handle navigation between calls/settings better

Change-Id: Ib621e160a8563b65c0967a0bf12d5d32663c8826
diff --git a/callwidget.cpp b/callwidget.cpp
index 24b3078..8dbd78e 100644
--- a/callwidget.cpp
+++ b/callwidget.cpp
@@ -218,6 +218,7 @@
 
     // hide the call stack
     ui->callStackWidget->hide();
+    ui->messagingHeaderWidget->show();
 
     ui->containerWidget->setVisible(false);
 }
@@ -245,6 +246,15 @@
             }
         } catch (...) {}
         ui->currentAccountComboBox->updateComboBoxDisplay();
+        auto selectedConvUid = LRCInstance::getSelectedConvUid();
+        auto convModel = LRCInstance::getCurrentConversationModel();
+        auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel);
+        if (!selectedConvUid.empty() && conversation != convModel->allFilteredConversations().end()) {
+            selectSmartlistItem(selectedConvUid);
+            ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
+        } else {
+            backToWelcomePage();
+        }
     } else {
         QObject::disconnect(smartlistSelectionConnection_);
         smartListModel_.reset(nullptr);
@@ -270,6 +280,9 @@
     if (!QApplication::focusWidget()) {
         auto convModel = LRCInstance::getCurrentConversationModel();
         auto conversation = Utils::getConversationFromUid(convUid, *convModel);
+        if (conversation == convModel->allFilteredConversations().end()) {
+            return;
+        }
         auto bestName = Utils::bestNameForConversation(*conversation, *convModel);
         Utils::showSystemNotification(this,
             QString(tr("Message incoming from %1"))
@@ -627,7 +640,7 @@
     Q_UNUSED(accountId);
     Q_UNUSED(convInfo);
     qDebug() << "slotShowCallView";
-    ui->callStackWidget->show();
+    showCallPanel();
     ui->callStackWidget->setCurrentWidget(ui->videoPage);
     ui->videoWidget->showChatviewIfToggled();
     hideMiniSpinner();
@@ -657,10 +670,9 @@
     if (call.isOutgoing) {
         if (isCallSelected) {
             miniSpinner_->start();
-            ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
             ui->spinnerLabel->show();
             ui->callStackWidget->setCurrentWidget(ui->outgoingCallPage);
-            ui->callStackWidget->show();
+            showCallPanel();
         }
     } else {
         if (!QApplication::focusWidget()) {
@@ -672,12 +684,11 @@
         auto selectedAccountId = LRCInstance::getCurrentAccountInfo().id;
         auto accountProperties = LRCInstance::accountModel().getAccountConfig(selectedAccountId);
         if (accountProperties.autoAnswer) {
-            ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
             ui->callStackWidget->setCurrentWidget(ui->videoPage);
+            showCallPanel();
         } else if (isCallSelected) {
-            ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
             ui->callStackWidget->setCurrentWidget(ui->incomingCallPage);
-            ui->callStackWidget->show();
+            showCallPanel();
         }
     }
 
@@ -709,6 +720,7 @@
     Q_UNUSED(convInfo);
 
     ui->callStackWidget->hide();
+    ui->messagingHeaderWidget->show();
     showConversationView();
 }
 
@@ -873,6 +885,7 @@
 void
 CallWidget::backToWelcomePage()
 {
+    qDebug() << "backToWelcomePage";
     deselectConversation();
     ui->messageView->hideMessages();
     ui->stackedWidget->setCurrentWidget(ui->welcomePage);
@@ -1065,11 +1078,11 @@
         auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
         const auto item = currentConversationModel->filteredConversation(index.row());
         if (callModel->hasCall(conversation->callId) && item.callId == conversation->callId) {
-            ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
-            ui->callStackWidget->show();
+            showCallPanel();
             return;
         }
         ui->callStackWidget->hide();
+        ui->messagingHeaderWidget->show();
     }
 }
 
@@ -1179,6 +1192,7 @@
             case lrc::api::call::Status::TERMINATING:
             {
                 ui->callStackWidget->hide();
+                ui->messagingHeaderWidget->show();
                 showConversationView();
                 break;
             }
@@ -1201,4 +1215,15 @@
                 ui->messageView->printHistory(*convModel, currentConversation->interactions);
             }
         });
-}
\ No newline at end of file
+}
+
+void
+CallWidget::showCallPanel()
+{
+    ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
+    ui->callStackWidget->show();
+    ui->imBackButton->hide();
+    ui->imBackButton->hide();
+    ui->btnAudioCall->hide();
+    ui->btnVideoCall->hide();
+}
diff --git a/callwidget.h b/callwidget.h
index 94b7d09..bb27718 100644
--- a/callwidget.h
+++ b/callwidget.h
@@ -114,7 +114,6 @@
     void setupQRCode(QString ringID);
     void backToWelcomePage();
 
-    // lrc
     void selectConversation(const QModelIndex& index);
     bool selectConversation(const lrc::api::conversation::Info& item,
         lrc::api::ConversationModel& convModel);
@@ -134,6 +133,7 @@
     void updateConversationsFilterWidget();
     void updateComboBox();
     void connectAccount(const std::string& accId);
+    void showCallPanel();
 
     QMenu* menu_;
 
diff --git a/deleteaccountdialog.cpp b/deleteaccountdialog.cpp
index b9d9399..2c2a691 100644
--- a/deleteaccountdialog.cpp
+++ b/deleteaccountdialog.cpp
@@ -46,12 +46,12 @@
 void
 DeleteAccountDialog::on_deleteCancelBtn_clicked()
 {
-    done(0);
+    done(DialogCode::Rejected);
 }
 
 void
 DeleteAccountDialog::on_deleteAcceptBtn_clicked()
 {
     LRCInstance::editableAccountModel()->removeAccount(LRCInstance::getCurrAccId());
-    done(0);
+    done(DialogCode::Accepted);
 }
\ No newline at end of file
diff --git a/settingswidget.cpp b/settingswidget.cpp
index 2a149c2..e8016b1 100644
--- a/settingswidget.cpp
+++ b/settingswidget.cpp
@@ -500,13 +500,15 @@
 SettingsWidget::delAccountSlot()
 {
     DeleteAccountDialog delDialog(this);
-    delDialog.exec();
-
-    LRCInstance::setSelectedAccountId("");
-    if (!LRCInstance::accountModel().getAccountList().size()) {
-        emit NavigationRequested(ScreenEnum::WizardScreen);
-    } else {
-        emit NavigationRequested(ScreenEnum::CallScreen);
+    auto ret = delDialog.exec();
+    if (ret == QDialog::Accepted) {
+        LRCInstance::setSelectedAccountId("");
+        if (!LRCInstance::accountModel().getAccountList().size()) {
+            emit NavigationRequested(ScreenEnum::WizardScreen);
+        } else {
+            LRCInstance::setSelectedConvId("");
+            emit NavigationRequested(ScreenEnum::CallScreen);
+        }
     }
 }