From 655fe1ae9f8440e3f9f7227475bfade0d096c320 Mon Sep 17 00:00:00 2001 From: iaom Date: Sat, 12 Feb 2022 14:20:55 +0800 Subject: [PATCH] Update search plugin interface, add stop search function. --- frontend/model/search-result-manager.cpp | 11 +++++----- libsearch/appsearch/app-search-plugin.cpp | 7 +++++++ libsearch/appsearch/app-search-plugin.h | 1 + libsearch/index/file-search-plugin.cpp | 21 +++++++++++++++++++ libsearch/index/file-search-plugin.h | 3 +++ libsearch/mailsearch/mail-search-plugin.cpp | 7 +++++++ libsearch/mailsearch/mail-search-plugin.h | 1 + libsearch/notesearch/note-search-plugin.cpp | 7 +++++++ libsearch/notesearch/note-search-plugin.h | 1 + .../plugininterface/search-plugin-iface.h | 1 + .../settingsearch/settings-search-plugin.cpp | 7 +++++++ .../settingsearch/settings-search-plugin.h | 1 + libsearch/websearch/web-search-plugin.cpp | 4 ++++ libsearch/websearch/web-search-plugin.h | 1 + 14 files changed, 67 insertions(+), 6 deletions(-) diff --git a/frontend/model/search-result-manager.cpp b/frontend/model/search-result-manager.cpp index ea36eed..1ac4a63 100644 --- a/frontend/model/search-result-manager.cpp +++ b/frontend/model/search-result-manager.cpp @@ -31,9 +31,7 @@ SearchResultManager::SearchResultManager(const QString& plugin_id, QObject *pare void SearchResultManager::startSearch(const QString &keyword) { - //NEW_TODO 加锁?停止线程?重新搜索? -// stopSearch(); - qDebug()<start by others"; + qDebug()<isRunning()) { m_get_result_thread->start(); } @@ -48,8 +46,10 @@ void SearchResultManager::startSearch(const QString &keyword) void SearchResultManager::stopSearch() { if(m_get_result_thread->isRunning()) { - qDebug()<stopped by others"; + qDebug()<stop(); + SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id); + plugin->stopSearch(); // m_get_result_thread->quit(); } } @@ -70,7 +70,6 @@ void ReceiveResultThread::stop() this->quit(); } -//NEW_TODO 还未对队列加锁 void ReceiveResultThread::run() { QTimer * m_timer = new QTimer; @@ -86,7 +85,7 @@ void ReceiveResultThread::run() } if(m_timer->isActive() && m_timer->remainingTime() < 0.01) { this->requestInterruption(); - qWarning()<<"-------------->stopped by self"; + qWarning()<<"-------------->stopped by itself"; } if(is_empty && !m_timer->isActive()) { m_timer->start(); diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 149cc6e..39142a5 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -44,6 +44,13 @@ void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue AppSearchPlugin::getActioninfo(int type) { switch (type) { diff --git a/libsearch/appsearch/app-search-plugin.h b/libsearch/appsearch/app-search-plugin.h index 8d98243..2b34c2e 100644 --- a/libsearch/appsearch/app-search-plugin.h +++ b/libsearch/appsearch/app-search-plugin.h @@ -30,6 +30,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type); // bool isPreviewEnable(QString key, int type); diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index 6e86f8c..d76c93d 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -49,6 +49,13 @@ void UkuiSearch::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue FileSearchPlugin::getActioninfo(int type) { return m_actionInfo; @@ -250,6 +257,13 @@ void UkuiSearch::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue DirSearchPlugin::getActioninfo(int type) { 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 FileContengSearchPlugin::getActioninfo(int type) { return m_actionInfo; diff --git a/libsearch/index/file-search-plugin.h b/libsearch/index/file-search-plugin.h index 6c37f1b..762e6b8 100644 --- a/libsearch/index/file-search-plugin.h +++ b/libsearch/index/file-search-plugin.h @@ -31,6 +31,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type = 0); // bool isPreviewEnable(QString key, int type); @@ -85,6 +86,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type = 0); // bool isPreviewEnable(QString key, int type); @@ -138,6 +140,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type = 0); // bool isPreviewEnable(QString key, int type); diff --git a/libsearch/mailsearch/mail-search-plugin.cpp b/libsearch/mailsearch/mail-search-plugin.cpp index cd3e661..e4df9e1 100644 --- a/libsearch/mailsearch/mail-search-plugin.cpp +++ b/libsearch/mailsearch/mail-search-plugin.cpp @@ -57,6 +57,13 @@ void MailSearchPlugin::KeywordSearch(QString keyword, DataQueue MailSearchPlugin::getActioninfo(int type) { return m_actionInfo; diff --git a/libsearch/mailsearch/mail-search-plugin.h b/libsearch/mailsearch/mail-search-plugin.h index 9a65bea..dad6f84 100644 --- a/libsearch/mailsearch/mail-search-plugin.h +++ b/libsearch/mailsearch/mail-search-plugin.h @@ -51,6 +51,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword, DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type); QWidget *detailPage(const ResultInfo &ri); diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index 74ebac8..161a655 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -41,6 +41,13 @@ void NoteSearchPlugin::KeywordSearch(QString keyword, DataQueue NoteSearchPlugin::getActioninfo(int type) { return m_actionInfo; diff --git a/libsearch/notesearch/note-search-plugin.h b/libsearch/notesearch/note-search-plugin.h index 2f3f413..f057436 100644 --- a/libsearch/notesearch/note-search-plugin.h +++ b/libsearch/notesearch/note-search-plugin.h @@ -39,6 +39,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type); // bool isPreviewEnable(QString key, int type); diff --git a/libsearch/plugininterface/search-plugin-iface.h b/libsearch/plugininterface/search-plugin-iface.h index 0ca9315..2d17ced 100644 --- a/libsearch/plugininterface/search-plugin-iface.h +++ b/libsearch/plugininterface/search-plugin-iface.h @@ -39,6 +39,7 @@ public: virtual ~SearchPluginIface() {} virtual QString getPluginName() = 0; virtual void KeywordSearch(QString keyword,DataQueue *searchResult) = 0; + virtual void stopSearch() = 0; virtual QList getActioninfo(int type) = 0; virtual void openAction(int actionkey, QString key, int type) = 0; // virtual bool isPreviewEnable(QString key, int type) = 0; diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index 310891a..fbe665c 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -44,6 +44,13 @@ void UkuiSearch::SettingsSearchPlugin::KeywordSearch(QString keyword, DataQueue< m_pool.start(settingSearch); } +void SettingsSearchPlugin::stopSearch() +{ + m_mutex.lock(); + ++m_uniqueSymbolForSettings; + m_mutex.unlock(); +} + QList SettingsSearchPlugin::getActioninfo(int type) { return m_actionInfo; diff --git a/libsearch/settingsearch/settings-search-plugin.h b/libsearch/settingsearch/settings-search-plugin.h index dd3eaa0..3bec896 100644 --- a/libsearch/settingsearch/settings-search-plugin.h +++ b/libsearch/settingsearch/settings-search-plugin.h @@ -31,6 +31,7 @@ public: QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type); // bool isPreviewEnable(QString key, int type); diff --git a/libsearch/websearch/web-search-plugin.cpp b/libsearch/websearch/web-search-plugin.cpp index 269170a..64f1718 100644 --- a/libsearch/websearch/web-search-plugin.cpp +++ b/libsearch/websearch/web-search-plugin.cpp @@ -35,6 +35,10 @@ void UkuiSearch::WebSearchPlugin::KeywordSearch(QString keyword, DataQueueenqueue(resultInfo); } +void WebSearchPlugin::stopSearch() +{ +} + QList UkuiSearch::WebSearchPlugin::getActioninfo(int type) { return m_actionInfo; diff --git a/libsearch/websearch/web-search-plugin.h b/libsearch/websearch/web-search-plugin.h index 28107c8..5790411 100644 --- a/libsearch/websearch/web-search-plugin.h +++ b/libsearch/websearch/web-search-plugin.h @@ -28,6 +28,7 @@ public: bool isEnable() {return m_enable;} QString getPluginName(); void KeywordSearch(QString keyword,DataQueue *searchResult); + void stopSearch(); QList getActioninfo(int type); void openAction(int actionkey, QString key, int type); QWidget *detailPage(const ResultInfo &ri);