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();
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchResultProperties SearchControllerPrivate::getResultProperties(SearchProperty::SearchType searchType)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return m_searchType2ResultProperties[searchType];
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2023-05-06 15:41:56 +08:00
|
|
|
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;
|
2023-05-19 15:15:28 +08:00
|
|
|
m_informNum = m_formerController->d->m_informNum;
|
2023-05-06 15:41:56 +08:00
|
|
|
m_searchOnlineApps = m_formerController->d->m_searchOnlineApps;
|
|
|
|
m_searchType2ResultProperties = m_formerController->d->m_searchType2ResultProperties;
|
|
|
|
m_customSearchType2ResultDataType = m_formerController->d->m_customSearchType2ResultDataType;
|
2022-01-11 16:20:40 +08:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
|
|
|
bool res(true);
|
2023-03-15 16:39:38 +08:00
|
|
|
m_searchType2ResultProperties[searchType] = searchResultProperties;
|
2022-06-13 13:38:47 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
|
|
|
m_customSearchType2ResultDataType[customSearchType] = dataType;
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void SearchControllerPrivate::setMaxResultNum(unsigned int maxResults)
|
2022-03-25 09:40:56 +08:00
|
|
|
{
|
|
|
|
m_maxResults = maxResults;
|
|
|
|
}
|
|
|
|
|
2023-05-19 15:15:28 +08:00
|
|
|
void SearchControllerPrivate::setInformNum(int num)
|
|
|
|
{
|
|
|
|
if(num >= 0) {
|
|
|
|
m_informNum = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
unsigned int SearchControllerPrivate::maxResults() const
|
|
|
|
{
|
|
|
|
return m_maxResults;
|
|
|
|
}
|
|
|
|
|
2023-05-19 15:15:28 +08:00
|
|
|
int SearchControllerPrivate::informNum() const
|
|
|
|
{
|
|
|
|
return m_informNum;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->getResultProperties(searchType);
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void SearchController::setMaxResultNum(unsigned int maxResults)
|
2022-03-25 09:40:56 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->setMaxResultNum(maxResults);
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
|
|
|
|
2023-05-19 15:15:28 +08:00
|
|
|
void SearchController::setInformNum(int num)
|
|
|
|
{
|
|
|
|
d->setInformNum(num);
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
unsigned int SearchController::maxResults() const
|
|
|
|
{
|
|
|
|
return d->maxResults();
|
|
|
|
}
|
2022-06-13 13:38:47 +08:00
|
|
|
|
2023-05-19 15:15:28 +08:00
|
|
|
int SearchController::informNum() const
|
|
|
|
{
|
|
|
|
return d->informNum();
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->setResultProperties(searchType, searchResultProperties);
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
|
|
|
return d->setCustomResultDataType(customSearchType, dataType);
|
|
|
|
}
|