From 266dd30e57ac1212110c0c72e67d6eeecb0925b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anthony=20L=C3=A9onard?= <anthony.leonard@savoirfairelinux.com> Date: Fri, 31 Mar 2017 14:38:32 -0400 Subject: [PATCH] display the selected account's RingID/username This patch improves the way the client react to a modification of the selected account. From a UI point of view, the displayed Ring ID now depends on the selected account in the combo box. Previously, it was always set to the first enabled Ring account found in AccountModel. The old behavior is removed from findRingAccount() which now only focus on looking if an account needs migration or if it is needed to create one (at first launch). Change-Id: If63a74eb320b8fc31064d87b04b5e062fc0cc10a Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com> --- callwidget.cpp | 53 ++++++++++++-------------------------------------- callwidget.h | 1 - 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/callwidget.cpp b/callwidget.cpp index 382f8f2..cb10747 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -98,11 +98,6 @@ CallWidget::CallWidget(QWidget* parent) : connect(callModel_, SIGNAL(callStateChanged(Call*, Call::State)), this, SLOT(callStateChanged(Call*, Call::State))); - connect(&AccountModel::instance() - , SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)) - , this - , SLOT(findRingAccount(QModelIndex, QModelIndex, QVector<int>))); - RecentModel::instance().peopleProxy()->setFilterRole(static_cast<int>(Ring::Role::Name)); RecentModel::instance().peopleProxy()->setFilterCaseSensitivity(Qt::CaseInsensitive); ui->smartList->setModel(RecentModel::instance().peopleProxy()); @@ -291,33 +286,6 @@ CallWidget::setupSmartListMenu() }); } -void -CallWidget::findRingAccount(QModelIndex idx1, QModelIndex idx2, QVector<int> vec) -{ - Q_UNUSED(idx1) - Q_UNUSED(idx2) - Q_UNUSED(vec) - - auto a_count = AccountModel::instance().rowCount(); - for (int i = 0; i < a_count; ++i) { - auto idx = AccountModel::instance().index(i, 0); - auto protocol = idx.data(static_cast<int>(Account::Role::Proto)); - if (static_cast<Account::Protocol>(protocol.toUInt()) == Account::Protocol::RING) { - auto account = AccountModel::instance().getAccountByModelIndex(idx); - auto registeredName = account->registeredName(); - auto username = idx.data(static_cast<int>(Account::Role::Username)); - if (registeredName.isEmpty()) { - ui->ringIdLabel->setText(username.toString()); - } else - ui->ringIdLabel->setText(registeredName); - setupQRCode(username.toString()); - - return; - } - } - ui->ringIdLabel->setText(tr("NO RING ACCOUNT FOUND")); -} - void CallWidget::setupQRCode(QString ringID) { auto rcode = QRcode_encodeString(ringID.toStdString().c_str(), @@ -358,13 +326,14 @@ void CallWidget::setupQRCode(QString ringID) void CallWidget::findRingAccount() { - ui->ringIdLabel->clear(); + bool ringAccountFound = false; auto a_count = AccountModel::instance().rowCount(); for (int i = 0; i < a_count; ++i) { auto idx = AccountModel::instance().index(i, 0); auto protocol = idx.data(static_cast<int>(Account::Role::Proto)); if (static_cast<Account::Protocol>(protocol.toUInt()) == Account::Protocol::RING) { + ringAccountFound = true; auto account = AccountModel::instance().getAccountByModelIndex(idx); if (account->displayName().isEmpty()) account->displayName() = account->alias(); @@ -372,16 +341,9 @@ CallWidget::findRingAccount() WizardDialog dlg(WizardDialog::MIGRATION, account); dlg.exec(); } - if (ui->ringIdLabel->text().isEmpty()) { - auto registeredName = account->registeredName(); - ui->ringIdLabel->setText((registeredName.isEmpty())?account->username():registeredName); - setupQRCode(account->username()); - } } } - - if (ui->ringIdLabel->text().isEmpty()) { - ui->ringIdLabel->setText(tr("NO RING ACCOUNT FOUND")); + if (!ringAccountFound) { WizardDialog wizardDialog; wizardDialog.exec(); } @@ -718,6 +680,15 @@ CallWidget::selectedAccountChanged(const QModelIndex ¤t, const QModelIndex slidePage(ui->welcomePage); } + // We setup the ringIdLabel and the QRCode + auto protocol = ac->protocol(); + if (protocol == Account::Protocol::RING) { + ui->ringIdLabel->setText((ac->registeredName().isEmpty())?ac->username():ac->registeredName()); + setupQRCode(ac->username()); + } else { + ui->ringIdLabel->setText(tr("NO RING ACCOUNT FOUND")); + } + // Then, we update the pending CR list with those from the newly selected account if (disconnect(crListSelectionConnection_)) { // The selection model must be deleted by the application (see QT doc). diff --git a/callwidget.h b/callwidget.h index 59bc496..374ad56 100644 --- a/callwidget.h +++ b/callwidget.h @@ -87,7 +87,6 @@ private slots: private slots: void callIncoming(Call* call); void callStateChanged(Call* call, Call::State previousState); - void findRingAccount(QModelIndex idx1, QModelIndex idx2, QVector<int> vec); void smartListCurrentChanged(const QModelIndex ¤tIdx, const QModelIndex &previousIdx); void contactReqListCurrentChanged(const QModelIndex ¤tIdx, const QModelIndex &previousIdx); void slotAccountMessageReceived(const QMap<QString,QString> message,ContactMethod* cm,Media::Media::Direction dir); -- GitLab