updated the freedesktop backend :D

This commit is contained in:
Patrick von Reth 2013-07-25 01:50:39 +02:00
parent 2aeb8928fc
commit d41092eb16
5 changed files with 69 additions and 76 deletions

View File

@ -18,7 +18,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_SYSTEM_NAME MATCHES Linux) 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_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) add_definitions (-D_BSD_SOURCE)
endif (CMAKE_SYSTEM_NAME MATCHES Linux) endif (CMAKE_SYSTEM_NAME MATCHES Linux)

View File

@ -1,9 +1,14 @@
if(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE) if(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE)
message(STATUS "Adding Freedesktop notification backend") message(STATUS "Adding Freedesktop notification backend")
set ( FREEDESKTOP_NOTIFICATION_SRC set ( FREEDESKTOP_NOTIFICATION_SRC
freedesktopnotification_backend.cpp freedesktopnotification_backend.cpp
fredesktopnotification.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} ) add_library(freedesktop_backend MODULE ${FREEDESKTOP_NOTIFICATION_SRC} )
target_link_libraries(freedesktop_backend snorecore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} ) target_link_libraries(freedesktop_backend snorecore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} )

View File

@ -13,115 +13,96 @@ using namespace Snore;
Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) 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 () : FreedesktopBackend::FreedesktopBackend () :
SnoreBackend ( "FreedesktopNotification_Backend") SnoreBackend ( "FreedesktopNotification_Backend",true,true)
{ {
} }
bool FreedesktopBackend::init(SnoreCore *snore){ 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" ) m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
QDBusConnection::sessionBus().connect ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","NotificationClosed",this,SLOT ( closed ( uint,uint ) ) ); QDBusConnection::sessionBus(), this );
QDBusPendingReply<QStringList> 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); return SnoreBackend::init(snore);
} }
void FreedesktopBackend::registerApplication ( Application *application ) void FreedesktopBackend::slotRegisterApplication ( Application *application )
{ {
Q_UNUSED ( application ); Q_UNUSED ( application );
} }
void FreedesktopBackend::unregisterApplication ( Application *application ) void FreedesktopBackend::slotUnregisterApplication ( Application *application )
{ {
Q_UNUSED ( 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<<noti.application() ; // app_name
args<<noti.id() ; // replaces_id
args<<"" ; // app_icon
args<<noti.title() ; // summary
args<<noti.text() ; // body
QStringList actions; QStringList actions;
foreach(int k,noti.actions().keys()){ foreach(int k,noti.actions().keys())
actions<<QString::number(k)<<noti.actions()[k]->name; {
} actions << QString::number(k) << noti.actions()[k]->name;
args<<actions;
if(!noti.icon().isEmpty()){
QVariantMap image_data;
QVariant img = QVariant::fromValue(FreedesktopImageHint(noti.icon().image().scaledToWidth(50,Qt::FastTransformation)));
image_data.insert(QString("image_data"),img);
args<<image_data;
} }
args<<noti.timeout()*1000; QVariantMap hints;
hints["image_data"] = QVariant::fromValue(FreedesktopImageHint(noti.icon().image().scaledToWidth(50,Qt::FastTransformation)));
message.setArguments(args); uint updateId = 0;
if(noti.updateID() != 0)
QDBusMessage replyMsg = QDBusConnection::sessionBus().call(message); {
uint id = 0; updateId = m_idMap[noti.updateID()];
if(replyMsg.type() == QDBusMessage::ReplyMessage){ noti.hints().setValue("DBUS_ID", updateId);
id= replyMsg.arguments().at(0).toUInt(); }
qDebug()<<"DBUS_ID"<<id;
m_activeNotifications[id] = noti; QDBusPendingReply<uint> 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){ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){
Notification noti = m_activeNotifications[id]; Notification noti = getActiveNotificationByID(m_idMap[id]);
if(noti.id() == 0) if(!noti.isValid())
return; return;
qDebug() <<"Action"<<id<<"|"<<actionID ; qDebug() <<"Action"<<id<<"|"<<actionID ;
noti.setActionInvoked ( actionID == "default"?1:actionID.toInt() ); noti.setActionInvoked ( actionID.toInt() );
snore()->notificationActionInvoked ( noti ); snore()->notificationActionInvoked ( noti );
} }
void FreedesktopBackend::closeNotification ( Notification notification ) void FreedesktopBackend::slotCloseNotification ( Notification notification )
{ {
m_activeNotifications.remove(notification.id()); uint id = notification.hints().value("DBUS_ID").toUInt();
QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName,"CloseNotification"); m_idMap.remove(id);
QVariantList args; m_interface->CloseNotification(id);
args<<notification.id();
message.setArguments(args);
QDBusConnection::sessionBus().send(message);
} }
void FreedesktopBackend::closed ( const uint &id,const uint &reason ) void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
{ {
qDebug() <<"Closed"<<id<<"|"<<reason; qDebug() <<"Closed"<<id<<"|"<<reason;
if(id == 0) if(id == 0)
return; return;
Notification noti = m_activeNotifications.take(id); Notification noti = getActiveNotificationByID(m_idMap.take(id));
snore()->closeNotification ( noti ,QFlag(reason)); closeNotification(noti ,NotificationEnums::CloseReasons::closeReasons(reason));
} }
//QString fNotification::getVendor()
//{
// if ( vendor == "" )
// {
// QDBusMessage recive = notificationInterface.call ( QDBus::AutoDetect,"GetServerInformation" );
// vendor=recive.arguments() [1].toString();
// qDebug() <<recive.arguments();
// }
// return vendor;
//}

View File

@ -1,8 +1,7 @@
#ifndef FREEDESKTOPNOTIFICATION_H #ifndef FREEDESKTOPNOTIFICATION_H
#define FREEDESKTOPNOTIFICATION_H #define FREEDESKTOPNOTIFICATION_H
#include "core/plugins/snorebackend.h" #include "core/plugins/snorebackend.h"
#include <QtDBus> #include "notificationinterface.h"
class fNotification; class fNotification;
@ -10,17 +9,24 @@ class FreedesktopBackend:public Snore::SnoreBackend
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES ( Snore::SnoreBackend ) Q_INTERFACES ( Snore::SnoreBackend )
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
public: public:
FreedesktopBackend(); FreedesktopBackend();
virtual bool init(Snore::SnoreCore *snore); virtual bool init(Snore::SnoreCore *snore);
public slots: public slots:
void registerApplication ( Snore::Application *application ); void slotNotify( Snore::Notification notification );
void unregisterApplication ( Snore::Application *application ); void slotCloseNotification ( Snore::Notification notification );
uint notify ( Snore::Notification notification );
void closeNotification ( Snore::Notification notification ); void slotActionInvoked(const uint &id,const QString &actionID);
void actionInvoked(const uint &id,const QString &actionID); void slotNotificationClosed ( const uint &id,const uint &reason );
void closed ( const uint &id,const uint &reason ); void slotRegisterApplication ( Snore::Application *application );
void slotUnregisterApplication ( Snore::Application *application );
private:
org::freedesktop::Notifications* m_interface;
QHash<uint,uint> m_idMap;
}; };
QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i); QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i);

View File

@ -15,6 +15,7 @@ class TrayIconNotifer:public Snore::SnoreBackend
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend) Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
public: public:
TrayIconNotifer (); TrayIconNotifer ();
virtual bool init(Snore::SnoreCore *snore); virtual bool init(Snore::SnoreCore *snore);