From fa46fa236b5f4a9a5677da2e7464a6b9f8b7b5f3 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Wed, 12 May 2010 14:41:49 +0200 Subject: make QFileSystemModel distinguish C: from C:\ Since QFileSystemModel just uses a C: to represent C:\ for esthetics, we now need to append a slash to make sure we do not accidently point to the current working directory on C:\. Reviewed-by: Joao Task-number: QTBUG-8241 --- src/gui/dialogs/qfilesystemmodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 8a6190f..e5a8445 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -1290,6 +1290,10 @@ QString QFileSystemModelPrivate::filePath(const QModelIndex &index) const if ((fullPath.length() > 2) && fullPath[0] == QLatin1Char('/') && fullPath[1] == QLatin1Char('/')) fullPath = fullPath.mid(1); #endif +#if defined(Q_OS_WIN) + if (fullPath.length() == 2 && fullPath.endsWith(QLatin1Char(':'))) + fullPath.append(QLatin1Char('/')); +#endif return fullPath; } -- cgit v0.12 From 5658fac923b419df1f9a95f01b2a5c76737004b2 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Wed, 26 May 2010 13:15:41 +0200 Subject: make QFileSystemWatcher_win distinguish C: from C:\ Since we now support this in QFileInfo, we also need to support this in QFileSystemWatcher. Otherwise the changes in a watched root folder would not get detected. Reviewed-by: Joao Task-number: QTBUG-8241 --- src/corelib/io/qfilesystemwatcher_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 249ce0f..71df3c2 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -86,7 +86,8 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, while (it.hasNext()) { QString path = it.next(); QString normalPath = path; - if ((normalPath.endsWith(QLatin1Char('/')) || normalPath.endsWith(QLatin1Char('\\'))) + if ((normalPath.endsWith(QLatin1Char('/')) && !normalPath.endsWith(QLatin1String(":/"))) + || (normalPath.endsWith(QLatin1Char('\\')) && !normalPath.endsWith(QLatin1String(":\\"))) #ifdef Q_OS_WINCE && normalPath.size() > 1) #else -- cgit v0.12 From 83ad5ebb033799352723a9d968b31a9cef61396c Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Wed, 12 May 2010 14:41:49 +0200 Subject: make QFileSystemModel::rmdir(dir) remove dir from fileInfoGatherer Otherwise directories cannot be deleted as long as they are watched, since the fileInfoGatherer keeps a QFileInfo object with open file handles. Reviewed-by: Joao Task-number: QTBUG-8241 --- src/gui/dialogs/qfilesystemmodel.cpp | 8 ++++++++ src/gui/dialogs/qfilesystemmodel.h | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index e5a8445..b8aafe3 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -1612,6 +1612,14 @@ bool QFileSystemModel::event(QEvent *event) return QAbstractItemModel::event(event); } +bool QFileSystemModel::rmdir(const QModelIndex &aindex) const +{ + QString path = filePath(aindex); + QFileSystemModelPrivate * d = const_cast(d_func()); + d->fileInfoGatherer.removePath(path); + return QDir().rmdir(path); +} + /*! \internal diff --git a/src/gui/dialogs/qfilesystemmodel.h b/src/gui/dialogs/qfilesystemmodel.h index d8178c7..741f22b 100644 --- a/src/gui/dialogs/qfilesystemmodel.h +++ b/src/gui/dialogs/qfilesystemmodel.h @@ -139,7 +139,7 @@ public: QDateTime lastModified(const QModelIndex &index) const; QModelIndex mkdir(const QModelIndex &parent, const QString &name); - inline bool rmdir(const QModelIndex &index) const; + bool rmdir(const QModelIndex &index) const; // ### Qt5: should not be const inline QString fileName(const QModelIndex &index) const; inline QIcon fileIcon(const QModelIndex &index) const; QFile::Permissions permissions(const QModelIndex &index) const; @@ -163,8 +163,6 @@ private: friend class QFileDialogPrivate; }; -inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const -{ QDir dir; return dir.rmdir(filePath(aindex)); } inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const { return aindex.data(Qt::DisplayRole).toString(); } inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const -- cgit v0.12 From 3ce123a89cf9b8dfcf4ecb1a4e3f8c2ff5121c45 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 28 May 2010 13:01:59 +0200 Subject: fix for tst_qfiledialog2 to distinguish between C: and C:/ This fix is needed because the qfiledialog uses just "C:" to display the drive entry. But "C:" in fact does not point to the drive root necessarily. Therfor qfiledialog now appends a slash, but the unit test did not expect that. Reviewed-by: TrustMe --- tests/auto/qfiledialog2/tst_qfiledialog2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp index eee495f..9a96130 100644 --- a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp @@ -547,7 +547,7 @@ void tst_QFileDialog2::task226366_lowerCaseHardDriveWindows() QTest::qWait(200); QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); QTest::qWait(200); - QCOMPARE(edit->text(), QString("C:")); + QCOMPARE(edit->text(), QString("C:/")); QTest::qWait(2000); //i clear my previous selection in the completer QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); @@ -555,7 +555,7 @@ void tst_QFileDialog2::task226366_lowerCaseHardDriveWindows() QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT)); QTest::qWait(200); QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - QCOMPARE(edit->text(), QString("C:")); + QCOMPARE(edit->text(), QString("C:/")); } #endif -- cgit v0.12