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)
This commit is contained in:
parent
bdf1d197ec
commit
9e1e797d8c
6 changed files with 47 additions and 23 deletions
|
|
@ -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<AccountList> me) {
|
|||
mustBeInMainThread(getClassName());
|
||||
resetData();
|
||||
add(*accounts);
|
||||
setHaveAccount(accounts->size() > 0);
|
||||
delete accounts;
|
||||
});
|
||||
});
|
||||
|
|
@ -73,33 +75,29 @@ void AccountList::setSelf(QSharedPointer<AccountList> me) {
|
|||
lUpdate();
|
||||
}
|
||||
|
||||
AccountGui *AccountList::getDefaultAccount() const {
|
||||
QSharedPointer<AccountCore> AccountList::getDefaultAccountCore() const {
|
||||
for (auto it : mList) {
|
||||
auto account = it.objectCast<AccountCore>();
|
||||
if (account->getIsDefaultAccount()) return new AccountGui(account);
|
||||
if (account->getIsDefaultAccount()) return account;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
/*
|
||||
void AccountList::update() {
|
||||
App::postModelAsync([=]() {
|
||||
QList<QSharedPointer<AccountCore>> 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();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <QLocale>
|
||||
|
||||
class AccountGui;
|
||||
class AccountCore;
|
||||
// =============================================================================
|
||||
|
||||
class AccountList : public ListProxy, public AbstractObject {
|
||||
|
|
@ -39,11 +40,18 @@ public:
|
|||
void setSelf(QSharedPointer<AccountList> me);
|
||||
|
||||
AccountGui *getDefaultAccount() const;
|
||||
QSharedPointer<AccountCore> 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<SafeConnection> mModelConnection;
|
||||
DECLARE_ABSTRACT_OBJECT
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<AccountList *>(sourceModel())->getHaveAccount();
|
||||
}
|
||||
|
||||
bool AccountProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
|
||||
bool show = (mFilterText.isEmpty() || mFilterText == "*");
|
||||
if (!show) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ private:
|
|||
|
||||
signals:
|
||||
void accountAdded(const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::Account> &account);
|
||||
void accountRemoved();
|
||||
void accountRegistrationStateChanged(const std::shared_ptr<linphone::Core> &core,
|
||||
const std::shared_ptr<linphone::Account> &account,
|
||||
linphone::RegistrationState state,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue