diff --git a/.gitignore b/.gitignore index ff385780..bfd07a85 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,29 @@ CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt + +#####=== OSX ===##### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/CMakeLists.txt b/CMakeLists.txt index ab93957a..3b352730 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ project(nheko CXX) option(BUILD_TESTS "Build all tests" OFF) +# +# Discover Qt dependencies. +# find_package(Qt5Widgets REQUIRED) find_package(Qt5Network REQUIRED) find_package(Qt5LinguistTools REQUIRED) @@ -19,6 +22,9 @@ if (Qt5Widgets_FOUND) endif() endif(Qt5Widgets_FOUND) +# +# Set up compiler flags. +# set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_STANDARD 11) @@ -81,6 +87,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") endif() endif() +# +# Declare source and header files. +# set(SRC_FILES src/AvatarProvider.cc src/ChatPage.cc @@ -205,6 +214,9 @@ qt5_wrap_cpp(MOC_HEADERS include/ui/ThemeManager.h ) +# +# Bundle translations. +# FILE(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts") qt5_add_translation(QM_SRC ${LANG_TS_SRC}) @@ -222,10 +234,24 @@ file(APPEND ${_qrc} " ") qt5_add_resources(LANG_QRC ${_qrc}) qt5_add_resources(QRC resources/res.qrc) +# +# Matrix events library. +# add_library(matrix_events ${MATRIX_EVENTS} src/Deserializable.cc) target_link_libraries(matrix_events Qt5::Core) +# +# Bundle icons. +# +if (APPLE) + set(ICON_FILE resources/nheko.icns) + set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) +endif() + if (BUILD_TESTS) + # + # Build tests. + # enable_testing() find_package(GTest REQUIRED) @@ -244,14 +270,20 @@ if (BUILD_TESTS) add_test(MatrixEventCollection event_collection_test) add_test(MatrixMessageEvents message_events) else() - add_executable (nheko ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC} ${LANG_QRC} ${QM_SRC}) - target_link_libraries (nheko matrix_events Qt5::Widgets Qt5::Network) + # + # Build the executable. + # + SET (NHEKO_LIBS matrix_events Qt5::Widgets Qt5::Network) + set (NHEKO_DEPS ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC} ${LANG_QRC} ${QM_SRC}) - if (APPLE) - target_link_libraries(nheko Qt5::MacExtras) - endif(APPLE) - - if(WIN32) - target_link_libraries(nheko Qt5::WinMain) - endif(WIN32) + if(APPLE) + add_executable (nheko ${NHEKO_DEPS}) + target_link_libraries (nheko ${NHEKO_LIBS} Qt5::MacExtras) + elseif(WIN32) + add_executable (nheko ${ICON_FILE} ${NHEKO_DEPS}) + target_link_libraries (nheko ${NHEKO_LIBS} Qt5::WinMain) + else() + add_executable (nheko ${NHEKO_DEPS}) + target_link_libraries (nheko ${NHEKO_LIBS}) + endif() endif() diff --git a/resources/nheko-1024.png b/resources/nheko-1024.png new file mode 100644 index 00000000..45b19a62 Binary files /dev/null and b/resources/nheko-1024.png differ diff --git a/resources/nheko.icns b/resources/nheko.icns new file mode 100644 index 00000000..ecb66b6f Binary files /dev/null and b/resources/nheko.icns differ diff --git a/scripts/generate_icns.sh b/scripts/generate_icns.sh new file mode 100755 index 00000000..39d7ac77 --- /dev/null +++ b/scripts/generate_icns.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# +# Manually generate icon set for MacOS. +# + +INPUT=$1 +OUTPUT=nheko + +mkdir ${OUTPUT}.iconset + +sips -z 16 16 ${INPUT} --out ${OUTPUT}.iconset/icon_16x16.png +sips -z 32 32 ${INPUT} --out ${OUTPUT}.iconset/icon_16x16@2x.png +sips -z 32 32 ${INPUT} --out ${OUTPUT}.iconset/icon_32x32.png +sips -z 64 64 ${INPUT} --out ${OUTPUT}.iconset/icon_32x32@2x.png +sips -z 128 128 ${INPUT} --out ${OUTPUT}.iconset/icon_128x128.png +sips -z 256 256 ${INPUT} --out ${OUTPUT}.iconset/icon_128x128@2x.png +sips -z 256 256 ${INPUT} --out ${OUTPUT}.iconset/icon_256x256.png +sips -z 512 512 ${INPUT} --out ${OUTPUT}.iconset/icon_256x256@2x.png +sips -z 512 512 ${INPUT} --out ${OUTPUT}.iconset/icon_512x512.png + +cp ${INPUT} ${OUTPUT}.iconset/icon_512x512@2x.png + +iconutil -c icns ${OUTPUT}.iconset + +rm -R ${OUTPUT}.iconset diff --git a/src/TrayIcon.cc b/src/TrayIcon.cc index 7e649077..e6a10444 100644 --- a/src/TrayIcon.cc +++ b/src/TrayIcon.cc @@ -70,8 +70,12 @@ QIconEngine *MsgCountComposedIcon::clone() const TrayIcon::TrayIcon(const QString &filename, QWidget *parent) : QSystemTrayIcon(parent) { +#if defined(Q_OS_MAC) || defined(Q_OS_WIN) + setIcon(QIcon(filename)); +#else icon_ = new MsgCountComposedIcon(filename); setIcon(QIcon(icon_)); +#endif QMenu *menu = new QMenu(parent); viewAction_ = new QAction(tr("Show"), parent); @@ -95,12 +99,17 @@ TrayIcon::TrayIcon(const QString &filename, QWidget *parent) void TrayIcon::setUnreadCount(int count) { +// Use the native badge counter in MacOS. #if defined(Q_OS_MAC) if (count == 0) QtMac::setBadgeLabelText(""); else QtMac::setBadgeLabelText(QString::number(count)); +#elif defined(Q_OS_WIN) +// FIXME: Find a way to use Windows apis for the badge counter (if any). #else + // Custom drawing on Linux. + // FIXME: It doesn't seem to work on KDE. MsgCountComposedIcon *tmp = static_cast(icon_->clone()); tmp->msgCount = count;