From 2d659cf16481e6f0637b38b1d6a93f091d76c4db Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 28 Dec 2021 15:56:41 +0800 Subject: [PATCH] Add search interface frame. --- libsearch/libsearch.pro | 1 + libsearch/plugininterface/common-defines.h | 15 ++ libsearch/plugininterface/plugin-iface.h | 3 +- .../plugininterface/plugin-interface.pri | 4 +- .../search-task-plugin-iface.h | 28 +++ .../searchinterface/result-item-private.h | 22 ++ libsearch/searchinterface/result-item.cpp | 11 + libsearch/searchinterface/result-item.h | 18 ++ .../search-controller-private.h | 51 +++++ .../searchinterface/search-controller.cpp | 210 ++++++++++++++++++ libsearch/searchinterface/search-controller.h | 43 ++++ .../searchinterface/search-interface.pri | 16 ++ .../searchtasks/file-search-task.cpp | 43 ++++ .../searchtasks/file-search-task.h | 28 +++ .../searchtasks/search-tasks.pri | 9 + .../ukui-search-task-private.h | 37 +++ .../searchinterface/ukui-search-task.cpp | 113 ++++++++++ libsearch/searchinterface/ukui-search-task.h | 32 +++ 18 files changed, 682 insertions(+), 2 deletions(-) create mode 100644 libsearch/plugininterface/common-defines.h create mode 100644 libsearch/plugininterface/search-task-plugin-iface.h create mode 100644 libsearch/searchinterface/result-item-private.h create mode 100644 libsearch/searchinterface/result-item.cpp create mode 100644 libsearch/searchinterface/result-item.h create mode 100644 libsearch/searchinterface/search-controller-private.h create mode 100644 libsearch/searchinterface/search-controller.cpp create mode 100644 libsearch/searchinterface/search-controller.h create mode 100644 libsearch/searchinterface/search-interface.pri create mode 100644 libsearch/searchinterface/searchtasks/file-search-task.cpp create mode 100644 libsearch/searchinterface/searchtasks/file-search-task.h create mode 100644 libsearch/searchinterface/searchtasks/search-tasks.pri create mode 100644 libsearch/searchinterface/ukui-search-task-private.h create mode 100644 libsearch/searchinterface/ukui-search-task.cpp create mode 100644 libsearch/searchinterface/ukui-search-task.h diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 9cea2bf..e88fd6b 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -32,6 +32,7 @@ include(appsearch/appsearch.pri) include(notesearch/notesearch.pri) include(settingsearch/settingsearch.pri) include(websearch/websearch.pri) +include(searchinterface/search-interface.pri) LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation LIBS += -lxapian -lquazip5 -luchardet -lQt5Xdg#-L/usr/local/lib/libjemalloc -ljemalloc diff --git a/libsearch/plugininterface/common-defines.h b/libsearch/plugininterface/common-defines.h new file mode 100644 index 0000000..6e183c8 --- /dev/null +++ b/libsearch/plugininterface/common-defines.h @@ -0,0 +1,15 @@ +#ifndef COMMONDEFINES_H +#define COMMONDEFINES_H +namespace UkuiSearch { +enum class SearchType +{ + File, + FileContent, + Application, + Setting, + Note, + Mail, + Custom +}; +} +#endif // COMMONDEFINES_H diff --git a/libsearch/plugininterface/plugin-iface.h b/libsearch/plugininterface/plugin-iface.h index 5159204..eb25e51 100644 --- a/libsearch/plugininterface/plugin-iface.h +++ b/libsearch/plugininterface/plugin-iface.h @@ -10,7 +10,8 @@ public: { MenuPlugin, PreviewPagePlugin, - SearchPlugin, + SearchPlugin, // for ukui-search itself. + SearchTaskPlugin, // for search service. Other }; diff --git a/libsearch/plugininterface/plugin-interface.pri b/libsearch/plugininterface/plugin-interface.pri index ea4d345..f427c43 100644 --- a/libsearch/plugininterface/plugin-interface.pri +++ b/libsearch/plugininterface/plugin-interface.pri @@ -2,9 +2,11 @@ INCLUDEPATH += $$PWD \ HEADERS += \ $$PWD/action-label.h \ + $$PWD/common-defines.h \ $$PWD/plugin-iface.h \ $$PWD/search-plugin-iface.h \ - $$PWD/data-queue.h + $$PWD/data-queue.h \ + $$PWD/search-task-plugin-iface.h SOURCES += \ $$PWD/action-label.cpp diff --git a/libsearch/plugininterface/search-task-plugin-iface.h b/libsearch/plugininterface/search-task-plugin-iface.h new file mode 100644 index 0000000..b407473 --- /dev/null +++ b/libsearch/plugininterface/search-task-plugin-iface.h @@ -0,0 +1,28 @@ +#ifndef SEARCHTASKPLUGINIFACE_H +#define SEARCHTASKPLUGINIFACE_H +#define SearchTaskPLuginIface_iid "org.ukui.ukui-search.plugin-iface.SearchTaskPLuginIface" + +#include +#include +#include "plugin-iface.h" +#include "search-controller.h" +#include "common-defines.h" + +namespace UkuiSearch { +class SearchTaskPLuginIface : public QObject, public PluginInterface +{ + Q_OBJECT +public: + virtual QString getSearchType() = 0; + //Asynchronous,multithread. + virtual void startSearch(SearchController searchController) = 0; + virtual void stop() = 0; +Q_SIGNALS: + void searchFinished(size_t searchId); +}; +} +Q_DECLARE_INTERFACE(UkuiSearch::SearchTaskPLuginIface, SearchTaskPLuginIface_iid) + + + +#endif // SEARCHTASKPLUGINIFACE_H diff --git a/libsearch/searchinterface/result-item-private.h b/libsearch/searchinterface/result-item-private.h new file mode 100644 index 0000000..f2fba0a --- /dev/null +++ b/libsearch/searchinterface/result-item-private.h @@ -0,0 +1,22 @@ +#ifndef RESULTITEMPRIVATE_H +#define RESULTITEMPRIVATE_H +#include "result-item.h" +#include "result-item-private.h" +namespace UkuiSearch { +class ResultItemPrivate +{ +public: + explicit ResultItemPrivate(const QString &itemKey, ResultItem *parent); + ~ResultItemPrivate(); +private: + size_t searchId; + QString m_itemKey; + QString m_label; + QVariant m_extral; + //and something else... + + ResultItem *q; + +}; +} +#endif // RESULTITEMPRIVATE_H diff --git a/libsearch/searchinterface/result-item.cpp b/libsearch/searchinterface/result-item.cpp new file mode 100644 index 0000000..f962c24 --- /dev/null +++ b/libsearch/searchinterface/result-item.cpp @@ -0,0 +1,11 @@ +#include "result-item.h" +#include "result-item-private.h" +using namespace UkuiSearch; +ResultItem::ResultItem(const QString &itemKey) +{ + d = new ResultItemPrivate(itemKey, this); +} + +ResultItem::~ResultItem() +{ +} diff --git a/libsearch/searchinterface/result-item.h b/libsearch/searchinterface/result-item.h new file mode 100644 index 0000000..3689692 --- /dev/null +++ b/libsearch/searchinterface/result-item.h @@ -0,0 +1,18 @@ +#ifndef RESULTITEM_H +#define RESULTITEM_H + +#include +#include +namespace UkuiSearch { +class ResultItemPrivate; +class ResultItem +{ +public: + explicit ResultItem(const QString &itemKey); + ~ResultItem(); +private: + ResultItemPrivate *d; +}; +} + +#endif // RESULTITEM_H diff --git a/libsearch/searchinterface/search-controller-private.h b/libsearch/searchinterface/search-controller-private.h new file mode 100644 index 0000000..c39b41a --- /dev/null +++ b/libsearch/searchinterface/search-controller-private.h @@ -0,0 +1,51 @@ +#ifndef SEARCHCONTROLLERPRIVATE_H +#define SEARCHCONTROLLERPRIVATE_H + +#include +#include +#include "search-controller.h" +namespace UkuiSearch { + +class SearchControllerPrivate +{ +public: + explicit SearchControllerPrivate(SearchController *parent); + ~SearchControllerPrivate(); + size_t refreshSearchId(); + DataQueue* refreshDataqueue(); + DataQueue* initDataQueue(); + + void addSearchDir(QString &path); + void setRecurse(bool recurse = true); + void addKeyword(QString &keyword); + void setActiveKeywordSegmentation(bool active); + void addFileLabel(QString &label); + + size_t getCurrentSearchId(); + DataQueue* getDataQueue(); + bool beginSearchIdCheck(size_t searchId); + void finishSearchIdCheck(); + void stop(); + QStringList getSearchDir(); + bool isRecurse(); + QStringList getKeyword(); + bool isKeywordSegmentationActived(); + QStringList getFileLabel(); + +private: + DataQueue* m_dataQueue = nullptr ; + size_t m_searchId = 0; + QMutex m_searchIdMutex; + SearchController *q; + QSharedPointer m_formerController; + + QStringList m_keywords; + QStringList m_searchDirs; + QStringList m_FileLabels; + bool m_recurse = true; + bool m_activeKeywordSegmentation = false; + +}; +} + +#endif // SEARCHCONTROLLERPRIVATE_H diff --git a/libsearch/searchinterface/search-controller.cpp b/libsearch/searchinterface/search-controller.cpp new file mode 100644 index 0000000..8ee243e --- /dev/null +++ b/libsearch/searchinterface/search-controller.cpp @@ -0,0 +1,210 @@ +#include "search-controller.h" +#include "search-controller-private.h" +#include "ukui-search-task.h" +#include +using namespace UkuiSearch; +SearchControllerPrivate::SearchControllerPrivate(SearchController *parent) + : q(parent) +{ + if(q->m_parent) { + m_formerController = QSharedPointer(q->m_parent); + m_searchId = q->m_parent->d->m_searchId; + m_dataQueue = q->m_parent->d->m_dataQueue; + m_keywords = q->m_parent->d->m_keywords; + m_searchDirs = q->m_parent->d->m_searchDirs; + m_FileLabels = q->m_parent->d->m_FileLabels; + m_recurse = q->m_parent->d->m_recurse; + m_activeKeywordSegmentation = q->m_parent->d->m_activeKeywordSegmentation; + } +} + +SearchControllerPrivate::~SearchControllerPrivate() +{ + m_formerController.clear(); +} + +size_t SearchControllerPrivate::refreshSearchId() +{ + m_searchIdMutex.lock(); + m_searchId += 1; + m_searchIdMutex.unlock(); + return m_searchId; +} + +DataQueue *SearchControllerPrivate::refreshDataqueue() +{ + if(!m_dataQueue) { + m_dataQueue = new DataQueue; + return m_dataQueue; + } + m_dataQueue->clear(); + return m_dataQueue;; +} + +DataQueue *SearchControllerPrivate::initDataQueue() +{ + if(!m_dataQueue) { + m_dataQueue = new DataQueue; + return m_dataQueue; + } + return m_dataQueue; +} + +void SearchControllerPrivate::addSearchDir(QString &path) +{ + m_searchDirs.append(path); +} + +void SearchControllerPrivate::setRecurse(bool recurse) +{ + m_recurse = recurse; +} + +void SearchControllerPrivate::addKeyword(QString &keyword) +{ + m_keywords.append(keyword); +} + +void SearchControllerPrivate::setActiveKeywordSegmentation(bool active) +{ + m_activeKeywordSegmentation = active; +} + +void SearchControllerPrivate::addFileLabel(QString &label) +{ + m_FileLabels.append(label); +} + +size_t SearchControllerPrivate::getCurrentSearchId() +{ + return m_searchId; +} + +DataQueue *SearchControllerPrivate::getDataQueue() +{ + return m_dataQueue; +} + +bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId) +{ + if(q->m_parent) { + return q->m_parent->beginSearchIdCheck(searchId); + } + m_searchIdMutex.lock(); + return m_searchId == searchId; +} + +void SearchControllerPrivate::finishSearchIdCheck() +{ + if(q->m_parent) { + return q->m_parent->finishSearchIdCheck(); + } + m_searchIdMutex.unlock(); + return; +} + +void SearchControllerPrivate::stop() +{ + m_searchIdMutex.lock(); + m_searchId = 0; + m_searchIdMutex.unlock(); +} + +QStringList SearchControllerPrivate::getSearchDir() +{ + +} + +bool SearchControllerPrivate::isRecurse() +{ + +} + +QStringList SearchControllerPrivate::getKeyword() +{ + +} + +bool SearchControllerPrivate::isKeywordSegmentationActived() +{ + +} + +QStringList SearchControllerPrivate::getFileLabel() +{ + +} + +SearchController::SearchController(SearchController *parent) : m_parent(parent), d(new SearchControllerPrivate(this)) +{ +} + +SearchController::~SearchController() +{ + delete d; +} + +DataQueue *SearchController::refreshDataqueue() +{ + return d->refreshDataqueue(); +} + +size_t SearchController::refreshSearchId() +{ + return d->refreshSearchId(); +} + +DataQueue *SearchController::initDataQueue() +{ + return d->initDataQueue(); +} + +void SearchController::addSearchDir(QString &path) +{ + return d->addSearchDir(path); +} + +void SearchController::setRecurse(bool recurse) +{ + d->setRecurse(recurse); +} + +void SearchController::addKeyword(QString &keyword) +{ + d->addKeyword(keyword); +} + +size_t SearchController::getCurrentSearchId() +{ + d->getCurrentSearchId(); +} + +DataQueue *SearchController::getDataQueue() +{ + return d->getDataQueue(); +} + +void SearchController::setActiveKeywordSegmentation(bool active) +{ + d->setActiveKeywordSegmentation(active); +} + +void SearchController::addFileLabel(QString &label) +{ + d->addFileLabel(label); +} + +bool SearchController::beginSearchIdCheck(size_t searchId) +{ + return d->beginSearchIdCheck(searchId); +} + +void SearchController::finishSearchIdCheck() +{ + d->finishSearchIdCheck(); +} + +void SearchController::stop() +{ + d->stop(); +} diff --git a/libsearch/searchinterface/search-controller.h b/libsearch/searchinterface/search-controller.h new file mode 100644 index 0000000..ad9c9f0 --- /dev/null +++ b/libsearch/searchinterface/search-controller.h @@ -0,0 +1,43 @@ +#ifndef SEARCHCONTROLLER_H +#define SEARCHCONTROLLER_H + +#include +#include "data-queue.h" +//todo: url parser? +namespace UkuiSearch { +class UkuiSearchTask; +class ResultItem; +class SearchControllerPrivate; +class SearchController +{ + friend class SearchControllerPrivate; +public: + explicit SearchController(SearchController *parent = nullptr); + ~SearchController(); + DataQueue* refreshDataqueue(); + size_t refreshSearchId(); + DataQueue* initDataQueue(); + + void addSearchDir(QString &path); + void setRecurse(bool recurse = true); + void addKeyword(QString &keyword); + void setActiveKeywordSegmentation(bool active); + void addFileLabel(QString &label); + + size_t getCurrentSearchId(); + DataQueue* getDataQueue(); + bool beginSearchIdCheck(size_t searchId); + void finishSearchIdCheck(); + void stop(); + QStringList getSearchDir(); + bool isRecurse(); + QStringList getKeyword(); + bool isKeywordSegmentationActived(); + QStringList getFileLabel(); +private: + SearchControllerPrivate *d; + SearchController *m_parent; +}; +} + +#endif // SEARCHCONTROLLER_H diff --git a/libsearch/searchinterface/search-interface.pri b/libsearch/searchinterface/search-interface.pri new file mode 100644 index 0000000..a81d7f8 --- /dev/null +++ b/libsearch/searchinterface/search-interface.pri @@ -0,0 +1,16 @@ +INCLUDEPATH += $$PWD +include(searchtasks/search-tasks.pri) + +HEADERS += \ + $$PWD/result-item-private.h \ + $$PWD/search-controller-private.h \ + $$PWD/search-controller.h \ + $$PWD/result-item.h \ + $$PWD/ukui-search-task-private.h \ + $$PWD/ukui-search-task.h + +SOURCES += \ + $$PWD/search-controller.cpp \ + $$PWD/result-item.cpp \ + $$PWD/ukui-search-task.cpp + diff --git a/libsearch/searchinterface/searchtasks/file-search-task.cpp b/libsearch/searchinterface/searchtasks/file-search-task.cpp new file mode 100644 index 0000000..f8ddcf0 --- /dev/null +++ b/libsearch/searchinterface/searchtasks/file-search-task.cpp @@ -0,0 +1,43 @@ +#include "file-search-task.h" +using namespace UkuiSearch; +FileSearchTask::FileSearchTask(SearchController searchController): m_searchControl(searchController) +{ +} + +const QString FileSearchTask::name() +{ + +} + +const QString FileSearchTask::description() +{ + +} + +QString FileSearchTask::getSearchType() +{ + +} + +void FileSearchTask::startSearch(SearchController searchController) +{ + +} + +void FileSearchTask::stop() +{ + +} + +void FileSearchTask::run() +{ + //file search, based on index or direct search? + //1.do search + if(m_searchControl.beginSearchIdCheck(m_searchControl.getCurrentSearchId())) { + + //do enqueue here + m_searchControl.finishSearchIdCheck(); + } + m_searchControl.finishSearchIdCheck(); + //finish +} diff --git a/libsearch/searchinterface/searchtasks/file-search-task.h b/libsearch/searchinterface/searchtasks/file-search-task.h new file mode 100644 index 0000000..dd2b66b --- /dev/null +++ b/libsearch/searchinterface/searchtasks/file-search-task.h @@ -0,0 +1,28 @@ +#ifndef FILESEARCHTASK_H +#define FILESEARCHTASK_H +#include "search-task-plugin-iface.h" +#include "search-controller.h" +#include +namespace UkuiSearch { +class FileSearchTask : public SearchTaskPLuginIface +{ + Q_OBJECT +public: + explicit FileSearchTask(SearchController searchController); + PluginType pluginType() {return PluginType::SearchTaskPlugin;} + const QString name(); + const QString description(); + const QIcon icon() {return QIcon::fromTheme("folder");} + void setEnable(bool enable) {} + bool isEnable() {} + + QString getSearchType(); + void startSearch(SearchController searchController); + void stop(); +protected: + void run(); +private: + SearchController m_searchControl; +}; +} +#endif // FILESEARCHTASK_H diff --git a/libsearch/searchinterface/searchtasks/search-tasks.pri b/libsearch/searchinterface/searchtasks/search-tasks.pri new file mode 100644 index 0000000..b1f5c08 --- /dev/null +++ b/libsearch/searchinterface/searchtasks/search-tasks.pri @@ -0,0 +1,9 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/file-search-task.h + +SOURCES += \ + $$PWD/file-search-task.cpp + + diff --git a/libsearch/searchinterface/ukui-search-task-private.h b/libsearch/searchinterface/ukui-search-task-private.h new file mode 100644 index 0000000..2555a1d --- /dev/null +++ b/libsearch/searchinterface/ukui-search-task-private.h @@ -0,0 +1,37 @@ +#ifndef UKUISEARCHPRIVATE_H +#define UKUISEARCHPRIVATE_H + +#include "ukui-search-task.h" +#include +#include +#include + +#include "data-queue.h" +#include "search-controller.h" +namespace UkuiSearch { +class UkuiSearchTaskPrivate : public QObject +{ + Q_OBJECT +public: + explicit UkuiSearchTaskPrivate(UkuiSearchTask* parent); + ~UkuiSearchTaskPrivate(); + DataQueue* init(); + void addSearchDir(QString &path); + void setRecurse(bool recurse = true); + void addKeyword(QString &keyword); + void addFileLabel(QString &label); + void setSearchOnlineApps(bool searchOnlineApps); + size_t startSearch(SearchType searchtype); + void stop(); + +private: + SearchController* m_searchCotroller; + size_t m_searchId = 0; + UkuiSearchTask* q = nullptr; + +Q_SIGNALS: + void searchFinished(size_t searchId); +}; +} + +#endif // UKUISEARCHPRIVATE_H diff --git a/libsearch/searchinterface/ukui-search-task.cpp b/libsearch/searchinterface/ukui-search-task.cpp new file mode 100644 index 0000000..46a853d --- /dev/null +++ b/libsearch/searchinterface/ukui-search-task.cpp @@ -0,0 +1,113 @@ +#include "ukui-search-task.h" +#include "ukui-search-task-private.h" +#include +using namespace UkuiSearch; +UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent) + : QObject(parent), + q(parent) +{ + m_searchCotroller = new SearchController(); +} + +UkuiSearchTaskPrivate::~UkuiSearchTaskPrivate() +{ + this->stop(); +} + +DataQueue *UkuiSearchTaskPrivate::init() +{ + return m_searchCotroller->initDataQueue(); +} + +void UkuiSearchTaskPrivate::addSearchDir(QString &path) +{ + m_searchCotroller->addSearchDir(path); +} + +void UkuiSearchTaskPrivate::setRecurse(bool recurse) +{ + m_searchCotroller->setRecurse(recurse); +} + +void UkuiSearchTaskPrivate::addKeyword(QString &keyword) +{ + m_searchCotroller->addKeyword(keyword); +} + +void UkuiSearchTaskPrivate::addFileLabel(QString &label) +{ + m_searchCotroller->addFileLabel(label); +} + +void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps) +{ +} + +size_t UkuiSearchTaskPrivate::startSearch(SearchType searchtype) +{ + + m_searchId = m_searchCotroller->refreshSearchId(); +// if(!m_dataQueue) { +// qWarning() << "Please run init first!"; +// return -1; +// } + + //plugin manager do async search here + // plugin->search(SearchController(m_searchController)) + + return m_searchId; +} + +void UkuiSearchTaskPrivate::stop() +{ + m_searchCotroller->stop(); +} + +UkuiSearchTask::UkuiSearchTask(QObject *parent) : QObject(parent), d(new UkuiSearchTaskPrivate(this)) +{ + connect(d, &UkuiSearchTaskPrivate::searchFinished, this, &UkuiSearchTask::searchFinished); +} + +UkuiSearchTask::~UkuiSearchTask() +{ +} + +DataQueue *UkuiSearchTask::init() +{ + d->init(); +} + +void UkuiSearchTask::addSearchDir(QString &path) +{ + d->addSearchDir(path); +} + +void UkuiSearchTask::setRecurse(bool recurse) +{ + d->setRecurse(recurse); +} + +void UkuiSearchTask::addKeyword(QString &keyword) +{ + d->addKeyword(keyword); +} + +void UkuiSearchTask::addFileLabel(QString &label) +{ + d->addFileLabel(label); +} + +void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps) +{ + d->setSearchOnlineApps(searchOnlineApps); +} + +size_t UkuiSearchTask::startSearch(SearchType searchtype) +{ + return d->startSearch(searchtype); +} + +void UkuiSearchTask::stop() +{ + d->stop(); +} diff --git a/libsearch/searchinterface/ukui-search-task.h b/libsearch/searchinterface/ukui-search-task.h new file mode 100644 index 0000000..2aafd36 --- /dev/null +++ b/libsearch/searchinterface/ukui-search-task.h @@ -0,0 +1,32 @@ +#ifndef UKUISEARCH_H +#define UKUISEARCH_H + +#include "result-item.h" +#include "data-queue.h" +#include "common-defines.h" +namespace UkuiSearch { +class UkuiSearchTaskPrivate; +class UkuiSearchTask : public QObject +{ + Q_OBJECT +public: + explicit UkuiSearchTask(QObject *parent = nullptr); + ~UkuiSearchTask(); + DataQueue* init(); + void addSearchDir(QString &path); + void setRecurse(bool recurse = true); + void addKeyword(QString &keyword); + void addFileLabel(QString &label); + void setSearchOnlineApps(bool searchOnlineApps); + size_t startSearch(SearchType searchtype); + void stop(); + +Q_SIGNALS: + void searchFinished(size_t searchId); + +private: + UkuiSearchTaskPrivate* d = nullptr; +}; +} + +#endif // UKUISEARCH_H