Skip to content
Snippets Groups Projects
Commit 4a098509 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

FileWatcher: Use Utils::FileSystemWatcher in Core::FileManager.

for everything except links on UNIX, further reducing shutdown time.
parent d81b039e
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/reloadpromptutils.h> #include <utils/reloadpromptutils.h>
#include <utils/filesystemwatcher.h>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
...@@ -113,8 +114,9 @@ struct FileState ...@@ -113,8 +114,9 @@ struct FileState
struct FileManagerPrivate { struct FileManagerPrivate {
explicit FileManagerPrivate(FileManager *q, QMainWindow *mw); explicit FileManagerPrivate(FileManager *q, QMainWindow *mw);
QFileSystemWatcher *fileWatcher();
QFileSystemWatcher *linkWatcher(); void watchFile(const QString &f);
void watchLink(const QString &f);
static FileManager *m_instance; static FileManager *m_instance;
QMap<QString, FileState> m_states; QMap<QString, FileState> m_states;
...@@ -129,7 +131,7 @@ struct FileManagerPrivate { ...@@ -129,7 +131,7 @@ struct FileManagerPrivate {
QString m_currentFile; QString m_currentFile;
QMainWindow *m_mainWindow; QMainWindow *m_mainWindow;
QFileSystemWatcher *m_fileWatcher; // Delayed creation. Utils::FileSystemWatcher *m_fileWatcher; // Delayed creation.
QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen). QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen).
bool m_blockActivated; bool m_blockActivated;
QString m_lastVisitedDirectory; QString m_lastVisitedDirectory;
...@@ -142,28 +144,30 @@ struct FileManagerPrivate { ...@@ -142,28 +144,30 @@ struct FileManagerPrivate {
IFile *m_blockedIFile; IFile *m_blockedIFile;
}; };
QFileSystemWatcher *FileManagerPrivate::fileWatcher() void FileManagerPrivate::watchFile(const QString &f)
{ {
if (!m_fileWatcher) { if (!m_fileWatcher) {
m_fileWatcher= new QFileSystemWatcher(m_instance); m_fileWatcher = new Utils::FileSystemWatcher(m_instance);
m_fileWatcher->setObjectName(QLatin1String("FileManagerWatcher"));
QObject::connect(m_fileWatcher, SIGNAL(fileChanged(QString)), QObject::connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
m_instance, SLOT(changedFile(QString))); m_instance, SLOT(changedFile(QString)));
} }
return m_fileWatcher; m_fileWatcher->addFile(f, Utils::FileSystemWatcher::WatchAllChanges);
} }
QFileSystemWatcher *FileManagerPrivate::linkWatcher() void FileManagerPrivate::watchLink(const QString &f)
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
if (!m_linkWatcher) { if (!m_linkWatcher) {
// Use a different file watcher engine for links on UNIX
m_linkWatcher = new QFileSystemWatcher(m_instance); m_linkWatcher = new QFileSystemWatcher(m_instance);
m_linkWatcher->setObjectName(QLatin1String("_qt_autotest_force_engine_poller")); m_linkWatcher->setObjectName(QLatin1String("_qt_autotest_force_engine_poller"));
QObject::connect(m_linkWatcher, SIGNAL(fileChanged(QString)), QObject::connect(m_linkWatcher, SIGNAL(fileChanged(QString)),
m_instance, SLOT(changedFile(QString))); m_instance, SLOT(changedFile(QString)));
} }
return m_linkWatcher; m_linkWatcher->addPath(f);
#else #else
return fileWatcher(); watchFile(f);
#endif #endif
} }
...@@ -266,9 +270,9 @@ void FileManager::addFileInfo(const QString &fileName, IFile *file, bool isLink) ...@@ -266,9 +270,9 @@ void FileManager::addFileInfo(const QString &fileName, IFile *file, bool isLink)
d->m_states.insert(fileName, Internal::FileState()); d->m_states.insert(fileName, Internal::FileState());
if (isLink) if (isLink)
d->linkWatcher()->addPath(fileName); d->watchLink(fileName);
else else
d->fileWatcher()->addPath(fileName); d->watchFile(fileName);
} }
d->m_states[fileName].lastUpdatedState.insert(file, state); d->m_states[fileName].lastUpdatedState.insert(file, state);
} }
...@@ -371,8 +375,8 @@ void FileManager::removeFileInfo(IFile *file) ...@@ -371,8 +375,8 @@ void FileManager::removeFileInfo(IFile *file)
continue; continue;
d->m_states[fileName].lastUpdatedState.remove(file); d->m_states[fileName].lastUpdatedState.remove(file);
if (d->m_states.value(fileName).lastUpdatedState.isEmpty()) { if (d->m_states.value(fileName).lastUpdatedState.isEmpty()) {
if (d->m_fileWatcher && d->m_fileWatcher->files().contains(fileName)) if (d->m_fileWatcher && d->m_fileWatcher->watchesFile(fileName))
d->m_fileWatcher->removePath(fileName); d->m_fileWatcher->removeFile(fileName);
if (d->m_linkWatcher && d->m_linkWatcher->files().contains(fileName)) if (d->m_linkWatcher && d->m_linkWatcher->files().contains(fileName))
d->m_linkWatcher->removePath(fileName); d->m_linkWatcher->removePath(fileName);
d->m_states.remove(fileName); d->m_states.remove(fileName);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment