KConfig

ksharedconfig.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Preston Brown <[email protected]>
4  SPDX-FileCopyrightText: 1997-1999 Matthias Kalle Dalheimer <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KSHAREDCONFIG_H
10 #define KSHAREDCONFIG_H
11 
12 #include <QExplicitlySharedDataPointer>
13 #include <kconfig.h>
14 
15 /**
16  * \class KSharedConfig ksharedconfig.h <KSharedConfig>
17  *
18  * KConfig variant using shared memory
19  *
20  * KSharedConfig provides a shared (reference counted) variant
21  * of KConfig. This allows you to use/manipulate the same configuration
22  * files from different places in your code without worrying about
23  * accidentally overwriting changes.
24  *
25  * The openConfig() method is threadsafe: every thread gets a separate repository
26  * of shared KConfig objects. This means, however, that you'll be responsible for
27  * synchronizing the instances of KConfig for the same filename between threads,
28  * using KConfig::reparseConfiguration() after a manual change notification, just like you have
29  * to do between processes.
30  */
31 class KCONFIGCORE_EXPORT KSharedConfig : public KConfig, public QSharedData // krazy:exclude=dpointer (only for refcounting)
32 {
33 public:
35 
36 public:
37  /**
38  * Creates a KSharedConfig object to manipulate a configuration file
39  *
40  * If an absolute path is specified for @p fileName, that file will be used
41  * as the store for the configuration settings. If a non-absolute path
42  * is provided, the file will be looked for in the standard directory
43  * specified by @p type. If no path is provided, a default
44  * configuration file will be used based on the name of the main
45  * application component.
46  *
47  * @p mode determines whether the user or global settings will be allowed
48  * to influence the values returned by this object. See KConfig::OpenFlags for
49  * more details.
50  *
51  * @param fileName the configuration file to open. If empty, it will be determined
52  * automatically (from --config on the command line, otherwise
53  * from the application name + "rc")
54  * @param mode how global settings should affect the configuration
55  * options exposed by this KConfig object
56  * @param type The standard directory to look for the configuration
57  * file in (see QStandardPaths)
58  *
59  * @sa KConfig
60  */
61  static KSharedConfig::Ptr
62  openConfig(const QString &fileName = QString(), OpenFlags mode = FullConfig, QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation);
63 
64  /**
65  * Creates a KSharedConfig object to manipulate a configuration file suitable
66  * for storing state information. Use this for storing information that is
67  * changing frequently and should not be saved by configuration backup
68  * utilities.
69  *
70  * If an absolute path is specified for @p fileName, that file will be used
71  * as the store for the configuration settings. If a non-absolute path
72  * is provided, the file will be looked for in the standard data directory
73  * (QStandardPaths::AppDataLocation). If no path is provided, a default
74  * configuration file will be used based on the name of the main
75  * application component.
76  *
77  * @param fileName the configuration file to open. If empty, it will be determined
78  * automatically from the application name + "staterc"
79  *
80  * @since 5.67
81  *
82  * @sa KConfig
83  */
84  static KSharedConfig::Ptr openStateConfig(const QString &fileName = QString());
85 
86  ~KSharedConfig() override;
87 
88 private:
89  Q_DISABLE_COPY(KSharedConfig)
90  KConfigGroup groupImpl(const QByteArray &aGroup) override;
91  const KConfigGroup groupImpl(const QByteArray &aGroup) const override;
92 
93  KCONFIGCORE_NO_EXPORT KSharedConfig(const QString &file, OpenFlags mode, QStandardPaths::StandardLocation resourceType);
94 };
95 
97 
98 #endif // multiple inclusion guard
The central class of the KDE configuration data system.
Definition: kconfig.h:56
KConfigGroup groupImpl(const QByteArray &b) override
Definition: kconfig.cpp:899
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:10:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.