diff --git a/CMakeLists.txt b/CMakeLists.txt index b9d0501d2..0d27b0fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,7 @@ set(SOURCES src/components/contacts/ContactsListProxyModel.cpp src/components/core/CoreHandlers.cpp src/components/core/CoreManager.cpp - src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp + src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp src/components/file/FileDownloader.cpp src/components/file/FileExtractor.cpp src/components/notifier/Notifier.cpp @@ -200,7 +200,7 @@ set(HEADERS src/components/contacts/ContactsListProxyModel.hpp src/components/core/CoreHandlers.hpp src/components/core/CoreManager.hpp - src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp + src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp src/components/file/FileDownloader.hpp src/components/file/FileExtractor.hpp src/components/notifier/Notifier.hpp @@ -230,37 +230,37 @@ set(MAIN_FILE src/app/main.cpp) if (APPLE) list(APPEND SOURCES src/app/single-application/SingleApplication.cpp - src/components/core/messages-count-notifier/MessageCountNotifierMacOs.m + src/components/core/event-count-notifier/EventCountNotifierMacOs.m src/components/other/desktop-tools/DesktopToolsMacOs.cpp src/components/other/desktop-tools/screen-saver/ScreenSaverMacOs.m ) list(APPEND HEADERS src/app/single-application/SingleApplicationPrivate.hpp - src/components/core/messages-count-notifier/MessageCountNotifierMacOs.hpp + src/components/core/event-count-notifier/EventCountNotifierMacOs.hpp src/components/other/desktop-tools/DesktopToolsMacOs.hpp ) elseif (WIN32) list(APPEND SOURCES src/app/single-application/SingleApplication.cpp - src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.cpp + src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp src/components/other/desktop-tools/DesktopToolsWindows.cpp ) list(APPEND HEADERS src/app/single-application/SingleApplicationPrivate.hpp - src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp + src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.hpp src/components/other/desktop-tools/DesktopToolsWindows.hpp ) else () list(APPEND SOURCES src/app/single-application/SingleApplicationDBus.cpp - src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.cpp + src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp src/components/other/desktop-tools/DesktopToolsLinux.cpp src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.cpp src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.cpp ) list(APPEND HEADERS src/app/single-application/SingleApplicationDBusPrivate.hpp - src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp + src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.hpp src/components/other/desktop-tools/DesktopToolsLinux.hpp src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp diff --git a/src/components/call/CallModel.cpp b/src/components/call/CallModel.cpp index 6effeff1a..6fba9a6d6 100644 --- a/src/components/call/CallModel.cpp +++ b/src/components/call/CallModel.cpp @@ -88,11 +88,11 @@ CallModel::~CallModel () { // ----------------------------------------------------------------------------- QString CallModel::getPeerAddress () const { - return Utils::coreStringToAppString(mCall->getRemoteAddress()->asString()); + return Utils::coreStringToAppString(mCall->getRemoteAddress()->asStringUriOnly()); } QString CallModel::getLocalAddress () const { - return Utils::coreStringToAppString(mCall->getCallLog()->getFromAddress()->asString()); + return Utils::coreStringToAppString(mCall->getCallLog()->getLocalAddress()->asStringUriOnly()); } // ----------------------------------------------------------------------------- diff --git a/src/components/calls/CallsListModel.cpp b/src/components/calls/CallsListModel.cpp index b5aba1b59..212fb863f 100644 --- a/src/components/calls/CallsListModel.cpp +++ b/src/components/calls/CallsListModel.cpp @@ -192,6 +192,8 @@ void CallsListModel::handleCallStateChanged (const shared_ptr &c case linphone::Call::State::End: case linphone::Call::State::Error: + if (call->getCallLog()->getStatus() == linphone::Call::Status::Missed) + emit callMissed(&call->getData("call-model")); removeCall(call); break; diff --git a/src/components/calls/CallsListModel.hpp b/src/components/calls/CallsListModel.hpp index 1676108b2..8b61d7f35 100644 --- a/src/components/calls/CallsListModel.hpp +++ b/src/components/calls/CallsListModel.hpp @@ -55,6 +55,8 @@ signals: void callRunning (int index, CallModel *callModel); void callTransferAsked (CallModel *callModel); + void callMissed (CallModel *callModel); + private: bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; diff --git a/src/components/chat/ChatModel.hpp b/src/components/chat/ChatModel.hpp index 1eccd3295..b7e312ed7 100644 --- a/src/components/chat/ChatModel.hpp +++ b/src/components/chat/ChatModel.hpp @@ -117,6 +117,8 @@ signals: void messageCountReset (); + void focused (); + private: typedef QPair> ChatEntryData; diff --git a/src/components/chat/ChatProxyModel.cpp b/src/components/chat/ChatProxyModel.cpp index ee45ecf1b..0a90c4430 100644 --- a/src/components/chat/ChatProxyModel.cpp +++ b/src/components/chat/ChatProxyModel.cpp @@ -194,6 +194,7 @@ void ChatProxyModel::reload () { if (mChatModel) { mChatModel->resetMessageCount(); + mChatModel->focused(); ChatModel *chatModel = mChatModel.get(); QObject::connect(chatModel, &ChatModel::isRemoteComposingChanged, this, &ChatProxyModel::handleIsRemoteComposingChanged); @@ -217,8 +218,10 @@ static inline QWindow *getParentWindow (QObject *object) { } void ChatProxyModel::handleIsActiveChanged (QWindow *window) { - if (mChatModel && window->isActive() && getParentWindow(this) == window) + if (mChatModel && window->isActive() && getParentWindow(this) == window) { mChatModel->resetMessageCount(); + mChatModel->focused(); + } } void ChatProxyModel::handleIsRemoteComposingChanged (bool status) { diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index f68d6ce23..5df6e8db1 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -39,9 +39,9 @@ #include "utils/Utils.hpp" #if defined(Q_OS_MACOS) - #include "messages-count-notifier/MessageCountNotifierMacOs.hpp" + #include "event-count-notifier/EventCountNotifierMacOs.hpp" #else - #include "messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp" + #include "event-count-notifier/EventCountNotifierSystemTrayIcon.hpp" #endif // if defined(Q_OS_MACOS) #include "CoreHandlers.hpp" @@ -90,13 +90,13 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : mInstance->mSipAddressesModel = new SipAddressesModel(mInstance); { - MessageCountNotifier *messageCountNotifier = new MessageCountNotifier(mInstance); - messageCountNotifier->updateUnreadMessageCount(); + EventCountNotifier *eventCountNotifier = new EventCountNotifier(mInstance); + eventCountNotifier->updateUnreadMessageCount(); QObject::connect( - messageCountNotifier, &MessageCountNotifier::unreadMessageCountChanged, - mInstance, &CoreManager::unreadMessageCountChanged + eventCountNotifier, &EventCountNotifier::eventCountChanged, + mInstance, &CoreManager::eventCountChanged ); - mInstance->mMessageCountNotifier = messageCountNotifier; + mInstance->mEventCountNotifier = eventCountNotifier; } mInstance->migrate(); @@ -319,8 +319,8 @@ QString CoreManager::getVersion () const { // ----------------------------------------------------------------------------- -int CoreManager::getUnreadMessageCount () const { - return mMessageCountNotifier ? mMessageCountNotifier->getUnreadMessageCount() : 0; +int CoreManager::getEventCount () const { + return mEventCountNotifier ? mEventCountNotifier->getEventCount() : 0; } // ----------------------------------------------------------------------------- diff --git a/src/components/core/CoreManager.hpp b/src/components/core/CoreManager.hpp index 114a452ea..5c29a28b1 100644 --- a/src/components/core/CoreManager.hpp +++ b/src/components/core/CoreManager.hpp @@ -35,7 +35,7 @@ class CallsListModel; class ChatModel; class ContactsListModel; class CoreHandlers; -class MessageCountNotifier; +class EventCountNotifier; class SettingsModel; class SipAddressesModel; class VcardModel; @@ -45,7 +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); + Q_PROPERTY(int eventCount READ getEventCount NOTIFY eventCountChanged); public: bool started () const { @@ -137,7 +137,7 @@ signals: void logsUploaded (const QString &url); - void unreadMessageCountChanged (int count); + void eventCountChanged (int count); private: CoreManager (QObject *parent, const QString &configPath); @@ -151,7 +151,7 @@ private: QString getVersion () const; - int getUnreadMessageCount () const; + int getEventCount () const; void iterate (); @@ -170,7 +170,7 @@ private: SettingsModel *mSettingsModel = nullptr; AccountSettingsModel *mAccountSettingsModel = nullptr; - MessageCountNotifier *mMessageCountNotifier = nullptr; + EventCountNotifier *mEventCountNotifier = nullptr; QHash, std::weak_ptr> mChatModels; diff --git a/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp b/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp new file mode 100644 index 000000000..e03fa5d3d --- /dev/null +++ b/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp @@ -0,0 +1,98 @@ +/* + * AbstractEventCountNotifier.cpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 29, 2017 + * Author: Ronan Abhamon + */ + +#include "components/call/CallModel.hpp" +#include "components/calls/CallsListModel.hpp" +#include "components/chat/ChatModel.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "components/settings/SettingsModel.hpp" + +#include "AbstractEventCountNotifier.hpp" + +// ============================================================================= + +using namespace std; + +AbstractEventCountNotifier::AbstractEventCountNotifier (QObject *parent) : QObject(parent) { + CoreManager *coreManager = CoreManager::getInstance(); + QObject::connect( + coreManager, &CoreManager::chatModelCreated, + this, &AbstractEventCountNotifier::handleChatModelCreated + ); + QObject::connect( + coreManager->getHandlers().get(), &CoreHandlers::messageReceived, + this, &AbstractEventCountNotifier::updateUnreadMessageCount + ); + QObject::connect( + coreManager->getSettingsModel(), &SettingsModel::chatEnabledChanged, + this, &AbstractEventCountNotifier::internalnotifyEventCount + ); + QObject::connect( + coreManager->getCallsListModel(), &CallsListModel::callMissed, + this, &AbstractEventCountNotifier::handleCallMissed + ); +} + +// ----------------------------------------------------------------------------- + +void AbstractEventCountNotifier::updateUnreadMessageCount () { + mUnreadMessageCount = CoreManager::getInstance()->getCore()->getUnreadChatMessageCountFromActiveLocals(); + internalnotifyEventCount(); +} + +void AbstractEventCountNotifier::internalnotifyEventCount () { + int n = mUnreadMessageCount + getMissedCallCount(); + qInfo() << QStringLiteral("Notify event count: %1.").arg(n); + n = n > 99 ? 99 : n; + + notifyEventCount(CoreManager::getInstance()->getSettingsModel()->getChatEnabled() ? n : 0); + emit eventCountChanged(mUnreadMessageCount); +} + +// ----------------------------------------------------------------------------- + +void AbstractEventCountNotifier::handleChatModelCreated (const shared_ptr &chatModel) { + ChatModel *chatModelPtr = chatModel.get(); + QObject::connect( + chatModelPtr, &ChatModel::messageCountReset, + this, &AbstractEventCountNotifier::updateUnreadMessageCount + ); + QObject::connect( + chatModelPtr, &ChatModel::focused, + this, [this, chatModelPtr]() { handleChatModelFocused(chatModelPtr); } + ); +} + +void AbstractEventCountNotifier::handleChatModelFocused (ChatModel *chatModel) { + auto it = mMissedCalls.find({ chatModel->getPeerAddress(), chatModel->getLocalAddress() }); + if (it != mMissedCalls.cend()) { + mMissedCalls.erase(it); + internalnotifyEventCount(); + } +} + +void AbstractEventCountNotifier::handleCallMissed (CallModel *callModel) { + Q_UNUSED(callModel); + ++mMissedCalls[{ callModel->getPeerAddress(), callModel->getLocalAddress() }]; + internalnotifyEventCount(); +} diff --git a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp b/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp similarity index 58% rename from src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp rename to src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp index 550d084fa..5ed3d5349 100644 --- a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.hpp +++ b/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp @@ -1,5 +1,5 @@ /* - * AbstractMessageCountNotifier.hpp + * AbstractEventCountNotifier.hpp * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -20,12 +20,14 @@ * Author: Ronan Abhamon */ -#ifndef ABSTRACT_MESSAGE_COUNT_NOTIFIER_H_ -#define ABSTRACT_MESSAGE_COUNT_NOTIFIER_H_ +#ifndef ABSTRACT_EVENT_COUNT_NOTIFIER_H_ +#define ABSTRACT_EVENT_COUNT_NOTIFIER_H_ #include +#include #include +#include // ============================================================================= @@ -33,32 +35,44 @@ namespace linphone { class ChatMessage; } +class CallModel; class ChatModel; -class AbstractMessageCountNotifier : public QObject { +class AbstractEventCountNotifier : public QObject { Q_OBJECT; public: - AbstractMessageCountNotifier (QObject *parent = Q_NULLPTR); + AbstractEventCountNotifier (QObject *parent = Q_NULLPTR); void updateUnreadMessageCount (); - int getUnreadMessageCount () const { - return mUnreadMessageCount; + int getUnreadMessageCount () const { return mUnreadMessageCount; } + int getMissedCallCount () const { + int t = 0; + for (int n : mMissedCalls) t += n; + return t; } + int getEventCount () const { return mUnreadMessageCount + getMissedCallCount(); } + signals: - void unreadMessageCountChanged (int count); + void eventCountChanged (int count); protected: - virtual void notifyUnreadMessageCount (int n) = 0; + virtual void notifyEventCount (int n) = 0; private: - void internalNotifyUnreadMessageCount (); + using ConferenceId = QPair; + + void internalnotifyEventCount (); void handleChatModelCreated (const std::shared_ptr &chatModel); + void handleChatModelFocused (ChatModel *chatModel); + void handleCallMissed (CallModel *callModel); + + QHash mMissedCalls; int mUnreadMessageCount = 0; }; -#endif // ABSTRACT_MESSAGE_COUNT_NOTIFIER_H_ +#endif // ABSTRACT_EVENT_COUNT_NOTIFIER_H_ diff --git a/src/components/core/messages-count-notifier/MessageCountNotifierMacOs.hpp b/src/components/core/event-count-notifier/EventCountNotifierMacOs.hpp similarity index 65% rename from src/components/core/messages-count-notifier/MessageCountNotifierMacOs.hpp rename to src/components/core/event-count-notifier/EventCountNotifierMacOs.hpp index 6f21856f9..48e5f126e 100644 --- a/src/components/core/messages-count-notifier/MessageCountNotifierMacOs.hpp +++ b/src/components/core/event-count-notifier/EventCountNotifierMacOs.hpp @@ -1,5 +1,5 @@ /* - * MessageCountNotifierMacOs.hpp + * EventCountNotifierMacOs.hpp * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -20,22 +20,22 @@ * Author: Ghislain MARY */ -#ifndef MESSAGE_COUNT_NOTIFIER_MAC_OS_H_ -#define MESSAGE_COUNT_NOTIFIER_MAC_OS_H_ +#ifndef EVENT_COUNT_NOTIFIER_MAC_OS_H_ +#define EVENT_COUNT_NOTIFIER_MAC_OS_H_ -#include "AbstractMessageCountNotifier.hpp" +#include "AbstractEventCountNotifier.hpp" // ============================================================================= -extern "C" void notifyUnreadMessageCountMacOs (int n); +extern "C" void notifyEventCountMacOs (int n); -class MessageCountNotifier : public AbstractMessageCountNotifier { +class EventCountNotifier : public AbstractEventCountNotifier { public: - MessageCountNotifier (QObject *parent = Q_NULLPTR) : AbstractMessageCountNotifier(parent) {} + EventCountNotifier (QObject *parent = Q_NULLPTR) : AbstractEventCountNotifier(parent) {} - void notifyUnreadMessageCount (int n) override { - notifyUnreadMessageCountMacOs(n); + void notifyEventCount (int n) override { + notifyEventCountMacOs(n); } }; -#endif // MESSAGE_COUNT_NOTIFIER_MAC_OS_H_ +#endif // EVENT_COUNT_NOTIFIER_MAC_OS_H_ diff --git a/src/components/core/messages-count-notifier/MessageCountNotifierMacOs.m b/src/components/core/event-count-notifier/EventCountNotifierMacOs.m similarity index 93% rename from src/components/core/messages-count-notifier/MessageCountNotifierMacOs.m rename to src/components/core/event-count-notifier/EventCountNotifierMacOs.m index 9ecd692d0..7d5d777b1 100644 --- a/src/components/core/messages-count-notifier/MessageCountNotifierMacOs.m +++ b/src/components/core/event-count-notifier/EventCountNotifierMacOs.m @@ -1,5 +1,5 @@ /* - * MessageCountNotifierMacOS.m + * EventCountNotifierMacOs.m * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -24,7 +24,7 @@ // ============================================================================= -void notifyUnreadMessageCountMacOs (int n) { +void notifyEventCountMacOs (int n) { NSString *badgeStr = (n > 0) ? [NSString stringWithFormat:@"%d", n] : @""; [[NSApp dockTile] setBadgeLabel:badgeStr]; } diff --git a/src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.cpp b/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp similarity index 86% rename from src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.cpp rename to src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp index 06ebac3ac..345916fb7 100644 --- a/src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.cpp +++ b/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp @@ -1,5 +1,5 @@ /* - * MessageCountNotifierSystemTrayIcon.hpp + * EventCountNotifierSystemTrayIcon.hpp * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -31,7 +31,7 @@ #include "utils/LinphoneUtils.hpp" #include "utils/Utils.hpp" -#include "MessageCountNotifierSystemTrayIcon.hpp" +#include "EventCountNotifierSystemTrayIcon.hpp" // ============================================================================= @@ -46,7 +46,7 @@ namespace { constexpr int IconCounterTextPixelSize = 144; } -MessageCountNotifier::MessageCountNotifier (QObject *parent) : AbstractMessageCountNotifier(parent) { +EventCountNotifier::EventCountNotifier (QObject *parent) : AbstractEventCountNotifier(parent) { QSvgRenderer renderer((QString(LinphoneUtils::WindowIconPath))); if (!renderer.isValid()) qFatal("Invalid SVG Image."); @@ -62,20 +62,20 @@ MessageCountNotifier::MessageCountNotifier (QObject *parent) : AbstractMessageCo mBlinkTimer = new QTimer(this); mBlinkTimer->setInterval(IconCounterBlinkInterval); - QObject::connect(mBlinkTimer, &QTimer::timeout, this, &MessageCountNotifier::update); + QObject::connect(mBlinkTimer, &QTimer::timeout, this, &EventCountNotifier::update); Utils::connectOnce( App::getInstance(), &App::focusWindowChanged, - this, &MessageCountNotifier::updateUnreadMessageCount + this, &EventCountNotifier::updateUnreadMessageCount ); } -MessageCountNotifier::~MessageCountNotifier () { +EventCountNotifier::~EventCountNotifier () { delete mBuf; delete mBufWithCounter; } -void MessageCountNotifier::notifyUnreadMessageCount (int n) { +void EventCountNotifier::notifyEventCount (int n) { QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon(); if (!sysTrayIcon) return; @@ -115,7 +115,7 @@ void MessageCountNotifier::notifyUnreadMessageCount (int n) { update(); } -void MessageCountNotifier::update () { +void EventCountNotifier::update () { QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon(); Q_CHECK_PTR(sysTrayIcon); sysTrayIcon->setIcon(QIcon(mDisplayCounter ? *mBufWithCounter : *mBuf)); diff --git a/src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp b/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.hpp similarity index 72% rename from src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp rename to src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.hpp index 3b1e171a1..61cfcf7f1 100644 --- a/src/components/core/messages-count-notifier/MessageCountNotifierSystemTrayIcon.hpp +++ b/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.hpp @@ -1,5 +1,5 @@ /* - * MessageCountNotifierSystemTrayIcon.hpp + * EventCountNotifierSystemTrayIcon.hpp * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -20,22 +20,22 @@ * Author: Ronan Abhamon */ -#ifndef MESSAGE_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ -#define MESSAGE_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ +#ifndef EVENT_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ +#define EVENT_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ -#include "AbstractMessageCountNotifier.hpp" +#include "AbstractEventCountNotifier.hpp" // ============================================================================= class QTimer; -class MessageCountNotifier : public AbstractMessageCountNotifier { +class EventCountNotifier : public AbstractEventCountNotifier { public: - MessageCountNotifier (QObject *parent = Q_NULLPTR); - ~MessageCountNotifier (); + EventCountNotifier (QObject *parent = Q_NULLPTR); + ~EventCountNotifier (); protected: - void notifyUnreadMessageCount (int n) override; + void notifyEventCount (int n) override; private: void update (); @@ -46,4 +46,4 @@ private: bool mDisplayCounter = false; }; -#endif // MESSAGE_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ +#endif // EVENT_COUNT_NOTIFIER_SYSTEM_TRAY_ICON_H_ diff --git a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp b/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp deleted file mode 100644 index 2b7fc674b..000000000 --- a/src/components/core/messages-count-notifier/AbstractMessageCountNotifier.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * AbstractMessageCountNotifier.cpp - * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Created on: June 29, 2017 - * Author: Ronan Abhamon - */ - -#include "components/chat/ChatModel.hpp" -#include "components/core/CoreHandlers.hpp" -#include "components/core/CoreManager.hpp" -#include "components/settings/SettingsModel.hpp" - -#include "AbstractMessageCountNotifier.hpp" - -// ============================================================================= - -using namespace std; - -AbstractMessageCountNotifier::AbstractMessageCountNotifier (QObject *parent) : QObject(parent) { - CoreManager *coreManager = CoreManager::getInstance(); - QObject::connect( - coreManager, &CoreManager::chatModelCreated, - this, &AbstractMessageCountNotifier::handleChatModelCreated - ); - QObject::connect( - coreManager->getHandlers().get(), &CoreHandlers::messageReceived, - this, &AbstractMessageCountNotifier::updateUnreadMessageCount - ); - QObject::connect( - coreManager->getSettingsModel(), &SettingsModel::chatEnabledChanged, - this, &AbstractMessageCountNotifier::internalNotifyUnreadMessageCount - ); -} - -// ----------------------------------------------------------------------------- - -void AbstractMessageCountNotifier::updateUnreadMessageCount () { - mUnreadMessageCount = CoreManager::getInstance()->getCore()->getUnreadChatMessageCountFromActiveLocals(); - internalNotifyUnreadMessageCount(); -} - -void AbstractMessageCountNotifier::internalNotifyUnreadMessageCount () { - qInfo() << QStringLiteral("Notify unread messages count: %1.").arg(mUnreadMessageCount); - int n = mUnreadMessageCount > 99 ? 99 : mUnreadMessageCount; - - notifyUnreadMessageCount(CoreManager::getInstance()->getSettingsModel()->getChatEnabled() ? n : 0); - unreadMessageCountChanged(mUnreadMessageCount); -} - -// ----------------------------------------------------------------------------- - -void AbstractMessageCountNotifier::handleChatModelCreated (const shared_ptr &chatModel) { - QObject::connect( - chatModel.get(), &ChatModel::messageCountReset, - this, &AbstractMessageCountNotifier::updateUnreadMessageCount - ); -} diff --git a/src/components/settings/AccountSettingsModel.cpp b/src/components/settings/AccountSettingsModel.cpp index 4843b83f2..276864e1a 100644 --- a/src/components/settings/AccountSettingsModel.cpp +++ b/src/components/settings/AccountSettingsModel.cpp @@ -59,7 +59,7 @@ AccountSettingsModel::AccountSettingsModel (QObject *parent) : QObject(parent) { coreManager->getHandlers().get(), &CoreHandlers::registrationStateChanged, this, &AccountSettingsModel::handleRegistrationStateChanged ); - QObject::connect(coreManager, &CoreManager::unreadMessageCountChanged, this, [this]() { emit accountSettingsUpdated(); }); + QObject::connect(coreManager, &CoreManager::eventCountChanged, this, [this]() { emit accountSettingsUpdated(); }); } // ----------------------------------------------------------------------------- diff --git a/ui/modules/Linphone/Account/AccountStatus.qml b/ui/modules/Linphone/Account/AccountStatus.qml index b273651d0..6d0233642 100644 --- a/ui/modules/Linphone/Account/AccountStatus.qml +++ b/ui/modules/Linphone/Account/AccountStatus.qml @@ -83,7 +83,7 @@ Item { id: messageCounter anchors.fill: parent - count: CoreManager.unreadMessageCount + count: CoreManager.eventCount } } }