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 | |
14 | class KCModuleDataPrivate |
15 | { |
16 | public: |
17 | explicit KCModuleDataPrivate(KCModuleData *probe) |
18 | : _q(probe) |
19 | { |
20 | } |
21 | |
22 | KCModuleData *_q; |
23 | QList<QPointer<KCoreConfigSkeleton>> _skeletons; |
24 | QAction *auxiliaryAction = nullptr; |
25 | bool relevant = true; |
26 | }; |
27 | |
28 | KCModuleData::KCModuleData(QObject *parent) |
29 | : QObject(parent) |
30 | , d(new KCModuleDataPrivate(this)) |
31 | { |
32 | connect(sender: this, signal: &KCModuleData::aboutToLoad, context: this, slot: &KCModuleData::loaded); |
33 | QMetaObject::invokeMethod( |
34 | object: this, |
35 | function: [this] { |
36 | aboutToLoad(QPrivateSignal()); |
37 | }, |
38 | type: Qt::QueuedConnection); |
39 | } |
40 | |
41 | KCModuleData::~KCModuleData() = default; |
42 | |
43 | void KCModuleData::registerSkeleton(KCoreConfigSkeleton *skeleton) |
44 | { |
45 | if (!skeleton || d->_skeletons.contains(t: skeleton)) { |
46 | return; |
47 | } |
48 | |
49 | d->_skeletons.append(t: skeleton); |
50 | } |
51 | |
52 | bool KCModuleData::isDefaults() const |
53 | { |
54 | bool defaults = true; |
55 | for (const auto &skeleton : std::as_const(t&: d->_skeletons)) { |
56 | defaults &= skeleton->isDefaults(); |
57 | } |
58 | return defaults; |
59 | } |
60 | |
61 | void KCModuleData::revertToDefaults() |
62 | { |
63 | for (const auto &skeleton : std::as_const(t&: d->_skeletons)) { |
64 | skeleton->useDefaults(b: true); |
65 | skeleton->save(); |
66 | } |
67 | } |
68 | |
69 | void KCModuleData::autoRegisterSkeletons() |
70 | { |
71 | const auto skeletons = findChildren<KCoreConfigSkeleton *>(); |
72 | for (auto *skeleton : skeletons) { |
73 | registerSkeleton(skeleton); |
74 | } |
75 | } |
76 | |
77 | bool KCModuleData::matchesQuery(const QString &query) const |
78 | { |
79 | // Currently not implemented, here for future use case |
80 | Q_UNUSED(query) |
81 | return false; |
82 | } |
83 | |
84 | QAction *KCModuleData::auxiliaryAction() const |
85 | { |
86 | return d->auxiliaryAction; |
87 | } |
88 | |
89 | void KCModuleData::setAuxiliaryAction(QAction *action) |
90 | { |
91 | if (d->auxiliaryAction != action) { |
92 | d->auxiliaryAction = action; |
93 | Q_EMIT auxiliaryActionChanged(action); |
94 | } |
95 | } |
96 | |
97 | bool KCModuleData::isRelevant() const |
98 | { |
99 | return d->relevant; |
100 | } |
101 | |
102 | void KCModuleData::setRelevant(bool relevant) |
103 | { |
104 | if (d->relevant != relevant) { |
105 | d->relevant = relevant; |
106 | Q_EMIT relevantChanged(relevant); |
107 | } |
108 | } |
109 | |
110 | #include "moc_kcmoduledata.cpp" |
111 |