From a62fbc821c3c32c0ebe63a77f2705d6f1db67394 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 16 Nov 2009 15:28:35 +1000 Subject: Use QDir::separator() and follow no-trailing-slash convention. Fixes QTBUG-5841 --- src/declarative/qml/qmlengine.cpp | 15 ++++++++------- src/declarative/qml/qmlsqldatabase.cpp | 3 ++- tests/auto/declarative/qmlengine/tst_qmlengine.cpp | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 66d4990..c8848fd 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -112,11 +112,6 @@ struct StaticQtMetaObject : public QObject { return &static_cast (0)->staticQtMetaObject; } }; -static QString userLocalDataPath(const QString& app) -{ - return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/") + app; -} - QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0), @@ -130,7 +125,9 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) scriptEngine.newQMetaObject(StaticQtMetaObject::get()); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); - offlineStoragePath = userLocalDataPath(QLatin1String("QML/OfflineStorage")); + offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + + QDir::separator() + QLatin1String("QML") + + QDir::separator() + QLatin1String("OfflineStorage"); qt_add_qmlxmlhttprequest(&scriptEngine); qt_add_qmlsqldatabase(&scriptEngine); @@ -1265,8 +1262,12 @@ void QmlEngine::addImportPath(const QString& path) QmlGraphicsWebView and the SQL databases created with openDatabase() are stored here. - The default is QML/OfflineStorage/ in the platform-standard + The default is QML/OfflineStorage in the platform-standard user application data directory. + + Note that the path may not currently exist on the filesystem, so + callers wanting to \e create new files at this location should create + it first - see QDir::mkpath(). */ void QmlEngine::setOfflineStoragePath(const QString& dir) { diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index c7d2e12..330d904 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -337,7 +337,8 @@ static QScriptValue qmlsqldatabase_open(QScriptContext *context, QScriptEngine * database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); } if (!database.isOpen()) { - QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + QLatin1String("/Databases/"); + QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + + QDir::separator() + QLatin1String("Databases") + QDir::separator(); QDir().mkpath(basename); basename += dbid; database.setDatabaseName(basename+QLatin1String(".sqlite")); diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp index ef1eee5..e060e7f 100644 --- a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -159,10 +159,18 @@ void tst_qmlengine::contextForObject() void tst_qmlengine::offlineStoragePath() { + // Without these set, QDesktopServices::storageLocation returns + // strings with extra "//" at the end. We set them to ignore this problem. + qApp->setApplicationName("tst_qmlengine"); + qApp->setOrganizationName("Nokia"); + qApp->setOrganizationDomain("nokia.com"); + QmlEngine engine; QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); + dir.mkpath("QML"); dir.cd("QML"); + dir.mkpath("OfflineStorage"); dir.cd("OfflineStorage"); QCOMPARE(engine.offlineStoragePath(), dir.path()); -- cgit v0.12