diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2011-04-15 15:55:11 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2011-04-15 15:55:11 +0200 |
commit | f5cbf879654aa297fe7c43ade21d6b317952190d (patch) | |
tree | 0bcf6dd91a365f43d9e9db056a0dbb2dfcb73c7f /src/plugins | |
parent | 72ae03ba808157f48b769cd04a9aa7ed48342be3 (diff) | |
download | qt-creator-f5cbf879654aa297fe7c43ade21d6b317952190d.tar.gz |
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).
Diffstat (limited to 'src/plugins')
17 files changed, 104 insertions, 580 deletions
diff --git a/src/plugins/coreplugin/helpmanager.cpp b/src/plugins/coreplugin/helpmanager.cpp index ae53d2d47e..7a01ce326c 100644 --- a/src/plugins/coreplugin/helpmanager.cpp +++ b/src/plugins/coreplugin/helpmanager.cpp @@ -32,13 +32,13 @@ #include "helpmanager.h" -#include "icore.h" +#include <coreplugin/icore.h> +#include <utils/filesystemwatcher.h> #include <QtCore/QDateTime> #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFileInfo> -#include <QtCore/QFileSystemWatcher> #include <QtCore/QStringList> #include <QtHelp/QHelpEngineCore> @@ -58,7 +58,7 @@ struct HelpManagerPrivate { bool m_needsSetup; QHelpEngineCore *m_helpEngine; - QFileSystemWatcher *m_collectionWatcher; + Utils::FileSystemWatcher *m_collectionWatcher; QStringList m_filesToRegister; QStringList m_nameSpacesToUnregister; @@ -429,8 +429,9 @@ void HelpManager::setupHelpManager() for (it = d->m_customValues.constBegin(); it != d->m_customValues.constEnd(); ++it) setCustomValue(it.key(), it.value()); - d->m_collectionWatcher = new QFileSystemWatcher(QStringList() << collectionFilePath(), - this); + d->m_collectionWatcher = new Utils::FileSystemWatcher(this); + d->m_collectionWatcher->setObjectName(QLatin1String("HelpCollectionWatcher")); + d->m_collectionWatcher->addFile(collectionFilePath(), Utils::FileSystemWatcher::WatchAllChanges); connect(d->m_collectionWatcher, SIGNAL(fileChanged(QString)), this, SLOT(collectionFileModified())); diff --git a/src/plugins/projectexplorer/filewatcher.cpp b/src/plugins/projectexplorer/filewatcher.cpp deleted file mode 100644 index 96a0bc2d4d..0000000000 --- a/src/plugins/projectexplorer/filewatcher.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "filewatcher.h" - -#include <QtCore/QDebug> -#include <QtCore/QDir> -#include <QtCore/QFileInfo> -#include <QtCore/QFileSystemWatcher> -#include <QtCore/QTimer> - -enum { debugWatcher = 0 }; - -using namespace ProjectExplorer; - -int FileWatcher::m_objectCount = 0; -QHash<QString,int> FileWatcher::m_fileCount; -QFileSystemWatcher *FileWatcher::m_watcher = 0; - -FileWatcher::FileWatcher(QObject *parent) : - QObject(parent) -{ - if (!m_watcher) - m_watcher = new QFileSystemWatcher(); - ++m_objectCount; - connect(m_watcher, SIGNAL(fileChanged(QString)), - this, SLOT(slotFileChanged(QString))); -} - -FileWatcher::~FileWatcher() -{ - QStringList keys = m_files.keys(); - foreach(const QString &file, keys) - removeFile(file); - - if (--m_objectCount == 0) { - delete m_watcher; - m_watcher = 0; - } -} - -void FileWatcher::slotFileChanged(const QString &file) -{ - if (m_files.contains(file)) { - QDateTime lastModified = QFileInfo(file).lastModified(); - if (lastModified != m_files.value(file)) { - m_files[file] = lastModified; - emit fileChanged(file); - } - } -} - -void FileWatcher::addFile(const QString &file) -{ - const int count = ++m_fileCount[file]; - Q_ASSERT(count > 0); - - m_files.insert(file, QFileInfo(file).lastModified()); - - if (count == 1) - m_watcher->addPath(file); -} - -void FileWatcher::removeFile(const QString &file) -{ - if (!m_files.contains(file)) - return; - - const int count = --m_fileCount[file]; - Q_ASSERT(count >= 0); - - m_files.remove(file); - - if (!count) { - m_watcher->removePath(file); - m_fileCount.remove(file); - } -} diff --git a/src/plugins/projectexplorer/filewatcher.h b/src/plugins/projectexplorer/filewatcher.h deleted file mode 100644 index e5fcedb28d..0000000000 --- a/src/plugins/projectexplorer/filewatcher.h +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef FILEWATCHER_H -#define FILEWATCHER_H - -#include "projectexplorer_export.h" - -#include <QtCore/QDateTime> -#include <QtCore/QHash> -#include <QtCore/QObject> -#include <QtCore/QStringList> -#include <QtCore/QMap> - -QT_BEGIN_NAMESPACE -class QFileSystemWatcher; -QT_END_NAMESPACE - -namespace ProjectExplorer { - -class PROJECTEXPLORER_EXPORT FileWatcher : public QObject -{ - Q_DISABLE_COPY(FileWatcher) - Q_OBJECT -public: - explicit FileWatcher(QObject *parent = 0); - virtual ~FileWatcher(); - - void addFile(const QString &file); - void removeFile(const QString &file); -signals: - void fileChanged(const QString &path); - void debugOutout(const QString &path); - -private slots: - void slotFileChanged(const QString&); - -private: - static int m_objectCount; - static QHash<QString, int> m_fileCount; - static QFileSystemWatcher *m_watcher; - QMap<QString, QDateTime> m_files; -}; - -} // namespace ProjectExplorer - -#endif // FILEWATCHER_H diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 6adc7b80e8..7b77b27f8f 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -77,7 +77,6 @@ HEADERS += projectexplorer.h \ userfileaccessor.h \ cesdkhandler.h \ gccparser.h \ - filewatcher.h \ debugginghelper.h \ projectexplorersettingspage.h \ projectwelcomepage.h \ @@ -168,7 +167,6 @@ SOURCES += projectexplorer.cpp \ cesdkhandler.cpp \ userfileaccessor.cpp \ gccparser.cpp \ - filewatcher.cpp \ debugginghelper.cpp \ projectexplorersettingspage.cpp \ projectwelcomepage.cpp \ diff --git a/src/plugins/qmljstools/qmljsplugindumper.cpp b/src/plugins/qmljstools/qmljsplugindumper.cpp index 8e1c5f2113..ba4ce8a6ab 100644 --- a/src/plugins/qmljstools/qmljsplugindumper.cpp +++ b/src/plugins/qmljstools/qmljsplugindumper.cpp @@ -35,9 +35,9 @@ #include <qmljs/qmljsdocument.h> #include <qmljs/qmljsinterpreter.h> -#include <projectexplorer/filewatcher.h> #include <projectexplorer/projectexplorer.h> #include <coreplugin/messagemanager.h> +#include <utils/filesystemwatcher.h> #include <QtCore/QDir> @@ -49,9 +49,19 @@ using namespace QmlJSTools::Internal; PluginDumper::PluginDumper(ModelManager *modelManager) : QObject(modelManager) , m_modelManager(modelManager) - , m_pluginWatcher(new ProjectExplorer::FileWatcher(this)) + , m_pluginWatcher(0) { - connect(m_pluginWatcher, SIGNAL(fileChanged(QString)), SLOT(pluginChanged(QString))); +} + +Utils::FileSystemWatcher *PluginDumper::pluginWatcher() +{ + if (!m_pluginWatcher) { + m_pluginWatcher = new Utils::FileSystemWatcher(this); + m_pluginWatcher->setObjectName(QLatin1String("PluginDumperWatcher")); + connect(m_pluginWatcher, SIGNAL(fileChanged(QString)), + this, SLOT(pluginChanged(QString))); + } + return m_pluginWatcher; } void PluginDumper::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion) @@ -92,14 +102,14 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString & // watch plugin libraries foreach (const QmlDirParser::Plugin &plugin, snapshot.libraryInfo(canonicalLibraryPath).plugins()) { const QString pluginLibrary = resolvePlugin(canonicalLibraryPath, plugin.path, plugin.name); - m_pluginWatcher->addFile(pluginLibrary); + pluginWatcher()->addFile(pluginLibrary, Utils::FileSystemWatcher::WatchModifiedDate); m_libraryToPluginIndex.insert(pluginLibrary, index); } // watch library xml file if (plugin.hasPredumpedQmlTypesFile()) { const QString &path = plugin.predumpedQmlTypesFilePath(); - m_pluginWatcher->addFile(path); + pluginWatcher()->addFile(path, Utils::FileSystemWatcher::WatchModifiedDate); m_libraryToPluginIndex.insert(path, index); } diff --git a/src/plugins/qmljstools/qmljsplugindumper.h b/src/plugins/qmljstools/qmljsplugindumper.h index 21bd372567..5a4d22c16e 100644 --- a/src/plugins/qmljstools/qmljsplugindumper.h +++ b/src/plugins/qmljstools/qmljsplugindumper.h @@ -41,8 +41,8 @@ QT_BEGIN_NAMESPACE class QDir; QT_END_NAMESPACE -namespace ProjectExplorer { -class FileWatcher; +namespace Utils { +class FileSystemWatcher; } namespace QmlJSTools { @@ -89,8 +89,10 @@ private: const QString &prefix = QString()); private: + Utils::FileSystemWatcher *pluginWatcher(); + ModelManager *m_modelManager; - ProjectExplorer::FileWatcher *m_pluginWatcher; + Utils::FileSystemWatcher *m_pluginWatcher; QHash<QProcess *, QString> m_runningQmldumps; QList<Plugin> m_plugins; QHash<QString, int> m_libraryToPluginIndex; diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index 87ae0b8535..a934fcb470 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp @@ -32,6 +32,9 @@ #include "filefilteritems.h" +#include <utils/filesystemwatcher.h> +#include <utils/qtcassert.h> + #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtGui/QImageReader> @@ -40,14 +43,30 @@ namespace QmlProjectManager { FileFilterBaseItem::FileFilterBaseItem(QObject *parent) : QmlProjectContentItem(parent), - m_recurse(RecurseDefault) + m_recurse(RecurseDefault), + m_dirWatcher(0) { m_updateFileListTimer.setSingleShot(true); m_updateFileListTimer.setInterval(50); - connect(&m_dirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList())); + connect(&m_updateFileListTimer, SIGNAL(timeout()), this, SLOT(updateFileListNow())); } +Utils::FileSystemWatcher *FileFilterBaseItem::dirWatcher() +{ + if (!m_dirWatcher) { + m_dirWatcher = new Utils::FileSystemWatcher(1, this); // Separate id, might exceed OS limits. + m_dirWatcher->setObjectName(QLatin1String("FileFilterBaseItemWatcher")); + connect(m_dirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList())); + } + return m_dirWatcher; +} + +QStringList FileFilterBaseItem::watchedDirectories() const +{ + return m_dirWatcher ? m_dirWatcher->directories() : QStringList(); +} + QString FileFilterBaseItem::directory() const { return m_rootDir; @@ -170,7 +189,7 @@ bool FileFilterBaseItem::matchesFile(const QString &filePath) const return false; const QDir fileDir = QFileInfo(filePath).absoluteDir(); - foreach (const QString &watchedDirectory, m_dirWatcher.directories()) { + foreach (const QString &watchedDirectory, watchedDirectories()) { if (QDir(watchedDirectory) == fileDir) return true; } @@ -233,14 +252,16 @@ void FileFilterBaseItem::updateFileListNow() } // update watched directories - const QSet<QString> oldDirs = m_dirWatcher.directories().toSet(); + const QSet<QString> oldDirs = watchedDirectories().toSet(); const QSet<QString> unwatchDirs = oldDirs - dirsToBeWatched; const QSet<QString> watchDirs = dirsToBeWatched - oldDirs; - if (!unwatchDirs.isEmpty()) - m_dirWatcher.removeDirectories(unwatchDirs.toList()); + if (!unwatchDirs.isEmpty()) { + QTC_ASSERT(m_dirWatcher, return ; ) + m_dirWatcher->removeDirectories(unwatchDirs.toList()); + } if (!watchDirs.isEmpty()) - m_dirWatcher.addDirectories(watchDirs.toList()); + dirWatcher()->addDirectories(watchDirs.toList(), Utils::FileSystemWatcher::WatchAllChanges); } bool FileFilterBaseItem::fileMatches(const QString &fileName) const diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h index 62b5a2a49d..986b1298b0 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h @@ -34,7 +34,6 @@ #define FILEFILTERITEMS_H #include "qmlprojectitem.h" -#include "filesystemwatcher.h" #include <QtCore/QObject> #include <QtCore/QSet> @@ -44,6 +43,10 @@ QT_FORWARD_DECLARE_CLASS(QDir) +namespace Utils { +class FileSystemWatcher; +} + namespace QmlProjectManager { class FileFilterBaseItem : public QmlProjectContentItem { @@ -91,6 +94,8 @@ private: bool fileMatches(const QString &fileName) const; QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0); + Utils::FileSystemWatcher *dirWatcher(); + QStringList watchedDirectories() const; QString m_rootDir; QString m_defaultDir; @@ -111,7 +116,7 @@ private: QStringList m_explicitFiles; QSet<QString> m_files; - FileSystemWatcher m_dirWatcher; + Utils::FileSystemWatcher *m_dirWatcher; QTimer m_updateFileListTimer; diff --git a/src/plugins/qmlprojectmanager/fileformat/fileformat.pri b/src/plugins/qmlprojectmanager/fileformat/fileformat.pri index f669492cbf..5edc94b4c9 100644 --- a/src/plugins/qmlprojectmanager/fileformat/fileformat.pri +++ b/src/plugins/qmlprojectmanager/fileformat/fileformat.pri @@ -1,8 +1,6 @@ HEADERS += $$PWD/qmlprojectitem.h \ $$PWD/filefilteritems.h \ - $$PWD/qmlprojectfileformat.h \ - $$PWD/filesystemwatcher.h + $$PWD/qmlprojectfileformat.h SOURCES += $$PWD/qmlprojectitem.cpp \ $$PWD/filefilteritems.cpp \ - $$PWD/qmlprojectfileformat.cpp \ - $$PWD/filesystemwatcher.cpp + $$PWD/qmlprojectfileformat.cpp diff --git a/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.cpp b/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.cpp deleted file mode 100644 index 86a811fec8..0000000000 --- a/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "filesystemwatcher.h" - -#include <QtCore/QDebug> -#include <QtCore/QDir> -#include <QtCore/QFileInfo> -#include <QtCore/QFileSystemWatcher> -#include <QtCore/QTimer> - -enum { debug = false }; - -namespace QmlProjectManager { - -int FileSystemWatcher::m_objectCount = 0; -QHash<QString,int> FileSystemWatcher::m_fileCount; -QHash<QString,int> FileSystemWatcher::m_directoryCount; -QFileSystemWatcher *FileSystemWatcher::m_watcher = 0; - -FileSystemWatcher::FileSystemWatcher(QObject *parent) : - QObject(parent) -{ - if (!m_watcher) - m_watcher = new QFileSystemWatcher(); - ++m_objectCount; - connect(m_watcher, SIGNAL(fileChanged(QString)), - this, SLOT(slotFileChanged(QString))); - connect(m_watcher, SIGNAL(directoryChanged(QString)), - this, SLOT(slotDirectoryChanged(QString))); -} - -FileSystemWatcher::~FileSystemWatcher() -{ - removeFiles(files()); - removeDirectories(directories()); - - if (--m_objectCount == 0) { - delete m_watcher; - m_watcher = 0; - } -} - -void FileSystemWatcher::addFile(const QString &file) -{ - addFiles(QStringList(file)); -} - - -#ifdef Q_OS_MAC - -// Returns upper limit of file handles that can be opened by this process at once. Exceeding it will probably result in crashes! -static rlim_t getFileLimit() -{ - struct rlimit rl; - getrlimit(RLIMIT_NOFILE, &rl); - return rl.rlim_cur; -} - -#endif - -void FileSystemWatcher::addFiles(const QStringList &files) -{ - QStringList toAdd; - - if (debug) - qDebug() << Q_FUNC_INFO << files.count(); - - foreach (const QString &file, files) { - if (m_files.contains(file)) { - qWarning() << "FileSystemWatcher: File" << file << "is already being watched"; - continue; - } - -#ifdef Q_OS_MAC - static rlim_t maxFileOpen = getFileLimit(); - // We're potentially watching a _lot_ of directories. This might crash qtcreator when we hit the upper limit. - // Heuristic is therefore: Don't use more than half of the file handles available in this watcher - if ((rlim_t)m_directories.size() + (rlim_t)m_files.size() > maxFileOpen / 2) { - qWarning() << "File" << file << "is not watched: Too many file handles are already open (max is" << maxFileOpen; - break; - } -#endif - - m_files.append(file); - - const int count = ++m_fileCount[file]; - Q_ASSERT(count > 0); - - if (count == 1) - toAdd << file; - } - - if (!toAdd.isEmpty()) - m_watcher->addPaths(toAdd); -} - -void FileSystemWatcher::removeFile(const QString &file) -{ - removeFiles(QStringList(file)); -} - -void FileSystemWatcher::removeFiles(const QStringList &files) -{ - QStringList toRemove; - - if (debug) - qDebug() << Q_FUNC_INFO << files.count(); - - foreach (const QString &file, files) { - if (!m_files.contains(file)) { - qWarning() << "FileSystemWatcher: File" << file << "is not watched"; - continue; - } - m_files.removeOne(file); - const int count = --m_fileCount[file]; - Q_ASSERT(count >= 0); - - if (!count) { - toRemove << file; - } - } - - if (!toRemove.isEmpty()) - m_watcher->removePaths(toRemove); -} - -QStringList FileSystemWatcher::files() const -{ - return m_files; -} - -void FileSystemWatcher::addDirectory(const QString &directory) -{ - addDirectories(QStringList(directory)); -} - -void FileSystemWatcher::addDirectories(const QStringList &directories) -{ - QStringList toAdd; - - if (debug) - qDebug() << Q_FUNC_INFO << directories.count(); - - foreach (const QString &directory, directories) { - if (m_directories.contains(directory)) { - qWarning() << "Directory" << directory << "is already being watched"; - continue; - } - -#ifdef Q_OS_MAC - static rlim_t maxFileOpen = getFileLimit(); - // We're potentially watching a _lot_ of directories. This might crash qtcreator when we hit the upper limit. - // Heuristic is therefore: Don't use more than half of the file handles available in this watcher - if ((rlim_t)m_directories.size() + (rlim_t)m_files.size() > maxFileOpen / 2) { - qWarning() << "Directory" << directory << "is not watched: Too many file handles are already open (max is" << maxFileOpen; - break; - } -#endif - - m_directories.append(directory); - - const int count = ++m_directoryCount[directory]; - Q_ASSERT(count > 0); - - if (count == 1) - toAdd << directory; - } - - if (!toAdd.isEmpty()) - m_watcher->addPaths(toAdd); -} - -void FileSystemWatcher::removeDirectory(const QString &directory) -{ - removeDirectories(QStringList(directory)); -} - -void FileSystemWatcher::removeDirectories(const QStringList &directories) -{ - QStringList toRemove; - - if (debug) - qDebug() << Q_FUNC_INFO << directories.count(); - - foreach (const QString &directory, directories) { - if (!m_directories.contains(directory)) { - qWarning() << "FileSystemWatcher: Directory" << directory << "is not watched"; - continue; - } - m_directories.removeOne(directory); - - const int count = --m_directoryCount[directory]; - Q_ASSERT(count >= 0); - - if (!count) { - toRemove << directory; - } - } - if (!toRemove.isEmpty()) - m_watcher->removePaths(toRemove); -} - -QStringList FileSystemWatcher::directories() const -{ - return m_directories; -} - -void FileSystemWatcher::slotFileChanged(const QString &path) -{ - if (m_files.contains(path)) - emit fileChanged(path); -} - -void FileSystemWatcher::slotDirectoryChanged(const QString &path) -{ - if (m_directories.contains(path)) - emit directoryChanged(path); -} - -} // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.h b/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.h deleted file mode 100644 index 82d86dc713..0000000000 --- a/src/plugins/qmlprojectmanager/fileformat/filesystemwatcher.h +++ /dev/null @@ -1,93 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef FSWATCHER_H -#define FSWATCHER_H - -#include <QtCore/QDateTime> -#include <QtCore/QHash> -#include <QtCore/QObject> -#include <QtCore/QStringList> -#include <QtCore/QMap> - -QT_BEGIN_NAMESPACE -class QTimer; -class QFileSystemWatcher; -QT_END_NAMESPACE - -namespace QmlProjectManager { - -class FileSystemWatcher : public QObject -{ - Q_DISABLE_COPY(FileSystemWatcher) - Q_OBJECT -public: - explicit FileSystemWatcher(QObject *parent = 0); - virtual ~FileSystemWatcher(); - - void addFile(const QString &file); - void addFiles(const QStringList &files); - - void removeFile(const QString &file); - void removeFiles(const QStringList &files); - - QStringList files() const; - - void addDirectory(const QString &file); - void addDirectories(const QStringList &files); - - void removeDirectory(const QString &file); - void removeDirectories(const QStringList &files); - - QStringList directories() const; - -private slots: - void slotFileChanged(const QString &path); - void slotDirectoryChanged(const QString &path); - -signals: - void fileChanged(const QString &path); - void directoryChanged(const QString &path); - -private: - QStringList m_files; - QStringList m_directories; - - static int m_objectCount; - static QHash<QString, int> m_fileCount; - static QHash<QString, int> m_directoryCount; - static QFileSystemWatcher *m_watcher; -}; - -} // namespace QmlProjectManager - -#endif // FSWATCHER_H diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 5a1907b9e6..6e1771bc10 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -41,11 +41,12 @@ #include <coreplugin/icore.h> #include <coreplugin/messagemanager.h> #include <extensionsystem/pluginmanager.h> -#include <projectexplorer/filewatcher.h> #include <qt4projectmanager/qmldumptool.h> #include <qt4projectmanager/qtversionmanager.h> #include <qmljs/qmljsmodelmanagerinterface.h> +#include <utils/filesystemwatcher.h> + #include <QtCore/QTextStream> #include <QtDeclarative/QDeclarativeComponent> #include <QtCore/QtDebug> @@ -56,8 +57,9 @@ QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName) : m_manager(manager), m_fileName(fileName), m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>()), - m_fileWatcher(new ProjectExplorer::FileWatcher(this)) + m_fileWatcher(new Utils::FileSystemWatcher(this)) { + m_fileWatcher->setObjectName(QLatin1String("QmlProjectWatcher")); setProjectContext(Core::Context(QmlProjectManager::Constants::PROJECTCONTEXT)); setProjectLanguage(Core::Context(QmlProjectManager::Constants::LANG_QML)); @@ -67,7 +69,7 @@ QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName) m_file = new Internal::QmlProjectFile(this, fileName); m_rootNode = new Internal::QmlProjectNode(this, m_file); - m_fileWatcher->addFile(fileName), + m_fileWatcher->addFile(fileName, Utils::FileSystemWatcher::WatchModifiedDate); connect(m_fileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(refreshProjectFile())); diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 090a834900..9e8c3eaddf 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -45,8 +45,8 @@ namespace QmlJS { class ModelManagerInterface; } -namespace ProjectExplorer { -class FileWatcher; +namespace Utils { +class FileSystemWatcher; } namespace QmlProjectManager { @@ -125,7 +125,7 @@ private: // qml based, new format QDeclarativeEngine m_engine; QWeakPointer<QmlProjectItem> m_projectItem; - ProjectExplorer::FileWatcher *m_fileWatcher; + Utils::FileSystemWatcher *m_fileWatcher; Internal::QmlProjectNode *m_rootNode; }; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp index 051958fd99..4467833297 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp @@ -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); } } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h index c3c9ee75d0..6a673cff57 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h @@ -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 diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp index cba94e705f..af1d79e117 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp @@ -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())); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h index bf996b825c..4546768630 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h @@ -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); |