style fixes, kde-dev-scripts/astyle-kdelibs

This commit is contained in:
Patrick von Reth 2015-07-03 11:43:18 +02:00
parent 1dbc3e4710
commit 09620f66f0
31 changed files with 183 additions and 214 deletions

View File

@ -11,47 +11,46 @@
using namespace Snore; using namespace Snore;
class SnoreBenchmark : public QObject
class SnoreBenchmark : public QObject{ {
Q_OBJECT Q_OBJECT
public: public:
SnoreBenchmark(){ SnoreBenchmark()
{
SnoreCore::instance(); SnoreCore::instance();
} }
QString htmlTestString = QLatin1String("<i>Italic A</i><br>" QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
"<i>Italic B</i><br>" "<i>Italic B</i><br>"
"<b>Bold</b><br>" "<b>Bold</b><br>"
"<u>Underline</u><br>" "<u>Underline</u><br>"
"<font color=\"blue\">Font</font><br>" "<font color=\"blue\">Font</font><br>"
"&lt;&amp;&gt;<br>" "&lt;&amp;&gt;<br>"
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>"); "<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>");
private Q_SLOTS: private Q_SLOTS:
void benchmarkUtilsToHtml(); void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup(); void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain(); void benchmarkUtilsToPlain();
}; };
void SnoreBenchmark::benchmarkUtilsToHtml()
void SnoreBenchmark::benchmarkUtilsToHtml(){ {
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n" QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n"
"Italic B\n" "Italic B\n"
"Bold\n" "Bold\n"
"Underline\n" "Underline\n"
"Font\n" "Font\n"
"<&>\n" "<&>\n"
"Website\n")); "Website\n"));
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF), QLatin1String("Italic A\n" QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF), QLatin1String("Italic A\n"
"Italic B\n" "Italic B\n"
"Bold\n" "Bold\n"
"Underline\n" "Underline\n"
"Font\n" "Font\n"
"&lt;&amp;&gt;\n" "&lt;&amp;&gt;\n"
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a>\n")); "<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a>\n"));
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF | Utils::BOLD | Utils::BREAK | QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF | Utils::BOLD | Utils::BREAK |
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC), htmlTestString); Utils::UNDERLINE | Utils::FONT | Utils::ITALIC), htmlTestString);
QBENCHMARK{ QBENCHMARK{

View File

@ -92,7 +92,7 @@ QDebug operator<< (QDebug debug, const Snore::Application &app)
{ {
if (app.isValid()) { if (app.isValid()) {
debug << "Snore::Application(" << app.name() << ", "; debug << "Snore::Application(" << app.name() << ", ";
foreach(const Alert & a, app.alerts()) { foreach (const Alert &a, app.alerts()) {
debug << a << ", "; debug << a << ", ";
} }
debug << ")" ; debug << ")" ;

View File

@ -24,7 +24,7 @@ Hint::Hint()
{ {
} }
void Hint::setValue(const QByteArray & key, const QVariant &value) void Hint::setValue(const QByteArray &key, const QVariant &value)
{ {
m_data.insert(key, value); m_data.insert(key, value);
} }
@ -34,34 +34,34 @@ QVariant Hint::value(const QByteArray &key) const
return m_data.value(key); return m_data.value(key);
} }
QVariant Hint::take(const QByteArray & key) QVariant Hint::take(const QByteArray &key)
{ {
return m_data.take(key); return m_data.take(key);
} }
bool Hint::contains(const QByteArray & key) const bool Hint::contains(const QByteArray &key) const
{ {
return m_data.contains(key); return m_data.contains(key);
} }
void Hint::setPrivateValue(const void *owner, const QByteArray & key, const QVariant &value) void Hint::setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value)
{ {
m_privateData.insert(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key), value); m_privateData.insert(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key), value);
} }
QVariant Hint::privateValue(const void *owner, const QByteArray &key) const QVariant Hint::privateValue(const void *owner, const QByteArray &key) const
{ {
return m_privateData.value(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key)); return m_privateData.value(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
} }
bool Hint::containsPrivateValue(const void *owner, const QByteArray & key) const bool Hint::containsPrivateValue(const void *owner, const QByteArray &key) const
{ {
return m_privateData.contains(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key)); return m_privateData.contains(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
} }
QVariant Hint::takePrivateValue(const void *owner, const QByteArray & key) QVariant Hint::takePrivateValue(const void *owner, const QByteArray &key)
{ {
return m_privateData.take(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key)); return m_privateData.take(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
} }
QDebug operator<<(QDebug debug, const Snore::Hint &hint) QDebug operator<<(QDebug debug, const Snore::Hint &hint)
@ -72,7 +72,7 @@ QDebug operator<<(QDebug debug, const Snore::Hint &hint)
debug << "(" << it.key() << ", " << it.value(); debug << "(" << it.key() << ", " << it.value();
} }
for (auto it = hint.m_privateData.cbegin(); it != hint.m_privateData.cend(); ++it) { for (auto it = hint.m_privateData.cbegin(); it != hint.m_privateData.cend(); ++it) {
debug << ", "; debug << ", ";
debug << "(" << it.key() << ", " << it.value(); debug << "(" << it.key() << ", " << it.value();
} }
debug << ")" ; debug << ")" ;

View File

