diff --git a/src/core/notification/notificationenums.h b/src/core/notification/notificationenums.h index eb1e154..2b7c307 100644 --- a/src/core/notification/notificationenums.h +++ b/src/core/notification/notificationenums.h @@ -38,7 +38,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys) namespace CloseReasons{ enum closeReason { - NONE, + NONE = 0, TIMED_OUT, DISMISSED, CLOSED diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.cpp b/src/plugins/backends/freedesktop/fredesktopnotification.cpp index 9511687..17b5a97 100644 --- a/src/plugins/backends/freedesktop/fredesktopnotification.cpp +++ b/src/plugins/backends/freedesktop/fredesktopnotification.cpp @@ -33,13 +33,13 @@ FreedesktopImageHint::FreedesktopImageHint(){ FreedesktopImageHint::FreedesktopImageHint(const QImage &img) { QImage image(img.convertToFormat(QImage::Format_ARGB32)); - this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes()); - width=image.width(); - height=image.height(); - rowstride=image.bytesPerLine(); - hasAlpha=image.hasAlphaChannel(); - channels =image.isGrayscale()?1:hasAlpha?4:3; - bitsPerSample=image.depth()/channels; + imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes()); + width = image.width(); + height = image.height(); + rowstride = image.bytesPerLine(); + hasAlpha = image.hasAlphaChannel(); + channels = image.isGrayscale()?1:hasAlpha?4:3; + bitsPerSample = image.depth()/channels; } @@ -50,14 +50,26 @@ QImage FreedesktopImageHint::toQImage() const { QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) { a.beginStructure(); - a << i.width<>(const QDBusArgument &a, FreedesktopImageHint &i) { - a.beginStructure(); - a >> i.width>> i.height>> i.rowstride>> i.hasAlpha>> i.bitsPerSample>> i.channels>> i.imageData; + a.beginStructure(); + a >> i.width >> + i.height >> + i.rowstride >> + i.hasAlpha >> + i.bitsPerSample >> + i.channels >> + i.imageData; a.endStructure(); return a; } diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index 610954d..d071076 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -17,8 +17,6 @@ Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) FreedesktopBackend::FreedesktopBackend () : SnoreBackend ( "FreedesktopNotification_Backend",true,true) { - - } bool FreedesktopBackend::init(SnoreCore *snore){ @@ -28,7 +26,7 @@ bool FreedesktopBackend::init(SnoreCore *snore){ QDBusPendingReply reply = m_interface->GetCapabilities(); reply.waitForFinished(); - QStringList caps = reply.reply().arguments().first().toStringList(); + QStringList caps = reply.value(); 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))); @@ -54,30 +52,35 @@ void FreedesktopBackend::slotNotify ( Notification noti ) actions << QString::number(k) << noti.actions()[k]->name; } + FreedesktopImageHint image(noti.icon().image()); + + noti.icon().localUrl(); QVariantMap hints; - hints["image_data"] = QVariant::fromValue(FreedesktopImageHint(noti.icon().image().scaledToWidth(50,Qt::FastTransformation))); + hints["image_data"] = QVariant::fromValue(image); uint updateId = 0; if(noti.updateID() != 0) { - updateId = m_idMap[noti.updateID()]; - noti.hints().setValue("DBUS_ID", updateId); + updateId = m_snoreIdMap[noti.updateID()]; + m_dbusIdMap[updateId] = noti.id(); + m_snoreIdMap[noti.id()] = updateId; } QDBusPendingReply id = m_interface->Notify(noti.application(), updateId, "", noti.title(), - noti.text(), actions, hints, noti.timeout()*1000); + noti.text(), actions, hints, noti.sticky()?-1:noti.timeout()*1000); if(noti.updateID() == 0) { id.waitForFinished(); - noti.hints().setValue("DBUS_ID", id.value()); - m_idMap[id.value()] = noti.id(); + m_snoreIdMap[noti.id()] = id.value(); + m_dbusIdMap[id.value()] = noti.id(); + qDebug() << "dbus showed " << id.value() << m_dbusIdMap.keys(); } } void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){ - Notification noti = getActiveNotificationByID(m_idMap[id]); + Notification noti = getActiveNotificationByID(m_dbusIdMap[id]); if(!noti.isValid()) return; qDebug() <<"Action"<CloseNotification(id); } @@ -96,11 +100,18 @@ void FreedesktopBackend::slotCloseNotification ( Notification notification ) void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) { - qDebug() <<"Closed"<notificationActionInvoked(noti); + } + closeNotification(noti, closeReason); } diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h index 3500365..8f02c0e 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h @@ -3,8 +3,6 @@ #include "core/plugins/snorebackend.h" #include "notificationinterface.h" -class fNotification; - class FreedesktopBackend:public Snore::SnoreBackend { Q_OBJECT @@ -17,21 +15,19 @@ public: public slots: void slotNotify( Snore::Notification notification ); void slotCloseNotification ( Snore::Notification notification ); + void slotRegisterApplication ( Snore::Application *application ); + void slotUnregisterApplication ( Snore::Application *application ); 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 m_idMap; + QHash m_dbusIdMap; + QHash m_snoreIdMap; + }; -QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i); -const QDBusArgument & operator >>(const QDBusArgument &a, Snore::Notification &i) ; - - #endif // FREEDESKTOPNOTIFICATION_H