1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org> |
4 | SPDX-FileCopyrightText: 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org> |
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 |
17 | * \inmodule KConfigCore |
18 | * |
19 | * \brief KConfig variant using shared memory. |
20 | * |
21 | * KSharedConfig provides a shared (reference counted) variant |
22 | * of KConfig. This allows you to use/manipulate the same configuration |
23 | * files from different places in your code without worrying about |
24 | * accidentally overwriting changes. |
25 | * |
26 | * The openConfig() method is threadsafe: every thread gets a separate repository |
27 | * of shared KConfig objects. This means, however, that you'll be responsible for |
28 | * synchronizing the instances of KConfig for the same filename between threads, |
29 | * using KConfig::reparseConfiguration() after a manual change notification, just like you have |
30 | * to do between processes. |
31 | */ |
32 | class KCONFIGCORE_EXPORT KSharedConfig : public KConfig, public QSharedData // krazy:exclude=dpointer (only for refcounting) |
33 | { |
34 | public: |
35 | /*! |
36 | * \typedef KSharedConfig::Ptr |
37 | * |
38 | * A pointer to a KSharedConfig object. |
39 | */ |
40 | typedef QExplicitlySharedDataPointer<KSharedConfig> Ptr; |
41 | |
42 | public: |
43 | /*! |
44 | * Creates a KSharedConfig object to manipulate a configuration file. |
45 | * |
46 | * If an absolute path is specified for \a fileName, that file will be used |
47 | * as the store for the configuration settings. If a non-absolute path |
48 | * is provided, the file will be looked for in the standard directory |
49 | * specified by \a type. If no path is provided, a default |
50 | * configuration file will be used based on the name of the main |
51 | * application component. |
52 | * |
53 | * \a mode determines whether the user or global settings will be allowed |
54 | * to influence the values returned by this object. See KConfig::OpenFlags for |
55 | * more details. |
56 | * |
57 | * \a fileName The configuration file to open. If empty, it will be determined |
58 | * automatically (from --config on the command line, otherwise |
59 | * from the application name + "rc") |
60 | * |
61 | * \a mode How global settings should affect the configuration options exposed by this KConfig object |
62 | * |
63 | * \a type The standard directory to look for the configuration file in (see QStandardPaths) |
64 | * |
65 | * \sa KConfig |
66 | */ |
67 | static KSharedConfig::Ptr |
68 | openConfig(const QString &fileName = QString(), OpenFlags mode = FullConfig, QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation); |
69 | |
70 | /*! |
71 | * Creates a KSharedConfig object to manipulate a configuration file suitable |
72 | * for storing state information. Use this for storing information that is |
73 | * changing frequently and should not be saved by configuration backup |
74 | * utilities. |
75 | * |
76 | * If an absolute path is specified for \a fileName, that file will be used |
77 | * as the store for the configuration settings. If a non-absolute path |
78 | * is provided, the file will be looked for in the standard data directory |
79 | * (QStandardPaths::AppDataLocation). If no path is provided, a default |
80 | * configuration file will be used based on the name of the main |
81 | * application component. |
82 | * |
83 | * \a fileName the configuration file to open. If empty, it will be determined |
84 | * automatically from the application name + "staterc" |
85 | * |
86 | * \since 5.67 |
87 | * |
88 | * \sa KConfig |
89 | */ |
90 | static KSharedConfig::Ptr openStateConfig(const QString &fileName = QString()); |
91 | |
92 | ~KSharedConfig() override; |
93 | |
94 | private: |
95 | Q_DISABLE_COPY(KSharedConfig) |
96 | KConfigGroup groupImpl(const QString &groupName) override; |
97 | const KConfigGroup groupImpl(const QString &groupName) const override; |
98 | |
99 | KCONFIGCORE_NO_EXPORT KSharedConfig(const QString &file, OpenFlags mode, QStandardPaths::StandardLocation resourceType); |
100 | }; |
101 | |
102 | /*! |
103 | * \typedef KSharedConfigPtr |
104 | */ |
105 | typedef KSharedConfig::Ptr KSharedConfigPtr; |
106 | |
107 | #endif // multiple inclusion guard |
108 | |