summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativeimport.cpp
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2011-02-08 12:33:03 +0100
committermae <qt-info@nokia.com>2011-02-08 12:44:15 +0100
commitdd49b322b327fe87d8420abcce0e6cee877a88d7 (patch)
tree61a87a94773ca7cc209bcf92967ec5f39bef732a /src/declarative/qml/qdeclarativeimport.cpp
parent77bd529c04b2f08ca40a282a3ff20df699b27295 (diff)
Support seperate versions of installed modules
QML supports versioned types in modules. There's a version major and a version minor. This makes it possible to have a module com.organisation.fancycomponents with version 1.0, and later you could ship a new module com.organisation.fancycomponents which contains a more recent version 1.1 or 2.0 AND also the old versions to keep old code running. This is good. The problem is that this is difficult with certain QA procedures. It's hard to verify that a new module is indeed 100% compatible with the previous versions. The change extends the import mechanism by adding optional versioning to the component patch. With the patch, you can add a new module com.organisation.fancycomponents.2.0 which will be loaded when the QML file specifies "import com.organisation.fancycomponents 2.0". The patch works as follows: if you try to load com.organisation.fancycomponents in version 2.0, the engine first looks for com/organisation/fancycomponents.2.0, then for com/organisation/fancycomponents.2 then for com.organisation/fancycomponents. Reviewed-by: Aaron Kennedy Task-number: QTBUG-16455
Diffstat (limited to 'src/declarative/qml/qdeclarativeimport.cpp')
-rw-r--r--src/declarative/qml/qdeclarativeimport.cpp76
1 files changed, 64 insertions, 12 deletions
diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp
index c89666d134..22dcb44d4a 100644
--- a/src/declarative/qml/qdeclarativeimport.cpp
+++ b/src/declarative/qml/qdeclarativeimport.cpp
@@ -425,8 +425,18 @@ QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclara
break;
}
}
+
+ stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('/'));
+
+ // remove optional versioning in dot notation from uri
+ int lastSlash = stableRelativePath.lastIndexOf(QLatin1Char('/'));
+ if (lastSlash >= 0) {
+ int versionDot = stableRelativePath.indexOf(QLatin1Char('.'), lastSlash);
+ if (versionDot >= 0)
+ stableRelativePath = stableRelativePath.left(versionDot);
+ }
+
stableRelativePath.replace(QLatin1Char('/'), QLatin1Char('.'));
- stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('.'));
return stableRelativePath;
}
@@ -453,20 +463,62 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
QString dir;
- foreach (const QString &p, database->fileImportPath) {
- dir = p+QLatin1Char('/')+url;
+ // step 1: search for extension with fully encoded version number
+ if (vmaj >= 0 && vmin >= 0) {
+ foreach (const QString &p, database->fileImportPath) {
+ dir = p+QLatin1Char('/')+url;
- QFileInfo fi(dir+QLatin1String("/qmldir"));
- const QString absoluteFilePath = fi.absoluteFilePath();
+ QFileInfo fi(dir+QString(QLatin1String(".%1.%2")).arg(vmaj).arg(vmin)+QLatin1String("/qmldir"));
+ const QString absoluteFilePath = fi.absoluteFilePath();
- if (fi.isFile()) {
- found = true;
+ if (fi.isFile()) {
+ found = true;
- url = QUrl::fromLocalFile(fi.absolutePath()).toString();
- uri = resolvedUri(dir, database);
- if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
- return false;
- break;
+ url = QUrl::fromLocalFile(fi.absolutePath()).toString();
+ uri = resolvedUri(dir, database);
+ if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
+ return false;
+ break;
+ }
+ }
+ }
+ // step 2: search for extension with encoded version major
+ if (vmaj >= 0 && vmin >= 0) {
+ foreach (const QString &p, database->fileImportPath) {
+ dir = p+QLatin1Char('/')+url;
+
+ QFileInfo fi(dir+QString(QLatin1String(".%1")).arg(vmaj)+QLatin1String("/qmldir"));
+ const QString absoluteFilePath = fi.absoluteFilePath();
+
+ if (fi.isFile()) {
+ found = true;
+
+ url = QUrl::fromLocalFile(fi.absolutePath()).toString();
+ uri = resolvedUri(dir, database);
+ if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
+ return false;
+ break;
+ }
+ }
+ }
+ if (!found) {
+ // step 3: search for extension without version number
+
+ foreach (const QString &p, database->fileImportPath) {
+ dir = p+QLatin1Char('/')+url;
+
+ QFileInfo fi(dir+QLatin1String("/qmldir"));
+ const QString absoluteFilePath = fi.absoluteFilePath();
+
+ if (fi.isFile()) {
+ found = true;
+
+ url = QUrl::fromLocalFile(fi.absolutePath()).toString();
+ uri = resolvedUri(dir, database);
+ if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
+ return false;
+ break;
+ }
}
}