aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp17
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp52
2 files changed, 65 insertions, 4 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
index 409c2563f1..1cffa44c66 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
@@ -83,6 +83,8 @@ public:
void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list);
void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex);
void _q_sortFinished(const QList<FileProperty> &list);
+
+ static QString resolvePath(const QUrl &path);
};
@@ -195,6 +197,15 @@ void QQuickFolderListModelPrivate::_q_sortFinished(const QList<FileProperty> &li
q->endInsertRows();
}
+QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
+{
+ QString localPath = QQmlFile::urlToLocalFileOrQrc(path);
+ QUrl localUrl = QUrl(localPath);
+ QString fullPath = localUrl.path();
+ if (localUrl.scheme().length())
+ fullPath = localUrl.scheme() + ":" + fullPath;
+ return QDir::cleanPath(fullPath);
+}
/*!
\qmltype FolderListModel
@@ -370,8 +381,7 @@ void QQuickFolderListModel::setFolder(const QUrl &folder)
if (folder == d->currentDir)
return;
- QString localPath = QQmlFile::urlToLocalFileOrQrc(folder);
- QString resolvedPath = QDir::cleanPath(QUrl(localPath).path());
+ QString resolvedPath = QQuickFolderListModelPrivate::resolvePath(folder);
beginResetModel();
@@ -413,8 +423,7 @@ void QQuickFolderListModel::setRootFolder(const QUrl &path)
if (path.isEmpty())
return;
- QString localPath = QQmlFile::urlToLocalFileOrQrc(path);
- QString resolvedPath = QDir::cleanPath(QUrl(localPath).path());
+ QString resolvedPath = QQuickFolderListModelPrivate::resolvePath(path);
QFileInfo info(resolvedPath);
if (!info.exists() || !info.isDir())
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
index 804bd1a813..b574ef799b 100644
--- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
+++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
@@ -48,6 +48,10 @@
#include <QDebug>
#include "../../shared/util.h"
+#if defined (Q_OS_WIN)
+#include <qt_windows.h>
+#endif
+
// From qquickfolderlistmodel.h
const int FileNameRole = Qt::UserRole+1;
const int FilePathRole = Qt::UserRole+2;
@@ -69,6 +73,9 @@ private slots:
void basicProperties();
void resetFiltering();
void refresh();
+#if defined (Q_OS_WIN)
+ void changeDrive();
+#endif
private:
void checkNoErrors(const QQmlComponent& component);
@@ -174,6 +181,51 @@ void tst_qquickfolderlistmodel::refresh()
QTRY_COMPARE(removeEnd, count-1); // wait for refresh
}
+#if defined (Q_OS_WIN)
+void tst_qquickfolderlistmodel::changeDrive()
+{
+ class DriveMapper
+ {
+ public:
+ DriveMapper(const QString &dataDir)
+ {
+ size_t stringLen = dataDir.length();
+ targetPath = new wchar_t[stringLen+1];
+ dataDir.toWCharArray(targetPath);
+ targetPath[stringLen] = 0;
+
+ DefineDosDevice(DDD_NO_BROADCAST_SYSTEM, L"X:", targetPath);
+ }
+
+ ~DriveMapper()
+ {
+ DefineDosDevice(DDD_EXACT_MATCH_ON_REMOVE | DDD_NO_BROADCAST_SYSTEM | DDD_REMOVE_DEFINITION, L"X:", targetPath);
+ delete [] targetPath;
+ }
+
+ private:
+ wchar_t *targetPath;
+ };
+
+ QString dataDir = testFile(0);
+ DriveMapper dm(dataDir);
+ QQmlComponent component(&engine, testFileUrl("basic.qml"));
+
+ QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
+ QVERIFY(flm != 0);
+
+ QSignalSpy folderChangeSpy(flm, SIGNAL(folderChanged()));
+
+ flm->setProperty("folder",QUrl::fromLocalFile(dataDir));
+ QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(dataDir));
+ QTRY_VERIFY(folderChangeSpy.count() == 1);
+
+ flm->setProperty("folder",QUrl::fromLocalFile("X:/resetfiltering/"));
+ QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile("X:/resetfiltering/"));
+ QTRY_VERIFY(folderChangeSpy.count() == 2);
+}
+#endif
+
QTEST_MAIN(tst_qquickfolderlistmodel)
#include "tst_qquickfolderlistmodel.moc"