diff --git a/src/accountadapter.cpp b/src/accountadapter.cpp index b031e567b95845cfb5bf4fc55288335949eeea48..7d9bc12c2b7c3b391dfc13c50c80d92dd6376e13 100644 --- a/src/accountadapter.cpp +++ b/src/accountadapter.cpp @@ -1,11 +1,8 @@ /* - * Copyright (C) 2020 by Savoir-faire Linux - * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com> - * Author: Anthony L�onard <anthony.leonard@savoirfairelinux.com - * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> + * Copyright (C) 2020-2021 by Savoir-faire Linux + * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> + * Author: Yang Wang <yang.yang@savoirfairelinux.com> * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> - * Author: Isa Nanic <isa.nanic@savoirfairelinux.com> - * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,28 +34,31 @@ AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager, , accSrcModel_(new AccountListModel(instance)) , accModel_(new CurrentAccountFilterModel(instance, accSrcModel_.get())) { - QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, accModel_.get(), "CurrentAccountFilterModel"); QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, accSrcModel_.get(), "AccountListModel"); + QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, accModel_.get(), "CurrentAccountFilterModel"); } void AccountAdapter::safeInit() { - connect(lrcInstance_, - &LRCInstance::currentAccountIdChanged, + connect(&lrcInstance_->accountModel(), + &NewAccountModel::accountStatusChanged, this, - &AccountAdapter::onCurrentAccountChanged); + &AccountAdapter::accountStatusChanged); - connectAccount(lrcInstance_->getCurrentAccountId()); + connect(&lrcInstance_->accountModel(), + &NewAccountModel::profileUpdated, + this, + &AccountAdapter::accountStatusChanged); } -lrc::api::NewAccountModel* +NewAccountModel* AccountAdapter::getModel() { return &(lrcInstance_->accountModel()); } -lrc::api::NewDeviceModel* +NewDeviceModel* AccountAdapter::getDeviceModel() { return lrcInstance_->getCurrentAccountInfo().deviceModel.get(); @@ -69,7 +69,7 @@ AccountAdapter::changeAccount(int row) { auto accountList = lrcInstance_->accountModel().getAccountList(); if (accountList.size() > row) { - lrcInstance_->setCurrentAccountId(accountList.at(row)); + lrcInstance_->set_currentAccountId(accountList.at(row)); } } @@ -82,6 +82,7 @@ AccountAdapter::connectFailure() Q_UNUSED(accountId); Q_EMIT reportFailure(); }); + Utils::oneShotConnect(&lrcInstance_->accountModel(), &lrc::api::NewAccountModel::invalidAccountDetected, [this](const QString& accountId) { @@ -226,7 +227,7 @@ AccountAdapter::createJAMSAccount(const QVariantMap& settings) void AccountAdapter::deleteCurrentAccount() { - lrcInstance_->accountModel().removeAccount(lrcInstance_->getCurrentAccountId()); + lrcInstance_->accountModel().removeAccount(lrcInstance_->get_currentAccountId()); Q_EMIT lrcInstance_->accountListChanged(); } @@ -270,12 +271,6 @@ AccountAdapter::setCurrAccDisplayName(const QString& text) lrcInstance_->setCurrAccDisplayName(text); } -lrc::api::profile::Type -AccountAdapter::getCurrentAccountType() -{ - return lrcInstance_->getCurrentAccountInfo().profileInfo.type; -} - void AccountAdapter::setCurrAccAvatar(bool fromFile, const QString& source) { @@ -292,17 +287,11 @@ AccountAdapter::setCurrAccAvatar(bool fromFile, const QString& source) }); } -void -AccountAdapter::onCurrentAccountChanged() -{ - connectAccount(lrcInstance_->getCurrentAccountId()); -} - bool AccountAdapter::hasPassword() { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); return confProps.archiveHasPassword; } @@ -310,9 +299,9 @@ void AccountAdapter::setArchiveHasPassword(bool isHavePassword) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.archiveHasPassword = isHavePassword; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } bool AccountAdapter::exportToFile(const QString& accountId, @@ -341,50 +330,3 @@ AccountAdapter::passwordSetStatusMessageBox(bool success, QString title, QString QMessageBox::critical(0, title, infoToDisplay); } } - -void -AccountAdapter::connectAccount(const QString& accountId) -{ - try { - auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId); - - QObject::disconnect(accountStatusChangedConnection_); - QObject::disconnect(accountProfileUpdatedConnection_); - QObject::disconnect(addedToConferenceConnection_); - QObject::disconnect(bannedStatusChangedConnection_); - - accountStatusChangedConnection_ - = QObject::connect(accInfo.accountModel, - &lrc::api::NewAccountModel::accountStatusChanged, - [this](const QString& accountId) { - Q_EMIT accountStatusChanged(accountId); - }); - - accountProfileUpdatedConnection_ - = QObject::connect(accInfo.accountModel, - &lrc::api::NewAccountModel::profileUpdated, - [this](const QString& accountId) { - Q_EMIT accountStatusChanged(accountId); - }); - - addedToConferenceConnection_ - = QObject::connect(accInfo.callModel.get(), - &NewCallModel::callAddedToConference, - [this](const QString& callId, const QString& confId) { - Q_UNUSED(callId); - lrcInstance_->renderer()->addDistantRenderer(confId); - }); - - bannedStatusChangedConnection_ - = QObject::connect(accInfo.contactModel.get(), - &lrc::api::ContactModel::bannedStatusChanged, - [this](const QString& uri, bool banned) { - if (!banned) - Q_EMIT contactUnbanned(); - else - Q_EMIT lrcInstance_->contactBanned(uri); - }); - } catch (...) { - qWarning() << "Couldn't get account: " << accountId; - } -} diff --git a/src/accountadapter.h b/src/accountadapter.h index bd3ee9f905049da1290aafb4e6a5f36396769bf1..96f2dab5b6b0586f130164ea9d42235c409ec032 100644 --- a/src/accountadapter.h +++ b/src/accountadapter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 by Savoir-faire Linux + * Copyright (C) 2021 by Savoir-faire Linux * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify @@ -20,14 +20,13 @@ #include "qmladapterbase.h" -#include <QObject> -#include <QSettings> -#include <QString> - #include "accountlistmodel.h" #include "lrcinstance.h" #include "utils.h" +#include <QSettings> +#include <QString> + class AppSettingsManager; class AccountAdapter final : public QmlAdapterBase @@ -51,10 +50,8 @@ public: QObject* parent = nullptr); ~AccountAdapter() = default; -protected: void safeInit() override; -public: // Change to account corresponding to combox box index. Q_INVOKABLE void changeAccount(int row); @@ -89,8 +86,6 @@ public: Q_INVOKABLE bool hasVideoCall(); Q_INVOKABLE bool isPreviewing(); Q_INVOKABLE void setCurrAccDisplayName(const QString& text); - Q_INVOKABLE lrc::api::profile::Type getCurrentAccountType(); - Q_INVOKABLE void setCurrAccAvatar(bool fromFile, const QString& source); Q_SIGNALS: @@ -100,22 +95,11 @@ Q_SIGNALS: // Send report failure to QML to make it show the right UI state . void reportFailure(); void accountAdded(QString accountId, bool showBackUp, int index); - void contactUnbanned(); - -private Q_SLOTS: - void onCurrentAccountChanged(); private: - // Make account signal connections. - void connectAccount(const QString& accountId); - // Implement what to do when account creation fails. void connectFailure(); - QMetaObject::Connection accountStatusChangedConnection_; - QMetaObject::Connection accountProfileUpdatedConnection_; - QMetaObject::Connection addedToConferenceConnection_; - QMetaObject::Connection bannedStatusChangedConnection_; QMetaObject::Connection registeredNameSavedConnection_; AppSettingsManager* settingsManager_; diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index 4c253e71b339496381e531b3ed8d91e646458e3a..33d16bcbf8cb646e7e978d03221afadc9447edd3 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -19,8 +19,6 @@ #include "accountlistmodel.h" -#include <QDateTime> - #include "lrcinstance.h" #include "utils.h" @@ -28,39 +26,23 @@ #include "api/contact.h" #include "api/conversation.h" +#include <QDateTime> + AccountListModel::AccountListModel(LRCInstance* instance, QObject* parent) : AbstractListModelBase(parent) { lrcInstance_ = instance; } -AccountListModel::~AccountListModel() {} - int AccountListModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid() && lrcInstance_) { - /* - * Count. - */ return lrcInstance_->accountModel().getAccountList().size(); } - /* - * A valid QModelIndex returns 0 as no entry has sub-elements. - */ return 0; } -int -AccountListModel::columnCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent); - /* - * Only need one column. - */ - return 1; -} - QVariant AccountListModel::data(const QModelIndex& index, int role) const { diff --git a/src/accountlistmodel.h b/src/accountlistmodel.h index a7733ab2c09864978b94f1d0d74da712401d0fbd..841b92248fd0bfdc1710d2eb93be58690855a7dd 100644 --- a/src/accountlistmodel.h +++ b/src/accountlistmodel.h @@ -63,32 +63,23 @@ public: { // Accept all contacts in conversation list filtered with account type, except those in a call. auto index = sourceModel()->index(sourceRow, 0, sourceParent); - auto accountID = sourceModel()->data(index, AccountList::ID); - return accountID != lrcInstance_->getCurrentAccountId(); + auto accountId = sourceModel()->data(index, AccountList::ID); + return accountId != lrcInstance_->get_currentAccountId(); } protected: LRCInstance* lrcInstance_ {nullptr}; }; -class AccountListModel : public AbstractListModelBase +class AccountListModel final : public AbstractListModelBase { Q_OBJECT public: explicit AccountListModel(LRCInstance* instance, QObject* parent = nullptr); - ~AccountListModel(); - /* - * QAbstractListModel override. - */ int rowCount(const QModelIndex& parent = QModelIndex()) const override; - int columnCount(const QModelIndex& parent) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - - /* - * Override role name as access point in qml. - */ QHash<int, QByteArray> roleNames() const override; /* diff --git a/src/calladapter.cpp b/src/calladapter.cpp index 036e06c36b5ac280787824bfcfbc33e4921f7c10..b4f9a6625c3d62a87bc2ef01566e5ce4c0d6bb9f 100644 --- a/src/calladapter.cpp +++ b/src/calladapter.cpp @@ -39,7 +39,7 @@ CallAdapter::CallAdapter(SystemTray* systemTray, LRCInstance* instance, QObject* overlayModel_.reset(new CallOverlayModel(lrcInstance_, this)); QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, overlayModel_.get(), "CallOverlayModel"); - accountId_ = lrcInstance_->getCurrentAccountId(); + accountId_ = lrcInstance_->get_currentAccountId(); if (!accountId_.isEmpty()) connectCallModel(accountId_); @@ -90,7 +90,7 @@ CallAdapter::CallAdapter(SystemTray* systemTray, LRCInstance* instance, QObject* void CallAdapter::onAccountChanged() { - accountId_ = lrcInstance_->getCurrentAccountId(); + accountId_ = lrcInstance_->get_currentAccountId(); connectCallModel(accountId_); } @@ -284,7 +284,7 @@ void CallAdapter::onCallAddedToConference(const QString& callId, const QString& confId) { Q_UNUSED(callId) - Q_UNUSED(confId) + lrcInstance_->renderer()->addDistantRenderer(confId); saveConferenceSubcalls(); } @@ -362,7 +362,7 @@ CallAdapter::onShowIncomingCallView(const QString& accountId, const QString& con // this will update various UI elements that portray the call state Q_EMIT callStatusChanged(static_cast<int>(call.status), accountId, convInfo.uid); - auto callBelongsToSelectedAccount = accountId == lrcInstance_->getCurrentAccountId(); + auto callBelongsToSelectedAccount = accountId == lrcInstance_->get_currentAccountId(); auto accountProperties = lrcInstance_->accountModel().getAccountConfig(accountId); // do nothing but update the status UI for incoming calls on RendezVous accounts diff --git a/src/contactadapter.cpp b/src/contactadapter.cpp index 2a7169c6d039517102e38bf58a67caf1ea1f33ad..621cd21d8c8cbd43ce0f1e6e7e3871f55bd0cf8b 100644 --- a/src/contactadapter.cpp +++ b/src/contactadapter.cpp @@ -28,6 +28,18 @@ ContactAdapter::ContactAdapter(LRCInstance* instance, QObject* parent) selectableProxyModel_.reset(new SelectableProxyModel(this)); } +void +ContactAdapter::safeInit() +{ + connect(lrcInstance_, &LRCInstance::currentAccountIdChanged, [this] { + connect(lrcInstance_->getCurrentContactModel(), + &ContactModel::bannedStatusChanged, + this, + &ContactAdapter::bannedStatusChanged, + Qt::UniqueConnection); + }); +} + QVariant ContactAdapter::getContactSelectableModel(int type) { @@ -36,7 +48,7 @@ ContactAdapter::getContactSelectableModel(int type) if (listModeltype_ == SmartListModel::Type::CONVERSATION) { defaultModerators_ = lrcInstance_->accountModel().getDefaultModerators( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); } smartListModel_.reset(new SmartListModel(this, listModeltype_, lrcInstance_)); @@ -63,7 +75,7 @@ ContactAdapter::getContactSelectableModel(int type) lrcInstance_->get_selectedConvUid()); if (!conv.participants.isEmpty()) { QString calleeDisplayId = lrcInstance_ - ->getAccountInfo(lrcInstance_->getCurrentAccountId()) + ->getAccountInfo(lrcInstance_->get_currentAccountId()) .contactModel->bestIdForContact(conv.participants[0]); QRegExp matchExcept = QRegExp(QString("\\b(?!" + calleeDisplayId + "\\b)\\w+")); @@ -171,7 +183,7 @@ ContactAdapter::contactSelected(int index) return; } - lrcInstance_->accountModel().setDefaultModerator(lrcInstance_->getCurrentAccountId(), + lrcInstance_->accountModel().setDefaultModerator(lrcInstance_->get_currentAccountId(), contactUri, true); Q_EMIT defaultModeratorsUpdated(); diff --git a/src/contactadapter.h b/src/contactadapter.h index 6713bac542e298b4f82304851c6d0096f90b88b9..fa3e645d2a4dc8e75a08bb81bb27e8b6aac5f089 100644 --- a/src/contactadapter.h +++ b/src/contactadapter.h @@ -84,15 +84,17 @@ public: explicit ContactAdapter(LRCInstance* instance, QObject* parent = nullptr); ~ContactAdapter() = default; -protected: using Role = ConversationList::Role; - void safeInit() override {}; + void safeInit() override; Q_INVOKABLE QVariant getContactSelectableModel(int type); Q_INVOKABLE void setSearchFilter(const QString& filter); Q_INVOKABLE void contactSelected(int index); +Q_SIGNALS: + void bannedStatusChanged(const QString& uri, bool banned); + private: SmartListModel::Type listModeltype_; QScopedPointer<SmartListModel> smartListModel_; diff --git a/src/conversationlistmodel.h b/src/conversationlistmodel.h index 27027914de7d9604c605c151f0672458f61eb331..d7a1f4b3110487ded68ee070e22c396d80f26b70 100644 --- a/src/conversationlistmodel.h +++ b/src/conversationlistmodel.h @@ -35,7 +35,7 @@ public: explicit ConversationListModel(LRCInstance* instance, QObject* parent = nullptr); int rowCount(const QModelIndex& parent = QModelIndex()) const override; - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; }; // The top level filtered and sorted model to be consumed by QML ListViews diff --git a/src/conversationsadapter.cpp b/src/conversationsadapter.cpp index be4415ad799d12c08aa4ef5d811079bd5fd6ca22..836e0daa660502e829757ef6857feb7ca1084354 100644 --- a/src/conversationsadapter.cpp +++ b/src/conversationsadapter.cpp @@ -82,16 +82,6 @@ ConversationsAdapter::ConversationsAdapter(SystemTray* systemTray, Q_EMIT convSrcModel_->dataChanged(index, index); }); - connect(lrcInstance_, &LRCInstance::contactBanned, [this](const QString& uri) { - auto& convInfo = lrcInstance_->getConversationFromPeerUri(uri); - if (convInfo.uid.isEmpty()) - return; - auto row = lrcInstance_->indexOf(convInfo.uid); - const auto index = convSrcModel_->index(row, 0); - Q_EMIT convSrcModel_->dataChanged(index, index); - lrcInstance_->set_selectedConvUid(); - }); - #ifdef Q_OS_LINUX // notification responses connect(systemTray_, @@ -174,7 +164,7 @@ ConversationsAdapter::onNewUnreadInteraction(const QString& accountId, const interaction::Info& interaction) { if (!interaction.authorUri.isEmpty() - && (!QApplication::focusWindow() || accountId != lrcInstance_->getCurrentAccountId() + && (!QApplication::focusWindow() || accountId != lrcInstance_->get_currentAccountId() || convUid != lrcInstance_->get_selectedConvUid())) { auto& accountInfo = lrcInstance_->getAccountInfo(accountId); auto from = accountInfo.contactModel->bestNameForContact(interaction.authorUri); @@ -224,7 +214,7 @@ void ConversationsAdapter::onNewTrustRequest(const QString& accountId, const QString& convId, const QString& peerUri) { #ifdef Q_OS_LINUX - if (!QApplication::focusWindow() || accountId != lrcInstance_->getCurrentAccountId()) { + if (!QApplication::focusWindow() || accountId != lrcInstance_->get_currentAccountId()) { auto conv = convId; if (conv.isEmpty()) { auto& convInfo = lrcInstance_->getConversationFromPeerUri(peerUri); @@ -327,6 +317,19 @@ ConversationsAdapter::updateConversation(const QString& convId) lrcInstance_->selectConversation(convId); } +void +ConversationsAdapter::onBannedStatusChanged(const QString& uri, bool banned) +{ + Q_UNUSED(banned) + auto& convInfo = lrcInstance_->getConversationFromPeerUri(uri); + if (convInfo.uid.isEmpty()) + return; + auto row = lrcInstance_->indexOf(convInfo.uid); + const auto index = convSrcModel_->index(row, 0); + Q_EMIT convSrcModel_->dataChanged(index, index); + lrcInstance_->set_selectedConvUid(); +} + void ConversationsAdapter::updateConversationFilterData() { @@ -461,6 +464,12 @@ ConversationsAdapter::connectConversationModel() &ConversationsAdapter::updateConversation, Qt::UniqueConnection); + QObject::connect(lrcInstance_->getCurrentContactModel(), + &ContactModel::bannedStatusChanged, + this, + &ConversationsAdapter::onBannedStatusChanged, + Qt::UniqueConnection); + convSrcModel_.reset(new ConversationListModel(lrcInstance_)); convModel_->bindSourceModel(convSrcModel_.get()); searchSrcModel_.reset(new SearchResultsListModel(lrcInstance_)); diff --git a/src/conversationsadapter.h b/src/conversationsadapter.h index 00ea26e4d46ecacf71071607acaa08b8daac78fe..57ed6b83aae1c055fce8098881092ea0dffd0aaa 100644 --- a/src/conversationsadapter.h +++ b/src/conversationsadapter.h @@ -82,6 +82,7 @@ private Q_SLOTS: void onSearchStatusChanged(const QString&); void onSearchResultUpdated(); void updateConversation(const QString&); + void onBannedStatusChanged(const QString&, bool); void updateConversationFilterData(); diff --git a/src/lrcinstance.cpp b/src/lrcinstance.cpp index 3b07d3308bd71a133db970f62605aee7c96b2f4d..5d2adb183ae6f2f05e3f106e6e805b13e9c6b1d4 100644 --- a/src/lrcinstance.cpp +++ b/src/lrcinstance.cpp @@ -38,6 +38,21 @@ LRCInstance::LRCInstance(migrateCallback willMigrateCb, , updateManager_(std::make_unique<UpdateManager>(updateUrl, connectivityMonitor, this)) { lrc_->holdConferences = false; + + connect(this, &LRCInstance::currentAccountIdChanged, [this] { + // save to config, editing the accountlistmodel's underlying data + accountModel().setTopAccount(currentAccountId_); + Q_EMIT accountListChanged(); + + // update type + set_currentAccountType(getCurrentAccountInfo().profileInfo.type); + }); + + // set the current account if any + auto accountList = accountModel().getAccountList(); + if (accountList.size()) { + set_currentAccountId(accountList.at(0)); + } }; VectorString @@ -109,20 +124,7 @@ LRCInstance::getAccountInfo(const QString& accountId) const account::Info& LRCInstance::getCurrentAccountInfo() { - return getAccountInfo(getCurrentAccountId()); -} - -profile::Type -LRCInstance::getCurrentAccountType() -{ - if (currentAccountType_ == profile::Type::INVALID) { - try { - currentAccountType_ = getCurrentAccountInfo().profileInfo.type; - } catch (...) { - qDebug() << "Cannot find current account info"; - } - } - return currentAccountType_; + return getAccountInfo(get_currentAccountId()); } bool @@ -194,7 +196,7 @@ const conversation::Info& LRCInstance::getConversationFromConvUid(const QString& convUid, const QString& accountId) { auto& accInfo = accountModel().getAccountInfo(!accountId.isEmpty() ? accountId - : getCurrentAccountId()); + : get_currentAccountId()); auto& convModel = accInfo.conversationModel; return convModel->getConversationForUid(convUid).value_or(invalid); } @@ -203,7 +205,7 @@ const conversation::Info& LRCInstance::getConversationFromPeerUri(const QString& peerUri, const QString& accountId) { auto& accInfo = accountModel().getAccountInfo(!accountId.isEmpty() ? accountId - : getCurrentAccountId()); + : get_currentAccountId()); auto& convModel = accInfo.conversationModel; return convModel->getConversationForPeerUri(peerUri).value_or(invalid); } @@ -212,7 +214,7 @@ const conversation::Info& LRCInstance::getConversationFromCallId(const QString& callId, const QString& accountId) { auto& accInfo = accountModel().getAccountInfo(!accountId.isEmpty() ? accountId - : getCurrentAccountId()); + : get_currentAccountId()); auto& convModel = accInfo.conversationModel; return convModel->getConversationForCallId(callId).value_or(invalid); } @@ -250,43 +252,11 @@ LRCInstance::getCurrentContactModel() } } -const QString& -LRCInstance::getCurrentAccountId() -{ - if (currentAccountId_.isEmpty()) { - auto accountList = accountModel().getAccountList(); - if (accountList.size()) - currentAccountId_ = accountList.at(0); - } - return currentAccountId_; -} - -void -LRCInstance::setCurrentAccountId(const QString& accountId) -{ - if (accountId == currentAccountId_) - return; // No need to select current selected account - - auto newAccountType = getAccountInfo(accountId).profileInfo.type; - bool accountTypeChanged = getCurrentAccountType() != newAccountType; - - currentAccountId_ = accountId; - - // Last selected account should be set as preferred. - accountModel().setTopAccount(accountId); - - if (accountTypeChanged) { - currentAccountType_ = newAccountType; - Q_EMIT currentAccountTypeChanged(newAccountType); - } - Q_EMIT currentAccountIdChanged(accountId); -} - int LRCInstance::getCurrentAccountIndex() { for (int i = 0; i < accountModel().getAccountList().size(); i++) { - if (accountModel().getAccountList()[i] == getCurrentAccountId()) { + if (accountModel().getAccountList()[i] == get_currentAccountId()) { return i; } } @@ -312,19 +282,19 @@ LRCInstance::setCurrAccAvatar(const QPixmap& avatarPixmap) bu.open(QIODevice::WriteOnly); avatarPixmap.save(&bu, "PNG"); auto str = QString::fromLocal8Bit(ba.toBase64()); - accountModel().setAvatar(getCurrentAccountId(), str); + accountModel().setAvatar(get_currentAccountId(), str); } void LRCInstance::setCurrAccAvatar(const QString& avatar) { - accountModel().setAvatar(getCurrentAccountId(), avatar); + accountModel().setAvatar(get_currentAccountId(), avatar); } void LRCInstance::setCurrAccDisplayName(const QString& displayName) { - auto accountId = getCurrentAccountId(); + auto accountId = get_currentAccountId(); accountModel().setAlias(accountId, displayName); /* * Force save to .yml. @@ -423,11 +393,11 @@ LRCInstance::selectConversation(const QString& convId, const QString& accountId) } // if the account is not currently selected, do that first, then // proceed to select the conversation - if (!accountId.isEmpty() && accountId != getCurrentAccountId()) { + if (!accountId.isEmpty() && accountId != get_currentAccountId()) { Utils::oneShotConnect(this, &LRCInstance::currentAccountIdChanged, [this, convId] { set_selectedConvUid(convId); }); - setCurrentAccountId(accountId); + set_currentAccountId(accountId); return; } set_selectedConvUid(convId); diff --git a/src/lrcinstance.h b/src/lrcinstance.h index bc653ea2579be83c0f36d9820c5784d09174c198..5c1082d0368c429ef16d13c191de04a5f2009d0e 100644 --- a/src/lrcinstance.h +++ b/src/lrcinstance.h @@ -55,10 +55,8 @@ class LRCInstance : public QObject { Q_OBJECT QML_PROPERTY(QString, selectedConvUid) - Q_PROPERTY(lrc::api::profile::Type currentAccountType READ getCurrentAccountType NOTIFY - currentAccountTypeChanged) - Q_PROPERTY(QString currentAccountId READ getCurrentAccountId WRITE setCurrentAccountId NOTIFY - currentAccountIdChanged) + QML_PROPERTY(QString, currentAccountId) + QML_RO_PROPERTY(lrc::api::profile::Type, currentAccountType) public: explicit LRCInstance(migrateCallback willMigrateCb = {}, @@ -88,7 +86,6 @@ public: const account::Info& getAccountInfo(const QString& accountId); const account::Info& getCurrentAccountInfo(); - profile::Type getCurrentAccountType(); QString getCallIdForConversationUid(const QString& convUid, const QString& accountId); const call::Info* getCallInfo(const QString& callId, const QString& accountId); const call::Info* getCallInfoForConversation(const conversation::Info& convInfo, @@ -109,8 +106,6 @@ public: const QString& accountId, const QString& content); - const QString& getCurrentAccountId(); - void setCurrentAccountId(const QString& accountId = {}); int getCurrentAccountIndex(); void setAvatarForAccount(const QPixmap& avatarPixmap, const QString& accountID); void setCurrAccAvatar(const QPixmap& avatarPixmap); @@ -134,17 +129,12 @@ Q_SIGNALS: void quitEngineRequested(); void conversationUpdated(const QString& convId, const QString& accountId); void draftSaved(const QString& convId); - void contactBanned(const QString& uri); - void currentAccountIdChanged(const QString& accountId); - void currentAccountTypeChanged(profile::Type type); private: std::unique_ptr<Lrc> lrc_; std::unique_ptr<RenderManager> renderer_; std::unique_ptr<UpdateManager> updateManager_; - QString currentAccountId_ {}; - profile::Type currentAccountType_ = profile::Type::INVALID; MapStringString contentDrafts_; MapStringString lastConferences_; diff --git a/src/mainview/components/AccountComboBox.qml b/src/mainview/components/AccountComboBox.qml index aca6119ed4ed15511ba6989db0241ba8ecc2582f..4e7a32e12cdcda5ea84032e8423cfe570a4080d9 100644 --- a/src/mainview/components/AccountComboBox.qml +++ b/src/mainview/components/AccountComboBox.qml @@ -46,7 +46,7 @@ Label { Connections { target: LRCInstance - function onCurrentAccountIdChanged() { + function onAccountListChanged() { root.update() resetAccountListModel(LRCInstance.currentAccountId) } diff --git a/src/mainview/components/AccountComboBoxPopup.qml b/src/mainview/components/AccountComboBoxPopup.qml index 7e499b0b4837efb6ff0536b753499a3cb66694b7..9f26dc76f1fb9abf2c20c179b647b2d24c487c93 100644 --- a/src/mainview/components/AccountComboBoxPopup.qml +++ b/src/mainview/components/AccountComboBoxPopup.qml @@ -61,9 +61,7 @@ Popup { width: root.width onClicked: { root.close() - var sourceRow = CurrentAccountFilterModel.mapToSource( - CurrentAccountFilterModel.index(index, 0)).row - AccountAdapter.changeAccount(sourceRow) + LRCInstance.currentAccountId = ID } } diff --git a/src/messagesadapter.cpp b/src/messagesadapter.cpp index a11e3381304acbb61ced0c370cf86675e16d312d..1e12851d9de4649a16218fcdfe0f50ae96d0e280 100644 --- a/src/messagesadapter.cpp +++ b/src/messagesadapter.cpp @@ -71,7 +71,7 @@ MessagesAdapter::setupChatView(const QString& convUid) QString contactURI = convInfo.participants.at(0); - auto selectedAccountId = lrcInstance_->getCurrentAccountId(); + auto selectedAccountId = lrcInstance_->get_currentAccountId(); auto& accountInfo = lrcInstance_->accountModel().getAccountInfo(selectedAccountId); QMetaObject::invokeMethod(qmlObj_, @@ -102,7 +102,7 @@ MessagesAdapter::onNewInteraction(const QString& convUid, const QString& interactionId, const lrc::api::interaction::Info& interaction) { - auto accountId = lrcInstance_->getCurrentAccountId(); + auto accountId = lrcInstance_->get_currentAccountId(); newInteraction(accountId, convUid, interactionId, interaction); } @@ -270,7 +270,7 @@ MessagesAdapter::copyToDownloads(const QString& interactionId, const QString& di { auto downloadDir = lrcInstance_->accountModel().downloadDirectory; if (auto accInfo = &lrcInstance_->getCurrentAccountInfo()) - accInfo->dataTransferModel->copyTo(lrcInstance_->getCurrentAccountId(), + accInfo->dataTransferModel->copyTo(lrcInstance_->get_currentAccountId(), lrcInstance_->get_selectedConvUid(), interactionId, downloadDir, @@ -627,7 +627,6 @@ MessagesAdapter::blockConversation(const QString& convUid) const auto currentConvUid = convUid.isEmpty() ? lrcInstance_->get_selectedConvUid() : convUid; lrcInstance_->getCurrentConversationModel()->removeConversation(currentConvUid, true); setInvitation(false); - Q_EMIT contactBanned(); } void diff --git a/src/messagesadapter.h b/src/messagesadapter.h index 38ec4b6cf84007434e6a9510504820fa4e0de269..bdf45443e811271edb7955adece7e07742d6502c 100644 --- a/src/messagesadapter.h +++ b/src/messagesadapter.h @@ -94,7 +94,6 @@ protected: void contactIsComposing(const QString& contactUri, bool isComposing); Q_SIGNALS: - void contactBanned(); void newInteraction(int type); void newMessageBarPlaceholderText(QString placeholderText); void newFilePasted(QString filePath); diff --git a/src/moderatorlistmodel.cpp b/src/moderatorlistmodel.cpp index 182b2f3d33cbcddd620a7179abcaa72272858192..85350671a2a848df223753bf0921c0dc54badf01 100644 --- a/src/moderatorlistmodel.cpp +++ b/src/moderatorlistmodel.cpp @@ -52,7 +52,7 @@ ModeratorListModel::data(const QModelIndex& index, int role) const { try { QStringList list = lrcInstance_->accountModel().getDefaultModerators( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); if (!index.isValid() || list.size() <= index.row()) { return QVariant(); } diff --git a/src/qtutils.h b/src/qtutils.h index b6da0213d59d7d7a34aa4232ffbf389a5982a5d5..1ec3101fd26a193a7591cf9ca92f82f9481ea5f8 100644 --- a/src/qtutils.h +++ b/src/qtutils.h @@ -24,9 +24,7 @@ #include <QObject> -#define QML_PROPERTY(type, prop) \ -private: \ - Q_PROPERTY(type prop MEMBER prop##_ NOTIFY prop##Changed); \ +#define PROPERTY_BASE(type, prop) \ type prop##_ {}; \ \ public: \ @@ -43,6 +41,16 @@ public: \ } \ } +#define QML_RO_PROPERTY(type, prop) \ +private: \ + Q_PROPERTY(type prop READ get_##prop NOTIFY prop##Changed); \ + PROPERTY_BASE(type, prop) + +#define QML_PROPERTY(type, prop) \ +private: \ + Q_PROPERTY(type prop MEMBER prop##_ NOTIFY prop##Changed); \ + PROPERTY_BASE(type, prop) + namespace Utils { template<typename Func1, typename Func2> diff --git a/src/settingsadapter.cpp b/src/settingsadapter.cpp index c9c75eb4eb8f5697e0355e335339d6819b30f9ae..1702aaeed93f2d84566d2e8a6bf03ccdb9e5612e 100644 --- a/src/settingsadapter.cpp +++ b/src/settingsadapter.cpp @@ -256,7 +256,7 @@ SettingsAdapter::getCurrentAccount_Profile_Info_Type() QString SettingsAdapter::getAccountBestName() { - return lrcInstance_->accountModel().bestNameForAccount(lrcInstance_->getCurrentAccountId()); + return lrcInstance_->accountModel().bestNameForAccount(lrcInstance_->get_currentAccountId()); } lrc::api::account::ConfProperties_t @@ -264,7 +264,7 @@ SettingsAdapter::getAccountConfig() { lrc::api::account::ConfProperties_t res; try { - res = lrcInstance_->accountModel().getAccountConfig(lrcInstance_->getCurrentAccountId()); + res = lrcInstance_->accountModel().getAccountConfig(lrcInstance_->get_currentAccountId()); } catch (...) { } return res; @@ -563,7 +563,7 @@ SettingsAdapter::setAccountConfig_Username(QString input) { auto confProps = getAccountConfig(); confProps.username = input; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void @@ -571,7 +571,7 @@ SettingsAdapter::setAccountConfig_Hostname(QString input) { auto confProps = getAccountConfig(); confProps.hostname = input; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void @@ -579,7 +579,7 @@ SettingsAdapter::setAccountConfig_Password(QString input) { auto confProps = getAccountConfig(); confProps.password = input; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void @@ -587,366 +587,366 @@ SettingsAdapter::setAccountConfig_RouteSet(QString input) { auto confProps = getAccountConfig(); confProps.routeset = input; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setAutoConnectOnLocalNetwork(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.peerDiscovery = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setCallsUntrusted(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.DHT.PublicInCalls = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setIsRendezVous(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.isRendezVous = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setAutoAnswerCalls(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.autoAnswer = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setEnableRingtone(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Ringtone.ringtoneEnabled = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setEnableProxy(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.proxyEnabled = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setKeepAliveEnabled(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.keepAliveEnabled = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseUPnP(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.upnpEnabled = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseTURN(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TURN.enable = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseSTUN(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.STUN.enable = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setVideoState(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Video.videoEnabled = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseSRTP(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.SRTP.enable = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseSDES(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.SRTP.keyExchange = state ? lrc::api::account::KeyExchangeProtocol::SDES : lrc::api::account::KeyExchangeProtocol::NONE; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseRTPFallback(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.SRTP.rtpFallback = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseTLS(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.enable = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setVerifyCertificatesServer(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.verifyServer = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setVerifyCertificatesClient(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.verifyClient = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setRequireCertificatesIncomingTLS(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.requireClientCertificate = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setUseCustomAddressAndPort(bool state) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.publishedSameAsLocal = state; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setNameServer(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.RingNS.uri = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setProxyAddress(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.proxyServer = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setBootstrapAddress(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.hostname = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setTURNAddress(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TURN.server = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setTURNUsername(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TURN.username = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setTURNPassword(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TURN.password = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setTURNRealm(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TURN.realm = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::setSTUNAddress(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.STUN.server = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::lineEditVoiceMailDialCodeEditFinished(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.mailbox = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::outgoingTLSServerNameLineEditTextChanged(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.serverName = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::lineEditSIPCertPasswordLineEditTextChanged(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.password = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::lineEditSIPCustomAddressLineEditTextChanged(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.publishedAddress = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::customPortSIPSpinBoxValueChanged(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.publishedPort = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::negotiationTimeoutSpinBoxValueChanged(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.negotiationTimeoutSec = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::registrationExpirationTimeSpinBoxValueChanged(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Registration.expire = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::networkInterfaceSpinBoxValueChanged(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.localPort = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::audioRTPMinPortSpinBoxEditFinished(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Audio.audioPortMin = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::audioRTPMaxPortSpinBoxEditFinished(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Audio.audioPortMax = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::videoRTPMinPortSpinBoxEditFinished(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Video.videoPortMin = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::videoRTPMaxPortSpinBoxEditFinished(int value) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Video.videoPortMax = value; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::tlsProtocolComboBoxIndexChanged(const int& index) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); if (static_cast<int>(confProps.TLS.method) != index) { if (index == 0) { @@ -958,7 +958,7 @@ SettingsAdapter::tlsProtocolComboBoxIndexChanged(const int& index) } else { confProps.TLS.method = lrc::api::account::TlsMethod::TLSv1_2; } - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } } @@ -967,9 +967,9 @@ void SettingsAdapter::setDeviceName(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.deviceName = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void @@ -1030,36 +1030,36 @@ void SettingsAdapter::set_RingtonePath(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.Ringtone.ringtonePath = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::set_FileCACert(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.certificateListFile = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::set_FileUserCert(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.certificateFile = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void SettingsAdapter::set_FilePrivateKey(QString text) { auto confProps = lrcInstance_->accountModel().getAccountConfig( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); confProps.TLS.privateKeyFile = text; - lrcInstance_->accountModel().setAccountConfig(lrcInstance_->getCurrentAccountId(), confProps); + lrcInstance_->accountModel().setAccountConfig(lrcInstance_->get_currentAccountId(), confProps); } void diff --git a/src/settingsview/components/BannedContacts.qml b/src/settingsview/components/BannedContacts.qml index 6ffd49fa40999930086f13771c19bd9c30a32de2..0571805dd4cb42f890b7152954ad8f146519a86f 100644 --- a/src/settingsview/components/BannedContacts.qml +++ b/src/settingsview/components/BannedContacts.qml @@ -41,21 +41,17 @@ ColumnLayout { } Connections { - target: MessagesAdapter - - function onContactBanned() { - bannedListWidget.model.reset() - root.visible = true - bannedContactsBtn.visible = true - bannedListWidget.visible = false - } - } - - Connections { - target: AccountAdapter - - function onContactUnbanned() { - updateAndShowBannedContactsSlot() + target: ContactAdapter + + function onBannedStatusChanged(uri, banned) { + if (banned) { + bannedListWidget.model.reset() + root.visible = true + bannedContactsBtn.visible = true + bannedListWidget.visible = false + } else { + updateAndShowBannedContactsSlot() + } } } diff --git a/src/smartlistmodel.cpp b/src/smartlistmodel.cpp index cbd8f52e1c710bcfc352bd6381b1c8b7b8be0575..548a47f04698e1dce82360a7e702e97f059ad076 100644 --- a/src/smartlistmodel.cpp +++ b/src/smartlistmodel.cpp @@ -47,7 +47,7 @@ SmartListModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid() && lrcInstance_) { auto& accInfo = lrcInstance_->accountModel().getAccountInfo( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); auto& convModel = accInfo.conversationModel; if (listModelType_ == Type::TRANSFER) { return convModel->getFilteredConversations(accInfo.profileInfo.type).size(); @@ -77,7 +77,7 @@ SmartListModel::data(const QModelIndex& index, int role) const case Type::TRANSFER: { try { auto& currentAccountInfo = lrcInstance_->accountModel().getAccountInfo( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); auto& convModel = currentAccountInfo.conversationModel; auto& item = convModel->getFilteredConversations(currentAccountInfo.profileInfo.type) @@ -144,7 +144,7 @@ SmartListModel::setConferenceableFilter(const QString& filter) { beginResetModel(); auto& accountInfo = lrcInstance_->accountModel().getAccountInfo( - lrcInstance_->getCurrentAccountId()); + lrcInstance_->get_currentAccountId()); auto& convModel = accountInfo.conversationModel; conferenceables_ = convModel->getConferenceableConversations(lrcInstance_->get_selectedConvUid(), filter); diff --git a/src/utils.cpp b/src/utils.cpp index 2b12dfefc7c68ed4a28e48589e0143b17fd8a15e..aab3648ae44c647fe94515c7b7a8d07b2315c93a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -337,7 +337,7 @@ Utils::contactPhoto(LRCInstance* instance, * Get first contact photo. */ auto& accountInfo = instance->accountModel().getAccountInfo( - accountId.isEmpty() ? instance->getCurrentAccountId() : accountId); + accountId.isEmpty() ? instance->get_currentAccountId() : accountId); auto contactInfo = accountInfo.contactModel->getContact(contactUri); auto contactPhoto = contactInfo.profileInfo.avatar; auto bestName = accountInfo.contactModel->bestNameForContact(contactUri); diff --git a/src/utilsadapter.cpp b/src/utilsadapter.cpp index dce5462859b99455b131c7c01ec2f20ca1c90e53..95a5668033ea6b198beb071fb0c2a3bbf1377a71 100644 --- a/src/utilsadapter.cpp +++ b/src/utilsadapter.cpp @@ -212,7 +212,7 @@ UtilsAdapter::getCallId(const QString& accountId, const QString& convUid) int UtilsAdapter::getCallStatus(const QString& callId) { - const auto callStatus = lrcInstance_->getCallInfo(callId, lrcInstance_->getCurrentAccountId()); + const auto callStatus = lrcInstance_->getCallInfo(callId, lrcInstance_->get_currentAccountId()); return static_cast<int>(callStatus->status); } diff --git a/tests/unittests/account_unittest.cpp b/tests/unittests/account_unittest.cpp index 350363d4e23c2764bab3fb90a815d5ea6ea9bc8f..685aaf837e54e4bd7e7efba3fc4a719ad1d493df 100644 --- a/tests/unittests/account_unittest.cpp +++ b/tests/unittests/account_unittest.cpp @@ -55,7 +55,7 @@ TEST_F(AccountFixture, CreateSIPAccountTest) { // AccountAdded signal spy QSignalSpy accountAddedSpy(&globalEnv.lrcInstance->accountModel(), - &lrc::api::NewAccountModel::accountAdded); + &NewAccountModel::accountAdded); // Create SIP Acc globalEnv.accountAdapter->createSIPAccount(QVariantMap()); @@ -67,24 +67,24 @@ TEST_F(AccountFixture, CreateSIPAccountTest) QVERIFY(accountAddedArguments.at(0).type() == QVariant::String); // Select the created account - globalEnv.lrcInstance->setCurrentAccountId(accountAddedArguments.at(0).toString()); + globalEnv.lrcInstance->set_currentAccountId(accountAddedArguments.at(0).toString()); auto accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size(); ASSERT_EQ(accountListSize, 1); // Make sure the account setup is done QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(), - &lrc::api::NewAccountModel::accountStatusChanged); + &NewAccountModel::accountStatusChanged); QVERIFY(accountStatusChangedSpy.wait()); QCOMPARE(accountStatusChangedSpy.count(), 1); // Remove the account globalEnv.lrcInstance->accountModel().removeAccount( - globalEnv.lrcInstance->getCurrentAccountId()); + globalEnv.lrcInstance->get_currentAccountId()); QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(), - &lrc::api::NewAccountModel::accountRemoved); + &NewAccountModel::accountRemoved); QVERIFY(accountRemovedSpy.wait()); QCOMPARE(accountRemovedSpy.count(), 1); diff --git a/tests/unittests/contact_unittest.cpp b/tests/unittests/contact_unittest.cpp index cf293ef253ec0acae6144e04682ddb9758631408..cd7ff6265afb9f0d95b720ae0904573316e40293 100644 --- a/tests/unittests/contact_unittest.cpp +++ b/tests/unittests/contact_unittest.cpp @@ -55,7 +55,7 @@ TEST_F(ContactFixture, AddSIPContactTest) QVERIFY(accountAddedArguments.at(0).type() == QVariant::String); // Select the created account - globalEnv.lrcInstance->setCurrentAccountId(accountAddedArguments.at(0).toString()); + globalEnv.lrcInstance->set_currentAccountId(accountAddedArguments.at(0).toString()); // Make sure the account setup is done QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(), @@ -94,7 +94,7 @@ TEST_F(ContactFixture, AddSIPContactTest) // Remove the account globalEnv.lrcInstance->accountModel().removeAccount( - globalEnv.lrcInstance->getCurrentAccountId()); + globalEnv.lrcInstance->get_currentAccountId()); QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(), &lrc::api::NewAccountModel::accountRemoved);