-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
- * Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kdirectorycontentscounter.h"
#include "kitemviews/kfileitemmodel.h"
m_watchedDirs.insert(resolvedPath);
}
- if (!m_queue.isEmpty()) {
- startWorker(m_queue.dequeue());
+ if (!m_priorityQueue.empty()) {
+ const QString firstPath = m_priorityQueue.front();
+ m_priorityQueue.pop_front();
+ startWorker(firstPath);
+ } else if (!m_queue.empty()) {
+ const QString firstPath = m_queue.front();
+ m_queue.pop_front();
+ startWorker(firstPath);
}
if (s_cache->contains(resolvedPath)) {
}
// sends the results
- emit result(resolvedPath, count, size);
+ Q_EMIT result(path, count, size);
}
void KDirectoryContentsCounter::slotDirWatchDirty(const QString& path)
void KDirectoryContentsCounter::startWorker(const QString& path)
{
- if (s_cache->contains(path)) {
+ const QString resolvedPath = QFileInfo(path).canonicalFilePath();
+ const bool alreadyInCache = s_cache->contains(resolvedPath);
+ if (alreadyInCache) {
// fast path when in cache
// will be updated later if result has changed
- const auto pair = s_cache->value(path);
- emit result(path, pair.first, pair.second);
+ const auto pair = s_cache->value(resolvedPath);
+ Q_EMIT result(path, pair.first, pair.second);
}
if (m_workerIsBusy) {
- m_queue.enqueue(path);
+ if (std::find(m_queue.begin(), m_queue.end(), path) == m_queue.end() &&
+ std::find(m_priorityQueue.begin(), m_priorityQueue.end(), path) == m_priorityQueue.end()) {
+ if (alreadyInCache) {
+ m_queue.push_back(path);
+ } else {
+ // append to priority queue
+ m_priorityQueue.push_back(path);
+ }
+ }
} else {
KDirectoryContentsCounterWorker::Options options;
options |= KDirectoryContentsCounterWorker::CountDirectoriesOnly;
}
- emit requestDirectoryContentsCount(path, options);
+ Q_EMIT requestDirectoryContentsCount(path, options);
m_workerIsBusy = true;
}
}