improved icon handling

This commit is contained in:
Patrick von Reth 2011-07-21 18:33:43 +02:00
parent 7abeae216d
commit 75ba909f7d
11 changed files with 486 additions and 477 deletions

BIN
data/freedesktop-dbus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -2,4 +2,7 @@
<qresource prefix="/root">
<file>zzz.png</file>
</qresource>
<qresource prefix="/root/images">
<file>freedesktop-dbus.png</file>
</qresource>
</RCC>

View File

@ -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;
}

View File

@ -17,6 +17,7 @@
#ifndef APPLICATION_H
#define APPLICATION_H
#include "snore_exports.h"
#include "notification/icon.h"
#include <QHash>
@ -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;

View File

@ -23,22 +23,22 @@
#include <QDebug>
QHash<QString,QString> NotificationIcon::hasedImages;
QHash<QString,QString> 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<NotificationIconData>(new NotificationIconData());
d = QSharedPointer<SnoreIconData>(new SnoreIconData());
}
NotificationIcon::NotificationIcon(const QImage &img)
SnoreIcon::SnoreIcon(const QImage &img)
{
d = QSharedPointer<NotificationIconData>(new NotificationIconData(img));
d = QSharedPointer<SnoreIconData>(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"
#include "icon.moc"

View File

@ -23,13 +23,14 @@
#include <QSharedPointer>
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<QString,QString> hasedImages;
private:
class NotificationIconData;
QSharedPointer<NotificationIconData> d;
class SnoreIconData;
QSharedPointer<SnoreIconData> d;
const QString &hash() const;

View File

@ -1,226 +1,226 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "notification.h"
#include "snoreserver.h"
#include "notification\icon.h"
#include <QDebug>
#include <QTcpSocket>
#include <Qt>
#include <QTextDocumentFragment>
#include <QTextDocument>
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<int,Notification::Action*> _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<NotificationData>(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<NotificationData>(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;
d->_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"<<a->id<<a->name;
d->_actions.insert(a->id,a);
}
const QMap<int,Notification::Action*> &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 &noti )
{
stream<<noti.toString();
return stream;
}
QDataStream & operator<< ( QDataStream &stream, const Notification::Action &a)
{
stream<<a.id<<a.id;
return stream;
}
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "notification.h"
#include "snoreserver.h"
#include "notification\icon.h"
#include <QDebug>
#include <QTcpSocket>
#include <Qt>
#include <QTextDocumentFragment>
#include <QTextDocument>
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<int,Notification::Action*> _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<NotificationData>(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<NotificationData>(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;
d->_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"<<a->id<<a->name;
d->_actions.insert(a->id,a);
}
const QMap<int,Notification::Action*> &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 &noti )
{
stream<<noti.toString();
return stream;
}
QDataStream & operator<< ( QDataStream &stream, const Notification::Action &a)
{
stream<<a.id<<a.id;
return stream;
}

View File

@ -1,104 +1,104 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
#include "../snore_exports.h"
#include "../application.h"
#include "icon.h"
#include <QVariant>
#include <QSharedPointer>
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<int,Action*> &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<NotificationData> 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 <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
#include "../snore_exports.h"
#include "../application.h"
#include "icon.h"
#include <QVariant>
#include <QSharedPointer>
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<int,Action*> &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<NotificationData> d;
};
QDataStream & operator<< ( QDataStream & stream, const Notification & noti );
QDataStream & operator<< ( QDataStream & stream, const Notification::Action & action);
#endif // NOTIFICATION_H

View File

@ -1,111 +1,111 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "freedesktopnotificationfrontend.h"
#include "notificationsadaptor.h"
#include "plugins/freedesktopnotification/fredesktopnotification.h"
#include "core/snoreserver.h"
#include <QtCore>
#include <QtDBus>
#include <QImage>
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"<<notification.id()<<"reason:"<<(int)notification.closeReason();
activeNotifications.take(notification.id());
emit NotificationClosed(notification.id(),notification.closeReason());
}
uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint replaces_id,
const QString &app_icon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantMap &hints, int timeout)
{
qDebug()<<app_name<<summary<<body<<app_icon;
NotificationIcon icon;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>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"<<actions;
for(int i = 0;i < actions.length(); i+=2){
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
}
snore()->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 <patrick.vonreth@gmail.com> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "freedesktopnotificationfrontend.h"
#include "notificationsadaptor.h"
#include "plugins/freedesktopnotification/fredesktopnotification.h"
#include "core/snoreserver.h"
#include <QtCore>
#include <QtDBus>
#include <QImage>
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"<<notification.id()<<"reason:"<<(int)notification.closeReason();
activeNotifications.take(notification.id());
emit NotificationClosed(notification.id(),notification.closeReason());
}
uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint replaces_id,
const QString &app_icon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantMap &hints, int timeout)
{
qDebug()<<app_name<<summary<<body<<app_icon;
SnoreIcon icon;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>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"<<actions;
for(int i = 0;i < actions.length(); i+=2){
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
}
snore()->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"

View File

@ -1,5 +1,5 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* Copyright (c) 2010,2011 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* 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 *

View File

@ -62,12 +62,12 @@ void Snarl_Backend::registerApplication(Application *application){
snarlInterface = new SnarlInterface();
_applications.insert(application->name(),snarlInterface);
}
qDebug()<<"Register with Snarl"<<application->name()<<application->icon();
qDebug()<<"Register with Snarl"<<application->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()){