Modernize the "filesystemwatcher" feature

Change-Id: If030b56ad97e047d89d442629262b4839df306d4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Liang Qi 2018-09-26 08:56:36 +02:00
parent 5e64957ee4
commit 555a6b5d5d
24 changed files with 79 additions and 106 deletions

View File

@ -84,7 +84,7 @@ FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
QFileInfo info(fragmentSource);
m_fragment_file_last_modified = info.lastModified();
m_fragment_file = fragmentSource;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
m_watcher.addPath(info.canonicalPath());
QObject::connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FragmentToy::fileChanged);
#endif

View File

@ -54,7 +54,9 @@
#include <QObject>
#include <QFile>
#include <QDateTime>
#if QT_CONFIG(filesystemwatcher)
#include <QFileSystemWatcher>
#endif
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
@ -71,7 +73,7 @@ public:
private:
void fileChanged(const QString &path);
bool m_recompile_shaders;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QFileSystemWatcher m_watcher;
#endif
QString m_fragment_file;

View File

@ -38,9 +38,6 @@ HEADERS += \
io/qsettings_p.h \
io/qfsfileengine_p.h \
io/qfsfileengine_iterator_p.h \
io/qfilesystemwatcher.h \
io/qfilesystemwatcher_p.h \
io/qfilesystemwatcher_polling_p.h \
io/qfilesystementry_p.h \
io/qfilesystemengine_p.h \
io/qfilesystemmetadata_p.h \
@ -79,14 +76,38 @@ SOURCES += \
io/qsettings.cpp \
io/qfsfileengine.cpp \
io/qfsfileengine_iterator.cpp \
io/qfilesystemwatcher.cpp \
io/qfilesystemwatcher_polling.cpp \
io/qfilesystementry.cpp \
io/qfilesystemengine.cpp \
io/qfileselector.cpp \
io/qloggingcategory.cpp \
io/qloggingregistry.cpp
qtConfig(filesystemwatcher) {
HEADERS += \
io/qfilesystemwatcher.h \
io/qfilesystemwatcher_p.h \
io/qfilesystemwatcher_polling_p.h
SOURCES += \
io/qfilesystemwatcher.cpp \
io/qfilesystemwatcher_polling.cpp
win32 {
SOURCES += io/qfilesystemwatcher_win.cpp
HEADERS += io/qfilesystemwatcher_win_p.h
} else:macos {
OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm
HEADERS += io/qfilesystemwatcher_fsevents_p.h
} else:qtConfig(inotify) {
SOURCES += io/qfilesystemwatcher_inotify.cpp
HEADERS += io/qfilesystemwatcher_inotify_p.h
} else {
freebsd|darwin|openbsd|netbsd {
SOURCES += io/qfilesystemwatcher_kqueue.cpp
HEADERS += io/qfilesystemwatcher_kqueue_p.h
}
}
}
qtConfig(processenvironment) {
SOURCES += \
io/qprocess.cpp
@ -103,9 +124,6 @@ qtConfig(processenvironment) {
win32 {
SOURCES += io/qfsfileengine_win.cpp
SOURCES += io/qlockfile_win.cpp
SOURCES += io/qfilesystemwatcher_win.cpp
HEADERS += io/qfilesystemwatcher_win_p.h
SOURCES += io/qfilesystemengine_win.cpp
qtConfig(filesystemiterator) {
@ -153,8 +171,6 @@ win32 {
OBJECTIVE_SOURCES += io/qprocess_darwin.mm
OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm
osx {
OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm
HEADERS += io/qfilesystemwatcher_fsevents_p.h
LIBS += -framework DiskArbitration -framework IOKit
} else {
LIBS += -framework MobileCoreServices
@ -173,17 +189,5 @@ win32 {
io/qstandardpaths_unix.cpp \
io/qstorageinfo_unix.cpp
}
linux|if(qnx:qtConfig(inotify)) {
SOURCES += io/qfilesystemwatcher_inotify.cpp
HEADERS += io/qfilesystemwatcher_inotify_p.h
}
!nacl {
freebsd-*|mac|darwin-*|openbsd-*|netbsd-*:{
SOURCES += io/qfilesystemwatcher_kqueue.cpp
HEADERS += io/qfilesystemwatcher_kqueue_p.h
}
}
}

View File

@ -40,8 +40,6 @@
#include "qfilesystemwatcher.h"
#include "qfilesystemwatcher_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include <qdatetime.h>
#include <qdebug.h>
#include <qdir.h>
@ -499,5 +497,3 @@ QT_END_NAMESPACE
#include "moc_qfilesystemwatcher.cpp"
#include "moc_qfilesystemwatcher_p.cpp"
#endif // QT_NO_FILESYSTEMWATCHER

View File

@ -42,7 +42,7 @@
#include <QtCore/qobject.h>
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
QT_BEGIN_NAMESPACE
@ -78,5 +78,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_H

View File

@ -45,8 +45,6 @@
#include "private/qcore_unix_p.h"
#include "kernel/qcore_mac_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include <qdebug.h>
#include <qdir.h>
#include <qfile.h>
@ -585,6 +583,4 @@ bool QFseventsFileSystemWatcherEngine::derefPath(const QString &watchedPath)
return false;
}
#endif //QT_NO_FILESYSTEMWATCHER
QT_END_NAMESPACE

View File

@ -62,7 +62,7 @@
#include <dispatch/dispatch.h>
#include <CoreServices/CoreServices.h>
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
QT_BEGIN_NAMESPACE
@ -150,5 +150,4 @@ private:
QT_END_NAMESPACE
#endif //QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_FSEVENTS_P_H

View File

@ -40,8 +40,6 @@
#include "qfilesystemwatcher.h"
#include "qfilesystemwatcher_inotify_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include "private/qcore_unix_p.h"
#include "private/qsystemerror_p.h"
@ -427,5 +425,3 @@ QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const
QT_END_NAMESPACE
#include "moc_qfilesystemwatcher_inotify_p.cpp"
#endif // QT_NO_FILESYSTEMWATCHER

View File

@ -53,7 +53,7 @@
#include "qfilesystemwatcher_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
@ -89,5 +89,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_INOTIFY_P_H

View File

@ -43,8 +43,6 @@
#include "qfilesystemwatcher_kqueue_p.h"
#include "private/qcore_unix_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include <qdebug.h>
#include <qfile.h>
#include <qsocketnotifier.h>
@ -254,6 +252,4 @@ void QKqueueFileSystemWatcherEngine::readFromKqueue()
}
}
#endif //QT_NO_FILESYSTEMWATCHER
QT_END_NAMESPACE

View File

@ -59,7 +59,7 @@
#include <QtCore/qvector.h>
#include <QtCore/qsocketnotifier.h>
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
struct kevent;
QT_BEGIN_NAMESPACE
@ -90,5 +90,4 @@ private:
QT_END_NAMESPACE
#endif //QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_KQUEUE_P_H

View File

@ -53,7 +53,7 @@
#include "qfilesystemwatcher.h"
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
#include <private/qobject_p.h>
@ -120,5 +120,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_P_H

View File

@ -40,8 +40,6 @@
#include "qfilesystemwatcher_polling_p.h"
#include <QtCore/qtimer.h>
#ifndef QT_NO_FILESYSTEMWATCHER
QT_BEGIN_NAMESPACE
QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent)
@ -153,5 +151,3 @@ void QPollingFileSystemWatcherEngine::timeout()
QT_END_NAMESPACE
#include "moc_qfilesystemwatcher_polling_p.cpp"
#endif // !QT_NO_FILESYSTEMWATCHER

View File

@ -60,7 +60,7 @@
#include "qfilesystemwatcher_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
QT_REQUIRE_CONFIG(filesystemwatcher);
QT_BEGIN_NAMESPACE
enum { PollingInterval = 1000 };
@ -121,6 +121,5 @@ private:
};
QT_END_NAMESPACE
#endif // !QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_POLLING_P_H

View File

@ -40,8 +40,6 @@
#include "qfilesystemwatcher.h"
#include "qfilesystemwatcher_win_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include <qdebug.h>
#include <qfileinfo.h>
#include <qstringlist.h>
@ -757,5 +755,3 @@ QT_END_NAMESPACE
#ifndef Q_OS_WINRT
# include "qfilesystemwatcher_win.moc"
#endif
#endif // QT_NO_FILESYSTEMWATCHER

View File

@ -53,8 +53,6 @@
#include "qfilesystemwatcher_p.h"
#ifndef QT_NO_FILESYSTEMWATCHER
#include <QtCore/qdatetime.h>
#include <QtCore/qthread.h>
#include <QtCore/qfile.h>
@ -175,6 +173,4 @@ Q_SIGNALS:
QT_END_NAMESPACE
#endif // QT_NO_FILESYSTEMWATCHER
#endif // QFILESYSTEMWATCHER_WIN_P_H

View File

@ -112,7 +112,7 @@ QIBusPlatformInputContext::QIBusPlatformInputContext ()
QString socketPath = QIBusPlatformInputContextPrivate::getSocketPath();
QFile file(socketPath);
if (file.open(QFile::ReadOnly)) {
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
qCDebug(qtQpaInputMethods) << "socketWatcher.addPath" << socketPath;
// If KDE session save is used or restart ibus-daemon,
// the applications could run before ibus-daemon runs.
@ -564,7 +564,7 @@ void QIBusPlatformInputContext::connectToBus()
d->initBus();
connectToContextSignals();
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
if (!d->usePortal && m_socketWatcher.files().size() == 0)
m_socketWatcher.addPath(QIBusPlatformInputContextPrivate::getSocketPath());
#endif

View File

@ -44,7 +44,9 @@
#include <QtCore/qpointer.h>
#include <QtCore/QLocale>
#include <QtDBus/qdbuspendingreply.h>
#if QT_CONFIG(filesystemwatcher)
#include <QFileSystemWatcher>
#endif
#include <QTimer>
#include <QWindow>
@ -116,7 +118,7 @@ public Q_SLOTS:
private:
QIBusPlatformInputContextPrivate *d;
bool m_eventFilterUseSynchronousMode;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QFileSystemWatcher m_socketWatcher;
#endif
QTimer m_timer;

View File

@ -80,7 +80,7 @@ static QString translateDriveName(const QFileInfo &drive)
*/
QFileInfoGatherer::QFileInfoGatherer(QObject *parent)
: QThread(parent), abort(false),
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
watcher(0),
#endif
#ifdef Q_OS_WIN
@ -88,7 +88,7 @@ QFileInfoGatherer::QFileInfoGatherer(QObject *parent)
#endif
m_iconProvider(&defaultProvider)
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
watcher = new QFileSystemWatcher(this);
connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString)));
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString)));
@ -179,7 +179,7 @@ void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStr
this->files.push(files);
condition.wakeAll();
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
if (files.isEmpty()
&& !path.isEmpty()
&& !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) {
@ -208,7 +208,7 @@ void QFileInfoGatherer::updateFile(const QString &filePath)
*/
void QFileInfoGatherer::clear()
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QMutexLocker locker(&mutex);
watcher->removePaths(watcher->files());
watcher->removePaths(watcher->directories());
@ -222,7 +222,7 @@ void QFileInfoGatherer::clear()
*/
void QFileInfoGatherer::removePath(const QString &path)
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QMutexLocker locker(&mutex);
watcher->removePath(path);
#else
@ -266,7 +266,7 @@ QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const
QExtendedInformation info(fileInfo);
info.icon = m_iconProvider->icon(fileInfo);
info.displayType = m_iconProvider->type(fileInfo);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
// ### Not ready to listen all modifications by default
static const bool watchFiles = qEnvironmentVariableIsSet("QT_FILESYSTEMMODEL_WATCH_FILES");
if (watchFiles) {
@ -280,7 +280,7 @@ QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const
}
}
}
#endif
#endif // filesystemwatcher
#ifdef Q_OS_WIN
if (m_resolveSymlinks && info.isSymLink(/* ignoreNtfsSymLinks = */ true)) {

View File

@ -56,7 +56,9 @@
#include <qthread.h>
#include <qmutex.h>
#include <qwaitcondition.h>
#if QT_CONFIG(filesystemwatcher)
#include <qfilesystemwatcher.h>
#endif
#include <qfileiconprovider.h>
#include <qpair.h>
#include <qstack.h>
@ -207,7 +209,7 @@ private:
// end protected by mutex
QAtomicInt abort;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QFileSystemWatcher *watcher;
#endif
#ifdef Q_OS_WIN

View File

@ -472,7 +472,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS
return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);
node = p->addNode(parent, element,info);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
node->populate(fileInfoGatherer.getInfo(info));
#endif
} else {
@ -510,7 +510,7 @@ void QFileSystemModel::timerEvent(QTimerEvent *event)
Q_D(QFileSystemModel);
if (event->timerId() == d->fetchingTimer.timerId()) {
d->fetchingTimer.stop();
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
for (int i = 0; i < d->toFetch.count(); ++i) {
const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node;
if (!node->hasInformation()) {
@ -658,7 +658,7 @@ void QFileSystemModel::fetchMore(const QModelIndex &parent)
if (indexNode->populatedChildren)
return;
indexNode->populatedChildren = true;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
d->fileInfoGatherer.list(filePath(parent));
#endif
}
@ -694,13 +694,13 @@ int QFileSystemModel::columnCount(const QModelIndex &parent) const
*/
QVariant QFileSystemModel::myComputer(int role) const
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_D(const QFileSystemModel);
#endif
switch (role) {
case Qt::DisplayRole:
return QFileSystemModelPrivate::myComputer();
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
case Qt::DecorationRole:
return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer);
#endif
@ -737,14 +737,14 @@ QVariant QFileSystemModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
if (index.column() == 0) {
QIcon icon = d->icon(index);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
if (icon.isNull()) {
if (d->node(index)->isDir())
icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder);
else
icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File);
}
#endif // QT_NO_FILESYSTEMWATCHER
#endif // filesystemwatcher
return icon;
}
break;
@ -821,7 +821,7 @@ QString QFileSystemModelPrivate::name(const QModelIndex &index) const
return QString();
QFileSystemNode *dirNode = node(index);
if (
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
fileInfoGatherer.resolveSymlinks() &&
#endif
!resolvedSymLinks.isEmpty() && dirNode->isSymLink(/* ignoreNtfsSymLinks = */ true)) {
@ -923,7 +923,7 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in
QScopedPointer<QFileSystemModelPrivate::QFileSystemNode> nodeToRename(parentNode->children.take(oldName));
nodeToRename->fileName = newName;
nodeToRename->parent = parentNode;
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
nodeToRename->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName)));
#endif
nodeToRename->isVisible = true;
@ -1274,7 +1274,7 @@ QString QFileSystemModel::filePath(const QModelIndex &index) const
QString fullPath = d->filePath(index);
QFileSystemModelPrivate::QFileSystemNode *dirNode = d->node(index);
if (dirNode->isSymLink()
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
&& d->fileInfoGatherer.resolveSymlinks()
#endif
&& d->resolvedSymLinks.contains(fullPath)
@ -1330,7 +1330,7 @@ QModelIndex QFileSystemModel::mkdir(const QModelIndex &parent, const QString &na
d->addNode(parentNode, name, QFileInfo());
Q_ASSERT(parentNode->children.contains(name));
QFileSystemModelPrivate::QFileSystemNode *node = parentNode->children[name];
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name)));
#endif
d->addVisibleFiles(parentNode, QStringList(name));
@ -1394,7 +1394,7 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
//We remove the watcher on the previous path
if (!rootPath().isEmpty() && rootPath() != QLatin1String(".")) {
//This remove the watcher for the old rootPath
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
d->fileInfoGatherer.removePath(rootPath());
#endif
//This line "marks" the node as dirty, so the next fetchMore
@ -1450,7 +1450,7 @@ QDir QFileSystemModel::rootDirectory() const
void QFileSystemModel::setIconProvider(QFileIconProvider *provider)
{
Q_D(QFileSystemModel);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
d->fileInfoGatherer.setIconProvider(provider);
#endif
d->root.updateIcon(provider, QString());
@ -1461,7 +1461,7 @@ void QFileSystemModel::setIconProvider(QFileIconProvider *provider)
*/
QFileIconProvider *QFileSystemModel::iconProvider() const
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_D(const QFileSystemModel);
return d->fileInfoGatherer.iconProvider();
#else
@ -1513,7 +1513,7 @@ QDir::Filters QFileSystemModel::filter() const
*/
void QFileSystemModel::setResolveSymlinks(bool enable)
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_D(QFileSystemModel);
d->fileInfoGatherer.setResolveSymlinks(enable);
#else
@ -1523,7 +1523,7 @@ void QFileSystemModel::setResolveSymlinks(bool enable)
bool QFileSystemModel::resolveSymlinks() const
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_D(const QFileSystemModel);
return d->fileInfoGatherer.resolveSymlinks();
#else
@ -1633,7 +1633,7 @@ QStringList QFileSystemModel::nameFilters() const
*/
bool QFileSystemModel::event(QEvent *event)
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_D(QFileSystemModel);
if (event->type() == QEvent::LanguageChange) {
d->root.retranslateStrings(d->fileInfoGatherer.iconProvider(), QString());
@ -1647,7 +1647,7 @@ bool QFileSystemModel::rmdir(const QModelIndex &aindex)
{
QString path = filePath(aindex);
const bool success = QDir().rmdir(path);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
if (success) {
QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
d->fileInfoGatherer.removePath(path);
@ -1690,7 +1690,7 @@ QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFile
{
// In the common case, itemLocation == count() so check there first
QFileSystemModelPrivate::QFileSystemNode *node = new QFileSystemModelPrivate::QFileSystemNode(fileName, parentNode);
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
node->populate(info);
#else
Q_UNUSED(info)
@ -1798,7 +1798,7 @@ void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int
*/
void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QVector<QPair<QString, QFileInfo> > &updates)
{
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_Q(QFileSystemModel);
QVector<QString> rowsToUpdate;
QStringList newFiles;
@ -1894,7 +1894,7 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QV
#else
Q_UNUSED(path)
Q_UNUSED(updates)
#endif // !QT_NO_FILESYSTEMWATCHER
#endif // filesystemwatcher
}
/*!
@ -1952,7 +1952,7 @@ void QFileSystemModelPrivate::init()
{
Q_Q(QFileSystemModel);
qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >();
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),
q, SLOT(_q_directoryChanged(QString,QStringList)));
q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QVector<QPair<QString,QFileInfo> >)),
@ -1961,7 +1961,7 @@ void QFileSystemModelPrivate::init()
q, SLOT(_q_resolvedName(QString,QString)));
q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)),
q, SIGNAL(directoryLoaded(QString)));
#endif // !QT_NO_FILESYSTEMWATCHER
#endif // filesystemwatcher
q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection);
roleNames.insertMulti(QFileSystemModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration

View File

@ -55,6 +55,9 @@ SUBDIRS=\
win32:!qtConfig(private_tests): SUBDIRS -= \
qfilesystementry
!qtConfig(filesystemwatcher): SUBDIRS -= \
qfilesystemwatcher
!qtConfig(processenvironment): SUBDIRS -= \
qprocessenvironment

View File

@ -45,7 +45,6 @@ class tst_QFileSystemWatcher : public QObject
public:
tst_QFileSystemWatcher();
#ifndef QT_NO_FILESYSTEMWATCHER
private slots:
void basicTest_data();
void basicTest();
@ -77,24 +76,20 @@ private slots:
private:
QString m_tempDirPattern;
#endif // QT_NO_FILESYSTEMWATCHER
};
tst_QFileSystemWatcher::tst_QFileSystemWatcher()
{
#ifndef QT_NO_FILESYSTEMWATCHER
m_tempDirPattern = QDir::tempPath();
if (!m_tempDirPattern.endsWith(QLatin1Char('/')))
m_tempDirPattern += QLatin1Char('/');
m_tempDirPattern += QStringLiteral("tst_qfilesystemwatcherXXXXXX");
#endif // QT_NO_FILESYSTEMWATCHER
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
#endif
}
#ifndef QT_NO_FILESYSTEMWATCHER
void tst_QFileSystemWatcher::basicTest_data()
{
QTest::addColumn<QString>("backend");
@ -805,7 +800,6 @@ void tst_QFileSystemWatcher::watchUnicodeCharacters()
QVERIFY(testDir.mkdir("creme"));
QTRY_COMPARE(changedSpy.count(), 1);
}
#endif // QT_NO_FILESYSTEMWATCHER
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"

View File

@ -2259,7 +2259,7 @@ Q_GLOBAL_STATIC(QLocale, tst_qapp_locale);
#if QT_CONFIG(process)
Q_GLOBAL_STATIC(QProcess, tst_qapp_process);
#endif
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
Q_GLOBAL_STATIC(QFileSystemWatcher, tst_qapp_fileSystemWatcher);
#endif
#ifndef QT_NO_SHAREDMEMORY
@ -2284,7 +2284,7 @@ void tst_QApplication::globalStaticObjectDestruction()
#if QT_CONFIG(process)
QVERIFY(tst_qapp_process());
#endif
#ifndef QT_NO_FILESYSTEMWATCHER
#if QT_CONFIG(filesystemwatcher)
QVERIFY(tst_qapp_fileSystemWatcher());
#endif
#ifndef QT_NO_SHAREDMEMORY