1/*
2 SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "kcmoduledata.h"
8
9#include <QList>
10#include <QPointer>
11
12#include <KCoreConfigSkeleton>
13
14class KCModuleDataPrivate
15{
16public:
17 explicit KCModuleDataPrivate(KCModuleData *probe)
18 : _q(probe)
19 {
20 }
21
22 KCModuleData *_q;
23 QList<QPointer<KCoreConfigSkeleton>> _skeletons;
24};
25
26KCModuleData::KCModuleData(QObject *parent)
27 : QObject(parent)
28 , d(new KCModuleDataPrivate(this))
29{
30 connect(sender: this, signal: &KCModuleData::aboutToLoad, context: this, slot: &KCModuleData::loaded);
31 QMetaObject::invokeMethod(
32 object: this,
33 function: [this] {
34 aboutToLoad(QPrivateSignal());
35 },
36 type: Qt::QueuedConnection);
37}
38
39KCModuleData::~KCModuleData() = default;
40
41void KCModuleData::registerSkeleton(KCoreConfigSkeleton *skeleton)
42{
43 if (!skeleton || d->_skeletons.contains(t: skeleton)) {
44 return;
45 }
46
47 d->_skeletons.append(t: skeleton);
48}
49
50bool KCModuleData::isDefaults() const
51{
52 bool defaults = true;
53 for (const auto &skeleton : std::as_const(t&: d->_skeletons)) {
54 defaults &= skeleton->isDefaults();
55 }
56 return defaults;
57}
58
59void KCModuleData::revertToDefaults()
60{
61 for (const auto &skeleton : std::as_const(t&: d->_skeletons)) {
62 skeleton->useDefaults(b: true);
63 skeleton->save();
64 }
65}
66
67void KCModuleData::autoRegisterSkeletons()
68{
69 const auto skeletons = findChildren<KCoreConfigSkeleton *>();
70 for (auto *skeleton : skeletons) {
71 registerSkeleton(skeleton);
72 }
73}
74
75bool KCModuleData::matchesQuery(const QString &query) const
76{
77 // Currently not implemented, here for future use case
78 Q_UNUSED(query)
79 return false;
80}
81
82#include "moc_kcmoduledata.cpp"
83

source code of kcmutils/src/core/kcmoduledata.cpp