Optimize the result queue logic of app search plugin.
This commit is contained in:
parent
e73366e7f0
commit
4fdc102102
|
@ -4,8 +4,7 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include "file-utils.h"
|
#include "file-utils.h"
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
size_t AppSearchPlugin::uniqueSymbol = 0;
|
|
||||||
QMutex AppSearchPlugin::m_mutex;
|
|
||||||
AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearchTask(new UkuiSearchTask(this))
|
AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearchTask(new UkuiSearchTask(this))
|
||||||
{
|
{
|
||||||
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
||||||
|
@ -21,12 +20,6 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
|
||||||
m_timer = new QTimer;
|
m_timer = new QTimer;
|
||||||
m_timer->setInterval(3000);
|
m_timer->setInterval(3000);
|
||||||
m_timer->moveToThread(this);
|
m_timer->moveToThread(this);
|
||||||
connect(this, SIGNAL(startTimer()), m_timer, SLOT(start()));
|
|
||||||
connect(this, &AppSearchPlugin::stopTimer, m_timer, &QTimer::stop);
|
|
||||||
connect(m_timer, &QTimer::timeout, this, [ & ]{
|
|
||||||
qWarning() << "The app-search thread stopped because of timeout.";
|
|
||||||
this->quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
m_appSearchResults = m_appSearchTask->init();
|
m_appSearchResults = m_appSearchTask->init();
|
||||||
m_appSearchTask->initSearchPlugin(SearchType::Application);
|
m_appSearchTask->initSearchPlugin(SearchType::Application);
|
||||||
|
@ -36,37 +29,13 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearch
|
||||||
UkuiSearch::ApplicationIconName |
|
UkuiSearch::ApplicationIconName |
|
||||||
UkuiSearch::ApplicationDescription |
|
UkuiSearch::ApplicationDescription |
|
||||||
UkuiSearch::IsOnlineApplication);
|
UkuiSearch::IsOnlineApplication);
|
||||||
|
|
||||||
connect(m_appSearchTask, &UkuiSearchTask::searchFinished, this, [ & ] {
|
|
||||||
if (m_timer->isActive()) {
|
|
||||||
Q_EMIT this->stopTimer();
|
|
||||||
m_timer->setInterval(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(!m_appSearchResults->isEmpty()) {
|
|
||||||
ResultItem oneResult = m_appSearchResults->dequeue();
|
|
||||||
SearchPluginIface::ResultInfo ri;
|
|
||||||
ri.actionKey = oneResult.getExtral().at(0).toString();
|
|
||||||
ri.name = oneResult.getExtral().at(1).toString();
|
|
||||||
ri.icon = oneResult.getExtral().at(2).value<QIcon>();
|
|
||||||
SearchPluginIface::DescriptionInfo description;
|
|
||||||
description.key = QString(tr("Application Description:"));
|
|
||||||
description.value = oneResult.getExtral().at(3).toString();
|
|
||||||
ri.description.append(description);
|
|
||||||
ri.type = oneResult.getExtral().at(4).toInt();
|
|
||||||
m_searchResult->enqueue(ri);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!m_timer->isActive()) {
|
|
||||||
Q_EMIT this->startTimer();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSearchPlugin::~AppSearchPlugin()
|
AppSearchPlugin::~AppSearchPlugin()
|
||||||
{
|
{
|
||||||
this->quit();
|
this->quit();
|
||||||
this->wait();
|
this->wait();
|
||||||
|
|
||||||
if (m_timer) {
|
if (m_timer) {
|
||||||
delete m_timer;
|
delete m_timer;
|
||||||
m_timer = nullptr;
|
m_timer = nullptr;
|
||||||
|
@ -90,10 +59,6 @@ QString AppSearchPlugin::getPluginName()
|
||||||
|
|
||||||
void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface::ResultInfo> *searchResult)
|
void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface::ResultInfo> *searchResult)
|
||||||
{
|
{
|
||||||
m_mutex.lock();
|
|
||||||
++uniqueSymbol;
|
|
||||||
m_mutex.unlock();
|
|
||||||
|
|
||||||
if (!this->isRunning()) {
|
if (!this->isRunning()) {
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
|
@ -108,9 +73,7 @@ void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface
|
||||||
|
|
||||||
void AppSearchPlugin::stopSearch()
|
void AppSearchPlugin::stopSearch()
|
||||||
{
|
{
|
||||||
m_mutex.lock();
|
m_appSearchTask->stop();
|
||||||
++uniqueSymbol;
|
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<SearchPluginIface::Actioninfo> AppSearchPlugin::getActioninfo(int type)
|
QList<SearchPluginIface::Actioninfo> AppSearchPlugin::getActioninfo(int type)
|
||||||
|
@ -198,7 +161,36 @@ QWidget *AppSearchPlugin::detailPage(const ResultInfo &ri)
|
||||||
|
|
||||||
void AppSearchPlugin::run()
|
void AppSearchPlugin::run()
|
||||||
{
|
{
|
||||||
exec();
|
m_timer->setInterval(3000);
|
||||||
|
while (!isInterruptionRequested()) {
|
||||||
|
if (m_appSearchResults->isEmpty()) {
|
||||||
|
if (!m_timer->isActive()) {
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_timer->isActive()) {
|
||||||
|
m_timer->stop();
|
||||||
|
}
|
||||||
|
ResultItem oneResult = m_appSearchResults->dequeue();
|
||||||
|
SearchPluginIface::ResultInfo ri;
|
||||||
|
ri.actionKey = oneResult.getExtral().at(0).toString();
|
||||||
|
ri.name = oneResult.getExtral().at(1).toString();
|
||||||
|
ri.icon = oneResult.getExtral().at(2).value<QIcon>();
|
||||||
|
SearchPluginIface::DescriptionInfo description;
|
||||||
|
description.key = QString(tr("Application Description:"));
|
||||||
|
description.value = oneResult.getExtral().at(3).toString();
|
||||||
|
ri.description.append(description);
|
||||||
|
ri.type = oneResult.getExtral().at(4).toInt();
|
||||||
|
m_searchResult->enqueue(ri);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_timer->isActive() && m_timer->remainingTime() < 0.01) {
|
||||||
|
m_timer->setInterval(3000);
|
||||||
|
this->requestInterruption();
|
||||||
|
}
|
||||||
|
|
||||||
|
msleep(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppSearchPlugin::initDetailPage()
|
void AppSearchPlugin::initDetailPage()
|
||||||
|
@ -308,6 +300,7 @@ bool AppSearchPlugin::launch(const QString &path)
|
||||||
g_object_unref(desktopAppInfo);
|
g_object_unref(desktopAppInfo);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppSearchPlugin::addPanelShortcut(const QString& path) {
|
bool AppSearchPlugin::addPanelShortcut(const QString& path) {
|
||||||
QDBusInterface iface("com.ukui.panel.desktop",
|
QDBusInterface iface("com.ukui.panel.desktop",
|
||||||
"/",
|
"/",
|
||||||
|
|
|
@ -52,8 +52,6 @@ private:
|
||||||
QList<SearchPluginIface::Actioninfo> m_actionInfo_not_installed;
|
QList<SearchPluginIface::Actioninfo> m_actionInfo_not_installed;
|
||||||
// QThreadPool m_pool;
|
// QThreadPool m_pool;
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
static size_t uniqueSymbol;
|
|
||||||
static QMutex m_mutex;
|
|
||||||
|
|
||||||
UkuiSearchTask *m_appSearchTask = nullptr;
|
UkuiSearchTask *m_appSearchTask = nullptr;
|
||||||
DataQueue<ResultItem>* m_appSearchResults = nullptr;
|
DataQueue<ResultItem>* m_appSearchResults = nullptr;
|
||||||
|
@ -80,9 +78,6 @@ private:
|
||||||
ActionLabel *m_actionLabel4 = nullptr;
|
ActionLabel *m_actionLabel4 = nullptr;
|
||||||
|
|
||||||
QVBoxLayout * m_actionLyt = nullptr;
|
QVBoxLayout * m_actionLyt = nullptr;
|
||||||
Q_SIGNALS:
|
|
||||||
void startTimer();
|
|
||||||
void stopTimer();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//class AppSearch : public QObject, public QRunnable {
|
//class AppSearch : public QObject, public QRunnable {
|
||||||
|
|
Loading…
Reference in New Issue