Wallpaper API changes:

- modes -> renderingModes
- remove modeName & modeIcon
- add config group to init for reading config
- add save for config saving

Update containment for api changes.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=849801
This commit is contained in:
Petri Damstén 2008-08-20 08:06:34 +00:00
parent 3f368be2c1
commit 0a2eb79e61
5 changed files with 82 additions and 58 deletions

View File

@ -249,12 +249,19 @@ void Containment::restore(KConfigGroup &group)
setContext(group.readEntry("context", QString())); setContext(group.readEntry("context", QString()));
flushPendingConstraintsEvents(); flushPendingConstraintsEvents();
//kDebug() << "Containment" << id() << "geometry is" << geometry() << "config'd with" << appletConfig.name();
restoreContents(group); restoreContents(group);
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable)); setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
setWallpaper(group.readEntry("wallpaperplugin", QString()), setWallpaper(group.readEntry("wallpaperplugin", "image"),
group.readEntry("wallpaperpluginmode", QString())); group.readEntry("wallpaperpluginmode", "SingleImage"));
/*
kDebug() << "Containment" << id() <<
"screen" << screen() <<
"geometry is" << geometry() <<
"wallpaper" << ((d->wallpaper) ? d->wallpaper->pluginName() : QString()) <<
"wallpaper mode" << wallpaperMode() <<
"config entries" << group.entryMap();
*/
} }
void Containment::save(KConfigGroup &g) const void Containment::save(KConfigGroup &g) const
@ -1027,6 +1034,14 @@ void Containment::removeAssociatedWidget(QWidget *widget)
void Containment::setDrawWallpaper(bool drawWallpaper) void Containment::setDrawWallpaper(bool drawWallpaper)
{ {
d->drawWallpaper = drawWallpaper; d->drawWallpaper = drawWallpaper;
if (d->drawWallpaper) {
KConfigGroup cfg = config();
setWallpaper(cfg.readEntry("wallpaperplugin", "image"),
cfg.readEntry("wallpaperpluginmode", "SingleImage"));
} else if (!d->drawWallpaper && d->wallpaper) {
delete d->wallpaper;
d->wallpaper = 0;
}
} }
bool Containment::drawWallpaper() bool Containment::drawWallpaper()
@ -1036,20 +1051,26 @@ bool Containment::drawWallpaper()
void Containment::setWallpaper(const QString &pluginName, const QString &mode) void Containment::setWallpaper(const QString &pluginName, const QString &mode)
{ {
delete d->wallpaper; KConfigGroup cfg = config();
if (!pluginName.isEmpty()) {
d->wallpaper = Plasma::Wallpaper::load(pluginName); if (d->drawWallpaper) {
setDrawWallpaper(d->wallpaper != 0); if (d->wallpaper && d->wallpaper->pluginName() != pluginName) {
delete d->wallpaper;
d->wallpaper = 0;
}
if (!pluginName.isEmpty() && !d->wallpaper) {
d->wallpaper = Plasma::Wallpaper::load(pluginName);
}
if (d->wallpaper) { if (d->wallpaper) {
d->wallpaper->setBoundingRect(geometry()); d->wallpaper->setBoundingRect(geometry());
d->wallpaper->init(mode); d->wallpaper->init(KConfigGroup(&cfg, "Wallpaper"), mode);
connect(d->wallpaper, SIGNAL(update(const QRectF&)), connect(d->wallpaper, SIGNAL(update(const QRectF&)),
this, SLOT(updateRect(const QRectF&))); this, SLOT(updateRect(const QRectF&)));
} }
} else { update();
d->wallpaper = 0;
setDrawWallpaper(false);
} }
cfg.writeEntry("wallpaperplugin", pluginName);
cfg.writeEntry("wallpaperpluginmode", mode);
} }
Plasma::Wallpaper* Containment::wallpaper() const Plasma::Wallpaper* Containment::wallpaper() const
@ -1057,6 +1078,12 @@ Plasma::Wallpaper* Containment::wallpaper() const
return d->wallpaper; return d->wallpaper;
} }
QString Containment::wallpaperMode() const
{
KConfigGroup cfg = config();
return cfg.readEntry("wallpaperpluginmode", QString());
}
void Containment::setContext(const QString &context) void Containment::setContext(const QString &context)
{ {
if (d->context != context) { if (d->context != context) {
@ -1149,6 +1176,8 @@ void Containment::destroy()
return; return;
} }
//TODO For desktop containment change we need to remove containment so do we need these?
#if 0
if (isContainment()) { if (isContainment()) {
//don't remove a desktop that's in use //don't remove a desktop that's in use
//FIXME allow removal of containments for screens that don't currently exist //FIXME allow removal of containments for screens that don't currently exist
@ -1165,8 +1194,9 @@ void Containment::destroy()
Applet::destroy(); Applet::destroy();
} }
} else { } else {
#endif
Applet::destroy(); Applet::destroy();
} //}
} }
@ -1415,14 +1445,14 @@ void ContainmentPrivate::appletDestroyed(QObject* object)
if (focusedApplet == applet) { if (focusedApplet == applet) {
focusedApplet = 0; focusedApplet = 0;
} }
foreach (AppletHandle* handle, handles) { foreach (AppletHandle* handle, handles) {
if (handles.contains(applet)) { if (handles.contains(applet)) {
handles.remove(handle->applet()); handles.remove(handle->applet());
handle->deleteLater(); handle->deleteLater();
} }
} }
emit q->appletRemoved(applet); emit q->appletRemoved(applet);
emit q->configNeedsSaving(); emit q->configNeedsSaving();
} }

View File

