Code reformatted using kde-dev-scripts/astyle-kdelibs

This commit is contained in:
Patrick von Reth 2014-09-11 14:36:34 +02:00
parent e613f1de73
commit 0d46672737
65 changed files with 1323 additions and 1667 deletions

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -67,15 +66,11 @@ bool Alert::isValid() const
return d; return d;
} }
QDebug operator<<(QDebug debug, const Alert &alert) QDebug operator<<(QDebug debug, const Alert &alert)
{ {
if(alert.isValid()) if (alert.isValid()) {
{
debug << "Snore::Alert(" << alert.name() << ")" ; debug << "Snore::Alert(" << alert.name() << ")" ;
} } else {
else
{
debug << "Snore::Alert(0x00)" ; debug << "Snore::Alert(0x00)" ;
} }
return debug.maybeSpace(); return debug.maybeSpace();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -94,5 +93,4 @@ private:
QDebug SNORE_EXPORT operator<< (QDebug debug, const Snore::Alert &alert); QDebug SNORE_EXPORT operator<< (QDebug debug, const Snore::Alert &alert);
#endif // ALERT_H #endif // ALERT_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#include "application.h" #include "application.h"
#include "application_p.h" #include "application_p.h"
using namespace Snore; using namespace Snore;
Application::Application(): Application::Application():
@ -86,17 +84,13 @@ const Hint &Application::constHints() const
QDebug operator<< (QDebug debug, const Snore::Application &app) QDebug operator<< (QDebug debug, const Snore::Application &app)
{ {
if(app.isValid()) if (app.isValid()) {
{
debug << "Snore::Application(" << app.name() << ", "; debug << "Snore::Application(" << app.name() << ", ";
foreach(const Alert &a, app.alerts()) foreach(const Alert & a, app.alerts()) {
{
debug << a << ", "; debug << a << ", ";
} }
debug << ")" ; debug << ")" ;
} } else {
else
{
debug << "Snore::Application(0x00)" ; debug << "Snore::Application(0x00)" ;
} }
return debug.maybeSpace(); return debug.maybeSpace();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -25,7 +24,8 @@
#include "alert.h" #include "alert.h"
#include <QHash> #include <QHash>
namespace Snore{ namespace Snore
{
class ApplicationData; class ApplicationData;
@ -110,7 +110,6 @@ public:
private: private:
QExplicitlySharedDataPointer<ApplicationData> d; QExplicitlySharedDataPointer<ApplicationData> d;
}; };
} }
@ -118,6 +117,4 @@ Q_DECLARE_METATYPE(Snore::Application)
SNORE_EXPORT QDebug operator<< (QDebug debug, const Snore::Application &app); SNORE_EXPORT QDebug operator<< (QDebug debug, const Snore::Application &app);
#endif // APPLICATION_H #endif // APPLICATION_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -40,12 +39,9 @@ void Hint::setValue(const QString &key, QObject *value)
QVariant Hint::value(const QString &k, const QVariant &defaultValue) const QVariant Hint::value(const QString &k, const QVariant &defaultValue) const
{ {
QString key(k.toLower()); QString key(k.toLower());
if(m_data.contains(key)) if (m_data.contains(key)) {
{
return m_data.value(key); return m_data.value(key);
} } else {
else
{
return defaultValue; return defaultValue;
} }
} }
@ -70,21 +66,16 @@ void Hint::setPrivateValue(const void *owner, const QString &key, QObject *value
connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection);
} }
QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const
{ {
QPair<quintptr, QString> key((quintptr)owner, k.toLower()); QPair<quintptr, QString> key((quintptr)owner, k.toLower());
if(m_privateData.contains(key)) if (m_privateData.contains(key)) {
{
return m_privateData.value(key); return m_privateData.value(key);
} } else {
else
{
return defaultValue; return defaultValue;
} }
} }
bool Hint::containsPrivateValue(const void *owner, const QString &key) const bool Hint::containsPrivateValue(const void *owner, const QString &key) const
{ {
QPair<quintptr, QString> pk((quintptr)owner, key.toLower()); QPair<quintptr, QString> pk((quintptr)owner, key.toLower());
@ -95,13 +86,10 @@ void Hint::slotValueDestroyed()
{ {
QObject *o = sender(); QObject *o = sender();
QString key = o->property("hint_key").toString(); QString key = o->property("hint_key").toString();
if(!o->property("hint_owner").isNull()) if (!o->property("hint_owner").isNull()) {
{
QPair<quintptr, QString> pk(o->property("hint_owner").value<quintptr>(), key); QPair<quintptr, QString> pk(o->property("hint_owner").value<quintptr>(), key);
m_privateData.remove(pk); m_privateData.remove(pk);
} } else {
else
{
m_data.remove(key); m_data.remove(key);
} }
} }
@ -109,18 +97,14 @@ void Hint::slotValueDestroyed()
QDebug operator<<(QDebug debug, const Snore::Hint &hint) QDebug operator<<(QDebug debug, const Snore::Hint &hint)
{ {
debug << "Snore::Hint("; debug << "Snore::Hint(";
for(QVariantHash::const_iterator it = hint.m_data.constBegin();it != hint.m_data.constEnd();++it) for (QVariantHash::const_iterator it = hint.m_data.constBegin(); it != hint.m_data.constEnd(); ++it) {
{ if (it != hint.m_data.constBegin()) {
if(it != hint.m_data.constBegin())
{
debug << ", "; debug << ", ";
} }
debug << "(" << it.key() << ", " << it.value(); debug << "(" << it.key() << ", " << it.value();
} }
for(QHash< QPair<quintptr, QString>, QVariant>::const_iterator it = hint.m_privateData.constBegin();it != hint.m_privateData.constEnd();++it) for (QHash< QPair<quintptr, QString>, QVariant>::const_iterator it = hint.m_privateData.constBegin(); it != hint.m_privateData.constEnd(); ++it) {
{ if (it != hint.m_privateData.constBegin()) {
if(it != hint.m_privateData.constBegin())
{
debug << ", "; debug << ", ";
} }
debug << "(" << it.key() << ", " << it.value(); debug << "(" << it.key() << ", " << it.value();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -116,10 +115,6 @@ private:
}; };
} }
#endif // HINT_H #endif // HINT_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -31,12 +30,9 @@ class Loger
public: public:
static int s_debugLevel; static int s_debugLevel;
static inline int debugLvl() static inline int debugLvl()
{ {
if(s_debugLevel == -1) if (s_debugLevel == -1) {
{
s_debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt(); s_debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt();
} }
return s_debugLevel; return s_debugLevel;
@ -45,8 +41,7 @@ static inline int debugLvl()
static inline bool isLogToFileEnabled() static inline bool isLogToFileEnabled()
{ {
static int s_logToFile = -1; static int s_logToFile = -1;
if(s_logToFile == -1) if (s_logToFile == -1) {
{
s_logToFile = qgetenv("LIBSNORE_LOG_TO_FILE").toInt(); s_logToFile = qgetenv("LIBSNORE_LOG_TO_FILE").toInt();
} }
return s_logToFile == 1; return s_logToFile == 1;
@ -56,12 +51,10 @@ static inline QTextStream &logFile()
{ {
static QTextStream *s_out = NULL; static QTextStream *s_out = NULL;
static QFile *s_file = NULL; static QFile *s_file = NULL;
if(!s_out) if (!s_out) {
{
QString name = QString("%1/libsnore/%2-log.txt").arg(QDir::tempPath(), qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName()); QString name = QString("%1/libsnore/%2-log.txt").arg(QDir::tempPath(), qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName());
if(!qgetenv("LIBSNORE_LOGFILE").isNull()) if (!qgetenv("LIBSNORE_LOGFILE").isNull()) {
{
name = QString(qgetenv("LIBSNORE_LOGFILE")); name = QString(qgetenv("LIBSNORE_LOGFILE"));
} }
std::cout << "Started logging to " << name.toUtf8().constData() << std::endl; std::cout << "Started logging to " << name.toUtf8().constData() << std::endl;
@ -73,7 +66,6 @@ static inline QTextStream &logFile()
return *s_out; return *s_out;
} }
}; };
int Loger::s_debugLevel = -1; int Loger::s_debugLevel = -1;
@ -86,13 +78,11 @@ SnoreLog::SnoreLog(SnoreDebugLevels lvl):
SnoreLog::~SnoreLog() SnoreLog::~SnoreLog()
{ {
if(Loger::isLogToFileEnabled()) if (Loger::isLogToFileEnabled()) {
{
Loger::logFile() << m_msg << "\n"; Loger::logFile() << m_msg << "\n";
Loger::logFile().flush(); Loger::logFile().flush();
} }
if(Loger::debugLvl() >= m_lvl) if (Loger::debugLvl() >= m_lvl) {
{
std::cout << m_msg.toLatin1().constData() << std::endl; std::cout << m_msg.toLatin1().constData() << std::endl;
} }
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -23,8 +22,6 @@
#include <QDebug> #include <QDebug>
#include "snore_exports.h" #include "snore_exports.h"
/** /**
* @file * @file
*/ */
@ -32,8 +29,7 @@
/** /**
* SnoreDebugLevels enumerates all possible debugg levels. * SnoreDebugLevels enumerates all possible debugg levels.
*/ */
enum SnoreDebugLevels enum SnoreDebugLevels {
{
/** /**
* The most important messages, will be diplayed if the debug level >= 1 * The most important messages, will be diplayed if the debug level >= 1
*/ */
@ -51,7 +47,6 @@ enum SnoreDebugLevels
}; };
/** /**
* Logg macro use to logg messages. * Logg macro use to logg messages.
* snoreDebug( SNORE_DEBUG ) << "Message" << notification; * snoreDebug( SNORE_DEBUG ) << "Message" << notification;
@ -63,7 +58,6 @@ enum SnoreDebugLevels
#define snoreDebug(X) QNoDebug() #define snoreDebug(X) QNoDebug()
#endif #endif
namespace Snore namespace Snore
{ {
@ -95,9 +89,6 @@ private:
QString m_msg; QString m_msg;
}; };
} }
#endif // SNORELOG_H #endif // SNORELOG_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -65,7 +64,8 @@ Icon::~Icon()
} }
const QImage &Icon::image() const{ const QImage &Icon::image() const
{
return d->image(); return d->image();
} }
@ -94,7 +94,6 @@ QString Icon::url() const
return d->m_url; return d->m_url;
} }
bool Snore::Icon::isRemoteFile() const bool Snore::Icon::isRemoteFile() const
{ {
return d->m_isRemoteFile; return d->m_isRemoteFile;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,8 @@
#include <QSharedData> #include <QSharedData>
#include <QDebug> #include <QDebug>
namespace Snore{ namespace Snore
{
class Icon; class Icon;
} }
@ -117,6 +117,4 @@ private:
}; };
} }
#endif // NOTIFICATION_ICON_H #endif // NOTIFICATION_ICON_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -35,8 +34,7 @@ IconData::IconData(const QString &url):
m_isLocalFile(false), m_isLocalFile(false),
m_isResource(m_url.startsWith(":/") || m_url.startsWith("qrc:/")) m_isResource(m_url.startsWith(":/") || m_url.startsWith("qrc:/"))
{ {
if(!m_isResource && QFile::exists(url)) if (!m_isResource && QFile::exists(url)) {
{
m_isLocalFile = true; m_isLocalFile = true;
m_localUrl = url; m_localUrl = url;
} }
@ -61,14 +59,10 @@ IconData::~IconData()
const QImage &IconData::image() const QImage &IconData::image()
{ {
QMutexLocker lock(&m_mutex); QMutexLocker lock(&m_mutex);
if(m_img.isNull()) if (m_img.isNull()) {
{ if (!m_isRemoteFile) {
if(!m_isRemoteFile )
{
m_img = QImage(m_url); m_img = QImage(m_url);
} } else {
else
{
download(); download();
} }
} }
@ -77,11 +71,9 @@ const QImage &IconData::image()
QString IconData::localUrl() QString IconData::localUrl()
{ {
if(!m_isLocalFile && !s_localImageCache.contains(m_localUrl)) if (!m_isLocalFile && !s_localImageCache.contains(m_localUrl)) {
{
QImage img = image(); QImage img = image();
if(!s_localImageCache.contains(m_localUrl))//double check as image() could have called download if (!s_localImageCache.contains(m_localUrl)) { //double check as image() could have called download
{
img.save(m_localUrl , "PNG"); img.save(m_localUrl , "PNG");
s_localImageCache.insert(m_localUrl); s_localImageCache.insert(m_localUrl);
snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache"; snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache";
@ -90,13 +82,10 @@ QString IconData::localUrl()
return m_localUrl; return m_localUrl;
} }
void IconData::download() void IconData::download()
{ {
if(m_isRemoteFile) if (m_isRemoteFile) {
{ if (!s_localImageCache.contains(m_localUrl)) {
if(!s_localImageCache.contains(m_localUrl))
{
snoreDebug(SNORE_DEBUG) << "Downloading:" << m_url; snoreDebug(SNORE_DEBUG) << "Downloading:" << m_url;
QNetworkAccessManager manager; QNetworkAccessManager manager;
QEventLoop loop; QEventLoop loop;
@ -106,16 +95,13 @@ void IconData::download()
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); //timeout QTimer::singleShot(1000, &loop, SLOT(quit())); //timeout
loop.exec(); loop.exec();
if(reply->isFinished()) if (reply->isFinished()) {
{
m_img = QImage::fromData(reply->readAll(), "PNG"); m_img = QImage::fromData(reply->readAll(), "PNG");
m_img.save(m_localUrl, "PNG"); m_img.save(m_localUrl, "PNG");
s_localImageCache.insert(m_localUrl); s_localImageCache.insert(m_localUrl);
snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache"; snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache";
} }
} } else {
else
{
m_img = QImage(m_localUrl); m_img = QImage(m_localUrl);
} }
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#ifndef ICONDATA_H #ifndef ICONDATA_H
#define ICONDATA_H #define ICONDATA_H
#include "notification.h" #include "notification.h"
#include "snore_p.h" #include "snore_p.h"
@ -33,7 +31,8 @@
#include <QMutex> #include <QMutex>
namespace Snore{ namespace Snore
{
class IconData : public QSharedData class IconData : public QSharedData
{ {
@ -46,7 +45,6 @@ public:
QString localUrl(); QString localUrl();
void download(); void download();
QImage m_img; QImage m_img;
QString m_url; QString m_url;
QString m_hash; QString m_hash;
@ -56,7 +54,6 @@ public:
bool m_isRemoteFile; bool m_isRemoteFile;
QMutex m_mutex; QMutex m_mutex;
static QSet<QString> s_localImageCache; static QSet<QString> s_localImageCache;
private: private:

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -27,10 +26,8 @@
using namespace Snore; using namespace Snore;
int Notification::m_defaultTimeout = 10; int Notification::m_defaultTimeout = 10;
Notification::Notification() : Notification::Notification() :
d(NULL) d(NULL)
{ {
@ -117,7 +114,6 @@ bool Notification::isSticky() const
return d->m_timeout == 0; return d->m_timeout == 0;
} }
Notification::Prioritys Notification::priority() const Notification::Prioritys Notification::priority() const
{ {
return d->m_priority; return d->m_priority;
@ -128,13 +124,13 @@ void Notification::addAction(const Action &a)
d->m_actions.insert(a.id(), a); d->m_actions.insert(a.id(), a);
} }
const QHash<int, Action> &Notification::actions() const const QHash<int, Action> &Notification::actions() const
{ {
return d->m_actions; return d->m_actions;
} }
const Notification::CloseReasons &Notification::closeReason(){ const Notification::CloseReasons &Notification::closeReason()
{
return d->m_closeReason; return d->m_closeReason;
} }
@ -178,8 +174,7 @@ QDataStream &operator<< ( QDataStream &stream, const Notification &noti )
QDebug operator <<(QDebug debug, const Snore::Notification::CloseReasons &flags) QDebug operator <<(QDebug debug, const Snore::Notification::CloseReasons &flags)
{ {
debug.nospace() << "CloseReasons("; debug.nospace() << "CloseReasons(";
switch(flags) switch (flags) {
{
debugPrintEnum(Notification::NONE); debugPrintEnum(Notification::NONE);
debugPrintEnum(Notification::TIMED_OUT); debugPrintEnum(Notification::TIMED_OUT);
debugPrintEnum(Notification::DISMISSED); debugPrintEnum(Notification::DISMISSED);
@ -194,8 +189,7 @@ QDebug operator <<(QDebug debug, const Snore::Notification::CloseReasons &flags)
QDebug operator<< (QDebug debug, const Snore::Notification::Prioritys &flags) QDebug operator<< (QDebug debug, const Snore::Notification::Prioritys &flags)
{ {
debug.nospace() << "Prioritys("; debug.nospace() << "Prioritys(";
switch(flags) switch (flags) {
{
debugPrintEnum(Notification::LOW); debugPrintEnum(Notification::LOW);
debugPrintEnum(Notification::NORMAL); debugPrintEnum(Notification::NORMAL);
debugPrintEnum(Notification::HIGH); debugPrintEnum(Notification::HIGH);

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -28,7 +27,6 @@
#include <QVariant> #include <QVariant>
#include <QDebug> #include <QDebug>
namespace Snore namespace Snore
{ {
@ -41,7 +39,6 @@ class NotificationData;
* @author Patrick von Reth \<vonreth at kde.org\> * @author Patrick von Reth \<vonreth at kde.org\>
*/ */
class SNORE_EXPORT Notification class SNORE_EXPORT Notification
{ {
friend class NotificationData; friend class NotificationData;
@ -49,8 +46,7 @@ public:
/** /**
* The reason why the Notification was closed. * The reason why the Notification was closed.
*/ */
enum CloseReason enum CloseReason {
{
/** /**
* The default value, the notification was not closed. * The default value, the notification was not closed.
*/ */
@ -86,8 +82,7 @@ public:
* The Priority for the Notification. * The Priority for the Notification.
* Some notification systems support this flag to filter notifications or indicate different prioritys by color. * Some notification systems support this flag to filter notifications or indicate different prioritys by color.
*/ */
enum Priority enum Priority {
{
/** /**
* Indicates a low priority. * Indicates a low priority.
*/ */
@ -241,7 +236,6 @@ public:
*/ */
bool isValid() const; bool isValid() const;
/** /**
* *
* @return the old notification to be replaced * @return the old notification to be replaced
@ -279,7 +273,6 @@ private:
static int m_defaultTimeout; static int m_defaultTimeout;
}; };
} }
@ -297,21 +290,16 @@ SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Notification::Prioritys &)
inline QDebug operator<< (QDebug debug, const Snore::Notification &noti) inline QDebug operator<< (QDebug debug, const Snore::Notification &noti)
{ {
if(noti.isValid()) if (noti.isValid()) {
{
debug.nospace() << "Snore::Notification(" << noti.title() << ", " << noti.text() << ", id = " << noti.id(); debug.nospace() << "Snore::Notification(" << noti.title() << ", " << noti.text() << ", id = " << noti.id();
if(noti.isUpdate()) if (noti.isUpdate()) {
{
debug << ", oldID = " << noti.old().id(); debug << ", oldID = " << noti.old().id();
} }
debug << ")" ; debug << ")" ;
} } else {
else
{
debug.nospace() << "Snore::Notification(0x00)" ; debug.nospace() << "Snore::Notification(0x00)" ;
} }
return debug.maybeSpace(); return debug.maybeSpace();
} }
#endif // NOTIFICATION_H #endif // NOTIFICATION_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -17,8 +16,6 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "notification/notification_p.h" #include "notification/notification_p.h"
#include "notification/icon.h" #include "notification/icon.h"
#include "../hint.h" #include "../hint.h"
@ -68,15 +65,13 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString
NotificationData::~NotificationData() NotificationData::~NotificationData()
{ {
if(!m_timeoutTimer.isNull()) if (!m_timeoutTimer.isNull()) {
{
m_timeoutTimer->deleteLater(); m_timeoutTimer->deleteLater();
} }
notificationCount--; notificationCount--;
snoreDebug(SNORE_DEBUG) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason; snoreDebug(SNORE_DEBUG) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason;
} }
void NotificationData::setActionInvoked(const Snore::Action &action) void NotificationData::setActionInvoked(const Snore::Action &action)
{ {
m_actionInvoked = action; m_actionInvoked = action;
@ -104,8 +99,7 @@ void NotificationData::setCloseReason(Snore::Notification::CloseReasons r)
QTimer *NotificationData::timeoutTimer() QTimer *NotificationData::timeoutTimer()
{ {
if(m_timeoutTimer.isNull()) if (m_timeoutTimer.isNull()) {
{
m_timeoutTimer = new QTimer(); m_timeoutTimer = new QTimer();
m_timeoutTimer->setSingleShot(true); m_timeoutTimer->setSingleShot(true);
m_timeoutTimer->setProperty("notificationID", m_id); m_timeoutTimer->setProperty("notificationID", m_id);

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#ifndef NOTIFICATIONDATA_H #ifndef NOTIFICATIONDATA_H
#define NOTIFICATIONDATA_H #define NOTIFICATIONDATA_H
#include "icon.h" #include "icon.h"
#include "notification.h" #include "notification.h"
#include "../hint.h" #include "../hint.h"
@ -29,9 +27,8 @@
#include <QTimer> #include <QTimer>
#include <QPointer> #include <QPointer>
namespace Snore
namespace Snore{ {
class SNORE_EXPORT NotificationData : public QSharedData class SNORE_EXPORT NotificationData : public QSharedData
{ {
@ -43,7 +40,6 @@ public:
NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority); NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority);
~NotificationData(); ~NotificationData();
void setSource(class SnoreFrontend *source); void setSource(class SnoreFrontend *source);
@ -52,10 +48,8 @@ public:
void setActionInvoked(const Action &action); void setActionInvoked(const Action &action);
void setActionInvoked(const int &actionID); void setActionInvoked(const int &actionID);
void setCloseReason(Notification::CloseReasons r); void setCloseReason(Notification::CloseReasons r);
QTimer *timeoutTimer(); QTimer *timeoutTimer();
private: private:
@ -78,8 +72,6 @@ private:
Notification m_toReplace; Notification m_toReplace;
QPointer<QTimer> m_timeoutTimer; QPointer<QTimer> m_timeoutTimer;
static uint notificationCount; static uint notificationCount;
static uint m_idCount; static uint m_idCount;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,6 @@
#include <QDataStream> #include <QDataStream>
namespace Snore namespace Snore
{ {

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -35,7 +34,6 @@ using namespace Snore;
QHash<SnorePlugin::PluginTypes, QHash<QString, PluginContainer *> > PluginContainer::s_pluginCache; QHash<SnorePlugin::PluginTypes, QHash<QString, PluginContainer *> > PluginContainer::s_pluginCache;
PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type): PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type):
m_pluginFile(fileName), m_pluginFile(fileName),
m_pluginName(pluginName), m_pluginName(pluginName),
@ -52,8 +50,7 @@ PluginContainer::~PluginContainer()
SnorePlugin *PluginContainer::load() SnorePlugin *PluginContainer::load()
{ {
if(!m_loader.isLoaded() && !m_loader.load()) if (!m_loader.isLoaded() && !m_loader.load()) {
{
snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << m_loader.errorString(); snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << m_loader.errorString();
return NULL; return NULL;
} }
@ -98,11 +95,9 @@ QString PluginContainer::typeToString(const SnorePlugin::PluginTypes t)
const QList<SnorePlugin::PluginTypes> &PluginContainer::types() const QList<SnorePlugin::PluginTypes> &PluginContainer::types()
{ {
static QList<SnorePlugin::PluginTypes> t; static QList<SnorePlugin::PluginTypes> t;
if(t.isEmpty()) if (t.isEmpty()) {
{
QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType"));
for (int i = 0; i < e.keyCount(); ++i) for (int i = 0; i < e.keyCount(); ++i) {
{
t << (SnorePlugin::PluginTypes) e.value(i); t << (SnorePlugin::PluginTypes) e.value(i);
} }
} }
@ -112,10 +107,8 @@ const QList<SnorePlugin::PluginTypes> &PluginContainer::types()
void PluginContainer::updatePluginCache() void PluginContainer::updatePluginCache()
{ {
snoreDebug(SNORE_DEBUG) << "Updating plugin cache"; snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
foreach(PluginContaienrHash list, s_pluginCache) foreach(PluginContaienrHash list, s_pluginCache) {
{ foreach(PluginContainer * p, list.values()) {
foreach(PluginContainer* p, list.values())
{
delete p; delete p;
} }
list.clear(); list.clear();
@ -123,22 +116,18 @@ void PluginContainer::updatePluginCache()
QList<PluginContainer *> plugins; QList<PluginContainer *> plugins;
foreach(const SnorePlugin::PluginTypes type,PluginContainer::types()) foreach(const SnorePlugin::PluginTypes type, PluginContainer::types()) {
{
foreach(const QFileInfo & file, pluginDir().entryInfoList( foreach(const QFileInfo & file, pluginDir().entryInfoList(
QStringList(pluginFileFilters(type)), QDir::Files)) QStringList(pluginFileFilters(type)), QDir::Files)) {
{
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath(); snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath()); QPluginLoader loader(file.absoluteFilePath());
QObject *plugin = loader.instance(); QObject *plugin = loader.instance();
if (plugin == NULL)//TODO: Qt5 json stuff if (plugin == NULL) { //TODO: Qt5 json stuff
{
snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << file.absoluteFilePath() << loader.errorString(); snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << file.absoluteFilePath() << loader.errorString();
continue; continue;
} }
SnorePlugin *sp = qobject_cast<SnorePlugin *>(plugin); SnorePlugin *sp = qobject_cast<SnorePlugin *>(plugin);
if(sp == NULL) if (sp == NULL) {
{
snoreDebug(SNORE_WARNING) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ; snoreDebug(SNORE_WARNING) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ;
loader.unload(); loader.unload();
continue; continue;
@ -153,8 +142,7 @@ void PluginContainer::updatePluginCache()
const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin::PluginTypes type) const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin::PluginTypes type)
{ {
if(s_pluginCache.isEmpty()) if (s_pluginCache.isEmpty()) {
{
QTime time; QTime time;
time.start(); time.start();
updatePluginCache(); updatePluginCache();
@ -162,15 +150,11 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
} }
QHash<QString, PluginContainer *> out; QHash<QString, PluginContainer *> out;
if(type == SnorePlugin::ALL) if (type == SnorePlugin::ALL) {
{ foreach(const SnorePlugin::PluginTypes & t, types()) {
foreach(const SnorePlugin::PluginTypes &t,types())
{
out.unite(s_pluginCache.value(t)); out.unite(s_pluginCache.value(t));
} }
} } else {
else
{
out = s_pluginCache[type]; out = s_pluginCache[type];
} }
return out; return out;
@ -180,14 +164,12 @@ const QDir &PluginContainer::pluginDir()
{ {
static bool isLoaded = false; static bool isLoaded = false;
static QDir path; static QDir path;
if(!isLoaded) if (!isLoaded) {
{
isLoaded = true; isLoaded = true;
QString appDir = qApp->applicationDirPath(); QString appDir = qApp->applicationDirPath();
QStringList list; QStringList list;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
if ( appDir == "MacOS" ) if (appDir == "MacOS") {
{
list << appDir; list << appDir;
QDir dir(appDir); QDir dir(appDir);
// Development convenience-hack // Development convenience-hack
@ -202,21 +184,16 @@ const QDir &PluginContainer::pluginDir()
<< QString("%1/../lib/libsnore" SNORE_SUFFIX).arg(appDir) << QString("%1/../lib/libsnore" SNORE_SUFFIX).arg(appDir)
<< QString("%1/../lib64/libsnore" SNORE_SUFFIX).arg(appDir) << QString("%1/../lib64/libsnore" SNORE_SUFFIX).arg(appDir)
<< QLatin1String(LIBSNORE_PLUGIN_PATH); << QLatin1String(LIBSNORE_PLUGIN_PATH);
foreach(const QString &p, list) foreach(const QString & p, list) {
{
path = QDir(p); path = QDir(p);
if(!path.entryInfoList(pluginFileFilters()).isEmpty()) if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {
{
break; break;
} } else {
else
{
snoreDebug(SNORE_DEBUG) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins."; snoreDebug(SNORE_DEBUG) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins.";
} }
} }
if(path.entryInfoList(pluginFileFilters()).isEmpty()) if (path.entryInfoList(pluginFileFilters()).isEmpty()) {
{
snoreDebug(SNORE_WARNING) << "Couldnt find any plugins"; snoreDebug(SNORE_WARNING) << "Couldnt find any plugins";
} }
snoreDebug(SNORE_INFO) << "PluginPath is :" << path.absolutePath(); snoreDebug(SNORE_INFO) << "PluginPath is :" << path.absolutePath();
@ -224,4 +201,3 @@ const QDir &PluginContainer::pluginDir()
return path; return path;
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -27,8 +26,6 @@
#include <QFlag> #include <QFlag>
#include <QPluginLoader> #include <QPluginLoader>
namespace Snore namespace Snore
{ {
class PluginContainer; class PluginContainer;
@ -50,7 +47,6 @@ public:
bool isLoaded() const; bool isLoaded() const;
static SnorePlugin::PluginTypes typeFromString(const QString &t); static SnorePlugin::PluginTypes typeFromString(const QString &t);
static QString typeToString(const SnorePlugin::PluginTypes t); static QString typeToString(const SnorePlugin::PluginTypes t);
static const QList<SnorePlugin::PluginTypes> &types(); static const QList<SnorePlugin::PluginTypes> &types();
@ -78,8 +74,7 @@ private:
static inline const QStringList pluginFileFilters() static inline const QStringList pluginFileFilters()
{ {
QStringList out; QStringList out;
foreach(const QString extention, pluginExtentions()) foreach(const QString extention, pluginExtentions()) {
{
out << QString("libsnore_*.%1").arg(extention); out << QString("libsnore_*.%1").arg(extention);
} }
return out; return out;
@ -88,8 +83,7 @@ private:
static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type) static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type)
{ {
QStringList out; QStringList out;
foreach(const QString extention, pluginExtentions()) foreach(const QString extention, pluginExtentions()) {
{
out << QString("libsnore_%1_*.%2").arg(typeToString(type).toLower(), extention); out << QString("libsnore_%1_*.%2").arg(typeToString(type).toLower(), extention);
} }
return out; return out;
@ -102,5 +96,4 @@ private:
}; };
} }
#endif//PLUGINCONTAINER_H #endif//PLUGINCONTAINER_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -35,8 +34,7 @@ SnorePlugin::SnorePlugin ( const QString &name ) :
m_name(name), m_name(name),
m_initialized(false) m_initialized(false)
{ {
if(thread() != qApp->thread()) if (thread() != qApp->thread()) {
{
moveToThread(qApp->thread()); moveToThread(qApp->thread());
} }
} }
@ -48,8 +46,7 @@ SnorePlugin::~SnorePlugin()
bool SnorePlugin::initialize(SnoreCore *snore) bool SnorePlugin::initialize(SnoreCore *snore)
{ {
if(m_initialized) if (m_initialized) {
{
qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData()); qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData());
return false; return false;
} }
@ -76,8 +73,7 @@ const QString &SnorePlugin::name() const
bool SnorePlugin::deinitialize() bool SnorePlugin::deinitialize()
{ {
if(m_initialized) if (m_initialized) {
{
snoreDebug(SNORE_DEBUG) << "Deinitialize" << m_name << this; snoreDebug(SNORE_DEBUG) << "Deinitialize" << m_name << this;
m_initialized = false; m_initialized = false;
return true; return true;
@ -85,24 +81,18 @@ bool SnorePlugin::deinitialize()
return false; return false;
} }
QDebug operator <<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags) QDebug operator <<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags)
{ {
QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType"));
debug.nospace() << "PluginTypes("; debug.nospace() << "PluginTypes(";
bool needSeparator = false; bool needSeparator = false;
int key; int key;
for (int i = 0; i < e.keyCount(); ++i) for (int i = 0; i < e.keyCount(); ++i) {
{
key = e.value(i); key = e.value(i);
if (flags.testFlag((SnorePlugin::PluginType)key)) if (flags.testFlag((SnorePlugin::PluginType)key)) {
{ if (needSeparator) {
if (needSeparator)
{
debug.nospace() << '|'; debug.nospace() << '|';
} } else {
else
{
needSeparator = true; needSeparator = true;
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -27,12 +26,11 @@
#include <QTimer> #include <QTimer>
#include <QtPlugin> #include <QtPlugin>
namespace Snore
namespace Snore{ {
class Application; class Application;
class SnoreCore; class SnoreCore;
class SNORE_EXPORT SnorePlugin : public QObject class SNORE_EXPORT SnorePlugin : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -47,7 +45,6 @@ public:
Q_DECLARE_FLAGS(PluginTypes, PluginType) Q_DECLARE_FLAGS(PluginTypes, PluginType)
Q_ENUMS(PluginType) Q_ENUMS(PluginType)
SnorePlugin(const QString &name); SnorePlugin(const QString &name);
virtual ~SnorePlugin(); virtual ~SnorePlugin();
virtual bool initialize(SnoreCore *snore); virtual bool initialize(SnoreCore *snore);
@ -62,11 +59,9 @@ private:
bool m_initialized; bool m_initialized;
QPointer<SnoreCore> m_snore; QPointer<SnoreCore> m_snore;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes) Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes)
} }
Q_DECLARE_INTERFACE(Snore::SnorePlugin, Q_DECLARE_INTERFACE(Snore::SnorePlugin,
"org.Snore.SnorePlugin/1.0") "org.Snore.SnorePlugin/1.0")
@ -87,6 +82,4 @@ SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::SnorePlugin::PluginTypes &
# define Q_PLUGIN_METADATA(a) # define Q_PLUGIN_METADATA(a)
#endif #endif
#endif//SNORE_PLUGINS_H #endif//SNORE_PLUGINS_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -30,7 +29,6 @@
#include <QThread> #include <QThread>
#include <QMetaMethod> #include <QMetaMethod>
using namespace Snore; using namespace Snore;
SnoreBackend::SnoreBackend(const QString &name , bool canCloseNotification, bool supportsRichtext, bool canUpdateNotifications) : SnoreBackend::SnoreBackend(const QString &name , bool canCloseNotification, bool supportsRichtext, bool canUpdateNotifications) :
@ -47,33 +45,28 @@ SnoreBackend::~SnoreBackend()
snoreDebug(SNORE_DEBUG) << "Deleting" << name(); snoreDebug(SNORE_DEBUG) << "Deleting" << name();
} }
bool SnoreBackend::initialize(SnoreCore *snore) bool SnoreBackend::initialize(SnoreCore *snore)
{ {
if(!SnorePlugin::initialize(snore)) if (!SnorePlugin::initialize(snore)) {
{
return false; return false;
} }
connect( snore->d(), SIGNAL(applicationRegistered(const Snore::Application&)), this, SLOT(slotRegisterApplication(const Snore::Application&)), Qt::QueuedConnection); connect(snore->d(), SIGNAL(applicationRegistered(Snore::Application)), this, SLOT(slotRegisterApplication(Snore::Application)), Qt::QueuedConnection);
connect( snore->d(), SIGNAL(applicationDeregistered(const Snore::Application&)), this, SLOT(slotDeregisterApplication(const Snore::Application&)), Qt::QueuedConnection); connect(snore->d(), SIGNAL(applicationDeregistered(Snore::Application)), this, SLOT(slotDeregisterApplication(Snore::Application)), Qt::QueuedConnection);
connect(this, SIGNAL(notificationClosed(Snore::Notification)), snore->d(), SLOT(slotNotificationClosed(Snore::Notification)), Qt::QueuedConnection); connect(this, SIGNAL(notificationClosed(Snore::Notification)), snore->d(), SLOT(slotNotificationClosed(Snore::Notification)), Qt::QueuedConnection);
connect(snore->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection); connect(snore->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection);
foreach(const Application &a,snore->aplications()) foreach(const Application & a, snore->aplications()) {
{
this->slotRegisterApplication(a); this->slotRegisterApplication(a);
} }
return true; return true;
} }
void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason) void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason)
{ {
if(canCloseNotification() && notification.isValid()) if (canCloseNotification() && notification.isValid()) {
{
closeNotification(notification, reason); closeNotification(notification, reason);
slotCloseNotification(notification); slotCloseNotification(notification);
} }
@ -81,16 +74,13 @@ void SnoreBackend::requestCloseNotification (Notification notification, Notifica
void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons reason) void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons reason)
{ {
if(!n.isValid()) if (!n.isValid()) {
{
return; return;
} }
if(m_activeNotifications.contains(n.id())) if (m_activeNotifications.contains(n.id())) {
{
m_activeNotifications.remove(n.id()); m_activeNotifications.remove(n.id());
} }
if(n.isUpdate() && m_activeNotifications.contains(n.old().id())) if (n.isUpdate() && m_activeNotifications.contains(n.old().id())) {
{
m_activeNotifications.remove(n.old().id()); m_activeNotifications.remove(n.old().id());
} }
n.data()->setCloseReason(reason); n.data()->setCloseReason(reason);
@ -122,8 +112,7 @@ SnoreSecondaryBackend::~SnoreSecondaryBackend()
bool SnoreSecondaryBackend::initialize(SnoreCore *snore) bool SnoreSecondaryBackend::initialize(SnoreCore *snore)
{ {
if(!SnorePlugin::initialize(snore)) if (!SnorePlugin::initialize(snore)) {
{
return false; return false;
} }
connect(snore->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection); connect(snore->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection);
@ -132,8 +121,7 @@ bool SnoreSecondaryBackend::initialize(SnoreCore *snore)
bool SnoreSecondaryBackend::deinitialize() bool SnoreSecondaryBackend::deinitialize()
{ {
if(SnorePlugin::deinitialize()) if (SnorePlugin::deinitialize()) {
{
disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification))); disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)));
return true; return true;
} }
@ -180,23 +168,18 @@ void SnoreBackend::addActiveNotification(Notification n)
m_activeNotifications.insert(n.id(), n); m_activeNotifications.insert(n.id(), n);
} }
bool SnoreBackend::deinitialize() bool SnoreBackend::deinitialize()
{ {
if(SnorePlugin::deinitialize()) if (SnorePlugin::deinitialize()) {
{ foreach(Notification n, m_activeNotifications) {
foreach(Notification n,m_activeNotifications)
{
requestCloseNotification(n, Notification::DISMISSED); requestCloseNotification(n, Notification::DISMISSED);
} }
foreach(const Application & a, snore()->aplications()) {
foreach(const Application &a,snore()->aplications())
{
slotDeregisterApplication(a); slotDeregisterApplication(a);
} }
disconnect( snore()->d(), SIGNAL(applicationRegistered(const Snore::Application&)), this, SLOT(slotRegisterApplication(const Snore::Application&))); disconnect(snore()->d(), SIGNAL(applicationRegistered(Snore::Application)), this, SLOT(slotRegisterApplication(Snore::Application)));
disconnect( snore()->d(), SIGNAL(applicationDeregistered(const Snore::Application&)), this, SLOT(slotDeregisterApplication(const Snore::Application&))); disconnect(snore()->d(), SIGNAL(applicationDeregistered(Snore::Application)), this, SLOT(slotDeregisterApplication(Snore::Application)));
disconnect(this, SIGNAL(notificationClosed(Snore::Notification)), snore()->d(), SLOT(slotNotificationClosed(Snore::Notification))); disconnect(this, SIGNAL(notificationClosed(Snore::Notification)), snore()->d(), SLOT(slotNotificationClosed(Snore::Notification)));
disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification))); disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)));
@ -205,22 +188,18 @@ bool SnoreBackend::deinitialize()
return false; return false;
} }
void SnoreBackend::startTimeout(Notification &notification) void SnoreBackend::startTimeout(Notification &notification)
{ {
if(thread() != QThread::currentThread()) if (thread() != QThread::currentThread()) {
{
metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification)); metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification));
return; return;
} }
if(notification.isSticky()) if (notification.isSticky()) {
{
return; return;
} }
QTimer *timer = notification.data()->timeoutTimer(); QTimer *timer = notification.data()->timeoutTimer();
timer->stop(); timer->stop();
if(notification.isUpdate()) if (notification.isUpdate()) {
{
notification.old().data()->timeoutTimer()->stop(); notification.old().data()->timeoutTimer()->stop();
} }
timer->setInterval(notification.timeout() * 1000); timer->setInterval(notification.timeout() * 1000);
@ -233,8 +212,7 @@ void SnoreBackend::notificationTimedOut()
QTimer *timer = qobject_cast<QTimer *>(sender()); QTimer *timer = qobject_cast<QTimer *>(sender());
Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt()); Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt());
if(n.isValid()) if (n.isValid()) {
{
snoreDebug(SNORE_DEBUG) << n; snoreDebug(SNORE_DEBUG) << n;
snore()->requestCloseNotification(n, Notification::TIMED_OUT); snore()->requestCloseNotification(n, Notification::TIMED_OUT);
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -27,7 +26,8 @@
#include <QPointer> #include <QPointer>
#include <QFlag> #include <QFlag>
namespace Snore{ namespace Snore
{
class SNORE_EXPORT SnoreBackend : public SnorePlugin class SNORE_EXPORT SnoreBackend : public SnorePlugin
{ {
@ -50,7 +50,6 @@ public:
signals: signals:
void notificationClosed(Snore::Notification); void notificationClosed(Snore::Notification);
public slots: public slots:
virtual void slotRegisterApplication(const Snore::Application &application); virtual void slotRegisterApplication(const Snore::Application &application);
virtual void slotDeregisterApplication(const Snore::Application &application); virtual void slotDeregisterApplication(const Snore::Application &application);
@ -77,14 +76,14 @@ private:
void addActiveNotification(Notification n); void addActiveNotification(Notification n);
friend void SnoreCore::broadcastNotification(Notification notification); friend void SnoreCore::broadcastNotification(Notification notification);
}; };
} }
Q_DECLARE_INTERFACE(Snore::SnoreBackend, Q_DECLARE_INTERFACE(Snore::SnoreBackend,
"org.Snore.NotificationBackend/1.0") "org.Snore.NotificationBackend/1.0")
namespace Snore{ namespace Snore
{
class SnoreCore; class SnoreCore;
class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin
@ -97,7 +96,6 @@ public:
virtual bool initialize(SnoreCore *snore); virtual bool initialize(SnoreCore *snore);
virtual bool deinitialize(); virtual bool deinitialize();
bool supportsRichtext(); bool supportsRichtext();
public slots: public slots:

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,8 @@
#include <QDir> #include <QDir>
#include <QDebug> #include <QDebug>
namespace Snore{ namespace Snore
{
SnoreFrontend::SnoreFrontend(const QString &name) : SnoreFrontend::SnoreFrontend(const QString &name) :
SnorePlugin(name) SnorePlugin(name)

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -26,12 +25,12 @@
#include <QPointer> #include <QPointer>
#include <QFlag> #include <QFlag>
namespace Snore{ namespace Snore
{
class Application; class Application;
class SnoreCore; class SnoreCore;
class SnorePlugin; class SnorePlugin;
class SNORE_EXPORT SnoreFrontend: public SnorePlugin class SNORE_EXPORT SnoreFrontend: public SnorePlugin
{ {
Q_OBJECT Q_OBJECT

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -37,7 +36,6 @@
using namespace Snore; using namespace Snore;
SnoreCore::SnoreCore(QSystemTrayIcon *trayIcon) SnoreCore::SnoreCore(QSystemTrayIcon *trayIcon)
{ {
SnoreCorePrivate::registerMetaTypes(); SnoreCorePrivate::registerMetaTypes();
@ -55,21 +53,16 @@ SnoreCore::~SnoreCore()
void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
foreach( SnorePlugin::PluginTypes type, PluginContainer::types()) foreach(SnorePlugin::PluginTypes type, PluginContainer::types()) {
{ if (type != SnorePlugin::ALL && types & type) {
if(type != SnorePlugin::ALL && types & type) foreach(PluginContainer * info, PluginContainer::pluginCache(type).values()) {
{ switch (info->type()) {
foreach( PluginContainer *info, PluginContainer::pluginCache(type).values())
{
switch(info->type())
{
case SnorePlugin::BACKEND: case SnorePlugin::BACKEND:
break; break;
case SnorePlugin::SECONDARY_BACKEND: case SnorePlugin::SECONDARY_BACKEND:
case SnorePlugin::FRONTEND: case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN: case SnorePlugin::PLUGIN:
if(!info->load()->initialize( this )) if (!info->load()->initialize(this)) {
{
info->unload(); info->unload();
break; break;
} }
@ -81,8 +74,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types )
snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type(); snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type();
d->m_plugins[info->type()].append(info->name()); d->m_plugins[info->type()].append(info->name());
} }
if(d->m_plugins.contains(type)) if (d->m_plugins.contains(type)) {
{
qSort(d->m_plugins[type]); qSort(d->m_plugins[type]);
} }
} }
@ -95,10 +87,8 @@ void SnoreCore::broadcastNotification ( Notification notification )
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout(); snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
if ( d->m_notificationBackend != NULL ) if (d->m_notificationBackend != NULL) {
{ if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
if(notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification())
{
requestCloseNotification(notification.old(), Notification::REPLACED); requestCloseNotification(notification.old(), Notification::REPLACED);
} }
d->m_notificationBackend->addActiveNotification(notification); d->m_notificationBackend->addActiveNotification(notification);
@ -109,8 +99,7 @@ void SnoreCore::broadcastNotification ( Notification notification )
void SnoreCore::registerApplication(const Application &application) void SnoreCore::registerApplication(const Application &application)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
if(!d->m_applications.contains(application.name())) if (!d->m_applications.contains(application.name())) {
{
snoreDebug(SNORE_DEBUG) << "Registering Application:" << application; snoreDebug(SNORE_DEBUG) << "Registering Application:" << application;
d->m_applications.insert(application.name(), application); d->m_applications.insert(application.name(), application);
emit d->applicationRegistered(application); emit d->applicationRegistered(application);
@ -130,7 +119,6 @@ const QHash<QString, Application> &SnoreCore::aplications() const
return d->m_applications; return d->m_applications;
} }
const QStringList SnoreCore::notificationBackends() const const QStringList SnoreCore::notificationBackends() const
{ {
Q_D(const SnoreCore); Q_D(const SnoreCore);
@ -152,28 +140,23 @@ const QStringList SnoreCore::secondaryNotificationBackends() const
bool SnoreCore::setPrimaryNotificationBackend(const QString &backend) bool SnoreCore::setPrimaryNotificationBackend(const QString &backend)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
if(backend == primaryNotificationBackend()) if (backend == primaryNotificationBackend()) {
{
return true; return true;
} }
const QHash<QString, PluginContainer *> backends = PluginContainer::pluginCache(SnorePlugin::BACKEND); const QHash<QString, PluginContainer *> backends = PluginContainer::pluginCache(SnorePlugin::BACKEND);
if(!backends.contains(backend)) if (!backends.contains(backend)) {
{
snoreDebug(SNORE_DEBUG) << "Unknown Backend:" << backend; snoreDebug(SNORE_DEBUG) << "Unknown Backend:" << backend;
return false; return false;
} }
snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend; snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend;
SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load()); SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load());
if(!b->isInitialized()) if (!b->isInitialized()) {
{ if (!b->initialize(this)) {
if(!b->initialize(this))
{
snoreDebug(SNORE_DEBUG) << "Failed to initialize" << b->name(); snoreDebug(SNORE_DEBUG) << "Failed to initialize" << b->name();
return false; return false;
} }
} }
if(d->m_notificationBackend) if (d->m_notificationBackend) {
{
d->m_notificationBackend->deinitialize(); d->m_notificationBackend->deinitialize();
} }
@ -185,35 +168,28 @@ bool SnoreCore::setPrimaryNotificationBackend()
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if(QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8 && d->setBackendIfAvailible("Windows 8")) if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8 && d->setBackendIfAvailible("Windows 8")) {
{
return true; return true;
} }
if(d->setBackendIfAvailible("Growl")) if (d->setBackendIfAvailible("Growl")) {
{
return true; return true;
} }
if(d->setBackendIfAvailible("Snarl")) if (d->setBackendIfAvailible("Snarl")) {
{
return true; return true;
} }
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
if(d->setBackendIfAvailible("FreedesktopNotification")) if (d->setBackendIfAvailible("FreedesktopNotification")) {
{
return true; return true;
} }
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
if(d->setBackendIfAvailible("OSX Notification Center")) if (d->setBackendIfAvailible("OSX Notification Center")) {
{
return true; return true;
} }
if(d->setBackendIfAvailible("Growl")) if (d->setBackendIfAvailible("Growl")) {
{
return true; return true;
} }
#endif #endif
if(d->setBackendIfAvailible("Snore")) if (d->setBackendIfAvailible("Snore")) {
{
return true; return true;
} }
return false; return false;
@ -222,14 +198,14 @@ bool SnoreCore::setPrimaryNotificationBackend()
const QString SnoreCore::primaryNotificationBackend() const const QString SnoreCore::primaryNotificationBackend() const
{ {
Q_D(const SnoreCore); Q_D(const SnoreCore);
if(d->m_notificationBackend.isNull()) if (d->m_notificationBackend.isNull()) {
{
return QString::null; return QString::null;
} }
return d->m_notificationBackend->name(); return d->m_notificationBackend->name();
} }
QSystemTrayIcon *SnoreCore::trayIcon(){ QSystemTrayIcon *SnoreCore::trayIcon()
{
Q_D(SnoreCore); Q_D(SnoreCore);
return d->m_trayIcon; return d->m_trayIcon;
} }
@ -237,8 +213,7 @@ QSystemTrayIcon *SnoreCore::trayIcon(){
Notification SnoreCore::getActiveNotificationByID(uint id) Notification SnoreCore::getActiveNotificationByID(uint id)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
if(!d->m_notificationBackend->isInitialized()) if (!d->m_notificationBackend->isInitialized()) {
{
qFatal("Notification backend %s isn't initialized will snore will exit now", d->m_notificationBackend->name().toLatin1().constData()); qFatal("Notification backend %s isn't initialized will snore will exit now", d->m_notificationBackend->name().toLatin1().constData());
} }
return d->m_notificationBackend->getActiveNotificationByID(id); return d->m_notificationBackend->getActiveNotificationByID(id);

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -33,7 +32,6 @@
class QSystemTrayIcon; class QSystemTrayIcon;
/** /**
* Snore is a platform independent Qt notification framework. * Snore is a platform independent Qt notification framework.
* *
@ -47,7 +45,8 @@ class QSystemTrayIcon;
* @author Patrick von Reth \<vonreth at kde.org\> * @author Patrick von Reth \<vonreth at kde.org\>
*/ */
namespace Snore{ namespace Snore
{
class SnoreCorePrivate; class SnoreCorePrivate;
/** /**
@ -76,7 +75,6 @@ public:
*/ */
void loadPlugins(SnorePlugin::PluginTypes types); void loadPlugins(SnorePlugin::PluginTypes types);
/** /**
* Broadcast a notification. * Broadcast a notification.
* @param notification the Notification * @param notification the Notification
@ -173,14 +171,12 @@ public:
*/ */
bool primaryBackendSupportsRichtext(); bool primaryBackendSupportsRichtext();
/** /**
* *
* @return a pointer to the private class, for internal use only. * @return a pointer to the private class, for internal use only.
*/ */
const SnoreCorePrivate *d(); const SnoreCorePrivate *d();
signals: signals:
/** /**
* This signal is emitted when an action on the Notification was performed. * This signal is emitted when an action on the Notification was performed.
@ -200,7 +196,6 @@ signals:
private: private:
SnoreCorePrivate *d_ptr; SnoreCorePrivate *d_ptr;
}; };
/** /**
@ -211,12 +206,9 @@ private:
static inline QString toPlainText(const QString &string) static inline QString toPlainText(const QString &string)
{ {
if(Qt::mightBeRichText(string)) if (Qt::mightBeRichText(string)) {
{
return QTextDocumentFragment::fromHtml(string).toPlainText(); return QTextDocumentFragment::fromHtml(string).toPlainText();
} } else {
else
{
return string; return string;
} }
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -17,7 +16,6 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "snore_p.h" #include "snore_p.h"
#include "snore.h" #include "snore.h"
#include "plugins/plugins.h" #include "plugins/plugins.h"
@ -39,8 +37,7 @@ SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
m_defaultApp("SnoreNotify", Icon(":/root/snore.png")) m_defaultApp("SnoreNotify", Icon(":/root/snore.png"))
{ {
snoreDebug(SNORE_INFO) << "Version:" << Version::version(); snoreDebug(SNORE_INFO) << "Version:" << Version::version();
if( !Version::revision().isEmpty() ) if (!Version::revision().isEmpty()) {
{
snoreDebug(SNORE_INFO) << "Revision:" << Version::revision(); snoreDebug(SNORE_INFO) << "Revision:" << Version::revision();
} }
@ -64,8 +61,7 @@ void SnoreCorePrivate::notificationActionInvoked(Notification notification) cons
{ {
Q_Q(const SnoreCore); Q_Q(const SnoreCore);
emit const_cast<SnoreCore *>(q)->actionInvoked(notification); emit const_cast<SnoreCore *>(q)->actionInvoked(notification);
if ( notification.data()->source() ) if (notification.data()->source()) {
{
notification.data()->source()->actionInvoked(notification); notification.data()->source()->actionInvoked(notification);
} }
} }
@ -73,8 +69,7 @@ void SnoreCorePrivate::notificationActionInvoked(Notification notification) cons
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend) bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);
if( m_plugins[SnorePlugin::BACKEND].contains(backend)) if (m_plugins[SnorePlugin::BACKEND].contains(backend)) {
{
return q->setPrimaryNotificationBackend(backend); return q->setPrimaryNotificationBackend(backend);
} }
return false; return false;
@ -105,18 +100,15 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);
emit q->notificationClosed(n); emit q->notificationClosed(n);
if(n.data()->source()) if (n.data()->source()) {
{
n.data()->source()->notificationClosed(n); n.data()->source()->notificationClosed(n);
} }
} }
void SnoreCorePrivate::slotAboutToQuit() void SnoreCorePrivate::slotAboutToQuit()
{ {
foreach (PluginContainer *p, PluginContainer::pluginCache(SnorePlugin::ALL)) foreach(PluginContainer * p, PluginContainer::pluginCache(SnorePlugin::ALL)) {
{ if (p->isLoaded()) {
if(p->isLoaded())
{
snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name(); snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name();
p->load()->deinitialize(); p->load()->deinitialize();
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -17,7 +16,6 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef SNORECOREPRIVATE_H #ifndef SNORECOREPRIVATE_H
#define SNORECOREPRIVATE_H #define SNORECOREPRIVATE_H
@ -54,12 +52,10 @@ public:
~SnoreCorePrivate(); ~SnoreCorePrivate();
const Application defaultApplication() const; const Application defaultApplication() const;
void notificationActionInvoked(Notification notification) const; void notificationActionInvoked(Notification notification) const;
bool setBackendIfAvailible(const QString &backend); bool setBackendIfAvailible(const QString &backend);
/** /**
* *
* @return whether the backend can update a notification * @return whether the backend can update a notification

View File

@ -7,7 +7,8 @@
#include <QString> #include <QString>
namespace Snore{ namespace Snore
{
/** /**
* Version contains relevant version informations. * Version contains relevant version informations.

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -22,10 +21,8 @@
#include <QImage> #include <QImage>
#include <QtGlobal> #include <QtGlobal>
int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>(); int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
FreedesktopImageHint::FreedesktopImageHint() FreedesktopImageHint::FreedesktopImageHint()
{ {
@ -44,12 +41,13 @@ FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
} }
QImage FreedesktopImageHint::toQImage() const
QImage FreedesktopImageHint::toQImage() const { {
return QImage((uchar *)imageData.data(), width, height, QImage::Format_ARGB32).rgbSwapped(); return QImage((uchar *)imageData.data(), width, height, QImage::Format_ARGB32).rgbSwapped();
} }
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) { QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i)
{
a.beginStructure(); a.beginStructure();
a << i.width << a << i.width <<
i.height << i.height <<
@ -62,7 +60,8 @@ QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
return a; return a;
} }
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) { const QDBusArgument &operator >>(const QDBusArgument &a, FreedesktopImageHint &i)
{
a.beginStructure(); a.beginStructure();
a >> i.width >> a >> i.width >>
i.height >> i.height >>

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -25,7 +24,6 @@
#include <QtDBus> #include <QtDBus>
#include <QMetaType> #include <QMetaType>
class FreedesktopImageHint class FreedesktopImageHint
{ {
public: public:
@ -44,7 +42,6 @@ public:
private: private:
static int imageHintID; static int imageHintID;
}; };
Q_DECLARE_METATYPE(FreedesktopImageHint); Q_DECLARE_METATYPE(FreedesktopImageHint);

View File

@ -10,12 +10,10 @@
#include "fredesktopnotification.h" #include "fredesktopnotification.h"
#include "core/snore.h" #include "core/snore.h"
using namespace Snore; using namespace Snore;
Q_EXPORT_PLUGIN2(libsnore_backend_freedesktop, FreedesktopBackend) Q_EXPORT_PLUGIN2(libsnore_backend_freedesktop, FreedesktopBackend)
FreedesktopBackend::FreedesktopBackend() : FreedesktopBackend::FreedesktopBackend() :
SnoreBackend("FreedesktopNotification", true, true, true) SnoreBackend("FreedesktopNotification", true, true, true)
{ {
@ -39,8 +37,7 @@ bool FreedesktopBackend::initialize(SnoreCore *snore)
bool FreedesktopBackend::deinitialize() bool FreedesktopBackend::deinitialize()
{ {
if(SnoreBackend::deinitialize()) if (SnoreBackend::deinitialize()) {
{
disconnect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString))); disconnect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
disconnect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint))); disconnect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint)));
m_interface->deleteLater(); m_interface->deleteLater();
@ -53,45 +50,38 @@ bool FreedesktopBackend::deinitialize()
void FreedesktopBackend::slotNotify(Notification noti) void FreedesktopBackend::slotNotify(Notification noti)
{ {
QStringList actions; QStringList actions;
foreach(int k,noti.actions().keys()) foreach(int k, noti.actions().keys()) {
{
actions << QString::number(k) << noti.actions()[k].name(); actions << QString::number(k) << noti.actions()[k].name();
} }
QVariantMap hints; QVariantMap hints;
if(noti.icon().isValid()) if (noti.icon().isValid()) {
{
FreedesktopImageHint image(noti.icon().image()); FreedesktopImageHint image(noti.icon().image());
hints["image_data"] = QVariant::fromValue(image); hints["image_data"] = QVariant::fromValue(image);
} }
if(noti.priority() != Notification::NORMAL) if (noti.priority() != Notification::NORMAL) {
{
hints["urgency"] = (char)noti.priority() + 1; hints["urgency"] = (char)noti.priority() + 1;
} }
if(noti.application().constHints().contains("desktop-entry")) if (noti.application().constHints().contains("desktop-entry")) {
{
hints["desktop-entry"] = noti.application().constHints().value("desktop-entry"); hints["desktop-entry"] = noti.application().constHints().value("desktop-entry");
} }
uint updateId = 0; uint updateId = 0;
if(noti.isUpdate()) if (noti.isUpdate()) {
{
updateId = noti.old().hints().privateValue(this, "id").toUInt(); updateId = noti.old().hints().privateValue(this, "id").toUInt();
m_dbusIdMap.take(updateId); m_dbusIdMap.take(updateId);
} }
QString title = QString("%1 - %2").arg(noti.application().name(), noti.title()); QString title = QString("%1 - %2").arg(noti.application().name(), noti.title());
QString body(noti.text()); QString body(noti.text());
if(!supportsRichtext()) if (!supportsRichtext()) {
{
title = Snore::toPlainText(title); title = Snore::toPlainText(title);
body = Snore::toPlainText(body); body = Snore::toPlainText(body);
} }
QDBusPendingReply<uint> id = m_interface->Notify(noti.application().name(), updateId, "", title, QDBusPendingReply<uint> id = m_interface->Notify(noti.application().name(), updateId, "", title,
body, actions, hints, noti.isSticky() ? -1 : noti.timeout() * 1000); body, actions, hints, noti.isSticky() ? -1 : noti.timeout() * 1000);
id.waitForFinished(); id.waitForFinished();
noti.hints().setPrivateValue(this, "id", id.value()); noti.hints().setPrivateValue(this, "id", id.value());
m_dbusIdMap[id.value()] = noti.id(); m_dbusIdMap[id.value()] = noti.id();
@ -102,8 +92,7 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action
{ {
snoreDebug(SNORE_DEBUG) << id << m_dbusIdMap[id]; snoreDebug(SNORE_DEBUG) << id << m_dbusIdMap[id];
Notification noti = getActiveNotificationByID(m_dbusIdMap[id]); Notification noti = getActiveNotificationByID(m_dbusIdMap[id]);
if(!noti.isValid()) if (!noti.isValid()) {
{
return; return;
} }
noti.data()->setActionInvoked(actionID.toInt()); noti.data()->setActionInvoked(actionID.toInt());
@ -117,8 +106,6 @@ void FreedesktopBackend::slotCloseNotification ( Notification notification )
m_interface->CloseNotification(id); m_interface->CloseNotification(id);
} }
void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reason) void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reason)
{ {
/* /*
@ -134,8 +121,7 @@ void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &rea
* 4 - Undefined/reserved reasons. * 4 - Undefined/reserved reasons.
*/ */
Notification::CloseReasons closeReason; Notification::CloseReasons closeReason;
switch(reason) switch (reason) {
{
case (1): case (1):
closeReason = Notification::TIMED_OUT; closeReason = Notification::TIMED_OUT;
break; break;
@ -150,17 +136,12 @@ void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &rea
} }
snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason; snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason;
if(id == 0) if (id == 0) {
{
return; return;
} }
Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id)); Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id));
if(noti.isValid()) if (noti.isValid()) {
{
closeNotification(noti, closeReason); closeNotification(noti, closeReason);
} }
} }

View File

@ -20,12 +20,10 @@ public slots:
void slotActionInvoked(const uint &id, const QString &actionID); void slotActionInvoked(const uint &id, const QString &actionID);
void slotNotificationClosed(const uint &id, const uint &reason); void slotNotificationClosed(const uint &id, const uint &reason);
private: private:
org::freedesktop::Notifications *m_interface; org::freedesktop::Notifications *m_interface;
QHash<uint, uint> m_dbusIdMap; QHash<uint, uint> m_dbusIdMap;
}; };
#endif // FREEDESKTOPNOTIFICATION_H #endif // FREEDESKTOPNOTIFICATION_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -22,7 +21,6 @@
#include "core/snore.h" #include "core/snore.h"
#include "core/snore_p.h" #include "core/snore_p.h"
#include <QtCore> #include <QtCore>
#include <QTcpSocket> #include <QTcpSocket>
@ -45,8 +43,7 @@ GrowlBackend::~GrowlBackend()
bool GrowlBackend::initialize(SnoreCore *snore) bool GrowlBackend::initialize(SnoreCore *snore)
{ {
if(Growl::init((GROWL_CALLBACK)&GrowlBackend::gntpCallback) && Growl::isRunning(GROWL_TCP)) if (Growl::init((GROWL_CALLBACK)&GrowlBackend::gntpCallback) && Growl::isRunning(GROWL_TCP)) {
{
return SnoreBackend::initialize(snore); return SnoreBackend::initialize(snore);
} }
snoreDebug(SNORE_DEBUG) << "Growl is not running"; snoreDebug(SNORE_DEBUG) << "Growl is not running";
@ -55,8 +52,7 @@ bool GrowlBackend::initialize(SnoreCore *snore)
bool GrowlBackend::deinitialize() bool GrowlBackend::deinitialize()
{ {
if(!Growl::shutdown()) if (!Growl::shutdown()) {
{
return false; return false;
} }
s_instance = NULL; s_instance = NULL;
@ -67,8 +63,7 @@ void GrowlBackend::slotRegisterApplication(const Application &application)
{ {
// snoreDebug( SNORE_DEBUG ) << application.name().toUtf8().constData(); // snoreDebug( SNORE_DEBUG ) << application.name().toUtf8().constData();
std::vector<std::string> alerts; std::vector<std::string> alerts;
foreach(const Alert &a,application.alerts()) foreach(const Alert & a, application.alerts()) {
{
snoreDebug(SNORE_DEBUG) << a.name().toUtf8().constData(); snoreDebug(SNORE_DEBUG) << a.name().toUtf8().constData();
alerts.push_back(a.name().toUtf8().constData()); alerts.push_back(a.name().toUtf8().constData());
} }
@ -82,8 +77,7 @@ void GrowlBackend::slotRegisterApplication(const Application &application)
void GrowlBackend::slotDeregisterApplication(const Application &application) void GrowlBackend::slotDeregisterApplication(const Application &application)
{ {
Growl *growl = m_applications.take(application.name()); Growl *growl = m_applications.take(application.name());
if(growl == NULL) if (growl == NULL) {
{
return; return;
} }
delete growl; delete growl;
@ -99,39 +93,30 @@ void GrowlBackend::slotNotify(Notification notification)
Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.title()).toUtf8().constData(),
Snore::toPlainText(notification.text()).toUtf8().constData()); Snore::toPlainText(notification.text()).toUtf8().constData());
if(notification.icon().isValid()) if (notification.icon().isValid()) {
{
data.setIcon(notification.icon().localUrl().toUtf8().constData()); data.setIcon(notification.icon().localUrl().toUtf8().constData());
} }
data.setCallbackData("1"); data.setCallbackData("1");
growl->Notify(data); growl->Notify(data);
startTimeout(notification); startTimeout(notification);
} }
void GrowlBackend::gntpCallback(growl_callback_data *data) void GrowlBackend::gntpCallback(growl_callback_data *data)
{ {
if(s_instance) if (s_instance) {
{
snoreDebug(SNORE_DEBUG) << data->id << QString(data->reason) << QString(data->data); snoreDebug(SNORE_DEBUG) << data->id << QString(data->reason) << QString(data->data);
Notification n = s_instance->snore()->getActiveNotificationByID(data->id); Notification n = s_instance->snore()->getActiveNotificationByID(data->id);
if(!n.isValid()) if (!n.isValid()) {
{
return; return;
} }
Notification::CloseReasons r = Notification::NONE; Notification::CloseReasons r = Notification::NONE;
std::string reason(data->reason); std::string reason(data->reason);
if(reason == "TIMEDOUT") if (reason == "TIMEDOUT") {
{
r = Notification::TIMED_OUT; r = Notification::TIMED_OUT;
} } else if (reason == "CLOSED") {
else if(reason == "CLOSED")
{
r = Notification::DISMISSED; r = Notification::DISMISSED;
} } else if (reason == "CLICK") {
else if(reason == "CLICK")
{
r = Notification::CLOSED; r = Notification::CLOSED;
s_instance->snore()->d()->notificationActionInvoked(n); s_instance->snore()->d()->notificationActionInvoked(n);
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -50,5 +49,4 @@ public slots:
void slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
}; };
#endif // GROWL_BACKEND_H #endif // GROWL_BACKEND_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -37,5 +36,4 @@ public slots:
virtual void slotNotify(Snore::Notification notification); virtual void slotNotify(Snore::Notification notification);
}; };
#endif // OSXNOTIFICATIONCENTER_H #endif // OSXNOTIFICATIONCENTER_H

View File

@ -51,10 +51,10 @@
#include "SnarlInterface.h" #include "SnarlInterface.h"
namespace Snarl
namespace Snarl { {
namespace V42 { namespace V42
{
// workaround for mingw-w64 bug // workaround for mingw-w64 bug
#ifdef __MINGW64_VERSION_MAJOR #ifdef __MINGW64_VERSION_MAJOR
@ -65,7 +65,6 @@ namespace V42 {
} }
#endif //__MINGW64_VERSION_MAJOR #endif //__MINGW64_VERSION_MAJOR
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Static Snarl interface functions // Static Snarl interface functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -85,8 +84,9 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout)
DWORD_PTR nResult = 0; DWORD_PTR nResult = 0;
HWND hWnd = GetSnarlWindow(); HWND hWnd = GetSnarlWindow();
if (!IsWindow(hWnd)) if (!IsWindow(hWnd)) {
return -SnarlEnums::ErrorNotRunning; return -SnarlEnums::ErrorNotRunning;
}
// Create COPYDATASTRUCT // Create COPYDATASTRUCT
COPYDATASTRUCT cds; COPYDATASTRUCT cds;
@ -95,21 +95,21 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout)
cds.lpData = const_cast<char *>(request); cds.lpData = const_cast<char *>(request);
// Send message // Send message
if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, replyTimeout, &nResult) == 0) if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, replyTimeout, &nResult) == 0) {
{
// Handle error // Handle error
DWORD nError = GetLastError(); DWORD nError = GetLastError();
LONG32 errorResult = 0; LONG32 errorResult = 0;
if (nError == ERROR_TIMEOUT) if (nError == ERROR_TIMEOUT) {
errorResult = -SnarlEnums::ErrorTimedOut; errorResult = -SnarlEnums::ErrorTimedOut;
else } else {
errorResult = -SnarlEnums::ErrorFailed; errorResult = -SnarlEnums::ErrorFailed;
}
return errorResult; return errorResult;
} } else {
else
return (LONG32)nResult; return (LONG32)nResult;
} }
}
LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout) LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
{ {
@ -117,8 +117,9 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
// Convert to UTF8 // Convert to UTF8
LPSTR utf8Request = WideToUTF8(request); LPSTR utf8Request = WideToUTF8(request);
if (utf8Request == NULL) if (utf8Request == NULL) {
return -SnarlEnums::ErrorCppInterface; return -SnarlEnums::ErrorCppInterface;
}
nResult = DoRequest(utf8Request, replyTimeout); nResult = DoRequest(utf8Request, replyTimeout);
@ -130,13 +131,11 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
std::basic_string<char> &SnarlInterface::Escape(std::basic_string<char> &str) std::basic_string<char> &SnarlInterface::Escape(std::basic_string<char> &str)
{ {
std::basic_string<char>::size_type strLength = str.length(); std::basic_string<char>::size_type strLength = str.length();
for (std::basic_string<char>::size_type i = 0; i < strLength; ++i) for (std::basic_string<char>::size_type i = 0; i < strLength; ++i) {
{
if (str.at(i) == '=') { if (str.at(i) == '=') {
str.insert(++i, "="); str.insert(++i, "=");
++strLength; ++strLength;
} } else if (str[i] == '&') {
else if (str[i] == '&') {
str.insert(++i, "&"); str.insert(++i, "&");
++strLength; ++strLength;
} }
@ -148,13 +147,11 @@ std::basic_string<char>& SnarlInterface::Escape(std::basic_string<char>& str)
std::basic_string<wchar_t> &SnarlInterface::Escape(std::basic_string<wchar_t> &str) std::basic_string<wchar_t> &SnarlInterface::Escape(std::basic_string<wchar_t> &str)
{ {
std::basic_string<wchar_t>::size_type strLength = str.length(); std::basic_string<wchar_t>::size_type strLength = str.length();
for (std::basic_string<wchar_t>::size_type i = 0; i < strLength; ++i) for (std::basic_string<wchar_t>::size_type i = 0; i < strLength; ++i) {
{
if (str.at(i) == L'=') { if (str.at(i) == L'=') {
str.insert(++i, L"="); str.insert(++i, L"=");
++strLength; ++strLength;
} } else if (str[i] == L'&') {
else if (str[i] == L'&') {
str.insert(++i, L"&"); str.insert(++i, L"&");
++strLength; ++strLength;
} }
@ -166,11 +163,9 @@ std::basic_string<wchar_t>& SnarlInterface::Escape(std::basic_string<wchar_t>& s
LPCTSTR SnarlInterface::GetAppPath() LPCTSTR SnarlInterface::GetAppPath()
{ {
HWND hWnd = GetSnarlWindow(); HWND hWnd = GetSnarlWindow();
if (hWnd) if (hWnd) {
{
HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL);
if (hWndPath) if (hWndPath) {
{
TCHAR strTmp[MAX_PATH] = {0}; TCHAR strTmp[MAX_PATH] = {0};
int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH - 1); int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH - 1);
if (nReturn > 0) { if (nReturn > 0) {
@ -189,13 +184,13 @@ LPCTSTR SnarlInterface::GetIconsPath()
{ {
TCHAR *szIconPath = NULL; TCHAR *szIconPath = NULL;
LPCTSTR szPath = GetAppPath(); LPCTSTR szPath = GetAppPath();
if (!szPath) if (!szPath) {
return NULL; return NULL;
}
size_t nLen = 0; size_t nLen = 0;
nLen = _tcsnlen(szPath, MAX_PATH); nLen = _tcsnlen(szPath, MAX_PATH);
if (nLen > 0) if (nLen > 0) {
{
nLen += 10 + 1; // etc\\icons\\ + NULL nLen += 10 + 1; // etc\\icons\\ + NULL
szIconPath = AllocateString(nLen); szIconPath = AllocateString(nLen);
@ -223,7 +218,6 @@ BOOL SnarlInterface::IsSnarlRunning()
return IsWindow(GetSnarlWindow()); return IsWindow(GetSnarlWindow());
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
// SnarlInterface member functions // SnarlInterface member functions
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -267,7 +261,6 @@ LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd)
return DoRequest(Requests::AddActionW(), spl); return DoRequest(Requests::AddActionW(), spl);
} }
LONG32 SnarlInterface::AddClass(LPCSTR classId, LPCSTR name, LPCSTR title, LPCSTR text, LPCSTR icon, LPCSTR sound, LONG32 duration, LPCSTR callback, bool enabled) LONG32 SnarlInterface::AddClass(LPCSTR classId, LPCSTR name, LPCSTR title, LPCSTR text, LPCSTR icon, LPCSTR sound, LONG32 duration, LPCSTR callback, bool enabled)
{ {
// addclass?[app-sig=<signature>|token=<application token>][&password=<password>]&id=<class identifier>&name=<class name>[&enabled=<0|1>][&callback=<callback>] // addclass?[app-sig=<signature>|token=<application token>][&password=<password>]&id=<class identifier>&name=<class name>[&enabled=<0|1>][&callback=<callback>]
@ -285,7 +278,9 @@ LONG32 SnarlInterface::AddClass(LPCSTR classId, LPCSTR name, LPCSTR title, LPCST
spl.Add("text", text); spl.Add("text", text);
spl.Add("icon", icon); spl.Add("icon", icon);
spl.Add("sound", sound); spl.Add("sound", sound);
if (duration != -1) spl.Add("duration", duration); if (duration != -1) {
spl.Add("duration", duration);
}
return DoRequest(Requests::AddClassA(), spl); return DoRequest(Requests::AddClassA(), spl);
} }
@ -304,12 +299,13 @@ LONG32 SnarlInterface::AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title, LP
spl.Add(L"text", text); spl.Add(L"text", text);
spl.Add(L"icon", icon); spl.Add(L"icon", icon);
spl.Add(L"sound", sound); spl.Add(L"sound", sound);
if (duration != -1) spl.Add(L"duration", duration); if (duration != -1) {
spl.Add(L"duration", duration);
}
return DoRequest(Requests::AddClassW(), spl); return DoRequest(Requests::AddClassW(), spl);
} }
LONG32 SnarlInterface::ClearActions(LONG32 msgToken) LONG32 SnarlInterface::ClearActions(LONG32 msgToken)
{ {
// clearactions?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>] // clearactions?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>]
@ -321,7 +317,6 @@ LONG32 SnarlInterface::ClearActions(LONG32 msgToken)
return DoRequest(Requests::ClearActionsA(), spl); return DoRequest(Requests::ClearActionsA(), spl);
} }
LONG32 SnarlInterface::ClearClasses() LONG32 SnarlInterface::ClearClasses()
{ {
// clearclasses?[token=app-sig=<signature>|token=<application token>][&password=<password>] // clearclasses?[token=app-sig=<signature>|token=<application token>][&password=<password>]
@ -333,13 +328,11 @@ LONG32 SnarlInterface::ClearClasses()
return DoRequest(Requests::ClearClassesA(), spl); return DoRequest(Requests::ClearClassesA(), spl);
} }
LONG32 SnarlInterface::GetLastMsgToken() const LONG32 SnarlInterface::GetLastMsgToken() const
{ {
return lastMsgToken; return lastMsgToken;
} }
LONG32 SnarlInterface::Hide(LONG32 msgToken) LONG32 SnarlInterface::Hide(LONG32 msgToken)
{ {
// hide?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>] // hide?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>]
@ -351,7 +344,6 @@ LONG32 SnarlInterface::Hide(LONG32 msgToken)
return DoRequest(Requests::HideA(), spl); return DoRequest(Requests::HideA(), spl);
} }
LONG32 SnarlInterface::IsVisible(LONG32 msgToken) LONG32 SnarlInterface::IsVisible(LONG32 msgToken)
{ {
// isvisible?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>] // isvisible?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>]
@ -363,7 +355,6 @@ LONG32 SnarlInterface::IsVisible(LONG32 msgToken)
return DoRequest(Requests::IsVisibleA(), spl); return DoRequest(Requests::IsVisibleA(), spl);
} }
LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32 timeout, LPCSTR iconPath, LPCSTR iconBase64, SnarlEnums::MessagePriority priority, LPCSTR uid, LPCSTR callback, LPCSTR value) LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32 timeout, LPCSTR iconPath, LPCSTR iconBase64, SnarlEnums::MessagePriority priority, LPCSTR uid, LPCSTR callback, LPCSTR value)
{ {
// notify?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>] // notify?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>]
@ -382,8 +373,12 @@ LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32
spl.Add("uid", uid); spl.Add("uid", uid);
spl.Add("callback", callback); spl.Add("callback", callback);
spl.Add("value", value); spl.Add("value", value);
if (timeout != -1) spl.Add("timeout", timeout); if (timeout != -1) {
if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority spl.Add("timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add("priority", priority); // -1 is a legal priority
}
LONG32 request = DoRequest(Requests::NotifyA(), spl); LONG32 request = DoRequest(Requests::NotifyA(), spl);
lastMsgToken = (request > 0) ? request : 0; lastMsgToken = (request > 0) ? request : 0;
@ -405,8 +400,12 @@ LONG32 SnarlInterface::Notify(LPCWSTR classId, LPCWSTR title, LPCWSTR text, LONG
spl.Add(L"uid", uid); spl.Add(L"uid", uid);
spl.Add(L"callback", callback); spl.Add(L"callback", callback);
spl.Add(L"value", value); spl.Add(L"value", value);
if (timeout != -1) spl.Add(L"timeout", timeout); if (timeout != -1) {
if (priority != SnarlEnums::PriorityUndefined) spl.Add(L"priority", priority); // -1 is a legal priority spl.Add(L"timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add(L"priority", priority); // -1 is a legal priority
}
LONG32 request = DoRequest(Requests::NotifyW(), spl); LONG32 request = DoRequest(Requests::NotifyW(), spl);
lastMsgToken = (request > 0) ? request : 0; lastMsgToken = (request > 0) ? request : 0;
@ -414,7 +413,6 @@ LONG32 SnarlInterface::Notify(LPCWSTR classId, LPCWSTR title, LPCWSTR text, LONG
return request; return request;
} }
LONG32 SnarlInterface::Register(LPCSTR signature, LPCSTR title, LPCSTR icon, LPCSTR password, HWND hWndReplyTo, LONG32 msgReply, SnarlEnums::AppFlags flags) LONG32 SnarlInterface::Register(LPCSTR signature, LPCSTR title, LPCSTR icon, LPCSTR password, HWND hWndReplyTo, LONG32 msgReply, SnarlEnums::AppFlags flags)
{ {
// register?app-sig=<signature>&title=<title>[&icon=<icon>][&password=<password>][&reply-to=<reply window>][&reply=<reply message>] // register?app-sig=<signature>&title=<title>[&icon=<icon>][&password=<password>][&reply-to=<reply window>][&reply=<reply message>]
@ -429,12 +427,14 @@ LONG32 SnarlInterface::Register(LPCSTR signature, LPCSTR title, LPCSTR icon, LPC
spl.Add("flags", flags); spl.Add("flags", flags);
// If password was given, save and use in all other functions requiring password // If password was given, save and use in all other functions requiring password
if (password != NULL && strlen(password) > 0) if (password != NULL && strlen(password) > 0) {
SetPassword(password); SetPassword(password);
}
LONG32 request = DoRequest(Requests::RegisterA(), spl); LONG32 request = DoRequest(Requests::RegisterA(), spl);
if (request > 0) if (request > 0) {
appToken = request; appToken = request;
}
return request; return request;
} }
@ -451,17 +451,18 @@ LONG32 SnarlInterface::Register(LPCWSTR signature, LPCWSTR name, LPCWSTR icon, L
spl.Add(L"flags", flags); spl.Add(L"flags", flags);
// If password was given, save and use in all other functions requiring password // If password was given, save and use in all other functions requiring password
if (password != NULL && wcslen(password) > 0) if (password != NULL && wcslen(password) > 0) {
SetPassword(password); SetPassword(password);
}
LONG32 request = DoRequest(Requests::RegisterW(), spl); LONG32 request = DoRequest(Requests::RegisterW(), spl);
if (request > 0) if (request > 0) {
appToken = request; appToken = request;
}
return request; return request;
} }
LONG32 SnarlInterface::RemoveClass(LPCSTR classId) LONG32 SnarlInterface::RemoveClass(LPCSTR classId)
{ {
// remclass?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>|&all=<0|1>] // remclass?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>|&all=<0|1>]
@ -487,7 +488,6 @@ LONG32 SnarlInterface::RemoveClass(LPCWSTR classId)
return DoRequest(Requests::RemoveClassW(), spl); return DoRequest(Requests::RemoveClassW(), spl);
} }
LONG32 SnarlInterface::Unregister(LPCSTR signature) LONG32 SnarlInterface::Unregister(LPCSTR signature)
{ {
// unregister?[app-sig=<signature>|token=<application token>][&password=<password>] // unregister?[app-sig=<signature>|token=<application token>][&password=<password>]
@ -530,8 +530,12 @@ LONG32 SnarlInterface::Update(LONG32 msgToken, LPCSTR classId, LPCSTR title, LPC
spl.Add("icon-base64", iconBase64); spl.Add("icon-base64", iconBase64);
spl.Add("callback", callback); spl.Add("callback", callback);
spl.Add("value", value); spl.Add("value", value);
if (timeout != -1) spl.Add("timeout", timeout); if (timeout != -1) {
if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority spl.Add("timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add("priority", priority); // -1 is a legal priority
}
return DoRequest(Requests::UpdateA(), spl); return DoRequest(Requests::UpdateA(), spl);
} }
@ -550,8 +554,12 @@ LONG32 SnarlInterface::Update(LONG32 msgToken, LPCWSTR classId, LPCWSTR title, L
spl.Add(L"icon-base64", iconBase64); spl.Add(L"icon-base64", iconBase64);
spl.Add(L"callback", callback); spl.Add(L"callback", callback);
spl.Add(L"value", value); spl.Add(L"value", value);
if (timeout != -1) spl.Add(L"timeout", timeout); if (timeout != -1) {
if (priority != SnarlEnums::PriorityUndefined) spl.Add(L"priority", priority); // -1 is a legal priority spl.Add(L"timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add(L"priority", priority); // -1 is a legal priority
}
return DoRequest(Requests::UpdateW(), spl); return DoRequest(Requests::UpdateW(), spl);
} }
@ -578,7 +586,6 @@ LONG32 SnarlInterface::UpdateApp(LPCWSTR title, LPCWSTR icon)
return DoRequest(Requests::UpdateAppW(), spl); return DoRequest(Requests::UpdateAppW(), spl);
}*/ }*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Private functions // Private functions
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -588,19 +595,16 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char>& spl,
// <action>[?<data>=<value>[&<data>=<value>]] // <action>[?<data>=<value>[&<data>=<value>]]
const std::vector<SnarlParameterList<char>::PairType> &list = spl.GetList(); const std::vector<SnarlParameterList<char>::PairType> &list = spl.GetList();
if (list.size() > 0) if (list.size() > 0) {
{
std::string requestStr = request; std::string requestStr = request;
requestStr.append("?"); requestStr.append("?");
std::vector<SnarlParameterList<char>::PairType>::const_iterator listEnd = list.end(); // cend(); std::vector<SnarlParameterList<char>::PairType>::const_iterator listEnd = list.end(); // cend();
for (std::vector<SnarlParameterList<char>::PairType>::const_iterator iter = list.begin(); // cbegin(); for (std::vector<SnarlParameterList<char>::PairType>::const_iterator iter = list.begin(); // cbegin();
iter != listEnd; ++iter) iter != listEnd; ++iter) {
{
SnarlParameterList<char>::PairType pair = *iter; SnarlParameterList<char>::PairType pair = *iter;
if (iter->second.length() > 0) if (iter->second.length() > 0) {
{
std::basic_string<char> &value = const_cast<std::basic_string<char>&>(iter->second); std::basic_string<char> &value = const_cast<std::basic_string<char>&>(iter->second);
requestStr.append(iter->first).append("=").append(Escape(value)); requestStr.append(iter->first).append("=").append(Escape(value));
requestStr.append("&"); requestStr.append("&");
@ -610,27 +614,24 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char>& spl,
requestStr.erase(requestStr.size() - 1); requestStr.erase(requestStr.size() - 1);
return DoRequest(requestStr.c_str(), replyTimeout); return DoRequest(requestStr.c_str(), replyTimeout);
} } else {
else
return DoRequest(request, replyTimeout); return DoRequest(request, replyTimeout);
} }
}
LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t> &spl, UINT replyTimeout) LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t> &spl, UINT replyTimeout)
{ {
// <action>[?<data>=<value>[&<data>=<value>]] // <action>[?<data>=<value>[&<data>=<value>]]
const std::vector<SnarlParameterList<wchar_t>::PairType> &list = spl.GetList(); const std::vector<SnarlParameterList<wchar_t>::PairType> &list = spl.GetList();
if (list.size() > 0) if (list.size() > 0) {
{
std::basic_string<wchar_t> requestStr = request; std::basic_string<wchar_t> requestStr = request;
requestStr.append(L"?"); requestStr.append(L"?");
std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator listEnd = list.end(); // cend(); std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator listEnd = list.end(); // cend();
for (std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator iter = list.begin(); // cbegin(); for (std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator iter = list.begin(); // cbegin();
iter != listEnd; ++iter) iter != listEnd; ++iter) {
{ if (iter->second.length() > 0) {
if (iter->second.length() > 0)
{
std::basic_string<wchar_t> &value = const_cast<std::basic_string<wchar_t>&>(iter->second); std::basic_string<wchar_t> &value = const_cast<std::basic_string<wchar_t>&>(iter->second);
requestStr.append(iter->first).append(L"=").append(Escape(value)); requestStr.append(iter->first).append(L"=").append(Escape(value));
requestStr.append(L"&"); requestStr.append(L"&");
@ -640,16 +641,17 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& s
requestStr.erase(requestStr.size() - 1); requestStr.erase(requestStr.size() - 1);
return DoRequest(requestStr.c_str(), replyTimeout); return DoRequest(requestStr.c_str(), replyTimeout);
} } else {
else
return DoRequest(request, replyTimeout); return DoRequest(request, replyTimeout);
} }
}
// Remember to delete [] returned string // Remember to delete [] returned string
LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr) LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr)
{ {
if (szWideStr == NULL) if (szWideStr == NULL) {
return NULL; return NULL;
}
int nSize = WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, NULL, 0, NULL, NULL); int nSize = WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, NULL, 0, NULL, NULL);
LPSTR szUTF8 = new char[nSize]; LPSTR szUTF8 = new char[nSize];
@ -662,8 +664,7 @@ void SnarlInterface::SetPassword(LPCSTR password)
{ {
ClearPassword(); ClearPassword();
if (password != NULL) if (password != NULL) {
{
int bufSize = (int)strlen(password) + 1; int bufSize = (int)strlen(password) + 1;
szPasswordA = new char[bufSize]; szPasswordA = new char[bufSize];
szPasswordW = new wchar_t[bufSize]; szPasswordW = new wchar_t[bufSize];
@ -680,8 +681,7 @@ void SnarlInterface::SetPassword(LPCWSTR password)
{ {
ClearPassword(); ClearPassword();
if (password != NULL) if (password != NULL) {
{
size_t bufSize = wcslen(password) + 1; size_t bufSize = wcslen(password) + 1;
szPasswordW = new wchar_t[bufSize]; szPasswordW = new wchar_t[bufSize];
@ -702,6 +702,6 @@ void SnarlInterface::ClearPassword()
szPasswordW = NULL; szPasswordW = NULL;
} }
}
}} // namespace Snarl::V42 } // namespace Snarl::V42

View File

@ -11,14 +11,14 @@
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#ifndef SMTO_NOTIMEOUTIFNOTHUNG #ifndef SMTO_NOTIMEOUTIFNOTHUNG
#define SMTO_NOTIMEOUTIFNOTHUNG 8 #define SMTO_NOTIMEOUTIFNOTHUNG 8
#endif #endif
namespace Snarl
namespace Snarl { {
namespace V42 { namespace V42
{
static LPCTSTR SnarlWindowClass = _T("w>Snarl"); static LPCTSTR SnarlWindowClass = _T("w>Snarl");
static LPCTSTR SnarlWindowTitle = _T("Snarl"); static LPCTSTR SnarlWindowTitle = _T("Snarl");
@ -33,24 +33,22 @@ namespace Snarl {
/// <summary>Application requests - these values appear in wParam.<para>Application should show its About... dialog</para></summary> /// <summary>Application requests - these values appear in wParam.<para>Application should show its About... dialog</para></summary>
static const WPARAM AppDoAbout = 2; static const WPARAM AppDoAbout = 2;
// Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :( // Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :(
namespace SnarlEnums { namespace SnarlEnums
{
/// <summary> /// <summary>
/// Global event identifiers - sent as Windows broadcast messages. /// Global event identifiers - sent as Windows broadcast messages.
/// These values appear in wParam of the message. /// These values appear in wParam of the message.
/// </summary> /// </summary>
enum GlobalEvent enum GlobalEvent {
{
SnarlLaunched = 1, // Snarl has just started running SnarlLaunched = 1, // Snarl has just started running
SnarlQuit = 2, // Snarl is about to stop running SnarlQuit = 2, // Snarl is about to stop running
SnarlGlobalStopped = 3, // Sent when stopped by user - Also sent to registered window SnarlGlobalStopped = 3, // Sent when stopped by user - Also sent to registered window
SnarlGlobalStarted = 4, // Sent when started by user - Also sent to registered window SnarlGlobalStarted = 4, // Sent when started by user - Also sent to registered window
}; };
enum SnarlStatus enum SnarlStatus {
{
Success = 0, Success = 0,
// Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code, // Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code,
@ -125,7 +123,6 @@ namespace Snarl {
// the following is generic to SNP and the Win32 API // the following is generic to SNP and the Win32 API
NotifyAction = 308, // user picked an action from the list, the data value will indicate which one NotifyAction = 308, // user picked an action from the list, the data value will indicate which one
// C++ interface custom errors- not part of official API! // C++ interface custom errors- not part of official API!
ErrorCppInterface = 1001 ErrorCppInterface = 1001
}; };
@ -134,8 +131,7 @@ namespace Snarl {
/// The priority of messages. /// The priority of messages.
/// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref> /// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref>
/// </summary> /// </summary>
enum MessagePriority enum MessagePriority {
{
PriorityUndefined = -2, PriorityUndefined = -2,
PriorityLow = -1, PriorityLow = -1,
PriorityNormal = 0, PriorityNormal = 0,
@ -145,8 +141,7 @@ namespace Snarl {
/// <summary> /// <summary>
/// Application flags - features this app supports. /// Application flags - features this app supports.
/// </summary> /// </summary>
enum AppFlags enum AppFlags {
{
AppFlagNone = 0, AppFlagNone = 0,
AppHasPrefs = 1, AppHasPrefs = 1,
AppHasAbout = 2, AppHasAbout = 2,
@ -175,9 +170,10 @@ namespace Snarl {
void Add(const T *_key, const T *_value) void Add(const T *_key, const T *_value)
{ {
if (_value != NULL) if (_value != NULL) {
list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); // list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); //
} }
}
void Add(const T *_key, LONG32 _value) void Add(const T *_key, LONG32 _value)
{ {
@ -188,8 +184,7 @@ namespace Snarl {
void Add(const T *_key, void *_value) void Add(const T *_key, void *_value)
{ {
if (_value != NULL) if (_value != NULL) {
{
std::basic_stringstream<T> valStr; std::basic_stringstream<T> valStr;
valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex
@ -216,34 +211,118 @@ namespace Snarl {
class Requests class Requests
{ {
public: public:
static LPCSTR AddActionA() { return "addaction"; } static LPCSTR AddActionA()
static LPCWSTR AddActionW() { return L"addaction"; } {
static LPCSTR AddClassA() { return "addclass"; } return "addaction";
static LPCWSTR AddClassW() { return L"addclass"; } }
static LPCSTR ClearActionsA() { return "clearactions"; } static LPCWSTR AddActionW()
static LPCWSTR ClearActionsW() { return L"clearactions"; } {
static LPCSTR ClearClassesA() { return "clearclasses"; } return L"addaction";
static LPCWSTR ClearClassesW() { return L"clearclasses"; } }
static LPCSTR HelloA() { return "hello"; } static LPCSTR AddClassA()
static LPCWSTR HelloW() { return L"hello"; } {
static LPCSTR HideA() { return "hide"; } return "addclass";
static LPCWSTR HideW() { return L"hide"; } }
static LPCSTR IsVisibleA() { return "isvisible"; } static LPCWSTR AddClassW()
static LPCWSTR IsVisibleW() { return L"isvisible"; } {
static LPCSTR NotifyA() { return "notify"; } return L"addclass";
static LPCWSTR NotifyW() { return L"notify"; } }
static LPCSTR RegisterA() { return "reg"; } // register static LPCSTR ClearActionsA()
static LPCWSTR RegisterW() { return L"reg"; } {
static LPCSTR RemoveClassA() { return "remclass"; } return "clearactions";
static LPCWSTR RemoveClassW() { return L"remclass"; } }
static LPCSTR UnregisterA() { return "unregister"; } static LPCWSTR ClearActionsW()
static LPCWSTR UnregisterW() { return L"unregister"; } {
static LPCSTR UpdateAppA() { return "updateapp"; } return L"clearactions";
static LPCWSTR UpdateAppW() { return L"updateapp"; } }
static LPCSTR UpdateA() { return "update"; } static LPCSTR ClearClassesA()
static LPCWSTR UpdateW() { return L"update"; } {
static LPCSTR VersionA() { return "version"; } return "clearclasses";
static LPCWSTR VersionW() { return L"version"; } }
static LPCWSTR ClearClassesW()
{
return L"clearclasses";
}
static LPCSTR HelloA()
{
return "hello";
}
static LPCWSTR HelloW()
{
return L"hello";
}
static LPCSTR HideA()
{
return "hide";
}
static LPCWSTR HideW()
{
return L"hide";
}
static LPCSTR IsVisibleA()
{
return "isvisible";
}
static LPCWSTR IsVisibleW()
{
return L"isvisible";
}
static LPCSTR NotifyA()
{
return "notify";
}
static LPCWSTR NotifyW()
{
return L"notify";
}
static LPCSTR RegisterA()
{
return "reg"; // register
}
static LPCWSTR RegisterW()
{
return L"reg";
}
static LPCSTR RemoveClassA()
{
return "remclass";
}
static LPCWSTR RemoveClassW()
{
return L"remclass";
}
static LPCSTR UnregisterA()
{
return "unregister";
}
static LPCWSTR UnregisterW()
{
return L"unregister";
}
static LPCSTR UpdateAppA()
{
return "updateapp";
}
static LPCWSTR UpdateAppW()
{
return L"updateapp";
}
static LPCSTR UpdateA()
{
return "update";
}
static LPCWSTR UpdateW()
{
return L"update";
}
static LPCSTR VersionA()
{
return "version";
}
static LPCWSTR VersionW()
{
return L"version";
}
}; };
SnarlInterface(); SnarlInterface();
@ -254,11 +333,28 @@ namespace Snarl {
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
// Use FreeString, when SnarlInterface returns a null terminated string pointer // Use FreeString, when SnarlInterface returns a null terminated string pointer
static LPTSTR AllocateString(size_t n) { return new TCHAR[n]; } static LPTSTR AllocateString(size_t n)
static void FreeString(LPSTR str) { delete [] str; str = NULL; } {
static void FreeString(LPCSTR str) { delete [] str; } return new TCHAR[n];
static void FreeString(LPWSTR str) { delete [] str; str = NULL; } }
static void FreeString(LPCWSTR str) { delete [] str; } static void FreeString(LPSTR str)
{
delete [] str;
str = NULL;
}
static void FreeString(LPCSTR str)
{
delete [] str;
}
static void FreeString(LPWSTR str)
{
delete [] str;
str = NULL;
}
static void FreeString(LPCWSTR str)
{
delete [] str;
}
/// <summary>Send message to Snarl.</summary> /// <summary>Send message to Snarl.</summary>
/// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param> /// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param>
@ -323,10 +419,8 @@ namespace Snarl {
/// <returns>Returns true if Snarl system was found running.</returns> /// <returns>Returns true if Snarl system was found running.</returns>
static BOOL IsSnarlRunning(); static BOOL IsSnarlRunning();
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/// <summary>Adds an action to an existing (on-screen or in the missed list) notification.</summary> /// <summary>Adds an action to an existing (on-screen or in the missed list) notification.</summary>
LONG32 AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd); LONG32 AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd);
LONG32 AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd); LONG32 AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd);
@ -380,7 +474,6 @@ namespace Snarl {
/*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL); /*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL);
LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/ LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/
private: private:
/// <summary>Convert a unicode string to UTF8</summary> /// <summary>Convert a unicode string to UTF8</summary>

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -28,10 +27,8 @@
#include <QtDebug> #include <QtDebug>
#include <QWidget> #include <QWidget>
#include <iostream> #include <iostream>
#define SNORENOTIFIER_MESSAGE_ID WM_USER + 238 #define SNORENOTIFIER_MESSAGE_ID WM_USER + 238
using namespace Snore; using namespace Snore;
@ -49,13 +46,13 @@ public:
SNARL_GLOBAL_MESSAGE = SnarlInterface::Broadcast(); SNARL_GLOBAL_MESSAGE = SnarlInterface::Broadcast();
} }
bool winEvent( MSG * msg, long * result ){ bool winEvent(MSG *msg, long *result)
{
Q_UNUSED(result); Q_UNUSED(result);
if (msg->message == SNARL_GLOBAL_MESSAGE) { if (msg->message == SNARL_GLOBAL_MESSAGE) {
int action = msg->wParam; int action = msg->wParam;
if (action == SnarlEnums::SnarlLaunched) { if (action == SnarlEnums::SnarlLaunched) {
foreach(const Application &a,m_snarl->snore()->aplications()) foreach(const Application & a, m_snarl->snore()->aplications()) {
{
m_snarl->slotRegisterApplication(a); m_snarl->slotRegisterApplication(a);
} }
} }
@ -65,8 +62,7 @@ public:
int data = (msg->wParam & 0xffffffff) >> 16; int data = (msg->wParam & 0xffffffff) >> 16;
Notification notification; Notification notification;
if(msg->lParam != 0) if (msg->lParam != 0) {
{
notification = m_snarl->snore()->getActiveNotificationByID(m_snarl->m_idMap.value(msg->lParam)); notification = m_snarl->snore()->getActiveNotificationByID(m_snarl->m_idMap.value(msg->lParam));
} }
@ -77,8 +73,7 @@ public:
break; break;
case SnarlEnums::NotifyAction: case SnarlEnums::NotifyAction:
reason = Notification::CLOSED; reason = Notification::CLOSED;
if(notification.isValid()) if (notification.isValid()) {
{
notification.data()->setActionInvoked(data); notification.data()->setActionInvoked(data);
m_snarl->snore()->d()->notificationActionInvoked(notification); m_snarl->snore()->d()->notificationActionInvoked(notification);
} }
@ -100,13 +95,10 @@ public:
snoreDebug(SNORE_DEBUG) << "Unknown snarl action found!!"; snoreDebug(SNORE_DEBUG) << "Unknown snarl action found!!";
return false; return false;
} }
if(notification.isValid()) if (notification.isValid()) {
{
m_snarl->closeNotification(notification, reason); m_snarl->closeNotification(notification, reason);
m_snarl->m_idMap.take(msg->lParam); m_snarl->m_idMap.take(msg->lParam);
} } else {
else
{
snoreDebug(SNORE_DEBUG) << "Snarl notification already closed" << msg->lParam << action; snoreDebug(SNORE_DEBUG) << "Snarl notification already closed" << msg->lParam << action;
snoreDebug(SNORE_DEBUG) << m_snarl->m_idMap; snoreDebug(SNORE_DEBUG) << m_snarl->m_idMap;
} }
@ -121,7 +113,6 @@ private:
}; };
SnarlBackend::SnarlBackend(): SnarlBackend::SnarlBackend():
SnoreBackend("Snarl", true, false, true) SnoreBackend("Snarl", true, false, true)
{ {
@ -133,12 +124,10 @@ SnarlBackend::~SnarlBackend()
} }
bool SnarlBackend::initialize(SnoreCore *snore) bool SnarlBackend::initialize(SnoreCore *snore)
{ {
SnarlInterface *snarlInterface = new SnarlInterface(); SnarlInterface *snarlInterface = new SnarlInterface();
if(!snarlInterface->IsSnarlRunning()) if (!snarlInterface->IsSnarlRunning()) {
{
delete snarlInterface; delete snarlInterface;
return false; return false;
} }
@ -150,10 +139,8 @@ bool SnarlBackend::initialize(SnoreCore *snore)
bool SnarlBackend::deinitialize() bool SnarlBackend::deinitialize()
{ {
if(SnoreBackend::deinitialize()) if (SnoreBackend::deinitialize()) {
{ if (m_eventLoop) {
if(m_eventLoop)
{
m_eventLoop->deleteLater(); m_eventLoop->deleteLater();
m_eventLoop = NULL; m_eventLoop = NULL;
} }
@ -162,7 +149,8 @@ bool SnarlBackend::deinitialize()
return false; return false;
} }
void SnarlBackend::slotRegisterApplication(const Application &application){ void SnarlBackend::slotRegisterApplication(const Application &application)
{
Q_ASSERT_X(!m_applications.contains(application.name()), Q_FUNC_INFO, "Application already registered"); Q_ASSERT_X(!m_applications.contains(application.name()), Q_FUNC_INFO, "Application already registered");
@ -175,8 +163,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application){
application.icon().localUrl().toUtf8().constData(), application.icon().localUrl().toUtf8().constData(),
0, (HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID); 0, (HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
foreach(const Alert &alert,application.alerts()) foreach(const Alert & alert, application.alerts()) {
{
snarlInterface->AddClass(alert.name().toUtf8().constData(), snarlInterface->AddClass(alert.name().toUtf8().constData(),
alert.name().toUtf8().constData(), alert.name().toUtf8().constData(),
0, 0, alert.icon().localUrl().toUtf8().constData()); 0, 0, alert.icon().localUrl().toUtf8().constData());
@ -185,8 +172,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application){
void SnarlBackend::slotDeregisterApplication(const Application &application) void SnarlBackend::slotDeregisterApplication(const Application &application)
{ {
if(!m_applications.contains(application.name())) if (!m_applications.contains(application.name())) {
{
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << application.name(); snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << application.name();
return; return;
} }
@ -196,9 +182,9 @@ void SnarlBackend::slotDeregisterApplication(const Application &application)
delete snarlInterface; delete snarlInterface;
} }
void SnarlBackend::slotNotify(Notification notification){ void SnarlBackend::slotNotify(Notification notification)
if(!m_applications.contains(notification.application().name()))
{ {
if (!m_applications.contains(notification.application().name())) {
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name(); snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name();
return; return;
} }
@ -206,8 +192,7 @@ void SnarlBackend::slotNotify(Notification notification){
SnarlInterface *snarlInterface = m_applications.value(notification.application().name()); SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined; Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
switch(notification.priority()) switch (notification.priority()) {
{
case Notification::LOW: case Notification::LOW:
priority = Snarl::V42::SnarlEnums::PriorityLow; priority = Snarl::V42::SnarlEnums::PriorityLow;
break; break;
@ -222,8 +207,7 @@ void SnarlBackend::slotNotify(Notification notification){
ULONG32 id = 0; ULONG32 id = 0;
snoreDebug(SNORE_DEBUG) << notification.icon(); snoreDebug(SNORE_DEBUG) << notification.icon();
if(!notification.isUpdate()) if (!notification.isUpdate()) {
{
id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(), id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.title()).toUtf8().constData(),
Snore::toPlainText(notification.text()).toUtf8().constData(), Snore::toPlainText(notification.text()).toUtf8().constData(),
@ -232,15 +216,12 @@ void SnarlBackend::slotNotify(Notification notification){
!notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0,
priority); priority);
foreach(const Action &a, notification.actions()) foreach(const Action & a, notification.actions()) {
{
snarlInterface->AddAction(id, a.name().toUtf8().constData(), QString("@").append(QString::number(a.id())).toUtf8().constData()); snarlInterface->AddAction(id, a.name().toUtf8().constData(), QString("@").append(QString::number(a.id())).toUtf8().constData());
} }
m_idMap[id] = notification.id(); m_idMap[id] = notification.id();
notification.hints().setPrivateValue(this, "id", id); notification.hints().setPrivateValue(this, "id", id);
} } else {
else
{
//update message //update message
id = notification.old().hints().privateValue(this, "id").toUInt(); id = notification.old().hints().privateValue(this, "id").toUInt();
snarlInterface->Update(id, snarlInterface->Update(id,
@ -260,8 +241,7 @@ void SnarlBackend::slotNotify(Notification notification){
void SnarlBackend::slotCloseNotification(Notification notification) void SnarlBackend::slotCloseNotification(Notification notification)
{ {
if(!m_applications.contains(notification.application().name())) if (!m_applications.contains(notification.application().name())) {
{
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name(); snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name();
return; return;
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -22,8 +21,6 @@
#include "core/plugins/snorebackend.h" #include "core/plugins/snorebackend.h"
#include "SnarlInterface.h" #include "SnarlInterface.h"
class SnarlBackend: public Snore::SnoreBackend class SnarlBackend: public Snore::SnoreBackend
{ {
Q_OBJECT Q_OBJECT
@ -51,5 +48,4 @@ private:
}; };
#endif // SNARL_BACKEND_H #endif // SNARL_BACKEND_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -43,18 +42,14 @@ NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
| Qt::WindowDoesNotAcceptFocus | Qt::WindowDoesNotAcceptFocus
#endif #endif
); );
if(m_mem.create(sizeof(SHARED_MEM_TYPE))) if (m_mem.create(sizeof(SHARED_MEM_TYPE))) {
{
m_mem.lock(); m_mem.lock();
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data(); SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
data->free = true; data->free = true;
data->date = QTime::currentTime(); data->date = QTime::currentTime();
m_mem.unlock(); m_mem.unlock();
} } else {
else if (!m_mem.attach()) {
{
if(!m_mem.attach())
{
qFatal("Failed to atatche to shared mem"); qFatal("Failed to atatche to shared mem");
} }
m_mem.lock(); m_mem.lock();
@ -63,7 +58,6 @@ NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000; snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000;
} }
setResizeMode(QDeclarativeView::SizeRootObjectToView); setResizeMode(QDeclarativeView::SizeRootObjectToView);
connect(m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked())); connect(m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked()));
@ -102,12 +96,9 @@ void NotifyWidget::update(const Notification &notification)
m_notification = notification; m_notification = notification;
QColor color; QColor color;
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor"); QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
if(vcolor.isValid()) if (vcolor.isValid()) {
{
color = vcolor.value<QColor>(); color = vcolor.value<QColor>();
} } else {
else
{
color = computeBackgrondColor(notification.application().icon().image().scaled(20, 20)); color = computeBackgrondColor(notification.application().icon().image().scaled(20, 20));
notification.application().constHints().setPrivateValue(parent(), "backgroundColor", color); notification.application().constHints().setPrivateValue(parent(), "backgroundColor", color);
} }
@ -125,16 +116,13 @@ void NotifyWidget::update(const Notification &notification)
bool NotifyWidget::acquire() bool NotifyWidget::acquire()
{ {
bool out = false; bool out = false;
if(m_ready) if (m_ready) {
{
m_mem.lock(); m_mem.lock();
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data(); SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000; snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000;
bool timedout = data->date.elapsed() / 1000 > 60; bool timedout = data->date.elapsed() / 1000 > 60;
if(data->free || timedout) if (data->free || timedout) {
{ if (timedout) {
if(timedout)
{
snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << data->date.elapsed() / 1000; snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << data->date.elapsed() / 1000;
} }
data->free = false; data->free = false;
@ -150,13 +138,11 @@ bool NotifyWidget::acquire()
bool NotifyWidget::release() bool NotifyWidget::release()
{ {
bool out = false; bool out = false;
if(!m_ready) if (!m_ready) {
{
m_mem.lock(); m_mem.lock();
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data(); SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000 << m_notification.id(); snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000 << m_notification.id();
if(!data->free) if (!data->free) {
{
data->free = true; data->free = true;
m_ready = true; m_ready = true;
out = true; out = true;
@ -192,10 +178,8 @@ QColor NotifyWidget::computeBackgrondColor(const QImage &img)
qulonglong r = 0; qulonglong r = 0;
qulonglong g = 0; qulonglong g = 0;
qulonglong b = 0; qulonglong b = 0;
for(int x = 0; x < img.width(); ++x) for (int x = 0; x < img.width(); ++x) {
{ for (int y = 0; y < img.height(); ++y) {
for(int y = 0; y < img.height(); ++y)
{
QRgb c = img.pixel(x, y); QRgb c = img.pixel(x, y);
r += qRed(c); r += qRed(c);
g += qGreen(c); g += qGreen(c);

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -28,9 +27,7 @@
#include <QtDeclarative> #include <QtDeclarative>
#include <QPropertyAnimation> #include <QPropertyAnimation>
typedef struct {
typedef struct
{
bool free; bool free;
QTime date; QTime date;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -17,7 +16,6 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "snorenotifier.h" #include "snorenotifier.h"
#include "notifywidget.h" #include "notifywidget.h"
#include "core/notification/notification_p.h" #include "core/notification/notification_p.h"
@ -37,8 +35,7 @@ SnoreNotifier::SnoreNotifier():
SnoreNotifier::~SnoreNotifier() SnoreNotifier::~SnoreNotifier()
{ {
foreach (NotifyWidget *w, m_widgets) foreach(NotifyWidget * w, m_widgets) {
{
w->deleteLater(); w->deleteLater();
} }
} }
@ -46,40 +43,28 @@ SnoreNotifier::~SnoreNotifier()
void SnoreNotifier::slotNotify(Snore::Notification notification) void SnoreNotifier::slotNotify(Snore::Notification notification)
{ {
if(notification.isUpdate()) if (notification.isUpdate()) {
{ if (notification.old().hints().privateValue(this, "id").isValid()) {
if(notification.old().hints().privateValue(this, "id").isValid())
{
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()]; NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
if(w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id()) if (w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id()) {
{
snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id(); snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id();
w->update(notification); w->update(notification);
notification.hints().setPrivateValue(this, "id", w->id()); notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification); startTimeout(notification);
} }
} } else {
else for (int i = 0; i < m_queue.length(); ++i) {
{
for(int i = 0; i < m_queue.length(); ++i)
{
Notification n = m_queue.at(i); Notification n = m_queue.at(i);
if(n.id() == notification.old().id()) if (n.id() == notification.old().id()) {
{
snoreDebug(SNORE_DEBUG) << "replacing qued notification" << n.id() << notification.id(); snoreDebug(SNORE_DEBUG) << "replacing qued notification" << n.id() << notification.id();
m_queue.replace(i, notification); m_queue.replace(i, notification);
} }
} }
} }
} } else {
else if (m_queue.isEmpty()) {
{ foreach(NotifyWidget * w, m_widgets) {
if(m_queue.isEmpty()) if (w->acquire()) {
{
foreach (NotifyWidget *w, m_widgets)
{
if(w->acquire())
{
w->display(notification); w->display(notification);
notification.hints().setPrivateValue(this, "id", w->id()); notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification); startTimeout(notification);
@ -100,7 +85,6 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
//the timer will show the next //the timer will show the next
} }
void SnoreNotifier::slotDismissed() void SnoreNotifier::slotDismissed()
{ {
NotifyWidget *widget = qobject_cast<NotifyWidget *>(sender()); NotifyWidget *widget = qobject_cast<NotifyWidget *>(sender());
@ -120,23 +104,17 @@ void SnoreNotifier::slotInvoked()
void SnoreNotifier::slotProcessQueue() void SnoreNotifier::slotProcessQueue()
{ {
if(m_queue.isEmpty()) if (m_queue.isEmpty()) {
{
snoreDebug(SNORE_DEBUG) << "queue is empty"; snoreDebug(SNORE_DEBUG) << "queue is empty";
m_timer->stop(); m_timer->stop();
} } else {
else foreach(NotifyWidget * w, m_widgets) {
{ if (w->acquire()) {
foreach (NotifyWidget *w, m_widgets)
{
if(w->acquire())
{
Notification notification = m_queue.takeFirst(); Notification notification = m_queue.takeFirst();
w->display(notification); w->display(notification);
notification.hints().setPrivateValue(this, "id", w->id()); notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification); startTimeout(notification);
if(m_queue.isEmpty()) if (m_queue.isEmpty()) {
{
m_timer->stop(); m_timer->stop();
return; return;
} }
@ -148,25 +126,21 @@ void SnoreNotifier::slotProcessQueue()
void SnoreNotifier::setup() void SnoreNotifier::setup()
{ {
for(int i=0;i<m_widgets.size();++i) for (int i = 0; i < m_widgets.size(); ++i) {
{
NotifyWidget *w = new NotifyWidget(i); NotifyWidget *w = new NotifyWidget(i);
m_widgets[i] = w; m_widgets[i] = w;
connect(w, SIGNAL(dismissed()), this, SLOT(slotDismissed())); connect(w, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
connect(w, SIGNAL(invoked()), this, SLOT(slotInvoked())); connect(w, SIGNAL(invoked()), this, SLOT(slotInvoked()));
} }
m_timer = new QTimer(this); m_timer = new QTimer(this);
m_timer->setInterval(500); m_timer->setInterval(500);
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessQueue())); connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessQueue()));
} }
bool SnoreNotifier::initialize(SnoreCore *snore) bool SnoreNotifier::initialize(SnoreCore *snore)
{ {
if(SnoreBackend::initialize(snore)) if (SnoreBackend::initialize(snore)) {
{
return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection); return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection);
} }
return false; return false;
@ -174,10 +148,8 @@ bool SnoreNotifier::initialize(SnoreCore *snore)
bool SnoreNotifier::deinitialize() bool SnoreNotifier::deinitialize()
{ {
if(SnoreBackend::deinitialize()) if (SnoreBackend::deinitialize()) {
{ for (int i = 0; i < m_widgets.size(); ++i) {
for(int i=0;i<m_widgets.size();++i)
{
m_widgets[i]->release(); m_widgets[i]->release();
m_widgets[i]->deleteLater(); m_widgets[i]->deleteLater();
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -53,7 +52,6 @@ private:
QVector<NotifyWidget *> m_widgets; QVector<NotifyWidget *> m_widgets;
QTimer *m_timer; QTimer *m_timer;
}; };
#endif // SNORENOTIFIER_H #endif // SNORENOTIFIER_H

View File

@ -15,7 +15,6 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(libsnore_backend_snoretoast, SnoreToast) Q_EXPORT_PLUGIN2(libsnore_backend_snoretoast, SnoreToast)
SnoreToast::SnoreToast(): SnoreToast::SnoreToast():
SnoreBackend("Windows 8", true, false) SnoreBackend("Windows 8", true, false)
{ {
@ -28,15 +27,13 @@ SnoreToast::~SnoreToast()
bool SnoreToast::initialize(SnoreCore *snore) bool SnoreToast::initialize(SnoreCore *snore)
{ {
if(QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
{
snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
return false; return false;
} }
return SnoreBackend::initialize(snore); return SnoreBackend::initialize(snore);
} }
void SnoreToast::slotNotify(Notification notification) void SnoreToast::slotNotify(Notification notification)
{ {
QProcess *p = new QProcess(this); QProcess *p = new QProcess(this);
@ -50,8 +47,7 @@ void SnoreToast::slotNotify(Notification notification)
<< Snore::toPlainText(notification.title()) << Snore::toPlainText(notification.title())
<< "-m" << "-m"
<< Snore::toPlainText(notification.text()); << Snore::toPlainText(notification.text());
if(notification.icon().isValid()) if (notification.icon().isValid()) {
{
arguements << "-p" arguements << "-p"
<< QDir::toNativeSeparators(notification.icon().localUrl()); << QDir::toNativeSeparators(notification.icon().localUrl());
} }
@ -60,8 +56,7 @@ void SnoreToast::slotNotify(Notification notification)
<< appId(notification.application()) << appId(notification.application())
<< "-id" << "-id"
<< QString::number(notification.id()); << QString::number(notification.id());
if(notification.hints().value("silent",true).toBool()) if (notification.hints().value("silent", true).toBool()) {
{
arguements << "-silent"; arguements << "-silent";
} }
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;
@ -72,8 +67,7 @@ void SnoreToast::slotNotify(Notification notification)
void SnoreToast::slotRegisterApplication(const Application &application) void SnoreToast::slotRegisterApplication(const Application &application)
{ {
if(!application.constHints().contains("windows_app_id")) if (!application.constHints().contains("windows_app_id")) {
{
QProcess *p = new QProcess(this); QProcess *p = new QProcess(this);
p->setReadChannelMode(QProcess::MergedChannels); p->setReadChannelMode(QProcess::MergedChannels);
@ -109,16 +103,14 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{ {
QProcess *p = qobject_cast<QProcess *>(sender()); QProcess *p = qobject_cast<QProcess *>(sender());
snoreDebug(SNORE_DEBUG) << p->readAll(); snoreDebug(SNORE_DEBUG) << p->readAll();
if(p->property("SNORE_NOTIFICATION_ID").isNull()) if (p->property("SNORE_NOTIFICATION_ID").isNull()) {
{
return; return;
} }
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt()); Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
Notification::CloseReasons reason = Notification::CLOSED; Notification::CloseReasons reason = Notification::CLOSED;
switch(code) switch (code) {
{
case 0: case 0:
reason = Notification::CLOSED; reason = Notification::CLOSED;
snore()->d()->notificationActionInvoked(n); snore()->d()->notificationActionInvoked(n);
@ -146,8 +138,7 @@ QString SnoreToast::appId(const Application &application)
{ {
QString appID = application.constHints().value("windows_app_id").toString(); QString appID = application.constHints().value("windows_app_id").toString();
if(appID.isEmpty()) if (appID.isEmpty()) {
{
appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" "); appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" ");
} }
return appID; return appID;

View File

@ -25,7 +25,6 @@ private slots:
private: private:
QString appId(const Snore::Application &application); QString appId(const Snore::Application &application);
}; };
#endif // TOASTER_H #endif // TOASTER_H

View File

@ -25,10 +25,10 @@ TrayIconNotifer::~TrayIconNotifer()
} }
bool TrayIconNotifer::initialize(SnoreCore *snore){ bool TrayIconNotifer::initialize(SnoreCore *snore)
m_trayIcon = snore->trayIcon();
if(m_trayIcon == NULL)
{ {
m_trayIcon = snore->trayIcon();
if (m_trayIcon == NULL) {
return false; return false;
} }
connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked())); connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked()));
@ -37,10 +37,8 @@ bool TrayIconNotifer::initialize(SnoreCore *snore){
bool TrayIconNotifer::deinitialize() bool TrayIconNotifer::deinitialize()
{ {
if(SnoreBackend::deinitialize()) if (SnoreBackend::deinitialize()) {
{ if (m_trayIcon) {
if(m_trayIcon)
{
disconnect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked())); disconnect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked()));
m_trayIcon = NULL; m_trayIcon = NULL;
m_currentlyDisplaying = false; m_currentlyDisplaying = false;
@ -65,12 +63,10 @@ void TrayIconNotifer::slotCloseNotification(Notification n)
void TrayIconNotifer::displayNotification() void TrayIconNotifer::displayNotification()
{ {
if(m_currentlyDisplaying) if (m_currentlyDisplaying) {
{
return; return;
} }
if(m_notificationQue.isEmpty()) if (m_notificationQue.isEmpty()) {
{
m_currentlyDisplaying = false; m_currentlyDisplaying = false;
return; return;
} }
@ -84,8 +80,7 @@ void TrayIconNotifer::displayNotification()
void TrayIconNotifer::actionInvoked() void TrayIconNotifer::actionInvoked()
{ {
Notification n = getActiveNotificationByID(m_displayed); Notification n = getActiveNotificationByID(m_displayed);
if(n.isValid()) if (n.isValid()) {
{
snore()->d()->notificationActionInvoked(n); snore()->d()->notificationActionInvoked(n);
closeNotification(n, Notification::CLOSED); closeNotification(n, Notification::CLOSED);
m_currentlyDisplaying = false; m_currentlyDisplaying = false;

View File

@ -3,8 +3,8 @@
#include "core/plugins/snorebackend.h" #include "core/plugins/snorebackend.h"
namespace Snore
namespace Snore{ {
class SnoreCore; class SnoreCore;
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -38,10 +37,10 @@ FreedesktopFrontend::FreedesktopFrontend():
SnoreFrontend("Freedesktop") SnoreFrontend("Freedesktop")
{ {
} }
FreedesktopFrontend::~FreedesktopFrontend(){ FreedesktopFrontend::~FreedesktopFrontend()
{
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService("org.freedesktop.Notifications"); dbus.unregisterService("org.freedesktop.Notifications");
} }
@ -51,8 +50,7 @@ bool FreedesktopFrontend::initialize(SnoreCore *snore)
m_adaptor = new NotificationsAdaptor(this); m_adaptor = new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
if (dbus.registerService("org.freedesktop.Notifications") && if (dbus.registerService("org.freedesktop.Notifications") &&
dbus.registerObject( "/org/freedesktop/Notifications", this )) dbus.registerObject("/org/freedesktop/Notifications", this)) {
{
return SnoreFrontend::initialize(snore); return SnoreFrontend::initialize(snore);
} }
return false; return false;
@ -60,8 +58,7 @@ bool FreedesktopFrontend::initialize(SnoreCore *snore)
bool FreedesktopFrontend::deinitialize() bool FreedesktopFrontend::deinitialize()
{ {
if(SnoreFrontend::deinitialize()) if (SnoreFrontend::deinitialize()) {
{
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService("org.freedesktop.Notifications"); dbus.unregisterService("org.freedesktop.Notifications");
dbus.unregisterObject("/org/freedesktop/Notifications"); dbus.unregisterObject("/org/freedesktop/Notifications");
@ -74,8 +71,7 @@ bool FreedesktopFrontend::deinitialize()
void FreedesktopFrontend::actionInvoked(Notification notification) void FreedesktopFrontend::actionInvoked(Notification notification)
{ {
if(notification.actionInvoked().isValid()) if (notification.actionInvoked().isValid()) {
{
emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id())); emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id()));
} }
} }
@ -93,25 +89,20 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
Application app; Application app;
Notification::Prioritys priotity = Notification::NORMAL; Notification::Prioritys priotity = Notification::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 = Icon(image.toQImage()); icon = Icon(image.toQImage());
} } else {
else
{
icon = Icon(":/root/snore.png"); icon = Icon(":/root/snore.png");
} }
if(!snore()->aplications().contains(app_name)) if (!snore()->aplications().contains(app_name)) {
{
qDebug() << QIcon::themeSearchPaths(); qDebug() << QIcon::themeSearchPaths();
QIcon qicon = QIcon::fromTheme(app_icon, QIcon(":/root/snore.png")); QIcon qicon = QIcon::fromTheme(app_icon, QIcon(":/root/snore.png"));
QSize max; QSize max;
foreach(const QSize & s, qicon.availableSizes()) { foreach(const QSize & s, qicon.availableSizes()) {
if(s.width()*s.height()>max.width()*max.height()) if (s.width()*s.height() > max.width()*max.height()) {
{
max = s; max = s;
} }
} }
@ -120,29 +111,22 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
app = Application(app_name, appIcon); app = Application(app_name, appIcon);
app.addAlert(alert); app.addAlert(alert);
snore()->registerApplication(app); snore()->registerApplication(app);
} } else {
else
{
app = snore()->aplications()[app_name]; app = snore()->aplications()[app_name];
} }
if (hints.contains("urgency")) if (hints.contains("urgency")) {
{
priotity = Notification::Prioritys(hints["urgency"].toInt() - 1); priotity = Notification::Prioritys(hints["urgency"].toInt() - 1);
} }
Notification noti; Notification noti;
if(replaces_id != 0 && snore()->getActiveNotificationByID(replaces_id).isValid()) if (replaces_id != 0 && snore()->getActiveNotificationByID(replaces_id).isValid()) {
{
noti = Notification(snore()->getActiveNotificationByID(replaces_id), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity); noti = Notification(snore()->getActiveNotificationByID(replaces_id), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
} } else {
else
{
noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity); noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
} }
noti.data()->setSource(this); noti.data()->setSource(this);
for(int i = 0;i < actions.length(); i+=2) for (int i = 0; i < actions.length(); i += 2) {
{
noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1))); noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1)));
} }
@ -150,13 +134,10 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
return noti.id(); return noti.id();
} }
void FreedesktopFrontend::CloseNotification(uint id) void FreedesktopFrontend::CloseNotification(uint id)
{ {
Notification noti = snore()->getActiveNotificationByID(id); Notification noti = snore()->getActiveNotificationByID(id);
if(noti.isValid()) if (noti.isValid()) {
{
snore()->requestCloseNotification(noti, Notification::TIMED_OUT); snore()->requestCloseNotification(noti, Notification::TIMED_OUT);
} }
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -53,7 +52,6 @@ private:
Snore::Icon m_icon; Snore::Icon m_icon;
NotificationsAdaptor *m_adaptor; NotificationsAdaptor *m_adaptor;
}; };
#endif//FREEDESKTOPNOTIFICATION_FRONTEND_H #endif//FREEDESKTOPNOTIFICATION_FRONTEND_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,6 @@
#include "core/notification/notification.h" #include "core/notification/notification.h"
#include "core/notification/notification_p.h" #include "core/notification/notification_p.h"
#include <QDir> #include <QDir>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QEventLoop> #include <QEventLoop>
@ -53,7 +51,6 @@ Parser::Parser(SnarlNetworkFrontend *snarl):
getSnpType.insert("timeout", TIMEOUT); getSnpType.insert("timeout", TIMEOUT);
} }
void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *client) void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *client)
{ {
snoreDebug(SNORE_DEBUG) << msg; snoreDebug(SNORE_DEBUG) << msg;
@ -70,12 +67,10 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl
QString key; QString key;
QString value; QString value;
foreach(QString s,splitted) foreach(QString s, splitted) {
{
key = s.mid(0, s.indexOf("=")).toLower(); key = s.mid(0, s.indexOf("=")).toLower();
value = s.mid(s.indexOf("=") + 1); value = s.mid(s.indexOf("=") + 1);
switch(getSnpType.value(key)) switch (getSnpType.value(key)) {
{
case APP: case APP:
appName = value; appName = value;
break; break;
@ -102,38 +97,26 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl
} }
} }
Application app; Application app;
Alert alert; Alert alert;
if(snarl->m_applications.contains(client)) if (snarl->m_applications.contains(client)) {
{
app = snarl->m_applications[client]; app = snarl->m_applications[client];
} }
if (!alertName.isEmpty() && app.isValid()) {
if(!alertName.isEmpty() && app.isValid()) if (app.alerts().contains(alertName)) {
{
if(app.alerts().contains(alertName))
{
alert = app.alerts()[alertName]; alert = app.alerts()[alertName];
} }
} }
switch (action) {
case NOTIFICATION: {
if (!snarl->snore()->aplications().contains(app.name())) {
switch(action)
{
case NOTIFICATION:
{
if(!snarl->snore()->aplications().contains(app.name()))
{
snarl->snore()->registerApplication(app); snarl->snore()->registerApplication(app);
} }
if(!alert.isActive()) if (!alert.isActive()) {
{
break; break;
} }
sNotification = Notification(app, alert, title, text, icon, timeout); sNotification = Notification(app, alert, title, text, icon, timeout);
@ -142,8 +125,7 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl
break; break;
} }
case ADD_CLASS: case ADD_CLASS:
if(alertName.isEmpty()) if (alertName.isEmpty()) {
{
snoreDebug(SNORE_DEBUG) << "Error registering alert with empty name"; snoreDebug(SNORE_DEBUG) << "Error registering alert with empty name";
break; break;
} }
@ -151,12 +133,9 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl
app.addAlert(alert); app.addAlert(alert);
break; break;
case REGISTER: case REGISTER:
if(!snarl->m_applications.contains(client)) if (!snarl->m_applications.contains(client)) {
{
snarl->m_applications[client] = Application(appName, icon); snarl->m_applications[client] = Application(appName, icon);
} } else {
else
{
snoreDebug(SNORE_DEBUG) << appName << "already registred"; snoreDebug(SNORE_DEBUG) << appName << "already registred";
} }
break; break;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -25,8 +24,6 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QObject> #include <QObject>
class Parser : public QObject class Parser : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -29,27 +28,24 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(libsnore_frontend_snarlnetwork, SnarlNetworkFrontend) Q_EXPORT_PLUGIN2(libsnore_frontend_snarlnetwork, SnarlNetworkFrontend)
SnarlNetworkFrontend::SnarlNetworkFrontend(): SnarlNetworkFrontend::SnarlNetworkFrontend():
SnoreFrontend("SnarlNetwork") SnoreFrontend("SnarlNetwork")
{ {
} }
SnarlNetworkFrontend::~SnarlNetworkFrontend(){ SnarlNetworkFrontend::~SnarlNetworkFrontend()
{
} }
bool SnarlNetworkFrontend::initialize(SnoreCore *snore) bool SnarlNetworkFrontend::initialize(SnoreCore *snore)
{ {
parser = new Parser(this); parser = new Parser(this);
tcpServer = new QTcpServer(this); tcpServer = new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port)) if (!tcpServer->listen(QHostAddress::Any, port)) {
{
snoreDebug(SNORE_DEBUG) << "The port is already used"; snoreDebug(SNORE_DEBUG) << "The port is already used";
return false; return false;
} } else {
else
{
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection())); connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl; std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl;
} }
@ -58,8 +54,7 @@ bool SnarlNetworkFrontend::initialize(SnoreCore *snore)
bool SnarlNetworkFrontend::deinitialize() bool SnarlNetworkFrontend::deinitialize()
{ {
if(SnoreFrontend::deinitialize()) if (SnoreFrontend::deinitialize()) {
{
parser->deleteLater(); parser->deleteLater();
parser = NULL; parser = NULL;
@ -70,7 +65,6 @@ bool SnarlNetworkFrontend::deinitialize()
return false; return false;
} }
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification) void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
{ {
snoreDebug(SNORE_DEBUG) << notification.closeReason(); snoreDebug(SNORE_DEBUG) << notification.closeReason();
@ -79,8 +73,7 @@ void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification)
{ {
switch(notification.closeReason()) switch (notification.closeReason()) {
{
case Notification::TIMED_OUT: case Notification::TIMED_OUT:
callback(notification, "SNP/1.1/303/Notification timed out/"); callback(notification, "SNP/1.1/303/Notification timed out/");
break; break;
@ -106,21 +99,16 @@ void SnarlNetworkFrontend::handleMessages()
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender()); QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
QStringList messages(QString::fromAscii(client->readAll()).trimmed().split("\r\n")); QStringList messages(QString::fromAscii(client->readAll()).trimmed().split("\r\n"));
foreach(const QString &s, messages) foreach(const QString & s, messages) {
{ if (s.isEmpty()) {
if(s.isEmpty())
{
continue; continue;
} }
Notification noti; Notification noti;
parser->parse(noti, s, client); parser->parse(noti, s, client);
if(noti.isValid()) if (noti.isValid()) {
{
snore()->broadcastNotification(noti); snore()->broadcastNotification(noti);
write(client, QString("%1/%2\r\n").arg(out, QString::number(noti.id()))); write(client, QString("%1/%2\r\n").arg(out, QString::number(noti.id())));
} } else {
else
{
write(client, QString("%1\r\n").arg(out)); write(client, QString("%1\r\n").arg(out));
} }
} }
@ -128,8 +116,7 @@ void SnarlNetworkFrontend::handleMessages()
void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) void SnarlNetworkFrontend::callback(Notification &sn, const QString msg)
{ {
if(sn.hints().containsPrivateValue(this, "clientSocket")) if (sn.hints().containsPrivateValue(this, "clientSocket")) {
{
QTcpSocket *client = qobject_cast<QTcpSocket *>(sn.hints().privateValue(this, "clientSocket").value<QObject *>()); QTcpSocket *client = qobject_cast<QTcpSocket *>(sn.hints().privateValue(this, "clientSocket").value<QObject *>());
write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id()))); write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id())));
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -27,7 +26,6 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <QTcpServer> #include <QTcpServer>
class SnarlNetworkFrontend : public Snore::SnoreFrontend class SnarlNetworkFrontend : public Snore::SnoreFrontend
{ {
Q_OBJECT Q_OBJECT

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -47,7 +46,8 @@ SnoreNotify::SnoreNotify():
snoreDebug(SNORE_DEBUG) << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend(); snoreDebug(SNORE_DEBUG) << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend();
} }
SnoreNotify::~SnoreNotify(){ SnoreNotify::~SnoreNotify()
{
delete m_snore; delete m_snore;
delete m_trayIcon; delete m_trayIcon;
} }
@ -55,26 +55,23 @@ SnoreNotify::~SnoreNotify(){
void SnoreNotify::load() void SnoreNotify::load()
{ {
QString backend = m_settings.value("notificationBackend").toString(); QString backend = m_settings.value("notificationBackend").toString();
if(!backend.isEmpty()) if (!backend.isEmpty()) {
{ if (!m_snore->setPrimaryNotificationBackend(backend)) {
if(!m_snore->setPrimaryNotificationBackend(backend)) m_snore->setPrimaryNotificationBackend();
{ }
} else {
m_snore->setPrimaryNotificationBackend(); m_snore->setPrimaryNotificationBackend();
} }
} }
else void SnoreNotify::save()
{ {
m_snore->setPrimaryNotificationBackend();
}
}
void SnoreNotify::save(){
m_settings.setValue("notificationBackend", m_snore->primaryNotificationBackend()); m_settings.setValue("notificationBackend", m_snore->primaryNotificationBackend());
} }
void SnoreNotify::exit(){ void SnoreNotify::exit()
snoreDebug( SNORE_DEBUG )<<"Saving snore settings";
foreach(const Application &a,m_snore->aplications())
{ {
snoreDebug(SNORE_DEBUG) << "Saving snore settings";
foreach(const Application & a, m_snore->aplications()) {
m_snore->deregisterApplication(a); m_snore->deregisterApplication(a);
} }
save(); save();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -22,7 +21,8 @@
#include <QtCore> #include <QtCore>
namespace Snore{ namespace Snore
{
class SnoreCore; class SnoreCore;
} }

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -44,8 +43,7 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
m_trayMenu = new QMenu("SnoreNotify"); m_trayMenu = new QMenu("SnoreNotify");
QString version = QString("SnoreNotify %1").arg(Version::version()); QString version = QString("SnoreNotify %1").arg(Version::version());
if(Version::revision() != "") if (Version::revision() != "") {
{
version += QString("-%1").arg(Version::revision()); version += QString("-%1").arg(Version::revision());
} }
m_trayMenu->addAction(version); m_trayMenu->addAction(version);
@ -54,12 +52,10 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
m_trayMenu->addSeparator(); m_trayMenu->addSeparator();
m_backendActions = new QActionGroup(m_trayMenu); m_backendActions = new QActionGroup(m_trayMenu);
m_backendActions->setExclusive(true); m_backendActions->setExclusive(true);
foreach(const QString &back,m_snore->notificationBackends()) foreach(const QString & back, m_snore->notificationBackends()) {
{
QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend())); QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend()));
b->setCheckable(true); b->setCheckable(true);
if(back == m_snore->primaryNotificationBackend()) if (back == m_snore->primaryNotificationBackend()) {
{
b->setChecked(true); b->setChecked(true);
} }
m_backendActions->addAction(b); m_backendActions->addAction(b);
@ -67,7 +63,6 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
m_trayMenu->addSeparator(); m_trayMenu->addSeparator();
m_trayMenu->addAction("Exit", qApp, SLOT(quit())); m_trayMenu->addAction("Exit", qApp, SLOT(quit()));
m_trayIcon->setContextMenu(m_trayMenu); m_trayIcon->setContextMenu(m_trayMenu);
} }
@ -81,14 +76,13 @@ QSystemTrayIcon* TrayIcon::trayIcon()
return m_trayIcon; return m_trayIcon;
} }
void TrayIcon::setPrimaryBackend(){ void TrayIcon::setPrimaryBackend()
{
QAction *a = qobject_cast<QAction *>(sender()); QAction *a = qobject_cast<QAction *>(sender());
m_snore->setPrimaryNotificationBackend(a->text()); m_snore->setPrimaryNotificationBackend(a->text());
foreach (QAction *action, m_backendActions->actions()) foreach(QAction * action, m_backendActions->actions()) {
{ if (action->text() == m_snore->primaryNotificationBackend()) {
if(action->text() == m_snore->primaryNotificationBackend())
{
action->setChecked(true); action->setChecked(true);
break; break;
} }
@ -98,8 +92,7 @@ void TrayIcon::setPrimaryBackend(){
void TrayIcon::slotTestNotification() void TrayIcon::slotTestNotification()
{ {
if(!m_snore->aplications().contains(m_app.name())) if (!m_snore->aplications().contains(m_app.name())) {
{
m_snore->registerApplication(m_app); m_snore->registerApplication(m_app);
} }
Notification noti(m_app, m_alert, "Hello World", Notification noti(m_app, m_alert, "Hello World",

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org> Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,6 @@
#include <QAction> #include <QAction>
#include "core/snore.h" #include "core/snore.h"
class TrayIcon: public QObject class TrayIcon: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -44,7 +42,6 @@ private:
QHash<QTimer *, Snore::Notification> m_notifications; QHash<QTimer *, Snore::Notification> m_notifications;
public slots: public slots:
void setPrimaryBackend(); void setPrimaryBackend();
void slotTestNotification(); void slotTestNotification();