Changeset View
Changeset View
Standalone View
Standalone View
kcms/workspaceoptions/kcm.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 <furkantokac34@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | #include "kcm.h" | ||||
19 | | ||||
20 | #include <KPluginFactory> | ||||
21 | #include <KAboutData> | ||||
22 | #include <KLocalizedString> | ||||
23 | #include <KConfigGroup> | ||||
24 | | ||||
25 | #include <ksharedconfig.h> | ||||
26 | | ||||
27 | K_PLUGIN_FACTORY_WITH_JSON(KCMWorkspaceOptionsFactory, "kcm_workspace.json", registerPlugin<KCMWorkspaceOptions>();) | ||||
28 | | ||||
29 | KCMWorkspaceOptions::KCMWorkspaceOptions(QObject *parent, const QVariantList& args) | ||||
30 | : KQuickAddons::ConfigModule(parent, args) | ||||
31 | { | ||||
32 | KAboutData* about = new KAboutData(QStringLiteral("kcm_workspace"), | ||||
33 | i18n("Plasma Workspace global options"), | ||||
34 | QStringLiteral("1.1"), | ||||
35 | i18n("System Settings module for managing global options for the Plasma Workspace."), | ||||
36 | KAboutLicense::GPL); | ||||
37 | | ||||
38 | about->addAuthor(i18n("Furkan Tokac"), QString(), QStringLiteral("furkantokac34@gmail.com")); | ||||
39 | setAboutData(about); | ||||
40 | | ||||
41 | setButtons( Default | Apply ); | ||||
42 | } | ||||
43 | | ||||
furkantokac: This is unnecessary. Just ignore it. | |||||
44 | /*ConfigModule functions*/ | ||||
45 | void KCMWorkspaceOptions::load() | ||||
46 | { | ||||
47 | bool state = false; | ||||
48 | KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasmarc")); | ||||
49 | | ||||
50 | // Load toolTip | ||||
51 | { | ||||
52 | const KConfigGroup cg(config, QStringLiteral("PlasmaToolTips")); | ||||
ngraham: Why are these within braces? | |||||
To make the const KConfigGroup cg(config, QStringLiteral("PlasmaToolTips")); this definition local. furkantokac: To make the
```
const KConfigGroup cg(config, QStringLiteral("PlasmaToolTips"));
```
this… | |||||
53 | state = cg.readEntry("Delay", 0.7) > 0; | ||||
54 | setToolTip(state); | ||||
55 | m_ostateToolTip = state; | ||||
56 | } | ||||
57 | | ||||
58 | // Load visualFeedback | ||||
59 | { | ||||
60 | const KConfigGroup cg(config, QStringLiteral("OSD")); | ||||
61 | state = cg.readEntry(QStringLiteral("Enabled"), true); | ||||
62 | setVisualFeedback(state); | ||||
63 | m_ostateVisualFeedback = state; | ||||
64 | } | ||||
65 | | ||||
66 | setNeedsSave(false); | ||||
67 | } | ||||
68 | | ||||
69 | void KCMWorkspaceOptions::save() | ||||
70 | { | ||||
71 | KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasmarc")); | ||||
72 | | ||||
73 | // Save toolTip | ||||
74 | { | ||||
75 | KConfigGroup cg(config, QStringLiteral("PlasmaToolTips")); | ||||
76 | cg.writeEntry("Delay", getToolTip() ? 0.7 : -1); | ||||
77 | m_ostateToolTip = getToolTip(); | ||||
78 | } | ||||
79 | | ||||
80 | // Save visualFeedback | ||||
81 | { | ||||
82 | KConfigGroup cg(config, QStringLiteral("OSD")); | ||||
83 | cg.writeEntry("Enabled", getVisualFeedback()); | ||||
84 | m_ostateVisualFeedback = getVisualFeedback(); | ||||
85 | } | ||||
86 | | ||||
87 | config->sync(); | ||||
88 | setNeedsSave(false); | ||||
89 | } | ||||
90 | | ||||
91 | void KCMWorkspaceOptions::defaults() | ||||
92 | { | ||||
93 | setToolTip(true); | ||||
94 | setVisualFeedback(true); | ||||
95 | | ||||
96 | handleNeedsSave(); | ||||
97 | } | ||||
98 | | ||||
99 | /*ToolTip functions*/ | ||||
100 | bool KCMWorkspaceOptions::getToolTip() const | ||||
101 | { | ||||
102 | return m_stateToolTip; | ||||
103 | } | ||||
104 | | ||||
105 | void KCMWorkspaceOptions::setToolTip(bool state) | ||||
106 | { | ||||
107 | // Prevent from binding loop | ||||
108 | if( m_stateToolTip == state ) { | ||||
needs braces. see https://community.kde.org/Policies/Kdelibs_Coding_Style#Braces romangg: needs braces. see https://community.kde.org/Policies/Kdelibs_Coding_Style#Braces | |||||
And a whitespace between if and (: https://community.kde.org/Policies/Kdelibs_Coding_Style#Whitespace romangg: And a whitespace between `if` and `(`: https://community.kde. | |||||
109 | return; | ||||
110 | } | ||||
111 | | ||||
112 | m_stateToolTip = state; | ||||
113 | | ||||
114 | emit toolTipChanged(); | ||||
115 | handleNeedsSave(); | ||||
116 | } | ||||
117 | | ||||
118 | /*VisualFeedback functions*/ | ||||
119 | bool KCMWorkspaceOptions::getVisualFeedback() const | ||||
120 | { | ||||
121 | return m_stateVisualFeedback; | ||||
122 | } | ||||
123 | | ||||
124 | void KCMWorkspaceOptions::setVisualFeedback(bool state) | ||||
125 | { | ||||
126 | // Prevent from binding loop | ||||
127 | if( m_stateVisualFeedback == state ) { | ||||
128 | return; | ||||
129 | } | ||||
130 | | ||||
131 | m_stateVisualFeedback = state; | ||||
132 | | ||||
133 | emit visualFeedbackChanged(); | ||||
134 | handleNeedsSave(); | ||||
ngraham: How about `handleNeedsSave()` instead? | |||||
furkantokac: Makes more sense :) Done. | |||||
135 | } | ||||
136 | | ||||
137 | /*Other functions*/ | ||||
138 | // Checks if the current states are different than the first states. | ||||
139 | // If yes, setNeedsSave(true). | ||||
140 | void KCMWorkspaceOptions::handleNeedsSave() | ||||
141 | { | ||||
142 | setNeedsSave(m_ostateToolTip != getToolTip() || | ||||
143 | m_ostateVisualFeedback != getVisualFeedback()); | ||||
144 | } | ||||
145 | | ||||
146 | #include "kcm.moc" |
This is unnecessary. Just ignore it.