From 3893e2882ffce14c4dd8c8357c4595b27066e19d Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 30 Jun 2017 15:18:13 +0200 Subject: [PATCH] Implement display of unread messages count on the application icon in the dock on Mac OS X. --- CMakeLists.txt | 6 ++++ src/components/core/MessagesCountNotifier.cpp | 12 +++++-- .../core/MessagesCountNotifierMacOS.h | 26 ++++++++++++++++ .../core/MessagesCountNotifierMacOS.m | 31 +++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/components/core/MessagesCountNotifierMacOS.h create mode 100644 src/components/core/MessagesCountNotifierMacOS.m diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f5533146..6b860de9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,9 @@ set(HEADERS src/utils/Utils.hpp ) +if(APPLE) + list(APPEND SOURCES src/components/core/MessagesCountNotifierMacOS.m) +endif() if(ENABLE_DBUS) list(APPEND SOURCES src/app/single-application/SingleApplicationDBus.cpp) list(APPEND HEADERS src/app/single-application/SingleApplicationDBusPrivate.hpp) @@ -348,6 +351,9 @@ foreach (package ${QT5_PACKAGES_OPTIONAL}) endforeach () target_link_libraries(${TARGET_NAME} ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES}) +if(APPLE) + target_link_libraries(${TARGET_NAME} "-framework Cocoa") +endif() install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/src/components/core/MessagesCountNotifier.cpp b/src/components/core/MessagesCountNotifier.cpp index e54e3607c..beb69752b 100644 --- a/src/components/core/MessagesCountNotifier.cpp +++ b/src/components/core/MessagesCountNotifier.cpp @@ -24,6 +24,14 @@ #include "MessagesCountNotifier.hpp" +#if defined(Q_OS_LINUX) + // TODO. +#elif defined(Q_OS_MACOS) + #include "MessagesCountNotifierMacOS.h" +#elif defined(Q_OS_WIN) + // TODO. +#endif + using namespace std; // ============================================================================= @@ -58,10 +66,10 @@ void MessagesCountNotifier::notifyUnreadMessagesCount () { #if defined(Q_OS_LINUX) // TODO. #elif defined(Q_OS_MACOS) - // TODO. + ::notifyUnreadMessagesCountMacOS(mUnreadMessagesCount); #elif defined(Q_OS_WIN) // TODO. - #endif // ifdef Q_OS_LINUX + #endif } // ----------------------------------------------------------------------------- diff --git a/src/components/core/MessagesCountNotifierMacOS.h b/src/components/core/MessagesCountNotifierMacOS.h new file mode 100644 index 000000000..c49c3666f --- /dev/null +++ b/src/components/core/MessagesCountNotifierMacOS.h @@ -0,0 +1,26 @@ +/* + * MessagesCountNotifierMacOS.h + * 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 + */ + +// ============================================================================= + +extern "C" void notifyUnreadMessagesCountMacOS(int count); + diff --git a/src/components/core/MessagesCountNotifierMacOS.m b/src/components/core/MessagesCountNotifierMacOS.m new file mode 100644 index 000000000..940c27ada --- /dev/null +++ b/src/components/core/MessagesCountNotifierMacOS.m @@ -0,0 +1,31 @@ +/* + * MessagesCountNotifierMacOS.m + * 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 + */ + +#import + +// ============================================================================= + +void notifyUnreadMessagesCountMacOS(int count) { + NSString *badgeStr = (count > 0) ? [NSString stringWithFormat:@"%d", count] : @""; + [[NSApp dockTile] setBadgeLabel:badgeStr]; +} +