Commit 2d99df02 authored by Anthony Léonard's avatar Anthony Léonard

use new lrc system for account selection + ui fixes

Recent changes in LRC introduced a selection system to choose a
current active account in AccountModel. It was decided to prefer the
selectionModel of the AvailableAccountModel as it filters out accounts
not enabled.

Moreover, the selected account is now the one used when looking for a
new contact. The default scheme used depends on the account type and
the account linked to the contact method is now the selected one.

Finally, the CurrentAccountWidget now better reflects changes of
profile's picture and selected account when this one is changed by an
external event (like a call on an enabled, but not selected, account).

Change-Id: I5ad50a6f6b9d28e03ab031ffecfb0018965475f9
parent 2fde81db
......@@ -150,14 +150,18 @@ CallWidget::CallWidget(QWidget* parent) :
slidePage(ui->welcomePage);
});
connect(AccountModel::instance().userSelectionModel(), &QItemSelectionModel::currentChanged,
connect(AvailableAccountModel::instance().selectionModel(), &QItemSelectionModel::currentChanged,
this, &CallWidget::selectedAccountChanged);
ui->contactReqList->setItemDelegate(new ContactRequestItemDelegate());
// It needs to be called manually once to initialize the ui with the account selected at start.
// The second argument (previous) is set to an invalid QModelIndex as it is the first selection.
selectedAccountChanged(AccountModel::instance().userSelectionModel()->currentIndex(), QModelIndex());
selectedAccountChanged(AvailableAccountModel::instance().selectionModel()->currentIndex(), QModelIndex());
// This connect() is used to initialise and track changes of profile's picture
connect(&ProfileModel::instance(), &ProfileModel::dataChanged,
ui->currentAccountWidget, &CurrentAccountWidget::setPhoto);
} catch (const std::exception& e) {
qDebug() << "INIT ERROR" << e.what();
......@@ -622,8 +626,8 @@ CallWidget::uriNeedNameLookup(const URI uri_passed)
uri_passed.protocolHint() != URI::ProtocolHint::RING && // not a RingID
uri_passed.schemeType() == URI::SchemeType::NONE // scheme type not specified
){
// if no scheme type has been specified, determine ring vs sip by the first available account
auto idx = AvailableAccountModel::instance().index(0, 0);
// if no scheme type has been specified, determine ring vs sip by the current selected account
auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex();
if (idx.isValid()) {
auto account = idx.data((int)Ring::Role::Object).value<Account *>();
if (account && account->protocol() == Account::Protocol::RING)
......@@ -639,10 +643,12 @@ CallWidget::processContactLineEdit()
{
auto contactLineText = ui->ringContactLineEdit->text();
URI uri_passed = URI(contactLineText);
Account* ac = AvailableAccountModel::instance().selectionModel()->currentIndex()
.data(static_cast<int>(Ring::Role::Object)).value<Account*>();
if (!contactLineText.isNull() && !contactLineText.isEmpty()){
if (uriNeedNameLookup(uri_passed)){
NameDirectory::instance().lookupName(nullptr, QString(), uri_passed);
NameDirectory::instance().lookupName(ac, QString(), uri_passed);
} else {
searchContactLineEditEntry(uri_passed);
}
......@@ -676,7 +682,7 @@ CallWidget::selectedAccountChanged(const QModelIndex &current, const QModelIndex
Q_UNUSED(previous)
if (current.isValid()) {
auto ac = AccountModel::instance().getAccountByModelIndex(current);
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) {
......@@ -702,6 +708,10 @@ CallWidget::selectedAccountChanged(const QModelIndex &current, const QModelIndex
ui->contactReqList->setModel(ac->pendingContactRequestModel());
crListSelectionConnection_ = connect(ui->contactReqList->selectionModel(), &QItemSelectionModel::currentChanged,
this, &CallWidget::contactReqListCurrentChanged);
// We modify the currentAccountWidget to reflect the new selected account
// if the event wasn't triggered by this widget
ui->currentAccountWidget->changeSelectedIndex(current.row());
}
}
......
......@@ -20,7 +20,7 @@
#include "currentaccountwidget.h"
#include "ui_currentaccountwidget.h"
#include "globalinstances.h"
#include "accountmodel.h"
#include "availableaccountmodel.h"
#include "account.h"
#include "qstandarditemmodel.h"
#include "profilemodel.h"
......@@ -47,10 +47,10 @@ CurrentAccountWidget::setup()
{
ui->accountsStatus->setText("No enabled account: impossible to communicate!");
ui->accountsStatus->hide();
ui->currentAccountSelector->setModel(&AvailableAccountModel::instance());
updateAccounts();
if (ui->currentAccountSelector->count() > 0) {
ui->currentAccountSelector->setCurrentIndex(0);
emit ui->currentAccountSelector->currentIndexChanged(0);
qDebug() << "CurrentAccount : setup over";
} else {
qDebug() << "CurrentAccount : No account available";
......@@ -68,19 +68,6 @@ void
CurrentAccountWidget::updateAccounts()
{
auto selector = ui->currentAccountSelector;
AccountModel* model = &(AccountModel::instance());
QModelIndex qIndex;
selector->clear();
for (int idx = 0; idx <= model->rowCount() - 1; idx++){
qIndex = model->index(idx);
if (! model->getAccountByModelIndex(qIndex)->isEnabled()) {
qDebug() << model->getAccountByModelIndex(qIndex)->alias() << " Account is not enabled";
} else {
selector->addItem(model->getAccountByModelIndex(qIndex)->alias());
}
}
if (selector->count() <= 1){
selector->hide();
......@@ -103,22 +90,16 @@ CurrentAccountWidget::setPhoto()
{
auto selector = ui->currentAccountSelector;
if (selector->count() > 0) {
if(&ProfileModel::instance()){
if (ProfileModel::instance().selectedProfile()) {
if (ProfileModel::instance().selectedProfile()->person()){
QImage img = Utils::getCirclePhoto(ProfileModel::instance().selectedProfile()->person()->photo().value<QImage>(),
ui->idDisplayLayout->contentsRect().height());
ui->currentAccountPixmap->setPixmap(QPixmap::fromImage(img));
qDebug() << "CurrentAccount : Photo set";
} else {
qDebug() << "CurrentAccount : selected profile has no person";
}
} else {
qDebug() << "CurrentAccount : Profilemodel: no selected profile";
}
} else {
qDebug() << "CurrentAccount : Profilemodel not set";
}
if (ProfileModel::instance().selectedProfile()) {
if (ProfileModel::instance().selectedProfile()->person()){
QImage img = Utils::getCirclePhoto(ProfileModel::instance().selectedProfile()->person()->photo().value<QImage>(),
ui->idDisplayLayout->contentsRect().height());
ui->currentAccountPixmap->setPixmap(QPixmap::fromImage(img));
qDebug() << "CurrentAccount : Photo set";
} else
qDebug() << "CurrentAccount : selected profile has no person";
} else
qDebug() << "CurrentAccount : Profilemodel: no selected profile";
} else {
qDebug() << "CurrentAccount : account not set";
ui->currentAccountPixmap->setPixmap(QPixmap());
......@@ -132,7 +113,7 @@ CurrentAccountWidget::on_currentAccountSelector_currentIndexChanged(int index)
Account* ac = AccountModel::instance().getAccountByModelIndex(idx);
if (ac) {
AccountModel::instance().setUserChosenAccount(ac);
AvailableAccountModel::instance().selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
setPhoto();
} else {
qDebug() << "CurrentAccount : account not referenced correctly";
......@@ -140,3 +121,11 @@ CurrentAccountWidget::on_currentAccountSelector_currentIndexChanged(int index)
}
}
void
CurrentAccountWidget::changeSelectedIndex(int index)
{
if (index != ui->currentAccountSelector->currentIndex()) {
ui->currentAccountSelector->setCurrentIndex(index);
}
}
......@@ -33,9 +33,11 @@ class CurrentAccountWidget : public QWidget
public:
explicit CurrentAccountWidget(QWidget *parent = 0);
~CurrentAccountWidget();
void changeSelectedIndex(int index);
public slots:
void update();
void setPhoto();
private slots:
void on_currentAccountSelector_currentIndexChanged(int index);
......@@ -43,7 +45,6 @@ private slots:
private:
Ui::CurrentAccountWidget *ui;
void setup();
void setPhoto();
void updateAccounts();
};
......
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