diff --git a/plasma/applet.cpp b/plasma/applet.cpp index abb3fc729..294372771 100644 --- a/plasma/applet.cpp +++ b/plasma/applet.cpp @@ -187,7 +187,7 @@ void Applet::init() d->setupScriptSupport(); if (!d->script->init() && !d->failed) { - setFailedToLaunch(true, i18n("Script initialization failed")); + setLaunchErrorMessage(i18n("Script initialization failed")); } } } @@ -264,10 +264,14 @@ void Applet::restore(KConfigGroup &group) */ } -void Applet::setFailedToLaunch(bool failed, const QString &reason) +void Applet::setLaunchErrorMessage(const QString &message) { - d->failed = failed; - d->updateFailedToLaunch(reason); + if (message == d->launchErrorMessage) { + return; + } + + d->failed = true; + d->launchErrorMessage = message; } void Applet::saveState(KConfigGroup &group) const @@ -464,7 +468,12 @@ void Applet::setImmutability(const ImmutabilityType immutable) updateConstraints(ImmutableConstraint); } -bool Applet::hasFailedToLaunch() const +QString Applet::launchErrorMessage() const +{ + return d->launchErrorMessage; +} + +bool Applet::failedToLaunch() const { return d->failed; } diff --git a/plasma/applet.h b/plasma/applet.h index acc7f4d38..b83ed35b6 100644 --- a/plasma/applet.h +++ b/plasma/applet.h @@ -119,9 +119,17 @@ class PLASMA_EXPORT Applet : public QObject /** * If for some reason, the applet fails to get up on its feet (the * library couldn't be loaded, necessary hardware support wasn't found, - * etc..) this method returns true + * etc..) this method returns the reason why, in an user-readable way. + * @since 5.0 **/ - bool hasFailedToLaunch() const; + QString launchErrorMessage() const; + + /** + * If for some reason, the applet fails to get up on its feet (the + * library couldn't be loaded, necessary hardware support wasn't found, + * etc..) this method returns true. + **/ + bool failedToLaunch() const; /** * @return true if destroy() was called; useful for Applets which should avoid @@ -652,8 +660,9 @@ class PLASMA_EXPORT Applet : public QObject * @param failed true when the applet failed, false when it succeeded * @param reason an optional reason to show the user why the applet * failed to launch + * @since 5.0 **/ - void setFailedToLaunch(bool failed, const QString &reason = QString()); + void setLaunchErrorMessage(const QString &reason = QString()); //CONFIGURATION /** @@ -738,7 +747,7 @@ class PLASMA_EXPORT Applet : public QObject AppletPrivate *const d; - //Corona needs to access setFailedToLaunch and init + //Corona needs to access setLaunchErrorMessage and init friend class Corona; friend class CoronaPrivate; friend class Containment; diff --git a/plasma/corona.cpp b/plasma/corona.cpp index 684d703d3..fd0631619 100644 --- a/plasma/corona.cpp +++ b/plasma/corona.cpp @@ -615,7 +615,7 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi if (loadingNull) { containment->setDrawWallpaper(false); } else { - containment->setFailedToLaunch(false); + containment->setLaunchErrorMessage(false); } // we want to provide something and don't care about the failure to launch diff --git a/plasma/private/applet_p.cpp b/plasma/private/applet_p.cpp index 3dcd4423e..5970c3170 100644 --- a/plasma/private/applet_p.cpp +++ b/plasma/private/applet_p.cpp @@ -126,7 +126,7 @@ void AppletPrivate::init(const QString &packagePath) // we have a scripted plasmoid if (api.isEmpty()) { - q->setFailedToLaunch(true, i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name())); + q->setLaunchErrorMessage(i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name())); return; } @@ -138,7 +138,7 @@ void AppletPrivate::init(const QString &packagePath) if (!package->isValid()) { delete package; package = 0; - q->setFailedToLaunch(true, i18nc("Package file, name of the widget", + q->setLaunchErrorMessage(i18nc("Package file, name of the widget", "Could not open the %1 package required for the %2 widget.", appletDescription.pluginName(), appletDescription.name())); return; @@ -156,7 +156,7 @@ void AppletPrivate::init(const QString &packagePath) if (!script) { delete package; package = 0; - q->setFailedToLaunch(true, + q->setLaunchErrorMessage( i18nc("API or programming language the widget was written in, name of the widget", "Could not create a %1 ScriptEngine for the %2 widget.", api, appletDescription.name())); @@ -175,12 +175,6 @@ void AppletPrivate::showConfigurationRequiredMessage(bool show, const QString &r Q_UNUSED(reason) } -void AppletPrivate::updateFailedToLaunch(const QString &reason) -{ - // reimplemented in the UI specific library - Q_UNUSED(reason) -} - void AppletPrivate::globalShortcutChanged() { if (!activationAction) { diff --git a/plasma/private/applet_p.h b/plasma/private/applet_p.h index 66704236d..af2a6d690 100644 --- a/plasma/private/applet_p.h +++ b/plasma/private/applet_p.h @@ -79,7 +79,6 @@ public: // the interface virtual void showConfigurationRequiredMessage(bool show, const QString &reason); virtual void cleanUpAndDelete(); - virtual void updateFailedToLaunch(const QString &reason); // put all setup routines for script here. at this point we can assume that // package exists and that we have a script engin @@ -122,6 +121,7 @@ public: // applet attributes ImmutabilityType immutability; + QString launchErrorMessage; // applet info we keep around in case its needed KPluginInfo appletDescription; @@ -152,8 +152,8 @@ public: // a great green field of booleans :) bool hasConfigurationInterface : 1; - bool failed : 1; bool isContainment : 1; + bool failed : 1; bool transient : 1; bool needsConfig : 1; bool started : 1; diff --git a/plasma/private/containment_p.cpp b/plasma/private/containment_p.cpp index 1c5d26ed8..d7b2a1598 100644 --- a/plasma/private/containment_p.cpp +++ b/plasma/private/containment_p.cpp @@ -406,7 +406,7 @@ Applet *ContainmentPrivate::addApplet(const QString &name, const QVariantList &a kDebug() << "Applet" << name << "could not be loaded."; #endif applet = new Applet(0, QString(), id); - applet->setFailedToLaunch(true, i18n("Could not find requested component: %1", name)); + applet->setLaunchErrorMessage(i18n("Could not find requested component: %1", name)); } //kDebug() << applet->title() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry(); diff --git a/plasma/scripting/appletscript.cpp b/plasma/scripting/appletscript.cpp index d29ccf084..8f9435fcb 100644 --- a/plasma/scripting/appletscript.cpp +++ b/plasma/scripting/appletscript.cpp @@ -91,10 +91,10 @@ void AppletScript::setConfigurationRequired(bool req, const QString &reason) } } -void AppletScript::setFailedToLaunch(bool failed, const QString &reason) +void AppletScript::setLaunchErrorMessage(const QString &reason) { if (applet()) { - applet()->setFailedToLaunch(failed, reason); + applet()->setLaunchErrorMessage(reason); } } diff --git a/plasma/scripting/appletscript.h b/plasma/scripting/appletscript.h index eb428ef11..cd25e9d07 100644 --- a/plasma/scripting/appletscript.h +++ b/plasma/scripting/appletscript.h @@ -120,7 +120,7 @@ public: /** * @see Applet */ - void setFailedToLaunch(bool failed, const QString &reason = QString()); + void setLaunchErrorMessage(const QString &reason = QString()); /** * @see Applet diff --git a/scriptengines/javascript/plasmoid/appletauthorization.cpp b/scriptengines/javascript/plasmoid/appletauthorization.cpp index c0b1571e5..0a2f20c90 100644 --- a/scriptengines/javascript/plasmoid/appletauthorization.cpp +++ b/scriptengines/javascript/plasmoid/appletauthorization.cpp @@ -33,7 +33,7 @@ bool AppletAuthorization::authorizeRequiredExtension(const QString &extension) bool ok = m_scriptEngine->applet()->hasAuthorization(extension); if (!ok) { - m_scriptEngine->setFailedToLaunch(true, + m_scriptEngine->setLaunchErrorMessage(true, i18n("Authorization for required extension '%1' was denied.", extension)); } diff --git a/scriptengines/javascript/plasmoid/appletinterface.cpp b/scriptengines/javascript/plasmoid/appletinterface.cpp index 85c7a4e55..d46f630d6 100644 --- a/scriptengines/javascript/plasmoid/appletinterface.cpp +++ b/scriptengines/javascript/plasmoid/appletinterface.cpp @@ -98,7 +98,7 @@ bool AppletInterface::shouldConserveResources() const void AppletInterface::setFailedToLaunch(bool failed, const QString &reason) { - m_appletScriptEngine->setFailedToLaunch(failed, reason); + m_appletScriptEngine->setLaunchErrorMessage(failed, reason); } bool AppletInterface::isBusy() const @@ -224,7 +224,7 @@ QList AppletInterface::contextualActions() const { QList actions; Plasma::Applet *a = applet(); - if (a->hasFailedToLaunch()) { + if (a->launchErrorMessage()) { return actions; } diff --git a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp index 131bcca08..5232cea08 100644 --- a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp @@ -129,7 +129,7 @@ void SimpleJavaScriptApplet::reportError(ScriptEnv *env, bool fatal) file, error.property("lineNumber").toString(), error.toString()); if (fatal) { - setFailedToLaunch(true, failureMsg); + setLaunchErrorMessage(true, failureMsg); } else { showMessage(KIcon("dialog-error"), failureMsg, Plasma::ButtonOk); } diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index a16a332fc..c4a4fd077 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -81,11 +81,6 @@ QString AppletInterface::currentActivity() const return applet()->containment()->activity(); } -void AppletInterface::setFailedToLaunch(bool failed, const QString &reason) -{ - m_appletScriptEngine->setFailedToLaunch(failed, reason); -} - bool AppletInterface::isBusy() const { return m_busy; @@ -204,7 +199,7 @@ QList AppletInterface::contextualActions() const { QList actions; Plasma::Applet *a = applet(); - if (a->hasFailedToLaunch()) { + if (a->failedToLaunch()) { return actions; } @@ -455,6 +450,18 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPoi if (applet && contGraphicObject && appletGraphicObject) { 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 (applet && contGraphicObject) { + QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), applet); + component->loadUrl(QUrl::fromLocalFile(containment()->corona()->package().filePath("ui", "AppletError.qml"))); + QObject *errorUi = component->create(); + + if (errorUi) { + errorUi->setProperty("visible", false); + errorUi->setProperty("parent", QVariant::fromValue(contGraphicObject)); + errorUi->setProperty("reason", applet->launchErrorMessage()); + appletGraphicObject = errorUi; + } } emit appletAdded(appletGraphicObject, pos); diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index f30684558..c95218c02 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -207,8 +207,6 @@ enum IntervalAlignment { Location location() const; QString currentActivity() const; - Q_INVOKABLE void setFailedToLaunch(bool failed, const QString &reason = QString()); - Q_INVOKABLE bool isBusy() const; Q_INVOKABLE void setBusy(bool busy); diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 3150f4554..5f1721c12 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -109,7 +109,7 @@ bool DeclarativeAppletScript::init() m_qmlObject->rootObject()->setProperty("reason", reason); } - setFailedToLaunch(true, reason); + setLaunchErrorMessage(reason); } Plasma::Applet *a = applet();