KConfig

kcoreconfigskeleton.cpp
1 /*
2  This file is part of KOrganizer.
3  SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <[email protected]>
4  SPDX-FileCopyrightText: 2003 Waldo Bastian <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "kcoreconfigskeleton.h"
10 #include "kcoreconfigskeleton_p.h"
11 
12 #include <QUrl>
13 
14 #include <algorithm>
15 
16 static QString obscuredString(const QString &str)
17 {
18  QString result;
19  const QChar *unicode = str.unicode();
20  for (int i = 0; i < str.length(); ++i)
21  // yes, no typo. can't encode ' ' or '!' because
22  // they're the unicode BOM. stupid scrambling. stupid.
23  result += (unicode[i].unicode() <= 0x21) ? unicode[i] : QChar(0x1001F - unicode[i].unicode());
24 
25  return result;
26 }
27 
28 KConfigSkeletonItemPrivate::~KConfigSkeletonItemPrivate() = default;
29 
31  : mGroup(_group)
32  , mKey(_key)
33  , d_ptr(new KConfigSkeletonItemPrivate)
34 {
35 }
36 
37 KConfigSkeletonItem::KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key)
38  : mGroup(_group)
39  , mKey(_key)
40  , d_ptr(&dd)
41 {
42 }
43 
45 {
46  delete d_ptr;
47 }
48 
50 {
51  mGroup = _group;
52 }
53 
55 {
57  d->mConfigGroup = cg;
58 }
59 
61 {
62  Q_D(const KConfigSkeletonItem);
63  if (d->mConfigGroup.isValid()) {
64  return d->mConfigGroup;
65  }
66  return KConfigGroup(config, mGroup);
67 }
68 
70 {
71  return mGroup;
72 }
73 
75 {
76  mKey = _key;
77 }
78 
80 {
81  return mKey;
82 }
83 
85 {
86  mName = _name;
87 }
88 
90 {
91  return mName;
92 }
93 
95 {
97  d->mLabel = l;
98 }
99 
101 {
102  Q_D(const KConfigSkeletonItem);
103  return d->mLabel;
104 }
105 
107 {
108  Q_D(KConfigSkeletonItem);
109  d->mToolTip = t;
110 }
111 
113 {
114  Q_D(const KConfigSkeletonItem);
115  return d->mToolTip;
116 }
117 
119 {
120  Q_D(KConfigSkeletonItem);
121  d->mWhatsThis = w;
122 }
123 
125 {
126  Q_D(const KConfigSkeletonItem);
127  return d->mWhatsThis;
128 }
129 
131 {
132  Q_D(KConfigSkeletonItem);
133  d->mWriteFlags = flags;
134 }
135 
137 {
138  Q_D(const KConfigSkeletonItem);
139  return d->mWriteFlags;
140 }
141 
143 {
144  return QVariant();
145 }
146 
148 {
149  return QVariant();
150 }
151 
153 {
154  Q_D(const KConfigSkeletonItem);
155  return d->mIsImmutable;
156 }
157 
159 {
160  Q_D(const KConfigSkeletonItem);
161  return d->mIsDefaultImpl();
162 }
163 
165 {
166  Q_D(const KConfigSkeletonItem);
167  return d->mIsSaveNeededImpl();
168 }
169 
171 {
172  Q_D(const KConfigSkeletonItem);
173  return d->mGetDefaultImpl();
174 }
175 
177 {
178  Q_D(KConfigSkeletonItem);
179  d->mIsImmutable = group.isEntryImmutable(mKey);
180 }
181 
182 void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool()> &impl)
183 {
184  Q_D(KConfigSkeletonItem);
185  d->mIsDefaultImpl = impl;
186 }
187 
188 void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool()> &impl)
189 {
190  Q_D(KConfigSkeletonItem);
191  d->mIsSaveNeededImpl = impl;
192 }
193 
194 void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant()> &impl)
195 {
196  Q_D(KConfigSkeletonItem);
197  d->mGetDefaultImpl = impl;
198 }
199 
200 KPropertySkeletonItem::KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
201  : KConfigSkeletonItem(*new KPropertySkeletonItemPrivate(object, propertyName, defaultValue), {}, {})
202 {
203  setIsDefaultImpl([this] {
204  Q_D(const KPropertySkeletonItem);
205  return d->mReference == d->mDefaultValue;
206  });
207  setIsSaveNeededImpl([this] {
208  Q_D(const KPropertySkeletonItem);
209  return d->mReference != d->mLoadedValue;
210  });
211  setGetDefaultImpl([this] {
212  Q_D(const KPropertySkeletonItem);
213  return d->mDefaultValue;
214  });
215 }
216 
218 {
219  Q_D(const KPropertySkeletonItem);
220  return d->mReference;
221 }
222 
224 {
226  if (d->mReference == p) {
227  return;
228  }
229  d->mReference = p;
230  if (d->mNotifyFunction) {
231  d->mNotifyFunction();
232  }
233 }
234 
236 {
237  Q_D(const KPropertySkeletonItem);
238  return d->mReference == p;
239 }
240 
242 {
244  setProperty(d->mObject->property(d->mPropertyName.constData()));
245  d->mLoadedValue = d->mReference;
246 }
247 
249 {
251  d->mObject->setProperty(d->mPropertyName.constData(), d->mReference);
252  d->mLoadedValue = d->mReference;
253 }
254 
256 {
258  setProperty(d->mConstDefaultValue);
259 }
260 
262 {
264  setProperty(d->mDefaultValue);
265 }
266 
268 {
270  if (d->mReference == d->mDefaultValue) {
271  return;
272  }
273  std::swap(d->mReference, d->mDefaultValue);
274  if (d->mNotifyFunction) {
275  d->mNotifyFunction();
276  }
277 }
278 
279 void KPropertySkeletonItem::setNotifyFunction(const std::function<void()> &impl)
280 {
282  d->mNotifyFunction = impl;
283 }
284 
285 KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue, Type type)
286  : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue)
287  , mType(type)
288 {
289 }
290 
292 {
293  if (mReference != mLoadedValue) { // WABA: Is this test needed?
294  KConfigGroup cg = configGroup(config);
295  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
297  } else if (mType == Path) {
298  cg.writePathEntry(mKey, mReference, writeFlags());
299  } else if (mType == Password) {
300  cg.writeEntry(mKey, obscuredString(mReference), writeFlags());
301  } else {
302  cg.writeEntry(mKey, mReference, writeFlags());
303  }
304  mLoadedValue = mReference;
305  }
306 }
307 
309 {
310  KConfigGroup cg = configGroup(config);
311 
312  if (mType == Path) {
313  mReference = cg.readPathEntry(mKey, mDefault);
314  } else if (mType == Password) {
315  QString val = cg.readEntry(mKey, obscuredString(mDefault));
316  mReference = obscuredString(val);
317  } else {
318  mReference = cg.readEntry(mKey, mDefault);
319  }
320 
321  mLoadedValue = mReference;
322 
323  readImmutability(cg);
324 }
325 
327 {
328  mReference = p.toString();
329 }
330 
332 {
333  return mReference == v.toString();
334 }
335 
337 {
338  return QVariant(mReference);
339 }
340 
341 KCoreConfigSkeleton::ItemPassword::ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
342  : ItemString(_group, _key, reference, defaultValue, Password)
343 {
344 }
345 
346 KCoreConfigSkeleton::ItemPath::ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
347  : ItemString(_group, _key, reference, defaultValue, Path)
348 {
349 }
350 
351 KCoreConfigSkeleton::ItemUrl::ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue)
352  : KConfigSkeletonGenericItem<QUrl>(_group, _key, reference, defaultValue)
353 {
354 }
355 
357 {
358  if (mReference != mLoadedValue) { // WABA: Is this test needed?
359  KConfigGroup cg = configGroup(config);
360  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
362  } else {
363  cg.writeEntry<QString>(mKey, mReference.toString(), writeFlags());
364  }
365  mLoadedValue = mReference;
366  }
367 }
368 
370 {
371  KConfigGroup cg = configGroup(config);
372 
373  mReference = QUrl(cg.readEntry<QString>(mKey, mDefault.toString()));
374  mLoadedValue = mReference;
375 
376  readImmutability(cg);
377 }
378 
380 {
381  mReference = qvariant_cast<QUrl>(p);
382 }
383 
385 {
386  return mReference == qvariant_cast<QUrl>(v);
387 }
388 
390 {
391  return QVariant::fromValue<QUrl>(mReference);
392 }
393 
394 KCoreConfigSkeleton::ItemProperty::ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue)
395  : KConfigSkeletonGenericItem<QVariant>(_group, _key, reference, defaultValue)
396 {
397 }
398 
400 {
401  KConfigGroup cg = configGroup(config);
402  mReference = cg.readEntry(mKey, mDefault);
403  mLoadedValue = mReference;
404 
405  readImmutability(cg);
406 }
407 
409 {
410  mReference = p;
411 }
412 
414 {
415  // this might cause problems if the QVariants are not of default types
416  return mReference == v;
417 }
418 
420 {
421  return mReference;
422 }
423 
424 KCoreConfigSkeleton::ItemBool::ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue)
425  : KConfigSkeletonGenericItem<bool>(_group, _key, reference, defaultValue)
426 {
427 }
428 
430 {
431  KConfigGroup cg = configGroup(config);
432  mReference = cg.readEntry(mKey, mDefault);
433  mLoadedValue = mReference;
434 
435  readImmutability(cg);
436 }
437 
439 {
440  mReference = p.toBool();
441 }
442 
444 {
445  return mReference == v.toBool();
446 }
447 
449 {
450  return QVariant(mReference);
451 }
452 
453 KCoreConfigSkeleton::ItemInt::ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue)
454  : KConfigSkeletonGenericItem<qint32>(_group, _key, reference, defaultValue)
455  , mHasMin(false)
456  , mHasMax(false)
457 {
458 }
459 
461 {
462  KConfigGroup cg = configGroup(config);
463  mReference = cg.readEntry(mKey, mDefault);
464  if (mHasMin) {
465  mReference = qMax(mReference, mMin);
466  }
467  if (mHasMax) {
468  mReference = qMin(mReference, mMax);
469  }
470  mLoadedValue = mReference;
471 
472  readImmutability(cg);
473 }
474 
476 {
477  mReference = p.toInt();
478 }
479 
481 {
482  return mReference == v.toInt();
483 }
484 
486 {
487  return QVariant(mReference);
488 }
489 
491 {
492  if (mHasMin) {
493  return QVariant(mMin);
494  }
495  return QVariant();
496 }
497 
499 {
500  if (mHasMax) {
501  return QVariant(mMax);
502  }
503  return QVariant();
504 }
505 
507 {
508  mHasMin = true;
509  mMin = v;
510 }
511 
513 {
514  mHasMax = true;
515  mMax = v;
516 }
517 
518 KCoreConfigSkeleton::ItemLongLong::ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue)
519  : KConfigSkeletonGenericItem<qint64>(_group, _key, reference, defaultValue)
520  , mHasMin(false)
521  , mHasMax(false)
522 {
523 }
524 
526 {
527  KConfigGroup cg = configGroup(config);
528  mReference = cg.readEntry(mKey, mDefault);
529  if (mHasMin) {
530  mReference = qMax(mReference, mMin);
531  }
532  if (mHasMax) {
533  mReference = qMin(mReference, mMax);
534  }
535  mLoadedValue = mReference;
536 
537  readImmutability(cg);
538 }
539 
541 {
542  mReference = p.toLongLong();
543 }
544 
546 {
547  return mReference == v.toLongLong();
548 }
549 
551 {
552  return QVariant(mReference);
553 }
554 
556 {
557  if (mHasMin) {
558  return QVariant(mMin);
559  }
560  return QVariant();
561 }
562 
564 {
565  if (mHasMax) {
566  return QVariant(mMax);
567  }
568  return QVariant();
569 }
570 
572 {
573  mHasMin = true;
574  mMin = v;
575 }
576 
578 {
579  mHasMax = true;
580  mMax = v;
581 }
582 
584 {
585  // HACK for BC concerns
586  // TODO KF6: remove KConfigSkeletonItemPrivate::mValues and add a value field to KCoreConfigSkeleton::ItemEnum::Choice
587  const auto inHash = d_ptr->mValues.value(name);
588  return !inHash.isEmpty() ? inHash : name;
589 }
590 
592 {
593  d_ptr->mValues.insert(name, value);
594 }
595 
596 KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue)
597  : ItemInt(_group, _key, reference, defaultValue)
598  , mChoices(choices)
599 {
600 }
601 
603 {
604  KConfigGroup cg = configGroup(config);
605  if (!cg.hasKey(mKey)) {
606  mReference = mDefault;
607  } else {
608  int i = 0;
609  mReference = -1;
610  QString tmp = cg.readEntry(mKey, QString()).toLower();
611  for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {
612  QString choiceName = (*it).name;
613  if (valueForChoice(choiceName).toLower() == tmp) {
614  mReference = i;
615  break;
616  }
617  }
618  if (mReference == -1) {
619  mReference = cg.readEntry(mKey, mDefault);
620  }
621  }
622  mLoadedValue = mReference;
623 
624  readImmutability(cg);
625 }
626 
628 {
629  if (mReference != mLoadedValue) { // WABA: Is this test needed?
630  KConfigGroup cg = configGroup(config);
631  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
633  } else if ((mReference >= 0) && (mReference < mChoices.count())) {
634  cg.writeEntry(mKey, valueForChoice(mChoices.at(mReference).name), writeFlags());
635  } else {
636  cg.writeEntry(mKey, mReference, writeFlags());
637  }
638  mLoadedValue = mReference;
639  }
640 }
641 
642 QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choices() const
643 {
644  return mChoices;
645 }
646 
647 QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choices2() const
648 {
649  return mChoices;
650 }
651 
652 KCoreConfigSkeleton::ItemUInt::ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue)
653  : KConfigSkeletonGenericItem<quint32>(_group, _key, reference, defaultValue)
654  , mHasMin(false)
655  , mHasMax(false)
656 {
657 }
658 
660 {
661  KConfigGroup cg = configGroup(config);
662  mReference = cg.readEntry(mKey, mDefault);
663  if (mHasMin) {
664  mReference = qMax(mReference, mMin);
665  }
666  if (mHasMax) {
667  mReference = qMin(mReference, mMax);
668  }
669  mLoadedValue = mReference;
670 
671  readImmutability(cg);
672 }
673 
675 {
676  mReference = p.toUInt();
677 }
678 
680 {
681  return mReference == v.toUInt();
682 }
683 
685 {
686  return QVariant(mReference);
687 }
688 
690 {
691  if (mHasMin) {
692  return QVariant(mMin);
693  }
694  return QVariant();
695 }
696 
698 {
699  if (mHasMax) {
700  return QVariant(mMax);
701  }
702  return QVariant();
703 }
704 
706 {
707  mHasMin = true;
708  mMin = v;
709 }
710 
712 {
713  mHasMax = true;
714  mMax = v;
715 }
716 
717 KCoreConfigSkeleton::ItemULongLong::ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue)
718  : KConfigSkeletonGenericItem<quint64>(_group, _key, reference, defaultValue)
719  , mHasMin(false)
720  , mHasMax(false)
721 {
722 }
723 
725 {
726  KConfigGroup cg = configGroup(config);
727  mReference = cg.readEntry(mKey, mDefault);
728  if (mHasMin) {
729  mReference = qMax(mReference, mMin);
730  }
731  if (mHasMax) {
732  mReference = qMin(mReference, mMax);
733  }
734  mLoadedValue = mReference;
735 
736  readImmutability(cg);
737 }
738 
740 {
741  mReference = p.toULongLong();
742 }
743 
745 {
746  return mReference == v.toULongLong();
747 }
748 
750 {
751  return QVariant(mReference);
752 }
753 
755 {
756  if (mHasMin) {
757  return QVariant(mMin);
758  }
759  return QVariant();
760 }
761 
763 {
764  if (mHasMax) {
765  return QVariant(mMax);
766  }
767  return QVariant();
768 }
769 
771 {
772  mHasMin = true;
773  mMin = v;
774 }
775 
777 {
778  mHasMax = true;
779  mMax = v;
780 }
781 
782 KCoreConfigSkeleton::ItemDouble::ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue)
783  : KConfigSkeletonGenericItem<double>(_group, _key, reference, defaultValue)
784  , mHasMin(false)
785  , mHasMax(false)
786 {
787 }
788 
790 {
791  KConfigGroup cg = configGroup(config);
792  mReference = cg.readEntry(mKey, mDefault);
793  if (mHasMin) {
794  mReference = qMax(mReference, mMin);
795  }
796  if (mHasMax) {
797  mReference = qMin(mReference, mMax);
798  }
799  mLoadedValue = mReference;
800 
801  readImmutability(cg);
802 }
803 
805 {
806  mReference = p.toDouble();
807 }
808 
810 {
811  return mReference == v.toDouble();
812 }
813 
815 {
816  return QVariant(mReference);
817 }
818 
820 {
821  if (mHasMin) {
822  return QVariant(mMin);
823  }
824  return QVariant();
825 }
826 
828 {
829  if (mHasMax) {
830  return QVariant(mMax);
831  }
832  return QVariant();
833 }
834 
836 {
837  mHasMin = true;
838  mMin = v;
839 }
840 
842 {
843  mHasMax = true;
844  mMax = v;
845 }
846 
847 KCoreConfigSkeleton::ItemRect::ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue)
848  : KConfigSkeletonGenericItem<QRect>(_group, _key, reference, defaultValue)
849 {
850 }
851 
853 {
854  KConfigGroup cg = configGroup(config);
855  mReference = cg.readEntry(mKey, mDefault);
856  mLoadedValue = mReference;
857 
858  readImmutability(cg);
859 }
860 
862 {
863  mReference = p.toRect();
864 }
865 
867 {
868  return mReference == v.toRect();
869 }
870 
872 {
873  return QVariant(mReference);
874 }
875 
876 KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue)
877  : KConfigSkeletonGenericItem<QPoint>(_group, _key, reference, defaultValue)
878 {
879 }
880 
882 {
883  KConfigGroup cg = configGroup(config);
884  mReference = cg.readEntry(mKey, mDefault);
885  mLoadedValue = mReference;
886 
887  readImmutability(cg);
888 }
889 
891 {
892  mReference = p.toPoint();
893 }
894 
896 {
897  return mReference == v.toPoint();
898 }
899 
901 {
902  return QVariant(mReference);
903 }
904 
905 KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue)
906  : KConfigSkeletonGenericItem<QSize>(_group, _key, reference, defaultValue)
907 {
908 }
909 
911 {
912  KConfigGroup cg = configGroup(config);
913  mReference = cg.readEntry(mKey, mDefault);
914  mLoadedValue = mReference;
915 
916  readImmutability(cg);
917 }
918 
920 {
921  mReference = p.toSize();
922 }
923 
925 {
926  return mReference == v.toSize();
927 }
928 
930 {
931  return QVariant(mReference);
932 }
933 
934 KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue)
935  : KConfigSkeletonGenericItem<QDateTime>(_group, _key, reference, defaultValue)
936 {
937 }
938 
940 {
941  KConfigGroup cg = configGroup(config);
942  mReference = cg.readEntry(mKey, mDefault);
943  mLoadedValue = mReference;
944 
945  readImmutability(cg);
946 }
947 
949 {
950  mReference = p.toDateTime();
951 }
952 
954 {
955  return mReference == v.toDateTime();
956 }
957 
959 {
960  return QVariant(mReference);
961 }
962 
963 KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
964  : KConfigSkeletonGenericItem<QStringList>(_group, _key, reference, defaultValue)
965 {
966 }
967 
969 {
970  KConfigGroup cg = configGroup(config);
971  if (!cg.hasKey(mKey)) {
972  mReference = mDefault;
973  } else {
974  mReference = cg.readEntry(mKey, mDefault);
975  }
976  mLoadedValue = mReference;
977 
978  readImmutability(cg);
979 }
980 
982 {
983  mReference = p.toStringList();
984 }
985 
987 {
988  return mReference == v.toStringList();
989 }
990 
992 {
993  return QVariant(mReference);
994 }
995 
996 KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
997  : ItemStringList(_group, _key, reference, defaultValue)
998 {
999 }
1000 
1002 {
1003  KConfigGroup cg = configGroup(config);
1004  if (!cg.hasKey(mKey)) {
1005  mReference = mDefault;
1006  } else {
1007  mReference = cg.readPathEntry(mKey, QStringList());
1008  }
1009  mLoadedValue = mReference;
1010 
1011  readImmutability(cg);
1012 }
1013 
1015 {
1016  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1017  KConfigGroup cg = configGroup(config);
1018  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1020  } else {
1021  QStringList sl = mReference;
1022  cg.writePathEntry(mKey, sl, writeFlags());
1023  }
1024  mLoadedValue = mReference;
1025  }
1026 }
1027 
1028 KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue)
1029  : KConfigSkeletonGenericItem<QList<QUrl>>(_group, _key, reference, defaultValue)
1030 {
1031 }
1032 
1034 {
1035  KConfigGroup cg = configGroup(config);
1036  if (!cg.hasKey(mKey)) {
1037  mReference = mDefault;
1038  } else {
1039  QStringList strList;
1040  for (const QUrl &url : qAsConst(mDefault)) {
1041  strList.append(url.toString());
1042  }
1043  mReference.clear();
1044  const QStringList readList = cg.readEntry<QStringList>(mKey, strList);
1045  for (const QString &str : readList) {
1046  mReference.append(QUrl(str));
1047  }
1048  }
1049  mLoadedValue = mReference;
1050 
1051  readImmutability(cg);
1052 }
1053 
1055 {
1056  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1057  KConfigGroup cg = configGroup(config);
1058  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1060  } else {
1061  QStringList strList;
1062  for (const QUrl &url : qAsConst(mReference)) {
1063  strList.append(url.toString());
1064  }
1065  cg.writeEntry<QStringList>(mKey, strList, writeFlags());
1066  }
1067  mLoadedValue = mReference;
1068  }
1069 }
1070 
1072 {
1073  mReference = qvariant_cast<QList<QUrl>>(p);
1074 }
1075 
1077 {
1078  return mReference == qvariant_cast<QList<QUrl>>(v);
1079 }
1080 
1082 {
1083  return QVariant::fromValue<QList<QUrl>>(mReference);
1084 }
1085 
1086 KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue)
1087  : KConfigSkeletonGenericItem<QList<int>>(_group, _key, reference, defaultValue)
1088 {
1089 }
1090 
1092 {
1093  KConfigGroup cg = configGroup(config);
1094  if (!cg.hasKey(mKey)) {
1095  mReference = mDefault;
1096  } else {
1097  mReference = cg.readEntry(mKey, mDefault);
1098  }
1099  mLoadedValue = mReference;
1100 
1101  readImmutability(cg);
1102 }
1103 
1105 {
1106  mReference = qvariant_cast<QList<int>>(p);
1107 }
1108 
1110 {
1111  return mReference == qvariant_cast<QList<int>>(v);
1112 }
1113 
1115 {
1116  return QVariant::fromValue<QList<int>>(mReference);
1117 }
1118 
1119 // static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; }
1120 
1122  : QObject(parent)
1123  , d(new KCoreConfigSkeletonPrivate)
1124 {
1125  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1126 
1127  d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig);
1128 }
1129 
1131  : QObject(parent)
1132  , d(new KCoreConfigSkeletonPrivate)
1133 {
1134  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1135  d->mConfig = std::move(pConfig);
1136 }
1137 
1139 {
1140  delete d;
1141 }
1142 
1144 {
1145  d->mCurrentGroup = group;
1146 }
1147 
1149 {
1150  return d->mCurrentGroup;
1151 }
1152 
1154 {
1155  return d->mConfig.data();
1156 }
1157 
1159 {
1160  return d->mConfig.data();
1161 }
1162 
1164 {
1165  return d->mConfig;
1166 }
1167 
1169 {
1170  d->mConfig = std::move(pConfig);
1171 }
1172 
1174 {
1175  return d->mItems;
1176 }
1177 
1179 {
1180  if (b == d->mUseDefaults) {
1181  return d->mUseDefaults;
1182  }
1183 
1184  d->mUseDefaults = b;
1185  for (auto *skelItem : qAsConst(d->mItems)) {
1186  skelItem->swapDefault();
1187  }
1188 
1189  usrUseDefaults(b);
1190  return !d->mUseDefaults;
1191 }
1192 
1194 {
1195  for (auto *skelItem : qAsConst(d->mItems)) {
1196  skelItem->setDefault();
1197  }
1198  usrSetDefaults();
1199 }
1200 
1202 {
1203  d->mConfig->reparseConfiguration();
1204  read();
1205 }
1206 
1208 {
1209  for (auto *skelItem : qAsConst(d->mItems)) {
1210  skelItem->readConfig(d->mConfig.data());
1211  }
1212  usrRead();
1213 }
1214 
1216 {
1217  return std::all_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1218  return skelItem->isDefault();
1219  });
1220 }
1221 
1223 {
1224  return std::any_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1225  return skelItem->isSaveNeeded();
1226  });
1227 }
1228 
1230 {
1231  // qDebug();
1232  for (auto *skelItem : qAsConst(d->mItems)) {
1233  skelItem->writeConfig(d->mConfig.data());
1234  }
1235 
1236  if (!usrSave()) {
1237  return false;
1238  }
1239 
1240  if (d->mConfig->isDirty()) {
1241  if (!d->mConfig->sync()) {
1242  return false;
1243  }
1245  }
1246  return true;
1247 }
1248 
1250 {
1251  return false;
1252 }
1253 
1255 {
1256 }
1257 
1259 {
1260 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1261  usrReadConfig();
1262 #endif
1263 }
1264 
1265 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1267 {
1268 }
1269 #endif
1270 
1272 {
1273 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1274  return usrWriteConfig();
1275 #else
1276  return true;
1277 #endif
1278 }
1279 
1280 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1282 {
1283  return true;
1284 }
1285 #endif
1286 
1288 {
1289  if (d->mItems.contains(item)) {
1290  if (item->name() == name || (name.isEmpty() && item->name() == item->key())) {
1291  // nothing to do -> it is already in our collection
1292  // and the name isn't changing
1293  return;
1294  }
1295 
1296  d->mItemDict.remove(item->name());
1297  } else {
1298  d->mItems.append(item);
1299  }
1300 
1301  item->setName(name.isEmpty() ? item->key() : name);
1302  d->mItemDict.insert(item->name(), item);
1303  item->readDefault(d->mConfig.data());
1304  item->readConfig(d->mConfig.data());
1305 }
1306 
1308 {
1309  KConfigSkeletonItem *item = d->mItemDict.value(name);
1310  if (item) {
1311  d->mItems.removeAll(item);
1312  d->mItemDict.remove(item->name());
1313  delete item;
1314  }
1315 }
1316 
1318 {
1319  KConfigSkeletonItem::List items = d->mItems;
1320  d->mItems.clear();
1321  d->mItemDict.clear();
1322  qDeleteAll(items);
1323 }
1324 
1325 KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1326 {
1328  item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, reference, defaultValue, KCoreConfigSkeleton::ItemString::Normal);
1329  addItem(item, name);
1330  return item;
1331 }
1332 
1334 KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1335 {
1337  item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1338  addItem(item, name);
1339  return item;
1340 }
1341 
1342 KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1343 {
1345  item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1346  addItem(item, name);
1347  return item;
1348 }
1349 
1351 KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key)
1352 {
1354  item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1355  addItem(item, name);
1356  return item;
1357 }
1358 
1359 KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, bool defaultValue, const QString &key)
1360 {
1362  item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1363  addItem(item, name);
1364  return item;
1365 }
1366 
1367 KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, qint32 defaultValue, const QString &key)
1368 {
1370  item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1371  addItem(item, name);
1372  return item;
1373 }
1374 
1375 KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue, const QString &key)
1376 {
1378  item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1379  addItem(item, name);
1380  return item;
1381 }
1382 
1383 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1384 {
1386  item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1387  addItem(item, name);
1388  return item;
1389 }
1390 
1391 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1392 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1393 {
1394  return addItemLongLong(name, reference, defaultValue, key);
1395 }
1396 #endif
1397 
1398 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1399 {
1401  item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1402  addItem(item, name);
1403  return item;
1404 }
1405 
1406 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1407 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1408 {
1409  return addItemULongLong(name, reference, defaultValue, key);
1410 }
1411 #endif
1412 
1413 KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, double defaultValue, const QString &key)
1414 {
1416  item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1417  addItem(item, name);
1418  return item;
1419 }
1420 
1421 KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, const QRect &defaultValue, const QString &key)
1422 {
1424  item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1425  addItem(item, name);
1426  return item;
1427 }
1428 
1429 KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue, const QString &key)
1430 {
1432  item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1433  addItem(item, name);
1434  return item;
1435 }
1436 
1437 KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, const QSize &defaultValue, const QString &key)
1438 {
1440  item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1441  addItem(item, name);
1442  return item;
1443 }
1444 
1446 KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key)
1447 {
1449  item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1450  addItem(item, name);
1451  return item;
1452 }
1453 
1455 KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key)
1456 {
1458  item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1459  addItem(item, name);
1460  return item;
1461 }
1462 
1464 KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key)
1465 {
1467  item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1468  addItem(item, name);
1469  return item;
1470 }
1471 
1473 {
1474  KConfigSkeletonItem *item = findItem(name);
1475  return !item || item->isImmutable();
1476 }
1477 
1479 {
1480  return d->mItemDict.value(name);
1481 }
1482 
1483 KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem *item,
1484  QObject *object,
1485  KConfigCompilerSignallingItem::NotifyFunction targetFunction,
1486  quint64 userData)
1487  : KConfigSkeletonItem(item->group(), item->key())
1488  , mItem(item)
1489  , mTargetFunction(targetFunction)
1490  , mObject(object)
1491  , mUserData(userData)
1492 {
1493  Q_ASSERT(mTargetFunction);
1494  Q_ASSERT(mItem);
1495  Q_ASSERT(mObject);
1496 
1497  setIsDefaultImpl([this] {
1498  return mItem->isDefault();
1499  });
1500  setIsSaveNeededImpl([this] {
1501  return mItem->isSaveNeeded();
1502  });
1503  setGetDefaultImpl([this] {
1504  return mItem->getDefault();
1505  });
1506 }
1507 
1508 KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem()
1509 {
1510 }
1511 
1512 bool KConfigCompilerSignallingItem::isEqual(const QVariant &p) const
1513 {
1514  return mItem->isEqual(p);
1515 }
1516 
1517 QVariant KConfigCompilerSignallingItem::property() const
1518 {
1519  return mItem->property();
1520 }
1521 
1522 void KConfigCompilerSignallingItem::readConfig(KConfig *c)
1523 {
1524  QVariant oldValue = mItem->property();
1525  mItem->readConfig(c);
1526  // readConfig() changes mIsImmutable, update it here as well
1527  KConfigGroup cg = configGroup(c);
1528  readImmutability(cg);
1529  if (!mItem->isEqual(oldValue)) {
1530  invokeNotifyFunction();
1531  }
1532 }
1533 
1534 void KConfigCompilerSignallingItem::readDefault(KConfig *c)
1535 {
1536  mItem->readDefault(c);
1537  // readDefault() changes mIsImmutable, update it here as well
1538  KConfigGroup cg = configGroup(c);
1539  readImmutability(cg);
1540 }
1541 
1542 void KConfigCompilerSignallingItem::writeConfig(KConfig *c)
1543 {
1544  mItem->writeConfig(c);
1545 }
1546 
1547 void KConfigCompilerSignallingItem::setDefault()
1548 {
1549  QVariant oldValue = mItem->property();
1550  mItem->setDefault();
1551  if (!mItem->isEqual(oldValue)) {
1552  invokeNotifyFunction();
1553  }
1554 }
1555 
1556 void KConfigCompilerSignallingItem::setProperty(const QVariant &p)
1557 {
1558  if (!mItem->isEqual(p)) {
1559  mItem->setProperty(p);
1560  invokeNotifyFunction();
1561  }
1562 }
1563 
1564 void KConfigCompilerSignallingItem::swapDefault()
1565 {
1566  QVariant oldValue = mItem->property();
1567  mItem->swapDefault();
1568  if (!mItem->isEqual(oldValue)) {
1569  invokeNotifyFunction();
1570  }
1571 }
1572 
1573 void KConfigCompilerSignallingItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
1574 {
1575  mItem->setWriteFlags(flags);
1576 }
1577 
1578 KConfigBase::WriteConfigFlags KConfigCompilerSignallingItem::writeFlags() const
1579 {
1580  return mItem->writeFlags();
1581 }
1582 
1583 void KConfigCompilerSignallingItem::setGroup(const KConfigGroup &cg)
1584 {
1585  mItem->setGroup(cg);
1586 }
1587 
1588 KConfigGroup KConfigCompilerSignallingItem::configGroup(KConfig *config) const
1589 {
1590  return mItem->configGroup(config);
1591 }
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
void setProperty(const QVariant &p) override
Set item to p.
Class for handling unsigned 64-bit integer preferences item.
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
qlonglong toLongLong(bool *ok) const const
QString readPathEntry(const QString &pKey, const QString &aDefault) const
Reads a path.
KConfig * config()
Return the KConfig object used for reading and writing the settings.
ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue=0)
Class for proxying a QObject property as a preferences setting.
ItemSize * addItemSize(const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString())
Register an item of type QSize.
void setDefault() override
Sets the current value to the default value.
virtual bool usrSave()
Perform the actual writing of the configuration file.
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
Writes a file path to the configuration.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
Class for handling a floating point preference item.
Class for handling a string preferences item.
QString group() const
Return config file group.
void setProperty(const QVariant &p) override
Set item to p.
void read()
Read preferences from the KConfig object.
void setMaxValue(quint32)
Set the maximum value for the item.
QVariant property() const override
Return item as property.
virtual void readDefault(KConfig *)=0
Read global default value.
QVariant property() const override
Return item as property.
bool hasDefault(const QString &key) const
Whether a default is specified for an entry in either the system wide configuration file or the globa...
QDateTime toDateTime() const const
ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
void removeItem(const QString &name)
Removes and deletes an item by name.
ItemLongLong * addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
bool isImmutable() const
Return if the entry can be modified.
QVariant property() const override
Return item as property.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEntryImmutable(const QString &key) const
Checks if it is possible to change the given entry.
const T & at(int i) const const
bool isSaveNeeded() const
Indicates if the item has a different value than the previously loaded value.
void setProperty(const QVariant &p) override
Set item to p.
ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList< Choice > &choices, qint32 defaultValue=0)
ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue=QPoint())
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
void setCurrentGroup(const QString &group)
Set the config file group for subsequent addItem() calls.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
QVariant property() const override
Return item as property.
bool isDefaults() const
Indicates if all the registered items are set to their default value.
void setProperty(const QVariant &p) override
Set item to p.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue=QDateTime())
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
bool save()
Write preferences to config file.
QString toolTip() const
Return ToolTip description of item.
bool isSaveNeeded() const
Indicates if any registered item has a different value than the previously loaded value...
Class for handling a QDateTime preferences item.
ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue=true)
void setProperty(const QVariant &p) override
Set item to p.
Class for handling a 64-bit integer preferences item.
QVariant property() const override
Return item as property.
void setKey(const QString &_key)
Set config file key.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
A path to a file or directory.
void setProperty(const QVariant &p) override
Set item to p.
virtual void usrSetDefaults()
Perform the actual setting of default values.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
virtual QVariant maxValue() const
Return maximum value of item or invalid if not specified.
ItemUrlList(const QString &_group, const QString &_key, QList< QUrl > &reference, const QList< QUrl > &defaultValue=QList< QUrl >())
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
qulonglong toULongLong(bool *ok) const const
Class for handling a password preferences item.
void setProperty(const QVariant &p) override
Set item to p.
void setValueForChoice(const QString &name, const QString &valueForChoice)
Stores a choice value for name.
void configChanged()
This signal is emitted when the configuration change.
ItemDateTime * addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString())
Register an item of type QDateTime.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
ItemUInt * addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString())
Register an item of type quint32.
void readDefault(KConfig *) override
Read global default value.
bool isNull() const const
QVariant property() const override
Return item as property.
ItemIntList * addItemIntList(const QString &name, QList< int > &reference, const QList< int > &defaultValue=QList< int >(), const QString &key=QString())
Register an item of type QList<int>.
KConfigSkeletonItem * findItem(const QString &name) const
Lookup item by name.
ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
virtual void readConfig(KConfig *)=0
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
QVariant property() const override
Return item as property.
void setWhatsThis(const QString &w)
Set WhatsThis description of item.
bool isDefault() const
Indicates if the item is set to its default value.
ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue=QUrl())
Class for handling a QVariant preferences item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue=0)
bool isEqual(const QVariant &p) const override
void setProperty(const QVariant &p) override
Set item to p.
int count(const T &value) const const
void append(const T &value)
QVariant property() const override
Return item as property.
uint toUInt(bool *ok) const const
void setWriteFlags(KConfigBase::WriteConfigFlags flags)
The write flags to be used when writing configuration.
Class for handling a bool preferences item.
void setProperty(const QVariant &p) override
Set item to p.
Type
The type of string that is held in this item.
int toInt(bool *ok) const const
ItemInt * addItemInt(const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString())
Register an item of type qint32.
KConfigGroup configGroup(KConfig *config) const
Return a KConfigGroup, the one provided by setGroup(KConfigGroup) if it&#39;s valid, or make one from...
Class for handling an unsigned 32-bit integer preferences item.
void setMaxValue(double)
Set the maximum value for the item.
QString label() const
Return label of item.
ItemIntList(const QString &_group, const QString &_key, QList< int > &reference, const QList< int > &defaultValue=QList< int >())
void setToolTip(const QString &t)
Set ToolTip description of item.
void setProperty(const QVariant &p) override
Set item to p.
QVariant getDefault() const
Returns the default value.
void setProperty(const QVariant &p) override
Set item to p.
bool isEmpty() const const
void setLabel(const QString &l)
Set label providing a translated one-line description of the item.
void setMinValue(double)
Set the minimum value for the item.
ItemBool * addItemBool(const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString())
Register an item of type bool.
QVariant property() const override
Return item as property.
ItemPath * addItemPath(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a path item of type QString.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
ItemULongLong * addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
Register an item of type quint64.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void setMinValue(qint32)
Set the minimum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
void load()
Read preferences from config file.
QString name() const
Return internal name of entry.
ItemLongLong * addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
Register an item of type qint64.
Class for handling a QRect preferences item.
void setProperty(const QVariant &p) override
Set item to p.
ItemStringList * addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString())
Register an item of type QStringList.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QSize toSize() const const
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue=0)
void setMinValue(qint64)
Set the minimum value for the item.
QString toLower() const const
ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""))
QString key() const
Return config file key.
ItemRect * addItemRect(const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString())
Register an item of type QRect.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
KConfigSkeletonItem(const QString &_group, const QString &_key)
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
Creates a KSharedConfig object to manipulate a configuration file.
QString mName
The name of this item.
Class for handling a 32-bit integer preferences item.
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
ItemPoint * addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString())
Register an item of type QPoint.
void setMinValue(quint64)
Set the minimum value for the item.
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:38
ItemULongLong * addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
void setMinValue(quint32)
Set the minimum value for the item.
ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue=0)
const QChar * unicode() const const
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
QVariant property() const override
Return item as property.
Class for handling a QPoint preferences item.
The central class of the KDE configuration data system.
Definition: kconfig.h:56
void readImmutability(const KConfigGroup &group)
sets mIsImmutable to true if mKey in config is immutable
QList::const_iterator cend() const const
QString valueForChoice(const QString &name) const
Returns the value for for the choice with the given name.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
QStringList toStringList() const const
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
QVariant property() const override
Return item as property.
void setSharedConfig(KSharedConfig::Ptr pConfig)
Set the KSharedConfig object used for reading and writing the settings.
QList::const_iterator cbegin() const const
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMaxValue(qint64)
Set the maximum value for the item.
Class for handling a QSize preferences item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
virtual void setDefaults()
Set all registered items to their default values.
KCoreConfigSkeleton(const QString &configname=QString(), QObject *parent=nullptr)
Constructor.
ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue=QRect())
ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QString())
void clearItems()
Removes and deletes all items.
void setNotifyFunction(const std::function< void()> &impl)
Set a notify function, it will be invoked when the value of the property changes. ...
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
ItemDouble * addItemDouble(const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString())
Register an item of type double.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file...
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setProperty(const QVariant &p) override
Set item to p.
QString mKey
The config key for this item.
ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue=0)
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
void addItem(KConfigSkeletonItem *, const QString &name=QString())
Register a custom KConfigSkeletonItem with a given name.
ItemPassword * addItemPassword(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a password item of type QString.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
void setProperty(const QVariant &p) override
Set item to p.
void setName(const QString &_name)
Set internal name of entry.
QString whatsThis() const
Return WhatsThis description of item.
ItemString * addItemString(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register an item of type QString.
int length() const const
void setMaxValue(qint32)
Set the maximum value for the item.
bool toBool() const const
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
virtual void usrRead()
Perform the actual reading of the configuration file.
Class for handling a string list preferences item.
QPoint toPoint() const const
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
double toDouble(bool *ok) const const
Class for storing a preferences setting.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
virtual ~KCoreConfigSkeleton()
Destructor.
QVariant property() const override
Return item as property.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
QString mGroup
The group name for this item.
KSharedConfig::Ptr sharedConfig() const
Return the KConfig object used for reading and writing the settings.
QRect toRect() const const
Fully-fledged config, including globals and cascading to system settings.
Definition: kconfig.h:89
QVariant property() const override
Return item as property.
KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
Constructor.
virtual ~KConfigSkeletonItem()
Destructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QObject * parent() const const
Class for handling an integer list preferences item.
KConfigBase::WriteConfigFlags writeFlags() const
Return write flags to be used when writing configuration.
void setGroup(const QString &_group)
Set config file group.
QVariant property() const override
Return item as property.
QString toString() const const
QString currentGroup() const
Returns the current group used for addItem() calls.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:250
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
virtual bool usrUseDefaults(bool b)
Implemented by subclasses that use special defaults.
void revertToDefault(const QString &key)
Reverts an entry to the default settings.
QVariant property() const override
Return item as property.
void setMaxValue(quint64)
Set the maximum value for the item.
KConfigSkeletonItem::List items() const
Return list of items managed by this KCoreConfigSkeleton object.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
Q_EMITQ_EMIT
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file...
Q_INVOKABLE bool isImmutable(const QString &name) const
Return whether a certain item is immutable.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue=QSize())
Class for handling a path preferences item.
ItemProperty * addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString())
Register a property item of type QVariant.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
virtual QVariant minValue() const
Return minimum value of item or invalid if not specified.
ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue=QVariant())
ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""), Type type=Normal)
virtual bool useDefaults(bool b)
Specify whether this object should reflect the actual values or the default values.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Apr 13 2021 22:47:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.