updated the freedesktop backend :D
This commit is contained in:
parent
2aeb8928fc
commit
d41092eb16
|
@ -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)
|
||||
|
||||
|
|
|
@ -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} )
|
||||
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
|
||||
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<<noti.application() ; // app_name
|
||||
args<<noti.id() ; // replaces_id
|
||||
args<<"" ; // app_icon
|
||||
args<<noti.title() ; // summary
|
||||
args<<noti.text() ; // body
|
||||
|
||||
QStringList actions;
|
||||
foreach(int k,noti.actions().keys()){
|
||||
foreach(int k,noti.actions().keys())
|
||||
{
|
||||
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;
|
||||
QVariantMap hints;
|
||||
hints["image_data"] = QVariant::fromValue(FreedesktopImageHint(noti.icon().image().scaledToWidth(50,Qt::FastTransformation)));
|
||||
|
||||
uint updateId = 0;
|
||||
if(noti.updateID() != 0)
|
||||
{
|
||||
updateId = m_idMap[noti.updateID()];
|
||||
noti.hints().setValue("DBUS_ID", updateId);
|
||||
}
|
||||
|
||||
args<<noti.timeout()*1000;
|
||||
QDBusPendingReply<uint> id = m_interface->Notify(noti.application(), updateId, "", noti.title(),
|
||||
noti.text(), actions, hints, noti.timeout()*1000);
|
||||
|
||||
message.setArguments(args);
|
||||
|
||||
QDBusMessage replyMsg = QDBusConnection::sessionBus().call(message);
|
||||
uint id = 0;
|
||||
if(replyMsg.type() == QDBusMessage::ReplyMessage){
|
||||
id= replyMsg.arguments().at(0).toUInt();
|
||||
qDebug()<<"DBUS_ID"<<id;
|
||||
m_activeNotifications[id] = noti;
|
||||
|
||||
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"<<id<<"|"<<actionID ;
|
||||
noti.setActionInvoked ( actionID == "default"?1:actionID.toInt() );
|
||||
noti.setActionInvoked ( actionID.toInt() );
|
||||
snore()->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<<notification.id();
|
||||
message.setArguments(args);
|
||||
QDBusConnection::sessionBus().send(message);
|
||||
uint id = notification.hints().value("DBUS_ID").toUInt();
|
||||
m_idMap.remove(id);
|
||||
m_interface->CloseNotification(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreedesktopBackend::closed ( const uint &id,const uint &reason )
|
||||
void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
|
||||
{
|
||||
qDebug() <<"Closed"<<id<<"|"<<reason;
|
||||
if(id == 0)
|
||||
return;
|
||||
Notification noti = m_activeNotifications.take(id);
|
||||
snore()->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() <<recive.arguments();
|
||||
// }
|
||||
// return vendor;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#ifndef FREEDESKTOPNOTIFICATION_H
|
||||
#define FREEDESKTOPNOTIFICATION_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include <QtDBus>
|
||||
|
||||
#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<uint,uint> m_idMap;
|
||||
|
||||
};
|
||||
QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue