setFailedToLaunch -> setLaunchErrorMessage
setFailedToLaunch has a weird asymmetric api: now launchErrorMessage is a string property. failedToLaunch remains and is internally set true the first time a message is set (is not posssible to set it back to false) the message is in turn used by the scriptengine for the user visible error message. It is done in 2 places: if the applet package is invalid (applet not found) the message is created by the containment if the applet package is valid, but there is a parse error in the qml file the error message is generated by the scriptengine of the applet itself. I'm still really not happy about how the error ui is generated.
This commit is contained in:
parent
0b24d969fe
commit
de4fa09a6d
@ -187,7 +187,7 @@ void Applet::init()
|
|||||||
d->setupScriptSupport();
|
d->setupScriptSupport();
|
||||||
|
|
||||||
if (!d->script->init() && !d->failed) {
|
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;
|
if (message == d->launchErrorMessage) {
|
||||||
d->updateFailedToLaunch(reason);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->failed = true;
|
||||||
|
d->launchErrorMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::saveState(KConfigGroup &group) const
|
void Applet::saveState(KConfigGroup &group) const
|
||||||
@ -464,7 +468,12 @@ void Applet::setImmutability(const ImmutabilityType immutable)
|
|||||||
updateConstraints(ImmutableConstraint);
|
updateConstraints(ImmutableConstraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Applet::hasFailedToLaunch() const
|
QString Applet::launchErrorMessage() const
|
||||||
|
{
|
||||||
|
return d->launchErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Applet::failedToLaunch() const
|
||||||
{
|
{
|
||||||
return d->failed;
|
return d->failed;
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,17 @@ class PLASMA_EXPORT Applet : public QObject
|
|||||||
/**
|
/**
|
||||||
* If for some reason, the applet fails to get up on its feet (the
|
* 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,
|
* 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
|
* @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 failed true when the applet failed, false when it succeeded
|
||||||
* @param reason an optional reason to show the user why the applet
|
* @param reason an optional reason to show the user why the applet
|
||||||
* failed to launch
|
* failed to launch
|
||||||
|
* @since 5.0
|
||||||
**/
|
**/
|
||||||
void setFailedToLaunch(bool failed, const QString &reason = QString());
|
void setLaunchErrorMessage(const QString &reason = QString());
|
||||||
|
|
||||||
//CONFIGURATION
|
//CONFIGURATION
|
||||||
/**
|
/**
|
||||||
@ -738,7 +747,7 @@ class PLASMA_EXPORT Applet : public QObject
|
|||||||
|
|
||||||
AppletPrivate *const d;
|
AppletPrivate *const d;
|
||||||
|
|
||||||
//Corona needs to access setFailedToLaunch and init
|
//Corona needs to access setLaunchErrorMessage and init
|
||||||
friend class Corona;
|
friend class Corona;
|
||||||
friend class CoronaPrivate;
|
friend class CoronaPrivate;
|
||||||
friend class Containment;
|
friend class Containment;
|
||||||
|
@ -615,7 +615,7 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi
|
|||||||
if (loadingNull) {
|
if (loadingNull) {
|
||||||
containment->setDrawWallpaper(false);
|
containment->setDrawWallpaper(false);
|
||||||
} else {
|
} else {
|
||||||
containment->setFailedToLaunch(false);
|
containment->setLaunchErrorMessage(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want to provide something and don't care about the failure to launch
|
// we want to provide something and don't care about the failure to launch
|
||||||
|
@ -126,7 +126,7 @@ void AppletPrivate::init(const QString &packagePath)
|
|||||||
|
|
||||||
// we have a scripted plasmoid
|
// we have a scripted plasmoid
|
||||||
if (api.isEmpty()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ void AppletPrivate::init(const QString &packagePath)
|
|||||||
if (!package->isValid()) {
|
if (!package->isValid()) {
|
||||||
delete package;
|
delete package;
|
||||||
package = 0;
|
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.",
|
"Could not open the %1 package required for the %2 widget.",
|
||||||
appletDescription.pluginName(), appletDescription.name()));
|
appletDescription.pluginName(), appletDescription.name()));
|
||||||
return;
|
return;
|
||||||
@ -156,7 +156,7 @@ void AppletPrivate::init(const QString &packagePath)
|
|||||||
if (!script) {
|
if (!script) {
|
||||||
delete package;
|
delete package;
|
||||||
package = 0;
|
package = 0;
|
||||||
q->setFailedToLaunch(true,
|
q->setLaunchErrorMessage(
|
||||||
i18nc("API or programming language the widget was written in, name of the widget",
|
i18nc("API or programming language the widget was written in, name of the widget",
|
||||||
"Could not create a %1 ScriptEngine for the %2 widget.",
|
"Could not create a %1 ScriptEngine for the %2 widget.",
|
||||||
api, appletDescription.name()));
|
api, appletDescription.name()));
|
||||||
@ -175,12 +175,6 @@ void AppletPrivate::showConfigurationRequiredMessage(bool show, const QString &r
|
|||||||
Q_UNUSED(reason)
|
Q_UNUSED(reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletPrivate::updateFailedToLaunch(const QString &reason)
|
|
||||||
{
|
|
||||||
// reimplemented in the UI specific library
|
|
||||||
Q_UNUSED(reason)
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppletPrivate::globalShortcutChanged()
|
void AppletPrivate::globalShortcutChanged()
|
||||||
{
|
{
|
||||||
if (!activationAction) {
|
if (!activationAction) {
|
||||||
|
@ -79,7 +79,6 @@ public:
|
|||||||
// the interface
|
// the interface
|
||||||
virtual void showConfigurationRequiredMessage(bool show, const QString &reason);
|
virtual void showConfigurationRequiredMessage(bool show, const QString &reason);
|
||||||
virtual void cleanUpAndDelete();
|
virtual void cleanUpAndDelete();
|
||||||
virtual void updateFailedToLaunch(const QString &reason);
|
|
||||||
|
|
||||||
// put all setup routines for script here. at this point we can assume that
|
// put all setup routines for script here. at this point we can assume that
|
||||||
// package exists and that we have a script engin
|
// package exists and that we have a script engin
|
||||||
@ -122,6 +121,7 @@ public:
|
|||||||
|
|
||||||
// applet attributes
|
// applet attributes
|
||||||
ImmutabilityType immutability;
|
ImmutabilityType immutability;
|
||||||
|
QString launchErrorMessage;
|
||||||
|
|
||||||
// applet info we keep around in case its needed
|
// applet info we keep around in case its needed
|
||||||
KPluginInfo appletDescription;
|
KPluginInfo appletDescription;
|
||||||
@ -152,8 +152,8 @@ public:
|
|||||||
|
|
||||||
// a great green field of booleans :)
|
// a great green field of booleans :)
|
||||||
bool hasConfigurationInterface : 1;
|
bool hasConfigurationInterface : 1;
|
||||||
bool failed : 1;
|
|
||||||
bool isContainment : 1;
|
bool isContainment : 1;
|
||||||
|
bool failed : 1;
|
||||||
bool transient : 1;
|
bool transient : 1;
|
||||||
bool needsConfig : 1;
|
bool needsConfig : 1;
|
||||||
bool started : 1;
|
bool started : 1;
|
||||||
|
@ -406,7 +406,7 @@ Applet *ContainmentPrivate::addApplet(const QString &name, const QVariantList &a
|
|||||||
kDebug() << "Applet" << name << "could not be loaded.";
|
kDebug() << "Applet" << name << "could not be loaded.";
|
||||||
#endif
|
#endif
|
||||||
applet = new Applet(0, QString(), id);
|
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();
|
//kDebug() << applet->title() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
||||||
|
@ -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()) {
|
if (applet()) {
|
||||||
applet()->setFailedToLaunch(failed, reason);
|
applet()->setLaunchErrorMessage(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @see Applet
|
* @see Applet
|
||||||
*/
|
*/
|
||||||
void setFailedToLaunch(bool failed, const QString &reason = QString());
|
void setLaunchErrorMessage(const QString &reason = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Applet
|
* @see Applet
|
||||||
|
@ -33,7 +33,7 @@ bool AppletAuthorization::authorizeRequiredExtension(const QString &extension)
|
|||||||
bool ok = m_scriptEngine->applet()->hasAuthorization(extension);
|
bool ok = m_scriptEngine->applet()->hasAuthorization(extension);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
m_scriptEngine->setFailedToLaunch(true,
|
m_scriptEngine->setLaunchErrorMessage(true,
|
||||||
i18n("Authorization for required extension '%1' was denied.",
|
i18n("Authorization for required extension '%1' was denied.",
|
||||||
extension));
|
extension));
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ bool AppletInterface::shouldConserveResources() const
|
|||||||
|
|
||||||
void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
|
void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
|
||||||
{
|
{
|
||||||
m_appletScriptEngine->setFailedToLaunch(failed, reason);
|
m_appletScriptEngine->setLaunchErrorMessage(failed, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppletInterface::isBusy() const
|
bool AppletInterface::isBusy() const
|
||||||
@ -224,7 +224,7 @@ QList<QAction*> AppletInterface::contextualActions() const
|
|||||||
{
|
{
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
Plasma::Applet *a = applet();
|
Plasma::Applet *a = applet();
|
||||||
if (a->hasFailedToLaunch()) {
|
if (a->launchErrorMessage()) {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ void SimpleJavaScriptApplet::reportError(ScriptEnv *env, bool fatal)
|
|||||||
file, error.property("lineNumber").toString(),
|
file, error.property("lineNumber").toString(),
|
||||||
error.toString());
|
error.toString());
|
||||||
if (fatal) {
|
if (fatal) {
|
||||||
setFailedToLaunch(true, failureMsg);
|
setLaunchErrorMessage(true, failureMsg);
|
||||||
} else {
|
} else {
|
||||||
showMessage(KIcon("dialog-error"), failureMsg, Plasma::ButtonOk);
|
showMessage(KIcon("dialog-error"), failureMsg, Plasma::ButtonOk);
|
||||||
}
|
}
|
||||||
|
@ -81,11 +81,6 @@ QString AppletInterface::currentActivity() const
|
|||||||
return applet()->containment()->activity();
|
return applet()->containment()->activity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
|
|
||||||
{
|
|
||||||
m_appletScriptEngine->setFailedToLaunch(failed, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppletInterface::isBusy() const
|
bool AppletInterface::isBusy() const
|
||||||
{
|
{
|
||||||
return m_busy;
|
return m_busy;
|
||||||
@ -204,7 +199,7 @@ QList<QAction*> AppletInterface::contextualActions() const
|
|||||||
{
|
{
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
Plasma::Applet *a = applet();
|
Plasma::Applet *a = applet();
|
||||||
if (a->hasFailedToLaunch()) {
|
if (a->failedToLaunch()) {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,6 +450,18 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPoi
|
|||||||
if (applet && contGraphicObject && appletGraphicObject) {
|
if (applet && contGraphicObject && appletGraphicObject) {
|
||||||
appletGraphicObject->setProperty("visible", false);
|
appletGraphicObject->setProperty("visible", false);
|
||||||
appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject));
|
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);
|
emit appletAdded(appletGraphicObject, pos);
|
||||||
|
@ -207,8 +207,6 @@ enum IntervalAlignment {
|
|||||||
Location location() const;
|
Location location() const;
|
||||||
QString currentActivity() const;
|
QString currentActivity() const;
|
||||||
|
|
||||||
Q_INVOKABLE void setFailedToLaunch(bool failed, const QString &reason = QString());
|
|
||||||
|
|
||||||
Q_INVOKABLE bool isBusy() const;
|
Q_INVOKABLE bool isBusy() const;
|
||||||
Q_INVOKABLE void setBusy(bool busy);
|
Q_INVOKABLE void setBusy(bool busy);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ bool DeclarativeAppletScript::init()
|
|||||||
m_qmlObject->rootObject()->setProperty("reason", reason);
|
m_qmlObject->rootObject()->setProperty("reason", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
setFailedToLaunch(true, reason);
|
setLaunchErrorMessage(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Applet *a = applet();
|
Plasma::Applet *a = applet();
|
||||||
|
Loading…
Reference in New Issue
Block a user