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

147 lines
4.1 KiB
C++
Raw Normal View History

2021-12-28 15:56:41 +08:00
#include "ukui-search-task.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;
namespace UkuiSearch {
2021-12-28 15:56:41 +08:00
class UkuiSearchTaskPrivate
2022-01-11 16:20:40 +08:00
{
friend class UkuiSearchTask;
private:
std::shared_ptr<SearchController> m_searchCotroller = nullptr;
size_t m_searchId = 0;
QUuid m_uuid;
};
2022-01-11 16:20:40 +08:00
}
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
2022-01-11 16:20:40 +08:00
{
d->m_searchCotroller = std::make_shared<SearchController>();
d->m_uuid = QUuid::createUuid();
2021-12-28 15:56:41 +08:00
}
UkuiSearchTask::~UkuiSearchTask()
{
stop();
SearchTaskPluginManager::getInstance()->destroyPlugins(d->m_uuid);
2021-12-28 15:56:41 +08:00
}
DataQueue<ResultItem> *UkuiSearchTask::init()
{
return d->m_searchCotroller->initDataQueue();
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::addSearchDir(const QString &path)
2021-12-28 15:56:41 +08:00
{
d->m_searchCotroller->addSearchDir(path);
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::setRecurse(bool recurse)
{
d->m_searchCotroller->setRecurse(recurse);
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::addKeyword(const QString &keyword)
2021-12-28 15:56:41 +08:00
{
d->m_searchCotroller->addKeyword(keyword);
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::addFileLabel(const QString &label)
2021-12-28 15:56:41 +08:00
{
d->m_searchCotroller->addFileLabel(label);
2021-12-28 15:56:41 +08:00
}
2022-01-11 16:20:40 +08:00
void UkuiSearchTask::setOnlySearchFile(bool onlySearchFile)
{
d->m_searchCotroller->setOnlySearchFile(onlySearchFile);
2022-01-11 16:20:40 +08:00
}
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
{
d->m_searchCotroller->setOnlySearchDir(onlySearchDir);
2022-01-11 16:20:40 +08:00
}
2021-12-28 15:56:41 +08:00
void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
{
d->m_searchCotroller->setSearchOnlineApps(searchOnlineApps);
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
{
SearchTaskPluginIface *plugin = SearchTaskPluginManager::getInstance()->initPlugins(d->m_uuid, searchType, customSearchType);
if (plugin) {
plugin->setController(d->m_searchCotroller);
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTask::searchFinished);
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTask::searchError);
connect(plugin, &SearchTaskPluginIface::reachInformNum,this, &UkuiSearchTask::reachInformNum);
} else {
qWarning() << "The plugin has been initialized or the plugin failed to load.";
}
}
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
{
return d->m_searchCotroller->setResultProperties(searchType, searchResultProperties);
}
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
{
return d->m_searchCotroller->setCustomResultDataType(customSearchType, dataType);
}
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
2021-12-28 15:56:41 +08:00
{
d->m_searchId = d->m_searchCotroller->refreshSearchId();
if(d->m_searchCotroller->getDataQueue() == nullptr) {
qWarning() << "the date queue has not been initialized, you need run init first!";
}
d->m_searchCotroller->refreshDataqueue();
//plugin manager do async search here
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, searchtype, customSearchType)) {
Q_EMIT searchError(d->m_searchCotroller->getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
}
return d->m_searchId;
2021-12-28 15:56:41 +08:00
}
void UkuiSearchTask::stop()
{
d->m_searchCotroller->stop();
2021-12-28 15:56:41 +08:00
}
bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString customSearchType)
{
return SearchTaskPluginManager::getInstance()->isSearching(d->m_uuid, searchtype, customSearchType);
}
void UkuiSearchTask::clearAllConditions()
{
d->m_searchCotroller->clearAllConditions();
}
void UkuiSearchTask::clearKeyWords()
{
d->m_searchCotroller->clearKeyWords();
}
void UkuiSearchTask::clearSearchDir()
{
d->m_searchCotroller->clearSearchDir();
}
void UkuiSearchTask::clearFileLabel()
{
d->m_searchCotroller->clearFileLabel();
}
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
{
d->m_searchCotroller->setMaxResultNum(maxResults);
}
void UkuiSearchTask::setInformNum(int num)
{
d->m_searchCotroller->setInformNum(num);
}