File indexing completed on 2024-05-05 05:51:19
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2008-2014 Dominik Haumann <dhaumann kde org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "btfileindexer.h" 0008 #include "btdatabase.h" 0009 0010 #include <QDebug> 0011 #include <QDir> 0012 0013 BtFileIndexer::BtFileIndexer(KateBtDatabase *database) 0014 : cancelAsap(false) 0015 , db(database) 0016 { 0017 } 0018 0019 BtFileIndexer::~BtFileIndexer() 0020 { 0021 } 0022 0023 void BtFileIndexer::setSearchPaths(const QStringList &urls) 0024 { 0025 searchPaths.clear(); 0026 for (const QString &url : urls) { 0027 if (!searchPaths.contains(url)) { 0028 searchPaths += url; 0029 } 0030 } 0031 } 0032 0033 void BtFileIndexer::setFilter(const QStringList &fileFilter) 0034 { 0035 filter = fileFilter; 0036 qDebug() << filter; 0037 } 0038 0039 void BtFileIndexer::run() 0040 { 0041 if (filter.empty()) { 0042 qDebug() << "Filter is empty. Aborting."; 0043 return; 0044 } 0045 0046 cancelAsap = false; 0047 for (int i = 0; i < searchPaths.size(); ++i) { 0048 if (cancelAsap) { 0049 break; 0050 } 0051 indexFiles(searchPaths[i]); 0052 } 0053 qDebug() << QStringLiteral("Backtrace file database contains %1 files").arg(db->size()); 0054 } 0055 0056 void BtFileIndexer::cancel() 0057 { 0058 cancelAsap = true; 0059 } 0060 0061 void BtFileIndexer::indexFiles(const QString &url) 0062 { 0063 QDir dir(url); 0064 if (!dir.exists()) { 0065 return; 0066 } 0067 0068 QStringList files = dir.entryList(filter, QDir::Files | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive); 0069 db->add(url, files); 0070 0071 QStringList subdirs = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive); 0072 for (int i = 0; i < subdirs.size(); ++i) { 0073 if (cancelAsap) { 0074 break; 0075 } 0076 indexFiles(url + QLatin1Char('/') + subdirs[i]); 0077 } 0078 } 0079 0080 #include "moc_btfileindexer.cpp" 0081 0082 // kate: space-indent on; indent-width 4; replace-tabs on;