From aa2ea09496f196fc53fc8583afda3d047588e3b8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Thu, 14 Apr 2011 16:29:00 +0200 Subject: [PATCH] Maemo: Create file watchers on demand. As QFileSystemWatcher cause some shutdown time. Rubber-stamped-by: Christian Kandeler <christian.kandeler@nokia.com> --- .../qt-maemo/maemoqemumanager.cpp | 36 +++++++++++++------ .../qt-maemo/maemoqemumanager.h | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp index 7b0f9b91f00..051958fd996 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.cpp @@ -79,6 +79,8 @@ MaemoQemuManager::MaemoQemuManager(QObject *parent) , m_qemuProcess(new QProcess(this)) , m_runningQtId(INT_MIN) , m_userTerminated(false) + , m_runtimeRootWatcher(0) + , m_runtimeFolderWatcher(0) { m_qemuStarterIcon.addFile(":/qt-maemo/images/qemu-run.png", iconSize); m_qemuStarterIcon.addFile(":/qt-maemo/images/qemu-stop.png", iconSize, @@ -124,13 +126,26 @@ MaemoQemuManager::MaemoQemuManager(QObject *parent) SLOT(qemuOutput())); connect(this, SIGNAL(qemuProcessStatus(QemuStatus, QString)), this, SLOT(qemuStatusChanged(QemuStatus, QString))); +} - m_runtimeRootWatcher = new QFileSystemWatcher(this); - connect(m_runtimeRootWatcher, SIGNAL(directoryChanged(QString)), this, - SLOT(runtimeRootChanged(QString))); - m_runtimeFolderWatcher = new QFileSystemWatcher(this); - connect(m_runtimeFolderWatcher, SIGNAL(directoryChanged(QString)), this, - SLOT(runtimeFolderChanged(QString))); +QFileSystemWatcher *MaemoQemuManager::runtimeRootWatcher() +{ + if (!m_runtimeRootWatcher) { + m_runtimeRootWatcher = new QFileSystemWatcher(this); + connect(m_runtimeRootWatcher, SIGNAL(directoryChanged(QString)), this, + SLOT(runtimeRootChanged(QString))); + } + return m_runtimeRootWatcher; +} + +QFileSystemWatcher *MaemoQemuManager::runtimeFolderWatcher() +{ + if (!m_runtimeFolderWatcher) { + m_runtimeFolderWatcher = new QFileSystemWatcher(this); + connect(m_runtimeFolderWatcher, SIGNAL(directoryChanged(QString)), this, + SLOT(runtimeFolderChanged(QString))); + } + return m_runtimeFolderWatcher; } MaemoQemuManager::~MaemoQemuManager() @@ -170,8 +185,8 @@ void MaemoQemuManager::qtVersionsChanged(const QList<int> &uniqueIds) = MaemoQemuRuntimeParser::parseRuntime(version); if (runtime.isValid()) { m_runtimes.insert(uniqueId, runtime); - if (!m_runtimeRootWatcher->directories().contains(runtime.m_watchPath)) - m_runtimeRootWatcher->addPath(runtime.m_watchPath); + if (!runtimeRootWatcher()->directories().contains(runtime.m_watchPath)) + runtimeRootWatcher()->addPath(runtime.m_watchPath); } else { m_runtimes.remove(uniqueId); } @@ -462,7 +477,7 @@ void MaemoQemuManager::runtimeRootChanged(const QString &directory) if (!QFile::exists(runtime.m_root + QLatin1String("/information"))) { // install might be still in progress uniqueIds.removeAll(uniqueId); - m_runtimeFolderWatcher->addPath(runtime.m_root); + runtimeFolderWatcher()->addPath(runtime.m_root); } } } @@ -480,7 +495,8 @@ void MaemoQemuManager::runtimeFolderChanged(const QString &directory) uniqueIds.append(it.key()); } notify(uniqueIds); - m_runtimeFolderWatcher->removePath(directory); + if (m_runtimeFolderWatcher) + m_runtimeFolderWatcher->removePath(directory); } } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h index 68a775e9a7b..c3c9ee75d03 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoqemumanager.h @@ -123,6 +123,8 @@ private: private: QAction *m_qemuAction; QProcess *m_qemuProcess; + QFileSystemWatcher *runtimeRootWatcher(); + QFileSystemWatcher *runtimeFolderWatcher(); int m_runningQtId; bool m_userTerminated; -- GitLab