Utils: Introduce FileSystemWatcher.

Remove duplicated classes ProjectExplorer::FileWatcher
and QmlProjectManager::FileSystemWatcher, create
Utils::FileSystemWatcher from them, merging the functionality.

Also use in HelpManager/Maemo, reducing the number
of QFileSystemWatcher instances (and thus, shutdown time).
This commit is contained in:
Friedemann Kleint
2011-04-15 15:55:11 +02:00
parent 72ae03ba80
commit f5cbf87965
19 changed files with 532 additions and 508 deletions

View File

@@ -52,6 +52,7 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <utils/filesystemwatcher.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
@@ -128,20 +129,22 @@ MaemoQemuManager::MaemoQemuManager(QObject *parent)
this, SLOT(qemuStatusChanged(QemuStatus, QString)));
}
QFileSystemWatcher *MaemoQemuManager::runtimeRootWatcher()
Utils::FileSystemWatcher *MaemoQemuManager::runtimeRootWatcher()
{
if (!m_runtimeRootWatcher) {
m_runtimeRootWatcher = new QFileSystemWatcher(this);
m_runtimeRootWatcher = new Utils::FileSystemWatcher(this);
m_runtimeRootWatcher->setObjectName(QLatin1String("MaemoQemuRuntimeRootWatcher"));
connect(m_runtimeRootWatcher, SIGNAL(directoryChanged(QString)), this,
SLOT(runtimeRootChanged(QString)));
}
return m_runtimeRootWatcher;
}
QFileSystemWatcher *MaemoQemuManager::runtimeFolderWatcher()
Utils::FileSystemWatcher *MaemoQemuManager::runtimeFolderWatcher()
{
if (!m_runtimeFolderWatcher) {
m_runtimeFolderWatcher = new QFileSystemWatcher(this);
m_runtimeFolderWatcher = new Utils::FileSystemWatcher(this);
m_runtimeFolderWatcher->setObjectName(QLatin1String("MaemoQemuRuntimeFolderWatcher"));
connect(m_runtimeFolderWatcher, SIGNAL(directoryChanged(QString)), this,
SLOT(runtimeFolderChanged(QString)));
}
@@ -185,8 +188,9 @@ void MaemoQemuManager::qtVersionsChanged(const QList<int> &uniqueIds)
= MaemoQemuRuntimeParser::parseRuntime(version);
if (runtime.isValid()) {
m_runtimes.insert(uniqueId, runtime);
if (!runtimeRootWatcher()->directories().contains(runtime.m_watchPath))
runtimeRootWatcher()->addPath(runtime.m_watchPath);
if (!runtimeRootWatcher()->watchesDirectory(runtime.m_watchPath))
runtimeRootWatcher()->addDirectory(runtime.m_watchPath,
Utils::FileSystemWatcher::WatchAllChanges);
} else {
m_runtimes.remove(uniqueId);
}
@@ -477,7 +481,8 @@ void MaemoQemuManager::runtimeRootChanged(const QString &directory)
if (!QFile::exists(runtime.m_root + QLatin1String("/information"))) {
// install might be still in progress
uniqueIds.removeAll(uniqueId);
runtimeFolderWatcher()->addPath(runtime.m_root);
runtimeFolderWatcher()->addDirectory(runtime.m_root,
Utils::FileSystemWatcher::WatchAllChanges);
}
}
}
@@ -496,7 +501,7 @@ void MaemoQemuManager::runtimeFolderChanged(const QString &directory)
}
notify(uniqueIds);
if (m_runtimeFolderWatcher)
m_runtimeFolderWatcher->removePath(directory);
m_runtimeFolderWatcher->removeDirectory(directory);
}
}

View File

