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,15 +11,15 @@
using namespace Snore;
class SnoreBenchmark : public QObject{
class SnoreBenchmark : public QObject
{
Q_OBJECT
public:
SnoreBenchmark(){
SnoreBenchmark()
{
SnoreCore::instance();
}
QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
"<i>Italic B</i><br>"
"<b>Bold</b><br>"
@ -28,15 +28,14 @@ public:
"&lt;&amp;&gt;<br>"
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>");
private Q_SLOTS:
void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain();
void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain();
};
void SnoreBenchmark::benchmarkUtilsToHtml(){
void SnoreBenchmark::benchmarkUtilsToHtml()
{
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n"
"Italic B\n"

View File

@ -92,7 +92,7 @@ QDebug operator<< (QDebug debug, const Snore::Application &app)
{
if (app.isValid()) {
debug << "Snore::Application(" << app.name() << ", ";
foreach(const Alert & a, app.alerts()) {
foreach (const Alert &a, app.alerts()) {
debug << a << ", ";
}
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);
}
@ -34,34 +34,34 @@ QVariant Hint::value(const QByteArray &key) const
return m_data.value(key);
}
QVariant Hint::take(const QByteArray & key)
QVariant Hint::take(const QByteArray &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);
}
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
{
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)

View File

@ -48,28 +48,26 @@ public:
* @param key the key
* @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.
* @param key the key
*/
QVariant value(const QByteArray & key) const;
QVariant value(const QByteArray &key) const;
/**
* The associated value of the key.
* @param key the key
*/
QVariant take(const QByteArray & key);
QVariant take(const QByteArray &key);
/**
*
* @param key the key
* @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
@ -77,14 +75,14 @@ public:
* @param key the key
* @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.
* @param owner the owner
* @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
* @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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,7 +46,7 @@ SnoreCore::SnoreCore(QObject *parent):
SnoreCore &SnoreCore::instance()
{
static SnoreCore *instance = nullptr;
if(!instance){
if (!instance) {
instance = new SnoreCore(qApp);
SnoreCorePrivate::instance()->init();
}
@ -207,8 +207,8 @@ QVariant SnoreCore::settingsValue(const QString &key, SettingsType type) const
{
Q_D(const SnoreCore);
QString nk = d->normalizeSettingsKey(key, type);
if(type == LOCAL_SETTING && !d->m_settings->contains(nk)){
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"),type);
if (type == LOCAL_SETTING && !d->m_settings->contains(nk)) {
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"), type);
}
return d->m_settings->value(nk);
}
@ -235,13 +235,12 @@ Notification SnoreCore::getActiveNotificationByID(uint id) const
return d->m_activeNotifications.value(id);
}
void SnoreCore::displayExapleNotification()
{
Application app = SnoreCorePrivate::instance()->defaultApplication();
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>");
if(!app.constHints().value("use-markup").toBool()) {
if (!app.constHints().value("use-markup").toBool()) {
text = Utils::normalizeMarkup(text, Utils::NO_MARKUP);
}
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)
{
Q_Q(SnoreCore);
QString nk = normalizeSettingsKey( key + QLatin1String("-SnoreDefault"), LOCAL_SETTING);
QString nk = normalizeSettingsKey(key + QLatin1String("-SnoreDefault"), LOCAL_SETTING);
if (!m_settings->contains(nk)) {
m_settings->setValue(nk, value);
}
@ -173,7 +173,7 @@ void SnoreCorePrivate::syncSettings()
auto types = SnorePlugin::types();
types.removeOne(SnorePlugin::BACKEND);
for(auto type : types) {
for (auto type : types) {
for (auto &pluginName : m_pluginNames[type]) {
SnorePlugin *plugin = m_plugins.value(pluginName);
bool enable = m_plugins[pluginName]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool();
@ -262,11 +262,11 @@ static void registerMetaTypes()
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
}
static void snoreStartup(){
static void snoreStartup()
{
loadTranslator();
registerMetaTypes();
}
Q_COREAPP_STARTUP_FUNCTION(snoreStartup)

View File

@ -71,19 +71,17 @@ void Utils::raiseWindowToFront(qlonglong wid)
#endif
}
#define HTML_REPLACE(STRING, PATTERN){\
static QRegExp regexp(QLatin1String(PATTERN));\
STRING = STRING.replace(regexp, QLatin1String("\\1"));\
}\
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
{
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
{
static QMutex mutex;
if(tags == ALL_MARKUP){
if (tags == ALL_MARKUP) {
return string;
} else if(tags == NO_MARKUP) {
} else if (tags == NO_MARKUP) {
return QTextDocumentFragment::fromHtml(string).toPlainText();
}
@ -108,20 +106,20 @@ QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
}
return string;
}
}
#ifdef Q_OS_WIN
int Utils::attatchToActiveProcess()
{
int Utils::attatchToActiveProcess()
{
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
}
}
void Utils::detatchActiveProcess(int idActive)
{
void Utils::detatchActiveProcess(int idActive)
{
if (idActive != -1) {
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
}
}
}
#endif

View File

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

View File

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

View File

@ -53,7 +53,7 @@ bool FreedesktopBackend::canUpdateNotification() const
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;
@ -63,9 +63,9 @@ void FreedesktopBackend::slotNotify(Notification noti)
}
char urgency = '1';
if(noti.priority() < 0){
if (noti.priority() < 0) {
urgency = '0';
} else if(noti.priority() > 2) {
} else if (noti.priority() > 2) {
urgency = '2';
}
hints.insert(QLatin1String("urgency"), urgency);

View File

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

View File

@ -115,7 +115,7 @@ bool SnarlBackend::initialize()
{
setDefaultSettingsValue(QLatin1String("Password"), QString());
if(!SnoreBackend::initialize()) {
if (!SnoreBackend::initialize()) {
return false;
}
@ -176,7 +176,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
snoreDebug(SNORE_DEBUG) << result;
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());
@ -205,11 +205,11 @@ void SnarlBackend::slotNotify(Notification notification)
SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
if(notification.priority() > 1){
if (notification.priority() > 1) {
priority = Snarl::V42::SnarlEnums::PriorityHigh;
} else if(notification.priority() < -1) {
} else if (notification.priority() < -1) {
priority = Snarl::V42::SnarlEnums::PriorityLow;
}else{
} else {
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,
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());
}
m_idMap[id] = notification;

View File

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

View File

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

View File

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

View File

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

View File

@ -23,7 +23,6 @@
#include "libsnore/version.h"
#include "libsnore/notification/notification_p.h"
#include <QNetworkAccessManager>
#include <QHttpMultiPart>
#include <QNetworkReply>
@ -32,7 +31,6 @@
#include <QJsonArray>
#include <QtWebSockets/QWebSocket>
using namespace Snore;
// TODO: use qtkeychain to encrypt credentials?
@ -40,10 +38,10 @@ using namespace Snore;
PushoverFrontend::PushoverFrontend()
{
connect(this, &PushoverFrontend::loggedInChanged, [this](bool state){
connect(this, &PushoverFrontend::loggedInChanged, [this](bool state) {
m_loggedIn = state;
});
connect(this, &PushoverFrontend::error, [this](QString error){
connect(this, &PushoverFrontend::error, [this](QString error) {
m_errorMessage = error;
});
}
@ -53,7 +51,7 @@ bool PushoverFrontend::initialize()
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
if(!SnoreFrontend::initialize()) {
if (!SnoreFrontend::initialize()) {
return false;
}
@ -65,7 +63,7 @@ bool PushoverFrontend::initialize()
bool PushoverFrontend::deinitialize()
{
if (SnoreFrontend::deinitialize()) {
if(m_socket) {
if (m_socket) {
m_socket->close();
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")));
QNetworkReply *reply = m_manager.post(request, QString(QLatin1String("email=%1&password=%2")).arg(email, password).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() {
snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll();
reply->close();
reply->deleteLater();
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);
}else {
} else {
snoreDebug(SNORE_WARNING) << "An error occure" << input;
emit loggedInChanged(false);
}
@ -129,7 +124,7 @@ QString PushoverFrontend::errorMessage()
void PushoverFrontend::slotActionInvoked(Notification notification)
{
if(notification.priority() == Notification::EMERGENCY){
if (notification.priority() == Notification::EMERGENCY) {
snoreDebug(SNORE_WARNING) << "emergeency notification" << notification;
acknowledgeNotification(notification);
}
@ -147,16 +142,15 @@ QString PushoverFrontend::device()
void PushoverFrontend::connectToService()
{
if(secret().isEmpty() || device().isEmpty())
{
if (secret().isEmpty() || device().isEmpty()) {
snoreDebug(SNORE_WARNING) << "not logged in";
return;
}
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);
switch(c){
switch (c) {
case '#':
snoreDebug(SNORE_DEBUG) << "still alive";
break;
@ -180,14 +174,14 @@ void PushoverFrontend::connectToService()
snoreDebug(SNORE_WARNING) << "unknown message recieved" << msg;
}
});
connect(m_socket, &QWebSocket::disconnected, [](){
connect(m_socket, &QWebSocket::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();
emit loggedInChanged(false);
});
connect(m_socket, &QWebSocket::connected, [&](){
connect(m_socket, &QWebSocket::connected, [&]() {
snoreDebug(SNORE_DEBUG) << "connecting";
m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData());
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")));
QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply, secret, this]() {
snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll();
reply->close();
reply->deleteLater();
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("DeviceID"), message.value(QLatin1String("id")).toString(), LOCAL_SETTING);;
connectToService();
@ -222,7 +215,6 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
});
}
void PushoverFrontend::getMessages()
@ -231,8 +223,7 @@ void PushoverFrontend::getMessages()
"secret=") + secret() + QLatin1String("&device_id=") + device()).toUtf8().constData()));
QNetworkReply *reply = m_manager.get(request);
connect(reply, &QNetworkReply::finished, [reply,this]() {
connect(reply, &QNetworkReply::finished, [reply, this]() {
snoreDebug(SNORE_DEBUG) << reply->error();
QByteArray input = reply->readAll();
reply->close();
@ -243,9 +234,9 @@ void PushoverFrontend::getMessages()
QJsonObject message = QJsonDocument::fromJson(input).object();
int latestID = -1;
if(message.value(QLatin1String("status")).toInt() == 1){
if (message.value(QLatin1String("status")).toInt() == 1) {
QJsonArray notifications = message.value(QLatin1String("messages")).toArray();
for( const QJsonValue &v : notifications) {
for (const QJsonValue &v : notifications) {
QJsonObject notification = v.toObject();
latestID = qMax(latestID, notification.value(QLatin1String("id")).toInt());
@ -253,7 +244,7 @@ void PushoverFrontend::getMessages()
QString appName = notification.value(QLatin1String("app")).toString();
Application app = SnoreCore::instance().aplications().value(appName);
if (!app.isValid()){
if (!app.isValid()) {
Icon icon(QLatin1String("https://api.pushover.net/icons/") +
notification.value(QLatin1String("icon")).toString() +
QLatin1String(".png"));
@ -261,21 +252,20 @@ void PushoverFrontend::getMessages()
SnoreCore::instance().registerApplication(app);
}
Notification n(app, app.defaultAlert(), notification.value(QLatin1String("title")).toString(),
notification.value(QLatin1String("message")).toString(),
app.icon(), Notification::defaultTimeout(),
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("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) ;
}
SnoreCore::instance().broadcastNotification(n);
}
if(latestID != -1){
if (latestID != -1) {
deleteMessages(latestID);
}
} else {
@ -295,7 +285,6 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
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());
connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error();
snoreDebug(SNORE_DEBUG) << reply->readAll();
@ -306,7 +295,7 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
void PushoverFrontend::acknowledgeNotification(Notification notification)
{
if(notification.constHints().value("acked").toInt() == 1){
if (notification.constHints().value("acked").toInt() == 1) {
return;
}
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
@ -318,7 +307,6 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData());
connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error();
snoreDebug(SNORE_DEBUG) << reply->readAll();
@ -328,4 +316,3 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
});
}

View File

@ -25,7 +25,6 @@
#include <QPointer>
#include <QtWebSockets/QWebSocket>
class PushoverFrontend : public Snore::SnoreFrontend
{
Q_OBJECT
@ -39,7 +38,7 @@ public:
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();
bool isLoggedIn() const;
@ -68,9 +67,6 @@ private:
void deleteMessages(int latestMessageId);
void acknowledgeNotification(Snore::Notification notification);
};
#endif//PUSHOVER_FRONTEND_H

View File

@ -39,28 +39,28 @@ PushoverSettings::PushoverSettings(Snore::SnorePlugin *plugin, QWidget *parent)
addRow(QString(), m_registerButton);
addRow(tr("Status"), m_errorMessageLabel);
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_passwordLineEdit->setEnabled(false);
m_deviceLineEdit->setEnabled(false);
m_registerButton->setEnabled(false);
PushoverFrontend *pushover = dynamic_cast<PushoverFrontend*>(plugin);
PushoverFrontend *pushover = dynamic_cast<PushoverFrontend *>(plugin);
m_errorMessageLabel->setText(pushover->errorMessage());
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);
});
slotUpdateLoginState(pushover->isLoggedIn());
connect(m_registerButton, &QPushButton::clicked, [pushover, this] () {
connect(m_registerButton, &QPushButton::clicked, [pushover, this]() {
m_registerButton->setEnabled(false);
if(!pushover->isLoggedIn()) {
if (!pushover->isLoggedIn()) {
pushover->login(m_emailLineEdit->text(), m_passwordLineEdit->text(), m_deviceLineEdit->text());
}else{
} else {
pushover->logOut();
}
});

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ void Pushover::slotNotify(Notification notification)
mp->append(title);
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);
QHttpPart html;
@ -65,7 +65,7 @@ void Pushover::slotNotify(Notification notification)
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"priority\"")));
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
mp->append(priority);
if(notification.priority() == Notification::EMERGENCY){
if (notification.priority() == Notification::EMERGENCY) {
QHttpPart 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;
}
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;
}
@ -46,7 +46,7 @@ void listSettings(SettingsType type, const QString &application)
cout << qPrintable(application) << endl;
for (const QString &key : Utils::allSettingsKeysWithPrefix(
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"));
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.addPositionalArgument(QLatin1String("key"), QLatin1String("The settings Key."));