style fixes, kde-dev-scripts/astyle-kdelibs
This commit is contained in:
parent
1dbc3e4710
commit
09620f66f0
|
@ -11,15 +11,15 @@
|
||||||
|
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
|
class SnoreBenchmark : public QObject
|
||||||
class SnoreBenchmark : public QObject{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SnoreBenchmark(){
|
SnoreBenchmark()
|
||||||
|
{
|
||||||
SnoreCore::instance();
|
SnoreCore::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
|
QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
|
||||||
"<i>Italic B</i><br>"
|
"<i>Italic B</i><br>"
|
||||||
"<b>Bold</b><br>"
|
"<b>Bold</b><br>"
|
||||||
|
@ -28,15 +28,14 @@ public:
|
||||||
"<&><br>"
|
"<&><br>"
|
||||||
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>");
|
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>");
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void benchmarkUtilsToHtml();
|
void benchmarkUtilsToHtml();
|
||||||
void benchmarkUtilsToHtmlAllMarkup();
|
void benchmarkUtilsToHtmlAllMarkup();
|
||||||
void benchmarkUtilsToPlain();
|
void benchmarkUtilsToPlain();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SnoreBenchmark::benchmarkUtilsToHtml()
|
||||||
void SnoreBenchmark::benchmarkUtilsToHtml(){
|
{
|
||||||
|
|
||||||
|
|
||||||
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n"
|
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n"
|
||||||
"Italic B\n"
|
"Italic B\n"
|
||||||
|
|
|
@ -92,7 +92,7 @@ QDebug operator<< (QDebug debug, const Snore::Application &app)
|
||||||
{
|
{
|
||||||
if (app.isValid()) {
|
if (app.isValid()) {
|
||||||
debug << "Snore::Application(" << app.name() << ", ";
|
debug << "Snore::Application(" << app.name() << ", ";
|
||||||
foreach(const Alert & a, app.alerts()) {
|
foreach (const Alert &a, app.alerts()) {
|
||||||
debug << a << ", ";
|
debug << a << ", ";
|
||||||
}
|
}
|
||||||
debug << ")" ;
|
debug << ")" ;
|
||||||
|
|
|
@ -24,7 +24,7 @@ Hint::Hint()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hint::setValue(const QByteArray & key, const QVariant &value)
|
void Hint::setValue(const QByteArray &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
m_data.insert(key, value);
|
m_data.insert(key, value);
|
||||||
}
|
}
|
||||||
|
@ -34,34 +34,34 @@ QVariant Hint::value(const QByteArray &key) const
|
||||||
return m_data.value(key);
|
return m_data.value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Hint::take(const QByteArray & key)
|
QVariant Hint::take(const QByteArray &key)
|
||||||
{
|
{
|
||||||
return m_data.take(key);
|
return m_data.take(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hint::contains(const QByteArray & key) const
|
bool Hint::contains(const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return m_data.contains(key);
|
return m_data.contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hint::setPrivateValue(const void *owner, const QByteArray & key, const QVariant &value)
|
void Hint::setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
m_privateData.insert(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key), value);
|
m_privateData.insert(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Hint::privateValue(const void *owner, const QByteArray &key) const
|
QVariant Hint::privateValue(const void *owner, const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return m_privateData.value(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key));
|
return m_privateData.value(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hint::containsPrivateValue(const void *owner, const QByteArray & key) const
|
bool Hint::containsPrivateValue(const void *owner, const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return m_privateData.contains(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key));
|
return m_privateData.contains(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Hint::takePrivateValue(const void *owner, const QByteArray & key)
|
QVariant Hint::takePrivateValue(const void *owner, const QByteArray &key)
|
||||||
{
|
{
|
||||||
return m_privateData.take(qMakePair<const quintptr,const QByteArray>((quintptr)owner,key));
|
return m_privateData.take(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Snore::Hint &hint)
|
QDebug operator<<(QDebug debug, const Snore::Hint &hint)
|
||||||
|
|
|
@ -48,28 +48,26 @@ public:
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
void setValue(const QByteArray & key, const QVariant &value);
|
void setValue(const QByteArray &key, const QVariant &value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated value of the key.
|
* The associated value of the key.
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
QVariant value(const QByteArray & key) const;
|
QVariant value(const QByteArray &key) const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated value of the key.
|
* The associated value of the key.
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
QVariant take(const QByteArray & key);
|
QVariant take(const QByteArray &key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @return whether the key is set
|
* @return whether the key is set
|
||||||
*/
|
*/
|
||||||
bool contains(const QByteArray & key) const;
|
bool contains(const QByteArray &key) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value for the key depending on the owner
|
* Sets the value for the key depending on the owner
|
||||||
|
@ -77,14 +75,14 @@ public:
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
void setPrivateValue(const void *owner, const QByteArray & key, const QVariant &value);
|
void setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated value of the key if present.
|
* The associated value of the key if present.
|
||||||
* @param owner the owner
|
* @param owner the owner
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
QVariant privateValue(const void *owner, const QByteArray & key) const;
|
QVariant privateValue(const void *owner, const QByteArray &key) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -92,7 +90,7 @@ public:
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @return whether the key is set
|
* @return whether the key is set
|
||||||
*/
|
*/
|
||||||
bool containsPrivateValue(const void *owner, const QByteArray & key) const;
|
bool containsPrivateValue(const void *owner, const QByteArray &key) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated value of the key if present.
|
* The associated value of the key if present.
|
||||||
|
|
|
@ -94,8 +94,8 @@ void NotificationData::setTimeoutTimer(QTimer *timer)
|
||||||
|
|
||||||
QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags)
|
QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags)
|
||||||
{
|
{
|
||||||
if(!m_hints.value("use-markup").toBool()) {
|
if (!m_hints.value("use-markup").toBool()) {
|
||||||
if(flags == Utils::NO_MARKUP){
|
if (flags == Utils::NO_MARKUP) {
|
||||||
return string;
|
return string;
|
||||||
} else {
|
} else {
|
||||||
return Utils::normalizeMarkup(string.toHtmlEscaped(), flags);
|
return Utils::normalizeMarkup(string.toHtmlEscaped(), flags);
|
||||||
|
|
|
@ -87,14 +87,14 @@ void PluginContainer::updatePluginCache()
|
||||||
{
|
{
|
||||||
snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
|
snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
|
||||||
for (auto list : s_pluginCache) {
|
for (auto list : s_pluginCache) {
|
||||||
foreach(PluginContainer * p, list.values()) {
|
foreach (PluginContainer *p, list.values()) {
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
foreach (const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
||||||
foreach(const QFileInfo & file, pluginDir().entryInfoList(
|
foreach (const QFileInfo &file, pluginDir().entryInfoList(
|
||||||
QStringList(pluginFileFilters(type)), QDir::Files)) {
|
QStringList(pluginFileFilters(type)), QDir::Files)) {
|
||||||
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
|
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
|
||||||
QPluginLoader loader(file.absoluteFilePath());
|
QPluginLoader loader(file.absoluteFilePath());
|
||||||
|
@ -152,7 +152,7 @@ const QDir &PluginContainer::pluginDir()
|
||||||
<< appDir + suffix
|
<< appDir + suffix
|
||||||
<< appDir + QLatin1String("/../lib/plugins") + suffix
|
<< appDir + QLatin1String("/../lib/plugins") + suffix
|
||||||
<< appDir + QLatin1String("/../lib64/plugins") + suffix;
|
<< appDir + QLatin1String("/../lib64/plugins") + suffix;
|
||||||
for(const QString & p : list) {
|
for (const QString &p : list) {
|
||||||
path = QDir(p);
|
path = QDir(p);
|
||||||
|
|
||||||
if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {
|
if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
static inline const QStringList pluginFileFilters()
|
static inline const QStringList pluginFileFilters()
|
||||||
{
|
{
|
||||||
QStringList out;
|
QStringList out;
|
||||||
for(const QString &extention : pluginExtentions()) {
|
for (const QString &extention : pluginExtentions()) {
|
||||||
out << QString(QLatin1String("libsnore_*.%1")).arg(extention);
|
out << QString(QLatin1String("libsnore_*.%1")).arg(extention);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type)
|
static inline const QStringList pluginFileFilters(Snore::SnorePlugin::PluginTypes type)
|
||||||
{
|
{
|
||||||
QStringList out;
|
QStringList out;
|
||||||
for(const QString &extention : pluginExtentions()) {
|
for (const QString &extention : pluginExtentions()) {
|
||||||
out << QString(QLatin1String("libsnore_%1_*.%2")).arg(SnorePlugin::typeToString(type).toLower(), extention);
|
out << QString(QLatin1String("libsnore_%1_*.%2")).arg(SnorePlugin::typeToString(type).toLower(), extention);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
SnorePlugin();
|
SnorePlugin();
|
||||||
virtual ~SnorePlugin();
|
virtual ~SnorePlugin();
|
||||||
|
|
||||||
|
|
||||||
// TODO: remove need of recursive calling of parent methode....
|
// TODO: remove need of recursive calling of parent methode....
|
||||||
virtual bool initialize();
|
virtual bool initialize();
|
||||||
virtual bool deinitialize();
|
virtual bool deinitialize();
|
||||||
|
|
|
@ -57,7 +57,6 @@ protected Q_SLOTS:
|
||||||
protected:
|
protected:
|
||||||
void closeNotification(Snore::Notification, Snore::Notification::CloseReasons);
|
void closeNotification(Snore::Notification, Snore::Notification::CloseReasons);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ SnoreCore::SnoreCore(QObject *parent):
|
||||||
SnoreCore &SnoreCore::instance()
|
SnoreCore &SnoreCore::instance()
|
||||||
{
|
{
|
||||||
static SnoreCore *instance = nullptr;
|
static SnoreCore *instance = nullptr;
|
||||||
if(!instance){
|
if (!instance) {
|
||||||
instance = new SnoreCore(qApp);
|
instance = new SnoreCore(qApp);
|
||||||
SnoreCorePrivate::instance()->init();
|
SnoreCorePrivate::instance()->init();
|
||||||
}
|
}
|
||||||
|
@ -207,8 +207,8 @@ QVariant SnoreCore::settingsValue(const QString &key, SettingsType type) const
|
||||||
{
|
{
|
||||||
Q_D(const SnoreCore);
|
Q_D(const SnoreCore);
|
||||||
QString nk = d->normalizeSettingsKey(key, type);
|
QString nk = d->normalizeSettingsKey(key, type);
|
||||||
if(type == LOCAL_SETTING && !d->m_settings->contains(nk)){
|
if (type == LOCAL_SETTING && !d->m_settings->contains(nk)) {
|
||||||
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"),type);
|
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"), type);
|
||||||
}
|
}
|
||||||
return d->m_settings->value(nk);
|
return d->m_settings->value(nk);
|
||||||
}
|
}
|
||||||
|
@ -235,13 +235,12 @@ Notification SnoreCore::getActiveNotificationByID(uint id) const
|
||||||
return d->m_activeNotifications.value(id);
|
return d->m_activeNotifications.value(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SnoreCore::displayExapleNotification()
|
void SnoreCore::displayExapleNotification()
|
||||||
{
|
{
|
||||||
Application app = SnoreCorePrivate::instance()->defaultApplication();
|
Application app = SnoreCorePrivate::instance()->defaultApplication();
|
||||||
QString text = QLatin1String("<i>") + tr("This is Snore") + QLatin1String("</i><br>") +
|
QString text = QLatin1String("<i>") + tr("This is Snore") + QLatin1String("</i><br>") +
|
||||||
QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>");
|
QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>");
|
||||||
if(!app.constHints().value("use-markup").toBool()) {
|
if (!app.constHints().value("use-markup").toBool()) {
|
||||||
text = Utils::normalizeMarkup(text, Utils::NO_MARKUP);
|
text = Utils::normalizeMarkup(text, Utils::NO_MARKUP);
|
||||||
}
|
}
|
||||||
Notification noti(app, app.defaultAlert(), tr("Hello World"), text, app.icon());
|
Notification noti(app, app.defaultAlert(), tr("Hello World"), text, app.icon());
|
||||||
|
|
|
@ -148,7 +148,7 @@ void SnoreCorePrivate::init()
|
||||||
void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const QVariant &value)
|
void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
Q_Q(SnoreCore);
|
Q_Q(SnoreCore);
|
||||||
QString nk = normalizeSettingsKey( key + QLatin1String("-SnoreDefault"), LOCAL_SETTING);
|
QString nk = normalizeSettingsKey(key + QLatin1String("-SnoreDefault"), LOCAL_SETTING);
|
||||||
if (!m_settings->contains(nk)) {
|
if (!m_settings->contains(nk)) {
|
||||||
m_settings->setValue(nk, value);
|
m_settings->setValue(nk, value);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ void SnoreCorePrivate::syncSettings()
|
||||||
|
|
||||||
auto types = SnorePlugin::types();
|
auto types = SnorePlugin::types();
|
||||||
types.removeOne(SnorePlugin::BACKEND);
|
types.removeOne(SnorePlugin::BACKEND);
|
||||||
for(auto type : types) {
|
for (auto type : types) {
|
||||||
for (auto &pluginName : m_pluginNames[type]) {
|
for (auto &pluginName : m_pluginNames[type]) {
|
||||||
SnorePlugin *plugin = m_plugins.value(pluginName);
|
SnorePlugin *plugin = m_plugins.value(pluginName);
|
||||||
bool enable = m_plugins[pluginName]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool();
|
bool enable = m_plugins[pluginName]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool();
|
||||||
|
@ -262,11 +262,11 @@ static void registerMetaTypes()
|
||||||
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
|
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void snoreStartup(){
|
static void snoreStartup()
|
||||||
|
{
|
||||||
loadTranslator();
|
loadTranslator();
|
||||||
registerMetaTypes();
|
registerMetaTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_COREAPP_STARTUP_FUNCTION(snoreStartup)
|
Q_COREAPP_STARTUP_FUNCTION(snoreStartup)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -71,19 +71,17 @@ void Utils::raiseWindowToFront(qlonglong wid)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define HTML_REPLACE(STRING, PATTERN){\
|
#define HTML_REPLACE(STRING, PATTERN){\
|
||||||
static QRegExp regexp(QLatin1String(PATTERN));\
|
static QRegExp regexp(QLatin1String(PATTERN));\
|
||||||
STRING = STRING.replace(regexp, QLatin1String("\\1"));\
|
STRING = STRING.replace(regexp, QLatin1String("\\1"));\
|
||||||
}\
|
}\
|
||||||
|
|
||||||
|
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
||||||
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
{
|
||||||
{
|
|
||||||
static QMutex mutex;
|
static QMutex mutex;
|
||||||
if(tags == ALL_MARKUP){
|
if (tags == ALL_MARKUP) {
|
||||||
return string;
|
return string;
|
||||||
} else if(tags == NO_MARKUP) {
|
} else if (tags == NO_MARKUP) {
|
||||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,20 +106,20 @@ QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
||||||
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
|
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
int Utils::attatchToActiveProcess()
|
int Utils::attatchToActiveProcess()
|
||||||
{
|
{
|
||||||
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
|
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
|
||||||
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
|
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::detatchActiveProcess(int idActive)
|
void Utils::detatchActiveProcess(int idActive)
|
||||||
{
|
{
|
||||||
if (idActive != -1) {
|
if (idActive != -1) {
|
||||||
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
|
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,7 +31,7 @@ class SNORE_EXPORT Utils : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum MARKUP_FLAG{
|
enum MARKUP_FLAG {
|
||||||
NO_MARKUP = 0,
|
NO_MARKUP = 0,
|
||||||
HREF = 1 << 0,
|
HREF = 1 << 0,
|
||||||
BREAK = 1 << 1,
|
BREAK = 1 << 1,
|
||||||
|
@ -42,7 +42,7 @@ public:
|
||||||
ALL_MARKUP = ~0
|
ALL_MARKUP = ~0
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(MARKUP_FLAGS,MARKUP_FLAG)
|
Q_DECLARE_FLAGS(MARKUP_FLAGS, MARKUP_FLAG)
|
||||||
|
|
||||||
Utils(QObject *parent = nullptr);
|
Utils(QObject *parent = nullptr);
|
||||||
~Utils();
|
~Utils();
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
|
int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
|
||||||
|
|
||||||
|
|
||||||
FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
|
FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
|
||||||
{
|
{
|
||||||
QImage image(img.convertToFormat(QImage::Format_ARGB32));
|
QImage image(img.convertToFormat(QImage::Format_ARGB32));
|
||||||
|
|
|
@ -53,7 +53,7 @@ bool FreedesktopBackend::canUpdateNotification() const
|
||||||
void FreedesktopBackend::slotNotify(Notification noti)
|
void FreedesktopBackend::slotNotify(Notification noti)
|
||||||
{
|
{
|
||||||
QStringList actions;
|
QStringList actions;
|
||||||
foreach(int k, noti.actions().keys()) {
|
foreach (int k, noti.actions().keys()) {
|
||||||
actions << QString::number(k) << noti.actions()[k].name();
|
actions << QString::number(k) << noti.actions()[k].name();
|
||||||
}
|
}
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
|
@ -63,9 +63,9 @@ void FreedesktopBackend::slotNotify(Notification noti)
|
||||||
}
|
}
|
||||||
|
|
||||||
char urgency = '1';
|
char urgency = '1';
|
||||||
if(noti.priority() < 0){
|
if (noti.priority() < 0) {
|
||||||
urgency = '0';
|
urgency = '0';
|
||||||
} else if(noti.priority() > 2) {
|
} else if (noti.priority() > 2) {
|
||||||
urgency = '2';
|
urgency = '2';
|
||||||
}
|
}
|
||||||
hints.insert(QLatin1String("urgency"), urgency);
|
hints.insert(QLatin1String("urgency"), urgency);
|
||||||
|
|
|
@ -29,13 +29,12 @@ using namespace Snore;
|
||||||
|
|
||||||
GrowlBackend *GrowlBackend::s_instance = nullptr;
|
GrowlBackend *GrowlBackend::s_instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
bool GrowlBackend::initialize()
|
bool GrowlBackend::initialize()
|
||||||
{
|
{
|
||||||
setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost"));
|
setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost"));
|
||||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||||
|
|
||||||
if(!SnoreBackend::initialize()) {
|
if (!SnoreBackend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +79,9 @@ bool GrowlBackend::deinitialize()
|
||||||
|
|
||||||
void GrowlBackend::slotRegisterApplication(const Application &application)
|
void GrowlBackend::slotRegisterApplication(const Application &application)
|
||||||
{
|
{
|
||||||
snoreDebug( SNORE_DEBUG ) << application.name();
|
snoreDebug(SNORE_DEBUG) << application.name();
|
||||||
std::vector<std::string> alerts;
|
std::vector<std::string> alerts;
|
||||||
foreach(const Alert & a, application.alerts()) {
|
foreach (const Alert &a, application.alerts()) {
|
||||||
snoreDebug(SNORE_DEBUG) << a.name();
|
snoreDebug(SNORE_DEBUG) << a.name();
|
||||||
alerts.push_back(a.name().toUtf8().constData());
|
alerts.push_back(a.name().toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ bool SnarlBackend::initialize()
|
||||||
{
|
{
|
||||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||||
|
|
||||||
if(!SnoreBackend::initialize()) {
|
if (!SnoreBackend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
|
||||||
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
|
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
|
||||||
snoreDebug(SNORE_DEBUG) << result;
|
snoreDebug(SNORE_DEBUG) << result;
|
||||||
|
|
||||||
foreach(const Alert & alert, application.alerts()) {
|
foreach (const Alert &alert, application.alerts()) {
|
||||||
snarlInterface->AddClass(alert.name().toUtf8().constData(),
|
snarlInterface->AddClass(alert.name().toUtf8().constData(),
|
||||||
alert.name().toUtf8().constData(),
|
alert.name().toUtf8().constData(),
|
||||||
0, 0, alert.icon().localUrl().toUtf8().constData());
|
0, 0, alert.icon().localUrl().toUtf8().constData());
|
||||||
|
@ -205,11 +205,11 @@ void SnarlBackend::slotNotify(Notification notification)
|
||||||
SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
|
SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
|
||||||
|
|
||||||
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
|
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
|
||||||
if(notification.priority() > 1){
|
if (notification.priority() > 1) {
|
||||||
priority = Snarl::V42::SnarlEnums::PriorityHigh;
|
priority = Snarl::V42::SnarlEnums::PriorityHigh;
|
||||||
} else if(notification.priority() < -1) {
|
} else if (notification.priority() < -1) {
|
||||||
priority = Snarl::V42::SnarlEnums::PriorityLow;
|
priority = Snarl::V42::SnarlEnums::PriorityLow;
|
||||||
}else{
|
} else {
|
||||||
priority = static_cast<Snarl::V42::SnarlEnums::MessagePriority>(notification.priority());
|
priority = static_cast<Snarl::V42::SnarlEnums::MessagePriority>(notification.priority());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ void SnarlBackend::slotNotify(Notification notification)
|
||||||
!notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0,
|
!notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0,
|
||||||
priority);
|
priority);
|
||||||
|
|
||||||
foreach(const Action & a, notification.actions()) {
|
foreach (const Action &a, notification.actions()) {
|
||||||
snarlInterface->AddAction(id, a.name().toUtf8().constData(), (QLatin1Char('@') + QString::number(a.id())).toUtf8().constData());
|
snarlInterface->AddAction(id, a.name().toUtf8().constData(), (QLatin1Char('@') + QString::number(a.id())).toUtf8().constData());
|
||||||
}
|
}
|
||||||
m_idMap[id] = notification;
|
m_idMap[id] = notification;
|
||||||
|
|
|
@ -36,7 +36,7 @@ SnoreNotifier::SnoreNotifier():
|
||||||
snoreDebug(SNORE_DEBUG) << "queue is empty";
|
snoreDebug(SNORE_DEBUG) << "queue is empty";
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
} else {
|
} else {
|
||||||
for(NotifyWidget * w : m_widgets) {
|
for (NotifyWidget *w : m_widgets) {
|
||||||
if (w->acquire()) {
|
if (w->acquire()) {
|
||||||
Notification notification = m_queue.takeFirst();
|
Notification notification = m_queue.takeFirst();
|
||||||
w->display(notification);
|
w->display(notification);
|
||||||
|
@ -86,7 +86,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (m_queue.isEmpty()) {
|
if (m_queue.isEmpty()) {
|
||||||
for(NotifyWidget * w : m_widgets) {
|
for (NotifyWidget *w : m_widgets) {
|
||||||
if (w->acquire()) {
|
if (w->acquire()) {
|
||||||
display(w, notification);
|
display(w, notification);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -16,7 +16,7 @@ using namespace Snore;
|
||||||
|
|
||||||
bool SnoreToast::initialize()
|
bool SnoreToast::initialize()
|
||||||
{
|
{
|
||||||
if(!SnoreBackend::initialize()) {
|
if (!SnoreBackend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
|
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
|
|
||||||
bool TrayIconNotifer::deinitialize()
|
bool TrayIconNotifer::deinitialize()
|
||||||
{
|
{
|
||||||
if (SnoreBackend::deinitialize()) {
|
if (SnoreBackend::deinitialize()) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ using namespace Snore;
|
||||||
bool FreedesktopFrontend::initialize()
|
bool FreedesktopFrontend::initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!SnoreFrontend::initialize()) {
|
if (!SnoreFrontend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_adaptor = new NotificationsAdaptor(this);
|
m_adaptor = new NotificationsAdaptor(this);
|
||||||
|
@ -99,7 +99,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
||||||
qDebug() << QIcon::themeSearchPaths();
|
qDebug() << QIcon::themeSearchPaths();
|
||||||
QIcon qicon = QIcon::fromTheme(app_icon, QIcon(QLatin1String(":/root/snore.png")));
|
QIcon qicon = QIcon::fromTheme(app_icon, QIcon(QLatin1String(":/root/snore.png")));
|
||||||
QSize max;
|
QSize max;
|
||||||
foreach(const QSize & s, qicon.availableSizes()) {
|
foreach (const QSize &s, qicon.availableSizes()) {
|
||||||
if (s.width()*s.height() > max.width()*max.height()) {
|
if (s.width()*s.height() > max.width()*max.height()) {
|
||||||
max = s;
|
max = s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "libsnore/version.h"
|
#include "libsnore/version.h"
|
||||||
#include "libsnore/notification/notification_p.h"
|
#include "libsnore/notification/notification_p.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
@ -32,7 +31,6 @@
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QtWebSockets/QWebSocket>
|
#include <QtWebSockets/QWebSocket>
|
||||||
|
|
||||||
|
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
// TODO: use qtkeychain to encrypt credentials?
|
// TODO: use qtkeychain to encrypt credentials?
|
||||||
|
@ -40,10 +38,10 @@ using namespace Snore;
|
||||||
|
|
||||||
PushoverFrontend::PushoverFrontend()
|
PushoverFrontend::PushoverFrontend()
|
||||||
{
|
{
|
||||||
connect(this, &PushoverFrontend::loggedInChanged, [this](bool state){
|
connect(this, &PushoverFrontend::loggedInChanged, [this](bool state) {
|
||||||
m_loggedIn = state;
|
m_loggedIn = state;
|
||||||
});
|
});
|
||||||
connect(this, &PushoverFrontend::error, [this](QString error){
|
connect(this, &PushoverFrontend::error, [this](QString error) {
|
||||||
m_errorMessage = error;
|
m_errorMessage = error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -53,7 +51,7 @@ bool PushoverFrontend::initialize()
|
||||||
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
|
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
|
||||||
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
|
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
|
||||||
|
|
||||||
if(!SnoreFrontend::initialize()) {
|
if (!SnoreFrontend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +63,7 @@ bool PushoverFrontend::initialize()
|
||||||
bool PushoverFrontend::deinitialize()
|
bool PushoverFrontend::deinitialize()
|
||||||
{
|
{
|
||||||
if (SnoreFrontend::deinitialize()) {
|
if (SnoreFrontend::deinitialize()) {
|
||||||
if(m_socket) {
|
if (m_socket) {
|
||||||
m_socket->close();
|
m_socket->close();
|
||||||
m_socket->deleteLater();
|
m_socket->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -88,20 +86,17 @@ void PushoverFrontend::login(const QString &email, const QString &password, cons
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||||
QNetworkReply *reply = m_manager.post(request, QString(QLatin1String("email=%1&password=%2")).arg(email, password).toUtf8().constData());
|
QNetworkReply *reply = m_manager.post(request, QString(QLatin1String("email=%1&password=%2")).arg(email, password).toUtf8().constData());
|
||||||
|
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() {
|
connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
QByteArray input = reply->readAll();
|
QByteArray input = reply->readAll();
|
||||||
reply->close();
|
reply->close();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
|
|
||||||
QJsonObject message = QJsonDocument::fromJson(input).object();
|
QJsonObject message = QJsonDocument::fromJson(input).object();
|
||||||
|
|
||||||
if(message.value(QLatin1String("status")).toInt() == 1)
|
if (message.value(QLatin1String("status")).toInt() == 1) {
|
||||||
{
|
|
||||||
registerDevice(message.value(QLatin1String("secret")).toString(), deviceName);
|
registerDevice(message.value(QLatin1String("secret")).toString(), deviceName);
|
||||||
}else {
|
} else {
|
||||||
snoreDebug(SNORE_WARNING) << "An error occure" << input;
|
snoreDebug(SNORE_WARNING) << "An error occure" << input;
|
||||||
emit loggedInChanged(false);
|
emit loggedInChanged(false);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +124,7 @@ QString PushoverFrontend::errorMessage()
|
||||||
|
|
||||||
void PushoverFrontend::slotActionInvoked(Notification notification)
|
void PushoverFrontend::slotActionInvoked(Notification notification)
|
||||||
{
|
{
|
||||||
if(notification.priority() == Notification::EMERGENCY){
|
if (notification.priority() == Notification::EMERGENCY) {
|
||||||
snoreDebug(SNORE_WARNING) << "emergeency notification" << notification;
|
snoreDebug(SNORE_WARNING) << "emergeency notification" << notification;
|
||||||
acknowledgeNotification(notification);
|
acknowledgeNotification(notification);
|
||||||
}
|
}
|
||||||
|
@ -147,16 +142,15 @@ QString PushoverFrontend::device()
|
||||||
|
|
||||||
void PushoverFrontend::connectToService()
|
void PushoverFrontend::connectToService()
|
||||||
{
|
{
|
||||||
if(secret().isEmpty() || device().isEmpty())
|
if (secret().isEmpty() || device().isEmpty()) {
|
||||||
{
|
|
||||||
snoreDebug(SNORE_WARNING) << "not logged in";
|
snoreDebug(SNORE_WARNING) << "not logged in";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this);
|
m_socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this);
|
||||||
|
|
||||||
connect(m_socket, &QWebSocket::binaryMessageReceived, [&](const QByteArray &msg){
|
connect(m_socket, &QWebSocket::binaryMessageReceived, [&](const QByteArray & msg) {
|
||||||
char c = msg.at(0);
|
char c = msg.at(0);
|
||||||
switch(c){
|
switch (c) {
|
||||||
case '#':
|
case '#':
|
||||||
snoreDebug(SNORE_DEBUG) << "still alive";
|
snoreDebug(SNORE_DEBUG) << "still alive";
|
||||||
break;
|
break;
|
||||||
|
@ -180,14 +174,14 @@ void PushoverFrontend::connectToService()
|
||||||
snoreDebug(SNORE_WARNING) << "unknown message recieved" << msg;
|
snoreDebug(SNORE_WARNING) << "unknown message recieved" << msg;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(m_socket, &QWebSocket::disconnected, [](){
|
connect(m_socket, &QWebSocket::disconnected, []() {
|
||||||
snoreDebug(SNORE_DEBUG) << "disconnected";
|
snoreDebug(SNORE_DEBUG) << "disconnected";
|
||||||
});
|
});
|
||||||
connect(m_socket, static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), [&](QAbstractSocket::SocketError error){
|
connect(m_socket, static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), [&](QAbstractSocket::SocketError error) {
|
||||||
snoreDebug(SNORE_WARNING) << error << m_socket->errorString();
|
snoreDebug(SNORE_WARNING) << error << m_socket->errorString();
|
||||||
emit loggedInChanged(false);
|
emit loggedInChanged(false);
|
||||||
});
|
});
|
||||||
connect(m_socket, &QWebSocket::connected, [&](){
|
connect(m_socket, &QWebSocket::connected, [&]() {
|
||||||
snoreDebug(SNORE_DEBUG) << "connecting";
|
snoreDebug(SNORE_DEBUG) << "connecting";
|
||||||
m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData());
|
m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData());
|
||||||
emit loggedInChanged(true);
|
emit loggedInChanged(true);
|
||||||
|
@ -203,14 +197,13 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData());
|
QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData());
|
||||||
|
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::finished, [reply, secret, this]() {
|
connect(reply, &QNetworkReply::finished, [reply, secret, this]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
QByteArray input = reply->readAll();
|
QByteArray input = reply->readAll();
|
||||||
reply->close();
|
reply->close();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
QJsonObject message = QJsonDocument::fromJson(input).object();
|
QJsonObject message = QJsonDocument::fromJson(input).object();
|
||||||
if(message.value(QLatin1String("status")).toInt() == 1) {
|
if (message.value(QLatin1String("status")).toInt() == 1) {
|
||||||
setSettingsValue(QLatin1String("Secret"), secret, LOCAL_SETTING);
|
setSettingsValue(QLatin1String("Secret"), secret, LOCAL_SETTING);
|
||||||
setSettingsValue(QLatin1String("DeviceID"), message.value(QLatin1String("id")).toString(), LOCAL_SETTING);;
|
setSettingsValue(QLatin1String("DeviceID"), message.value(QLatin1String("id")).toString(), LOCAL_SETTING);;
|
||||||
connectToService();
|
connectToService();
|
||||||
|
@ -222,7 +215,6 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PushoverFrontend::getMessages()
|
void PushoverFrontend::getMessages()
|
||||||
|
@ -231,8 +223,7 @@ void PushoverFrontend::getMessages()
|
||||||
"secret=") + secret() + QLatin1String("&device_id=") + device()).toUtf8().constData()));
|
"secret=") + secret() + QLatin1String("&device_id=") + device()).toUtf8().constData()));
|
||||||
QNetworkReply *reply = m_manager.get(request);
|
QNetworkReply *reply = m_manager.get(request);
|
||||||
|
|
||||||
|
connect(reply, &QNetworkReply::finished, [reply, this]() {
|
||||||
connect(reply, &QNetworkReply::finished, [reply,this]() {
|
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
QByteArray input = reply->readAll();
|
QByteArray input = reply->readAll();
|
||||||
reply->close();
|
reply->close();
|
||||||
|
@ -243,9 +234,9 @@ void PushoverFrontend::getMessages()
|
||||||
QJsonObject message = QJsonDocument::fromJson(input).object();
|
QJsonObject message = QJsonDocument::fromJson(input).object();
|
||||||
|
|
||||||
int latestID = -1;
|
int latestID = -1;
|
||||||
if(message.value(QLatin1String("status")).toInt() == 1){
|
if (message.value(QLatin1String("status")).toInt() == 1) {
|
||||||
QJsonArray notifications = message.value(QLatin1String("messages")).toArray();
|
QJsonArray notifications = message.value(QLatin1String("messages")).toArray();
|
||||||
for( const QJsonValue &v : notifications) {
|
for (const QJsonValue &v : notifications) {
|
||||||
QJsonObject notification = v.toObject();
|
QJsonObject notification = v.toObject();
|
||||||
|
|
||||||
latestID = qMax(latestID, notification.value(QLatin1String("id")).toInt());
|
latestID = qMax(latestID, notification.value(QLatin1String("id")).toInt());
|
||||||
|
@ -253,7 +244,7 @@ void PushoverFrontend::getMessages()
|
||||||
QString appName = notification.value(QLatin1String("app")).toString();
|
QString appName = notification.value(QLatin1String("app")).toString();
|
||||||
Application app = SnoreCore::instance().aplications().value(appName);
|
Application app = SnoreCore::instance().aplications().value(appName);
|
||||||
|
|
||||||
if (!app.isValid()){
|
if (!app.isValid()) {
|
||||||
Icon icon(QLatin1String("https://api.pushover.net/icons/") +
|
Icon icon(QLatin1String("https://api.pushover.net/icons/") +
|
||||||
notification.value(QLatin1String("icon")).toString() +
|
notification.value(QLatin1String("icon")).toString() +
|
||||||
QLatin1String(".png"));
|
QLatin1String(".png"));
|
||||||
|
@ -261,21 +252,20 @@ void PushoverFrontend::getMessages()
|
||||||
SnoreCore::instance().registerApplication(app);
|
SnoreCore::instance().registerApplication(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Notification n(app, app.defaultAlert(), notification.value(QLatin1String("title")).toString(),
|
Notification n(app, app.defaultAlert(), notification.value(QLatin1String("title")).toString(),
|
||||||
notification.value(QLatin1String("message")).toString(),
|
notification.value(QLatin1String("message")).toString(),
|
||||||
app.icon(), Notification::defaultTimeout(),
|
app.icon(), Notification::defaultTimeout(),
|
||||||
static_cast<Notification::Prioritys>(notification.value(QLatin1String("priority")).toInt()));
|
static_cast<Notification::Prioritys>(notification.value(QLatin1String("priority")).toInt()));
|
||||||
if(n.priority() == Notification::EMERGENCY){
|
if (n.priority() == Notification::EMERGENCY) {
|
||||||
n.hints().setValue("receipt", notification.value(QLatin1String("receipt")).toString());
|
n.hints().setValue("receipt", notification.value(QLatin1String("receipt")).toString());
|
||||||
n.hints().setValue("acked", notification.value(QLatin1String("acked")).toInt());
|
n.hints().setValue("acked", notification.value(QLatin1String("acked")).toInt());
|
||||||
}
|
}
|
||||||
if(notification.value(QLatin1String("html")).toInt() == 1) {
|
if (notification.value(QLatin1String("html")).toInt() == 1) {
|
||||||
n.hints().setValue("use-markup", true) ;
|
n.hints().setValue("use-markup", true) ;
|
||||||
}
|
}
|
||||||
SnoreCore::instance().broadcastNotification(n);
|
SnoreCore::instance().broadcastNotification(n);
|
||||||
}
|
}
|
||||||
if(latestID != -1){
|
if (latestID != -1) {
|
||||||
deleteMessages(latestID);
|
deleteMessages(latestID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -295,7 +285,6 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret() + QLatin1String("&message=") + QString::number(latestMessageId)).toUtf8().constData());
|
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret() + QLatin1String("&message=") + QString::number(latestMessageId)).toUtf8().constData());
|
||||||
|
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||||
|
@ -306,7 +295,7 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
|
||||||
|
|
||||||
void PushoverFrontend::acknowledgeNotification(Notification notification)
|
void PushoverFrontend::acknowledgeNotification(Notification notification)
|
||||||
{
|
{
|
||||||
if(notification.constHints().value("acked").toInt() == 1){
|
if (notification.constHints().value("acked").toInt() == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
|
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
|
||||||
|
@ -318,7 +307,6 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData());
|
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData());
|
||||||
|
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||||
|
@ -328,4 +316,3 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QtWebSockets/QWebSocket>
|
#include <QtWebSockets/QWebSocket>
|
||||||
|
|
||||||
|
|
||||||
class PushoverFrontend : public Snore::SnoreFrontend
|
class PushoverFrontend : public Snore::SnoreFrontend
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -39,7 +38,7 @@ public:
|
||||||
|
|
||||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||||
|
|
||||||
void login(const QString &email, const QString &password, const QString& deviceName);
|
void login(const QString &email, const QString &password, const QString &deviceName);
|
||||||
void logOut();
|
void logOut();
|
||||||
|
|
||||||
bool isLoggedIn() const;
|
bool isLoggedIn() const;
|
||||||
|
@ -68,9 +67,6 @@ private:
|
||||||
void deleteMessages(int latestMessageId);
|
void deleteMessages(int latestMessageId);
|
||||||
void acknowledgeNotification(Snore::Notification notification);
|
void acknowledgeNotification(Snore::Notification notification);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//PUSHOVER_FRONTEND_H
|
#endif//PUSHOVER_FRONTEND_H
|
||||||
|
|
|
@ -39,28 +39,28 @@ PushoverSettings::PushoverSettings(Snore::SnorePlugin *plugin, QWidget *parent)
|
||||||
addRow(QString(), m_registerButton);
|
addRow(QString(), m_registerButton);
|
||||||
addRow(tr("Status"), m_errorMessageLabel);
|
addRow(tr("Status"), m_errorMessageLabel);
|
||||||
addRow(QString(), new QLabel(this));
|
addRow(QString(), new QLabel(this));
|
||||||
addRow(QString(), new QLabel(tr("If you don't have an accout yet please register at <a href=\"https://pushover.net\">Pushover.net</a>"),this));
|
addRow(QString(), new QLabel(tr("If you don't have an accout yet please register at <a href=\"https://pushover.net\">Pushover.net</a>"), this));
|
||||||
|
|
||||||
m_emailLineEdit->setEnabled(false);
|
m_emailLineEdit->setEnabled(false);
|
||||||
m_passwordLineEdit->setEnabled(false);
|
m_passwordLineEdit->setEnabled(false);
|
||||||
m_deviceLineEdit->setEnabled(false);
|
m_deviceLineEdit->setEnabled(false);
|
||||||
m_registerButton->setEnabled(false);
|
m_registerButton->setEnabled(false);
|
||||||
|
|
||||||
PushoverFrontend *pushover = dynamic_cast<PushoverFrontend*>(plugin);
|
PushoverFrontend *pushover = dynamic_cast<PushoverFrontend *>(plugin);
|
||||||
m_errorMessageLabel->setText(pushover->errorMessage());
|
m_errorMessageLabel->setText(pushover->errorMessage());
|
||||||
|
|
||||||
connect(pushover, &PushoverFrontend::loggedInChanged, this, &PushoverSettings::slotUpdateLoginState);
|
connect(pushover, &PushoverFrontend::loggedInChanged, this, &PushoverSettings::slotUpdateLoginState);
|
||||||
connect(pushover, &PushoverFrontend::error, [this](QString message){
|
connect(pushover, &PushoverFrontend::error, [this](QString message) {
|
||||||
m_errorMessageLabel->setText(message);
|
m_errorMessageLabel->setText(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
slotUpdateLoginState(pushover->isLoggedIn());
|
slotUpdateLoginState(pushover->isLoggedIn());
|
||||||
|
|
||||||
connect(m_registerButton, &QPushButton::clicked, [pushover, this] () {
|
connect(m_registerButton, &QPushButton::clicked, [pushover, this]() {
|
||||||
m_registerButton->setEnabled(false);
|
m_registerButton->setEnabled(false);
|
||||||
if(!pushover->isLoggedIn()) {
|
if (!pushover->isLoggedIn()) {
|
||||||
pushover->login(m_emailLineEdit->text(), m_passwordLineEdit->text(), m_deviceLineEdit->text());
|
pushover->login(m_emailLineEdit->text(), m_passwordLineEdit->text(), m_deviceLineEdit->text());
|
||||||
}else{
|
} else {
|
||||||
pushover->logOut();
|
pushover->logOut();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,6 @@ private:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void slotUpdateLoginState(bool state);
|
void slotUpdateLoginState(bool state);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PUSHOVERSETTINGS_H
|
#endif // PUSHOVERSETTINGS_H
|
||||||
|
|
|
@ -64,7 +64,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
|
||||||
QByteArray key;
|
QByteArray key;
|
||||||
QString value;
|
QString value;
|
||||||
|
|
||||||
foreach(QString s, splitted) {
|
foreach (QString s, splitted) {
|
||||||
key = s.mid(0, s.indexOf(QLatin1String("="))).toLower().toLatin1();
|
key = s.mid(0, s.indexOf(QLatin1String("="))).toLower().toLatin1();
|
||||||
value = s.mid(s.indexOf(QLatin1String("=")) + 1);
|
value = s.mid(s.indexOf(QLatin1String("=")) + 1);
|
||||||
switch (getSnpType.value(key)) {
|
switch (getSnpType.value(key)) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ using namespace Snore;
|
||||||
|
|
||||||
bool SnarlNetworkFrontend::initialize()
|
bool SnarlNetworkFrontend::initialize()
|
||||||
{
|
{
|
||||||
if(!SnoreFrontend::initialize()) {
|
if (!SnoreFrontend::initialize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
parser = new Parser(this);
|
parser = new Parser(this);
|
||||||
|
@ -99,7 +99,7 @@ void SnarlNetworkFrontend::handleMessages()
|
||||||
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
|
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
|
||||||
|
|
||||||
QStringList messages(QString::fromLatin1(client->readAll()).trimmed().split(QLatin1String("\r\n")));
|
QStringList messages(QString::fromLatin1(client->readAll()).trimmed().split(QLatin1String("\r\n")));
|
||||||
foreach(const QString & s, messages) {
|
foreach (const QString &s, messages) {
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ void SnarlNetworkFrontend::callback(Notification &sn, const QString msg)
|
||||||
{
|
{
|
||||||
if (sn.hints().containsPrivateValue(this, "clientSocket")) {
|
if (sn.hints().containsPrivateValue(this, "clientSocket")) {
|
||||||
QTcpSocket *client = sn.hints().privateValue(this, "clientSocket").value<QPointer<QTcpSocket>>();
|
QTcpSocket *client = sn.hints().privateValue(this, "clientSocket").value<QPointer<QTcpSocket>>();
|
||||||
if(client){
|
if (client) {
|
||||||
write(client, QString(QLatin1String("%1%2\r\n")).arg(msg, QString::number(sn.id())));
|
write(client, QString(QLatin1String("%1%2\r\n")).arg(msg, QString::number(sn.id())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,22 +36,20 @@ void NotifyMyAndroid::slotNotify(Notification notification)
|
||||||
QNetworkRequest request(QUrl::fromEncoded("https://www.notifymyandroid.com/publicapi/notify"));
|
QNetworkRequest request(QUrl::fromEncoded("https://www.notifymyandroid.com/publicapi/notify"));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||||
|
|
||||||
|
|
||||||
QString data = QLatin1String("apikey=") + key
|
QString data = QLatin1String("apikey=") + key
|
||||||
+ QLatin1String("&application=") + notification.application().name()
|
+ QLatin1String("&application=") + notification.application().name()
|
||||||
+ QLatin1String("&event=") + notification.title()
|
+ QLatin1String("&event=") + notification.title()
|
||||||
+ QLatin1String("&priority=") + QString::number(notification.priority())
|
+ QLatin1String("&priority=") + QString::number(notification.priority())
|
||||||
+ QLatin1String("&description=");
|
+ QLatin1String("&description=");
|
||||||
|
|
||||||
if(notification.constHints().value("supports-markup").toBool()){
|
if (notification.constHints().value("supports-markup").toBool()) {
|
||||||
data += notification.text(Utils::HREF | Utils::BOLD | Utils::BREAK |
|
data += notification.text(Utils::HREF | Utils::BOLD | Utils::BREAK |
|
||||||
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC)
|
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC)
|
||||||
+ QLatin1String("&content-type=text/html");
|
+ QLatin1String("&content-type=text/html");
|
||||||
}else{
|
} else {
|
||||||
data += notification.text();
|
data += notification.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QNetworkReply *reply = m_manager.post(request, data.toUtf8().constData());
|
QNetworkReply *reply = m_manager.post(request, data.toUtf8().constData());
|
||||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
|
|
|
@ -43,7 +43,7 @@ void Pushover::slotNotify(Notification notification)
|
||||||
mp->append(title);
|
mp->append(title);
|
||||||
|
|
||||||
QString textString;
|
QString textString;
|
||||||
if(notification.constHints().value("use-markup").toBool()){
|
if (notification.constHints().value("use-markup").toBool()) {
|
||||||
textString = notification.text(Utils::HREF | Utils::BOLD | Utils::UNDERLINE | Utils::FONT | Utils::ITALIC);
|
textString = notification.text(Utils::HREF | Utils::BOLD | Utils::UNDERLINE | Utils::FONT | Utils::ITALIC);
|
||||||
|
|
||||||
QHttpPart html;
|
QHttpPart html;
|
||||||
|
@ -65,7 +65,7 @@ void Pushover::slotNotify(Notification notification)
|
||||||
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"priority\"")));
|
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"priority\"")));
|
||||||
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
|
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
|
||||||
mp->append(priority);
|
mp->append(priority);
|
||||||
if(notification.priority() == Notification::EMERGENCY){
|
if (notification.priority() == Notification::EMERGENCY) {
|
||||||
|
|
||||||
QHttpPart retry;
|
QHttpPart retry;
|
||||||
retry.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"retry\"")));
|
retry.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"retry\"")));
|
||||||
|
|
|
@ -25,7 +25,7 @@ bool setSetting(const QString &appName, SettingsType type, const QString &_key,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
settings.setValue(key, value);
|
settings.setValue(key, value);
|
||||||
cout <<"Set: " << qPrintable(key) << " to " << qPrintable(settings.value(key).toString()) << endl;
|
cout << "Set: " << qPrintable(key) << " to " << qPrintable(settings.value(key).toString()) << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void listSettings(SettingsType type, const QString &application)
|
||||||
cout << qPrintable(application) << endl;
|
cout << qPrintable(application) << endl;
|
||||||
for (const QString &key : Utils::allSettingsKeysWithPrefix(
|
for (const QString &key : Utils::allSettingsKeysWithPrefix(
|
||||||
Utils::normalizeSettingsKey(QLatin1String(""), type, application), settings, getAllKeys)) {
|
Utils::normalizeSettingsKey(QLatin1String(""), type, application), settings, getAllKeys)) {
|
||||||
cout <<" " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, application)).toString()) << endl;
|
cout << " " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, application)).toString()) << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
||||||
QCommandLineOption appNameCommand({QLatin1String("a"), QLatin1String("appName")} , QLatin1String("Set the Name of the app <app>."), QLatin1String("app"), QLatin1String("GlobalSettings"));
|
QCommandLineOption appNameCommand({QLatin1String("a"), QLatin1String("appName")} , QLatin1String("Set the Name of the app <app>."), QLatin1String("app"), QLatin1String("GlobalSettings"));
|
||||||
parser.addOption(appNameCommand);
|
parser.addOption(appNameCommand);
|
||||||
|
|
||||||
QCommandLineOption typeCommand({QLatin1String("t"),QLatin1String("type")} ,QLatin1String("Type of the setting [global|local]."),QLatin1String("type"));
|
QCommandLineOption typeCommand({QLatin1String("t"), QLatin1String("type")} , QLatin1String("Type of the setting [global|local]."), QLatin1String("type"));
|
||||||
parser.addOption(typeCommand);
|
parser.addOption(typeCommand);
|
||||||
|
|
||||||
parser.addPositionalArgument(QLatin1String("key"), QLatin1String("The settings Key."));
|
parser.addPositionalArgument(QLatin1String("key"), QLatin1String("The settings Key."));
|
||||||
|
|
Loading…
Reference in New Issue