this should be less horrible

This commit is contained in:
Patrick von Reth 2015-03-01 16:35:30 +01:00
parent 2217cbeaf7
commit ef402be6fc
14 changed files with 65 additions and 152 deletions

View File

@ -27,7 +27,6 @@ list(APPEND SnoreNotify_SRCS
hint.cpp
log.cpp
settingsdialog.cpp
setting.cpp
${UI}
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${SNORENOTIFY_RCS}
@ -41,7 +40,7 @@ list(APPEND SnoreNotify_HDR
hint.h
log.h
settingsdialog.h
setting.h
snoreglobals.h
${CMAKE_CURRENT_BINARY_DIR}/snore_exports.h
version.h
)

View File

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

View File

@ -19,6 +19,7 @@
#ifndef SNORE_PLUGINS_H
#define SNORE_PLUGINS_H
#include "snore_exports.h"
#include "snoreglobals.h"
#include "pluginsettingswidget.h"
#include "../notification/notification.h"
@ -26,7 +27,6 @@
namespace Snore
{
class SnoreCore;
class SNORE_EXPORT SnorePlugin : public QObject
{
@ -53,9 +53,9 @@ public:
PluginTypes type() const;
const QString typeName() const;
QVariant value(const QString &key) const;
void setValue(const QString &key, const QVariant &value);
void setDefaultValue(const QString &key, const QVariant &value);
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);
virtual PluginSettingsWidget *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").value<Setting>().value().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", Setting(m_enabled->isChecked(),true));
m_snorePlugin->setValue("Enabled", m_enabled->isChecked(),LOCAL_SETTING);
}
save();
}

View File

