added pushover support

This commit is contained in:
Patrick von Reth 2015-06-22 20:19:23 +02:00
parent a91ee4579c
commit 252b7588cf
12 changed files with 274 additions and 11 deletions

View File

@ -103,9 +103,10 @@ public:
* Returns application specific hints:
* Key | Value | Required
* ------------- | ----------- | -----------
* desktop-entry | The name of the desktop enty associated with the application | Used for The freedesktop backend
* windows-app-id | The app id associated with the application | Needed for the Windows 8 backend [See MSDN Documentation](http://msdn.microsoft.com/en-us/library/windows/apps/dd378459.aspx)
* tray-icon | A instance of QSystemTray | Needed for the System Tray Backend
* desktop-entry | The name of the desktop enty associated with the application. | Used for The freedesktop backend.
* windows-app-id | The app id associated with the application. | Needed for the Windows 8 backend [See MSDN Documentation](http://msdn.microsoft.com/en-us/library/windows/apps/dd378459.aspx).
* tray-icon | A pointer to a QSystemTray item. | Needed for the System Tray Backend.
* pushover-token | The token associated with your application. | Needed to associate pushover notification with your application, to register your application visit [Pushover](https://pushover.net/apps/build).
*/
Hint &hints();

View File

@ -74,15 +74,15 @@ bool PluginSettingsWidget::isDirty()
return m_dirty;
}
QVariant PluginSettingsWidget::value(const QString &key) const
QVariant PluginSettingsWidget::value(const QString &key, SettingsType type) const
{
return m_snorePlugin->value(key);
return m_snorePlugin->value(key, type);
}
void PluginSettingsWidget::setValue(const QString &key, const QVariant &value)
void PluginSettingsWidget::setValue(const QString &key, const QVariant &value, SettingsType type)
{
if (this->value(key) != value) {
m_snorePlugin->setValue(key, value);
m_snorePlugin->setValue(key, value, type);
m_dirty = true;
}
}

View File

@ -19,6 +19,7 @@
#define PLUGINSETTINGSWIDGET_H
#include "libsnore/snore_exports.h"
#include "libsnore/snoreglobals.h"
#include <QWidget>
#include <QFormLayout>
@ -45,8 +46,8 @@ public:
bool isDirty();
protected:
QVariant value(const QString &key) const;
void setValue(const QString &key, const QVariant &value);
QVariant value(const QString &key, Snore::SettingsType type = Snore::GLOBAL_SETTING) const;
void setValue(const QString &key, const QVariant &value, Snore::SettingsType type = Snore::GLOBAL_SETTING);
virtual void load();
virtual void save();

View File

@ -196,6 +196,7 @@ QString SnoreCorePrivate::tempPath()
return dir.path();
}
// TODO: this is somehow horrible code
SnoreCorePrivate *SnoreCorePrivate::instance()
{
return SnoreCore::instance().d_ptr;

View File

@ -1,3 +1,4 @@
add_subdirectory(toasty)
add_subdirectory(nma)
add_subdirectory(sound)
add_subdirectory(pushover)

View File

@ -0,0 +1,10 @@
set( PUSHOVER_SRC
pushover.cpp
pushoversettings.cpp
)
add_library(libsnore_secondary_backend_pushover MODULE ${PUSHOVER_SRC} )
target_link_libraries(libsnore_secondary_backend_pushover Snore::Libsnore)
install(TARGETS libsnore_secondary_backend_pushover ${SNORE_PLUGIN_INSTALL_PATH})

View File

@ -0,0 +1 @@
{ "type" : "secondary_backend", "name" : "Pushover" }

View File

@ -0,0 +1,111 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 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
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pushover.h"
#include "pushoversettings.h"
#include"libsnore/utils.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QHttpMultiPart>
using namespace Snore;
Pushover::Pushover():
SnoreSecondaryBackend("Pushover", false)
{
setDefaultValue("UserKey", "");
setDefaultValue("Sound", "pushover", LOCAL_SETTING);
setDefaultValue("Devices", "", LOCAL_SETTING);
}
Pushover::~Pushover()
{
}
void Pushover::slotNotify(Notification notification)
{
QString key = value("ApiKey").toString();
if (key.isEmpty()) {
return;
}
QNetworkRequest request(QUrl("https://api.pushover.net/1/messages.json"));
QHttpMultiPart *mp = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart title;
title.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\""));
title.setBody(Utils::toPlainText(notification.title()).toUtf8().constData());
mp->append(title);
QHttpPart text;
text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"message\""));
text.setBody(Utils::toPlainText(notification.text()).toUtf8().constData());
mp->append(text);
QHttpPart priority;
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"priority\""));
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
mp->append(priority);
QHttpPart sound;
sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\""));
if (notification.hints().value("silent", false).toBool()) {
sound.setBody("none");
} else {
sound.setBody(value("Sound", LOCAL_SETTING).toString().toUtf8().constData());
}
mp->append(sound);
if (!value("Devices", LOCAL_SETTING).toString().isEmpty()) {
QHttpPart devices;
devices.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"device\""));
devices.setBody(value("Devices", LOCAL_SETTING).toString().toUtf8().constData());
mp->append(devices);
}
QHttpPart token;
token.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"token\""));
token.setBody(notification.application().constHints().value("pushover-token","aFB1TPCyZkkr7mubCGEKy5vJEWak9t").toString().toUtf8().constData());
mp->append(token);
QHttpPart user;
user.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"user\""));
user.setBody(key.toUtf8().constData());
mp->append(user);
QNetworkReply *reply = m_manager.post(request, mp);
mp->setParent(reply);
connect(reply, &QNetworkReply::finished, [reply]() {
snoreDebug(SNORE_DEBUG) << reply->error();
snoreDebug(SNORE_DEBUG) << reply->readAll();
reply->close();
reply->deleteLater();
});
}
PluginSettingsWidget *Pushover::settingsWidget()
{
return new PushoverSettings(this);
}

