diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-05-24 11:15:16 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-10-27 06:23:00 +0000 |
commit | 8e79806d08ab77aa0f87b69a2ef65789216f41c0 (patch) | |
tree | 060ed8daa47066863769f087164041fa97604314 /src/widgets | |
parent | 41b27047eaf385cd99d2f064be27ef99bc476d34 (diff) | |
download | qtbase-8e79806d08ab77aa0f87b69a2ef65789216f41c0.tar.gz |
QFileInfoGatherer/Win32: Connect to drive arrival/removal signals of watcher
Retrieve instance of QWindowsRemovableDriveListener via dynamic property
of QFileSystemWatcher and connect to its signals to add/remove drives.
Task-number: QTBUG-18729
Task-number: QTBUG-14290
Change-Id: I603a6f99aca8e6fb3e28d4bc997d8e49d7d0a7c8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dialogs/qfileinfogatherer.cpp | 48 | ||||
-rw-r--r-- | src/widgets/dialogs/qfileinfogatherer_p.h | 4 |
2 files changed, 40 insertions, 12 deletions
diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp index 6df020dd58..08c5a40c7c 100644 --- a/src/widgets/dialogs/qfileinfogatherer.cpp +++ b/src/widgets/dialogs/qfileinfogatherer.cpp @@ -65,6 +65,18 @@ Q_AUTOTEST_EXPORT bool qt_test_isFetchedRoot() } #endif +static QString translateDriveName(const QFileInfo &drive) +{ + QString driveName = drive.absoluteFilePath(); +#ifdef Q_OS_WIN + if (driveName.startsWith(QLatin1Char('/'))) // UNC host + return drive.fileName(); + if (driveName.endsWith(QLatin1Char('/'))) + driveName.chop(1); +#endif // Q_OS_WIN + return driveName; +} + /*! Creates thread */ @@ -82,6 +94,16 @@ QFileInfoGatherer::QFileInfoGatherer(QObject *parent) watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString))); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString))); + +# if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + const QVariant listener = watcher->property("_q_driveListener"); + if (listener.canConvert<QObject *>()) { + if (QObject *driveListener = listener.value<QObject *>()) { + connect(driveListener, SIGNAL(driveAdded()), this, SLOT(driveAdded())); + connect(driveListener, SIGNAL(driveRemoved(QString)), this, SLOT(driveRemoved())); + } + } +# endif // Q_OS_WIN && !Q_OS_WINRT #endif start(LowPriority); } @@ -106,6 +128,20 @@ void QFileInfoGatherer::setResolveSymlinks(bool enable) #endif } +void QFileInfoGatherer::driveAdded() +{ + fetchExtendedInformation(QString(), QStringList()); +} + +void QFileInfoGatherer::driveRemoved() +{ + QStringList drives; + const QFileInfoList driveInfoList = QDir::drives(); + for (const QFileInfo &fi : driveInfoList) + drives.append(translateDriveName(fi)); + newListOfFiles(QString(), drives); +} + bool QFileInfoGatherer::resolveSymlinks() const { #ifdef Q_OS_WIN @@ -260,18 +296,6 @@ QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const return info; } -static QString translateDriveName(const QFileInfo &drive) -{ - QString driveName = drive.absoluteFilePath(); -#if defined(Q_OS_WIN) - if (driveName.startsWith(QLatin1Char('/'))) // UNC host - return drive.fileName(); - if (driveName.endsWith(QLatin1Char('/'))) - driveName.chop(1); -#endif - return driveName; -} - /* Get specific file info's, batch the files so update when we have 100 items and every 200ms after that diff --git a/src/widgets/dialogs/qfileinfogatherer_p.h b/src/widgets/dialogs/qfileinfogatherer_p.h index 3186e9d015..0018b6c387 100644 --- a/src/widgets/dialogs/qfileinfogatherer_p.h +++ b/src/widgets/dialogs/qfileinfogatherer_p.h @@ -180,6 +180,10 @@ public Q_SLOTS: void setResolveSymlinks(bool enable); void setIconProvider(QFileIconProvider *provider); +private Q_SLOTS: + void driveAdded(); + void driveRemoved(); + private: void run() Q_DECL_OVERRIDE; // called by run(): |