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());