]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kdirectorycontentscounter.cpp
Add Duplicate feature
[dolphin.git] / src / kitemviews / private / kdirectorycontentscounter.cpp
index af7312ad270089999bc29164d3837aab9716a85c..bd204fe8e24a353a16a0dccdc6ff821b668c8474 100644 (file)
  ***************************************************************************/
 
 #include "kdirectorycontentscounter.h"
-
-#include "kdirectorycontentscounterworker.h"
-#include <kitemviews/kfileitemmodel.h>
+#include "kitemviews/kfileitemmodel.h"
 
 #include <KDirWatch>
+
+#include <QFileInfo>
 #include <QThread>
 
 KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObject* parent) :
     QObject(parent),
     m_model(model),
     m_queue(),
-    m_worker(0),
+    m_worker(nullptr),
     m_workerIsBusy(false),
-    m_dirWatcher(0),
+    m_dirWatcher(nullptr),
     m_watchedDirs()
 {
     connect(m_model, &KFileItemModel::itemsRemoved,
@@ -70,7 +70,7 @@ KDirectoryContentsCounter::~KDirectoryContentsCounter()
         m_workerThread->quit();
         m_workerThread->wait();
         delete m_workerThread;
-        m_workerThread = 0;
+        m_workerThread = nullptr;
 
         // The worker thread has finished running now, so it's safe to delete
         // m_worker. deleteLater() would not work at all because the event loop
@@ -86,9 +86,11 @@ void KDirectoryContentsCounter::addDirectory(const QString& path)
 
 int KDirectoryContentsCounter::countDirectoryContentsSynchronously(const QString& path)
 {
-    if (!m_dirWatcher->contains(path)) {
-        m_dirWatcher->addDir(path);
-        m_watchedDirs.insert(path);
+    const QString resolvedPath = QFileInfo(path).canonicalFilePath();
+
+    if (!m_dirWatcher->contains(resolvedPath)) {
+        m_dirWatcher->addDir(resolvedPath);
+        m_watchedDirs.insert(resolvedPath);
     }
 
     KDirectoryContentsCounterWorker::Options options;
@@ -108,9 +110,11 @@ void KDirectoryContentsCounter::slotResult(const QString& path, int count)
 {
     m_workerIsBusy = false;
 
-    if (!m_dirWatcher->contains(path)) {
-        m_dirWatcher->addDir(path);
-        m_watchedDirs.insert(path);
+    const QString resolvedPath = QFileInfo(path).canonicalFilePath();
+
+    if (!m_dirWatcher->contains(resolvedPath)) {
+        m_dirWatcher->addDir(resolvedPath);
+        m_watchedDirs.insert(resolvedPath);
     }
 
     if (!m_queue.isEmpty()) {
@@ -180,5 +184,5 @@ void KDirectoryContentsCounter::startWorker(const QString& path)
     }
 }
 
-QThread* KDirectoryContentsCounter::m_workerThread = 0;
+QThread* KDirectoryContentsCounter::m_workerThread = nullptr;
 int KDirectoryContentsCounter::m_workersCount = 0;