• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

  • kdecore
kconfigskeleton.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (c) 2003 Waldo Bastian <bastian@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 #include <tqcolor.h>
23 #include <tqvariant.h>
24 
25 #include <kconfig.h>
26 #include <kstandarddirs.h>
27 #include <kglobal.h>
28 #include <kglobalsettings.h>
29 #include <kdebug.h>
30 
31 #include "kstringhandler.h"
32 
33 #include "kconfigskeleton.h"
34 
35 void KConfigSkeletonItem::readImmutability( KConfig *config )
36 {
37  mIsImmutable = config->entryIsImmutable( mKey );
38 }
39 
40 
41 KConfigSkeleton::ItemString::ItemString( const TQString &group, const TQString &key,
42  TQString &reference,
43  const TQString &defaultValue,
44  Type type )
45  : KConfigSkeletonGenericItem<TQString>( group, key, reference, defaultValue ),
46  mType( type )
47 {
48 }
49 
50 void KConfigSkeleton::ItemString::writeConfig( KConfig *config )
51 {
52  if ( mReference != mLoadedValue ) // WABA: Is this test needed?
53  {
54  config->setGroup( mGroup );
55  if ((mDefault == mReference) && !config->hasDefault( mKey))
56  config->revertToDefault( mKey );
57  else if ( mType == Path )
58  config->writePathEntry( mKey, mReference );
59  else if ( mType == Password )
60  config->writeEntry( mKey, KStringHandler::obscure( mReference ) );
61  else
62  config->writeEntry( mKey, mReference );
63  }
64 }
65 
66 
67 void KConfigSkeleton::ItemString::readConfig( KConfig *config )
68 {
69  config->setGroup( mGroup );
70 
71  if ( mType == Path )
72  {
73  mReference = config->readPathEntry( mKey, mDefault );
74  }
75  else if ( mType == Password )
76  {
77  TQString value = config->readEntry( mKey,
78  KStringHandler::obscure( mDefault ) );
79  mReference = KStringHandler::obscure( value );
80  }
81  else
82  {
83  mReference = config->readEntry( mKey, mDefault );
84  }
85 
86  mLoadedValue = mReference;
87 
88  readImmutability( config );
89 }
90 
91 void KConfigSkeleton::ItemString::setProperty(const TQVariant & p)
92 {
93  mReference = p.toString();
94 }
95 
96 TQVariant KConfigSkeleton::ItemString::property() const
97 {
98  return TQVariant(mReference);
99 }
100 
101 KConfigSkeleton::ItemPassword::ItemPassword( const TQString &group, const TQString &key,
102  TQString &reference,
103  const TQString &defaultValue)
104  : ItemString( group, key, reference, defaultValue, Password )
105 {
106 }
107 
108 KConfigSkeleton::ItemPath::ItemPath( const TQString &group, const TQString &key,
109  TQString &reference,
110  const TQString &defaultValue)
111  : ItemString( group, key, reference, defaultValue, Path )
112 {
113 }
114 
115 KConfigSkeleton::ItemProperty::ItemProperty( const TQString &group,
116  const TQString &key,
117  TQVariant &reference,
118  TQVariant defaultValue )
119  : KConfigSkeletonGenericItem<TQVariant>( group, key, reference, defaultValue )
120 {
121 }
122 
123 void KConfigSkeleton::ItemProperty::readConfig( KConfig *config )
124 {
125  config->setGroup( mGroup );
126  mReference = config->readPropertyEntry( mKey, mDefault );
127  mLoadedValue = mReference;
128 
129  readImmutability( config );
130 }
131 
132 void KConfigSkeleton::ItemProperty::setProperty(const TQVariant & p)
133 {
134  mReference = p;
135 }
136 
137 TQVariant KConfigSkeleton::ItemProperty::property() const
138 {
139  return mReference;
140 }
141 
142 KConfigSkeleton::ItemBool::ItemBool( const TQString &group, const TQString &key,
143  bool &reference, bool defaultValue )
144  : KConfigSkeletonGenericItem<bool>( group, key, reference, defaultValue )
145 {
146 }
147 
148 void KConfigSkeleton::ItemBool::readConfig( KConfig *config )
149 {
150  config->setGroup( mGroup );
151  mReference = config->readBoolEntry( mKey, mDefault );
152  mLoadedValue = mReference;
153 
154  readImmutability( config );
155 }
156 
157 void KConfigSkeleton::ItemBool::setProperty(const TQVariant & p)
158 {
159  mReference = p.toBool();
160 }
161 
162 TQVariant KConfigSkeleton::ItemBool::property() const
163 {
164  return TQVariant( mReference, 42 /* dummy */ );
165 }
166 
167 
168 KConfigSkeleton::ItemInt::ItemInt( const TQString &group, const TQString &key,
169  int &reference, int defaultValue )
170  : KConfigSkeletonGenericItem<int>( group, key, reference, defaultValue )
171  ,mHasMin(false), mHasMax(false)
172 {
173 }
174 
175 void KConfigSkeleton::ItemInt::readConfig( KConfig *config )
176 {
177  config->setGroup( mGroup );
178  mReference = config->readNumEntry( mKey, mDefault );
179  if (mHasMin)
180  mReference = QMAX(mReference, mMin);
181  if (mHasMax)
182  mReference = QMIN(mReference, mMax);
183  mLoadedValue = mReference;
184 
185  readImmutability( config );
186 }
187 
188 void KConfigSkeleton::ItemInt::setProperty(const TQVariant & p)
189 {
190  mReference = p.toInt();
191 }
192 
193 TQVariant KConfigSkeleton::ItemInt::property() const
194 {
195  return TQVariant(mReference);
196 }
197 
198 TQVariant KConfigSkeleton::ItemInt::minValue() const
199 {
200  if (mHasMin)
201  return TQVariant(mMin);
202  return TQVariant();
203 }
204 
205 TQVariant KConfigSkeleton::ItemInt::maxValue() const
206 {
207  if (mHasMax)
208  return TQVariant(mMax);
209  return TQVariant();
210 }
211 
212 void KConfigSkeleton::ItemInt::setMinValue(int v)
213 {
214  mHasMin = true;
215  mMin = v;
216 }
217 
218 void KConfigSkeleton::ItemInt::setMaxValue(int v)
219 {
220  mHasMax = true;
221  mMax = v;
222 }
223 
224 
225 KConfigSkeleton::ItemInt64::ItemInt64( const TQString &group, const TQString &key,
226  TQ_INT64 &reference, TQ_INT64 defaultValue )
227  : KConfigSkeletonGenericItem<TQ_INT64>( group, key, reference, defaultValue )
228  ,mHasMin(false), mHasMax(false)
229 {
230 }
231 
232 void KConfigSkeleton::ItemInt64::readConfig( KConfig *config )
233 {
234  config->setGroup( mGroup );
235  mReference = config->readNum64Entry( mKey, mDefault );
236  if (mHasMin)
237  mReference = QMAX(mReference, mMin);
238  if (mHasMax)
239  mReference = QMIN(mReference, mMax);
240  mLoadedValue = mReference;
241 
242  readImmutability( config );
243 }
244 
245 void KConfigSkeleton::ItemInt64::setProperty(const TQVariant & p)
246 {
247  mReference = p.toLongLong();
248 }
249 
250 TQVariant KConfigSkeleton::ItemInt64::property() const
251 {
252  return TQVariant(mReference);
253 }
254 
255 TQVariant KConfigSkeleton::ItemInt64::minValue() const
256 {
257  if (mHasMin)
258  return TQVariant(mMin);
259  return TQVariant();
260 }
261 
262 TQVariant KConfigSkeleton::ItemInt64::maxValue() const
263 {
264  if (mHasMax)
265  return TQVariant(mMax);
266  return TQVariant();
267 }
268 
269 void KConfigSkeleton::ItemInt64::setMinValue(TQ_INT64 v)
270 {
271  mHasMin = true;
272  mMin = v;
273 }
274 
275 void KConfigSkeleton::ItemInt64::setMaxValue(TQ_INT64 v)
276 {
277  mHasMax = true;
278  mMax = v;
279 }
280 
281 KConfigSkeleton::ItemEnum::ItemEnum( const TQString &group, const TQString &key,
282  int &reference,
283  const TQValueList<Choice> &choices,
284  int defaultValue )
285  : ItemInt( group, key, reference, defaultValue ), mChoices( choices )
286 {
287 }
288 
289 void KConfigSkeleton::ItemEnum::readConfig( KConfig *config )
290 {
291  config->setGroup( mGroup );
292  if (!config->hasKey(mKey))
293  {
294  mReference = mDefault;
295  }
296  else
297  {
298  int i = 0;
299  mReference = -1;
300  TQString tmp = config->readEntry( mKey ).lower();
301  for(TQValueList<Choice>::ConstIterator it = mChoices.begin();
302  it != mChoices.end(); ++it, ++i)
303  {
304  if ((*it).name.lower() == tmp)
305  {
306  mReference = i;
307  break;
308  }
309  }
310  if (mReference == -1)
311  mReference = config->readNumEntry( mKey, mDefault );
312  }
313  mLoadedValue = mReference;
314 
315  readImmutability( config );
316 }
317 
318 void KConfigSkeleton::ItemEnum::writeConfig( KConfig *config )
319 {
320  if ( mReference != mLoadedValue ) // WABA: Is this test needed?
321  {
322  config->setGroup( mGroup );
323  if ((mDefault == mReference) && !config->hasDefault( mKey))
324  config->revertToDefault( mKey );
325  else if ((mReference >= 0) && (mReference < (int) mChoices.count()))
326  config->writeEntry( mKey, mChoices[mReference].name );
327  else
328  config->writeEntry( mKey, mReference );
329  }
330 }
331 
332 TQValueList<KConfigSkeleton::ItemEnum::Choice> KConfigSkeleton::ItemEnum::choices() const
333 {
334  return mChoices;
335 }
336 
337 
338 KConfigSkeleton::ItemUInt::ItemUInt( const TQString &group, const TQString &key,
339  unsigned int &reference,
340  unsigned int defaultValue )
341  : KConfigSkeletonGenericItem<unsigned int>( group, key, reference, defaultValue )
342  ,mHasMin(false), mHasMax(false)
343 {
344 }
345 
346 void KConfigSkeleton::ItemUInt::readConfig( KConfig *config )
347 {
348  config->setGroup( mGroup );
349  mReference = config->readUnsignedNumEntry( mKey, mDefault );
350  if (mHasMin)
351  mReference = QMAX(mReference, mMin);
352  if (mHasMax)
353  mReference = QMIN(mReference, mMax);
354  mLoadedValue = mReference;
355 
356  readImmutability( config );
357 }
358 
359 void KConfigSkeleton::ItemUInt::setProperty(const TQVariant & p)
360 {
361  mReference = p.toUInt();
362 }
363 
364 TQVariant KConfigSkeleton::ItemUInt::property() const
365 {
366  return TQVariant(mReference);
367 }
368 
369 TQVariant KConfigSkeleton::ItemUInt::minValue() const
370 {
371  if (mHasMin)
372  return TQVariant(mMin);
373  return TQVariant();
374 }
375 
376 TQVariant KConfigSkeleton::ItemUInt::maxValue() const
377 {
378  if (mHasMax)
379  return TQVariant(mMax);
380  return TQVariant();
381 }
382 
383 void KConfigSkeleton::ItemUInt::setMinValue(unsigned int v)
384 {
385  mHasMin = true;
386  mMin = v;
387 }
388 
389 void KConfigSkeleton::ItemUInt::setMaxValue(unsigned int v)
390 {
391  mHasMax = true;
392  mMax = v;
393 }
394 
395 
396 KConfigSkeleton::ItemUInt64::ItemUInt64( const TQString &group, const TQString &key,
397  TQ_UINT64 &reference, TQ_UINT64 defaultValue )
398  : KConfigSkeletonGenericItem<TQ_UINT64>( group, key, reference, defaultValue )
399  ,mHasMin(false), mHasMax(false)
400 {
401 }
402 
403 void KConfigSkeleton::ItemUInt64::readConfig( KConfig *config )
404 {
405  config->setGroup( mGroup );
406  mReference = config->readUnsignedNum64Entry( mKey, mDefault );
407  if (mHasMin)
408  mReference = QMAX(mReference, mMin);
409  if (mHasMax)
410  mReference = QMIN(mReference, mMax);
411  mLoadedValue = mReference;
412 
413  readImmutability( config );
414 }
415 
416 void KConfigSkeleton::ItemUInt64::setProperty(const TQVariant & p)
417 {
418  mReference = p.toULongLong();
419 }
420 
421 TQVariant KConfigSkeleton::ItemUInt64::property() const
422 {
423  return TQVariant(mReference);
424 }
425 
426 TQVariant KConfigSkeleton::ItemUInt64::minValue() const
427 {
428  if (mHasMin)
429  return TQVariant(mMin);
430  return TQVariant();
431 }
432 
433 TQVariant KConfigSkeleton::ItemUInt64::maxValue() const
434 {
435  if (mHasMax)
436  return TQVariant(mMax);
437  return TQVariant();
438 }
439 
440 void KConfigSkeleton::ItemUInt64::setMinValue(TQ_UINT64 v)
441 {
442  mHasMin = true;
443  mMin = v;
444 }
445 
446 void KConfigSkeleton::ItemUInt64::setMaxValue(TQ_UINT64 v)
447 {
448  mHasMax = true;
449  mMax = v;
450 }
451 
452 KConfigSkeleton::ItemLong::ItemLong( const TQString &group, const TQString &key,
453  long &reference, long defaultValue )
454  : KConfigSkeletonGenericItem<long>( group, key, reference, defaultValue )
455  ,mHasMin(false), mHasMax(false)
456 {
457 }
458 
459 void KConfigSkeleton::ItemLong::readConfig( KConfig *config )
460 {
461  config->setGroup( mGroup );
462  mReference = config->readLongNumEntry( mKey, mDefault );
463  if (mHasMin)
464  mReference = QMAX(mReference, mMin);
465  if (mHasMax)
466  mReference = QMIN(mReference, mMax);
467  mLoadedValue = mReference;
468 
469  readImmutability( config );
470 }
471 
472 void KConfigSkeleton::ItemLong::setProperty(const TQVariant & p)
473 {
474  mReference = p.toLongLong();
475 }
476 
477 TQVariant KConfigSkeleton::ItemLong::property() const
478 {
479  return TQVariant((TQ_LLONG) mReference);
480 }
481 
482 TQVariant KConfigSkeleton::ItemLong::minValue() const
483 {
484  if (mHasMin)
485  return TQVariant((TQ_LLONG) mMin);
486  return TQVariant();
487 }
488 
489 TQVariant KConfigSkeleton::ItemLong::maxValue() const
490 {
491  if (mHasMax)
492  return TQVariant((TQ_LLONG) mMax);
493  return TQVariant();
494 }
495 
496 void KConfigSkeleton::ItemLong::setMinValue(long v)
497 {
498  mHasMin = true;
499  mMin = v;
500 }
501 
502 void KConfigSkeleton::ItemLong::setMaxValue(long v)
503 {
504  mHasMax = true;
505  mMax = v;
506 }
507 
508 
509 KConfigSkeleton::ItemULong::ItemULong( const TQString &group, const TQString &key,
510  unsigned long &reference,
511  unsigned long defaultValue )
512  : KConfigSkeletonGenericItem<unsigned long>( group, key, reference, defaultValue )
513  ,mHasMin(false), mHasMax(false)
514 {
515 }
516 
517 void KConfigSkeleton::ItemULong::readConfig( KConfig *config )
518 {
519  config->setGroup( mGroup );
520  mReference = config->readUnsignedLongNumEntry( mKey, mDefault );
521  if (mHasMin)
522  mReference = QMAX(mReference, mMin);
523  if (mHasMax)
524  mReference = QMIN(mReference, mMax);
525  mLoadedValue = mReference;
526 
527  readImmutability( config );
528 }
529 
530 void KConfigSkeleton::ItemULong::setProperty(const TQVariant & p)
531 {
532  mReference = p.toULongLong();
533 }
534 
535 TQVariant KConfigSkeleton::ItemULong::property() const
536 {
537  return TQVariant((TQ_ULLONG) mReference);
538 }
539 
540 TQVariant KConfigSkeleton::ItemULong::minValue() const
541 {
542  if (mHasMin)
543  return TQVariant((TQ_ULLONG) mMin);
544  return TQVariant();
545 }
546 
547 TQVariant KConfigSkeleton::ItemULong::maxValue() const
548 {
549  if (mHasMax)
550  return TQVariant((TQ_ULLONG) mMax);
551  return TQVariant();
552 }
553 
554 void KConfigSkeleton::ItemULong::setMinValue(unsigned long v)
555 {
556  mHasMin = true;
557  mMin = v;
558 }
559 
560 void KConfigSkeleton::ItemULong::setMaxValue(unsigned long v)
561 {
562  mHasMax = true;
563  mMax = v;
564 }
565 
566 
567 KConfigSkeleton::ItemDouble::ItemDouble( const TQString &group, const TQString &key,
568  double &reference, double defaultValue )
569  : KConfigSkeletonGenericItem<double>( group, key, reference, defaultValue )
570  ,mHasMin(false), mHasMax(false)
571 {
572 }
573 
574 void KConfigSkeleton::ItemDouble::readConfig( KConfig *config )
575 {
576  config->setGroup( mGroup );
577  mReference = config->readDoubleNumEntry( mKey, mDefault );
578  if (mHasMin)
579  mReference = QMAX(mReference, mMin);
580  if (mHasMax)
581  mReference = QMIN(mReference, mMax);
582  mLoadedValue = mReference;
583 
584  readImmutability( config );
585 }
586 
587 void KConfigSkeleton::ItemDouble::setProperty(const TQVariant & p)
588 {
589  mReference = p.toDouble();
590 }
591 
592 TQVariant KConfigSkeleton::ItemDouble::property() const
593 {
594  return TQVariant(mReference);
595 }
596 
597 TQVariant KConfigSkeleton::ItemDouble::minValue() const
598 {
599  if (mHasMin)
600  return TQVariant(mMin);
601  return TQVariant();
602 }
603 
604 TQVariant KConfigSkeleton::ItemDouble::maxValue() const
605 {
606  if (mHasMax)
607  return TQVariant(mMax);
608  return TQVariant();
609 }
610 
611 void KConfigSkeleton::ItemDouble::setMinValue(double v)
612 {
613  mHasMin = true;
614  mMin = v;
615 }
616 
617 void KConfigSkeleton::ItemDouble::setMaxValue(double v)
618 {
619  mHasMax = true;
620  mMax = v;
621 }
622 
623 
624 KConfigSkeleton::ItemColor::ItemColor( const TQString &group, const TQString &key,
625  TQColor &reference,
626  const TQColor &defaultValue )
627  : KConfigSkeletonGenericItem<TQColor>( group, key, reference, defaultValue )
628 {
629 }
630 
631 void KConfigSkeleton::ItemColor::readConfig( KConfig *config )
632 {
633  config->setGroup( mGroup );
634  mReference = config->readColorEntry( mKey, &mDefault );
635  mLoadedValue = mReference;
636 
637  readImmutability( config );
638 }
639 
640 void KConfigSkeleton::ItemColor::setProperty(const TQVariant & p)
641 {
642  mReference = p.toColor();
643 }
644 
645 TQVariant KConfigSkeleton::ItemColor::property() const
646 {
647  return TQVariant(mReference);
648 }
649 
650 
651 KConfigSkeleton::ItemFont::ItemFont( const TQString &group, const TQString &key,
652  TQFont &reference,
653  const TQFont &defaultValue )
654  : KConfigSkeletonGenericItem<TQFont>( group, key, reference, defaultValue )
655 {
656 }
657 
658 void KConfigSkeleton::ItemFont::readConfig( KConfig *config )
659 {
660  config->setGroup( mGroup );
661  mReference = config->readFontEntry( mKey, &mDefault );
662  mLoadedValue = mReference;
663 
664  readImmutability( config );
665 }
666 
667 void KConfigSkeleton::ItemFont::setProperty(const TQVariant & p)
668 {
669  mReference = p.toFont();
670 }
671 
672 TQVariant KConfigSkeleton::ItemFont::property() const
673 {
674  return TQVariant(mReference);
675 }
676 
677 
678 KConfigSkeleton::ItemRect::ItemRect( const TQString &group, const TQString &key,
679  TQRect &reference,
680  const TQRect &defaultValue )
681  : KConfigSkeletonGenericItem<TQRect>( group, key, reference, defaultValue )
682 {
683 }
684 
685 void KConfigSkeleton::ItemRect::readConfig( KConfig *config )
686 {
687  config->setGroup( mGroup );
688  mReference = config->readRectEntry( mKey, &mDefault );
689  mLoadedValue = mReference;
690 
691  readImmutability( config );
692 }
693 
694 void KConfigSkeleton::ItemRect::setProperty(const TQVariant & p)
695 {
696  mReference = p.toRect();
697 }
698 
699 TQVariant KConfigSkeleton::ItemRect::property() const
700 {
701  return TQVariant(mReference);
702 }
703 
704 
705 KConfigSkeleton::ItemPoint::ItemPoint( const TQString &group, const TQString &key,
706  TQPoint &reference,
707  const TQPoint &defaultValue )
708  : KConfigSkeletonGenericItem<TQPoint>( group, key, reference, defaultValue )
709 {
710 }
711 
712 void KConfigSkeleton::ItemPoint::readConfig( KConfig *config )
713 {
714  config->setGroup( mGroup );
715  mReference = config->readPointEntry( mKey, &mDefault );
716  mLoadedValue = mReference;
717 
718  readImmutability( config );
719 }
720 
721 void KConfigSkeleton::ItemPoint::setProperty(const TQVariant & p)
722 {
723  mReference = p.toPoint();
724 }
725 
726 TQVariant KConfigSkeleton::ItemPoint::property() const
727 {
728  return TQVariant(mReference);
729 }
730 
731 
732 KConfigSkeleton::ItemSize::ItemSize( const TQString &group, const TQString &key,
733  TQSize &reference,
734  const TQSize &defaultValue )
735  : KConfigSkeletonGenericItem<TQSize>( group, key, reference, defaultValue )
736 {
737 }
738 
739 void KConfigSkeleton::ItemSize::readConfig( KConfig *config )
740 {
741  config->setGroup( mGroup );
742  mReference = config->readSizeEntry( mKey, &mDefault );
743  mLoadedValue = mReference;
744 
745  readImmutability( config );
746 }
747 
748 void KConfigSkeleton::ItemSize::setProperty(const TQVariant & p)
749 {
750  mReference = p.toSize();
751 }
752 
753 TQVariant KConfigSkeleton::ItemSize::property() const
754 {
755  return TQVariant(mReference);
756 }
757 
758 
759 KConfigSkeleton::ItemDateTime::ItemDateTime( const TQString &group, const TQString &key,
760  TQDateTime &reference,
761  const TQDateTime &defaultValue )
762  : KConfigSkeletonGenericItem<TQDateTime>( group, key, reference, defaultValue )
763 {
764 }
765 
766 void KConfigSkeleton::ItemDateTime::readConfig( KConfig *config )
767 {
768  config->setGroup( mGroup );
769  mReference = config->readDateTimeEntry( mKey, &mDefault );
770  mLoadedValue = mReference;
771 
772  readImmutability( config );
773 }
774 
775 void KConfigSkeleton::ItemDateTime::setProperty(const TQVariant & p)
776 {
777  mReference = p.toDateTime();
778 }
779 
780 TQVariant KConfigSkeleton::ItemDateTime::property() const
781 {
782  return TQVariant(mReference);
783 }
784 
785 
786 KConfigSkeleton::ItemStringList::ItemStringList( const TQString &group, const TQString &key,
787  TQStringList &reference,
788  const TQStringList &defaultValue )
789  : KConfigSkeletonGenericItem<TQStringList>( group, key, reference, defaultValue )
790 {
791 }
792 
793 void KConfigSkeleton::ItemStringList::readConfig( KConfig *config )
794 {
795  config->setGroup( mGroup );
796  if ( !config->hasKey( mKey ) )
797  mReference = mDefault;
798  else
799  mReference = config->readListEntry( mKey );
800  mLoadedValue = mReference;
801 
802  readImmutability( config );
803 }
804 
805 void KConfigSkeleton::ItemStringList::setProperty(const TQVariant & p)
806 {
807  mReference = p.toStringList();
808 }
809 
810 TQVariant KConfigSkeleton::ItemStringList::property() const
811 {
812  return TQVariant(mReference);
813 }
814 
815 
816 KConfigSkeleton::ItemPathList::ItemPathList( const TQString &group, const TQString &key,
817  TQStringList &reference,
818  const TQStringList &defaultValue )
819  : ItemStringList( group, key, reference, defaultValue )
820 {
821 }
822 
823 void KConfigSkeleton::ItemPathList::readConfig( KConfig *config )
824 {
825  config->setGroup( mGroup );
826  if ( !config->hasKey( mKey ) )
827  mReference = mDefault;
828  else
829  mReference = config->readPathListEntry( mKey );
830  mLoadedValue = mReference;
831 
832  readImmutability( config );
833 }
834 
835 void KConfigSkeleton::ItemPathList::writeConfig( KConfig *config )
836 {
837  if ( mReference != mLoadedValue ) // WABA: Is this test needed?
838  {
839  config->setGroup( mGroup );
840  if ((mDefault == mReference) && !config->hasDefault( mKey))
841  config->revertToDefault( mKey );
842  else {
843  TQStringList sl = mReference;
844  config->writePathEntry( mKey, sl );
845  }
846  }
847 }
848 
849 
850 KConfigSkeleton::ItemIntList::ItemIntList( const TQString &group, const TQString &key,
851  TQValueList<int> &reference,
852  const TQValueList<int> &defaultValue )
853  : KConfigSkeletonGenericItem<TQValueList<int> >( group, key, reference, defaultValue )
854 {
855 }
856 
857 void KConfigSkeleton::ItemIntList::readConfig( KConfig *config )
858 {
859  config->setGroup( mGroup );
860  if ( !config->hasKey( mKey ) )
861  mReference = mDefault;
862  else
863  mReference = config->readIntListEntry( mKey );
864  mLoadedValue = mReference;
865 
866  readImmutability( config );
867 }
868 
869 void KConfigSkeleton::ItemIntList::setProperty(const TQVariant &)
870 {
871  // TODO: Not yet supported
872 }
873 
874 TQVariant KConfigSkeleton::ItemIntList::property() const
875 {
876  // TODO: Not yet supported
877  return TQVariant();
878 }
879 
880 
881 KConfigSkeleton::KConfigSkeleton( const TQString &configname )
882  : mCurrentGroup( "No Group" ), mUseDefaults(false)
883 {
884  kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
885 
886  if ( !configname.isEmpty() )
887  {
888  mConfig = KSharedConfig::openConfig( configname );
889  }
890  else
891  {
892  mConfig = KGlobal::sharedConfig();
893  }
894 }
895 
896 KConfigSkeleton::KConfigSkeleton(KSharedConfig::Ptr config)
897  : mCurrentGroup( "No Group" ), mUseDefaults(false)
898 {
899  kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
900  mConfig = config;
901 }
902 
903 
904 KConfigSkeleton::~KConfigSkeleton()
905 {
906  KConfigSkeletonItem::List::ConstIterator it;
907  for( it = mItems.begin(); it != mItems.end(); ++it )
908  {
909  delete *it;
910  }
911 }
912 
913 void KConfigSkeleton::setCurrentGroup( const TQString &group )
914 {
915  mCurrentGroup = group;
916 }
917 
918 KConfig *KConfigSkeleton::config() const
919 {
920  return mConfig;
921 }
922 
923 bool KConfigSkeleton::useDefaults(bool b)
924 {
925  if (b == mUseDefaults)
926  return mUseDefaults;
927 
928  mUseDefaults = b;
929  KConfigSkeletonItem::List::ConstIterator it;
930  for( it = mItems.begin(); it != mItems.end(); ++it )
931  {
932  (*it)->swapDefault();
933  }
934 
935  usrUseDefaults(b);
936  return !mUseDefaults;
937 }
938 
939 void KConfigSkeleton::setDefaults()
940 {
941  KConfigSkeletonItem::List::ConstIterator it;
942  for( it = mItems.begin(); it != mItems.end(); ++it ) {
943  (*it)->setDefault();
944  }
945 
946  usrSetDefaults();
947 }
948 
949 void KConfigSkeleton::readConfig()
950 {
951  kdDebug(177) << "KConfigSkeleton::readConfig()" << endl;
952 
953  TQString origGroup = mConfig->group();
954 
955  mConfig->reparseConfiguration();
956  KConfigSkeletonItem::List::ConstIterator it;
957  for( it = mItems.begin(); it != mItems.end(); ++it )
958  {
959  (*it)->readConfig( mConfig );
960  }
961 
962  usrReadConfig();
963 
964  mConfig->setGroup(origGroup);
965 }
966 
967 void KConfigSkeleton::writeConfig()
968 {
969  kdDebug(177) << "KConfigSkeleton::writeConfig()" << endl;
970 
971  TQString origGroup = mConfig->group();
972 
973  KConfigSkeletonItem::List::ConstIterator it;
974  for( it = mItems.begin(); it != mItems.end(); ++it )
975  {
976  (*it)->writeConfig( mConfig );
977  }
978 
979  usrWriteConfig();
980 
981  mConfig->sync();
982 
983  readConfig();
984 
985  mConfig->setGroup(origGroup);
986 }
987 
988 void KConfigSkeleton::addItem( KConfigSkeletonItem *item, const TQString &name )
989 {
990  item->setName( name.isEmpty() ? item->key() : name );
991  mItems.append( item );
992  mItemDict.insert( item->name(), item );
993  item->readDefault( mConfig );
994  item->readConfig( mConfig );
995 }
996 
997 KConfigSkeleton::ItemString *KConfigSkeleton::addItemString( const TQString &name, TQString &reference,
998  const TQString &defaultValue, const TQString &key )
999 {
1000  KConfigSkeleton::ItemString *item;
1001  item = new KConfigSkeleton::ItemString( mCurrentGroup, key.isEmpty() ? name : key,
1002  reference, defaultValue,
1003  KConfigSkeleton::ItemString::Normal );
1004  addItem( item, name );
1005  return item;
1006 }
1007 
1008 KConfigSkeleton::ItemPassword *KConfigSkeleton::addItemPassword( const TQString &name, TQString &reference,
1009  const TQString &defaultValue, const TQString &key )
1010 {
1011  KConfigSkeleton::ItemPassword *item;
1012  item = new KConfigSkeleton::ItemPassword( mCurrentGroup, key.isNull() ? name : key,
1013  reference, defaultValue );
1014  addItem( item, name );
1015  return item;
1016 }
1017 
1018 KConfigSkeleton::ItemPath *KConfigSkeleton::addItemPath( const TQString &name, TQString &reference,
1019  const TQString &defaultValue, const TQString &key )
1020 {
1021  KConfigSkeleton::ItemPath *item;
1022  item = new KConfigSkeleton::ItemPath( mCurrentGroup, key.isNull() ? name : key,
1023  reference, defaultValue );
1024  addItem( item, name );
1025  return item;
1026 }
1027 
1028 KConfigSkeleton::ItemProperty *KConfigSkeleton::addItemProperty( const TQString &name, TQVariant &reference,
1029  const TQVariant &defaultValue, const TQString &key )
1030 {
1031  KConfigSkeleton::ItemProperty *item;
1032  item = new KConfigSkeleton::ItemProperty( mCurrentGroup, key.isNull() ? name : key,
1033  reference, defaultValue );
1034  addItem( item, name );
1035  return item;
1036 }
1037 
1038 KConfigSkeleton::ItemBool *KConfigSkeleton::addItemBool( const TQString &name, bool &reference,
1039  bool defaultValue, const TQString &key )
1040 {
1041  KConfigSkeleton::ItemBool *item;
1042  item = new KConfigSkeleton::ItemBool( mCurrentGroup, key.isNull() ? name : key,
1043  reference, defaultValue );
1044  addItem( item, name );
1045  return item;
1046 }
1047 
1048 KConfigSkeleton::ItemInt *KConfigSkeleton::addItemInt( const TQString &name, int &reference,
1049  int defaultValue, const TQString &key )
1050 {
1051  KConfigSkeleton::ItemInt *item;
1052  item = new KConfigSkeleton::ItemInt( mCurrentGroup, key.isNull() ? name : key,
1053  reference, defaultValue );
1054  addItem( item, name );
1055  return item;
1056 }
1057 
1058 KConfigSkeleton::ItemUInt *KConfigSkeleton::addItemUInt( const TQString &name, unsigned int &reference,
1059  unsigned int defaultValue, const TQString &key )
1060 {
1061  KConfigSkeleton::ItemUInt *item;
1062  item = new KConfigSkeleton::ItemUInt( mCurrentGroup, key.isNull() ? name : key,
1063  reference, defaultValue );
1064  addItem( item, name );
1065  return item;
1066 }
1067 
1068 KConfigSkeleton::ItemInt64 *KConfigSkeleton::addItemInt64( const TQString &name, TQ_INT64 &reference,
1069  TQ_INT64 defaultValue, const TQString &key )
1070 {
1071  KConfigSkeleton::ItemInt64 *item;
1072  item = new KConfigSkeleton::ItemInt64( mCurrentGroup, key.isNull() ? name : key,
1073  reference, defaultValue );
1074  addItem( item, name );
1075  return item;
1076 }
1077 
1078 KConfigSkeleton::ItemUInt64 *KConfigSkeleton::addItemUInt64( const TQString &name, TQ_UINT64 &reference,
1079  TQ_UINT64 defaultValue, const TQString &key )
1080 {
1081  KConfigSkeleton::ItemUInt64 *item;
1082  item = new KConfigSkeleton::ItemUInt64( mCurrentGroup, key.isNull() ? name : key,
1083  reference, defaultValue );
1084  addItem( item, name );
1085  return item;
1086 }
1087 
1088 KConfigSkeleton::ItemLong *KConfigSkeleton::addItemLong( const TQString &name, long &reference,
1089  long defaultValue, const TQString &key )
1090 {
1091  KConfigSkeleton::ItemLong *item;
1092  item = new KConfigSkeleton::ItemLong( mCurrentGroup, key.isNull() ? name : key,
1093  reference, defaultValue );
1094  addItem( item, name );
1095  return item;
1096 }
1097 
1098 KConfigSkeleton::ItemULong *KConfigSkeleton::addItemULong( const TQString &name, unsigned long &reference,
1099  unsigned long defaultValue, const TQString &key )
1100 {
1101  KConfigSkeleton::ItemULong *item;
1102  item = new KConfigSkeleton::ItemULong( mCurrentGroup, key.isNull() ? name : key,
1103  reference, defaultValue );
1104  addItem( item, name );
1105  return item;
1106 }
1107 
1108 KConfigSkeleton::ItemDouble *KConfigSkeleton::addItemDouble( const TQString &name, double &reference,
1109  double defaultValue, const TQString &key )
1110 {
1111  KConfigSkeleton::ItemDouble *item;
1112  item = new KConfigSkeleton::ItemDouble( mCurrentGroup, key.isNull() ? name : key,
1113  reference, defaultValue );
1114  addItem( item, name );
1115  return item;
1116 }
1117 
1118 KConfigSkeleton::ItemColor *KConfigSkeleton::addItemColor( const TQString &name, TQColor &reference,
1119  const TQColor &defaultValue, const TQString &key )
1120 {
1121  KConfigSkeleton::ItemColor *item;
1122  item = new KConfigSkeleton::ItemColor( mCurrentGroup, key.isNull() ? name : key,
1123  reference, defaultValue );
1124  addItem( item, name );
1125  return item;
1126 }
1127 
1128 KConfigSkeleton::ItemFont *KConfigSkeleton::addItemFont( const TQString &name, TQFont &reference,
1129  const TQFont &defaultValue, const TQString &key )
1130 {
1131  KConfigSkeleton::ItemFont *item;
1132  item = new KConfigSkeleton::ItemFont( mCurrentGroup, key.isNull() ? name : key,
1133  reference, defaultValue );
1134  addItem( item, name );
1135  return item;
1136 }
1137 
1138 KConfigSkeleton::ItemRect *KConfigSkeleton::addItemRect( const TQString &name, TQRect &reference,
1139  const TQRect &defaultValue, const TQString &key )
1140 {
1141  KConfigSkeleton::ItemRect *item;
1142  item = new KConfigSkeleton::ItemRect( mCurrentGroup, key.isNull() ? name : key,
1143  reference, defaultValue );
1144  addItem( item, name );
1145  return item;
1146 }
1147 
1148 KConfigSkeleton::ItemPoint *KConfigSkeleton::addItemPoint( const TQString &name, TQPoint &reference,
1149  const TQPoint &defaultValue, const TQString &key )
1150 {
1151  KConfigSkeleton::ItemPoint *item;
1152  item = new KConfigSkeleton::ItemPoint( mCurrentGroup, key.isNull() ? name : key,
1153  reference, defaultValue );
1154  addItem( item, name );
1155  return item;
1156 }
1157 
1158 KConfigSkeleton::ItemSize *KConfigSkeleton::addItemSize( const TQString &name, TQSize &reference,
1159  const TQSize &defaultValue, const TQString &key )
1160 {
1161  KConfigSkeleton::ItemSize *item;
1162  item = new KConfigSkeleton::ItemSize( mCurrentGroup, key.isNull() ? name : key,
1163  reference, defaultValue );
1164  addItem( item, name );
1165  return item;
1166 }
1167 
1168 KConfigSkeleton::ItemDateTime *KConfigSkeleton::addItemDateTime( const TQString &name, TQDateTime &reference,
1169  const TQDateTime &defaultValue, const TQString &key )
1170 {
1171  KConfigSkeleton::ItemDateTime *item;
1172  item = new KConfigSkeleton::ItemDateTime( mCurrentGroup, key.isNull() ? name : key,
1173  reference, defaultValue );
1174  addItem( item, name );
1175  return item;
1176 }
1177 
1178 KConfigSkeleton::ItemStringList *KConfigSkeleton::addItemStringList( const TQString &name, TQStringList &reference,
1179  const TQStringList &defaultValue, const TQString &key )
1180 {
1181  KConfigSkeleton::ItemStringList *item;
1182  item = new KConfigSkeleton::ItemStringList( mCurrentGroup, key.isNull() ? name : key,
1183  reference, defaultValue );
1184  addItem( item, name );
1185  return item;
1186 }
1187 
1188 KConfigSkeleton::ItemIntList *KConfigSkeleton::addItemIntList( const TQString &name, TQValueList<int> &reference,
1189  const TQValueList<int> &defaultValue, const TQString &key )
1190 {
1191  KConfigSkeleton::ItemIntList *item;
1192  item = new KConfigSkeleton::ItemIntList( mCurrentGroup, key.isNull() ? name : key,
1193  reference, defaultValue );
1194  addItem( item, name );
1195  return item;
1196 }
1197 
1198 bool KConfigSkeleton::isImmutable(const TQString &name)
1199 {
1200  KConfigSkeletonItem *item = findItem(name);
1201  return !item || item->isImmutable();
1202 }
1203 
1204 KConfigSkeletonItem *KConfigSkeleton::findItem(const TQString &name)
1205 {
1206  return mItemDict.find(name);
1207 }

kdecore

Skip menu "kdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |