Update search plugin interface, add stop search function.

This commit is contained in:
iaom 2022-02-12 14:20:55 +08:00
parent 2e668d374a
commit 655fe1ae9f
14 changed files with 67 additions and 6 deletions

View File

@ -31,9 +31,7 @@ SearchResultManager::SearchResultManager(const QString& plugin_id, QObject *pare
void SearchResultManager::startSearch(const QString &keyword) void SearchResultManager::startSearch(const QString &keyword)
{ {
//NEW_TODO 加锁?停止线程?重新搜索? qDebug()<<m_plugin_id<<"started";
// stopSearch();
qDebug()<<m_plugin_id<<"------------------>start by others";
if(! m_get_result_thread->isRunning()) { if(! m_get_result_thread->isRunning()) {
m_get_result_thread->start(); m_get_result_thread->start();
} }
@ -48,8 +46,10 @@ void SearchResultManager::startSearch(const QString &keyword)
void SearchResultManager::stopSearch() void SearchResultManager::stopSearch()
{ {
if(m_get_result_thread->isRunning()) { if(m_get_result_thread->isRunning()) {
qDebug()<<m_plugin_id<<"-------------->stopped by others"; qDebug()<<m_plugin_id<<"stopped";
m_get_result_thread->stop(); m_get_result_thread->stop();
SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id);
plugin->stopSearch();
// m_get_result_thread->quit(); // m_get_result_thread->quit();
} }
} }
@ -70,7 +70,6 @@ void ReceiveResultThread::stop()
this->quit(); this->quit();
} }
//NEW_TODO 还未对队列加锁
void ReceiveResultThread::run() void ReceiveResultThread::run()
{ {
QTimer * m_timer = new QTimer; QTimer * m_timer = new QTimer;
@ -86,7 +85,7 @@ void ReceiveResultThread::run()
} }
if(m_timer->isActive() && m_timer->remainingTime() < 0.01) { if(m_timer->isActive() && m_timer->remainingTime() < 0.01) {
this->requestInterruption(); this->requestInterruption();
qWarning()<<"-------------->stopped by self"; qWarning()<<"-------------->stopped by itself";
} }
if(is_empty && !m_timer->isActive()) { if(is_empty && !m_timer->isActive()) {
m_timer->start(); m_timer->start();

View File

@ -44,6 +44,13 @@ void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface
m_pool.start(appsearch); m_pool.start(appsearch);
} }
void AppSearchPlugin::stopSearch()
{
m_mutex.lock();
++uniqueSymbol;
m_mutex.unlock();
}
QList<SearchPluginIface::Actioninfo> AppSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> AppSearchPlugin::getActioninfo(int type)
{ {
switch (type) { switch (type) {

View File

@ -30,6 +30,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type); void openAction(int actionkey, QString key, int type);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);

View File

@ -49,6 +49,13 @@ void UkuiSearch::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resu
} }
} }
void FileSearchPlugin::stopSearch()
{
SearchManager::m_mutexFile.lock();
++SearchManager::uniqueSymbolFile;
SearchManager::m_mutexFile.unlock();
}
QList<SearchPluginIface::Actioninfo> FileSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> FileSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;
@ -250,6 +257,13 @@ void UkuiSearch::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resul
} }
} }
void DirSearchPlugin::stopSearch()
{
SearchManager::m_mutexDir.lock();
++SearchManager::uniqueSymbolDir;
SearchManager::m_mutexDir.unlock();
}
QList<SearchPluginIface::Actioninfo> DirSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> DirSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;
@ -423,6 +437,13 @@ void UkuiSearch::FileContengSearchPlugin::KeywordSearch(QString keyword, DataQue
} }
} }
void FileContengSearchPlugin::stopSearch()
{
SearchManager::m_mutexContent.lock();
++SearchManager::uniqueSymbolContent;
SearchManager::m_mutexContent.unlock();
}
QList<SearchPluginIface::Actioninfo> FileContengSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> FileContengSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;

