From 308b9b642f12daabbe445ee6e159625eb41a2268 Mon Sep 17 00:00:00 2001 From: iaom Date: Thu, 16 Mar 2023 17:42:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8F=92=E4=BB=B6=E5=88=A4=E6=96=AD=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=89=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=92=8C=E6=96=87=E4=BB=B6=E5=9B=BE=E6=A0=87=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/file-indexer-config.cpp | 2 +- .../searchtasks/file-content-search-task.cpp | 2 +- .../searchtasks/file-search-task.cpp | 29 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libsearch/index/file-indexer-config.cpp b/libsearch/index/file-indexer-config.cpp index 6db2a01..847857e 100644 --- a/libsearch/index/file-indexer-config.cpp +++ b/libsearch/index/file-indexer-config.cpp @@ -41,7 +41,7 @@ FileIndexerConfig *FileIndexerConfig::getInstance() return global_intance; } -FileIndexerConfig::FileIndexerConfig(QObject *parent) \ +FileIndexerConfig::FileIndexerConfig(QObject *parent) : QObject(parent), m_dirWatcher(DirWatcher::getDirWatcher()) { diff --git a/libsearch/searchinterface/searchtasks/file-content-search-task.cpp b/libsearch/searchinterface/searchtasks/file-content-search-task.cpp index 138e892..c447e62 100644 --- a/libsearch/searchinterface/searchtasks/file-content-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-content-search-task.cpp @@ -147,7 +147,7 @@ bool FileContentSearchWorker::execSearch() resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path); } if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) { - resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(path).name()); + resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString()).name()); } if(properties.contains(SearchProperty::SearchResultProperty::FileName)) { resultItem.setValue(SearchProperty::SearchResultProperty::FileName, path.section("/", -1)); diff --git a/libsearch/searchinterface/searchtasks/file-search-task.cpp b/libsearch/searchinterface/searchtasks/file-search-task.cpp index ea9ec51..e068a63 100644 --- a/libsearch/searchinterface/searchtasks/file-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-search-task.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "index-status-recorder.h" #include "dir-watcher.h" #include "common.h" @@ -92,21 +93,29 @@ void FileSearchWorker::run() } bool finished = true; - bool indexed = !DirWatcher::getDirWatcher()->currentIndexableDir().isEmpty(); - qDebug() << DirWatcher::getDirWatcher()->currentIndexableDir(); - for(const QString &dir : DirWatcher::getDirWatcher()->currentIndexableDir()) { + bool indexed = true; + + QStringList indexedDir = DirWatcher::getDirWatcher()->currentIndexableDir(); + if(!indexedDir.isEmpty() && IndexStatusRecorder::getInstance()->indexDatabaseEnable()) { for(const QString &path : m_searchController->getSearchDir()) { - if(!FileUtils::isOrUnder(path, dir)) { + bool pathIndexed = false; + for(const QString &dir : indexedDir) { + if(FileUtils::isOrUnder(path, dir)) { + pathIndexed = true; + break; + } + } + if(!pathIndexed) { indexed = false; break; } } - if(!indexed) { - break; - } + } else { + indexed = false; } + //TODO 还需要判断是否为不能建立索引的目录 - if (IndexStatusRecorder::getInstance()->indexDatabaseEnable() && indexed) { + if (indexed) { qDebug() << "index ready"; finished = searchWithIndex(); } else { @@ -176,7 +185,7 @@ bool FileSearchWorker::searchWithIndex() resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path); } if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) { - resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(path).name()); + resultItem.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString()).name()); } if(properties.contains(SearchProperty::SearchResultProperty::FileName)) { resultItem.setValue(SearchProperty::SearchResultProperty::FileName, path.section("/", -1)); @@ -278,7 +287,7 @@ bool FileSearchWorker::directSearch() ri.setValue(SearchProperty::SearchResultProperty::FilePath, fileInfo.absoluteFilePath()); } if(properties.contains(SearchProperty::SearchResultProperty::FileIconName)) { - ri.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(fileInfo.absoluteFilePath()).name()); + ri.setValue(SearchProperty::SearchResultProperty::FileIconName, FileUtils::getFileIcon(QUrl::fromLocalFile(fileInfo.absoluteFilePath()).toString()).name()); } if(properties.contains(SearchProperty::SearchResultProperty::FileName)) { ri.setValue(SearchProperty::SearchResultProperty::FileName, fileInfo.fileName());