Changeset View
Changeset View
Standalone View
Standalone View
kcms/launch/launchfeedback.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> | 2 | * Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> | ||
3 | * Copyright (C) 2017 Eike Hein <hein@kde.org> | 3 | * Copyright (C) 2017 Eike Hein <hein@kde.org> | ||
4 | * Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com> | ||||
4 | * | 5 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | 9 | * (at your option) any later version. | ||
9 | * | 10 | * | ||
10 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. | ||
14 | * | 15 | * | ||
15 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software | ||
17 | */ | 18 | */ | ||
18 | 19 | | |||
19 | #include "launchfeedback.h" | 20 | #include "launchfeedback.h" | ||
20 | 21 | | |||
21 | #include <KAboutData> | 22 | #include <KAboutData> | ||
22 | #include <KConfig> | | |||
23 | #include <KConfigGroup> | | |||
24 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
25 | #include <KPluginFactory> | 24 | #include <KPluginFactory> | ||
26 | 25 | | |||
27 | #include "kwin_interface.h" | 26 | #include "kwin_interface.h" | ||
28 | 27 | | |||
29 | #define STARTUP_DEFAULT_TIMEOUT 5 | 28 | #include "launchfeedbacksettings.h" | ||
30 | 29 | | |||
31 | K_PLUGIN_FACTORY_WITH_JSON(LaunchFactory, "kcm_launchfeedback.json", registerPlugin<LaunchFeedback>();) | 30 | K_PLUGIN_FACTORY_WITH_JSON(LaunchFactory, "kcm_launchfeedback.json", registerPlugin<LaunchFeedback>();) | ||
32 | 31 | | |||
33 | LaunchFeedback::LaunchFeedback(QObject *parent, const QVariantList &args) | 32 | LaunchFeedback::LaunchFeedback(QObject *parent, const QVariantList &args) | ||
34 | : KQuickAddons::ConfigModule(parent, args) | 33 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
35 | , m_busyCursorCurrentIndex(3) | 34 | , m_settings(new LaunchFeedbackSettings(this)) | ||
36 | , m_taskManagerNotification(true) | | |||
37 | , m_notificationTimeout(STARTUP_DEFAULT_TIMEOUT) | | |||
38 | { | 35 | { | ||
36 | qmlRegisterUncreatableType<LaunchFeedback>("org.kde.private.kcms.launchfeedback", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); | ||||
37 | qmlRegisterType<LaunchFeedbackSettings>(); | ||||
38 | | ||||
39 | KAboutData *about = new KAboutData(QStringLiteral("kcm_launchfeedback"), | 39 | KAboutData *about = new KAboutData(QStringLiteral("kcm_launchfeedback"), | ||
40 | i18n("Configure application launch feedback"), | 40 | i18n("Configure application launch feedback"), | ||
41 | QStringLiteral("0.2"), QString(), KAboutLicense::LGPL); | 41 | QStringLiteral("0.2"), QString(), KAboutLicense::LGPL); | ||
42 | setAboutData(about); | 42 | setAboutData(about); | ||
43 | 43 | | |||
44 | setButtons(Apply | Default); | 44 | setButtons(Apply | Default); | ||
45 | } | 45 | } | ||
46 | 46 | | |||
47 | LaunchFeedback::~LaunchFeedback() | 47 | LaunchFeedback::~LaunchFeedback() | ||
48 | { | 48 | { | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | int LaunchFeedback::busyCursorCurrentIndex() const | 51 | LaunchFeedbackSettings *LaunchFeedback::launchFeedbackSettings() const | ||
52 | { | | |||
53 | return m_busyCursorCurrentIndex; | | |||
54 | } | | |||
55 | | ||||
56 | void LaunchFeedback::setBusyCursorCurrentIndex(int index) | | |||
57 | { | | |||
58 | if (m_busyCursorCurrentIndex != index) { | | |||
59 | m_busyCursorCurrentIndex = index; | | |||
60 | | ||||
61 | emit busyCursorCurrentIndexChanged(); | | |||
62 | | ||||
63 | updateNeedsSave(); | | |||
64 | } | | |||
65 | } | | |||
66 | | ||||
67 | bool LaunchFeedback::taskManagerNotification() const | | |||
68 | { | | |||
69 | return m_taskManagerNotification; | | |||
70 | } | | |||
71 | | ||||
72 | void LaunchFeedback::setTaskManagerNotification(bool enabled) | | |||
73 | { | 52 | { | ||
74 | if (m_taskManagerNotification != enabled) { | 53 | return m_settings; | ||
75 | m_taskManagerNotification = enabled; | | |||
76 | | ||||
77 | emit taskManagerNotificationChanged(); | | |||
78 | | ||||
79 | updateNeedsSave(); | | |||
80 | } | | |||
81 | } | | |||
82 | | ||||
83 | int LaunchFeedback::notificationTimeout() const | | |||
84 | { | | |||
85 | return m_notificationTimeout; | | |||
86 | } | | |||
87 | | ||||
88 | void LaunchFeedback::setNotificationTimeout(int duration) | | |||
89 | { | | |||
90 | if (m_notificationTimeout != duration) { | | |||
91 | m_notificationTimeout = duration; | | |||
92 | | ||||
93 | emit notificationTimeoutChanged(); | | |||
94 | | ||||
95 | updateNeedsSave(); | | |||
96 | } | | |||
97 | } | | |||
98 | | ||||
99 | void LaunchFeedback::load() | | |||
100 | { | | |||
101 | KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals); | | |||
102 | KConfigGroup c = conf.group("FeedbackStyle"); | | |||
103 | | ||||
104 | const bool busyCursor = c.readEntry("BusyCursor", true); | | |||
105 | | ||||
106 | setTaskManagerNotification(c.readEntry("TaskbarButton", true)); | | |||
107 | | ||||
108 | c = conf.group("BusyCursorSettings"); | | |||
109 | | ||||
110 | setNotificationTimeout(c.readEntry("Timeout", STARTUP_DEFAULT_TIMEOUT)); | | |||
111 | | ||||
112 | bool busyBlinking = c.readEntry("Blinking", false); | | |||
113 | bool busyBouncing = c.readEntry("Bouncing", true); | | |||
114 | | ||||
115 | if (!busyCursor) { | | |||
116 | setBusyCursorCurrentIndex(0); | | |||
117 | } else if (busyBlinking) { | | |||
118 | setBusyCursorCurrentIndex(2); | | |||
119 | } else if (busyBouncing) { | | |||
120 | setBusyCursorCurrentIndex(3); | | |||
121 | } else { | | |||
122 | setBusyCursorCurrentIndex(1); | | |||
123 | } | | |||
124 | } | 54 | } | ||
125 | 55 | | |||
126 | void LaunchFeedback::save() | 56 | void LaunchFeedback::save() | ||
127 | { | 57 | { | ||
128 | KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals); | 58 | ManagedConfigModule::save(); | ||
129 | KConfigGroup c = conf.group("FeedbackStyle"); | | |||
130 | | ||||
131 | c.writeEntry("BusyCursor", m_busyCursorCurrentIndex != 0); | | |||
132 | c.writeEntry("TaskbarButton", m_taskManagerNotification); | | |||
133 | | ||||
134 | c = conf.group("BusyCursorSettings"); | | |||
135 | c.writeEntry("Timeout", m_notificationTimeout); | | |||
136 | c.writeEntry("Blinking", m_busyCursorCurrentIndex == 2); | | |||
137 | c.writeEntry("Bouncing", m_busyCursorCurrentIndex == 3); | | |||
138 | | ||||
139 | c = conf.group("TaskbarButtonSettings"); | | |||
140 | c.writeEntry( "Timeout", m_notificationTimeout); | | |||
141 | | ||||
142 | c.sync(); | | |||
143 | | ||||
144 | setNeedsSave(false); | | |||
145 | 59 | | |||
146 | org::kde::kwin::Effects kwin(QStringLiteral("org.kde.KWin"), | 60 | org::kde::kwin::Effects kwin(QStringLiteral("org.kde.KWin"), | ||
147 | QStringLiteral("/Effects"), | 61 | QStringLiteral("/Effects"), | ||
148 | QDBusConnection::sessionBus()); | 62 | QDBusConnection::sessionBus()); | ||
149 | kwin.reconfigureEffect(QStringLiteral("startupfeedback")); | 63 | kwin.reconfigureEffect(QStringLiteral("startupfeedback")); | ||
150 | } | 64 | } | ||
151 | 65 | | |||
152 | void LaunchFeedback::defaults() | | |||
153 | { | | |||
154 | setBusyCursorCurrentIndex(3); // Bouncing cursor. | | |||
155 | | ||||
156 | setTaskManagerNotification(true); | | |||
157 | | ||||
158 | setNotificationTimeout(STARTUP_DEFAULT_TIMEOUT); | | |||
159 | } | | |||
160 | | ||||
161 | void LaunchFeedback::updateNeedsSave() | | |||
162 | { | | |||
163 | bool needsSave = false; | | |||
164 | | ||||
165 | KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals); | | |||
166 | KConfigGroup c = conf.group("FeedbackStyle"); | | |||
167 | | ||||
168 | const bool savedBusyCursor = c.readEntry("BusyCursor", true); | | |||
169 | | ||||
170 | if (m_taskManagerNotification != c.readEntry("TaskbarButton", true)) { | | |||
171 | needsSave = true; | | |||
172 | } | | |||
173 | | ||||
174 | c = conf.group("BusyCursorSettings"); | | |||
175 | | ||||
176 | if (m_notificationTimeout != c.readEntry("Timeout", STARTUP_DEFAULT_TIMEOUT)) { | | |||
177 | needsSave = true; | | |||
178 | } | | |||
179 | | ||||
180 | int savedBusyCursorIndex = 3; // Bouncing cursor (default); | | |||
181 | | ||||
182 | bool savedBusyBlinking = c.readEntry("Blinking", false); | | |||
183 | bool savedBusyBouncing = c.readEntry("Bouncing", true); | | |||
184 | | ||||
185 | if (!savedBusyCursor) { | | |||
186 | savedBusyCursorIndex = 0; | | |||
187 | } else if (savedBusyBlinking) { | | |||
188 | savedBusyCursorIndex = 2; | | |||
189 | } else if (savedBusyBouncing) { | | |||
190 | savedBusyCursorIndex = 3; | | |||
191 | } else { | | |||
192 | savedBusyCursorIndex = 1; | | |||
193 | } | | |||
194 | | ||||
195 | if (m_busyCursorCurrentIndex != savedBusyCursorIndex) { | | |||
196 | needsSave = true; | | |||
197 | } | | |||
198 | | ||||
199 | setNeedsSave(needsSave); | | |||
200 | } | | |||
201 | | ||||
202 | #include "launchfeedback.moc" | 66 | #include "launchfeedback.moc" |