diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativeengine.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index f1adc16..c5afe92 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -212,10 +212,13 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr newQMetaObject(StaticQtMetaObject::get()); globalObject().setProperty(QLatin1String("Qt"), qtObject); +#ifndef QT_NO_DESKTOPSERVICES offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation).replace(QLatin1Char('/'), QDir::separator()) + QDir::separator() + QLatin1String("QML") + QDir::separator() + QLatin1String("OfflineStorage"); - +#else + qWarning("offlineStoragePath is not set by default with QT_NO_DESKTOPSERVICES"); +#endif qt_add_qmlxmlhttprequest(this); qt_add_qmlsqldatabase(this); @@ -848,6 +851,9 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) if (propertyCache) propertyCache->release(); + if (ownContext) + context->destroy(); + QDeclarativeGuard<QObject> *guard = guards; while (guard) { QDeclarativeGuard<QObject> *g = guard; @@ -858,9 +864,6 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) g->objectDestroyed(object); } - if (ownContext) - context->destroy(); - if (scriptValue) delete scriptValue; @@ -1214,7 +1217,10 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc { if(ctxt->argumentCount() < 1) return e->newVariant(QVariant(false)); - bool ret = QDesktopServices::openUrl(QUrl(ctxt->argument(0).toString())); + bool ret = false; +#ifndef QT_NO_DESKTOPSERVICES + ret = QDesktopServices::openUrl(QUrl(ctxt->argument(0).toString())); +#endif return e->newVariant(QVariant(ret)); } @@ -1486,13 +1492,17 @@ public: QSet<QString> qmlDirFilesForWhichPluginsHaveBeenLoaded; - QDeclarativeDirComponents importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine) { + bool importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, QDeclarativeDirComponents* components, QString *errorString) { QFile file(absoluteFilePath); QString filecontent; if (file.open(QFile::ReadOnly)) { filecontent = QString::fromUtf8(file.readAll()); if (qmlImportTrace()) qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath; + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); + return false; } QDir dir = QFileInfo(file).dir(); @@ -1512,11 +1522,23 @@ public: plugin.name); if (!resolvedFilePath.isEmpty()) { - engine->importPlugin(resolvedFilePath, uri); + if (!engine->importPlugin(resolvedFilePath, uri, errorString)) { + if (errorString) + *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); + return false; + } + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); + return false; } } } - return qmldirParser.components(); + + if (components) + *components = qmldirParser.components(); + + return true; } QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine) @@ -1577,7 +1599,8 @@ public: url = QUrl::fromLocalFile(fi.absolutePath()).toString(); uri = resolvedUri(dir, engine); - qmldircomponents = importExtension(absoluteFilePath, uri, engine); + if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString)) + return false; break; } } @@ -1608,12 +1631,12 @@ public: return false; // local import dirs must exist } uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine); - qmldircomponents = importExtension(localFileOrQrc, - uri, - engine); - if (uri.endsWith(QLatin1Char('/'))) uri.chop(1); + if (QFile::exists(localFileOrQrc)) { + if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString)) + return false; + } } else { if (prefix.isEmpty()) { // directory must at least exist for valid import @@ -1926,8 +1949,10 @@ void QDeclarativeEngine::setPluginPathList(const QStringList &paths) /*! Imports the plugin named \a filePath with the \a uri provided. Returns true if the plugin was successfully imported; otherwise returns false. + + The plugin has to be a Qt plugin which implements the QDeclarativeExtensionPlugin interface. */ -bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri) +bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri, QString *errorString) { if (qmlImportTrace()) qDebug() << "QDeclarativeEngine::importPlugin" << uri << "from" << filePath; @@ -1948,9 +1973,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur QPluginLoader loader(absoluteFilePath); if (!loader.load()) { - if (qmlImportTrace()) { - qDebug() << "QDeclarativeEngine::importPlugin: " << loader.errorString(); - } + if (errorString) + *errorString = loader.errorString(); return false; } @@ -1972,8 +1996,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur iface->initializeEngine(this, moduleId); } } else { - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::importPlugin: no DeclarativeExtensionInterface error"; + if (errorString) + *errorString = loader.errorString(); return false; } } |