diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index 03a7ca8d2..67feaae62 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -91,6 +91,11 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : { MessageCountNotifier *messageCountNotifier = new MessageCountNotifier(mInstance); messageCountNotifier->updateUnreadMessageCount(); + QObject::connect( + messageCountNotifier, &MessageCountNotifier::unreadMessageCountChanged, + mInstance, &CoreManager::unreadMessageCountChanged + ); + mInstance->mMessageCountNotifier = messageCountNotifier; } mInstance->migrate(); @@ -301,6 +306,12 @@ QString CoreManager::getVersion () const { // ----------------------------------------------------------------------------- +int CoreManager::getUnreadMessageCount () const { + return mMessageCountNotifier ? mMessageCountNotifier->getUnreadMessageCount() : 0; +} + +// ----------------------------------------------------------------------------- + void CoreManager::iterate () { mInstance->lockVideoRender(); mCore->iterate(); diff --git a/src/components/core/CoreManager.hpp b/src/components/core/CoreManager.hpp index 22e7fe0ee..114a452ea 100644 --- a/src/components/core/CoreManager.hpp +++ b/src/components/core/CoreManager.hpp @@ -35,6 +35,7 @@ class CallsListModel; class ChatModel; class ContactsListModel; class CoreHandlers; +class MessageCountNotifier; class SettingsModel; class SipAddressesModel; class VcardModel; @@ -44,6 +45,7 @@ class CoreManager : public QObject { Q_PROPERTY(QString version READ getVersion CONSTANT); Q_PROPERTY(QString downloadUrl READ getDownloadUrl CONSTANT); + Q_PROPERTY(int unreadMessageCount READ getUnreadMessageCount NOTIFY unreadMessageCountChanged); public: bool started () const { @@ -135,6 +137,8 @@ signals: void logsUploaded (const QString &url); + void unreadMessageCountChanged (int count); + private: CoreManager (QObject *parent, const QString &configPath); @@ -147,6 +151,8 @@ private: QString getVersion () const; + int getUnreadMessageCount () const; + void iterate (); void handleLogsUploadStateChanged (linphone::Core::LogCollectionUploadState state, const std::string &info); @@ -164,6 +170,8 @@ private: SettingsModel *mSettingsModel = nullptr; AccountSettingsModel *mAccountSettingsModel = nullptr; + MessageCountNotifier *mMessageCountNotifier = nullptr; + QHash, std::weak_ptr> mChatModels; QTimer *mCbsTimer = nullptr; diff --git a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp b/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp index 80c8a2a26..2b7fc674b 100644 --- a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp +++ b/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp @@ -59,6 +59,7 @@ void AbstractMessageCountNotifier::internalNotifyUnreadMessageCount () { int n = mUnreadMessageCount > 99 ? 99 : mUnreadMessageCount; notifyUnreadMessageCount(CoreManager::getInstance()->getSettingsModel()->getChatEnabled() ? n : 0); + unreadMessageCountChanged(mUnreadMessageCount); } // ----------------------------------------------------------------------------- diff --git a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp b/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp index f039cde47..550d084fa 100644 --- a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp +++ b/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp @@ -43,6 +43,13 @@ public: void updateUnreadMessageCount (); + int getUnreadMessageCount () const { + return mUnreadMessageCount; + } + +signals: + void unreadMessageCountChanged (int count); + protected: virtual void notifyUnreadMessageCount (int n) = 0; diff --git a/src/components/settings/AccountSettingsModel.cpp b/src/components/settings/AccountSettingsModel.cpp index ce514ad85..b264e31e5 100644 --- a/src/components/settings/AccountSettingsModel.cpp +++ b/src/components/settings/AccountSettingsModel.cpp @@ -54,10 +54,12 @@ static inline AccountSettingsModel::RegistrationState mapLinphoneRegistrationSta // ----------------------------------------------------------------------------- AccountSettingsModel::AccountSettingsModel (QObject *parent) : QObject(parent) { + CoreManager *coreManager = CoreManager::getInstance(); QObject::connect( - CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::registrationStateChanged, + coreManager->getHandlers().get(), &CoreHandlers::registrationStateChanged, this, &AccountSettingsModel::handleRegistrationStateChanged ); + QObject::connect(coreManager, &CoreManager::unreadMessageCountChanged, this, [this]() { emit accountSettingsUpdated(); }); } // ----------------------------------------------------------------------------- diff --git a/ui/modules/Linphone/Account/AccountStatus.qml b/ui/modules/Linphone/Account/AccountStatus.qml index 25a109905..b273651d0 100644 --- a/ui/modules/Linphone/Account/AccountStatus.qml +++ b/ui/modules/Linphone/Account/AccountStatus.qml @@ -16,58 +16,75 @@ Item { // --------------------------------------------------------------------------- - Column { + RowLayout { anchors.fill: parent - RowLayout { - height: parent.height / 2 - spacing: AccountStatusStyle.horizontalSpacing - width: parent.width + Column { + Layout.fillWidth: true + Layout.fillHeight: true - Item { - Layout.alignment: Qt.AlignBottom - Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin - Layout.preferredHeight: AccountStatusStyle.presenceLevel.size - Layout.preferredWidth: AccountStatusStyle.presenceLevel.size + RowLayout { + height: parent.height / 2 + spacing: AccountStatusStyle.horizontalSpacing + width: parent.width - PresenceLevel { - anchors.fill: parent - level: SettingsModel.rlsUriEnabled ? OwnPresenceModel.presenceLevel : Presence.Green - visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateRegistered + Item { + Layout.alignment: Qt.AlignBottom + Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin + Layout.preferredHeight: AccountStatusStyle.presenceLevel.size + Layout.preferredWidth: AccountStatusStyle.presenceLevel.size + + PresenceLevel { + anchors.fill: parent + level: SettingsModel.rlsUriEnabled ? OwnPresenceModel.presenceLevel : Presence.Green + visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateRegistered + } + + BusyIndicator { + anchors.fill: parent + running: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateInProgress + } + + Icon { + iconSize: parent.width + icon: 'generic_error' + visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateNotRegistered + } } - BusyIndicator { - anchors.fill: parent - running: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateInProgress - } - - Icon { - iconSize: parent.width - icon: 'generic_error' - visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateNotRegistered + Text { + Layout.fillHeight: true + Layout.fillWidth: true + color: AccountStatusStyle.username.color + elide: Text.ElideRight + font.bold: true + font.pointSize: AccountStatusStyle.username.pointSize + text: AccountSettingsModel.username + verticalAlignment: Text.AlignBottom } } Text { - Layout.fillHeight: true - Layout.fillWidth: true - color: AccountStatusStyle.username.color + color: AccountStatusStyle.sipAddress.color elide: Text.ElideRight - font.bold: true - font.pointSize: AccountStatusStyle.username.pointSize - text: AccountSettingsModel.username - verticalAlignment: Text.AlignBottom + font.pointSize: AccountStatusStyle.sipAddress.pointSize + height: parent.height / 2 + text: AccountSettingsModel.sipAddress + verticalAlignment: Text.AlignTop + width: parent.width } } - Text { - color: AccountStatusStyle.sipAddress.color - elide: Text.ElideRight - font.pointSize: AccountStatusStyle.sipAddress.pointSize - height: parent.height / 2 - text: AccountSettingsModel.sipAddress - verticalAlignment: Text.AlignTop - width: parent.width + Item { + Layout.preferredWidth: MessageCounterStyle.iconSize.message + Layout.preferredHeight: MessageCounterStyle.iconSize.message + + MessageCounter { + id: messageCounter + + anchors.fill: parent + count: CoreManager.unreadMessageCount + } } } diff --git a/ui/views/App/Main/Dialogs/ManageAccounts.qml b/ui/views/App/Main/Dialogs/ManageAccounts.qml index c336b98b0..790a1cfae 100644 --- a/ui/views/App/Main/Dialogs/ManageAccounts.qml +++ b/ui/views/App/Main/Dialogs/ManageAccounts.qml @@ -67,10 +67,11 @@ DialogPlus { property string textRole: 'sipAddress' // Used by delegate. anchors.fill: parent - currentIndex: Utils.findIndex(AccountSettingsModel.accounts, function (account) { + model: AccountSettingsModel.accounts + + onModelChanged: currentIndex = Utils.findIndex(AccountSettingsModel.accounts, function (account) { return account.sipAddress === AccountSettingsModel.sipAddress }) - model: AccountSettingsModel.accounts delegate: CommonItemDelegate { id: item @@ -80,7 +81,10 @@ DialogPlus { itemIcon: Logic.getItemIcon(flattenedModel) width: parent.width - onClicked: AccountSettingsModel.setDefaultProxyConfig(flattenedModel.proxyConfig) + onClicked: { + container.currentIndex = index + AccountSettingsModel.setDefaultProxyConfig(flattenedModel.proxyConfig) + } MessageCounter { anchors.fill: parent diff --git a/ui/views/App/Styles/Main/Dialogs/ManageAccountsStyle.qml b/ui/views/App/Styles/Main/Dialogs/ManageAccountsStyle.qml index fcfbcf178..534334493 100644 --- a/ui/views/App/Styles/Main/Dialogs/ManageAccountsStyle.qml +++ b/ui/views/App/Styles/Main/Dialogs/ManageAccountsStyle.qml @@ -4,11 +4,11 @@ import QtQml 2.2 // ============================================================================= QtObject { - property int height: 303 - property int heightWithoutPresence: 234 + property int height: 353 + property int heightWithoutPresence: 284 property int width: 450 property QtObject accountSelector: QtObject { - property int height: 126 + property int height: 176 } }