2024-01-30 14:35:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* * Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
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;
|
2023-03-15 16:39:38 +08:00
|
|
|
namespace UkuiSearch {
|
2021-12-28 15:56:41 +08:00
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
class UkuiSearchTaskPrivate
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
friend class UkuiSearchTask;
|
|
|
|
private:
|
2023-07-06 15:27:23 +08:00
|
|
|
SearchController m_searchCotroller;
|
2023-03-15 16:39:38 +08:00
|
|
|
size_t m_searchId = 0;
|
|
|
|
QUuid m_uuid;
|
|
|
|
};
|
2022-01-11 16:20:40 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate())
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_uuid = QUuid::createUuid();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UkuiSearchTask::~UkuiSearchTask()
|
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
stop();
|
|
|
|
SearchTaskPluginManager::getInstance()->destroyPlugins(d->m_uuid);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataQueue<ResultItem> *UkuiSearchTask::init()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
return d->m_searchCotroller.initDataQueue();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void UkuiSearchTask::addSearchDir(const QString &path)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.addSearchDir(path);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::setRecurse(bool recurse)
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.setRecurse(recurse);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void UkuiSearchTask::addKeyword(const QString &keyword)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.addKeyword(keyword);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2024-04-25 10:59:18 +08:00
|
|
|
void UkuiSearchTask::setMatchAllIfNoKeyword(bool matchAll)
|
|
|
|
{
|
|
|
|
d->m_searchCotroller.setMatchAllIfNoKeyword(matchAll);
|
|
|
|
}
|
|
|
|
|
2023-03-07 17:33:08 +08:00
|
|
|
void UkuiSearchTask::addFileLabel(const QString &label)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +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)
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.setOnlySearchFile(onlySearchFile);
|
2022-01-11 16:20:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::setOnlySearchDir(bool onlySearchDir)
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
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)
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.setSearchOnlineApps(searchOnlineApps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::setSearchHiddenFiles(bool searchHiddenFiles)
|
|
|
|
{
|
|
|
|
d->m_searchCotroller.setSearchHiddenFiles(searchHiddenFiles);
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, const QString &customSearchType)
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchTaskPluginIface *plugin = SearchTaskPluginManager::getInstance()->initPlugins(d->m_uuid, searchType, customSearchType);
|
|
|
|
if (plugin) {
|
2023-05-06 15:41:56 +08:00
|
|
|
plugin->setController(d->m_searchCotroller);
|
2023-03-15 16:39:38 +08:00
|
|
|
connect(plugin, &SearchTaskPluginIface::searchFinished,this, &UkuiSearchTask::searchFinished);
|
|
|
|
connect(plugin, &SearchTaskPluginIface::searchError,this, &UkuiSearchTask::searchError);
|
2023-05-19 15:15:28 +08:00
|
|
|
connect(plugin, &SearchTaskPluginIface::reachInformNum,this, &UkuiSearchTask::reachInformNum);
|
2023-03-15 16:39:38 +08:00
|
|
|
} else {
|
|
|
|
qWarning() << "The plugin has been initialized or the plugin failed to load.";
|
|
|
|
}
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
bool UkuiSearchTask::setResultProperties(SearchProperty::SearchType searchType, SearchResultProperties searchResultProperties)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
return d->m_searchCotroller.setResultProperties(searchType, searchResultProperties);
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void UkuiSearchTask::setCustomResultDataType(QString customSearchType, QStringList dataType)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
return d->m_searchCotroller.setCustomResultDataType(customSearchType, dataType);
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QString customSearchType)
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchId = d->m_searchCotroller.refreshSearchId();
|
|
|
|
if(d->m_searchCotroller.getDataQueue() == nullptr) {
|
2023-03-15 16:39:38 +08:00
|
|
|
qWarning() << "the date queue has not been initialized, you need run init first!";
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.refreshDataqueue();
|
2023-03-15 16:39:38 +08:00
|
|
|
//plugin manager do async search here
|
2023-05-06 15:41:56 +08:00
|
|
|
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, searchtype, customSearchType)) {
|
2023-07-06 15:27:23 +08:00
|
|
|
Q_EMIT searchError(d->m_searchCotroller.getCurrentSearchId(), tr("Current task uuid error or an unregistered plugin is used!"));
|
2023-03-15 16:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return d->m_searchId;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::stop()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.stop();
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
2022-03-25 09:40:56 +08:00
|
|
|
|
2023-05-19 15:15:28 +08:00
|
|
|
bool UkuiSearchTask::isSearching(SearchProperty::SearchType searchtype, QString customSearchType)
|
|
|
|
{
|
|
|
|
return SearchTaskPluginManager::getInstance()->isSearching(d->m_uuid, searchtype, customSearchType);
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:40:56 +08:00
|
|
|
void UkuiSearchTask::clearAllConditions()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.clearAllConditions();
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::clearKeyWords()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.clearKeyWords();
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchTask::clearSearchDir()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.clearSearchDir();
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
|
|
|
|
2022-04-28 15:49:51 +08:00
|
|
|
void UkuiSearchTask::clearFileLabel()
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.clearFileLabel();
|
2022-04-28 15:49:51 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void UkuiSearchTask::setMaxResultNum(unsigned int maxResults)
|
2022-03-25 09:40:56 +08:00
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.setMaxResultNum(maxResults);
|
2022-03-25 09:40:56 +08:00
|
|
|
}
|
2023-05-19 15:15:28 +08:00
|
|
|
|
|
|
|
void UkuiSearchTask::setInformNum(int num)
|
|
|
|
{
|
2023-07-06 15:27:23 +08:00
|
|
|
d->m_searchCotroller.setInformNum(num);
|
2023-05-19 15:15:28 +08:00
|
|
|
}
|