精简代码;完善搜索服务插件生命周期管理;增加搜索搜索隐藏文件功能

This commit is contained in:
iaom 2023-07-06 15:27:23 +08:00
parent 0c2ef7bee2
commit cbf833fa08
14 changed files with 186 additions and 442 deletions

View File

@ -34,7 +34,7 @@ class SearchTaskPluginIface : public QObject, public PluginInterface
{
Q_OBJECT
public:
virtual void setController(const std::shared_ptr<SearchController> &searchController) = 0;
virtual void setController(const SearchController &searchController) = 0;
virtual QString getCustomSearchType() = 0;
virtual SearchProperty::SearchType getSearchType() = 0;
//Asynchronous,multithread.

View File

@ -76,13 +76,13 @@ SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchProperty::Search
} else {
switch (searchType) {
case SearchProperty::SearchType::File:
searchPlugin = new FileSearchTask(this);
searchPlugin = new FileSearchTask();
break;
case SearchProperty::SearchType::FileContent:
searchPlugin = new FileContentSearchTask(this);
searchPlugin = new FileContentSearchTask();
break;
case SearchProperty::SearchType::Application:
searchPlugin = new AppSearchTask(this);
searchPlugin = new AppSearchTask();
break;
default:
break;
@ -148,6 +148,8 @@ void SearchTaskPluginManager::destroyPlugins(const QUuid &uuid)
ManagedPlugin::~ManagedPlugin()
{
qDeleteAll(m_internalPlugins);
qDeleteAll(m_externalPlugin);
}
bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searchType, SearchTaskPluginIface *plugin)
@ -163,7 +165,6 @@ bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searc
plugin->deleteLater();
}
return false;
}

View File

@ -1,86 +0,0 @@
#ifndef SEARCHCONTROLLERPRIVATE_H
#define SEARCHCONTROLLERPRIVATE_H
#include <QMutex>
#include <QMap>
#include "search-controller.h"
#include "search-result-property.h"
namespace UkuiSearch {
class SearchControllerPrivate
{
public:
explicit SearchControllerPrivate(SearchController *parent);
~SearchControllerPrivate();
size_t refreshSearchId();
DataQueue<ResultItem>* refreshDataqueue();
DataQueue<ResultItem>* initDataQueue();
void addSearchDir(const QString &path);
void setRecurse(bool recurse = true);
void addKeyword(const QString &keyword);
void setActiveKeywordSegmentation(bool active);
void addFileLabel(const QString &label);
void setOnlySearchFile(bool onlySearchFile);
void setOnlySearchDir(bool onlySearchDir);
void setSearchOnlineApps(bool searchOnlineApps);
size_t getCurrentSearchId();
DataQueue<ResultItem>* getDataQueue();
SearchResultProperties getResultProperties(SearchProperty::SearchType searchType);
QStringList getCustomResultDataType(QString customSearchType);
bool beginSearchIdCheck(size_t searchId);
void finishSearchIdCheck();
void stop();
QStringList getSearchDir();
bool isRecurse();
QStringList getKeyword();
bool isKeywordSegmentationActived();
QStringList getFileLabel();
bool isSearchFileOnly();
bool isSearchDirOnly();
bool isSearchOnlineApps();
void clearAllConditions();
void clearKeyWords();
void clearSearchDir();
void clearFileLabel();
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
void setCustomResultDataType(QString customSearchType, QStringList dataType);
/**
* @brief
* @param maxResults
*/
void setMaxResultNum(unsigned int maxResults);
void setInformNum(int num = 0);
unsigned int maxResults() const;
int informNum() const;
private:
void copyData();
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataQueue = nullptr;
size_t m_searchId = 0;
QMutex m_searchIdMutex;
SearchController *q = nullptr;
std::shared_ptr<SearchController> m_formerController = nullptr;
QStringList m_keywords;
QStringList m_searchDirs;
QStringList m_FileLabels;
bool m_recurse = true;
bool m_activeKeywordSegmentation = false;
bool m_onlySearchFile = false;
bool m_onlySearchDir = false;
bool m_searchOnlineApps = false;
unsigned int m_maxResults = 100; //默认取100条结果
int m_informNum = 0;
QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
QMap<QString, QStringList> m_customSearchType2ResultDataType;
};
}
#endif // SEARCHCONTROLLERPRIVATE_H

