-rw-r--r-- | microkde/kdecore/kprefs.cpp | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/microkde/kdecore/kprefs.cpp b/microkde/kdecore/kprefs.cpp index f5e5e5a..71050e7 100644 --- a/microkde/kdecore/kprefs.cpp +++ b/microkde/kdecore/kprefs.cpp | |||
@@ -52,48 +52,63 @@ class KPrefsItemInt : public KPrefsItem { | |||
52 | void readConfig(KConfig *); | 52 | void readConfig(KConfig *); |
53 | void writeConfig(KConfig *); | 53 | void writeConfig(KConfig *); |
54 | 54 | ||
55 | private: | 55 | private: |
56 | int *mReference; | 56 | int *mReference; |
57 | int mDefault; | 57 | int mDefault; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
61 | class KPrefsItemColor : public KPrefsItem { | 61 | class KPrefsItemColor : public KPrefsItem { |
62 | public: | 62 | public: |
63 | KPrefsItemColor(const QString &group,const QString &name,QColor *, | 63 | KPrefsItemColor(const QString &group,const QString &name,QColor *, |
64 | const QColor &defaultValue=QColor(128,128,128)); | 64 | const QColor &defaultValue=QColor(128,128,128)); |
65 | virtual ~KPrefsItemColor() {} | 65 | virtual ~KPrefsItemColor() {} |
66 | 66 | ||
67 | void setDefault(); | 67 | void setDefault(); |
68 | void readConfig(KConfig *); | 68 | void readConfig(KConfig *); |
69 | void writeConfig(KConfig *); | 69 | void writeConfig(KConfig *); |
70 | 70 | ||
71 | private: | 71 | private: |
72 | QColor *mReference; | 72 | QColor *mReference; |
73 | QColor mDefault; | 73 | QColor mDefault; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | class KPrefsItemSize : public KPrefsItem { | ||
77 | public: | ||
78 | KPrefsItemSize(const QString &group,const QString &name,QSize *, | ||
79 | const QSize &defaultValue=QSize()); | ||
80 | ~KPrefsItemSize() {} | ||
81 | |||
82 | void setDefault(); | ||
83 | void readConfig(KConfig *); | ||
84 | void writeConfig(KConfig *); | ||
85 | |||
86 | private: | ||
87 | QSize *mReference; | ||
88 | QSize mDefault; | ||
89 | }; | ||
90 | |||
76 | 91 | ||
77 | class KPrefsItemFont : public KPrefsItem { | 92 | class KPrefsItemFont : public KPrefsItem { |
78 | public: | 93 | public: |
79 | KPrefsItemFont(const QString &group,const QString &name,QFont *, | 94 | KPrefsItemFont(const QString &group,const QString &name,QFont *, |
80 | const QFont &defaultValue=QFont("helvetica",12)); | 95 | const QFont &defaultValue=QFont("helvetica",12)); |
81 | virtual ~KPrefsItemFont() {} | 96 | virtual ~KPrefsItemFont() {} |
82 | 97 | ||
83 | void setDefault(); | 98 | void setDefault(); |
84 | void readConfig(KConfig *); | 99 | void readConfig(KConfig *); |
85 | void writeConfig(KConfig *); | 100 | void writeConfig(KConfig *); |
86 | 101 | ||
87 | private: | 102 | private: |
88 | QFont *mReference; | 103 | QFont *mReference; |
89 | QFont mDefault; | 104 | QFont mDefault; |
90 | }; | 105 | }; |
91 | 106 | ||
92 | 107 | ||
93 | class KPrefsItemString : public KPrefsItem { | 108 | class KPrefsItemString : public KPrefsItem { |
94 | public: | 109 | public: |
95 | KPrefsItemString(const QString &group,const QString &name,QString *, | 110 | KPrefsItemString(const QString &group,const QString &name,QString *, |
96 | const QString &defaultValue="", bool isPassword=false); | 111 | const QString &defaultValue="", bool isPassword=false); |
97 | virtual ~KPrefsItemString() {} | 112 | virtual ~KPrefsItemString() {} |
98 | 113 | ||
99 | void setDefault(); | 114 | void setDefault(); |
@@ -198,48 +213,75 @@ KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name, | |||
198 | { | 213 | { |
199 | mReference = reference; | 214 | mReference = reference; |
200 | mDefault = defaultValue; | 215 | mDefault = defaultValue; |
201 | } | 216 | } |
202 | 217 | ||
203 | void KPrefsItemColor::setDefault() | 218 | void KPrefsItemColor::setDefault() |
204 | { | 219 | { |
205 | *mReference = mDefault; | 220 | *mReference = mDefault; |
206 | } | 221 | } |
207 | 222 | ||
208 | void KPrefsItemColor::writeConfig(KConfig *config) | 223 | void KPrefsItemColor::writeConfig(KConfig *config) |
209 | { | 224 | { |
210 | config->setGroup(mGroup); | 225 | config->setGroup(mGroup); |
211 | config->writeEntry(mName,*mReference); | 226 | config->writeEntry(mName,*mReference); |
212 | } | 227 | } |
213 | 228 | ||
214 | void KPrefsItemColor::readConfig(KConfig *config) | 229 | void KPrefsItemColor::readConfig(KConfig *config) |
215 | { | 230 | { |
216 | config->setGroup(mGroup); | 231 | config->setGroup(mGroup); |
217 | *mReference = config->readColorEntry(mName,&mDefault); | 232 | *mReference = config->readColorEntry(mName,&mDefault); |
218 | 233 | ||
219 | } | 234 | } |
220 | 235 | ||
221 | 236 | ||
237 | KPrefsItemSize::KPrefsItemSize(const QString &group,const QString &name, | ||
238 | QSize *reference,const QSize &defaultValue) : | ||
239 | KPrefsItem(group,name) | ||
240 | { | ||
241 | mReference = reference; | ||
242 | mDefault = defaultValue; | ||
243 | } | ||
244 | |||
245 | void KPrefsItemSize::setDefault() | ||
246 | { | ||
247 | *mReference = mDefault; | ||
248 | } | ||
249 | |||
250 | void KPrefsItemSize::writeConfig(KConfig *config) | ||
251 | { | ||
252 | config->setGroup(mGroup); | ||
253 | config->writeEntry(mName,*mReference); | ||
254 | } | ||
255 | |||
256 | void KPrefsItemSize::readConfig(KConfig *config) | ||
257 | { | ||
258 | config->setGroup(mGroup); | ||
259 | *mReference = config->readSizeEntry(mName,&mDefault); | ||
260 | |||
261 | } | ||
262 | |||
263 | |||
222 | KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name, | 264 | KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name, |
223 | QFont *reference,const QFont &defaultValue) : | 265 | QFont *reference,const QFont &defaultValue) : |
224 | KPrefsItem(group,name) | 266 | KPrefsItem(group,name) |
225 | { | 267 | { |
226 | mReference = reference; | 268 | mReference = reference; |
227 | mDefault = defaultValue; | 269 | mDefault = defaultValue; |
228 | } | 270 | } |
229 | 271 | ||
230 | void KPrefsItemFont::setDefault() | 272 | void KPrefsItemFont::setDefault() |
231 | { | 273 | { |
232 | *mReference = mDefault; | 274 | *mReference = mDefault; |
233 | } | 275 | } |
234 | 276 | ||
235 | void KPrefsItemFont::writeConfig(KConfig *config) | 277 | void KPrefsItemFont::writeConfig(KConfig *config) |
236 | { | 278 | { |
237 | config->setGroup(mGroup); | 279 | config->setGroup(mGroup); |
238 | config->writeEntry(mName,*mReference); | 280 | config->writeEntry(mName,*mReference); |
239 | } | 281 | } |
240 | 282 | ||
241 | void KPrefsItemFont::readConfig(KConfig *config) | 283 | void KPrefsItemFont::readConfig(KConfig *config) |
242 | { | 284 | { |
243 | config->setGroup(mGroup); | 285 | config->setGroup(mGroup); |
244 | *mReference = config->readFontEntry(mName,&mDefault); | 286 | *mReference = config->readFontEntry(mName,&mDefault); |
245 | } | 287 | } |
@@ -379,85 +421,91 @@ void KPrefs::setCurrentGroup(const QString &group) | |||
379 | 421 | ||
380 | KConfig *KPrefs::config() const | 422 | KConfig *KPrefs::config() const |
381 | { | 423 | { |
382 | return mConfig; | 424 | return mConfig; |
383 | } | 425 | } |
384 | 426 | ||
385 | void KPrefs::setDefaults() | 427 | void KPrefs::setDefaults() |
386 | { | 428 | { |
387 | KPrefsItem *item; | 429 | KPrefsItem *item; |
388 | for(item = mItems.first();item;item = mItems.next()) { | 430 | for(item = mItems.first();item;item = mItems.next()) { |
389 | item->setDefault(); | 431 | item->setDefault(); |
390 | } | 432 | } |
391 | 433 | ||
392 | usrSetDefaults(); | 434 | usrSetDefaults(); |
393 | } | 435 | } |
394 | 436 | ||
395 | void KPrefs::readConfig() | 437 | void KPrefs::readConfig() |
396 | { | 438 | { |
397 | KPrefsItem *item; | 439 | KPrefsItem *item; |
398 | for(item = mItems.first();item;item = mItems.next()) { | 440 | for(item = mItems.first();item;item = mItems.next()) { |
399 | item->readConfig(mConfig); | 441 | item->readConfig(mConfig); |
400 | } | 442 | } |
401 | 443 | ||
402 | usrReadConfig(); | 444 | usrReadConfig(); |
445 | //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1()); | ||
403 | } | 446 | } |
404 | 447 | ||
405 | void KPrefs::writeConfig() | 448 | void KPrefs::writeConfig() |
406 | { | 449 | { |
407 | KPrefsItem *item; | 450 | KPrefsItem *item; |
408 | for(item = mItems.first();item;item = mItems.next()) { | 451 | for(item = mItems.first();item;item = mItems.next()) { |
409 | item->writeConfig(mConfig); | 452 | item->writeConfig(mConfig); |
410 | } | 453 | } |
411 | 454 | ||
412 | usrWriteConfig(); | 455 | usrWriteConfig(); |
413 | 456 | //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1()); | |
414 | mConfig->sync(); | 457 | mConfig->sync(); |
415 | } | 458 | } |
416 | 459 | ||
417 | 460 | ||
418 | void KPrefs::addItem(KPrefsItem *item) | 461 | void KPrefs::addItem(KPrefsItem *item) |
419 | { | 462 | { |
420 | mItems.append(item); | 463 | mItems.append(item); |
421 | } | 464 | } |
422 | 465 | ||
423 | void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) | 466 | void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) |
424 | { | 467 | { |
425 | addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); | 468 | addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); |
426 | } | 469 | } |
427 | 470 | ||
428 | void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) | 471 | void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) |
429 | { | 472 | { |
430 | addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue)); | 473 | addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue)); |
431 | } | 474 | } |
432 | 475 | ||
433 | void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) | 476 | void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) |
434 | { | 477 | { |
435 | addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); | 478 | addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); |
436 | } | 479 | } |
437 | 480 | ||
438 | void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) | 481 | void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) |
439 | { | 482 | { |
440 | addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); | 483 | addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); |
441 | } | 484 | } |
442 | 485 | ||
486 | void KPrefs::addItemSize(const QString &key,QSize *reference,const QSize &defaultValue) | ||
487 | { | ||
488 | addItem(new KPrefsItemSize(*mCurrentGroup,key,reference,defaultValue)); | ||
489 | } | ||
490 | |||
443 | void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) | 491 | void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) |
444 | { | 492 | { |
445 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); | 493 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); |
446 | } | 494 | } |
447 | 495 | ||
448 | void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) | 496 | void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) |
449 | { | 497 | { |
450 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); | 498 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); |
451 | } | 499 | } |
452 | 500 | ||
453 | void KPrefs::addItemStringList(const QString &key,QStringList *reference, | 501 | void KPrefs::addItemStringList(const QString &key,QStringList *reference, |
454 | const QStringList &defaultValue) | 502 | const QStringList &defaultValue) |
455 | { | 503 | { |
456 | addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue)); | 504 | addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue)); |
457 | } | 505 | } |
458 | 506 | ||
459 | void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference, | 507 | void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference, |
460 | const QValueList<int> &defaultValue) | 508 | const QValueList<int> &defaultValue) |
461 | { | 509 | { |
462 | addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue)); | 510 | addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue)); |
463 | } | 511 | } |