@ -48,28 +48,26 @@ public:
* @param key the key * @param key the key
* @param value the value * @param value the value
*/ */
void setValue(const QByteArray & key, const QVariant &value); void setValue(const QByteArray &key, const QVariant &value);
/** /**
* The associated value of the key. * The associated value of the key.
* @param key the key * @param key the key
*/ */
QVariant value(const QByteArray & key) const; QVariant value(const QByteArray &key) const;
/** /**
* The associated value of the key. * The associated value of the key.
* @param key the key * @param key the key
*/ */
QVariant take(const QByteArray & key); QVariant take(const QByteArray &key);
/** /**
* *
* @param key the key * @param key the key
* @return whether the key is set * @return whether the key is set
*/ */
bool contains(const QByteArray & key) const; bool contains(const QByteArray &key) const;
/** /**
* Sets the value for the key depending on the owner * Sets the value for the key depending on the owner
@ -77,14 +75,14 @@ public:
* @param key the key * @param key the key
* @param value the value * @param value the value
*/ */
void setPrivateValue(const void *owner, const QByteArray & key, const QVariant &value); void setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value);
/** /**
* The associated value of the key if present. * The associated value of the key if present.
* @param owner the owner * @param owner the owner
* @param key the key * @param key the key
*/ */
QVariant privateValue(const void *owner, const QByteArray & key) const; QVariant privateValue(const void *owner, const QByteArray &key) const;
/** /**
* *
@ -92,7 +90,7 @@ public:
* @param key the key * @param key the key
* @return whether the key is set * @return whether the key is set
*/ */
bool containsPrivateValue(const void *owner, const QByteArray & key) const; bool containsPrivateValue(const void *owner, const QByteArray &key) const;
/** /**
* The associated value of the key if present. * The associated value of the key if present.

View File

@ -37,8 +37,8 @@ static void init()
if (qgetenv("LIBSNORE_LOG_TO_FILE").toInt() == 1) { if (qgetenv("LIBSNORE_LOG_TO_FILE").toInt() == 1) {
QString name = QDir::tempPath() + QLatin1String("/libsnore/") + QString name = QDir::tempPath() + QLatin1String("/libsnore/") +
(qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName()) + (qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName()) +
QLatin1String("-log.txt"); QLatin1String("-log.txt");
if (!qgetenv("LIBSNORE_LOGFILE").isNull()) { if (!qgetenv("LIBSNORE_LOGFILE").isNull()) {
name = QString::fromUtf8(qgetenv("LIBSNORE_LOGFILE")); name = QString::fromUtf8(qgetenv("LIBSNORE_LOGFILE"));
} else { } else {

View File

@ -94,8 +94,8 @@ void NotificationData::setTimeoutTimer(QTimer *timer)
QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags) QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags)
{ {
if(!m_hints.value("use-markup").toBool()) { if (!m_hints.value("use-markup").toBool()) {
if(flags == Utils::NO_MARKUP){ if (flags == Utils::NO_MARKUP) {
return string; return string;
} else { } else {
return Utils::normalizeMarkup(string.toHtmlEscaped(), flags); return Utils::normalizeMarkup(string.toHtmlEscaped(), flags);

View File

@ -87,15 +87,15 @@ void PluginContainer::updatePluginCache()
{ {
snoreDebug(SNORE_DEBUG) << "Updating plugin cache"; snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
for (auto list : s_pluginCache) { for (auto list : s_pluginCache) {
foreach(PluginContainer * p, list.values()) { foreach (PluginContainer *p, list.values()) {
delete p; delete p;
} }
list.clear(); list.clear();
} }
foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) { foreach (const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
foreach(const QFileInfo & file, pluginDir().entryInfoList( foreach (const QFileInfo &file, pluginDir().entryInfoList(
QStringList(pluginFileFilters(type)), QDir::Files)) { QStringList(pluginFileFilters(type)), QDir::Files)) {
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath(); snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath()); QPluginLoader loader(file.absoluteFilePath());
QJsonObject data = loader.metaData()[QLatin1String("MetaData")].toObject(); QJsonObject data = loader.metaData()[QLatin1String("MetaData")].toObject();
@ -152,7 +152,7 @@ const QDir &PluginContainer::pluginDir()
<< appDir + suffix << appDir + suffix
<< appDir + QLatin1String("/../lib/plugins") + suffix << appDir + QLatin1String("/../lib/plugins") + suffix
<< appDir + QLatin1String("/../lib64/plugins") + suffix; << appDir + QLatin1String("/../lib64/plugins") + suffix;
for(const QString & p : list) { for (const QString &p : list) {
path = QDir(p); path = QDir(p);
if (!path.entryInfoList(pluginFileFilters()).isEmpty()) { if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {

View File

@ -68,7 +68,7 @@ private:
static inline const QStringList pluginFileFilters() static inline const QStringList pluginFileFilters()
{ {
QStringList out; QStringList out;
for(const QString &extention : pluginExtentions()) { for (const QString &extention : pluginExtentions()) {
out << QString(QLatin1String("libsnore_*.%1")).arg(extention); out << QString(QLatin1String("libsnore_*.%1")).arg(extention);
} }
return out; return out;
@ -77,7 +77,7 @@ private:
static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type) static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type)
{ {
QStringList out; QStringList out;
for(const QString &extention : pluginExtentions()) { for (const QString &extention : pluginExtentions()) {
out << QString(QLatin1String("libsnore_%1_*.%2")).arg(SnorePlugin::typeToString(type).toLower(), extention); out << QString(QLatin1String("libsnore_%1_*.%2")).arg(SnorePlugin::typeToString(type).toLower(), extention);
} }
return out; return out;

View File

@ -53,7 +53,6 @@ public:
SnorePlugin(); SnorePlugin();
virtual ~SnorePlugin(); virtual ~SnorePlugin();
// TODO: remove need of recursive calling of parent methode.... // TODO: remove need of recursive calling of parent methode....
virtual bool initialize(); virtual bool initialize();
virtual bool deinitialize(); virtual bool deinitialize();

View File

@ -57,7 +57,6 @@ protected Q_SLOTS:
protected: protected:
void closeNotification(Snore::Notification, Snore::Notification::CloseReasons); void closeNotification(Snore::Notification, Snore::Notification::CloseReasons);
}; };
} }

View File

@ -46,7 +46,7 @@ SnoreCore::SnoreCore(QObject *parent):
SnoreCore &SnoreCore::instance() SnoreCore &SnoreCore::instance()
{ {
static SnoreCore *instance = nullptr; static SnoreCore *instance = nullptr;
if(!instance){ if (!instance) {
instance = new SnoreCore(qApp); instance = new SnoreCore(qApp);
SnoreCorePrivate::instance()->init(); SnoreCorePrivate::instance()->init();
} }
@ -91,7 +91,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
} }
} }
} }
break; break;
default: default:
snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type(); snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type();
continue; continue;
@ -207,8 +207,8 @@ QVariant SnoreCore::settingsValue(const QString &key, SettingsType type) const
{ {
Q_D(const SnoreCore); Q_D(const SnoreCore);
QString nk = d->normalizeSettingsKey(key, type); QString nk = d->normalizeSettingsKey(key, type);
if(type == LOCAL_SETTING && !d->m_settings->contains(nk)){ if (type == LOCAL_SETTING && !d->m_settings->contains(nk)) {
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"),type); nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"), type);
} }
return d->m_settings->value(nk); return d->m_settings->value(nk);
} }
@ -235,13 +235,12 @@ Notification SnoreCore::getActiveNotificationByID(uint id) const
return d->m_activeNotifications.value(id); return d->m_activeNotifications.value(id);
} }
void SnoreCore::displayExapleNotification() void SnoreCore::displayExapleNotification()
{ {
Application app = SnoreCorePrivate::instance()->defaultApplication(); Application app = SnoreCorePrivate::instance()->defaultApplication();
QString text = QLatin1String("<i>") + tr("This is Snore") + QLatin1String("</i><br>") + QString text = QLatin1String("<i>") + tr("This is Snore") + QLatin1String("</i><br>") +
QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>"); QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>");
if(!app.constHints().value("use-markup").toBool()) { if (!app.constHints().value("use-markup").toBool()) {
text = Utils::normalizeMarkup(text, Utils::NO_MARKUP); text = Utils::normalizeMarkup(text, Utils::NO_MARKUP);
} }
Notification noti(app, app.defaultAlert(), tr("Hello World"), text, app.icon()); Notification noti(app, app.defaultAlert(), tr("Hello World"), text, app.icon());

View File

@ -148,7 +148,7 @@ void SnoreCorePrivate::init()
void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const QVariant &value) void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const QVariant &value)
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);
QString nk = normalizeSettingsKey( key + QLatin1String("-SnoreDefault"), LOCAL_SETTING); QString nk = normalizeSettingsKey(key + QLatin1String("-SnoreDefault"), LOCAL_SETTING);
if (!m_settings->contains(nk)) { if (!m_settings->contains(nk)) {
m_settings->setValue(nk, value); m_settings->setValue(nk, value);
} }
@ -173,7 +173,7 @@ void SnoreCorePrivate::syncSettings()
auto types = SnorePlugin::types(); auto types = SnorePlugin::types();
types.removeOne(SnorePlugin::BACKEND); types.removeOne(SnorePlugin::BACKEND);
for(auto type : types) { for (auto type : types) {
for (auto &pluginName : m_pluginNames[type]) { for (auto &pluginName : m_pluginNames[type]) {
SnorePlugin *plugin = m_plugins.value(pluginName); SnorePlugin *plugin = m_plugins.value(pluginName);
bool enable = m_plugins[pluginName]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool(); bool enable = m_plugins[pluginName]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool();
@ -262,11 +262,11 @@ static void registerMetaTypes()
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>(); qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
} }
static void snoreStartup(){ static void snoreStartup()
{
loadTranslator(); loadTranslator();
registerMetaTypes(); registerMetaTypes();
} }
Q_COREAPP_STARTUP_FUNCTION(snoreStartup) Q_COREAPP_STARTUP_FUNCTION(snoreStartup)

View File

@ -71,57 +71,55 @@ void Utils::raiseWindowToFront(qlonglong wid)
#endif #endif
} }
#define HTML_REPLACE(STRING, PATTERN){\ #define HTML_REPLACE(STRING, PATTERN){\
static QRegExp regexp(QLatin1String(PATTERN));\ static QRegExp regexp(QLatin1String(PATTERN));\
STRING = STRING.replace(regexp, QLatin1String("\\1"));\ STRING = STRING.replace(regexp, QLatin1String("\\1"));\
}\ }\
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
{
static QMutex mutex;
if (tags == ALL_MARKUP) {
return string;
} else if (tags == NO_MARKUP) {
return QTextDocumentFragment::fromHtml(string).toPlainText();
}
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags) QMutexLocker lock(&mutex);
{ if (~tags & Utils::BREAK) {
static QMutex mutex; static QRegExp br(QLatin1String("<br>"));
if(tags == ALL_MARKUP){ string = string.replace(br, QLatin1String("\n"));
}
if (~tags & Utils::HREF) {
HTML_REPLACE(string, "<a href=.*>([^<]*)</a>");
}
if (~tags & Utils::ITALIC) {
HTML_REPLACE(string, "<i>([^<]*)</i>");
}
if (~tags & Utils::BOLD) {
HTML_REPLACE(string, "<b>([^<]*)</b>");
}
if (~tags & Utils::UNDERLINE) {
HTML_REPLACE(string, "<u>([^<]*)</u>");
}
if (~tags & Utils::FONT) {
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
}
return string; return string;
} else if(tags == NO_MARKUP) {
return QTextDocumentFragment::fromHtml(string).toPlainText();
} }
QMutexLocker lock(&mutex);
if (~tags & Utils::BREAK) {
static QRegExp br(QLatin1String("<br>"));
string = string.replace(br, QLatin1String("\n"));
}
if (~tags & Utils::HREF) {
HTML_REPLACE(string, "<a href=.*>([^<]*)</a>");
}
if (~tags & Utils::ITALIC) {
HTML_REPLACE(string, "<i>([^<]*)</i>");
}
if (~tags & Utils::BOLD) {
HTML_REPLACE(string, "<b>([^<]*)</b>");
}
if (~tags & Utils::UNDERLINE) {
HTML_REPLACE(string, "<u>([^<]*)</u>");
}
if (~tags & Utils::FONT) {
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
}
return string;
}
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
int Utils::attatchToActiveProcess() int Utils::attatchToActiveProcess()
{ {
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL); int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1; return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
} }
void Utils::detatchActiveProcess(int idActive) void Utils::detatchActiveProcess(int idActive)
{ {
if (idActive != -1) { if (idActive != -1) {
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE); AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
}
} }
}
#endif #endif

View File

@ -31,7 +31,7 @@ class SNORE_EXPORT Utils : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum MARKUP_FLAG{ enum MARKUP_FLAG {
NO_MARKUP = 0, NO_MARKUP = 0,
HREF = 1 << 0, HREF = 1 << 0,
BREAK = 1 << 1, BREAK = 1 << 1,
@ -42,7 +42,7 @@ public:
ALL_MARKUP = ~0 ALL_MARKUP = ~0
}; };
Q_DECLARE_FLAGS(MARKUP_FLAGS,MARKUP_FLAG) Q_DECLARE_FLAGS(MARKUP_FLAGS, MARKUP_FLAG)
Utils(QObject *parent = nullptr); Utils(QObject *parent = nullptr);
~Utils(); ~Utils();

View File

@ -23,7 +23,6 @@
int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>(); int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
FreedesktopImageHint::FreedesktopImageHint(const QImage &img) FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
{ {
QImage image(img.convertToFormat(QImage::Format_ARGB32)); QImage image(img.convertToFormat(QImage::Format_ARGB32));

View File

@ -14,7 +14,7 @@ bool FreedesktopBackend::initialize()
{ {
m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"), m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"),
QLatin1String("/org/freedesktop/Notifications"), QLatin1String("/org/freedesktop/Notifications"),
QDBusConnection::sessionBus(), this); QDBusConnection::sessionBus(), this);
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities(); QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
@ -53,7 +53,7 @@ bool FreedesktopBackend::canUpdateNotification() const
void FreedesktopBackend::slotNotify(Notification noti) void FreedesktopBackend::slotNotify(Notification noti)
{ {
QStringList actions; QStringList actions;
foreach(int k, noti.actions().keys()) { foreach (int k, noti.actions().keys()) {
actions << QString::number(k) << noti.actions()[k].name(); actions << QString::number(k) << noti.actions()[k].name();
} }
QVariantMap hints; QVariantMap hints;
@ -61,13 +61,13 @@ void FreedesktopBackend::slotNotify(Notification noti)
FreedesktopImageHint image(noti.icon().image()); FreedesktopImageHint image(noti.icon().image());
hints.insert(QLatin1String("image_data"), QVariant::fromValue(image)); hints.insert(QLatin1String("image_data"), QVariant::fromValue(image));
} }
char urgency = '1'; char urgency = '1';
if(noti.priority() < 0){ if (noti.priority() < 0) {
urgency = '0'; urgency = '0';
} else if(noti.priority() > 2) { } else if (noti.priority() > 2) {
urgency = '2'; urgency = '2';
} }
hints.insert(QLatin1String("urgency"), urgency); hints.insert(QLatin1String("urgency"), urgency);
if (noti.application().constHints().contains("desktop-entry")) { if (noti.application().constHints().contains("desktop-entry")) {

View File

@ -29,13 +29,12 @@ using namespace Snore;
GrowlBackend *GrowlBackend::s_instance = nullptr; GrowlBackend *GrowlBackend::s_instance = nullptr;
bool GrowlBackend::initialize() bool GrowlBackend::initialize()
{ {
setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost")); setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost"));
setDefaultSettingsValue(QLatin1String("Password"), QString()); setDefaultSettingsValue(QLatin1String("Password"), QString());
if(!SnoreBackend::initialize()) { if (!SnoreBackend::initialize()) {
return false; return false;
} }
@ -80,9 +79,9 @@ bool GrowlBackend::deinitialize()
void GrowlBackend::slotRegisterApplication(const Application &application) void GrowlBackend::slotRegisterApplication(const Application &application)
{ {
snoreDebug( SNORE_DEBUG ) << application.name(); snoreDebug(SNORE_DEBUG) << application.name();
std::vector<std::string> alerts; std::vector<std::string> alerts;
foreach(const Alert & a, application.alerts()) { foreach (const Alert &a, application.alerts()) {
snoreDebug(SNORE_DEBUG) << a.name(); snoreDebug(SNORE_DEBUG) << a.name();
alerts.push_back(a.name().toUtf8().constData()); alerts.push_back(a.name().toUtf8().constData());
} }

View File

@ -115,7 +115,7 @@ bool SnarlBackend::initialize()
{ {
setDefaultSettingsValue(QLatin1String("Password"), QString()); setDefaultSettingsValue(QLatin1String("Password"), QString());
if(!SnoreBackend::initialize()) { if (!SnoreBackend::initialize()) {
return false; return false;
} }
@ -176,7 +176,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID); (HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
snoreDebug(SNORE_DEBUG) << result; snoreDebug(SNORE_DEBUG) << result;
foreach(const Alert & alert, application.alerts()) { foreach (const Alert &alert, application.alerts()) {
snarlInterface->AddClass(alert.name().toUtf8().constData(), snarlInterface->AddClass(alert.name().toUtf8().constData(),
alert.name().toUtf8().constData(), alert.name().toUtf8().constData(),
0, 0, alert.icon().localUrl().toUtf8().constData()); 0, 0, alert.icon().localUrl().toUtf8().constData());
@ -205,11 +205,11 @@ void SnarlBackend::slotNotify(Notification notification)
SnarlInterface *snarlInterface = m_applications.value(notification.application().name()); SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined; Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
if(notification.priority() > 1){ if (notification.priority() > 1) {
priority = Snarl::V42::SnarlEnums::PriorityHigh; priority = Snarl::V42::SnarlEnums::PriorityHigh;
} else if(notification.priority() < -1) { } else if (notification.priority() < -1) {
priority = Snarl::V42::SnarlEnums::PriorityLow; priority = Snarl::V42::SnarlEnums::PriorityLow;
}else{ } else {
priority = static_cast<Snarl::V42::SnarlEnums::MessagePriority>(notification.priority()); priority = static_cast<Snarl::V42::SnarlEnums::MessagePriority>(notification.priority());
} }
@ -225,7 +225,7 @@ void SnarlBackend::slotNotify(Notification notification)
!notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0,
priority); priority);
foreach(const Action & a, notification.actions()) { foreach (const Action &a, notification.actions()) {
snarlInterface->AddAction(id, a.name().toUtf8().constData(), (QLatin1Char('@') + QString::number(a.id())).toUtf8().constData()); snarlInterface->AddAction(id, a.name().toUtf8().constData(), (QLatin1Char('@') + QString::number(a.id())).toUtf8().constData());
} }
m_idMap[id] = notification; m_idMap[id] = notification;

View File

@ -36,7 +36,7 @@ SnoreNotifier::SnoreNotifier():
snoreDebug(SNORE_DEBUG) << "queue is empty"; snoreDebug(SNORE_DEBUG) << "queue is empty";
m_timer->stop(); m_timer->stop();
} else { } else {
for(NotifyWidget * w : m_widgets) { for (NotifyWidget *w : m_widgets) {
if (w->acquire()) { if (w->acquire()) {
Notification notification = m_queue.takeFirst(); Notification notification = m_queue.takeFirst();
w->display(notification); w->display(notification);
@ -86,7 +86,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
} }
} else { } else {
if (m_queue.isEmpty()) { if (m_queue.isEmpty()) {
for(NotifyWidget * w : m_widgets) { for (NotifyWidget *w : m_widgets) {
if (w->acquire()) { if (w->acquire()) {
display(w, notification); display(w, notification);
return; return;

View File

@ -16,7 +16,7 @@ using namespace Snore;
bool SnoreToast::initialize() bool SnoreToast::initialize()
{ {
if(!SnoreBackend::initialize()) { if (!SnoreBackend::initialize()) {
return false; return false;
} }
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) { if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {

View File

@ -6,7 +6,6 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
using namespace Snore; using namespace Snore;
bool TrayIconNotifer::deinitialize() bool TrayIconNotifer::deinitialize()
{ {
if (SnoreBackend::deinitialize()) { if (SnoreBackend::deinitialize()) {

View File

@ -32,7 +32,7 @@ using namespace Snore;
bool FreedesktopFrontend::initialize() bool FreedesktopFrontend::initialize()
{ {
if(!SnoreFrontend::initialize()) { if (!SnoreFrontend::initialize()) {
return false; return false;
} }
m_adaptor = new NotificationsAdaptor(this); m_adaptor = new NotificationsAdaptor(this);
@ -99,7 +99,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
qDebug() << QIcon::themeSearchPaths(); qDebug() << QIcon::themeSearchPaths();
QIcon qicon = QIcon::fromTheme(app_icon, QIcon(QLatin1String(":/root/snore.png"))); QIcon qicon = QIcon::fromTheme(app_icon, QIcon(QLatin1String(":/root/snore.png")));
QSize max; QSize max;
foreach(const QSize & s, qicon.availableSizes()) { foreach (const QSize &s, qicon.availableSizes()) {
if (s.width()*s.height() > max.width()*max.height()) { if (s.width()*s.height() > max.width()*max.height()) {
max = s; max = s;
} }

View File

@ -23,7 +23,6 @@
#include "libsnore/version.h" #include "libsnore/version.h"
#include "libsnore/notification/notification_p.h" #include "libsnore/notification/notification_p.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QHttpMultiPart> #include <QHttpMultiPart>
#include <QNetworkReply> #include <QNetworkReply>
@ -32,7 +31,6 @@
#include <QJsonArray> #include <QJsonArray>
#include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocket>
using namespace Snore; using namespace Snore;
// TODO: use qtkeychain to encrypt credentials? // TODO: use qtkeychain to encrypt credentials?
@ -40,11 +38,11 @@ using namespace Snore;
PushoverFrontend::PushoverFrontend() PushoverFrontend::PushoverFrontend()
{ {
connect(this, &PushoverFrontend::loggedInChanged, [this](bool state){ connect(this, &PushoverFrontend::loggedInChanged, [this](bool state) {
m_loggedIn = state; m_loggedIn = state;
}); });
connect(this, &PushoverFrontend::error, [this](QString error){ connect(this, &PushoverFrontend::error, [this](QString error) {
m_errorMessage = error; m_errorMessage = error;
}); });
} }
@ -53,7 +51,7 @@ bool PushoverFrontend::initialize()
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING); setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING); setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
if(!SnoreFrontend::initialize()) { if (!SnoreFrontend::initialize()) {
return false; return false;
} }
@ -65,7 +63,7 @@ bool PushoverFrontend::initialize()
bool PushoverFrontend::deinitialize() bool PushoverFrontend::deinitialize()
{ {
if (SnoreFrontend::deinitialize()) { if (SnoreFrontend::deinitialize()) {
if(m_socket) { if (m_socket) {
m_socket->close(); m_socket->close();
m_socket->deleteLater(); m_socket->deleteLater();
} }
@ -88,20 +86,17 @@ void PushoverFrontend::login(const QString &email, const QString &password, cons
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded"))); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QNetworkReply *reply = m_manager.post(request, QString(QLatin1String("email=%1&password=%2")).arg(email, password).toUtf8().constData()); QNetworkReply *reply = m_manager.post(request, QString(QLatin1String("email=%1&password=%2")).arg(email, password).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() { connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll(); QByteArray input = reply->readAll();
reply->close(); reply->close();
reply->deleteLater(); reply->deleteLater();
QJsonObject message = QJsonDocument::fromJson(input).object(); QJsonObject message = QJsonDocument::fromJson(input).object();
if(message.value(QLatin1String("status")).toInt() == 1) if (message.value(QLatin1String("status")).toInt() == 1) {
{
registerDevice(message.value(QLatin1String("secret")).toString(), deviceName); registerDevice(message.value(QLatin1String("secret")).toString(), deviceName);
}else { } else {
snoreDebug(SNORE_WARNING) << "An error occure" << input; snoreDebug(SNORE_WARNING) << "An error occure" << input;
emit loggedInChanged(false); emit loggedInChanged(false);
} }
@ -129,7 +124,7 @@ QString PushoverFrontend::errorMessage()
void PushoverFrontend::slotActionInvoked(Notification notification) void PushoverFrontend::slotActionInvoked(Notification notification)
{ {
if(notification.priority() == Notification::EMERGENCY){ if (notification.priority() == Notification::EMERGENCY) {
snoreDebug(SNORE_WARNING) << "emergeency notification" << notification; snoreDebug(SNORE_WARNING) << "emergeency notification" << notification;
acknowledgeNotification(notification); acknowledgeNotification(notification);
} }
@ -147,16 +142,15 @@ QString PushoverFrontend::device()
void PushoverFrontend::connectToService() void PushoverFrontend::connectToService()
{ {
if(secret().isEmpty() || device().isEmpty()) if (secret().isEmpty() || device().isEmpty()) {
{
snoreDebug(SNORE_WARNING) << "not logged in"; snoreDebug(SNORE_WARNING) << "not logged in";
return; return;
} }
m_socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this); m_socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this);
connect(m_socket, &QWebSocket::binaryMessageReceived, [&](const QByteArray &msg){ connect(m_socket, &QWebSocket::binaryMessageReceived, [&](const QByteArray & msg) {
char c = msg.at(0); char c = msg.at(0);
switch(c){ switch (c) {
case '#': case '#':
snoreDebug(SNORE_DEBUG) << "still alive"; snoreDebug(SNORE_DEBUG) << "still alive";
break; break;
@ -180,14 +174,14 @@ void PushoverFrontend::connectToService()
snoreDebug(SNORE_WARNING) << "unknown message recieved" << msg; snoreDebug(SNORE_WARNING) << "unknown message recieved" << msg;
} }
}); });
connect(m_socket, &QWebSocket::disconnected, [](){ connect(m_socket, &QWebSocket::disconnected, []() {
snoreDebug(SNORE_DEBUG) << "disconnected"; snoreDebug(SNORE_DEBUG) << "disconnected";
}); });
connect(m_socket, static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), [&](QAbstractSocket::SocketError error){ connect(m_socket, static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), [&](QAbstractSocket::SocketError error) {
snoreDebug(SNORE_WARNING) << error << m_socket->errorString(); snoreDebug(SNORE_WARNING) << error << m_socket->errorString();
emit loggedInChanged(false); emit loggedInChanged(false);
}); });
connect(m_socket, &QWebSocket::connected, [&](){ connect(m_socket, &QWebSocket::connected, [&]() {
snoreDebug(SNORE_DEBUG) << "connecting"; snoreDebug(SNORE_DEBUG) << "connecting";
m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData()); m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData());
emit loggedInChanged(true); emit loggedInChanged(true);
@ -203,14 +197,13 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded"))); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData()); QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply, secret, this]() { connect(reply, &QNetworkReply::finished, [reply, secret, this]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll(); QByteArray input = reply->readAll();
reply->close(); reply->close();
reply->deleteLater(); reply->deleteLater();
QJsonObject message = QJsonDocument::fromJson(input).object(); QJsonObject message = QJsonDocument::fromJson(input).object();
if(message.value(QLatin1String("status")).toInt() == 1) { if (message.value(QLatin1String("status")).toInt() == 1) {
setSettingsValue(QLatin1String("Secret"), secret, LOCAL_SETTING); setSettingsValue(QLatin1String("Secret"), secret, LOCAL_SETTING);
setSettingsValue(QLatin1String("DeviceID"), message.value(QLatin1String("id")).toString(), LOCAL_SETTING);; setSettingsValue(QLatin1String("DeviceID"), message.value(QLatin1String("id")).toString(), LOCAL_SETTING);;
connectToService(); connectToService();
@ -222,17 +215,15 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
}); });
} }
void PushoverFrontend::getMessages() void PushoverFrontend::getMessages()
{ {
QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/messages.json?" QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/messages.json?"
"secret=") + secret() + QLatin1String("&device_id=") + device()).toUtf8().constData())); "secret=") + secret() + QLatin1String("&device_id=") + device()).toUtf8().constData()));
QNetworkReply *reply = m_manager.get(request); QNetworkReply *reply = m_manager.get(request);
connect(reply, &QNetworkReply::finished, [reply, this]() {
connect(reply, &QNetworkReply::finished, [reply,this]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll(); QByteArray input = reply->readAll();
reply->close(); reply->close();
@ -243,9 +234,9 @@ void PushoverFrontend::getMessages()
QJsonObject message = QJsonDocument::fromJson(input).object(); QJsonObject message = QJsonDocument::fromJson(input).object();
int latestID = -1; int latestID = -1;
if(message.value(QLatin1String("status")).toInt() == 1){ if (message.value(QLatin1String("status")).toInt() == 1) {
QJsonArray notifications = message.value(QLatin1String("messages")).toArray(); QJsonArray notifications = message.value(QLatin1String("messages")).toArray();
for( const QJsonValue &v : notifications) { for (const QJsonValue &v : notifications) {
QJsonObject notification = v.toObject(); QJsonObject notification = v.toObject();
latestID = qMax(latestID, notification.value(QLatin1String("id")).toInt()); latestID = qMax(latestID, notification.value(QLatin1String("id")).toInt());
@ -253,29 +244,28 @@ void PushoverFrontend::getMessages()
QString appName = notification.value(QLatin1String("app")).toString(); QString appName = notification.value(QLatin1String("app")).toString();
Application app = SnoreCore::instance().aplications().value(appName); Application app = SnoreCore::instance().aplications().value(appName);
if (!app.isValid()){ if (!app.isValid()) {
Icon icon(QLatin1String("https://api.pushover.net/icons/") + Icon icon(QLatin1String("https://api.pushover.net/icons/") +
notification.value(QLatin1String("icon")).toString() + notification.value(QLatin1String("icon")).toString() +
QLatin1String(".png")); QLatin1String(".png"));
app = Application(appName, icon); app = Application(appName, icon);
SnoreCore::instance().registerApplication(app); SnoreCore::instance().registerApplication(app);
} }
Notification n(app, app.defaultAlert(), notification.value(QLatin1String("title")).toString(), Notification n(app, app.defaultAlert(), notification.value(QLatin1String("title")).toString(),
notification.value(QLatin1String("message")).toString(), notification.value(QLatin1String("message")).toString(),
app.icon(), Notification::defaultTimeout(), app.icon(), Notification::defaultTimeout(),
static_cast<Notification::Prioritys>(notification.value(QLatin1String("priority")).toInt())); static_cast<Notification::Prioritys>(notification.value(QLatin1String("priority")).toInt()));
if(n.priority() == Notification::EMERGENCY){ if (n.priority() == Notification::EMERGENCY) {
n.hints().setValue("receipt", notification.value(QLatin1String("receipt")).toString()); n.hints().setValue("receipt", notification.value(QLatin1String("receipt")).toString());
n.hints().setValue("acked", notification.value(QLatin1String("acked")).toInt()); n.hints().setValue("acked", notification.value(QLatin1String("acked")).toInt());
} }
if(notification.value(QLatin1String("html")).toInt() == 1) { if (notification.value(QLatin1String("html")).toInt() == 1) {
n.hints().setValue("use-markup", true) ; n.hints().setValue("use-markup", true) ;
} }
SnoreCore::instance().broadcastNotification(n); SnoreCore::instance().broadcastNotification(n);
} }
if(latestID != -1){ if (latestID != -1) {
deleteMessages(latestID); deleteMessages(latestID);
} }
} else { } else {
@ -290,12 +280,11 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
{ {
QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/devices/") + QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/devices/") +
device() + QLatin1String("/update_highest_message.json")).toUtf8().constData())); device() + QLatin1String("/update_highest_message.json")).toUtf8().constData()));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded"))); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret() + QLatin1String("&message=") + QString::number(latestMessageId)).toUtf8().constData()); QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret() + QLatin1String("&message=") + QString::number(latestMessageId)).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply]() { connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();
snoreDebug(SNORE_DEBUG) << reply->readAll(); snoreDebug(SNORE_DEBUG) << reply->readAll();
@ -306,19 +295,18 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
void PushoverFrontend::acknowledgeNotification(Notification notification) void PushoverFrontend::acknowledgeNotification(Notification notification)
{ {
if(notification.constHints().value("acked").toInt() == 1){ if (notification.constHints().value("acked").toInt() == 1) {
return; return;
} }
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt(); snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
QString receipt = notification.constHints().value("receipt").toString(); QString receipt = notification.constHints().value("receipt").toString();
QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/receipts/") + QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/receipts/") +
receipt + QLatin1String("/acknowledge.json")).toUtf8().constData())); receipt + QLatin1String("/acknowledge.json")).toUtf8().constData()));
snoreDebug(SNORE_WARNING) << request.url(); snoreDebug(SNORE_WARNING) << request.url();
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded"))); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData()); QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply]() { connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();
snoreDebug(SNORE_DEBUG) << reply->readAll(); snoreDebug(SNORE_DEBUG) << reply->readAll();
@ -328,4 +316,3 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
}); });
} }

View File

@ -25,7 +25,6 @@
#include <QPointer> #include <QPointer>
#include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocket>
class PushoverFrontend : public Snore::SnoreFrontend class PushoverFrontend : public Snore::SnoreFrontend
{ {
Q_OBJECT Q_OBJECT
@ -39,7 +38,7 @@ public:
Snore::PluginSettingsWidget *settingsWidget() override; Snore::PluginSettingsWidget *settingsWidget() override;
void login(const QString &email, const QString &password, const QString& deviceName); void login(const QString &email, const QString &password, const QString &deviceName);
void logOut(); void logOut();
bool isLoggedIn() const; bool isLoggedIn() const;
@ -68,9 +67,6 @@ private:
void deleteMessages(int latestMessageId); void deleteMessages(int latestMessageId);
void acknowledgeNotification(Snore::Notification notification); void acknowledgeNotification(Snore::Notification notification);
}; };
#endif//PUSHOVER_FRONTEND_H #endif//PUSHOVER_FRONTEND_H

View File

@ -39,28 +39,28 @@ PushoverSettings::PushoverSettings(Snore::SnorePlugin *plugin, QWidget *parent)
addRow(QString(), m_registerButton); addRow(QString(), m_registerButton);
addRow(tr("Status"), m_errorMessageLabel); addRow(tr("Status"), m_errorMessageLabel);
addRow(QString(), new QLabel(this)); addRow(QString(), new QLabel(this));
addRow(QString(), new QLabel(tr("If you don't have an accout yet please register at <a href=\"https://pushover.net\">Pushover.net</a>"),this)); addRow(QString(), new QLabel(tr("If you don't have an accout yet please register at <a href=\"https://pushover.net\">Pushover.net</a>"), this));
m_emailLineEdit->setEnabled(false); m_emailLineEdit->setEnabled(false);
m_passwordLineEdit->setEnabled(false); m_passwordLineEdit->setEnabled(false);
m_deviceLineEdit->setEnabled(false); m_deviceLineEdit->setEnabled(false);
m_registerButton->setEnabled(false); m_registerButton->setEnabled(false);
PushoverFrontend *pushover = dynamic_cast<PushoverFrontend*>(plugin); PushoverFrontend *pushover = dynamic_cast<PushoverFrontend *>(plugin);
m_errorMessageLabel->setText(pushover->errorMessage()); m_errorMessageLabel->setText(pushover->errorMessage());
connect(pushover, &PushoverFrontend::loggedInChanged, this, &PushoverSettings::slotUpdateLoginState); connect(pushover, &PushoverFrontend::loggedInChanged, this, &PushoverSettings::slotUpdateLoginState);
connect(pushover, &PushoverFrontend::error, [this](QString message){ connect(pushover, &PushoverFrontend::error, [this](QString message) {
m_errorMessageLabel->setText(message); m_errorMessageLabel->setText(message);
}); });
slotUpdateLoginState(pushover->isLoggedIn()); slotUpdateLoginState(pushover->isLoggedIn());
connect(m_registerButton, &QPushButton::clicked, [pushover, this] () { connect(m_registerButton, &QPushButton::clicked, [pushover, this]() {
m_registerButton->setEnabled(false); m_registerButton->setEnabled(false);
if(!pushover->isLoggedIn()) { if (!pushover->isLoggedIn()) {
pushover->login(m_emailLineEdit->text(), m_passwordLineEdit->text(), m_deviceLineEdit->text()); pushover->login(m_emailLineEdit->text(), m_passwordLineEdit->text(), m_deviceLineEdit->text());
}else{ } else {
pushover->logOut(); pushover->logOut();
} }
}); });

View File

@ -44,7 +44,6 @@ private:
private Q_SLOTS: private Q_SLOTS:
void slotUpdateLoginState(bool state); void slotUpdateLoginState(bool state);
}; };
#endif // PUSHOVERSETTINGS_H #endif // PUSHOVERSETTINGS_H

View File

@ -64,7 +64,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
QByteArray key; QByteArray key;
QString value; QString value;
foreach(QString s, splitted) { foreach (QString s, splitted) {
key = s.mid(0, s.indexOf(QLatin1String("="))).toLower().toLatin1(); key = s.mid(0, s.indexOf(QLatin1String("="))).toLower().toLatin1();
value = s.mid(s.indexOf(QLatin1String("=")) + 1); value = s.mid(s.indexOf(QLatin1String("=")) + 1);
switch (getSnpType.value(key)) { switch (getSnpType.value(key)) {

View File

@ -29,7 +29,7 @@ using namespace Snore;
bool SnarlNetworkFrontend::initialize() bool SnarlNetworkFrontend::initialize()
{ {
if(!SnoreFrontend::initialize()) { if (!SnoreFrontend::initialize()) {
return false; return false;
} }
parser = new Parser(this); parser = new Parser(this);
@ -99,7 +99,7 @@ void SnarlNetworkFrontend::handleMessages()
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender()); QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
QStringList messages(QString::fromLatin1(client->readAll()).trimmed().split(QLatin1String("\r\n"))); QStringList messages(QString::fromLatin1(client->readAll()).trimmed().split(QLatin1String("\r\n")));
foreach(const QString & s, messages) { foreach (const QString &s, messages) {
if (s.isEmpty()) { if (s.isEmpty()) {
continue; continue;
} }
@ -119,7 +119,7 @@ void SnarlNetworkFrontend::callback(Notification &sn, const QString msg)
{ {
if (sn.hints().containsPrivateValue(this, "clientSocket")) { if (sn.hints().containsPrivateValue(this, "clientSocket")) {
QTcpSocket *client = sn.hints().privateValue(this, "clientSocket").value<QPointer<QTcpSocket>>(); QTcpSocket *client = sn.hints().privateValue(this, "clientSocket").value<QPointer<QTcpSocket>>();
if(client){ if (client) {
write(client, QString(QLatin1String("%1%2\r\n")).arg(msg, QString::number(sn.id()))); write(client, QString(QLatin1String("%1%2\r\n")).arg(msg, QString::number(sn.id())));
} }
} }

View File

@ -36,22 +36,20 @@ void NotifyMyAndroid::slotNotify(Notification notification)
QNetworkRequest request(QUrl::fromEncoded("https://www.notifymyandroid.com/publicapi/notify")); QNetworkRequest request(QUrl::fromEncoded("https://www.notifymyandroid.com/publicapi/notify"));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded"))); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QString data = QLatin1String("apikey=") + key QString data = QLatin1String("apikey=") + key
+ QLatin1String("&application=") + notification.application().name() + QLatin1String("&application=") + notification.application().name()
+ QLatin1String("&event=") + notification.title() + QLatin1String("&event=") + notification.title()
+ QLatin1String("&priority=") + QString::number(notification.priority()) + QLatin1String("&priority=") + QString::number(notification.priority())
+ QLatin1String("&description="); + QLatin1String("&description=");
if(notification.constHints().value("supports-markup").toBool()){ if (notification.constHints().value("supports-markup").toBool()) {
data += notification.text(Utils::HREF | Utils::BOLD | Utils::BREAK | data += notification.text(Utils::HREF | Utils::BOLD | Utils::BREAK |
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC) Utils::UNDERLINE | Utils::FONT | Utils::ITALIC)
+ QLatin1String("&content-type=text/html"); + QLatin1String("&content-type=text/html");
}else{ } else {
data += notification.text(); data += notification.text();
} }
QNetworkReply *reply = m_manager.post(request, data.toUtf8().constData()); QNetworkReply *reply = m_manager.post(request, data.toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply]() { connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->error();

View File

@ -43,7 +43,7 @@ void Pushover::slotNotify(Notification notification)
mp->append(title); mp->append(title);
QString textString; QString textString;
if(notification.constHints().value("use-markup").toBool()){ if (notification.constHints().value("use-markup").toBool()) {
textString = notification.text(Utils::HREF | Utils::BOLD | Utils::UNDERLINE | Utils::FONT | Utils::ITALIC); textString = notification.text(Utils::HREF | Utils::BOLD | Utils::UNDERLINE | Utils::FONT | Utils::ITALIC);
QHttpPart html; QHttpPart html;
@ -65,7 +65,7 @@ void Pushover::slotNotify(Notification notification)
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"priority\""))); priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"priority\"")));
priority.setBody(QString::number(notification.priority()).toUtf8().constData()); priority.setBody(QString::number(notification.priority()).toUtf8().constData());
mp->append(priority); mp->append(priority);
if(notification.priority() == Notification::EMERGENCY){ if (notification.priority() == Notification::EMERGENCY) {
QHttpPart retry; QHttpPart retry;
retry.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"retry\""))); retry.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"retry\"")));

View File

@ -25,7 +25,7 @@ bool setSetting(const QString &appName, SettingsType type, const QString &_key,
return false; return false;
} }
settings.setValue(key, value); settings.setValue(key, value);
cout <<"Set: " << qPrintable(key) << " to " << qPrintable(settings.value(key).toString()) << endl; cout << "Set: " << qPrintable(key) << " to " << qPrintable(settings.value(key).toString()) << endl;
return true; return true;
} }
@ -46,7 +46,7 @@ void listSettings(SettingsType type, const QString &application)
cout << qPrintable(application) << endl; cout << qPrintable(application) << endl;
for (const QString &key : Utils::allSettingsKeysWithPrefix( for (const QString &key : Utils::allSettingsKeysWithPrefix(
Utils::normalizeSettingsKey(QLatin1String(""), type, application), settings, getAllKeys)) { Utils::normalizeSettingsKey(QLatin1String(""), type, application), settings, getAllKeys)) {
cout <<" " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, application)).toString()) << endl; cout << " " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, application)).toString()) << endl;
} }
} }
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
QCommandLineOption appNameCommand({QLatin1String("a"), QLatin1String("appName")} , QLatin1String("Set the Name of the app <app>."), QLatin1String("app"), QLatin1String("GlobalSettings")); QCommandLineOption appNameCommand({QLatin1String("a"), QLatin1String("appName")} , QLatin1String("Set the Name of the app <app>."), QLatin1String("app"), QLatin1String("GlobalSettings"));
parser.addOption(appNameCommand); parser.addOption(appNameCommand);
QCommandLineOption typeCommand({QLatin1String("t"),QLatin1String("type")} ,QLatin1String("Type of the setting [global|local]."),QLatin1String("type")); QCommandLineOption typeCommand({QLatin1String("t"), QLatin1String("type")} , QLatin1String("Type of the setting [global|local]."), QLatin1String("type"));
parser.addOption(typeCommand); parser.addOption(typeCommand);
parser.addPositionalArgument(QLatin1String("key"), QLatin1String("The settings Key.")); parser.addPositionalArgument(QLatin1String("key"), QLatin1String("The settings Key."));