summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/kprefs.h
Unidiff
Diffstat (limited to 'microkde/kdecore/kprefs.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kprefs.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/microkde/kdecore/kprefs.h b/microkde/kdecore/kprefs.h
index 95d2724..d9d1572 100644
--- a/microkde/kdecore/kprefs.h
+++ b/microkde/kdecore/kprefs.h
@@ -1,124 +1,126 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef _KPREFS_H 20#ifndef _KPREFS_H
21#define _KPREFS_H 21#define _KPREFS_H
22// $Id$ 22// $Id$
23 23
24#include <qptrlist.h> 24#include <q3ptrlist.h>
25#include <qcolor.h> 25#include <qcolor.h>
26#include <qfont.h> 26#include <qfont.h>
27#include <qsize.h> 27#include <qsize.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29//Added by qt3to4:
30#include <Q3ValueList>
29 31
30class KConfig; 32class KConfig;
31 33
32/** 34/**
33 @short Class for storing a preferences setting 35 @short Class for storing a preferences setting
34 @author Cornelius Schumacher 36 @author Cornelius Schumacher
35 @see KPref 37 @see KPref
36 38
37 This class represents one preferences setting as used by @ref KPrefs. 39 This class represents one preferences setting as used by @ref KPrefs.
38 Subclasses of KPrefsItem implement storage functions for a certain type of 40 Subclasses of KPrefsItem implement storage functions for a certain type of
39 setting. Normally you don't have to use this class directly. Use the special 41 setting. Normally you don't have to use this class directly. Use the special
40 addItem() functions of KPrefs instead. If you subclass this class you will 42 addItem() functions of KPrefs instead. If you subclass this class you will
41 have to register instances with the function KPrefs::addItem(). 43 have to register instances with the function KPrefs::addItem().
42*/ 44*/
43class KPrefsItem { 45class KPrefsItem {
44 public: 46 public:
45 /** 47 /**
46 Constructor. 48 Constructor.
47 49
48 @param group Config file group. 50 @param group Config file group.
49 @param name Config file key. 51 @param name Config file key.
50 */ 52 */
51 KPrefsItem(const QString &group,const QString &name) : 53 KPrefsItem(const QString &group,const QString &name) :
52 mGroup(group),mName(name) {} 54 mGroup(group),mName(name) {}
53 /** 55 /**
54 Destructor. 56 Destructor.
55 */ 57 */
56 virtual ~KPrefsItem() {} 58 virtual ~KPrefsItem() {}
57 59
58 /** 60 /**
59 This function is called by @ref KPrefs to set this setting to its default 61 This function is called by @ref KPrefs to set this setting to its default
60 value. 62 value.
61 */ 63 */
62 virtual void setDefault() = 0; 64 virtual void setDefault() = 0;
63 /** 65 /**
64 This function is called by @ref KPrefs to read the value for this setting 66 This function is called by @ref KPrefs to read the value for this setting
65 from a config file. 67 from a config file.
66 value. 68 value.
67 */ 69 */
68 virtual void readConfig(KConfig *) = 0; 70 virtual void readConfig(KConfig *) = 0;
69 /** 71 /**
70 This function is called by @ref KPrefs to write the value of this setting 72 This function is called by @ref KPrefs to write the value of this setting
71 to a config file. 73 to a config file.
72 */ 74 */
73 virtual void writeConfig(KConfig *) = 0; 75 virtual void writeConfig(KConfig *) = 0;
74 76
75 protected: 77 protected:
76 QString mGroup; 78 QString mGroup;
77 QString mName; 79 QString mName;
78}; 80};
79 81
80/** 82/**
81 @short Class for handling preferences settings for an application. 83 @short Class for handling preferences settings for an application.
82 @author Cornelius Schumacher 84 @author Cornelius Schumacher
83 @see KPrefsItem 85 @see KPrefsItem
84 86
85 This class provides an interface to preferences settings. Preferences items 87 This class provides an interface to preferences settings. Preferences items
86 can be registered by the addItem() function corresponding to the data type of 88 can be registered by the addItem() function corresponding to the data type of
87 the seetting. KPrefs then handles reading and writing of config files and 89 the seetting. KPrefs then handles reading and writing of config files and
88 setting of default values. 90 setting of default values.
89 91
90 Normally you will subclass KPrefs, add data members for the preferences 92 Normally you will subclass KPrefs, add data members for the preferences
91 settings and register the members in the constructor of the subclass. 93 settings and register the members in the constructor of the subclass.
92 94
93 Example: 95 Example:
94 <pre> 96 <pre>
95 class MyPrefs : public KPrefs { 97 class MyPrefs : public KPrefs {
96 public: 98 public:
97 MyPrefs() 99 MyPrefs()
98 { 100 {
99 setCurrentGroup("MyGroup"); 101 setCurrentGroup("MyGroup");
100 addItemBool("MySetting1",&mMyBool,false); 102 addItemBool("MySetting1",&mMyBool,false);
101 addItemColor("MySetting2",&mMyColor,QColor(1,2,3)); 103 addItemColor("MySetting2",&mMyColor,QColor(1,2,3));
102 104
103 setCurrentGroup("MyOtherGroup"); 105 setCurrentGroup("MyOtherGroup");
104 addItemFont("MySetting3",&mMyFont,QFont("helvetica",12)); 106 addItemFont("MySetting3",&mMyFont,QFont("helvetica",12));
105 } 107 }
106 108
107 bool mMyBool; 109 bool mMyBool;
108 QColor mMyColor; 110 QColor mMyColor;
109 QFont mMyFont; 111 QFont mMyFont;
110 } 112 }
111 </pre> 113 </pre>
112 114
113 It might be convenient in many cases to make this subclass of KPrefs a 115 It might be convenient in many cases to make this subclass of KPrefs a
114 singleton for global access from all over the application without passing 116 singleton for global access from all over the application without passing
115 references to the KPrefs object around. 117 references to the KPrefs object around.
116 118
117 You can set all values to default values by calling @ref setDefaults(), write 119 You can set all values to default values by calling @ref setDefaults(), write
118 the data to the configuration file by calling @ref writeConfig() and read the 120 the data to the configuration file by calling @ref writeConfig() and read the
119 data from the configuration file by calling @ref readConfig(). 121 data from the configuration file by calling @ref readConfig().
120 122
121 If you have items, which are not covered by the existing addItem() functions 123 If you have items, which are not covered by the existing addItem() functions
122 you can add customized code for reading, writing and default setting by 124 you can add customized code for reading, writing and default setting by
123 implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and 125 implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and
124 @ref usrWriteConfig(). 126 @ref usrWriteConfig().
@@ -190,127 +192,127 @@ class KPrefs {
190 @param key Key used in config file. 192 @param key Key used in config file.
191 @param reference Pointer to the variable, which is set by readConfig() 193 @param reference Pointer to the variable, which is set by readConfig()
192 and setDefaults() calls and read by writeConfig() calls. 194 and setDefaults() calls and read by writeConfig() calls.
193 @param defaultValue Default value, which is used by setDefaults() and 195 @param defaultValue Default value, which is used by setDefaults() and
194 when the config file does not yet contain the key of 196 when the config file does not yet contain the key of
195 this item. 197 this item.
196 */ 198 */
197 void addItemInt(const QString &key,int *reference, 199 void addItemInt(const QString &key,int *reference,
198 int defaultValue=0); 200 int defaultValue=0);
199 /** 201 /**
200 Register an item of type QColor. 202 Register an item of type QColor.
201 203
202 @param key Key used in config file. 204 @param key Key used in config file.
203 @param reference Pointer to the variable, which is set by readConfig() 205 @param reference Pointer to the variable, which is set by readConfig()
204 and setDefaults() calls and read by writeConfig() calls. 206 and setDefaults() calls and read by writeConfig() calls.
205 @param defaultValue Default value, which is used by setDefaults() and 207 @param defaultValue Default value, which is used by setDefaults() and
206 when the config file does not yet contain the key of 208 when the config file does not yet contain the key of
207 this item. 209 this item.
208 */ 210 */
209 void addItemColor(const QString &key,QColor *reference, 211 void addItemColor(const QString &key,QColor *reference,
210 const QColor &defaultValue=QColor(128,128,128)); 212 const QColor &defaultValue=QColor(128,128,128));
211 213
212 /** 214 /**
213 Register an item of type QSize. 215 Register an item of type QSize.
214 216
215 @param key Key used in config file. 217 @param key Key used in config file.
216 @param reference Pointer to the variable, which is set by readConfig() 218 @param reference Pointer to the variable, which is set by readConfig()
217 and setDefaults() calls and read by writeConfig() calls. 219 and setDefaults() calls and read by writeConfig() calls.
218 @param defaultValue Default value, which is used by setDefaults() and 220 @param defaultValue Default value, which is used by setDefaults() and
219 when the config file does not yet contain the key of 221 when the config file does not yet contain the key of
220 this item. 222 this item.
221 */ 223 */
222 void addItemSize(const QString &key,QSize *reference, 224 void addItemSize(const QString &key,QSize *reference,
223 const QSize &defaultValue=QSize()); 225 const QSize &defaultValue=QSize());
224 226
225 /** 227 /**
226 Register an item of type QFont. 228 Register an item of type QFont.
227 229
228 @param key Key used in config file. 230 @param key Key used in config file.
229 @param reference Pointer to the variable, which is set by readConfig() 231 @param reference Pointer to the variable, which is set by readConfig()
230 and setDefaults() calls and read by writeConfig() calls. 232 and setDefaults() calls and read by writeConfig() calls.
231 @param defaultValue Default value, which is used by setDefaults() and 233 @param defaultValue Default value, which is used by setDefaults() and
232 when the config file does not yet contain the key of 234 when the config file does not yet contain the key of
233 this item. 235 this item.
234 */ 236 */
235 void addItemFont(const QString &key,QFont *reference, 237 void addItemFont(const QString &key,QFont *reference,
236 const QFont &defaultValue=QFont("helvetica",12)); 238 const QFont &defaultValue=QFont("helvetica",12));
237 /** 239 /**
238 Register an item of type QString. 240 Register an item of type QString.
239 241
240 @param key Key used in config file. 242 @param key Key used in config file.
241 @param reference Pointer to the variable, which is set by readConfig() 243 @param reference Pointer to the variable, which is set by readConfig()
242 and setDefaults() calls and read by writeConfig() calls. 244 and setDefaults() calls and read by writeConfig() calls.
243 @param defaultValue Default value, which is used by setDefaults() and 245 @param defaultValue Default value, which is used by setDefaults() and
244 when the config file does not yet contain the key of 246 when the config file does not yet contain the key of
245 this item. 247 this item.
246 */ 248 */
247 void addItemString(const QString &key,QString *reference, 249 void addItemString(const QString &key,QString *reference,
248 const QString &defaultValue=""); 250 const QString &defaultValue="");
249 /** 251 /**
250 Register a password item of type QString. The string value is written 252 Register a password item of type QString. The string value is written
251 encrypted to the config file. Note that the current encryption scheme 253 encrypted to the config file. Note that the current encryption scheme
252 is very weak. 254 is very weak.
253 255
254 @param key Key used in config file. 256 @param key Key used in config file.
255 @param reference Pointer to the variable, which is set by readConfig() 257 @param reference Pointer to the variable, which is set by readConfig()
256 and setDefaults() calls and read by writeConfig() calls. 258 and setDefaults() calls and read by writeConfig() calls.
257 @param defaultValue Default value, which is used by setDefaults() and 259 @param defaultValue Default value, which is used by setDefaults() and
258 when the config file does not yet contain the key of 260 when the config file does not yet contain the key of
259 this item. 261 this item.
260 */ 262 */
261 void addItemPassword(const QString &key,QString *reference, 263 void addItemPassword(const QString &key,QString *reference,
262 const QString &defaultValue=""); 264 const QString &defaultValue="");
263 /** 265 /**
264 Register an item of type QStringList. 266 Register an item of type QStringList.
265 267
266 @param key Key used in config file. 268 @param key Key used in config file.
267 @param reference Pointer to the variable, which is set by readConfig() 269 @param reference Pointer to the variable, which is set by readConfig()
268 and setDefaults() calls and read by writeConfig() calls. 270 and setDefaults() calls and read by writeConfig() calls.
269 @param defaultValue Default value, which is used by setDefaults() and 271 @param defaultValue Default value, which is used by setDefaults() and
270 when the config file does not yet contain the key of 272 when the config file does not yet contain the key of
271 this item. 273 this item.
272 */ 274 */
273 void addItemStringList(const QString &key,QStringList *reference, 275 void addItemStringList(const QString &key,QStringList *reference,
274 const QStringList &defaultValue=QStringList()); 276 const QStringList &defaultValue=QStringList());
275 277
276 /** 278 /**
277 Register an item of type QValueList<int>. 279 Register an item of type QValueList<int>.
278 280
279 @param key Key used in config file. 281 @param key Key used in config file.
280 @param reference Pointer to the variable, which is set by readConfig() 282 @param reference Pointer to the variable, which is set by readConfig()
281 and setDefaults() calls and read by writeConfig() calls. 283 and setDefaults() calls and read by writeConfig() calls.
282 @param defaultValue Default value, which is used by setDefaults() and 284 @param defaultValue Default value, which is used by setDefaults() and
283 when the config file does not yet contain the key of 285 when the config file does not yet contain the key of
284 this item. 286 this item.
285 */ 287 */
286 void addItemIntList(const QString &key,QValueList<int> *reference, 288 void addItemIntList(const QString &key,Q3ValueList<int> *reference,
287 const QValueList<int> &defaultValue=QValueList<int>()); 289 const Q3ValueList<int> &defaultValue=Q3ValueList<int>());
288 290
289 protected: 291 protected:
290 /** 292 /**
291 Implemented by subclasses that use special defaults. 293 Implemented by subclasses that use special defaults.
292 */ 294 */
293 virtual void usrSetDefaults() {}; 295 virtual void usrSetDefaults() {};
294 /** 296 /**
295 Implemented by subclasses that read special config values. 297 Implemented by subclasses that read special config values.
296 */ 298 */
297 virtual void usrReadConfig() {}; 299 virtual void usrReadConfig() {};
298 /** 300 /**
299 Implemented by subclasses that write special config values. 301 Implemented by subclasses that write special config values.
300 */ 302 */
301 virtual void usrWriteConfig() {}; 303 virtual void usrWriteConfig() {};
302 304
303 /** 305 /**
304 Return the @ref KConfig object used for reading and writing the settings. 306 Return the @ref KConfig object used for reading and writing the settings.
305 */ 307 */
306 KConfig *config() const; 308 KConfig *config() const;
307 309
308 private: 310 private:
309 static QString *mCurrentGroup; 311 static QString *mCurrentGroup;
310 312
311 KConfig *mConfig; // pointer to KConfig object 313 KConfig *mConfig; // pointer to KConfig object
312 314
313 QPtrList<KPrefsItem> mItems; 315 Q3PtrList<KPrefsItem> mItems;
314}; 316};
315 317
316#endif 318#endif