timeout for freedesktop notifications, to close them all
This commit is contained in:
parent
2370fd47cc
commit
e348dd7f7c
|
@ -37,15 +37,16 @@ public:
|
||||||
|
|
||||||
SnoreIconData(const QString &url){
|
SnoreIconData(const QString &url){
|
||||||
if(url.startsWith(":/")){
|
if(url.startsWith(":/")){
|
||||||
_img = QImage(url);
|
_img = QImage(url);
|
||||||
_isLocalFile = false;
|
_isLocalFile = false;
|
||||||
}else if(QFile(url).exists()){
|
}else if(QFile(url).exists()){
|
||||||
_isLocalFile = true;
|
_isLocalFile = true;
|
||||||
_localFileName = url;
|
_localFileName = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SnoreIconData()
|
~SnoreIconData()
|
||||||
{/*nothing to do*/ }
|
{}
|
||||||
|
|
||||||
|
|
||||||
QImage _img;
|
QImage _img;
|
||||||
|
@ -54,11 +55,6 @@ public:
|
||||||
QString _hash;
|
QString _hash;
|
||||||
bool _isLocalFile;
|
bool _isLocalFile;
|
||||||
|
|
||||||
private:
|
|
||||||
SnoreIconData(const SnoreIconData &other)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,104 +30,115 @@
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
|
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
|
||||||
|
|
||||||
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
|
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
|
||||||
Notification_Frontend("FreedesktopNotification_Frontend",snore)
|
Notification_Frontend("FreedesktopNotification_Frontend",snore)
|
||||||
{
|
{
|
||||||
new NotificationsAdaptor(this);
|
new NotificationsAdaptor(this);
|
||||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||||
dbus.registerService( "org.freedesktop.Notifications" );
|
dbus.registerService( "org.freedesktop.Notifications" );
|
||||||
dbus.registerObject( "/org/freedesktop/Notifications", this );
|
dbus.registerObject( "/org/freedesktop/Notifications", this );
|
||||||
}
|
}
|
||||||
|
|
||||||
FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){
|
FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){
|
||||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||||
dbus.unregisterService( "org.freedesktop.Notifications" );
|
dbus.unregisterService( "org.freedesktop.Notifications" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreedesktopNotification_Frontend::actionInvoked(Notification notification) {
|
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) {
|
void FreedesktopNotification_Frontend::notificationClosed(Notification notification) {
|
||||||
|
|
||||||
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
|
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
|
||||||
activeNotifications.remove(notification.id());
|
activeNotifications.remove(notification.id());
|
||||||
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
|
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
|
||||||
emit NotificationClosed(notification.id(),notification.closeReason());
|
emit NotificationClosed(notification.id(),notification.closeReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint replaces_id,
|
uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint replaces_id,
|
||||||
const QString &app_icon, const QString &summary, const QString &body,
|
const QString &app_icon, const QString &summary, const QString &body,
|
||||||
const QStringList &actions, const QVariantMap &hints, int timeout)
|
const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||||
{
|
{
|
||||||
qDebug()<<app_name<<summary<<body<<app_icon;
|
qDebug()<<app_name<<summary<<body<<app_icon;
|
||||||
SnoreIcon icon;
|
SnoreIcon icon;
|
||||||
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
||||||
|
|
||||||
if(hints.contains("image_data")){
|
if(hints.contains("image_data")){
|
||||||
FreedesktopImageHint image;
|
FreedesktopImageHint image;
|
||||||
hints["image_data"].value<QDBusArgument>()>>image;
|
hints["image_data"].value<QDBusArgument>()>>image;
|
||||||
icon = SnoreIcon(image.toQImage());
|
icon = SnoreIcon(image.toQImage());
|
||||||
}
|
}
|
||||||
if(!snore()->aplications().contains(app_name)){
|
if(!snore()->aplications().contains(app_name)){
|
||||||
SnoreIcon appIcon;
|
SnoreIcon appIcon;
|
||||||
#ifdef HAVE_KDE
|
#ifdef HAVE_KDE
|
||||||
KIcon kicon(app_icon);
|
KIcon kicon(app_icon);
|
||||||
appIcon = SnoreIcon(kicon.pixmap(100,100).toImage());
|
appIcon = SnoreIcon(kicon.pixmap(100,100).toImage());
|
||||||
#else
|
#else
|
||||||
appIcon = SnoreIcon(":/root/images/freedesktop-dbus.png");
|
appIcon = SnoreIcon(":/root/images/freedesktop-dbus.png");
|
||||||
#endif
|
#endif
|
||||||
Application *a = new Application(app_name,appIcon);
|
Application *a = new Application(app_name,appIcon);
|
||||||
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
|
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
|
||||||
snore()->addApplication(a);
|
snore()->addApplication(a);
|
||||||
snore()->applicationIsInitialized(a);
|
snore()->applicationIsInitialized(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hints.contains("urgency")) {
|
if (hints.contains("urgency")) {
|
||||||
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
|
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);
|
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id,priotity);
|
||||||
noti.setSource(this);
|
noti.setSource(this);
|
||||||
qDebug()<<"Actions"<<actions;
|
qDebug()<<"Actions"<<actions;
|
||||||
|
|
||||||
for(int i = 0;i < actions.length(); i+=2){
|
for(int i = 0;i < actions.length(); i+=2){
|
||||||
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
snore()->broadcastNotification(noti);
|
snore()->broadcastNotification(noti);
|
||||||
activeNotifications[noti.id()] = noti;
|
activeNotifications[noti.id()] = noti;
|
||||||
return noti.id();
|
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){
|
void FreedesktopNotification_Frontend::CloseNotification(uint id){
|
||||||
Notification noti = activeNotifications.take(id);
|
Notification noti = activeNotifications.take(id);
|
||||||
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
|
qDebug()<<"Active Dbus Notifications"<<activeNotifications.keys();
|
||||||
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
|
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList FreedesktopNotification_Frontend::GetCapabilities()
|
QStringList FreedesktopNotification_Frontend::GetCapabilities()
|
||||||
{
|
{
|
||||||
return QStringList()
|
return QStringList()
|
||||||
<< "body"
|
<< "body"
|
||||||
// << "body-hyperlinks"
|
// << "body-hyperlinks"
|
||||||
// << "body-markup"
|
// << "body-markup"
|
||||||
<< "icon-static"
|
<< "icon-static"
|
||||||
<< "actions"
|
<< "actions"
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FreedesktopNotification_Frontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
|
QString FreedesktopNotification_Frontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
|
||||||
{
|
{
|
||||||
vendor = "Snore";
|
vendor = "Snore";
|
||||||
version = snore()->version();
|
version = snore()->version();
|
||||||
specVersion = "0";
|
specVersion = "0";
|
||||||
return "Snore";
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,15 @@ public:
|
||||||
QStringList GetCapabilities();
|
QStringList GetCapabilities();
|
||||||
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
|
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<uint> timeout_notifications;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void NotificationClosed( uint id, uint reason );
|
void NotificationClosed( uint id, uint reason );
|
||||||
void ActionInvoked( uint id, const QString& actionKey );
|
void ActionInvoked( uint id, const QString& actionKey );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void timeoutClose();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue