get rid of local qmlobject and config bindings

they're in kdeclarative now
This commit is contained in:
Marco Martin 2013-04-25 20:56:36 +02:00
parent 7be9da07b4
commit d44f0973d3
9 changed files with 7 additions and 561 deletions

View File

@ -13,10 +13,8 @@ include_directories(${KDE4_INCLUDE_DIR}/KDE ${PHONON_INCLUDES} ${CMAKE_CURRENT_S
#DECLARATIVE APPLET
set(declarative_appletscript_SRCS
declarative/configpropertymap.cpp
declarative/packageaccessmanager.cpp
declarative/packageaccessmanagerfactory.cpp
declarative/qmlobject.cpp
plasmoid/appletinterface.cpp
plasmoid/containmentinterface.cpp
plasmoid/declarativeappletscript.cpp

View File

@ -1,84 +0,0 @@
/*
* Copyright 2013 Marco Martin <notmart@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.
*/
#include "configpropertymap.h"
#include <QDebug>
#include <KConfigSkeletonItem>
ConfigPropertyMap::ConfigPropertyMap(KConfigSkeleton *config, QObject *parent)
: QQmlPropertyMap(parent),
m_config(config)
{
connect(config, &KConfigSkeleton::configChanged,
this, &ConfigPropertyMap::loadConfig);
connect(this, &ConfigPropertyMap::valueChanged,
this, &ConfigPropertyMap::writeConfigValue);
loadConfig();
}
ConfigPropertyMap::~ConfigPropertyMap()
{
writeConfig();
}
void ConfigPropertyMap::loadConfig()
{
if (!m_config) {
return;
}
foreach (KConfigSkeletonItem *item, m_config.data()->items()) {
insert(item->key(), item->property());
}
}
void ConfigPropertyMap::writeConfig()
{
if (!m_config) {
return;
}
foreach (KConfigSkeletonItem *item, m_config.data()->items()) {
item->setProperty(value(item->key()));
}
m_config.data()->blockSignals(true);
m_config.data()->writeConfig();
m_config.data()->blockSignals(false);
}
void ConfigPropertyMap::writeConfigValue(const QString &key, const QVariant &value)
{
KConfigSkeletonItem *item = m_config.data()->findItem(key);
if (item) {
item->setProperty(value);
m_config.data()->blockSignals(true);
m_config.data()->writeConfig();
m_config.data()->blockSignals(false);
}
}
#include "moc_configpropertymap.cpp"

View File

@ -1,45 +0,0 @@
/*
* Copyright 2013 Marco Martin <notmart@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 CONFIGPROPERTYMAP_P
#define CONFIGPROPERTYMAP_P
#include <QQmlPropertyMap>
#include <KConfigSkeleton>
class ConfigPropertyMap : public QQmlPropertyMap
{
Q_OBJECT
public:
ConfigPropertyMap(KConfigSkeleton *config, QObject *parent = 0);
~ConfigPropertyMap();
private Q_SLOTS:
void loadConfig();
void writeConfig();
void writeConfigValue(const QString &key, const QVariant &value);
private:
QWeakPointer<KConfigSkeleton>m_config;
};
#endif

View File

@ -1,233 +0,0 @@
/*
* Copyright 2010 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 "qmlobject.h"
#include <QQmlComponent>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQmlIncubator>
#include <QTimer>
#include <kdebug.h>
#include <kdeclarative.h>
#include "packageaccessmanagerfactory.h"
//#include "private/declarative/dataenginebindings_p.h"
class QmlObjectPrivate
{
public:
QmlObjectPrivate(QmlObject *parent)
: q(parent),
engine(0),
component(0),
delay(false)
{
}
~QmlObjectPrivate()
{
delete root.data();
}
void errorPrint(QQmlComponent *component);
void execute(const QUrl &source);
void scheduleExecutionEnd();
void minimumWidthChanged();
void minimumHeightChanged();
void maximumWidthChanged();
void maximumHeightChanged();
void preferredWidthChanged();
void preferredHeightChanged();
QmlObject *q;
QUrl source;
QQmlEngine* engine;
QQmlIncubator incubator;
QQmlComponent* component;
QWeakPointer<QObject> root;
bool delay : 1;
};
void QmlObjectPrivate::errorPrint(QQmlComponent *component)
{
QString errorStr = "Error loading QML file.\n";
if(component->isError()){
QList<QQmlError> errors = component->errors();
foreach (const QQmlError &error, errors) {
errorStr += (error.line()>0?QString(QString::number(error.line()) + QLatin1String(": ")):QLatin1String(""))
+ error.description() + '\n';
}
}
kWarning() << component->url().toString() + '\n' + errorStr;
}
void QmlObjectPrivate::execute(const QUrl &source)
{
if (source.isEmpty()) {
#ifndef NDEBUG
kDebug() << "File name empty!";
#endif
return;
}
delete component;
component = new QQmlComponent(engine, q);
delete root.data();
KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine);
kdeclarative.initialize();
//binds things like kconfig and icons
kdeclarative.setupBindings();
component->loadUrl(source);
if (delay) {
QTimer::singleShot(0, q, SLOT(scheduleExecutionEnd()));
} else {
scheduleExecutionEnd();
}
}
void QmlObjectPrivate::scheduleExecutionEnd()
{
if (component->isReady() || component->isError()) {
q->completeInitialization();
} else {
QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), q, SLOT(completeInitialization()));
}
}
QmlObject::QmlObject(QObject *parent)
: QObject(parent),
d(new QmlObjectPrivate(this))
{
d->engine = new QQmlEngine(this);
d->engine->setIncubationController(new QmlObjectIncubationController(0));
//d->engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory());
}
QmlObject::~QmlObject()
{
// QDeclarativeNetworkAccessManagerFactory *factory = d->engine->networkAccessManagerFactory();
// d->engine->setNetworkAccessManagerFactory(0);
// delete factory;
delete d;
}
void QmlObject::setSource(const QUrl &source)
{
qDebug() << "Opening" << source;
d->source = source;
d->execute(source);
}
QUrl QmlObject::source() const
{
return d->source;
}
void QmlObject::setInitializationDelayed(const bool delay)
{
d->delay = delay;
}
bool QmlObject::isInitializationDelayed() const
{
return d->delay;
}
QQmlEngine* QmlObject::engine()
{
return d->engine;
}
QObject *QmlObject::rootObject() const
{
return d->root.data();
}
QQmlComponent *QmlObject::mainComponent() const
{
return d->component;
}
void QmlObject::completeInitialization()
{
if (d->root) {
return;
}
if (d->component->status() != QQmlComponent::Ready || d->component->isError()) {
d->errorPrint(d->component);
return;
}
d->component->create(d->incubator);
while (!d->incubator.isReady() && d->incubator.status() != QQmlIncubator::Error) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
}
d->root = d->incubator.object();
//d->root = d->component->create();
if (!d->root) {
d->errorPrint(d->component);
}
#ifndef NDEBUG
kDebug() << "Execution of QML done!";
#endif
emit finished();
}
QObject *QmlObject::createObjectFromSource(const QUrl &source)
{
QQmlComponent *component = new QQmlComponent(d->engine, this);
component->loadUrl(source);
component->create(d->incubator, d->engine->rootContext());
while (!d->incubator.isReady() && d->incubator.status() != QQmlIncubator::Error) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
}
QObject *object = d->incubator.object();
if (!component->isError() && d->root && object) {
//memory management
component->setParent(object);
object->setProperty("parent", QVariant::fromValue(d->root.data()));
return object;
} else {
d->errorPrint(component);
delete component;
delete object;
return 0;
}
}
#include "moc_qmlobject.cpp"

View File

@ -1,190 +0,0 @@
/*
* Copyright 2010 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 QMLOBJECT_H
#define QMLOBJECT_H
#include <QObject>
#include <QQmlIncubationController>
#include <QWindow>
#include <QAnimationDriver>
#include <QGuiApplication>
#include <QScreen>
class QQmlEngine;
class QQmlComponent;
class QmlObjectPrivate;
class QmlObjectIncubationController : public QObject, public QQmlIncubationController
{
Q_OBJECT
public:
QmlObjectIncubationController(QObject *parent)
: QObject(parent),
QQmlIncubationController()
{
// Allow incubation for 1/3 of a frame.
m_incubation_time = qMax(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3);
}
protected:
virtual bool event(QEvent *e)
{
if (e->type() == QEvent::User) {
incubate();
return true;
}
return QObject::event(e);
}
public slots:
void incubate()
{
if (incubatingObjectCount()) {
incubateFor(m_incubation_time * 2);
if (incubatingObjectCount()) {
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
}
}
void animationStopped() { incubate(); }
protected:
virtual void incubatingObjectCountChanged(int count)
{
if (count) {
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
}
private:
int m_incubation_time;
};
/**
* @class QmlObject plasma/declarativewidget.h <Plasma/QmlObject>
*
* @author Marco Martin <mart@kde.org>
*
* @short An object that instantiates an entire QML context, with its own declarative engine
*
* Plasma::QmlObject provides a class for conveniently use QML based
* declarative user interfaces inside Plasma widgets.
* To one QmlObject corresponds one QML file (that can eventually include others)
* tere will be its own QQmlEngine with a single root object,
* described in the QML file.
*/
class QmlObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource)
Q_PROPERTY(bool initializationDelayed READ isInitializationDelayed WRITE setInitializationDelayed)
Q_PROPERTY(QObject * rootObject READ rootObject)
public:
/**
* Constructs a new QmlObject
*
* @param parent the parent of this object
*/
explicit QmlObject(QObject *parent = 0);
~QmlObject();
/**
* Sets the path of the QML file to parse and execute
*
* @param path the absolute path of a QML file
*/
void setSource(const QUrl &source);
/**
* @return the absolute path of the current QML file
*/
QUrl source() const;
/**
* Sets whether the execution of the QML file has to be delayed later in the event loop. It has to be called before setQmlPath().
* In this case will be possible to assign new objects in the main engine context
* before the main component gets initialized.
* So it will be possible to access it immediately from the QML code.
* The initialization will either be completed automatically asyncronously
* or explicitly by calling completeInitialization()
*
* @param delay if true the initialization of the QML file will be delayed
* at the end of the event loop
*/
void setInitializationDelayed(const bool delay);
/**
* @return true if the initialization of the QML file will be delayed
* at the end of the event loop
*/
bool isInitializationDelayed() const;
/**
* @return the declarative engine that runs the qml file assigned to this widget.
*/
QQmlEngine* engine();
/**
* @return the root object of the declarative object tree
*/
QObject *rootObject() const;
/**
* @return the main QQmlComponent of the engine
*/
QQmlComponent *mainComponent() const;
/**
* Creates and returns an object based on the provided url to a Qml file
* with the same QQmlEngine and the same root context as the amin object,
* that will be the parent of the newly created object
* @param source url where the QML file is located
*/
QObject *createObjectFromSource(const QUrl &source);
public Q_SLOTS:
/**
* Finishes the process of initialization.
* If isInitializationDelayed() is false, calling this will have no effect.
*/
void completeInitialization();
Q_SIGNALS:
/**
* Emitted when the parsing and execution of the QML file is terminated
*/
void finished();
private:
friend class QmlObjectPrivate;
QmlObjectPrivate * const d;
Q_PRIVATE_SLOT(d, void scheduleExecutionEnd())
};
#endif // multiple inclusion guard

View File

@ -46,8 +46,8 @@
#include <Plasma/PluginLoader>
#include "containmentinterface.h"
#include "declarative/configpropertymap.h"
#include "declarative/qmlobject.h"
#include <kdeclarative/configpropertymap.h>
#include <kdeclarative/qmlobject.h>
#include "declarative/packageaccessmanagerfactory.h"
Q_DECLARE_METATYPE(AppletInterface*)

View File

@ -21,7 +21,7 @@
#include "containmentinterface.h"
#include "wallpaperinterface.h"
#include "declarative/qmlobject.h"
#include <kdeclarative/qmlobject.h>
#include <QQmlExpression>
#include <QQmlProperty>

View File

@ -46,9 +46,9 @@
#include "plasmoid/appletinterface.h"
#include "plasmoid/containmentinterface.h"
#include "declarative/qmlobject.h"
#include <kdeclarative/qmlobject.h>
#include "declarative/packageaccessmanagerfactory.h"
#include "declarative/configpropertymap.h"
#include <kdeclarative/configpropertymap.h>
K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScript)

View File

@ -20,8 +20,8 @@
#include "wallpaperinterface.h"
#include "containmentinterface.h"
#include "declarative/configpropertymap.h"
#include "declarative/qmlobject.h"
#include <kdeclarative/configpropertymap.h>
#include <kdeclarative/qmlobject.h>
#include <QDebug>
#include <QQmlExpression>