Skip to content

Commit

Permalink
add galyd plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ehnap committed Aug 4, 2019
1 parent feb7c5a commit 57b4110
Show file tree
Hide file tree
Showing 33 changed files with 385 additions and 53 deletions.
2 changes: 1 addition & 1 deletion galapp/include/galcppfreeinterface.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QtPlugin>
#include <QString>
Expand Down
2 changes: 1 addition & 1 deletion galapp/include/galcpplistinterface.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QtPlugin>
#include <QString>
Expand Down
2 changes: 1 addition & 1 deletion galapp/resource.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//{{NO_DEPENDENCIES}}
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by qlauncher1.rc

Expand Down
2 changes: 1 addition & 1 deletion galapp/src/data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "data.h"
#include "data.h"
#include "pydata.h"
#include "resultlist.h"
#include "Everything.h"
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/data.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QObject>
#include <QString>
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/gallistwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "gallistwidget.h"
#include "gallistwidget.h"
#include "mainbox.h"
#include "omniobject.h"

Expand Down
2 changes: 1 addition & 1 deletion galapp/src/gallistwidget.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QWidget>
#include <QListWidget>
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mainbox.h"
#include "mainbox.h"
#include "pydata.h"
#include "maintray.h"
#include <QtWidgets/QApplication>
Expand Down
19 changes: 11 additions & 8 deletions galapp/src/mainbox.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mainbox.h"
#include "mainbox.h"
#include "data.h"
#include "resultlist.h"
#include "pluginmanager.h"
Expand Down Expand Up @@ -130,13 +130,16 @@ void Mainbox::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)
{
if (m_omniObjects[m_currentObjectIndex]->respondType() == OmniObject::RespondType::Delay)
{
m_omniObjects[m_currentObjectIndex]->execEx(queryKey());
}
m_pInputEdit->clear();
QString k = queryKey().trimmed();
if (m_omniObjects[m_currentObjectIndex]->respondType(k) == OmniObject::RespondType::Delay)
m_omniObjects[m_currentObjectIndex]->execEx(k);
else
m_pInputEdit->clear();

adjustSize();
hide();

if (m_omniObjects[m_currentObjectIndex]->respondType(k) != OmniObject::RespondType::Delay)
hide();
}

if (e->key() == Qt::Key_Escape)
Expand Down Expand Up @@ -203,7 +206,7 @@ void Mainbox::processInputWord(const QString& t)
if (m_omniObjects[i]->filter(t))
{
m_currentObjectIndex = i;
if (m_omniObjects[i]->respondType() == OmniObject::RespondType::Real)
if (m_omniObjects[i]->respondType(k) == OmniObject::RespondType::Real)
m_omniObjects[i]->execEx(k);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/mainbox.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QWidget>
#include <QHash>
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/maintray.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "maintray.h"
#include "maintray.h"
#include "mainbox.h"
#include <QMenu>
#include <QApplication>
Expand Down
2 changes: 1 addition & 1 deletion galapp/src/maintray.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QSystemTrayIcon>

Expand Down
16 changes: 14 additions & 2 deletions galapp/src/omniobject.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "omniobject.h"
#include "omniobject.h"
#include "pluginmanager.h"
#include "data.h"

Expand Down Expand Up @@ -30,8 +30,9 @@ void OmniObject::execEx(const QString& k)
}


OmniObject::RespondType OmniObject::respondType() const
OmniObject::RespondType OmniObject::respondType(const QString& k/* = ""*/) const
{
Q_UNUSED(k);
return m_respondType;
}

Expand Down Expand Up @@ -160,6 +161,17 @@ bool OmniPlugin::filter(const QString& k)
return m_pPluginManager->isPluginExist(strKey);
}

OmniObject::RespondType OmniPlugin::respondType(const QString& k/* = ""*/) const
{
QString strKey = k.left(k.indexOf(" "));

if (!m_pPluginManager->isPluginExist(strKey))
return OmniObject::RespondType::Real;

auto pl = m_pPluginManager->queryPlugin(strKey);
return pl->respondType();
}

