cleanups
move qmlobject initialization in appletloader
This commit is contained in:
parent
012554d8d9
commit
2a37efbdb7
@ -48,12 +48,10 @@
|
||||
#include <kdeclarative/configpropertymap.h>
|
||||
#include <kdeclarative/qmlobject.h>
|
||||
|
||||
#include <packageurlinterceptor.h>
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(AppletInterface*)
|
||||
|
||||
QHash<QObject *, AppletInterface *> AppletInterface::s_rootObjects = QHash<QObject *, AppletInterface *>();
|
||||
|
||||
AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
: AppletLoader(script, parent),
|
||||
m_actionSignals(0),
|
||||
@ -75,11 +73,11 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
||||
connect(applet(), &Plasma::Applet::statusChanged,
|
||||
this, &AppletInterface::statusChanged);
|
||||
|
||||
connect(m_appletScriptEngine, &DeclarativeAppletScript::formFactorChanged,
|
||||
connect(appletScript(), &DeclarativeAppletScript::formFactorChanged,
|
||||
this, &AppletInterface::formFactorChanged);
|
||||
connect(m_appletScriptEngine, &DeclarativeAppletScript::locationChanged,
|
||||
connect(appletScript(), &DeclarativeAppletScript::locationChanged,
|
||||
this, &AppletInterface::locationChanged);
|
||||
connect(m_appletScriptEngine, &DeclarativeAppletScript::contextChanged,
|
||||
connect(appletScript(), &DeclarativeAppletScript::contextChanged,
|
||||
this, &AppletInterface::contextChanged);
|
||||
|
||||
if (applet()->containment()) {
|
||||
@ -87,71 +85,21 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
||||
this, &ContainmentInterface::screenChanged);
|
||||
}
|
||||
|
||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||
m_qmlObject->setInitializationDelayed(true);
|
||||
|
||||
m_collapseTimer = new QTimer(this);
|
||||
m_collapseTimer->setSingleShot(true);
|
||||
//connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck);
|
||||
}
|
||||
|
||||
AppletInterface::~AppletInterface()
|
||||
{
|
||||
s_rootObjects.remove(m_qmlObject->engine());
|
||||
}
|
||||
|
||||
void AppletInterface::init()
|
||||
{
|
||||
AppletLoader::init();
|
||||
|
||||
if (m_qmlObject->rootObject()) {
|
||||
if (qmlObject()->rootObject() && m_configuration) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_configuration = new KDeclarative::ConfigPropertyMap(applet()->configScheme(), this);
|
||||
|
||||
//use our own custom network access manager that will access Plasma packages and to manage security (i.e. deny access to remote stuff when the proper extension isn't enabled
|
||||
QQmlEngine *engine = m_qmlObject->engine();
|
||||
|
||||
s_rootObjects[m_qmlObject->engine()] = this;
|
||||
|
||||
//Hook generic url resolution to the applet package as well
|
||||
//TODO: same thing will have to be done for every qqmlengine: PackageUrlInterceptor is material for plasmaquick?
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_appletScriptEngine->package());
|
||||
interceptor->addAllowedPath(applet()->containment()->corona()->package().path());
|
||||
engine->setUrlInterceptor(interceptor);
|
||||
|
||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript()));
|
||||
|
||||
if (!m_qmlObject->engine() || !m_qmlObject->engine()->rootContext() || !m_qmlObject->engine()->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {
|
||||
QString reason;
|
||||
foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) {
|
||||
reason += error.toString()+'\n';
|
||||
}
|
||||
reason = i18n("Error loading QML file: %1", reason);
|
||||
|
||||
m_qmlObject->setSource(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("appleterror")));
|
||||
m_qmlObject->completeInitialization();
|
||||
|
||||
|
||||
//even the error message QML may fail
|
||||
if (m_qmlObject->mainComponent()->isError()) {
|
||||
return;
|
||||
} else {
|
||||
m_qmlObject->rootObject()->setProperty("reason", reason);
|
||||
}
|
||||
|
||||
m_appletScriptEngine->setLaunchErrorMessage(reason);
|
||||
}
|
||||
|
||||
|
||||
m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", this);
|
||||
|
||||
//initialize size, so an useless resize less
|
||||
QVariantHash initialProperties;
|
||||
initialProperties["width"] = width();
|
||||
initialProperties["height"] = height();
|
||||
m_qmlObject->completeInitialization(initialProperties);
|
||||
AppletLoader::init();
|
||||
|
||||
qDebug() << "Graphic object created:" << applet() << applet()->property("graphicObject");
|
||||
|
||||
@ -218,7 +166,7 @@ void AppletInterface::setTitle(const QString &title)
|
||||
|
||||
bool AppletInterface::isBusy() const
|
||||
{
|
||||
return !m_qmlObject->rootObject() || m_busy;
|
||||
return m_busy;
|
||||
}
|
||||
|
||||
void AppletInterface::setBusy(bool busy)
|
||||
@ -240,7 +188,7 @@ void AppletInterface::setExpanded(bool expanded)
|
||||
{
|
||||
//if there is no compact representation it means it's always expanded
|
||||
//Containnments are always expanded
|
||||
if (/*!m_compactUiObject ||*/ qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
|
||||
if (qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,7 +213,7 @@ void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint)
|
||||
|
||||
void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
|
||||
{
|
||||
m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason);
|
||||
appletScript()->setConfigurationRequired(needsConfiguring, reason);
|
||||
}
|
||||
|
||||
QString AppletInterface::activeConfig() const
|
||||
@ -283,7 +231,7 @@ void AppletInterface::setActiveConfig(const QString &name)
|
||||
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
||||
|
||||
if (!loader) {
|
||||
QString path = m_appletScriptEngine->filePath("config", name + ".xml");
|
||||
QString path = appletScript()->filePath("config", name + ".xml");
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -313,7 +261,7 @@ void AppletInterface::writeConfig(const QString &entry, const QVariant &value)
|
||||
config->blockSignals(true);
|
||||
config->writeConfig();
|
||||
config->blockSignals(false);
|
||||
m_appletScriptEngine->configNeedsSaving();
|
||||
appletScript()->configNeedsSaving();
|
||||
}
|
||||
} else
|
||||
qWarning() << "Couldn't find a configuration entry";
|
||||
@ -339,12 +287,12 @@ QVariant AppletInterface::readConfig(const QString &entry) const
|
||||
|
||||
QString AppletInterface::file(const QString &fileType)
|
||||
{
|
||||
return m_appletScriptEngine->filePath(fileType, QString());
|
||||
return appletScript()->filePath(fileType, QString());
|
||||
}
|
||||
|
||||
QString AppletInterface::file(const QString &fileType, const QString &filePath)
|
||||
{
|
||||
return m_appletScriptEngine->filePath(fileType, filePath);
|
||||
return appletScript()->filePath(fileType, filePath);
|
||||
}
|
||||
|
||||
QList<QAction*> AppletInterface::contextualActions() const
|
||||
@ -398,7 +346,7 @@ void AppletInterface::setAction(const QString &name, const QString &text, const
|
||||
if (!m_actionSignals) {
|
||||
m_actionSignals = new QSignalMapper(this);
|
||||
connect(m_actionSignals, SIGNAL(mapped(QString)),
|
||||
m_appletScriptEngine, SLOT(executeAction(QString)));
|
||||
appletScript(), SLOT(executeAction(QString)));
|
||||
}
|
||||
|
||||
connect(action, SIGNAL(triggered()), m_actionSignals, SLOT(map()));
|
||||
@ -521,36 +469,20 @@ QStringList AppletInterface::downloadedFiles() const
|
||||
return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable);
|
||||
}
|
||||
|
||||
void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
{
|
||||
Q_UNUSED(oldGeometry)
|
||||
|
||||
AppletLoader::geometryChanged(newGeometry, oldGeometry);
|
||||
m_collapseTimer->start(100);
|
||||
}
|
||||
|
||||
void AppletInterface::updatePopupSize()
|
||||
{
|
||||
KConfigGroup cg = applet()->config();
|
||||
cg = KConfigGroup(&cg, "PopupApplet");
|
||||
cg.writeEntry("DialogWidth", m_qmlObject->rootObject()->property("width").toInt());
|
||||
cg.writeEntry("DialogHeight", m_qmlObject->rootObject()->property("height").toInt());
|
||||
cg.writeEntry("DialogWidth", qmlObject()->rootObject()->property("width").toInt());
|
||||
cg.writeEntry("DialogHeight", qmlObject()->rootObject()->property("height").toInt());
|
||||
}
|
||||
|
||||
void AppletInterface::itemChange(ItemChange change, const ItemChangeData &value)
|
||||
{
|
||||
if (change == QQuickItem::ItemSceneChange) {
|
||||
//we have a window: create the
|
||||
if (value.window && !m_qmlObject->rootObject()) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
AppletLoader::itemChange(change, value);
|
||||
}
|
||||
|
||||
KDeclarative::QmlObject *AppletInterface::qmlObject()
|
||||
void AppletInterface::executeAction(const QString &name)
|
||||
{
|
||||
return m_qmlObject;
|
||||
if (qmlObject()->rootObject()) {
|
||||
QMetaObject::invokeMethod(qmlObject()->rootObject(), QString("action_" + name).toLatin1(), Qt::DirectConnection);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_appletinterface.cpp"
|
||||
|
@ -159,11 +159,12 @@ public:
|
||||
~AppletInterface();
|
||||
|
||||
//API not intended for the QML part
|
||||
KDeclarative::QmlObject *qmlObject();
|
||||
|
||||
QList<QAction*> contextualActions() const;
|
||||
|
||||
inline Plasma::Applet *applet() const { return m_appletScriptEngine->applet(); }
|
||||
void executeAction(const QString &name);
|
||||
|
||||
Plasma::Applet *applet() const { return appletScript()->applet(); }
|
||||
|
||||
//QML API-------------------------------------------------------------------
|
||||
|
||||
@ -225,11 +226,7 @@ public:
|
||||
|
||||
static AppletInterface *qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
||||
return s_rootObjects.value(QtQml::qmlEngine(object));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return qobject_cast<AppletInterface *>(AppletLoader::qmlAttachedProperties(object));
|
||||
}
|
||||
|
||||
//PROPERTY ACCESSORS-------------------------------------------------------------------
|
||||
@ -303,12 +300,6 @@ Q_SIGNALS:
|
||||
|
||||
void userConfiguringChanged();
|
||||
|
||||
protected:
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||
void itemChange(ItemChange change, const ItemChangeData &value);
|
||||
|
||||
|
||||
|
||||
protected Q_SLOTS:
|
||||
virtual void init();
|
||||
|
||||
@ -326,17 +317,13 @@ private:
|
||||
KDeclarative::ConfigPropertyMap *m_configuration;
|
||||
|
||||
//UI-specific members ------------------
|
||||
QWeakPointer<QObject> m_compactUiObject;
|
||||
|
||||
QTimer *m_collapseTimer;
|
||||
|
||||
Plasma::Types::BackgroundHints m_backgroundHints;
|
||||
bool m_busy : 1;
|
||||
bool m_expanded : 1;
|
||||
bool m_hideOnDeactivate : 1;
|
||||
friend class ContainmentInterface;
|
||||
|
||||
static QHash<QObject *, AppletInterface *> s_rootObjects;
|
||||
};
|
||||
|
||||
QML_DECLARE_TYPEINFO(AppletInterface, QML_HAS_ATTACHED_PROPERTIES)
|
||||
|
@ -27,6 +27,8 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <klocalizedstring.h>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Corona>
|
||||
@ -34,7 +36,9 @@
|
||||
#include <kdeclarative/qmlobject.h>
|
||||
#include <plasma/scripting/appletscript.h>
|
||||
|
||||
#include <packageurlinterceptor.h>
|
||||
|
||||
QHash<QObject *, AppletLoader *> AppletLoader::s_rootObjects = QHash<QObject *, AppletLoader *>();
|
||||
|
||||
AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
: QQuickItem(parent),
|
||||
@ -48,7 +52,7 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
this, SLOT(compactRepresentationCheck()));
|
||||
m_compactRepresentationCheckTimer.start();
|
||||
|
||||
m_fullRepresentationResizeTimer.setSingleShot(true);
|
||||
/* m_fullRepresentationResizeTimer.setSingleShot(true);
|
||||
m_fullRepresentationResizeTimer.setInterval(250);
|
||||
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
|
||||
[=]() {
|
||||
@ -57,37 +61,88 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
|
||||
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
|
||||
}
|
||||
);
|
||||
|
||||
//hide all the children that aren't the known ones.
|
||||
//all the UI is supposed to happen in the representations
|
||||
/* connect (this, &QQuickItem::childrenChanged, [=]() {
|
||||
foreach (QQuickItem *child, childItems()) {
|
||||
if (child != m_compactRepresentationItem.data() &&
|
||||
child != m_fullRepresentationItem.data() &&
|
||||
child != m_compactRepresentationExpanderItem.data()) {
|
||||
child->setVisible(false);
|
||||
}
|
||||
}
|
||||
});*/
|
||||
);*/
|
||||
|
||||
|
||||
|
||||
m_applet = m_appletScriptEngine->applet();
|
||||
|
||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||
m_qmlObject->setInitializationDelayed(true);
|
||||
}
|
||||
|
||||
AppletLoader::~AppletLoader()
|
||||
{
|
||||
s_rootObjects.remove(m_qmlObject->engine());
|
||||
}
|
||||
|
||||
Plasma::Applet *AppletLoader::applet() const
|
||||
void AppletLoader::init()
|
||||
{
|
||||
return m_applet;
|
||||
s_rootObjects[m_qmlObject->engine()] = this;
|
||||
|
||||
Q_ASSERT(m_appletScriptEngine);
|
||||
|
||||
|
||||
//Initialize the main QML file
|
||||
QQmlEngine *engine = m_qmlObject->engine();
|
||||
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, appletScript()->package());
|
||||
interceptor->addAllowedPath(m_appletScriptEngine->applet()->containment()->corona()->package().path());
|
||||
engine->setUrlInterceptor(interceptor);
|
||||
|
||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript()));
|
||||
|
||||
if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {
|
||||
QString reason;
|
||||
foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) {
|
||||
reason += error.toString()+'\n';
|
||||
}
|
||||
reason = i18n("Error loading QML file: %1", reason);
|
||||
|
||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror")));
|
||||
m_qmlObject->completeInitialization();
|
||||
|
||||
|
||||
//even the error message QML may fail
|
||||
if (m_qmlObject->mainComponent()->isError()) {
|
||||
return;
|
||||
} else {
|
||||
m_qmlObject->rootObject()->setProperty("reason", reason);
|
||||
}
|
||||
|
||||
Plasma::AppletScript *AppletLoader::appletScript()
|
||||
appletScript()->setLaunchErrorMessage(reason);
|
||||
}
|
||||
|
||||
qWarning()<<"AAAAAAAAAAA"<<m_qmlObject->mainComponent()->errors();
|
||||
engine->rootContext()->setContextProperty("plasmoid", this);
|
||||
|
||||
//initialize size, so an useless resize less
|
||||
QVariantHash initialProperties;
|
||||
initialProperties["width"] = width();
|
||||
initialProperties["height"] = height();
|
||||
m_qmlObject->completeInitialization(initialProperties);
|
||||
qWarning()<<"BBBBB";
|
||||
|
||||
|
||||
//default m_compactRepresentation is a simple icon provided by the shell package
|
||||
if (!m_compactRepresentation) {
|
||||
m_compactRepresentation = new QQmlComponent(engine, this);
|
||||
m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation")));
|
||||
}
|
||||
|
||||
//we really want a full representation, default m_fullRepresentation is an error message
|
||||
/* if (!m_fullRepresentation) {
|
||||
m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this);
|
||||
m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror")));
|
||||
}*/
|
||||
|
||||
//default m_compactRepresentationExpander is the popup in which fullRepresentation goes
|
||||
if (!m_compactRepresentationExpander) {
|
||||
m_compactRepresentationExpander = new QQmlComponent(engine, this);
|
||||
m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("compactapplet")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DeclarativeAppletScript *AppletLoader::appletScript() const
|
||||
{
|
||||
return m_appletScriptEngine;
|
||||
}
|
||||
@ -171,37 +226,6 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component)
|
||||
|
||||
////////////Internals
|
||||
|
||||
void AppletLoader::init()
|
||||
{
|
||||
//m_appletScriptEngine = property("_plasma_appletscript").value<Plasma::AppletScript *>();
|
||||
|
||||
Q_ASSERT(m_appletScriptEngine);
|
||||
// m_applet = m_appletScriptEngine->applet();
|
||||
Q_ASSERT(m_applet);
|
||||
|
||||
// m_qmlObject = new KDeclarative::QmlObject(m_qmlObject->engine(), this);
|
||||
|
||||
//default m_compactRepresentation is a simple icon provided by the shell package
|
||||
if (!m_compactRepresentation) {
|
||||
m_compactRepresentation = new QQmlComponent(m_qmlObject->engine(), this);
|
||||
m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("defaultcompactrepresentation")));
|
||||
}
|
||||
|
||||
//we really want a full representation, default m_fullRepresentation is an error message
|
||||
/* if (!m_fullRepresentation) {
|
||||
m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this);
|
||||
m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("appleterror")));
|
||||
}*/
|
||||
|
||||
//default m_compactRepresentationExpander is the popup in which fullRepresentation goes
|
||||
if (!m_compactRepresentationExpander) {
|
||||
m_compactRepresentationExpander = new QQmlComponent(m_qmlObject->engine(), this);
|
||||
m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("compactapplet")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
KDeclarative::QmlObject *AppletLoader::qmlObject()
|
||||
{
|
||||
@ -387,7 +411,7 @@ void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value)
|
||||
if (change == QQuickItem::ItemSceneChange) {
|
||||
//we have a window: create the representations if needed
|
||||
if (value.window) {
|
||||
m_compactRepresentationCheckTimer.start();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +430,7 @@ void AppletLoader::compactRepresentationCheck()
|
||||
|
||||
bool full = false;
|
||||
|
||||
if (applet()->isContainment()) {
|
||||
if (m_appletScriptEngine->applet()->isContainment()) {
|
||||
full = true;
|
||||
|
||||
} else {
|
||||
@ -419,7 +443,7 @@ void AppletLoader::compactRepresentationCheck()
|
||||
full = m_preferredRepresentation.data() == m_fullRepresentation.data();
|
||||
//Otherwise, base on FormFactor
|
||||
} else {
|
||||
full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical);
|
||||
full = (m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Horizontal && m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Vertical);
|
||||
}
|
||||
}
|
||||
|
||||
@ -520,6 +544,5 @@ void AppletLoader::fillHeightChanged()
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "moc_appletloader.cpp"
|
||||
|
||||
|
@ -65,8 +65,7 @@ public:
|
||||
AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0);
|
||||
~AppletLoader();
|
||||
|
||||
Plasma::Applet *applet() const;
|
||||
Plasma::AppletScript *appletScript();
|
||||
DeclarativeAppletScript *appletScript() const;
|
||||
|
||||
int switchWidth() const;
|
||||
void setSwitchWidth(int width);
|
||||
@ -95,6 +94,17 @@ public:
|
||||
//Reimplemented
|
||||
virtual void init();
|
||||
|
||||
static AppletLoader *qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
//at the moment of the attached object creation, the root item is the only one that hasn't a parent
|
||||
//only way to avoid creation of this attached for everybody but the root item
|
||||
if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
||||
return s_rootObjects.value(QtQml::qmlEngine(object));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void switchWidthChanged(int width);
|
||||
void switchHeightChanged(int height);
|
||||
@ -112,7 +122,7 @@ Q_SIGNALS:
|
||||
protected:
|
||||
KDeclarative::QmlObject *qmlObject();
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||
void itemChange(ItemChange change, const ItemChangeData &value);
|
||||
virtual void itemChange(ItemChange change, const ItemChangeData &value);
|
||||
|
||||
QObject *createCompactRepresentationItem();
|
||||
QObject *createFullRepresentationItem();
|
||||
@ -135,11 +145,6 @@ private Q_SLOTS:
|
||||
void fillWidthChanged();
|
||||
void fillHeightChanged();
|
||||
|
||||
//FIXME:
|
||||
protected:
|
||||
DeclarativeAppletScript *m_appletScriptEngine;
|
||||
KDeclarative::QmlObject *m_qmlObject;
|
||||
|
||||
private:
|
||||
int m_switchWidth;
|
||||
int m_switchHeight;
|
||||
@ -161,8 +166,12 @@ private:
|
||||
QTimer m_compactRepresentationCheckTimer;
|
||||
QTimer m_fullRepresentationResizeTimer;
|
||||
|
||||
Plasma::Applet *m_applet;
|
||||
DeclarativeAppletScript *m_appletScriptEngine;
|
||||
KDeclarative::QmlObject *m_qmlObject;
|
||||
|
||||
static QHash<QObject *, AppletLoader *> s_rootObjects;
|
||||
};
|
||||
|
||||
QML_DECLARE_TYPEINFO(AppletLoader, QML_HAS_ATTACHED_PROPERTIES)
|
||||
|
||||
#endif
|
||||
|
@ -119,15 +119,15 @@ void ContainmentInterface::init()
|
||||
pkg.setPath("org.kde.desktoptoolbox");
|
||||
}
|
||||
|
||||
PackageUrlInterceptor *interceptor = dynamic_cast<PackageUrlInterceptor *>(m_qmlObject->engine()->urlInterceptor());
|
||||
PackageUrlInterceptor *interceptor = dynamic_cast<PackageUrlInterceptor *>(qmlObject()->engine()->urlInterceptor());
|
||||
if (interceptor) {
|
||||
interceptor->addAllowedPath(pkg.path());
|
||||
}
|
||||
|
||||
if (pkg.isValid()) {
|
||||
QObject *toolBoxObject = m_qmlObject->createObjectFromSource(QUrl::fromLocalFile(pkg.filePath("mainscript")));
|
||||
QObject *toolBoxObject = qmlObject()->createObjectFromSource(QUrl::fromLocalFile(pkg.filePath("mainscript")));
|
||||
|
||||
QObject *containmentGraphicObject = m_qmlObject->rootObject();
|
||||
QObject *containmentGraphicObject = qmlObject()->rootObject();
|
||||
|
||||
if (containmentGraphicObject && toolBoxObject) {
|
||||
toolBoxObject->setProperty("parent", QVariant::fromValue(containmentGraphicObject));
|
||||
@ -144,12 +144,12 @@ void ContainmentInterface::init()
|
||||
|
||||
//set parent, both as object hyerarchy and visually
|
||||
//do this only for containments, applets will do it in compactrepresentationcheck
|
||||
if (m_qmlObject->rootObject()) {
|
||||
m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this));
|
||||
if (qmlObject()->rootObject()) {
|
||||
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");
|
||||
QQmlExpression expr(qmlObject()->engine()->rootContext(), qmlObject()->rootObject(), "parent");
|
||||
QQmlProperty prop(qmlObject()->rootObject(), "anchors.fill");
|
||||
prop.write(expr.evaluate());
|
||||
}
|
||||
}
|
||||
@ -161,28 +161,28 @@ QList <QObject *> ContainmentInterface::applets()
|
||||
|
||||
void ContainmentInterface::setDrawWallpaper(bool drawWallpaper)
|
||||
{
|
||||
if (drawWallpaper == m_appletScriptEngine->drawWallpaper()) {
|
||||
if (drawWallpaper == appletScript()->drawWallpaper()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_appletScriptEngine->setDrawWallpaper(drawWallpaper);
|
||||
appletScript()->setDrawWallpaper(drawWallpaper);
|
||||
|
||||
loadWallpaper();
|
||||
}
|
||||
|
||||
bool ContainmentInterface::drawWallpaper()
|
||||
{
|
||||
return m_appletScriptEngine->drawWallpaper();
|
||||
return appletScript()->drawWallpaper();
|
||||
}
|
||||
|
||||
Plasma::Types::ContainmentType ContainmentInterface::containmentType() const
|
||||
{
|
||||
return m_appletScriptEngine->containmentType();
|
||||
return appletScript()->containmentType();
|
||||
}
|
||||
|
||||
void ContainmentInterface::setContainmentType(Plasma::Types::ContainmentType type)
|
||||
{
|
||||
m_appletScriptEngine->setContainmentType(type);
|
||||
appletScript()->setContainmentType(type);
|
||||
}
|
||||
|
||||
void ContainmentInterface::lockWidgets(bool locked)
|
||||
@ -548,7 +548,7 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
|
||||
|
||||
void ContainmentInterface::loadWallpaper()
|
||||
{
|
||||
if (m_appletScriptEngine->drawWallpaper() && !containment()->wallpaper().isEmpty()) {
|
||||
if (appletScript()->drawWallpaper() && !containment()->wallpaper().isEmpty()) {
|
||||
delete m_wallpaperInterface;
|
||||
|
||||
m_wallpaperInterface = new WallpaperInterface(this);
|
||||
|
@ -75,7 +75,7 @@ class ContainmentInterface : public AppletInterface
|
||||
public:
|
||||
ContainmentInterface(DeclarativeAppletScript *parent);
|
||||
//Not for QML
|
||||
inline Plasma::Containment *containment() const { return static_cast<Plasma::Containment *>(m_appletScriptEngine->applet()->containment()); }
|
||||
Plasma::Containment *containment() const { return static_cast<Plasma::Containment *>(appletScript()->applet()->containment()); }
|
||||
|
||||
inline WallpaperInterface *wallpaperInterface() const { return m_wallpaperInterface;}
|
||||
|
||||
@ -112,6 +112,11 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE void processMimeData(QMimeData *data, int x, int y);
|
||||
|
||||
static ContainmentInterface *qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
return qobject_cast<ContainmentInterface *>(AppletLoader::qmlAttachedProperties(object));
|
||||
}
|
||||
|
||||
protected:
|
||||
void init();
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
@ -57,6 +57,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
|
||||
//qmlRegisterType<AppletInterface>();
|
||||
qmlRegisterUncreatableType<AppletInterface>("org.kde.plasma.shell", 2, 0, "Plasmoid",
|
||||
QLatin1String("Do not create objects of type Plasmoid"));
|
||||
qmlRegisterUncreatableType<ContainmentInterface>("org.kde.plasma.shell", 2, 0, "Containment",
|
||||
QLatin1String("Do not create objects of type Containment"));
|
||||
|
||||
qmlRegisterType<KDeclarative::ConfigPropertyMap>();
|
||||
Q_UNUSED(args);
|
||||
}
|
||||
@ -111,9 +114,7 @@ void DeclarativeAppletScript::constraintsEvent(Plasma::Types::Constraints constr
|
||||
|
||||
void DeclarativeAppletScript::executeAction(const QString &name)
|
||||
{
|
||||
if (m_interface->qmlObject()->rootObject()) {
|
||||
QMetaObject::invokeMethod(m_interface->qmlObject()->rootObject(), QString("action_" + name).toLatin1(), Qt::DirectConnection);
|
||||
}
|
||||
m_interface->executeAction(name);
|
||||
}
|
||||
|
||||
QList<QAction*> DeclarativeAppletScript::contextualActions()
|
||||
|
@ -56,6 +56,7 @@ Q_SIGNALS:
|
||||
|
||||
private:
|
||||
AppletInterface *m_interface;
|
||||
friend class AppletLoader;
|
||||
friend class AppletInterface;
|
||||
friend class ContainmentInterface;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user