From 8a527b7b09a30cfad88cbc74d784b7d2081aa338 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 7 Apr 2009 05:45:20 +0000 Subject: [PATCH] * move Wallpaper::Private to its own class * introduce a default ctor for Wallpaper * allow associating a Wallpaper PackageStructure with a Wallpaper object so that the structure can pull info from the paper svn path=/trunk/KDE/kdelibs/; revision=950410 --- private/wallpaper_p.h | 69 +++++++++++++++++++++++++++++++++++++++++++ wallpaper.cpp | 64 ++++++++++++++------------------------- wallpaper.h | 16 ++++++++-- 3 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 private/wallpaper_p.h diff --git a/private/wallpaper_p.h b/private/wallpaper_p.h new file mode 100644 index 000000000..9dafce4a5 --- /dev/null +++ b/private/wallpaper_p.h @@ -0,0 +1,69 @@ +/* + * Copyright 2008 by Aaron Seigo + * Copyright 2008 by Petri Damsten + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PLASMA_WALLPAPERPRIVATE_H +#define PLASMA_WALLPAPERPRIVATE_H + +#include "plasma/private/dataengineconsumer_p.h" +#include "plasma/private/wallpaperrenderthread_p.h" + +namespace Plasma +{ + +class WallpaperPrivate : public DataEngineConsumer +{ +public: + WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) : + q(wallpaper), + wallpaperDescription(service), + renderToken(-1), + lastResizeMethod(Wallpaper::ScaledResize), + cacheRendering(false), + initialized(false), + needsConfig(false) + { + }; + + QString cachePath(const QString &sourceImagePath, const QSize &size, + int resizeMethod, const QColor &color) const; + + + void renderCompleted(int token, const QImage &image, + const QString &sourceImagePath, const QSize &size, + int resizeMethod, const QColor &color); + + static WallpaperRenderThread s_renderer; + static PackageStructure::Ptr s_packageStructure; + + Wallpaper *q; + KPluginInfo wallpaperDescription; + Package *package; + QRectF boundingRect; + KServiceAction mode; + int renderToken; + Wallpaper::ResizeMethod lastResizeMethod; + bool cacheRendering : 1; + bool initialized : 1; + bool needsConfig : 1; +}; + +} // namespace Plasma +#endif + diff --git a/wallpaper.cpp b/wallpaper.cpp index 5205891a7..abe75a13c 100644 --- a/wallpaper.cpp +++ b/wallpaper.cpp @@ -33,47 +33,21 @@ #include "plasma/private/dataengineconsumer_p.h" #include "plasma/private/packages_p.h" -#include "plasma/private/wallpaperrenderthread_p.h" +#include "plasma/private/wallpaper_p.h" namespace Plasma { -class WallpaperPrivate : public DataEngineConsumer -{ -public: - WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) : - q(wallpaper), - wallpaperDescription(service), - renderToken(-1), - cacheRendering(false), - initialized(false), - needsConfig(false) - { - }; - - QString cachePath(const QString &sourceImagePath, const QSize &size, - int resizeMethod, const QColor &color) const; - - - void renderCompleted(int token, const QImage &image, - const QString &sourceImagePath, const QSize &size, - int resizeMethod, const QColor &color); - - static WallpaperRenderThread s_renderer; - static PackageStructure::Ptr packageStructure; - - Wallpaper *q; - KPluginInfo wallpaperDescription; - QRectF boundingRect; - KServiceAction mode; - int renderToken; - bool cacheRendering : 1; - bool initialized : 1; - bool needsConfig : 1; -}; - WallpaperRenderThread WallpaperPrivate::s_renderer; -PackageStructure::Ptr WallpaperPrivate::packageStructure(0); +PackageStructure::Ptr WallpaperPrivate::s_packageStructure(0); + +Wallpaper::Wallpaper(QObject * parentObject) + : d(new WallpaperPrivate(KService::serviceByStorageId(QString()), this)) +{ + setParent(parentObject); + connect(&WallpaperPrivate::s_renderer, SIGNAL(done(int,QImage,QString,QSize,int,QColor)), + this, SLOT(renderCompleted(int,QImage,QString,QSize,int,QColor))); +} Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args) : d(new WallpaperPrivate(KService::serviceByStorageId(args.count() > 0 ? @@ -86,8 +60,8 @@ Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args) if (!mutableArgs.isEmpty()) { mutableArgs.removeFirst(); } - setParent(parentObject); + setParent(parentObject); connect(&WallpaperPrivate::s_renderer, SIGNAL(done(int,QImage,QString,QSize,int,QColor)), this, SLOT(renderCompleted(int,QImage,QString,QSize,int,QColor))); } @@ -150,15 +124,19 @@ Wallpaper *Wallpaper::load(const KPluginInfo &info, const QVariantList &args) return load(info.pluginName(), args); } -PackageStructure::Ptr Wallpaper::packageStructure() +PackageStructure::Ptr Wallpaper::packageStructure(Wallpaper *paper) { - if (!WallpaperPrivate::packageStructure) { - WallpaperPrivate::packageStructure = new WallpaperPackage(); + if (paper) { + PackageStructure::Ptr package(new WallpaperPackage(paper, paper)); + return package; } - return WallpaperPrivate::packageStructure; -} + if (!WallpaperPrivate::s_packageStructure) { + WallpaperPrivate::s_packageStructure = new WallpaperPackage(); + } + return WallpaperPrivate::s_packageStructure; +} QString Wallpaper::name() const { @@ -319,6 +297,8 @@ void Wallpaper::render(const QString &sourceImagePath, const QSize &size, return; } + d->lastResizeMethod = resizeMethod; + if (d->cacheRendering) { QString cache = d->cachePath(sourceImagePath, size, resizeMethod, color); if (QFile::exists(cache)) { diff --git a/wallpaper.h b/wallpaper.h index 089944b6e..f5c0404cd 100644 --- a/wallpaper.h +++ b/wallpaper.h @@ -75,6 +75,11 @@ class PLASMA_EXPORT Wallpaper : public QObject }; Q_ENUMS(ResizeMethod) + /** + * Default constructor for an empty or null wallpaper + */ + explicit Wallpaper(QObject * parent = 0); + ~Wallpaper(); /** @@ -111,9 +116,15 @@ class PLASMA_EXPORT Wallpaper : public QObject static Wallpaper *load(const KPluginInfo &info, const QVariantList &args = QVariantList()); /** - * Returns the Package specialization for wallpapers + * Returns the Package specialization for wallpapers. May be queried for 'preferred' + * which will return the preferred wallpaper image path given the associated Wallpaper + * object, if any. + * + * @param paper the Wallpaper object to associated the PackageStructure with, + * which will then use the Wallpaper object to define things such as + * default size and resize methods. */ - static PackageStructure::Ptr packageStructure(); + static PackageStructure::Ptr packageStructure(Wallpaper *paper = 0); /** * Returns the user-visible name for the wallpaper, as specified in the @@ -358,6 +369,7 @@ class PLASMA_EXPORT Wallpaper : public QObject const QString &sourceImagePath, const QSize &size, int resizeMethod, const QColor &color)) + friend class WallpaperPackage; friend class WallpaperPrivate; WallpaperPrivate *const d; };