2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Petri Damsten <damu@iki.fi>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wallpaper.h"
|
|
|
|
|
2010-04-29 07:57:34 +02:00
|
|
|
#include "config-plasma.h"
|
|
|
|
|
2009-04-02 08:31:37 +02:00
|
|
|
#include <QColor>
|
|
|
|
#include <QFile>
|
2009-04-10 21:49:33 +02:00
|
|
|
#include <QFileInfo>
|
2009-04-02 08:31:37 +02:00
|
|
|
#include <QImage>
|
2009-10-12 15:01:51 +02:00
|
|
|
#include <QAction>
|
2010-03-04 02:33:19 +01:00
|
|
|
#include <QQueue>
|
2009-10-29 06:54:11 +01:00
|
|
|
#include <QTimer>
|
2010-03-04 22:04:45 +01:00
|
|
|
#include <QRunnable>
|
|
|
|
#include <QThreadPool>
|
2009-04-02 08:31:37 +02:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
2009-04-02 08:31:37 +02:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
#include <kstandarddirs.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-04-29 19:25:05 +02:00
|
|
|
#ifndef PLASMA_NO_KIO
|
2009-04-10 21:49:33 +02:00
|
|
|
#include <kio/job.h>
|
2010-04-29 19:25:05 +02:00
|
|
|
#endif
|
2009-04-10 21:49:33 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <version.h>
|
|
|
|
|
2011-07-20 00:06:24 +02:00
|
|
|
#include "package.h"
|
|
|
|
#include "pluginloader.h"
|
|
|
|
#include "private/dataengineconsumer_p.h"
|
|
|
|
#include "private/packages_p.h"
|
|
|
|
#include "private/wallpaper_p.h"
|
2009-04-01 01:51:52 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-03-04 22:04:45 +01:00
|
|
|
class SaveImageThread : public QRunnable
|
|
|
|
{
|
|
|
|
QImage m_image;
|
|
|
|
QString m_filePath;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SaveImageThread(const QImage &image, const QString &filePath)
|
|
|
|
{
|
|
|
|
m_image = image;
|
|
|
|
m_filePath = filePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
m_image.save(m_filePath);
|
|
|
|
}
|
|
|
|
};
|
2010-10-14 14:27:15 +02:00
|
|
|
|
2010-03-05 00:22:24 +01:00
|
|
|
LoadImageThread::LoadImageThread(const QString &filePath)
|
|
|
|
{
|
|
|
|
m_filePath = filePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadImageThread::run()
|
|
|
|
{
|
|
|
|
QImage image;
|
|
|
|
image.load(m_filePath);
|
|
|
|
emit done(image);
|
|
|
|
}
|
2010-03-04 22:04:45 +01:00
|
|
|
|
2009-10-29 06:54:11 +01:00
|
|
|
class WallpaperWithPaint : public Wallpaper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WallpaperWithPaint(QObject *parent, const QVariantList &args)
|
|
|
|
: Wallpaper(parent, args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void paint(QPainter *painter, const QRectF &exposedRect)
|
|
|
|
{
|
|
|
|
if (d->script) {
|
|
|
|
d->script->paint(painter, exposedRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-07 07:45:20 +02:00
|
|
|
Wallpaper::Wallpaper(QObject * parentObject)
|
|
|
|
: d(new WallpaperPrivate(KService::serviceByStorageId(QString()), this))
|
|
|
|
{
|
|
|
|
setParent(parentObject);
|
|
|
|
}
|
2009-04-02 08:31:37 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args)
|
|
|
|
: d(new WallpaperPrivate(KService::serviceByStorageId(args.count() > 0 ?
|
|
|
|
args[0].toString() : QString()), this))
|
|
|
|
{
|
|
|
|
// now remove first item since those are managed by Wallpaper and subclasses shouldn't
|
|
|
|
// need to worry about them. yes, it violates the constness of this var, but it lets us add
|
|
|
|
// or remove items later while applets can just pretend that their args always start at 0
|
|
|
|
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
}
|
2009-04-02 08:31:37 +02:00
|
|
|
|
2009-04-07 07:45:20 +02:00
|
|
|
setParent(parentObject);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Wallpaper::~Wallpaper()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2011-01-20 20:50:11 +01:00
|
|
|
void Wallpaper::addUrls(const KUrl::List &urls)
|
|
|
|
{
|
2011-01-25 21:41:50 +01:00
|
|
|
if (d->script) {
|
2011-05-18 15:08:07 +02:00
|
|
|
d->script->addUrls(urls);
|
2011-01-25 21:41:50 +01:00
|
|
|
}
|
2011-01-20 20:50:11 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KPluginInfo::List Wallpaper::listWallpaperInfo(const QString &formFactor)
|
|
|
|
{
|
|
|
|
QString constraint;
|
2009-09-03 22:40:22 +02:00
|
|
|
if (!formFactor.isEmpty()) {
|
|
|
|
constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-05-06 12:23:42 +02:00
|
|
|
KPluginInfo::List Wallpaper::listWallpaperInfoForMimetype(const QString &mimeType, const QString &formFactor)
|
2009-09-03 22:40:22 +02:00
|
|
|
{
|
2011-05-06 12:23:42 +02:00
|
|
|
QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimeType);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!formFactor.isEmpty()) {
|
|
|
|
constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 22:40:22 +02:00
|
|
|
kDebug() << offers.count() << constraint;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2011-01-26 21:08:35 +01:00
|
|
|
bool Wallpaper::supportsMimetype(const QString &mimetype) const
|
|
|
|
{
|
|
|
|
return d->wallpaperDescription.isValid() &&
|
|
|
|
d->wallpaperDescription.service()->hasMimeType(mimetype);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Wallpaper *Wallpaper::load(const QString &wallpaperName, const QVariantList &args)
|
|
|
|
{
|
|
|
|
if (wallpaperName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(wallpaperName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "offers is empty for " << wallpaperName;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::Ptr offer = offers.first();
|
2009-10-29 06:54:11 +01:00
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << offer->storageId() << args;
|
|
|
|
|
|
|
|
if (!offer->property("X-Plasma-API").toString().isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-10-29 06:54:11 +01:00
|
|
|
kDebug() << "we have a script using the"
|
|
|
|
<< offer->property("X-Plasma-API").toString() << "API";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-10-29 06:54:11 +01:00
|
|
|
return new WallpaperWithPaint(0, allArgs);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KPluginLoader plugin(*offer);
|
|
|
|
|
|
|
|
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString error;
|
|
|
|
Wallpaper *wallpaper = offer->createInstance<Plasma::Wallpaper>(0, allArgs, &error);
|
|
|
|
|
|
|
|
if (!wallpaper) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "Couldn't load wallpaper \"" << wallpaperName << "\"! reason given: " << error;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-04-01 01:51:52 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return wallpaper;
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallpaper *Wallpaper::load(const KPluginInfo &info, const QVariantList &args)
|
|
|
|
{
|
|
|
|
if (!info.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return load(info.pluginName(), args);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallpaper::name() const
|
|
|
|
{
|
|
|
|
if (!d->wallpaperDescription.isValid()) {
|
|
|
|
return i18n("Unknown Wallpaper");
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->wallpaperDescription.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallpaper::icon() const
|
|
|
|
{
|
|
|
|
if (!d->wallpaperDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->wallpaperDescription.icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallpaper::pluginName() const
|
|
|
|
{
|
|
|
|
if (!d->wallpaperDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->wallpaperDescription.pluginName();
|
|
|
|
}
|
|
|
|
|
|
|
|
KServiceAction Wallpaper::renderingMode() const
|
|
|
|
{
|
|
|
|
return d->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<KServiceAction> Wallpaper::listRenderingModes() const
|
|
|
|
{
|
|
|
|
if (!d->wallpaperDescription.isValid()) {
|
|
|
|
return QList<KServiceAction>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->wallpaperDescription.service()->actions();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Wallpaper::boundingRect() const
|
|
|
|
{
|
|
|
|
return d->boundingRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallpaper::isInitialized() const
|
|
|
|
{
|
|
|
|
return d->initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setBoundingRect(const QRectF &boundingRect)
|
|
|
|
{
|
|
|
|
d->boundingRect = boundingRect;
|
2009-04-07 09:18:58 +02:00
|
|
|
|
2011-05-09 14:17:06 +02:00
|
|
|
if (d->targetSize != boundingRect.size()) {
|
2009-04-07 09:18:58 +02:00
|
|
|
d->targetSize = boundingRect.size();
|
|
|
|
emit renderHintsChanged();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setRenderingMode(const QString &mode)
|
|
|
|
{
|
|
|
|
if (d->mode.name() == mode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->mode = KServiceAction();
|
|
|
|
if (!mode.isEmpty()) {
|
|
|
|
QList<KServiceAction> modes = listRenderingModes();
|
|
|
|
|
|
|
|
foreach (const KServiceAction &action, modes) {
|
|
|
|
if (action.name() == mode) {
|
|
|
|
d->mode = action;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::restore(const KConfigGroup &config)
|
|
|
|
{
|
|
|
|
init(config);
|
2009-04-08 19:26:22 +02:00
|
|
|
d->initialized = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::init(const KConfigGroup &config)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
2009-11-17 14:29:40 +01:00
|
|
|
d->initScript();
|
2009-10-29 06:54:11 +01:00
|
|
|
d->script->initWallpaper(config);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::save(KConfigGroup &config)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
d->script->save(config);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *Wallpaper::createConfigurationInterface(QWidget *parent)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
return d->script->createConfigurationInterface(parent);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
return d->script->mouseMoveEvent(event);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
return d->script->mousePressEvent(event);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
return d->script->mouseReleaseEvent(event);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|
|
|
{
|
2009-10-29 06:54:11 +01:00
|
|
|
if (d->script) {
|
|
|
|
return d->script->wheelEvent(event);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-04-01 01:51:52 +02:00
|
|
|
DataEngine *Wallpaper::dataEngine(const QString &name) const
|
|
|
|
{
|
|
|
|
return d->dataEngine(name);
|
|
|
|
}
|
|
|
|
|
2009-04-02 06:15:50 +02:00
|
|
|
bool Wallpaper::configurationRequired() const
|
|
|
|
{
|
|
|
|
return d->needsConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setConfigurationRequired(bool needsConfig, const QString &reason)
|
|
|
|
{
|
|
|
|
//TODO: implement something for reason. first, we need to decide where/how
|
|
|
|
// to communicate it to the user
|
|
|
|
Q_UNUSED(reason)
|
|
|
|
|
|
|
|
if (d->needsConfig == needsConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->needsConfig = needsConfig;
|
|
|
|
emit configurationRequired(needsConfig);
|
|
|
|
}
|
|
|
|
|
2009-05-13 18:13:56 +02:00
|
|
|
bool Wallpaper::isUsingRenderingCache() const
|
2009-04-02 08:31:37 +02:00
|
|
|
{
|
|
|
|
return d->cacheRendering;
|
|
|
|
}
|
|
|
|
|
2009-05-13 18:13:56 +02:00
|
|
|
void Wallpaper::setUsingRenderingCache(bool useCache)
|
2009-04-02 08:31:37 +02:00
|
|
|
{
|
|
|
|
d->cacheRendering = useCache;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:18:58 +02:00
|
|
|
void Wallpaper::setResizeMethodHint(Wallpaper::ResizeMethod resizeMethod)
|
|
|
|
{
|
2011-09-19 16:18:52 +02:00
|
|
|
const ResizeMethod method = qBound(ScaledResize, resizeMethod, LastResizeMethod);
|
|
|
|
if (method != d->lastResizeMethod) {
|
|
|
|
d->lastResizeMethod = method;
|
|
|
|
emit renderHintsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallpaper::ResizeMethod Wallpaper::resizeMethodHint() const
|
|
|
|
{
|
|
|
|
return d->lastResizeMethod;
|
2009-04-07 09:18:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setTargetSizeHint(const QSizeF &targetSize)
|
|
|
|
{
|
2011-09-19 16:18:52 +02:00
|
|
|
if (targetSize != d->targetSize) {
|
|
|
|
d->targetSize = targetSize;
|
|
|
|
emit renderHintsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Wallpaper::targetSizeHint() const
|
|
|
|
{
|
|
|
|
return d->targetSize;
|
2009-04-07 09:18:58 +02:00
|
|
|
}
|
|
|
|
|
2011-10-30 10:24:57 +01:00
|
|
|
void Wallpaper::render(const QImage &image, const QSize &size,
|
|
|
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color)
|
|
|
|
{
|
|
|
|
if (image.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->renderWallpaper(QString(), image, size, resizeMethod, color);
|
|
|
|
}
|
|
|
|
|
2009-04-02 08:31:37 +02:00
|
|
|
void Wallpaper::render(const QString &sourceImagePath, const QSize &size,
|
|
|
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color)
|
|
|
|
{
|
|
|
|
if (sourceImagePath.isEmpty() || !QFile::exists(sourceImagePath)) {
|
2009-04-02 19:21:42 +02:00
|
|
|
//kDebug() << "failed on:" << sourceImagePath;
|
2009-04-02 08:31:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-30 10:24:57 +01:00
|
|
|
d->renderWallpaper(sourceImagePath, QImage(), size, resizeMethod, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WallpaperPrivate::renderWallpaper(const QString &sourceImagePath, const QImage &image, const QSize &size,
|
|
|
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color)
|
|
|
|
{
|
|
|
|
resizeMethod = qBound(Wallpaper::ScaledResize, resizeMethod, Wallpaper::LastResizeMethod);
|
|
|
|
if (lastResizeMethod != resizeMethod) {
|
|
|
|
lastResizeMethod = resizeMethod;
|
|
|
|
emit q->renderHintsChanged();
|
2009-04-07 09:18:58 +02:00
|
|
|
}
|
2009-04-07 07:45:20 +02:00
|
|
|
|
2011-10-30 10:24:57 +01:00
|
|
|
if (cacheRendering) {
|
2009-04-10 21:49:33 +02:00
|
|
|
QFileInfo info(sourceImagePath);
|
2011-10-30 10:24:57 +01:00
|
|
|
QString cache = cacheKey(sourceImagePath, size, resizeMethod, color);
|
|
|
|
if (findInCache(cache, info.lastModified().toTime_t())) {
|
2009-04-02 08:31:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-30 13:29:38 +02:00
|
|
|
WallpaperRenderRequest request;
|
2011-10-30 10:24:57 +01:00
|
|
|
renderToken = request.token;
|
|
|
|
request.requester = q;
|
|
|
|
request.providedImage = image;
|
2011-04-30 13:29:38 +02:00
|
|
|
request.file = sourceImagePath;
|
|
|
|
request.size = size;
|
|
|
|
request.resizeMethod = resizeMethod;
|
|
|
|
request.color = color;
|
|
|
|
WallpaperRenderThread::render(request);
|
2009-04-02 19:21:42 +02:00
|
|
|
//kDebug() << "rendering" << sourceImagePath << ", token is" << d->renderToken;
|
2009-04-02 08:31:37 +02:00
|
|
|
}
|
|
|
|
|
2009-10-29 06:54:11 +01:00
|
|
|
WallpaperPrivate::WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
|
|
|
|
q(wallpaper),
|
|
|
|
wallpaperDescription(service),
|
|
|
|
package(0),
|
|
|
|
renderToken(-1),
|
|
|
|
lastResizeMethod(Wallpaper::ScaledResize),
|
|
|
|
script(0),
|
|
|
|
cacheRendering(false),
|
|
|
|
initialized(false),
|
2009-11-17 14:29:40 +01:00
|
|
|
needsConfig(false),
|
2010-03-05 01:54:30 +01:00
|
|
|
scriptInitialized(false),
|
2010-08-12 21:51:39 +02:00
|
|
|
previewing(false),
|
|
|
|
needsPreviewDuringConfiguration(false)
|
2009-10-29 06:54:11 +01:00
|
|
|
{
|
|
|
|
if (wallpaperDescription.isValid()) {
|
|
|
|
QString api = wallpaperDescription.property("X-Plasma-API").toString();
|
|
|
|
|
|
|
|
if (!api.isEmpty()) {
|
|
|
|
const QString path = KStandardDirs::locate("data",
|
|
|
|
"plasma/wallpapers/" + wallpaperDescription.pluginName() + '/');
|
2011-07-20 00:06:24 +02:00
|
|
|
package = new Package(PluginLoader::self()->loadPackage("Plasma/Wallpaper", api));
|
2011-07-15 12:58:06 +02:00
|
|
|
package->setPath(path);
|
|
|
|
|
|
|
|
if (package->isValid()) {
|
|
|
|
script = Plasma::loadScriptEngine(api, q);
|
|
|
|
}
|
2009-10-29 06:54:11 +01:00
|
|
|
|
|
|
|
if (!script) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-10-29 06:54:11 +01:00
|
|
|
kDebug() << "Could not create a" << api << "ScriptEngine for the"
|
2011-07-29 15:46:52 +02:00
|
|
|
<< wallpaperDescription.name() << "Wallpaper.";
|
|
|
|
#endif
|
2009-10-29 06:54:11 +01:00
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
2011-07-15 12:58:06 +02:00
|
|
|
}
|
2009-10-29 06:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:49:33 +02:00
|
|
|
QString WallpaperPrivate::cacheKey(const QString &sourceImagePath, const QSize &size,
|
|
|
|
int resizeMethod, const QColor &color) const
|
2009-04-02 08:31:37 +02:00
|
|
|
{
|
2009-04-10 21:49:33 +02:00
|
|
|
const QString id = QString("%5_%3_%4_%1x%2")
|
2009-04-02 08:31:37 +02:00
|
|
|
.arg(size.width()).arg(size.height()).arg(color.name())
|
|
|
|
.arg(resizeMethod).arg(sourceImagePath);
|
2009-04-10 21:49:33 +02:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WallpaperPrivate::cachePath(const QString &key) const
|
|
|
|
{
|
|
|
|
return KGlobal::dirs()->locateLocal("cache", "plasma-wallpapers/" + key + ".png");
|
2009-04-02 08:31:37 +02:00
|
|
|
}
|
|
|
|
|
2011-04-30 13:29:38 +02:00
|
|
|
void WallpaperPrivate::newRenderCompleted(const WallpaperRenderRequest &request, const QImage &image)
|
2009-04-02 08:31:37 +02:00
|
|
|
{
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2011-04-30 13:29:38 +02:00
|
|
|
kDebug() << request.token << renderToken;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-04-30 13:29:38 +02:00
|
|
|
if (request.token != renderToken) {
|
2009-04-02 19:21:42 +02:00
|
|
|
//kDebug() << "render token mismatch" << token << renderToken;
|
2009-04-02 08:31:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cacheRendering) {
|
2011-04-30 13:29:38 +02:00
|
|
|
q->insertIntoCache(cacheKey(request.file, request.size, request.resizeMethod, request.color), image);
|
2009-04-02 08:31:37 +02:00
|
|
|
}
|
|
|
|
|
2009-04-02 19:21:42 +02:00
|
|
|
//kDebug() << "rendering complete!";
|
2009-04-02 08:48:30 +02:00
|
|
|
emit q->renderCompleted(image);
|
2009-04-02 08:31:37 +02:00
|
|
|
}
|
|
|
|
|
2009-10-29 06:54:11 +01:00
|
|
|
// put all setup routines for script here. at this point we can assume that
|
|
|
|
// package exists and that we have a script engine
|
|
|
|
void WallpaperPrivate::setupScriptSupport()
|
|
|
|
{
|
|
|
|
Q_ASSERT(package);
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-10-29 06:54:11 +01:00
|
|
|
kDebug() << "setting up script support, package is in" << package->path()
|
|
|
|
<< ", main script is" << package->filePath("mainscript");
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-10-29 06:54:11 +01:00
|
|
|
|
2011-05-31 00:11:55 +02:00
|
|
|
const QString translationsPath = package->filePath("translations");
|
2009-10-29 06:54:11 +01:00
|
|
|
if (!translationsPath.isEmpty()) {
|
|
|
|
KGlobal::dirs()->addResourceDir("locale", translationsPath);
|
2011-05-31 00:11:55 +02:00
|
|
|
KGlobal::locale()->insertCatalog(wallpaperDescription.pluginName());
|
2009-10-29 06:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WallpaperPrivate::initScript()
|
|
|
|
{
|
2009-11-17 14:29:40 +01:00
|
|
|
if (script && !scriptInitialized) {
|
2009-10-29 06:54:11 +01:00
|
|
|
setupScriptSupport();
|
|
|
|
script->init();
|
2009-11-17 14:29:40 +01:00
|
|
|
scriptInitialized = true;
|
2009-10-29 06:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 00:22:24 +01:00
|
|
|
bool WallpaperPrivate::findInCache(const QString &key, unsigned int lastModified)
|
|
|
|
{
|
|
|
|
if (cacheRendering) {
|
|
|
|
QString cache = cachePath(key);
|
|
|
|
if (QFile::exists(cache)) {
|
|
|
|
if (lastModified > 0) {
|
|
|
|
QFileInfo info(cache);
|
|
|
|
if (info.lastModified().toTime_t() < lastModified) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadImageThread *loadImageT = new LoadImageThread(cache);
|
2012-01-22 03:11:26 +01:00
|
|
|
q->connect(loadImageT, SIGNAL(done(QImage)), q, SIGNAL(renderCompleted(QImage)));
|
2010-03-05 00:22:24 +01:00
|
|
|
QThreadPool::globalInstance()->start(loadImageT);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:49:33 +02:00
|
|
|
bool Wallpaper::findInCache(const QString &key, QImage &image, unsigned int lastModified)
|
|
|
|
{
|
|
|
|
if (d->cacheRendering) {
|
|
|
|
QString cache = d->cachePath(key);
|
|
|
|
if (QFile::exists(cache)) {
|
|
|
|
if (lastModified > 0) {
|
|
|
|
QFileInfo info(cache);
|
|
|
|
if (info.lastModified().toTime_t() < lastModified) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image.load(cache);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::insertIntoCache(const QString& key, const QImage &image)
|
|
|
|
{
|
|
|
|
//TODO: cache limits?
|
2009-04-14 19:37:40 +02:00
|
|
|
if (key.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:49:33 +02:00
|
|
|
if (d->cacheRendering) {
|
|
|
|
if (image.isNull()) {
|
2010-04-29 19:24:16 +02:00
|
|
|
#ifndef PLASMA_NO_KIO
|
2009-04-14 19:37:40 +02:00
|
|
|
KIO::file_delete(d->cachePath(key));
|
2010-04-29 19:24:16 +02:00
|
|
|
#else
|
|
|
|
QFile f(d->cachePath(key));
|
2010-10-14 14:27:15 +02:00
|
|
|
f.remove();
|
2010-04-29 19:24:16 +02:00
|
|
|
#endif
|
2009-04-10 21:49:33 +02:00
|
|
|
} else {
|
2010-03-04 22:04:45 +01:00
|
|
|
QThreadPool::globalInstance()->start(new SaveImageThread(image, d->cachePath(key)));
|
2009-04-10 21:49:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-12 15:01:51 +02:00
|
|
|
QList<QAction*> Wallpaper::contextualActions() const
|
|
|
|
{
|
2011-05-06 11:57:49 +02:00
|
|
|
return d->contextActions;
|
2009-10-12 15:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setContextualActions(const QList<QAction*> &actions)
|
|
|
|
{
|
2011-05-06 11:57:49 +02:00
|
|
|
d->contextActions = actions;
|
2009-10-12 15:01:51 +02:00
|
|
|
}
|
|
|
|
|
2010-03-05 01:54:30 +01:00
|
|
|
bool Wallpaper::isPreviewing() const
|
|
|
|
{
|
|
|
|
return d->previewing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setPreviewing(bool previewing)
|
|
|
|
{
|
|
|
|
d->previewing = previewing;
|
|
|
|
}
|
|
|
|
|
2010-08-12 21:51:39 +02:00
|
|
|
bool Wallpaper::needsPreviewDuringConfiguration() const
|
|
|
|
{
|
|
|
|
return d->needsPreviewDuringConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallpaper::setPreviewDuringConfiguration(const bool preview)
|
|
|
|
{
|
|
|
|
d->needsPreviewDuringConfiguration = preview;
|
|
|
|
}
|
|
|
|
|
2011-07-15 12:58:06 +02:00
|
|
|
Package Wallpaper::package() const
|
2009-10-29 06:54:11 +01:00
|
|
|
{
|
2011-07-15 12:58:06 +02:00
|
|
|
return d->package ? *d->package : Package();
|
2009-10-29 06:54:11 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
|
|
|
|
#include "moc_wallpaper.cpp"
|
|
|
|
#include "private/moc_wallpaper_p.cpp"
|