- Fix navigation to login screen upon last account removed

- Implemented navigation to multi accounts
- Implemented navigation back to home screen when removing an account but other remains
- removed focus on "DND" menu entry.
This commit is contained in:
Christophe Deschamps 2024-08-29 18:12:44 +02:00
parent 1cf436263a
commit 08a822991b
8 changed files with 51 additions and 11 deletions

View file

@ -84,6 +84,17 @@ void AccountList::setSelf(QSharedPointer<AccountList> me) {
mModelConnection->makeConnectToModel(&CoreModel::accountAdded, &AccountList::lUpdate);
lUpdate();
mModelConnection->makeConnectToModel(
&CoreModel::accountRemoved,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::Account> &account) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
bool wasLast = CoreModel::getInstance()->getCore()->getAccountList().size() == 0;
mModelConnection->invokeToCore([this, wasLast]() {
mustBeInMainThread(log().arg(Q_FUNC_INFO));
emit accountRemoved(wasLast);
});
});
}
QSharedPointer<AccountCore> AccountList::getDefaultAccountCore() const {
@ -114,6 +125,15 @@ AccountGui *AccountList::findAccountByAddress(const QString &address) {
return nullptr;
}
AccountGui *AccountList::firstAccount() {
for (auto &item : mList) {
if (auto isAccount = item.objectCast<AccountCore>()) {
return new AccountGui(isAccount);
}
}
return nullptr;
}
bool AccountList::getHaveAccount() const {
return mHaveAccount;
}

View file

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2010-2024 Belledonne Communications SARL.
*
* This file is part of linphone-desktop
@ -44,6 +44,7 @@ public:
QSharedPointer<AccountCore> getDefaultAccountCore() const;
void setDefaultAccount(QSharedPointer<AccountCore> account);
AccountGui *findAccountByAddress(const QString &address);
AccountGui *firstAccount();
bool getHaveAccount() const;
void setHaveAccount(bool haveAccount);
@ -53,6 +54,7 @@ signals:
void lUpdate();
void haveAccountChanged();
void defaultAccountChanged();
void accountRemoved(bool wasLast);
private:
bool mHaveAccount = false;

View file

@ -27,6 +27,7 @@ AccountProxy::AccountProxy(QObject *parent) : SortFilterProxy(parent) {
connect(mAccountList.get(), &AccountList::countChanged, this, &AccountProxy::resetDefaultAccount);
connect(mAccountList.get(), &AccountList::defaultAccountChanged, this, &AccountProxy::resetDefaultAccount);
connect(mAccountList.get(), &AccountList::haveAccountChanged, this, &AccountProxy::haveAccountChanged);
connect(mAccountList.get(), &AccountList::accountRemoved, this, &AccountProxy::accountRemoved);
setSourceModel(mAccountList.get());
sort(0);
}
@ -65,6 +66,10 @@ AccountGui *AccountProxy::findAccountByAddress(const QString &address) {
return dynamic_cast<AccountList *>(sourceModel())->findAccountByAddress(address);
}
AccountGui *AccountProxy::firstAccount() {
return dynamic_cast<AccountList *>(sourceModel())->firstAccount();
}
bool AccountProxy::getHaveAccount() const {
return dynamic_cast<AccountList *>(sourceModel())->getHaveAccount();
}

View file

@ -45,6 +45,7 @@ public:
void setDefaultAccount(AccountGui *account); // TODO
void resetDefaultAccount(); // Reset the default account to let UI build its new object if needed.
Q_INVOKABLE AccountGui *findAccountByAddress(const QString &address);
Q_INVOKABLE AccountGui *firstAccount();
bool getHaveAccount() const;
@ -52,6 +53,7 @@ signals:
void filterTextChanged();
void defaultAccountChanged();
void haveAccountChanged();
void accountRemoved(bool wasLast);
protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;

View file

@ -59,6 +59,11 @@ Item {
mainItem.contextualMenuOpenedComponent = undefined
}
function openAccountSettings(account: AccountGui) {
var page = accountSettingsPageComponent.createObject(parent, {"account": account});
openContextualMenuComponent(page)
}
AccountProxy {
id: accountProxy
onDefaultAccountChanged: if (tabbar.currentIndex === 0 && defaultAccount) defaultAccount.core.lResetMissedCalls()
@ -394,6 +399,10 @@ Item {
id: accounts
accountProxy: accountProxy
onAddAccountRequest: mainItem.addAccountRequest()
onEditAccount: function(account) {
avatarButton.popup.close()
openAccountSettings(account)
}
}
}
}
@ -444,7 +453,7 @@ Item {
iconSize: 32 * DefaultStyle.dp
text: qsTr("Mon compte")
iconSource: AppIcons.manageProfile
onClicked: openContextualMenuComponent(myAccountSettingsPageComponent)
onClicked: openAccountSettings(accountProxy.defaultAccount ? accountProxy.defaultAccount : accountProxy.firstAccount())
KeyNavigation.up: visibleChildren.length != 0 ? settingsButtons.getPreviousItem(0) : null
KeyNavigation.down: visibleChildren.length != 0 ? settingsButtons.getNextItem(0) : null
}
@ -452,7 +461,6 @@ Item {
id: dndButton
Layout.preferredHeight: 32 * DefaultStyle.dp
Layout.fillWidth: true
focus: visible
iconSize: 32 * DefaultStyle.dp
text: SettingsCpp.dnd ? qsTr("Désactiver ne pas déranger") : qsTr("Activer ne pas déranger")
iconSource: AppIcons.bellDnd
@ -559,9 +567,8 @@ Item {
}
}
Component {
id: myAccountSettingsPageComponent
id: accountSettingsPageComponent
AccountSettingsPage {
account: accountProxy.defaultAccount
onGoBack: closeContextualMenuComponent()
}
}

View file

@ -49,10 +49,9 @@ AppWindow {
AccountProxy {
id: accountProxy
onHaveAccountChanged: {
// this function can't be used like this. It will show the main page when
// trying to connect and then return to login page if connection fails.
// initStackViewItem()
onAccountRemoved:function (wasLast) {
if (wasLast) mainWindowStackView.replace(loginPage, StackView.Immediate)
else mainWindowStackView.replace(mainPage, StackView.Immediate)
}
}
StackView {

View file

@ -19,6 +19,8 @@ Item {
property AccountProxy accountProxy
signal addAccountRequest()
signal editAccount(AccountGui account)
implicitHeight: list.contentHeight + topPadding + bottomPadding + 32 * DefaultStyle.dp + 1 + newAccountArea.height
ColumnLayout{
id: childLayout
@ -42,6 +44,7 @@ Item {
account: modelData
onAvatarClicked: fileDialog.open()
onBackgroundClicked: modelData.core.lSetDefaultAccount()
onEdit: editAccount(modelData)
FileDialog {
id: fileDialog
currentFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]

View file

@ -15,6 +15,7 @@ Rectangle{
signal avatarClicked()
signal backgroundClicked()
signal edit()
height: 45 * DefaultStyle.dp
MouseArea{
@ -148,9 +149,10 @@ Rectangle{
width: 24 * DefaultStyle.dp
fillMode: Image.PreserveAspectFit
colorizationColor: DefaultStyle.main2_500main
MouseArea{ // TODO
MouseArea{
anchors.fill: parent
onClicked: console.log('TODO: Manage!')
onClicked: mainItem.edit()
cursorShape: Qt.PointingHandCursor
}
}
}