Commit f71f8d84 authored by Nicolas Jager's avatar Nicolas Jager Committed by Guillaume Roguez

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's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent a06e443e
......@@ -1109,10 +1109,8 @@ selected_account_changed(GtkComboBox *gtk_combo_box, RingMainWindow *self)
{
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 @@ ring_main_window_init(RingMainWindow *win)
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 @@ ring_main_window_init(RingMainWindow *win)
&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());
......
......@@ -30,6 +30,9 @@
#include <QObject>
#include <QItemSelectionModel>
// LRC
#include <availableaccountmodel.h>
struct _RingWelcomeView
{
GtkScrolledWindow parent;
......@@ -197,17 +200,12 @@ ring_welcome_view_init(RingWelcomeView *self)
gtk_box_pack_start(GTK_BOX(box_main), priv->button_qrcode, TRUE, TRUE, 0);
priv->account_model_data_changed = QObject::connect(
&AccountModel::instance(),
&AccountModel::dataChanged,
[self] (const QModelIndex&, const QModelIndex&) { update_view(self); }
);
/* connect to the next signal to update in terms of the account selected */
QObject::connect(AccountModel::instance().userSelectionModel(), &QItemSelectionModel::currentChanged,
[self](const QModelIndex& idx){
Q_UNUSED(idx)
update_view(self);
});
&AvailableAccountModel::instance(),
&AvailableAccountModel::currentDefaultAccountChanged,
[self] (Account* a)
{
update_view(self);
});
gtk_widget_show_all(GTK_WIDGET(self));
}
......
......@@ -20,6 +20,7 @@
#include "accounts.h"
#include <accountmodel.h>
#include <availableaccountmodel.h>
// LRC
#include <QItemSelectionModel>
......@@ -58,6 +59,8 @@ force_ring_display_name()
Account*
get_active_ring_account()
{
auto account = AccountModel::instance().userChosenAccount();
const auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex();
auto account = idx.data(static_cast<int>(Account::Role::Object)).value<Account*>();
return (account && account->protocol() == Account::Protocol::RING) ? account : nullptr;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment