From 7f46e579c59f43b460148432f5d7e43f0b337baf Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Fri, 24 Jul 2015 01:30:16 +0200 Subject: [PATCH] use ECMOptionalAddSubdirectory --- CMakeLists.txt | 6 +- src/CMakeLists.txt | 6 +- src/plugins/CMakeLists.txt | 8 +- src/plugins/backends/CMakeLists.txt | 14 +- .../CMakeLists.txt | 2 +- .../fredesktopnotification.cpp | 0 .../fredesktopnotification.h | 0 .../freedesktopnotification_backend.cpp | 0 ...freedesktopnotification_backend.cpp.Wm2740 | 166 ++++++++++++++++++ .../freedesktopnotification_backend.h | 0 .../plugin.json | 0 src/plugins/frontends/CMakeLists.txt | 9 +- .../CMakeLists.txt | 6 +- .../freedesktopnotificationfrontend.cpp | 2 +- .../freedesktopnotificationfrontend.h | 0 ...rg.freedesktop.Notifications.service.cmake | 0 .../org.freedesktop.Notifications.xml | 0 .../plugin.json | 0 .../CMakeLists.txt | 0 .../plugin.json | 0 .../pushover_frontend.cpp | 0 .../pushover_frontend.h | 0 .../pushoversettings.cpp | 0 .../pushoversettings.h | 0 src/plugins/secondary_backends/CMakeLists.txt | 8 +- .../CMakeLists.txt | 0 .../plugin.json | 0 .../pushover.cpp | 0 .../{pushover => pushover_backend}/pushover.h | 0 .../pushoversettings.cpp | 0 .../pushoversettings.h | 0 31 files changed, 193 insertions(+), 34 deletions(-) rename src/plugins/backends/{freedesktop => freedesktop_backend}/CMakeLists.txt (88%) rename src/plugins/backends/{freedesktop => freedesktop_backend}/fredesktopnotification.cpp (100%) rename src/plugins/backends/{freedesktop => freedesktop_backend}/fredesktopnotification.h (100%) rename src/plugins/backends/{freedesktop => freedesktop_backend}/freedesktopnotification_backend.cpp (100%) create mode 100644 src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp.Wm2740 rename src/plugins/backends/{freedesktop => freedesktop_backend}/freedesktopnotification_backend.h (100%) rename src/plugins/backends/{freedesktop => freedesktop_backend}/plugin.json (100%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/CMakeLists.txt (91%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/freedesktopnotificationfrontend.cpp (98%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/freedesktopnotificationfrontend.h (100%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/org.freedesktop.Notifications.service.cmake (100%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/org.freedesktop.Notifications.xml (100%) rename src/plugins/frontends/{freedesktop => freedesktop_frontend}/plugin.json (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/CMakeLists.txt (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/plugin.json (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/pushover_frontend.cpp (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/pushover_frontend.h (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/pushoversettings.cpp (100%) rename src/plugins/frontends/{pushover => pushover_frontend}/pushoversettings.h (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/CMakeLists.txt (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/plugin.json (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/pushover.cpp (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/pushover.h (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/pushoversettings.cpp (100%) rename src/plugins/secondary_backends/{pushover => pushover_backend}/pushoversettings.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed2b9e..d995457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,13 +21,9 @@ include(ECMAddAppIcon) include(ECMGeneratePriFile) include(ECMInstallIcons) include(ECMPackageConfigHelpers) +include(ECMOptionalAddSubdirectory) include(ECMSetupVersion) -####################################################################### -option(WITH_FRONTENDS "Build frontends currently only useful if WITH_SNORE_DAEMON=ON." OFF) -option(WITH_SNORE_DAEMON "Build the Snore daemon, which redirects notifications." OFF) -option(WITH_SNORE_SEND "Build snore-send, a cli for snore notifications." ON) -####################################################################### set(SNORE_VERSION_MAJOR 0) set(SNORE_VERSION_MINOR 5) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6653e0a..f6e290e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(libsnore) -add_subdirectory(daemon) -add_subdirectory(settings) -add_subdirectory(snoresend) +ecm_optional_add_subdirectory(daemon) +ecm_optional_add_subdirectory(settings) +ecm_optional_add_subdirectory(snoresend) add_subdirectory(plugins) diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 9c00798..2666fc9 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(backends) -add_subdirectory(frontends) -add_subdirectory(secondary_backends) -add_subdirectory(plugins) +ecm_optional_add_subdirectory(backends) +ecm_optional_add_subdirectory(frontends) +ecm_optional_add_subdirectory(secondary_backends) +ecm_optional_add_subdirectory(plugins) diff --git a/src/plugins/backends/CMakeLists.txt b/src/plugins/backends/CMakeLists.txt index c7d4c66..6dd98b1 100644 --- a/src/plugins/backends/CMakeLists.txt +++ b/src/plugins/backends/CMakeLists.txt @@ -1,7 +1,7 @@ -add_subdirectory(freedesktop) -add_subdirectory(snarl) -add_subdirectory(growl) -add_subdirectory(trayicon) -add_subdirectory(snoretoast) -add_subdirectory(snore) -add_subdirectory(osxnotificationcenter) +ecm_optional_add_subdirectory(freedesktop_backend) +ecm_optional_add_subdirectory(snarl) +ecm_optional_add_subdirectory(growl) +ecm_optional_add_subdirectory(trayicon) +ecm_optional_add_subdirectory(snoretoast) +ecm_optional_add_subdirectory(snore) +ecm_optional_add_subdirectory(osxnotificationcenter) diff --git a/src/plugins/backends/freedesktop/CMakeLists.txt b/src/plugins/backends/freedesktop_backend/CMakeLists.txt similarity index 88% rename from src/plugins/backends/freedesktop/CMakeLists.txt rename to src/plugins/backends/freedesktop_backend/CMakeLists.txt index f2f8642..766f05e 100644 --- a/src/plugins/backends/freedesktop/CMakeLists.txt +++ b/src/plugins/backends/freedesktop_backend/CMakeLists.txt @@ -9,7 +9,7 @@ if(Qt5DBus_FOUND) fredesktopnotification.cpp ) - qt5_add_dbus_interface( FREEDESKTOP_NOTIFICATION_SRC ../../frontends/freedesktop/org.freedesktop.Notifications.xml notificationinterface ) + qt5_add_dbus_interface( FREEDESKTOP_NOTIFICATION_SRC ../../frontends/freedesktop_frontend/org.freedesktop.Notifications.xml notificationinterface ) add_library(libsnore_backend_freedesktop MODULE ${FREEDESKTOP_NOTIFICATION_SRC} ) diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.cpp b/src/plugins/backends/freedesktop_backend/fredesktopnotification.cpp similarity index 100% rename from src/plugins/backends/freedesktop/fredesktopnotification.cpp rename to src/plugins/backends/freedesktop_backend/fredesktopnotification.cpp diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.h b/src/plugins/backends/freedesktop_backend/fredesktopnotification.h similarity index 100% rename from src/plugins/backends/freedesktop/fredesktopnotification.h rename to src/plugins/backends/freedesktop_backend/fredesktopnotification.h diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp similarity index 100% rename from src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp rename to src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp diff --git a/src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp.Wm2740 b/src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp.Wm2740 new file mode 100644 index 0000000..df418ee --- /dev/null +++ b/src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.cpp.Wm2740 @@ -0,0 +1,166 @@ +#include "freedesktopnotification_backend.h" + +#include "libsnore/notification/notification.h" +#include "libsnore/notification/notification_p.h" +#include "libsnore/snore.h" +#include "libsnore/snore_p.h" +#include "libsnore/utils.h" + +#include "fredesktopnotification.h" + +using namespace Snore; + + +FreedesktopBackend::FreedesktopBackend() +{ + m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"), + QLatin1String("/org/freedesktop/Notifications"), + QDBusConnection::sessionBus(), this); + + +} + +FreedesktopBackend::~FreedesktopBackend() +{ + m_interface->deleteLater(); +} + +void FreedesktopBackend::initialize() +{ + QDBusPendingReply reply = m_interface->GetCapabilities(); + reply.waitForFinished(); + QStringList caps = reply.value(); + m_supportsRichtext = caps.contains(QLatin1String("body-markup")); + emit initialisationFinished(true); +} + +void FreedesktopBackend::setEnabled(bool enabled) +{ + if(enabled == isEnabled()){ + return; + } + SnoreBackend::setEnabled(enabled); + if(enabled){ + connect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked); + connect(m_interface, &org::freedesktop::Notifications::NotificationClosed, this , &FreedesktopBackend::slotNotificationClosed); + }else{ + disconnect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked); + disconnect(m_interface, &org::freedesktop::Notifications::NotificationClosed, this , &FreedesktopBackend::slotNotificationClosed); + + } +} + +bool FreedesktopBackend::canCloseNotification() const +{ + return true; +} + +bool FreedesktopBackend::canUpdateNotification() const +{ + return true; +} + +void FreedesktopBackend::slotNotify(Notification noti) +{ + if (noti.data()->sourceAndTargetAreSimilar(this)) { + return; + } + + QStringList actions; + foreach (int k, noti.actions().keys()) { + actions << QString::number(k) << noti.actions()[k].name(); + } + QVariantMap hints; + if (noti.icon().isValid()) { + FreedesktopImageHint image(noti.icon().image()); + hints.insert(QLatin1String("image_data"), QVariant::fromValue(image)); + } + + char urgency = '1'; + if (noti.priority() < 0) { + urgency = '0'; + } else if (noti.priority() > 2) { + urgency = '2'; + } + hints.insert(QLatin1String("urgency"), urgency); + + if (noti.application().constHints().contains("desktop-entry")) { + hints.insert(QLatin1String("desktop-entry"), noti.application().constHints().value("desktop-entry")); + } + + uint updateId = 0; + if (noti.isUpdate()) { + updateId = noti.old().hints().privateValue(this, "id").toUInt(); + m_dbusIdMap.take(updateId); + } + + QString title = noti.application().name() + QLatin1String(" - ") + noti.title(m_supportsRichtext ? Utils::ALL_MARKUP : Utils::NO_MARKUP); + QString body(noti.text(m_supportsRichtext ? Utils::ALL_MARKUP : Utils::NO_MARKUP)); + //TODO: add app icon hint? + QDBusPendingReply id = m_interface->Notify(noti.application().name(), updateId, QString(), title, + body, actions, hints, noti.isSticky() ? -1 : noti.timeout() * 1000); + + id.waitForFinished(); + noti.hints().setPrivateValue(this, "id", id.value()); + m_dbusIdMap[id.value()] = noti; + slotNotificationDisplayed(noti); + + snoreDebug(SNORE_DEBUG) << noti.id() << "|" << id.value(); +} + +void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID) +{ + snoreDebug(SNORE_DEBUG) << id << m_dbusIdMap[id]; + Notification noti = m_dbusIdMap[id]; + if (!noti.isValid()) { + return; + } + slotNotificationActionInvoked(noti, noti.actions().value(actionID.toInt()));; +} + +void FreedesktopBackend::slotCloseNotification(Notification notification) +{ + uint id = notification.hints().privateValue(this, "id").toUInt(); + snoreDebug(SNORE_DEBUG) << notification.id() << id; + m_interface->CloseNotification(id); +} + +void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reason) +{ + /* + * + * The reason the notification was closed. + * + * 1 - The notification expired. + * + * 2 - The notification was dismissed by the user. + * + * 3 - The notification was closed by a call to CloseNotification. + * + * 4 - Undefined/reserved reasons. + */ + Notification::CloseReasons closeReason; + switch (reason) { + case (1): + closeReason = Notification::TIMED_OUT; + break; + case (2): + closeReason = Notification::DISMISSED; + break; + case (3): + closeReason = Notification::CLOSED; + break; + default: + closeReason = Notification::NONE; + } + + snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason; + if (id == 0) { + return; + } + Notification noti = m_dbusIdMap.take(id); + if (noti.isValid()) { + closeNotification(noti, closeReason); + } +} + diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.h similarity index 100% rename from src/plugins/backends/freedesktop/freedesktopnotification_backend.h rename to src/plugins/backends/freedesktop_backend/freedesktopnotification_backend.h diff --git a/src/plugins/backends/freedesktop/plugin.json b/src/plugins/backends/freedesktop_backend/plugin.json similarity index 100% rename from src/plugins/backends/freedesktop/plugin.json rename to src/plugins/backends/freedesktop_backend/plugin.json diff --git a/src/plugins/frontends/CMakeLists.txt b/src/plugins/frontends/CMakeLists.txt index 2235575..29d0605 100644 --- a/src/plugins/frontends/CMakeLists.txt +++ b/src/plugins/frontends/CMakeLists.txt @@ -1,6 +1,3 @@ -if(WITH_FRONTENDS) - add_subdirectory(freedesktop) - add_subdirectory(snarlnetwork) - add_subdirectory(pushover) - #add_subdirectory(snp3) -endif() +ecm_optional_add_subdirectory(freedesktop_frontend) +ecm_optional_add_subdirectory(snarlnetwork) +ecm_optional_add_subdirectory(pushover_frontend) diff --git a/src/plugins/frontends/freedesktop/CMakeLists.txt b/src/plugins/frontends/freedesktop_frontend/CMakeLists.txt similarity index 91% rename from src/plugins/frontends/freedesktop/CMakeLists.txt rename to src/plugins/frontends/freedesktop_frontend/CMakeLists.txt index 6fe0b5b..c2d2f54 100644 --- a/src/plugins/frontends/freedesktop/CMakeLists.txt +++ b/src/plugins/frontends/freedesktop_frontend/CMakeLists.txt @@ -8,7 +8,7 @@ if(Qt5DBus_FOUND) set( FREEDESKTOP_NOTIFICATION_FRONTEND_SRC freedesktopnotificationfrontend.cpp - ../../backends/freedesktop/fredesktopnotification.cpp + ../../backends/freedesktop_backend/fredesktopnotification.cpp ) qt5_add_dbus_adaptor( FREEDESKTOP_NOTIFICATION_FRONTEND_SRC org.freedesktop.Notifications.xml freedesktopnotificationfrontend.h FreedesktopFrontend) @@ -18,7 +18,7 @@ if(Qt5DBus_FOUND) #install the dbus interface - if(WITH_SNORE_DAEMON) + if(BUILD_daemon) if(WIN32) set(SNORE_LOCATION ../bin/snorenotify) else() @@ -28,7 +28,7 @@ if(Qt5DBus_FOUND) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Notifications.service DESTINATION share/dbus-1/services/) - endif(WITH_SNORE_DAEMON) + endif() install(TARGETS libsnore_frontend_freedesktop ${SNORE_PLUGIN_INSTALL_PATH}) diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop_frontend/freedesktopnotificationfrontend.cpp similarity index 98% rename from src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp rename to src/plugins/frontends/freedesktop_frontend/freedesktopnotificationfrontend.cpp index 8343d6f..5a44944 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop_frontend/freedesktopnotificationfrontend.cpp @@ -19,7 +19,7 @@ #include "freedesktopnotificationfrontend.h" #include "notificationsadaptor.h" -#include "plugins/backends/freedesktop/fredesktopnotification.h" +#include "plugins/backends/freedesktop_backend/fredesktopnotification.h" #include "libsnore/snore.h" #include "libsnore/version.h" #include "libsnore/notification/notification_p.h" diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h b/src/plugins/frontends/freedesktop_frontend/freedesktopnotificationfrontend.h similarity index 100% rename from src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h rename to src/plugins/frontends/freedesktop_frontend/freedesktopnotificationfrontend.h diff --git a/src/plugins/frontends/freedesktop/org.freedesktop.Notifications.service.cmake b/src/plugins/frontends/freedesktop_frontend/org.freedesktop.Notifications.service.cmake similarity index 100% rename from src/plugins/frontends/freedesktop/org.freedesktop.Notifications.service.cmake rename to src/plugins/frontends/freedesktop_frontend/org.freedesktop.Notifications.service.cmake diff --git a/src/plugins/frontends/freedesktop/org.freedesktop.Notifications.xml b/src/plugins/frontends/freedesktop_frontend/org.freedesktop.Notifications.xml similarity index 100% rename from src/plugins/frontends/freedesktop/org.freedesktop.Notifications.xml rename to src/plugins/frontends/freedesktop_frontend/org.freedesktop.Notifications.xml diff --git a/src/plugins/frontends/freedesktop/plugin.json b/src/plugins/frontends/freedesktop_frontend/plugin.json similarity index 100% rename from src/plugins/frontends/freedesktop/plugin.json rename to src/plugins/frontends/freedesktop_frontend/plugin.json diff --git a/src/plugins/frontends/pushover/CMakeLists.txt b/src/plugins/frontends/pushover_frontend/CMakeLists.txt similarity index 100% rename from src/plugins/frontends/pushover/CMakeLists.txt rename to src/plugins/frontends/pushover_frontend/CMakeLists.txt diff --git a/src/plugins/frontends/pushover/plugin.json b/src/plugins/frontends/pushover_frontend/plugin.json similarity index 100% rename from src/plugins/frontends/pushover/plugin.json rename to src/plugins/frontends/pushover_frontend/plugin.json diff --git a/src/plugins/frontends/pushover/pushover_frontend.cpp b/src/plugins/frontends/pushover_frontend/pushover_frontend.cpp similarity index 100% rename from src/plugins/frontends/pushover/pushover_frontend.cpp rename to src/plugins/frontends/pushover_frontend/pushover_frontend.cpp diff --git a/src/plugins/frontends/pushover/pushover_frontend.h b/src/plugins/frontends/pushover_frontend/pushover_frontend.h similarity index 100% rename from src/plugins/frontends/pushover/pushover_frontend.h rename to src/plugins/frontends/pushover_frontend/pushover_frontend.h diff --git a/src/plugins/frontends/pushover/pushoversettings.cpp b/src/plugins/frontends/pushover_frontend/pushoversettings.cpp similarity index 100% rename from src/plugins/frontends/pushover/pushoversettings.cpp rename to src/plugins/frontends/pushover_frontend/pushoversettings.cpp diff --git a/src/plugins/frontends/pushover/pushoversettings.h b/src/plugins/frontends/pushover_frontend/pushoversettings.h similarity index 100% rename from src/plugins/frontends/pushover/pushoversettings.h rename to src/plugins/frontends/pushover_frontend/pushoversettings.h diff --git a/src/plugins/secondary_backends/CMakeLists.txt b/src/plugins/secondary_backends/CMakeLists.txt index 09dfc91..332a366 100644 --- a/src/plugins/secondary_backends/CMakeLists.txt +++ b/src/plugins/secondary_backends/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(toasty) -add_subdirectory(nma) -add_subdirectory(sound) -add_subdirectory(pushover) +ecm_optional_add_subdirectory(toasty) +ecm_optional_add_subdirectory(nma) +ecm_optional_add_subdirectory(sound) +ecm_optional_add_subdirectory(pushover_backend) diff --git a/src/plugins/secondary_backends/pushover/CMakeLists.txt b/src/plugins/secondary_backends/pushover_backend/CMakeLists.txt similarity index 100% rename from src/plugins/secondary_backends/pushover/CMakeLists.txt rename to src/plugins/secondary_backends/pushover_backend/CMakeLists.txt diff --git a/src/plugins/secondary_backends/pushover/plugin.json b/src/plugins/secondary_backends/pushover_backend/plugin.json similarity index 100% rename from src/plugins/secondary_backends/pushover/plugin.json rename to src/plugins/secondary_backends/pushover_backend/plugin.json diff --git a/src/plugins/secondary_backends/pushover/pushover.cpp b/src/plugins/secondary_backends/pushover_backend/pushover.cpp similarity index 100% rename from src/plugins/secondary_backends/pushover/pushover.cpp rename to src/plugins/secondary_backends/pushover_backend/pushover.cpp diff --git a/src/plugins/secondary_backends/pushover/pushover.h b/src/plugins/secondary_backends/pushover_backend/pushover.h similarity index 100% rename from src/plugins/secondary_backends/pushover/pushover.h rename to src/plugins/secondary_backends/pushover_backend/pushover.h diff --git a/src/plugins/secondary_backends/pushover/pushoversettings.cpp b/src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp similarity index 100% rename from src/plugins/secondary_backends/pushover/pushoversettings.cpp rename to src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp diff --git a/src/plugins/secondary_backends/pushover/pushoversettings.h b/src/plugins/secondary_backends/pushover_backend/pushoversettings.h similarity index 100% rename from src/plugins/secondary_backends/pushover/pushoversettings.h rename to src/plugins/secondary_backends/pushover_backend/pushoversettings.h