PluginManager* OmniPlugin::pluginManager() const
{
return m_pPluginManager;
Expand Down
5 changes: 3 additions & 2 deletions galapp/src/omniobject.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QString>
#include <QHash>
Expand Down Expand Up @@ -28,7 +28,7 @@ class OmniObject

void execEx(const QString& k);
OmniType omniType() const;
RespondType respondType() const;
virtual RespondType respondType(const QString& k = "") const;

virtual bool filter(const QString& k) = 0;

Expand Down Expand Up @@ -86,6 +86,7 @@ class OmniPlugin : public QObject, public OmniObject
~OmniPlugin();

virtual bool filter(const QString& k) override;
RespondType respondType(const QString& k) const override;

PluginManager* pluginManager() const;

Expand Down
35 changes: 27 additions & 8 deletions galapp/src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "plugin.h"
#include "plugin.h"
#include "pluginmanager.h"

#include <QJSEngine>
Expand All @@ -15,21 +15,31 @@
#include <QTimer>
#include <QPluginLoader>

Plugin::Plugin(QObject* parent, const QString& pluName, const QString& pluKey, const QString& pluVer, const QString& pluAuthor, const QString& pluDir, PluginType t)
Plugin::Plugin(QObject* parent, const QString& pluName,
const QString& pluKey, const QString& pluVer,
const QString& pluAuthor, const QString& pluDir,
PluginType t, OmniObject::RespondType rt /*= OmniObject::RespondType::Real*/)
: QObject(parent)
, m_key(pluKey)
, m_name(pluName)
, m_version(pluVer)
, m_author(pluAuthor)
, m_dir(pluDir)
, m_type(t)
, m_respondType(rt)
{
}

Plugin::~Plugin()
{
}


OmniObject::RespondType Plugin::respondType() const
{
return m_respondType;
}

Plugin::PluginType Plugin::type() const
{
return m_type;
Expand Down Expand Up @@ -72,8 +82,11 @@ Plugin::PluginType Plugin::getTypeFromStr(const QString& str)
return PluginType::UNKNOWN_TYPE;
}

JsSimplePlugin::JsSimplePlugin(QObject* parent, const QString& pluName, const QString& pluKey, const QString& pluVer, const QString& pluAuthor, const QString& pluDir)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::JS_SIMPLE)
JsSimplePlugin::JsSimplePlugin(QObject* parent, const QString& pluName,
const QString& pluKey, const QString& pluVer,
const QString& pluAuthor, const QString& pluDir,
OmniObject::RespondType rt /*= OmniObject::RespondType::Real*/)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::JS_SIMPLE, rt)
, m_widget(Q_NULLPTR)
{
m_jsEngine = new QJSEngine();
Expand Down Expand Up @@ -147,8 +160,11 @@ void LabelPluginWidget::copyContent()
pClipboard->setText(m_pResultLabel->text());
}

CppFreePlugin::CppFreePlugin(QObject* parent, const QString& pluName, const QString& pluKey, const QString& pluVer, const QString& pluAuthor, const QString& pluDir)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::CPP_FREE)
CppFreePlugin::CppFreePlugin(QObject* parent, const QString& pluName,
const QString& pluKey, const QString& pluVer,
const QString& pluAuthor, const QString& pluDir,
OmniObject::RespondType rt /*= OmniObject::RespondType::Real*/)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::CPP_FREE, rt)
, m_widget(Q_NULLPTR)
{
QTimer::singleShot(0, this, &CppFreePlugin::firstInit);
Expand Down Expand Up @@ -299,8 +315,11 @@ void CppSimpleListWidget::clear()
GalListWidget::clear();
}

CppSimpleListPlugin::CppSimpleListPlugin(QObject* parent, const QString& pluName, const QString& pluKey, const QString& pluVer, const QString& pluAuthor, const QString& pluDir)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::CPP_SIMPLELIST)
CppSimpleListPlugin::CppSimpleListPlugin(QObject* parent, const QString& pluName,
const QString& pluKey, const QString& pluVer,
const QString& pluAuthor, const QString& pluDir,
OmniObject::RespondType rt /*= OmniObject::RespondType::Real*/)
: Plugin(parent, pluName, pluKey, pluVer, pluAuthor, pluDir, Plugin::PluginType::CPP_SIMPLELIST, rt)
{
QTimer::singleShot(0, this, &CppSimpleListPlugin::firstInit);
}
Expand Down
21 changes: 14 additions & 7 deletions galapp/src/plugin.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#pragma once

#include "include/galcppfreeinterface.h"
#include "include/galcpplistinterface.h"
#include "gallistwidget.h"
#include "omniobject.h"

#include <QObject>
#include <QWidget>
Expand Down Expand Up @@ -30,18 +31,20 @@ class Plugin : public QObject
const QString& pluVer,
const QString& pluAuthor,
const QString& pluDir,
PluginType t);
PluginType t,
OmniObject::RespondType rt = OmniObject::RespondType::Real);
virtual ~Plugin();

OmniObject::RespondType respondType() const;
PluginType type() const;
QString name() const;
QString version() const;
QString key() const;
QString dir() const;
QString author() const;
virtual void query(const QString& content, QWidget* canvas) = 0; //查询动作
virtual void query(const QString& content, QWidget* canvas) = 0; //查询动作
virtual void exec(ListItem it) { Q_UNUSED(it); }
virtual QWidget* widget() const { return Q_NULLPTR; } //查询异步支持时会用得上
virtual QWidget* widget() const { return Q_NULLPTR; } //查询异步支持时会用得上
static PluginType getTypeFromStr(const QString& str);

