add buttons on videooverlay and fix multi account

this patch adds buttons to switch to welcome page and settings
page whilst in a call.
The client was lacking this fonctionnality, in comparison to the
gnome client.

This patch also fixes the comportment of the smartlist responding
to these new possible states (including changing account during
a call).

Change-Id: I9c620d83ae0daf75f3ffc64205299006686807f1
Reviewed-by: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
diff --git a/callwidget.cpp b/callwidget.cpp
index 1ce1377..5bd630f 100644
--- a/callwidget.cpp
+++ b/callwidget.cpp
@@ -53,6 +53,7 @@
 #include "profile.h"
 #include "peerprofilecollection.h"
 #include "localprofilecollection.h"
+#include "callmodel.h"
 
 //Client
 #include "wizarddialog.h"
@@ -165,6 +166,10 @@
         connect(&ProfileModel::instance(), &ProfileModel::dataChanged,
                 ui->currentAccountWidget, &CurrentAccountWidget::setPhoto);
 
+        connect(ui->videoWidget, &VideoView::videoSettingsClicked, this, &CallWidget::settingsButtonClicked);
+        connect(ui->videoWidget, &VideoView::videoBackClicked, [=]{setActualCall(nullptr);
+                                                                    backToWelcomePage();});
+
     } catch (const std::exception& e) {
         qDebug() << "INIT ERROR" << e.what();
     }
@@ -541,17 +546,21 @@
     //catch call of current index
     auto currentIdxCall = RecentModel::instance().getActiveCall(currentIdx);
 
-    if (currentIdxCall && currentIdxCall != actualCall_) { //if it is different from actual call, switch between the two
-        setActualCall(currentIdxCall);
-    } else if (currentIdxCall == nullptr){ // if there is no call attached to this smartlist index (contact tab)
+    if (currentIdxCall) {
+        if (currentIdxCall != actualCall_) //if it is different from actual call, switch between the two
+            setActualCall(currentIdxCall);
+    } else { // if there is no call attached to this smartlist index (contact tab)
         setActualCall(nullptr);
         showIMOutOfCall(currentIdx); // change page to contact request of messaging page with correct behaviour
-    } else { // if non defined behaviour disconnect instant messaging and return to welcome page
+    }
+    /*
+    else { // if non defined behaviour disconnect instant messaging and return to welcome page
         setActualCall(nullptr);
         if (imConnection_)
             disconnect(imConnection_);
         ui->stackedWidget->setCurrentWidget(ui->welcomePage);
     }
+    */
 }
 
 void
@@ -686,8 +695,10 @@
     if (current.isValid()) {
         auto ac = current.data(static_cast<int>(Account::Role::Object)).value<Account*>();
 
-        // First, we get back to the welcome view
-        if (ui->stackedWidget->currentWidget() != ui->welcomePage) {
+        // First, we get back to the welcome view (except if in call)
+
+        if (ui->stackedWidget->currentWidget() != ui->videoPage &&
+            ui->stackedWidget->currentWidget() != ui->welcomePage) {
             slidePage(ui->welcomePage);
         }
 
@@ -705,6 +716,8 @@
             // The selection model must be deleted by the application (see QT doc).
             QItemSelectionModel* sMod = ui->contactRequestList->selectionModel();
             delete sMod;
+            RecentModel::instance().selectionModel()->clear();
+            slidePage(ui->welcomePage);
         }
 
         ui->contactRequestList->setItemModel(ac->pendingContactRequestModel());
@@ -714,6 +727,11 @@
         // We modify the currentAccountWidget to reflect the new selected account
         // if the event wasn't triggered by this widget
         ui->currentAccountWidget->changeSelectedIndex(current.row());
+
+        if (actualCall_){
+            // keep call on foreground
+            callStateToView(actualCall_);
+        }
     }
 }
 
@@ -815,13 +833,19 @@
 }
 
 void
-CallWidget::on_imBackButton_clicked()
+CallWidget::backToWelcomePage()
 {
     RecentModel::instance().selectionModel()->clear();
     slidePage(ui->welcomePage);
 }
 
 void
+CallWidget::on_imBackButton_clicked()
+{
+    backToWelcomePage();
+}
+
+void
 CallWidget::slidePage(QWidget* widget, bool toRight)
 {
     short dir = (toRight ? -1 : 1);
diff --git a/callwidget.h b/callwidget.h
index 46beaf1..3aa7b51 100644
--- a/callwidget.h
+++ b/callwidget.h
@@ -130,4 +130,5 @@
     bool uriNeedNameLookup(const URI uri_passed);
     void processContactLineEdit();
     static Account* getSelectedAccount();
+    void backToWelcomePage();
 };
diff --git a/stylesheet.css b/stylesheet.css
index ceef3ea..3496e1b 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -186,19 +186,22 @@
 }
 
 QPushButton#exitSettingsButton, QPushButton#settingsButton, QPushButton#addToContactButton,
