ukui-search/libsearch/searchinterface/search-controller.cpp

441 lines
9.5 KiB
C++
Raw Normal View History

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)
: q(parent),
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
2021-12-28 15:56:41 +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()
{
if(!m_sharedDataQueue.get()) {
2022-02-16 18:13:59 +08:00
// m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return m_sharedDataQueue.get();
2021-12-28 15:56:41 +08:00
}
m_sharedDataQueue.get()->clear();
return m_sharedDataQueue.get();
2021-12-28 15:56:41 +08:00
}
DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
{
if(!m_sharedDataQueue.get()) {
m_sharedDataQueue = std::make_shared<DataQueue<ResultItem>>();
return m_sharedDataQueue.get();
2021-12-28 15:56:41 +08:00
}
return m_sharedDataQueue.get();
2021-12-28 15:56:41 +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;
}
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;
}
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;
}
void SearchControllerPrivate::setSearchOnlineApps(bool searchOnlineApps)
{
m_searchOnlineApps = searchOnlineApps;
}
2021-12-28 15:56:41 +08:00
size_t SearchControllerPrivate::getCurrentSearchId()
{
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()
{
return m_sharedDataQueue.get();
}
SearchResultProperties SearchControllerPrivate::getResultProperties(SearchProperty::SearchType searchType)
{
return m_searchType2ResultProperties[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();
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
bool SearchControllerPrivate::isSearchOnlineApps()
2022-01-11 16:20:40 +08:00
{
return m_searchOnlineApps;
}
void SearchControllerPrivate::copyData()
{
2022-01-11 16:20:40 +08:00
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;
2022-01-11 16:20:40 +08:00
}
2021-12-28 15:56:41 +08:00
}
void SearchControllerPrivate::clearAllConditions()
{
clearKeyWords();
clearSearchDir();
clearFileLabel();
}
void SearchControllerPrivate::clearKeyWords()
{
m_keywords.clear();
}
void SearchControllerPrivate::clearSearchDir()
{
m_searchDirs.clear();
}
void SearchControllerPrivate::clearFileLabel()
{
m_FileLabels.clear();
}
bool SearchControllerPrivate::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{
bool res(true);
m_searchType2ResultProperties[searchType] = searchResultProperties;
return res;
}
void SearchControllerPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
{
m_customSearchType2ResultDataType[customSearchType] = dataType;
}
void SearchControllerPrivate::setMaxResultNum(unsigned int maxResults)
{
m_maxResults = maxResults;
}
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;
}
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()
{
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();
}
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);
}
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();
}
SearchResultProperties SearchController::getResultProperties(SearchProperty::SearchType searchType)
{
return d->getResultProperties(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);
}
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);
}
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
}
bool SearchController::isSearchOnlineApps()
{
return d->isSearchOnlineApps();
}
2021-12-28 15:56:41 +08:00
void SearchController::stop()
{
d->stop();
}
void SearchController::clearAllConditions()
{
d->clearAllConditions();
}
void SearchController::clearKeyWords()
{
d->clearKeyWords();
}
void SearchController::clearSearchDir()
{
d->clearSearchDir();
}
void SearchController::clearFileLabel()
{
d->clearFileLabel();
}
void SearchController::setMaxResultNum(unsigned int maxResults)
{
d->setMaxResultNum(maxResults);
}
void SearchController::setInformNum(int num)
{
d->setInformNum(num);
}
unsigned int SearchController::maxResults() const
{
return d->maxResults();
}
int SearchController::informNum() const
{
return d->informNum();
}
bool SearchController::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{
return d->setResultProperties(searchType, searchResultProperties);
}
void SearchController::setCustomResultDataType(QString customSearchType, QStringList dataType)
{
return d->setCustomResultDataType(customSearchType, dataType);
}