make the dbus backend work

This commit is contained in:
Patrick von Reth 2013-07-25 10:26:50 +02:00
parent d41092eb16
commit ddf1660172
4 changed files with 54 additions and 35 deletions

View File

@ -38,7 +38,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys)
namespace CloseReasons{
enum closeReason
{
NONE,
NONE = 0,
TIMED_OUT,
DISMISSED,
CLOSED

View File

@ -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<<i.height<<i.rowstride<<i.hasAlpha<<i.bitsPerSample<<i.channels<<i.imageData;
a << i.width <<
i.height <<
i.rowstride <<
i.hasAlpha <<
i.bitsPerSample <<
i.channels <<
i.imageData;
a.endStructure();
return a;
}
const QDBusArgument & operator >>(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;
}

View File

@ -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<QStringList> 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<uint> 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"<<id<<"|"<<actionID ;
@ -87,8 +90,9 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action
void FreedesktopBackend::slotCloseNotification ( Notification notification )
{
uint id = notification.hints().value("DBUS_ID").toUInt();
m_idMap.remove(id);
uint id = m_snoreIdMap.take(notification.id());
qDebug() << "dbus closing " << id;
m_dbusIdMap.remove(id);
m_interface->CloseNotification(id);
}
@ -96,11 +100,18 @@ void FreedesktopBackend::slotCloseNotification ( Notification notification )
void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
{
qDebug() <<"Closed"<<id<<"|"<<reason;
NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason);
qDebug() << "Closed" << id << "|" << closeReason << reason;
if(id == 0)
return;
Notification noti = getActiveNotificationByID(m_idMap.take(id));
closeNotification(noti ,NotificationEnums::CloseReasons::closeReasons(reason));
Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id));
m_snoreIdMap.remove(noti.id());
if(closeReason == NotificationEnums::CloseReasons::CLOSED)
{
snore()->notificationActionInvoked(noti);
}
closeNotification(noti, closeReason);
}

View File

@ -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<uint,uint> m_idMap;
QHash<uint,uint> m_dbusIdMap;
QHash<uint,uint> m_snoreIdMap;
};
QDBusArgument &operator<<(QDBusArgument &a,const Snore::Notification &i);
const QDBusArgument & operator >>(const QDBusArgument &a, Snore::Notification &i) ;
#endif // FREEDESKTOPNOTIFICATION_H