2021-05-28 10:16:28 +08:00
|
|
|
#include <QDebug>
|
2021-05-03 00:21:36 +08:00
|
|
|
#include "search-plugin-manager.h"
|
2021-05-27 21:10:11 +08:00
|
|
|
#include "file-search-plugin.h"
|
2021-08-26 08:20:38 +08:00
|
|
|
#include "app-search-plugin.h"
|
2021-06-18 09:48:58 +08:00
|
|
|
#include "settings-search-plugin.h"
|
2021-08-26 08:20:38 +08:00
|
|
|
#include "note-search-plugin.h"
|
2021-10-27 11:37:55 +08:00
|
|
|
#include "web-search-plugin.h"
|
2021-05-03 00:21:36 +08:00
|
|
|
|
|
|
|
using namespace Zeeker;
|
|
|
|
|
|
|
|
static SearchPluginManager *global_instance = nullptr;
|
2021-05-27 21:10:11 +08:00
|
|
|
SearchPluginManager::SearchPluginManager(QObject *parent)
|
|
|
|
{
|
2021-06-17 14:08:55 +08:00
|
|
|
registerPlugin(new AppSearchPlugin(this));
|
2021-08-26 08:20:38 +08:00
|
|
|
registerPlugin(new NoteSearchPlugin(this));
|
2021-06-18 09:48:58 +08:00
|
|
|
registerPlugin(new SettingsSearchPlugin(this));
|
2021-08-02 13:46:59 +08:00
|
|
|
registerPlugin(new DirSearchPlugin(this));
|
|
|
|
registerPlugin(new FileSearchPlugin(this));
|
|
|
|
registerPlugin(new FileContengSearchPlugin(this));
|
2021-10-27 11:37:55 +08:00
|
|
|
registerPlugin(new WebSearchPlugin(this));
|
2021-05-27 21:10:11 +08:00
|
|
|
}
|
|
|
|
|
2021-05-03 00:21:36 +08:00
|
|
|
bool SearchPluginManager::registerPlugin(Zeeker::SearchPluginIface *plugin)
|
|
|
|
{
|
2021-08-02 13:46:59 +08:00
|
|
|
if (m_map.end() != m_map.find(plugin->name())){
|
2021-05-03 00:21:36 +08:00
|
|
|
return false;
|
|
|
|
}
|
2021-08-02 13:46:59 +08:00
|
|
|
m_map[plugin->name()] = plugin;
|
2021-08-03 16:08:30 +08:00
|
|
|
m_plugin_order[m_plugin_order.size()] = plugin->name();//按注册顺序绑定优先级
|
2021-05-03 00:21:36 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchPluginManager *SearchPluginManager::getInstance()
|
|
|
|
{
|
|
|
|
if (!global_instance) {
|
|
|
|
global_instance = new SearchPluginManager;
|
|
|
|
}
|
|
|
|
return global_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList SearchPluginManager::getPluginIds()
|
|
|
|
{
|
2021-08-02 13:46:59 +08:00
|
|
|
QStringList list;
|
2021-08-03 16:08:30 +08:00
|
|
|
for (auto i = m_plugin_order.begin(); i != m_plugin_order.end(); i++) {
|
|
|
|
list.append(m_plugin_order[(*i).first]);//根据优先级返回plugin ID
|
2021-08-02 13:46:59 +08:00
|
|
|
}
|
|
|
|
return list;
|
2021-05-03 00:21:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchPluginIface *SearchPluginManager::getPlugin(const QString &pluginId)
|
|
|
|
{
|
2021-08-02 13:46:59 +08:00
|
|
|
return m_map[pluginId];
|
2021-05-03 00:21:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPluginManager::close()
|
|
|
|
{
|
|
|
|
this->deleteLater();
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:23:36 +08:00
|
|
|
SearchPluginManager::~SearchPluginManager()
|
|
|
|
{
|
2021-08-02 13:46:59 +08:00
|
|
|
m_map.clear();
|
2021-05-06 20:23:36 +08:00
|
|
|
}
|