From f872186866bf5250ed9c40ce05a32ae1b71618b1 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sat, 5 Sep 2015 16:50:49 +0100 Subject: [PATCH] refs #450 Make disk file saving and loading available in core settings. --- src/blackcore/context_application.h | 6 ++++++ src/blackcore/context_application_impl.cpp | 12 ++++++++++++ src/blackcore/context_application_impl.h | 6 ++++++ src/blackcore/context_application_proxy.cpp | 10 ++++++++++ src/blackcore/context_application_proxy.h | 6 ++++++ src/blackcore/settingscache.cpp | 17 +++++++++++++++++ src/blackcore/settingscache.h | 9 +++++++++ 7 files changed, 66 insertions(+) diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 9d7f5cce8..c090f23b5 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -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 diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index 00344d1c2..f53a80813 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -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 diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index b8f051f81..6899dfc53 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -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; diff --git a/src/blackcore/context_application_proxy.cpp b/src/blackcore/context_application_proxy.cpp index b8dff9b96..82f1bc9c3 100644 --- a/src/blackcore/context_application_proxy.cpp +++ b/src/blackcore/context_application_proxy.cpp @@ -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(QLatin1Literal("saveSettings"), keyPrefix); + } + + BlackMisc::CStatusMessage CContextApplicationProxy::loadSettings() + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("loadSettings")); + } + void CContextApplicationProxy::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin) { this->m_dBusInterface->callDBus(QLatin1Literal("registerHotkeyActions"), actions, origin); diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index 22ee50469..8904a07ed 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -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; diff --git a/src/blackcore/settingscache.cpp b/src/blackcore/settingscache.cpp index 83ea1870c..e376cbcb2 100644 --- a/src/blackcore/settingscache.cpp +++ b/src/blackcore/settingscache.cpp @@ -8,6 +8,7 @@ */ #include "settingscache.h" +#include 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()); + } + } diff --git a/src/blackcore/settingscache.h b/src/blackcore/settingscache.h index fb7c83ef7..5abfbfaf4 100644 --- a/src/blackcore/settingscache.h +++ b/src/blackcore/settingscache.h @@ -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(); };