mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #450 Make disk file saving and loading available in core settings.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user