versionize settings
This commit is contained in:
parent
018628db88
commit
06a82304bd
|
@ -85,7 +85,7 @@ Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
|
|||
|
||||
QString SnorePlugin::normaliseKey(const QString &key) const
|
||||
{
|
||||
return QString("%1/%2").arg(m_name, key);
|
||||
return QString("%1/%2/%3").arg(m_name, settingsVersion(), key);
|
||||
}
|
||||
|
||||
const QString &SnorePlugin::name() const
|
||||
|
@ -103,6 +103,11 @@ const QString SnorePlugin::typeName() const
|
|||
return PluginContainer::typeToString(m_type);
|
||||
}
|
||||
|
||||
QString SnorePlugin::settingsVersion() const
|
||||
{
|
||||
return "1";
|
||||
}
|
||||
|
||||
bool SnorePlugin::deinitialize()
|
||||
{
|
||||
if (m_initialized) {
|
||||
|
|
|
@ -59,8 +59,11 @@ public:
|
|||
|
||||
virtual PluginSettingsWidget *settingsWidget();
|
||||
|
||||
protected:
|
||||
virtual QString settingsVersion() const;
|
||||
|
||||
private:
|
||||
SnorePlugin() {}
|
||||
SnorePlugin() = delete;
|
||||
QString normaliseKey(const QString &key) const;
|
||||
|
||||
QString m_name;
|
||||
|
|
|
@ -41,7 +41,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
|||
ui->tabWidget->addTab(widget, widget->name());
|
||||
m_tabs.append(widget);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog()
|
||||
|
@ -77,10 +76,10 @@ void SettingsDialog::load()
|
|||
void SettingsDialog::save()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "saving";
|
||||
SnoreCorePrivate::instance()->setBackendIfAvailible(ui->primaryBackendComboBox->currentText());
|
||||
for (auto w : m_tabs) {
|
||||
w->saveSettings();
|
||||
}
|
||||
SnoreCorePrivate::instance()->syncSettings();
|
||||
}
|
||||
|
||||
void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
||||
|
@ -99,3 +98,9 @@ void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|||
snoreDebug(SNORE_WARNING) << "unhandled role" << button->text();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::show()
|
||||
{
|
||||
load();
|
||||
QDialog::show();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
explicit SettingsDialog(QWidget *parent = 0);
|
||||
~SettingsDialog();
|
||||
|
||||
void show();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
void load();
|
||||
|
|
|
@ -100,9 +100,6 @@ void SnoreCore::broadcastNotification(Notification notification)
|
|||
{
|
||||
Q_D(SnoreCore);
|
||||
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
||||
if (!notification.isUpdate()) {
|
||||
d->syncSettings();
|
||||
}
|
||||
if (d->m_notificationBackend != nullptr) {
|
||||
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
||||
requestCloseNotification(notification.old(), Notification::REPLACED);
|
||||
|
@ -200,22 +197,22 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
|
|||
QVariant SnoreCore::value(const QString &key) const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
QString nk = d->normalizeKey(key);
|
||||
QString nk = d->specificKey(key);
|
||||
if(d->m_settings->contains(nk))
|
||||
{
|
||||
return d->m_settings->value(nk);
|
||||
}
|
||||
return d->m_settings->value(key);
|
||||
return d->m_settings->value(d->versionizeKey(key));
|
||||
|
||||
}
|
||||
|
||||
void SnoreCore::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = key;
|
||||
QString nk = d->versionizeKey(key);
|
||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||
{
|
||||
nk = d->normalizeKey(nk);
|
||||
nk = d->specificKey(key);
|
||||
}
|
||||
d->m_settings->setValue(nk,value);
|
||||
}
|
||||
|
@ -224,10 +221,10 @@ void SnoreCore::setValue(const QString &key, const QVariant &value)
|
|||
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = key;
|
||||
QString nk = d->versionizeKey(key);
|
||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||
{
|
||||
nk = d->normalizeKey(nk);
|
||||
nk = d->specificKey(key);
|
||||
}
|
||||
if (!d->m_settings->contains(nk)) {
|
||||
d->m_settings->setValue(nk, value);
|
||||
|
|
|
@ -133,8 +133,16 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend()
|
|||
|
||||
void SnoreCorePrivate::syncSettings()
|
||||
{
|
||||
setBackendIfAvailible(m_settings->value("PrimaryBackend").value<Setting>().value().toString());
|
||||
for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) {
|
||||
Q_Q(SnoreCore);
|
||||
QString oldBackend = q->primaryNotificationBackend();
|
||||
m_notificationBackend->deinitialize();
|
||||
m_notificationBackend = nullptr;
|
||||
if(!setBackendIfAvailible(q->value("PrimaryBackend").value<Setting>().value().toString()))
|
||||
{
|
||||
setBackendIfAvailible(oldBackend);
|
||||
}
|
||||
//TODO: cleanup
|
||||
auto syncPluginStatus = [&](const QString &pluginName){
|
||||
SnorePlugin *plugin = m_plugins.value(pluginName);
|
||||
bool enable = m_plugins[pluginName]->value("Enabled").toBool();
|
||||
if (!plugin->isInitialized() && enable) {
|
||||
|
@ -142,6 +150,16 @@ void SnoreCorePrivate::syncSettings()
|
|||
} else if (plugin->isInitialized() && !enable) {
|
||||
plugin->deinitialize();
|
||||
}
|
||||
};
|
||||
|
||||
for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) {
|
||||
syncPluginStatus(pluginName);
|
||||
}
|
||||
for (auto pluginName : m_pluginNames[SnorePlugin::FRONTEND]) {
|
||||
syncPluginStatus(pluginName);
|
||||
}
|
||||
for (auto pluginName : m_pluginNames[SnorePlugin::PLUGIN]) {
|
||||
syncPluginStatus(pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define SNORECOREPRIVATE_H
|
||||
|
||||
#include "snore.h"
|
||||
#include "version.h"
|
||||
#include "plugins/snorebackend.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
*/
|
||||
static QString tempPath();
|
||||
|
||||
|
||||
public:
|
||||
static SnoreCorePrivate *instance();
|
||||
~SnoreCorePrivate();
|
||||
|
@ -63,10 +65,19 @@ public:
|
|||
|
||||
bool initPrimaryNotificationBackend();
|
||||
|
||||
inline QString versionSchema() const {
|
||||
return "1";
|
||||
}
|
||||
|
||||
void syncSettings();
|
||||
|
||||
QString normalizeKey(const QString &key) const{
|
||||
return QString("AppSpecificSettings/%1/%2").arg(m_hints.value("app_specific_settings","SnoreNotify").toString(),key);
|
||||
|
||||
QString versionizeKey(const QString &key) const{
|
||||
return QString("%1/%2").arg(key, versionSchema());
|
||||
}
|
||||
|
||||
QString specificKey(const QString &key) const{
|
||||
return versionizeKey(QString("AppSpecificSettings/%1/%2").arg(m_hints.value("app_specific_settings","SnoreNotify").toString(),key));
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,7 +91,6 @@ private slots:
|
|||
void slotAboutToQuit();
|
||||
|
||||
private:
|
||||
|
||||
SnoreCorePrivate();
|
||||
SnoreCore *q_ptr;
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ bool SnarlBackend::initialize()
|
|||
{
|
||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||
if (!snarlInterface->IsSnarlRunning()) {
|
||||
snoreDebug(SNORE_WARNING) << "Snarl is not running";
|
||||
delete snarlInterface;
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue