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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public:
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void setFailedToLaunch(bool failed, const QString &reason = QString());
|
||||
void setLaunchErrorMessage(const QString &reason = QString());
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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<QAction*> AppletInterface::contextualActions() const
|
||||
{
|
||||
QList<QAction*> actions;
|
||||
Plasma::Applet *a = applet();
|
||||
if (a->hasFailedToLaunch()) {
|
||||
if (a->launchErrorMessage()) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<QAction*> AppletInterface::contextualActions() const
|
||||
{
|
||||
QList<QAction*> 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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -109,7 +109,7 @@ bool DeclarativeAppletScript::init()
|
||||
m_qmlObject->rootObject()->setProperty("reason", reason);
|
||||
}
|
||||
|
||||
setFailedToLaunch(true, reason);
|
||||
setLaunchErrorMessage(reason);
|
||||
}
|
||||
|
||||
Plasma::Applet *a = applet();
|
||||
|
Loading…
Reference in New Issue
Block a user