2
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
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
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include <QGraphicsLinearLayout>
26
#include <KServiceTypeTrader>
28
#include <Plasma/Applet>
29
#include <Plasma/Containment>
30
#include <Plasma/Corona>
32
namespace WorkspaceScripting
40
inWallpaperConfig(false),
41
wallpaperConfigDirty(false)
45
KConfigGroup configGroup;
46
QStringList configGroupPath;
47
KConfigGroup globalConfigGroup;
48
QStringList globalConfigGroupPath;
50
bool inWallpaperConfig : 1;
51
bool wallpaperConfigDirty : 1;
54
Applet::Applet(QObject *parent)
56
d(new Applet::Private)
65
void Applet::setCurrentConfigGroup(const QStringList &groupNames)
67
Plasma::Applet *app = applet();
69
d->configGroup = KConfigGroup();
70
d->configGroupPath.clear();
74
d->configGroup = app->config();
75
d->configGroupPath = groupNames;
77
foreach (const QString &groupName, groupNames) {
78
d->configGroup = KConfigGroup(&d->configGroup, groupName);
81
d->inWallpaperConfig = !groupNames.isEmpty() && groupNames.first() == "Wallpaper";
84
QStringList Applet::currentConfigGroup() const
86
return d->configGroupPath;
89
QStringList Applet::configKeys() const
91
if (d->configGroup.isValid()) {
92
return d->configGroup.keyList();
98
QStringList Applet::configGroups() const
100
if (d->configGroup.isValid()) {
101
return d->configGroup.groupList();
104
return QStringList();
107
QVariant Applet::readConfig(const QString &key, const QVariant &def) const
109
if (d->configGroup.isValid()) {
110
return d->configGroup.readEntry(key, def);
116
void Applet::writeConfig(const QString &key, const QVariant &value)
118
if (d->configGroup.isValid()) {
119
if (d->inWallpaperConfig) {
120
d->wallpaperConfigDirty = true;
123
d->configGroup.writeEntry(key, value);
124
d->configDirty = true;
128
void Applet::setCurrentGlobalConfigGroup(const QStringList &groupNames)
130
Plasma::Applet *app = applet();
132
d->globalConfigGroup = KConfigGroup();
133
d->globalConfigGroupPath.clear();
137
d->globalConfigGroup = app->globalConfig();
138
d->globalConfigGroupPath = groupNames;
140
foreach (const QString &groupName, groupNames) {
141
d->globalConfigGroup = KConfigGroup(&d->globalConfigGroup, groupName);
145
QStringList Applet::currentGlobalConfigGroup() const
147
return d->globalConfigGroupPath;
150
QStringList Applet::globalConfigKeys() const
152
if (d->globalConfigGroup.isValid()) {
153
return d->globalConfigGroup.keyList();
156
return QStringList();
159
QStringList Applet::globalConfigGroups() const
161
if (d->globalConfigGroup.isValid()) {
162
return d->globalConfigGroup.groupList();
165
return QStringList();
168
QVariant Applet::readGlobalConfig(const QString &key, const QVariant &def) const
170
if (d->globalConfigGroup.isValid()) {
171
return d->globalConfigGroup.readEntry(key, def);
177
void Applet::writeGlobalConfig(const QString &key, const QVariant &value)
179
if (d->globalConfigGroup.isValid()) {
180
d->globalConfigGroup.writeEntry(key, value);
181
d->configDirty = true;
185
void Applet::reloadConfigIfNeeded()
187
if (d->configDirty) {
192
void Applet::reloadConfig()
194
Plasma::Applet *app = applet();
196
KConfigGroup cg = app->config();
198
if (!app->isContainment()) {
202
app->configChanged();
204
if (app->containment() && app->containment()->corona()) {
205
app->containment()->corona()->requestConfigSync();
208
d->configDirty = false;
212
QString Applet::version() const
214
Plasma::Applet *app = applet();
219
QString type = app->pluginName();
220
KService::List services = KServiceTypeTrader::self()->query("Plasma/Applet", "[X-KDE-PluginInfo-Name] == '" + type + "'");
221
if (services.isEmpty()) {
225
KPluginInfo info(services.first());
226
return info.version();
229
void Applet::setLocked(bool locked)
231
Plasma::Applet *app = applet();
236
app->setImmutability(locked ? Plasma::UserImmutable : Plasma::Mutable);
239
bool Applet::locked() const
241
Plasma::Applet *app = applet();
243
return Plasma::Mutable;
246
return app->immutability() != Plasma::Mutable;
249
bool Applet::wallpaperConfigDirty() const
251
return d->wallpaperConfigDirty;
254
Plasma::Applet *Applet::applet() const
261
#include "applet.moc"