summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-10-06 02:16:48 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-10-06 02:16:48 (GMT)
commit47db21ecd772a980e0a4a5f91c63cdffafdff8c0 (patch)
treeb4ded96de3be27e7b73baaf04c0955a85d3c47f4
parent8ca8d4b8b234d6d57e9f963d3c1e7f7522bcaf98 (diff)
downloadQt-47db21ecd772a980e0a4a5f91c63cdffafdff8c0.zip
Qt-47db21ecd772a980e0a4a5f91c63cdffafdff8c0.tar.gz
Qt-47db21ecd772a980e0a4a5f91c63cdffafdff8c0.tar.bz2
Use QDesktopServices::storageLocation() in place of placeform-specific code.
-rw-r--r--src/declarative/qml/qmlengine.cpp42
-rw-r--r--tests/auto/declarative/sql/tst_sql.cpp27
2 files changed, 24 insertions, 45 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 72603ed..f34d790 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -114,43 +114,9 @@ QScriptValue desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e)
return e->newVariant(QVariant(ret));
}
-// XXX Something like this should be exported by Qt.
static QString userLocalDataPath(const QString& app)
{
- QString result;
-
-#ifdef Q_OS_WIN
-#ifndef Q_OS_WINCE
- QLibrary library(QLatin1String("shell32"));
-#else
- QLibrary library(QLatin1String("coredll"));
-#endif // Q_OS_WINCE
- typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
- GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
- if (SHGetSpecialFolderPath) {
- wchar_t path[MAX_PATH];
- SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE);
- result = QString::fromWCharArray(path);
- }
-#endif // Q_OS_WIN
-
-#ifdef Q_OS_MAC
- result = QLatin1String(qgetenv("HOME"));
- result += "/Library/Application Support";
-#else
- if (result.isEmpty()) {
- // Fallback: UNIX style
- result = QLatin1String(qgetenv("XDG_DATA_HOME"));
- if (result.isEmpty()) {
- result = QLatin1String(qgetenv("HOME"));
- result += QLatin1String("/.local/share");
- }
- }
-#endif
-
- result += QLatin1Char('/');
- result += app;
- return result;
+ return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/") + app;
}
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
@@ -166,7 +132,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
qtObject.setProperty(QLatin1String("DesktopServices"), desktopObject);
scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject);
- offlineStoragePath = userLocalDataPath(QLatin1String("Nokia/Qt/QML/OfflineStorage"));
+ offlineStoragePath = userLocalDataPath(QLatin1String("QML/OfflineStorage"));
qt_add_qmlxmlhttprequest(&scriptEngine);
qt_add_qmlsqldatabase(&scriptEngine);
@@ -1602,7 +1568,7 @@ public:
if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return))
return true;
if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) {
- *url_return = QUrl(s->urls[0]+"/").resolved(QUrl(QLatin1String(unqualifiedtype + ".qml")));
+ *url_return = QUrl(s->urls[0]+QLatin1String("/")).resolved(QUrl(QLatin1String(unqualifiedtype + ".qml")));
return true;
}
}
@@ -1697,7 +1663,7 @@ void QmlEngine::addImportPath(const QString& path)
QFxWebView and the SQL databases created with openDatabase()
are stored here.
- The default is Nokia/Qt/QML/Databases/ in the platform-standard
+ The default is QML/OfflineStorage/ in the platform-standard
user application data directory.
*/
void QmlEngine::setOfflineStoragePath(const QString& dir)
diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp
index 10ce6d8..22e9ba4 100644
--- a/tests/auto/declarative/sql/tst_sql.cpp
+++ b/tests/auto/declarative/sql/tst_sql.cpp
@@ -14,7 +14,18 @@ class tst_sql : public QObject
{
Q_OBJECT
public:
- tst_sql() {}
+ tst_sql()
+ {
+ qApp->setApplicationName("tst_sql");
+ qApp->setOrganizationName("Nokia");
+ qApp->setOrganizationDomain("nokia.com");
+ engine = new QmlEngine;
+ }
+
+ ~tst_sql()
+ {
+ delete engine;
+ }
private slots:
void initTestCase();
@@ -31,7 +42,7 @@ private slots:
private:
QString dbDir() const;
- QmlEngine engine;
+ QmlEngine *engine;
};
class QWebPageWithJavaScriptConsoleMessages : public QWebPage {
@@ -67,14 +78,16 @@ void tst_sql::cleanupTestCase()
QString tst_sql::dbDir() const
{
- return QString(SRCDIR)+"/output";
+ static QString tmpd = QDir::tempPath()+"/tst_sql_output-"
+ + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss"));
+ return tmpd;
}
void tst_sql::checkDatabasePath()
{
// Check default storage path (we can't use it since we don't want to mess with user's data)
- QVERIFY(engine.offlineStoragePath().contains("Nokia"));
- QVERIFY(engine.offlineStoragePath().contains("OfflineStorage"));
+ QVERIFY(engine->offlineStoragePath().contains("Nokia"));
+ QVERIFY(engine->offlineStoragePath().contains("OfflineStorage"));
}
void tst_sql::testQml_data()
@@ -142,8 +155,8 @@ void tst_sql::testQml()
"import Qt 4.6\n"
"Text { Script { source: \""+jsfile+"\" } text: test() }";
- engine.setOfflineStoragePath(dbDir());
- QmlComponent component(&engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports
+ engine->setOfflineStoragePath(dbDir());
+ QmlComponent component(engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports
QFxText *text = qobject_cast<QFxText*>(component.create());
QVERIFY(text != 0);
QCOMPARE(text->text(),result);