This commit is contained in:
Patrick von Reth 2015-03-01 17:29:17 +01:00
parent b1dcef1271
commit 69819fb635
18 changed files with 41 additions and 49 deletions

View File

@ -35,7 +35,7 @@ SnorePlugin::SnorePlugin(const QString &name) :
if (thread() != qApp->thread()) {
moveToThread(qApp->thread());
}
setDefaultValue("Enabled", false,LOCAL_SETTING);
setDefaultValue("Enabled", false, LOCAL_SETTING);
}
SnorePlugin::~SnorePlugin()
@ -61,17 +61,17 @@ bool SnorePlugin::isInitialized() const
QVariant SnorePlugin::value(const QString &key, SettingsType type) const
{
return SnoreCore::instance().value(normaliseKey(key),type);
return SnoreCore::instance().value(normaliseKey(key), type);
}
void SnorePlugin::setValue(const QString &key, const QVariant &value, SettingsType type)
{
SnoreCore::instance().setValue(normaliseKey(key), value,type);
SnoreCore::instance().setValue(normaliseKey(key), value, type);
}
void SnorePlugin::setDefaultValue(const QString &key, const QVariant &value, SettingsType type)
{
SnoreCore::instance().setDefaultValue(normaliseKey(key),value,type);
SnoreCore::instance().setDefaultValue(normaliseKey(key), value, type);
}
Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()

View File

@ -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",LOCAL_SETTING).toBool());
m_enabled->setChecked(m_snorePlugin->value("Enabled", LOCAL_SETTING).toBool());
}
load();
}
@ -65,7 +65,7 @@ void PluginSettingsWidget::loadSettings()
void PluginSettingsWidget::saveSettings()
{
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
m_snorePlugin->setValue("Enabled", m_enabled->isChecked(),LOCAL_SETTING);
m_snorePlugin->setValue("Enabled", m_enabled->isChecked(), LOCAL_SETTING);
}
save();
}
@ -77,7 +77,7 @@ QVariant PluginSettingsWidget::value(const QString &key) const
void PluginSettingsWidget::setValue(const QString &key, const QVariant &value)
{
m_snorePlugin->setValue(key,value);
m_snorePlugin->setValue(key, value);
}
void PluginSettingsWidget::load()

View File

@ -49,7 +49,7 @@ protected:
virtual void load();
virtual void save();
private:
private:
SnorePlugin *m_snorePlugin;
QFormLayout *m_layout;
QCheckBox *m_enabled;

View File

@ -79,7 +79,7 @@ void SettingsDialog::save()
for (auto w : m_tabs) {
w->saveSettings();
}
SnoreCore::instance().setValue("PrimaryBackend", ui->primaryBackendComboBox->currentText(),LOCAL_SETTING);
SnoreCore::instance().setValue("PrimaryBackend", ui->primaryBackendComboBox->currentText(), LOCAL_SETTING);
SnoreCorePrivate::instance()->syncSettings();
}

View File