View File

@ -1,392 +1,230 @@
#include "search-controller.h"
#include "search-controller-private.h"
#include "ukui-search-task.h"
#include <QMutex>
#include <QMap>
#include <QDebug>
using namespace UkuiSearch;
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
: q(parent),
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
{
copyData();
}
#include "search-result-property.h"
#include "ukui-search-task.h"
namespace UkuiSearch {
SearchControllerPrivate::~SearchControllerPrivate()
class SearchControllerPrivate
{
}
public:
void clearAllConditions();
size_t SearchControllerPrivate::refreshSearchId()
{
m_searchIdMutex.lock();
m_searchId += 1;
m_searchIdMutex.unlock();
return m_searchId;
}
DataQueue<ResultItem> *SearchControllerPrivate::refreshDataqueue()
{
if(!m_sharedDataQueue.get()) {
// m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return m_sharedDataQueue.get();
}
m_sharedDataQueue.get()->clear();
return m_sharedDataQueue.get();
}
DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
{
if(!m_sharedDataQueue.get()) {
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return m_sharedDataQueue.get();
}
return m_sharedDataQueue.get();
}
void SearchControllerPrivate::addSearchDir(const QString &path)
{
m_searchDirs.append(path);
}
void SearchControllerPrivate::setRecurse(bool recurse)
{
m_recurse = recurse;
}
void SearchControllerPrivate::addKeyword(const QString &keyword)
{
m_keywords.append(keyword);
}
void SearchControllerPrivate::setActiveKeywordSegmentation(bool active)
{
m_activeKeywordSegmentation = active;
}
void SearchControllerPrivate::addFileLabel(const QString &label)
{
m_FileLabels.append(label);
}
void SearchControllerPrivate::setOnlySearchFile(bool onlySearchFile)
{
m_onlySearchFile = onlySearchFile;
}
void SearchControllerPrivate::setOnlySearchDir(bool onlySearchDir)
{
m_onlySearchDir = onlySearchDir;
}
void SearchControllerPrivate::setSearchOnlineApps(bool searchOnlineApps)
{
m_searchOnlineApps = searchOnlineApps;
}
size_t SearchControllerPrivate::getCurrentSearchId()
{
m_searchIdMutex.lock();
size_t searchId = m_searchId;
m_searchIdMutex.unlock();
return searchId;
}
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
{
return m_sharedDataQueue.get();
}
SearchResultProperties SearchControllerPrivate::getResultProperties(SearchProperty::SearchType searchType)
{
return m_searchType2ResultProperties[searchType];
}
QStringList SearchControllerPrivate::getCustomResultDataType(QString customSearchType)
{
return m_customSearchType2ResultDataType[customSearchType];
}
bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId)
{
if(q->m_parent) {
return q->m_parent->beginSearchIdCheck(searchId);
}
m_searchIdMutex.lock();
return m_searchId == searchId;
}
void SearchControllerPrivate::finishSearchIdCheck()
{
if(q->m_parent) {
return q->m_parent->finishSearchIdCheck();
}
m_searchIdMutex.unlock();
return;
}
void SearchControllerPrivate::stop()
{
m_searchIdMutex.lock();
m_searchId += 1;
m_searchIdMutex.unlock();
}
QStringList SearchControllerPrivate::getSearchDir()
{
return m_searchDirs;
}
bool SearchControllerPrivate::isRecurse()
{
return m_recurse;
}
QStringList SearchControllerPrivate::getKeyword()
{
return m_keywords;
}
bool SearchControllerPrivate::isKeywordSegmentationActived()
{
return m_activeKeywordSegmentation;
}
QStringList SearchControllerPrivate::getFileLabel()
{
return m_FileLabels;
}
bool SearchControllerPrivate::isSearchFileOnly()
{
return m_onlySearchFile;
}
bool SearchControllerPrivate::isSearchDirOnly()
{
return m_onlySearchDir;
}
bool SearchControllerPrivate::isSearchOnlineApps()
{
return m_searchOnlineApps;
}
void SearchControllerPrivate::copyData()
{
if(m_formerController.get()) {
m_searchId = m_formerController->d->m_searchId;
m_sharedDataQueue = m_formerController->d->m_sharedDataQueue;
m_keywords = m_formerController->d->m_keywords;
m_searchDirs = m_formerController->d->m_searchDirs;
m_FileLabels = m_formerController->d->m_FileLabels;
m_onlySearchFile = m_formerController->d->m_onlySearchFile;
m_onlySearchDir = m_formerController->d->m_onlySearchDir;
m_recurse = m_formerController->d->m_recurse;
m_activeKeywordSegmentation = m_formerController->d->m_activeKeywordSegmentation;
m_maxResults = m_formerController->d->m_maxResults;
m_informNum = m_formerController->d->m_informNum;
m_searchOnlineApps = m_formerController->d->m_searchOnlineApps;
m_searchType2ResultProperties = m_formerController->d->m_searchType2ResultProperties;
m_customSearchType2ResultDataType = m_formerController->d->m_customSearchType2ResultDataType;
}
}
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataQueue = nullptr;
size_t m_searchId = 0;
QMutex m_searchIdMutex;
QStringList m_keywords;
QStringList m_searchDirs;
QStringList m_FileLabels;
bool m_recurse = true;
bool m_activeKeywordSegmentation = false;
bool m_onlySearchFile = false;
bool m_onlySearchDir = false;
bool m_searchOnlineApps = false;
bool m_searchHiddenFiles = false;
unsigned int m_maxResults = 100; //默认取100条结果
int m_informNum = 0;
QMap<SearchProperty::SearchType, SearchResultProperties> m_searchType2ResultProperties;
QMap<QString, QStringList> m_customSearchType2ResultDataType;
};
void SearchControllerPrivate::clearAllConditions()
{
clearKeyWords();
clearSearchDir();
clearFileLabel();
}
void SearchControllerPrivate::clearKeyWords()
{
m_keywords.clear();
}
void SearchControllerPrivate::clearSearchDir()
{
m_searchDirs.clear();
}
void SearchControllerPrivate::clearFileLabel()
{
m_FileLabels.clear();
m_recurse = true;
m_activeKeywordSegmentation = false;
m_onlySearchFile = false;
m_onlySearchDir = false;
m_searchOnlineApps = false;
}
bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
SearchController::SearchController(): d(new SearchControllerPrivate)
{
bool res(true);
m_searchType2ResultProperties[searchType] = searchResultProperties;
return res;
}
void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
SearchController::SearchController(const SearchController &other):d(other.d)
{
m_customSearchType2ResultDataType[customSearchType] = dataType;
}
void SearchControllerPrivate::setMaxResultNum(unsigned int maxResults)
SearchController &SearchController::operator =(const SearchController &other)
{
m_maxResults = maxResults;
d = other.d;
return *this;
}
void SearchControllerPrivate::setInformNum(int num)
{
if(num >= 0) {
m_informNum = num;
}
}
unsigned int SearchControllerPrivate::maxResults() const
{
return m_maxResults;
}
int SearchControllerPrivate::informNum() const
{
return m_informNum;
}
SearchController::SearchController(std::shared_ptr<SearchController> parent) : m_parent(parent), d(new SearchControllerPrivate(this))
SearchController &SearchController::operator=(SearchController &&other) Q_DECL_NOEXCEPT
{
d = other.d;
other.d.reset();
return *this;
}
SearchController::~SearchController()
{
if(d) {
delete d;
d = nullptr;
}
d.reset();
}
DataQueue<ResultItem> *SearchController::refreshDataqueue()
{
return d->refreshDataqueue();
if(!d->m_sharedDataQueue.get()) {
// m_dataQueue = new DataQueue<ResultItem>;
d->m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return d->m_sharedDataQueue.get();
}
d->m_sharedDataQueue.get()->clear();
return d->m_sharedDataQueue.get();
}
size_t SearchController::refreshSearchId()
{
return d->refreshSearchId();
d->m_searchIdMutex.lock();
d->m_searchId += 1;
d->m_searchIdMutex.unlock();
return d->m_searchId;
}
DataQueue<ResultItem> *SearchController::initDataQueue()
{
return d->initDataQueue();
if(!d->m_sharedDataQueue.get()) {
d->m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return d->m_sharedDataQueue.get();
}
return d->m_sharedDataQueue.get();
}
void SearchController::addSearchDir(const QString &path)
{
return d->addSearchDir(path);
d->m_searchDirs.append(path);
}
void SearchController::setRecurse(bool recurse)
{
d->setRecurse(recurse);
d->m_recurse = recurse;;
}
void SearchController::addKeyword(const QString &keyword)
{
d->addKeyword(keyword);
d->m_keywords.append(keyword);
}
size_t SearchController::getCurrentSearchId()
{
return d->getCurrentSearchId();
d->m_searchIdMutex.lock();
size_t searchId = d->m_searchId;
d->m_searchIdMutex.unlock();
return searchId;
}
DataQueue<ResultItem> *SearchController::getDataQueue()
{
return d->getDataQueue();
return d->m_sharedDataQueue.get();
}
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
{
return d->getResultProperties(searchType);
return d->m_searchType2ResultProperties[searchType];;
}
QStringList SearchController::getCustomResultDataType(QString customSearchType)
{
return d->getCustomResultDataType(customSearchType);
return d->m_customSearchType2ResultDataType[customSearchType];
}
void SearchController::setActiveKeywordSegmentation(bool active)
{
d->setActiveKeywordSegmentation(active);
d->m_activeKeywordSegmentation = active;;
}
void SearchController::addFileLabel(const QString &label)
{
d->addFileLabel(label);
d->m_FileLabels.append(label);;
}
void SearchController::setOnlySearchFile(bool onlySearchFile)
{
d->setOnlySearchFile(onlySearchFile);
d->m_onlySearchFile = onlySearchFile;
}
void SearchController::setOnlySearchDir(bool onlySearchDir)
{
d->setOnlySearchDir(onlySearchDir);
d->m_onlySearchDir = onlySearchDir;
}
void SearchController::setSearchOnlineApps(bool searchOnlineApps)
{
d->setSearchOnlineApps(searchOnlineApps);
d->m_searchOnlineApps = searchOnlineApps;
}
void SearchController::setSearchHiddenFiles(bool searchHiddenFiles)
{
d->m_searchHiddenFiles = searchHiddenFiles;
}
bool SearchController::beginSearchIdCheck(size_t searchId)
{
return d->beginSearchIdCheck(searchId);
d->m_searchIdMutex.lock();
return d->m_searchId == searchId;
}
void SearchController::finishSearchIdCheck()
{
d->finishSearchIdCheck();
d->m_searchIdMutex.unlock();
return;
}
QStringList SearchController::getSearchDir()
{
return d->getSearchDir();
return d->m_searchDirs;
}
bool SearchController::isRecurse()
{
return d->isRecurse();
return d->m_recurse;
}
QStringList SearchController::getKeyword()
{
return d->getKeyword();
return d->m_keywords;
}
bool SearchController::isKeywordSegmentationActived()
{
return d->isKeywordSegmentationActived();
return d->m_activeKeywordSegmentation;
}
QStringList SearchController::getFileLabel()
{
return d->getFileLabel();
return d->m_FileLabels;
}
bool SearchController::isSearchFileOnly()
{
return d->isSearchFileOnly();
return d->m_onlySearchFile;
}
bool SearchController::isSearchDirOnly()
{
return d->isSearchDirOnly();
return d->m_onlySearchDir;
}
bool SearchController::isSearchOnlineApps()
{
return d->isSearchOnlineApps();
return d->m_searchOnlineApps;
}
bool SearchController::searchHiddenFiles()
{
return d->m_searchHiddenFiles;
}
void SearchController::stop()
{
d->stop();
d->m_searchIdMutex.lock();
d->m_searchId += 1;
d->m_searchIdMutex.unlock();
}
void SearchController::clearAllConditions()
@ -396,45 +234,49 @@ void SearchController::clearAllConditions()
void SearchController::clearKeyWords()
{
d->clearKeyWords();
d->m_keywords.clear();
}
void SearchController::clearSearchDir()
{
d->clearSearchDir();
d->m_searchDirs.clear();
}
void SearchController::clearFileLabel()
{
d->clearFileLabel();
d->m_FileLabels.clear();
}
void SearchController::setMaxResultNum(unsigned int maxResults)
{
d->setMaxResultNum(maxResults);
d->m_maxResults = maxResults;
}
void SearchController::setInformNum(int num)
{
d->setInformNum(num);
if(num >= 0) {
d->m_informNum = num;
}
}
unsigned int SearchController::maxResults() const
{
return d->maxResults();
return d->m_maxResults;
}
int SearchController::informNum() const
{
return d->informNum();
return d->m_informNum;
}
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{
return d->setResultProperties(searchType, searchResultProperties);
d->m_searchType2ResultProperties[searchType] = searchResultProperties;
return true;
}
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
{
return d->setCustomResultDataType(customSearchType, dataType);
d->m_customSearchType2ResultDataType[customSearchType] = dataType;
}
}

View File

@ -15,17 +15,17 @@ class SearchControllerPrivate;
*/
class SearchController
{
friend class SearchControllerPrivate;
public:
explicit SearchController(std::shared_ptr<SearchController> parent = nullptr);
SearchController(SearchController &) = delete;
SearchController &operator =(const SearchController &) = delete;
SearchController();
SearchController(const SearchController &other);
SearchController &operator=(const SearchController &other);
SearchController &operator=(SearchController &&other) Q_DECL_NOEXCEPT;
~SearchController();
DataQueue<ResultItem>* refreshDataqueue();
size_t refreshSearchId();
DataQueue<ResultItem>* initDataQueue();
void stop();
void addSearchDir(const QString &path);
void setRecurse(bool recurse = true);
void addKeyword(const QString &keyword);
@ -34,6 +34,7 @@ public:
void setOnlySearchFile(bool onlySearchFile);
void setOnlySearchDir(bool onlySearchDir);
void setSearchOnlineApps(bool searchOnlineApps);
void setSearchHiddenFiles(bool searchHiddenFiles);
void setMaxResultNum(unsigned int maxResults);
void setInformNum(int num = 0);
//以上方法插件请不要调用
@ -54,6 +55,7 @@ public:
bool isSearchFileOnly();
bool isSearchDirOnly();
bool isSearchOnlineApps();
bool searchHiddenFiles();
void clearAllConditions();
void clearKeyWords();
void clearSearchDir();
@ -65,8 +67,7 @@ public:
bool setResultProperties(SearchProperty::SearchType searchType, UkuiSearch::SearchResultProperties searchResultProperties);
void setCustomResultDataType(QString customSearchType, QStringList dataType);
private:
std::shared_ptr<SearchController> m_parent = nullptr;
SearchControllerPrivate *d = nullptr;
std::shared_ptr<SearchControllerPrivate> d;
};
}

View File

@ -3,7 +3,6 @@ include(searchtasks/search-tasks.pri)
HEADERS += \
# $$PWD/result-item-private.h \
$$PWD/search-controller-private.h \
$$PWD/search-controller.h \
$$PWD/result-item.h \
$$PWD/search-result-property-info.h \

View File

@ -42,7 +42,7 @@ AppSearchTask::~AppSearchTask()
m_pool->waitForDone();
}
void AppSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
void AppSearchTask::setController(const SearchController &searchController)
{
m_searchController = searchController;
}
@ -79,7 +79,7 @@ bool AppSearchTask::isSearching()
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
{
m_controller = new SearchController(m_appSearchTask->m_searchController);
m_controller = &m_appSearchTask->m_searchController;
m_currentSearchId = m_controller->getCurrentSearchId();
}
@ -183,14 +183,6 @@ void AppSearchWorker::run()
QMetaObject::invokeMethod(m_appSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId));
}
AppSearchWorker::~AppSearchWorker()
{
if(m_controller) {
delete m_controller;
m_controller = nullptr;
}
}
void AppSearchWorker::sendErrorMsg(const QString &msg)
{
QMetaObject::invokeMethod(m_appSearchTask, "searchError",

View File

@ -39,7 +39,7 @@ class AppSearchTask : public SearchTaskPluginIface
public:
explicit AppSearchTask(QObject *parent = nullptr);
~AppSearchTask();
void setController(const std::shared_ptr<SearchController> &searchController);
void setController(const SearchController &searchController);
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name();
const QString description();
@ -55,7 +55,7 @@ public:
private:
ApplicationInfo m_appinfo;
std::shared_ptr<SearchController> m_searchController;
SearchController m_searchController;
QThreadPool *m_pool = nullptr;
};
@ -63,7 +63,7 @@ class AppSearchWorker : public QRunnable
{
public:
explicit AppSearchWorker(AppSearchTask *AppSarchTask);
~AppSearchWorker();
protected:
void run();

View File

@ -47,7 +47,7 @@ FileContentSearchTask::~FileContentSearchTask()
m_pool->waitForDone();
}
void FileContentSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
void FileContentSearchTask::setController(const SearchController &searchController)
{
m_searchController = searchController;
}
@ -94,7 +94,7 @@ SearchProperty::SearchType FileContentSearchTask::getSearchType()
void FileContentSearchTask::startSearch()
{
FileContentSearchWorker *worker = new FileContentSearchWorker(this, m_searchController);
FileContentSearchWorker *worker = new FileContentSearchWorker(this, &m_searchController);
m_pool->start(worker);
}
@ -108,21 +108,13 @@ bool FileContentSearchTask::isSearching()
return m_pool->activeThreadCount() > 0;
}
FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController)
FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController)
{
m_fileContentSearchTask = fileContentSearchTask;
m_searchController = new SearchController(searchController);
m_searchController = searchController;
m_currentSearchId = m_searchController->getCurrentSearchId();
}
FileContentSearchWorker::~FileContentSearchWorker()
{
if(m_searchController) {
delete m_searchController;
m_searchController = nullptr;
}
}
void FileContentSearchWorker::run()
{
QStringList searchDirs = m_searchController->getSearchDir();

View File

@ -39,7 +39,7 @@ public:
explicit FileContentSearchTask(QObject *parent = nullptr);
~FileContentSearchTask() override;
void setController(const std::shared_ptr<SearchController> &searchController) override;
void setController(const SearchController &searchController) override;
PluginType pluginType() override;
const QString name() override;
const QString description() override;
@ -51,12 +51,12 @@ public:
SearchProperty::SearchType getSearchType() override;
void startSearch() override;
void stop() override;
bool isSearching();
bool isSearching() override;
private:
QThreadPool *m_pool = nullptr;
bool m_enable = true;
std::shared_ptr<SearchController> m_searchController;
SearchController m_searchController;
};
class FileContentSearchWorker : public QRunnable
@ -64,9 +64,7 @@ class FileContentSearchWorker : public QRunnable
friend class FileContentSearchFilter;
public:
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController);
~FileContentSearchWorker();
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, SearchController *searchController);
void run() override;
private:

View File

@ -46,7 +46,7 @@ FileSearchTask::~FileSearchTask()
m_pool->waitForDone();
}
void FileSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
void FileSearchTask::setController(const SearchController &searchController)
{
m_searchController = searchController;
}
@ -69,7 +69,7 @@ QString FileSearchTask::getCustomSearchType()
void FileSearchTask::startSearch()
{
FileSearchWorker *fileSearchWorker;
fileSearchWorker = new FileSearchWorker(this, m_searchController);
fileSearchWorker = new FileSearchWorker(this, &m_searchController);
m_pool->start(fileSearchWorker);
}
@ -83,20 +83,12 @@ bool FileSearchTask::isSearching()
return m_pool->activeThreadCount() > 0;
}
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController) : m_FileSearchTask(fileSarchTask)
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, SearchController *searchController) : m_FileSearchTask(fileSarchTask)
{
m_searchController = new SearchController(searchController);
m_searchController = searchController;
m_currentSearchId = m_searchController->getCurrentSearchId();
}
FileSearchWorker::~FileSearchWorker()
{
if(m_searchController) {
delete m_searchController;
m_searchController = nullptr;
}
}
void FileSearchWorker::run()
{
//1.检查是否为不可搜索目录
@ -128,7 +120,7 @@ void FileSearchWorker::run()
bool indexed = true;
QStringList indexedDir = DirWatcher::getDirWatcher()->currentIndexableDir();
if(!indexedDir.isEmpty() && IndexStatusRecorder::getInstance()->indexDatabaseEnable()) {
if(!indexedDir.isEmpty() && IndexStatusRecorder::getInstance()->indexDatabaseEnable() && !m_searchController->searchHiddenFiles()) {
for(const QString &path : m_searchController->getSearchDir()) {
bool pathIndexed = false;
for(const QString &dir : indexedDir) {
@ -266,13 +258,17 @@ bool FileSearchWorker::directSearch()
QDir dir;
QFileInfoList infoList;
QDir::Filters filters;
if (m_searchController->isSearchDirOnly()) {
dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
filters = QDir::Dirs | QDir::NoDotAndDotDot;
} else {
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
dir.setSorting(QDir::DirsFirst);
}
if(m_searchController->searchHiddenFiles()) {
filters |= QDir::Hidden;
}
dir.setFilter(filters);
while (!searchPathQueue.empty()) {
dir.setPath(searchPathQueue.dequeue());
if (!dir.exists())

View File

@ -34,10 +34,10 @@ class FileSearchTask : public SearchTaskPluginIface
{
Q_OBJECT
public:
explicit FileSearchTask(QObject *parent);
explicit FileSearchTask(QObject *parent = nullptr);
~FileSearchTask();
void setController(const std::shared_ptr<SearchController> &searchController);
void setController(const SearchController &searchController);
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
const QString name();
const QString description();
@ -53,7 +53,7 @@ public:
private:
QThreadPool *m_pool = nullptr;
std::shared_ptr<SearchController> m_searchController;
SearchController m_searchController;
};
class FileSearchWorker : public QRunnable
@ -61,8 +61,7 @@ class FileSearchWorker : public QRunnable
friend class FileSearchFilter;
public:
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
~FileSearchWorker();
explicit FileSearchWorker(FileSearchTask *fileSarchTask, SearchController *searchController);
protected:
void run();

View File

@ -8,7 +8,7 @@ class UkuiSearchTaskPrivate
{
friend class UkuiSearchTask;
private:
std::shared_ptr<SearchController> m_searchCotroller = nullptr;
SearchController m_searchCotroller;
size_t m_searchId = 0;
QUuid m_uuid;
};
@ -16,7 +16,6 @@ private:
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
{
d->m_searchCotroller = std::make_shared<SearchController>();
d->m_uuid = QUuid::createUuid();
}
@ -28,42 +27,47 @@ UkuiSearchTask::~UkuiSearchTask()
DataQueue<ResultItem> *UkuiSearchTask::init()
{
return d->m_searchCotroller->initDataQueue();
return d->m_searchCotroller.initDataQueue();
}
void UkuiSearchTask::addSearchDir(const QString &path)
{
d->m_searchCotroller->addSearchDir(path);
d->m_searchCotroller.addSearchDir(path);
}
void UkuiSearchTask::setRecurse(bool recurse)
{
d->m_searchCotroller->setRecurse(recurse);
d->m_searchCotroller.setRecurse(recurse);
}
void UkuiSearchTask::addKeyword(const QString &keyword)
{
d->m_searchCotroller->addKeyword(keyword);
d->m_searchCotroller.addKeyword(keyword);
}
void UkuiSearchTask::addFileLabel(const QString &label)
{
d->m_searchCotroller->addFileLabel(label);
d->m_searchCotroller.addFileLabel(label);
}
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
{
d->m_searchCotroller->setOnlySearchFile(onlySearchFile);
d->m_searchCotroller.setOnlySearchFile(onlySearchFile);
}
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
{
d->m_searchCotroller->setOnlySearchDir(onlySearchDir);
d->m_searchCotroller.setOnlySearchDir(onlySearchDir);
}
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
{
d->m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
d->m_searchCotroller.setSearchOnlineApps(searchOnlineApps);
}
void UkuiSearchTask::setSearchHiddenFiles(bool searchHiddenFiles)
{
d->m_searchCotroller.setSearchHiddenFiles(searchHiddenFiles);
}
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
@ -81,25 +85,25 @@ void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, con
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{
return d->m_searchCotroller->setResultProperties(searchType, searchResultProperties);
return d->m_searchCotroller.setResultProperties(searchType, searchResultProperties);
}
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
{
return d->m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
return d->m_searchCotroller.setCustomResultDataType(customSearchType, dataType);
}
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
{
d->m_searchId = d->m_searchCotroller->refreshSearchId();
if(d->m_searchCotroller->getDataQueue() == nullptr) {
d->m_searchId = d->m_searchCotroller.refreshSearchId();
if(d->m_searchCotroller.getDataQueue() == nullptr) {
qWarning() << "the date queue has not been initialized, you need run init first!";
}
d->m_searchCotroller->refreshDataqueue();
d->m_searchCotroller.refreshDataqueue();
//plugin manager do async search here
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, searchtype, customSearchType)) {
Q_EMIT searchError(d->m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
Q_EMIT searchError(d->m_searchCotroller.getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
}
return d->m_searchId;
@ -107,7 +111,7 @@ size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QStrin
void UkuiSearchTask::stop()
{
d->m_searchCotroller->stop();
d->m_searchCotroller.stop();
}
bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString customSearchType)
@ -117,30 +121,30 @@ bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString
void UkuiSearchTask::clearAllConditions()
{
d->m_searchCotroller->clearAllConditions();
d->m_searchCotroller.clearAllConditions();
}
void UkuiSearchTask::clearKeyWords()
{
d->m_searchCotroller->clearKeyWords();
d->m_searchCotroller.clearKeyWords();
}
void UkuiSearchTask::clearSearchDir()
{
d->m_searchCotroller->clearSearchDir();
d->m_searchCotroller.clearSearchDir();
}
void UkuiSearchTask::clearFileLabel()
{
d->m_searchCotroller->clearFileLabel();
d->m_searchCotroller.clearFileLabel();
}
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
{
d->m_searchCotroller->setMaxResultNum(maxResults);
d->m_searchCotroller.setMaxResultNum(maxResults);
}
void UkuiSearchTask::setInformNum(int num)
{
d->m_searchCotroller->setInformNum(num);
d->m_searchCotroller.setInformNum(num);
}

View File

@ -39,6 +39,12 @@ public:
void setOnlySearchFile(bool onlySearchFile);
void setOnlySearchDir(bool onlySearchDir);
void setSearchOnlineApps(bool searchOnlineApps);
/**
*
* @brief setSearchHiddenFiles
* @param searchHiddenFiles
*/
void setSearchHiddenFiles(bool searchHiddenFiles);
/**
* @brief initSearchPlugin
* @param searchType