2021-12-28 15:56:41 +08:00
|
|
|
#include "search-controller.h"
|
|
|
|
#include "search-controller-private.h"
|
|
|
|
#include "ukui-search-task.h"
|
|
|
|
#include <QDebug>
|
|
|
|
using namespace UkuiSearch;
|
|
|
|
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
|
2022-01-12 18:01:59 +08:00
|
|
|
: q(parent),
|
|
|
|
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2022-01-12 18:01:59 +08:00
|
|
|
copyData();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchControllerPrivate::~SearchControllerPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SearchControllerPrivate::refreshSearchId()
|
|
|
|
{
|
|
|
|
m_searchIdMutex.lock();
|
|
|
|
m_searchId += 1;
|
|
|
|
m_searchIdMutex.unlock();
|
|
|
|
return m_searchId;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchControllerPrivate::refreshDataqueue()
|
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
if(!m_sharedDataQueue.get()) {
|
2022-02-16 18:13:59 +08:00
|
|
|
// m_dataQueue = new DataQueue<ResultItem>;
|
2022-06-13 13:38:47 +08:00
|
|
|
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
|
|
|
return m_sharedDataQueue.get();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
2022-06-13 13:38:47 +08:00
|
|
|
m_sharedDataQueue.get()->clear();
|
|
|
|
return m_sharedDataQueue.get();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
|
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
if(!m_sharedDataQueue.get()) {
|
|
|
|
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
|
|
|
|
return m_sharedDataQueue.get();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
2022-06-13 13:38:47 +08:00
|
|
|
return m_sharedDataQueue.get();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchControllerPrivate::addSearchDir(const QString &path)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
m_searchDirs.append(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchControllerPrivate::setRecurse(bool recurse)
|
|
|
|
{
|
|
|
|
m_recurse = recurse;
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchControllerPrivate::addKeyword(const QString &keyword)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
m_keywords.append(keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchControllerPrivate::setActiveKeywordSegmentation(bool active)
|
|
|
|
{
|
|
|
|
m_activeKeywordSegmentation = active;
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchControllerPrivate::addFileLabel(const QString &label)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
m_FileLabels.append(label);
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
void SearchControllerPrivate::setOnlySearchFile(bool onlySearchFile)
|
|
|
|
{
|
|
|
|
m_onlySearchFile = onlySearchFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchControllerPrivate::setOnlySearchDir(bool onlySearchDir)
|
|
|
|
{
|
|
|
|
m_onlySearchDir = onlySearchDir;
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
void SearchControllerPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
|
|
|
{
|
|
|
|
m_searchOnlineApps = searchOnlineApps;
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
size_t SearchControllerPrivate::getCurrentSearchId()
|
|
|
|
{
|
2022-03-25 09:40:56 +08:00
|
|
|
m_searchIdMutex.lock();
|
|
|
|
size_t searchId = m_searchId;
|
|
|
|
m_searchIdMutex.unlock();
|
|
|
|
|
|
|
|
return searchId;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
|
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
return m_sharedDataQueue.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultDataTypes SearchControllerPrivate::getResultDataType(SearchType searchType)
|
|
|
|
{
|
|
|
|
return m_searchType2ResultDataType[searchType];
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchControllerPrivate::getCustomResultDataType(QString customSearchType)
|
|
|
|
{
|
|
|
|
return m_customSearchType2ResultDataType[customSearchType];
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2022-06-09 18:56:17 +08:00
|
|
|
m_searchId += 1;
|
2021-12-28 15:56:41 +08:00
|
|
|
m_searchIdMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchControllerPrivate::getSearchDir()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return m_searchDirs;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchControllerPrivate::isRecurse()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return m_recurse;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchControllerPrivate::getKeyword()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return m_keywords;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchControllerPrivate::isKeywordSegmentationActived()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return m_activeKeywordSegmentation;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchControllerPrivate::getFileLabel()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return m_FileLabels;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchControllerPrivate::isSearchFileOnly()
|
|
|
|
{
|
|
|
|
return m_onlySearchFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchControllerPrivate::isSearchDirOnly()
|
|
|
|
{
|
|
|
|
return m_onlySearchDir;
|
|
|
|
}
|
2021-12-28 15:56:41 +08:00
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
bool SearchControllerPrivate::isSearchOnlineApps()
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
return m_searchOnlineApps;
|
|
|
|
}
|
2022-01-12 18:01:59 +08:00
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
void SearchControllerPrivate::copyData()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
if(m_formerController.get()) {
|
|
|
|
m_searchId = m_formerController.get()->getCurrentSearchId();
|
2022-01-12 18:01:59 +08:00
|
|
|
//所有子节点都有一个指向根节点的队列的智能指针
|
2022-06-13 13:38:47 +08:00
|
|
|
m_sharedDataQueue = m_formerController.get()->d->m_sharedDataQueue;
|
2022-01-11 16:20:40 +08:00
|
|
|
m_keywords = m_formerController.get()->getKeyword();
|
|
|
|
m_searchDirs = m_formerController.get()->getSearchDir();
|
|
|
|
m_FileLabels = m_formerController.get()->getFileLabel();
|
|
|
|
m_onlySearchFile = m_formerController.get()->isSearchFileOnly();
|
|
|
|
m_onlySearchDir = m_formerController.get()->isSearchDirOnly();
|
|
|
|
m_recurse = m_formerController.get()->isRecurse();
|
|
|
|
m_activeKeywordSegmentation = m_formerController.get()->isKeywordSegmentationActived();
|
|
|
|
}
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void SearchControllerPrivate::clearAllConditions()
|
|
|
|
{
|
|
|
|
clearKeyWords();
|
|
|
|
clearSearchDir();
|
2022-04-28 15:49:51 +08:00
|
|
|
clearFileLabel();
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchControllerPrivate::clearKeyWords()
|
|
|
|
{
|
|
|
|
m_keywords.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchControllerPrivate::clearSearchDir()
|
|
|
|
{
|
|
|
|
m_searchDirs.clear();
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
void SearchControllerPrivate::clearFileLabel()
|
|
|
|
{
|
|
|
|
m_FileLabels.clear();
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
bool SearchControllerPrivate::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
|
|
|
{
|
|
|
|
bool res(true);
|
|
|
|
m_searchType2ResultDataType[searchType] = dataType;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
|
|
|
{
|
|
|
|
bool res(true);
|
|
|
|
m_customSearchType2ResultDataType[customSearchType] = dataType;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void SearchControllerPrivate::setPagination(unsigned int first, unsigned int maxResults)
|
|
|
|
{
|
|
|
|
m_first = first;
|
|
|
|
m_maxResults = maxResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SearchControllerPrivate::first() const
|
|
|
|
{
|
|
|
|
return m_first;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SearchControllerPrivate::maxResults() const
|
|
|
|
{
|
|
|
|
return m_maxResults;
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
SearchController::SearchController(std::shared_ptr<SearchController> parent) : m_parent(parent), d(new SearchControllerPrivate(this))
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchController::~SearchController()
|
|
|
|
{
|
2022-01-24 09:44:42 +08:00
|
|
|
if(d) {
|
|
|
|
delete d;
|
|
|
|
d = nullptr;
|
|
|
|
}
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchController::refreshDataqueue()
|
|
|
|
{
|
|
|
|
return d->refreshDataqueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SearchController::refreshSearchId()
|
|
|
|
{
|
|
|
|
return d->refreshSearchId();
|
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchController::initDataQueue()
|
|
|
|
{
|
|
|
|
return d->initDataQueue();
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchController::addSearchDir(const QString &path)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
return d->addSearchDir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchController::setRecurse(bool recurse)
|
|
|
|
{
|
|
|
|
d->setRecurse(recurse);
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchController::addKeyword(const QString &keyword)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
d->addKeyword(keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SearchController::getCurrentSearchId()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return d->getCurrentSearchId();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *SearchController::getDataQueue()
|
|
|
|
{
|
|
|
|
return d->getDataQueue();
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
ResultDataTypes SearchController::getResultDataType(SearchType searchType)
|
|
|
|
{
|
|
|
|
return d->getResultDataType(searchType);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchController::getCustomResultDataType(QString customSearchType)
|
|
|
|
{
|
|
|
|
return d->getCustomResultDataType(customSearchType);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
void SearchController::setActiveKeywordSegmentation(bool active)
|
|
|
|
{
|
|
|
|
d->setActiveKeywordSegmentation(active);
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void SearchController::addFileLabel(const QString &label)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
d->addFileLabel(label);
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
void SearchController::setOnlySearchFile(bool onlySearchFile)
|
|
|
|
{
|
|
|
|
d->setOnlySearchFile(onlySearchFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchController::setOnlySearchDir(bool onlySearchDir)
|
|
|
|
{
|
|
|
|
d->setOnlySearchDir(onlySearchDir);
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
void SearchController::setSearchOnlineApps(bool searchOnlineApps)
|
|
|
|
{
|
|
|
|
d->setSearchOnlineApps(searchOnlineApps);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
bool SearchController::beginSearchIdCheck(size_t searchId)
|
|
|
|
{
|
|
|
|
return d->beginSearchIdCheck(searchId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchController::finishSearchIdCheck()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
d->finishSearchIdCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchController::getSearchDir()
|
|
|
|
{
|
|
|
|
return d->getSearchDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchController::isRecurse()
|
|
|
|
{
|
|
|
|
return d->isRecurse();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchController::getKeyword()
|
|
|
|
{
|
|
|
|
return d->getKeyword();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchController::isKeywordSegmentationActived()
|
|
|
|
{
|
|
|
|
return d->isKeywordSegmentationActived();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SearchController::getFileLabel()
|
|
|
|
{
|
|
|
|
return d->getFileLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchController::isSearchFileOnly()
|
|
|
|
{
|
|
|
|
return d->isSearchFileOnly();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchController::isSearchDirOnly()
|
|
|
|
{
|
|
|
|
return d->isSearchDirOnly();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
bool SearchController::isSearchOnlineApps()
|
|
|
|
{
|
|
|
|
return d->isSearchOnlineApps();
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
void SearchController::stop()
|
|
|
|
{
|
|
|
|
d->stop();
|
|
|
|
}
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
|
|
void SearchController::clearAllConditions()
|
|
|
|
{
|
|
|
|
d->clearAllConditions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchController::clearKeyWords()
|
|
|
|
{
|
|
|
|
d->clearKeyWords();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchController::clearSearchDir()
|
|
|
|
{
|
|
|
|
d->clearSearchDir();
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
void SearchController::clearFileLabel()
|
|
|
|
{
|
|
|
|
d->clearFileLabel();
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void SearchController::setPagination(unsigned int first, unsigned int maxResults)
|
|
|
|
{
|
|
|
|
d->setPagination(first, maxResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SearchController::first() const
|
|
|
|
{
|
|
|
|
return d->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SearchController::maxResults() const
|
|
|
|
{
|
|
|
|
return d->maxResults();
|
|
|
|
}
|
2022-06-13 13:38:47 +08:00
|
|
|
|
|
|
|
bool SearchController::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
|
|
|
{
|
|
|
|
return d->setResultDataType(searchType, dataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
|
|
|
{
|
|
|
|
return d->setCustomResultDataType(customSearchType, dataType);
|
|
|
|
}
|