fix the wallpaper configuration

still pretty hacky, makes a lot of assumptions about the scriptengine
object hyerarchy and for some reason digging  a ConfigPropertyMap out of
a qvariant doesn't work properly
This commit is contained in:
Marco Martin 2013-05-07 11:55:21 +02:00
parent 3d290decd2
commit f9436999d9
3 changed files with 28 additions and 16 deletions

View File

@ -36,6 +36,7 @@
#include <Plasma/Package>
#include <Plasma/PluginLoader>
#include "kdeclarative/configpropertymap.h"
ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
: AppletInterface(parent),
@ -167,9 +168,7 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
void ContainmentInterface::loadWallpaper()
{
if (m_appletScriptEngine->drawWallpaper()) {
if (m_wallpaperInterface || containment()->wallpaper().isEmpty()) {
return;
}
delete m_wallpaperInterface;
m_wallpaperInterface = new WallpaperInterface(this);
m_wallpaperInterface->setZ(-1000);
@ -181,6 +180,7 @@ void ContainmentInterface::loadWallpaper()
QQmlProperty prop(m_wallpaperInterface, "anchors.fill");
prop.write(expr.evaluate());
containment()->setProperty("wallpaperGraphicsObject", QVariant::fromValue(m_wallpaperInterface));
} else {
if (m_wallpaperInterface) {
m_wallpaperInterface->deleteLater();

View File

@ -39,7 +39,8 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow
: ConfigView(cont, parent),
m_containment(cont),
m_wallpaperConfigModel(0),
m_currentWallpaperConfig(0)
m_currentWallpaperConfig(0),
m_ownWallpaperConfig(0)
{
engine()->rootContext()->setContextProperty("configDialog", this);
setCurrentWallpaper(cont->containment()->wallpaper());
@ -50,7 +51,8 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow
QFile file(pkg.filePath("config", "main.xml"));
KConfigGroup cfg = m_containment->config();
cfg = KConfigGroup(&cfg, "Wallpaper");
m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
syncWallpaperObjects();
}
ContainmentConfigView::~ContainmentConfigView()
@ -113,13 +115,12 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper)
return;
}
delete m_ownWallpaperConfig;
m_ownWallpaperConfig = 0;
if (m_containment->wallpaper() == wallpaper) {
delete m_currentWallpaperConfig;
m_currentWallpaperConfig = m_ownWallpaperConfig;
syncWallpaperObjects();
} else {
if (m_containment->wallpaper() != m_currentWallpaper) {
delete m_currentWallpaperConfig;
}
//we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
@ -128,7 +129,7 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper)
QFile file(pkg.filePath("config", "main.xml"));
KConfigGroup cfg = m_containment->config();
cfg = KConfigGroup(&cfg, "Wallpaper");
m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
}
m_currentWallpaper = wallpaper;
@ -140,12 +141,20 @@ void ContainmentConfigView::applyWallpaper()
{
m_containment->setWallpaper(m_currentWallpaper);
if (m_currentWallpaperConfig != m_ownWallpaperConfig) {
delete m_currentWallpaperConfig;
m_currentWallpaperConfig = m_ownWallpaperConfig;
emit wallpaperConfigurationChanged();
}
delete m_ownWallpaperConfig;
m_ownWallpaperConfig = 0;
syncWallpaperObjects();
emit wallpaperConfigurationChanged();
}
void ContainmentConfigView::syncWallpaperObjects()
{
QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>();
engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject);
//FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work?
m_currentWallpaperConfig = static_cast<ConfigPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>());
}
#include "moc_containmentconfigview.cpp"

View File

@ -54,6 +54,9 @@ Q_SIGNALS:
void currentWallpaperChanged();
void wallpaperConfigurationChanged();
protected:
void syncWallpaperObjects();
private:
Plasma::Containment *m_containment;
ConfigModel *m_wallpaperConfigModel;