selected account: behaviour on conversation

This commit add a few changes to prevent bugs when account is changed
during call or conversation or when:

- Receiving an incoming call change selected account to be the same
as call destination account
- Making a call disable account selection
- Changing the selected account close current conversation

Tuleap: #1532
Change-Id: Ia37fabce0285a02233b35e69e73244e14d0a334a
Reviewed-by: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
diff --git a/src/AppDelegate.mm b/src/AppDelegate.mm
index ac8b630..c75002e 100644
--- a/src/AppDelegate.mm
+++ b/src/AppDelegate.mm
@@ -28,6 +28,8 @@
 #import <media/textrecording.h>
 #import <QItemSelectionModel>
 #import <account.h>
+#import <AvailableAccountModel.h>
+
 
 #if ENABLE_SPARKLE
 #import <Sparkle/Sparkle.h>
@@ -120,6 +122,14 @@
     QObject::connect(&CallModel::instance(),
                      &CallModel::incomingCall,
                      [=](Call* call) {
+                         // on incoming call set selected account match call destination account
+                         if (call->account()) {
+                             QModelIndex index = call->account()->index();
+                             index = AvailableAccountModel::instance().mapFromSource(index);
+
+                             AvailableAccountModel::instance().selectionModel()->setCurrentIndex(index,
+                                                                                                 QItemSelectionModel::ClearAndSelect);
+                         }
                          BOOL shouldComeToForeground = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::WindowBehaviour];
                          BOOL shouldNotify = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::Notifications];
                          if (shouldComeToForeground) {