@@ -43,9 +43,12 @@
#include <QtGui/QIcon>
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
QT_FORWARD_DECLARE_CLASS(QStringList)
namespace Utils {
class FileSystemWatcher;
}
namespace ProjectExplorer {
class BuildConfiguration;
class Project;
@@ -123,16 +126,16 @@ private:
private:
QAction *m_qemuAction;
QProcess *m_qemuProcess;
QFileSystemWatcher *runtimeRootWatcher();
QFileSystemWatcher *runtimeFolderWatcher();
Utils::FileSystemWatcher *runtimeRootWatcher();
Utils::FileSystemWatcher *runtimeFolderWatcher();
int m_runningQtId;
bool m_userTerminated;
QIcon m_qemuStarterIcon;
QMap<int, MaemoQemuRuntime> m_runtimes;
static MaemoQemuManager *m_instance;
QFileSystemWatcher *m_runtimeRootWatcher;
QFileSystemWatcher *m_runtimeFolderWatcher;
Utils::FileSystemWatcher *m_runtimeRootWatcher;
Utils::FileSystemWatcher *m_runtimeFolderWatcher;
};
} // namespace Internal

View File

@@ -48,6 +48,8 @@
#include <projectexplorer/toolchain.h>
#include <qt4projectmanager/qt4project.h>
#include <utils/filesystemwatcher.h>
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtCore/QBuffer>
@@ -109,10 +111,11 @@ bool adaptTagValue(QByteArray &document, const QByteArray &fieldName,
AbstractQt4MaemoTarget::AbstractQt4MaemoTarget(Qt4Project *parent, const QString &id) :
Qt4BaseTarget(parent, id),
m_filesWatcher(new QFileSystemWatcher(this)),
m_filesWatcher(new Utils::FileSystemWatcher(this)),
m_buildConfigurationFactory(new Qt4BuildConfigurationFactory(this)),
m_isInitialized(false)
{
m_filesWatcher->setObjectName(QLatin1String("Qt4MaemoTarget"));
setIcon(QIcon(":/projectexplorer/images/MaemoDevice.png"));
connect(parent, SIGNAL(addedTarget(ProjectExplorer::Target*)),
this, SLOT(handleTargetAdded(ProjectExplorer::Target*)));
@@ -692,9 +695,9 @@ void AbstractDebBasedQt4MaemoTarget::handleTargetAddedSpecial()
if (QFileInfo(iconPath).exists())
setPackageManagerIcon(iconPath);
}
m_filesWatcher->addPath(debianDirPath());
m_filesWatcher->addPath(changeLogFilePath());
m_filesWatcher->addPath(controlFilePath());
m_filesWatcher->addDirectory(debianDirPath(), Utils::FileSystemWatcher::WatchAllChanges);
m_filesWatcher->addFile(changeLogFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
m_filesWatcher->addFile(controlFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
connect(m_filesWatcher, SIGNAL(directoryChanged(QString)), this,
SLOT(handleDebianDirContentsChanged()));
connect(m_filesWatcher, SIGNAL(fileChanged(QString)), this,
@@ -1017,7 +1020,7 @@ AbstractQt4MaemoTarget::ActionStatus AbstractRpmBasedQt4MaemoTarget::createSpeci
void AbstractRpmBasedQt4MaemoTarget::handleTargetAddedSpecial()
{
m_filesWatcher->addPath(specFilePath());
m_filesWatcher->addFile(specFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
connect(m_filesWatcher, SIGNAL(fileChanged(QString)), this,
SIGNAL(specFileChanged()));
}

View File

@@ -40,8 +40,10 @@
#include <QtGui/QIcon>
QT_FORWARD_DECLARE_CLASS(QFile)
QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
namespace Utils {
class FileSystemWatcher;
}
namespace Qt4ProjectManager {
class Qt4Project;
namespace Internal {
@@ -92,7 +94,7 @@ protected:
QSharedPointer<QFile> openFile(const QString &filePath,
QIODevice::OpenMode mode, QString *error) const;
QFileSystemWatcher * const m_filesWatcher;
Utils::FileSystemWatcher* const m_filesWatcher;
private slots:
void handleTargetAdded(ProjectExplorer::Target *target);