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