use ECMOptionalAddSubdirectory
This commit is contained in:
parent
b472441c79
commit
7f46e579c5
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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} )
|
|
@ -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<QStringList> 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<uint> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
@ -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})
|
||||
|
|
@ -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"
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue