Move settings keys to constants

This commit is contained in:
Hannah von Reth 2017-08-01 08:50:40 +02:00
parent 45f837654c
commit ad4eb3d502
39 changed files with 250 additions and 111 deletions

View File

@ -1,6 +1,7 @@
#include <libsnore/snore.h>
#include <libsnore/snore_p.h>
#include <libsnore/utils.h>
#include <libsnore/snoreconstants.h>
#include <QTextDocument>
@ -17,7 +18,7 @@ public:
{
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::Backend);
instance.setSettingsValue(QStringLiteral("Timeout"), 10, LocalSetting);
instance.setSettingsValue(Snore::Constants::SettingsKeys::Timeout, 10);
SnoreCore::instance().registerApplication(app);
}
@ -46,7 +47,7 @@ private:
QString old = snore.primaryNotificationBackend();
while (!backends.empty() && snore.primaryNotificationBackend() == old) {
QString p = backends.takeLast();
snore.setSettingsValue(QStringLiteral("PrimaryBackend"), p, LocalSetting);
snore.setSettingsValue(Snore::Constants::SettingsKeys::PrimaryBackend, p);
SnoreCorePrivate::instance()->syncSettings();
if (snore.primaryNotificationBackend() == p) {
for (const auto &message : messages) {

View File

@ -1,6 +1,7 @@
#include <libsnore/snore.h>
#include <libsnore/snore_p.h>
#include <libsnore/utils.h>
#include <libsnore/snoreconstants.h>
#include <QTextDocument>
@ -16,7 +17,7 @@ public:
{
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::Backend);
instance.setSettingsValue(QStringLiteral("Timeout"), 1, LocalSetting);
instance.setSettingsValue(Snore::Constants::SettingsKeys::Timeout, 1);
}
// clazy is complaining about this string but QStringLiteral won't work for the multiline string, so use QStringBuilder to silence it.

View File

@ -19,6 +19,7 @@
#include "application_p.h"
#include "lambdahint.h"
#include "snore_p.h"
#include "snoreconstants.h"
#include <QGuiApplication>
@ -36,7 +37,7 @@ ApplicationData::ApplicationData(const QString &key, const QString &name, const
m_hint.setValue("pushover-token", QLatin1String("aFB1TPCyZkkr7mubCGEKy5vJEWak9t"));
m_hint.setValue("use-markup", false);
m_hint.setValue("silent", QVariant::fromValue(LambdaHint([]() {
return SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting);
return SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent);
})));
}

View File

@ -18,6 +18,7 @@
#include "notification.h"
#include "snore.h"
#include "snoreconstants.h"
#include "notification/icon.h"
#include "notification/notification_p.h"
#include "plugins/plugincontainer.h"
@ -181,7 +182,7 @@ NotificationData *Notification::data()
int Notification::defaultTimeout()
{
return SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt();
return SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt();
}
QDataStream &operator<< (QDataStream &stream, const Notification &noti)

View File

@ -18,6 +18,7 @@
#include "../snore.h"
#include "../snore_p.h"
#include "../snoreconstants.h"
#include "snorebackend.h"
#include "snorefrontend.h"
#include "../notification/notification_p.h"
@ -47,19 +48,19 @@ bool SnorePlugin::isEnabled() const
return m_enabled;
}
QVariant SnorePlugin::settingsValue(const QString &key, SettingsType type) const
QVariant SnorePlugin::settingsValue(const SettingsKey &key) const
{
return SnoreCore::instance().settingsValue(normaliseKey(key), type);
return SnoreCore::instance().settingsValue(normaliseKey(key));
}
void SnorePlugin::setSettingsValue(const QString &key, const QVariant &value, SettingsType type)
void SnorePlugin::setSettingsValue(const SettingsKey &key, const QVariant &value)
{
SnoreCore::instance().setSettingsValue(normaliseKey(key), value, type);
SnoreCore::instance().setSettingsValue(normaliseKey(key), value);
}
void SnorePlugin::setDefaultSettingsValue(const QString &key, const QVariant &value, SettingsType type)
void SnorePlugin::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value)
{
SnoreCore::instance().setDefaultSettingsValue(normaliseKey(key), value, type);
SnoreCore::instance().setDefaultSettingsValue(normaliseKey(key), value);
}
const Hint &SnorePlugin::constHints() const
@ -72,9 +73,9 @@ Hint &SnorePlugin::hints()
return m_hints;
}
QString SnorePlugin::normaliseKey(const QString &key) const
SettingsKey SnorePlugin::normaliseKey(const SettingsKey &key) const
{
return name() + QLatin1Char('-') + typeName() + QLatin1Char('/') + key + QLatin1Char('.') + settingsVersion();
return SettingsKey{name() + QLatin1Char('-') + typeName() + QLatin1Char('/') + key.key + QLatin1Char('.') + settingsVersion(), key.type};
}
const QString &SnorePlugin::name() const
@ -104,7 +105,7 @@ QString SnorePlugin::settingsVersion() const
void SnorePlugin::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("Enabled"), false, LocalSetting);
setDefaultSettingsValue(Constants::SettingsKeys::Enabled, false);
}
void SnorePlugin::setErrorString(const QString &_error)

View File

@ -133,9 +133,9 @@ public:
*/
QString errorString() const;
QVariant settingsValue(const QString &key, SettingsType type = GlobalSetting) const;
void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting);
void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting);
QVariant settingsValue(const SettingsKey &key) const;
void setSettingsValue(const SettingsKey &key, const QVariant &settingsValue);
void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue);
const Hint &constHints() const;
@ -158,7 +158,7 @@ protected:
Hint &hints();
private:
QString normaliseKey(const QString &key) const;
SettingsKey normaliseKey(const SettingsKey &key) const;
void setDefaultSettingsPlugin();
bool m_enabled = false;

View File

@ -17,6 +17,7 @@
*/
#include "pluginsettingswidget.h"
#include "libsnore/plugins/plugins.h"
#include "libsnore/snoreconstants.h"
#include "snore.h"
#include <QCheckBox>
@ -61,7 +62,7 @@ void PluginSettingsWidget::addRow(const QString &label, QWidget *widget, const Q
void PluginSettingsWidget::loadSettings()
{
if (m_snorePlugin->type() != SnorePlugin::Backend) {
m_enabled->setChecked(m_snorePlugin->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool());
m_enabled->setChecked(m_snorePlugin->settingsValue(Constants::SettingsKeys::Enabled).toBool());
}
load();
}
@ -69,7 +70,7 @@ void PluginSettingsWidget::loadSettings()
void PluginSettingsWidget::saveSettings()
{
if (m_snorePlugin->type() != SnorePlugin::Backend) {
m_snorePlugin->setSettingsValue(QStringLiteral("Enabled"), m_enabled->isChecked(), LocalSetting);
m_snorePlugin->setSettingsValue(Constants::SettingsKeys::Enabled, m_enabled->isChecked());
}
save();
}
@ -79,15 +80,15 @@ bool PluginSettingsWidget::isDirty()
return m_dirty;
}
QVariant PluginSettingsWidget::settingsValue(const QString &key, SettingsType type) const
QVariant PluginSettingsWidget::settingsValue(const SettingsKey &key) const
{
return m_snorePlugin->settingsValue(key, type);
return m_snorePlugin->settingsValue(key);
}
void PluginSettingsWidget::setSettingsValue(const QString &key, const QVariant &value, SettingsType type)
void PluginSettingsWidget::setSettingsValue(const SettingsKey &key, const QVariant &value)
{
if (this->settingsValue(key) != value) {
m_snorePlugin->setSettingsValue(key, value, type);
m_snorePlugin->setSettingsValue(key, value);
m_dirty = true;
}
}

View File

@ -46,8 +46,8 @@ public:
bool isDirty();
protected:
QVariant settingsValue(const QString &key, Snore::SettingsType type = Snore::GlobalSetting) const;
void setSettingsValue(const QString &key, const QVariant &settingsValue, Snore::SettingsType type = Snore::GlobalSetting);
QVariant settingsValue(const SettingsKey &key) const;
void setSettingsValue(const SettingsKey &key, const QVariant &settingsValue);
virtual void load();
virtual void save();

View File