@ -275,11 +275,6 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void removeAssociatedWidget(QWidget *widget); void removeAssociatedWidget(QWidget *widget);
/**
* Sets whether wallpaper is painted or not.
*/
void setDrawWallpaper(bool drawWallpaper);
/** /**
* Return whether wallpaper is painted or not. * Return whether wallpaper is painted or not.
*/ */
@ -300,6 +295,11 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
Plasma::Wallpaper* wallpaper() const; Plasma::Wallpaper* wallpaper() const;
/**
* Return wallpaper mode.
*/
QString wallpaperMode() const;
/** /**
* Sets the current context * Sets the current context
* *
@ -365,6 +365,11 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void focusRequested(Plasma::Containment *containment); void focusRequested(Plasma::Containment *containment);
/**
* Emitted when the user wants to configure/change containment.
*/
void configureRequested();
public Q_SLOTS: public Q_SLOTS:
/** /**
* Informs the Corona as to what position it is in. This is informational * Informs the Corona as to what position it is in. This is informational
@ -410,6 +415,11 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void setContainmentType(Containment::Type type); void setContainmentType(Containment::Type type);
/**
* Sets whether wallpaper is painted or not.
*/
void setDrawWallpaper(bool drawWallpaper);
/** /**
* Called when the contents of the containment should be saved. By default this saves * Called when the contents of the containment should be saved. By default this saves
* all loaded Applets * all loaded Applets

View File

@ -43,7 +43,7 @@ public:
toolBox(0), toolBox(0),
type(Containment::NoContainmentType), type(Containment::NoContainmentType),
positioning(false), positioning(false),
drawWallpaper(false) drawWallpaper(true)
{ {
} }

View File

@ -141,32 +141,12 @@ QString Wallpaper::pluginName() const
return d->wallpaperDescription.pluginName(); return d->wallpaperDescription.pluginName();
} }
QStringList Wallpaper::modes() const QList<KServiceAction> Wallpaper::renderingModes() const
{ {
if (!d->wallpaperDescription.isValid()) { if (!d->wallpaperDescription.isValid()) {
return QStringList(); return QList<KServiceAction>();
} }
return d->wallpaperDescription.property("Actions").toStringList(); return d->wallpaperDescription.service()->actions();
}
QString Wallpaper::modeName(const QString& mode) const
{
if (!d->wallpaperDescription.isValid()) {
return QString();
}
KConfigGroup wallpaperCfg = d->wallpaperDescription.config();
KConfigGroup cfg(&wallpaperCfg, QString("Desktop Action %1").arg(mode));
return cfg.readEntry("Name");
}
QString Wallpaper::modeIcon(const QString& mode) const
{
if (!d->wallpaperDescription.isValid()) {
return QString();
}
KConfigGroup wallpaperCfg = d->wallpaperDescription.config();
KConfigGroup cfg(&wallpaperCfg, QString("Desktop Action %1").arg(mode));
return cfg.readEntry("Icon");
} }
QRectF Wallpaper::boundingRect() const QRectF Wallpaper::boundingRect() const
@ -179,11 +159,17 @@ void Wallpaper::setBoundingRect(const QRectF& boundingRect)
d->boundingRect = boundingRect; d->boundingRect = boundingRect;
} }
void Wallpaper::init(const QString &mode) void Wallpaper::init(const KConfigGroup &config, const QString &mode)
{ {
Q_UNUSED(config);
Q_UNUSED(mode); Q_UNUSED(mode);
} }
void Wallpaper::save(KConfigGroup config)
{
Q_UNUSED(config);
}
QWidget *Wallpaper::createConfigurationInterface(QWidget *parent) QWidget *Wallpaper::createConfigurationInterface(QWidget *parent)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);

View File

@ -52,7 +52,8 @@ class PLASMA_EXPORT Wallpaper : public QObject
Q_PROPERTY(QRectF boundingRect READ boundingRect WRITE setBoundingRect) Q_PROPERTY(QRectF boundingRect READ boundingRect WRITE setBoundingRect)
Q_PROPERTY(QString name READ name) Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString pluginName READ pluginName) Q_PROPERTY(QString pluginName READ pluginName)
Q_PROPERTY(QStringList modes READ modes) Q_PROPERTY(QString icon READ icon)
Q_PROPERTY(QList<KServiceAction> renderingModes READ renderingModes)
Q_PROPERTY(QRectF boundingRect READ boundingRect WRITE setBoundingRect) Q_PROPERTY(QRectF boundingRect READ boundingRect WRITE setBoundingRect)
public: public:
@ -113,17 +114,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
* Returns modes the wallpaper has, as specified in the * Returns modes the wallpaper has, as specified in the
* .desktop file. * .desktop file.
*/ */
QStringList modes() const; QList<KServiceAction> renderingModes() const;
/**
* Returns the translted name for the mode.
*/
QString modeName(const QString& mode) const;
/**
* Returns icon for the mode.
*/
QString modeIcon(const QString& mode) const;
/** /**
* Returns bounding rectangle * Returns bounding rectangle
@ -144,11 +135,18 @@ class PLASMA_EXPORT Wallpaper : public QObject
virtual void paint(QPainter *painter, const QRectF& exposedRect) = 0; virtual void paint(QPainter *painter, const QRectF& exposedRect) = 0;
/** /**
* This method is called once the wallpaper is loaded. * This method is called once the wallpaper is loaded or mode is changed.
* @param config Config group to load settings
* @param mode One of the modes supported by the plugin, * @param mode One of the modes supported by the plugin,
* or an empty string for the default mode. * or an empty string for the default mode.
**/ **/
virtual void init(const QString &mode = QString()); virtual void init(const KConfigGroup &config, const QString &mode = QString());
/**
* This method is called when settings need to be saved.
* @param config Config group to save settings
**/
virtual void save(KConfigGroup config);
/** /**
* Returns widget for configuration dialog. * Returns widget for configuration dialog.