diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index c4403cf6f..ea967354b 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -448,23 +448,28 @@ void AppletQuickItem::init() //Initialize the main QML file QQmlEngine *engine = d->qmlObject->engine(); - PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->package()); - interceptor->addAllowedPath(d->coronaPackage.path()); - engine->setUrlInterceptor(interceptor); + if (d->applet->package().isValid()) { + PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->package()); + interceptor->addAllowedPath(d->coronaPackage.path()); + engine->setUrlInterceptor(interceptor); + } d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->package().filePath("mainscript"))); if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || d->qmlObject->mainComponent()->isError()) { QString reason; - foreach (QQmlError error, d->qmlObject->mainComponent()->errors()) { - reason += error.toString()+'\n'; + if (d->applet->package().isValid()) { + foreach (QQmlError error, d->qmlObject->mainComponent()->errors()) { + reason += error.toString()+'\n'; + } + reason = i18n("Error loading QML file: %1", reason); + } else { + reason = i18n("Error loading Applet: package inexistent. %1", applet()->launchErrorMessage()); } - reason = i18n("Error loading QML file: %1", reason); d->qmlObject->setSource(QUrl::fromLocalFile(d->coronaPackage.filePath("appleterror"))); d->qmlObject->completeInitialization(); - //even the error message QML may fail if (d->qmlObject->mainComponent()->isError()) { return; diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 996dd2c40..24dc7e6f7 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -85,6 +85,39 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa } } +AppletInterface::AppletInterface(Plasma::Applet *a, QQuickItem *parent) + : AppletQuickItem(a, parent), + m_actionSignals(0), + m_appletScriptEngine(0), + m_backgroundHints(Plasma::Types::StandardBackground), + m_busy(false), + m_hideOnDeactivate(true) +{ + qmlRegisterType(); + + connect(this, &AppletInterface::configNeedsSaving, + applet(), &Plasma::Applet::configNeedsSaving); + connect(applet(), &Plasma::Applet::immutabilityChanged, + this, &AppletInterface::immutableChanged); + connect(applet(), &Plasma::Applet::userConfiguringChanged, + this, &AppletInterface::userConfiguringChanged); + + connect(applet(), &Plasma::Applet::statusChanged, + this, &AppletInterface::statusChanged); + + connect(appletScript(), &DeclarativeAppletScript::formFactorChanged, + this, &AppletInterface::formFactorChanged); + connect(appletScript(), &DeclarativeAppletScript::locationChanged, + this, &AppletInterface::locationChanged); + connect(appletScript(), &DeclarativeAppletScript::contextChanged, + this, &AppletInterface::contextChanged); + + if (applet()->containment()) { + connect(applet()->containment(), &Plasma::Containment::screenChanged, + this, &ContainmentInterface::screenChanged); + } +} + AppletInterface::~AppletInterface() { } diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 81abb97f0..36ad6e0fc 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -168,6 +168,7 @@ class AppletInterface : public PlasmaQuick::AppletQuickItem public: AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0); + AppletInterface(Plasma::Applet *applet, QQuickItem *parent = 0); ~AppletInterface(); //API not intended for the QML part diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index eb58940be..91059982c 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -505,20 +505,15 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) qDebug() << "Applet added on containment:" << containment()->title() << contGraphicObject << "Applet: " << applet << applet->title() << appletGraphicObject; - if (contGraphicObject && appletGraphicObject) { + if (!appletGraphicObject) { + appletGraphicObject = new AppletInterface(applet, this); + applet->setProperty("_plasma_graphicObject", QVariant::fromValue(appletGraphicObject)); + static_cast(appletGraphicObject)->init(); + } + + if (contGraphicObject) { appletGraphicObject->setProperty("visible", false); appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject)); - - //if an appletGraphicObject is not set, we have to display some error message - } else if (contGraphicObject) { - QObject *errorUi = qmlObject()->createObjectFromSource(QUrl::fromLocalFile(containment()->corona()->package().filePath("appleterror"))); - - if (errorUi) { - errorUi->setProperty("visible", false); - errorUi->setProperty("parent", QVariant::fromValue(contGraphicObject)); - errorUi->setProperty("reason", applet->launchErrorMessage()); - appletGraphicObject = errorUi; - } } m_appletInterfaces << appletGraphicObject;