Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/private/kdirectorycontentscounter.cpp
Show All 17 Lines | |||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "kdirectorycontentscounter.h" | 21 | #include "kdirectorycontentscounter.h" | ||
22 | #include "kitemviews/kfileitemmodel.h" | 22 | #include "kitemviews/kfileitemmodel.h" | ||
23 | 23 | | |||
24 | #include <KDirWatch> | 24 | #include <KDirWatch> | ||
25 | 25 | | |||
26 | #include <QFileInfo> | ||||
26 | #include <QThread> | 27 | #include <QThread> | ||
27 | 28 | | |||
28 | KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObject* parent) : | 29 | KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObject* parent) : | ||
29 | QObject(parent), | 30 | QObject(parent), | ||
30 | m_model(model), | 31 | m_model(model), | ||
31 | m_queue(), | 32 | m_queue(), | ||
32 | m_worker(nullptr), | 33 | m_worker(nullptr), | ||
33 | m_workerIsBusy(false), | 34 | m_workerIsBusy(false), | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
80 | 81 | | |||
81 | void KDirectoryContentsCounter::addDirectory(const QString& path) | 82 | void KDirectoryContentsCounter::addDirectory(const QString& path) | ||
82 | { | 83 | { | ||
83 | startWorker(path); | 84 | startWorker(path); | ||
84 | } | 85 | } | ||
85 | 86 | | |||
86 | int KDirectoryContentsCounter::countDirectoryContentsSynchronously(const QString& path) | 87 | int KDirectoryContentsCounter::countDirectoryContentsSynchronously(const QString& path) | ||
87 | { | 88 | { | ||
88 | if (!m_dirWatcher->contains(path)) { | 89 | const QString resolvedPath = QFileInfo(path).canonicalFilePath(); | ||
89 | m_dirWatcher->addDir(path); | 90 | | ||
90 | m_watchedDirs.insert(path); | 91 | if (!m_dirWatcher->contains(resolvedPath)) { | ||
92 | m_dirWatcher->addDir(resolvedPath); | ||||
93 | m_watchedDirs.insert(resolvedPath); | ||||
elvisangelaccio: Missing `const`. I'd also call this variable `resolvedPath` or `canonicalPath`. | |||||
91 | } | 94 | } | ||
92 | 95 | | |||
93 | KDirectoryContentsCounterWorker::Options options; | 96 | KDirectoryContentsCounterWorker::Options options; | ||
94 | 97 | | |||
95 | if (m_model->showHiddenFiles()) { | 98 | if (m_model->showHiddenFiles()) { | ||
96 | options |= KDirectoryContentsCounterWorker::CountHiddenFiles; | 99 | options |= KDirectoryContentsCounterWorker::CountHiddenFiles; | ||
97 | } | 100 | } | ||
98 | 101 | | |||
99 | if (m_model->showDirectoriesOnly()) { | 102 | if (m_model->showDirectoriesOnly()) { | ||
100 | options |= KDirectoryContentsCounterWorker::CountDirectoriesOnly; | 103 | options |= KDirectoryContentsCounterWorker::CountDirectoriesOnly; | ||
101 | } | 104 | } | ||
102 | 105 | | |||
103 | return KDirectoryContentsCounterWorker::subItemsCount(path, options); | 106 | return KDirectoryContentsCounterWorker::subItemsCount(path, options); | ||
104 | } | 107 | } | ||
105 | 108 | | |||
106 | void KDirectoryContentsCounter::slotResult(const QString& path, int count) | 109 | void KDirectoryContentsCounter::slotResult(const QString& path, int count) | ||
107 | { | 110 | { | ||
108 | m_workerIsBusy = false; | 111 | m_workerIsBusy = false; | ||
109 | 112 | | |||
110 | if (!m_dirWatcher->contains(path)) { | 113 | const QString resolvedPath = QFileInfo(path).canonicalFilePath(); | ||
111 | m_dirWatcher->addDir(path); | 114 | | ||
112 | m_watchedDirs.insert(path); | 115 | if (!m_dirWatcher->contains(resolvedPath)) { | ||
116 | m_dirWatcher->addDir(resolvedPath); | ||||
117 | m_watchedDirs.insert(resolvedPath); | ||||
elvisangelaccio: Same here | |||||
113 | } | 118 | } | ||
114 | 119 | | |||
115 | if (!m_queue.isEmpty()) { | 120 | if (!m_queue.isEmpty()) { | ||
116 | startWorker(m_queue.dequeue()); | 121 | startWorker(m_queue.dequeue()); | ||
117 | } | 122 | } | ||
118 | 123 | | |||
119 | emit result(path, count); | 124 | emit result(path, count); | ||
120 | } | 125 | } | ||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Missing const. I'd also call this variable resolvedPath or canonicalPath.