@ -69,7 +69,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
case SnorePlugin::SECONDARY_BACKEND:
case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN: {
if (plugin->value("Enabled",LOCAL_SETTING).toBool()) {
if (plugin->value("Enabled", LOCAL_SETTING).toBool()) {
if (!plugin->initialize()) {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << plugin->name();
plugin->deinitialize();
@ -197,20 +197,19 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
QVariant SnoreCore::value(const QString &key, SettingsType type) const
{
Q_D(const SnoreCore);
return d->m_settings->value(d->normalizeKey(key,type));
return d->m_settings->value(d->normalizeKey(key, type));
}
void SnoreCore::setValue(const QString &key, const QVariant &value, SettingsType type)
{
Q_D(SnoreCore);
d->m_settings->setValue(d->normalizeKey(key,type),value);
d->m_settings->setValue(d->normalizeKey(key, type), value);
}
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, SettingsType type)
{
Q_D(SnoreCore);
QString nk = d->normalizeKey(key,type);
QString nk = d->normalizeKey(key, type);
if (!d->m_settings->contains(nk)) {
d->m_settings->setValue(nk, value);
}

View File

@ -150,12 +150,10 @@ public:
*/
QList<PluginSettingsWidget *> settingWidgets();
QVariant value(const QString &key, SettingsType type = GLOBAL_SETTING) const;
void setValue(const QString &key, const QVariant &value, SettingsType type = GLOBAL_SETTING);
void setDefaultValue(const QString &key, const QVariant &value, SettingsType type = GLOBAL_SETTING);
signals:
/**
* This signal is emitted when an action on the Notification was performed.

View File

@ -100,8 +100,8 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
bool SnoreCorePrivate::initPrimaryNotificationBackend()
{
Q_Q(SnoreCore);
snoreDebug(SNORE_DEBUG)<<q->value("PrimaryBackend",LOCAL_SETTING).toString();
if (setBackendIfAvailible(q->value("PrimaryBackend",LOCAL_SETTING).toString())) {
snoreDebug(SNORE_DEBUG) << q->value("PrimaryBackend", LOCAL_SETTING).toString();
if (setBackendIfAvailible(q->value("PrimaryBackend", LOCAL_SETTING).toString())) {
return true;
}
#ifdef Q_OS_WIN
@ -138,13 +138,12 @@ void SnoreCorePrivate::syncSettings()
QString oldBackend = q->primaryNotificationBackend();
m_notificationBackend->deinitialize();
m_notificationBackend = nullptr;
if(!setBackendIfAvailible(q->value("PrimaryBackend",LOCAL_SETTING).toString()))
{
snoreDebug(SNORE_WARNING) << "Failed to set new backend" << q->value("PrimaryBackend",LOCAL_SETTING).toString() << "restoring" << oldBackend;
if (!setBackendIfAvailible(q->value("PrimaryBackend", LOCAL_SETTING).toString())) {
snoreDebug(SNORE_WARNING) << "Failed to set new backend" << q->value("PrimaryBackend", LOCAL_SETTING).toString() << "restoring" << oldBackend;
setBackendIfAvailible(oldBackend);
}
//TODO: cleanup
auto syncPluginStatus = [&](const QString &pluginName){
auto syncPluginStatus = [&](const QString & pluginName) {
SnorePlugin *plugin = m_plugins.value(pluginName);
bool enable = m_plugins[pluginName]->value("Enabled", LOCAL_SETTING).toBool();
if (!plugin->isInitialized() && enable) {
@ -198,7 +197,7 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
void SnoreCorePrivate::slotAboutToQuit()
{
for(PluginContainer * p : PluginContainer::pluginCache(SnorePlugin::ALL)) {
for (PluginContainer *p : PluginContainer::pluginCache(SnorePlugin::ALL)) {
if (p->isLoaded()) {
snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name();
p->load()->deinitialize();

View File

@ -48,7 +48,6 @@ public:
*/
static QString tempPath();
public:
static SnoreCorePrivate *instance();
~SnoreCorePrivate();
@ -66,21 +65,22 @@ public:
bool initPrimaryNotificationBackend();
inline QString versionSchema() const {
inline QString versionSchema() const
{
return "v1";
}
void syncSettings();
QString normalizeKey(const QString &key, SettingsType type) const{
if(type == LOCAL_SETTING) {
QString normalizeKey(const QString &key, SettingsType type) const
{
if (type == LOCAL_SETTING) {
return QString("%1/LocalSettings/%2.%3/%4").arg(versionSchema(), qApp->organizationName(), qApp->applicationName(), key);
} else {
return QString("%1/%2").arg(versionSchema(), key);
}
}
signals:
void applicationRegistered(const Snore::Application &);
void applicationDeregistered(const Snore::Application &);

View File

@ -19,9 +19,10 @@
#ifndef SNOREGLOBALS
#define SNOREGLOBALS
namespace Snore{
namespace Snore
{
enum SettingsType{
enum SettingsType {
GLOBAL_SETTING,
LOCAL_SETTING
};

View File

@ -31,8 +31,8 @@ GrowlBackend::GrowlBackend():
m_id(0)
{
s_instance = this;
setDefaultValue("Host","localhost");
setDefaultValue("Password","");
setDefaultValue("Host", "localhost");
setDefaultValue("Password", "");
}
GrowlBackend::~GrowlBackend()

View File

@ -36,7 +36,6 @@ public:
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
static void gntpCallback(growl_callback_data *data);
private:

View File

@ -22,12 +22,12 @@
using namespace Snore;
GrowlSettings::GrowlSettings(SnorePlugin *plugin, QWidget *parent):
PluginSettingsWidget(plugin,parent),
PluginSettingsWidget(plugin, parent),
m_host(new QLineEdit),
m_password(new QLineEdit)
{
m_password->setEchoMode(QLineEdit::Password);
addRow("Host:",m_host);
addRow("Host:", m_host);
addRow("Password:", m_password);
}
@ -44,7 +44,7 @@ void GrowlSettings::load()
void GrowlSettings::save()
{
setValue("Host",m_host->text());
setValue("Password",m_password->text());
setValue("Host", m_host->text());
setValue("Password", m_password->text());
}

View File

@ -22,7 +22,6 @@
class QLineEdit;
class GrowlSettings : public Snore::PluginSettingsWidget
{
public:

View File

@ -114,7 +114,7 @@ private:
SnarlBackend::SnarlBackend():
SnoreBackend("Snarl", true, false, true)
{
setDefaultValue("Password",QString());
setDefaultValue("Password", QString());
}
SnarlBackend::~SnarlBackend()
@ -164,10 +164,10 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
QString appName = application.name().replace(" ", "_"); //app sig must not contain spaces
QString password = value("Password").toString();
LONG32 result = snarlInterface->Register(appName.toUtf8().constData(),
application.name().toUtf8().constData(),
application.icon().localUrl().toUtf8().constData(),
password.isEmpty()?0:password.toUtf8().constData(),
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
application.name().toUtf8().constData(),
application.icon().localUrl().toUtf8().constData(),
password.isEmpty() ? 0 : password.toUtf8().constData(),
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
snoreDebug(SNORE_DEBUG) << result;
foreach(const Alert & alert, application.alerts()) {

View File

@ -33,8 +33,6 @@ public:
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
private:
class SnarlWidget;
SnarlBackend::SnarlWidget *m_eventLoop;

View File

@ -22,7 +22,7 @@
using namespace Snore;
SnarlSettings::SnarlSettings(SnorePlugin *plugin, QWidget *parent):
PluginSettingsWidget(plugin,parent),
PluginSettingsWidget(plugin, parent),
m_password(new QLineEdit)
{
m_password->setEchoMode(QLineEdit::Password);
@ -41,6 +41,6 @@ void SnarlSettings::load()
void SnarlSettings::save()
{
setValue("Password",m_password->text());
setValue("Password", m_password->text());
}

View File

@ -22,7 +22,6 @@
class QLineEdit;
class SnarlSettings : public Snore::PluginSettingsWidget
{
public:

View File

@ -28,7 +28,7 @@ using namespace Snore;
Toasty::Toasty():
SnoreSecondaryBackend("Toasty", false)
{
{
setDefaultValue("DeviceID", "");
}