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
31KConfigSkeletonItem::KConfigSkeletonItem(const QString &_group, const QString &_key)
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
45KConfigSkeletonItem::~KConfigSkeletonItem()
46{
47 delete d_ptr;
48}
49
50void KConfigSkeletonItem::setGroup(const QString &_group)
51{
52 mGroup = _group;
53}
54
55void KConfigSkeletonItem::setGroup(const KConfigGroup &cg)
56{
57 Q_D(KConfigSkeletonItem);
58 d->mConfigGroup = cg;
59}
60
61KConfigGroup KConfigSkeletonItem::configGroup(KConfig *config) const
62{
63 Q_D(const KConfigSkeletonItem);
64 if (d->mConfigGroup.isValid()) {
65 return d->mConfigGroup;
66 }
67 return KConfigGroup(config, mGroup);
68}
69
70QString KConfigSkeletonItem::group() const
71{
72 return mGroup;
73}
74
75void KConfigSkeletonItem::setKey(const QString &_key)
76{
77 mKey = _key;
78}
79
80QString KConfigSkeletonItem::key() const
81{
82 return mKey;
83}
84
85void KConfigSkeletonItem::setName(const QString &_name)
86{
87 mName = _name;
88}
89
90QString KConfigSkeletonItem::name() const
91{
92 return mName;
93}
94
95void KConfigSkeletonItem::setLabel(const QString &l)
96{
97 Q_D(KConfigSkeletonItem);
98 d->mLabel = l;
99}
100
101QString KConfigSkeletonItem::label() const
102{
103 Q_D(const KConfigSkeletonItem);
104 return d->mLabel;
105}
106
107void KConfigSkeletonItem::setToolTip(const QString &t)
108{
109 Q_D(KConfigSkeletonItem);
110 d->mToolTip = t;
111}
112
113QString KConfigSkeletonItem::toolTip() const
114{
115 Q_D(const KConfigSkeletonItem);
116 return d->mToolTip;
117}
118
119void KConfigSkeletonItem::setWhatsThis(const QString &w)
120{
121 Q_D(KConfigSkeletonItem);
122 d->mWhatsThis = w;
123}
124
125QString KConfigSkeletonItem::whatsThis() const
126{
127 Q_D(const KConfigSkeletonItem);
128 return d->mWhatsThis;
129}
130
131void KConfigSkeletonItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
132{
133 Q_D(KConfigSkeletonItem);
134 d->mWriteFlags = flags;
135}
136
137KConfigBase::WriteConfigFlags KConfigSkeletonItem::writeFlags() const
138{
139 Q_D(const KConfigSkeletonItem);
140 return d->mWriteFlags;
141}
142
143QVariant KConfigSkeletonItem::minValue() const
144{
145 return QVariant();
146}
147
148QVariant KConfigSkeletonItem::maxValue() const
149{
150 return QVariant();
151}
152
153bool KConfigSkeletonItem::isImmutable() const
154{
155 Q_D(const KConfigSkeletonItem);
156 return d->mIsImmutable;
157}
158
159bool KConfigSkeletonItem::isDefault() const
160{
161 Q_D(const KConfigSkeletonItem);
162 return d->mIsDefaultImpl();
163}
164
165bool KConfigSkeletonItem::isSaveNeeded() const
166{
167 Q_D(const KConfigSkeletonItem);
168 return d->mIsSaveNeededImpl();
169}
170
171QVariant KConfigSkeletonItem::getDefault() const
172{
173 Q_D(const KConfigSkeletonItem);
174 return d->mGetDefaultImpl();
175}
176
177void KConfigSkeletonItem::readImmutability(const KConfigGroup &group)
178{
179 Q_D(KConfigSkeletonItem);
180 d->mIsImmutable = group.isEntryImmutable(key: mKey);
181}
182
183void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool()> &impl)
184{
185 Q_D(KConfigSkeletonItem);
186 d->mIsDefaultImpl = impl;
187}
188
189void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool()> &impl)
190{
191 Q_D(KConfigSkeletonItem);
192 d->mIsSaveNeededImpl = impl;
193}
194
195void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant()> &impl)
196{
197 Q_D(KConfigSkeletonItem);
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] {
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
218QVariant KPropertySkeletonItem::property() const
219{
220 Q_D(const KPropertySkeletonItem);
221 return d->mReference;
222}
223
224void KPropertySkeletonItem::setProperty(const QVariant &p)
225{
226 Q_D(KPropertySkeletonItem);
227 if (d->mReference == p) {
228 return;
229 }
230 d->mReference = p;
231 if (d->mNotifyFunction) {
232 d->mNotifyFunction();
233 }
234}
235
236bool KPropertySkeletonItem::isEqual(const QVariant &p) const
237{
238 Q_D(const KPropertySkeletonItem);
239 return d->mReference == p;
240}
241
242void KPropertySkeletonItem::readConfig(KConfig *)
243{
244 Q_D(KPropertySkeletonItem);
245 setProperty(d->mObject->property(name: d->mPropertyName.constData()));
246 d->mLoadedValue = d->mReference;
247}
248
249void KPropertySkeletonItem::writeConfig(KConfig *)
250{
251 Q_D(KPropertySkeletonItem);
252 d->mObject->setProperty(name: d->mPropertyName.constData(), value: d->mReference);
253 d->mLoadedValue = d->mReference;
254}
255
256void KPropertySkeletonItem::readDefault(KConfig *)
257{
258 Q_D(KPropertySkeletonItem);
259 setProperty(d->mConstDefaultValue);
260}
261
262void KPropertySkeletonItem::setDefault()
263{
264 Q_D(KPropertySkeletonItem);
265 setProperty(d->mDefaultValue);
266}
267
268void KPropertySkeletonItem::swapDefault()
269{
270 Q_D(KPropertySkeletonItem);
271 if (d->mReference == d->mDefaultValue) {
272 return;
273 }
274 std::swap(a&: d->mReference, b&: d->mDefaultValue);
275 if (d->mNotifyFunction) {
276 d->mNotifyFunction();
277 }
278}
279
280void KPropertySkeletonItem::setNotifyFunction(const std::function<void()> &impl)
281{
282 Q_D(KPropertySkeletonItem);
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
292void KCoreConfigSkeleton::ItemString::writeConfig(KConfig *config)
293{
294 if (mReference != mLoadedValue) { // WABA: Is this test needed?
295 KConfigGroup cg = configGroup(config);
296 if ((mDefault == mReference) && !cg.hasDefault(key: mKey)) {
297 cg.revertToDefault(key: mKey, pFlag: writeFlags());
298 } else if (mType == Path) {
299 cg.writePathEntry(pKey: mKey, path: mReference, pFlags: writeFlags());
300 } else if (mType == Password) {
301 cg.writeEntry(key: mKey, value: obscuredString(str: mReference), pFlags: writeFlags());
302 } else {
303 cg.writeEntry(key: mKey, value: mReference, pFlags: writeFlags());
304 }
305 mLoadedValue = mReference;
306 }
307}
308
309void KCoreConfigSkeleton::ItemString::readConfig(KConfig *config)
310{
311 KConfigGroup cg = configGroup(config);
312
313 if (mType == Path) {
314 mReference = cg.readPathEntry(pKey: mKey, aDefault: mDefault);
315 } else if (mType == Password) {
316 QString val = cg.readEntry(key: mKey, aDefault: obscuredString(str: mDefault));
317 mReference = obscuredString(str: val);
318 } else {
319 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
320 }
321
322 mLoadedValue = mReference;
323
324 readImmutability(group: cg);
325}
326
327void KCoreConfigSkeleton::ItemString::setProperty(const QVariant &p)
328{
329 mReference = p.toString();
330}
331
332bool KCoreConfigSkeleton::ItemString::isEqual(const QVariant &v) const
333{
334 return mReference == v.toString();
335}
336
337QVariant KCoreConfigSkeleton::ItemString::property() const
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
357void KCoreConfigSkeleton::ItemUrl::writeConfig(KConfig *config)
358{
359 if (mReference != mLoadedValue) { // WABA: Is this test needed?
360 KConfigGroup cg = configGroup(config);
361 if ((mDefault == mReference) && !cg.hasDefault(key: mKey)) {
362 cg.revertToDefault(key: mKey, pFlag: writeFlags());
363 } else {
364 cg.writeEntry<QString>(key: mKey, value: mReference.toString(), pFlags: writeFlags());
365 }
366 mLoadedValue = mReference;
367 }
368}
369
370void KCoreConfigSkeleton::ItemUrl::readConfig(KConfig *config)
371{
372 KConfigGroup cg = configGroup(config);
373
374 mReference = QUrl(cg.readEntry<QString>(key: mKey, aDefault: mDefault.toString()));
375 mLoadedValue = mReference;
376
377 readImmutability(group: cg);
378}
379
380void KCoreConfigSkeleton::ItemUrl::setProperty(const QVariant &p)
381{
382 mReference = qvariant_cast<QUrl>(v: p);
383}
384
385bool KCoreConfigSkeleton::ItemUrl::isEqual(const QVariant &v) const
386{
387 return mReference == qvariant_cast<QUrl>(v);
388}
389
390QVariant KCoreConfigSkeleton::ItemUrl::property() const
391{
392 return QVariant::fromValue<QUrl>(value: mReference);
393}
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
400void KCoreConfigSkeleton::ItemProperty::readConfig(KConfig *config)
401{
402 KConfigGroup cg = configGroup(config);
403 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
404 mLoadedValue = mReference;
405
406 readImmutability(group: cg);
407}
408
409void KCoreConfigSkeleton::ItemProperty::setProperty(const QVariant &p)
410{
411 mReference = p;
412}
413
414bool KCoreConfigSkeleton::ItemProperty::isEqual(const QVariant &v) const
415{
416 // this might cause problems if the QVariants are not of default types
417 return mReference == v;
418}
419
420QVariant KCoreConfigSkeleton::ItemProperty::property() const
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
430void KCoreConfigSkeleton::ItemBool::readConfig(KConfig *config)
431{
432 KConfigGroup cg = configGroup(config);
433 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
434 mLoadedValue = mReference;
435
436 readImmutability(group: cg);
437}
438
439void KCoreConfigSkeleton::ItemBool::setProperty(const QVariant &p)
440{
441 mReference = p.toBool();
442}
443
444bool KCoreConfigSkeleton::ItemBool::isEqual(const QVariant &v) const
445{
446 return mReference == v.toBool();
447}
448
449QVariant KCoreConfigSkeleton::ItemBool::property() const
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
461void KCoreConfigSkeleton::ItemInt::readConfig(KConfig *config)
462{
463 KConfigGroup cg = configGroup(config);
464 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
465 if (mHasMin) {
466 mReference = qMax(a: mReference, b: mMin);
467 }
468 if (mHasMax) {
469 mReference = qMin(a: mReference, b: mMax);
470 }
471 mLoadedValue = mReference;
472
473 readImmutability(group: cg);
474}
475
476void KCoreConfigSkeleton::ItemInt::setProperty(const QVariant &p)
477{
478 mReference = p.toInt();
479}
480
481bool KCoreConfigSkeleton::ItemInt::isEqual(const QVariant &v) const
482{
483 return mReference == v.toInt();
484}
485
486QVariant KCoreConfigSkeleton::ItemInt::property() const
487{
488 return QVariant(mReference);
489}
490
491QVariant KCoreConfigSkeleton::ItemInt::minValue() const
492{
493 if (mHasMin) {
494 return QVariant(mMin);
495 }
496 return QVariant();
497}
498
499QVariant KCoreConfigSkeleton::ItemInt::maxValue() const
500{
501 if (mHasMax) {
502 return QVariant(mMax);
503 }
504 return QVariant();
505}
506
507void KCoreConfigSkeleton::ItemInt::setMinValue(qint32 v)
508{
509 mHasMin = true;
510 mMin = v;
511}
512
513void KCoreConfigSkeleton::ItemInt::setMaxValue(qint32 v)
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
526void KCoreConfigSkeleton::ItemLongLong::readConfig(KConfig *config)
527{
528 KConfigGroup cg = configGroup(config);
529 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
530 if (mHasMin) {
531 mReference = qMax(a: mReference, b: mMin);
532 }
533 if (mHasMax) {
534 mReference = qMin(a: mReference, b: mMax);
535 }
536 mLoadedValue = mReference;
537
538 readImmutability(group: cg);
539}
540
541void KCoreConfigSkeleton::ItemLongLong::setProperty(const QVariant &p)
542{
543 mReference = p.toLongLong();
544}
545
546bool KCoreConfigSkeleton::ItemLongLong::isEqual(const QVariant &v) const
547{
548 return mReference == v.toLongLong();
549}
550
551QVariant KCoreConfigSkeleton::ItemLongLong::property() const
552{
553 return QVariant(mReference);
554}
555
556QVariant KCoreConfigSkeleton::ItemLongLong::minValue() const
557{
558 if (mHasMin) {
559 return QVariant(mMin);
560 }
561 return QVariant();
562}
563
564QVariant KCoreConfigSkeleton::ItemLongLong::maxValue() const
565{
566 if (mHasMax) {
567 return QVariant(mMax);
568 }
569 return QVariant();
570}
571
572void KCoreConfigSkeleton::ItemLongLong::setMinValue(qint64 v)
573{
574 mHasMin = true;
575 mMin = v;
576}
577
578void KCoreConfigSkeleton::ItemLongLong::setMaxValue(qint64 v)
579{
580 mHasMax = true;
581 mMax = v;
582}
583
584QString KCoreConfigSkeleton::ItemEnum::valueForChoice(const QString &name) const
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
594void KCoreConfigSkeleton::ItemEnum::setValueForChoice(const QString &name, const QString &value)
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
610void KCoreConfigSkeleton::ItemEnum::readConfig(KConfig *config)
611{
612 KConfigGroup cg = configGroup(config);
613 if (!cg.hasKey(key: mKey)) {
614 mReference = mDefault;
615 } else {
616 int i = 0;
617 mReference = -1;
618 const QString entryString = cg.readEntry(key: mKey, aDefault: QString());
619 for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {
620 QString choiceName = (*it).name;
621 if (valueForChoice(name: choiceName).compare(s: entryString, cs: Qt::CaseInsensitive) == 0) {
622 mReference = i;
623 break;
624 }
625 }
626 if (mReference == -1) {
627 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
628 }
629 }
630 mLoadedValue = mReference;
631
632 readImmutability(group: cg);
633}
634
635void KCoreConfigSkeleton::ItemEnum::writeConfig(KConfig *config)
636{
637 if (mReference != mLoadedValue) { // WABA: Is this test needed?
638 KConfigGroup cg = configGroup(config);
639 if ((mDefault == mReference) && !cg.hasDefault(key: mKey)) {
640 cg.revertToDefault(key: mKey, pFlag: writeFlags());
641 } else if ((mReference >= 0) && (mReference < mChoices.count())) {
642 cg.writeEntry(key: mKey, value: valueForChoice(name: mChoices.at(i: mReference).name), pFlags: writeFlags());
643 } else {
644 cg.writeEntry(key: mKey, value: mReference, pFlags: 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
662void KCoreConfigSkeleton::ItemUInt::readConfig(KConfig *config)
663{
664 KConfigGroup cg = configGroup(config);
665 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
666 if (mHasMin) {
667 mReference = qMax(a: mReference, b: mMin);
668 }
669 if (mHasMax) {
670 mReference = qMin(a: mReference, b: mMax);
671 }
672 mLoadedValue = mReference;
673
674 readImmutability(group: cg);
675}
676
677void KCoreConfigSkeleton::ItemUInt::setProperty(const QVariant &p)
678{
679 mReference = p.toUInt();
680}
681
682bool KCoreConfigSkeleton::ItemUInt::isEqual(const QVariant &v) const
683{
684 return mReference == v.toUInt();
685}
686
687QVariant KCoreConfigSkeleton::ItemUInt::property() const
688{
689 return QVariant(mReference);
690}
691
692QVariant KCoreConfigSkeleton::ItemUInt::minValue() const
693{
694 if (mHasMin) {
695 return QVariant(mMin);
696 }
697 return QVariant();
698}
699
700QVariant KCoreConfigSkeleton::ItemUInt::maxValue() const
701{
702 if (mHasMax) {
703 return QVariant(mMax);
704 }
705 return QVariant();
706}
707
708void KCoreConfigSkeleton::ItemUInt::setMinValue(quint32 v)
709{
710 mHasMin = true;
711 mMin = v;
712}
713
714void KCoreConfigSkeleton::ItemUInt::setMaxValue(quint32 v)
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
727void KCoreConfigSkeleton::ItemULongLong::readConfig(KConfig *config)
728{
729 KConfigGroup cg = configGroup(config);
730 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
731 if (mHasMin) {
732 mReference = qMax(a: mReference, b: mMin);
733 }
734 if (mHasMax) {
735 mReference = qMin(a: mReference, b: mMax);
736 }
737 mLoadedValue = mReference;
738
739 readImmutability(group: cg);
740}
741
742void KCoreConfigSkeleton::ItemULongLong::setProperty(const QVariant &p)
743{
744 mReference = p.toULongLong();
745}
746
747bool KCoreConfigSkeleton::ItemULongLong::isEqual(const QVariant &v) const
748{
749 return mReference == v.toULongLong();
750}
751
752QVariant KCoreConfigSkeleton::ItemULongLong::property() const
753{
754 return QVariant(mReference);
755}
756
757QVariant KCoreConfigSkeleton::ItemULongLong::minValue() const
758{
759 if (mHasMin) {
760 return QVariant(mMin);
761 }
762 return QVariant();
763}
764
765QVariant KCoreConfigSkeleton::ItemULongLong::maxValue() const
766{
767 if (mHasMax) {
768 return QVariant(mMax);
769 }
770 return QVariant();
771}
772
773void KCoreConfigSkeleton::ItemULongLong::setMinValue(quint64 v)
774{
775 mHasMin = true;
776 mMin = v;
777}
778
779void KCoreConfigSkeleton::ItemULongLong::setMaxValue(quint64 v)
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
792void KCoreConfigSkeleton::ItemDouble::readConfig(KConfig *config)
793{
794 KConfigGroup cg = configGroup(config);
795 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
796 if (mHasMin) {
797 mReference = qMax(a: mReference, b: mMin);
798 }
799 if (mHasMax) {
800 mReference = qMin(a: mReference, b: mMax);
801 }
802 mLoadedValue = mReference;
803
804 readImmutability(group: cg);
805}
806
807void KCoreConfigSkeleton::ItemDouble::setProperty(const QVariant &p)
808{
809 mReference = p.toDouble();
810}
811
812bool KCoreConfigSkeleton::ItemDouble::isEqual(const QVariant &v) const
813{
814 return mReference == v.toDouble();
815}
816
817QVariant KCoreConfigSkeleton::ItemDouble::property() const
818{
819 return QVariant(mReference);
820}
821
822QVariant KCoreConfigSkeleton::ItemDouble::minValue() const
823{
824 if (mHasMin) {
825 return QVariant(mMin);
826 }
827 return QVariant();
828}
829
830QVariant KCoreConfigSkeleton::ItemDouble::maxValue() const
831{
832 if (mHasMax) {
833 return QVariant(mMax);
834 }
835 return QVariant();
836}
837
838void KCoreConfigSkeleton::ItemDouble::setMinValue(double v)
839{
840 mHasMin = true;
841 mMin = v;
842}
843
844void KCoreConfigSkeleton::ItemDouble::setMaxValue(double v)
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
855void KCoreConfigSkeleton::ItemRect::readConfig(KConfig *config)
856{
857 KConfigGroup cg = configGroup(config);
858 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
859 mLoadedValue = mReference;
860
861 readImmutability(group: cg);
862}
863
864void KCoreConfigSkeleton::ItemRect::setProperty(const QVariant &p)
865{
866 mReference = p.toRect();
867}
868
869bool KCoreConfigSkeleton::ItemRect::isEqual(const QVariant &v) const
870{
871 return mReference == v.toRect();
872}
873
874QVariant KCoreConfigSkeleton::ItemRect::property() const
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
884void KCoreConfigSkeleton::ItemRectF::readConfig(KConfig *config)
885{
886 KConfigGroup cg = configGroup(config);
887 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
888 mLoadedValue = mReference;
889
890 readImmutability(group: cg);
891}
892
893void KCoreConfigSkeleton::ItemRectF::setProperty(const QVariant &p)
894{
895 mReference = p.toRectF();
896}
897
898bool KCoreConfigSkeleton::ItemRectF::isEqual(const QVariant &v) const
899{
900 return mReference == v.toRectF();
901}
902
903QVariant KCoreConfigSkeleton::ItemRectF::property() const
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
913void KCoreConfigSkeleton::ItemPoint::readConfig(KConfig *config)
914{
915 KConfigGroup cg = configGroup(config);
916 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
917 mLoadedValue = mReference;
918
919 readImmutability(group: cg);
920}
921
922void KCoreConfigSkeleton::ItemPoint::setProperty(const QVariant &p)
923{
924 mReference = p.toPoint();
925}
926
927bool KCoreConfigSkeleton::ItemPoint::isEqual(const QVariant &v) const
928{
929 return mReference == v.toPoint();
930}
931
932QVariant KCoreConfigSkeleton::ItemPoint::property() const
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
942void KCoreConfigSkeleton::ItemPointF::readConfig(KConfig *config)
943{
944 KConfigGroup cg = configGroup(config);
945 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
946 mLoadedValue = mReference;
947
948 readImmutability(group: cg);
949}
950
951void KCoreConfigSkeleton::ItemPointF::setProperty(const QVariant &p)
952{
953 mReference = p.toPointF();
954}
955
956bool KCoreConfigSkeleton::ItemPointF::isEqual(const QVariant &v) const
957{
958 return mReference == v.toPointF();
959}
960
961QVariant KCoreConfigSkeleton::ItemPointF::property() const
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
971void KCoreConfigSkeleton::ItemSize::readConfig(KConfig *config)
972{
973 KConfigGroup cg = configGroup(config);
974 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
975 mLoadedValue = mReference;
976
977 readImmutability(group: cg);
978}
979
980void KCoreConfigSkeleton::ItemSize::setProperty(const QVariant &p)
981{
982 mReference = p.toSize();
983}
984
985bool KCoreConfigSkeleton::ItemSize::isEqual(const QVariant &v) const
986{
987 return mReference == v.toSize();
988}
989
990QVariant KCoreConfigSkeleton::ItemSize::property() const
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
1000void KCoreConfigSkeleton::ItemSizeF::readConfig(KConfig *config)
1001{
1002 KConfigGroup cg = configGroup(config);
1003 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
1004 mLoadedValue = mReference;
1005
1006 readImmutability(group: cg);
1007}
1008
1009void KCoreConfigSkeleton::ItemSizeF::setProperty(const QVariant &p)
1010{
1011 mReference = p.toSizeF();
1012}
1013
1014bool KCoreConfigSkeleton::ItemSizeF::isEqual(const QVariant &v) const
1015{
1016 return mReference == v.toSizeF();
1017}
1018
1019QVariant KCoreConfigSkeleton::ItemSizeF::property() const
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
1029void KCoreConfigSkeleton::ItemDateTime::readConfig(KConfig *config)
1030{
1031 KConfigGroup cg = configGroup(config);
1032 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
1033 mLoadedValue = mReference;
1034
1035 readImmutability(group: cg);
1036}
1037
1038void KCoreConfigSkeleton::ItemDateTime::setProperty(const QVariant &p)
1039{
1040 mReference = p.toDateTime();
1041}
1042
1043bool KCoreConfigSkeleton::ItemDateTime::isEqual(const QVariant &v) const
1044{
1045 return mReference == v.toDateTime();
1046}
1047
1048QVariant KCoreConfigSkeleton::ItemDateTime::property() const
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
1058void KCoreConfigSkeleton::ItemStringList::readConfig(KConfig *config)
1059{
1060 KConfigGroup cg = configGroup(config);
1061 if (!cg.hasKey(key: mKey)) {
1062 mReference = mDefault;
1063 } else {
1064 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
1065 }
1066 mLoadedValue = mReference;
1067
1068 readImmutability(group: cg);
1069}
1070
1071void KCoreConfigSkeleton::ItemStringList::setProperty(const QVariant &p)
1072{
1073 mReference = p.toStringList();
1074}
1075
1076bool KCoreConfigSkeleton::ItemStringList::isEqual(const QVariant &v) const
1077{
1078 return mReference == v.toStringList();
1079}
1080
1081QVariant KCoreConfigSkeleton::ItemStringList::property() const
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
1091void KCoreConfigSkeleton::ItemPathList::readConfig(KConfig *config)
1092{
1093 KConfigGroup cg = configGroup(config);
1094 if (!cg.hasKey(key: mKey)) {
1095 mReference = mDefault;
1096 } else {
1097 mReference = cg.readPathEntry(pKey: mKey, aDefault: QStringList());
1098 }
1099 mLoadedValue = mReference;
1100
1101 readImmutability(group: cg);
1102}
1103
1104void KCoreConfigSkeleton::ItemPathList::writeConfig(KConfig *config)
1105{
1106 if (mReference != mLoadedValue) { // WABA: Is this test needed?
1107 KConfigGroup cg = configGroup(config);
1108 if ((mDefault == mReference) && !cg.hasDefault(key: mKey)) {
1109 cg.revertToDefault(key: mKey, pFlag: writeFlags());
1110 } else {
1111 QStringList sl = mReference;
1112 cg.writePathEntry(pKey: mKey, value: sl, pFlags: 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
1123void KCoreConfigSkeleton::ItemUrlList::readConfig(KConfig *config)
1124{
1125 KConfigGroup cg = configGroup(config);
1126 if (!cg.hasKey(key: mKey)) {
1127 mReference = mDefault;
1128 } else {
1129 QStringList strList;
1130 for (const QUrl &url : std::as_const(t&: mDefault)) {
1131 strList.append(t: url.toString());
1132 }
1133 mReference.clear();
1134 const QStringList readList = cg.readEntry<QStringList>(key: mKey, aDefault: strList);
1135 for (const QString &str : readList) {
1136 mReference.append(t: QUrl(str));
1137 }
1138 }
1139 mLoadedValue = mReference;
1140
1141 readImmutability(group: cg);
1142}
1143
1144void KCoreConfigSkeleton::ItemUrlList::writeConfig(KConfig *config)
1145{
1146 if (mReference != mLoadedValue) { // WABA: Is this test needed?
1147 KConfigGroup cg = configGroup(config);
1148 if ((mDefault == mReference) && !cg.hasDefault(key: mKey)) {
1149 cg.revertToDefault(key: mKey, pFlag: writeFlags());
1150 } else {
1151 QStringList strList;
1152 for (const QUrl &url : std::as_const(t&: mReference)) {
1153 strList.append(t: url.toString());
1154 }
1155 cg.writeEntry<QStringList>(key: mKey, value: strList, pFlags: writeFlags());
1156 }
1157 mLoadedValue = mReference;
1158 }
1159}
1160
1161void KCoreConfigSkeleton::ItemUrlList::setProperty(const QVariant &p)
1162{
1163 mReference = qvariant_cast<QList<QUrl>>(v: p);
1164}
1165
1166bool KCoreConfigSkeleton::ItemUrlList::isEqual(const QVariant &v) const
1167{
1168 return mReference == qvariant_cast<QList<QUrl>>(v);
1169}
1170
1171QVariant KCoreConfigSkeleton::ItemUrlList::property() const
1172{
1173 return QVariant::fromValue<QList<QUrl>>(value: mReference);
1174}
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
1181void KCoreConfigSkeleton::ItemIntList::readConfig(KConfig *config)
1182{
1183 KConfigGroup cg = configGroup(config);
1184 if (!cg.hasKey(key: mKey)) {
1185 mReference = mDefault;
1186 } else {
1187 mReference = cg.readEntry(key: mKey, aDefault: mDefault);
1188 }
1189 mLoadedValue = mReference;
1190
1191 readImmutability(group: cg);
1192}
1193
1194void KCoreConfigSkeleton::ItemIntList::setProperty(const QVariant &p)
1195{
1196 mReference = qvariant_cast<QList<int>>(v: p);
1197}
1198
1199bool KCoreConfigSkeleton::ItemIntList::isEqual(const QVariant &v) const
1200{
1201 return mReference == qvariant_cast<QList<int>>(v);
1202}
1203
1204QVariant KCoreConfigSkeleton::ItemIntList::property() const
1205{
1206 return QVariant::fromValue<QList<int>>(value: mReference);
1207}
1208
1209// static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; }
1210
1211KCoreConfigSkeleton::KCoreConfigSkeleton(const QString &configname, QObject *parent)
1212 : QObject(parent)
1213 , d(new KCoreConfigSkeletonPrivate)
1214{
1215 // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1216
1217 d->mConfig = KSharedConfig::openConfig(fileName: configname, mode: KConfig::FullConfig);
1218}
1219
1220KCoreConfigSkeleton::KCoreConfigSkeleton(KSharedConfig::Ptr pConfig, QObject *parent)
1221 : QObject(parent)
1222 , d(new KCoreConfigSkeletonPrivate)
1223{
1224 // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
1225 d->mConfig = std::move(pConfig);
1226}
1227
1228KCoreConfigSkeleton::~KCoreConfigSkeleton()
1229{
1230 delete d;
1231}
1232
1233void KCoreConfigSkeleton::setCurrentGroup(const QString &group)
1234{
1235 d->mCurrentGroup = group;
1236}
1237
1238QString KCoreConfigSkeleton::currentGroup() const
1239{
1240 return d->mCurrentGroup;
1241}
1242
1243KConfig *KCoreConfigSkeleton::config()
1244{
1245 return d->mConfig.data();
1246}
1247
1248const KConfig *KCoreConfigSkeleton::config() const
1249{
1250 return d->mConfig.data();
1251}
1252
1253KSharedConfig::Ptr KCoreConfigSkeleton::sharedConfig() const
1254{
1255 return d->mConfig;
1256}
1257
1258void KCoreConfigSkeleton::setSharedConfig(KSharedConfig::Ptr pConfig)
1259{
1260 d->mConfig = std::move(pConfig);
1261}
1262
1263KConfigSkeletonItem::List KCoreConfigSkeleton::items() const
1264{
1265 return d->mItems;
1266}
1267
1268bool KCoreConfigSkeleton::useDefaults(bool b)
1269{
1270 if (b == d->mUseDefaults) {
1271 return d->mUseDefaults;
1272 }
1273
1274 d->mUseDefaults = b;
1275 for (auto *skelItem : std::as_const(t&: d->mItems)) {
1276 skelItem->swapDefault();
1277 }
1278
1279 usrUseDefaults(b);
1280 return !d->mUseDefaults;
1281}
1282
1283void KCoreConfigSkeleton::setDefaults()
1284{
1285 for (auto *skelItem : std::as_const(t&: d->mItems)) {
1286 skelItem->setDefault();
1287 }
1288 usrSetDefaults();
1289}
1290
1291void KCoreConfigSkeleton::load()
1292{
1293 d->mConfig->reparseConfiguration();
1294 read();
1295}
1296
1297void KCoreConfigSkeleton::read()
1298{
1299 for (auto *skelItem : std::as_const(t&: d->mItems)) {
1300 skelItem->readConfig(d->mConfig.data());
1301 }
1302 usrRead();
1303}
1304
1305bool KCoreConfigSkeleton::isDefaults() const
1306{
1307 return std::all_of(first: d->mItems.cbegin(), last: d->mItems.cend(), pred: [](KConfigSkeletonItem *skelItem) {
1308 return skelItem->isDefault();
1309 });
1310}
1311
1312bool KCoreConfigSkeleton::isSaveNeeded() const
1313{
1314 return std::any_of(first: d->mItems.cbegin(), last: d->mItems.cend(), pred: [](KConfigSkeletonItem *skelItem) {
1315 return skelItem->isSaveNeeded();
1316 });
1317}
1318
1319bool KCoreConfigSkeleton::save()
1320{
1321 // qDebug();
1322 for (auto *skelItem : std::as_const(t&: 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 }
1334 Q_EMIT configChanged();
1335 }
1336 return true;
1337}
1338
1339bool KCoreConfigSkeleton::usrUseDefaults(bool)
1340{
1341 return false;
1342}
1343
1344void KCoreConfigSkeleton::usrSetDefaults()
1345{
1346}
1347
1348void KCoreConfigSkeleton::usrRead()
1349{
1350}
1351
1352bool KCoreConfigSkeleton::usrSave()
1353{
1354 return true;
1355}
1356
1357void KCoreConfigSkeleton::addItem(KConfigSkeletonItem *item, const QString &name)
1358{
1359 if (d->mItems.contains(t: 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(key: item->name());
1367 } else {
1368 d->mItems.append(t: item);
1369 }
1370
1371 item->setName(name.isEmpty() ? item->key() : name);
1372 d->mItemDict.insert(key: item->name(), value: item);
1373 item->readDefault(d->mConfig.data());
1374 item->readConfig(d->mConfig.data());
1375}
1376
1377void KCoreConfigSkeleton::removeItem(const QString &name)
1378{
1379 KConfigSkeletonItem *item = d->mItemDict.value(key: name);
1380 if (item) {
1381 d->mItems.removeAll(t: item);
1382 d->mItemDict.remove(key: item->name());
1383 delete item;
1384 }
1385}
1386
1387void KCoreConfigSkeleton::clearItems()
1388{
1389 KConfigSkeletonItem::List items = d->mItems;
1390 d->mItems.clear();
1391 d->mItemDict.clear();
1392 qDeleteAll(c: items);
1393}
1394
1395KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1396{
1397 KCoreConfigSkeleton::ItemString *item;
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
1403KCoreConfigSkeleton::ItemPassword *
1404KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key)
1405{
1406 KCoreConfigSkeleton::ItemPassword *item;
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{
1414 KCoreConfigSkeleton::ItemPath *item;
1415 item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1416 addItem(item, name);
1417 return item;
1418}
1419
1420KCoreConfigSkeleton::ItemProperty *
1421KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key)
1422{
1423 KCoreConfigSkeleton::ItemProperty *item;
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{
1431 KCoreConfigSkeleton::ItemBool *item;
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{
1439 KCoreConfigSkeleton::ItemInt *item;
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{
1447 KCoreConfigSkeleton::ItemUInt *item;
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{
1455 KCoreConfigSkeleton::ItemLongLong *item;
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{
1463 KCoreConfigSkeleton::ItemULongLong *item;
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{
1471 KCoreConfigSkeleton::ItemDouble *item;
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{
1479 KCoreConfigSkeleton::ItemRect *item;
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{
1487 KCoreConfigSkeleton::ItemRectF *item;
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{
1495 KCoreConfigSkeleton::ItemPoint *item;
1496 item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1497 addItem(item, name);
1498 return item;
1499}
1500
1501KCoreConfigSkeleton::ItemPointF *KCoreConfigSkeleton::addItemPointF(const QString &name, QPointF &reference, const QPointF &defaultValue, const QString &key)
1502{
1503 KCoreConfigSkeleton::ItemPointF *item;
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{
1511 KCoreConfigSkeleton::ItemSize *item;
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{
1519 KCoreConfigSkeleton::ItemSizeF *item;
1520 item = new KCoreConfigSkeleton::ItemSizeF(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1521 addItem(item, name);
1522 return item;
1523}
1524
1525KCoreConfigSkeleton::ItemDateTime *
1526KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key)
1527{
1528 KCoreConfigSkeleton::ItemDateTime *item;
1529 item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1530 addItem(item, name);
1531 return item;
1532}
1533
1534KCoreConfigSkeleton::ItemStringList *
1535KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key)
1536{
1537 KCoreConfigSkeleton::ItemStringList *item;
1538 item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1539 addItem(item, name);
1540 return item;
1541}
1542
1543KCoreConfigSkeleton::ItemIntList *
1544KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key)
1545{
1546 KCoreConfigSkeleton::ItemIntList *item;
1547 item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue);
1548 addItem(item, name);
1549 return item;
1550}
1551
1552bool KCoreConfigSkeleton::isImmutable(const QString &name) const
1553{
1554 KConfigSkeletonItem *item = findItem(name);
1555 return !item || item->isImmutable();
1556}
1557
1558KConfigSkeletonItem *KCoreConfigSkeleton::findItem(const QString &name) const
1559{
1560 return d->mItemDict.value(key: name);
1561}
1562
1563KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem *item,
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
1592bool KConfigCompilerSignallingItem::isEqual(const QVariant &p) const
1593{
1594 return mItem->isEqual(p);
1595}
1596
1597QVariant KConfigCompilerSignallingItem::property() const
1598{
1599 return mItem->property();
1600}
1601
1602QVariant KConfigCompilerSignallingItem::minValue() const
1603{
1604 return mItem->minValue();
1605}
1606
1607QVariant KConfigCompilerSignallingItem::maxValue() const
1608{
1609 return mItem->maxValue();
1610}
1611
1612void KConfigCompilerSignallingItem::readConfig(KConfig *c)
1613{
1614 QVariant oldValue = mItem->property();
1615 mItem->readConfig(c);
1616 // readConfig() changes mIsImmutable, update it here as well
1617 KConfigGroup cg = configGroup(config: c);
1618 readImmutability(group: cg);
1619 if (!mItem->isEqual(p: oldValue)) {
1620 invokeNotifyFunction();
1621 }
1622}
1623
1624void KConfigCompilerSignallingItem::readDefault(KConfig *c)
1625{
1626 mItem->readDefault(c);
1627 // readDefault() changes mIsImmutable, update it here as well
1628 KConfigGroup cg = configGroup(config: c);
1629 readImmutability(group: cg);
1630}
1631
1632void KConfigCompilerSignallingItem::writeConfig(KConfig *c)
1633{
1634 mItem->writeConfig(c);
1635}
1636
1637void KConfigCompilerSignallingItem::setDefault()
1638{
1639 QVariant oldValue = mItem->property();
1640 mItem->setDefault();
1641 if (!mItem->isEqual(p: oldValue)) {
1642 invokeNotifyFunction();
1643 }
1644}
1645
1646void KConfigCompilerSignallingItem::setProperty(const QVariant &p)
1647{
1648 if (!mItem->isEqual(p)) {
1649 mItem->setProperty(p);
1650 invokeNotifyFunction();
1651 }
1652}
1653
1654void KConfigCompilerSignallingItem::swapDefault()
1655{
1656 QVariant oldValue = mItem->property();
1657 mItem->swapDefault();
1658 if (!mItem->isEqual(p: 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"
1684

source code of kconfig/src/core/kcoreconfigskeleton.cpp