From 09c6495bd13db29ccaf5f6f171cf99431d2b20f4 Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Wed, 13 Oct 2010 15:22:52 +0200
Subject: [PATCH 1/2] Optimize which folders we recursively enumerate

Reviewed-By: pending
---
 src/plugins/qt4projectmanager/qt4nodes.cpp   |    9 ++++++---
 src/plugins/qt4projectmanager/qt4nodes.h     |    2 +-
 src/plugins/qt4projectmanager/qt4project.cpp |    1 -
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp
index 888c45f..e67dd17 100644
--- a/src/plugins/qt4projectmanager/qt4nodes.cpp
+++ b/src/plugins/qt4projectmanager/qt4nodes.cpp
@@ -644,15 +644,18 @@ void Qt4PriFileNode::watchFolders(const QSet<QString> &folders)
     m_watchedFolders = folders;
 }
 
-void Qt4PriFileNode::folderChanged(const QString &)
+void Qt4PriFileNode::folderChanged(const QString &changedFolder)
 {
     //qDebug()<<"########## Qt4PriFileNode::folderChanged";
     // So, we need to figure out which files changed.
 
     // Collect all the files
     QSet<QString> newFiles;
-    foreach (const QString &folder, m_watchedFolders) {
-        newFiles += recursiveEnumerate(folder);
+    newFiles += recursiveEnumerate(changedFolder);
+
+    foreach (const QString &file, m_recursiveEnumerateFiles) {
+        if (!file.startsWith(changedFolder))
+            newFiles.insert(file);
     }
 
     QSet<QString> addedFiles = newFiles;
diff --git a/src/plugins/qt4projectmanager/qt4nodes.h b/src/plugins/qt4projectmanager/qt4nodes.h
index f9bdfd2..d2725de 100644
--- a/src/plugins/qt4projectmanager/qt4nodes.h
+++ b/src/plugins/qt4projectmanager/qt4nodes.h
@@ -155,7 +155,7 @@ public:
     bool renameFile(const FileType fileType,
                     const QString &filePath, const QString &newFilePath);
 
-    void folderChanged(const QString &folder);
+    void folderChanged(const QString &changedFolder);
 
     bool deploysFolder(const QString &folder) const;
 
diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp
index f480a72..264f010 100644
--- a/src/plugins/qt4projectmanager/qt4project.cpp
+++ b/src/plugins/qt4projectmanager/qt4project.cpp
@@ -1254,7 +1254,6 @@ void CentralizedFolderWatcher::folderChanged(const QString &folder)
     if (!folder.endsWith('/'))
         folderWithSlash.append('/');
 
-
     // If a subdirectory was added, watch it too
     QSet<QString> tmp = recursiveDirs(folderWithSlash);
     if (!tmp.isEmpty()) {
-- 
1.6.5.3


From e34c99a9cc7713561847e111d5c3c6871258cf1d Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Wed, 13 Oct 2010 15:33:51 +0200
Subject: [PATCH 2/2] Qt4ProjectManager: Compress the folderChanged via a small timer

Reviewed-By: pending
---
 src/plugins/qt4projectmanager/qt4project.cpp |   18 +++++++++++++++++-
 src/plugins/qt4projectmanager/qt4project.h   |    4 ++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp
index 264f010..ab0d40e 100644
--- a/src/plugins/qt4projectmanager/qt4project.cpp
+++ b/src/plugins/qt4projectmanager/qt4project.cpp
@@ -1128,6 +1128,10 @@ namespace {
 
 CentralizedFolderWatcher::CentralizedFolderWatcher()
 {
+    m_compressTimer.setSingleShot(true);
+    m_compressTimer.setInterval(200);
+    connect(&m_compressTimer, SIGNAL(timeout()),
+            this, SLOT(onTimer()));
     connect (&m_watcher, SIGNAL(directoryChanged(QString)),
              this, SLOT(folderChanged(QString)));
 }
@@ -1221,9 +1225,21 @@ void CentralizedFolderWatcher::unwatchFolders(const QList<QString> &folders, Qt4
     }
 }
 
-
 void CentralizedFolderWatcher::folderChanged(const QString &folder)
 {
+    m_changedFolders.insert(folder);
+    m_compressTimer.start();
+}
+
+void CentralizedFolderWatcher::onTimer()
+{
+    foreach(const QString &folder, m_changedFolders)
+        delayedFolderChanged(folder);
+    m_changedFolders.clear();
+}
+
+void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
+{
     if (debugCFW)
         qDebug()<<"CFW::folderChanged"<<folder;
     // Figure out whom to inform
diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h
index 7141fbb..6b2f7b2 100644
--- a/src/plugins/qt4projectmanager/qt4project.h
+++ b/src/plugins/qt4projectmanager/qt4project.h
@@ -122,6 +122,8 @@ public:
 
 private slots:
     void folderChanged(const QString &folder);
+    void onTimer();
+    void delayedFolderChanged(const QString &folder);
 
 private:
     QSet<QString> recursiveDirs(const QString &folder);
@@ -129,6 +131,8 @@ private:
     QMultiMap<QString, Qt4PriFileNode *> m_map;
 
     QSet<QString> m_recursiveWatchedFolders;
+    QTimer m_compressTimer;
+    QSet<QString> m_changedFolders;
 };
 
 }
-- 
1.6.5.3

