some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / plasma / wallpaper.cpp
blobae75db84846b7e1831c817d622ca0292993d51bc
1 /*
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>
24 #include <kdebug.h>
26 #include <version.h>
28 namespace Plasma
31 class WallpaperPrivate
33 public:
34 WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
35 q(wallpaper),
36 wallpaperDescription(service),
37 initialized(false)
41 ~WallpaperPrivate()
45 Wallpaper *q;
46 KPluginInfo wallpaperDescription;
47 QRectF boundingRect;
48 KServiceAction mode;
49 bool initialized;
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()
68 delete d;
71 KPluginInfo::List Wallpaper::listWallpaperInfo(const QString &formFactor)
73 QString constraint;
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()) {
86 return 0;
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;
94 return 0;
97 KService::Ptr offer = offers.first();
98 KPluginLoader plugin(*offer);
100 if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
101 return 0;
104 QVariantList allArgs;
105 allArgs << offer->storageId() << args;
106 QString error;
107 Wallpaper *wallpaper = offer->createInstance<Plasma::Wallpaper>(0, allArgs, &error);
109 if (!wallpaper) {
110 kDebug() << "Couldn't load wallpaper \"" << wallpaperName << "\"! reason given: " << error;
112 return wallpaper;
115 Wallpaper *Wallpaper::load(const KPluginInfo &info, const QVariantList &args)
117 if (!info.isValid()) {
118 return 0;
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()) {
135 return QString();
138 return d->wallpaperDescription.icon();
141 QString Wallpaper::pluginName() const
143 if (!d->wallpaperDescription.isValid()) {
144 return QString();
147 return d->wallpaperDescription.pluginName();
150 KServiceAction Wallpaper::renderingMode() const
152 return d->mode;
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) {
182 return;
185 d->mode = KServiceAction();
186 if (!mode.isEmpty()) {
187 QList<KServiceAction> modes = listRenderingModes();
189 foreach (const KServiceAction &action, modes) {
190 if (action.name() == mode) {
191 d->mode = action;
192 break;
198 void Wallpaper::restore(const KConfigGroup &config)
200 d->initialized = true;
201 init(config);
204 void Wallpaper::init(const KConfigGroup &config)
206 Q_UNUSED(config);
209 void Wallpaper::save(KConfigGroup &config)
211 Q_UNUSED(config);
214 QWidget *Wallpaper::createConfigurationInterface(QWidget *parent)
216 Q_UNUSED(parent);
217 return 0;
220 void Wallpaper::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
222 Q_UNUSED(event)
225 void Wallpaper::mousePressEvent(QGraphicsSceneMouseEvent *event)
227 Q_UNUSED(event)
230 void Wallpaper::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
232 Q_UNUSED(event)
235 void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent *event)
237 Q_UNUSED(event)
240 } // Plasma namespace
242 #include "wallpaper.moc"