diff --git a/cmake/modules/NoKDE.cmake b/cmake/modules/NoKDE.cmake index 3db366c..e976912 100644 --- a/cmake/modules/NoKDE.cmake +++ b/cmake/modules/NoKDE.cmake @@ -18,7 +18,7 @@ if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_SYSTEM_NAME MATCHES Linux) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common") - set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -fno-check-new -fno-common") + set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -fno-check-new -fno-common -fPIC") add_definitions (-D_BSD_SOURCE) endif (CMAKE_SYSTEM_NAME MATCHES Linux) diff --git a/src/plugins/backends/freedesktop/CMakeLists.txt b/src/plugins/backends/freedesktop/CMakeLists.txt index 70ad08a..4c8ca9a 100644 --- a/src/plugins/backends/freedesktop/CMakeLists.txt +++ b/src/plugins/backends/freedesktop/CMakeLists.txt @@ -1,9 +1,14 @@ if(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE) message(STATUS "Adding Freedesktop notification backend") + set ( FREEDESKTOP_NOTIFICATION_SRC freedesktopnotification_backend.cpp fredesktopnotification.cpp ) + + qt4_add_dbus_interface( FREEDESKTOP_NOTIFICATION_SRC ../../frontends/freedesktop/org.freedesktop.Notifications.xml notificationinterface ) + + add_library(freedesktop_backend MODULE ${FREEDESKTOP_NOTIFICATION_SRC} ) target_link_libraries(freedesktop_backend snorecore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} ) diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index f29d541..610954d 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -13,115 +13,96 @@ using namespace Snore; Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) -static const char dbusServiceName[] = "org.freedesktop.Notifications"; -static const char dbusInterfaceName[] = "org.freedesktop.Notifications"; -static const char dbusPath[] = "/org/freedesktop/Notifications"; - FreedesktopBackend::FreedesktopBackend () : - SnoreBackend ( "FreedesktopNotification_Backend") + SnoreBackend ( "FreedesktopNotification_Backend",true,true) { } bool FreedesktopBackend::init(SnoreCore *snore){ - QDBusConnection::sessionBus().connect ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","ActionInvoked",this,SLOT ( actionInvoked( uint,QString ) ) ); - // if ( getVendor() =="GNOME" ) - QDBusConnection::sessionBus().connect ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","NotificationClosed",this,SLOT ( closed ( uint,uint ) ) ); + + m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this ); + + QDBusPendingReply reply = m_interface->GetCapabilities(); + reply.waitForFinished(); + QStringList caps = reply.reply().arguments().first().toStringList(); + m_supportsRichtext = caps.contains( "body-markup" ); + connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString))); + connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint))); + return SnoreBackend::init(snore); } -void FreedesktopBackend::registerApplication ( Application *application ) +void FreedesktopBackend::slotRegisterApplication ( Application *application ) { Q_UNUSED ( application ); } -void FreedesktopBackend::unregisterApplication ( Application *application ) +void FreedesktopBackend::slotUnregisterApplication ( Application *application ) { Q_UNUSED ( application ); } -uint FreedesktopBackend::notify ( Notification noti ) +void FreedesktopBackend::slotNotify ( Notification noti ) { - QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName, "Notify"); - QVariantList args; - - args<name; - } - args<name; } - args< id = m_interface->Notify(noti.application(), updateId, "", noti.title(), + noti.text(), actions, hints, noti.timeout()*1000); + + + + if(noti.updateID() == 0) + { + id.waitForFinished(); + noti.hints().setValue("DBUS_ID", id.value()); + m_idMap[id.value()] = noti.id(); } - return id; } -void FreedesktopBackend::actionInvoked(const uint &id, const QString &actionID){ - Notification noti = m_activeNotifications[id]; - if(noti.id() == 0) +void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){ + Notification noti = getActiveNotificationByID(m_idMap[id]); + if(!noti.isValid()) return; qDebug() <<"Action"<notificationActionInvoked ( noti ); } -void FreedesktopBackend::closeNotification ( Notification notification ) +void FreedesktopBackend::slotCloseNotification ( Notification notification ) { - m_activeNotifications.remove(notification.id()); - QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName,"CloseNotification"); - QVariantList args; - args<CloseNotification(id); } -void FreedesktopBackend::closed ( const uint &id,const uint &reason ) +void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) { qDebug() <<"Closed"<closeNotification ( noti ,QFlag(reason)); + Notification noti = getActiveNotificationByID(m_idMap.take(id)); + closeNotification(noti ,NotificationEnums::CloseReasons::closeReasons(reason)); } -//QString fNotification::getVendor() -//{ -// if ( vendor == "" ) -// { -// QDBusMessage recive = notificationInterface.call ( QDBus::AutoDetect,"GetServerInformation" ); -// vendor=recive.arguments() [1].toString(); -// qDebug() < - +#include "notificationinterface.h" class fNotification; @@ -10,17 +9,24 @@ class FreedesktopBackend:public Snore::SnoreBackend { Q_OBJECT Q_INTERFACES ( Snore::SnoreBackend ) + Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") public: FreedesktopBackend(); virtual bool init(Snore::SnoreCore *snore); public slots: - void registerApplication ( Snore::Application *application ); - void unregisterApplication ( Snore::Application *application ); - uint notify ( Snore::Notification notification ); - void closeNotification ( Snore::Notification notification ); - void actionInvoked(const uint &id,const QString &actionID); - void closed ( const uint &id,const uint &reason ); + void slotNotify( Snore::Notification notification ); + void slotCloseNotification ( Snore::Notification notification ); + + void slotActionInvoked(const uint &id,const QString &actionID); + void slotNotificationClosed ( const uint &id,const uint &reason ); + void slotRegisterApplication ( Snore::Application *application ); + void slotUnregisterApplication ( Snore::Application *application ); + + +private: + org::freedesktop::Notifications* m_interface; + QHash m_idMap; }; QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i); diff --git a/src/plugins/backends/trayicon/trayiconnotifer.h b/src/plugins/backends/trayicon/trayiconnotifer.h index 0f067e9..048f4c0 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.h +++ b/src/plugins/backends/trayicon/trayiconnotifer.h @@ -15,6 +15,7 @@ class TrayIconNotifer:public Snore::SnoreBackend { Q_OBJECT Q_INTERFACES(Snore::SnoreBackend) + Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") public: TrayIconNotifer (); virtual bool init(Snore::SnoreCore *snore);