diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,10 @@ # Dependencies set(REQUIRED_QT_VERSION 5.9.0) -find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets DBus) +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets) +if (NOT ANDROID) + find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED DBus) +endif() find_package(Qt5 ${REQUIRED_QT_VERSION} QUIET OPTIONAL_COMPONENTS TextToSpeech) set_package_properties(Qt5TextToSpeech PROPERTIES DESCRIPTION "Qt text to speech module" @@ -113,6 +116,10 @@ include(CMakePackageConfigHelpers) +set(HAVE_DBUS FALSE) +if (TARGET Qt5::DBus) + set(HAVE_DBUS TRUE) +endif() configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5NotificationsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5NotificationsConfig.cmake" diff --git a/KF5NotificationsConfig.cmake.in b/KF5NotificationsConfig.cmake.in --- a/KF5NotificationsConfig.cmake.in +++ b/KF5NotificationsConfig.cmake.in @@ -4,7 +4,9 @@ include(CMakeFindDependencyMacro) find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@) -find_dependency(Qt5DBus @REQUIRED_QT_VERSION@) +if (@HAVE_DBUS@) + find_dependency(Qt5DBus @REQUIRED_QT_VERSION@) +endif() include("${CMAKE_CURRENT_LIST_DIR}/KF5NotificationsTargets.cmake") @PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -7,5 +7,7 @@ return() endif() -set(KNotificationTest_SRCS knotification_test.cpp fake_notifications_server.cpp) -ecm_add_test(${KNotificationTest_SRCS} TEST_NAME "KNotificationTest" LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Notifications) +if (TARGET Qt5::DBus) + set(KNotificationTest_SRCS knotification_test.cpp fake_notifications_server.cpp) + ecm_add_test(${KNotificationTest_SRCS} TEST_NAME "KNotificationTest" LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Notifications) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,22 +12,28 @@ knotification.cpp knotificationmanager.cpp kpassivepopup.cpp - kstatusnotifieritem.cpp - kstatusnotifieritemdbus_p.cpp - knotificationrestrictions.cpp knotifyconfig.cpp knotificationplugin.cpp - notifybypopup.cpp - imageconverter.cpp #needed to marshal images for sending over dbus by NotifyByPopup notifybypopupgrowl.cpp notifybyexecute.cpp - notifybyportal.cpp notifybylogfile.cpp notifybytaskbar.cpp ${knotifications_QM_LOADER} ) +if (TARGET Qt5::DBus) + list(APPEND knotifications_SRCS + kstatusnotifieritem.cpp + kstatusnotifieritemdbus_p.cpp + knotificationrestrictions.cpp + + imageconverter.cpp #needed to marshal images for sending over dbus by NotifyByPopup + notifybypopup.cpp + notifybyportal.cpp + ) +endif() + ecm_qt_declare_logging_category(knotifications_SRCS HEADER debug_p.h IDENTIFIER LOG_KNOTIFICATIONS CATEGORY_NAME org.kde.knotifications) if (CANBERRA_FOUND) @@ -55,14 +61,16 @@ set(HAVE_DBUSMENUQT 0) endif() -qt5_add_dbus_adaptor(knotifications_SRCS org.kde.StatusNotifierItem.xml - kstatusnotifieritemdbus_p.h KStatusNotifierItemDBus) +if (TARGET Qt5::DBus) + qt5_add_dbus_adaptor(knotifications_SRCS org.kde.StatusNotifierItem.xml + kstatusnotifieritemdbus_p.h KStatusNotifierItemDBus) -set(statusnotifierwatcher_xml org.kde.StatusNotifierWatcher.xml) -qt5_add_dbus_interface(knotifications_SRCS ${statusnotifierwatcher_xml} statusnotifierwatcher_interface) -set(notifications_xml org.freedesktop.Notifications.xml) -qt5_add_dbus_interface(knotifications_SRCS ${notifications_xml} notifications_interface) + set(statusnotifierwatcher_xml org.kde.StatusNotifierWatcher.xml) + qt5_add_dbus_interface(knotifications_SRCS ${statusnotifierwatcher_xml} statusnotifierwatcher_interface) + set(notifications_xml org.freedesktop.Notifications.xml) + qt5_add_dbus_interface(knotifications_SRCS ${notifications_xml} notifications_interface) +endif() configure_file(config-knotifications.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-knotifications.h ) @@ -74,8 +82,10 @@ target_link_libraries(KF5Notifications PUBLIC Qt5::Widgets - Qt5::DBus ) +if (TARGET Qt5::DBus) + target_link_libraries(KF5Notifications PUBLIC Qt5::DBus) +endif() target_link_libraries(KF5Notifications PRIVATE KF5::CoreAddons KF5::ConfigCore @@ -161,15 +171,17 @@ ) endif() -install(FILES - org.kde.StatusNotifierItem.xml - DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} - RENAME kf5_org.kde.StatusNotifierItem.xml) +if (TARGET Qt5::DBus) + install(FILES + org.kde.StatusNotifierItem.xml + DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} + RENAME kf5_org.kde.StatusNotifierItem.xml) -install(FILES - org.kde.StatusNotifierWatcher.xml - DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} - RENAME kf5_org.kde.StatusNotifierWatcher.xml) + install(FILES + org.kde.StatusNotifierWatcher.xml + DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} + RENAME kf5_org.kde.StatusNotifierWatcher.xml) +endif() install(FILES knotificationplugin.desktop diff --git a/src/knotificationmanager.cpp b/src/knotificationmanager.cpp --- a/src/knotificationmanager.cpp +++ b/src/knotificationmanager.cpp @@ -23,22 +23,27 @@ #include #include -#include #include #include #include -#include #include #include +#ifdef QT_DBUS_LIB +#include +#include +#endif + #include "knotifyconfig.h" #include "knotificationplugin.h" -#include "notifybypopup.h" #include "notifybylogfile.h" #include "notifybytaskbar.h" #include "notifybyexecute.h" +#ifndef Q_OS_ANDROID +#include "notifybypopup.h" #include "notifybyportal.h" +#endif #include "debug_p.h" #if defined(HAVE_CANBERRA) @@ -93,6 +98,7 @@ d->inSandbox = true; } +#ifdef QT_DBUS_LIB if (d->inSandbox) { QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface(); d->portalDBusServiceExists = interface->isServiceRegistered(QStringLiteral("org.freedesktop.portal.Desktop")); @@ -104,6 +110,7 @@ QStringLiteral("reparseConfiguration"), this, SLOT(reparseConfiguration(QString))); +#endif } KNotificationManager::~KNotificationManager() @@ -132,11 +139,13 @@ // We have a series of built-ins up first, and fall back to trying // to instantiate an externally supplied plugin. if (action == QLatin1String("Popup")) { +#ifndef Q_OS_ANDROID if (d->inSandbox && d->portalDBusServiceExists) { plugin = new NotifyByPortal(this); } else { plugin = new NotifyByPopup(this); } +#endif addPlugin(plugin); } else if (action == QLatin1String("Taskbar")) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,12 +8,14 @@ endforeach(_testname) endmacro() -knotifications_executable_tests( - knotificationrestrictionstest - kpassivepopuptest - unitylaunchertest - kstatusnotifieritemtest - knotificationdbustest -) +if (TARGET Qt5::DBus) + knotifications_executable_tests( + knotificationrestrictionstest + kpassivepopuptest + unitylaunchertest + kstatusnotifieritemtest + knotificationdbustest + ) -target_link_libraries(kpassivepopuptest KF5::WindowSystem) + target_link_libraries(kpassivepopuptest KF5::WindowSystem) +endif()