diff --git a/CMakeLists.txt b/CMakeLists.txt index 4507f126e..b5469602c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/app/App.cpp b/src/app/App.cpp index 3739b64bd..b907186e6 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -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" diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index 9f1994f02..9e7719f4f 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -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" diff --git a/src/components/core/MessagesCountNotifier.cpp b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp similarity index 60% rename from src/components/core/MessagesCountNotifier.cpp rename to src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp index 7186c416e..e0ddd1cd0 100644 --- a/src/components/core/MessagesCountNotifier.cpp +++ b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp @@ -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) { +void AbstractMessagesCountNotifier::handleChatModelCreated (const shared_ptr &chatModel) { QObject::connect( chatModel.get(), &ChatModel::messagesCountReset, - this, &MessagesCountNotifier::updateUnreadMessagesCount + this, &AbstractMessagesCountNotifier::updateUnreadMessagesCount ); } -void MessagesCountNotifier::handleMessageReceived (const shared_ptr &) { +void AbstractMessagesCountNotifier::handleMessageReceived (const shared_ptr &) { mUnreadMessagesCount++; - notifyUnreadMessagesCount(); + internalNotifyUnreadMessagesCount(); } diff --git a/src/components/core/MessagesCountNotifier.hpp b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp similarity index 79% rename from src/components/core/MessagesCountNotifier.hpp rename to src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp index 67c37d452..60e7376a9 100644 --- a/src/components/core/MessagesCountNotifier.hpp +++ b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp @@ -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); void handleMessageReceived (const std::shared_ptr &message); diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp new file mode 100644 index 000000000..d795f9677 --- /dev/null +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp @@ -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 + +#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; +} diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp new file mode 100644 index 000000000..ee1a6d208 --- /dev/null +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp @@ -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; +}; diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp new file mode 100644 index 000000000..b8eefd804 --- /dev/null +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp @@ -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); + } +}; diff --git a/src/components/core/MessagesCountNotifierMacOS.m b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m similarity index 88% rename from src/components/core/MessagesCountNotifierMacOS.m rename to src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m index 4483bbece..89f5fb8c5 100644 --- a/src/components/core/MessagesCountNotifierMacOS.m +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m @@ -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]; } diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierWindows.cpp b/src/components/core/messages-count-notifier/MessagesCountNotifierWindows.cpp new file mode 100644 index 000000000..118ed22ae --- /dev/null +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierWindows.cpp @@ -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; +} diff --git a/src/components/core/MessagesCountNotifierMacOS.h b/src/components/core/messages-count-notifier/MessagesCountNotifierWindows.hpp similarity index 72% rename from src/components/core/MessagesCountNotifierMacOS.h rename to src/components/core/messages-count-notifier/MessagesCountNotifierWindows.hpp index 8967973fd..9269c5296 100644 --- a/src/components/core/MessagesCountNotifierMacOS.h +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierWindows.hpp @@ -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; +}; diff --git a/src/utils/LinphoneUtils.hpp b/src/utils/LinphoneUtils.hpp index 5d3480acc..a4b91f468 100644 --- a/src/utils/LinphoneUtils.hpp +++ b/src/utils/LinphoneUtils.hpp @@ -28,6 +28,8 @@ // ============================================================================= +#define WINDOW_ICON_PATH ":/assets/images/linphone_logo.svg" + #define VU_MIN (-20.f) #define VU_MAX (4.f)