mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(MessagesCountNotifier): refactoring
This commit is contained in:
parent
6b28a34ae7
commit
66a0748fef
12 changed files with 219 additions and 53 deletions
|
|
@ -134,10 +134,10 @@ set(SOURCES
|
|||
src/components/contacts/ContactsListProxyModel.cpp
|
||||
src/components/core/CoreHandlers.cpp
|
||||
src/components/core/CoreManager.cpp
|
||||
src/components/core/MessagesCountNotifier.cpp
|
||||
src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp
|
||||
src/components/notifier/Notifier.cpp
|
||||
src/components/other/colors/Colors.cpp
|
||||
src/components/other/clipboard/Clipboard.cpp
|
||||
src/components/other/colors/Colors.cpp
|
||||
src/components/other/text-to-speech/TextToSpeech.cpp
|
||||
src/components/other/units/Units.cpp
|
||||
src/components/presence/OwnPresenceModel.cpp
|
||||
|
|
@ -190,10 +190,10 @@ set(HEADERS
|
|||
src/components/contacts/ContactsListProxyModel.hpp
|
||||
src/components/core/CoreHandlers.hpp
|
||||
src/components/core/CoreManager.hpp
|
||||
src/components/core/MessagesCountNotifier.hpp
|
||||
src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp
|
||||
src/components/notifier/Notifier.hpp
|
||||
src/components/other/colors/Colors.hpp
|
||||
src/components/other/clipboard/Clipboard.hpp
|
||||
src/components/other/colors/Colors.hpp
|
||||
src/components/other/text-to-speech/TextToSpeech.hpp
|
||||
src/components/other/units/Units.hpp
|
||||
src/components/presence/OwnPresenceModel.hpp
|
||||
|
|
@ -226,16 +226,28 @@ set(TESTS
|
|||
set(MAIN_FILE src/app/main.cpp)
|
||||
set(TESTER_MAIN_FILE src/tests/main.cpp)
|
||||
|
||||
if(APPLE)
|
||||
list(APPEND SOURCES src/components/core/MessagesCountNotifierMacOS.m)
|
||||
endif()
|
||||
if(ENABLE_DBUS)
|
||||
if (UNIX AND NOT APPLE)
|
||||
list(APPEND SOURCES src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp)
|
||||
list(APPEND HEADERS src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp)
|
||||
endif ()
|
||||
|
||||
if (WIN32)
|
||||
list(APPEND SOURCES src/components/core/messages-count-notifier/MessagesCountNotifierWindow.cpp)
|
||||
list(APPEND HEADERS src/components/core/messages-count-notifier/MessagesCountNotifierWindow.hpp)
|
||||
endif ()
|
||||
|
||||
if (APPLE)
|
||||
list(APPEND SOURCES src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m)
|
||||
list(APPEND HEADERS src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp)
|
||||
endif ()
|
||||
|
||||
if (ENABLE_DBUS)
|
||||
list(APPEND SOURCES src/app/single-application/SingleApplicationDBus.cpp)
|
||||
list(APPEND HEADERS src/app/single-application/SingleApplicationDBusPrivate.hpp)
|
||||
else()
|
||||
else ()
|
||||
list(APPEND SOURCES src/app/single-application/SingleApplication.cpp)
|
||||
list(APPEND HEADERS src/app/single-application/SingleApplicationPrivate.hpp)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
set(QRC_RESOURCES resources.qrc)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "config.h"
|
||||
|
||||
#include "../components/Components.hpp"
|
||||
#include "../utils/LinphoneUtils.hpp"
|
||||
#include "../utils/Utils.hpp"
|
||||
|
||||
#include "cli/Cli.hpp"
|
||||
|
|
@ -46,7 +47,6 @@
|
|||
#define DEFAULT_LOCALE "en"
|
||||
|
||||
#define LANGUAGES_PATH ":/languages/"
|
||||
#define WINDOW_ICON_PATH ":/assets/images/linphone_logo.svg"
|
||||
|
||||
// The main windows of Linphone desktop.
|
||||
#define QML_VIEW_MAIN_WINDOW "qrc:/ui/views/App/Main/MainWindow.qml"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,14 @@
|
|||
|
||||
#include "../../app/paths/Paths.hpp"
|
||||
#include "../../utils/Utils.hpp"
|
||||
#include "MessagesCountNotifier.hpp"
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include "messages-count-notifier/MessagesCountNotifierLinux.hpp"
|
||||
#elif defined(Q_OS_MACOS)
|
||||
#include "messages-count-notifier/MessagesCountNotifierMacOS.hpp"
|
||||
#elif defined(Q_OS_WIN)
|
||||
#include "messages-count-notifier/MessagesCountNotifierWindows.hpp"
|
||||
#endif // if defined(Q_OS_LINUX)
|
||||
|
||||
#include "CoreManager.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* MessagesCountNotifier.cpp
|
||||
* AbstractMessagesCountNotifier.cpp
|
||||
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
|
@ -20,31 +20,23 @@
|
|||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "../core/CoreManager.hpp"
|
||||
#include "../CoreManager.hpp"
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
// TODO.
|
||||
#elif defined(Q_OS_MACOS)
|
||||
#include "MessagesCountNotifierMacOS.h"
|
||||
#elif defined(Q_OS_WIN)
|
||||
// TODO.
|
||||
#endif // if defined(Q_OS_LINUX)
|
||||
|
||||
#include "MessagesCountNotifier.hpp"
|
||||
#include "AbstractMessagesCountNotifier.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : QObject(parent) {
|
||||
AbstractMessagesCountNotifier::AbstractMessagesCountNotifier (QObject *parent) : QObject(parent) {
|
||||
CoreManager *coreManager = CoreManager::getInstance();
|
||||
QObject::connect(
|
||||
coreManager, &CoreManager::chatModelCreated,
|
||||
this, &MessagesCountNotifier::handleChatModelCreated
|
||||
this, &AbstractMessagesCountNotifier::handleChatModelCreated
|
||||
);
|
||||
QObject::connect(
|
||||
coreManager->getHandlers().get(), &CoreHandlers::messageReceived,
|
||||
this, &MessagesCountNotifier::handleMessageReceived
|
||||
this, &AbstractMessagesCountNotifier::handleMessageReceived
|
||||
);
|
||||
|
||||
updateUnreadMessagesCount();
|
||||
|
|
@ -52,37 +44,33 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : QObject(parent)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void MessagesCountNotifier::updateUnreadMessagesCount () {
|
||||
void AbstractMessagesCountNotifier::notifyUnreadMessagesCount (int) {}
|
||||
|
||||
void AbstractMessagesCountNotifier::updateUnreadMessagesCount () {
|
||||
mUnreadMessagesCount = 0;
|
||||
for (const auto &chatRoom : CoreManager::getInstance()->getCore()->getChatRooms())
|
||||
mUnreadMessagesCount += chatRoom->getUnreadMessagesCount();
|
||||
|
||||
notifyUnreadMessagesCount();
|
||||
internalNotifyUnreadMessagesCount();
|
||||
}
|
||||
|
||||
void MessagesCountNotifier::notifyUnreadMessagesCount () {
|
||||
void AbstractMessagesCountNotifier::internalNotifyUnreadMessagesCount () {
|
||||
qInfo() << QStringLiteral("Notify unread messages count: %1.").arg(mUnreadMessagesCount);
|
||||
int count = mUnreadMessagesCount > 99 ? 99 : mUnreadMessagesCount;
|
||||
int n = mUnreadMessagesCount > 99 ? 99 : mUnreadMessagesCount;
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
(void)count;
|
||||
#elif defined(Q_OS_MACOS)
|
||||
::notifyUnreadMessagesCountMacOS(count);
|
||||
#elif defined(Q_OS_WIN)
|
||||
(void)count;
|
||||
#endif // if defined(Q_OS_LINUX)
|
||||
notifyUnreadMessagesCount(n);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void MessagesCountNotifier::handleChatModelCreated (const shared_ptr<ChatModel> &chatModel) {
|
||||
void AbstractMessagesCountNotifier::handleChatModelCreated (const shared_ptr<ChatModel> &chatModel) {
|
||||
QObject::connect(
|
||||
chatModel.get(), &ChatModel::messagesCountReset,
|
||||
this, &MessagesCountNotifier::updateUnreadMessagesCount
|
||||
this, &AbstractMessagesCountNotifier::updateUnreadMessagesCount
|
||||
);
|
||||
}
|
||||
|
||||
void MessagesCountNotifier::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
|
||||
void AbstractMessagesCountNotifier::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
|
||||
mUnreadMessagesCount++;
|
||||
notifyUnreadMessagesCount();
|
||||
internalNotifyUnreadMessagesCount();
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* MessagesCountNotifier.hpp
|
||||
* AbstractMessagesCountNotifier.hpp
|
||||
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
|
@ -27,21 +27,24 @@
|
|||
// =============================================================================
|
||||
|
||||
namespace linphone {
|
||||
class ChatMessage;
|
||||
class ChatMessage;
|
||||
}
|
||||
|
||||
class ChatModel;
|
||||
|
||||
class MessagesCountNotifier : public QObject {
|
||||
class AbstractMessagesCountNotifier : public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
||||
~MessagesCountNotifier () = default;
|
||||
AbstractMessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
||||
virtual ~AbstractMessagesCountNotifier () = default;
|
||||
|
||||
protected:
|
||||
virtual void notifyUnreadMessagesCount (int n) = 0;
|
||||
|
||||
private:
|
||||
void updateUnreadMessagesCount ();
|
||||
void notifyUnreadMessagesCount ();
|
||||
void internalNotifyUnreadMessagesCount ();
|
||||
|
||||
void handleChatModelCreated (const std::shared_ptr<ChatModel> &chatModel);
|
||||
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* MessagesCountNotifierLinux.hpp
|
||||
* Copyright (C) 2017 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: August 7, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include <QSvgRenderer>
|
||||
|
||||
#include "../../../utils/LinphoneUtils.hpp"
|
||||
|
||||
#include "MessagesCountNotifierLinux.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessagesCountNotifier(parent) {
|
||||
mSvgRenderer = new QSvgRenderer(QStringLiteral(WINDOW_ICON_PATH), this);
|
||||
}
|
||||
|
||||
void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
||||
// TODO.
|
||||
(void)n;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* MessagesCountNotifierLinux.hpp
|
||||
* Copyright (C) 2017 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: August 7, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "AbstractMessagesCountNotifier.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class QSvgRenderer;
|
||||
|
||||
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
|
||||
public:
|
||||
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
||||
|
||||
protected:
|
||||
void notifyUnreadMessagesCount (int n) override;
|
||||
|
||||
private:
|
||||
QSvgRenderer *mSvgRenderer = nullptr;
|
||||
};
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* MessagesCountNotifierMacOs.hpp
|
||||
* Copyright (C) 2017 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 30, 2017
|
||||
* Author: Ghislain MARY
|
||||
*/
|
||||
|
||||
#include "AbstractMessagesCountNotifier.hpp"
|
||||
|
||||
extern "C" void notifyUnreadMessagesCountMacOS (int n);
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
|
||||
public:
|
||||
MessagesCountNotifier (QObject *parent = Q_NULLPTR) : AbstractMessagesCountNotifier(parent) {}
|
||||
|
||||
void notifyUnreadMessagesCount (int n) override {
|
||||
::notifyUnreadMessagesCountMacOS(n);
|
||||
}
|
||||
};
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
void notifyUnreadMessagesCountMacOS(int count) {
|
||||
NSString *badgeStr = (count > 0) ? [NSString stringWithFormat:@"%d", count] : @"";
|
||||
void notifyUnreadMessagesCountMacOS (int n) {
|
||||
NSString *badgeStr = (n > 0) ? [NSString stringWithFormat:@"%d", n] : @"";
|
||||
[[NSApp dockTile] setBadgeLabel:badgeStr];
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* MessagesCountNotifierWindows.cpp
|
||||
* Copyright (C) 2017 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: August 7, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "MessagesCountNotifierWindows.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessagesCountNotifier(parent) {
|
||||
// TODO.
|
||||
}
|
||||
|
||||
void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
||||
// TODO.
|
||||
(void)n;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* MessagesCountNotifierMacOS.h
|
||||
* MessagesCountNotifierWindows.hpp
|
||||
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
|
@ -16,10 +16,18 @@
|
|||
* 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 30, 2017
|
||||
* Author: Ghislain MARY
|
||||
* Created on: August 7, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "AbstractMessagesCountNotifier.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
extern "C" void notifyUnreadMessagesCountMacOS (int count);
|
||||
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
|
||||
public:
|
||||
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
||||
|
||||
protected:
|
||||
void notifyUnreadMessagesCount (int n) override;
|
||||
};
|
||||
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
#define WINDOW_ICON_PATH ":/assets/images/linphone_logo.svg"
|
||||
|
||||
#define VU_MIN (-20.f)
|
||||
#define VU_MAX (4.f)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue