diff --git a/data/freedesktop-dbus.png b/data/freedesktop-dbus.png new file mode 100644 index 0000000..dbbb4ab Binary files /dev/null and b/data/freedesktop-dbus.png differ diff --git a/data/snore.qrc b/data/snore.qrc index 644ca3e..125eb14 100644 --- a/data/snore.qrc +++ b/data/snore.qrc @@ -2,4 +2,7 @@ zzz.png + + freedesktop-dbus.png + diff --git a/src/core/application.cpp b/src/core/application.cpp index cba03cc..b1b7d4c 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -17,7 +17,7 @@ #include "application.h" -Application::Application (const QString &name, const QString &icon) : +Application::Application (const QString &name, const SnoreIcon &icon) : _name ( name ), _icon(icon), _initialized ( false ) @@ -47,7 +47,7 @@ const QString &Application::name() const return _name; } -const QString &Application::icon()const +const SnoreIcon &Application::icon()const { return _icon; } diff --git a/src/core/application.h b/src/core/application.h index 647111a..5055fcf 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -17,6 +17,7 @@ #ifndef APPLICATION_H #define APPLICATION_H #include "snore_exports.h" +#include "notification/icon.h" #include @@ -27,12 +28,12 @@ class SNORE_EXPORT Application:public QObject { Q_OBJECT public: - Application ( const QString &name, const QString &icon = "" ); + Application ( const QString &name, const SnoreIcon &icon = SnoreIcon(QImage(":/root/zzz.png"))); Application(); ~Application(); void addAlert ( Alert *alert ); const QString &name() const; - const QString &icon() const; + const SnoreIcon &icon() const; const AlertList &alerts() const; bool isInitialized(); void setInitialized ( bool b ); @@ -40,7 +41,7 @@ public: private: QString _name; - QString _icon; + SnoreIcon _icon; AlertList _alerts; bool _initialized; diff --git a/src/core/notification/icon.cpp b/src/core/notification/icon.cpp index a97cc81..e090104 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -23,22 +23,22 @@ #include -QHash NotificationIcon::hasedImages; +QHash SnoreIcon::hasedImages; -class NotificationIcon::NotificationIconData +class SnoreIcon::SnoreIconData { public: - NotificationIconData(): + SnoreIconData(): _isLocalFile(false) - { }; + { } - NotificationIconData(const QImage &img): + SnoreIconData(const QImage &img): _img(img), _isLocalFile(false) - {}; + {} - ~NotificationIconData() - { }; + ~SnoreIconData() + { } QImage _img; @@ -47,28 +47,32 @@ public: bool _isLocalFile; private: - NotificationIconData(const NotificationIconData &other) - { }; + SnoreIconData(const SnoreIconData &other) + { } }; -NotificationIcon::NotificationIcon() +SnoreIcon::SnoreIcon() { - d = QSharedPointer(new NotificationIconData()); + d = QSharedPointer(new SnoreIconData()); } -NotificationIcon::NotificationIcon(const QImage &img) +SnoreIcon::SnoreIcon(const QImage &img) { - d = QSharedPointer(new NotificationIconData(img)); + d = QSharedPointer(new SnoreIconData(img)); } -NotificationIcon::NotificationIcon(const NotificationIcon &other): +SnoreIcon::SnoreIcon(const SnoreIcon &other): d(other.d) { } -const QString &NotificationIcon::hash() const{ +SnoreIcon::~SnoreIcon() +{ } + + +const QString &SnoreIcon::hash() const{ if(d->_hash.isEmpty()){ QCryptographicHash h(QCryptographicHash::Md5); h.addData(imageData()); @@ -77,11 +81,11 @@ const QString &NotificationIcon::hash() const{ return d->_hash; } -const QImage &NotificationIcon::image() const{ +const QImage &SnoreIcon::image() const{ return d->_img; } -const QString &NotificationIcon::localUrl()const{ +const QString &SnoreIcon::localUrl()const{ QString h = hash(); if(hasedImages.contains(h)) return hasedImages[h]; @@ -92,7 +96,7 @@ const QString &NotificationIcon::localUrl()const{ return hasedImages[h]; } -const QByteArray &NotificationIcon::imageData() const{ +const QByteArray &SnoreIcon::imageData() const{ if(d->_data.isEmpty()){ QBuffer buffer( &d->_data ); buffer.open( QBuffer::WriteOnly ); @@ -101,10 +105,10 @@ const QByteArray &NotificationIcon::imageData() const{ return d->_data; } -const bool NotificationIcon::isLocalFile() const +const bool SnoreIcon::isLocalFile() const { return d->_isLocalFile; } -#include "icon.moc" \ No newline at end of file +#include "icon.moc" diff --git a/src/core/notification/icon.h b/src/core/notification/icon.h index 5a9eb9b..71d3c5e 100644 --- a/src/core/notification/icon.h +++ b/src/core/notification/icon.h @@ -23,13 +23,14 @@ #include -class SNORE_EXPORT NotificationIcon +class SNORE_EXPORT SnoreIcon { public: - NotificationIcon(); - NotificationIcon(const QImage &img); - NotificationIcon(const QByteArray &img); - NotificationIcon(const NotificationIcon &other); + SnoreIcon(); + SnoreIcon(const QImage &img); + SnoreIcon(const QByteArray &img); + SnoreIcon(const SnoreIcon &other); + ~SnoreIcon(); const QImage &image() const; const QString &localUrl() const; @@ -40,8 +41,8 @@ public: private: static QHash hasedImages; private: - class NotificationIconData; - QSharedPointer d; + class SnoreIconData; + QSharedPointer d; const QString &hash() const; diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index cd16821..44b6996 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -1,226 +1,226 @@ -/**************************************************************************************** -* Copyright (c) 2010 Patrick von Reth * -* * -* This program is free software; you can redistribute it and/or modify it under * -* the terms of the GNU General Public License as published by the Free Software * -* Foundation; either version 2 of the License, or (at your option) any later * -* version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT ANY * -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * -* PARTICULAR PURPOSE. See the GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License along with * -* this program. If not, see . * -****************************************************************************************/ - -#include "notification.h" -#include "snoreserver.h" -#include "notification\icon.h" - -#include -#include -#include -#include -#include - - - - -class Notification::NotificationData -{ -public: - NotificationData ( uint id=0 ): - _id ( id ), - _timeout ( 10 ), - _source ( NULL ), - _closeReason(NotificationEnums::CloseReasons::NONE), - _priority(NotificationEnums::Prioritys::NORMAL) - {}; - - NotificationData ( Notification_Frontend *source,const QString &application,const QString &alert,const QString &title,const QString &text,const NotificationIcon &icon,int timeout,uint id,NotificationEnums::Prioritys::prioritys priority ): - _id ( id ), - _timeout ( timeout ), - _source ( source ), - _application ( application ), - _alert ( alert ), - _title ( title ), - _text ( text ), - _icon ( icon ), - _priority(priority), - _closeReason(NotificationEnums::CloseReasons::NONE) - {}; - - - ~NotificationData(){ - //delete _actionInvoked; - }; - - uint _id; - int _timeout; - Notification::Action *_actionInvoked; - Notification_Frontend *_source; - QString _application; - QString _alert; - QString _title; - QString _text; - NotificationIcon _icon; - NotificationEnums::Prioritys::prioritys _priority; - NotificationEnums::CloseReasons::closeReasons _closeReason; - QMap _actions; - QVariantHash _hints; -}; - - -int Notification::DefaultTimeout=10; - -QString Notification::toPlainText ( const QString &string ) -{ - if( Qt::mightBeRichText(string)) - return QTextDocumentFragment::fromHtml(string).toPlainText(); - return QString(string); -} - -Notification::Notification ( uint id ) -{ - d = QSharedPointer(new NotificationData(id)); -} - -Notification::Notification ( Notification_Frontend *source, const QString &application, const QString &alert, const QString &title, const QString &text, const NotificationIcon &icon, int timeout, uint id, NotificationEnums::Prioritys::prioritys priority ) -{ - d = QSharedPointer(new NotificationData(source,application,alert,title,text,icon,timeout,id,priority)); -} - -Notification::Notification ( const Notification &other ): -d(other.d) -{ -} - -Notification::~Notification(){ -} - -Notification &Notification::operator=(const Notification& other) -{ - d = other.d; - return *this; -} - -QString Notification::toString() const -{ - return QString ( "Title: "+d->_title+"\nText: "+d->_text ); -} - -const uint &Notification::id() const -{ - return d->_id; -} - -void Notification::setId(const uint &id) -{ - qDebug()<<"setting notification id:"<_id = id; -} - -const NotificationIcon &Notification::icon() const -{ - return d->_icon; -} - -const int &Notification::timeout() const -{ - return d->_timeout; -} - -const Notification::Action *Notification::actionInvoked() const -{ - return d->_actionInvoked; -} - -void Notification::setActionInvoked ( Action *action ) -{ - d->_actionInvoked = action; -} - -void Notification::setActionInvoked ( const int &id) -{ - d->_actionInvoked = d->_actions[id]; -} - -Notification_Frontend *Notification::source() const -{ - return d->_source; -} - -const QString &Notification::application() const -{ - return d->_application; -} - -const QString &Notification::title() const -{ - return d->_title; -} - -const QString &Notification::text() const -{ - return d->_text; -} - -const QString &Notification::alert() const -{ - return d->_alert; -} - -const NotificationEnums::Prioritys::prioritys &Notification::priority() const -{ - return d->_priority; -} - -void Notification::addAction(Notification::Action *a) -{ - qDebug()<<"Added notification"<id<name; - d->_actions.insert(a->id,a); -} - - -const QMap &Notification::actions() const -{ - return d->_actions; -} - -const NotificationEnums::CloseReasons::closeReasons &Notification::closeReason(){ - return d->_closeReason; -} - -void Notification::setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r){ - d->_closeReason = r; -} - -const QVariant Notification::hint ( const QString &key ) const -{ - return d->_hints.value ( key ); -} - -bool Notification::hintExists ( const QString &key ) -{ - return d->_hints.contains ( key ); -} - -void Notification::insertHint ( const QString &key, const QVariant &val ) -{ - d->_hints.insert ( key,val ); -} - -QDataStream & operator<< ( QDataStream &stream, const Notification ¬i ) -{ - stream< * +* * +* This program is free software; you can redistribute it and/or modify it under * +* the terms of the GNU General Public License as published by the Free Software * +* Foundation; either version 2 of the License, or (at your option) any later * +* version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT ANY * +* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * +* PARTICULAR PURPOSE. See the GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License along with * +* this program. If not, see . * +****************************************************************************************/ + +#include "notification.h" +#include "snoreserver.h" +#include "notification\icon.h" + +#include +#include +#include +#include +#include + + + + +class Notification::NotificationData +{ +public: + NotificationData ( uint id=0 ): + _id ( id ), + _timeout ( 10 ), + _source ( NULL ), + _closeReason(NotificationEnums::CloseReasons::NONE), + _priority(NotificationEnums::Prioritys::NORMAL) + {} + + NotificationData ( Notification_Frontend *source,const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout,uint id,NotificationEnums::Prioritys::prioritys priority ): + _id ( id ), + _timeout ( timeout ), + _source ( source ), + _application ( application ), + _alert ( alert ), + _title ( title ), + _text ( text ), + _icon ( icon ), + _priority(priority), + _closeReason(NotificationEnums::CloseReasons::NONE) + {} + + + ~NotificationData(){ + //delete _actionInvoked; + } + + uint _id; + int _timeout; + Notification::Action *_actionInvoked; + Notification_Frontend *_source; + QString _application; + QString _alert; + QString _title; + QString _text; + SnoreIcon _icon; + NotificationEnums::Prioritys::prioritys _priority; + NotificationEnums::CloseReasons::closeReasons _closeReason; + QMap _actions; + QVariantHash _hints; +}; + + +int Notification::DefaultTimeout=10; + +QString Notification::toPlainText ( const QString &string ) +{ + if( Qt::mightBeRichText(string)) + return QTextDocumentFragment::fromHtml(string).toPlainText(); + return QString(string); +} + +Notification::Notification ( uint id ) +{ + d = QSharedPointer(new NotificationData(id)); +} + +Notification::Notification ( Notification_Frontend *source, const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id, NotificationEnums::Prioritys::prioritys priority ) +{ + d = QSharedPointer(new NotificationData(source,application,alert,title,text,icon,timeout,id,priority)); +} + +Notification::Notification ( const Notification &other ): +d(other.d) +{ +} + +Notification::~Notification(){ +} + +Notification &Notification::operator=(const Notification& other) +{ + d = other.d; + return *this; +} + +QString Notification::toString() const +{ + return QString ( "Title: "+d->_title+"\nText: "+d->_text ); +} + +const uint &Notification::id() const +{ + return d->_id; +} + +void Notification::setId(const uint &id) +{ + qDebug()<<"setting notification id:"<_id = id; +} + +const SnoreIcon &Notification::icon() const +{ + return d->_icon; +} + +const int &Notification::timeout() const +{ + return d->_timeout; +} + +const Notification::Action *Notification::actionInvoked() const +{ + return d->_actionInvoked; +} + +void Notification::setActionInvoked ( Action *action ) +{ + d->_actionInvoked = action; +} + +void Notification::setActionInvoked ( const int &id) +{ + d->_actionInvoked = d->_actions[id]; +} + +Notification_Frontend *Notification::source() const +{ + return d->_source; +} + +const QString &Notification::application() const +{ + return d->_application; +} + +const QString &Notification::title() const +{ + return d->_title; +} + +const QString &Notification::text() const +{ + return d->_text; +} + +const QString &Notification::alert() const +{ + return d->_alert; +} + +const NotificationEnums::Prioritys::prioritys &Notification::priority() const +{ + return d->_priority; +} + +void Notification::addAction(Notification::Action *a) +{ + qDebug()<<"Added notification"<id<name; + d->_actions.insert(a->id,a); +} + + +const QMap &Notification::actions() const +{ + return d->_actions; +} + +const NotificationEnums::CloseReasons::closeReasons &Notification::closeReason(){ + return d->_closeReason; +} + +void Notification::setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r){ + d->_closeReason = r; +} + +const QVariant Notification::hint ( const QString &key ) const +{ + return d->_hints.value ( key ); +} + +bool Notification::hintExists ( const QString &key ) +{ + return d->_hints.contains ( key ); +} + +void Notification::insertHint ( const QString &key, const QVariant &val ) +{ + d->_hints.insert ( key,val ); +} + +QDataStream & operator<< ( QDataStream &stream, const Notification ¬i ) +{ + stream< * -* * -* This program is free software; you can redistribute it and/or modify it under * -* the terms of the GNU General Public License as published by the Free Software * -* Foundation; either version 2 of the License, or (at your option) any later * -* version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT ANY * -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * -* PARTICULAR PURPOSE. See the GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License along with * -* this program. If not, see . * -****************************************************************************************/ - -#ifndef NOTIFICATION_H -#define NOTIFICATION_H -#include "../snore_exports.h" -#include "../application.h" -#include "icon.h" - -#include -#include - -namespace NotificationEnums{ - -namespace Prioritys{ - enum prioritys{ - LOW=-1, - NORMAL, - HIGH - }; -} -namespace CloseReasons{ - enum closeReason - { - NONE, - TIMED_OUT, - DISMISSED, - CLOSED - }; - Q_DECLARE_FLAGS(closeReasons, closeReason) - Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons) -} -} - -class SNORE_EXPORT Notification -{ -public: - static int DefaultTimeout; - static QString toPlainText ( const QString &string ); - - class Action - { - public: - Action(int id,QString name):id(id),name(name){} - int id; - QString name; - }; - -public: - Notification ( uint id=0 ); - Notification ( class Notification_Frontend *source,const QString &application,const QString &alert,const QString &title,const QString &text,const NotificationIcon &icon,int timeout=10,uint id=0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); - Notification ( const Notification &other ); - ~Notification(); - Notification &operator=(const Notification& other); - - QString toString() const; - - const uint &id() const; - void setId(const uint &id); - const int &timeout() const; - //void setActionInvoked ( const Notification::defaultActions &action ); - void setActionInvoked ( Action *action ); - void setActionInvoked ( const int &actionID); - //const Notification::defaultActions &actionInvoked() const; - const Action* actionInvoked() const; - class Notification_Frontend *source() const; - const QString &application() const; - const QString &title() const; - const QString &text() const; - const NotificationIcon &icon() const; - const QString &alert() const; - const NotificationEnums::Prioritys::prioritys &priority() const; - const QMap &actions() const; - void addAction(Action *a); - const NotificationEnums::CloseReasons::closeReasons &closeReason(); - void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); - const QVariant hint ( const QString &key ) const; - bool hintExists ( const QString &key ); - void insertHint ( const QString &key,const QVariant &val ); - - -private: - class NotificationData; - QSharedPointer d; -}; - - -QDataStream & operator<< ( QDataStream & stream, const Notification & noti ); -QDataStream & operator<< ( QDataStream & stream, const Notification::Action & action); - -#endif // NOTIFICATION_H +/**************************************************************************************** +* Copyright (c) 2010 Patrick von Reth * +* * +* This program is free software; you can redistribute it and/or modify it under * +* the terms of the GNU General Public License as published by the Free Software * +* Foundation; either version 2 of the License, or (at your option) any later * +* version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT ANY * +* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * +* PARTICULAR PURPOSE. See the GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License along with * +* this program. If not, see . * +****************************************************************************************/ + +#ifndef NOTIFICATION_H +#define NOTIFICATION_H +#include "../snore_exports.h" +#include "../application.h" +#include "icon.h" + +#include +#include + +namespace NotificationEnums{ + +namespace Prioritys{ + enum prioritys{ + LOW=-1, + NORMAL, + HIGH + }; +} +namespace CloseReasons{ + enum closeReason + { + NONE, + TIMED_OUT, + DISMISSED, + CLOSED + }; + Q_DECLARE_FLAGS(closeReasons, closeReason) + Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons) +} +} + +class SNORE_EXPORT Notification +{ +public: + static int DefaultTimeout; + static QString toPlainText ( const QString &string ); + + class Action + { + public: + Action(int id,QString name):id(id),name(name){} + int id; + QString name; + }; + +public: + Notification ( uint id=0 ); + Notification ( class Notification_Frontend *source,const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id=0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); + Notification ( const Notification &other ); + ~Notification(); + Notification &operator=(const Notification& other); + + QString toString() const; + + const uint &id() const; + void setId(const uint &id); + const int &timeout() const; + //void setActionInvoked ( const Notification::defaultActions &action ); + void setActionInvoked ( Action *action ); + void setActionInvoked ( const int &actionID); + //const Notification::defaultActions &actionInvoked() const; + const Action* actionInvoked() const; + class Notification_Frontend *source() const; + const QString &application() const; + const QString &title() const; + const QString &text() const; + const SnoreIcon &icon() const; + const QString &alert() const; + const NotificationEnums::Prioritys::prioritys &priority() const; + const QMap &actions() const; + void addAction(Action *a); + const NotificationEnums::CloseReasons::closeReasons &closeReason(); + void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); + const QVariant hint ( const QString &key ) const; + bool hintExists ( const QString &key ); + void insertHint ( const QString &key,const QVariant &val ); + + +private: + class NotificationData; + QSharedPointer d; +}; + + +QDataStream & operator<< ( QDataStream & stream, const Notification & noti ); +QDataStream & operator<< ( QDataStream & stream, const Notification::Action & action); + +#endif // NOTIFICATION_H diff --git a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp index f32b2ee..4894814 100644 --- a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp +++ b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp @@ -1,111 +1,111 @@ -/**************************************************************************************** - * Copyright (c) 2010 Patrick von Reth * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 2 of the License, or (at your option) any later * - * version. * - * * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY * - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * - * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ - -#include "freedesktopnotificationfrontend.h" -#include "notificationsadaptor.h" - -#include "plugins/freedesktopnotification/fredesktopnotification.h" -#include "core/snoreserver.h" - -#include -#include -#include - -Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend) - -FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore): -Notification_Frontend("FreedesktopNotification_Frontend",snore) -{ - new NotificationsAdaptor(this); - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerService( "org.freedesktop.Notifications" ); - dbus.registerObject( "/org/freedesktop/Notifications", this ); -} - -FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){ - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.unregisterService( "org.freedesktop.Notifications" ); -} - -void FreedesktopNotification_Frontend::actionInvoked(Notification notification) { - emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id)); -} - -void FreedesktopNotification_Frontend::notificationClosed(Notification notification) { - - qDebug()<<"Closing Dbus notification"<()>>image; - icon = NotificationIcon(image.toQImage()); - } - if(!snore()->aplications().contains(app_name)){ - Application *a = new Application(app_name,app_icon); - a->addAlert(new Alert("DBus Alert","DBus Alert",app_icon)); - snore()->addApplication(a); - snore()->applicationIsInitialized(a); - } - Notification noti(this,app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id); - qDebug()<<"Actions"<broadcastNotification(noti); - activeNotifications[noti.id()] = noti; - return noti.id(); -} - - - -void FreedesktopNotification_Frontend::CloseNotification(uint id){ - Notification noti = activeNotifications.take(id); - snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT); -} - -QStringList FreedesktopNotification_Frontend::GetCapabilities() -{ - return QStringList() - << "body" - // << "body-hyperlinks" - // << "body-markup" - << "icon-static" - << "actions" - ; -} - -QString FreedesktopNotification_Frontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) -{ - vendor = "Snore"; - version = snore()->version(); - specVersion = "0"; - return "Snore"; -} - - -#include "freedesktopnotificationfrontend.moc" +/**************************************************************************************** + * Copyright (c) 2010 Patrick von Reth * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +#include "freedesktopnotificationfrontend.h" +#include "notificationsadaptor.h" + +#include "plugins/freedesktopnotification/fredesktopnotification.h" +#include "core/snoreserver.h" + +#include +#include +#include + +Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend) + +FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore): +Notification_Frontend("FreedesktopNotification_Frontend",snore) +{ + new NotificationsAdaptor(this); + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerService( "org.freedesktop.Notifications" ); + dbus.registerObject( "/org/freedesktop/Notifications", this ); +} + +FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){ + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.unregisterService( "org.freedesktop.Notifications" ); +} + +void FreedesktopNotification_Frontend::actionInvoked(Notification notification) { + emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id)); +} + +void FreedesktopNotification_Frontend::notificationClosed(Notification notification) { + + qDebug()<<"Closing Dbus notification"<()>>image; + icon = SnoreIcon(image.toQImage()); + } + if(!snore()->aplications().contains(app_name)){ + Application *a = new Application(app_name,SnoreIcon(QImage(":/root/images/freedesktop-dbus.png"))); + a->addAlert(new Alert("DBus Alert","DBus Alert",app_icon)); + snore()->addApplication(a); + snore()->applicationIsInitialized(a); + } + Notification noti(this,app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id); + qDebug()<<"Actions"<broadcastNotification(noti); + activeNotifications[noti.id()] = noti; + return noti.id(); +} + + + +void FreedesktopNotification_Frontend::CloseNotification(uint id){ + Notification noti = activeNotifications.take(id); + snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT); +} + +QStringList FreedesktopNotification_Frontend::GetCapabilities() +{ + return QStringList() + << "body" + // << "body-hyperlinks" + // << "body-markup" + << "icon-static" + << "actions" + ; +} + +QString FreedesktopNotification_Frontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) +{ + vendor = "Snore"; + version = snore()->version(); + specVersion = "0"; + return "Snore"; +} + + +#include "freedesktopnotificationfrontend.moc" diff --git a/src/plugins/freedesktopnotification/fredesktopnotification.cpp b/src/plugins/freedesktopnotification/fredesktopnotification.cpp index 57a3225..8ab267e 100644 --- a/src/plugins/freedesktopnotification/fredesktopnotification.cpp +++ b/src/plugins/freedesktopnotification/fredesktopnotification.cpp @@ -1,5 +1,5 @@ /**************************************************************************************** - * Copyright (c) 2010 Patrick von Reth * + * Copyright (c) 2010,2011 Patrick von Reth * * * * This program is free software; you can redistribute it and/or modify it under * * the terms of the GNU General Public License as published by the Free Software * diff --git a/src/plugins/snarl/snarl_backend.cpp b/src/plugins/snarl/snarl_backend.cpp index 3a7f32b..2a5d7da 100644 --- a/src/plugins/snarl/snarl_backend.cpp +++ b/src/plugins/snarl/snarl_backend.cpp @@ -62,12 +62,12 @@ void Snarl_Backend::registerApplication(Application *application){ snarlInterface = new SnarlInterface(); _applications.insert(application->name(),snarlInterface); } - qDebug()<<"Register with Snarl"<name()<icon(); + qDebug()<<"Register with Snarl"<name(); QString appName = application->name(); appName = appName.replace(" ","_");//app sig must not contain spaces snarlInterface->Register(appName.toUtf8().constData(), application->name().toUtf8().constData(), - application->icon().toUtf8().constData(), + application->icon().localUrl().toUtf8().constData(), 0,winIDWidget->winId(),SNORENOTIFIER_MESSAGE_ID); foreach(Alert *alert,application->alerts()){