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

286 lines
6.0 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_dataQueue) {
m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
2021-12-28 15:56:41 +08:00
return m_dataQueue;
}
m_dataQueue->clear();
return m_dataQueue;;
}
DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
{
if(!m_dataQueue) {
m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
2021-12-28 15:56:41 +08:00
return m_dataQueue;
}
return m_dataQueue;
}
void SearchControllerPrivate::addSearchDir(QString &path)
{
m_searchDirs.append(path);
}
void SearchControllerPrivate::setRecurse(bool recurse)
{
m_recurse = recurse;
}
void SearchControllerPrivate::addKeyword(QString &keyword)
{
m_keywords.append(keyword);
}
void SearchControllerPrivate::setActiveKeywordSegmentation(bool active)
{
m_activeKeywordSegmentation = active;
}
void SearchControllerPrivate::addFileLabel(QString &label)
{
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;
}
2021-12-28 15:56:41 +08:00
size_t SearchControllerPrivate::getCurrentSearchId()
{
return m_searchId;
}
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
{
return m_sharedDataueue.get();
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 = 0;
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-01-11 16:20:40 +08:00
void SearchControllerPrivate::copyData()
{
2022-01-11 16:20:40 +08:00
if(m_formerController.get()) {
m_searchId = m_formerController.get()->getCurrentSearchId();
//所有子节点都有一个指向根节点的队列的智能指针
m_sharedDataueue = m_formerController.get()->d->m_sharedDataueue;
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-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()
{
delete d;
}
DataQueue<ResultItem> *SearchController::refreshDataqueue()
{
return d->refreshDataqueue();
}
size_t SearchController::refreshSearchId()
{
return d->refreshSearchId();
}
DataQueue<ResultItem> *SearchController::initDataQueue()
{
return d->initDataQueue();
}
void SearchController::addSearchDir(QString &path)
{
return d->addSearchDir(path);
}
void SearchController::setRecurse(bool recurse)
{
d->setRecurse(recurse);
}
void SearchController::addKeyword(QString &keyword)
{
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();
}
void SearchController::setActiveKeywordSegmentation(bool active)
{
d->setActiveKeywordSegmentation(active);
}
void SearchController::addFileLabel(QString &label)
{
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);
}
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
}
void SearchController::stop()
{
d->stop();
}