Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
add: a working command plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Qv2ray-dev authored and Qv2ray-dev committed Apr 23, 2020
1 parent 5bf253e commit f2e02d4
Show file tree
Hide file tree
Showing 19 changed files with 558 additions and 333 deletions.
135 changes: 0 additions & 135 deletions .github/workflows/build-simpleplugin-qmake.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build-simpleplugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Get Plugin Name
id: get_name
shell: bash
run: echo ::set-output name=NAME::QvSimplePlugin
run: echo ::set-output name=NAME::QvCommandPlugin
- name: Checking out sources
uses: actions/checkout@master
- name: Install Python 3.7 version
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "interface"]
path = interface
url = https://github.com/Qv2ray/QvPlugin-Interface/
[submodule "lib/QJsonStruct"]
path = lib/QJsonStruct
url = https://github.com/Qv2ray/QJsonStruct
21 changes: 14 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(QvSimplePlugin)
project(QvCommandPlugin)
cmake_minimum_required(VERSION 3.1.0)

set(CMAKE_CXX_STANDARD 14)
Expand All @@ -19,17 +19,24 @@ include(interface/QvPluginInterface.cmake)
include_directories(${QVPLUGIN_INTERFACE_INCLUDE_DIR})

add_library(${PROJECT_NAME} MODULE
SimplePlugin.hpp
SimplePlugin.cpp
CommandPlugin.hpp
CommandPlugin.cpp
core/EventHandler.cpp
core/EventHandler.hpp
core/Serializer.cpp
core/Serializer.hpp
core/Kernel.cpp
core/Kernel.hpp
core/CommandConfig.hpp
ui/CommandPluginSettings.cpp
ui/CommandPluginSettings.hpp
ui/CommandPluginSettings.ui
lib/QJsonStruct/QJsonStruct.hpp
resx.qrc
${QVPLUGIN_INTERFACE_HEADERS})

if(APPLE)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" $<TARGET_FILE:${PROJECT_NAME}>)
endif()

target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Gui
Expand Down
49 changes: 49 additions & 0 deletions CommandPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "CommandPlugin.hpp"

#include "ui/CommandPluginSettings.hpp"

CommandPlugin *CommandPlugin::instance = nullptr;

std::shared_ptr<QvPluginKernel> CommandPlugin::GetKernel()
{
return nullptr;
}

bool CommandPlugin::UpdateSettings(const QJsonObject &conf)
{
settings = CommandPluginConfig::fromJson(conf);
return true;
}

bool CommandPlugin::Initialize(const QString &, const QJsonObject &settings)
{
instance = this;
this->settings.loadJson(settings);
eventHandler = std::make_shared<SimpleEventHandler>(this);
return true;
}

const QJsonObject CommandPlugin::GetSettngs()
{
return settings.toJson();
}

std::shared_ptr<QvPluginEventHandler> CommandPlugin::GetEventHandler()
{
return eventHandler;
}

std::unique_ptr<QWidget> CommandPlugin::GetSettingsWidget()
{
return std::make_unique<CommandPluginSettings>();
}

std::unique_ptr<QvPluginEditor> CommandPlugin::GetEditorWidget(UI_TYPE)
{
return nullptr;
}

std::shared_ptr<QvPluginSerializer> CommandPlugin::GetSerializer()
{
return nullptr;
}
35 changes: 18 additions & 17 deletions SimplePlugin.hpp → CommandPlugin.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#pragma once

#include "QvPluginInterface.hpp"
#include "core/CommandConfig.hpp"
#include "core/EventHandler.hpp"
#include "core/Kernel.hpp"
#include "core/Serializer.hpp"

#include <QObject>
#include <QtPlugin>

class QLabel;
using namespace Qv2rayPlugin;

class SimplePlugin
class CommandPlugin
: public QObject
, Qv2rayInterface
{
Expand All @@ -24,17 +23,15 @@ class SimplePlugin
const QvPluginMetadata GetMetadata() const override
{
return QvPluginMetadata{
"QvSimplePlugin", //
"Qv2ray Workgroup", //
"qvplugin_test", //
"QvSimplePlugin is a simple plugin for testing.", //
QIcon(":/qv2ray.png"), //
{ CAPABILITY_CONNECTION_ENTRY, //
CAPABILITY_CONNECTIVITY, //
CAPABILITY_STATS, //
CAPABILITY_SYSTEM_PROXY }, //
{ SPECIAL_TYPE_KERNEL, //
SPECIAL_TYPE_SERIALIZOR } //
"Qv2ray Command Plugin", //
"Qv2ray Workgroup", //
"qvplugin_command", //
"Run any command when an event from Qv2ray occurs.", //
QIcon(":/assets/qv2ray.png"), //
{ CAPABILITY_CONNECTION_ENTRY, //
CAPABILITY_CONNECTIVITY, //
CAPABILITY_SYSTEM_PROXY }, //
{} //
};
}
//
Expand All @@ -44,17 +41,21 @@ class SimplePlugin
std::unique_ptr<QvPluginEditor> GetEditorWidget(UI_TYPE) override;
std::unique_ptr<QWidget> GetSettingsWidget() override;
//
static CommandPlugin *instance;
//
bool UpdateSettings(const QJsonObject &) override;
bool Initialize(const QString &, const QJsonObject &) override;
const QJsonObject GetSettngs() override;
const CommandPluginConfig Settings()
{
return settings;
}
//
signals:
void PluginLog(const QString &) const override;
void PluginErrorMessageBox(const QString &) const override;

private:
QJsonObject settings;
std::shared_ptr<QvPluginSerializer> serializer;
CommandPluginConfig settings;
std::shared_ptr<QvPluginEventHandler> eventHandler;
std::shared_ptr<QvPluginKernel> kernel;
};
20 changes: 0 additions & 20 deletions QvSimplePlugin.pro

This file was deleted.

57 changes: 0 additions & 57 deletions SimplePlugin.cpp

This file was deleted.

Loading

0 comments on commit f2e02d4

Please sign in to comment.