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 
26  return result;
27 }
28 
29 KConfigSkeletonItemPrivate::~KConfigSkeletonItemPrivate() = default;
30 
32  : mGroup(_group)
33  , mKey(_key)
34  , d_ptr(new KConfigSkeletonItemPrivate)
35 {
36 }
37 
38 KConfigSkeletonItem::KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key)
39  : mGroup(_group)
40  , mKey(_key)
41  , d_ptr(&dd)
42 {
43 }
44 
46 {
47  delete d_ptr;
48 }
49 
51 {
52  mGroup = _group;
53 }
54 
56 {
58  d->mConfigGroup = cg;
59 }
60 
62 {
63  Q_D(const KConfigSkeletonItem);
64  if (d->mConfigGroup.isValid()) {
65  return d->mConfigGroup;
66  }
67  return KConfigGroup(config, mGroup);
68 }
69 
71 {
72  return mGroup;
73 }
74 
76 {
77  mKey = _key;
78 }
79 
81 {
82  return mKey;
83 }
84 
86 {
87  mName = _name;
88 }
89 
91 {
92  return mName;
93 }
94 
96 {
98  d->mLabel = l;
99 }
100 
102 {
103  Q_D(const KConfigSkeletonItem);
104  return d->mLabel;
105 }
106 
108 {
110  d->mToolTip = t;
111 }
112 
114 {
115  Q_D(const KConfigSkeletonItem);
116  return d->mToolTip;
117 }
118 
120 {
122  d->mWhatsThis = w;
123 }
124 
126 {
127  Q_D(const KConfigSkeletonItem);
128  return d->mWhatsThis;
129 }
130 
132 {
134  d->mWriteFlags = flags;
135 }
136 
138 {
139  Q_D(const KConfigSkeletonItem);
140  return d->mWriteFlags;
141 }
142 
144 {
145  return QVariant();
146 }
147 
149 {
150  return QVariant();
151 }
152 
154 {
155  Q_D(const KConfigSkeletonItem);
156  return d->mIsImmutable;
157 }
158 
160 {
161  Q_D(const KConfigSkeletonItem);
162  return d->mIsDefaultImpl();
163 }
164 
166 {
167  Q_D(const KConfigSkeletonItem);
168  return d->mIsSaveNeededImpl();
169 }
170 
172 {
173  Q_D(const KConfigSkeletonItem);
174  return d->mGetDefaultImpl();
175 }
176 
178 {
180  d->mIsImmutable = group.isEntryImmutable(mKey);
181 }
182 
183 void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool()> &impl)
184 {
186  d->mIsDefaultImpl = impl;
187 }
188 
189 void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool()> &impl)
190 {
192  d->mIsSaveNeededImpl = impl;
193 }
194 
195 void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant()> &impl)
196 {
198  d->mGetDefaultImpl = impl;
199 }
200 
201 KPropertySkeletonItem::KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
202  : KConfigSkeletonItem(*new KPropertySkeletonItemPrivate(object, propertyName, defaultValue), {}, {})
203 {
204  setIsDefaultImpl([this] {
205  Q_D(const KPropertySkeletonItem);
206  return d->mReference == d->mDefaultValue;
207  });
208  setIsSaveNeededImpl([this] {
209  Q_D(const KPropertySkeletonItem);
210  return d->mReference != d->mLoadedValue;
211  });
212  setGetDefaultImpl([this] {
213  Q_D(const KPropertySkeletonItem);
214  return d->mDefaultValue;
215  });
216 }
217 
219 {
220  Q_D(const KPropertySkeletonItem);
221  return d->mReference;
222 }
223 
225 {
227  if (d->mReference == p) {
228  return;
229  }
230  d->mReference = p;
231  if (d->mNotifyFunction) {
232  d->mNotifyFunction();
233  }
234 }
235 
237 {
238  Q_D(const KPropertySkeletonItem);
239  return d->mReference == p;
240 }
241 
243 {
245  setProperty(d->mObject->property(d->mPropertyName.constData()));
246  d->mLoadedValue = d->mReference;
247 }
248 
250 {
252  d->mObject->setProperty(d->mPropertyName.constData(), d->mReference);
253  d->mLoadedValue = d->mReference;
254 }
255 
257 {
259  setProperty(d->mConstDefaultValue);
260 }
261 
263 {
265  setProperty(d->mDefaultValue);
266 }
267 
269 {
271  if (d->mReference == d->mDefaultValue) {
272  return;
273  }
274  std::swap(d->mReference, d->mDefaultValue);
275  if (d->mNotifyFunction) {
276  d->mNotifyFunction();
277  }
278 }
279 
280 void KPropertySkeletonItem::setNotifyFunction(const std::function<void()> &impl)
281 {
283  d->mNotifyFunction = impl;
284 }
285 
286 KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue, Type type)
287  : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue)
288  , mType(type)
289 {
290 }
291 
293 {
294  if (mReference != mLoadedValue) { // WABA: Is this test needed?
295  KConfigGroup cg = configGroup(config);
296  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
297  cg.revertToDefault(mKey, writeFlags());
298  } else if (mType == Path) {
299  cg.writePathEntry(mKey, mReference, writeFlags());
300  } else if (mType == Password) {
301  cg.writeEntry(mKey, obscuredString(mReference), writeFlags());
302  } else {
303  cg.writeEntry(mKey, mReference, writeFlags());
304  }
305  mLoadedValue = mReference;
306  }
307 }
308 
310 {
311  KConfigGroup cg = configGroup(config);
312 
313  if (mType == Path) {
314  mReference = cg.readPathEntry(mKey, mDefault);
315  } else if (mType == Password) {
316  QString val = cg.readEntry(mKey, obscuredString(mDefault));
317  mReference = obscuredString(val);
318  } else {
319  mReference = cg.readEntry(mKey, mDefault);
320  }
321 
322  mLoadedValue = mReference;
323 
324  readImmutability(cg);
325 }
326 
328 {
329  mReference = p.toString();
330 }
331 
333 {
334  return mReference == v.toString();
335 }
336 
338 {
339  return QVariant(mReference);
340 }
341 
342 KCoreConfigSkeleton::ItemPassword::ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
343  : ItemString(_group, _key, reference, defaultValue, Password)
344 {
345 }
346 
347 KCoreConfigSkeleton::ItemPath::ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
348  : ItemString(_group, _key, reference, defaultValue, Path)
349 {
350 }
351 
352 KCoreConfigSkeleton::ItemUrl::ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue)
353  : KConfigSkeletonGenericItem<QUrl>(_group, _key, reference, defaultValue)
354 {
355 }
356 
358 {
359  if (mReference != mLoadedValue) { // WABA: Is this test needed?
360  KConfigGroup cg = configGroup(config);
361  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
362  cg.revertToDefault(mKey, writeFlags());
363  } else {
364  cg.writeEntry<QString>(mKey, mReference.toString(), writeFlags());
365  }
366  mLoadedValue = mReference;
367  }
368 }
369 
371 {
372  KConfigGroup cg = configGroup(config);
373 
374  mReference = QUrl(cg.readEntry<QString>(mKey, mDefault.toString()));
375  mLoadedValue = mReference;
376 
377  readImmutability(cg);
378 }
379 
381 {
382  mReference = qvariant_cast<QUrl>(p);
383 }
384 
386 {
387  return mReference == qvariant_cast<QUrl>(v);
388 }
389 
391 {
392  return QVariant::fromValue<QUrl>(mReference);
393 }
394 
395 KCoreConfigSkeleton::ItemProperty::ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue)
396  : KConfigSkeletonGenericItem<QVariant>(_group, _key, reference, defaultValue)
397 {
398 }
399 
401 {
402  KConfigGroup cg = configGroup(config);
403  mReference = cg.readEntry(mKey, mDefault);
404  mLoadedValue = mReference;
405 
406  readImmutability(cg);
407 }
408 
410 {
411  mReference = p;
412 }
413 
415 {
416  // this might cause problems if the QVariants are not of default types
417  return mReference == v;
418 }
419 
421 {
422  return mReference;
423 }
424 
425 KCoreConfigSkeleton::ItemBool::ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue)
426  : KConfigSkeletonGenericItem<bool>(_group, _key, reference, defaultValue)
427 {
428 }
429 
431 {
432  KConfigGroup cg = configGroup(config);
433  mReference = cg.readEntry(mKey, mDefault);
434  mLoadedValue = mReference;
435 
436  readImmutability(cg);
437 }
438 
440 {
441  mReference = p.toBool();
442 }
443 
445 {
446  return mReference == v.toBool();
447 }
448 
450 {
451  return QVariant(mReference);
452 }
453 
454 KCoreConfigSkeleton::ItemInt::ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue)
455  : KConfigSkeletonGenericItem<qint32>(_group, _key, reference, defaultValue)
456  , mHasMin(false)
457  , mHasMax(false)
458 {
459 }
460 
462 {
463  KConfigGroup cg = configGroup(config);
464  mReference = cg.readEntry(mKey, mDefault);
465  if (mHasMin) {
466  mReference = qMax(mReference, mMin);
467  }
468  if (mHasMax) {
469  mReference = qMin(mReference, mMax);
470  }
471  mLoadedValue = mReference;
472 
473  readImmutability(cg);
474 }
475 
477 {
478  mReference = p.toInt();
479 }
480 
482 {
483  return mReference == v.toInt();
484 }
485 
487 {
488  return QVariant(mReference);
489 }
490 
492 {
493  if (mHasMin) {
494  return QVariant(mMin);
495  }
496  return QVariant();
497 }
498 
500 {
501  if (mHasMax) {
502  return QVariant(mMax);
503  }
504  return QVariant();
505 }
506 
508 {
509  mHasMin = true;
510  mMin = v;
511 }
512 
514 {
515  mHasMax = true;
516  mMax = v;
517 }
518 
519 KCoreConfigSkeleton::ItemLongLong::ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue)
520  : KConfigSkeletonGenericItem<qint64>(_group, _key, reference, defaultValue)
521  , mHasMin(false)
522  , mHasMax(false)
523 {
524 }
525 
527 {
528  KConfigGroup cg = configGroup(config);
529  mReference = cg.readEntry(mKey, mDefault);
530  if (mHasMin) {
531  mReference = qMax(mReference, mMin);
532  }
533  if (mHasMax) {
534  mReference = qMin(mReference, mMax);
535  }
536  mLoadedValue = mReference;
537 
538  readImmutability(cg);
539 }
540 
542 {
543  mReference = p.toLongLong();
544 }
545 
547 {
548  return mReference == v.toLongLong();
549 }
550 
552 {
553  return QVariant(mReference);
554 }
555 
557 {
558  if (mHasMin) {
559  return QVariant(mMin);
560  }
561  return QVariant();
562 }
563 
565 {
566  if (mHasMax) {
567  return QVariant(mMax);
568  }
569  return QVariant();
570 }
571 
573 {
574  mHasMin = true;
575  mMin = v;
576 }
577 
579 {
580  mHasMax = true;
581  mMax = v;
582 }
583 
585 {
586  // HACK for BC concerns
587  // TODO KF6: remove KConfigSkeletonItemPrivate::mValues and add a value field to KCoreConfigSkeleton::ItemEnum::Choice
588  const auto inHash = d_ptr->mValues.value(name);
589  return !inHash.isEmpty() ? inHash : name;
590 }
591 
593 {
594  d_ptr->mValues.insert(name, value);
595 }
596 
597 KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue)
598  : ItemInt(_group, _key, reference, defaultValue)
599  , mChoices(choices)
600 {
601 }
602 
604 {
605  KConfigGroup cg = configGroup(config);
606  if (!cg.hasKey(mKey)) {
607  mReference = mDefault;
608  } else {
609  int i = 0;
610  mReference = -1;
611  const QString entryString = cg.readEntry(mKey, QString());
612  for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {
613  QString choiceName = (*it).name;
614  if (valueForChoice(choiceName).compare(entryString, Qt::CaseInsensitive) == 0) {
615  mReference = i;
616  break;
617  }
618  }
619  if (mReference == -1) {
620  mReference = cg.readEntry(mKey, mDefault);
621  }
622  }
623  mLoadedValue = mReference;
624 
625  readImmutability(cg);
626 }
627 
629 {
630  if (mReference != mLoadedValue) { // WABA: Is this test needed?
631  KConfigGroup cg = configGroup(config);
632  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
633  cg.revertToDefault(mKey, writeFlags());
634  } else if ((mReference >= 0) && (mReference < mChoices.count())) {
635  cg.writeEntry(mKey, valueForChoice(mChoices.at(mReference).name), writeFlags());
636  } else {
637  cg.writeEntry(mKey, mReference, writeFlags());
638  }
639  mLoadedValue = mReference;
640  }
641 }
642 
643 QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choices() const
644 {
645  return mChoices;
646 }
647 
648 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 103)
650 {
651  return mChoices;
652 }
653 #endif
654 
655 KCoreConfigSkeleton::ItemUInt::ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue)
656  : KConfigSkeletonGenericItem<quint32>(_group, _key, reference, defaultValue)
657  , mHasMin(false)
658  , mHasMax(false)
659 {
660 }
661 
663 {
664  KConfigGroup cg = configGroup(config);
665  mReference = cg.readEntry(mKey, mDefault);
666  if (mHasMin) {
667  mReference = qMax(mReference, mMin);
668  }
669  if (mHasMax) {
670  mReference = qMin(mReference, mMax);
671  }
672  mLoadedValue = mReference;
673 
674  readImmutability(cg);
675 }
676 
678 {
679  mReference = p.toUInt();
680 }
681 
683 {
684  return mReference == v.toUInt();
685 }
686 
688 {
689  return QVariant(mReference);
690 }
691 
693 {
694  if (mHasMin) {
695  return QVariant(mMin);
696  }
697  return QVariant();
698 }
699 
701 {
702  if (mHasMax) {
703  return QVariant(mMax);
704  }
705  return QVariant();
706 }
707 
709 {
710  mHasMin = true;
711  mMin = v;
712 }
713 
715 {
716  mHasMax = true;
717  mMax = v;
718 }
719 
720 KCoreConfigSkeleton::ItemULongLong::ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue)
721  : KConfigSkeletonGenericItem<quint64>(_group, _key, reference, defaultValue)
722  , mHasMin(false)
723  , mHasMax(false)
724 {
725 }
726 
728 {
729  KConfigGroup cg = configGroup(config);
730  mReference = cg.readEntry(mKey, mDefault);
731  if (mHasMin) {
732  mReference = qMax(mReference, mMin);
733  }
734  if (mHasMax) {
735  mReference = qMin(mReference, mMax);
736  }
737  mLoadedValue = mReference;
738 
739  readImmutability(cg);
740 }
741 
743 {
744  mReference = p.toULongLong();
745 }
746 
748 {
749  return mReference == v.toULongLong();
750 }
751 
753 {
754  return QVariant(mReference);
755 }
756 
758 {
759  if (mHasMin) {
760  return QVariant(mMin);
761  }
762  return QVariant();
763 }
764 
766 {
767  if (mHasMax) {
768  return QVariant(mMax);
769  }
770  return QVariant();
771 }
772 
774 {
775  mHasMin = true;
776  mMin = v;
777 }
778 
780 {
781  mHasMax = true;
782  mMax = v;
783 }
784 
785 KCoreConfigSkeleton::ItemDouble::ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue)
786  : KConfigSkeletonGenericItem<double>(_group, _key, reference, defaultValue)
787  , mHasMin(false)
788  , mHasMax(false)
789 {
790 }
791 
793 {
794  KConfigGroup cg = configGroup(config);
795  mReference = cg.readEntry(mKey, mDefault);
796  if (mHasMin) {
797  mReference = qMax(mReference, mMin);
798  }
799  if (mHasMax) {
800  mReference = qMin(mReference, mMax);
801  }
802  mLoadedValue = mReference;
803 
804  readImmutability(cg);
805 }
806 
808 {
809  mReference = p.toDouble();
810 }
811 
813 {
814  return mReference == v.toDouble();
815 }
816 
818 {
819  return QVariant(mReference);
820 }
821 
823 {
824  if (mHasMin) {
825  return QVariant(mMin);
826  }
827  return QVariant();
828 }
829 
831 {
832  if (mHasMax) {
833  return QVariant(mMax);
834  }
835  return QVariant();
836 }
837 
839 {
840  mHasMin = true;
841  mMin = v;
842 }
843 
845 {
846  mHasMax = true;
847  mMax = v;
848 }
849 
850 KCoreConfigSkeleton::ItemRect::ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue)
851  : KConfigSkeletonGenericItem<QRect>(_group, _key, reference, defaultValue)
852 {
853 }
854 
856 {
857  KConfigGroup cg = configGroup(config);
858  mReference = cg.readEntry(mKey, mDefault);
859  mLoadedValue = mReference;
860 
861  readImmutability(cg);
862 }
863 
865 {
866  mReference = p.toRect();
867 }
868 
870 {
871  return mReference == v.toRect();
872 }
873 
875 {
876  return QVariant(mReference);
877 }
878 
879 KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue)
880  : KConfigSkeletonGenericItem<QPoint>(_group, _key, reference, defaultValue)
881 {
882 }
883 
885 {
886  KConfigGroup cg = configGroup(config);
887  mReference = cg.readEntry(mKey, mDefault);
888  mLoadedValue = mReference;
889 
890  readImmutability(cg);
891 }
892 
894 {
895  mReference = p.toPoint();
896 }
897 
899 {
900  return mReference == v.toPoint();
901 }
902 
904 {
905  return QVariant(mReference);
906 }
907 
908 KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue)
909  : KConfigSkeletonGenericItem<QSize>(_group, _key, reference, defaultValue)
910 {
911 }
912 
914 {
915  KConfigGroup cg = configGroup(config);
916  mReference = cg.readEntry(mKey, mDefault);
917  mLoadedValue = mReference;
918 
919  readImmutability(cg);
920 }
921 
923 {
924  mReference = p.toSize();
925 }
926 
928 {
929  return mReference == v.toSize();
930 }
931 
933 {
934  return QVariant(mReference);
935 }
936 
937 KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue)
938  : KConfigSkeletonGenericItem<QDateTime>(_group, _key, reference, defaultValue)
939 {
940 }
941 
943 {
944  KConfigGroup cg = configGroup(config);
945  mReference = cg.readEntry(mKey, mDefault);
946  mLoadedValue = mReference;
947 
948  readImmutability(cg);
949 }
950 
952 {
953  mReference = p.toDateTime();
954 }
955 
957 {
958  return mReference == v.toDateTime();
959 }
960 
962 {
963  return QVariant(mReference);
964 }
965 
966 KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
967  : KConfigSkeletonGenericItem<QStringList>(_group, _key, reference, defaultValue)
968 {
969 }
970 
972 {
973  KConfigGroup cg = configGroup(config);
974  if (!cg.hasKey(mKey)) {
975  mReference = mDefault;
976  } else {
977  mReference = cg.readEntry(mKey, mDefault);
978  }
979  mLoadedValue = mReference;
980 
981  readImmutability(cg);
982 }
983 
985 {
986  mReference = p.toStringList();
987 }
988 
990 {
991  return mReference == v.toStringList();
992 }
993 
995 {
996  return QVariant(mReference);
997 }
998 
999 KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
1000  : ItemStringList(_group, _key, reference, defaultValue)
1001 {
1002 }
1003 
1005 {
1006  KConfigGroup cg = configGroup(config);
1007  if (!cg.hasKey(mKey)) {
1008  mReference = mDefault;
1009  } else {
1010  mReference = cg.readPathEntry(mKey, QStringList());
1011  }
1012  mLoadedValue = mReference;
1013 
1014  readImmutability(cg);
1015 }
1016 
1018 {
1019  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1020  KConfigGroup cg = configGroup(config);
1021  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1022  cg.revertToDefault(mKey, writeFlags());
1023  } else {
1024  QStringList sl = mReference;
1025  cg.writePathEntry(mKey, sl, writeFlags());
1026  }
1027  mLoadedValue = mReference;
1028  }
1029 }
1030 
1031 KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue)
1032  : KConfigSkeletonGenericItem<QList<QUrl>>(_group, _key, reference, defaultValue)
1033 {
1034 }
1035 
1037 {
1038  KConfigGroup cg = configGroup(config);
1039  if (!cg.hasKey(mKey)) {
1040  mReference = mDefault;
1041  } else {
1042  QStringList strList;
1043  for (const QUrl &url : std::as_const(mDefault)) {
1044  strList.append(url.toString());
1045  }
1046  mReference.clear();
1047  const QStringList readList = cg.readEntry<QStringList>(mKey, strList);
1048  for (const QString &str : readList) {
1049  mReference.append(QUrl(str));
1050  }
1051  }
1052  mLoadedValue = mReference;
1053 
1054  readImmutability(cg);
1055 }
1056 
1058 {
1059  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1060  KConfigGroup cg = configGroup(config);
1061  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1062  cg.revertToDefault(mKey, writeFlags());
1063  } else {
1064  QStringList strList;
1065  for (const QUrl &url : std::as_const(mReference)) {
1066  strList.append(url.toString());
1067  }
1068  cg.writeEntry<QStringList>(mKey, strList, writeFlags());
1069  }
1070  mLoadedValue = mReference;
1071  }
1072 }
1073 
1075 {
1076  mReference = qvariant_cast<QList<QUrl>>(p);
1077 }
1078 
1080 {
1081  return mReference == qvariant_cast<QList<QUrl>>(v);
1082 }
1083 
1085 {
1086  return QVariant::fromValue<QList<QUrl>>(mReference);
1087 }
1088 
1089 KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue)
1090  : KConfigSkeletonGenericItem<QList<int>>(_group, _key, reference, defaultValue)
1091 {
1092 }
1093 
1095 {
1096  KConfigGroup cg = configGroup(config);
1097  if (!cg.hasKey(mKey)) {
1098  mReference = mDefault;
1099  } else {
1100  mReference = cg.readEntry(mKey, mDefault);
1101  }
1102  mLoadedValue = mReference;
1103 
1104  readImmutability(cg);
1105 }
1106 
1108 {
1109  mReference = qvariant_cast<QList<int>>(p);
1110 }
1111 
1113 {
1114  return mReference == qvariant_cast<QList<int>>(v);
1115 }
1116 
1118 {
1119  return QVariant::fromValue<QList<int>>(mReference);
1120 }
1121 
1122 // static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; }
1123 
1125  : QObject(parent)
1126  , d(new KCoreConfigSkeletonPrivate)
1127 {
1128  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1129 
1130  d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig);
1131 }
1132 
1134  : QObject(parent)
1135  , d(new KCoreConfigSkeletonPrivate)
1136 {
1137  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1138  d->mConfig = std::move(pConfig);
1139 }
1140 
1142 {
1143  delete d;
1144 }
1145 
1147 {
1148  d->mCurrentGroup = group;
1149 }
1150 
1152 {
1153  return d->mCurrentGroup;
1154 }
1155 
1157 {
1158  return d->mConfig.data();
1159 }
1160 
1161 const KConfig *KCoreConfigSkeleton::config() const
1162 {
1163  return d->mConfig.data();
1164 }
1165 
1167 {
1168  return d->mConfig;
1169 }
1170 
1172 {
1173  d->mConfig = std::move(pConfig);
1174 }
1175 
1177 {
1178  return d->mItems;
1179 }
1180 
1182 {
1183  if (b == d->mUseDefaults) {
1184  return d->mUseDefaults;
1185  }
1186 
1187  d->mUseDefaults = b;
1188  for (auto *skelItem : std::as_const(d->mItems)) {
1189  skelItem->swapDefault();
1190  }
1191 
1192  usrUseDefaults(b);
1193  return !d->mUseDefaults;
1194 }
1195 
1197 {
1198  for (auto *skelItem : std::as_const(d->mItems)) {
1199  skelItem->setDefault();
1200  }
1201  usrSetDefaults();
1202 }
1203 
1205 {
1206  d->mConfig->reparseConfiguration();
1207  read();
1208 }
1209 
1211 {
1212  for (auto *skelItem : std::as_const(d->mItems)) {
1213  skelItem->readConfig(d->mConfig.data());
1214  }
1215  usrRead();
1216 }
1217 
1219 {
1220  return std::all_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1221  return skelItem->isDefault();
1222  });
1223 }
1224 
1226 {
1227  return std::any_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1228  return skelItem->isSaveNeeded();
1229  });
1230 }
1231 
1233 {
1234  // qDebug();
1235  for (auto *skelItem : std::as_const(d->mItems)) {
1236  skelItem->writeConfig(d->mConfig.data());
1237  }
1238 
1239  if (!usrSave()) {
1240  return false;
1241  }
1242 
1243  if (d->mConfig->isDirty()) {
1244  if (!d->mConfig->sync()) {
1245  return false;
1246  }
1248  }
1249  return true;
1250 }
1251 
1253 {
1254  return false;
1255 }
1256 
1258 {
1259 }
1260 
1262 {
1263 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1264  usrReadConfig();
1265 #endif
1266 }
1267 
1268 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1270 {
1271 }
1272 #endif
1273 
1275 {
1276 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1277  return usrWriteConfig();
1278 #else
1279  return true;
1280 #endif
1281 }
1282 
1283 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1285 {
1286  return true;
1287 }
1288 #endif
1289 
1291 {
1292  if (d->mItems.contains(item)) {
1293  if (item->name() == name || (name.isEmpty() && item->name() == item->key())) {
1294  // nothing to do -> it is already in our collection
1295  // and the name isn't changing
1296  return;
1297  }
1298 
1299  d->mItemDict.remove(item->name());
1300  } else {
1301  d->mItems.append(item);
1302  }
1303 
1304  item->setName(name.isEmpty() ? item->key() : name);
1305  d->mItemDict.insert(item->name(), item);
1306  item->readDefault(d->mConfig.data());
1307  item->readConfig(d->mConfig.data());
1308 }
1309 
1311 {
1312  KConfigSkeletonItem *item = d->mItemDict.value(name);
1313  if (item) {
1314  d->mItems.removeAll(item);
1315  d->mItemDict.remove(item->name());
1316  delete item;
1317  }
1318 }
1319 
1321 {
1322  KConfigSkeletonItem::List items = d->mItems;
1323  d->mItems.clear();
1324  d->mItemDict.clear();
1325  qDeleteAll(items);
1326 }
1327 
1328 KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1329 {
1331  item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, reference, defaultValue, KCoreConfigSkeleton::ItemString::Normal);
1332  addItem(item, name);
1333  return item;
1334 }
1335 
1337 KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1338 {
1340  item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1341  addItem(item, name);
1342  return item;
1343 }
1344 
1345 KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1346 {
1348  item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1349  addItem(item, name);
1350  return item;
1351 }
1352 
1354 KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key)
1355 {
1357  item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1358  addItem(item, name);
1359  return item;
1360 }
1361 
1362 KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, bool defaultValue, const QString &key)
1363 {
1365  item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1366  addItem(item, name);
1367  return item;
1368 }
1369 
1370 KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, qint32 defaultValue, const QString &key)
1371 {
1373  item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1374  addItem(item, name);
1375  return item;
1376 }
1377 
1378 KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue, const QString &key)
1379 {
1381  item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1382  addItem(item, name);
1383  return item;
1384 }
1385 
1386 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1387 {
1389  item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1390  addItem(item, name);
1391  return item;
1392 }
1393 
1394 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1395 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1396 {
1397  return addItemLongLong(name, reference, defaultValue, key);
1398 }
1399 #endif
1400 
1401 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1402 {
1404  item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1405  addItem(item, name);
1406  return item;
1407 }
1408 
1409 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1410 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1411 {
1412  return addItemULongLong(name, reference, defaultValue, key);
1413 }
1414 #endif
1415 
1416 KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, double defaultValue, const QString &key)
1417 {
1419  item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1420  addItem(item, name);
1421  return item;
1422 }
1423 
1424 KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, const QRect &defaultValue, const QString &key)
1425 {
1427  item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1428  addItem(item, name);
1429  return item;
1430 }
1431 
1432 KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue, const QString &key)
1433 {
1435  item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1436  addItem(item, name);
1437  return item;
1438 }
1439 
1440 KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, const QSize &defaultValue, const QString &key)
1441 {
1443  item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1444  addItem(item, name);
1445  return item;
1446 }
1447 
1449 KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key)
1450 {
1452  item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1453  addItem(item, name);
1454  return item;
1455 }
1456 
1458 KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key)
1459 {
1461  item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1462  addItem(item, name);
1463  return item;
1464 }
1465 
1467 KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key)
1468 {
1470  item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1471  addItem(item, name);
1472  return item;
1473 }
1474 
1476 {
1477  KConfigSkeletonItem *item = findItem(name);
1478  return !item || item->isImmutable();
1479 }
1480 
1482 {
1483  return d->mItemDict.value(name);
1484 }
1485 
1487  QObject *object,
1488  KConfigCompilerSignallingItem::NotifyFunction targetFunction,
1489  quint64 userData)
1490  : KConfigSkeletonItem(item->group(), item->key())
1491  , mItem(item)
1492  , mTargetFunction(targetFunction)
1493  , mObject(object)
1494  , mUserData(userData)
1495 {
1496  Q_ASSERT(mTargetFunction);
1497  Q_ASSERT(mItem);
1498  Q_ASSERT(mObject);
1499 
1500  setIsDefaultImpl([this] {
1501  return mItem->isDefault();
1502  });
1503  setIsSaveNeededImpl([this] {
1504  return mItem->isSaveNeeded();
1505  });
1506  setGetDefaultImpl([this] {
1507  return mItem->getDefault();
1508  });
1509 }
1510 
1511 KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem()
1512 {
1513 }
1514 
1516 {
1517  return mItem->isEqual(p);
1518 }
1519 
1521 {
1522  return mItem->property();
1523 }
1524 
1526 {
1527  return mItem->minValue();
1528 }
1529 
1531 {
1532  return mItem->maxValue();
1533 }
1534 
1536 {
1537  QVariant oldValue = mItem->property();
1538  mItem->readConfig(c);
1539  // readConfig() changes mIsImmutable, update it here as well
1540  KConfigGroup cg = configGroup(c);
1541  readImmutability(cg);
1542  if (!mItem->isEqual(oldValue)) {
1543  invokeNotifyFunction();
1544  }
1545 }
1546 
1548 {
1549  mItem->readDefault(c);
1550  // readDefault() changes mIsImmutable, update it here as well
1551  KConfigGroup cg = configGroup(c);
1552  readImmutability(cg);
1553 }
1554 
1556 {
1557  mItem->writeConfig(c);
1558 }
1559 
1561 {
1562  QVariant oldValue = mItem->property();
1563  mItem->setDefault();
1564  if (!mItem->isEqual(oldValue)) {
1565  invokeNotifyFunction();
1566  }
1567 }
1568 
1570 {
1571  if (!mItem->isEqual(p)) {
1572  mItem->setProperty(p);
1573  invokeNotifyFunction();
1574  }
1575 }
1576 
1578 {
1579  QVariant oldValue = mItem->property();
1580  mItem->swapDefault();
1581  if (!mItem->isEqual(oldValue)) {
1582  invokeNotifyFunction();
1583  }
1584 }
1585 
1586 void KConfigCompilerSignallingItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
1587 {
1588  mItem->setWriteFlags(flags);
1589 }
1590 
1591 KConfigBase::WriteConfigFlags KConfigCompilerSignallingItem::writeFlags() const
1592 {
1593  return mItem->writeFlags();
1594 }
1595 
1596 void KConfigCompilerSignallingItem::setGroup(const KConfigGroup &cg)
1597 {
1598  mItem->setGroup(cg);
1599 }
1600 
1601 KConfigGroup KConfigCompilerSignallingItem::configGroup(KConfig *config) const
1602 {
1603  return mItem->configGroup(config);
1604 }
QRect toRect() const const
void read()
Read preferences from the KConfig object.
KSharedConfig::Ptr sharedConfig() const
Return the KConfig object used for reading and writing the settings.
void append(const T &value)
QString mGroup
The group name for this item.
bool save()
Write preferences to config file.
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>.
ItemProperty * addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString())
Register a property item of type QVariant.
bool isNull() const const
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue=QPoint())
Constructor.
ItemLongLong * addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
virtual QVariant maxValue() const
Return maximum value of item or invalid if not specified.
void setCurrentGroup(const QString &group)
Set the config file group for subsequent addItem() calls.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
KCoreConfigSkeleton(const QString &configname=QString(), QObject *parent=nullptr)
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
void setMaxValue(double)
Set the maximum value for the item.
QVariant property() const override
Return item as property.
QVariant property() const override
Return item as property.
QVariant minValue() const override
Return minimum value of item or invalid if not specified.
Class for handling a floating point preference item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
CaseInsensitive
ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue=QSize())
Constructor.
ItemUrlList(const QString &_group, const QString &_key, QList< QUrl > &reference, const QList< QUrl > &defaultValue=QList< QUrl >())
Constructor.
KConfigSkeletonItem::List items() const
Return list of items managed by this KCoreConfigSkeleton object.
ItemInt * addItemInt(const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString())
Register an item of type qint32.
virtual bool useDefaults(bool b)
Specify whether this object should reflect the actual values or the default values.
Q_EMITQ_EMIT
QVariant property() const override
Return item as property.
virtual bool usrSave()
Perform the actual writing of the configuration file.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setValueForChoice(const QString &name, const QString &valueForChoice)
Stores a choice value for name.
void readDefault(KConfig *) override
Read global default value.
Class for handling a string preferences item.
ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
void clearItems()
Removes and deletes all items.
void setProperty(const QVariant &p) override
Set item to p.
bool isDefault() const
Indicates if the item is set to its default value.
ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue=0)
Constructor.
void configChanged()
This signal is emitted when the configuration change.
void setMinValue(quint64)
Set the minimum value for the item.
ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue=QDateTime())
Constructor.
The central class of the KDE configuration data system.
Definition: kconfig.h:56
QVariant property() const override
Return item as property.
Class for handling a 64-bit integer preferences item.
QList< Choice > choices2() const
virtual void usrRead()
Perform the actual reading of the configuration file.
QString toolTip() const
Return ToolTip description of item.
QString name() const
Return internal name of entry.
ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue=0)
Constructor.
void setMinValue(qint32)
Set the minimum value for the item.
KConfigSkeletonItem * findItem(const QString &name) const
Lookup item by name.
ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue=QUrl())
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
void setProperty(const QVariant &p) override
Set item to p.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
const QChar * unicode() const const
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
qlonglong toLongLong(bool *ok) const const
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
ItemPassword * addItemPassword(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a password item of type QString.
QString group() const
Return name of config file group.
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
Writes a file path to the configuration.
void setDefault() override
Sets the current value to the default value.
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.
ItemSize * addItemSize(const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString())
Register an item of type QSize.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
void setWhatsThis(const QString &w)
Set WhatsThis description of item.
void setToolTip(const QString &t)
Set ToolTip description of item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
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.
Class for handling a QPoint preferences item.
Class for handling a QVariant preferences item.
bool hasDefault(const QString &key) const
Whether a default is specified for an entry in either the system wide configuration file or the globa...
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this 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.
KConfigGroup configGroup(KConfig *config) const
Return a KConfigGroup, the one provided by setGroup(const KConfigGroup&) if it's valid,...
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemPath * addItemPath(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a path item of type QString.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
Class for handling a QDateTime preferences item.
void setWriteFlags(KConfigBase::WriteConfigFlags flags)
The write flags to be used when writing configuration.
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.
void removeItem(const QString &name)
Removes and deletes an item by name.
ItemString * addItemString(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register an item of type QString.
void setSharedConfig(KSharedConfig::Ptr pConfig)
Set the KSharedConfig object used for reading and writing the settings.
double toDouble(bool *ok) const const
ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QString())
Constructor.
void setKey(const QString &_key)
Set config file key.
QString whatsThis() const
Return WhatsThis description of item.
QVariant property() const override
Return item as property.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
qulonglong toULongLong(bool *ok) const const
Class for handling a password preferences item.
ItemLongLong * addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
Register an item of type qint64.
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.
ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue=QRect())
Constructor.
QString mKey
The config key for this item.
QVariant maxValue() const override
Return maximum value of item or invalid if not specified.
void setProperty(const QVariant &p) override
Set item to p.
@ FullConfig
Fully-fledged config, including globals and cascading to system settings.
Definition: kconfig.h:89
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
Class for handling unsigned 64-bit integer preferences item.
QVariant property() const override
Return item as property.
Class for handling a QSize preferences item.
void setMaxValue(quint64)
Set the maximum value for the item.
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.
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
bool isEmpty() const const
QString currentGroup() const
Returns the current group used for addItem() calls.
QString mName
The name of this item.
int length() const const
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setGroup(const QString &_group)
Set config file group.
Class for handling an unsigned 32-bit integer preferences item.
uint toUInt(bool *ok) const const
virtual void setDefaults()
Set all registered items to their default values.
void setProperty(const QVariant &p) override
Set item to p.
ItemIntList(const QString &_group, const QString &_key, QList< int > &reference, const QList< int > &defaultValue=QList< int >())
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
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)
Constructor.
ItemDateTime * addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString())
Register an item of type QDateTime.
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.
int toInt(bool *ok) 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.
void setProperty(const QVariant &p) override
Set item to p.
QVariant property() const override
Return item as property.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
void setDefault() override
Sets the current value to the default value.
KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData)
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readImmutability(const KConfigGroup &group)
Sets mIsImmutable to true if mKey in config is immutable.
void setMinValue(double)
Set the minimum value for the item.
virtual void readConfig(KConfig *)=0
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setMinValue(qint64)
Set the minimum value for the item.
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:258
QVariant property() const override
Return item as property.
void addItem(KConfigSkeletonItem *item, const QString &name=QString())
Register a custom KConfigSkeletonItem item with a given name.
virtual QVariant minValue() const
Return minimum value of item or invalid if not specified.
Base class for storing a preferences setting of type T.
Class for handling a string list preferences item.
void setProperty(const QVariant &p) override
Set item to p.
void setProperty(const QVariant &p) override
Set item to p.
KConfigBase::WriteConfigFlags writeFlags() const
Return write flags to be used when writing configuration.
QPoint toPoint() const const
bool isSaveNeeded() const
Indicates if any registered item has a different value than the previously loaded value.
ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""))
Constructor.
bool toBool() const const
ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue=0)
Constructor.
void readConfig(KConfig *) 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 swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
virtual void readDefault(KConfig *)=0
Read global default value.
ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue=true)
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
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 readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
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.
virtual void usrSetDefaults()
Perform the actual setting of default values.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
void setMaxValue(qint32)
Set the maximum value for the item.
bool isDefaults() const
Indicates if all the registered items are set to their default value.
QVariant getDefault() const
Returns the default value.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QDateTime toDateTime() const const
void setNotifyFunction(const std::function< void()> &impl)
Set a notify function, it will be invoked when the value of the property changes.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
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.
Class for handling a 32-bit integer preferences item.
Class for handling an integer list preferences item.
Class for storing a preferences setting.
void setName(const QString &_name)
Set internal name of entry.
void setMaxValue(qint64)
Set the maximum value for the item.
void writeConfig(KConfig *) 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.
ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
KConfig * config()
Return the KConfig object used for reading and writing the settings.
Class for handling a QRect preferences item.
QSize toSize() const const
QVariant property() const override
Return item as property.
bool isImmutable() const
Return if the entry can be modified.
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
Type
The type of string that is held in this item.
QString readPathEntry(const QString &pKey, const QString &aDefault) const
Reads a path.
void revertToDefault(const QString &key)
Reverts an entry to the default settings.
void load()
Read preferences from config file.
void readDefault(KConfig *) override
Read global default value.
KConfigSkeletonItem(const QString &_group, const QString &_key)
Constructor.
virtual bool usrUseDefaults(bool b)
Implemented by subclasses that use special defaults.
QVariant property() const override
Return item as property.
void setLabel(const QString &l)
Set label providing a translated one-line description of the item.
ItemULongLong * addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
Constructor.
virtual ~KConfigSkeletonItem()
Destructor.
QStringList toStringList() const const
ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""), Type type=Normal)
Constructor.
QString valueForChoice(const QString &name) const
Returns the value for for the choice with the given name.
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.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for proxying a QObject property as a preferences setting.
~KCoreConfigSkeleton() override
Destructor.
Class for handling a path preferences item.
QVariant property() const override
Return item as property.
ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue=0)
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
ItemDouble * addItemDouble(const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString())
Register an item of type double.
void setMinValue(quint32)
Set the minimum value for the item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setProperty(const QVariant &p) override
Set item to p.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QString label() const
Return the label of the item.
ItemULongLong * addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
Register an item of type quint64.
Class for handling a bool preferences item.
QObject * parent() const const
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue=QVariant())
Constructor.
QVariant property() const override
Return item as property.
ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue=0)
Constructor.
QVariant property() const override
Return item as property.
QVariant property() const override
Return item as property.
Q_D(Todo)
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
ushort unicode() const const
void readConfig(KConfig *config) override
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.
QString toString() const const
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setMaxValue(quint32)
Set the maximum value for the item.
ItemBool * addItemBool(const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString())
Register an item of type bool.
void setProperty(const QVariant &p) override
Set item to p.
ItemUInt * addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString())
Register an item of type quint32.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:07:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.