From 0d46672737894ed4336a6f53aba2c0a0a9e22ec6 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Thu, 11 Sep 2014 14:36:34 +0200 Subject: [PATCH] Code reformatted using kde-dev-scripts/astyle-kdelibs --- src/core/alert.cpp | 11 +- src/core/alert.h | 6 +- src/core/alert_p.cpp | 1 - src/core/alert_p.h | 1 - src/core/application.cpp | 18 +- src/core/application.h | 15 +- src/core/application_p.cpp | 3 +- src/core/application_p.h | 3 +- src/core/hint.cpp | 58 +- src/core/hint.h | 19 +- src/core/log.cpp | 78 +- src/core/log.h | 11 +- src/core/notification/icon.cpp | 17 +- src/core/notification/icon.h | 12 +- src/core/notification/icon_p.cpp | 46 +- src/core/notification/icon_p.h | 7 +- src/core/notification/notification.cpp | 48 +- src/core/notification/notification.h | 42 +- src/core/notification/notification_p.cpp | 56 +- src/core/notification/notification_p.h | 24 +- src/core/notification/notificationaction.cpp | 3 +- src/core/notification/notificationaction.h | 6 +- src/core/plugins/plugincontainer.cpp | 98 +-- src/core/plugins/plugincontainer.h | 13 +- src/core/plugins/plugins.cpp | 42 +- src/core/plugins/plugins.h | 25 +- src/core/plugins/snorebackend.cpp | 98 +-- src/core/plugins/snorebackend.h | 36 +- src/core/plugins/snorefrontend.cpp | 10 +- src/core/plugins/snorefrontend.h | 17 +- src/core/snore.cpp | 121 ++- src/core/snore.h | 36 +- src/core/snore_p.cpp | 36 +- src/core/snore_p.h | 14 +- src/core/version.h | 3 +- src/main.cpp | 4 +- .../freedesktop/fredesktopnotification.cpp | 45 +- .../freedesktop/fredesktopnotification.h | 7 +- .../freedesktopnotification_backend.cpp | 83 +- .../freedesktopnotification_backend.h | 20 +- src/plugins/backends/growl/growlbackend.cpp | 55 +- src/plugins/backends/growl/growlbackend.h | 10 +- .../osxnotificationcenter.h | 10 +- src/plugins/backends/snarl/SnarlInterface.cpp | 188 ++--- src/plugins/backends/snarl/SnarlInterface.h | 735 ++++++++++-------- src/plugins/backends/snarl/snarl.cpp | 136 ++-- src/plugins/backends/snarl/snarl.h | 12 +- src/plugins/backends/snore/notifywidget.cpp | 96 +-- src/plugins/backends/snore/notifywidget.h | 7 +- src/plugins/backends/snore/snorenotifier.cpp | 84 +- src/plugins/backends/snore/snorenotifier.h | 4 +- .../backends/snoretoast/snoretoast.cpp | 55 +- src/plugins/backends/snoretoast/snoretoast.h | 3 +- .../backends/trayicon/trayiconnotifer.cpp | 39 +- .../backends/trayicon/trayiconnotifer.h | 10 +- .../freedesktopnotificationfrontend.cpp | 93 +-- .../freedesktopnotificationfrontend.h | 10 +- src/plugins/frontends/snarlnetwork/parser.cpp | 87 +-- src/plugins/frontends/snarlnetwork/parser.h | 11 +- .../frontends/snarlnetwork/snarlnetwork.cpp | 55 +- .../frontends/snarlnetwork/snarlnetwork.h | 12 +- src/snorenotify.cpp | 33 +- src/snorenotify.h | 6 +- src/trayicon.cpp | 37 +- src/trayicon.h | 9 +- 65 files changed, 1323 insertions(+), 1667 deletions(-) diff --git a/src/core/alert.cpp b/src/core/alert.cpp index ec48534..5592063 100644 --- a/src/core/alert.cpp +++ b/src/core/alert.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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,7 +25,7 @@ Alert::Alert() : d(NULL) {} -Alert::Alert (const QString &name, const Icon &icon, bool active): +Alert::Alert(const QString &name, const Icon &icon, bool active): d(new AlertData(name, icon, active)) {} @@ -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(); diff --git a/src/core/alert.h b/src/core/alert.h index b08670a..cd148a6 100644 --- a/src/core/alert.h +++ b/src/core/alert.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 @@ -49,7 +48,7 @@ public: * @todo is isActive of any use? */ - explicit Alert(const QString &name, const Icon &icon, bool active = true ); + explicit Alert(const QString &name, const Icon &icon, bool active = true); /** * Creates a copy of other * @param other @@ -92,7 +91,6 @@ private: }; } -QDebug SNORE_EXPORT operator<< ( QDebug debug, const Snore::Alert &alert ); - +QDebug SNORE_EXPORT operator<< (QDebug debug, const Snore::Alert &alert); #endif // ALERT_H diff --git a/src/core/alert_p.cpp b/src/core/alert_p.cpp index 3f6588a..3e03e96 100644 --- a/src/core/alert_p.cpp +++ b/src/core/alert_p.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 diff --git a/src/core/alert_p.h b/src/core/alert_p.h index 5c32eb6..5ce1c7c 100644 --- a/src/core/alert_p.h +++ b/src/core/alert_p.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 diff --git a/src/core/application.cpp b/src/core/application.cpp index f219f74..846f8c3 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,15 +19,14 @@ #include "application.h" #include "application_p.h" - using namespace Snore; Application::Application(): d(NULL) {} -Application::Application (const QString &name, const Icon &icon) : - d(new ApplicationData(name,icon)) +Application::Application(const QString &name, const Icon &icon) : + d(new ApplicationData(name, icon)) { } @@ -84,19 +82,15 @@ const Hint &Application::constHints() const return d->m_hint; } -QDebug operator<< ( QDebug debug, const Snore::Application &app ) +QDebug operator<< (QDebug debug, const Snore::Application &app) { - if(app.isValid()) - { + if (app.isValid()) { debug << "Snore::Application(" << app.name() << ", "; - foreach(const Alert &a, app.alerts()) - { + foreach(const Alert & a, app.alerts()) { debug << a << ", "; } debug << ")" ; - } - else - { + } else { debug << "Snore::Application(0x00)" ; } return debug.maybeSpace(); diff --git a/src/core/application.h b/src/core/application.h index 2f48925..44b0795 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 -namespace Snore{ +namespace Snore +{ class ApplicationData; @@ -47,7 +47,7 @@ public: * @param icon * @see SnoreCore::registerApplication */ - explicit Application ( const QString &name, const Icon &icon); + explicit Application(const QString &name, const Icon &icon); /** * The copy constructor @@ -84,7 +84,7 @@ public: /** * Returns a QHash with the Alers registered with this Application */ - const QHash &alerts() const; + const QHash &alerts() const; /** * @@ -108,16 +108,13 @@ public: const Hint &constHints() const; private: - QExplicitlySharedDataPointer d; - + QExplicitlySharedDataPointer d; }; } Q_DECLARE_METATYPE(Snore::Application) -SNORE_EXPORT QDebug operator<< ( QDebug debug, const Snore::Application &app ); - - +SNORE_EXPORT QDebug operator<< (QDebug debug, const Snore::Application &app); #endif // APPLICATION_H diff --git a/src/core/application_p.cpp b/src/core/application_p.cpp index 88b5a6c..a6d977c 100644 --- a/src/core/application_p.cpp +++ b/src/core/application_p.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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,7 @@ ApplicationData::ApplicationData(const QString &name, const Icon &icon): m_name(name), m_icon(icon) { - Q_ASSERT_X(!name.isEmpty(),Q_FUNC_INFO, "invalid name detected"); + Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected"); } ApplicationData::~ApplicationData() diff --git a/src/core/application_p.h b/src/core/application_p.h index e20576c..92cf4c9 100644 --- a/src/core/application_p.h +++ b/src/core/application_p.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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,7 @@ public: QString m_name; Icon m_icon; - QHash m_alerts; + QHash m_alerts; Hint m_hint; }; diff --git a/src/core/hint.cpp b/src/core/hint.cpp index 691a11e..b7bc177 100644 --- a/src/core/hint.cpp +++ b/src/core/hint.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,19 +32,16 @@ void Hint::setValue(const QString &key, const QVariant &value) void Hint::setValue(const QString &key, QObject *value) { m_data.insert(key.toLower(), qVariantFromValue(value)); - value->setProperty("hint_key",key.toLower()); - connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()),Qt::DirectConnection ); + value->setProperty("hint_key", key.toLower()); + connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); } 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; } } @@ -57,70 +53,58 @@ bool Hint::contains(const QString &key) const void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant &value) const { - QPair pk((quintptr)owner,key.toLower()); + QPair pk((quintptr)owner, key.toLower()); m_privateData.insert(pk, value); } void Hint::setPrivateValue(const void *owner, const QString &key, QObject *value) const { - QPair pk((quintptr)owner,key.toLower()); + QPair pk((quintptr)owner, key.toLower()); m_privateData.insert(pk, qVariantFromValue(value)); - value->setProperty("hint_key",key.toLower()); - value->setProperty("hint_owner",(quintptr)owner); + value->setProperty("hint_key", key.toLower()); + value->setProperty("hint_owner", (quintptr)owner); connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); } - QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const { - QPair key((quintptr)owner, k.toLower()); - if(m_privateData.contains(key)) - { + QPair key((quintptr)owner, k.toLower()); + 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 pk((quintptr)owner,key.toLower()); + QPair pk((quintptr)owner, key.toLower()); return m_privateData.contains(pk); } void Hint::slotValueDestroyed() { - QObject * o = sender(); + QObject *o = sender(); QString key = o->property("hint_key").toString(); - if(!o->property("hint_owner").isNull()) - { - QPair pk(o->property("hint_owner").value(), key); + if (!o->property("hint_owner").isNull()) { + QPair pk(o->property("hint_owner").value(), key); m_privateData.remove(pk); - } - else - { + } else { m_data.remove(key); } } -QDebug operator<<( QDebug debug, const Snore::Hint &hint ) +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, QVariant>::const_iterator it = hint.m_privateData.constBegin();it != hint.m_privateData.constEnd();++it) - { - if(it != hint.m_privateData.constBegin()) - { + for (QHash< QPair, 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(); diff --git a/src/core/hint.h b/src/core/hint.h index 101ad0d..2988975 100644 --- a/src/core/hint.h +++ b/src/core/hint.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,7 @@ namespace Snore class Hint; } -SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Hint &); +SNORE_EXPORT QDebug operator<< (QDebug, const Snore::Hint &); namespace Snore { @@ -64,14 +63,14 @@ public: * @param key the key * @param defaultValue the fallback value */ - QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; + QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; /** * * @param key the key * @return whether the key is set */ - bool contains ( const QString & key ) const; + bool contains(const QString &key) const; /** * Sets the value for the key depending on the owner @@ -95,7 +94,7 @@ public: * @param key the key * @param defaultValue the fallback value */ - QVariant privateValue(const void *owner, const QString & key, const QVariant & defaultValue = QVariant() ) const; + QVariant privateValue(const void *owner, const QString &key, const QVariant &defaultValue = QVariant()) const; /** * @@ -103,23 +102,19 @@ public: * @param key the key * @return whether the key is set */ - bool containsPrivateValue(const void *owner, const QString & key ) const; + bool containsPrivateValue(const void *owner, const QString &key) const; private slots: void slotValueDestroyed(); private: QVariantHash m_data; - mutable QHash, QVariant> m_privateData; + mutable QHash, QVariant> m_privateData; - friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Hint &); + friend SNORE_EXPORT QDebug(::operator<<)(QDebug, const Snore::Hint &); }; - } - - - #endif // HINT_H diff --git a/src/core/log.cpp b/src/core/log.cpp index 9b50687..33b641a 100644 --- a/src/core/log.cpp +++ b/src/core/log.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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,50 +28,43 @@ using namespace Snore; class Loger { public: -static int s_debugLevel; + static int s_debugLevel; - - -static inline int debugLvl() -{ - if(s_debugLevel == -1) + static inline int debugLvl() { - s_debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt(); - } - return s_debugLevel; -} - -static inline bool isLogToFileEnabled() -{ - static int s_logToFile = -1; - if(s_logToFile == -1) - { - s_logToFile = qgetenv("LIBSNORE_LOG_TO_FILE").toInt(); - } - return s_logToFile == 1; -} - -static inline QTextStream &logFile() -{ - static QTextStream *s_out = NULL; - static QFile *s_file = NULL; - 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()) - { - name = QString(qgetenv("LIBSNORE_LOGFILE")); + if (s_debugLevel == -1) { + s_debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt(); } - std::cout << "Started logging to " << name.toUtf8().constData() << std::endl; - - s_file = new QFile(name); - s_file->open(QFile::WriteOnly); - s_out = new QTextStream(s_file); + return s_debugLevel; } - return *s_out; -} + static inline bool isLogToFileEnabled() + { + static int s_logToFile = -1; + if (s_logToFile == -1) { + s_logToFile = qgetenv("LIBSNORE_LOG_TO_FILE").toInt(); + } + return s_logToFile == 1; + } + + static inline QTextStream &logFile() + { + static QTextStream *s_out = NULL; + static QFile *s_file = NULL; + 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()) { + name = QString(qgetenv("LIBSNORE_LOGFILE")); + } + std::cout << "Started logging to " << name.toUtf8().constData() << std::endl; + + s_file = new QFile(name); + s_file->open(QFile::WriteOnly); + s_out = new QTextStream(s_file); + } + return *s_out; + } }; @@ -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; } } diff --git a/src/core/log.h b/src/core/log.h index 3e228e5..d0a9819 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 #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 diff --git a/src/core/notification/icon.cpp b/src/core/notification/icon.cpp index 7e85825..097513b 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,9 @@ using namespace Snore; QByteArray Icon::dataFromImage(const QImage &image) { QByteArray data; - QBuffer buffer( &data ); - buffer.open( QBuffer::WriteOnly ); - image.save( &buffer, "PNG" ); + QBuffer buffer(&data); + buffer.open(QBuffer::WriteOnly); + image.save(&buffer, "PNG"); return data; } @@ -65,7 +64,8 @@ Icon::~Icon() } -const QImage &Icon::image() const{ +const QImage &Icon::image() const +{ return d->image(); } @@ -86,7 +86,7 @@ bool Icon::isValid() const Icon Icon::scaled(const QSize &s) const { - return Icon(image().scaled(s,Qt::KeepAspectRatio, Qt::SmoothTransformation)); + return Icon(image().scaled(s, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } QString Icon::url() const @@ -94,14 +94,13 @@ QString Icon::url() const return d->m_url; } - bool Snore::Icon::isRemoteFile() const { return d->m_isRemoteFile; } -QDebug operator<< ( QDebug debug, const Snore::Icon &icon ) +QDebug operator<< (QDebug debug, const Snore::Icon &icon) { - debug << "Snore::Icon(" << (icon.url().isEmpty()?icon.d->m_localUrl:icon.url()) << ")" ; + debug << "Snore::Icon(" << (icon.url().isEmpty() ? icon.d->m_localUrl : icon.url()) << ")" ; return debug.maybeSpace(); } diff --git a/src/core/notification/icon.h b/src/core/notification/icon.h index de57d19..624aade 100644 --- a/src/core/notification/icon.h +++ b/src/core/notification/icon.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,11 +23,12 @@ #include #include -namespace Snore{ - class Icon; +namespace Snore +{ +class Icon; } -SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Icon &); +SNORE_EXPORT QDebug operator<< (QDebug, const Snore::Icon &); namespace Snore { @@ -113,10 +113,8 @@ public: private: QExplicitlySharedDataPointer d; - friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &); + friend SNORE_EXPORT QDebug(::operator<<)(QDebug, const Snore::Icon &); }; } - - #endif // NOTIFICATION_ICON_H diff --git a/src/core/notification/icon_p.cpp b/src/core/notification/icon_p.cpp index e0df668..5a0ef40 100644 --- a/src/core/notification/icon_p.cpp +++ b/src/core/notification/icon_p.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,45 +71,37 @@ 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 - { - img.save(m_localUrl ,"PNG"); + 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"; + snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache"; } } return m_localUrl; } - void IconData::download() { - if(m_isRemoteFile) - { - if(!s_localImageCache.contains(m_localUrl)) - { - snoreDebug( SNORE_DEBUG ) << "Downloading:" << m_url; + if (m_isRemoteFile) { + if (!s_localImageCache.contains(m_localUrl)) { + snoreDebug(SNORE_DEBUG) << "Downloading:" << m_url; QNetworkAccessManager manager; QEventLoop loop; QNetworkRequest request(m_url); request.setRawHeader("User-Agent", "SnoreNotify"); QNetworkReply *reply = manager.get(request); QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - QTimer::singleShot(1000,&loop, SLOT(quit()));//timeout + 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"); + m_img.save(m_localUrl, "PNG"); s_localImageCache.insert(m_localUrl); - snoreDebug( SNORE_DEBUG ) << m_localUrl << "added to cache"; + snoreDebug(SNORE_DEBUG) << m_localUrl << "added to cache"; } - } - else - { + } else { m_img = QImage(m_localUrl); } } diff --git a/src/core/notification/icon_p.h b/src/core/notification/icon_p.h index 2e53009..7fc81ad 100644 --- a/src/core/notification/icon_p.h +++ b/src/core/notification/icon_p.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 -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 s_localImageCache; private: diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index eef5e80..7227502 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,27 +26,25 @@ using namespace Snore; - int Notification::m_defaultTimeout = 10; - -Notification::Notification () : +Notification::Notification() : d(NULL) { } Notification::Notification(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): - d(new NotificationData(application,alert,title,text,icon,timeout,priority)) + d(new NotificationData(application, alert, title, text, icon, timeout, priority)) { } Notification::Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): - d(new NotificationData(old,title,text,icon,timeout,priority)) + d(new NotificationData(old, title, text, icon, timeout, priority)) { } -Notification::Notification ( const Notification &other ) : +Notification::Notification(const Notification &other) : d(other.d) { } @@ -117,7 +114,6 @@ bool Notification::isSticky() const return d->m_timeout == 0; } - Notification::Prioritys Notification::priority() const { return d->m_priority; @@ -125,16 +121,16 @@ Notification::Prioritys Notification::priority() const void Notification::addAction(const Action &a) { - d->m_actions.insert(a.id(),a); + d->m_actions.insert(a.id(), a); } - const QHash &Notification::actions() const { return d->m_actions; } -const Notification::CloseReasons &Notification::closeReason(){ +const Notification::CloseReasons &Notification::closeReason() +{ return d->m_closeReason; } @@ -167,7 +163,7 @@ void Notification::setDefaultTimeout(int defaultTimeout) m_defaultTimeout = defaultTimeout; } -QDataStream &operator<< ( QDataStream &stream, const Notification ¬i ) +QDataStream &operator<< (QDataStream &stream, const Notification ¬i) { stream << "Title: " << noti.title() << " Text: " << noti.text() << " ID: " << noti.id() ; return stream; @@ -178,29 +174,27 @@ QDataStream &operator<< ( QDataStream &stream, const Notification ¬i ) QDebug operator <<(QDebug debug, const Snore::Notification::CloseReasons &flags) { debug.nospace() << "CloseReasons("; - switch(flags) - { - debugPrintEnum(Notification::NONE); - debugPrintEnum(Notification::TIMED_OUT); - debugPrintEnum(Notification::DISMISSED); - debugPrintEnum(Notification::CLOSED); - debugPrintEnum(Notification::REPLACED); + switch (flags) { + debugPrintEnum(Notification::NONE); + debugPrintEnum(Notification::TIMED_OUT); + debugPrintEnum(Notification::DISMISSED); + debugPrintEnum(Notification::CLOSED); + debugPrintEnum(Notification::REPLACED); default: - debug << QByteArray::number(flags,16) << ")"; + debug << QByteArray::number(flags, 16) << ")"; } return debug.space(); } -QDebug operator<< ( QDebug debug, const Snore::Notification::Prioritys &flags) +QDebug operator<< (QDebug debug, const Snore::Notification::Prioritys &flags) { debug.nospace() << "Prioritys("; - switch(flags) - { - debugPrintEnum(Notification::LOW); - debugPrintEnum(Notification::NORMAL); - debugPrintEnum(Notification::HIGH); + switch (flags) { + debugPrintEnum(Notification::LOW); + debugPrintEnum(Notification::NORMAL); + debugPrintEnum(Notification::HIGH); default: - debug << QByteArray::number(flags,16) << ")"; + debug << QByteArray::number(flags, 16) << ")"; } return debug.space(); } diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index cdf3be4..33c097c 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 #include - namespace Snore { @@ -41,7 +39,6 @@ class NotificationData; * @author Patrick von Reth \ */ - class SNORE_EXPORT Notification { friend class NotificationData; @@ -49,11 +46,10 @@ public: /** * The reason why the Notification was closed. */ - enum CloseReason - { - /** - * The default value, the notification was not closed. - */ + enum CloseReason { + /** + * The default value, the notification was not closed. + */ NONE = 0, /** @@ -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. */ @@ -116,7 +111,7 @@ public: * @param timeout the timeout * @param priority the priority */ - explicit Notification(const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,int timeout = defaultTimeout(), Notification::Prioritys priority = NORMAL ); + explicit Notification(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout = defaultTimeout(), Notification::Prioritys priority = NORMAL); /** * Creates and update Notification replacing an existing Notification @@ -127,13 +122,13 @@ public: * @param timeout the timeout * @param priority the piority */ - explicit Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout = defaultTimeout(), Snore::Notification::Prioritys priority = NORMAL ); + explicit Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout = defaultTimeout(), Snore::Notification::Prioritys priority = NORMAL); /** * The copy constructor * @param other */ - Notification(const Notification &other ); + Notification(const Notification &other); /** * The copy operator @@ -241,7 +236,6 @@ public: */ bool isValid() const; - /** * * @return the old notification to be replaced @@ -279,7 +273,6 @@ private: static int m_defaultTimeout; - }; } @@ -289,29 +282,24 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::Notification::CloseReasons) Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::Notification::Prioritys) -QDataStream &operator<< ( QDataStream & stream, const Snore::Notification & noti ); +QDataStream &operator<< (QDataStream &stream, const Snore::Notification ¬i); -SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Notification::CloseReasons &); +SNORE_EXPORT QDebug operator<< (QDebug, const Snore::Notification::CloseReasons &); -SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Notification::Prioritys &); +SNORE_EXPORT QDebug operator<< (QDebug, const Snore::Notification::Prioritys &); -inline QDebug operator<< ( QDebug debug, const Snore::Notification ¬i ) +inline QDebug operator<< (QDebug debug, const Snore::Notification ¬i) { - 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 diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp index 81a8eab..ad52629 100644 --- a/src/core/notification/notification_p.cpp +++ b/src/core/notification/notification_p.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 . */ - - #include "notification/notification_p.h" #include "notification/icon.h" #include "../hint.h" @@ -32,57 +29,55 @@ uint NotificationData::notificationCount = 0; uint NotificationData::m_idCount = 1; -NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, - int timeout, Notification::Prioritys priority ): - m_id ( m_idCount++ ), - m_timeout( timeout ), - m_source( NULL), - m_application ( application ), - m_alert( alert ), - m_title( title ), - m_text( text ), - m_icon( icon ), +NotificationData::NotificationData(const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, + int timeout, Notification::Prioritys priority): + m_id(m_idCount++), + m_timeout(timeout), + m_source(NULL), + m_application(application), + m_alert(alert), + m_title(title), + m_text(text), + m_icon(icon), m_priority(priority), m_closeReason(Notification::NONE) { notificationCount++; - snoreDebug( SNORE_DEBUG ) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; + snoreDebug(SNORE_DEBUG) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; } Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): - m_id ( m_idCount++ ), - m_timeout( timeout ), - m_source( NULL), - m_application ( old.application()), - m_alert( old.alert() ), - m_title( title ), - m_text( text ), - m_icon( icon ), + m_id(m_idCount++), + m_timeout(timeout), + m_source(NULL), + m_application(old.application()), + m_alert(old.alert()), + m_title(title), + m_text(text), + m_icon(icon), m_priority(priority), m_closeReason(Notification::NONE), m_toReplace(old) { notificationCount++; - snoreDebug( SNORE_DEBUG )<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; + snoreDebug(SNORE_DEBUG) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; } 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; + snoreDebug(SNORE_DEBUG) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason; } - -void NotificationData::setActionInvoked (const Snore::Action &action ) +void NotificationData::setActionInvoked(const Snore::Action &action) { m_actionInvoked = action; } -void NotificationData::setActionInvoked ( const int &id) +void NotificationData::setActionInvoked(const int &id) { m_actionInvoked = m_actions[id]; } @@ -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); diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 653a368..e3381e5 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,33 +27,29 @@ #include #include - -namespace Snore{ - +namespace Snore +{ class SNORE_EXPORT NotificationData : public QSharedData { friend class Notification; public: - NotificationData ( const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon, - int timeout,Notification::Prioritys priority ); - - NotificationData(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout, Notification::Prioritys priority); + NotificationData(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, + int timeout, Notification::Prioritys priority); + NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority); ~NotificationData(); void setSource(class SnoreFrontend *source); class SnoreFrontend *source() const; - void setActionInvoked( const Action &action ); - void setActionInvoked( const int &actionID); - + void setActionInvoked(const Action &action); + void setActionInvoked(const int &actionID); void setCloseReason(Notification::CloseReasons r); - QTimer *timeoutTimer(); private: @@ -73,13 +67,11 @@ private: Notification::Prioritys m_priority; Notification::CloseReasons m_closeReason; Action m_actionInvoked; - QHash m_actions; + QHash m_actions; Hint m_hints; Notification m_toReplace; QPointer m_timeoutTimer; - - static uint notificationCount; static uint m_idCount; diff --git a/src/core/notification/notificationaction.cpp b/src/core/notification/notificationaction.cpp index 24b8ceb..42067b9 100644 --- a/src/core/notification/notificationaction.cpp +++ b/src/core/notification/notificationaction.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 @@ -49,7 +48,7 @@ int Action::id() const return m_id; } -QDataStream &operator<< ( QDataStream &stream, const Action &a) +QDataStream &operator<< (QDataStream &stream, const Action &a) { stream << a.id() << a.name(); return stream; diff --git a/src/core/notification/notificationaction.h b/src/core/notification/notificationaction.h index 884f82f..8e3c05a 100644 --- a/src/core/notification/notificationaction.h +++ b/src/core/notification/notificationaction.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 - namespace Snore { @@ -46,7 +44,7 @@ public: * @param id can be used to identify the action * @param name will be displayed in the notification system. */ - Action(int id,QString name); + Action(int id, QString name); /** * @@ -72,5 +70,5 @@ private: }; } -QDataStream &operator<< ( QDataStream & stream, const Snore::Action &action); +QDataStream &operator<< (QDataStream &stream, const Snore::Action &action); #endif // NOTIFICATIONACTION_H diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index 664c76e..1b57945 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,8 +32,7 @@ using namespace Snore; -QHash > PluginContainer::s_pluginCache; - +QHash > PluginContainer::s_pluginCache; PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type): m_pluginFile(fileName), @@ -52,12 +50,11 @@ PluginContainer::~PluginContainer() SnorePlugin *PluginContainer::load() { - if(!m_loader.isLoaded() && !m_loader.load()) - { - snoreDebug( SNORE_WARNING ) << "Failed loading plugin: " << m_loader.errorString(); + if (!m_loader.isLoaded() && !m_loader.load()) { + snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << m_loader.errorString(); return NULL; } - return qobject_cast ( m_loader.instance()); + return qobject_cast (m_loader.instance()); } void PluginContainer::unload() @@ -65,12 +62,12 @@ void PluginContainer::unload() m_loader.unload(); } -const QString & PluginContainer::file() +const QString &PluginContainer::file() { return m_pluginFile; } -const QString & PluginContainer::name() +const QString &PluginContainer::name() { return m_pluginName; } @@ -98,11 +95,9 @@ QString PluginContainer::typeToString(const SnorePlugin::PluginTypes t) const QList &PluginContainer::types() { static QList 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); } } @@ -111,66 +106,55 @@ const QList &PluginContainer::types() void PluginContainer::updatePluginCache() { - snoreDebug( SNORE_DEBUG ) << "Updating plugin cache"; - foreach(PluginContaienrHash list, s_pluginCache) - { - foreach(PluginContainer* p, list.values()) - { + snoreDebug(SNORE_DEBUG) << "Updating plugin cache"; + foreach(PluginContaienrHash list, s_pluginCache) { + foreach(PluginContainer * p, list.values()) { delete p; } list.clear(); } - QList plugins; + QList plugins; - foreach(const SnorePlugin::PluginTypes type,PluginContainer::types()) - { - foreach(const QFileInfo &file, pluginDir().entryInfoList( - QStringList(pluginFileFilters(type)), QDir::Files)) - { - snoreDebug( SNORE_DEBUG ) << "adding" << file.absoluteFilePath(); + foreach(const SnorePlugin::PluginTypes type, PluginContainer::types()) { + foreach(const QFileInfo & file, pluginDir().entryInfoList( + 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 - { - snoreDebug( SNORE_WARNING ) << "Failed loading plugin: " << file.absoluteFilePath() << loader.errorString(); + if (plugin == NULL) { //TODO: Qt5 json stuff + snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << file.absoluteFilePath() << loader.errorString(); continue; } - SnorePlugin *sp = qobject_cast(plugin); - if(sp == NULL) - { - snoreDebug( SNORE_WARNING ) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ; + SnorePlugin *sp = qobject_cast(plugin); + if (sp == NULL) { + snoreDebug(SNORE_WARNING) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ; loader.unload(); continue; } - PluginContainer *info = new PluginContainer(file.fileName(), sp->name() ,type); + PluginContainer *info = new PluginContainer(file.fileName(), sp->name() , type); s_pluginCache[type].insert(info->name(), info); plugins << info; - snoreDebug( SNORE_DEBUG ) << "added" << info->name() << "to cache"; + snoreDebug(SNORE_DEBUG) << "added" << info->name() << "to cache"; } } } const QHash PluginContainer::pluginCache(SnorePlugin::PluginTypes type) { - if(s_pluginCache.isEmpty()) - { + if (s_pluginCache.isEmpty()) { QTime time; time.start(); updatePluginCache(); - snoreDebug( SNORE_DEBUG ) << "Plugins loaded in:" << time.elapsed(); + snoreDebug(SNORE_DEBUG) << "Plugins loaded in:" << time.elapsed(); } QHash 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,26 +184,20 @@ 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 - { - snoreDebug( SNORE_DEBUG ) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins."; + } else { + snoreDebug(SNORE_DEBUG) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins."; } } - if(path.entryInfoList(pluginFileFilters()).isEmpty()) - { - snoreDebug( SNORE_WARNING ) << "Couldnt find any plugins"; + if (path.entryInfoList(pluginFileFilters()).isEmpty()) { + snoreDebug(SNORE_WARNING) << "Couldnt find any plugins"; } - snoreDebug( SNORE_INFO ) << "PluginPath is :" << path.absolutePath(); + snoreDebug(SNORE_INFO) << "PluginPath is :" << path.absolutePath(); } return path; } - diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index 9600d61..975a8e8 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,13 +26,11 @@ #include #include - - namespace Snore { class PluginContainer; -typedef QHash PluginContaienrHash; +typedef QHash PluginContaienrHash; class SNORE_EXPORT 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 &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 diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index 7955b21..914cedc 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,29 +30,27 @@ using namespace Snore; -SnorePlugin::SnorePlugin ( const QString &name ) : - m_name ( name ), +SnorePlugin::SnorePlugin(const QString &name) : + m_name(name), m_initialized(false) { - if(thread() != qApp->thread()) - { - moveToThread( qApp->thread() ); + if (thread() != qApp->thread()) { + moveToThread(qApp->thread()); } } SnorePlugin::~SnorePlugin() { - snoreDebug( SNORE_DEBUG ) << m_name << this << "deleted"; + snoreDebug(SNORE_DEBUG) << m_name << this << "deleted"; } -bool SnorePlugin::initialize( SnoreCore *snore ) +bool SnorePlugin::initialize(SnoreCore *snore) { - if(m_initialized) - { - qFatal("Something went wrong, plugin %s is already initialized",this->name().toLatin1().constData()); + if (m_initialized) { + qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData()); return false; } - snoreDebug( SNORE_DEBUG ) << "Initialize" << m_name << this << snore; + snoreDebug(SNORE_DEBUG) << "Initialize" << m_name << this << snore; this->m_snore = snore; m_initialized = true; return true; @@ -64,7 +61,7 @@ bool SnorePlugin::isInitialized() return m_initialized; } -SnoreCore* SnorePlugin::snore() +SnoreCore *SnorePlugin::snore() { return m_snore.data(); } @@ -76,33 +73,26 @@ const QString &SnorePlugin::name() const bool SnorePlugin::deinitialize() { - if(m_initialized) - { - snoreDebug( SNORE_DEBUG ) << "Deinitialize" << m_name << this; + if (m_initialized) { + snoreDebug(SNORE_DEBUG) << "Deinitialize" << m_name << this; m_initialized = false; return true; } 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; } diff --git a/src/core/plugins/plugins.h b/src/core/plugins/plugins.h index eb9e197..57549f5 100644 --- a/src/core/plugins/plugins.h +++ b/src/core/plugins/plugins.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,17 +26,16 @@ #include #include - -namespace Snore{ +namespace Snore +{ class Application; class SnoreCore; - class SNORE_EXPORT SnorePlugin : public QObject { Q_OBJECT public: - enum PluginType{ + enum PluginType { ALL = 0xFFFFF,//for loading plugins BACKEND = 0x1, SECONDARY_BACKEND = 0x2, @@ -47,13 +45,12 @@ public: Q_DECLARE_FLAGS(PluginTypes, PluginType) Q_ENUMS(PluginType) - - SnorePlugin ( const QString &name); + SnorePlugin(const QString &name); virtual ~SnorePlugin(); - virtual bool initialize( SnoreCore *snore ); + virtual bool initialize(SnoreCore *snore); virtual bool deinitialize(); bool isInitialized(); - SnoreCore* snore(); + SnoreCore *snore(); const QString &name() const; private: @@ -62,16 +59,14 @@ private: bool m_initialized; QPointer m_snore; - }; Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes) - } -Q_DECLARE_INTERFACE ( Snore::SnorePlugin, - "org.Snore.SnorePlugin/1.0" ) +Q_DECLARE_INTERFACE(Snore::SnorePlugin, + "org.Snore.SnorePlugin/1.0") -SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::SnorePlugin::PluginTypes &); +SNORE_EXPORT QDebug operator<< (QDebug, const Snore::SnorePlugin::PluginTypes &); //compatability defines to reduce the number of ifdefs to make fiat compile with qt4 and qt5 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) @@ -87,6 +82,4 @@ SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::SnorePlugin::PluginTypes & # define Q_PLUGIN_METADATA(a) #endif - - #endif//SNORE_PLUGINS_H diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 23a3ef6..b3e34dd 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,11 +29,10 @@ #include #include - using namespace Snore; -SnoreBackend::SnoreBackend (const QString &name , bool canCloseNotification, bool supportsRichtext, bool canUpdateNotifications) : - SnorePlugin ( name ), +SnoreBackend::SnoreBackend(const QString &name , bool canCloseNotification, bool supportsRichtext, bool canUpdateNotifications) : + SnorePlugin(name), m_canCloseNotification(canCloseNotification), m_supportsRichtext(supportsRichtext), m_canUpdateNotification(canUpdateNotifications) @@ -44,57 +42,49 @@ SnoreBackend::SnoreBackend (const QString &name , bool canCloseNotification, boo SnoreBackend::~SnoreBackend() { - snoreDebug( SNORE_DEBUG )<<"Deleting"<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); + 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 ) +void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason) { - if(canCloseNotification() && notification.isValid()) - { - closeNotification(notification,reason); + if (canCloseNotification() && notification.isValid()) { + closeNotification(notification, reason); slotCloseNotification(notification); } } 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); - snoreDebug( SNORE_DEBUG ) << n; + snoreDebug(SNORE_DEBUG) << n; emit notificationClosed(n); } @@ -117,24 +107,22 @@ SnoreSecondaryBackend::SnoreSecondaryBackend(const QString &name, bool supportsR SnoreSecondaryBackend::~SnoreSecondaryBackend() { - snoreDebug( SNORE_DEBUG )<<"Deleting"<d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection); + connect(snore->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)), Qt::QueuedConnection); return true; } bool SnoreSecondaryBackend::deinitialize() { - if(SnorePlugin::deinitialize()) - { - disconnect( snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification))); + if (SnorePlugin::deinitialize()) { + disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification))); return true; } return false; @@ -180,62 +168,52 @@ 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))); + disconnect(this, SIGNAL(notificationClosed(Snore::Notification)), snore()->d(), SLOT(slotNotificationClosed(Snore::Notification))); + disconnect(snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification))); return true; } return false; } - void SnoreBackend::startTimeout(Notification ¬ification) { - if(thread() != QThread::currentThread()) - { - metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification,notification)); + 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); - connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()), Qt::QueuedConnection); + connect(timer, SIGNAL(timeout()), this, SLOT(notificationTimedOut()), Qt::QueuedConnection); timer->start(); } void SnoreBackend::notificationTimedOut() { - QTimer *timer = qobject_cast(sender()); + QTimer *timer = qobject_cast(sender()); Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt()); - if(n.isValid()) - { - snoreDebug( SNORE_DEBUG ) << n; - snore()->requestCloseNotification(n,Notification::TIMED_OUT); + if (n.isValid()) { + snoreDebug(SNORE_DEBUG) << n; + snore()->requestCloseNotification(n, Notification::TIMED_OUT); } } diff --git a/src/core/plugins/snorebackend.h b/src/core/plugins/snorebackend.h index a74e83c..32d071d 100644 --- a/src/core/plugins/snorebackend.h +++ b/src/core/plugins/snorebackend.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 #include -namespace Snore{ +namespace Snore +{ class SNORE_EXPORT SnoreBackend : public SnorePlugin { @@ -39,7 +39,7 @@ public: virtual bool initialize(SnoreCore *snore); virtual bool deinitialize(); - void requestCloseNotification( Snore::Notification notification,Notification::CloseReasons reason ); + void requestCloseNotification(Snore::Notification notification, Notification::CloseReasons reason); Snore::Notification getActiveNotificationByID(uint id); @@ -48,14 +48,13 @@ public: bool supportsRichtext() const; signals: - void notificationClosed( Snore::Notification ); - + void notificationClosed(Snore::Notification); public slots: - virtual void slotRegisterApplication(const Snore::Application &application ); - virtual void slotDeregisterApplication(const Snore::Application &application ); - virtual void slotNotify ( Snore::Notification notification ) = 0; - virtual void slotCloseNotification ( Snore::Notification notification ); + virtual void slotRegisterApplication(const Snore::Application &application); + virtual void slotDeregisterApplication(const Snore::Application &application); + virtual void slotNotify(Snore::Notification notification) = 0; + virtual void slotCloseNotification(Snore::Notification notification); private slots: void notificationTimedOut(); @@ -64,11 +63,11 @@ protected slots: void startTimeout(Notification ¬ification); protected: - void closeNotification(Snore::Notification,Snore::Notification::CloseReasons); + void closeNotification(Snore::Notification, Snore::Notification::CloseReasons); void setSupportsRichtext(bool b); private: - QHash m_activeNotifications; + QHash m_activeNotifications; bool m_canCloseNotification; bool m_supportsRichtext; @@ -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" ) +Q_DECLARE_INTERFACE(Snore::SnoreBackend, + "org.Snore.NotificationBackend/1.0") -namespace Snore{ +namespace Snore +{ class SnoreCore; class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin @@ -97,11 +96,10 @@ public: virtual bool initialize(SnoreCore *snore); virtual bool deinitialize(); - bool supportsRichtext(); public slots: - virtual void slotNotify ( Snore::Notification notification ) = 0; + virtual void slotNotify(Snore::Notification notification) = 0; protected: bool m_supportsRichtext; @@ -110,7 +108,7 @@ protected: } -Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend, - "org.Snore.SecondaryNotificationBackend/1.0" ) +Q_DECLARE_INTERFACE(Snore::SnoreSecondaryBackend, + "org.Snore.SecondaryNotificationBackend/1.0") #endif//SNORE_BACKEND_H diff --git a/src/core/plugins/snorefrontend.cpp b/src/core/plugins/snorefrontend.cpp index cdbdcf8..29d0376 100644 --- a/src/core/plugins/snorefrontend.cpp +++ b/src/core/plugins/snorefrontend.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,17 +23,18 @@ #include #include -namespace Snore{ +namespace Snore +{ -SnoreFrontend::SnoreFrontend ( const QString &name ) : - SnorePlugin ( name ) +SnoreFrontend::SnoreFrontend(const QString &name) : + SnorePlugin(name) { } SnoreFrontend::~SnoreFrontend() { - snoreDebug( SNORE_DEBUG ) << "Deleting" << name(); + snoreDebug(SNORE_DEBUG) << "Deleting" << name(); } } diff --git a/src/core/plugins/snorefrontend.h b/src/core/plugins/snorefrontend.h index 8b15b31..2eba49c 100644 --- a/src/core/plugins/snorefrontend.h +++ b/src/core/plugins/snorefrontend.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,26 +25,26 @@ #include #include -namespace Snore{ +namespace Snore +{ class Application; class SnoreCore; class SnorePlugin; - -class SNORE_EXPORT SnoreFrontend:public SnorePlugin +class SNORE_EXPORT SnoreFrontend: public SnorePlugin { Q_OBJECT Q_INTERFACES(Snore::SnorePlugin) public: - SnoreFrontend ( const QString &name); + SnoreFrontend(const QString &name); virtual ~SnoreFrontend(); - virtual void actionInvoked( Snore::Notification notification ) = 0; - virtual void notificationClosed( Snore::Notification notification ) = 0; + virtual void actionInvoked(Snore::Notification notification) = 0; + virtual void notificationClosed(Snore::Notification notification) = 0; }; } -Q_DECLARE_INTERFACE ( Snore::SnoreFrontend, - "org.Snore.NotificationFrontend/1.0" ) +Q_DECLARE_INTERFACE(Snore::SnoreFrontend, + "org.Snore.NotificationFrontend/1.0") #endif//SNORE_FRONTEND_H diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 161eee7..da92c9f 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,11 +36,10 @@ using namespace Snore; - -SnoreCore::SnoreCore(QSystemTrayIcon *trayIcon ) +SnoreCore::SnoreCore(QSystemTrayIcon *trayIcon) { SnoreCorePrivate::registerMetaTypes(); - d_ptr = new SnoreCorePrivate(trayIcon ); + d_ptr = new SnoreCorePrivate(trayIcon); Q_D(SnoreCore); d->q_ptr = this; } @@ -52,76 +50,67 @@ SnoreCore::~SnoreCore() d->deleteLater(); } -void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types ) +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; } break; default: - snoreDebug( SNORE_WARNING ) << "Plugin Cache corrupted\n" << info->file() << info->type(); + snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type(); continue; } - snoreDebug( SNORE_DEBUG ) << info->name() << "is a" << info->type(); + snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type(); d->m_plugins[info->type()].append(info->name()); } - if(d->m_plugins.contains(type)) - { + if (d->m_plugins.contains(type)) { qSort(d->m_plugins[type]); } } } - snoreDebug( SNORE_INFO ) << "Loaded Plugins:" << d->m_plugins; + snoreDebug(SNORE_INFO) << "Loaded Plugins:" << d->m_plugins; } -void SnoreCore::broadcastNotification ( Notification notification ) +void SnoreCore::broadcastNotification(Notification notification) { Q_D(SnoreCore); - snoreDebug( SNORE_DEBUG )<<"Broadcasting"<m_notificationBackend != NULL ) - { - if(notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) - { - requestCloseNotification(notification.old(),Notification::REPLACED); + snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout(); + if (d->m_notificationBackend != NULL) { + if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) { + requestCloseNotification(notification.old(), Notification::REPLACED); } d->m_notificationBackend->addActiveNotification(notification); } - emit d->notify ( notification ); + emit d->notify(notification); } void SnoreCore::registerApplication(const Application &application) { Q_D(SnoreCore); - if(!d->m_applications.contains(application.name())) - { - snoreDebug( SNORE_DEBUG ) << "Registering Application:" << application; - d->m_applications.insert ( application.name(),application ); - emit d->applicationRegistered ( application ); + if (!d->m_applications.contains(application.name())) { + snoreDebug(SNORE_DEBUG) << "Registering Application:" << application; + d->m_applications.insert(application.name(), application); + emit d->applicationRegistered(application); } } void SnoreCore::deregisterApplication(const Application &application) { Q_D(SnoreCore); - emit d->applicationDeregistered (application ); - d->m_applications.take ( application.name() ); + emit d->applicationDeregistered(application); + d->m_applications.take(application.name()); } const QHash &SnoreCore::aplications() const @@ -130,7 +119,6 @@ const QHash &SnoreCore::aplications() const return d->m_applications; } - const QStringList SnoreCore::notificationBackends() const { Q_D(const SnoreCore); @@ -149,31 +137,26 @@ const QStringList SnoreCore::secondaryNotificationBackends() const return d->m_plugins.value(SnorePlugin::SECONDARY_BACKEND); } -bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend ) +bool SnoreCore::setPrimaryNotificationBackend(const QString &backend) { Q_D(SnoreCore); - if(backend == primaryNotificationBackend()) - { + if (backend == primaryNotificationBackend()) { return true; } - const QHash backends = PluginContainer::pluginCache(SnorePlugin::BACKEND); - if(!backends.contains(backend)) - { - snoreDebug( SNORE_DEBUG ) << "Unknown Backend:" << backend; + const QHash backends = PluginContainer::pluginCache(SnorePlugin::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(backends.value(backend)->load()); - if(!b->isInitialized()) - { - if(!b->initialize(this)) - { - snoreDebug( SNORE_DEBUG ) << "Failed to initialize" << b->name(); + snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend; + SnoreBackend *b = qobject_cast(backends.value(backend)->load()); + 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,9 +213,8 @@ QSystemTrayIcon *SnoreCore::trayIcon(){ Notification SnoreCore::getActiveNotificationByID(uint id) { Q_D(SnoreCore); - if(!d->m_notificationBackend->isInitialized()) - { - qFatal("Notification backend %s isn't initialized will snore will exit now",d->m_notificationBackend->name().toLatin1().constData()); + 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); } @@ -247,7 +222,7 @@ Notification SnoreCore::getActiveNotificationByID(uint id) void SnoreCore::requestCloseNotification(Notification n, Notification::CloseReasons r) { Q_D(SnoreCore); - d->m_notificationBackend->requestCloseNotification(n,r); + d->m_notificationBackend->requestCloseNotification(n, r); } bool SnoreCore::primaryBackendSupportsRichtext() diff --git a/src/core/snore.h b/src/core/snore.h index 6bf98fa..4cbdad3 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 \ */ -namespace Snore{ +namespace Snore +{ class SnoreCorePrivate; /** @@ -66,7 +65,7 @@ public: * Creates a Notification Manager SnoreCore * @param trayIcon a QSystemTrayIcon which can later be used by the fallback notification backend. */ - SnoreCore (QSystemTrayIcon *trayIcon = NULL ); + SnoreCore(QSystemTrayIcon *trayIcon = NULL); ~SnoreCore(); /** @@ -74,14 +73,13 @@ public: * * @param types the type of tha plugin */ - void loadPlugins ( SnorePlugin::PluginTypes types ); - + void loadPlugins(SnorePlugin::PluginTypes types); /** * Broadcast a notification. * @param notification the Notification */ - void broadcastNotification( Notification notification ); + void broadcastNotification(Notification notification); /** * Register an application. @@ -91,7 +89,7 @@ public: * @see broadcastNotification * @param application the application */ - void registerApplication(const Application &application ); + void registerApplication(const Application &application); /** * Deregisters an application. @@ -101,7 +99,7 @@ public: * @see setPrimaryNotificationBackend * @param application the application */ - void deregisterApplication(const Application &application ); + void deregisterApplication(const Application &application); /** * @@ -133,7 +131,7 @@ public: * @param backend the name of the backend * @return whether the backend was initialied succesfully. */ - bool setPrimaryNotificationBackend( const QString &backend ); + bool setPrimaryNotificationBackend(const QString &backend); /** * Tries to set one of all backends availible on this platform as backend. @@ -165,7 +163,7 @@ public: * Try to close a Notification if the backend supports the action. * @see SnoreBackend::canCloseNotification */ - void requestCloseNotification(Notification,Notification::CloseReasons); + void requestCloseNotification(Notification, Notification::CloseReasons); /** * @@ -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. @@ -189,18 +185,17 @@ signals: * @todo maybe introduce a pecial action state for this case * @see Action */ - void actionInvoked( Snore::Notification ); + void actionInvoked(Snore::Notification); /** * This signal is emitted when a Notification is closed. * @see Notification::CloseReasons */ - void notificationClosed(Snore::Notification ); + void notificationClosed(Snore::Notification); private: SnoreCorePrivate *d_ptr; - }; /** @@ -209,14 +204,11 @@ private: * @return if the string was rhichtext or html encoded a decoded string, else the original string. */ -static inline QString toPlainText ( const QString &string) +static inline QString toPlainText(const QString &string) { - if(Qt::mightBeRichText(string)) - { + if (Qt::mightBeRichText(string)) { return QTextDocumentFragment::fromHtml(string).toPlainText(); - } - else - { + } else { return string; } } diff --git a/src/core/snore_p.cpp b/src/core/snore_p.cpp index 9f2f0a5..b7ecc75 100644 --- a/src/core/snore_p.cpp +++ b/src/core/snore_p.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 . */ - #include "snore_p.h" #include "snore.h" #include "plugins/plugins.h" @@ -36,17 +34,16 @@ using namespace Snore; SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon): m_trayIcon(trayIcon), - m_defaultApp("SnoreNotify",Icon(":/root/snore.png")) + m_defaultApp("SnoreNotify", Icon(":/root/snore.png")) { - snoreDebug( SNORE_INFO ) << "Version:" << Version::version(); - if( !Version::revision().isEmpty() ) - { - snoreDebug( SNORE_INFO ) << "Revision:" << Version::revision(); + snoreDebug(SNORE_INFO) << "Version:" << Version::version(); + if (!Version::revision().isEmpty()) { + snoreDebug(SNORE_INFO) << "Revision:" << Version::revision(); } - snoreDebug( SNORE_DEBUG ) << "Temp dir is" << tempPath(); + snoreDebug(SNORE_DEBUG) << "Temp dir is" << tempPath(); - m_defaultApp.addAlert(Alert("Default",Icon(":/root/snore.png"))); + m_defaultApp.addAlert(Alert("Default", Icon(":/root/snore.png"))); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit())); } @@ -63,18 +60,16 @@ const Application SnoreCorePrivate::defaultApplication() const void SnoreCorePrivate::notificationActionInvoked(Notification notification) const { Q_Q(const SnoreCore); - emit const_cast(q)->actionInvoked(notification); - if ( notification.data()->source() ) - { - notification.data()->source()->actionInvoked ( notification ); + emit const_cast(q)->actionInvoked(notification); + if (notification.data()->source()) { + notification.data()->source()->actionInvoked(notification); } } 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,19 +100,16 @@ 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()) - { - snoreDebug( SNORE_DEBUG ) << "deinitialize" << p->name(); + foreach(PluginContainer * p, PluginContainer::pluginCache(SnorePlugin::ALL)) { + if (p->isLoaded()) { + snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name(); p->load()->deinitialize(); } } diff --git a/src/core/snore_p.h b/src/core/snore_p.h index a35c302..14d9a6d 100644 --- a/src/core/snore_p.h +++ b/src/core/snore_p.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2014 Patrick von Reth - 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 . */ - #ifndef SNORECOREPRIVATE_H #define SNORECOREPRIVATE_H @@ -38,7 +36,7 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject public: static inline QString computeHash(const QByteArray &data) { - return QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex(); + return QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex(); } static void registerMetaTypes(); @@ -54,11 +52,9 @@ public: ~SnoreCorePrivate(); const Application defaultApplication() const; - void notificationActionInvoked(Notification notification) const; - bool setBackendIfAvailible(const QString & backend); - + bool setBackendIfAvailible(const QString &backend); /** * @@ -67,8 +63,8 @@ public: bool primaryBackendCanUpdateNotification() const; signals: - void applicationRegistered(const Snore::Application&); - void applicationDeregistered(const Snore::Application&); + void applicationRegistered(const Snore::Application &); + void applicationDeregistered(const Snore::Application &); void notify(Snore::Notification noti); private slots: @@ -78,7 +74,7 @@ private slots: private: SnoreCore *q_ptr; - QHash m_applications; + QHash m_applications; QHash m_plugins; diff --git a/src/core/version.h b/src/core/version.h index d2d680d..4cf3f3e 100644 --- a/src/core/version.h +++ b/src/core/version.h @@ -7,7 +7,8 @@ #include -namespace Snore{ +namespace Snore +{ /** * Version contains relevant version informations. diff --git a/src/main.cpp b/src/main.cpp index 8cc1d28..53116c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,9 +5,9 @@ #include -int main ( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - QApplication app ( argc, argv ); + QApplication app(argc, argv); app.setApplicationName("SnoreNotify"); app.setOrganizationName("SnoreNotify"); app.setApplicationVersion(Snore::Version::version()); diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.cpp b/src/plugins/backends/freedesktop/fredesktopnotification.cpp index 0241950..cd0a091 100644 --- a/src/plugins/backends/freedesktop/fredesktopnotification.cpp +++ b/src/plugins/backends/freedesktop/fredesktopnotification.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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 #include - int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType(); - FreedesktopImageHint::FreedesktopImageHint() { @@ -34,43 +31,45 @@ FreedesktopImageHint::FreedesktopImageHint() FreedesktopImageHint::FreedesktopImageHint(const QImage &img) { QImage image(img.convertToFormat(QImage::Format_ARGB32)); - imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes()); + imageData = QByteArray((char *)image.rgbSwapped().bits(), image.numBytes()); width = image.width(); height = image.height(); rowstride = image.bytesPerLine(); hasAlpha = image.hasAlphaChannel(); - channels = hasAlpha?4:3; - bitsPerSample = image.depth()/channels; + channels = hasAlpha ? 4 : 3; + bitsPerSample = image.depth() / channels; } - -QImage FreedesktopImageHint::toQImage() const { - return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped(); +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 << - i.rowstride << - i.hasAlpha << - i.bitsPerSample << - i.channels << - i.imageData; + i.height << + i.rowstride << + i.hasAlpha << + i.bitsPerSample << + i.channels << + i.imageData; a.endStructure(); 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 >> - i.rowstride >> - i.hasAlpha >> - i.bitsPerSample >> - i.channels >> - i.imageData; + i.height >> + i.rowstride >> + i.hasAlpha >> + i.bitsPerSample >> + i.channels >> + i.imageData; a.endStructure(); return a; } diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.h b/src/plugins/backends/freedesktop/fredesktopnotification.h index ebafd64..1641b85 100644 --- a/src/plugins/backends/freedesktop/fredesktopnotification.h +++ b/src/plugins/backends/freedesktop/fredesktopnotification.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,10 +24,9 @@ #include #include - class FreedesktopImageHint { -public: +public: FreedesktopImageHint(); FreedesktopImageHint(const QImage &img); QImage toQImage()const; @@ -44,12 +42,11 @@ public: private: static int imageHintID; - }; Q_DECLARE_METATYPE(FreedesktopImageHint); QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i); -const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ; +const QDBusArgument &operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ; #endif // FreedesktopNotification_H diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index 5e08219..80defe3 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -10,27 +10,25 @@ #include "fredesktopnotification.h" #include "core/snore.h" - using namespace Snore; -Q_EXPORT_PLUGIN2 ( libsnore_backend_freedesktop,FreedesktopBackend ) +Q_EXPORT_PLUGIN2(libsnore_backend_freedesktop, FreedesktopBackend) - -FreedesktopBackend::FreedesktopBackend () : - SnoreBackend ( "FreedesktopNotification", true, true, true) +FreedesktopBackend::FreedesktopBackend() : + SnoreBackend("FreedesktopNotification", true, true, true) { } bool FreedesktopBackend::initialize(SnoreCore *snore) { - m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", - QDBusConnection::sessionBus(), this ); + m_interface = new org::freedesktop::Notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this); QDBusPendingReply reply = m_interface->GetCapabilities(); reply.waitForFinished(); QStringList caps = reply.value(); - setSupportsRichtext(caps.contains( "body-markup" )); + setSupportsRichtext(caps.contains("body-markup")); connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString))); connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint))); @@ -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(); @@ -50,76 +47,66 @@ bool FreedesktopBackend::deinitialize() return false; } -void FreedesktopBackend::slotNotify ( Notification noti ) -{ +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) - { - hints["urgency"] = (char)noti.priority()+1; + 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 id = m_interface->Notify(noti.application().name(), updateId, "", title, - body, actions, hints, noti.isSticky()?-1:noti.timeout()*1000); - + body, actions, hints, noti.isSticky() ? -1 : noti.timeout() * 1000); id.waitForFinished(); noti.hints().setPrivateValue(this, "id", id.value()); m_dbusIdMap[id.value()] = noti.id(); - snoreDebug( SNORE_DEBUG ) << noti.id() << "|" << id.value(); + snoreDebug(SNORE_DEBUG) << noti.id() << "|" << id.value(); } void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID) { - snoreDebug( SNORE_DEBUG ) << id << m_dbusIdMap[id]; + 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() ); - snore()->d()->notificationActionInvoked ( noti ); + noti.data()->setActionInvoked(actionID.toInt()); + snore()->d()->notificationActionInvoked(noti); } -void FreedesktopBackend::slotCloseNotification ( Notification notification ) +void FreedesktopBackend::slotCloseNotification(Notification notification) { uint id = notification.hints().privateValue(this, "id").toUInt(); - snoreDebug( SNORE_DEBUG ) << notification.id() << id; + snoreDebug(SNORE_DEBUG) << notification.id() << id; m_interface->CloseNotification(id); } - - -void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) +void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reason) { /* * @@ -134,33 +121,27 @@ void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &rea * 4 - Undefined/reserved reasons. */ Notification::CloseReasons closeReason; - switch(reason) - { - case(1): + switch (reason) { + case (1): closeReason = Notification::TIMED_OUT; break; - case(2): + case (2): closeReason = Notification::DISMISSED; break; - case(3): + case (3): closeReason = Notification::CLOSED; break; default: closeReason = Notification::NONE; } - snoreDebug( SNORE_DEBUG ) << id << "|" << closeReason << reason; - if(id == 0) - { + snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason; + if (id == 0) { return; } Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id)); - if(noti.isValid()) - { + if (noti.isValid()) { closeNotification(noti, closeReason); } } - - - diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h index 716dcbb..e5954ab 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h @@ -3,28 +3,26 @@ #include "core/plugins/snorebackend.h" #include "notificationinterface.h" -class FreedesktopBackend:public Snore::SnoreBackend +class FreedesktopBackend: public Snore::SnoreBackend { Q_OBJECT - Q_INTERFACES ( Snore::SnoreBackend ) + Q_INTERFACES(Snore::SnoreBackend) Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") public: FreedesktopBackend(); virtual bool initialize(Snore::SnoreCore *snore); virtual bool deinitialize(); - + public slots: - void slotNotify( Snore::Notification notification ); - void slotCloseNotification ( Snore::Notification notification ); - - void slotActionInvoked(const uint &id,const QString &actionID); - void slotNotificationClosed ( const uint &id,const uint &reason ); + void slotNotify(Snore::Notification notification); + void slotCloseNotification(Snore::Notification notification); + void slotActionInvoked(const uint &id, const QString &actionID); + void slotNotificationClosed(const uint &id, const uint &reason); private: - org::freedesktop::Notifications* m_interface; - QHash m_dbusIdMap; - + org::freedesktop::Notifications *m_interface; + QHash m_dbusIdMap; }; diff --git a/src/plugins/backends/growl/growlbackend.cpp b/src/plugins/backends/growl/growlbackend.cpp index 2101864..f086470 100644 --- a/src/plugins/backends/growl/growlbackend.cpp +++ b/src/plugins/backends/growl/growlbackend.cpp @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,18 +21,17 @@ #include "core/snore.h" #include "core/snore_p.h" - #include #include using namespace Snore; -Q_EXPORT_PLUGIN2(libsnore_backend_growl,GrowlBackend) +Q_EXPORT_PLUGIN2(libsnore_backend_growl, GrowlBackend) GrowlBackend *GrowlBackend::s_instance = NULL; GrowlBackend::GrowlBackend(): - SnoreBackend("Growl",false,false), + SnoreBackend("Growl", false, false), m_id(0) { s_instance = this; @@ -45,18 +43,16 @@ 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"; + snoreDebug(SNORE_DEBUG) << "Growl is not running"; return false; } bool GrowlBackend::deinitialize() { - if(!Growl::shutdown()) - { + if (!Growl::shutdown()) { return false; } s_instance = NULL; @@ -67,23 +63,21 @@ void GrowlBackend::slotRegisterApplication(const Application &application) { // snoreDebug( SNORE_DEBUG ) << application.name().toUtf8().constData(); std::vector alerts; - foreach(const Alert &a,application.alerts()) - { - snoreDebug( SNORE_DEBUG ) << a.name().toUtf8().constData(); + foreach(const Alert & a, application.alerts()) { + snoreDebug(SNORE_DEBUG) << a.name().toUtf8().constData(); alerts.push_back(a.name().toUtf8().constData()); } Growl *growl = new Growl(GROWL_TCP, "", application.name().toUtf8().constData()); - growl->Register(alerts,application.icon().localUrl().toUtf8().constData()); + growl->Register(alerts, application.icon().localUrl().toUtf8().constData()); - m_applications.insert(application.name(),growl); + m_applications.insert(application.name(), growl); } void GrowlBackend::slotDeregisterApplication(const Application &application) { Growl *growl = m_applications.take(application.name()); - if(growl == NULL) - { + if (growl == NULL) { return; } delete growl; @@ -93,49 +87,40 @@ void GrowlBackend::slotNotify(Notification notification) { Growl *growl = m_applications.value(notification.application().name()); QString alert = notification.alert().name(); - snoreDebug( SNORE_DEBUG ) << "Notify Growl:" <Notify(data); - startTimeout(notification); } void GrowlBackend::gntpCallback(growl_callback_data *data) { - if(s_instance) - { - snoreDebug( SNORE_DEBUG ) << data->id << QString(data->reason) << QString(data->data); + 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); } - s_instance->closeNotification(n,r); + s_instance->closeNotification(n, r); } } diff --git a/src/plugins/backends/growl/growlbackend.h b/src/plugins/backends/growl/growlbackend.h index 82fdfd0..83c1d75 100644 --- a/src/plugins/backends/growl/growlbackend.h +++ b/src/plugins/backends/growl/growlbackend.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,7 @@ #include "growl.hpp" #include -class GrowlBackend:public Snore::SnoreBackend +class GrowlBackend: public Snore::SnoreBackend { Q_OBJECT Q_INTERFACES(Snore::SnoreBackend) @@ -35,14 +34,14 @@ public: ~GrowlBackend(); virtual bool initialize(Snore::SnoreCore *snore); virtual bool deinitialize(); - + static void gntpCallback(growl_callback_data *data); private: - //a static instance for the static callback methode + //a static instance for the static callback methode static GrowlBackend *s_instance; uint m_id; - QHash m_applications; + QHash m_applications; public slots: void slotRegisterApplication(const Snore::Application &application); @@ -50,5 +49,4 @@ public slots: void slotNotify(Snore::Notification notification); }; - #endif // GROWL_BACKEND_H diff --git a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h index 7a2bb94..605c061 100644 --- a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h +++ b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h @@ -2,7 +2,6 @@ SnoreNotify is a Notification Framework based on Qt Copyright (C) 2013-2014 Patrick von Reth - 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,13 +28,12 @@ class OSXNotificationCenter : public Snore::SnoreBackend Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") public: - OSXNotificationCenter(); - ~OSXNotificationCenter(); - virtual bool initialize(Snore::SnoreCore *snore); + OSXNotificationCenter(); + ~OSXNotificationCenter(); + virtual bool initialize(Snore::SnoreCore *snore); public slots: - virtual void slotNotify (Snore::Notification notification); + virtual void slotNotify(Snore::Notification notification); }; - #endif // OSXNOTIFICATIONCENTER_H diff --git a/src/plugins/backends/snarl/SnarlInterface.cpp b/src/plugins/backends/snarl/SnarlInterface.cpp index a3b3557..fc04c66 100644 --- a/src/plugins/backends/snarl/SnarlInterface.cpp +++ b/src/plugins/backends/snarl/SnarlInterface.cpp @@ -51,21 +51,20 @@ #include "SnarlInterface.h" - -namespace Snarl { -namespace V42 { - +namespace Snarl +{ +namespace V42 +{ // workaround for mingw-w64 bug #ifdef __MINGW64_VERSION_MAJOR - extern "C" { - __declspec(dllimport) errno_t __cdecl strcpy_s(char * _Dst, size_t _SizeInBytes, const char *_Src); - __declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t * _Dst, size_t _SizeInBytes, const wchar_t *_Src); - __declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount); - } +extern "C" { + __declspec(dllimport) errno_t __cdecl strcpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src); + __declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t *_Dst, size_t _SizeInBytes, const wchar_t *_Src); + __declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount); +} #endif //__MINGW64_VERSION_MAJOR - // ---------------------------------------------------------------------------- // Static Snarl interface functions // ---------------------------------------------------------------------------- @@ -85,30 +84,31 @@ 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; cds.dwData = 0x534E4C03; // "SNL",3 cds.cbData = (DWORD)strlen(request); // No knowledge of max string lenght - cds.lpData = const_cast(request); + cds.lpData = const_cast(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); @@ -127,16 +128,14 @@ LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout) return nResult; } -std::basic_string& SnarlInterface::Escape(std::basic_string& str) +std::basic_string &SnarlInterface::Escape(std::basic_string &str) { std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { + for (std::basic_string::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; } @@ -145,16 +144,14 @@ std::basic_string& SnarlInterface::Escape(std::basic_string& str) return str; } -std::basic_string& SnarlInterface::Escape(std::basic_string& str) +std::basic_string &SnarlInterface::Escape(std::basic_string &str) { std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { + for (std::basic_string::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,15 +163,13 @@ std::basic_string& SnarlInterface::Escape(std::basic_string& 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); + int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH - 1); if (nReturn > 0) { - TCHAR* strReturn = AllocateString(nReturn + 1); + TCHAR *strReturn = AllocateString(nReturn + 1); _tcsncpy(strReturn, strTmp, nReturn + 1); strReturn[nReturn] = 0; return strReturn; @@ -187,15 +182,15 @@ LPCTSTR SnarlInterface::GetAppPath() LPCTSTR SnarlInterface::GetIconsPath() { - TCHAR* szIconPath = NULL; + 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=|token=][&password=]&id=&name=[&enabled=<0|1>][&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=|app-sig=&uid=][&password=] @@ -321,7 +317,6 @@ LONG32 SnarlInterface::ClearActions(LONG32 msgToken) return DoRequest(Requests::ClearActionsA(), spl); } - LONG32 SnarlInterface::ClearClasses() { // clearclasses?[token=app-sig=|token=][&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=|app-sig=&uid=][&password=] @@ -351,7 +344,6 @@ LONG32 SnarlInterface::Hide(LONG32 msgToken) return DoRequest(Requests::HideA(), spl); } - LONG32 SnarlInterface::IsVisible(LONG32 msgToken) { // isvisible?[token=|app-sig=&uid=][&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=|token=][&password=][&id=] @@ -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=&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,30 +586,26 @@ LONG32 SnarlInterface::UpdateApp(LPCWSTR title, LPCWSTR icon) return DoRequest(Requests::UpdateAppW(), spl); }*/ - //----------------------------------------------------------------------------- // Private functions //----------------------------------------------------------------------------- -LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char>& spl, UINT replyTimeout) +LONG32 SnarlInterface::DoRequest(LPCSTR request, SnarlParameterList<char> &spl, UINT replyTimeout) { // <action>[?<data>=<value>[&<data>=<value>]] - const std::vector<SnarlParameterList<char>::PairType>&list = spl.GetList(); + const std::vector<SnarlParameterList<char>::PairType> &list = spl.GetList(); - if (list.size() > 0) - { + if (list.size() > 0) { std::string requestStr = request; 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) - { - std::basic_string<char>& value = const_cast<std::basic_string<char>&>(iter->second); + 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,28 +614,25 @@ 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) +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(); + 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) - { - std::basic_string<wchar_t>& value = const_cast<std::basic_string<wchar_t>&>(iter->second); + 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 diff --git a/src/plugins/backends/snarl/SnarlInterface.h b/src/plugins/backends/snarl/SnarlInterface.h index 0d3c00a..a6479c9 100644 --- a/src/plugins/backends/snarl/SnarlInterface.h +++ b/src/plugins/backends/snarl/SnarlInterface.h @@ -2,7 +2,7 @@ #define SNARL_INTERFACE_V42_H #if defined(__MINGW32__) && !defined(MINGW_HAS_SECURE_API) - #define MINGW_HAS_SECURE_API +#define MINGW_HAS_SECURE_API #endif #include <tchar.h> @@ -11,397 +11,490 @@ #include <vector> #include <sstream> - #ifndef SMTO_NOTIMEOUTIFNOTHUNG - #define SMTO_NOTIMEOUTIFNOTHUNG 8 +#define SMTO_NOTIMEOUTIFNOTHUNG 8 #endif +namespace Snarl +{ +namespace V42 +{ -namespace Snarl { - namespace V42 { +static LPCTSTR SnarlWindowClass = _T("w>Snarl"); +static LPCTSTR SnarlWindowTitle = _T("Snarl"); - static LPCTSTR SnarlWindowClass = _T("w>Snarl"); - static LPCTSTR SnarlWindowTitle = _T("Snarl"); +static LPCTSTR SnarlGlobalMsg = _T("SnarlGlobalEvent"); +static LPCTSTR SnarlAppMsg = _T("SnarlAppMessage"); - static LPCTSTR SnarlGlobalMsg = _T("SnarlGlobalEvent"); - static LPCTSTR SnarlAppMsg = _T("SnarlAppMessage"); +static const DWORD WM_SNARLTEST = WM_USER + 237; - static const DWORD WM_SNARLTEST = WM_USER + 237; +/// <summary>Application requests - these values appear in wParam.<para>Application should launch its settings UI</para></summary> +static const WPARAM AppDoPrefs = 1; +/// <summary>Application requests - these values appear in wParam.<para>Application should show its About... dialog</para></summary> +static const WPARAM AppDoAbout = 2; - /// <summary>Application requests - these values appear in wParam.<para>Application should launch its settings UI</para></summary> - static const WPARAM AppDoPrefs = 1; - /// <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 +{ +/// <summary> +/// Global event identifiers - sent as Windows broadcast messages. +/// These values appear in wParam of the message. +/// </summary> +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 +}; - // Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :( - namespace SnarlEnums { +enum SnarlStatus { + Success = 0, - /// <summary> - /// Global event identifiers - sent as Windows broadcast messages. - /// These values appear in wParam of the message. - /// </summary> - 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 - }; + // Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code, + // but are sent directly to a registered window, so in C# they are defined here instead. + // Implemented as of Snarl R2.4 Beta3 + SnarlStopped = 3, // Sent when stopped by user - Also sent as broadcast message + SnarlStarted, // Sent when started by user - Also sent as broadcast message + SnarlUserAway, // Away mode was enabled + SnarlUserBack, // Away mode was disabled - enum SnarlStatus - { - Success = 0, + // Win32 callbacks (renamed under V42) + CallbackRightClick = 32, // Deprecated as of V42, ex. SNARL_NOTIFICATION_CLICKED/SNARL_NOTIFICATION_CANCELLED + CallbackTimedOut, + CallbackInvoked, // left clicked and no default callback assigned + CallbackMenuSelected, // HIWORD(wParam) contains 1-based menu item index + CallbackMiddleClick, // Deprecated as of V42 + CallbackClosed, - // Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code, - // but are sent directly to a registered window, so in C# they are defined here instead. - // Implemented as of Snarl R2.4 Beta3 - SnarlStopped = 3, // Sent when stopped by user - Also sent as broadcast message - SnarlStarted, // Sent when started by user - Also sent as broadcast message - SnarlUserAway, // Away mode was enabled - SnarlUserBack, // Away mode was disabled + // critical errors + ErrorFailed = 101, // miscellaneous failure + ErrorUnknownCommand, // specified command not recognised + ErrorTimedOut, // Snarl took too long to respond + //104 gen critical #4 + //105 gen critical #5 + ErrorBadSocket = 106, // invalid socket (or some other socket-related error) + ErrorBadPacket = 107, // badly formed request + ErrorInvalidArg = 108, // arg supplied was invalid (Added in v42.56) + ErrorArgMissing = 109, // required argument missing + ErrorSystem, // internal system error + //120 libsnarl critical block + ErrorAccessDenied = 121, // libsnarl only + //130 SNP/3.0-specific + ErrorUnsupportedVersion = 131, // requested SNP version is not supported + ErrorNoActionsProvided, // empty request + ErrorUnsupportedEncryption, // requested encryption type is not supported + ErrorUnsupportedHashing, // requested message hashing type is not supported - // Win32 callbacks (renamed under V42) - CallbackRightClick = 32, // Deprecated as of V42, ex. SNARL_NOTIFICATION_CLICKED/SNARL_NOTIFICATION_CANCELLED - CallbackTimedOut, - CallbackInvoked, // left clicked and no default callback assigned - CallbackMenuSelected, // HIWORD(wParam) contains 1-based menu item index - CallbackMiddleClick, // Deprecated as of V42 - CallbackClosed, + // warnings + ErrorNotRunning = 201, // Snarl handling window not found + ErrorNotRegistered, + ErrorAlreadyRegistered, // not used yet; sn41RegisterApp() returns existing token + ErrorClassAlreadyExists, // not used yet + ErrorClassBlocked, + ErrorClassNotFound, + ErrorNotificationNotFound, + ErrorFlooding, // notification generated by same class within quantum + ErrorDoNotDisturb, // DnD mode is in effect was not logged as missed + ErrorCouldNotDisplay, // not enough space on-screen to display notification + ErrorAuthFailure, // password mismatch + // Release 2.4.2 + ErrorDiscarded, // discarded for some reason, e.g. foreground app match + ErrorNotSubscribed, // subscriber not found - // critical errors - ErrorFailed = 101, // miscellaneous failure - ErrorUnknownCommand, // specified command not recognised - ErrorTimedOut, // Snarl took too long to respond - //104 gen critical #4 - //105 gen critical #5 - ErrorBadSocket = 106, // invalid socket (or some other socket-related error) - ErrorBadPacket = 107, // badly formed request - ErrorInvalidArg = 108, // arg supplied was invalid (Added in v42.56) - ErrorArgMissing = 109, // required argument missing - ErrorSystem, // internal system error - //120 libsnarl critical block - ErrorAccessDenied = 121, // libsnarl only - //130 SNP/3.0-specific - ErrorUnsupportedVersion = 131, // requested SNP version is not supported - ErrorNoActionsProvided, // empty request - ErrorUnsupportedEncryption, // requested encryption type is not supported - ErrorUnsupportedHashing, // requested message hashing type is not supported + // informational + // code 250 reserved for future use + WasMerged = 251, // notification was merged, returned token is the one we merged with - // warnings - ErrorNotRunning = 201, // Snarl handling window not found - ErrorNotRegistered, - ErrorAlreadyRegistered, // not used yet; sn41RegisterApp() returns existing token - ErrorClassAlreadyExists, // not used yet - ErrorClassBlocked, - ErrorClassNotFound, - ErrorNotificationNotFound, - ErrorFlooding, // notification generated by same class within quantum - ErrorDoNotDisturb, // DnD mode is in effect was not logged as missed - ErrorCouldNotDisplay, // not enough space on-screen to display notification - ErrorAuthFailure, // password mismatch - // Release 2.4.2 - ErrorDiscarded, // discarded for some reason, e.g. foreground app match - ErrorNotSubscribed, // subscriber not found + // callbacks + // code 300 reserved for future use + NotifyGone = 301, // reserved for future use - // informational - // code 250 reserved for future use - WasMerged = 251, // notification was merged, returned token is the one we merged with + // The following are currently specific to SNP 2.0 and are effectively the + // Win32 SNARL_CALLBACK_nnn constants with 270 added to them - // callbacks - // code 300 reserved for future use - NotifyGone = 301, // reserved for future use + // SNARL_NOTIFY_CLICK = 302 // indicates notification was right-clicked (deprecated as of V42) + NotifyExpired = 303, + NotifyInvoked = 304, // note this was "ACK" in a previous life + NotifyMenu, // indicates an item was selected from user-defined menu (deprecated as of V42) + // SNARL_NOTIFY_EX_CLICK // user clicked the middle mouse button (deprecated as of V42) + NotifyClosed = 307, // // user clicked the notification's close gadget (GNTP only) - // The following are currently specific to SNP 2.0 and are effectively the - // Win32 SNARL_CALLBACK_nnn constants with 270 added to them + // 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 - // SNARL_NOTIFY_CLICK = 302 // indicates notification was right-clicked (deprecated as of V42) - NotifyExpired = 303, - NotifyInvoked = 304, // note this was "ACK" in a previous life - NotifyMenu, // indicates an item was selected from user-defined menu (deprecated as of V42) - // SNARL_NOTIFY_EX_CLICK // user clicked the middle mouse button (deprecated as of V42) - NotifyClosed = 307, // // user clicked the notification's close gadget (GNTP only) + // C++ interface custom errors- not part of official API! + ErrorCppInterface = 1001 +}; - // 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 +/// <summary> +/// The priority of messages. +/// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref> +/// </summary> +enum MessagePriority { + PriorityUndefined = -2, + PriorityLow = -1, + PriorityNormal = 0, + PriorityHigh = 1 +}; +/// <summary> +/// Application flags - features this app supports. +/// </summary> +enum AppFlags { + AppFlagNone = 0, + AppHasPrefs = 1, + AppHasAbout = 2, + AppIsWindowless = 0x8000 +}; - // C++ interface custom errors- not part of official API! - ErrorCppInterface = 1001 - }; +} // namespace SnarlEnums - /// <summary> - /// The priority of messages. - /// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref> - /// </summary> - enum MessagePriority - { - PriorityUndefined = -2, - PriorityLow = -1, - PriorityNormal = 0, - PriorityHigh = 1 - }; +// ---------------------------------------------------------------------------------------- +/// SnarlParameterList class definition - Helper class, not meant for broad use +// ---------------------------------------------------------------------------------------- +template<class T> +class SnarlParameterList +{ +public: + typedef std::pair<std::basic_string<T>, std::basic_string<T> > PairType; - /// <summary> - /// Application flags - features this app supports. - /// </summary> - enum AppFlags - { - AppFlagNone = 0, - AppHasPrefs = 1, - AppHasAbout = 2, - AppIsWindowless = 0x8000 - }; - - } // namespace SnarlEnums - - // ---------------------------------------------------------------------------------------- - /// SnarlParameterList class definition - Helper class, not meant for broad use - // ---------------------------------------------------------------------------------------- - template<class T> - class SnarlParameterList + SnarlParameterList() { - public: - typedef std::pair<std::basic_string<T>, std::basic_string<T> > PairType; + } - SnarlParameterList() - { + explicit SnarlParameterList(int initialCapacity) + { + list.reserve(initialCapacity); + } + + void Add(const T *_key, const T *_value) + { + if (_value != NULL) { + list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); // } + } - explicit SnarlParameterList(int initialCapacity) - { - list.reserve(initialCapacity); - } + void Add(const T *_key, LONG32 _value) + { + std::basic_stringstream<T> valStr; + valStr << _value; + list.push_back(PairType(std::basic_string<T>(_key), valStr.str())); + } - void Add(const T* _key, const T* _value) - { - if (_value != NULL) - list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); // - } - - void Add(const T* _key, LONG32 _value) - { + void Add(const T *_key, void *_value) + { + if (_value != NULL) { std::basic_stringstream<T> valStr; - valStr << _value; + valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex + list.push_back(PairType(std::basic_string<T>(_key), valStr.str())); } + } - void Add(const T* _key, void* _value) - { - if (_value != NULL) - { - std::basic_stringstream<T> valStr; - valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex + const std::vector<PairType> &GetList() const + { + return list; + } - list.push_back(PairType(std::basic_string<T>(_key), valStr.str())); - } - } +private: + std::vector<PairType> list; +}; - const std::vector<PairType>& GetList() const - { - return list; - } - - private: - std::vector<PairType> list; - }; - - // ---------------------------------------------------------------------------------------- - // SnarlInterface class definition - // ---------------------------------------------------------------------------------------- - class SnarlInterface +// ---------------------------------------------------------------------------------------- +// SnarlInterface class definition +// ---------------------------------------------------------------------------------------- +class SnarlInterface +{ +public: + /// <summary>Requests strings known by Snarl</summary> + class Requests { public: - /// <summary>Requests strings known by Snarl</summary> - class Requests + static LPCSTR AddActionA() { - 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"; } - }; + 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(); - virtual ~SnarlInterface(); + SnarlInterface(); + virtual ~SnarlInterface(); - // ------------------------------------------------------------------------------------ - // Static functions - // ------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------ + // Static functions + // ------------------------------------------------------------------------------------ - // 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; } + // 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; + } - /// <summary>Send message to Snarl.</summary> - /// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param> - /// <param name='replyTimeout'>Time to wait before timeout - Default = 1000</param> - /// <returns> - /// Return zero or positive on Success. - /// Negative on failure. (Get error code by abs(return_value)) - /// <see>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API#Return_Value</see> - /// </returns> - static LONG32 DoRequest(LPCSTR request, UINT replyTimeout = 1000); - static LONG32 DoRequest(LPCWSTR request, UINT replyTimeout = 1000); + /// <summary>Send message to Snarl.</summary> + /// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param> + /// <param name='replyTimeout'>Time to wait before timeout - Default = 1000</param> + /// <returns> + /// Return zero or positive on Success. + /// Negative on failure. (Get error code by abs(return_value)) + /// <see>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API#Return_Value</see> + /// </returns> + static LONG32 DoRequest(LPCSTR request, UINT replyTimeout = 1000); + static LONG32 DoRequest(LPCWSTR request, UINT replyTimeout = 1000); - /// <summary>Escapes a string, so it can be passed to Snarl.</summary> - /// <remarks> - /// Should only be used, if you are using DoRequest() and not the helper functions. - /// Remember to Escape each key/value pair individually. - /// </remarks> - static std::basic_string<char>& Escape(std::basic_string<char>& str); - static std::basic_string<wchar_t>& Escape(std::basic_string<wchar_t>& str); + /// <summary>Escapes a string, so it can be passed to Snarl.</summary> + /// <remarks> + /// Should only be used, if you are using DoRequest() and not the helper functions. + /// Remember to Escape each key/value pair individually. + /// </remarks> + static std::basic_string<char> &Escape(std::basic_string<char> &str); + static std::basic_string<wchar_t> &Escape(std::basic_string<wchar_t> &str); - /// <summary>Returns the global Snarl Application message (V39)</summary> - /// <returns>Returns Snarl application registered message.</returns> - static UINT AppMsg(); + /// <summary>Returns the global Snarl Application message (V39)</summary> + /// <returns>Returns Snarl application registered message.</returns> + static UINT AppMsg(); - /// <summary> - /// Returns the value of Snarl's global registered message. - /// Notes: - /// Snarl registers SNARL_GLOBAL_MSG during startup which it then uses to communicate - /// with all running applications through a Windows broadcast message. This function can - /// only fail if for some reason the Windows RegisterWindowMessage() function fails - /// - given this, this function *cannnot* be used to test for the presence of Snarl. - /// </summary> - /// <returns>A 16-bit value (translated to 32-bit) which is the registered Windows message for Snarl.</returns> - static UINT Broadcast(); + /// <summary> + /// Returns the value of Snarl's global registered message. + /// Notes: + /// Snarl registers SNARL_GLOBAL_MSG during startup which it then uses to communicate + /// with all running applications through a Windows broadcast message. This function can + /// only fail if for some reason the Windows RegisterWindowMessage() function fails + /// - given this, this function *cannnot* be used to test for the presence of Snarl. + /// </summary> + /// <returns>A 16-bit value (translated to 32-bit) which is the registered Windows message for Snarl.</returns> + static UINT Broadcast(); - /// <summary> - /// Get the path to where Snarl is installed. - /// ** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!! - /// </summary> - /// <returns>Returns the path to where Snarl is installed.</returns> - /// <remarks>This is a V39 API method.</remarks> - static LPCTSTR GetAppPath(); + /// <summary> + /// Get the path to where Snarl is installed. + /// ** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!! + /// </summary> + /// <returns>Returns the path to where Snarl is installed.</returns> + /// <remarks>This is a V39 API method.</remarks> + static LPCTSTR GetAppPath(); - /// <summary> - /// Get the path to where the default Snarl icons are located. - /// <para>** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!</para> - /// </summary> - /// <returns>Returns the path to where the default Snarl icons are located.</returns> - /// <remarks>This is a V39 API method.</remarks> - static LPCTSTR GetIconsPath(); + /// <summary> + /// Get the path to where the default Snarl icons are located. + /// <para>** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!</para> + /// </summary> + /// <returns>Returns the path to where the default Snarl icons are located.</returns> + /// <remarks>This is a V39 API method.</remarks> + static LPCTSTR GetIconsPath(); - /// <summary>Returns a handle to the Snarl Dispatcher window (V37)</summary> - /// <returns>Returns handle to Snarl Dispatcher window, or zero if it's not found.</returns> - /// <remarks>This is now the preferred way to test if Snarl is actually running.</remarks> - static HWND GetSnarlWindow(); + /// <summary>Returns a handle to the Snarl Dispatcher window (V37)</summary> + /// <returns>Returns handle to Snarl Dispatcher window, or zero if it's not found.</returns> + /// <remarks>This is now the preferred way to test if Snarl is actually running.</remarks> + static HWND GetSnarlWindow(); - /// <summary>Get Snarl version, if it is running.</summary> - /// <returns>Returns a number indicating Snarl version.</returns> - static LONG32 GetVersion(); + /// <summary>Get Snarl version, if it is running.</summary> + /// <returns>Returns a number indicating Snarl version.</returns> + static LONG32 GetVersion(); - /// <summary>Check whether Snarl is running</summary> - /// <returns>Returns true if Snarl system was found running.</returns> - static BOOL IsSnarlRunning(); + /// <summary>Check whether Snarl is running</summary> + /// <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); + /// <summary>Add a notification class to Snarl.</summary> + LONG32 AddClass(LPCSTR classId, LPCSTR name, LPCSTR title = NULL, LPCSTR text = NULL, LPCSTR icon = NULL, LPCSTR sound = NULL, LONG32 duration = NULL, LPCSTR callback = NULL, bool enabled = true); + LONG32 AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title = NULL, LPCWSTR text = NULL, LPCWSTR icon = NULL, LPCWSTR sound = NULL, LONG32 duration = -1, LPCWSTR callback = NULL, bool enabled = true); - /// <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); + /// <summary>Remove all notification classes in one call.</summary> + LONG32 ClearActions(LONG32 msgToken); - /// <summary>Add a notification class to Snarl.</summary> - LONG32 AddClass(LPCSTR classId, LPCSTR name, LPCSTR title = NULL, LPCSTR text = NULL, LPCSTR icon = NULL, LPCSTR sound = NULL, LONG32 duration = NULL, LPCSTR callback = NULL, bool enabled = true); - LONG32 AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title = NULL, LPCWSTR text = NULL, LPCWSTR icon = NULL, LPCWSTR sound = NULL, LONG32 duration = -1, LPCWSTR callback = NULL, bool enabled = true); + /// <summary>Remove all notification classes in one call.</summary> + LONG32 ClearClasses(); - /// <summary>Remove all notification classes in one call.</summary> - LONG32 ClearActions(LONG32 msgToken); + /// <summary>GetLastMsgToken() returns token of the last message sent to Snarl.</summary> + /// <returns>Returns message token of last message.</returns> + /// <remarks>This function is not in the official API!</remarks> + LONG32 GetLastMsgToken() const; - /// <summary>Remove all notification classes in one call.</summary> - LONG32 ClearClasses(); + /// <summary>Hide a Snarl notification.</summary> + LONG32 Hide(LONG32 msgToken); - /// <summary>GetLastMsgToken() returns token of the last message sent to Snarl.</summary> - /// <returns>Returns message token of last message.</returns> - /// <remarks>This function is not in the official API!</remarks> - LONG32 GetLastMsgToken() const; + /// <summary>Test if a Snarl notification is visible. If the message is visible the function returns SnarlEnums::Success.</summary> + LONG32 IsVisible(LONG32 msgToken); - /// <summary>Hide a Snarl notification.</summary> - LONG32 Hide(LONG32 msgToken); + /// <summary>Show a Snarl notification.</summary> + /// <returns>Returns the notification token or negative on failure.</returns> + /// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks> + LONG32 Notify(LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR uid = NULL, LPCSTR callback = NULL, LPCSTR value = NULL); + LONG32 Notify(LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR uid = NULL, LPCWSTR callback = NULL, LPCWSTR value = NULL); - /// <summary>Test if a Snarl notification is visible. If the message is visible the function returns SnarlEnums::Success.</summary> - LONG32 IsVisible(LONG32 msgToken); + /// <summary>Register application with Snarl.</summary> + /// <returns>The application token or negative on failure.</returns> + /// <remarks>The application token is saved in SnarlInterface member variable, so just use return value to check for error.</remarks> + LONG32 Register(LPCSTR signature, LPCSTR title, LPCSTR icon = NULL, LPCSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone); + LONG32 Register(LPCWSTR signature, LPCWSTR title, LPCWSTR icon = NULL, LPCWSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone); - /// <summary>Show a Snarl notification.</summary> - /// <returns>Returns the notification token or negative on failure.</returns> - /// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks> - LONG32 Notify(LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR uid = NULL, LPCSTR callback = NULL, LPCSTR value = NULL); - LONG32 Notify(LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR uid = NULL, LPCWSTR callback = NULL, LPCWSTR value = NULL); + /// <summary>Remove a notification class added with AddClass().</summary> + LONG32 RemoveClass(LPCSTR classId); + LONG32 RemoveClass(LPCWSTR classId); - /// <summary>Register application with Snarl.</summary> - /// <returns>The application token or negative on failure.</returns> - /// <remarks>The application token is saved in SnarlInterface member variable, so just use return value to check for error.</remarks> - LONG32 Register(LPCSTR signature, LPCSTR title, LPCSTR icon = NULL, LPCSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone); - LONG32 Register(LPCWSTR signature, LPCWSTR title, LPCWSTR icon = NULL, LPCWSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone); + /// <summary>Update the text or other parameters of a visible Snarl notification.</summary> + LONG32 Update(LONG32 msgToken, LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR callback = NULL, LPCSTR value = NULL); + LONG32 Update(LONG32 msgToken, LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR callback = NULL, LPCWSTR value = NULL); - /// <summary>Remove a notification class added with AddClass().</summary> - LONG32 RemoveClass(LPCSTR classId); - LONG32 RemoveClass(LPCWSTR classId); + /// <summary>Unregister application with Snarl when application is closing.</summary> + LONG32 Unregister(LPCSTR signature); + LONG32 Unregister(LPCWSTR signature); - /// <summary>Update the text or other parameters of a visible Snarl notification.</summary> - LONG32 Update(LONG32 msgToken, LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR callback = NULL, LPCSTR value = NULL); - LONG32 Update(LONG32 msgToken, LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR callback = NULL, LPCWSTR value = NULL); + /// <summary>Update information provided when calling RegisterApp.</summary> + /*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL); + LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/ - /// <summary>Unregister application with Snarl when application is closing.</summary> - LONG32 Unregister(LPCSTR signature); - LONG32 Unregister(LPCWSTR signature); +private: - /// <summary>Update information provided when calling RegisterApp.</summary> - /*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL); - LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/ + /// <summary>Convert a unicode string to UTF8</summary> + /// <returns>Returns pointer to the new string - Remember to delete [] returned string !</returns> + /// <remarks>Remember to call FreeString on returned string !!!</remarks> + static LPSTR WideToUTF8(LPCWSTR szWideStr); + static LONG32 DoRequest(LPCSTR request, SnarlParameterList<char> &spl, UINT replyTimeout = 1000); + static LONG32 DoRequest(LPCWSTR request, SnarlParameterList<wchar_t> &spl, UINT replyTimeout = 1000); - private: + void SetPassword(LPCSTR password); + void SetPassword(LPCWSTR password); + void ClearPassword(); - /// <summary>Convert a unicode string to UTF8</summary> - /// <returns>Returns pointer to the new string - Remember to delete [] returned string !</returns> - /// <remarks>Remember to call FreeString on returned string !!!</remarks> - static LPSTR WideToUTF8(LPCWSTR szWideStr); + LONG32 appToken; + LONG32 lastMsgToken; + LPSTR szPasswordA; + LPWSTR szPasswordW; +}; // class SnarlInterface - static LONG32 DoRequest(LPCSTR request, SnarlParameterList<char>& spl, UINT replyTimeout = 1000); - static LONG32 DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& spl, UINT replyTimeout = 1000); - - void SetPassword(LPCSTR password); - void SetPassword(LPCWSTR password); - void ClearPassword(); - - LONG32 appToken; - LONG32 lastMsgToken; - LPSTR szPasswordA; - LPWSTR szPasswordW; - }; // class SnarlInterface - - } // namespace V42 +} // namespace V42 } // namespace Snarl #endif // SNARL_INTERFACE_V42_H diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 3faaac3..6ea22a6 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -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,57 +27,53 @@ #include <QtDebug> #include <QWidget> - #include <iostream> - #define SNORENOTIFIER_MESSAGE_ID WM_USER + 238 using namespace Snore; using namespace Snarl::V42; -Q_EXPORT_PLUGIN2(libsnore_backend_snarl,SnarlBackend) +Q_EXPORT_PLUGIN2(libsnore_backend_snarl, SnarlBackend) -class SnarlBackend::SnarlWidget:public QWidget +class SnarlBackend::SnarlWidget: public QWidget { //Q_OBJECT public: - SnarlWidget(SnarlBackend * snarl): + SnarlWidget(SnarlBackend *snarl): m_snarl(snarl) { 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){ + if (msg->message == SNARL_GLOBAL_MESSAGE) { int action = msg->wParam; - if(action == SnarlEnums::SnarlLaunched){ - foreach(const Application &a,m_snarl->snore()->aplications()) - { + if (action == SnarlEnums::SnarlLaunched) { + foreach(const Application & a, m_snarl->snore()->aplications()) { m_snarl->slotRegisterApplication(a); } } - }else if(msg->message == SNORENOTIFIER_MESSAGE_ID){ + } else if (msg->message == SNORENOTIFIER_MESSAGE_ID) { int action = msg->wParam & 0xffff; 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)); } Notification::CloseReasons reason = Notification::NONE; - switch(action){ + switch (action) { case SnarlEnums::CallbackInvoked: reason = Notification::CLOSED; break; case SnarlEnums::NotifyAction: reason = Notification::CLOSED; - if(notification.isValid()) - { + if (notification.isValid()) { notification.data()->setActionInvoked(data); m_snarl->snore()->d()->notificationActionInvoked(notification); } @@ -89,26 +84,23 @@ public: case SnarlEnums::CallbackTimedOut: reason = Notification::TIMED_OUT; break; - //away stuff + //away stuff case SnarlEnums::SnarlUserAway: - snoreDebug( SNORE_DEBUG )<<"Snalr user has gone away"; + snoreDebug(SNORE_DEBUG) << "Snalr user has gone away"; return true; case SnarlEnums::SnarlUserBack: - snoreDebug( SNORE_DEBUG )<<"Snalr user has returned"; + snoreDebug(SNORE_DEBUG) << "Snalr user has returned"; return true; default: - snoreDebug( SNORE_DEBUG )<<"Unknown snarl action found!!"; + snoreDebug(SNORE_DEBUG) << "Unknown snarl action found!!"; return false; } - if(notification.isValid()) - { - m_snarl->closeNotification(notification,reason); + if (notification.isValid()) { + m_snarl->closeNotification(notification, reason); m_snarl->m_idMap.take(msg->lParam); - } - else - { - snoreDebug( SNORE_DEBUG ) << "Snarl notification already closed" << msg->lParam << action; - snoreDebug( SNORE_DEBUG ) << m_snarl->m_idMap; + } else { + snoreDebug(SNORE_DEBUG) << "Snarl notification already closed" << msg->lParam << action; + snoreDebug(SNORE_DEBUG) << m_snarl->m_idMap; } return true; } @@ -117,11 +109,10 @@ public: private: uint SNARL_GLOBAL_MESSAGE; - SnarlBackend* m_snarl; + SnarlBackend *m_snarl; }; - SnarlBackend::SnarlBackend(): SnoreBackend("Snarl", true, false, true) { @@ -133,27 +124,23 @@ SnarlBackend::~SnarlBackend() } - bool SnarlBackend::initialize(SnoreCore *snore) { SnarlInterface *snarlInterface = new SnarlInterface(); - if(!snarlInterface->IsSnarlRunning()) - { + if (!snarlInterface->IsSnarlRunning()) { delete snarlInterface; return false; } m_eventLoop = new SnarlBackend::SnarlWidget(this); - snoreDebug( SNORE_DEBUG ) << "Initiating Snarl Backend, Snarl version: " << snarlInterface->GetVersion(); + snoreDebug(SNORE_DEBUG) << "Initiating Snarl Backend, Snarl version: " << snarlInterface->GetVersion(); delete snarlInterface; return SnoreBackend::initialize(snore); } bool SnarlBackend::deinitialize() { - if(SnoreBackend::deinitialize()) - { - if(m_eventLoop) - { + if (SnoreBackend::deinitialize()) { + if (m_eventLoop) { m_eventLoop->deleteLater(); m_eventLoop = NULL; } @@ -162,52 +149,50 @@ 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"); SnarlInterface *snarlInterface = new SnarlInterface(); - m_applications.insert(application.name(),snarlInterface); + m_applications.insert(application.name(), snarlInterface); - QString appName = application.name().replace(" ","_");//app sig must not contain spaces + QString appName = application.name().replace(" ", "_"); //app sig must not contain spaces snarlInterface->Register(appName.toUtf8().constData(), application.name().toUtf8().constData(), application.icon().localUrl().toUtf8().constData(), - 0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID); + 0, (HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID); - foreach(const Alert &alert,application.alerts()) - { + foreach(const Alert & alert, application.alerts()) { snarlInterface->AddClass(alert.name().toUtf8().constData(), alert.name().toUtf8().constData(), - 0,0,alert.icon().localUrl().toUtf8().constData()); + 0, 0, alert.icon().localUrl().toUtf8().constData()); } } void SnarlBackend::slotDeregisterApplication(const Application &application) { - if(!m_applications.contains(application.name())) - { - snoreDebug( SNORE_DEBUG ) << "Unknown apllication: " << application.name(); + if (!m_applications.contains(application.name())) { + snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << application.name(); return; } SnarlInterface *snarlInterface = m_applications.take(application.name()); - QString appName = application.name().replace(" ","_");//app sig must not contain spaces + QString appName = application.name().replace(" ", "_"); //app sig must not contain spaces snarlInterface->Unregister(appName.toUtf8().constData()); delete snarlInterface; } -void SnarlBackend::slotNotify(Notification notification){ - if(!m_applications.contains(notification.application().name())) - { - snoreDebug( SNORE_DEBUG ) << "Unknown apllication: " << notification.application().name(); +void SnarlBackend::slotNotify(Notification notification) +{ + if (!m_applications.contains(notification.application().name())) { + snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name(); return; } 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; @@ -219,28 +204,24 @@ void SnarlBackend::slotNotify(Notification notification){ break; } - ULONG32 id = 0; - snoreDebug( SNORE_DEBUG ) << notification.icon(); + ULONG32 id = 0; + snoreDebug(SNORE_DEBUG) << notification.icon(); - if(!notification.isUpdate()) - { - id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(), - Snore::toPlainText(notification.title()).toUtf8().constData(), - Snore::toPlainText(notification.text()).toUtf8().constData(), - notification.timeout(), - notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, - !notification.icon().isLocalFile()?Icon::dataFromImage(notification.icon().image()).toBase64().constData():0, - priority); + if (!notification.isUpdate()) { + id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(), + Snore::toPlainText(notification.title()).toUtf8().constData(), + Snore::toPlainText(notification.text()).toUtf8().constData(), + notification.timeout(), + notification.icon().isLocalFile() ? notification.icon().localUrl().toUtf8().constData() : 0, + !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, + priority); - foreach(const Action &a, notification.actions()) - { - snarlInterface->AddAction(id,a.name().toUtf8().constData(),QString("@").append(QString::number(a.id())).toUtf8().constData()); + 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, @@ -248,8 +229,8 @@ void SnarlBackend::slotNotify(Notification notification){ Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.text()).toUtf8().constData(), notification.timeout(), - notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, - !notification.icon().isLocalFile()?Icon::dataFromImage(notification.icon().image()).toBase64().constData():0, + notification.icon().isLocalFile() ? notification.icon().localUrl().toUtf8().constData() : 0, + !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, priority); } @@ -260,9 +241,8 @@ void SnarlBackend::slotNotify(Notification notification){ void SnarlBackend::slotCloseNotification(Notification notification) { - if(!m_applications.contains(notification.application().name())) - { - snoreDebug( SNORE_DEBUG ) << "Unknown apllication: " << notification.application().name(); + if (!m_applications.contains(notification.application().name())) { + snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name(); return; } ULONG32 id = notification.hints().privateValue(this, "id").toUInt(); diff --git a/src/plugins/backends/snarl/snarl.h b/src/plugins/backends/snarl/snarl.h index 739e940..2a95dab 100644 --- a/src/plugins/backends/snarl/snarl.h +++ b/src/plugins/backends/snarl/snarl.h @@ -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,9 +21,7 @@ #include "core/plugins/snorebackend.h" #include "SnarlInterface.h" - - -class SnarlBackend:public Snore::SnoreBackend +class SnarlBackend: public Snore::SnoreBackend { Q_OBJECT Q_INTERFACES(Snore::SnoreBackend) @@ -37,8 +34,8 @@ public: private: class SnarlWidget; - SnarlBackend::SnarlWidget* m_eventLoop; - QHash<QString,Snarl::V42::SnarlInterface*> m_applications; + SnarlBackend::SnarlWidget *m_eventLoop; + QHash<QString, Snarl::V42::SnarlInterface *> m_applications; public slots: void slotRegisterApplication(const Snore::Application &application); @@ -47,9 +44,8 @@ public slots: void slotCloseNotification(Snore::Notification notification); private: - QHash<LONG32,uint> m_idMap; + QHash<LONG32, uint> m_idMap; }; - #endif // SNARL_BACKEND_H diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp index 0c04b58..e74936f 100644 --- a/src/plugins/backends/snore/notifywidget.cpp +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -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 @@ -29,9 +28,9 @@ using namespace Snore; -NotifyWidget::NotifyWidget(int pos,QWidget *parent) : +NotifyWidget::NotifyWidget(int pos, QWidget *parent) : QDeclarativeView(QUrl("qrc:/notification.qml"), parent), - m_animation( new QPropertyAnimation(this, "pos")), + m_animation(new QPropertyAnimation(this, "pos")), m_id(pos), m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))), m_ready(true) @@ -39,36 +38,31 @@ NotifyWidget::NotifyWidget(int pos,QWidget *parent) : m_qmlNotification = rootObject(); this->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint - #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | Qt::WindowDoesNotAcceptFocus - #endif - ); - if(m_mem.create(sizeof(SHARED_MEM_TYPE))) - { +#endif + ); + if (m_mem.create(sizeof(SHARED_MEM_TYPE))) { m_mem.lock(); - SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data(); + SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data(); data->free = true; data->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(); - SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data(); + SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data(); m_mem.unlock(); - snoreDebug( SNORE_DEBUG ) << "Status" << data->free << data->date.elapsed() / 1000; + snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000; } - setResizeMode(QDeclarativeView::SizeRootObjectToView); - connect( m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked())); - connect( m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed())); - + connect(m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked())); + connect(m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed())); + } NotifyWidget::~NotifyWidget() @@ -78,9 +72,9 @@ NotifyWidget::~NotifyWidget() void NotifyWidget::display(const Notification ¬ification) { update(notification); - snoreDebug( SNORE_DEBUG ) << notification.id(); + snoreDebug(SNORE_DEBUG) << notification.id(); show(); - + QRect desktop = QDesktopWidget().availableGeometry(); resize(computeSize()); @@ -89,7 +83,7 @@ void NotifyWidget::display(const Notification ¬ification) QPoint dest(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id); QPoint start(desktop.topRight().x(), dest.y()); - + m_animation->setDuration(500); m_animation->setStartValue(start); m_animation->setEndValue(dest); @@ -98,44 +92,38 @@ void NotifyWidget::display(const Notification ¬ification) void NotifyWidget::update(const Notification ¬ification) { - snoreDebug( SNORE_DEBUG ) << m_id << notification.id(); + snoreDebug(SNORE_DEBUG) << m_id << notification.id(); m_notification = notification; QColor color; QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor"); - if(vcolor.isValid()) - { + if (vcolor.isValid()) { color = vcolor.value<QColor>(); - } - else - { - color = computeBackgrondColor(notification.application().icon().image().scaled(20,20)); + } else { + color = computeBackgrondColor(notification.application().icon().image().scaled(20, 20)); notification.application().constHints().setPrivateValue(parent(), "backgroundColor", color); } QRgb gray = qGray(qGray(color.rgb()) - qGray(QColor(Qt::white).rgb())); QColor textColor = QColor(gray, gray, gray); QMetaObject::invokeMethod(m_qmlNotification, "update", Qt::QueuedConnection, - Q_ARG( QVariant, notification.title()), - Q_ARG( QVariant, notification.text()), - Q_ARG( QVariant, QUrl::fromLocalFile(notification.icon().localUrl())), - Q_ARG( QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())), - Q_ARG( QVariant, color), - Q_ARG( QVariant, textColor)); + Q_ARG(QVariant, notification.title()), + Q_ARG(QVariant, notification.text()), + Q_ARG(QVariant, QUrl::fromLocalFile(notification.icon().localUrl())), + Q_ARG(QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())), + Q_ARG(QVariant, color), + Q_ARG(QVariant, textColor)); } 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; + 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) - { - snoreDebug( SNORE_DEBUG ) << "Notification Lock timed out" << data->date.elapsed() / 1000; + if (data->free || timedout) { + if (timedout) { + snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << data->date.elapsed() / 1000; } data->free = false; data->date = QTime::currentTime(); @@ -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) - { + 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) { data->free = true; m_ready = true; out = true; @@ -192,11 +178,9 @@ 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) - { - QRgb c = img.pixel(x,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); b += qBlue(c); diff --git a/src/plugins/backends/snore/notifywidget.h b/src/plugins/backends/snore/notifywidget.h index 3945d97..f581714 100644 --- a/src/plugins/backends/snore/notifywidget.h +++ b/src/plugins/backends/snore/notifywidget.h @@ -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,13 +27,11 @@ #include <QtDeclarative> #include <QPropertyAnimation> - -typedef struct -{ +typedef struct { bool free; QTime date; -}SHARED_MEM_TYPE; +} SHARED_MEM_TYPE; inline int SHARED_MEM_TYPE_REV() { diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp index cc15ef9..7433d81 100644 --- a/src/plugins/backends/snore/snorenotifier.cpp +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -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" @@ -25,7 +23,7 @@ #include <QApplication> #include <QThread> -Q_EXPORT_PLUGIN2(libsnore_backend_snore,SnoreNotifier) +Q_EXPORT_PLUGIN2(libsnore_backend_snore, SnoreNotifier) using namespace Snore; @@ -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()) - { - snoreDebug( SNORE_DEBUG ) << "replacing notification" << w->notification().id() << notification.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()) - { - snoreDebug( SNORE_DEBUG ) << "replacing qued notification" << n.id() << notification.id(); - m_queue.replace(i,notification); + 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,10 +85,9 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification) //the timer will show the next } - void SnoreNotifier::slotDismissed() { - NotifyWidget *widget = qobject_cast<NotifyWidget*>(sender()); + NotifyWidget *widget = qobject_cast<NotifyWidget *>(sender()); Notification notification = widget->notification(); closeNotification(notification, Notification::DISMISSED); slotCloseNotification(notification); @@ -111,32 +95,26 @@ void SnoreNotifier::slotDismissed() void SnoreNotifier::slotInvoked() { - NotifyWidget *widget = qobject_cast<NotifyWidget*>(sender()); + NotifyWidget *widget = qobject_cast<NotifyWidget *>(sender()); Notification notification = widget->notification(); snore()->d()->notificationActionInvoked(notification); - closeNotification(notification,Notification::CLOSED); + closeNotification(notification, Notification::CLOSED); slotCloseNotification(notification); } void SnoreNotifier::slotProcessQueue() { - if(m_queue.isEmpty()) - { - snoreDebug( SNORE_DEBUG ) << "queue is empty"; + 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(); } diff --git a/src/plugins/backends/snore/snorenotifier.h b/src/plugins/backends/snore/snorenotifier.h index d30e7d4..0d6b550 100644 --- a/src/plugins/backends/snore/snorenotifier.h +++ b/src/plugins/backends/snore/snorenotifier.h @@ -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 @@ -50,10 +49,9 @@ private slots: private: QList<Snore::Notification> m_queue; - QVector<NotifyWidget*> m_widgets; + QVector<NotifyWidget *> m_widgets; QTimer *m_timer; - }; #endif // SNORENOTIFIER_H diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index fbbdbac..d4ddfb2 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -13,8 +13,7 @@ using namespace Snore; -Q_EXPORT_PLUGIN2(libsnore_backend_snoretoast,SnoreToast) - +Q_EXPORT_PLUGIN2(libsnore_backend_snoretoast, SnoreToast) SnoreToast::SnoreToast(): SnoreBackend("Windows 8", true, false) @@ -28,30 +27,27 @@ SnoreToast::~SnoreToast() bool SnoreToast::initialize(SnoreCore *snore) { - if(QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) - { - snoreDebug( SNORE_DEBUG ) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); + 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); p->setReadChannelMode(QProcess::MergedChannels); - connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); - connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill())); + connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); + connect(qApp, SIGNAL(aboutToQuit()), p, SLOT(kill())); QStringList arguements; arguements << "-t" << 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,20 +56,18 @@ 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; + snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; p->start("SnoreToast", arguements); - p->setProperty("SNORE_NOTIFICATION_ID",notification.id()); + p->setProperty("SNORE_NOTIFICATION_ID", notification.id()); } 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); @@ -82,11 +76,11 @@ void SnoreToast::slotRegisterApplication(const Application &application) << QString("SnoreNotify\\%1").arg(qApp->applicationName()) << QDir::toNativeSeparators(qApp->applicationFilePath()) << appId(application); - snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements; + snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; p->start("SnoreToast", arguements); - connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); - connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill())); + connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); + connect(qApp, SIGNAL(aboutToQuit()), p, SLOT(kill())); } } @@ -98,27 +92,25 @@ void SnoreToast::slotCloseNotification(Notification notification) QStringList arguements; arguements << "-close" << QString::number(notification.id()); - snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements; + snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; p->start("SnoreToast", arguements); - connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); - connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill())); + connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); + connect(qApp, SIGNAL(aboutToQuit()), p, SLOT(kill())); } 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()) - { + QProcess *p = qobject_cast<QProcess *>(sender()); + snoreDebug(SNORE_DEBUG) << p->readAll(); + 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); @@ -134,11 +126,11 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) break; case -1: //failed - snoreDebug( SNORE_WARNING ) << "SnoreToast failed to display " << n; + snoreDebug(SNORE_WARNING) << "SnoreToast failed to display " << n; break; } - closeNotification(n,reason); + closeNotification(n, reason); } @@ -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; diff --git a/src/plugins/backends/snoretoast/snoretoast.h b/src/plugins/backends/snoretoast/snoretoast.h index 6cff5a3..d0885b5 100644 --- a/src/plugins/backends/snoretoast/snoretoast.h +++ b/src/plugins/backends/snoretoast/snoretoast.h @@ -17,7 +17,7 @@ public: public slots: void slotNotify(Snore::Notification notification); void slotRegisterApplication(const Snore::Application &application); - void slotCloseNotification ( Snore::Notification notification ); + void slotCloseNotification(Snore::Notification notification); private slots: void slotToastNotificationClosed(int code, QProcess::ExitStatus); @@ -25,7 +25,6 @@ private slots: private: QString appId(const Snore::Application &application); - }; #endif // TOASTER_H diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index d91a2b8..69e8ae4 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -9,10 +9,10 @@ #include <QDebug> using namespace Snore; -Q_EXPORT_PLUGIN2(libsnore_backend_trayicon,TrayIconNotifer) +Q_EXPORT_PLUGIN2(libsnore_backend_trayicon, TrayIconNotifer) -TrayIconNotifer::TrayIconNotifer () : - SnoreBackend ( "SystemTray",true,false ), +TrayIconNotifer::TrayIconNotifer() : + SnoreBackend("SystemTray", true, false), m_trayIcon(NULL), m_displayed(-1), m_currentlyDisplaying(false) @@ -25,23 +25,21 @@ TrayIconNotifer::~TrayIconNotifer() } -bool TrayIconNotifer::initialize(SnoreCore *snore){ +bool TrayIconNotifer::initialize(SnoreCore *snore) +{ m_trayIcon = snore->trayIcon(); - if(m_trayIcon == NULL) - { + if (m_trayIcon == NULL) { return false; } - connect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked())); + connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked())); return SnoreBackend::initialize(snore); } bool TrayIconNotifer::deinitialize() { - if(SnoreBackend::deinitialize()) - { - if(m_trayIcon) - { - disconnect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked())); + if (SnoreBackend::deinitialize()) { + if (m_trayIcon) { + disconnect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(actionInvoked())); m_trayIcon = NULL; m_currentlyDisplaying = false; } @@ -50,7 +48,7 @@ bool TrayIconNotifer::deinitialize() return false; } -void TrayIconNotifer::slotNotify( Notification notification ) +void TrayIconNotifer::slotNotify(Notification notification) { m_notificationQue.append(notification); displayNotification(); @@ -58,36 +56,33 @@ void TrayIconNotifer::slotNotify( Notification notification ) void TrayIconNotifer::slotCloseNotification(Notification n) { - snoreDebug( SNORE_DEBUG ) << n; + snoreDebug(SNORE_DEBUG) << n; m_currentlyDisplaying = false; displayNotification(); } void TrayIconNotifer::displayNotification() { - if(m_currentlyDisplaying) - { + if (m_currentlyDisplaying) { return; } - if(m_notificationQue.isEmpty()) - { + if (m_notificationQue.isEmpty()) { m_currentlyDisplaying = false; return; } m_currentlyDisplaying = true; Notification notification = m_notificationQue.takeFirst(); m_displayed = notification.id(); - m_trayIcon->showMessage ( Snore::toPlainText(notification.title()),Snore::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 ); + m_trayIcon->showMessage(Snore::toPlainText(notification.title()), Snore::toPlainText(notification.text()), QSystemTrayIcon::NoIcon, notification.timeout() * 1000); startTimeout(notification); } void TrayIconNotifer::actionInvoked() { Notification n = getActiveNotificationByID(m_displayed); - if(n.isValid()) - { + if (n.isValid()) { snore()->d()->notificationActionInvoked(n); - closeNotification(n,Notification::CLOSED); + closeNotification(n, Notification::CLOSED); m_currentlyDisplaying = false; displayNotification(); } diff --git a/src/plugins/backends/trayicon/trayiconnotifer.h b/src/plugins/backends/trayicon/trayiconnotifer.h index f58933d..709167f 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.h +++ b/src/plugins/backends/trayicon/trayiconnotifer.h @@ -3,20 +3,20 @@ #include "core/plugins/snorebackend.h" - -namespace Snore{ - class SnoreCore; +namespace Snore +{ +class SnoreCore; } class QSystemTrayIcon; -class TrayIconNotifer:public Snore::SnoreBackend +class TrayIconNotifer: public Snore::SnoreBackend { Q_OBJECT Q_INTERFACES(Snore::SnoreBackend) Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") public: - TrayIconNotifer (); + TrayIconNotifer(); virtual ~TrayIconNotifer(); virtual bool initialize(Snore::SnoreCore *snore); virtual bool deinitialize(); diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 1b5b7d9..b6dc6a8 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -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 @@ -32,27 +31,26 @@ using namespace Snore; -Q_EXPORT_PLUGIN2(libsnore_frontend_freedesktop,FreedesktopFrontend) +Q_EXPORT_PLUGIN2(libsnore_frontend_freedesktop, FreedesktopFrontend) FreedesktopFrontend::FreedesktopFrontend(): SnoreFrontend("Freedesktop") { - } -FreedesktopFrontend::~FreedesktopFrontend(){ +FreedesktopFrontend::~FreedesktopFrontend() +{ QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.unregisterService( "org.freedesktop.Notifications" ); + dbus.unregisterService("org.freedesktop.Notifications"); } 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 )) - { + if (dbus.registerService("org.freedesktop.Notifications") && + dbus.registerObject("/org/freedesktop/Notifications", this)) { return SnoreFrontend::initialize(snore); } return false; @@ -60,11 +58,10 @@ 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" ); + dbus.unregisterService("org.freedesktop.Notifications"); + dbus.unregisterObject("/org/freedesktop/Notifications"); m_adaptor->deleteLater(); m_adaptor = NULL; return true; @@ -74,15 +71,14 @@ bool FreedesktopFrontend::deinitialize() void FreedesktopFrontend::actionInvoked(Notification notification) { - if(notification.actionInvoked().isValid()) - { - emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked().id())); + if (notification.actionInvoked().isValid()) { + emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id())); } } void FreedesktopFrontend::notificationClosed(Notification notification) { - emit NotificationClosed(notification.id(),notification.closeReason()); + emit NotificationClosed(notification.id(), notification.closeReason()); } uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, @@ -93,86 +89,71 @@ 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") ); + 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()) - { + foreach(const QSize & s, qicon.availableSizes()) { + if (s.width()*s.height() > max.width()*max.height()) { max = s; } } - Icon appIcon( qicon.pixmap( max ).toImage()); + Icon appIcon(qicon.pixmap(max).toImage()); Alert alert("DBus Alert", appIcon); app = Application(app_name, appIcon); app.addAlert(alert); snore()->registerApplication(app); - } - else - { + } else { app = snore()->aplications()[app_name]; } - if (hints.contains("urgency")) - { - priotity = Notification::Prioritys(hints["urgency"].toInt()-1); + if (hints.contains("urgency")) { + priotity = Notification::Prioritys(hints["urgency"].toInt() - 1); } Notification noti; - 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 - { - noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout==-1?Notification::defaultTimeout():timeout/1000, priotity); + 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 { + 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) - { - noti.addAction(Action(actions.at(i).toInt(),actions.at(i+1))); + for (int i = 0; i < actions.length(); i += 2) { + noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1))); } snore()->broadcastNotification(noti); return noti.id(); } - - void FreedesktopFrontend::CloseNotification(uint id) { Notification noti = snore()->getActiveNotificationByID(id); - if(noti.isValid()) - { - snore()->requestCloseNotification(noti,Notification::TIMED_OUT); + if (noti.isValid()) { + snore()->requestCloseNotification(noti, Notification::TIMED_OUT); } } QStringList FreedesktopFrontend::GetCapabilities() { return QStringList() - << "body" - << "urgency" - // << "body-hyperlinks" - << "body-markup" - << "icon-static" - << "actions"; + << "body" + << "urgency" + // << "body-hyperlinks" + << "body-markup" + << "icon-static" + << "actions"; } -QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) +QString FreedesktopFrontend::GetServerInformation(QString &vendor, QString &version, QString &specVersion) { vendor = "SnoreNotify"; version = Version::version(); diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h index eb0b6d8..2311f79 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h @@ -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 @@ -39,21 +38,20 @@ public: void actionInvoked(Snore::Notification notification); void notificationClosed(Snore::Notification notification); uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout); - void CloseNotification( uint id ); + void CloseNotification(uint id); QStringList GetCapabilities(); - QString GetServerInformation(QString& vendor, QString& version, QString& specVersion); + QString GetServerInformation(QString &vendor, QString &version, QString &specVersion); signals: - void NotificationClosed( uint id, uint reason ); - void ActionInvoked( uint id, const QString& actionKey ); + void NotificationClosed(uint id, uint reason); + void ActionInvoked(uint id, const QString &actionKey); private: Snore::Alert m_alert; Snore::Icon m_icon; NotificationsAdaptor *m_adaptor; - }; #endif//FREEDESKTOPNOTIFICATION_FRONTEND_H diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 9e5b17d..13da77e 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -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> @@ -38,25 +36,24 @@ Parser::Parser(SnarlNetworkFrontend *snarl): QObject(snarl), snarl(snarl) { - getSnpType.insert("type",TYPE); - getSnpType.insert("app",APP); - getSnpType.insert("version",VERSION); - getSnpType.insert("action",ACTION); - getSnpType.insert("register",REGISTER); - getSnpType.insert("add_class",ADD_CLASS); - getSnpType.insert("notification",NOTIFICATION); - getSnpType.insert("unregister",UNREGISTER); - getSnpType.insert("class",CLASS); - getSnpType.insert("title",TITLE); - getSnpType.insert("text",TEXT); - getSnpType.insert("icon",ICON); - getSnpType.insert("timeout",TIMEOUT); + getSnpType.insert("type", TYPE); + getSnpType.insert("app", APP); + getSnpType.insert("version", VERSION); + getSnpType.insert("action", ACTION); + getSnpType.insert("register", REGISTER); + getSnpType.insert("add_class", ADD_CLASS); + getSnpType.insert("notification", NOTIFICATION); + getSnpType.insert("unregister", UNREGISTER); + getSnpType.insert("class", CLASS); + getSnpType.insert("title", TITLE); + getSnpType.insert("text", TEXT); + getSnpType.insert("icon", ICON); + getSnpType.insert("timeout", TIMEOUT); } - -void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* client) +void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *client) { - snoreDebug( SNORE_DEBUG ) << msg; + snoreDebug(SNORE_DEBUG) << msg; QStringList splitted(msg.split("#?")); snpTypes action(ERROR); @@ -70,12 +67,10 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl QString key; QString value; - foreach(QString s,splitted) - { - key = s.mid(0,s.indexOf("=")).toLower(); - value = s.mid(s.indexOf("=")+1); - switch(getSnpType.value(key)) - { + foreach(QString s, splitted) { + key = s.mid(0, s.indexOf("=")).toLower(); + value = s.mid(s.indexOf("=") + 1); + switch (getSnpType.value(key)) { case APP: appName = value; break; @@ -102,66 +97,50 @@ 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); + sNotification = Notification(app, alert, title, text, icon, timeout); sNotification.data()->setSource(snarl); sNotification.hints().setPrivateValue(snarl, "clientSocket", client); break; } case ADD_CLASS: - if(alertName.isEmpty()) - { - snoreDebug( SNORE_DEBUG ) << "Error registering alert with empty name"; + if (alertName.isEmpty()) { + snoreDebug(SNORE_DEBUG) << "Error registering alert with empty name"; break; } alert = Alert(alertName, icon); 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 - { - snoreDebug( SNORE_DEBUG ) << appName << "already registred"; + } else { + snoreDebug(SNORE_DEBUG) << appName << "already registred"; } break; case UNREGISTER: - snarl->snore()->deregisterApplication( app ); + snarl->snore()->deregisterApplication(app); snarl->m_applications.take(client); break; case ERROR: diff --git a/src/plugins/frontends/snarlnetwork/parser.h b/src/plugins/frontends/snarlnetwork/parser.h index fb41e7e..8c0f51b 100644 --- a/src/plugins/frontends/snarlnetwork/parser.h +++ b/src/plugins/frontends/snarlnetwork/parser.h @@ -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,20 +24,18 @@ #include <QSharedPointer> #include <QObject> - - class Parser : public QObject { Q_OBJECT public: - Parser(class SnarlNetworkFrontend* snarl); + Parser(class SnarlNetworkFrontend *snarl); - void parse(Snore::Notification &sNotification, const QString &msg, class QTcpSocket* client); + void parse(Snore::Notification &sNotification, const QString &msg, class QTcpSocket *client); private: class SnarlNetworkFrontend *snarl; - enum snpTypes{ + enum snpTypes { TYPE, APP, VERSION, @@ -56,7 +53,7 @@ private: }; - QHash<QString,Parser::snpTypes> getSnpType; + QHash<QString, Parser::snpTypes> getSnpType; }; diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 9c89948..5971961 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -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,7 @@ #include <iostream> using namespace Snore; -Q_EXPORT_PLUGIN2(libsnore_frontend_snarlnetwork,SnarlNetworkFrontend) - +Q_EXPORT_PLUGIN2(libsnore_frontend_snarlnetwork, SnarlNetworkFrontend) SnarlNetworkFrontend::SnarlNetworkFrontend(): SnoreFrontend("SnarlNetwork") @@ -36,20 +34,18 @@ SnarlNetworkFrontend::SnarlNetworkFrontend(): } -SnarlNetworkFrontend::~SnarlNetworkFrontend(){ +SnarlNetworkFrontend::~SnarlNetworkFrontend() +{ } bool SnarlNetworkFrontend::initialize(SnoreCore *snore) { parser = new Parser(this); tcpServer = new QTcpServer(this); - if(!tcpServer->listen(QHostAddress::Any,port)) - { - snoreDebug( SNORE_DEBUG ) << "The port is already used"; + 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,17 +65,15 @@ bool SnarlNetworkFrontend::deinitialize() return false; } - void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification) { - snoreDebug( SNORE_DEBUG ) << notification.closeReason(); - callback(notification,"SNP/1.1/304/Notification acknowledged/"); + snoreDebug(SNORE_DEBUG) << notification.closeReason(); + callback(notification, "SNP/1.1/304/Notification acknowledged/"); } 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; @@ -88,7 +81,7 @@ void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) callback(notification, "SNP/1.1/307/Notification closed/"); break; case Notification::DISMISSED: - callback(notification,"SNP/1.1/302/Notification cancelled/"); + callback(notification, "SNP/1.1/302/Notification cancelled/"); break; } } @@ -96,31 +89,26 @@ void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) void SnarlNetworkFrontend::handleConnection() { QTcpSocket *client = tcpServer->nextPendingConnection(); - connect(client,SIGNAL(readyRead()),this,SLOT(handleMessages())); - connect(client,SIGNAL(disconnected()), client, SLOT(deleteLater())); + connect(client, SIGNAL(readyRead()), this, SLOT(handleMessages())); + connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater())); } void SnarlNetworkFrontend::handleMessages() { const QString out("SNP/1.1/0/OK"); - QTcpSocket *client = qobject_cast<QTcpSocket*>(sender()); + 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 - { + write(client, QString("%1/%2\r\n").arg(out, QString::number(noti.id()))); + } else { write(client, QString("%1\r\n").arg(out)); } } @@ -128,9 +116,8 @@ void SnarlNetworkFrontend::handleMessages() void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) { - if(sn.hints().containsPrivateValue(this, "clientSocket")) - { - QTcpSocket *client = qobject_cast<QTcpSocket*>(sn.hints().privateValue(this, "clientSocket").value<QObject*>()); + 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()))); } } diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.h b/src/plugins/frontends/snarlnetwork/snarlnetwork.h index b7b9e4c..032be5a 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.h +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.h @@ -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 @@ -35,7 +33,7 @@ class SnarlNetworkFrontend : public Snore::SnoreFrontend Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0") friend class Parser; public: - static const int port=9887; + static const int port = 9887; public: SnarlNetworkFrontend(); @@ -53,13 +51,13 @@ private slots: private: QTcpServer *tcpServer; Parser *parser; - QHash<QTcpSocket*,Snore::Application> m_applications; + QHash<QTcpSocket *, Snore::Application> m_applications; - void callback(Snore::Notification &sn,QString msg); + void callback(Snore::Notification &sn, QString msg); - inline void write(QTcpSocket *dest,const QString &msg) + inline void write(QTcpSocket *dest, const QString &msg) { - snoreDebug( SNORE_DEBUG ) << msg; + snoreDebug(SNORE_DEBUG) << msg; dest->write(msg.toAscii()); } diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 26e0a6d..882d808 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -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,7 @@ using namespace Snore; SnoreNotify::SnoreNotify(): - m_settings("SnoreNotify","SnoreNotify") + m_settings("SnoreNotify", "SnoreNotify") { m_trayIcon = new TrayIcon(); m_snore = new SnoreCore(m_trayIcon->trayIcon()); @@ -43,11 +42,12 @@ SnoreNotify::SnoreNotify(): load(); m_trayIcon->initConextMenu(m_snore); - connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit())); - snoreDebug( SNORE_DEBUG ) << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend(); + connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(exit())); + 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 - { + } else { m_snore->setPrimaryNotificationBackend(); } } -void SnoreNotify::save(){ - m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend()); +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(); diff --git a/src/snorenotify.h b/src/snorenotify.h index 4c3b226..a5a2d22 100644 --- a/src/snorenotify.h +++ b/src/snorenotify.h @@ -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,11 +21,12 @@ #include <QtCore> -namespace Snore{ +namespace Snore +{ class SnoreCore; } -class SnoreNotify:public QObject +class SnoreNotify: public QObject { Q_OBJECT public: diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 1049856..eaa24e2 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -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 @@ -32,7 +31,7 @@ using namespace Snore; TrayIcon::TrayIcon(): m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png"))), m_app("SnoreNotify Test", Icon(":/root/snore.png")), - m_alert("Default",Icon(":/root/snore.png")) + m_alert("Default", Icon(":/root/snore.png")) { m_app.addAlert(m_alert); } @@ -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,19 +52,16 @@ 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); } m_trayMenu->addSeparator(); - m_trayMenu->addAction("Exit",qApp,SLOT(quit())); - + m_trayMenu->addAction("Exit", qApp, SLOT(quit())); m_trayIcon->setContextMenu(m_trayMenu); } @@ -76,19 +71,18 @@ void TrayIcon::hide() m_trayIcon->setVisible(false); } -QSystemTrayIcon* TrayIcon::trayIcon() +QSystemTrayIcon *TrayIcon::trayIcon() { return m_trayIcon; } -void TrayIcon::setPrimaryBackend(){ - QAction *a = qobject_cast<QAction*>(sender()); +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", @@ -110,13 +103,13 @@ void TrayIcon::slotTestNotification() "3<br>" "4<br>" "5<br>", Icon(":/root/snore.png")); - noti.addAction(Action(1,"Test Action")); + noti.addAction(Action(1, "Test Action")); m_snore->broadcastNotification(noti); QTimer *timer = new QTimer(this); m_notifications[timer] = noti; timer->setSingleShot(true); - timer->setInterval(noti.timeout()/2*1000); + timer->setInterval(noti.timeout() / 2 * 1000); connect(timer, SIGNAL(timeout()), this, SLOT(sloutUpdateTestNotification())); timer->start(); @@ -125,7 +118,7 @@ void TrayIcon::slotTestNotification() void TrayIcon::sloutUpdateTestNotification() { - QTimer *timer = qobject_cast<QTimer*>(sender()); + QTimer *timer = qobject_cast<QTimer *>(sender()); Notification noti = m_notifications.take(timer); Notification update(noti, "Hello World", "<b>This is Snore</b><br>" diff --git a/src/trayicon.h b/src/trayicon.h index 3dfb6d8..40154e3 100644 --- a/src/trayicon.h +++ b/src/trayicon.h @@ -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,15 +23,14 @@ #include <QAction> #include "core/snore.h" - -class TrayIcon:public QObject +class TrayIcon: public QObject { Q_OBJECT public: TrayIcon(); void initConextMenu(Snore::SnoreCore *snore); void hide(); - class QSystemTrayIcon* trayIcon(); + class QSystemTrayIcon *trayIcon(); private: class QSystemTrayIcon *m_trayIcon; @@ -42,8 +40,7 @@ private: Snore::Application m_app; Snore::Alert m_alert; - QHash<QTimer*,Snore::Notification> m_notifications; - + QHash<QTimer *, Snore::Notification> m_notifications; public slots: void setPrimaryBackend();