-QPushButton#imBackButton, QPushButton#sendCRBackButton, QPushButton#copyCMButton, QPushButton#pendingCRBackButton{
+QPushButton#imBackButton, QPushButton#sendCRBackButton, QPushButton#copyCMButton, QPushButton#pendingCRBackButton,
+QPushButton#videoBackBtn, QPushButton#videoCfgBtn{
     background-color: #414141;
     border-radius: 15px;
     border:solid 1px;
 }
 
 QPushButton#exitSettingsButton:hover, QPushButton#settingsButton:hover, QPushButton#imBackButton:hover,
-QPushButton#sendCRBackButton:hover, QPushButton#copyCMButton:hover, QPushButton#pendingCRBackButton:hover{
+QPushButton#sendCRBackButton:hover, QPushButton#copyCMButton:hover, QPushButton#pendingCRBackButton:hover,
+QPushButton#videoBackBtn:hover, QPushButton#videoCfgBtn:hover{
     background-color: #515151;
 }
 
 QPushButton#exitSettingsButton:pressed, QPushButton#settingsButton:pressed, QPushButton#imBackButton:pressed,
-QPushButton#sendCRBackButton:pressed, QPushButton#copyCMButton:pressed, QPushButton#pendingCRBackButton:pressed{
+QPushButton#sendCRBackButton:pressed, QPushButton#copyCMButton:pressed, QPushButton#pendingCRBackButton:pressed,
+QPushButton#videoBackBtn:pressed, QPushButton#videoCfgBtn:pressed{
     background-color: #313131;
 }
 
diff --git a/videooverlay.cpp b/videooverlay.cpp
index 718d5fa..9e30be7 100644
--- a/videooverlay.cpp
+++ b/videooverlay.cpp
@@ -211,3 +211,13 @@
 {
     actionModel_->execute(UserActionModel::Action::RECORD);
 }
+
+void VideoOverlay::on_videoBackBtn_clicked()
+{
+    emit videoBackBtnClicked();
+}
+
+void VideoOverlay::on_videoCfgBtn_clicked()
+{
+    emit videoCfgBtnClicked();
+}
diff --git a/videooverlay.h b/videooverlay.h
index 4b354ef..c525a3a 100644
--- a/videooverlay.h
+++ b/videooverlay.h
@@ -56,6 +56,8 @@
     void on_qualityButton_clicked();
     void on_addToContactButton_clicked();
     void on_recButton_clicked();
+    void on_videoBackBtn_clicked();
+    void on_videoCfgBtn_clicked();
 
 private:
     Ui::VideoOverlay* ui;
@@ -66,5 +68,7 @@
 
 signals:
     void setChatVisibility(bool visible);
+    void videoBackBtnClicked();
+    void videoCfgBtnClicked();
 };
 
diff --git a/videooverlay.ui b/videooverlay.ui
index b13d36c..150f37d 100644
--- a/videooverlay.ui
+++ b/videooverlay.ui
@@ -431,6 +431,23 @@
    <item row="0" column="2">
     <layout class="QHBoxLayout" name="horizontalLayout_7">
      <item>
+      <widget class="QPushButton" name="videoBackBtn">
+       <property name="minimumSize">
+        <size>
+         <width>30</width>
+         <height>30</height>
+        </size>
+       </property>
+       <property name="text">
+        <string/>
+       </property>
+       <property name="icon">
+        <iconset resource="ressources.qrc">
+         <normaloff>:/images/icons/ic_arrow_back_white_24dp.png</normaloff>:/images/icons/ic_arrow_back_white_24dp.png</iconset>
+       </property>
+      </widget>
+     </item>
+     <item>
       <widget class="QLabel" name="nameLabel">
        <property name="palette">
         <palette>
@@ -569,6 +586,23 @@
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QPushButton" name="videoCfgBtn">
+       <property name="minimumSize">
+        <size>
+         <width>30</width>
+         <height>30</height>
+        </size>
+       </property>
+       <property name="text">
+        <string/>
+       </property>
+       <property name="icon">
+        <iconset resource="ressources.qrc">
+         <normaloff>:/images/icons/ic_settings_white_48dp_2x.png</normaloff>:/images/icons/ic_settings_white_48dp_2x.png</iconset>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
   </layout>
diff --git a/videoview.cpp b/videoview.cpp
index dda4bfb..46d069f 100644
--- a/videoview.cpp
+++ b/videoview.cpp
@@ -65,6 +65,8 @@
     connect(overlay_, &VideoOverlay::setChatVisibility, [=](bool visible) {
         emit this->setChatVisibility(visible);
     });
+    connect(overlay_, &VideoOverlay::videoCfgBtnClicked, [=](){emit videoSettingsClicked();});
+    connect(overlay_, &VideoOverlay::videoBackBtnClicked, [=](){emit videoBackClicked();});
 }
 
 VideoView::~VideoView()
diff --git a/videoview.h b/videoview.h
index 5731dc0..c812818 100644
--- a/videoview.h
+++ b/videoview.h
@@ -76,5 +76,7 @@
     void toggleFullScreen();
 signals:
     void setChatVisibility(bool visible);
+    void videoSettingsClicked();
+    void videoBackClicked();
 };