mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-17 02:46:23 +00:00
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
|
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
|
const QString &SnorePlugin::name() const
|
||||||
@ -103,6 +103,11 @@ const QString SnorePlugin::typeName() const
|
|||||||
return PluginContainer::typeToString(m_type);
|
return PluginContainer::typeToString(m_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SnorePlugin::settingsVersion() const
|
||||||
|
{
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
|
||||||
bool SnorePlugin::deinitialize()
|
bool SnorePlugin::deinitialize()
|
||||||
{
|
{
|
||||||
if (m_initialized) {
|
if (m_initialized) {
|
||||||
|
@ -59,8 +59,11 @@ public:
|
|||||||
|
|
||||||
virtual PluginSettingsWidget *settingsWidget();
|
virtual PluginSettingsWidget *settingsWidget();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QString settingsVersion() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SnorePlugin() {}
|
SnorePlugin() = delete;
|
||||||
QString normaliseKey(const QString &key) const;
|
QString normaliseKey(const QString &key) const;
|
||||||
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
@ -41,7 +41,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
|||||||
ui->tabWidget->addTab(widget, widget->name());
|
ui->tabWidget->addTab(widget, widget->name());
|
||||||
m_tabs.append(widget);
|
m_tabs.append(widget);
|
||||||
}
|
}
|
||||||
load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsDialog::~SettingsDialog()
|
SettingsDialog::~SettingsDialog()
|
||||||
@ -77,10 +76,10 @@ void SettingsDialog::load()
|
|||||||
void SettingsDialog::save()
|
void SettingsDialog::save()
|
||||||
{
|
{
|
||||||
snoreDebug(SNORE_DEBUG) << "saving";
|
snoreDebug(SNORE_DEBUG) << "saving";
|
||||||
SnoreCorePrivate::instance()->setBackendIfAvailible(ui->primaryBackendComboBox->currentText());
|
|
||||||
for (auto w : m_tabs) {
|
for (auto w : m_tabs) {
|
||||||
w->saveSettings();
|
w->saveSettings();
|
||||||
}
|
}
|
||||||
|
SnoreCorePrivate::instance()->syncSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
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();
|
snoreDebug(SNORE_WARNING) << "unhandled role" << button->text();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::show()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
QDialog::show();
|
||||||
|
}
|
||||||
|
@ -48,6 +48,8 @@ public:
|
|||||||
explicit SettingsDialog(QWidget *parent = 0);
|
explicit SettingsDialog(QWidget *parent = 0);
|
||||||
~SettingsDialog();
|
~SettingsDialog();
|
||||||
|
|
||||||
|
void show();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
void load();
|
void load();
|
||||||
|
@ -100,9 +100,6 @@ void SnoreCore::broadcastNotification(Notification notification)
|
|||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
||||||
if (!notification.isUpdate()) {
|
|
||||||
d->syncSettings();
|
|
||||||
}
|
|
||||||
if (d->m_notificationBackend != nullptr) {
|
if (d->m_notificationBackend != nullptr) {
|
||||||
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
||||||
requestCloseNotification(notification.old(), Notification::REPLACED);
|
requestCloseNotification(notification.old(), Notification::REPLACED);
|
||||||
@ -200,22 +197,22 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
|
|||||||
QVariant SnoreCore::value(const QString &key) const
|
QVariant SnoreCore::value(const QString &key) const
|
||||||
{
|
{
|
||||||
Q_D(const SnoreCore);
|
Q_D(const SnoreCore);
|
||||||
QString nk = d->normalizeKey(key);
|
QString nk = d->specificKey(key);
|
||||||
if(d->m_settings->contains(nk))
|
if(d->m_settings->contains(nk))
|
||||||
{
|
{
|
||||||
return d->m_settings->value(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)
|
void SnoreCore::setValue(const QString &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
QString nk = key;
|
QString nk = d->versionizeKey(key);
|
||||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||||
{
|
{
|
||||||
nk = d->normalizeKey(nk);
|
nk = d->specificKey(key);
|
||||||
}
|
}
|
||||||
d->m_settings->setValue(nk,value);
|
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)
|
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
QString nk = key;
|
QString nk = d->versionizeKey(key);
|
||||||
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
if(value.canConvert<Setting>() && value.value<Setting>().isSpecific())
|
||||||
{
|
{
|
||||||
nk = d->normalizeKey(nk);
|
nk = d->specificKey(key);
|
||||||
}
|
}
|
||||||
if (!d->m_settings->contains(nk)) {
|
if (!d->m_settings->contains(nk)) {
|
||||||
d->m_settings->setValue(nk, value);
|
d->m_settings->setValue(nk, value);
|
||||||
|
@ -133,8 +133,16 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend()
|
|||||||
|
|
||||||
void SnoreCorePrivate::syncSettings()
|
void SnoreCorePrivate::syncSettings()
|
||||||
{
|
{
|
||||||
setBackendIfAvailible(m_settings->value("PrimaryBackend").value<Setting>().value().toString());
|
Q_Q(SnoreCore);
|
||||||
for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) {
|
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);
|
SnorePlugin *plugin = m_plugins.value(pluginName);
|
||||||
bool enable = m_plugins[pluginName]->value("Enabled").toBool();
|
bool enable = m_plugins[pluginName]->value("Enabled").toBool();
|
||||||
if (!plugin->isInitialized() && enable) {
|
if (!plugin->isInitialized() && enable) {
|
||||||
@ -142,6 +150,16 @@ void SnoreCorePrivate::syncSettings()
|
|||||||
} else if (plugin->isInitialized() && !enable) {
|
} else if (plugin->isInitialized() && !enable) {
|
||||||
plugin->deinitialize();
|
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
|
#define SNORECOREPRIVATE_H
|
||||||
|
|
||||||
#include "snore.h"
|
#include "snore.h"
|
||||||
|
#include "version.h"
|
||||||
#include "plugins/snorebackend.h"
|
#include "plugins/snorebackend.h"
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@ -46,6 +47,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
static QString tempPath();
|
static QString tempPath();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static SnoreCorePrivate *instance();
|
static SnoreCorePrivate *instance();
|
||||||
~SnoreCorePrivate();
|
~SnoreCorePrivate();
|
||||||
@ -63,10 +65,19 @@ public:
|
|||||||
|
|
||||||
bool initPrimaryNotificationBackend();
|
bool initPrimaryNotificationBackend();
|
||||||
|
|
||||||
|
inline QString versionSchema() const {
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
|
||||||
void syncSettings();
|
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();
|
void slotAboutToQuit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SnoreCorePrivate();
|
SnoreCorePrivate();
|
||||||
SnoreCore *q_ptr;
|
SnoreCore *q_ptr;
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ bool SnarlBackend::initialize()
|
|||||||
{
|
{
|
||||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||||
if (!snarlInterface->IsSnarlRunning()) {
|
if (!snarlInterface->IsSnarlRunning()) {
|
||||||
|
snoreDebug(SNORE_WARNING) << "Snarl is not running";
|
||||||
delete snarlInterface;
|
delete snarlInterface;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user