@ -20,6 +20,7 @@
#include "ui_settingsdialog.h"
#include "snore.h"
#include "snore_p.h"
#include "snoreconstants.h"
#include "settings.h"
#include <QTabWidget>
@ -42,7 +43,7 @@ SettingsDialog::~SettingsDialog()
void SettingsDialog::initTabs()
{
SnorePlugin::PluginTypes types = SnoreCore::instance().settingsValue(QStringLiteral("PluginTypes"), LocalSetting).value<SnorePlugin::PluginTypes>();
SnorePlugin::PluginTypes types = SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PluginTypes).value<SnorePlugin::PluginTypes>();
if (types == SnorePlugin::None) {
types = SnorePlugin::All;
}
@ -90,9 +91,9 @@ void SettingsDialog::on_pushButton_clicked()
void SettingsDialog::load()
{
qCDebug(SNORE) << "loading";
loadPrimaryBackendBox(SnoreCore::instance().settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString());
ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt());
ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting).toBool());
loadPrimaryBackendBox(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PrimaryBackend).toString());
ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt());
ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent).toBool());
foreach(auto widget, m_tabs) {
widget->loadSettings();
}
@ -100,7 +101,7 @@ void SettingsDialog::load()
void SettingsDialog::loadPrimaryBackendBox(const QString &backend)
{
if (SnoreCore::instance().settingsValue(QStringLiteral("PluginTypes"), LocalSetting).value<SnorePlugin::PluginTypes>() & SnorePlugin::Backend) {
if (SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PluginTypes).value<SnorePlugin::PluginTypes>() & SnorePlugin::Backend) {
ui->primaryBackendComboBox->clear();
QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::Backend);
ui->primaryBackendComboBox->addItems(list);
@ -121,13 +122,13 @@ void SettingsDialog::save()
w->saveSettings();
dirty |= w->isDirty();
}
dirty |= SnoreCore::instance().settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString() != ui->primaryBackendComboBox->currentText();
dirty |= SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt() != ui->timeoutSpinBox->value();
dirty |= SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting).toBool() != ui->disableNotificationSoundCheckBox->isChecked();
dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PrimaryBackend).toString() != ui->primaryBackendComboBox->currentText();
dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt() != ui->timeoutSpinBox->value();
dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent).toBool() != ui->disableNotificationSoundCheckBox->isChecked();
SnoreCore::instance().setSettingsValue(QStringLiteral("PrimaryBackend"), ui->primaryBackendComboBox->currentText(), LocalSetting);
SnoreCore::instance().setSettingsValue(QStringLiteral("Timeout"), ui->timeoutSpinBox->value(), LocalSetting);
SnoreCore::instance().setSettingsValue(QStringLiteral("Silent"), ui->disableNotificationSoundCheckBox->isChecked(), LocalSetting);
SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::PrimaryBackend, ui->primaryBackendComboBox->currentText());
SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::Timeout, ui->timeoutSpinBox->value());
SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::Silent, ui->disableNotificationSoundCheckBox->isChecked());
if (dirty) {
SnoreCorePrivate::instance()->syncSettings();

View File

@ -18,6 +18,7 @@
#include "snore.h"
#include "snore_p.h"
#include "snoreconstants.h"
#include "lambdahint.h"
#include "notification/notification.h"
#include "notification/notification_p.h"
@ -74,7 +75,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
return;
}
Q_D(SnoreCore);
setSettingsValue(QStringLiteral("PluginTypes"), QVariant::fromValue(types), LocalSetting);
setSettingsValue(Constants::SettingsKeys::PluginTypes, QVariant::fromValue(types));
qCDebug(SNORE) << "Loading plugin types:" << types;
foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
if (type != SnorePlugin::All && types & type) {
@ -91,7 +92,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
case SnorePlugin::Frontend:
case SnorePlugin::Plugin:
case SnorePlugin::Settings:
plugin->setEnabled(plugin->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool());
plugin->setEnabled(plugin->settingsValue(Constants::SettingsKeys::Enabled).toBool());
break;
default:
qCWarning(SNORE) << "Plugin Cache corrupted\n" << info->file() << info->type();
@ -209,26 +210,26 @@ void SnoreCore::setDefaultApplication(const Application app)
d->m_defaultApp = app;
}
QVariant SnoreCore::settingsValue(const QString &key, SettingsType type) const
QVariant SnoreCore::settingsValue(const SettingsKey &key) const
{
Q_D(const SnoreCore);
QString nk = d->normalizeSettingsKey(key, type);
if (type == LocalSetting && !d->m_settings->contains(nk)) {
nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"), type);
QString nk = d->normalizeSettingsKey(key.key, key.type);
if (key.type == LocalSetting && !d->m_settings->contains(nk)) {
nk = d->normalizeSettingsKey(key.key + QStringLiteral("-SnoreDefault"), key.type);
}
return d->m_settings->value(nk);
}
void SnoreCore::setSettingsValue(const QString &key, const QVariant &value, SettingsType type)
void SnoreCore::setSettingsValue(const SettingsKey &key, const QVariant &value)
{
Q_D(SnoreCore);
d->m_settings->setValue(d->normalizeSettingsKey(key, type), value);
d->m_settings->setValue(d->normalizeSettingsKey(key.key, key.type), value);
}
void SnoreCore::setDefaultSettingsValue(const QString &key, const QVariant &value, SettingsType type)
void SnoreCore::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value)
{
Q_D(SnoreCore);
QString nk = d->normalizeSettingsKey(key, type);
QString nk = d->normalizeSettingsKey(key.key, key.type);
if (!d->m_settings->contains(nk)) {
qCDebug(SNORE) << "Set default value" << nk << value;
d->m_settings->setValue(nk, value);

View File

@ -138,9 +138,9 @@ public:
*/
void setDefaultApplication(Application app);
QVariant settingsValue(const QString &key, SettingsType type = GlobalSetting) const;
void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting);
void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting);
QVariant settingsValue(const SettingsKey &key) const;
void setSettingsValue(const SettingsKey &key, const QVariant &value);
void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue);
Notification getActiveNotificationByID(uint id) const;

View File

