• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

wallpaper.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 by Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2008 by Petri Damsten <damu@iki.fi>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "wallpaper.h"
00022 
00023 #include <kservicetypetrader.h>
00024 #include <kdebug.h>
00025 
00026 #include <version.h>
00027 
00028 namespace Plasma
00029 {
00030 
00031 class WallpaperPrivate
00032 {
00033 public:
00034     WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
00035         q(wallpaper),
00036         wallpaperDescription(service),
00037         initialized(false)
00038     {
00039     };
00040 
00041     ~WallpaperPrivate()
00042     {
00043     };
00044 
00045     Wallpaper *q;
00046     KPluginInfo wallpaperDescription;
00047     QRectF boundingRect;
00048     KServiceAction mode;
00049     bool initialized;
00050 };
00051 
00052 Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args)
00053     : d(new WallpaperPrivate(KService::serviceByStorageId(args.count() > 0 ?
00054                              args[0].toString() : QString()), this))
00055 {
00056     // now remove first item since those are managed by Wallpaper and subclasses shouldn't
00057     // need to worry about them. yes, it violates the constness of this var, but it lets us add
00058     // or remove items later while applets can just pretend that their args always start at 0
00059     QVariantList &mutableArgs = const_cast<QVariantList &>(args);
00060     if (!mutableArgs.isEmpty()) {
00061         mutableArgs.removeFirst();
00062     }
00063     setParent(parentObject);
00064 }
00065 
00066 Wallpaper::~Wallpaper()
00067 {
00068     delete d;
00069 }
00070 
00071 KPluginInfo::List Wallpaper::listWallpaperInfo(const QString &formFactor)
00072 {
00073     QString constraint;
00074 
00075     if (!formFactor.isEmpty()) {
00076         constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'");
00077     }
00078 
00079     KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
00080     return KPluginInfo::fromServices(offers);
00081 }
00082 
00083 Wallpaper *Wallpaper::load(const QString &wallpaperName, const QVariantList &args)
00084 {
00085     if (wallpaperName.isEmpty()) {
00086         return 0;
00087     }
00088 
00089     QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(wallpaperName);
00090     KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
00091 
00092     if (offers.isEmpty()) {
00093         kDebug() << "offers is empty for " << wallpaperName;
00094         return 0;
00095     }
00096 
00097     KService::Ptr offer = offers.first();
00098     KPluginLoader plugin(*offer);
00099 
00100     if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
00101         return 0;
00102     }
00103 
00104     QVariantList allArgs;
00105     allArgs << offer->storageId() << args;
00106     QString error;
00107     Wallpaper *wallpaper = offer->createInstance<Plasma::Wallpaper>(0, allArgs, &error);
00108 
00109     if (!wallpaper) {
00110         kDebug() << "Couldn't load wallpaper \"" << wallpaperName << "\"! reason given: " << error;
00111     }
00112     return wallpaper;
00113 }
00114 
00115 Wallpaper *Wallpaper::load(const KPluginInfo &info, const QVariantList &args)
00116 {
00117     if (!info.isValid()) {
00118         return 0;
00119     }
00120     return load(info.pluginName(), args);
00121 }
00122 
00123 QString Wallpaper::name() const
00124 {
00125     if (!d->wallpaperDescription.isValid()) {
00126         return i18n("Unknown Wallpaper");
00127     }
00128 
00129     return d->wallpaperDescription.name();
00130 }
00131 
00132 QString Wallpaper::icon() const
00133 {
00134     if (!d->wallpaperDescription.isValid()) {
00135         return QString();
00136     }
00137 
00138     return d->wallpaperDescription.icon();
00139 }
00140 
00141 QString Wallpaper::pluginName() const
00142 {
00143     if (!d->wallpaperDescription.isValid()) {
00144         return QString();
00145     }
00146 
00147     return d->wallpaperDescription.pluginName();
00148 }
00149 
00150 KServiceAction Wallpaper::renderingMode() const
00151 {
00152     return d->mode;
00153 }
00154 
00155 QList<KServiceAction> Wallpaper::listRenderingModes() const
00156 {
00157     if (!d->wallpaperDescription.isValid()) {
00158         return QList<KServiceAction>();
00159     }
00160 
00161     return d->wallpaperDescription.service()->actions();
00162 }
00163 
00164 QRectF Wallpaper::boundingRect() const
00165 {
00166     return d->boundingRect;
00167 }
00168 
00169 bool Wallpaper::isInitialized() const
00170 {
00171     return d->initialized;
00172 }
00173 
00174 void Wallpaper::setBoundingRect(const QRectF &boundingRect)
00175 {
00176     d->boundingRect = boundingRect;
00177 }
00178 
00179 void Wallpaper::setRenderingMode(const QString &mode)
00180 {
00181     if (d->mode.name() == mode) {
00182         return;
00183     }
00184 
00185     d->mode = KServiceAction();
00186     if (!mode.isEmpty()) {
00187         QList<KServiceAction> modes = listRenderingModes();
00188 
00189         foreach (const KServiceAction &action, modes) {
00190             if (action.name() == mode) {
00191                 d->mode = action;
00192                 break;
00193             }
00194         }
00195     }
00196 }
00197 
00198 void Wallpaper::restore(const KConfigGroup &config)
00199 {
00200     d->initialized = true;
00201     init(config);
00202 }
00203 
00204 void Wallpaper::init(const KConfigGroup &config)
00205 {
00206     Q_UNUSED(config);
00207 }
00208 
00209 void Wallpaper::save(KConfigGroup &config)
00210 {
00211     Q_UNUSED(config);
00212 }
00213 
00214 QWidget *Wallpaper::createConfigurationInterface(QWidget *parent)
00215 {
00216     Q_UNUSED(parent);
00217     return 0;
00218 }
00219 
00220 void Wallpaper::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
00221 {
00222     Q_UNUSED(event)
00223 }
00224 
00225 void Wallpaper::mousePressEvent(QGraphicsSceneMouseEvent *event)
00226 {
00227     Q_UNUSED(event)
00228 }
00229 
00230 void Wallpaper::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
00231 {
00232     Q_UNUSED(event)
00233 }
00234 
00235 void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent *event)
00236 {
00237     Q_UNUSED(event)
00238 }
00239 
00240 } // Plasma namespace
00241 
00242 #include "wallpaper.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal