add settings for growl, app specific settings
This commit is contained in:
parent
fff339be3a
commit
018628db88
|
@ -27,6 +27,7 @@ list(APPEND SnoreNotify_SRCS
|
|||
hint.cpp
|
||||
log.cpp
|
||||
settingsdialog.cpp
|
||||
setting.cpp
|
||||
${UI}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
${SNORENOTIFY_RCS}
|
||||
|
@ -40,6 +41,7 @@ list(APPEND SnoreNotify_HDR
|
|||
hint.h
|
||||
log.h
|
||||
settingsdialog.h
|
||||
setting.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/snore_exports.h
|
||||
version.h
|
||||
)
|
||||
|
|
|
@ -35,7 +35,7 @@ SnorePlugin::SnorePlugin(const QString &name) :
|
|||
if (thread() != qApp->thread()) {
|
||||
moveToThread(qApp->thread());
|
||||
}
|
||||
setDefaultValue("Enabled", true);
|
||||
setDefaultValue("Enabled", Setting(true,true));
|
||||
}
|
||||
|
||||
SnorePlugin::~SnorePlugin()
|
||||
|
@ -61,20 +61,17 @@ bool SnorePlugin::isInitialized() const
|
|||
|
||||
QVariant SnorePlugin::value(const QString &key) const
|
||||
{
|
||||
return SnoreCore::instance().settings()->value(normaliseKey(key));
|
||||
return SnoreCore::instance().value(normaliseKey(key));
|
||||
}
|
||||
|
||||
void SnorePlugin::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
SnoreCore::instance().settings()->setValue(normaliseKey(key), value);
|
||||
SnoreCore::instance().setValue(normaliseKey(key), value);
|
||||
}
|
||||
|
||||
void SnorePlugin::setDefaultValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
QString pk(normaliseKey(key));
|
||||
if (!SnoreCore::instance().settings()->contains(pk)) {
|
||||
SnoreCore::instance().settings()->setValue(normaliseKey(key), value);
|
||||
}
|
||||
SnoreCore::instance().setDefaultValue(normaliseKey(key),value);
|
||||
}
|
||||
|
||||
Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
|
||||
|
|
|
@ -57,7 +57,7 @@ void PluginSettingsWidget::addRow(const QString &label, QWidget *widget)
|
|||
void PluginSettingsWidget::loadSettings()
|
||||
{
|
||||
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
|
||||
m_enabled->setChecked(m_snorePlugin->value("Enabled").toBool());
|
||||
m_enabled->setChecked(m_snorePlugin->value("Enabled").value<Setting>().value().toBool());
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
@ -65,11 +65,21 @@ void PluginSettingsWidget::loadSettings()
|
|||
void PluginSettingsWidget::saveSettings()
|
||||
{
|
||||
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
|
||||
m_snorePlugin->setValue("Enabled", m_enabled->isChecked());
|
||||
m_snorePlugin->setValue("Enabled", Setting(m_enabled->isChecked(),true));
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
QVariant PluginSettingsWidget::value(const QString &key) const
|
||||
{
|
||||
return m_snorePlugin->value(key);
|
||||
}
|
||||
|
||||
void PluginSettingsWidget::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
m_snorePlugin->setValue(key,value);
|
||||
}
|
||||
|
||||
void PluginSettingsWidget::load()
|
||||
{
|
||||
|
||||
|
|
|
@ -43,12 +43,14 @@ public:
|
|||
void saveSettings();
|
||||
|
||||
protected:
|
||||
SnorePlugin *m_snorePlugin;
|
||||
QVariant value(const QString &key) const;
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
|
||||
virtual void load();
|
||||
virtual void save();
|
||||
|
||||
private:
|
||||
private:
|
||||
SnorePlugin *m_snorePlugin;
|
||||
QFormLayout *m_layout;
|
||||
QCheckBox *m_enabled;
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013-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 "setting.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Setting::Setting()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Setting::Setting(const QVariant &value, bool specific):
|
||||
m_value(value),m_specific(specific)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Setting::~Setting()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Setting::isSpecific() const
|
||||
{
|
||||
return m_specific;
|
||||
}
|
||||
|
||||
QVariant Setting::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
Snore::Setting::operator QVariant()
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const Snore::Setting &myObj)
|
||||
{
|
||||
out << myObj.value() << myObj.isSpecific();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, Snore::Setting &myObj)
|
||||
{
|
||||
in >> myObj.m_value;
|
||||
in >> myObj.m_specific;
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013-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 SETTING_H
|
||||
#define SETTING_H
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
namespace Snore{
|
||||
class Setting;
|
||||
}
|
||||
|
||||
SNORE_EXPORT QDataStream &operator<<(QDataStream &out, const Snore::Setting &myObj);
|
||||
SNORE_EXPORT QDataStream &operator>>(QDataStream &in, Snore::Setting &myObj);
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT Setting
|
||||
{
|
||||
public:
|
||||
Setting();
|
||||
Setting(const QVariant &value, bool specific = false);
|
||||
|
||||
~Setting();
|
||||
|
||||
bool isSpecific() const;
|
||||
|
||||
QVariant value() const;
|
||||
|
||||
operator QVariant();
|
||||
|
||||
private:
|
||||
QVariant m_value;
|
||||
bool m_specific;
|
||||
|
||||
friend SNORE_EXPORT QDataStream &(::operator<<)(QDataStream &out, const Snore::Setting &myObj);
|
||||
friend SNORE_EXPORT QDataStream &(::operator>>)(QDataStream &in, Snore::Setting &myObj);
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Snore::Setting)
|
||||
|
||||
#endif // SETTING_H
|
|
@ -197,16 +197,41 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
|
|||
return list;
|
||||
}
|
||||
|
||||
QSettings *SnoreCore::settings()
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
return d->m_settings;
|
||||
}
|
||||
|
||||
const QSettings *SnoreCore::settings() const
|
||||
QVariant SnoreCore::value(const QString &key) const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_settings;
|
||||
QString nk = d->normalizeKey(key);
|
||||
if(d->m_settings->contains(nk))
|
||||
{
|
||||
return d->m_settings->value(nk);
|
||||
}
|
||||
return d->m_settings->value(key);
|
||||
|
||||
}
|
||||
|
||||
void SnoreCore::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = key;
|
||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||
{
|
||||
nk = d->normalizeKey(nk);
|
||||
}
|
||||
d->m_settings->setValue(nk,value);
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = key;
|
||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||
{
|
||||
nk = d->normalizeKey(nk);
|
||||
}
|
||||
if (!d->m_settings->contains(nk)) {
|
||||
d->m_settings->setValue(nk, value);
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::setSettingsPrefix(const QString &prefix)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "notification/notification.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "hint.h"
|
||||
#include "setting.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
@ -150,11 +151,11 @@ public:
|
|||
*/
|
||||
QList<PluginSettingsWidget *> settingWidgets();
|
||||
|
||||
/**
|
||||
* @return a pointer to the global settings
|
||||
*/
|
||||
QSettings *settings();
|
||||
const QSettings *settings() const;
|
||||
|
||||
QVariant value(const QString &key) const;
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
void setDefaultValue(const QString &key, const QVariant &value);
|
||||
|
||||
|
||||
/**
|
||||
* Some settings can be uniqe to your application.
|
||||
|
|
|
@ -90,7 +90,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
|||
}
|
||||
|
||||
m_notificationBackend = b;
|
||||
m_settings->setValue(primaryBackendSettingsName(), backend);
|
||||
q->setValue("PrimaryBackend", Setting(backend,true));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -98,7 +98,9 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
|||
|
||||
bool SnoreCorePrivate::initPrimaryNotificationBackend()
|
||||
{
|
||||
if (setBackendIfAvailible(m_settings->value(primaryBackendSettingsName()).toString())) {
|
||||
Q_Q(SnoreCore);
|
||||
snoreDebug(SNORE_DEBUG)<<q->value("PrimaryBackend").value<Setting>().value().toString();
|
||||
if (setBackendIfAvailible(q->value("PrimaryBackend").value<Setting>().value().toString())) {
|
||||
return true;
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -131,7 +133,7 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend()
|
|||
|
||||
void SnoreCorePrivate::syncSettings()
|
||||
{
|
||||
setBackendIfAvailible(m_settings->value(primaryBackendSettingsName()).toString());
|
||||
setBackendIfAvailible(m_settings->value("PrimaryBackend").value<Setting>().value().toString());
|
||||
for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) {
|
||||
SnorePlugin *plugin = m_plugins.value(pluginName);
|
||||
bool enable = m_plugins[pluginName]->value("Enabled").toBool();
|
||||
|
@ -147,6 +149,8 @@ void SnoreCorePrivate::registerMetaTypes()
|
|||
{
|
||||
qRegisterMetaType<Notification>();
|
||||
qRegisterMetaType<Application>();
|
||||
qRegisterMetaType<Setting>();
|
||||
qRegisterMetaTypeStreamOperators<Setting>("Snore::Settings");
|
||||
}
|
||||
|
||||
QString SnoreCorePrivate::tempPath()
|
||||
|
|
|
@ -65,6 +65,11 @@ public:
|
|||
|
||||
void syncSettings();
|
||||
|
||||
QString normalizeKey(const QString &key) const{
|
||||
return QString("AppSpecificSettings/%1/%2").arg(m_hints.value("app_specific_settings","SnoreNotify").toString(),key);
|
||||
}
|
||||
|
||||
|
||||
signals:
|
||||
void applicationRegistered(const Snore::Application &);
|
||||
void applicationDeregistered(const Snore::Application &);
|
||||
|
@ -75,9 +80,6 @@ private slots:
|
|||
void slotAboutToQuit();
|
||||
|
||||
private:
|
||||
QString primaryBackendSettingsName(){
|
||||
return QString("AppSpecificSettings/%1/PrimaryBackend").arg(m_hints.value("app_specific_settings","SnoreNotify").toString());
|
||||
}
|
||||
|
||||
SnoreCorePrivate();
|
||||
SnoreCore *q_ptr;
|
||||
|
|
|
@ -6,7 +6,7 @@ set_package_properties(SnoreGrowl++ PROPERTIES
|
|||
TYPE RECOMMENDED)
|
||||
|
||||
if(SnoreGrowl++_FOUND)
|
||||
set( GROWL_SRC growlbackend.cpp)
|
||||
set( GROWL_SRC growlbackend.cpp growlsettings.cpp)
|
||||
|
||||
add_library(libsnore_backend_growl MODULE ${GROWL_SRC} )
|
||||
target_link_libraries(libsnore_backend_growl Snore::Libsnore Snore::SnoreGrowl++ ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "growlbackend.h"
|
||||
#include "growlsettings.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
#include "core/snore_p.h"
|
||||
|
@ -30,6 +31,8 @@ GrowlBackend::GrowlBackend():
|
|||
m_id(0)
|
||||
{
|
||||
s_instance = this;
|
||||
setDefaultValue("Host","localhost");
|
||||
setDefaultValue("Password","");
|
||||
}
|
||||
|
||||
GrowlBackend::~GrowlBackend()
|
||||
|
@ -63,7 +66,9 @@ void GrowlBackend::slotRegisterApplication(const Application &application)
|
|||
alerts.push_back(a.name().toUtf8().constData());
|
||||
}
|
||||
|
||||
Growl *growl = new Growl(GROWL_TCP, "", application.name().toUtf8().constData());
|
||||
Growl *growl = new Growl(GROWL_TCP, value("Host").toString().toUtf8().constData(),
|
||||
value("Password").toString().toUtf8().constData(),
|
||||
application.name().toUtf8().constData());
|
||||
growl->Register(alerts, application.icon().localUrl().toUtf8().constData());
|
||||
|
||||
m_applications.insert(application.name(), growl);
|
||||
|
@ -97,6 +102,11 @@ void GrowlBackend::slotNotify(Notification notification)
|
|||
startTimeout(notification);
|
||||
}
|
||||
|
||||
PluginSettingsWidget *GrowlBackend::settingsWidget()
|
||||
{
|
||||
return new GrowlSettings(this);
|
||||
}
|
||||
|
||||
void GrowlBackend::gntpCallback(growl_callback_data *data)
|
||||
{
|
||||
if (s_instance) {
|
||||
|
|
|
@ -47,6 +47,11 @@ public slots:
|
|||
void slotRegisterApplication(const Snore::Application &application) override;
|
||||
void slotDeregisterApplication(const Snore::Application &application) override;
|
||||
void slotNotify(Snore::Notification notification) override;
|
||||
|
||||
|
||||
public:
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // GROWL_BACKEND_H
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
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 "growlsettings.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
GrowlSettings::GrowlSettings(SnorePlugin *plugin, QWidget *parent):
|
||||
PluginSettingsWidget(plugin,parent),
|
||||
m_host(new QLineEdit),
|
||||
m_password(new QLineEdit)
|
||||
{
|
||||
m_password->setEchoMode(QLineEdit::Password);
|
||||
addRow("Host:",m_host);
|
||||
addRow("Password:", m_password);
|
||||
}
|
||||
|
||||
GrowlSettings::~GrowlSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GrowlSettings::load()
|
||||
{
|
||||
m_host->setText(value("Host").toString());
|
||||
m_password->setText(value("Password").toString());
|
||||
}
|
||||
|
||||
void GrowlSettings::save()
|
||||
{
|
||||
setValue("Host",m_host->text());
|
||||
setValue("Password",m_password->text());
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
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 GROWLSETTINGS_H
|
||||
#define GROWLSETTINGS_H
|
||||
|
||||
#include "plugins/pluginsettingswidget.h"
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
|
||||
class GrowlSettings : public Snore::PluginSettingsWidget
|
||||
{
|
||||
public:
|
||||
explicit GrowlSettings(Snore::SnorePlugin *plugin, QWidget *parent = 0);
|
||||
~GrowlSettings();
|
||||
|
||||
protected:
|
||||
void load() override;
|
||||
void save() override;
|
||||
|
||||
private:
|
||||
QLineEdit *m_host;
|
||||
QLineEdit *m_password;
|
||||
};
|
||||
|
||||
#endif // GROWLSETTINGS_H
|
|
@ -40,10 +40,10 @@ SnoreNotifierSettings::~SnoreNotifierSettings()
|
|||
|
||||
void SnoreNotifierSettings::load()
|
||||
{
|
||||
m_comboBox->setCurrentIndex(m_snorePlugin->value("Position").toInt());
|
||||
m_comboBox->setCurrentIndex(value("Position").toInt());
|
||||
}
|
||||
|
||||
void SnoreNotifierSettings::save()
|
||||
{
|
||||
m_snorePlugin->setValue("Position", m_comboBox->currentIndex());
|
||||
setValue("Position", m_comboBox->currentIndex());
|
||||
}
|
||||
|
|
|
@ -48,11 +48,11 @@ SoundSettings::~SoundSettings()
|
|||
|
||||
void SoundSettings::load()
|
||||
{
|
||||
m_lineEdit->setText(m_snorePlugin->value("Sound").toString());
|
||||
m_lineEdit->setText(value("Sound").toString());
|
||||
}
|
||||
|
||||
void SoundSettings::save()
|
||||
{
|
||||
m_snorePlugin->setValue("Sound", m_lineEdit->text());
|
||||
setValue("Sound", m_lineEdit->text());
|
||||
}
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ ToastySettings::~ToastySettings()
|
|||
|
||||
void ToastySettings::load()
|
||||
{
|
||||
m_lineEdit->setText(m_snorePlugin->value("DeviceID").toString());
|
||||
m_lineEdit->setText(value("DeviceID").toString());
|
||||
}
|
||||
|
||||
void ToastySettings::save()
|
||||
{
|
||||
m_snorePlugin->setValue("DeviceID", m_lineEdit->text());
|
||||
setValue("DeviceID", m_lineEdit->text());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue