summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-21 18:24:28 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-27 13:01:05 (GMT)
commit4de788b10cf2753dc341d6d34c2a9190505640f0 (patch)
tree5ec01192e75dbc9adf3894e24797cabcbf3486ab
parentf15cd5c8f9b8fe867ae62d04eedb9c9cb7d5b250 (diff)
Port cache to QList
-rw-r--r--src/part/scan.cpp25
-rw-r--r--src/part/scan.h4
2 files changed, 16 insertions, 13 deletions
diff --git a/src/part/scan.cpp b/src/part/scan.cpp
index 567d637..c64ec65 100644
--- a/src/part/scan.cpp
+++ b/src/part/scan.cpp
@@ -39,7 +39,6 @@ ScanManager::ScanManager(QObject *parent)
, m_files(0)
, m_mutex()
, m_thread(0)
- , m_cache(new Chain<Folder>)
{
Filelight::LocalLister::readMounts();
connect(this, &ScanManager::branchCacheHit, this, &ScanManager::foundCached, Qt::QueuedConnection);
@@ -53,8 +52,6 @@ ScanManager::~ScanManager()
m_thread->wait();
}
- delete m_cache;
-
//RemoteListers are QObjects and get automatically deleted
}
@@ -104,8 +101,10 @@ bool ScanManager::start(const QUrl &url)
* cached: /usr/local/, /usr/include/
*/
- for (Iterator<Folder> it = m_cache->iterator(); it != m_cache->end(); ++it) {
- QString cachePath = (*it)->name();
+ QMutableListIterator<Folder*> it(m_cache);
+ while (it.hasNext()) {
+ Folder *folder = it.next();
+ QString cachePath = folder->name();
if (path.startsWith(cachePath)) { //then whole tree already scanned
//find a pointer to the requested branch
@@ -113,7 +112,7 @@ bool ScanManager::start(const QUrl &url)
qDebug() << "Cache-(a)hit: " << cachePath;
QVector<QStringRef> split = path.midRef(cachePath.length()).split(QLatin1Char('/'));
- Folder *d = *it;
+ Folder *d = folder;
while (!split.isEmpty() && d != NULL) { //if NULL we have got lost so abort!!
Iterator<File> jt = d->iterator();
@@ -146,12 +145,14 @@ bool ScanManager::start(const QUrl &url)
} else {
//something went wrong, we couldn't find the folder we were expecting
qWarning() << "Didn't find " << path << " in the cache!\n";
- delete it.remove(); //safest to get rid of it
+ it.remove();
+ delete folder;
break; //do a full scan
}
} else if (cachePath.startsWith(path)) { //then part of the requested tree is already scanned
qDebug() << "Cache-(b)hit: " << cachePath;
- it.transferTo(*trees);
+ it.remove();
+ trees->append(folder);
}
}
@@ -183,7 +184,8 @@ void ScanManager::emptyCache()
emit aboutToEmptyCache();
- m_cache->empty();
+ qDeleteAll(m_cache);
+ m_cache.clear();
}
void ScanManager::cacheTree(Folder *tree)
@@ -203,9 +205,10 @@ void ScanManager::cacheTree(Folder *tree)
if (tree) {
//we don't cache foreign stuff
//we don't recache stuff (thus only type 1000 events)
- m_cache->append(tree);
+ m_cache.append(tree);
} else { //scan failed
- m_cache->empty(); //FIXME this is safe but annoying
+ qDeleteAll(m_cache);
+ m_cache.clear();
}
QGuiApplication::restoreOverrideCursor();
diff --git a/src/part/scan.h b/src/part/scan.h
index 7f0109f..19cf26d 100644
--- a/src/part/scan.h
+++ b/src/part/scan.h
@@ -25,6 +25,7 @@
#include <QString>
#include <QObject>
#include <QMutex>
+#include <QList>
class QThread;
class Folder;
@@ -70,8 +71,7 @@ private:
QMutex m_mutex;
LocalLister *m_thread;
- Chain<Folder> *m_cache;
-
+ QList<Folder*> m_cache;
};
}