View File

@ -0,0 +1,44 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 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
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PUSHOVER_H
#define PUSHOVER_H
#include "libsnore/plugins/snorebackend.h"
#include <QNetworkAccessManager>
class Pushover : public Snore::SnoreSecondaryBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
Pushover();
~Pushover();
Snore::PluginSettingsWidget *settingsWidget() override;
public slots:
void slotNotify(Snore::Notification notification) override;
private:
QNetworkAccessManager m_manager;
};
#endif // PUSHOVER_H

View File

@ -0,0 +1,51 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 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
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pushoversettings.h"
#include "plugins/plugins.h"
#include <QLineEdit>
PushoverSettings::PushoverSettings(Snore::SnorePlugin *plugin, QWidget *parent) :
Snore::PluginSettingsWidget(plugin, parent),
m_keyLineEdit(new QLineEdit(this)),
m_soundLineEdit(new QLineEdit(this)),
m_deviceLineEdit(new QLineEdit(this))
{
addRow(tr("User Key:"), m_keyLineEdit);
addRow(tr("Sound:"), m_soundLineEdit);
addRow(tr("Devices:"), m_deviceLineEdit);
}
PushoverSettings::~PushoverSettings()
{
}
void PushoverSettings::load()
{
m_keyLineEdit->setText(value("UserKey").toString());
m_soundLineEdit->setText(value("Sound", Snore::LOCAL_SETTING).toString());
m_deviceLineEdit->setText(value("Devices", Snore::LOCAL_SETTING).toString());
}
void PushoverSettings::save()
{
setValue("UserKey", m_keyLineEdit->text());
setValue("Sound", m_soundLineEdit->text(), Snore::LOCAL_SETTING);
setValue("Devices", m_deviceLineEdit->text(), Snore::LOCAL_SETTING);
}

View File

@ -0,0 +1,42 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 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
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PUSHOVERSETTINGS_H
#define PUSHOVERSETTINGS_H
#include "plugins/pluginsettingswidget.h"
class QLineEdit;
class PushoverSettings : public Snore::PluginSettingsWidget
{
Q_OBJECT
public:
explicit PushoverSettings(Snore::SnorePlugin *plugin, QWidget *parent = 0);
~PushoverSettings();
void load() override;
void save() override;
private:
QLineEdit *m_keyLineEdit;
QLineEdit *m_soundLineEdit;
QLineEdit *m_deviceLineEdit;
};
#endif // PUSHOVERSETTINGS_H

View File

@ -53,7 +53,7 @@ void listSettings(SettingsType type, const QString &application)
int main(int argc, char *argv[])
{
QScopedPointer<SettingsWindow> window;
SettingsWindow *window;
QApplication app(argc, argv);
app.setApplicationName("SnoreSettings");
@ -103,7 +103,7 @@ int main(int argc, char *argv[])
} else if (parser.isSet(listSettingsCommand)) {
listSettings(type, parser.value(appNameCommand));
} else if (parser.optionNames().empty() && parser.positionalArguments().empty()) {
window.reset(new SettingsWindow());
window = new SettingsWindow();
window->show();
return app.exec();
} else {