@ -18,6 +18,7 @@
#include "snore_p.h"
#include "snore.h"
#include "snoreconstants.h"
#include "plugins/plugins.h"
#include "plugins/snorebackend.h"
#include "plugins/snorefrontend.h"
@ -107,7 +108,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
}
m_notificationBackend = b;
m_notificationBackend->enable();
q->setSettingsValue(QStringLiteral("PrimaryBackend"), backend, LocalSetting);
q->setSettingsValue(Constants::SettingsKeys::PrimaryBackend, backend);
connect(b, &SnoreBackend::error, [this, b](const QString &) {
slotInitPrimaryNotificationBackend();
@ -121,8 +122,8 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
bool SnoreCorePrivate::slotInitPrimaryNotificationBackend()
{
Q_Q(SnoreCore);
qCDebug(SNORE) << q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString();
if (setBackendIfAvailible(q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString())) {
qCDebug(SNORE) << q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString();
if (setBackendIfAvailible(q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString())) {
return true;
}
#ifdef Q_OS_WIN
@ -171,7 +172,7 @@ void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const Q
void SnoreCorePrivate::syncSettings()
{
Q_Q(SnoreCore);
QString newBackend = q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString();
QString newBackend = q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString();
if (!newBackend.isEmpty()) {
QString oldBackend;
if (m_notificationBackend) {
@ -180,7 +181,7 @@ void SnoreCorePrivate::syncSettings()
m_notificationBackend = nullptr;
}
if (!setBackendIfAvailible(newBackend)) {
qCWarning(SNORE) << "Failed to set new backend" << q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString() << "restoring" << oldBackend;
qCWarning(SNORE) << "Failed to set new backend" << q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString() << "restoring" << oldBackend;
setBackendIfAvailible(oldBackend);
}
}
@ -191,7 +192,7 @@ void SnoreCorePrivate::syncSettings()
foreach(auto & pluginName, m_pluginNames[type]) {
auto key = qMakePair(type, pluginName);
SnorePlugin *plugin = m_plugins.value(key);
bool enable = m_plugins[key]->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool();
bool enable = m_plugins[key]->settingsValue(Constants::SettingsKeys::Enabled).toBool();
plugin->setEnabled(enable);
}
}

View File

@ -0,0 +1,22 @@
#ifndef SNORECONSTANTS_H
#define SNORECONSTANTS_H
#include "snoreglobals.h"
#include <QString>
namespace Snore {
namespace Constants {
namespace SettingsKeys {
static const SettingsKey PrimaryBackend = {QStringLiteral("PrimaryBackend"), GlobalSetting};
static const SettingsKey Timeout = {QStringLiteral("Timeout"), GlobalSetting};
static const SettingsKey Silent = {QStringLiteral("Silent"), LocalSetting};
static const SettingsKey Enabled = {QStringLiteral("Enabled"), LocalSetting};
static const SettingsKey PluginTypes = {QStringLiteral("PluginTypes"), LocalSetting};
}
}
}
#endif // SNORECONSTANTS_H

View File

@ -31,6 +31,11 @@ enum SettingsType {
LocalSetting
};
struct SettingsKey {
QString key;
SettingsType type;
};
}
SNORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(SNORE)

View File

@ -17,6 +17,7 @@
*/
#include "growlbackend.h"
#include "growlconstants.h"
#include "libsnore/snore.h"
#include "libsnore/snore_p.h"
@ -63,7 +64,7 @@ SnorePlugin::Growl::~Growl()
bool SnorePlugin::Growl::isReady()
{
bool running = ::Growl::isRunning(GROWL_TCP, settingsValue(QStringLiteral("Host")).toString().toUtf8().constData());
bool running = ::Growl::isRunning(GROWL_TCP, settingsValue(GrowlConstants::Host).toString().toUtf8().constData());
if (!running) {
setErrorString(tr("%1 is not running.").arg(name()));
}
@ -80,8 +81,8 @@ void SnorePlugin::Growl::slotRegisterApplication(const Snore::Application &appli
alerts.push_back(a.name().toUtf8().constData());
}
::Growl *growl = new ::Growl(GROWL_TCP, settingsValue(QStringLiteral("Host")).toString().toUtf8().constData(),
settingsValue(QStringLiteral("Password")).toString().toUtf8().constData(),
::Growl *growl = new ::Growl(GROWL_TCP, settingsValue(GrowlConstants::Host).toString().toUtf8().constData(),
settingsValue(GrowlConstants::Password).toString().toUtf8().constData(),
application.name().toUtf8().constData());
m_applications.insert(application.name(), growl);
growl->Register(alerts, application.icon().localUrl(QSize(128, 128)).toUtf8().constData());
@ -117,7 +118,7 @@ void SnorePlugin::Growl::slotNotify(Snore::Notification notification)
void SnorePlugin::Growl::setDefaultSettings()
{
SnoreBackend::setDefaultSettings();
setDefaultSettingsValue(QStringLiteral("Host"), QLatin1String("localhost"));
setDefaultSettingsValue(QStringLiteral("Password"), QString());
setDefaultSettingsValue(GrowlConstants::Host, QLatin1String("localhost"));
setDefaultSettingsValue(GrowlConstants::Password, QString());
}

View File

@ -0,0 +1,12 @@
#ifndef GROWLCONSTANTS_H
#define GROWLCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace GrowlConstants {
static const Snore::SettingsKey Host = {QStringLiteral("Host"), Snore::GlobalSetting};
static const Snore::SettingsKey Password = {QStringLiteral("Password"), Snore::GlobalSetting};
}
#endif // GROWLCONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "growlsettings.h"
#include "growlconstants.h"
#include <QLineEdit>
@ -36,13 +37,13 @@ GrowlSettings::~GrowlSettings()
void GrowlSettings::load()
{
m_host->setText(settingsValue(QStringLiteral("Host")).toString());
m_password->setText(settingsValue(QStringLiteral("Password")).toString());
m_host->setText(settingsValue(GrowlConstants::Host).toString());
m_password->setText(settingsValue(GrowlConstants::Password).toString());
}
void GrowlSettings::save()
{
setSettingsValue(QStringLiteral("Host"), m_host->text());
setSettingsValue(QStringLiteral("Password"), m_password->text());
setSettingsValue(GrowlConstants::Host, m_host->text());
setSettingsValue(GrowlConstants::Password, m_password->text());
}

View File

@ -17,6 +17,7 @@
*/
#include "snarl.h"
#include "snarlconstants.h"
#include "libsnore/snore.h"
#include "libsnore/snore_p.h"
@ -157,7 +158,7 @@ bool SnorePlugin::Snarl::isReady()
void SnorePlugin::Snarl::setDefaultSettings()
{
setDefaultSettingsValue(QLatin1String("Password"), QString());
setDefaultSettingsValue(SnarlConstants::Password, QString());
SnoreBackend::setDefaultSettings();
}
@ -171,7 +172,7 @@ void SnorePlugin::Snarl::slotRegisterApplication(const Snore::Application &appli
m_applications.insert(application.name(), snarlInterface);
QString appName = application.name().replace(QLatin1Char(' '), QLatin1Char('_')); //app sig must not contain spaces
QString password = settingsValue(QLatin1String("Password")).toString();
QString password = settingsValue(SnarlConstants::Password).toString();
LONG32 result = snarlInterface->Register(appName.toUtf8().constData(),
application.name().toUtf8().constData(),
application.icon().localUrl(QSize(128, 128)).toUtf8().constData(),

View File

@ -0,0 +1,9 @@
#ifndef SNARLCONSTANTS_H
#define SNARLCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace SnarlConstants {
static const Snore::SettingsKey Password = {QStringLiteral("Password"), Snore::LocalSetting};
}
#endif // SNARLCONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "snarlsettings.h"
#include "snarlconstants.h"
#include <QLineEdit>
@ -34,11 +35,11 @@ SnarlSettings::~SnarlSettings()
void SnarlSettings::load()
{
m_password->setText(settingsValue(QLatin1String("Password")).toString());
m_password->setText(settingsValue(SnarlConstants::Password).toString());
}
void SnarlSettings::save()
{
setSettingsValue(QLatin1String("Password"), m_password->text());
setSettingsValue(SnarlConstants::Password, m_password->text());
}

View File

@ -18,6 +18,7 @@
#include "notifywidget.h"
#include "snorenotifier.h"
#include "snorebackendconstants.h"
#include "libsnore/utils.h"
#include <QGuiApplication>
@ -179,7 +180,7 @@ int NotifyWidget::id() const
void NotifyWidget::syncSettings()
{
Qt::Corner c = static_cast<Qt::Corner>(m_parent->settingsValue(QStringLiteral("Position")).toInt());
Qt::Corner c = static_cast<Qt::Corner>(m_parent->settingsValue(SnoreBackendConstants::Position).toInt());
if (c != m_corner || !m_initialized) {
m_initialized = true;
m_corner = c;

View File

@ -0,0 +1,11 @@
#ifndef SNOREBACKENDCONSTANTS_H
#define SNOREBACKENDCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace SnoreBackendConstants
{
static const Snore::SettingsKey Position = {QStringLiteral("Position"), Snore::GlobalSetting};
}
#endif // SNOREBACKENDCONSTANTS_H

View File

@ -18,6 +18,7 @@
#include "snorenotifier.h"
#include "notifywidget.h"
#include "snorebackendconstants.h"
#include "libsnore/notification/notification_p.h"
#include "libsnore/snore_p.h"
@ -107,6 +108,6 @@ int SnorePlugin::Snore::maxNumberOfActiveNotifications() const
void SnorePlugin::Snore::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("Position"), Qt::TopRightCorner);
setDefaultSettingsValue(SnoreBackendConstants::Position, Qt::TopRightCorner);
SnoreBackend::setDefaultSettings();
}

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "snorenotifiersettings.h"
#include "snorebackendconstants.h"
#include "snore.h"
#include <QComboBox>
@ -37,10 +38,10 @@ SnoreSettings::~SnoreSettings()
void SnoreSettings::load()
{
m_comboBox->setCurrentIndex(settingsValue(QStringLiteral("Position")).toInt());
m_comboBox->setCurrentIndex(settingsValue(SnoreBackendConstants::Position).toInt());
}
void SnoreSettings::save()
{
setSettingsValue(QStringLiteral("Position"), m_comboBox->currentIndex());
setSettingsValue(SnoreBackendConstants::Position, m_comboBox->currentIndex());
}

View File

@ -23,6 +23,11 @@
#include "libsnore/notification/notification_p.h"
#include "libsnore/hint.h"
namespace {
static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::GlobalSetting};
static const Snore::SettingsKey Secret = {QStringLiteral("Secret"), Snore::GlobalSetting};
}
using namespace Snore;
PushoverFrontend::PushoverFrontend():
@ -40,8 +45,8 @@ PushoverFrontend::PushoverFrontend():
void PushoverFrontend::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("Secret"), QString(), LocalSetting);
setDefaultSettingsValue(QStringLiteral("DeviceID"), QString(), LocalSetting);
setDefaultSettingsValue(Secret, QString());
setDefaultSettingsValue(DeviceID, QString());
SnoreFrontend::setDefaultSettings();
}

View File

@ -18,6 +18,8 @@
#include "pushoverclient.h"
#include "pushover_frontend.h"
#include "../../secondary_backends/pushover_backend/pushoverconstants.h"
#include "libsnore/snore.h"
#include "libsnore/notification/notification_p.h"
@ -47,7 +49,7 @@ PushoverClient::PushoverClient(PushoverFrontend *frontend):
void PushoverClient::login(const QString &email, const QString &password, const QString &deviceName)
{
m_frontend->setSettingsValue(QStringLiteral("DeviceName"), deviceName, Snore::LocalSetting);
m_frontend->setSettingsValue(PushoverConstants::DeviceName, deviceName);
QNetworkRequest request(QUrl(QStringLiteral("https://api.pushover.net/1/users/login.json")));
@ -73,8 +75,8 @@ void PushoverClient::login(const QString &email, const QString &password, const
void PushoverClient::logOut()
{
m_frontend->setSettingsValue(QStringLiteral("Secret"), QString(), LocalSetting);
m_frontend->setSettingsValue(QStringLiteral("DeviceID"), QString(), LocalSetting);
m_frontend->setSettingsValue(PushoverConstants::Secret, QString());
m_frontend->setSettingsValue(PushoverConstants::DeviceID, QString());
m_socket->close();
m_socket->deleteLater();
emit loggedInChanged(LoggedOut);
@ -92,12 +94,12 @@ QString PushoverClient::errorMessage()
QString PushoverClient::secret()
{
return m_frontend->settingsValue(QStringLiteral("Secret"), LocalSetting).toString();
return m_frontend->settingsValue(PushoverConstants::Secret).toString();
}
QString PushoverClient::device()
{
return m_frontend->settingsValue(QStringLiteral("DeviceID"), LocalSetting).toString();
return m_frontend->settingsValue(PushoverConstants::DeviceID).toString();
}
void PushoverClient::connectToService()
@ -175,8 +177,8 @@ void PushoverClient::registerDevice(const QString &secret, const QString &device
reply->deleteLater();
QJsonObject message = QJsonDocument::fromJson(input).object();
if (message.value(QStringLiteral("status")).toInt() == 1) {
m_frontend->setSettingsValue(QStringLiteral("Secret"), secret, LocalSetting);
m_frontend->setSettingsValue(QStringLiteral("DeviceID"), message.value(QStringLiteral("id")).toString(), LocalSetting);;
m_frontend->setSettingsValue(PushoverConstants::Secret, secret);
m_frontend->setSettingsValue(PushoverConstants::DeviceID, message.value(QStringLiteral("id")).toString());
connectToService();
} else {
qCWarning(SNORE) << "An error occured" << input;

View File

@ -17,6 +17,7 @@
*/
#include "pushoversettings.h"
#include "pushoverclient.h"
#include "../../secondary_backends/pushover_backend/pushoverconstants.h"
#include "libsnore/plugins/plugins.h"
#include "libsnore/hint.h"
@ -80,7 +81,7 @@ PushoverSettings::~PushoverSettings()
void PushoverSettings::load()
{
m_deviceLineEdit->setText(settingsValue(QStringLiteral("DeviceName"), Snore::LocalSetting).toString());
m_deviceLineEdit->setText(settingsValue(PushoverConstants::Devices).toString());
}
void PushoverSettings::save()

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nma.h"
#include "nmaconstants.h"
#include "libsnore/utils.h"
@ -26,7 +27,7 @@ namespace SnorePlugin {
void NMA::slotNotify(Snore::Notification notification)
{
QString key = settingsValue(QStringLiteral("ApiKey")).toString();
QString key = settingsValue(NMAConstants::ApiKey).toString();
if (key.isEmpty()) {
return;
}
@ -60,7 +61,7 @@ void NMA::slotNotify(Snore::Notification notification)
void NMA::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("ApiKey"), QString());
setDefaultSettingsValue(NMAConstants::ApiKey, QString());
SnoreSecondaryBackend::setDefaultSettings();
}

View File

@ -0,0 +1,9 @@
#ifndef NMACONSTANTS_H
#define NMACONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace NMAConstants {
static const Snore::SettingsKey ApiKey = {QStringLiteral("ApiKey"), Snore::GlobalSetting};
}
#endif // NMACONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nmasettings.h"
#include "nmaconstants.h"
#include "libsnore/plugins/plugins.h"
@ -36,10 +37,10 @@ NMASettings::~NMASettings()
void NMASettings::load()
{
m_lineEdit->setText(settingsValue(QStringLiteral("ApiKey")).toString());
m_lineEdit->setText(settingsValue(NMAConstants::ApiKey).toString());
}
void NMASettings::save()
{
setSettingsValue(QStringLiteral("ApiKey"), m_lineEdit->text());
setSettingsValue(NMAConstants::ApiKey, m_lineEdit->text());
}

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pushover.h"
#include "pushoverconstants.h"
#include "libsnore/utils.h"
#include "libsnore/notification/notification_p.h"
@ -32,7 +33,7 @@ void Pushover::slotNotify(Snore::Notification notification)
return;
}
QString key = settingsValue(QStringLiteral("UserKey")).toString();
QString key = settingsValue(PushoverConstants::UserKey).toString();
if (key.isEmpty()) {
return;
}
@ -86,14 +87,14 @@ void Pushover::slotNotify(Snore::Notification notification)
if (notification.hints().value("silent").toBool()) {
sound.setBody("none");
} else {
sound.setBody(settingsValue(QStringLiteral("Sound"), Snore::LocalSetting).toString().toUtf8().constData());
sound.setBody((settingsValue(PushoverConstants::Sound)).toString().toUtf8().constData());
}
mp->append(sound);
if (!settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString().isEmpty()) {
if (!settingsValue(PushoverConstants::Devices).toString().isEmpty()) {
QHttpPart devices;
devices.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"device\"")));
devices.setBody(settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString().toUtf8().constData());
devices.setBody(settingsValue(PushoverConstants::Devices).toString().toUtf8().constData());
mp->append(devices);
}
@ -121,9 +122,9 @@ void Pushover::slotNotify(Snore::Notification notification)
void Pushover::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("UserKey"), QString());
setDefaultSettingsValue(QStringLiteral("Sound"), QLatin1String("pushover"), Snore::LocalSetting);
setDefaultSettingsValue(QStringLiteral("Devices"), QString(), Snore::LocalSetting);
setDefaultSettingsValue(PushoverConstants::UserKey, QString());
setDefaultSettingsValue(PushoverConstants::Sound, QLatin1String("pushover"));
setDefaultSettingsValue(PushoverConstants::Devices, QString());
SnoreSecondaryBackend::setDefaultSettings();
}

View File

@ -0,0 +1,17 @@
#ifndef PUSHOVERCONSTANTS_H
#define PUSHOVERCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace PushoverConstants {
static const Snore::SettingsKey UserKey = {QStringLiteral("UserKey"), Snore::GlobalSetting};
static const Snore::SettingsKey Devices = {QStringLiteral("Devices"), Snore::LocalSetting};
static const Snore::SettingsKey Sound = {QStringLiteral("Sound"), Snore::LocalSetting};
//frontend
static const Snore::SettingsKey Secret = {QStringLiteral("Secret"), Snore::LocalSetting};
static const Snore::SettingsKey DeviceName = {QStringLiteral("DeviceName"), Snore::LocalSetting};
static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::LocalSetting};
}
#endif // PUSHOVERCONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pushoversettings.h"
#include "pushoverconstants.h"
#include "plugins/plugins.h"
@ -40,14 +41,14 @@ PushoverSettings::~PushoverSettings()
void PushoverSettings::load()
{
m_keyLineEdit->setText(settingsValue(QStringLiteral("UserKey")).toString());
m_soundLineEdit->setText(settingsValue(QStringLiteral("Sound"), Snore::LocalSetting).toString());
m_deviceLineEdit->setText(settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString());
m_keyLineEdit->setText(settingsValue(PushoverConstants::UserKey).toString());
m_soundLineEdit->setText(settingsValue(PushoverConstants::Sound).toString());
m_deviceLineEdit->setText(settingsValue(PushoverConstants::Devices).toString());
}
void PushoverSettings::save()
{
setSettingsValue(QStringLiteral("UserKey"), m_keyLineEdit->text());
setSettingsValue(QStringLiteral("Sound"), m_soundLineEdit->text(), Snore::LocalSetting);
setSettingsValue(QStringLiteral("Devices"), m_deviceLineEdit->text(), Snore::LocalSetting);
setSettingsValue(PushoverConstants::UserKey, m_keyLineEdit->text());
setSettingsValue(PushoverConstants::Sound, m_soundLineEdit->text());
setSettingsValue(PushoverConstants::Devices, m_deviceLineEdit->text());
}

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sound.h"
#include "soundconstants.h"
#include <QtMultimedia/QMediaPlayer>
#include <QTimer>
@ -35,7 +36,7 @@ Sound::Sound():
void Sound::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("Volume"), 50);
setDefaultSettingsValue(SoundConstants::Volume, 50);
SnoreSecondaryBackend::setDefaultSettings();
}
@ -44,11 +45,11 @@ void Sound::slotNotificationDisplayed(Snore::Notification notification)
if (notification.hints().value("silent").toBool()) {
return;
}
m_player->setVolume(settingsValue(QStringLiteral("Volume")).toInt());
m_player->setVolume(settingsValue(SoundConstants::Volume).toInt());
QString sound = notification.hints().value("sound").toString();
if (sound.isEmpty()) {
sound = settingsValue(QStringLiteral("Sound")).toString();
sound = settingsValue(SoundConstants::SoundKey).toString();
}
qCDebug(SNORE) << "SoundFile:" << sound;
if (!sound.isEmpty()) {

View File

@ -0,0 +1,11 @@
#ifndef SOUNDCONSTANTS_H
#define SOUNDCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace SoundConstants {
static const Snore::SettingsKey Volume = {QStringLiteral("Volume"), Snore::GlobalSetting};
static const Snore::SettingsKey SoundKey = {QStringLiteral("Sound"), Snore::LocalSetting};
}
#endif // SOUNDCONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "soundsettings.h"
#include "soundconstants.h"
#include "plugins/plugins.h"
#include <QFileDialog>
@ -52,13 +53,13 @@ SoundSettings::~SoundSettings()
void SoundSettings::load()
{
m_lineEditFileName->setText(settingsValue(QStringLiteral("Sound")).toString());
m_spinBoxVolume->setValue(settingsValue(QStringLiteral("Volume")).toInt());
m_lineEditFileName->setText(settingsValue(SoundConstants::SoundKey).toString());
m_spinBoxVolume->setValue(settingsValue(SoundConstants::Volume).toInt());
}
void SoundSettings::save()
{
setSettingsValue(QStringLiteral("Sound"), m_lineEditFileName->text());
setSettingsValue(QStringLiteral("Volume"), m_spinBoxVolume->value());
setSettingsValue(SoundConstants::SoundKey, m_lineEditFileName->text());
setSettingsValue(SoundConstants::Volume, m_spinBoxVolume->value());
}

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "toasty.h"
#include "toastyconstants.h"
#include "libsnore/utils.h"
@ -28,7 +29,7 @@ namespace SnorePlugin {
void Toasty::slotNotify(Snore::Notification notification)
{
QString key = settingsValue(QStringLiteral("DeviceID")).toString();
QString key = settingsValue(ToastyConstants::DeviceID).toString();
if (key.isEmpty()) {
return;
}
@ -74,7 +75,7 @@ void Toasty::slotNotify(Snore::Notification notification)
void Toasty::setDefaultSettings()
{
setDefaultSettingsValue(QStringLiteral("DeviceID"), QString());
setDefaultSettingsValue(ToastyConstants::DeviceID, QString());
SnoreSecondaryBackend::setDefaultSettings();
}

View File

@ -0,0 +1,11 @@
#ifndef TOASTYCONSTANTS_H
#define TOASTYCONSTANTS_H
#include "libsnore/snoreglobals.h"
namespace ToastyConstants {
static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::GlobalSetting};
}
#endif // TOASTYCONSTANTS_H

View File

@ -16,6 +16,7 @@
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "toastysettings.h"
#include "toastyconstants.h"
#include "plugins/plugins.h"
@ -36,10 +37,10 @@ ToastySettings::~ToastySettings()
void ToastySettings::load()
{
m_lineEdit->setText(settingsValue(QStringLiteral("DeviceID")).toString());
m_lineEdit->setText(settingsValue(ToastyConstants::DeviceID).toString());
}
void ToastySettings::save()
{
setSettingsValue(QStringLiteral("DeviceID"), m_lineEdit->text());
setSettingsValue(ToastyConstants::DeviceID, m_lineEdit->text());
}