2021-12-28 15:56:41 +08:00
|
|
|
#include "ukui-search-task.h"
|
|
|
|
#include "ukui-search-task-private.h"
|
2021-12-31 17:38:02 +08:00
|
|
|
#include "search-task-plugin-manager.h"
|
2021-12-28 15:56:41 +08:00
|
|
|
#include <QDebug>
|
|
|
|
using namespace UkuiSearch;
|
|
|
|
UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
q(parent)
|
|
|
|
{
|
2022-06-09 18:56:17 +08:00
|
|
|
m_searchCotroller = std::make_shared<SearchController>();
|
|
|
|
m_uuid = QUuid::createUuid();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate()
|
|
|
|
{
|
|
|
|
this->stop();
|
2022-06-09 18:56:17 +08:00
|
|
|
SearchTaskPluginManager::getInstance()->destroyPlugins(m_uuid);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *UkuiSearchTaskPrivate::init()
|
|
|
|
{
|
|
|
|
return m_searchCotroller->initDataQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::addSearchDir(QString &path)
|
|
|
|
{
|
|
|
|
m_searchCotroller->addSearchDir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::setRecurse(bool recurse)
|
|
|
|
{
|
|
|
|
m_searchCotroller->setRecurse(recurse);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::addKeyword(QString &keyword)
|
|
|
|
{
|
|
|
|
m_searchCotroller->addKeyword(keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::addFileLabel(QString &label)
|
|
|
|
{
|
|
|
|
m_searchCotroller->addFileLabel(label);
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
void UkuiSearchTaskPrivate::setOnlySearchFile(bool onlySearchFile)
|
|
|
|
{
|
|
|
|
m_searchCotroller->setOnlySearchFile(onlySearchFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::setOnlySearchDir(bool onlySearchDir)
|
|
|
|
{
|
|
|
|
m_searchCotroller->setOnlySearchDir(onlySearchDir);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:56:17 +08:00
|
|
|
void UkuiSearchTaskPrivate::initSearchPlugin(SearchType searchType, const QString& customSearchType)
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2022-06-09 18:56:17 +08:00
|
|
|
SearchTaskPluginIface *plugin = SearchTaskPluginManager::getInstance()->initPlugins(m_uuid, searchType, customSearchType);
|
|
|
|
if (plugin) {
|
|
|
|
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTaskPrivate::searchFinished);
|
|
|
|
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTaskPrivate::searchError);
|
|
|
|
} else {
|
|
|
|
qWarning() << "The plugin has been initialized or the plugin failed to load.";
|
|
|
|
}
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
|
|
|
|
bool UkuiSearchTaskPrivate::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
|
|
|
{
|
|
|
|
return m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UkuiSearchTaskPrivate::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
|
|
|
{
|
|
|
|
return m_searchCotroller->setResultDataType(searchType, dataType);
|
|
|
|
}
|
|
|
|
|
2022-06-09 18:56:17 +08:00
|
|
|
size_t UkuiSearchTaskPrivate::startSearch(SearchType searchtype, const QString& customSearchType)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
|
|
|
m_searchId = m_searchCotroller->refreshSearchId();
|
2021-12-31 17:38:02 +08:00
|
|
|
if(m_searchCotroller->getDataQueue() == nullptr) {
|
|
|
|
qWarning() << "the date queue has not been initialized, you need run init first!";
|
|
|
|
}
|
2021-12-28 15:56:41 +08:00
|
|
|
|
|
|
|
//plugin manager do async search here
|
2022-06-09 18:56:17 +08:00
|
|
|
if (!SearchTaskPluginManager::getInstance()->startSearch(m_uuid, m_searchCotroller, searchtype, customSearchType)) {
|
|
|
|
Q_EMIT searchError(m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
|
2021-12-31 17:38:02 +08:00
|
|
|
}
|
2021-12-28 15:56:41 +08:00
|
|
|
|
|
|
|
return m_searchId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::stop()
|
|
|
|
{
|
|
|
|
m_searchCotroller->stop();
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void UkuiSearchTaskPrivate::clearKeyWords()
|
|
|
|
{
|
|
|
|
m_searchCotroller->clearKeyWords();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::clearAllConditions()
|
|
|
|
{
|
|
|
|
m_searchCotroller->clearAllConditions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTaskPrivate::clearSearchDir()
|
|
|
|
{
|
|
|
|
m_searchCotroller->clearSearchDir();
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
void UkuiSearchTaskPrivate::clearFileLabel()
|
|
|
|
{
|
|
|
|
m_searchCotroller->clearFileLabel();
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void UkuiSearchTaskPrivate::setPagination(unsigned int first, unsigned int maxResults)
|
|
|
|
{
|
|
|
|
m_searchCotroller->setPagination(first, maxResults);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate(this))
|
|
|
|
{
|
|
|
|
connect(d, &UkuiSearchTaskPrivate::searchFinished, this, &UkuiSearchTask::searchFinished);
|
2022-06-09 18:56:17 +08:00
|
|
|
connect(d, &UkuiSearchTaskPrivate::searchError, this, &UkuiSearchTask::searchError);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UkuiSearchTask::~UkuiSearchTask()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *UkuiSearchTask::init()
|
|
|
|
{
|
2022-01-11 16:20:40 +08:00
|
|
|
return d->init();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::addSearchDir(QString &path)
|
|
|
|
{
|
|
|
|
d->addSearchDir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::setRecurse(bool recurse)
|
|
|
|
{
|
|
|
|
d->setRecurse(recurse);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::addKeyword(QString &keyword)
|
|
|
|
{
|
|
|
|
d->addKeyword(keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::addFileLabel(QString &label)
|
|
|
|
{
|
|
|
|
d->addFileLabel(label);
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:20:40 +08:00
|
|
|
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
|
|
|
|
{
|
|
|
|
d->setOnlySearchFile(onlySearchFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
|
|
|
{
|
|
|
|
d->setOnlySearchDir(onlySearchDir);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
|
|
|
{
|
|
|
|
d->setSearchOnlineApps(searchOnlineApps);
|
|
|
|
}
|
|
|
|
|
2022-01-24 09:44:42 +08:00
|
|
|
void UkuiSearchTask::initSearchPlugin(SearchType searchType)
|
|
|
|
{
|
|
|
|
d->initSearchPlugin(searchType);
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
bool UkuiSearchTask::setResultDataType(SearchType searchType, ResultDataTypes dataType)
|
|
|
|
{
|
|
|
|
return d->setResultDataType(searchType, dataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
|
|
|
{
|
|
|
|
return d->setCustomResultDataType(customSearchType, dataType);
|
|
|
|
}
|
|
|
|
|
2022-01-12 18:01:59 +08:00
|
|
|
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchType)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2022-01-12 18:01:59 +08:00
|
|
|
return d->startSearch(searchtype, customSearchType);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::stop()
|
|
|
|
{
|
|
|
|
d->stop();
|
|
|
|
}
|
2022-03-25 09:40:56 +08:00
|
|
|
|
|
|
|
void UkuiSearchTask::clearAllConditions()
|
|
|
|
{
|
|
|
|
d->clearAllConditions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::clearKeyWords()
|
|
|
|
{
|
|
|
|
d->clearKeyWords();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::clearSearchDir()
|
|
|
|
{
|
|
|
|
d->clearSearchDir();
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
void UkuiSearchTask::clearFileLabel()
|
|
|
|
{
|
|
|
|
d->clearFileLabel();
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void UkuiSearchTask::setPagination(unsigned int first, unsigned int maxResults)
|
|
|
|
{
|
|
|
|
d->setPagination(first, maxResults);
|
|
|
|
}
|