diff --git a/Linphone/core/account/AccountList.cpp b/Linphone/core/account/AccountList.cpp index 278c92c0..4f2673b4 100644 --- a/Linphone/core/account/AccountList.cpp +++ b/Linphone/core/account/AccountList.cpp @@ -84,6 +84,17 @@ void AccountList::setSelf(QSharedPointer me) { mModelConnection->makeConnectToModel(&CoreModel::accountAdded, &AccountList::lUpdate); lUpdate(); + + mModelConnection->makeConnectToModel( + &CoreModel::accountRemoved, + [this](const std::shared_ptr &core, const std::shared_ptr &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 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()) { + return new AccountGui(isAccount); + } + } + return nullptr; +} + bool AccountList::getHaveAccount() const { return mHaveAccount; } diff --git a/Linphone/core/account/AccountList.hpp b/Linphone/core/account/AccountList.hpp index 19c8fbce..2680bd80 100644 --- a/Linphone/core/account/AccountList.hpp +++ b/Linphone/core/account/AccountList.hpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2010-2024 Belledonne Communications SARL. * * This file is part of linphone-desktop @@ -44,6 +44,7 @@ public: QSharedPointer getDefaultAccountCore() const; void setDefaultAccount(QSharedPointer 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; diff --git a/Linphone/core/account/AccountProxy.cpp b/Linphone/core/account/AccountProxy.cpp index 7de0bc30..d977dc30 100644 --- a/Linphone/core/account/AccountProxy.cpp +++ b/Linphone/core/account/AccountProxy.cpp @@ -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(sourceModel())->findAccountByAddress(address); } +AccountGui *AccountProxy::firstAccount() { + return dynamic_cast(sourceModel())->firstAccount(); +} + bool AccountProxy::getHaveAccount() const { return dynamic_cast(sourceModel())->getHaveAccount(); } diff --git a/Linphone/core/account/AccountProxy.hpp b/Linphone/core/account/AccountProxy.hpp index 75087495..9ffe6126 100644 --- a/Linphone/core/account/AccountProxy.hpp +++ b/Linphone/core/account/AccountProxy.hpp @@ -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; diff --git a/Linphone/view/App/Layout/MainLayout.qml b/Linphone/view/App/Layout/MainLayout.qml index 96aa42f4..6296d19e 100644 --- a/Linphone/view/App/Layout/MainLayout.qml +++ b/Linphone/view/App/Layout/MainLayout.qml @@ -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() } } diff --git a/Linphone/view/App/Main.qml b/Linphone/view/App/Main.qml index ffc6bf01..49c49c01 100644 --- a/Linphone/view/App/Main.qml +++ b/Linphone/view/App/Main.qml @@ -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 { diff --git a/Linphone/view/Item/Account/Accounts.qml b/Linphone/view/Item/Account/Accounts.qml index a9ebf706..04873686 100644 --- a/Linphone/view/Item/Account/Accounts.qml +++ b/Linphone/view/Item/Account/Accounts.qml @@ -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] diff --git a/Linphone/view/Item/Contact/Contact.qml b/Linphone/view/Item/Contact/Contact.qml index be87198f..0ea496fc 100644 --- a/Linphone/view/Item/Contact/Contact.qml +++ b/Linphone/view/Item/Contact/Contact.qml @@ -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 } } }