@ -1,60 +0,0 @@
/*
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

View File

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

View File

@ -194,23 +194,23 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
return list;
}
QVariant SnoreCore::value(const QString &key) const
QVariant SnoreCore::value(const QString &key, SettingsType type) const
{
Q_D(const SnoreCore);
QString nk = d->specificKey(key);
if(d->m_settings->contains(nk))
QString nk = d->versionizeKey(key);
if(type == LOCAL_SETTING)
{
return d->m_settings->value(nk);
nk = d->specificKey(key);
}
return d->m_settings->value(d->versionizeKey(key));
return d->m_settings->value(nk);
}
void SnoreCore::setValue(const QString &key, const QVariant &value)
void SnoreCore::setValue(const QString &key, const QVariant &value, SettingsType type)
{
Q_D(SnoreCore);
QString nk = d->versionizeKey(key);
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
if(type == LOCAL_SETTING)
{
nk = d->specificKey(key);
}
@ -218,11 +218,11 @@ void SnoreCore::setValue(const QString &key, const QVariant &value)
}
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value)
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, SettingsType type)
{
Q_D(SnoreCore);
QString nk = d->versionizeKey(key);
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
if(type == LOCAL_SETTING)
{
nk = d->specificKey(key);
}

View File

@ -20,12 +20,12 @@
#define SNORESERVER_H
#include "snore_exports.h"
#include "snoreglobals.h"
#include "log.h"
#include "application.h"
#include "notification/notification.h"
#include "plugins/plugins.h"
#include "hint.h"
#include "setting.h"
#include <QSettings>
#include <QStringList>
@ -60,7 +60,6 @@ class SNORE_EXPORT SnoreCore : public QObject
Q_DECLARE_PRIVATE(SnoreCore)
Q_OBJECT
public:
/**
* Creates a Notification Manager SnoreCore
*/
@ -152,9 +151,9 @@ public:
QList<PluginSettingsWidget *> settingWidgets();
QVariant value(const QString &key) const;
void setValue(const QString &key, const QVariant &value);
void setDefaultValue(const QString &key, const QVariant &value);
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);
/**

View File

@ -90,7 +90,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
}
m_notificationBackend = b;
q->setValue("PrimaryBackend", Setting(backend,true));
q->setValue("PrimaryBackend", backend, LOCAL_SETTING);
return true;
}
return false;
@ -99,8 +99,8 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
bool SnoreCorePrivate::initPrimaryNotificationBackend()
{
Q_Q(SnoreCore);
snoreDebug(SNORE_DEBUG)<<q->value("PrimaryBackend").value<Setting>().value().toString();
if (setBackendIfAvailible(q->value("PrimaryBackend").value<Setting>().value().toString())) {
snoreDebug(SNORE_DEBUG)<<q->value("PrimaryBackend",LOCAL_SETTING).toString();
if (setBackendIfAvailible(q->value("PrimaryBackend",LOCAL_SETTING).toString())) {
return true;
}
#ifdef Q_OS_WIN
@ -137,8 +137,9 @@ void SnoreCorePrivate::syncSettings()
QString oldBackend = q->primaryNotificationBackend();
m_notificationBackend->deinitialize();
m_notificationBackend = nullptr;
if(!setBackendIfAvailible(q->value("PrimaryBackend").value<Setting>().value().toString()))
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
@ -167,8 +168,6 @@ void SnoreCorePrivate::registerMetaTypes()
{
qRegisterMetaType<Notification>();
qRegisterMetaType<Application>();
qRegisterMetaType<Setting>();
qRegisterMetaTypeStreamOperators<Setting>("Snore::Settings");
}
QString SnoreCorePrivate::tempPath()

View File

@ -1,6 +1,6 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2015 Patrick von Reth <vonreth@kde.org>
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
@ -15,54 +15,18 @@
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;
#ifndef SNOREGLOBALS
#define SNOREGLOBALS
Setting::Setting()
{
namespace Snore{
enum SettingsType{
GLOBAL_SETTING,
LOCAL_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;
}
#endif // SNOREGLOBALS

View File

@ -32,8 +32,10 @@ class GrowlBackend: public Snore::SnoreBackend
public:
GrowlBackend();
~GrowlBackend();
virtual bool initialize() override;
virtual bool deinitialize() override;
bool initialize() override;
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
static void gntpCallback(growl_callback_data *data);
@ -48,10 +50,6 @@ public slots:
void slotDeregisterApplication(const Snore::Application &application) override;
void slotNotify(Snore::Notification notification) override;
public:
Snore::PluginSettingsWidget *settingsWidget() override;
};
#endif // GROWL_BACKEND_H

View File

@ -6,6 +6,7 @@ if(WIN32)
set( SNARL_SRC
SnarlInterface.cpp
snarl.cpp
snarlsettings.cpp
)
add_library(libsnore_backend_snarl MODULE ${SNARL_SRC} )
target_link_libraries(libsnore_backend_snarl Snore::Libsnore )

View File

@ -17,6 +17,7 @@
*/
#include "snarl.h"
#include "snarlsettings.h"
#include "core/snore.h"
#include "core/snore_p.h"
@ -113,7 +114,7 @@ private:
SnarlBackend::SnarlBackend():
SnoreBackend("Snarl", true, false, true)
{
setDefaultValue("Password",QString());
}
SnarlBackend::~SnarlBackend()
@ -147,6 +148,11 @@ bool SnarlBackend::deinitialize()
return false;
}
PluginSettingsWidget *SnarlBackend::settingsWidget()
{
return new SnarlSettings(this);
}
void SnarlBackend::slotRegisterApplication(const Application &application)
{
@ -156,10 +162,13 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
m_applications.insert(application.name(), snarlInterface);
QString appName = application.name().replace(" ", "_"); //app sig must not contain spaces
snarlInterface->Register(appName.toUtf8().constData(),
QString password = value("Password").toString();
LONG32 result = snarlInterface->Register(appName.toUtf8().constData(),
application.name().toUtf8().constData(),
application.icon().localUrl().toUtf8().constData(),
0, (HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
password.isEmpty()?0:password.toUtf8().constData(),
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
snoreDebug(SNORE_DEBUG) << result;
foreach(const Alert & alert, application.alerts()) {
snarlInterface->AddClass(alert.name().toUtf8().constData(),

View File

@ -29,8 +29,11 @@ class SnarlBackend: public Snore::SnoreBackend
public:
SnarlBackend();
~SnarlBackend();
virtual bool initialize();
virtual bool deinitialize();
bool initialize() override;
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
private:
class SnarlWidget;