some small fixes hopfully improved performace of fredesktopnotification
This commit is contained in:
parent
93536f2070
commit
3b314daa6d
|
@ -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 ) :
|
||||
|
|
|
@ -27,12 +27,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
|
||||
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 );
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class SNORE_EXPORT SnoreServer:public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
static const QString snoreTMP;
|
||||
static void cleanupTMP();
|
||||
|
||||
|
||||
public:
|
||||
|
|
|
@ -49,7 +49,7 @@ void TrayIconNotifer::displayNotification(){
|
|||
}
|
||||
QSharedPointer<Notification> notification = _notificationQue.takeLast();
|
||||
qDebug()<<"taking"<<notification->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()));
|
||||
|
|
|
@ -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 ) )
|
||||
|
|
|
@ -64,14 +64,10 @@ void FreedesktopNotification_Frontend::notificationClosed(QSharedPointer<Notific
|
|||
}
|
||||
|
||||
QString FreedesktopNotification_Frontend::getImagefromHint(const FreedesktopImageHint &img){
|
||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||
hash.addData(img.imageData);
|
||||
QString filename=SnoreServer::snoreTMP+hash.result().toHex()+".png";
|
||||
QFile file(filename);
|
||||
if(file.exists())return filename;
|
||||
|
||||
QString filename=QString(SnoreServer::snoreTMP).append(img.hash()).append(".png");
|
||||
if(QFile::exists(filename))
|
||||
return filename;
|
||||
img.toQImage().save(filename,"PNG");
|
||||
qDebug()<<"Saving to "<<filename;
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void FreedesktopNotification::registerTypes() {
|
|||
}
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i) {
|
||||
// Q_ASSERT(!i.notification.isNull());
|
||||
// Q_ASSERT(!i.notification.isNull());
|
||||
qDebug()<<i.notification->toString();
|
||||
a<<i.notification->application();
|
||||
a<<uint(0);
|
||||
|
@ -64,27 +64,48 @@ QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i) {
|
|||
}
|
||||
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &) {
|
||||
//not supported
|
||||
//not supported
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint() {
|
||||
QHash<QString,void*> 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;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,12 @@ const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotificati
|
|||
class FreedesktopImageHint
|
||||
{
|
||||
public:
|
||||
static QHash<QString,void*> 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;
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue