refs #450 Make disk file saving and loading available in core settings.

This commit is contained in:
Mathew Sutcliffe
2015-09-05 16:50:49 +01:00
parent 54bc3f265a
commit f872186866
7 changed files with 66 additions and 0 deletions

View File

@@ -104,6 +104,12 @@ namespace BlackCore
//! \note This is the function which relays cache changes via DBus.
virtual void changeSettings(const BlackMisc::CVariantMap &settings, const BlackMisc::CIdentifier &origin);
//! Save core settings to disk
virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) = 0;
//! Load core settings from disk
virtual BlackMisc::CStatusMessage loadSettings() = 0;
//! Register hotkey action implemented by another process
//! \note Not pure because it can be called from the base class constructor.
//! \note This is the function which relays action registrations via DBus

View File

@@ -47,6 +47,18 @@ namespace BlackCore
emit this->settingsChanged(settings, origin);
}
BlackMisc::CStatusMessage CContextApplication::saveSettings(const QString &keyPrefix)
{
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << keyPrefix; }
return CSettingsCache::instance()->saveToStore(keyPrefix);
}
BlackMisc::CStatusMessage CContextApplication::loadSettings()
{
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
return CSettingsCache::instance()->loadFromStore();
}
void CContextApplication::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin)
{
// Intentionally don't check for round trip here

View File

@@ -35,6 +35,12 @@ namespace BlackCore
//! \copydoc IContextApplication::changeSettings
virtual void changeSettings(const BlackMisc::CVariantMap &settings, const BlackMisc::CIdentifier &origin) override;
//! \copydoc IContextApplication::saveSettings
virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override;
//! \copydoc IContextApplication::loadSettings
virtual BlackMisc::CStatusMessage loadSettings() override;
//! \copydoc IContextApplication::registerHotkeyActions
virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override;

View File

@@ -67,6 +67,16 @@ namespace BlackCore
this->m_dBusInterface->callDBus(QLatin1Literal("changeSettings"), settings, origin);
}
BlackMisc::CStatusMessage CContextApplicationProxy::saveSettings(const QString &keyPrefix)
{
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("saveSettings"), keyPrefix);
}
BlackMisc::CStatusMessage CContextApplicationProxy::loadSettings()
{
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("loadSettings"));
}
void CContextApplicationProxy::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin)
{
this->m_dBusInterface->callDBus(QLatin1Literal("registerHotkeyActions"), actions, origin);

View File

@@ -31,6 +31,12 @@ namespace BlackCore
//! \copydoc IContextApplication::changeSettings
virtual void changeSettings(const BlackMisc::CVariantMap &settings, const BlackMisc::CIdentifier &origin) override;
//! \copydoc IContextApplication::saveSettings
virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override;
//! \copydoc IContextApplication::loadSettings
virtual BlackMisc::CStatusMessage loadSettings() override;
//! \copydoc IContextApplication::registerHotkeyActions
virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override;

View File

@@ -8,6 +8,7 @@
*/
#include "settingscache.h"
#include <QStandardPaths>
namespace BlackCore
{
@@ -22,4 +23,20 @@ namespace BlackCore
return &cache;
}
const QString &CSettingsCache::persistentStore()
{
static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/org.swift-project/settings/core";
return dir;
}
BlackMisc::CStatusMessage CSettingsCache::saveToStore(const QString &keyPrefix) const
{
return saveToFiles(persistentStore(), keyPrefix);
}
BlackMisc::CStatusMessage CSettingsCache::loadFromStore()
{
return loadFromFiles(persistentStore());
}
}

View File

@@ -27,6 +27,15 @@ namespace BlackCore
//! Return the singleton instance.
static CSettingsCache *instance();
//! The directory where core settings are stored.
static const QString &persistentStore();
//! Save core settings to disk.
BlackMisc::CStatusMessage saveToStore(const QString &keyPrefix = {}) const;
//! Load core settings from disk.
BlackMisc::CStatusMessage loadFromStore();
private:
CSettingsCache();
};