abstract the bit of data engine management code out into a small class that the private classes can then subclass, and add dataEngine(const QString &) to Wallpaper
svn path=/trunk/KDE/kdelibs/; revision=947636
This commit is contained in:
parent
d0e40170fa
commit
89b70374c3
16
applet.cpp
16
applet.cpp
@ -574,17 +574,7 @@ ConfigLoader *Applet::configScheme() const
|
|||||||
|
|
||||||
DataEngine *Applet::dataEngine(const QString &name) const
|
DataEngine *Applet::dataEngine(const QString &name) const
|
||||||
{
|
{
|
||||||
int index = d->loadedEngines.indexOf(name);
|
return d->dataEngine(name);
|
||||||
if (index != -1) {
|
|
||||||
return DataEngineManager::self()->engine(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
DataEngine *engine = DataEngineManager::self()->loadEngine(name);
|
|
||||||
if (engine->isValid()) {
|
|
||||||
d->loadedEngines.append(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Package *Applet::package() const
|
const Package *Applet::package() const
|
||||||
@ -2035,10 +2025,6 @@ AppletPrivate::~AppletPrivate()
|
|||||||
activationAction->forgetGlobalShortcut();
|
activationAction->forgetGlobalShortcut();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QString &engine, loadedEngines) {
|
|
||||||
DataEngineManager::self()->unloadEngine(engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extender) {
|
if (extender) {
|
||||||
delete extender;
|
delete extender;
|
||||||
extender = 0;
|
extender = 0;
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include <kactioncollection.h>
|
#include <kactioncollection.h>
|
||||||
|
|
||||||
|
#include "plasma/private/dataengineconsumer_p.h"
|
||||||
|
|
||||||
class KKeySequenceWidget;
|
class KKeySequenceWidget;
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
@ -51,7 +53,7 @@ protected Q_SLOTS:
|
|||||||
void overlayAnimationComplete();
|
void overlayAnimationComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppletPrivate
|
class AppletPrivate : public DataEngineConsumer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet);
|
AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet);
|
||||||
@ -107,7 +109,6 @@ public:
|
|||||||
AppletOverlayWidget *messageOverlay;
|
AppletOverlayWidget *messageOverlay;
|
||||||
Plasma::BusyWidget *busyWidget;
|
Plasma::BusyWidget *busyWidget;
|
||||||
QSet<QGraphicsItem*> registeredAsDragHandle;
|
QSet<QGraphicsItem*> registeredAsDragHandle;
|
||||||
QStringList loadedEngines;
|
|
||||||
Plasma::FrameSvg *background;
|
Plasma::FrameSvg *background;
|
||||||
AppletScript *script;
|
AppletScript *script;
|
||||||
QVariantList args;
|
QVariantList args;
|
||||||
|
65
private/dataengineconsumer_p.h
Normal file
65
private/dataengineconsumer_p.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
||||||
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
||||||
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
||||||
|
*
|
||||||
|
* 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_DATAENGINECONSUMER_H
|
||||||
|
#define PLASMA_DATAENGINECONSUMER_H
|
||||||
|
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
|
#include "plasma/dataenginemanager.h"
|
||||||
|
|
||||||
|
namespace Plasma
|
||||||
|
{
|
||||||
|
|
||||||
|
class DataEngineConsumer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~DataEngineConsumer()
|
||||||
|
{
|
||||||
|
foreach (const QString &engine, m_loadedEngines) {
|
||||||
|
DataEngineManager::self()->unloadEngine(engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataEngine *dataEngine(const QString &name)
|
||||||
|
{
|
||||||
|
int index = m_loadedEngines.indexOf(name);
|
||||||
|
if (index != -1) {
|
||||||
|
return DataEngineManager::self()->engine(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataEngine *engine = DataEngineManager::self()->loadEngine(name);
|
||||||
|
if (engine->isValid()) {
|
||||||
|
m_loadedEngines.append(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList m_loadedEngines;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Plasma
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -25,10 +25,12 @@
|
|||||||
|
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
|
#include "plasma/private/dataengineconsumer_p.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class WallpaperPrivate
|
class WallpaperPrivate : public DataEngineConsumer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
|
WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
|
||||||
@ -109,6 +111,7 @@ Wallpaper *Wallpaper::load(const QString &wallpaperName, const QVariantList &arg
|
|||||||
if (!wallpaper) {
|
if (!wallpaper) {
|
||||||
kDebug() << "Couldn't load wallpaper \"" << wallpaperName << "\"! reason given: " << error;
|
kDebug() << "Couldn't load wallpaper \"" << wallpaperName << "\"! reason given: " << error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wallpaper;
|
return wallpaper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +240,11 @@ void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataEngine *Wallpaper::dataEngine(const QString &name) const
|
||||||
|
{
|
||||||
|
return d->dataEngine(name);
|
||||||
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
#include "wallpaper.moc"
|
#include "wallpaper.moc"
|
||||||
|
21
wallpaper.h
21
wallpaper.h
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class DataEngine;
|
||||||
class WallpaperPrivate;
|
class WallpaperPrivate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,6 +206,25 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
|
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given DataEngine
|
||||||
|
*
|
||||||
|
* Tries to load the data engine given by @p name. Each engine is
|
||||||
|
* only loaded once, and that instance is re-used on all subsequent
|
||||||
|
* requests.
|
||||||
|
*
|
||||||
|
* If the data engine was not found, an invalid data engine is returned
|
||||||
|
* (see DataEngine::isValid()).
|
||||||
|
*
|
||||||
|
* Note that you should <em>not</em> delete the returned engine.
|
||||||
|
*
|
||||||
|
* @param name Name of the data engine to load
|
||||||
|
* @return pointer to the data engine if it was loaded,
|
||||||
|
* or an invalid data engine if the requested engine
|
||||||
|
* could not be loaded
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE DataEngine *dataEngine(const QString &name) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* This signal indicates that wallpaper needs to be repainted.
|
* This signal indicates that wallpaper needs to be repainted.
|
||||||
|
Loading…
Reference in New Issue
Block a user