diff --git a/libsearch/plugininterface/search-task-plugin-iface.h b/libsearch/plugininterface/search-task-plugin-iface.h index c905355..24ee89f 100644 --- a/libsearch/plugininterface/search-task-plugin-iface.h +++ b/libsearch/plugininterface/search-task-plugin-iface.h @@ -21,6 +21,7 @@ public: virtual void stop() = 0; Q_SIGNALS: void searchFinished(size_t searchId); + void searchError(size_t searchId, QString msg = {}); }; } Q_DECLARE_INTERFACE(UkuiSearch::SearchTaskPluginIface, SearchTaskPluginIface_iid) diff --git a/libsearch/pluginmanage/search-task-plugin-manager.cpp b/libsearch/pluginmanage/search-task-plugin-manager.cpp index 19e21ef..7867137 100644 --- a/libsearch/pluginmanage/search-task-plugin-manager.cpp +++ b/libsearch/pluginmanage/search-task-plugin-manager.cpp @@ -39,6 +39,7 @@ bool SearchTaskPluginManager::registerPlugin(SearchTaskPluginIface *plugin) } m_loadedPlugin.insert(plugin->getCustomSearchType(), plugin); connect(plugin, &SearchTaskPluginIface::searchFinished, this, &SearchTaskPluginManager::searchFinished); + connect(plugin, &SearchTaskPluginIface::searchError, this, &SearchTaskPluginManager::searchError); return true; } @@ -46,6 +47,7 @@ bool SearchTaskPluginManager::registerBuildinPlugin(SearchTaskPluginIface *plugi { m_buildinPlugin.insert(static_cast(plugin->getSearchType()), plugin); connect(plugin, &SearchTaskPluginIface::searchFinished, this, &SearchTaskPluginManager::searchFinished); + connect(plugin, &SearchTaskPluginIface::searchError, this, &SearchTaskPluginManager::searchError); return true; } @@ -59,11 +61,13 @@ void SearchTaskPluginManager::pluginSearch(SearchType searchType, std::shared_pt qDebug() << "search type" << type; if(m_buildinPlugin.contains(type)) { if(!m_buildinPlugin.value(type)->isEnable()) { - Q_EMIT this->pluginDisable(searchController.get()->getCurrentSearchId()); + Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is disabled!").arg(type)); return; } qDebug() << "start search"; m_buildinPlugin.value(type)->startSearch(searchController); + } else { + Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is not registered!").arg(type)); } } @@ -71,9 +75,11 @@ void SearchTaskPluginManager::pluginSearch(QString customSearchType, std::shared { if(m_loadedPlugin.contains(customSearchType)) { if(!m_loadedPlugin.value(customSearchType)->isEnable()) { - Q_EMIT this->pluginDisable(searchController.get()->getCurrentSearchId()); + Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is disabled!").arg(customSearchType)); return; } m_loadedPlugin.value(customSearchType)->startSearch(searchController); + } else { + Q_EMIT this->searchError(searchController.get()->getCurrentSearchId(), tr("plugin type: %1, is not registered!").arg(customSearchType)); } } diff --git a/libsearch/pluginmanage/search-task-plugin-manager.h b/libsearch/pluginmanage/search-task-plugin-manager.h index 0c6f751..d94087f 100644 --- a/libsearch/pluginmanage/search-task-plugin-manager.h +++ b/libsearch/pluginmanage/search-task-plugin-manager.h @@ -17,7 +17,8 @@ public: void pluginSearch(QString customSearchType, std::shared_ptr searchController); Q_SIGNALS: void searchFinished(size_t searchId); - void pluginDisable(size_t searchId); + void searchError(size_t searchId, QString msg); + private: explicit SearchTaskPluginManager(QObject *parent = nullptr); diff --git a/libsearch/searchinterface/searchtasks/file-content-search-task.cpp b/libsearch/searchinterface/searchtasks/file-content-search-task.cpp index c6507c3..ea9e272 100644 --- a/libsearch/searchinterface/searchtasks/file-content-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-content-search-task.cpp @@ -81,11 +81,6 @@ void FileContentSearchTask::stop() } -void FileContentSearchTask::sendFinishSignal(size_t searchId) -{ - Q_EMIT sendFinishSignal(searchId); -} - FileContentSearchWorker::FileContentSearchWorker(FileContentSearchTask *fileContentSearchTask, std::shared_ptr searchController) { m_fileContentSearchTask = fileContentSearchTask; @@ -114,11 +109,21 @@ void FileContentSearchWorker::run() } else { qWarning() << "content index incomplete"; + sendErrorMsg(QObject::tr("Content index incomplete.")); + + finished = false; } if (finished) QMetaObject::invokeMethod(m_fileContentSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId)); } +void FileContentSearchWorker::sendErrorMsg(const QString &msg) +{ + QMetaObject::invokeMethod(m_fileContentSearchTask, "searchError", + Q_ARG(size_t, m_currentSearchId), + Q_ARG(QString, msg)); +} + bool FileContentSearchWorker::execSearch() { try { @@ -150,6 +155,7 @@ bool FileContentSearchWorker::execSearch() } catch (const Xapian::Error &e) { qWarning() << QString::fromStdString(e.get_description()); + sendErrorMsg("Xapian Error: " + QString::fromStdString(e.get_description())); return false; } } diff --git a/libsearch/searchinterface/searchtasks/file-content-search-task.h b/libsearch/searchinterface/searchtasks/file-content-search-task.h index a8fc358..a77d9f2 100644 --- a/libsearch/searchinterface/searchtasks/file-content-search-task.h +++ b/libsearch/searchinterface/searchtasks/file-content-search-task.h @@ -36,8 +36,6 @@ public: void startSearch(std::shared_ptr searchController) override; void stop() override; - Q_INVOKABLE void sendFinishSignal(size_t searchId); - private: QThreadPool *m_pool = nullptr; }; @@ -55,6 +53,8 @@ private: bool execSearch(); inline Xapian::Query createQuery(); + void sendErrorMsg(const QString &msg); + private: FileContentSearchTask *m_fileContentSearchTask = nullptr; std::shared_ptr m_searchController; diff --git a/libsearch/searchinterface/searchtasks/file-search-task.cpp b/libsearch/searchinterface/searchtasks/file-search-task.cpp index a332bb7..241d019 100644 --- a/libsearch/searchinterface/searchtasks/file-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-search-task.cpp @@ -144,11 +144,20 @@ bool FileSearchWorker::searchWithIndex() } catch(const Xapian::Error &e) { qWarning() << QString::fromStdString(e.get_description()); + sendErrorMsg("Xapian Error: " + QString::fromStdString(e.get_description())); + return false; } return true; } +void FileSearchWorker::sendErrorMsg(const QString &msg) +{ + QMetaObject::invokeMethod(m_FileSearchTask, "searchError", + Q_ARG(size_t, m_currentSearchId), + Q_ARG(QString, msg)); +} + bool FileSearchWorker::directSearch() { unsigned int maxResults = m_searchController->maxResults(); diff --git a/libsearch/searchinterface/searchtasks/file-search-task.h b/libsearch/searchinterface/searchtasks/file-search-task.h index bbbe18a..428b603 100644 --- a/libsearch/searchinterface/searchtasks/file-search-task.h +++ b/libsearch/searchinterface/searchtasks/file-search-task.h @@ -57,6 +57,7 @@ private: //同上 bool directSearch(); Xapian::Query creatQueryForFileSearch(); + void sendErrorMsg(const QString &msg); private: FileSearchTask *m_FileSearchTask; diff --git a/libsearch/searchinterface/ukui-search-task.cpp b/libsearch/searchinterface/ukui-search-task.cpp index 312256b..e272667 100644 --- a/libsearch/searchinterface/ukui-search-task.cpp +++ b/libsearch/searchinterface/ukui-search-task.cpp @@ -9,6 +9,7 @@ UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent) { m_searchCotroller = std::shared_ptr(new SearchController()); connect(SearchTaskPluginManager::getInstance(), &SearchTaskPluginManager::searchFinished, this, &UkuiSearchTaskPrivate::searchFinished); + connect(SearchTaskPluginManager::getInstance(), &SearchTaskPluginManager::searchError, q, &UkuiSearchTask::searchError); } UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate() diff --git a/libsearch/searchinterface/ukui-search-task.h b/libsearch/searchinterface/ukui-search-task.h index 7b27ca8..e9ed5eb 100644 --- a/libsearch/searchinterface/ukui-search-task.h +++ b/libsearch/searchinterface/ukui-search-task.h @@ -31,6 +31,7 @@ public: Q_SIGNALS: void searchFinished(size_t searchId); + void searchError(size_t searchId, QString msg); private: UkuiSearchTaskPrivate* d = nullptr;