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
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -67,15 +66,11 @@ bool Alert::isValid() const
return d;
}
QDebug operator<<(QDebug debug, const Alert &alert)
{
if(alert.isValid())
{
if (alert.isValid()) {
debug << "Snore::Alert(" << alert.name() << ")" ;
}
else
{
} else {
debug << "Snore::Alert(0x00)" ;
}
return debug.maybeSpace();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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);
#endif // ALERT_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#include "application.h"
#include "application_p.h"
using namespace Snore;
Application::Application():
@ -86,17 +84,13 @@ const Hint &Application::constHints() const
QDebug operator<< (QDebug debug, const Snore::Application &app)
{
if(app.isValid())
{
if (app.isValid()) {
debug << "Snore::Application(" << app.name() << ", ";
foreach(const Alert &a, app.alerts())
{
foreach(const Alert & a, app.alerts()) {
debug << a << ", ";
}
debug << ")" ;
}
else
{
} else {
debug << "Snore::Application(0x00)" ;
}
return debug.maybeSpace();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -25,7 +24,8 @@
#include "alert.h"
#include <QHash>
namespace Snore{
namespace Snore
{
class ApplicationData;
@ -110,7 +110,6 @@ public:
private:
QExplicitlySharedDataPointer<ApplicationData> d;
};
}
@ -118,6 +117,4 @@ Q_DECLARE_METATYPE(Snore::Application)
SNORE_EXPORT QDebug operator<< (QDebug debug, const Snore::Application &app);
#endif // APPLICATION_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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
{
QString key(k.toLower());
if(m_data.contains(key))
{
if (m_data.contains(key)) {
return m_data.value(key);
}
else
{
} else {
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);
}
QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const
{
QPair<quintptr, QString> key((quintptr)owner, k.toLower());
if(m_privateData.contains(key))
{
if (m_privateData.contains(key)) {
return m_privateData.value(key);
}
else
{
} else {
return defaultValue;
}
}
bool Hint::containsPrivateValue(const void *owner, const QString &key) const
{
QPair<quintptr, QString> pk((quintptr)owner, key.toLower());
@ -95,13 +86,10 @@ void Hint::slotValueDestroyed()
{
QObject *o = sender();
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);
m_privateData.remove(pk);
}
else
{
} else {
m_data.remove(key);
}
}
@ -109,18 +97,14 @@ void Hint::slotValueDestroyed()
QDebug operator<<(QDebug debug, const Snore::Hint &hint)
{
debug << "Snore::Hint(";
for(QVariantHash::const_iterator it = hint.m_data.constBegin();it != hint.m_data.constEnd();++it)
{
if(it != hint.m_data.constBegin())
{
for (QVariantHash::const_iterator it = hint.m_data.constBegin(); it != hint.m_data.constEnd(); ++it) {
if (it != hint.m_data.constBegin()) {
debug << ", ";
}
debug << "(" << it.key() << ", " << it.value();
}
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())
{
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()) {
debug << ", ";
}
debug << "(" << it.key() << ", " << it.value();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -116,10 +115,6 @@ private:
};
}
#endif // HINT_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -31,12 +30,9 @@ class Loger
public:
static int s_debugLevel;
static inline int debugLvl()
{
if(s_debugLevel == -1)
{
if (s_debugLevel == -1) {
s_debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt();
}
return s_debugLevel;
@ -45,8 +41,7 @@ static inline int debugLvl()
static inline bool isLogToFileEnabled()
{
static int s_logToFile = -1;
if(s_logToFile == -1)
{
if (s_logToFile == -1) {
s_logToFile = qgetenv("LIBSNORE_LOG_TO_FILE").toInt();
}
return s_logToFile == 1;
@ -56,12 +51,10 @@ static inline QTextStream &logFile()
{
static QTextStream *s_out = 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());
if(!qgetenv("LIBSNORE_LOGFILE").isNull())
{
if (!qgetenv("LIBSNORE_LOGFILE").isNull()) {
name = QString(qgetenv("LIBSNORE_LOGFILE"));
}
std::cout << "Started logging to " << name.toUtf8().constData() << std::endl;
@ -73,7 +66,6 @@ static inline QTextStream &logFile()
return *s_out;
}
};
int Loger::s_debugLevel = -1;
@ -86,13 +78,11 @@ SnoreLog::SnoreLog(SnoreDebugLevels lvl):
SnoreLog::~SnoreLog()
{
if(Loger::isLogToFileEnabled())
{
if (Loger::isLogToFileEnabled()) {
Loger::logFile() << m_msg << "\n";
Loger::logFile().flush();
}
if(Loger::debugLvl() >= m_lvl)
{
if (Loger::debugLvl() >= m_lvl) {
std::cout << m_msg.toLatin1().constData() << std::endl;
}
}

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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();
}
@ -94,7 +94,6 @@ QString Icon::url() const
return d->m_url;
}
bool Snore::Icon::isRemoteFile() const
{
return d->m_isRemoteFile;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,8 @@
#include <QSharedData>
#include <QDebug>
namespace Snore{
namespace Snore
{
class Icon;
}
@ -117,6 +117,4 @@ private:
};
}
#endif // NOTIFICATION_ICON_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -35,8 +34,7 @@ IconData::IconData(const QString &url):
m_isLocalFile(false),
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_localUrl = url;
}
@ -61,14 +59,10 @@ IconData::~IconData()
const QImage &IconData::image()
{
QMutexLocker lock(&m_mutex);
if(m_img.isNull())
{
if(!m_isRemoteFile )
{
if (m_img.isNull()) {
if (!m_isRemoteFile) {
m_img = QImage(m_url);
}
else
{
} else {
download();
}
}
@ -77,11 +71,9 @@ const QImage &IconData::image()
QString IconData::localUrl()
{
if(!m_isLocalFile && !s_localImageCache.contains(m_localUrl))
{
if (!m_isLocalFile && !s_localImageCache.contains(m_localUrl)) {
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");
s_localImageCache.insert(m_localUrl);
snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache";
@ -90,13 +82,10 @@ QString IconData::localUrl()
return m_localUrl;
}
void IconData::download()
{
if(m_isRemoteFile)
{
if(!s_localImageCache.contains(m_localUrl))
{
if (m_isRemoteFile) {
if (!s_localImageCache.contains(m_localUrl)) {
snoreDebug(SNORE_DEBUG) << "Downloading:" << m_url;
QNetworkAccessManager manager;
QEventLoop loop;
@ -106,16 +95,13 @@ void IconData::download()
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); //timeout
loop.exec();
if(reply->isFinished())
{
if (reply->isFinished()) {
m_img = QImage::fromData(reply->readAll(), "PNG");
m_img.save(m_localUrl, "PNG");
s_localImageCache.insert(m_localUrl);
snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache";
}
}
else
{
} else {
m_img = QImage(m_localUrl);
}
}

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#ifndef ICONDATA_H
#define ICONDATA_H
#include "notification.h"
#include "snore_p.h"
@ -33,7 +31,8 @@
#include <QMutex>
namespace Snore{
namespace Snore
{
class IconData : public QSharedData
{
@ -46,7 +45,6 @@ public:
QString localUrl();
void download();
QImage m_img;
QString m_url;
QString m_hash;
@ -56,7 +54,6 @@ public:
bool m_isRemoteFile;
QMutex m_mutex;
static QSet<QString> s_localImageCache;
private:

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -27,10 +26,8 @@
using namespace Snore;
int Notification::m_defaultTimeout = 10;
Notification::Notification() :
d(NULL)
{
@ -117,7 +114,6 @@ bool Notification::isSticky() const
return d->m_timeout == 0;
}
Notification::Prioritys Notification::priority() const
{
return d->m_priority;
@ -128,13 +124,13 @@ void Notification::addAction(const Action &a)
d->m_actions.insert(a.id(), a);
}
const QHash<int, Action> &Notification::actions() const
{
return d->m_actions;
}
const Notification::CloseReasons &Notification::closeReason(){
const Notification::CloseReasons &Notification::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)
{
debug.nospace() << "CloseReasons(";
switch(flags)
{
switch (flags) {
debugPrintEnum(Notification::NONE);
debugPrintEnum(Notification::TIMED_OUT);
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)
{
debug.nospace() << "Prioritys(";
switch(flags)
{
switch (flags) {
debugPrintEnum(Notification::LOW);
debugPrintEnum(Notification::NORMAL);
debugPrintEnum(Notification::HIGH);

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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/>.
*/
#include "notification/notification_p.h"
#include "notification/icon.h"
#include "../hint.h"
@ -68,15 +65,13 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString
NotificationData::~NotificationData()
{
if(!m_timeoutTimer.isNull())
{
if (!m_timeoutTimer.isNull()) {
m_timeoutTimer->deleteLater();
}
notificationCount--;
snoreDebug(SNORE_DEBUG) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason;
}
void NotificationData::setActionInvoked(const Snore::Action &action)
{
m_actionInvoked = action;
@ -104,8 +99,7 @@ void NotificationData::setCloseReason(Snore::Notification::CloseReasons r)
QTimer *NotificationData::timeoutTimer()
{
if(m_timeoutTimer.isNull())
{
if (m_timeoutTimer.isNull()) {
m_timeoutTimer = new QTimer();
m_timeoutTimer->setSingleShot(true);
m_timeoutTimer->setProperty("notificationID", m_id);

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -20,7 +19,6 @@
#ifndef NOTIFICATIONDATA_H
#define NOTIFICATIONDATA_H
#include "icon.h"
#include "notification.h"
#include "../hint.h"
@ -29,9 +27,8 @@
#include <QTimer>
#include <QPointer>
namespace Snore{
namespace Snore
{
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();
void setSource(class SnoreFrontend *source);
@ -52,10 +48,8 @@ public:
void setActionInvoked(const Action &action);
void setActionInvoked(const int &actionID);
void setCloseReason(Notification::CloseReasons r);
QTimer *timeoutTimer();
private:
@ -78,8 +72,6 @@ private:
Notification m_toReplace;
QPointer<QTimer> m_timeoutTimer;
static uint notificationCount;
static uint m_idCount;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,6 @@
#include <QDataStream>
namespace Snore
{

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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;
PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type):
m_pluginFile(fileName),
m_pluginName(pluginName),
@ -52,8 +50,7 @@ PluginContainer::~PluginContainer()
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();
return NULL;
}
@ -98,11 +95,9 @@ QString PluginContainer::typeToString(const SnorePlugin::PluginTypes t)
const QList<SnorePlugin::PluginTypes> &PluginContainer::types()
{
static QList<SnorePlugin::PluginTypes> t;
if(t.isEmpty())
{
if (t.isEmpty()) {
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);
}
}
@ -112,10 +107,8 @@ const QList<SnorePlugin::PluginTypes> &PluginContainer::types()
void PluginContainer::updatePluginCache()
{
snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
foreach(PluginContaienrHash list, s_pluginCache)
{
foreach(PluginContainer* p, list.values())
{
foreach(PluginContaienrHash list, s_pluginCache) {
foreach(PluginContainer * p, list.values()) {
delete p;
}
list.clear();
@ -123,22 +116,18 @@ void PluginContainer::updatePluginCache()
QList<PluginContainer *> plugins;
foreach(const SnorePlugin::PluginTypes type,PluginContainer::types())
{
foreach(const SnorePlugin::PluginTypes type, PluginContainer::types()) {
foreach(const QFileInfo & file, pluginDir().entryInfoList(
QStringList(pluginFileFilters(type)), QDir::Files))
{
QStringList(pluginFileFilters(type)), QDir::Files)) {
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath());
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();
continue;
}
SnorePlugin *sp = qobject_cast<SnorePlugin *>(plugin);
if(sp == NULL)
{
if (sp == NULL) {
snoreDebug(SNORE_WARNING) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ;
loader.unload();
continue;
@ -153,8 +142,7 @@ void PluginContainer::updatePluginCache()
const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin::PluginTypes type)
{
if(s_pluginCache.isEmpty())
{
if (s_pluginCache.isEmpty()) {
QTime time;
time.start();
updatePluginCache();
@ -162,15 +150,11 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
}
QHash<QString, PluginContainer *> out;
if(type == SnorePlugin::ALL)
{
foreach(const SnorePlugin::PluginTypes &t,types())
{
if (type == SnorePlugin::ALL) {
foreach(const SnorePlugin::PluginTypes & t, types()) {
out.unite(s_pluginCache.value(t));
}
}
else
{
} else {
out = s_pluginCache[type];
}
return out;
@ -180,14 +164,12 @@ const QDir &PluginContainer::pluginDir()
{
static bool isLoaded = false;
static QDir path;
if(!isLoaded)
{
if (!isLoaded) {
isLoaded = true;
QString appDir = qApp->applicationDirPath();
QStringList list;
#ifdef Q_OS_MAC
if ( appDir == "MacOS" )
{
if (appDir == "MacOS") {
list << appDir;
QDir dir(appDir);
// Development convenience-hack
@ -202,21 +184,16 @@ const QDir &PluginContainer::pluginDir()
<< QString("%1/../lib/libsnore" SNORE_SUFFIX).arg(appDir)
<< QString("%1/../lib64/libsnore" SNORE_SUFFIX).arg(appDir)
<< QLatin1String(LIBSNORE_PLUGIN_PATH);
foreach(const QString &p, list)
{
foreach(const QString & p, list) {
path = QDir(p);
if(!path.entryInfoList(pluginFileFilters()).isEmpty())
{
if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {
break;
}
else
{
} else {
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_INFO) << "PluginPath is :" << path.absolutePath();
@ -224,4 +201,3 @@ const QDir &PluginContainer::pluginDir()
return path;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,8 @@
#include <QDir>
#include <QDebug>
namespace Snore{
namespace Snore
{
SnoreFrontend::SnoreFrontend(const QString &name) :
SnorePlugin(name)

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -26,12 +25,12 @@
#include <QPointer>
#include <QFlag>
namespace Snore{
namespace Snore
{
class Application;
class SnoreCore;
class SnorePlugin;
class SNORE_EXPORT SnoreFrontend: public SnorePlugin
{
Q_OBJECT

View File

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

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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/>.
*/
#include "snore_p.h"
#include "snore.h"
#include "plugins/plugins.h"
@ -39,8 +37,7 @@ SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
m_defaultApp("SnoreNotify", Icon(":/root/snore.png"))
{
snoreDebug(SNORE_INFO) << "Version:" << Version::version();
if( !Version::revision().isEmpty() )
{
if (!Version::revision().isEmpty()) {
snoreDebug(SNORE_INFO) << "Revision:" << Version::revision();
}
@ -64,8 +61,7 @@ void SnoreCorePrivate::notificationActionInvoked(Notification notification) cons
{
Q_Q(const SnoreCore);
emit const_cast<SnoreCore *>(q)->actionInvoked(notification);
if ( notification.data()->source() )
{
if (notification.data()->source()) {
notification.data()->source()->actionInvoked(notification);
}
}
@ -73,8 +69,7 @@ void SnoreCorePrivate::notificationActionInvoked(Notification notification) cons
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
{
Q_Q(SnoreCore);
if( m_plugins[SnorePlugin::BACKEND].contains(backend))
{
if (m_plugins[SnorePlugin::BACKEND].contains(backend)) {
return q->setPrimaryNotificationBackend(backend);
}
return false;
@ -105,18 +100,15 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
{
Q_Q(SnoreCore);
emit q->notificationClosed(n);
if(n.data()->source())
{
if (n.data()->source()) {
n.data()->source()->notificationClosed(n);
}
}
void SnoreCorePrivate::slotAboutToQuit()
{
foreach (PluginContainer *p, PluginContainer::pluginCache(SnorePlugin::ALL))
{
if(p->isLoaded())
{
foreach(PluginContainer * p, PluginContainer::pluginCache(SnorePlugin::ALL)) {
if (p->isLoaded()) {
snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name();
p->load()->deinitialize();
}

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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/>.
*/
#ifndef SNORECOREPRIVATE_H
#define SNORECOREPRIVATE_H
@ -54,12 +52,10 @@ public:
~SnoreCorePrivate();
const Application defaultApplication() const;
void notificationActionInvoked(Notification notification) const;
bool setBackendIfAvailible(const QString &backend);
/**
*
* @return whether the backend can update a notification

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -22,10 +21,8 @@
#include <QImage>
#include <QtGlobal>
int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<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();
}
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i)
{
a.beginStructure();
a << i.width <<
i.height <<
@ -62,7 +60,8 @@ QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) {
const QDBusArgument &operator >>(const QDBusArgument &a, FreedesktopImageHint &i)
{
a.beginStructure();
a >> i.width >>
i.height >>

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -25,7 +24,6 @@
#include <QtDBus>
#include <QMetaType>
class FreedesktopImageHint
{
public:
@ -44,7 +42,6 @@ public:
private:
static int imageHintID;
};
Q_DECLARE_METATYPE(FreedesktopImageHint);

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -50,5 +49,4 @@ public slots:
void slotNotify(Snore::Notification notification);
};
#endif // GROWL_BACKEND_H

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -37,5 +36,4 @@ public slots:
virtual void slotNotify(Snore::Notification notification);
};
#endif // OSXNOTIFICATIONCENTER_H

View File

@ -51,10 +51,10 @@
#include "SnarlInterface.h"
namespace Snarl {
namespace V42 {
namespace Snarl
{
namespace V42
{
// workaround for mingw-w64 bug
#ifdef __MINGW64_VERSION_MAJOR
@ -65,7 +65,6 @@ namespace V42 {
}
#endif //__MINGW64_VERSION_MAJOR
// ----------------------------------------------------------------------------
// Static Snarl interface functions
// ----------------------------------------------------------------------------
@ -85,8 +84,9 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout)
DWORD_PTR nResult = 0;
HWND hWnd = GetSnarlWindow();
if (!IsWindow(hWnd))
if (!IsWindow(hWnd)) {
return -SnarlEnums::ErrorNotRunning;
}
// Create COPYDATASTRUCT
COPYDATASTRUCT cds;
@ -95,21 +95,21 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout)
cds.lpData = const_cast<char *>(request);
// 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
DWORD nError = GetLastError();
LONG32 errorResult = 0;
if (nError == ERROR_TIMEOUT)
if (nError == ERROR_TIMEOUT) {
errorResult = -SnarlEnums::ErrorTimedOut;
else
} else {
errorResult = -SnarlEnums::ErrorFailed;
}
return errorResult;
}
else
} else {
return (LONG32)nResult;
}
}
LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
{
@ -117,8 +117,9 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
// Convert to UTF8
LPSTR utf8Request = WideToUTF8(request);
if (utf8Request == NULL)
if (utf8Request == NULL) {
return -SnarlEnums::ErrorCppInterface;
}
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>::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) == '=') {
str.insert(++i, "=");
++strLength;
}
else if (str[i] == '&') {
} else if (str[i] == '&') {
str.insert(++i, "&");
++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>::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'=') {
str.insert(++i, L"=");
++strLength;
}
else if (str[i] == L'&') {
} else if (str[i] == L'&') {
str.insert(++i, L"&");
++strLength;
}
@ -166,11 +163,9 @@ std::basic_string<wchar_t>& SnarlInterface::Escape(std::basic_string<wchar_t>& s
LPCTSTR SnarlInterface::GetAppPath()
{
HWND hWnd = GetSnarlWindow();
if (hWnd)
{
if (hWnd) {
HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL);
if (hWndPath)
{
if (hWndPath) {
TCHAR strTmp[MAX_PATH] = {0};
int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH - 1);
if (nReturn > 0) {
@ -189,13 +184,13 @@ LPCTSTR SnarlInterface::GetIconsPath()
{
TCHAR *szIconPath = NULL;
LPCTSTR szPath = GetAppPath();
if (!szPath)
if (!szPath) {
return NULL;
}
size_t nLen = 0;
nLen = _tcsnlen(szPath, MAX_PATH);
if (nLen > 0)
{
if (nLen > 0) {
nLen += 10 + 1; // etc\\icons\\ + NULL
szIconPath = AllocateString(nLen);
@ -223,7 +218,6 @@ BOOL SnarlInterface::IsSnarlRunning()
return IsWindow(GetSnarlWindow());
}
// --------------------------------------------------------------------------------------------
// SnarlInterface member functions
// --------------------------------------------------------------------------------------------
@ -267,7 +261,6 @@ LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd)
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)
{
// 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("icon", icon);
spl.Add("sound", sound);
if (duration != -1) spl.Add("duration", duration);
if (duration != -1) {
spl.Add("duration", duration);
}
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"icon", icon);
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);
}
LONG32 SnarlInterface::ClearActions(LONG32 msgToken)
{
// 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);
}
LONG32 SnarlInterface::ClearClasses()
{
// clearclasses?[token=app-sig=<signature>|token=<application token>][&password=<password>]
@ -333,13 +328,11 @@ LONG32 SnarlInterface::ClearClasses()
return DoRequest(Requests::ClearClassesA(), spl);
}
LONG32 SnarlInterface::GetLastMsgToken() const
{
return lastMsgToken;
}
LONG32 SnarlInterface::Hide(LONG32 msgToken)
{
// 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);
}
LONG32 SnarlInterface::IsVisible(LONG32 msgToken)
{
// 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);
}
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>]
@ -382,8 +373,12 @@ LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32
spl.Add("uid", uid);
spl.Add("callback", callback);
spl.Add("value", value);
if (timeout != -1) spl.Add("timeout", timeout);
if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority
if (timeout != -1) {
spl.Add("timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add("priority", priority); // -1 is a legal priority
}
LONG32 request = DoRequest(Requests::NotifyA(), spl);
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"callback", callback);
spl.Add(L"value", value);
if (timeout != -1) spl.Add(L"timeout", timeout);
if (priority != SnarlEnums::PriorityUndefined) spl.Add(L"priority", priority); // -1 is a legal priority
if (timeout != -1) {
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);
lastMsgToken = (request > 0) ? request : 0;
@ -414,7 +413,6 @@ LONG32 SnarlInterface::Notify(LPCWSTR classId, LPCWSTR title, LPCWSTR text, LONG
return request;
}
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>]
@ -429,12 +427,14 @@ LONG32 SnarlInterface::Register(LPCSTR signature, LPCSTR title, LPCSTR icon, LPC
spl.Add("flags", flags);
// 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);
}
LONG32 request = DoRequest(Requests::RegisterA(), spl);
if (request > 0)
if (request > 0) {
appToken = request;
}
return request;
}
@ -451,17 +451,18 @@ LONG32 SnarlInterface::Register(LPCWSTR signature, LPCWSTR name, LPCWSTR icon, L
spl.Add(L"flags", flags);
// 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);
}
LONG32 request = DoRequest(Requests::RegisterW(), spl);
if (request > 0)
if (request > 0) {
appToken = request;
}
return request;
}
LONG32 SnarlInterface::RemoveClass(LPCSTR classId)
{
// 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);
}
LONG32 SnarlInterface::Unregister(LPCSTR signature)
{
// 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("callback", callback);
spl.Add("value", value);
if (timeout != -1) spl.Add("timeout", timeout);
if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority
if (timeout != -1) {
spl.Add("timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add("priority", priority); // -1 is a legal priority
}
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"callback", callback);
spl.Add(L"value", value);
if (timeout != -1) spl.Add(L"timeout", timeout);
if (priority != SnarlEnums::PriorityUndefined) spl.Add(L"priority", priority); // -1 is a legal priority
if (timeout != -1) {
spl.Add(L"timeout", timeout);
}
if (priority != SnarlEnums::PriorityUndefined) {
spl.Add(L"priority", priority); // -1 is a legal priority
}
return DoRequest(Requests::UpdateW(), spl);
}
@ -578,7 +586,6 @@ LONG32 SnarlInterface::UpdateApp(LPCWSTR title, LPCWSTR icon)
return DoRequest(Requests::UpdateAppW(), spl);
}*/
//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------
@ -588,19 +595,16 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char>& spl,
// <action>[?<data>=<value>[&<data>=<value>]]
const std::vector<SnarlParameterList<char>::PairType> &list = spl.GetList();
if (list.size() > 0)
{
if (list.size() > 0) {
std::string requestStr = request;
requestStr.append("?");
std::vector<SnarlParameterList<char>::PairType>::const_iterator listEnd = list.end(); // cend();
for (std::vector<SnarlParameterList<char>::PairType>::const_iterator iter = list.begin(); // cbegin();
iter != listEnd; ++iter)
{
iter != listEnd; ++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);
requestStr.append(iter->first).append("=").append(Escape(value));
requestStr.append("&");
@ -610,27 +614,24 @@ LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char>& spl,
requestStr.erase(requestStr.size() - 1);
return DoRequest(requestStr.c_str(), replyTimeout);
}
else
} else {
return DoRequest(request, replyTimeout);
}
}
LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t> &spl, UINT replyTimeout)
{
// <action>[?<data>=<value>[&<data>=<value>]]
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;
requestStr.append(L"?");
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();
iter != listEnd; ++iter)
{
if (iter->second.length() > 0)
{
iter != listEnd; ++iter) {
if (iter->second.length() > 0) {
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(L"&");
@ -640,16 +641,17 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& s
requestStr.erase(requestStr.size() - 1);
return DoRequest(requestStr.c_str(), replyTimeout);
}
else
} else {
return DoRequest(request, replyTimeout);
}
}
// Remember to delete [] returned string
LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr)
{
if (szWideStr == NULL)
if (szWideStr == NULL) {
return NULL;
}
int nSize = WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, NULL, 0, NULL, NULL);
LPSTR szUTF8 = new char[nSize];
@ -662,8 +664,7 @@ void SnarlInterface::SetPassword(LPCSTR password)
{
ClearPassword();
if (password != NULL)
{
if (password != NULL) {
int bufSize = (int)strlen(password) + 1;
szPasswordA = new char[bufSize];
szPasswordW = new wchar_t[bufSize];
@ -680,8 +681,7 @@ void SnarlInterface::SetPassword(LPCWSTR password)
{
ClearPassword();
if (password != NULL)
{
if (password != NULL) {
size_t bufSize = wcslen(password) + 1;
szPasswordW = new wchar_t[bufSize];
@ -702,6 +702,6 @@ void SnarlInterface::ClearPassword()
szPasswordW = NULL;
}
}} // namespace Snarl::V42
}
} // namespace Snarl::V42

View File

@ -11,14 +11,14 @@
#include <vector>
#include <sstream>
#ifndef SMTO_NOTIMEOUTIFNOTHUNG
#define SMTO_NOTIMEOUTIFNOTHUNG 8
#endif
namespace Snarl {
namespace V42 {
namespace Snarl
{
namespace V42
{
static LPCTSTR SnarlWindowClass = _T("w>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>
static const WPARAM AppDoAbout = 2;
// Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :(
namespace SnarlEnums {
namespace SnarlEnums
{
/// <summary>
/// Global event identifiers - sent as Windows broadcast messages.
/// These values appear in wParam of the message.
/// </summary>
enum GlobalEvent
{
enum GlobalEvent {
SnarlLaunched = 1, // Snarl has just started running
SnarlQuit = 2, // Snarl is about to stop running
SnarlGlobalStopped = 3, // Sent when stopped 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,
// 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
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!
ErrorCppInterface = 1001
};
@ -134,8 +131,7 @@ namespace Snarl {
/// The priority of messages.
/// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref>
/// </summary>
enum MessagePriority
{
enum MessagePriority {
PriorityUndefined = -2,
PriorityLow = -1,
PriorityNormal = 0,
@ -145,8 +141,7 @@ namespace Snarl {
/// <summary>
/// Application flags - features this app supports.
/// </summary>
enum AppFlags
{
enum AppFlags {
AppFlagNone = 0,
AppHasPrefs = 1,
AppHasAbout = 2,
@ -175,9 +170,10 @@ namespace Snarl {
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))); //
}
}
void Add(const T *_key, LONG32 _value)
{
@ -188,8 +184,7 @@ namespace Snarl {
void Add(const T *_key, void *_value)
{
if (_value != NULL)
{
if (_value != NULL) {
std::basic_stringstream<T> valStr;
valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex
@ -216,34 +211,118 @@ namespace Snarl {
class Requests
{
public:
static LPCSTR AddActionA() { return "addaction"; }
static LPCWSTR AddActionW() { return L"addaction"; }
static LPCSTR AddClassA() { return "addclass"; }
static LPCWSTR AddClassW() { return L"addclass"; }
static LPCSTR ClearActionsA() { return "clearactions"; }
static LPCWSTR ClearActionsW() { return L"clearactions"; }
static LPCSTR ClearClassesA() { return "clearclasses"; }
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"; }
static LPCSTR AddActionA()
{
return "addaction";
}
static LPCWSTR AddActionW()
{
return L"addaction";
}
static LPCSTR AddClassA()
{
return "addclass";
}
static LPCWSTR AddClassW()
{
return L"addclass";
}
static LPCSTR ClearActionsA()
{
return "clearactions";
}
static LPCWSTR ClearActionsW()
{
return L"clearactions";
}
static LPCSTR ClearClassesA()
{
return "clearclasses";
}
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();
@ -254,11 +333,28 @@ namespace Snarl {
// ------------------------------------------------------------------------------------
// Use FreeString, when SnarlInterface returns a null terminated string pointer
static LPTSTR AllocateString(size_t n) { return new TCHAR[n]; }
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; }
static LPTSTR AllocateString(size_t n)
{
return new TCHAR[n];
}
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>
/// <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>
static BOOL IsSnarlRunning();
// ------------------------------------------------------------------------------------
/// <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, LPCWSTR label, LPCWSTR cmd);
@ -380,7 +474,6 @@ namespace Snarl {
/*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL);
LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/
private:
/// <summary>Convert a unicode string to UTF8</summary>

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -22,8 +21,6 @@
#include "core/plugins/snorebackend.h"
#include "SnarlInterface.h"
class SnarlBackend: public Snore::SnoreBackend
{
Q_OBJECT
@ -51,5 +48,4 @@ private:
};
#endif // SNARL_BACKEND_H

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -28,9 +27,7 @@
#include <QtDeclarative>
#include <QPropertyAnimation>
typedef struct
{
typedef struct {
bool free;
QTime date;

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
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/>.
*/
#include "snorenotifier.h"
#include "notifywidget.h"
#include "core/notification/notification_p.h"
@ -37,8 +35,7 @@ SnoreNotifier::SnoreNotifier():
SnoreNotifier::~SnoreNotifier()
{
foreach (NotifyWidget *w, m_widgets)
{
foreach(NotifyWidget * w, m_widgets) {
w->deleteLater();
}
}
@ -46,40 +43,28 @@ SnoreNotifier::~SnoreNotifier()
void SnoreNotifier::slotNotify(Snore::Notification notification)
{
if(notification.isUpdate())
{
if(notification.old().hints().privateValue(this, "id").isValid())
{
if (notification.isUpdate()) {
if (notification.old().hints().privateValue(this, "id").isValid()) {
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();
w->update(notification);
notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification);
}
}
else
{
for(int i = 0; i < m_queue.length(); ++i)
{
} else {
for (int i = 0; i < m_queue.length(); ++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();
m_queue.replace(i, notification);
}
}
}
}
else
{
if(m_queue.isEmpty())
{
foreach (NotifyWidget *w, m_widgets)
{
if(w->acquire())
{
} else {
if (m_queue.isEmpty()) {
foreach(NotifyWidget * w, m_widgets) {
if (w->acquire()) {
w->display(notification);
notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification);
@ -100,7 +85,6 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
//the timer will show the next
}
void SnoreNotifier::slotDismissed()
{
NotifyWidget *widget = qobject_cast<NotifyWidget *>(sender());
@ -120,23 +104,17 @@ void SnoreNotifier::slotInvoked()
void SnoreNotifier::slotProcessQueue()
{
if(m_queue.isEmpty())
{
if (m_queue.isEmpty()) {
snoreDebug(SNORE_DEBUG) << "queue is empty";
m_timer->stop();
}
else
{
foreach (NotifyWidget *w, m_widgets)
{
if(w->acquire())
{
} else {
foreach(NotifyWidget * w, m_widgets) {
if (w->acquire()) {
Notification notification = m_queue.takeFirst();
w->display(notification);
notification.hints().setPrivateValue(this, "id", w->id());
startTimeout(notification);
if(m_queue.isEmpty())
{
if (m_queue.isEmpty()) {
m_timer->stop();
return;
}
@ -148,25 +126,21 @@ void SnoreNotifier::slotProcessQueue()
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);
m_widgets[i] = w;
connect(w, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
connect(w, SIGNAL(invoked()), this, SLOT(slotInvoked()));
}
m_timer = new QTimer(this);
m_timer->setInterval(500);
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessQueue()));
}
bool SnoreNotifier::initialize(SnoreCore *snore)
{
if(SnoreBackend::initialize(snore))
{
if (SnoreBackend::initialize(snore)) {
return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection);
}
return false;
@ -174,10 +148,8 @@ bool SnoreNotifier::initialize(SnoreCore *snore)
bool SnoreNotifier::deinitialize()
{
if(SnoreBackend::deinitialize())
{
for(int i=0;i<m_widgets.size();++i)
{
if (SnoreBackend::deinitialize()) {
for (int i = 0; i < m_widgets.size(); ++i) {
m_widgets[i]->release();
m_widgets[i]->deleteLater();
}

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -53,7 +52,6 @@ private:
QVector<NotifyWidget *> m_widgets;
QTimer *m_timer;
};
#endif // SNORENOTIFIER_H

View File

@ -15,7 +15,6 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(libsnore_backend_snoretoast, SnoreToast)
SnoreToast::SnoreToast():
SnoreBackend("Windows 8", true, false)
{
@ -28,15 +27,13 @@ SnoreToast::~SnoreToast()
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();
return false;
}
return SnoreBackend::initialize(snore);
}
void SnoreToast::slotNotify(Notification notification)
{
QProcess *p = new QProcess(this);
@ -50,8 +47,7 @@ void SnoreToast::slotNotify(Notification notification)
<< Snore::toPlainText(notification.title())
<< "-m"
<< Snore::toPlainText(notification.text());
if(notification.icon().isValid())
{
if (notification.icon().isValid()) {
arguements << "-p"
<< QDir::toNativeSeparators(notification.icon().localUrl());
}
@ -60,8 +56,7 @@ void SnoreToast::slotNotify(Notification notification)
<< appId(notification.application())
<< "-id"
<< QString::number(notification.id());
if(notification.hints().value("silent",true).toBool())
{
if (notification.hints().value("silent", true).toBool()) {
arguements << "-silent";
}
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;
@ -72,8 +67,7 @@ void SnoreToast::slotNotify(Notification notification)
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);
p->setReadChannelMode(QProcess::MergedChannels);
@ -109,16 +103,14 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{
QProcess *p = qobject_cast<QProcess *>(sender());
snoreDebug(SNORE_DEBUG) << p->readAll();
if(p->property("SNORE_NOTIFICATION_ID").isNull())
{
if (p->property("SNORE_NOTIFICATION_ID").isNull()) {
return;
}
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
Notification::CloseReasons reason = Notification::CLOSED;
switch(code)
{
switch (code) {
case 0:
reason = Notification::CLOSED;
snore()->d()->notificationActionInvoked(n);
@ -146,8 +138,7 @@ QString SnoreToast::appId(const Application &application)
{
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(" ");
}
return appID;

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -38,10 +37,10 @@ FreedesktopFrontend::FreedesktopFrontend():
SnoreFrontend("Freedesktop")
{
}
FreedesktopFrontend::~FreedesktopFrontend(){
FreedesktopFrontend::~FreedesktopFrontend()
{
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService("org.freedesktop.Notifications");
}
@ -51,8 +50,7 @@ bool FreedesktopFrontend::initialize(SnoreCore *snore)
m_adaptor = new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (dbus.registerService("org.freedesktop.Notifications") &&
dbus.registerObject( "/org/freedesktop/Notifications", this ))
{
dbus.registerObject("/org/freedesktop/Notifications", this)) {
return SnoreFrontend::initialize(snore);
}
return false;
@ -60,8 +58,7 @@ bool FreedesktopFrontend::initialize(SnoreCore *snore)
bool FreedesktopFrontend::deinitialize()
{
if(SnoreFrontend::deinitialize())
{
if (SnoreFrontend::deinitialize()) {
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService("org.freedesktop.Notifications");
dbus.unregisterObject("/org/freedesktop/Notifications");
@ -74,8 +71,7 @@ bool FreedesktopFrontend::deinitialize()
void FreedesktopFrontend::actionInvoked(Notification notification)
{
if(notification.actionInvoked().isValid())
{
if (notification.actionInvoked().isValid()) {
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;
Notification::Prioritys priotity = Notification::NORMAL;
if(hints.contains("image_data"))
{
if (hints.contains("image_data")) {
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>() >> image;
icon = Icon(image.toQImage());
}
else
{
} else {
icon = Icon(":/root/snore.png");
}
if(!snore()->aplications().contains(app_name))
{
if (!snore()->aplications().contains(app_name)) {
qDebug() << QIcon::themeSearchPaths();
QIcon qicon = QIcon::fromTheme(app_icon, QIcon(":/root/snore.png"));
QSize max;
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;
}
}
@ -120,29 +111,22 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
app = Application(app_name, appIcon);
app.addAlert(alert);
snore()->registerApplication(app);
}
else
{
} else {
app = snore()->aplications()[app_name];
}
if (hints.contains("urgency"))
{
if (hints.contains("urgency")) {
priotity = Notification::Prioritys(hints["urgency"].toInt() - 1);
}
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);
}
else
{
} else {
noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
}
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)));
}
@ -150,13 +134,10 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
return noti.id();
}
void FreedesktopFrontend::CloseNotification(uint id)
{
Notification noti = snore()->getActiveNotificationByID(id);
if(noti.isValid())
{
if (noti.isValid()) {
snore()->requestCloseNotification(noti, Notification::TIMED_OUT);
}
}

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -53,7 +52,6 @@ private:
Snore::Icon m_icon;
NotificationsAdaptor *m_adaptor;
};
#endif//FREEDESKTOPNOTIFICATION_FRONTEND_H

View File

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

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -25,8 +24,6 @@
#include <QSharedPointer>
#include <QObject>
class Parser : public QObject
{
Q_OBJECT

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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)
SnarlNetworkFrontend::SnarlNetworkFrontend():
SnoreFrontend("SnarlNetwork")
{
}
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
SnarlNetworkFrontend::~SnarlNetworkFrontend()
{
}
bool SnarlNetworkFrontend::initialize(SnoreCore *snore)
{
parser = new Parser(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";
return false;
}
else
{
} else {
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
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()
{
if(SnoreFrontend::deinitialize())
{
if (SnoreFrontend::deinitialize()) {
parser->deleteLater();
parser = NULL;
@ -70,7 +65,6 @@ bool SnarlNetworkFrontend::deinitialize()
return false;
}
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
{
snoreDebug(SNORE_DEBUG) << notification.closeReason();
@ -79,8 +73,7 @@ void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification)
{
switch(notification.closeReason())
{
switch (notification.closeReason()) {
case Notification::TIMED_OUT:
callback(notification, "SNP/1.1/303/Notification timed out/");
break;
@ -106,21 +99,16 @@ void SnarlNetworkFrontend::handleMessages()
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
QStringList messages(QString::fromAscii(client->readAll()).trimmed().split("\r\n"));
foreach(const QString &s, messages)
{
if(s.isEmpty())
{
foreach(const QString & s, messages) {
if (s.isEmpty()) {
continue;
}
Notification noti;
parser->parse(noti, s, client);
if(noti.isValid())
{
if (noti.isValid()) {
snore()->broadcastNotification(noti);
write(client, QString("%1/%2\r\n").arg(out, QString::number(noti.id())));
}
else
{
} else {
write(client, QString("%1\r\n").arg(out));
}
}
@ -128,8 +116,7 @@ void SnarlNetworkFrontend::handleMessages()
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 *>());
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
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -27,7 +26,6 @@
#include <QTcpSocket>
#include <QTcpServer>
class SnarlNetworkFrontend : public Snore::SnoreFrontend
{
Q_OBJECT

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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();
}
SnoreNotify::~SnoreNotify(){
SnoreNotify::~SnoreNotify()
{
delete m_snore;
delete m_trayIcon;
}
@ -55,26 +55,23 @@ SnoreNotify::~SnoreNotify(){
void SnoreNotify::load()
{
QString backend = m_settings.value("notificationBackend").toString();
if(!backend.isEmpty())
{
if(!m_snore->setPrimaryNotificationBackend(backend))
{
if (!backend.isEmpty()) {
if (!m_snore->setPrimaryNotificationBackend(backend)) {
m_snore->setPrimaryNotificationBackend();
}
} else {
m_snore->setPrimaryNotificationBackend();
}
}
else
void SnoreNotify::save()
{
m_snore->setPrimaryNotificationBackend();
}
}
void SnoreNotify::save(){
m_settings.setValue("notificationBackend", m_snore->primaryNotificationBackend());
}
void SnoreNotify::exit(){
snoreDebug( SNORE_DEBUG )<<"Saving snore settings";
foreach(const Application &a,m_snore->aplications())
void SnoreNotify::exit()
{
snoreDebug(SNORE_DEBUG) << "Saving snore settings";
foreach(const Application & a, m_snore->aplications()) {
m_snore->deregisterApplication(a);
}
save();

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -22,7 +21,8 @@
#include <QtCore>
namespace Snore{
namespace Snore
{
class SnoreCore;
}

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
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");
QString version = QString("SnoreNotify %1").arg(Version::version());
if(Version::revision() != "")
{
if (Version::revision() != "") {
version += QString("-%1").arg(Version::revision());
}
m_trayMenu->addAction(version);
@ -54,12 +52,10 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
m_trayMenu->addSeparator();
m_backendActions = new QActionGroup(m_trayMenu);
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()));
b->setCheckable(true);
if(back == m_snore->primaryNotificationBackend())
{
if (back == m_snore->primaryNotificationBackend()) {
b->setChecked(true);
}
m_backendActions->addAction(b);
@ -67,7 +63,6 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
m_trayMenu->addSeparator();
m_trayMenu->addAction("Exit", qApp, SLOT(quit()));
m_trayIcon->setContextMenu(m_trayMenu);
}
@ -81,14 +76,13 @@ QSystemTrayIcon* TrayIcon::trayIcon()
return m_trayIcon;
}
void TrayIcon::setPrimaryBackend(){
void TrayIcon::setPrimaryBackend()
{
QAction *a = qobject_cast<QAction *>(sender());
m_snore->setPrimaryNotificationBackend(a->text());
foreach (QAction *action, m_backendActions->actions())
{
if(action->text() == m_snore->primaryNotificationBackend())
{
foreach(QAction * action, m_backendActions->actions()) {
if (action->text() == m_snore->primaryNotificationBackend()) {
action->setChecked(true);
break;
}
@ -98,8 +92,7 @@ void TrayIcon::setPrimaryBackend(){
void TrayIcon::slotTestNotification()
{
if(!m_snore->aplications().contains(m_app.name()))
{
if (!m_snore->aplications().contains(m_app.name())) {
m_snore->registerApplication(m_app);
}
Notification noti(m_app, m_alert, "Hello World",

View File

@ -2,7 +2,6 @@
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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
the Free Software Foundation, either version 3 of the License, or
@ -24,7 +23,6 @@
#include <QAction>
#include "core/snore.h"
class TrayIcon: public QObject
{
Q_OBJECT
@ -44,7 +42,6 @@ private:
QHash<QTimer *, Snore::Notification> m_notifications;
public slots:
void setPrimaryBackend();
void slotTestNotification();