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 QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choices2() const
649 {
650  return mChoices;
651 }
652 
653 KCoreConfigSkeleton::ItemUInt::ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue)
654  : KConfigSkeletonGenericItem<quint32>(_group, _key, reference, defaultValue)
655  , mHasMin(false)
656  , mHasMax(false)
657 {
658 }
659 
661 {
662  KConfigGroup cg = configGroup(config);
663  mReference = cg.readEntry(mKey, mDefault);
664  if (mHasMin) {
665  mReference = qMax(mReference, mMin);
666  }
667  if (mHasMax) {
668  mReference = qMin(mReference, mMax);
669  }
670  mLoadedValue = mReference;
671 
672  readImmutability(cg);
673 }
674 
676 {
677  mReference = p.toUInt();
678 }
679 
681 {
682  return mReference == v.toUInt();
683 }
684 
686 {
687  return QVariant(mReference);
688 }
689 
691 {
692  if (mHasMin) {
693  return QVariant(mMin);
694  }
695  return QVariant();
696 }
697 
699 {
700  if (mHasMax) {
701  return QVariant(mMax);
702  }
703  return QVariant();
704 }
705 
707 {
708  mHasMin = true;
709  mMin = v;
710 }
711 
713 {
714  mHasMax = true;
715  mMax = v;
716 }
717 
718 KCoreConfigSkeleton::ItemULongLong::ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue)
719  : KConfigSkeletonGenericItem<quint64>(_group, _key, reference, defaultValue)
720  , mHasMin(false)
721  , mHasMax(false)
722 {
723 }
724 
726 {
727  KConfigGroup cg = configGroup(config);
728  mReference = cg.readEntry(mKey, mDefault);
729  if (mHasMin) {
730  mReference = qMax(mReference, mMin);
731  }
732  if (mHasMax) {
733  mReference = qMin(mReference, mMax);
734  }
735  mLoadedValue = mReference;
736 
737  readImmutability(cg);
738 }
739 
741 {
742  mReference = p.toULongLong();
743 }
744 
746 {
747  return mReference == v.toULongLong();
748 }
749 
751 {
752  return QVariant(mReference);
753 }
754 
756 {
757  if (mHasMin) {
758  return QVariant(mMin);
759  }
760  return QVariant();
761 }
762 
764 {
765  if (mHasMax) {
766  return QVariant(mMax);
767  }
768  return QVariant();
769 }
770 
772 {
773  mHasMin = true;
774  mMin = v;
775 }
776 
778 {
779  mHasMax = true;
780  mMax = v;
781 }
782 
783 KCoreConfigSkeleton::ItemDouble::ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue)
784  : KConfigSkeletonGenericItem<double>(_group, _key, reference, defaultValue)
785  , mHasMin(false)
786  , mHasMax(false)
787 {
788 }
789 
791 {
792  KConfigGroup cg = configGroup(config);
793  mReference = cg.readEntry(mKey, mDefault);
794  if (mHasMin) {
795  mReference = qMax(mReference, mMin);
796  }
797  if (mHasMax) {
798  mReference = qMin(mReference, mMax);
799  }
800  mLoadedValue = mReference;
801 
802  readImmutability(cg);
803 }
804 
806 {
807  mReference = p.toDouble();
808 }
809 
811 {
812  return mReference == v.toDouble();
813 }
814 
816 {
817  return QVariant(mReference);
818 }
819 
821 {
822  if (mHasMin) {
823  return QVariant(mMin);
824  }
825  return QVariant();
826 }
827 
829 {
830  if (mHasMax) {
831  return QVariant(mMax);
832  }
833  return QVariant();
834 }
835 
837 {
838  mHasMin = true;
839  mMin = v;
840 }
841 
843 {
844  mHasMax = true;
845  mMax = v;
846 }
847 
848 KCoreConfigSkeleton::ItemRect::ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue)
849  : KConfigSkeletonGenericItem<QRect>(_group, _key, reference, defaultValue)
850 {
851 }
852 
854 {
855  KConfigGroup cg = configGroup(config);
856  mReference = cg.readEntry(mKey, mDefault);
857  mLoadedValue = mReference;
858 
859  readImmutability(cg);
860 }
861 
863 {
864  mReference = p.toRect();
865 }
866 
868 {
869  return mReference == v.toRect();
870 }
871 
873 {
874  return QVariant(mReference);
875 }
876 
877 KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue)
878  : KConfigSkeletonGenericItem<QPoint>(_group, _key, reference, defaultValue)
879 {
880 }
881 
883 {
884  KConfigGroup cg = configGroup(config);
885  mReference = cg.readEntry(mKey, mDefault);
886  mLoadedValue = mReference;
887 
888  readImmutability(cg);
889 }
890 
892 {
893  mReference = p.toPoint();
894 }
895 
897 {
898  return mReference == v.toPoint();
899 }
900 
902 {
903  return QVariant(mReference);
904 }
905 
906 KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue)
907  : KConfigSkeletonGenericItem<QSize>(_group, _key, reference, defaultValue)
908 {
909 }
910 
912 {
913  KConfigGroup cg = configGroup(config);
914  mReference = cg.readEntry(mKey, mDefault);
915  mLoadedValue = mReference;
916 
917  readImmutability(cg);
918 }
919 
921 {
922  mReference = p.toSize();
923 }
924 
926 {
927  return mReference == v.toSize();
928 }
929 
931 {
932  return QVariant(mReference);
933 }
934 
935 KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue)
936  : KConfigSkeletonGenericItem<QDateTime>(_group, _key, reference, defaultValue)
937 {
938 }
939 
941 {
942  KConfigGroup cg = configGroup(config);
943  mReference = cg.readEntry(mKey, mDefault);
944  mLoadedValue = mReference;
945 
946  readImmutability(cg);
947 }
948 
950 {
951  mReference = p.toDateTime();
952 }
953 
955 {
956  return mReference == v.toDateTime();
957 }
958 
960 {
961  return QVariant(mReference);
962 }
963 
964 KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
965  : KConfigSkeletonGenericItem<QStringList>(_group, _key, reference, defaultValue)
966 {
967 }
968 
970 {
971  KConfigGroup cg = configGroup(config);
972  if (!cg.hasKey(mKey)) {
973  mReference = mDefault;
974  } else {
975  mReference = cg.readEntry(mKey, mDefault);
976  }
977  mLoadedValue = mReference;
978 
979  readImmutability(cg);
980 }
981 
983 {
984  mReference = p.toStringList();
985 }
986 
988 {
989  return mReference == v.toStringList();
990 }
991 
993 {
994  return QVariant(mReference);
995 }
996 
997 KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
998  : ItemStringList(_group, _key, reference, defaultValue)
999 {
1000 }
1001 
1003 {
1004  KConfigGroup cg = configGroup(config);
1005  if (!cg.hasKey(mKey)) {
1006  mReference = mDefault;
1007  } else {
1008  mReference = cg.readPathEntry(mKey, QStringList());
1009  }
1010  mLoadedValue = mReference;
1011 
1012  readImmutability(cg);
1013 }
1014 
1016 {
1017  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1018  KConfigGroup cg = configGroup(config);
1019  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1020  cg.revertToDefault(mKey, writeFlags());
1021  } else {
1022  QStringList sl = mReference;
1023  cg.writePathEntry(mKey, sl, writeFlags());
1024  }
1025  mLoadedValue = mReference;
1026  }
1027 }
1028 
1029 KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue)
1030  : KConfigSkeletonGenericItem<QList<QUrl>>(_group, _key, reference, defaultValue)
1031 {
1032 }
1033 
1035 {
1036  KConfigGroup cg = configGroup(config);
1037  if (!cg.hasKey(mKey)) {
1038  mReference = mDefault;
1039  } else {
1040  QStringList strList;
1041  for (const QUrl &url : std::as_const(mDefault)) {
1042  strList.append(url.toString());
1043  }
1044  mReference.clear();
1045  const QStringList readList = cg.readEntry<QStringList>(mKey, strList);
1046  for (const QString &str : readList) {
1047  mReference.append(QUrl(str));
1048  }
1049  }
1050  mLoadedValue = mReference;
1051 
1052  readImmutability(cg);
1053 }
1054 
1056 {
1057  if (mReference != mLoadedValue) { // WABA: Is this test needed?
1058  KConfigGroup cg = configGroup(config);
1059  if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1060  cg.revertToDefault(mKey, writeFlags());
1061  } else {
1062  QStringList strList;
1063  for (const QUrl &url : std::as_const(mReference)) {
1064  strList.append(url.toString());
1065  }
1066  cg.writeEntry<QStringList>(mKey, strList, writeFlags());
1067  }
1068  mLoadedValue = mReference;
1069  }
1070 }
1071 
1073 {
1074  mReference = qvariant_cast<QList<QUrl>>(p);
1075 }
1076 
1078 {
1079  return mReference == qvariant_cast<QList<QUrl>>(v);
1080 }
1081 
1083 {
1084  return QVariant::fromValue<QList<QUrl>>(mReference);
1085 }
1086 
1087 KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue)
1088  : KConfigSkeletonGenericItem<QList<int>>(_group, _key, reference, defaultValue)
1089 {
1090 }
1091 
1093 {
1094  KConfigGroup cg = configGroup(config);
1095  if (!cg.hasKey(mKey)) {
1096  mReference = mDefault;
1097  } else {
1098  mReference = cg.readEntry(mKey, mDefault);
1099  }
1100  mLoadedValue = mReference;
1101 
1102  readImmutability(cg);
1103 }
1104 
1106 {
1107  mReference = qvariant_cast<QList<int>>(p);
1108 }
1109 
1111 {
1112  return mReference == qvariant_cast<QList<int>>(v);
1113 }
1114 
1116 {
1117  return QVariant::fromValue<QList<int>>(mReference);
1118 }
1119 
1120 // static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; }
1121 
1123  : QObject(parent)
1124  , d(new KCoreConfigSkeletonPrivate)
1125 {
1126  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1127 
1128  d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig);
1129 }
1130 
1132  : QObject(parent)
1133  , d(new KCoreConfigSkeletonPrivate)
1134 {
1135  // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1136  d->mConfig = std::move(pConfig);
1137 }
1138 
1140 {
1141  delete d;
1142 }
1143 
1145 {
1146  d->mCurrentGroup = group;
1147 }
1148 
1150 {
1151  return d->mCurrentGroup;
1152 }
1153 
1155 {
1156  return d->mConfig.data();
1157 }
1158 
1159 const KConfig *KCoreConfigSkeleton::config() const
1160 {
1161  return d->mConfig.data();
1162 }
1163 
1165 {
1166  return d->mConfig;
1167 }
1168 
1170 {
1171  d->mConfig = std::move(pConfig);
1172 }
1173 
1175 {
1176  return d->mItems;
1177 }
1178 
1180 {
1181  if (b == d->mUseDefaults) {
1182  return d->mUseDefaults;
1183  }
1184 
1185  d->mUseDefaults = b;
1186  for (auto *skelItem : std::as_const(d->mItems)) {
1187  skelItem->swapDefault();
1188  }
1189 
1190  usrUseDefaults(b);
1191  return !d->mUseDefaults;
1192 }
1193 
1195 {
1196  for (auto *skelItem : std::as_const(d->mItems)) {
1197  skelItem->setDefault();
1198  }
1199  usrSetDefaults();
1200 }
1201 
1203 {
1204  d->mConfig->reparseConfiguration();
1205  read();
1206 }
1207 
1209 {
1210  for (auto *skelItem : std::as_const(d->mItems)) {
1211  skelItem->readConfig(d->mConfig.data());
1212  }
1213  usrRead();
1214 }
1215 
1217 {
1218  return std::all_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1219  return skelItem->isDefault();
1220  });
1221 }
1222 
1224 {
1225  return std::any_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1226  return skelItem->isSaveNeeded();
1227  });
1228 }
1229 
1231 {
1232  // qDebug();
1233  for (auto *skelItem : std::as_const(d->mItems)) {
1234  skelItem->writeConfig(d->mConfig.data());
1235  }
1236 
1237  if (!usrSave()) {
1238  return false;
1239  }
1240 
1241  if (d->mConfig->isDirty()) {
1242  if (!d->mConfig->sync()) {
1243  return false;
1244  }
1246  }
1247  return true;
1248 }
1249 
1251 {
1252  return false;
1253 }
1254 
1256 {
1257 }
1258 
1260 {
1261 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1262  usrReadConfig();
1263 #endif
1264 }
1265 
1266 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1268 {
1269 }
1270 #endif
1271 
1273 {
1274 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1275  return usrWriteConfig();
1276 #else
1277  return true;
1278 #endif
1279 }
1280 
1281 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1283 {
1284  return true;
1285 }
1286 #endif
1287 
1289 {
1290  if (d->mItems.contains(item)) {
1291  if (item->name() == name || (name.isEmpty() && item->name() == item->key())) {
1292  // nothing to do -> it is already in our collection
1293  // and the name isn't changing
1294  return;
1295  }
1296 
1297  d->mItemDict.remove(item->name());
1298  } else {
1299  d->mItems.append(item);
1300  }
1301 
1302  item->setName(name.isEmpty() ? item->key() : name);
1303  d->mItemDict.insert(item->name(), item);
1304  item->readDefault(d->mConfig.data());
1305  item->readConfig(d->mConfig.data());
1306 }
1307 
1309 {
1310  KConfigSkeletonItem *item = d->mItemDict.value(name);
1311  if (item) {
1312  d->mItems.removeAll(item);
1313  d->mItemDict.remove(item->name());
1314  delete item;
1315  }
1316 }
1317 
1319 {
1320  KConfigSkeletonItem::List items = d->mItems;
1321  d->mItems.clear();
1322  d->mItemDict.clear();
1323  qDeleteAll(items);
1324 }
1325 
1326 KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1327 {
1329  item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, reference, defaultValue, KCoreConfigSkeleton::ItemString::Normal);
1330  addItem(item, name);
1331  return item;
1332 }
1333 
1335 KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1336 {
1338  item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1339  addItem(item, name);
1340  return item;
1341 }
1342 
1343 KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1344 {
1346  item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1347  addItem(item, name);
1348  return item;
1349 }
1350 
1352 KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key)
1353 {
1355  item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1356  addItem(item, name);
1357  return item;
1358 }
1359 
1360 KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, bool defaultValue, const QString &key)
1361 {
1363  item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1364  addItem(item, name);
1365  return item;
1366 }
1367 
1368 KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, qint32 defaultValue, const QString &key)
1369 {
1371  item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1372  addItem(item, name);
1373  return item;
1374 }
1375 
1376 KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue, const QString &key)
1377 {
1379  item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1380  addItem(item, name);
1381  return item;
1382 }
1383 
1384 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1385 {
1387  item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1388  addItem(item, name);
1389  return item;
1390 }
1391 
1392 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1393 KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1394 {
1395  return addItemLongLong(name, reference, defaultValue, key);
1396 }
1397 #endif
1398 
1399 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1400 {
1402  item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1403  addItem(item, name);
1404  return item;
1405 }
1406 
1407 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1408 KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1409 {
1410  return addItemULongLong(name, reference, defaultValue, key);
1411 }
1412 #endif
1413 
1414 KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, double defaultValue, const QString &key)
1415 {
1417  item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1418  addItem(item, name);
1419  return item;
1420 }
1421 
1422 KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, const QRect &defaultValue, const QString &key)
1423 {
1425  item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1426  addItem(item, name);
1427  return item;
1428 }
1429 
1430 KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue, const QString &key)
1431 {
1433  item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1434  addItem(item, name);
1435  return item;
1436 }
1437 
1438 KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, const QSize &defaultValue, const QString &key)
1439 {
1441  item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1442  addItem(item, name);
1443  return item;
1444 }
1445 
1447 KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key)
1448 {
1450  item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1451  addItem(item, name);
1452  return item;
1453 }
1454 
1456 KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key)
1457 {
1459  item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1460  addItem(item, name);
1461  return item;
1462 }
1463 
1465 KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key)
1466 {
1468  item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1469  addItem(item, name);
1470  return item;
1471 }
1472 
1474 {
1475  KConfigSkeletonItem *item = findItem(name);
1476  return !item || item->isImmutable();
1477 }
1478 
1480 {
1481  return d->mItemDict.value(name);
1482 }
1483 
1485  QObject *object,
1486  KConfigCompilerSignallingItem::NotifyFunction targetFunction,
1487  quint64 userData)
1488  : KConfigSkeletonItem(item->group(), item->key())
1489  , mItem(item)
1490  , mTargetFunction(targetFunction)
1491  , mObject(object)
1492  , mUserData(userData)
1493 {
1494  Q_ASSERT(mTargetFunction);
1495  Q_ASSERT(mItem);
1496  Q_ASSERT(mObject);
1497 
1498  setIsDefaultImpl([this] {
1499  return mItem->isDefault();
1500  });
1501  setIsSaveNeededImpl([this] {
1502  return mItem->isSaveNeeded();
1503  });
1504  setGetDefaultImpl([this] {
1505  return mItem->getDefault();
1506  });
1507 }
1508 
1509 KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem()
1510 {
1511 }
1512 
1514 {
1515  return mItem->isEqual(p);
1516 }
1517 
1519 {
1520  return mItem->property();
1521 }
1522 
1524 {
1525  QVariant oldValue = mItem->property();
1526  mItem->readConfig(c);
1527  // readConfig() changes mIsImmutable, update it here as well
1528  KConfigGroup cg = configGroup(c);
1529  readImmutability(cg);
1530  if (!mItem->isEqual(oldValue)) {
1531  invokeNotifyFunction();
1532  }
1533 }
1534 
1536 {
1537  mItem->readDefault(c);
1538  // readDefault() changes mIsImmutable, update it here as well
1539  KConfigGroup cg = configGroup(c);
1540  readImmutability(cg);
1541 }
1542 
1544 {
1545  mItem->writeConfig(c);
1546 }
1547 
1549 {
1550  QVariant oldValue = mItem->property();
1551  mItem->setDefault();
1552  if (!mItem->isEqual(oldValue)) {
1553  invokeNotifyFunction();
1554  }
1555 }
1556 
1558 {
1559  if (!mItem->isEqual(p)) {
1560  mItem->setProperty(p);
1561  invokeNotifyFunction();
1562  }
1563 }
1564 
1566 {
1567  QVariant oldValue = mItem->property();
1568  mItem->swapDefault();
1569  if (!mItem->isEqual(oldValue)) {
1570  invokeNotifyFunction();
1571  }
1572 }
1573 
1574 void KConfigCompilerSignallingItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
1575 {
1576  mItem->setWriteFlags(flags);
1577 }
1578 
1579 KConfigBase::WriteConfigFlags KConfigCompilerSignallingItem::writeFlags() const
1580 {
1581  return mItem->writeFlags();
1582 }
1583 
1584 void KConfigCompilerSignallingItem::setGroup(const KConfigGroup &cg)
1585 {
1586  mItem->setGroup(cg);
1587 }
1588 
1589 KConfigGroup KConfigCompilerSignallingItem::configGroup(KConfig *config) const
1590 {
1591  return mItem->configGroup(config);
1592 }
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.
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.
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.
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-2022 The KDE developers.
Generated on Mon Jul 4 2022 04:09:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.