mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-17 11:28:07 +00:00
feat(call): display the missed call count in the tray icon + in the account status
This commit is contained in:
parent
7d9ead5b7f
commit
39c096fb47
17 changed files with 188 additions and 139 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -192,6 +192,8 @@ void CallsListModel::handleCallStateChanged (const shared_ptr<linphone::Call> &c
|
|||
|
||||
case linphone::Call::State::End:
|
||||
case linphone::Call::State::Error:
|
||||
if (call->getCallLog()->getStatus() == linphone::Call::Status::Missed)
|
||||
emit callMissed(&call->getData<CallModel>("call-model"));
|
||||
removeCall(call);
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -117,6 +117,8 @@ signals:
|
|||
|
||||
void messageCountReset ();
|
||||
|
||||
void focused ();
|
||||
|
||||
private:
|
||||
typedef QPair<QVariantMap, std::shared_ptr<void>> ChatEntryData;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<QPair<QString, QString>, std::weak_ptr<ChatModel>> mChatModels;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
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();
|
||||
}
|
||||
|
|
@ -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 <memory>
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -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<QString, QString>;
|
||||
|
||||
void internalnotifyEventCount ();
|
||||
|
||||
void handleChatModelCreated (const std::shared_ptr<ChatModel> &chatModel);
|
||||
|
||||
void handleChatModelFocused (ChatModel *chatModel);
|
||||
void handleCallMissed (CallModel *callModel);
|
||||
|
||||
QHash<ConferenceId, int> mMissedCalls;
|
||||
int mUnreadMessageCount = 0;
|
||||
};
|
||||
|
||||
#endif // ABSTRACT_MESSAGE_COUNT_NOTIFIER_H_
|
||||
#endif // ABSTRACT_EVENT_COUNT_NOTIFIER_H_
|
||||
|
|
@ -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_
|
||||
|
|
@ -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];
|
||||
}
|
||||
|
|
@ -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));
|
||||
|
|
@ -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_
|
||||
|
|
@ -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> &chatModel) {
|
||||
QObject::connect(
|
||||
chatModel.get(), &ChatModel::messageCountReset,
|
||||
this, &AbstractMessageCountNotifier::updateUnreadMessageCount
|
||||
);
|
||||
}
|
||||
|
|
@ -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(); });
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ Item {
|
|||
id: messageCounter
|
||||
|
||||
anchors.fill: parent
|
||||
count: CoreManager.unreadMessageCount
|
||||
count: CoreManager.eventCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue