2 * Copyright 2008 by Aaron Seigo <aseigo@kde.org>
3 * Copyright 2008 by Petri Damsten <damu@iki.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as
7 * published by the Free Software Foundation; either version 2, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "wallpaper.h"
23 #include <kservicetypetrader.h>
31 class WallpaperPrivate
34 WallpaperPrivate(KService::Ptr service
, Wallpaper
*wallpaper
) :
36 wallpaperDescription(service
),
46 KPluginInfo wallpaperDescription
;
52 Wallpaper::Wallpaper(QObject
*parentObject
, const QVariantList
&args
)
53 : d(new WallpaperPrivate(KService::serviceByStorageId(args
.count() > 0 ?
54 args
[0].toString() : QString()), this))
56 // now remove first item since those are managed by Wallpaper and subclasses shouldn't
57 // need to worry about them. yes, it violates the constness of this var, but it lets us add
58 // or remove items later while applets can just pretend that their args always start at 0
59 QVariantList
&mutableArgs
= const_cast<QVariantList
&>(args
);
60 if (!mutableArgs
.isEmpty()) {
61 mutableArgs
.removeFirst();
63 setParent(parentObject
);
66 Wallpaper::~Wallpaper()
71 KPluginInfo::List
Wallpaper::listWallpaperInfo(const QString
&formFactor
)
75 if (!formFactor
.isEmpty()) {
76 constraint
.append("[X-Plasma-FormFactors] ~~ '").append(formFactor
).append("'");
79 KService::List offers
= KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint
);
80 return KPluginInfo::fromServices(offers
);
83 Wallpaper
*Wallpaper::load(const QString
&wallpaperName
, const QVariantList
&args
)
85 if (wallpaperName
.isEmpty()) {
89 QString constraint
= QString("[X-KDE-PluginInfo-Name] == '%1'").arg(wallpaperName
);
90 KService::List offers
= KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint
);
92 if (offers
.isEmpty()) {
93 kDebug() << "offers is empty for " << wallpaperName
;
97 KService::Ptr offer
= offers
.first();
98 KPluginLoader
plugin(*offer
);
100 if (!Plasma::isPluginVersionCompatible(plugin
.pluginVersion())) {
104 QVariantList allArgs
;
105 allArgs
<< offer
->storageId() << args
;
107 Wallpaper
*wallpaper
= offer
->createInstance
<Plasma::Wallpaper
>(0, allArgs
, &error
);
110 kDebug() << "Couldn't load wallpaper \"" << wallpaperName
<< "\"! reason given: " << error
;
115 Wallpaper
*Wallpaper::load(const KPluginInfo
&info
, const QVariantList
&args
)
117 if (!info
.isValid()) {
120 return load(info
.pluginName(), args
);
123 QString
Wallpaper::name() const
125 if (!d
->wallpaperDescription
.isValid()) {
126 return i18n("Unknown Wallpaper");
129 return d
->wallpaperDescription
.name();
132 QString
Wallpaper::icon() const
134 if (!d
->wallpaperDescription
.isValid()) {
138 return d
->wallpaperDescription
.icon();
141 QString
Wallpaper::pluginName() const
143 if (!d
->wallpaperDescription
.isValid()) {
147 return d
->wallpaperDescription
.pluginName();
150 KServiceAction
Wallpaper::renderingMode() const
155 QList
<KServiceAction
> Wallpaper::listRenderingModes() const
157 if (!d
->wallpaperDescription
.isValid()) {
158 return QList
<KServiceAction
>();
161 return d
->wallpaperDescription
.service()->actions();
164 QRectF
Wallpaper::boundingRect() const
166 return d
->boundingRect
;
169 bool Wallpaper::isInitialized() const
171 return d
->initialized
;
174 void Wallpaper::setBoundingRect(const QRectF
&boundingRect
)
176 d
->boundingRect
= boundingRect
;
179 void Wallpaper::setRenderingMode(const QString
&mode
)
181 if (d
->mode
.name() == mode
) {
185 d
->mode
= KServiceAction();
186 if (!mode
.isEmpty()) {
187 QList
<KServiceAction
> modes
= listRenderingModes();
189 foreach (const KServiceAction
&action
, modes
) {
190 if (action
.name() == mode
) {
198 void Wallpaper::restore(const KConfigGroup
&config
)
200 d
->initialized
= true;
204 void Wallpaper::init(const KConfigGroup
&config
)
209 void Wallpaper::save(KConfigGroup
&config
)
214 QWidget
*Wallpaper::createConfigurationInterface(QWidget
*parent
)
220 void Wallpaper::mouseMoveEvent(QGraphicsSceneMouseEvent
*event
)
225 void Wallpaper::mousePressEvent(QGraphicsSceneMouseEvent
*event
)
230 void Wallpaper::mouseReleaseEvent(QGraphicsSceneMouseEvent
*event
)
235 void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent
*event
)
240 } // Plasma namespace
242 #include "wallpaper.moc"