From 9e1e797d8c6126ac450c82bbd821b5ac42a6da92 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Wed, 29 Nov 2023 10:49:32 +0100 Subject: [PATCH] Redirect to the main page if we have an account. Add API to account list to check usable account. On removed, redirect to login page if there is no more account(TODO: need SDK update for core callback) --- Linphone/core/account/AccountList.cpp | 40 ++++++++++++-------------- Linphone/core/account/AccountList.hpp | 8 ++++++ Linphone/core/account/AccountProxy.cpp | 5 ++++ Linphone/core/account/AccountProxy.hpp | 4 +++ Linphone/model/core/CoreModel.hpp | 1 + Linphone/view/App/Main.qml | 12 ++++++-- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Linphone/core/account/AccountList.cpp b/Linphone/core/account/AccountList.cpp index 2c08ef58..516227ae 100644 --- a/Linphone/core/account/AccountList.cpp +++ b/Linphone/core/account/AccountList.cpp @@ -40,6 +40,7 @@ AccountList::AccountList(QObject *parent) : ListProxy(parent) { qDebug() << "[AccountList] new" << this; mustBeInMainThread(getClassName()); connect(CoreModel::getInstance().get(), &CoreModel::accountAdded, this, &AccountList::lUpdate); + connect(CoreModel::getInstance().get(), &CoreModel::accountRemoved, this, &AccountList::lUpdate); } AccountList::~AccountList() { @@ -65,6 +66,7 @@ void AccountList::setSelf(QSharedPointer me) { mustBeInMainThread(getClassName()); resetData(); add(*accounts); + setHaveAccount(accounts->size() > 0); delete accounts; }); }); @@ -73,33 +75,29 @@ void AccountList::setSelf(QSharedPointer me) { lUpdate(); } -AccountGui *AccountList::getDefaultAccount() const { +QSharedPointer AccountList::getDefaultAccountCore() const { for (auto it : mList) { auto account = it.objectCast(); - if (account->getIsDefaultAccount()) return new AccountGui(account); + if (account->getIsDefaultAccount()) return account; } return nullptr; } -/* -void AccountList::update() { - App::postModelAsync([=]() { - QList> accounts; - // Model thread. - mustBeInLinphoneThread(getClassName()); - auto linphoneAccounts = CoreModel::getInstance()->getCore()->getAccountList(); - for (auto it : linphoneAccounts) { - auto model = AccountCore::create(it); - accounts.push_back(model); - } - // Invoke for adding stuffs in caller thread - QMetaObject::invokeMethod(this, [this, accounts]() { - mustBeInMainThread(getClassName()); - clearData(); - add(accounts); - }); - }); + +AccountGui *AccountList::getDefaultAccount() const { + auto account = getDefaultAccountCore(); + if (account) return new AccountGui(account); + else return nullptr; } -*/ +bool AccountList::getHaveAccount() const { + return mHaveAccount; +} +void AccountList::setHaveAccount(bool haveAccount) { + if (mHaveAccount != haveAccount) { + mHaveAccount = haveAccount; + emit haveAccountChanged(); + } +} + QVariant AccountList::data(const QModelIndex &index, int role) const { int row = index.row(); if (!index.isValid() || row < 0 || row >= mList.count()) return QVariant(); diff --git a/Linphone/core/account/AccountList.hpp b/Linphone/core/account/AccountList.hpp index 7a392d35..780e8ea7 100644 --- a/Linphone/core/account/AccountList.hpp +++ b/Linphone/core/account/AccountList.hpp @@ -27,6 +27,7 @@ #include class AccountGui; +class AccountCore; // ============================================================================= class AccountList : public ListProxy, public AbstractObject { @@ -39,11 +40,18 @@ public: void setSelf(QSharedPointer me); AccountGui *getDefaultAccount() const; + QSharedPointer getDefaultAccountCore() const; + + bool getHaveAccount() const; + void setHaveAccount(bool haveAccount); + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; signals: void lUpdate(); + void haveAccountChanged(); private: + bool mHaveAccount = false; QSharedPointer mModelConnection; DECLARE_ABSTRACT_OBJECT }; diff --git a/Linphone/core/account/AccountProxy.cpp b/Linphone/core/account/AccountProxy.cpp index 80c23c26..348b8292 100644 --- a/Linphone/core/account/AccountProxy.cpp +++ b/Linphone/core/account/AccountProxy.cpp @@ -26,6 +26,7 @@ AccountProxy::AccountProxy(QObject *parent) : SortFilterProxy(parent) { qDebug() << "[AccountProxy] new" << this; mList = AccountList::create(); connect(mList.get(), &AccountList::countChanged, this, &AccountProxy::defaultAccountChanged); + connect(mList.get(), &AccountList::haveAccountChanged, this, &AccountProxy::haveAccountChanged); setSourceModel(mList.get()); sort(0); } @@ -53,6 +54,10 @@ AccountGui *AccountProxy::getDefaultAccount() const { void AccountProxy::setDefaultAccount(AccountGui *account) { } +bool AccountProxy::getHaveAccount() const { + return dynamic_cast(sourceModel())->getHaveAccount(); +} + bool AccountProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { bool show = (mFilterText.isEmpty() || mFilterText == "*"); if (!show) { diff --git a/Linphone/core/account/AccountProxy.hpp b/Linphone/core/account/AccountProxy.hpp index cfc528bf..0b3c0378 100644 --- a/Linphone/core/account/AccountProxy.hpp +++ b/Linphone/core/account/AccountProxy.hpp @@ -32,6 +32,7 @@ class AccountProxy : public SortFilterProxy { Q_PROPERTY(QString filterText READ getFilterText WRITE setFilterText NOTIFY filterTextChanged) Q_PROPERTY(AccountGui *defaultAccount READ getDefaultAccount WRITE setDefaultAccount NOTIFY defaultAccountChanged) + Q_PROPERTY(bool haveAccount READ getHaveAccount NOTIFY haveAccountChanged) public: AccountProxy(QObject *parent = Q_NULLPTR); @@ -43,9 +44,12 @@ public: AccountGui *getDefaultAccount() const; void setDefaultAccount(AccountGui *account); + bool getHaveAccount() const; + signals: void filterTextChanged(); void defaultAccountChanged(); + void haveAccountChanged(); protected: virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 0e134dc7..acb2b31e 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -159,6 +159,7 @@ private: signals: void accountAdded(const std::shared_ptr &core, const std::shared_ptr &account); + void accountRemoved(); void accountRegistrationStateChanged(const std::shared_ptr &core, const std::shared_ptr &account, linphone::RegistrationState state, diff --git a/Linphone/view/App/Main.qml b/Linphone/view/App/Main.qml index 8cd7bbc0..8ba48bf6 100644 --- a/Linphone/view/App/Main.qml +++ b/Linphone/view/App/Main.qml @@ -11,11 +11,19 @@ Window { visible: true title: qsTr("Linphone") property bool firstConnection: true - + AccountProxy{ + id: accountProxy + onHaveAccountChanged: { + if(haveAccount) + mainWindowStackView.replace(mainPage) + else + mainWindowStackView.replace(loginPage) + } + } StackView { id: mainWindowStackView anchors.fill: parent - initialItem: welcomePage + initialItem: accountProxy.haveAccount ? mainPage : welcomePage } Component { id: welcomePage