private:
Expand All @@ -51,6 +54,7 @@ class Plugin : public QObject
QString m_author;
QString m_dir;
PluginType m_type;
OmniObject::RespondType m_respondType;
};

class PluginWidgetInterface
Expand Down Expand Up @@ -130,7 +134,8 @@ class JsSimplePlugin : public Plugin
const QString& pluKey,
const QString& pluVer,
const QString& pluAuthor,
const QString& pluDir);
const QString& pluDir,
OmniObject::RespondType rt = OmniObject::RespondType::Real);

void query(const QString& content, QWidget* canvas) override;

Expand All @@ -150,7 +155,8 @@ class CppFreePlugin : public Plugin
const QString& pluKey,
const QString& pluVer,
const QString& pluAuthor,
const QString& pluDir);
const QString& pluDir,
OmniObject::RespondType rt = OmniObject::RespondType::Real);

void query(const QString& content, QWidget* canvas) override;

Expand All @@ -173,7 +179,8 @@ class CppSimpleListPlugin : public Plugin
const QString& pluKey,
const QString& pluVer,
const QString& pluAuthor,
const QString& pluDir);
const QString& pluDir,
OmniObject::RespondType rt = OmniObject::RespondType::Real);

void query(const QString& content, QWidget* canvas) override;

Expand Down
29 changes: 21 additions & 8 deletions galapp/src/pluginmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "plugin.h"
#include "plugin.h"
#include "pluginmanager.h"
#include "omniobject.h"

Expand Down Expand Up @@ -26,6 +26,12 @@ void PluginManager::setStackedWidget(PluginStackedWidget* pWidget)


bool PluginManager::isPluginExist(const QString& key)
{
Plugin* p = m_plugins.value(key);
return p != Q_NULLPTR;
}

Plugin* PluginManager::queryPlugin(const QString& key) const
{
Plugin* p = m_plugins.value(key);
return p;
Expand All @@ -37,10 +43,7 @@ void PluginManager::onStartQuery(const QString& key, const QString& value)
if (!p)
return;

//¸ù¾ÝÀàÐÍÑ¡Ôñ¶ÔÓ¦widget
m_stackedWidget->setCurrentWidget(p->type());
m_stackedWidget->show();
p->query(value, m_stackedWidget->widget(p->type()));
execQuery(p, value);
}

void PluginManager::firstInit()
Expand Down Expand Up @@ -71,23 +74,25 @@ void PluginManager::init()
QString strVer = configSetting.value("version").toString();
QString strAuthor = configSetting.value("author").toString();
Plugin::PluginType t = Plugin::getTypeFromStr(configSetting.value("type").toString());
OmniObject::RespondType rt = configSetting.value("respondtype").toString() == "delay" ?
OmniObject::RespondType::Delay : OmniObject::RespondType::Real;
switch (t)
{
case Plugin::PluginType::JS_SIMPLE:
{
JsSimplePlugin* p = new JsSimplePlugin(this, strName, strKey, strVer, strAuthor, info.filePath());
JsSimplePlugin* p = new JsSimplePlugin(this, strName, strKey, strVer, strAuthor, info.filePath(), rt);
m_plugins.insert(strKey, p);
break;
}
case Plugin::PluginType::CPP_FREE:
{
CppFreePlugin* p = new CppFreePlugin(this, strName, strKey, strVer, strAuthor, info.filePath());
CppFreePlugin* p = new CppFreePlugin(this, strName, strKey, strVer, strAuthor, info.filePath(), rt);
m_plugins.insert(strKey, p);
break;
}
case Plugin::PluginType::CPP_SIMPLELIST:
{
CppSimpleListPlugin* p = new CppSimpleListPlugin(this, strName, strKey, strVer, strAuthor, info.filePath());
CppSimpleListPlugin* p = new CppSimpleListPlugin(this, strName, strKey, strVer, strAuthor, info.filePath(), rt);
m_plugins.insert(strKey, p);
break;
}
Expand All @@ -97,6 +102,14 @@ void PluginManager::init()
}
}

void PluginManager::execQuery(Plugin* pPlugin, const QString& value)
{
//根据类型选择对应widget
m_stackedWidget->setCurrentWidget(pPlugin->type());
m_stackedWidget->show();
pPlugin->query(value, m_stackedWidget->widget(pPlugin->type()));
}

PluginStackedWidget::PluginStackedWidget(QWidget* parent)
: QStackedWidget(parent)
, m_omniPlugin(new OmniPlugin())
Expand Down
Loading

0 comments on commit 57b4110

Please sign in to comment.