diff --git a/src/core/notification.cpp b/src/core/notification.cpp index 99f1301..3bc22a1 100644 --- a/src/core/notification.cpp +++ b/src/core/notification.cpp @@ -29,8 +29,7 @@ int Notification::DefaultTimeout=10; QString Notification::toPlainText ( const QString &string ) { - QTextDocumentFragment frag = QTextDocumentFragment::fromHtml(string); - return frag.toPlainText(); + return QTextDocumentFragment::fromHtml(string).toPlainText(); } Notification::Notification ( uint id ) : diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp index 821bc5c..053d419 100644 --- a/src/core/snoreserver.cpp +++ b/src/core/snoreserver.cpp @@ -27,12 +27,7 @@ #include QString const SnoreServer::snoreTMP = QDir::temp().path() +"/SnoreNotify/"; - -SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) : - _notificationBackend ( NULL ), - _trayIcon ( trayIcon ) -{ - qDebug() <<"Inititalized"; +void SnoreServer::cleanupTMP(){ QDir home ( snoreTMP ); if ( home.exists() ) { @@ -46,8 +41,20 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) : } } - else - QDir::temp().mkpath ( "SnoreNotify" ); + else{ + home.cdUp(); + home.mkdir("SnoreNotify"); + } + +} + +SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) : + _notificationBackend ( NULL ), + _trayIcon ( trayIcon ) +{ + qDebug() <<"Inititalized"; + + _defaultNotificationInterface = new SnoreNotificationInstance ( "Snore",this ); diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h index ee40994..bb4e15c 100644 --- a/src/core/snoreserver.h +++ b/src/core/snoreserver.h @@ -27,6 +27,7 @@ class SNORE_EXPORT SnoreServer:public QObject Q_OBJECT public: static const QString snoreTMP; + static void cleanupTMP(); public: diff --git a/src/core/trayiconnotifer.cpp b/src/core/trayiconnotifer.cpp index 6df4209..6c7f5fc 100644 --- a/src/core/trayiconnotifer.cpp +++ b/src/core/trayiconnotifer.cpp @@ -49,7 +49,7 @@ void TrayIconNotifer::displayNotification(){ } QSharedPointer notification = _notificationQue.takeLast(); qDebug()<<"taking"<title(); - _trayIcon->showMessage ( notification->title(),notification->text(),QSystemTrayIcon::NoIcon,notification->timeout() *1000 ); + _trayIcon->showMessage ( Notification::toPlainText(notification->title()),Notification::toPlainText(notification->text()),QSystemTrayIcon::NoIcon,notification->timeout() *1000 ); QTimer *t = new QTimer(notification.data()); t->setInterval(notification->timeout() *1000); connect(t,SIGNAL(timeout()),this,SLOT(displayNotification())); diff --git a/src/main.cpp b/src/main.cpp index b258a85..162d96e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ int main ( int argc, char *argv[] ) trayIcon->setVisible(true); SnoreServer *s = new SnoreServer( trayIcon ); + s->cleanupTMP(); QDir pluginsDir ( a.applicationDirPath() +"/snoreplugins" ); foreach ( QString fileName, pluginsDir.entryList ( QDir::Files ) ) diff --git a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp index ec241ca..0222abe 100644 --- a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp +++ b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp @@ -64,14 +64,10 @@ void FreedesktopNotification_Frontend::notificationClosed(QSharedPointertoString(); a<application(); a<>(const QDBusArgument &a, FreedesktopNotification &) { -//not supported + //not supported return a; } -FreedesktopImageHint::FreedesktopImageHint() { +QHash FreedesktopImageHint::hasedImages; + +FreedesktopImageHint::FreedesktopImageHint() +{ FreedesktopNotification::registerTypes(); } -FreedesktopImageHint::FreedesktopImageHint(const QImage &img) { +FreedesktopImageHint::FreedesktopImageHint(const QImage &img) +{ FreedesktopNotification::registerTypes(); QImage image(img.convertToFormat(QImage::Format_ARGB32)); + this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes()); + if(hasedImages.contains(computeHash())) + return; width=image.width(); height=image.height(); rowstride=image.bytesPerLine(); hasAlpha=image.hasAlphaChannel(); channels =image.isGrayscale()?1:hasAlpha?4:3; bitsPerSample=image.depth()/channels; - this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes()); + +} + +QString FreedesktopImageHint::computeHash(){ + if(this->_hash.isEmpty()){ + Q_ASSERT(!imageData.isEmpty()); + QCryptographicHash h(QCryptographicHash::Md5); + h.addData(imageData); + this->_hash = h.result().toHex(); + } + return this->_hash; +} +QString FreedesktopImageHint::hash()const{ + Q_ASSERT(!_hash.isEmpty()); + return _hash; } @@ -100,8 +121,9 @@ QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) { } const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) { - a.beginStructure(); + a.beginStructure(); a >> i.width>> i.height>> i.rowstride>> i.hasAlpha>> i.bitsPerSample>> i.channels>> i.imageData; a.endStructure(); + FreedesktopImageHint::hasedImages.insert(i.computeHash(),NULL); return a; } diff --git a/src/plugins/freedesktopnotification/fredesktopnotification.h b/src/plugins/freedesktopnotification/fredesktopnotification.h index 95a5e65..a807adc 100644 --- a/src/plugins/freedesktopnotification/fredesktopnotification.h +++ b/src/plugins/freedesktopnotification/fredesktopnotification.h @@ -44,8 +44,12 @@ const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotificati class FreedesktopImageHint { public: + static QHash hasedImages; +public: FreedesktopImageHint(); FreedesktopImageHint(const QImage &img); + QString hash()const; + QString computeHash(); QImage toQImage()const; @@ -56,6 +60,7 @@ public: int bitsPerSample; int channels; QByteArray imageData; + QString _hash; };