WallpaperInterface for wallpapers

will be used to provide configuration access and a configuration UI
This commit is contained in:
Marco Martin 2013-03-01 15:11:08 +01:00
parent fda16dee08
commit 6f5a593d91
11 changed files with 204 additions and 38 deletions

View File

@ -37,7 +37,6 @@
class QWidget;
class KConfigDialog;
class KActionCollection;
namespace Plasma

View File

@ -41,7 +41,7 @@
namespace Plasma
{
const char ContainmentPrivate::defaultWallpaper[] = "image";
const char ContainmentPrivate::defaultWallpaper[] = "org.kde.image";
void ContainmentPrivate::addDefaultActions(KActionCollection *actions, Containment *c)
{

View File

@ -20,7 +20,6 @@
#include "scripting/appletscript.h"
#include "kconfig.h"
#include "kconfigdialog.h"
#include "applet.h"
#include "package.h"

View File

@ -33,7 +33,6 @@
class QAction;
class QPainter;
class QStyleOptionGraphicsItem;
class KConfigDialog;
namespace Plasma
{

View File

@ -21,6 +21,7 @@ set(declarative_appletscript_SRCS
plasmoid/configview.cpp
plasmoid/containmentinterface.cpp
plasmoid/declarativeappletscript.cpp
plasmoid/wallpaperinterface.cpp
)
include_directories(${PHONON_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/common)

View File

@ -20,6 +20,8 @@
*/
#include "containmentinterface.h"
#include "wallpaperinterface.h"
#include "declarative/qmlobject.h"
#include <QQmlExpression>
#include <QQmlProperty>
@ -34,11 +36,10 @@
#include <Plasma/Package>
#include <Plasma/PluginLoader>
#include "declarative/qmlobject.h"
ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
: AppletInterface(parent),
m_wallpaperQmlObject(0)
m_wallpaperInterface(0)
{
//TODO: will accept all events specified as registered with containment actions
setAcceptedMouseButtons(Qt::RightButton);
@ -162,41 +163,23 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
void ContainmentInterface::loadWallpaper()
{
if (m_appletScriptEngine->drawWallpaper()) {
if (m_wallpaperQmlObject) {
if (m_wallpaperInterface) {
return;
}
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
pkg.setDefaultPackageRoot("plasma/wallpapers");
pkg.setPath("org.kde.wallpaper.image");
m_wallpaperInterface = new WallpaperInterface(this);
//Qml seems happier if the parent gets set in this way
m_wallpaperInterface->setProperty("parent", QVariant::fromValue(this));
m_wallpaperQmlObject = new QmlObject(this);
m_wallpaperQmlObject->setSource(QUrl::fromLocalFile(pkg.filePath("mainscript")));
if (m_wallpaperQmlObject->mainComponent() &&
m_wallpaperQmlObject->rootObject() &&
!m_wallpaperQmlObject->mainComponent()->isError()) {
m_wallpaperQmlObject->rootObject()->setProperty("z", -1000);
m_wallpaperQmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this));
//set anchors
QQmlExpression expr(qmlObject()->engine()->rootContext(), m_wallpaperQmlObject->rootObject(), "parent");
QQmlProperty prop(m_wallpaperQmlObject->rootObject(), "anchors.fill");
prop.write(expr.evaluate());
} else if (m_wallpaperQmlObject->mainComponent()) {
qWarning() << "Error loading the wallpaper" << m_wallpaperQmlObject->mainComponent()->errors();
m_wallpaperQmlObject->deleteLater();
m_wallpaperQmlObject = 0;
} else {
qWarning() << "Error loading the wallpaper, package not found";
}
//set anchors
QQmlExpression expr(qmlObject()->engine()->rootContext(), m_wallpaperInterface, "parent");
QQmlProperty prop(m_wallpaperInterface, "anchors.fill");
prop.write(expr.evaluate());
} else {
if (m_wallpaperQmlObject) {
m_wallpaperQmlObject->deleteLater();
m_wallpaperQmlObject = 0;
if (m_wallpaperInterface) {
m_wallpaperInterface->deleteLater();
m_wallpaperInterface = 0;
}
}
}

View File

@ -28,6 +28,7 @@
#include "appletinterface.h"
class QmlObject;
class WallpaperInterface;
class ContainmentInterface : public AppletInterface
{
@ -86,7 +87,7 @@ protected Q_SLOTS:
void loadWallpaper();
private:
QmlObject *m_wallpaperQmlObject;
WallpaperInterface *m_wallpaperInterface;
QList<QObject *> m_appletInterfaces;
};

View File

@ -0,0 +1,118 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* 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 "wallpaperinterface.h"
#include "containmentinterface.h"
#include "declarative/configpropertymap.h"
#include "declarative/qmlobject.h"
#include <QDebug>
#include <QQmlExpression>
#include <QQmlContext>
#include <QQmlProperty>
#include <Plasma/ConfigLoader>
#include <Plasma/PluginLoader>
WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
: QQuickItem(parent),
m_containmentInterface(parent),
m_qmlObject(0)
{
if (configScheme()) {
m_configuration = new ConfigPropertyMap(configScheme(), this);
}
connect(m_containmentInterface->containment(), &Plasma::Containment::wallpaperChanged,
this, &WallpaperInterface::syncWallpaperPackage);
syncWallpaperPackage();
}
WallpaperInterface::~WallpaperInterface()
{}
Plasma::Package WallpaperInterface::package() const
{
return m_pkg;
}
QObject* WallpaperInterface::configuration() const
{
return m_configuration;
}
Plasma::ConfigLoader *WallpaperInterface::configScheme()
{
if (!m_configLoader) {
const QString xmlPath = m_pkg.filePath("mainconfigxml");
KConfigGroup cfg = m_containmentInterface->containment()->config();
cfg = KConfigGroup(&cfg, "Wallpaper");
if (xmlPath.isEmpty()) {
m_configLoader = new Plasma::ConfigLoader(&cfg, 0);
} else {
QFile file(xmlPath);
m_configLoader = new Plasma::ConfigLoader(&cfg, &file);
}
}
return m_configLoader;
}
void WallpaperInterface::syncWallpaperPackage()
{
if (!m_qmlObject) {
m_qmlObject = new QmlObject(this);
m_qmlObject->setInitializationDelayed(true);
}
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
m_pkg.setDefaultPackageRoot("plasma/wallpapers");
m_pkg.setPath(m_containmentInterface->containment()->wallpaper());
m_qmlObject->setSource(QUrl::fromLocalFile(m_pkg.filePath("mainscript")));
m_qmlObject->engine()->rootContext()->setContextProperty("wallpaper", this);
m_qmlObject->completeInitialization();
if (m_qmlObject->mainComponent() &&
m_qmlObject->rootObject() &&
!m_qmlObject->mainComponent()->isError()) {
m_qmlObject->rootObject()->setProperty("z", -1000);
m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this));
//set anchors
QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent");
QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill");
prop.write(expr.evaluate());
} else if (m_qmlObject->mainComponent()) {
qWarning() << "Error loading the wallpaper" << m_qmlObject->mainComponent()->errors();
m_qmlObject->deleteLater();
m_qmlObject = 0;
} else {
qWarning() << "Error loading the wallpaper, package not found";
}
emit packageChanged();
}
#include "moc_wallpaperinterface.cpp"

View File

@ -0,0 +1,66 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* 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 WALLPAPERINTERFACE_H
#define WALLPAPERINTERFACE_H
#include <QQuickItem>
#include <Plasma/Package>
namespace Plasma {
class ConfigLoader;
}
class ContainmentInterface;
class ConfigPropertyMap;
class QmlObject;
class WallpaperInterface : public QQuickItem
{
Q_OBJECT
//Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
Q_PROPERTY(QObject* configuration READ configuration CONSTANT)
public:
WallpaperInterface(ContainmentInterface *parent = 0);
~WallpaperInterface();
Plasma::Package package() const;
QObject* configuration() const;
Plasma::ConfigLoader *configScheme();
Q_SIGNALS:
void packageChanged();
private Q_SLOTS:
void syncWallpaperPackage();
private:
ContainmentInterface *m_containmentInterface;
QmlObject *m_qmlObject;
Plasma::Package m_pkg;
ConfigPropertyMap *m_configuration;
Plasma::ConfigLoader *m_configLoader;
};
#endif

View File

@ -1,4 +1,4 @@
install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/plasma/wallpapers/org.kde.wallpaper.image PATTERN .svn EXCLUDE PATTERN CMakeLists.txt EXCLUDE PATTERN Messages.sh EXCLUDE)
install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/plasma/wallpapers/org.kde.image PATTERN .svn EXCLUDE PATTERN CMakeLists.txt EXCLUDE PATTERN Messages.sh EXCLUDE)

View File

@ -17,7 +17,7 @@ X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPLv2+
X-KDE-PluginInfo-Name=org.kde.wallpaper.image
X-KDE-PluginInfo-Name=org.kde.image
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-Plasma-MainScript=ui/main.qml