forked from openkylin/ukui-search
修复刚开机时应用搜索插件导致偶现卡死问题;优化搜索服务插件接口;优化搜索结果队列处理逻辑。
This commit is contained in:
parent
064c15471f
commit
f9f6fecd1d
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
*/
|
||||
#include "search-result-manager.h"
|
||||
#include <QDeadlineTimer>
|
||||
|
||||
using namespace UkuiSearch;
|
||||
SearchResultManager::SearchResultManager(const QString& plugin_id, QObject *parent) : QObject(parent)
|
||||
|
@ -71,24 +72,18 @@ void ReceiveResultThread::stop()
|
|||
|
||||
void ReceiveResultThread::run()
|
||||
{
|
||||
QTimer *timer = new QTimer;
|
||||
timer->setInterval(3000);
|
||||
|
||||
QDeadlineTimer deadline(3000);
|
||||
while(!isInterruptionRequested()) {
|
||||
SearchPluginIface::ResultInfo oneResult = m_resultQueue->tryDequeue();
|
||||
if(oneResult.name.isEmpty()) {
|
||||
if(!timer->isActive()) {
|
||||
timer->start();
|
||||
if(deadline.remainingTime()) {
|
||||
msleep(100);
|
||||
} else {
|
||||
this->requestInterruption();
|
||||
}
|
||||
msleep(100);
|
||||
} else {
|
||||
timer->stop();
|
||||
deadline.setRemainingTime(3000);
|
||||
Q_EMIT gotResultInfo(oneResult);
|
||||
}
|
||||
|
||||
if(timer->isActive() && timer->remainingTime() < 0.01 && m_resultQueue->isEmpty()) {
|
||||
this->requestInterruption();
|
||||
}
|
||||
}
|
||||
delete m_timer;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <qt5xdg/XdgIcon>
|
||||
#include <QDeadlineTimer>
|
||||
#include "file-utils.h"
|
||||
using namespace UkuiSearch;
|
||||
|
||||
|
@ -36,11 +37,6 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
|
|||
// m_pool.setMaxThreadCount(1);
|
||||
// m_pool.setExpiryTimeout(1000);
|
||||
initDetailPage();
|
||||
|
||||
m_timer = new QTimer;
|
||||
m_timer->setInterval(3000);
|
||||
m_timer->moveToThread(this);
|
||||
|
||||
m_appSearchResults = m_appSearchTask->init();
|
||||
m_appSearchTask->initSearchPlugin(SearchProperty::SearchType::Application);
|
||||
m_appSearchTask->setSearchOnlineApps(true);
|
||||
|
@ -56,11 +52,6 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
|
|||
AppSearchPlugin::~AppSearchPlugin()
|
||||
{
|
||||
this->wait();
|
||||
|
||||
if (m_timer) {
|
||||
delete m_timer;
|
||||
m_timer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const QString AppSearchPlugin::name()
|
||||
|
@ -182,18 +173,21 @@ QWidget *AppSearchPlugin::detailPage(const ResultInfo &ri)
|
|||
|
||||
void AppSearchPlugin::run()
|
||||
{
|
||||
QDeadlineTimer deadline(3000);
|
||||
while(!isInterruptionRequested()) {
|
||||
ResultItem oneResult = m_appSearchResults->tryDequeue();
|
||||
SearchResultPropertyMap data = oneResult.getAllValue();
|
||||
if(oneResult.getSearchId() == 0 && oneResult.getItemKey().isEmpty() && data.isEmpty()) {
|
||||
if(!m_timer->isActive()) {
|
||||
m_timer->start();
|
||||
if(deadline.remainingTime()) {
|
||||
msleep(100);
|
||||
} else {
|
||||
this->requestInterruption();
|
||||
}
|
||||
msleep(100);
|
||||
|
||||
} else {
|
||||
m_timer->stop();
|
||||
deadline.setRemainingTime(3000);
|
||||
SearchPluginIface::ResultInfo ri;
|
||||
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationDesktopPath).toString();
|
||||
|
||||
ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString();
|
||||
ri.icon = XdgIcon::fromTheme(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg"));
|
||||
SearchPluginIface::DescriptionInfo description;
|
||||
|
@ -203,13 +197,11 @@ void AppSearchPlugin::run()
|
|||
ri.type = data.value(SearchProperty::SearchResultProperty::IsOnlineApplication).toInt();
|
||||
if (ri.type == 1) {
|
||||
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationPkgName).toString();
|
||||
} else {
|
||||
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationDesktopPath).toString();
|
||||
}
|
||||
m_searchResult->enqueue(ri);
|
||||
}
|
||||
|
||||
if(m_timer->isActive() && m_timer->remainingTime() < 0.01 && m_appSearchResults->isEmpty()) {
|
||||
this->requestInterruption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
// bool isPreviewEnable(QString key, int type);
|
||||
// QWidget *previewPage(QString key, int type, QWidget *parent);
|
||||
QWidget *detailPage(const ResultInfo &ri);
|
||||
void run() override;
|
||||
void run();
|
||||
private:
|
||||
void initDetailPage();
|
||||
bool launch(const QString &path);
|
||||
|
@ -69,8 +69,6 @@ private:
|
|||
bool m_enable = true;
|
||||
QList<SearchPluginIface::Actioninfo> m_actionInfo_installed;
|
||||
QList<SearchPluginIface::Actioninfo> m_actionInfo_not_installed;
|
||||
// QThreadPool m_pool;
|
||||
QTimer *m_timer;
|
||||
|
||||
UkuiSearchTask *m_appSearchTask = nullptr;
|
||||
DataQueue<ResultItem>* m_appSearchResults = nullptr;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef SEARCHTASKPLUGINIFACE_H
|
||||
#define SEARCHTASKPLUGINIFACE_H
|
||||
#define SearchTaskPluginIface_iid "org.ukui.ukui-search.plugin-iface.SearchTaskPluginIface"
|
||||
#define SEARCH_TASK_PLUGIN_IFACE_VERSION "1.0.0"
|
||||
#define SEARCH_TASK_PLUGIN_IFACE_VERSION "1.1.0"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtPlugin>
|
||||
|
@ -34,10 +34,11 @@ class SearchTaskPluginIface : public QObject, public PluginInterface
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual void setController(const std::shared_ptr<SearchController> &searchController) = 0;
|
||||
virtual QString getCustomSearchType() = 0;
|
||||
virtual SearchProperty::SearchType getSearchType() = 0;
|
||||
//Asynchronous,multithread.
|
||||
virtual void startSearch(std::shared_ptr<SearchController> searchController) = 0;
|
||||
virtual void startSearch() = 0;
|
||||
virtual void stop() = 0;
|
||||
Q_SIGNALS:
|
||||
void searchFinished(size_t searchId);
|
||||
|
|
|
@ -88,7 +88,7 @@ void SearchTaskPluginManager::pluginSearch(SearchProperty::SearchType searchType
|
|||
return;
|
||||
}
|
||||
qDebug() << "start search";
|
||||
m_buildinPlugin.value(type)->startSearch(searchController);
|
||||
m_buildinPlugin.value(type)->startSearch();
|
||||
} else {
|
||||
Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is not registered!").arg(type));
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ void SearchTaskPluginManager::pluginSearch(QString customSearchType, std::shared
|
|||
Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is disabled!").arg(customSearchType));
|
||||
return;
|
||||
}
|
||||
m_loadedPlugin.value(customSearchType)->startSearch(searchController);
|
||||
m_loadedPlugin.value(customSearchType)->startSearch();
|
||||
} else {
|
||||
Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is not registered!").arg(customSearchType));
|
||||
}
|
||||
}
|
||||
|
||||
bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<SearchController> searchController, SearchProperty::SearchType searchType, const QString &customType)
|
||||
bool SearchTaskPluginManager::startSearch(const QUuid &uuid, SearchProperty::SearchType searchType, const QString &customType)
|
||||
{
|
||||
if (m_managedPlugins.contains(uuid)) {
|
||||
ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid);
|
||||
|
@ -121,7 +121,7 @@ bool SearchTaskPluginManager::startSearch(const QUuid &uuid, std::shared_ptr<Sea
|
|||
}
|
||||
|
||||
if (plugin) {
|
||||
plugin->startSearch(std::move(searchController));
|
||||
plugin->startSearch();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,8 @@ public:
|
|||
bool registerBuildinPlugin(SearchTaskPluginIface *plugin);
|
||||
void pluginSearch(SearchProperty::SearchType searchType, std::shared_ptr<SearchController> searchController);
|
||||
void pluginSearch(QString customSearchType, std::shared_ptr<SearchController> searchController);
|
||||
bool startSearch(const QUuid&, std::shared_ptr<SearchController>, SearchProperty::SearchType, const QString& customType = QString());
|
||||
bool startSearch(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
|
||||
void destroyPlugins(const QUuid& uuid);
|
||||
|
||||
SearchTaskPluginIface *getPlugin(SearchProperty::SearchType searchType, const QString& customType = QString());
|
||||
void registerPluginPath(const QString& customType, const QString& pluginPath);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -68,6 +66,7 @@ Q_SIGNALS:
|
|||
|
||||
private:
|
||||
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
||||
SearchTaskPluginIface *getPlugin(SearchProperty::SearchType searchType, const QString& customType = QString());
|
||||
|
||||
//这里初衷是把内外部插件分开管理,内部插件可以增加枚举值,外部插件似乎只能用编写者自定义的字符串区分?
|
||||
QHash<size_t, SearchTaskPluginIface*> m_buildinPlugin;
|
||||
|
|
|
@ -58,8 +58,7 @@ public:
|
|||
|
||||
private:
|
||||
void copyData();
|
||||
//TODO: 这里是否可以改为字节对齐的写法?
|
||||
// DataQueue<ResultItem>* m_dataQueue = nullptr ;
|
||||
|
||||
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataQueue = nullptr;
|
||||
size_t m_searchId = 0;
|
||||
QMutex m_searchIdMutex;
|
||||
|
|
|
@ -174,16 +174,19 @@ bool SearchControllerPrivate::isSearchOnlineApps()
|
|||
void SearchControllerPrivate::copyData()
|
||||
{
|
||||
if(m_formerController.get()) {
|
||||
m_searchId = m_formerController.get()->getCurrentSearchId();
|
||||
//所有子节点都有一个指向根节点的队列的智能指针
|
||||
m_sharedDataQueue = m_formerController.get()->d->m_sharedDataQueue;
|
||||
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();
|
||||
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_searchOnlineApps = m_formerController->d->m_searchOnlineApps;
|
||||
m_searchType2ResultProperties = m_formerController->d->m_searchType2ResultProperties;
|
||||
m_customSearchType2ResultDataType = m_formerController->d->m_customSearchType2ResultDataType;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ AppSearchTask::AppSearchTask(QObject *parent)
|
|||
this->setParent(parent);
|
||||
qRegisterMetaType<size_t>("size_t");
|
||||
m_pool = new QThreadPool(this);
|
||||
m_pool->setMaxThreadCount(1);
|
||||
m_pool->setMaxThreadCount(3);
|
||||
qDBusRegisterMetaType<QMap<QString, QString>>();
|
||||
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ AppSearchTask::~AppSearchTask()
|
|||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
void AppSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
||||
{
|
||||
m_searchController = searchController;
|
||||
}
|
||||
|
||||
const QString AppSearchTask::name()
|
||||
{
|
||||
return tr("Application");
|
||||
|
@ -57,11 +62,9 @@ QString AppSearchTask::getCustomSearchType()
|
|||
return "Application";
|
||||
}
|
||||
|
||||
void AppSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
|
||||
void AppSearchTask::startSearch()
|
||||
{
|
||||
m_searchController = searchController;
|
||||
AppSearchWorker *appSearchWorker;
|
||||
appSearchWorker = new AppSearchWorker(this);
|
||||
AppSearchWorker *appSearchWorker = new AppSearchWorker(this);
|
||||
m_pool->start(appSearchWorker);
|
||||
}
|
||||
|
||||
|
@ -74,23 +77,16 @@ void AppSearchTask::sendFinishSignal(size_t searchId)
|
|||
Q_EMIT searchFinished(searchId);
|
||||
}
|
||||
|
||||
|
||||
AppSearchWorker::AppSearchWorker(AppSearchTask *AppSarchTask): m_appSearchTask(AppSarchTask)
|
||||
{
|
||||
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
|
||||
"com.kylin.getsearchresults",
|
||||
QDBusConnection::sessionBus());
|
||||
if(!m_interFace->isValid()) {
|
||||
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
||||
}
|
||||
m_interFace->setTimeout(1500);
|
||||
m_currentSearchId = m_appSearchTask->m_searchController->getCurrentSearchId();
|
||||
m_controller = new SearchController(m_appSearchTask->m_searchController);
|
||||
m_currentSearchId = m_controller->getCurrentSearchId();
|
||||
}
|
||||
|
||||
void AppSearchWorker::run()
|
||||
{
|
||||
ApplicationProperties applicationProperties;
|
||||
SearchResultProperties properties = m_appSearchTask->m_searchController->getResultProperties(SearchProperty::SearchType::Application);
|
||||
SearchResultProperties properties = m_controller->getResultProperties(SearchProperty::SearchType::Application);
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationDesktopPath)) {
|
||||
applicationProperties.append(ApplicationProperty::DesktopFilePath);
|
||||
}
|
||||
|
@ -100,9 +96,9 @@ void AppSearchWorker::run()
|
|||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationIconName)) {
|
||||
applicationProperties.append(ApplicationProperty::Icon);
|
||||
}
|
||||
ApplicationInfoMap data = m_appSearchTask->m_appinfo.searchApp(applicationProperties, m_appSearchTask->m_searchController->getKeyword(), ApplicationPropertyMap{{ApplicationProperty::DontDisplay, 0}, {ApplicationProperty::AutoStart, 0}});
|
||||
ApplicationInfoMap data = m_appSearchTask->m_appinfo.searchApp(applicationProperties, m_controller->getKeyword(), ApplicationPropertyMap{{ApplicationProperty::DontDisplay, 0}, {ApplicationProperty::AutoStart, 0}});
|
||||
for (const QString &desktop : data.keys()) {
|
||||
if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
if (m_controller->beginSearchIdCheck(m_currentSearchId)) {
|
||||
ResultItem item(desktop);
|
||||
item.setSearchId(m_currentSearchId);
|
||||
|
||||
|
@ -116,21 +112,27 @@ void AppSearchWorker::run()
|
|||
if(oneResult.contains(ApplicationProperty::Icon)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::ApplicationIconName, oneResult.value(ApplicationProperty::Icon).toString());
|
||||
}
|
||||
m_appSearchTask->m_searchController->getDataQueue()->enqueue(item);
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
m_controller->getDataQueue()->enqueue(item);
|
||||
m_controller->finishSearchIdCheck();
|
||||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
m_controller->finishSearchIdCheck();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (m_appSearchTask->m_searchController->isSearchOnlineApps()) {
|
||||
if (m_controller->isSearchOnlineApps()) {
|
||||
//online app search
|
||||
for (auto keyword : m_appSearchTask->m_searchController->getKeyword()) {
|
||||
QDBusReply<QList<QMap<QString, QString>>> reply = m_interFace->call("get_search_result", keyword); //阻塞,直到远程方法调用完成。
|
||||
for (auto keyword : m_controller->getKeyword()) {
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("com.kylin.softwarecenter.getsearchresults"),
|
||||
QStringLiteral("/com/kylin/softwarecenter/getsearchresults"),
|
||||
QStringLiteral("com.kylin.getsearchresults"),
|
||||
QStringLiteral("get_search_result"));
|
||||
msg.setArguments({keyword});
|
||||
QDBusReply<QList<QMap<QString, QString>>> reply = QDBusConnection::sessionBus().call(msg, QDBus::Block, 1500);
|
||||
if(reply.isValid()) {
|
||||
// qDebug() << reply.value();
|
||||
for(int i = 0; i < reply.value().size(); i++) {
|
||||
if (m_appSearchTask->m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||
if (m_controller->beginSearchIdCheck(m_currentSearchId)) {
|
||||
ResultItem item(m_currentSearchId);
|
||||
item.setItemKey(reply.value().at(i).value("appname"));
|
||||
if(properties.contains(SearchProperty::SearchResultProperty::ApplicationPkgName)) {
|
||||
|
@ -155,11 +157,11 @@ void AppSearchWorker::run()
|
|||
if(properties.contains(SearchProperty::SearchResultProperty::IsOnlineApplication)) {
|
||||
item.setValue(SearchProperty::SearchResultProperty::IsOnlineApplication, 1);
|
||||
}
|
||||
m_appSearchTask->m_searchController->getDataQueue()->enqueue(item);
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
m_controller->getDataQueue()->enqueue(item);
|
||||
m_controller->finishSearchIdCheck();
|
||||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_appSearchTask->m_searchController->finishSearchIdCheck();
|
||||
m_controller->finishSearchIdCheck();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -175,9 +177,10 @@ void AppSearchWorker::run()
|
|||
|
||||
AppSearchWorker::~AppSearchWorker()
|
||||
{
|
||||
if (m_interFace)
|
||||
delete m_interFace;
|
||||
m_interFace = nullptr;
|
||||
if(m_controller) {
|
||||
delete m_controller;
|
||||
m_controller = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void AppSearchWorker::sendErrorMsg(const QString &msg)
|
||||
|
|
|
@ -37,8 +37,9 @@ class AppSearchTask : public SearchTaskPluginIface
|
|||
friend class AppSearchWorker;
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppSearchTask(QObject *parent);
|
||||
explicit AppSearchTask(QObject *parent = nullptr);
|
||||
~AppSearchTask();
|
||||
void setController(const std::shared_ptr<SearchController> &searchController);
|
||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
|
@ -48,7 +49,7 @@ public:
|
|||
|
||||
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::Application;}
|
||||
QString getCustomSearchType();
|
||||
void startSearch(std::shared_ptr<SearchController> searchController);
|
||||
void startSearch();
|
||||
void stop();
|
||||
Q_INVOKABLE void sendFinishSignal(size_t searchId);
|
||||
|
||||
|
@ -62,17 +63,16 @@ class AppSearchWorker : public QRunnable
|
|||
{
|
||||
public:
|
||||
explicit AppSearchWorker(AppSearchTask *AppSarchTask);
|
||||
|
||||
~AppSearchWorker();
|
||||
protected:
|
||||
void run();
|
||||
|
||||
private:
|
||||
~AppSearchWorker();
|
||||
void sendErrorMsg(const QString &msg);
|
||||
|
||||
private:
|
||||
SearchController* m_controller = nullptr;
|
||||
AppSearchTask *m_appSearchTask = nullptr;
|
||||
QDBusInterface *m_interFace = nullptr;
|
||||
size_t m_currentSearchId = 0;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ FileContentSearchTask::~FileContentSearchTask()
|
|||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
void FileContentSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
||||
{
|
||||
m_searchController = searchController;
|
||||
}
|
||||
|
||||
PluginInterface::PluginType FileContentSearchTask::pluginType()
|
||||
{
|
||||
return PluginType::SearchTaskPlugin;
|
||||
|
@ -87,9 +92,9 @@ SearchProperty::SearchType FileContentSearchTask::getSearchType()
|
|||
return SearchProperty::SearchType::FileContent;
|
||||
}
|
||||
|
||||
void FileContentSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
|
||||
void FileContentSearchTask::startSearch()
|
||||
{
|
||||
FileContentSearchWorker *worker = new FileContentSearchWorker(this, searchController);
|
||||
FileContentSearchWorker *worker = new FileContentSearchWorker(this, m_searchController);
|
||||
m_pool->start(worker);
|
||||
}
|
||||
|
||||
|
@ -101,10 +106,18 @@ void FileContentSearchTask::stop()
|
|||
FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController)
|
||||
{
|
||||
m_fileContentSearchTask = fileContentSearchTask;
|
||||
m_searchController = std::move(searchController);
|
||||
m_searchController = new SearchController(searchController);
|
||||
m_currentSearchId = m_searchController->getCurrentSearchId();
|
||||
}
|
||||
|
||||
FileContentSearchWorker::~FileContentSearchWorker()
|
||||
{
|
||||
if(m_searchController) {
|
||||
delete m_searchController;
|
||||
m_searchController = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void FileContentSearchWorker::run()
|
||||
{
|
||||
QStringList searchDirs = m_searchController->getSearchDir();
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
explicit FileContentSearchTask(QObject *parent = nullptr);
|
||||
|
||||
~FileContentSearchTask() override;
|
||||
|
||||
void setController(const std::shared_ptr<SearchController> &searchController) override;
|
||||
PluginType pluginType() override;
|
||||
const QString name() override;
|
||||
const QString description() override;
|
||||
|
@ -49,12 +49,13 @@ public:
|
|||
|
||||
QString getCustomSearchType() override;
|
||||
SearchProperty::SearchType getSearchType() override;
|
||||
void startSearch(std::shared_ptr<SearchController> searchController) override;
|
||||
void startSearch() override;
|
||||
void stop() override;
|
||||
|
||||
private:
|
||||
QThreadPool *m_pool = nullptr;
|
||||
bool m_enable = true;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
};
|
||||
|
||||
class FileContentSearchWorker : public QRunnable
|
||||
|
@ -63,6 +64,7 @@ class FileContentSearchWorker : public QRunnable
|
|||
|
||||
public:
|
||||
explicit FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr<SearchController> searchController);
|
||||
~FileContentSearchWorker();
|
||||
|
||||
void run() override;
|
||||
|
||||
|
@ -74,7 +76,7 @@ private:
|
|||
|
||||
private:
|
||||
FileContentSearchTask *m_fileContentSearchTask = nullptr;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
SearchController *m_searchController = nullptr;
|
||||
|
||||
QStringList m_validDirectories;
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@ FileSearchTask::~FileSearchTask()
|
|||
m_pool->waitForDone();
|
||||
}
|
||||
|
||||
void FileSearchTask::setController(const std::shared_ptr<SearchController> &searchController)
|
||||
{
|
||||
m_searchController = searchController;
|
||||
}
|
||||
|
||||
const QString FileSearchTask::name()
|
||||
{
|
||||
return "File";
|
||||
|
@ -61,10 +66,10 @@ QString FileSearchTask::getCustomSearchType()
|
|||
return "File";
|
||||
}
|
||||
|
||||
void FileSearchTask::startSearch(std::shared_ptr<SearchController> searchController)
|
||||
void FileSearchTask::startSearch()
|
||||
{
|
||||
FileSearchWorker *fileSearchWorker;
|
||||
fileSearchWorker = new FileSearchWorker(this, searchController);
|
||||
fileSearchWorker = new FileSearchWorker(this, m_searchController);
|
||||
m_pool->start(fileSearchWorker);
|
||||
}
|
||||
|
||||
|
@ -79,11 +84,20 @@ void FileSearchTask::sendFinishSignal(size_t searchId)
|
|||
}
|
||||
|
||||
|
||||
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController) : m_FileSearchTask(fileSarchTask), m_searchController(searchController)
|
||||
FileSearchWorker::FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController) : m_FileSearchTask(fileSarchTask)
|
||||
{
|
||||
m_searchController = new SearchController(searchController);
|
||||
m_currentSearchId = m_searchController->getCurrentSearchId();
|
||||
}
|
||||
|
||||
FileSearchWorker::~FileSearchWorker()
|
||||
{
|
||||
if(m_searchController) {
|
||||
delete m_searchController;
|
||||
m_searchController = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void FileSearchWorker::run()
|
||||
{
|
||||
//1.检查是否为不可搜索目录
|
||||
|
|
|
@ -36,6 +36,8 @@ class FileSearchTask : public SearchTaskPluginIface
|
|||
public:
|
||||
explicit FileSearchTask(QObject *parent);
|
||||
~FileSearchTask();
|
||||
|
||||
void setController(const std::shared_ptr<SearchController> &searchController);
|
||||
PluginType pluginType() {return PluginType::SearchTaskPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
|
@ -45,12 +47,13 @@ public:
|
|||
|
||||
SearchProperty::SearchType getSearchType() {return SearchProperty::SearchType::File;}
|
||||
QString getCustomSearchType();
|
||||
void startSearch(std::shared_ptr<SearchController> searchController);
|
||||
void startSearch();
|
||||
void stop();
|
||||
Q_INVOKABLE void sendFinishSignal(size_t searchId);
|
||||
|
||||
private:
|
||||
QThreadPool *m_pool = nullptr;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
};
|
||||
|
||||
class FileSearchWorker : public QRunnable
|
||||
|
@ -59,6 +62,7 @@ class FileSearchWorker : public QRunnable
|
|||
|
||||
public:
|
||||
explicit FileSearchWorker(FileSearchTask *fileSarchTask, std::shared_ptr<SearchController> searchController);
|
||||
~FileSearchWorker();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
@ -78,7 +82,7 @@ private:
|
|||
|
||||
private:
|
||||
FileSearchTask *m_FileSearchTask;
|
||||
std::shared_ptr<SearchController> m_searchController;
|
||||
SearchController *m_searchController = nullptr;
|
||||
|
||||
size_t m_currentSearchId = 0;
|
||||
QStringList m_validDirectories;
|
||||
|
|
|
@ -70,6 +70,7 @@ void UkuiSearchTask::initSearchPlugin(SearchProperty::SearchType searchType, con
|
|||
{
|
||||
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);
|
||||
} else {
|
||||
|
@ -96,7 +97,7 @@ size_t UkuiSearchTask::startSearch(SearchProperty::SearchType searchtype, QStrin
|
|||
|
||||
d->m_searchCotroller->refreshDataqueue();
|
||||
//plugin manager do async search here
|
||||
if (!SearchTaskPluginManager::getInstance()->startSearch(d->m_uuid, d->m_searchCotroller, searchtype, customSearchType)) {
|
||||
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!"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue