show an error message on QML parse error

the error message is QML itself, coming from the Corona package (so there is the possibility that even the error message can't parse, in this case we have no way to show an error)

the user of the qml plasmoid still can't set a message on his own (setFailedToLaunch will probably become scriptengine only)
This commit is contained in:
Marco Martin 2013-02-12 15:55:17 +01:00
parent c9d9ccc857
commit 0b24d969fe
6 changed files with 76 additions and 7 deletions

View File

@ -280,6 +280,7 @@ void ContainmentActionsPackage::initPackage(Package *package)
void GenericPackage::initPackage(Package *package)
{
PlasmoidPackage::initPackage(package);
package->setDefaultPackageRoot("plasma/packages/");
}

View File

@ -92,6 +92,11 @@ void QmlObjectPrivate::execute(const QString &fileName)
return;
}
delete component;
component = new QQmlComponent(engine, q);
delete root;
root = 0;
KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine);
kdeclarative.initialize();
@ -122,8 +127,6 @@ QmlObject::QmlObject(QObject *parent)
{
d->engine = new QQmlEngine(this);
//d->engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory());
d->component = new QQmlComponent(d->engine, this);
}
QmlObject::~QmlObject()
@ -173,6 +176,9 @@ QQmlComponent *QmlObject::mainComponent() const
void QmlObject::completeInitialization()
{
if (d->root) {
return;
}
if (d->component->status() != QQmlComponent::Ready || d->component->isError()) {
d->errorPrint();
return;

View File

@ -36,6 +36,7 @@
#include <klocalizedstring.h>
#include <Plasma/Applet>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <Plasma/PluginLoader>
#include <Plasma/Service>
@ -95,8 +96,20 @@ bool DeclarativeAppletScript::init()
foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) {
reason += error.toString()+'\n';
}
reason = i18n("Error loading QML file: %1", reason);
m_qmlObject->setQmlPath(applet()->containment()->corona()->package().filePath("ui", "AppletError.qml"));
m_qmlObject->completeInitialization();
//even the error message QML may fail
if (m_qmlObject->mainComponent()->isError()) {
return false;
} else {
m_qmlObject->rootObject()->setProperty("reason", reason);
}
setFailedToLaunch(true, reason);
return false;
}
Plasma::Applet *a = applet();
@ -110,6 +123,7 @@ bool DeclarativeAppletScript::init()
} else {
m_interface = new AppletInterface(this);
}
m_interface->setParent(this);
connect(applet(), SIGNAL(activate()),
@ -118,11 +132,15 @@ bool DeclarativeAppletScript::init()
setupObjects();
m_qmlObject->completeInitialization();
m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_interface));
m_qmlObject->rootObject()->setProperty("anchors.fill", "parent");
//set anchors
QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent");
QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill");
prop.write(expr.evaluate());
// set the graphicObject dynamic property on applet
a->setProperty("graphicObject", QVariant::fromValue(m_interface));
qDebug() << "Graphic object created:" << a << a->property("graphicObject");

View File

@ -0,0 +1,45 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
Row {
id: root
property alias reason: messageText.text
clip: true
PlasmaCore.IconItem {
id: icon
anchors.verticalCenter: parent
width: theme.hugeIconSize
height: width
source: "dialog-error"
}
PlasmaComponents.Label {
id: messageText
anchors.verticalCenter: parent
width: parent.width - icon.width
wrapMode: Text.Wrap
}
}

View File

@ -26,6 +26,8 @@ Rectangle {
color: "transparent"
width: 100
height: 100
radius: 10
smooth: true
Column {
anchors.centerIn: parent

View File

@ -116,8 +116,5 @@ Rectangle {
Component.onCompleted: {
print("Test Containment loaded")
print(plasmoid)
for (var i in plasmoid) {
print(i+" "+plasmoid[i])
}
}
}