KConfig

kcoreconfigskeleton.cpp
1/*
2 This file is part of KOrganizer.
3 SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org>
4 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
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
16static 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
29KConfigSkeletonItemPrivate::~KConfigSkeletonItemPrivate() = default;
30
32 : mGroup(_group)
33 , mKey(_key)
34 , d_ptr(new KConfigSkeletonItemPrivate)
35{
36}
37
38KConfigSkeletonItem::KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key)
39 : mGroup(_group)
40 , mKey(_key)
41 , d_ptr(&dd)
42{
43}
44
49
51{
52 mGroup = _group;
53}
54
56{
58 d->mConfigGroup = cg;
59}
60
62{
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{
104 return d->mLabel;
105}
106
108{
110 d->mToolTip = t;
111}
112
114{
116 return d->mToolTip;
117}
118
120{
122 d->mWhatsThis = w;
123}
124
126{
128 return d->mWhatsThis;
129}
130
132{
134 d->mWriteFlags = flags;
135}
136
138{
140 return d->mWriteFlags;
141}
142
144{
145 return QVariant();
146}
147
149{
150 return QVariant();
151}
152
154{
156 return d->mIsImmutable;
157}
158
160{
162 return d->mIsDefaultImpl();
163}
164
166{
168 return d->mIsSaveNeededImpl();
169}
170
172{
174 return d->mGetDefaultImpl();
175}
176
178{
180 d->mIsImmutable = group.isEntryImmutable(mKey);
181}
182
183void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool()> &impl)
184{
186 d->mIsDefaultImpl = impl;
187}
188
189void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool()> &impl)
190{
192 d->mIsSaveNeededImpl = impl;
193}
194
195void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant()> &impl)
196{
198 d->mGetDefaultImpl = impl;
199}
200
201KPropertySkeletonItem::KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
202 : KConfigSkeletonItem(*new KPropertySkeletonItemPrivate(object, propertyName, defaultValue), {}, {})
203{
204 setIsDefaultImpl([this] {
206 return d->mReference == d->mDefaultValue;
207 });
208 setIsSaveNeededImpl([this] {
210 return d->mReference != d->mLoadedValue;
211 });
212 setGetDefaultImpl([this] {
214 return d->mDefaultValue;
215 });
216}
217
219{
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{
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
280void KPropertySkeletonItem::setNotifyFunction(const std::function<void()> &impl)
281{
283 d->mNotifyFunction = impl;
284}
285
286KCoreConfigSkeleton::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
342KCoreConfigSkeleton::ItemPassword::ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
343 : ItemString(_group, _key, reference, defaultValue, Password)
344{
345}
346
347KCoreConfigSkeleton::ItemPath::ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue)
348 : ItemString(_group, _key, reference, defaultValue, Path)
349{
350}
351
352KCoreConfigSkeleton::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
394
395KCoreConfigSkeleton::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
425KCoreConfigSkeleton::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
454KCoreConfigSkeleton::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
519KCoreConfigSkeleton::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 for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it) {
587 if (it->name == name) {
588 return it->value.isEmpty() ? it->name : it->value;
589 }
590 }
591 return name;
592}
593
595{
596 for (auto it = mChoices.begin(); it != mChoices.end(); ++it) {
597 if (it->name == name) {
598 it->value = value;
599 return;
600 }
601 }
602}
603
604KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue)
605 : ItemInt(_group, _key, reference, defaultValue)
606 , mChoices(choices)
607{
608}
609
611{
612 KConfigGroup cg = configGroup(config);
613 if (!cg.hasKey(mKey)) {
614 mReference = mDefault;
615 } else {
616 int i = 0;
617 mReference = -1;
618 const QString entryString = cg.readEntry(mKey, QString());
619 for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {
620 QString choiceName = (*it).name;
621 if (valueForChoice(choiceName).compare(entryString, Qt::CaseInsensitive) == 0) {
622 mReference = i;
623 break;
624 }
625 }
626 if (mReference == -1) {
627 mReference = cg.readEntry(mKey, mDefault);
628 }
629 }
630 mLoadedValue = mReference;
631
632 readImmutability(cg);
633}
634
636{
637 if (mReference != mLoadedValue) { // WABA: Is this test needed?
638 KConfigGroup cg = configGroup(config);
639 if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
640 cg.revertToDefault(mKey, writeFlags());
641 } else if ((mReference >= 0) && (mReference < mChoices.count())) {
642 cg.writeEntry(mKey, valueForChoice(mChoices.at(mReference).name), writeFlags());
643 } else {
644 cg.writeEntry(mKey, mReference, writeFlags());
645 }
646 mLoadedValue = mReference;
647 }
648}
649
650QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choices() const
651{
652 return mChoices;
653}
654
655KCoreConfigSkeleton::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
720KCoreConfigSkeleton::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
785KCoreConfigSkeleton::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
850KCoreConfigSkeleton::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
879KCoreConfigSkeleton::ItemRectF::ItemRectF(const QString &_group, const QString &_key, QRectF &reference, const QRectF &defaultValue)
880 : KConfigSkeletonGenericItem<QRectF>(_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.toRectF();
896}
897
899{
900 return mReference == v.toRectF();
901}
902
904{
905 return QVariant(mReference);
906}
907
908KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue)
909 : KConfigSkeletonGenericItem<QPoint>(_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.toPoint();
925}
926
928{
929 return mReference == v.toPoint();
930}
931
933{
934 return QVariant(mReference);
935}
936
937KCoreConfigSkeleton::ItemPointF::ItemPointF(const QString &_group, const QString &_key, QPointF &reference, const QPointF &defaultValue)
938 : KConfigSkeletonGenericItem<QPointF>(_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.toPointF();
954}
955
957{
958 return mReference == v.toPointF();
959}
960
962{
963 return QVariant(mReference);
964}
965
966KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue)
967 : KConfigSkeletonGenericItem<QSize>(_group, _key, reference, defaultValue)
968{
969}
970
972{
973 KConfigGroup cg = configGroup(config);
974 mReference = cg.readEntry(mKey, mDefault);
975 mLoadedValue = mReference;
976
977 readImmutability(cg);
978}
979
981{
982 mReference = p.toSize();
983}
984
986{
987 return mReference == v.toSize();
988}
989
991{
992 return QVariant(mReference);
993}
994
995KCoreConfigSkeleton::ItemSizeF::ItemSizeF(const QString &_group, const QString &_key, QSizeF &reference, const QSizeF &defaultValue)
996 : KConfigSkeletonGenericItem<QSizeF>(_group, _key, reference, defaultValue)
997{
998}
999
1001{
1002 KConfigGroup cg = configGroup(config);
1003 mReference = cg.readEntry(mKey, mDefault);
1004 mLoadedValue = mReference;
1005
1006 readImmutability(cg);
1007}
1008
1010{
1011 mReference = p.toSizeF();
1012}
1013
1015{
1016 return mReference == v.toSizeF();
1017}
1018
1020{
1021 return QVariant(mReference);
1022}
1023
1024KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue)
1025 : KConfigSkeletonGenericItem<QDateTime>(_group, _key, reference, defaultValue)
1026{
1027}
1028
1030{
1031 KConfigGroup cg = configGroup(config);
1032 mReference = cg.readEntry(mKey, mDefault);
1033 mLoadedValue = mReference;
1034
1035 readImmutability(cg);
1036}
1037
1039{
1040 mReference = p.toDateTime();
1041}
1042
1044{
1045 return mReference == v.toDateTime();
1046}
1047
1049{
1050 return QVariant(mReference);
1051}
1052
1053KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
1054 : KConfigSkeletonGenericItem<QStringList>(_group, _key, reference, defaultValue)
1055{
1056}
1057
1059{
1060 KConfigGroup cg = configGroup(config);
1061 if (!cg.hasKey(mKey)) {
1062 mReference = mDefault;
1063 } else {
1064 mReference = cg.readEntry(mKey, mDefault);
1065 }
1066 mLoadedValue = mReference;
1067
1068 readImmutability(cg);
1069}
1070
1072{
1073 mReference = p.toStringList();
1074}
1075
1077{
1078 return mReference == v.toStringList();
1079}
1080
1082{
1083 return QVariant(mReference);
1084}
1085
1086KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue)
1087 : ItemStringList(_group, _key, reference, defaultValue)
1088{
1089}
1090
1092{
1093 KConfigGroup cg = configGroup(config);
1094 if (!cg.hasKey(mKey)) {
1095 mReference = mDefault;
1096 } else {
1097 mReference = cg.readPathEntry(mKey, QStringList());
1098 }
1099 mLoadedValue = mReference;
1100
1101 readImmutability(cg);
1102}
1103
1105{
1106 if (mReference != mLoadedValue) { // WABA: Is this test needed?
1107 KConfigGroup cg = configGroup(config);
1108 if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1109 cg.revertToDefault(mKey, writeFlags());
1110 } else {
1111 QStringList sl = mReference;
1112 cg.writePathEntry(mKey, sl, writeFlags());
1113 }
1114 mLoadedValue = mReference;
1115 }
1116}
1117
1118KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue)
1119 : KConfigSkeletonGenericItem<QList<QUrl>>(_group, _key, reference, defaultValue)
1120{
1121}
1122
1124{
1125 KConfigGroup cg = configGroup(config);
1126 if (!cg.hasKey(mKey)) {
1127 mReference = mDefault;
1128 } else {
1129 QStringList strList;
1130 for (const QUrl &url : std::as_const(mDefault)) {
1131 strList.append(url.toString());
1132 }
1133 mReference.clear();
1134 const QStringList readList = cg.readEntry<QStringList>(mKey, strList);
1135 for (const QString &str : readList) {
1136 mReference.append(QUrl(str));
1137 }
1138 }
1139 mLoadedValue = mReference;
1140
1141 readImmutability(cg);
1142}
1143
1145{
1146 if (mReference != mLoadedValue) { // WABA: Is this test needed?
1147 KConfigGroup cg = configGroup(config);
1148 if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
1149 cg.revertToDefault(mKey, writeFlags());
1150 } else {
1151 QStringList strList;
1152 for (const QUrl &url : std::as_const(mReference)) {
1153 strList.append(url.toString());
1154 }
1155 cg.writeEntry<QStringList>(mKey, strList, writeFlags());
1156 }
1157 mLoadedValue = mReference;
1158 }
1159}
1160
1162{
1163 mReference = qvariant_cast<QList<QUrl>>(p);
1164}
1165
1167{
1168 return mReference == qvariant_cast<QList<QUrl>>(v);
1169}
1170
1175
1176KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue)
1177 : KConfigSkeletonGenericItem<QList<int>>(_group, _key, reference, defaultValue)
1178{
1179}
1180
1182{
1183 KConfigGroup cg = configGroup(config);
1184 if (!cg.hasKey(mKey)) {
1185 mReference = mDefault;
1186 } else {
1187 mReference = cg.readEntry(mKey, mDefault);
1188 }
1189 mLoadedValue = mReference;
1190
1191 readImmutability(cg);
1192}
1193
1195{
1196 mReference = qvariant_cast<QList<int>>(p);
1197}
1198
1200{
1201 return mReference == qvariant_cast<QList<int>>(v);
1202}
1203
1208
1209// static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; }
1210
1212 : QObject(parent)
1213 , d(new KCoreConfigSkeletonPrivate)
1214{
1215 // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1216
1217 d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig);
1218}
1219
1221 : QObject(parent)
1222 , d(new KCoreConfigSkeletonPrivate)
1223{
1224 // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1225 d->mConfig = std::move(pConfig);
1226}
1227
1232
1234{
1235 d->mCurrentGroup = group;
1236}
1237
1239{
1240 return d->mCurrentGroup;
1241}
1242
1244{
1245 return d->mConfig.data();
1246}
1247
1249{
1250 return d->mConfig.data();
1251}
1252
1254{
1255 return d->mConfig;
1256}
1257
1259{
1260 d->mConfig = std::move(pConfig);
1261}
1262
1264{
1265 return d->mItems;
1266}
1267
1269{
1270 if (b == d->mUseDefaults) {
1271 return d->mUseDefaults;
1272 }
1273
1274 d->mUseDefaults = b;
1275 for (auto *skelItem : std::as_const(d->mItems)) {
1276 skelItem->swapDefault();
1277 }
1278
1279 usrUseDefaults(b);
1280 return !d->mUseDefaults;
1281}
1282
1284{
1285 for (auto *skelItem : std::as_const(d->mItems)) {
1286 skelItem->setDefault();
1287 }
1289}
1290
1292{
1293 d->mConfig->reparseConfiguration();
1294 read();
1295}
1296
1298{
1299 for (auto *skelItem : std::as_const(d->mItems)) {
1300 skelItem->readConfig(d->mConfig.data());
1301 }
1302 usrRead();
1303}
1304
1306{
1307 return std::all_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1308 return skelItem->isDefault();
1309 });
1310}
1311
1313{
1314 return std::any_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) {
1315 return skelItem->isSaveNeeded();
1316 });
1317}
1318
1320{
1321 // qDebug();
1322 for (auto *skelItem : std::as_const(d->mItems)) {
1323 skelItem->writeConfig(d->mConfig.data());
1324 }
1325
1326 if (!usrSave()) {
1327 return false;
1328 }
1329
1330 if (d->mConfig->isDirty()) {
1331 if (!d->mConfig->sync()) {
1332 return false;
1333 }
1335 }
1336 return true;
1337}
1338
1340{
1341 return false;
1342}
1343
1347
1351
1353{
1354 return true;
1355}
1356
1358{
1359 if (d->mItems.contains(item)) {
1360 if (item->name() == name || (name.isEmpty() && item->name() == item->key())) {
1361 // nothing to do -> it is already in our collection
1362 // and the name isn't changing
1363 return;
1364 }
1365
1366 d->mItemDict.remove(item->name());
1367 } else {
1368 d->mItems.append(item);
1369 }
1370
1371 item->setName(name.isEmpty() ? item->key() : name);
1372 d->mItemDict.insert(item->name(), item);
1373 item->readDefault(d->mConfig.data());
1374 item->readConfig(d->mConfig.data());
1375}
1376
1378{
1379 KConfigSkeletonItem *item = d->mItemDict.value(name);
1380 if (item) {
1381 d->mItems.removeAll(item);
1382 d->mItemDict.remove(item->name());
1383 delete item;
1384 }
1385}
1386
1388{
1389 KConfigSkeletonItem::List items = d->mItems;
1390 d->mItems.clear();
1391 d->mItemDict.clear();
1392 qDeleteAll(items);
1393}
1394
1396{
1398 item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, reference, defaultValue, KCoreConfigSkeleton::ItemString::Normal);
1399 addItem(item, name);
1400 return item;
1401}
1402
1404KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1405{
1407 item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1408 addItem(item, name);
1409 return item;
1410}
1411
1412KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1413{
1415 item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1416 addItem(item, name);
1417 return item;
1418}
1419
1421KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key)
1422{
1424 item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1425 addItem(item, name);
1426 return item;
1427}
1428
1429KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, bool defaultValue, const QString &key)
1430{
1432 item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1433 addItem(item, name);
1434 return item;
1435}
1436
1437KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, qint32 defaultValue, const QString &key)
1438{
1440 item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1441 addItem(item, name);
1442 return item;
1443}
1444
1445KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue, const QString &key)
1446{
1448 item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1449 addItem(item, name);
1450 return item;
1451}
1452
1453KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key)
1454{
1456 item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1457 addItem(item, name);
1458 return item;
1459}
1460
1461KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key)
1462{
1464 item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1465 addItem(item, name);
1466 return item;
1467}
1468
1469KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, double defaultValue, const QString &key)
1470{
1472 item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1473 addItem(item, name);
1474 return item;
1475}
1476
1477KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, const QRect &defaultValue, const QString &key)
1478{
1480 item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1481 addItem(item, name);
1482 return item;
1483}
1484
1485KCoreConfigSkeleton::ItemRectF *KCoreConfigSkeleton::addItemRectF(const QString &name, QRectF &reference, const QRectF &defaultValue, const QString &key)
1486{
1488 item = new KCoreConfigSkeleton::ItemRectF(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1489 addItem(item, name);
1490 return item;
1491}
1492
1493KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue, const QString &key)
1494{
1496 item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1497 addItem(item, name);
1498 return item;
1499}
1500
1502{
1504 item = new KCoreConfigSkeleton::ItemPointF(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1505 addItem(item, name);
1506 return item;
1507}
1508
1509KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, const QSize &defaultValue, const QString &key)
1510{
1512 item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1513 addItem(item, name);
1514 return item;
1515}
1516
1517KCoreConfigSkeleton::ItemSizeF *KCoreConfigSkeleton::addItemSizeF(const QString &name, QSizeF &reference, const QSizeF &defaultValue, const QString &key)
1518{
1520 item = new KCoreConfigSkeleton::ItemSizeF(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1521 addItem(item, name);
1522 return item;
1523}
1524
1526KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key)
1527{
1529 item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1530 addItem(item, name);
1531 return item;
1532}
1533
1535KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key)
1536{
1538 item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1539 addItem(item, name);
1540 return item;
1541}
1542
1544KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key)
1545{
1547 item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1548 addItem(item, name);
1549 return item;
1550}
1551
1553{
1554 KConfigSkeletonItem *item = findItem(name);
1555 return !item || item->isImmutable();
1556}
1557
1559{
1560 return d->mItemDict.value(name);
1561}
1562
1564 QObject *object,
1565 KConfigCompilerSignallingItem::NotifyFunction targetFunction,
1566 quint64 userData)
1567 : KConfigSkeletonItem(item->group(), item->key())
1568 , mItem(item)
1569 , mTargetFunction(targetFunction)
1570 , mObject(object)
1571 , mUserData(userData)
1572{
1573 Q_ASSERT(mTargetFunction);
1574 Q_ASSERT(mItem);
1575 Q_ASSERT(mObject);
1576
1577 setIsDefaultImpl([this] {
1578 return mItem->isDefault();
1579 });
1580 setIsSaveNeededImpl([this] {
1581 return mItem->isSaveNeeded();
1582 });
1583 setGetDefaultImpl([this] {
1584 return mItem->getDefault();
1585 });
1586}
1587
1588KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem()
1589{
1590}
1591
1593{
1594 return mItem->isEqual(p);
1595}
1596
1598{
1599 return mItem->property();
1600}
1601
1603{
1604 return mItem->minValue();
1605}
1606
1608{
1609 return mItem->maxValue();
1610}
1611
1613{
1614 QVariant oldValue = mItem->property();
1615 mItem->readConfig(c);
1616 // readConfig() changes mIsImmutable, update it here as well
1617 KConfigGroup cg = configGroup(c);
1618 readImmutability(cg);
1619 if (!mItem->isEqual(oldValue)) {
1620 invokeNotifyFunction();
1621 }
1622}
1623
1625{
1626 mItem->readDefault(c);
1627 // readDefault() changes mIsImmutable, update it here as well
1628 KConfigGroup cg = configGroup(c);
1629 readImmutability(cg);
1630}
1631
1633{
1634 mItem->writeConfig(c);
1635}
1636
1638{
1639 QVariant oldValue = mItem->property();
1640 mItem->setDefault();
1641 if (!mItem->isEqual(oldValue)) {
1642 invokeNotifyFunction();
1643 }
1644}
1645
1647{
1648 if (!mItem->isEqual(p)) {
1649 mItem->setProperty(p);
1650 invokeNotifyFunction();
1651 }
1652}
1653
1655{
1656 QVariant oldValue = mItem->property();
1657 mItem->swapDefault();
1658 if (!mItem->isEqual(oldValue)) {
1659 invokeNotifyFunction();
1660 }
1661}
1662
1663void KConfigCompilerSignallingItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
1664{
1665 mItem->setWriteFlags(flags);
1666}
1667
1668KConfigBase::WriteConfigFlags KConfigCompilerSignallingItem::writeFlags() const
1669{
1670 return mItem->writeFlags();
1671}
1672
1673void KConfigCompilerSignallingItem::setGroup(const KConfigGroup &cg)
1674{
1675 mItem->setGroup(cg);
1676}
1677
1678KConfigGroup KConfigCompilerSignallingItem::configGroup(KConfig *config) const
1679{
1680 return mItem->configGroup(config);
1681}
1682
1683#include "moc_kcoreconfigskeleton.cpp"
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void readDefault(KConfig *) override
Read global default value.
QVariant maxValue() const override
Return maximum value of item or invalid if not specified.
QVariant minValue() const override
Return minimum value of item or invalid if not specified.
void setDefault() override
Sets the current value to the default value.
void setProperty(const QVariant &p) override
Set item to p.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData)
Constructor.
QVariant property() const override
Return item as property.
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
A class for one specific group in a KConfig object.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
bool hasDefault(const QString &key) const
Whether a default is specified for an entry in either the system wide configuration file or the globa...
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
QString readPathEntry(const QString &pKey, const QString &aDefault) const
Reads a path.
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
Writes a file path to the configuration.
void revertToDefault(const QString &key, WriteConfigFlags pFlag=WriteConfigFlags())
Reverts an entry to the default settings.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
Base class for storing a preferences setting of type T.
Class for storing a preferences setting.
KConfigSkeletonItem(const QString &_group, const QString &_key)
Constructor.
KConfigGroup configGroup(KConfig *config) const
Return a KConfigGroup, the one provided by setGroup(const KConfigGroup&) if it's valid,...
bool isImmutable() const
Return if the entry can be modified.
virtual QVariant minValue() const
Return minimum value of item or invalid if not specified.
QString name() const
Return internal name of entry.
void readImmutability(const KConfigGroup &group)
Sets mIsImmutable to true if mKey in config is immutable.
virtual ~KConfigSkeletonItem()
Destructor.
void setToolTip(const QString &t)
Set ToolTip description of item.
void setWriteFlags(KConfigBase::WriteConfigFlags flags)
The write flags to be used when writing configuration.
QString mKey
The config key for this item.
virtual void readDefault(KConfig *)=0
Read global default value.
QString key() const
Return config file key.
void setGroup(const QString &_group)
Set config file group.
QVariant getDefault() const
Returns the default value.
void setName(const QString &_name)
Set internal name of entry.
void setLabel(const QString &l)
Set label providing a translated one-line description of the item.
QString whatsThis() const
Return WhatsThis description of item.
QString mGroup
The group name for this item.
QString toolTip() const
Return ToolTip description of item.
QString group() const
Return name of config file group.
KConfigBase::WriteConfigFlags writeFlags() const
Return write flags to be used when writing configuration.
void setKey(const QString &_key)
Set config file key.
virtual void readConfig(KConfig *)=0
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QString label() const
Return the label of the item.
virtual QVariant maxValue() const
Return maximum value of item or invalid if not specified.
bool isSaveNeeded() const
Indicates if the item has a different value than the previously loaded value.
void setWhatsThis(const QString &w)
Set WhatsThis description of item.
QString mName
The name of this item.
bool isDefault() const
Indicates if the item is set to its default value.
The central class of the KDE configuration data system.
Definition kconfig.h:56
@ FullConfig
Fully-fledged config, including globals and cascading to system settings.
Definition kconfig.h:88
Class for handling a bool preferences item.
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue=true)
Constructor.
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 a QDateTime preferences item.
void setProperty(const QVariant &p) override
Set item to p.
ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue=QDateTime())
Constructor.
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.
Class for handling a floating point preference item.
QVariant property() const override
Return item as property.
ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue=0)
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void setMinValue(double)
Set the minimum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
void setMaxValue(double)
Set the maximum value for the item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
void setValueForChoice(const QString &name, const QString &valueForChoice)
Stores a choice value for name.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QString valueForChoice(const QString &name) const
Returns the value for the choice with the given name.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList< Choice > &choices, qint32 defaultValue=0)
Constructor.
Class for handling an integer list preferences item.
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemIntList(const QString &_group, const QString &_key, QList< int > &reference, const QList< int > &defaultValue=QList< int >())
Constructor.
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.
Class for handling a 32-bit integer preferences item.
void setMaxValue(qint32)
Set the maximum value for the item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMinValue(qint32)
Set the minimum value for the item.
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.
ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue=0)
Constructor.
QVariant property() const override
Return item as property.
Class for handling a 64-bit integer preferences item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
QVariant property() const override
Return item as property.
void setMaxValue(qint64)
Set the maximum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue=0)
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMinValue(qint64)
Set the minimum value for the item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
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 a password preferences item.
ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""))
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.
ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
Class for handling a path preferences item.
ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QString())
Constructor.
Class for handling a QPointF preferences item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemPointF(const QString &_group, const QString &_key, QPointF &reference, const QPointF &defaultValue=QPointF())
Constructor.
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.
QVariant property() const override
Return item as property.
Class for handling a QPoint preferences item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue=QPoint())
Constructor.
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 a QVariant preferences item.
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.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue=QVariant())
Constructor.
Class for handling a QRectF preferences item.
ItemRectF(const QString &_group, const QString &_key, QRectF &reference, const QRectF &defaultValue=QRectF())
Constructor.
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.
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.
Class for handling a QRect preferences item.
void setProperty(const QVariant &p) override
Set item to p.
ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue=QRect())
Constructor.
QVariant property() const override
Return item as property.
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.
Class for handling a QSizeF preferences item.
ItemSizeF(const QString &_group, const QString &_key, QSizeF &reference, const QSizeF &defaultValue=QSizeF())
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
Class for handling a QSize preferences item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue=QSize())
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for handling a string list preferences item.
ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
Class for handling a string preferences item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Type
The type of string that is held in this item.
QVariant property() const override
Return item as property.
ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""), Type type=Normal)
Constructor.
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.
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 an unsigned 32-bit integer preferences item.
ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue=0)
Constructor.
QVariant property() const override
Return item as property.
void setMinValue(quint32)
Set the minimum value for the item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMaxValue(quint32)
Set the maximum value for the item.
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.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
Class for handling unsigned 64-bit integer preferences item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue=0)
Constructor.
void setMaxValue(quint64)
Set the maximum value for the item.
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.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setMinValue(quint64)
Set the minimum value for the 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.
void setProperty(const QVariant &p) override
Set item to p.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QVariant property() const override
Return item as property.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemUrlList(const QString &_group, const QString &_key, QList< QUrl > &reference, const QList< QUrl > &defaultValue=QList< QUrl >())
Constructor.
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.
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.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue=QUrl())
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemSize * addItemSize(const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString())
Register an item of type QSize.
ItemDouble * addItemDouble(const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString())
Register an item of type double.
ItemLongLong * addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
Register an item of type qint64.
ItemDateTime * addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString())
Register an item of type QDateTime.
void load()
Read preferences from config file.
virtual void usrSetDefaults()
Perform the actual setting of default values.
ItemULongLong * addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
Register an item of type quint64.
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>.
QString currentGroup() const
Returns the current group used for addItem() calls.
void setSharedConfig(KSharedConfig::Ptr pConfig)
Set the KSharedConfig object used for reading and writing the settings.
ItemString * addItemString(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register an item of type QString.
virtual bool usrUseDefaults(bool b)
Implemented by subclasses that use special defaults.
KSharedConfig::Ptr sharedConfig() const
Return the KConfig object used for reading and writing the settings.
void configChanged()
This signal is emitted when the configuration change.
bool isSaveNeeded() const
Indicates if any registered item has a different value than the previously loaded value.
ItemStringList * addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString())
Register an item of type QStringList.
virtual bool usrSave()
Perform the actual writing of the configuration file.
KConfigSkeletonItem * findItem(const QString &name) const
Lookup item by name.
virtual void usrRead()
Perform the actual reading of the configuration file.
ItemPointF * addItemPointF(const QString &name, QPointF &reference, const QPointF &defaultValue=QPointF(), const QString &key=QString())
Register an item of type QPointF.
void removeItem(const QString &name)
Removes and deletes an item by name.
KConfig * config()
Return the KConfig object used for reading and writing the settings.
ItemPath * addItemPath(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a path item of type QString.
KCoreConfigSkeleton(const QString &configname=QString(), QObject *parent=nullptr)
Constructor.
KConfigSkeletonItem::List items() const
Return list of items managed by this KCoreConfigSkeleton object.
void clearItems()
Removes and deletes all items.
ItemPassword * addItemPassword(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a password item of type QString.
Q_INVOKABLE bool isImmutable(const QString &name) const
Return whether a certain item is immutable.
~KCoreConfigSkeleton() override
Destructor.
ItemRectF * addItemRectF(const QString &name, QRectF &reference, const QRectF &defaultValue=QRectF(), const QString &key=QString())
Register an item of type QRectF.
bool save()
Write preferences to config file.
ItemProperty * addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString())
Register a property item of type QVariant.
ItemSizeF * addItemSizeF(const QString &name, QSizeF &reference, const QSizeF &defaultValue=QSizeF(), const QString &key=QString())
Register an item of type QSizeF.
ItemPoint * addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString())
Register an item of type QPoint.
void read()
Read preferences from the KConfig object.
void addItem(KConfigSkeletonItem *item, const QString &name=QString())
Register a custom KConfigSkeletonItem item with a given name.
ItemUInt * addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString())
Register an item of type quint32.
virtual void setDefaults()
Set all registered items to their default values.
ItemInt * addItemInt(const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString())
Register an item of type qint32.
ItemBool * addItemBool(const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString())
Register an item of type bool.
bool isDefaults() const
Indicates if all the registered items are set to their default value.
virtual bool useDefaults(bool b)
Specify whether this object should reflect the actual values or the default values.
void setCurrentGroup(const QString &group)
Set the config file group for subsequent addItem() calls.
ItemRect * addItemRect(const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString())
Register an item of type QRect.
Class for proxying a QObject property as a preferences setting.
bool isEqual(const QVariant &p) const override
void setDefault() override
Sets the current value to the default value.
QVariant property() const override
Return item as property.
KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
Constructor.
void setNotifyFunction(const std::function< void()> &impl)
Set a notify function, it will be invoked when the value of the property changes.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
void setProperty(const QVariant &p) override
Set item to p.
void readDefault(KConfig *) override
Read global default value.
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.
char16_t & unicode()
void append(QList< T > &&value)
void clear()
Q_EMITQ_EMIT
QObject * parent() const const
bool isEmpty() const const
bool isNull() const const
qsizetype length() const const
const QChar * unicode() const const
CaseInsensitive
QVariant fromValue(T &&value)
bool toBool() const const
QDateTime toDateTime() const const
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
QPoint toPoint() const const
QPointF toPointF() const const
QRect toRect() const const
QRectF toRectF() const const
QSize toSize() const const
QSizeF toSizeF() const const
QString toString() const const
QStringList toStringList() const const
uint toUInt(bool *ok) const const
qulonglong toULongLong(bool *ok) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.