diff options
author | Nicolas Fella <nicolas.fella@gmx.de> | 2020-01-05 21:02:08 +0100 |
---|---|---|
committer | Nicolas Fella <nicolas.fella@gmx.de> | 2020-01-05 21:14:43 +0100 |
commit | ebd14f29f8052ff5119bf97b42e61f404f223615 (patch) | |
tree | bf8163374685e0993cff7f3fd76fbb1208d2c885 | |
parent | ae93e9da13fa18bcc9be2d84010e916dc71ab1bf (diff) | |
download | kconfig-ebd14f29f8052ff5119bf97b42e61f404f223615.tar.gz kconfig-ebd14f29f8052ff5119bf97b42e61f404f223615.tar.bz2 |
Add KSharedConfig::openStateConfig for storing state information
Summary:
A common complaint is that our apps store 'state' information such as recent files or window sizes in their configuration files, making it ugly to store them in version control systems.
Therefore we should not store such information in XDG_CONFIG_DIR but instead use XDG_DATA_DIR for this.
This patch adds a utility method that creates a KSharedConfig backed by a file in such a suitable location.
For e.g. dolphin the file .local/share/dolphin/dolphinstaterc would be created.
See T12246 for some context
Reviewers: #frameworks, dfaure
Reviewed By: dfaure
Subscribers: kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D26440
-rw-r--r-- | src/core/ksharedconfig.cpp | 11 | ||||
-rw-r--r-- | src/core/ksharedconfig.h | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/core/ksharedconfig.cpp b/src/core/ksharedconfig.cpp index 0b2b9c35..0530abac 100644 --- a/src/core/ksharedconfig.cpp +++ b/src/core/ksharedconfig.cpp @@ -121,6 +121,17 @@ KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName, return ptr; } +KSharedConfig::Ptr KSharedConfig::openStateConfig(const QString &_fileName) +{ + QString fileName(_fileName); + + if (fileName.isEmpty()) { + fileName = QCoreApplication::applicationName() + QLatin1String("staterc"); + } + + return openConfig(fileName, SimpleConfig, QStandardPaths::AppDataLocation); +} + KSharedConfig::KSharedConfig(const QString &fileName, OpenFlags flags, QStandardPaths::StandardLocation resType) diff --git a/src/core/ksharedconfig.h b/src/core/ksharedconfig.h index e3a06b2e..0a35f9f4 100644 --- a/src/core/ksharedconfig.h +++ b/src/core/ksharedconfig.h @@ -75,6 +75,28 @@ public: OpenFlags mode = FullConfig, QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation); + /** + * Creates a KSharedConfig object to manipulate a configuration file suitable + * for storing state information. Use this for storing information that is + * changing frequently and should not be saved by configuration backup + * utilities. + * + * If an absolute path is specified for @p fileName, that file will be used + * as the store for the configuration settings. If a non-absolute path + * is provided, the file will be looked for in the standard data directory + * (QStandardPaths::AppDataLocation). If no path is provided, a default + * configuration file will be used based on the name of the main + * application component. + * + * @param fileName the configuration file to open. If empty, it will be determined + * automatically from the application name + "staterc" + * + * @since 5.67 + * + * @sa KConfig + */ + static KSharedConfig::Ptr openStateConfig(const QString &fileName = QString()); + ~KSharedConfig() override; private: |