View File

@ -31,6 +31,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0); void openAction(int actionkey, QString key, int type = 0);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);
@ -85,6 +86,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0); void openAction(int actionkey, QString key, int type = 0);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);
@ -138,6 +140,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0); void openAction(int actionkey, QString key, int type = 0);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);

View File

@ -57,6 +57,13 @@ void MailSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIfac
m_pool.start(mailSearch); m_pool.start(mailSearch);
} }
void MailSearchPlugin::stopSearch()
{
m_mutex.lock();
++uniqueSymbol;
m_mutex.unlock();
}
QList<SearchPluginIface::Actioninfo> MailSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> MailSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;

View File

@ -51,6 +51,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type); void openAction(int actionkey, QString key, int type);
QWidget *detailPage(const ResultInfo &ri); QWidget *detailPage(const ResultInfo &ri);

View File

@ -41,6 +41,13 @@ void NoteSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIfac
m_pool.start(ns); m_pool.start(ns);
} }
void NoteSearchPlugin::stopSearch()
{
g_mutex.lock();
++g_uniqueSymbol;
g_mutex.unlock();
}
QList<SearchPluginIface::Actioninfo> NoteSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> NoteSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;

View File

@ -39,6 +39,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type); void openAction(int actionkey, QString key, int type);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);

View File

@ -39,6 +39,7 @@ public:
virtual ~SearchPluginIface() {} virtual ~SearchPluginIface() {}
virtual QString getPluginName() = 0; virtual QString getPluginName() = 0;
virtual void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) = 0; virtual void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) = 0;
virtual void stopSearch() = 0;
virtual QList<Actioninfo> getActioninfo(int type) = 0; virtual QList<Actioninfo> getActioninfo(int type) = 0;
virtual void openAction(int actionkey, QString key, int type) = 0; virtual void openAction(int actionkey, QString key, int type) = 0;
// virtual bool isPreviewEnable(QString key, int type) = 0; // virtual bool isPreviewEnable(QString key, int type) = 0;

View File

@ -44,6 +44,13 @@ void UkuiSearch::SettingsSearchPlugin::KeywordSearch(QString keyword, DataQueue<
m_pool.start(settingSearch); m_pool.start(settingSearch);
} }
void SettingsSearchPlugin::stopSearch()
{
m_mutex.lock();
++m_uniqueSymbolForSettings;
m_mutex.unlock();
}
QList<SearchPluginIface::Actioninfo> SettingsSearchPlugin::getActioninfo(int type) QList<SearchPluginIface::Actioninfo> SettingsSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;

View File

@ -31,6 +31,7 @@ public:
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type); void openAction(int actionkey, QString key, int type);
// bool isPreviewEnable(QString key, int type); // bool isPreviewEnable(QString key, int type);

View File

@ -35,6 +35,10 @@ void UkuiSearch::WebSearchPlugin::KeywordSearch(QString keyword, DataQueue<UkuiS
searchResult->enqueue(resultInfo); searchResult->enqueue(resultInfo);
} }
void WebSearchPlugin::stopSearch()
{
}
QList<UkuiSearch::SearchPluginIface::Actioninfo> UkuiSearch::WebSearchPlugin::getActioninfo(int type) QList<UkuiSearch::SearchPluginIface::Actioninfo> UkuiSearch::WebSearchPlugin::getActioninfo(int type)
{ {
return m_actionInfo; return m_actionInfo;

View File

@ -28,6 +28,7 @@ public:
bool isEnable() {return m_enable;} bool isEnable() {return m_enable;}
QString getPluginName(); QString getPluginName();
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult); void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
void stopSearch();
QList<SearchPluginIface::Actioninfo> getActioninfo(int type); QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type); void openAction(int actionkey, QString key, int type);
QWidget *detailPage(const ResultInfo &ri); QWidget *detailPage(const ResultInfo &ri);