Merge branch '1213-ukss' into 'ukss-dev'
Add plugin manager for search task. See merge request kylin-desktop/ukui-search!236
This commit is contained in:
commit
06ba7ce612
|
@ -5,4 +5,5 @@ INCLUDEPATH += $$PWD/parser
|
|||
INCLUDEPATH += $$PWD/pluginmanage
|
||||
INCLUDEPATH += $$PWD/settingsearch
|
||||
INCLUDEPATH += $$PWD/appsearch
|
||||
INCLUDEPATH += $$PWD/searchinterface
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace UkuiSearch {
|
||||
enum class SearchType
|
||||
{
|
||||
File,
|
||||
File = 0,
|
||||
FileContent,
|
||||
Application,
|
||||
Setting,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
INCLUDEPATH += $$PWD \
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/action-label.h \
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
#ifndef SEARCHTASKPLUGINIFACE_H
|
||||
#define SEARCHTASKPLUGINIFACE_H
|
||||
#define SearchTaskPLuginIface_iid "org.ukui.ukui-search.plugin-iface.SearchTaskPLuginIface"
|
||||
#define SearchTaskPluginIface_iid "org.ukui.ukui-search.plugin-iface.SearchTaskPluginIface"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtPlugin>
|
||||
#include "plugin-iface.h"
|
||||
#include "search-controller.h"
|
||||
#include "common-defines.h"
|
||||
#include "search-controller.h"
|
||||
|
||||
|
||||
namespace UkuiSearch {
|
||||
class SearchTaskPLuginIface : public QObject, public PluginInterface
|
||||
class SearchTaskPluginIface : public QObject, public PluginInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual QString getSearchType() = 0;
|
||||
virtual QString getCustomSearchType() = 0;
|
||||
virtual SearchType getSearchType() = 0;
|
||||
//Asynchronous,multithread.
|
||||
virtual void startSearch(SearchController searchController) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
@ -21,7 +23,7 @@ Q_SIGNALS:
|
|||
void searchFinished(size_t searchId);
|
||||
};
|
||||
}
|
||||
Q_DECLARE_INTERFACE(UkuiSearch::SearchTaskPLuginIface, SearchTaskPLuginIface_iid)
|
||||
Q_DECLARE_INTERFACE(UkuiSearch::SearchTaskPluginIface, SearchTaskPluginIface_iid)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "plugin-manager.h"
|
||||
#include "search-plugin-manager.h"
|
||||
#include "search-task-plugin-manager.h"
|
||||
|
||||
using namespace UkuiSearch;
|
||||
|
||||
|
@ -46,6 +47,11 @@ PluginManager::PluginManager(QObject *parent) : QObject(parent)
|
|||
SearchPluginManager::getInstance()->registerPlugin(p);
|
||||
break;
|
||||
}
|
||||
case PluginInterface::PluginType::SearchTaskPlugin: {
|
||||
auto p = dynamic_cast<SearchTaskPluginIface*>(plugin);
|
||||
SearchTaskPluginManager::getInstance()->registerPlugin(p);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include <QDir>
|
||||
#include <QPluginLoader>
|
||||
#include <QApplication>
|
||||
#include "libsearch_global.h"
|
||||
#include "plugininterface/plugin-iface.h"
|
||||
#include "plugininterface/search-plugin-iface.h"
|
||||
#include "plugin-iface.h"
|
||||
#include "search-plugin-iface.h"
|
||||
#include "search-task-plugin-iface.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
class LIBSEARCH_EXPORT PluginManager : public QObject
|
||||
|
|
|
@ -2,8 +2,10 @@ INCLUDEPATH += $$PWD
|
|||
|
||||
HEADERS += \
|
||||
$$PWD/search-plugin-manager.h \
|
||||
$$PWD/plugin-manager.h
|
||||
$$PWD/plugin-manager.h \
|
||||
$$PWD/search-task-plugin-manager.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/search-plugin-manager.cpp \
|
||||
$$PWD/plugin-manager.cpp
|
||||
$$PWD/plugin-manager.cpp \
|
||||
$$PWD/search-task-plugin-manager.cpp
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#include "search-task-plugin-manager.h"
|
||||
#include <QDebug>
|
||||
using namespace UkuiSearch;
|
||||
static SearchTaskPluginManager *global_instance = nullptr;
|
||||
SearchTaskPluginManager *SearchTaskPluginManager::getInstance()
|
||||
{
|
||||
if (!global_instance) {
|
||||
global_instance = new SearchTaskPluginManager;
|
||||
}
|
||||
return global_instance;
|
||||
}
|
||||
|
||||
bool SearchTaskPluginManager::registerPlugin(SearchTaskPluginIface *plugin)
|
||||
{
|
||||
//这里把内部插件和外部插件分开写是考虑到异常处理,因为内部插件我们可以保证质量,但外部插件可能有各种各样的问题。
|
||||
//但异常处理我没想好怎么加。。
|
||||
//by zpf
|
||||
if(plugin->getCustomSearchType().isEmpty() || m_loadedPlugin.contains(plugin->getCustomSearchType())) {
|
||||
qWarning() << "search task plugin load failed! plugin type:" << plugin->getCustomSearchType();
|
||||
return false;
|
||||
}
|
||||
m_loadedPlugin.insert(plugin->getCustomSearchType(), plugin);
|
||||
connect(plugin, &SearchTaskPluginIface::searchFinished, this, &SearchTaskPluginManager::searchFinished);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SearchTaskPluginManager::registerBuildinPlugin(SearchTaskPluginIface *plugin)
|
||||
{
|
||||
m_buildinPlugin.insert(static_cast<int>(plugin->getSearchType()), plugin);
|
||||
connect(plugin, &SearchTaskPluginIface::searchFinished, this, &SearchTaskPluginManager::searchFinished);
|
||||
return true;
|
||||
}
|
||||
|
||||
SearchTaskPluginManager::SearchTaskPluginManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//register buildin plugin into m_buildinPlugin
|
||||
//registerBuildinPlugin();
|
||||
}
|
||||
|
||||
void SearchTaskPluginManager::pluginSearch(SearchType searchType, SearchController searchController)
|
||||
{
|
||||
int type = static_cast<int>(searchType);
|
||||
if(m_buildinPlugin.contains(type)) {
|
||||
if(!m_buildinPlugin.value(type)->isEnable()) {
|
||||
Q_EMIT this->pluginDisable(searchController.getCurrentSearchId());
|
||||
return;
|
||||
}
|
||||
m_buildinPlugin.value(type)->startSearch(searchController);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTaskPluginManager::pluginSearch(QString customSearchType, SearchController searchController)
|
||||
{
|
||||
if(m_loadedPlugin.contains(customSearchType)) {
|
||||
if(!m_loadedPlugin.value(customSearchType)->isEnable()) {
|
||||
Q_EMIT this->pluginDisable(searchController.getCurrentSearchId());
|
||||
return;
|
||||
}
|
||||
m_loadedPlugin.value(customSearchType)->startSearch(searchController);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef SEARCHTASKPLUGINMANAGER_H
|
||||
#define SEARCHTASKPLUGINMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "search-task-plugin-iface.h"
|
||||
namespace UkuiSearch {
|
||||
|
||||
class SearchTaskPluginManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SearchTaskPluginManager *getInstance();
|
||||
bool registerPlugin(SearchTaskPluginIface *plugin);
|
||||
bool registerBuildinPlugin(SearchTaskPluginIface *plugin);
|
||||
void pluginSearch(SearchType searchType, SearchController searchController);
|
||||
void pluginSearch(QString customSearchType, SearchController searchController);
|
||||
Q_SIGNALS:
|
||||
void searchFinished(size_t searchId);
|
||||
void pluginDisable(size_t searchId);
|
||||
private:
|
||||
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
||||
|
||||
QHash<int, SearchTaskPluginIface*> m_buildinPlugin;
|
||||
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SEARCHTASKPLUGINMANAGER_H
|
|
@ -18,5 +18,6 @@ private:
|
|||
ResultItem *q;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // RESULTITEMPRIVATE_H
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#include "result-item.h"
|
||||
#include "result-item-private.h"
|
||||
using namespace UkuiSearch;
|
||||
ResultItemPrivate::ResultItemPrivate::ResultItemPrivate(const QString &itemKey, ResultItem *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ResultItemPrivate::~ResultItemPrivate()
|
||||
{
|
||||
|
||||
}
|
||||
ResultItem::ResultItem(const QString &itemKey)
|
||||
{
|
||||
d = new ResultItemPrivate(itemKey, this);
|
||||
|
|
|
@ -17,18 +17,21 @@ public:
|
|||
DataQueue<ResultItem>* refreshDataqueue();
|
||||
size_t refreshSearchId();
|
||||
DataQueue<ResultItem>* initDataQueue();
|
||||
void stop();
|
||||
|
||||
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<ResultItem>* getDataQueue();
|
||||
bool beginSearchIdCheck(size_t searchId);
|
||||
void finishSearchIdCheck();
|
||||
void stop();
|
||||
|
||||
QStringList getSearchDir();
|
||||
bool isRecurse();
|
||||
QStringList getKeyword();
|
||||
|
|
|
@ -14,7 +14,7 @@ const QString FileSearchTask::description()
|
|||
|
||||
}
|
||||
|
||||
QString FileSearchTask::getSearchType()
|
||||
QString FileSearchTask::getCustomSearchType()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "search-controller.h"
|
||||
#include <QIcon>
|
||||
namespace UkuiSearch {
|
||||
class FileSearchTask : public SearchTaskPLuginIface
|
||||
class FileSearchTask : public SearchTaskPluginIface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -16,7 +16,8 @@ public:
|
|||
void setEnable(bool enable) {}
|
||||
bool isEnable() {}
|
||||
|
||||
QString getSearchType();
|
||||
SearchType getSearchType() {return SearchType::File;}
|
||||
QString getCustomSearchType();
|
||||
void startSearch(SearchController searchController);
|
||||
void stop();
|
||||
protected:
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
void addKeyword(QString &keyword);
|
||||
void addFileLabel(QString &label);
|
||||
void setSearchOnlineApps(bool searchOnlineApps);
|
||||
size_t startSearch(SearchType searchtype);
|
||||
size_t startSearch(SearchType searchtype, QString customSearchType = QString());
|
||||
void stop();
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "ukui-search-task.h"
|
||||
#include "ukui-search-task-private.h"
|
||||
#include "search-task-plugin-manager.h"
|
||||
#include <QDebug>
|
||||
using namespace UkuiSearch;
|
||||
UkuiSearchTaskPrivate::UkuiSearchTaskPrivate(UkuiSearchTask *parent)
|
||||
|
@ -43,17 +44,21 @@ void UkuiSearchTaskPrivate::setSearchOnlineApps(bool searchOnlineApps)
|
|||
{
|
||||
}
|
||||
|
||||
size_t UkuiSearchTaskPrivate::startSearch(SearchType searchtype)
|
||||
size_t UkuiSearchTaskPrivate::startSearch(SearchType searchtype, QString customSearchType)
|
||||
{
|
||||
|
||||
m_searchId = m_searchCotroller->refreshSearchId();
|
||||
// if(!m_dataQueue) {
|
||||
// qWarning() << "Please run init first!";
|
||||
// return -1;
|
||||
// }
|
||||
if(m_searchCotroller->getDataQueue() == nullptr) {
|
||||
qWarning() << "the date queue has not been initialized, you need run init first!";
|
||||
}
|
||||
|
||||
//plugin manager do async search here
|
||||
// plugin->search(SearchController(m_searchController))
|
||||
if(SearchType::Custom != searchtype) {
|
||||
SearchTaskPluginManager::getInstance()->pluginSearch(searchtype, SearchController(m_searchCotroller));
|
||||
} else {
|
||||
SearchTaskPluginManager::getInstance()->pluginSearch(customSearchType, SearchController(m_searchCotroller));
|
||||
|
||||
}
|
||||
|
||||
return m_searchId;
|
||||
}
|
||||
|
@ -102,9 +107,9 @@ void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
|
|||
d->setSearchOnlineApps(searchOnlineApps);
|
||||
}
|
||||
|
||||
size_t UkuiSearchTask::startSearch(SearchType searchtype)
|
||||
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchTYpe)
|
||||
{
|
||||
return d->startSearch(searchtype);
|
||||
return d->startSearch(searchtype, customSearchTYpe);
|
||||
}
|
||||
|
||||
void UkuiSearchTask::stop()
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
void addKeyword(QString &keyword);
|
||||
void addFileLabel(QString &label);
|
||||
void setSearchOnlineApps(bool searchOnlineApps);
|
||||
size_t startSearch(SearchType searchtype);
|
||||
size_t startSearch(SearchType searchtype, QString customSearchTYpe = QString());
|
||||
void stop();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
Loading…
Reference in New Issue