1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef PLUGINMETAOBJECT_H
6#define PLUGINMETAOBJECT_H
7
8#include "framework/framework_global.h"
9#include "framework/lifecycle/plugindepend.h"
10
11#include <QSharedData>
12#include <QPluginLoader>
13
14DPF_BEGIN_NAMESPACE
15
16/**
17 * @brief PluginMetaT1 模板类
18 * @details 此模板类为扩展特性,可实现不同插件元数据
19 * 目前只是预留接口
20 * @tparam 传入插件对象接口例如 Plugin
21 */
22template <class T>
23class PluginMetaT1 : public QSharedData
24{
25 Q_DISABLE_COPY(PluginMetaT1)
26public:
27 PluginMetaT1(){}
28};
29
30/** 插件json元文件示例
31 * @code
32 * {
33 * "Name" : "more",
34 * "Version" : "4.8.2",
35 * "CompatVersion" : "4.8.0",
36 * "Category" : "more",
37 * "Description" : "The core plugin for the Qt IDE.",
38 * "Vendor" : "The Qt Company Ltd",
39 * "Copyright" : "(C) 2019 The Qt Company Ltd",
40 * "License" : [
41 * "https://www.gnu.org/licenses/gpl-3.0.html"
42 * ],
43 * "UrlLink" : "http://www.qt.io",
44 * "Depends" : [
45 * {"Name" : "core", "Version" : "4.8.2"},
46 * {"Name" : "other", "Version" : "4.8.2"}
47 * ]
48 * }
49 * @endcode
50 */
51
52class Plugin;
53class PluginContext;
54class PluginService;
55
56/**
57 * @brief The PluginMetaObject class
58 * 插件元数据对象
59 * @details 该类与SharedPointer配套使用时是线程安全的
60 */
61class PluginMetaObjectPrivate;
62class PluginMetaObject final : public PluginMetaT1<Plugin>
63{
64 QSharedPointer<PluginMetaObjectPrivate> d;
65
66 friend class PluginManager;
67 friend class PluginManagerPrivate;
68 friend Q_CORE_EXPORT QDebug operator<< (QDebug, const PluginMetaObject &);
69
70public:
71
72 enum State {
73 Invalid, /// 插件未操作获得任何状态
74 Reading, /// 插件正在读取Json
75 Readed, /// 插件读取Json完毕
76 Loading, /// 插件正在加载
77 Loaded, /// 插件已加载
78 Initialized, /// 插件已经操作Initialized函数
79 Started, /// 插件已经操作Start函数
80 Stoped, /// 插件已停操作Stop函数
81 Shutdown, /// 插件卸载并已经释放
82 };
83
84 PluginMetaObject();
85 PluginMetaObject(const PluginMetaObject &meta);
86 PluginMetaObject& operator = (const PluginMetaObject &meta);
87 QString fileName() const;
88 QString iid() const;
89 QString name() const;
90 QString version() const;
91 QString compatVersion() const;
92 QString category() const;
93 QString vendor() const;
94 QString copyright() const;
95 QStringList license() const;
96 QString description() const;
97 QString urlLink() const;
98 QList<PluginDepend> depends() const;
99 State pluginState() const;
100 QSharedPointer<Plugin> plugin();
101 bool isEnabledBySettings();
102 bool isDisabledBySettings();
103 void setEnabledBySettings(bool value);
104
105 //state
106 State state() const;
107 QString errorString();
108};
109
110typedef QSharedPointer<DPF_NAMESPACE::PluginMetaObject> PluginMetaObjectPointer;
111
112QT_BEGIN_NAMESPACE
113#ifndef QT_NO_DEBUG_STREAM
114Q_CORE_EXPORT QDebug operator<< (QDebug, const DPF_NAMESPACE::PluginMetaObject &);
115Q_CORE_EXPORT QDebug operator<< (QDebug, const DPF_NAMESPACE::PluginMetaObjectPointer &);
116#endif //QT_NO_DEBUG_STREAM
117QT_END_NAMESPACE
118
119DPF_END_NAMESPACE
120
121#endif // PLUGINMETAOBJECT_H
122