timeout for freedesktop notifications, to close them all

This commit is contained in:
Patrick von Reth 2011-07-29 20:12:48 +02:00
parent 2370fd47cc
commit e348dd7f7c
3 changed files with 81 additions and 70 deletions

View File

@ -37,15 +37,16 @@ public:
SnoreIconData(const QString &url){
if(url.startsWith(":/")){
_img = QImage(url);
_isLocalFile = false;
}else if(QFile(url).exists()){
_img = QImage(url);
_isLocalFile = false;
}else if(QFile(url).exists()){
_isLocalFile = true;
_localFileName = url;
}
}
}
~SnoreIconData()
{/*nothing to do*/ }
{}
QImage _img;
@ -54,11 +55,6 @@ public:
QString _hash;
bool _isLocalFile;
private:
SnoreIconData(const SnoreIconData &other)
{ }
};

View File

@ -30,104 +30,115 @@
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
Notification_Frontend("FreedesktopNotification_Frontend",snore)
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 );
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" );
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService( "org.freedesktop.Notifications" );
}
void FreedesktopNotification_Frontend::actionInvoked(Notification notification) {
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
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.remove(notification.id());
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
emit NotificationClosed(notification.id(),notification.closeReason());
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
activeNotifications.remove(notification.id());
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
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)
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;
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
qDebug()<<app_name<<summary<<body<<app_icon;
SnoreIcon icon;
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>image;
icon = SnoreIcon(image.toQImage());
}
if(!snore()->aplications().contains(app_name)){
SnoreIcon appIcon;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>image;
icon = SnoreIcon(image.toQImage());
}
if(!snore()->aplications().contains(app_name)){
SnoreIcon appIcon;
#ifdef HAVE_KDE
KIcon kicon(app_icon);
appIcon = SnoreIcon(kicon.pixmap(100,100).toImage());
KIcon kicon(app_icon);
appIcon = SnoreIcon(kicon.pixmap(100,100).toImage());
#else
appIcon = SnoreIcon(":/root/images/freedesktop-dbus.png");
appIcon = SnoreIcon(":/root/images/freedesktop-dbus.png");
#endif
Application *a = new Application(app_name,appIcon);
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
snore()->addApplication(a);
snore()->applicationIsInitialized(a);
}
Application *a = new Application(app_name,appIcon);
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
snore()->addApplication(a);
snore()->applicationIsInitialized(a);
}
if (hints.contains("urgency")) {
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
}
if (hints.contains("urgency")) {
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
}
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id,priotity);
noti.setSource(this);
qDebug()<<"Actions"<<actions;
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id,priotity);
noti.setSource(this);
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)));
}
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();
snore()->broadcastNotification(noti);
activeNotifications[noti.id()] = noti;
timeout_notifications.append(noti.id());
QTimer::singleShot(timeout==-1?Notification::DefaultTimeout*1000:timeout,this,SLOT(timeoutClose()));
return noti.id();
}
void FreedesktopNotification_Frontend::CloseNotification(uint id){
Notification noti = activeNotifications.take(id);
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
Notification noti = activeNotifications.take(id);
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
}
QStringList FreedesktopNotification_Frontend::GetCapabilities()
{
return QStringList()
<< "body"
// << "body-hyperlinks"
// << "body-markup"
<< "icon-static"
<< "actions"
;
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";
vendor = "Snore";
version = snore()->version();
specVersion = "0";
return "Snore";
}
void FreedesktopNotification_Frontend::timeoutClose(){
uint id = timeout_notifications.takeFirst();
if(activeNotifications.contains(id)){
Notification noti = activeNotifications[id];
noti.setCloseReason(NotificationEnums::CloseReasons::TIMED_OUT);
notificationClosed(noti);
}
}

View File

@ -34,11 +34,15 @@ public:
QStringList GetCapabilities();
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
private:
QList<uint> timeout_notifications;
signals:
void NotificationClosed( uint id, uint reason );
void ActionInvoked( uint id, const QString& actionKey );
private slots:
void timeoutClose();
};