fix : AvailableAccountModel uses

- We are now using AvailableAccountModel in combobox_account_selector.

- this patch fix several bugs :
  * display the right information on ringwelcomeview.
  * get_active_ring_account() returns the right selected account.
  * bind the selection from combobox_account_selector to
    AvailableAccountModel.
  * use currentChanged signal from selectionModel() to refresh
    treeview_conversations.
  * select the good account in AvailableAccountModel during an
    incoming call.
  * fix client crash on incoming call

Change-Id: Id2660dafdfbf2c2b54a84641449f064d7597ce8c
Tuleap: #1579
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
index c529f98..26670de 100644
--- a/src/ringmainwindow.cpp
+++ b/src/ringmainwindow.cpp
@@ -1109,10 +1109,8 @@
 {
     int nbr = gtk_combo_box_get_active(gtk_combo_box);
 
-    QModelIndex idx = AccountModel::instance().userSelectionModel()->model()->index(nbr, 0);
-    auto account = AccountModel::instance().getAccountByModelIndex(idx);
-
-    AccountModel::instance().setUserChosenAccount(account);
+    const auto idx = AvailableAccountModel::instance().selectionModel()->model()->index(nbr, 0);
+    AvailableAccountModel::instance().selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
 
     // we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
     hide_view_clicked(nullptr, self);
@@ -1256,7 +1254,7 @@
     gtk_container_add(GTK_CONTAINER(priv->scrolled_window_history), priv->treeview_history);
 
     /* use this event to refresh the treeview_conversations when account selection changed */
-    QObject::connect(AccountModel::instance().userSelectionModel(), &QItemSelectionModel::currentChanged, [priv](const QModelIndex& idx){
+    QObject::connect(AvailableAccountModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [priv](const QModelIndex& idx){
         // next line will refresh the recentmodel so the treeview will do
         RecentModel::instance().peopleProxy()->setFilterRegExp("");
 
@@ -1307,7 +1305,11 @@
         &CallModel::incomingCall,
         [priv](Call* call) {
             // select the revelant account
-            AccountModel::instance().setUserChosenAccount(call->account());
+            if (call->account()) {
+                auto row = call->account()->index().row();
+                gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), row);
+            }
+
 
             // clear the regex to make sure the call is shown
             RecentModel::instance().peopleProxy()->setFilterRegExp(QRegExp());