6#include <QStandardPaths>
12 CSettingsCache::CSettingsCache() :
CValueCache(0) {}
16 static std::unique_ptr<CSettingsCache> cache(
new CSettingsCache);
28 const QString &CSettingsCache::lockFileName()
34 CStatusMessage CSettingsCache::lockFile(
QLockFile &lock)
39 return CStatusMessage(
this).error(u
"Failed to create %1") << persistentStore();
43 return CStatusMessage(
this).error(u
"Failed to lock %1: %2")
44 << lockFileName() << CFileUtils::lockFileError(lock);
76 &CSettingsCache::saveToStoreByPacket);
89 CStatusMessage status = saveToFiles(persistentStore(), values.
toVariantMap());
90 CLogMessage::preformatted(status);
112 static const QString p(
"/settings/core");
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
static QString filenameForKey(const QString &key)
Return the filename where the value with the given key may be stored.
static const QString & persistentStore()
The directory where settings are stored.
CStatusMessage loadFromStore()
Load settings from disk.
void enableLocalSave()
Connects signal CValueCache::valuesSaveRequested to a private slot that saves the values....
static const QString & relativeFilePath()
Relative file path in application data directory.
static CSettingsCache * instance()
Return the singleton instance.
CStatusMessage saveToStore(const QString &keyPrefix={})
Save settings to disk.
QStringList enumerateStore() const
Return all files where settings may be stored.
Streamable status message, e.g.
bool isFailure() const
Operation considered unsuccessful.
Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes.
QStringList enumerateFiles(const QString &directory) const
List the Json files which are (or would be) used to save the current values. The files may or may not...
QString filenameForKey(const QString &key) const
Return the (relative) filename that may is (or would be) used to save the value with the given key....
void valuesSaveRequested(const swift::misc::CValueCachePacket &values)
Emitted when this cache has ratified a change which included a request to save (i....
CStatusMessage loadFromFiles(const QString &directory)
Load all values from Json files in a given directory. Values already in the cache will remain in the ...
CStatusMessage saveToFiles(const QString &directory, const QString &keyPrefix={})
Save values to Json files in a given directory. If prefix is provided then only those values whose ke...
Value class used for signalling changed values in the cache.
CVariantMap toVariantMap() const
Discard timestamps and return as variant map.
Free functions in swift::misc.
bool isLocked() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)