From 703caba4d3abe6fb47956604aa330939d536a393 Mon Sep 17 00:00:00 2001
From: Olivier SOLDANO <olivier.soldano@savoirfairelinux.com>
Date: Tue, 15 Nov 2016 16:18:55 -0500
Subject: [PATCH] ui: Patch callwidget because of blanck messagingPage

Due to former duplicated code (between lambda connected to smartlist selection change
and the slot of smartlist clicked) and wrong signal caught from smartlist
(selectionChanged instead of currentChanged), the messagingPage was going blank
in certain cases.

Fixed by refactoring the code and catching the signal currentChanged with
smartlistCurrentChanged slot.

Change-Id: If6d2461fc203318708e9c373c8ccb8294207db37
Tuleap: #1314
---
 callwidget.cpp | 39 ++++++---------------------------------
 callwidget.h   |  1 -
 2 files changed, 6 insertions(+), 34 deletions(-)

diff --git a/callwidget.cpp b/callwidget.cpp
index 5f44e8f..297616a 100644
--- a/callwidget.cpp
+++ b/callwidget.cpp
@@ -172,26 +172,11 @@ CallWidget::CallWidget(QWidget* parent) :
 
         connect(ui->smartList, &SmartList::btnVideoClicked, this, &CallWidget::btnComBarVideoClicked);
 
-        connect(RecentModel::instance().selectionModel(),
-                SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
-                this,
-                SLOT(smartListSelectionChanged(QItemSelection,QItemSelection)));
-
         connect(RecentModel::instance().selectionModel(),
                 SIGNAL(currentChanged(QModelIndex,QModelIndex)),
                 this,
                 SLOT(smartListCurrentChanged(QModelIndex,QModelIndex)));
 
-        connect(RecentModel::instance().selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &selected, const QItemSelection &deselected) {
-            Q_UNUSED(deselected)
-            if (selected.size()) {
-                auto idx = selected.indexes().first();
-                auto realIdx = RecentModel::instance().peopleProxy()->mapFromSource(idx);
-                ui->smartList->selectionModel()->setCurrentIndex(realIdx, QItemSelectionModel::ClearAndSelect);
-            } else
-                ui->smartList->clearSelection();
-        });
-
         connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
                 this, SLOT(contactLineEdit_registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
 
@@ -616,33 +601,21 @@ CallWidget::smartListCurrentChanged(const QModelIndex &currentIdx, const QModelI
     if (not currentIdx.isValid())
         return;
 
+    //catch call of current index
     auto currentIdxCall = RecentModel::instance().getActiveCall(currentIdx);
-    if (currentIdxCall && currentIdxCall != actualCall_) {
+
+    if (currentIdxCall && currentIdxCall != actualCall_) { //if it is different from actual call, switch between the two
         setActualCall(currentIdxCall);
-    } else if (currentIdxCall == nullptr){
+    } else if (currentIdxCall == nullptr){ // if there is no call attached to this smartlist index (contact tab)
         setActualCall(nullptr);
-        ui->instantMessagingWidget->hide();
-        showIMOutOfCall(currentIdx);
-    } else {
+        showIMOutOfCall(currentIdx); //change page to messaging page with correct behaviour
+    } else { // if non defined behaviour disconnect instant messaging and return to welcome page
         setActualCall(nullptr);
-        ui->instantMessagingWidget->hide();
         if (imConnection_)
             disconnect(imConnection_);
         ui->stackedWidget->setCurrentWidget(ui->welcomePage);
     }
 }
-void
-CallWidget::smartListSelectionChanged(const QItemSelection& newSel, const QItemSelection& oldSel) {
-
-    Q_UNUSED(oldSel)
-    if (newSel.indexes().empty()) {
-        setActualCall(nullptr);
-        return ui->stackedWidget->setCurrentWidget(ui->welcomePage);
-    }
-
-    auto newIdx = newSel.indexes().first();
-    smartListCurrentChanged(newIdx, newIdx);
-}
 
 void
 CallWidget::placeCall()
diff --git a/callwidget.h b/callwidget.h
index 99a1cc2..274cfd9 100644
--- a/callwidget.h
+++ b/callwidget.h
@@ -90,7 +90,6 @@ private slots:
     void callIncoming(Call* call);
     void callStateChanged(Call* call, Call::State previousState);
     void findRingAccount(QModelIndex idx1, QModelIndex idx2, QVector<int> vec);
-    void smartListSelectionChanged(const QItemSelection& newSel, const QItemSelection& oldSel);
     void smartListCurrentChanged(const QModelIndex &currentIdx, const QModelIndex &previousIdx);
     void slotAccountMessageReceived(const QMap<QString,QString> message,ContactMethod* cm,Media::Media::Direction dir);
     void onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm);
-- 
GitLab