1 | /* |
2 | This file is part of the KDE libraries |
3 | Copyright (c) 1999 Preston Brown <pbrown@kde.org> |
4 | Copyright (C) 1997-1999 Matthias Kalle Dalheimer (kalle@kde.org) |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef KSHAREDCONFIG_H |
23 | #define KSHAREDCONFIG_H |
24 | |
25 | #include <kconfig.h> |
26 | #include <ksharedptr.h> |
27 | |
28 | /** |
29 | * \class KSharedConfig ksharedconfig.h <KSharedConfig> |
30 | * |
31 | * KConfig variant using shared memory |
32 | * |
33 | * KSharedConfig provides a reference counted, shared memory variant |
34 | * of KConfig. This allows you to use manipulate the same configuration |
35 | * files from different places in your code without worrying about |
36 | * accidentally overwriting changes. |
37 | * |
38 | * Note that, as with most of kdelibs, this is @b NOT threadsafe. |
39 | */ |
40 | class KDECORE_EXPORT KSharedConfig : public KConfig, public QSharedData //krazy:exclude=dpointer (only for refcounting) |
41 | { |
42 | public: |
43 | typedef KSharedPtr<KSharedConfig> Ptr; |
44 | |
45 | public: |
46 | /** |
47 | * Creates a KSharedConfig object to manipulate a configuration file |
48 | * |
49 | * If an absolute path is specified for @p fileName, that file will be used |
50 | * as the store for the configuration settings. If a non-absolute path |
51 | * is provided, the file will be looked for in the standard directory |
52 | * specified by resourceType. If no path is provided, a default |
53 | * configuration file will be used based on the name of the main |
54 | * application component. |
55 | * |
56 | * @p mode determines whether the user or global settings will be allowed |
57 | * to influence the values returned by this object. See KConfig::OpenFlags for |
58 | * more details. |
59 | * |
60 | * @param fileName the configuration file to open |
61 | * @param mode how global settings should affect the configuration |
62 | * options exposed by this KConfig object |
63 | * @param resourceType The standard directory to look for the configuration |
64 | * file in (see KStandardDirs) |
65 | * |
66 | * @sa KConfig::KConfig(const QString&, OpenFlags, const char*) |
67 | */ |
68 | static KSharedConfig::Ptr openConfig(const QString& fileName = QString(), |
69 | OpenFlags mode = FullConfig, |
70 | const char *resourceType = "config" ); |
71 | |
72 | /** |
73 | * Constructs a KSharedConfig object. |
74 | * |
75 | * If an absolute path is specified for @p fileName, that file will be used |
76 | * as the store for the configuration settings. If a non-absolute path |
77 | * is provided, the file will be looked for in the standard directory |
78 | * specified by resourceType. If no path is provided, a default |
79 | * configuration file will be used based on the component's name. |
80 | * |
81 | * @p mode determines whether the user or global settings will be allowed |
82 | * to influence the values returned by this object. See KConfig::OpenFlags for |
83 | * more details. |
84 | * |
85 | * @param componentData the component that you wish to load a configuration |
86 | * file for |
87 | * @param fileName the configuration file to open |
88 | * @param mode how global settings should affect the configuration |
89 | * options exposed by this KConfig object |
90 | * @param resourceType The standard directory to look for the configuration |
91 | * file in (see KStandardDirs) |
92 | * |
93 | * @sa KConfig::KConfig(const KComponentData&, const QString&, OpenFlags, const char*) |
94 | */ |
95 | static KSharedConfig::Ptr openConfig(const KComponentData &componentData, |
96 | const QString &fileName = QString(), |
97 | OpenFlags mode = FullConfig, |
98 | const char *resourceType = "config" ); |
99 | |
100 | virtual ~KSharedConfig(); |
101 | |
102 | private: |
103 | virtual KConfigGroup groupImpl(const QByteArray& aGroup); |
104 | virtual const KConfigGroup groupImpl(const QByteArray& aGroup) const; |
105 | |
106 | KSharedConfig(const KComponentData& componentData, const QString& file, OpenFlags mode, |
107 | const char* resourceType); |
108 | }; |
109 | |
110 | typedef KSharedConfig::Ptr KSharedConfigPtr; |
111 | |
112 | #endif // multiple inclusion guard |
113 | |