1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "pluginmetaobject.h"
6#include "private/pluginmetaobject_p.h"
7
8#include <QDebug>
9
10DPF_BEGIN_NAMESPACE
11
12/**
13 * @brief PluginMetaObject::version
14 * 获取插件元数据中插件版本
15 * @return
16 */
17QString PluginMetaObject::version() const
18{
19 return d->version;
20}
21
22/**
23 * @brief PluginMetaObject::compatVersion
24 * 获取插件元数据中兼容版本
25 * @return
26 */
27QString PluginMetaObject::compatVersion() const
28{
29 return d->compatVersion;
30}
31
32/**
33 * @brief PluginMetaObject::vendor
34 * 获取插件元数据中插件所有者
35 * @return
36 */
37QString PluginMetaObject::vendor() const
38{
39 return d->vendor;
40}
41
42/**
43 * @brief PluginMetaObject::copyright
44 * 获取插件元数据中的插件版权
45 * @return
46 */
47QString PluginMetaObject::copyright() const
48{
49 return d->copyright;
50}
51
52/**
53 * @brief PluginMetaObject::license
54 * 获取插件元数据中开源许可协议
55 * @return
56 */
57QStringList PluginMetaObject::license() const
58{
59 return d->license;
60}
61
62/**
63 * @brief PluginMetaObject::description
64 * 获取插件元数据中插件描述
65 * @return
66 */
67QString PluginMetaObject::description() const
68{
69 return d->description;
70}
71
72/**
73 * @brief PluginMetaObject::category
74 * 获取插件元数据中插件类别
75 * @return
76 */
77QString PluginMetaObject::category() const
78{
79 return d->category;
80}
81
82/**
83 * @brief PluginMetaObject::urlLink
84 * 获取插件元数据中插件主页链接
85 * @return
86 */
87QString PluginMetaObject::urlLink() const
88{
89 return d->urlLink;
90}
91
92/**
93 * @brief PluginMetaObject::depends
94 * 获取插件元数据中插件启动依赖
95 * @return
96 */
97QList<PluginDepend> PluginMetaObject::depends() const
98{
99 return d->depends;
100}
101
102/**
103 * @brief PluginMetaObject::pluginState
104 * 获取插件当前状态
105 * @return
106 */
107PluginMetaObject::State PluginMetaObject::pluginState() const
108{
109 return d->state;
110}
111
112/**
113 * @brief PluginMetaObject::plugin
114 * 获取插件对象接口
115 * @return
116 */
117QSharedPointer<Plugin> PluginMetaObject::plugin()
118{
119 return d->plugin;
120}
121
122/**
123 * @brief PluginMetaObject::errorString
124 * 获取插件加载错误信息
125 * @return
126 */
127QString PluginMetaObject::errorString()
128{
129 return d->error;
130}
131
132bool PluginMetaObject::isEnabledBySettings()
133{
134 return d->enabledBySettings;
135}
136
137bool PluginMetaObject::isDisabledBySettings()
138{
139 return d->disabledBySettings;
140}
141
142void PluginMetaObject::setEnabledBySettings(bool value)
143{
144 d->enabledBySettings = value;
145}
146
147PluginMetaObject::State PluginMetaObject::state() const
148{
149 return d->state;
150}
151
152/**
153 * @brief 默认构造函数
154 */
155PluginMetaObject::PluginMetaObject()
156 : d(new PluginMetaObjectPrivate(this))
157{
158
159}
160
161/**
162 * @brief 拷贝构造函数
163 */
164PluginMetaObject::PluginMetaObject(const PluginMetaObject &meta)
165{
166 d->iid = meta.iid();
167 d->name = meta.name();
168 d->version = meta.version();
169 d->compatVersion = meta.compatVersion();
170 d->category = meta.category();
171 d->license = meta.license();
172 d->description = meta.description();
173 d->urlLink = meta.urlLink();
174 d->depends = meta.depends();
175 d->state = pluginState();
176 d->plugin = plugin();
177 d->loader = meta.d->loader;
178}
179/**
180 * @brief 赋值拷贝
181 */
182PluginMetaObject &PluginMetaObject::operator =(const PluginMetaObject &meta)
183{
184 d->iid = meta.iid();
185 d->name = meta.name();
186 d->version = meta.version();
187 d->compatVersion = meta.compatVersion();
188 d->category = meta.category();
189 d->license = meta.license();
190 d->description = meta.description();
191 d->urlLink = meta.urlLink();
192 d->depends = meta.depends();
193 d->state = pluginState();
194 d->plugin = plugin();
195 d->loader = meta.d->loader;
196 return *this;
197}
198
199/**
200 * @brief PluginMetaObject::fileName
201 * 获取插件文件路径名称
202 * @return
203 */
204QString PluginMetaObject::fileName() const
205{
206 return d->loader->fileName();
207}
208
209/**
210 * @brief PluginMetaObject::iid
211 * 获取插件元数据中iid
212 * @return
213 */
214QString PluginMetaObject::iid() const
215{
216 return d->iid;
217}
218
219/**
220 * @brief PluginMetaObject::name
221 * 获取插件元数据中名称
222 * @return
223 */
224QString PluginMetaObject::name() const
225{
226 return d->name;
227}
228
229/**
230 * @brief PluginDepend::PluginDepend
231 * 构造函数
232 */
233PluginDepend::PluginDepend()
234{
235
236}
237
238/**
239 * @brief PluginDepend::PluginDepend
240 * 拷贝构造
241 * @param depend
242 */
243PluginDepend::PluginDepend(const PluginDepend &depend)
244{
245 pluginName = depend.name();
246 pluginVersion = depend.version();
247}
248
249/**
250 * @brief PluginDepend::operator =
251 * 赋值拷贝
252 * @param depend
253 * @return
254 */
255PluginDepend &PluginDepend::operator =(const PluginDepend &depend)
256{
257 pluginName = depend.name();
258 pluginVersion = depend.version();
259 return *this;
260}
261
262
263QT_BEGIN_NAMESPACE
264/**
265 * @brief operator <<
266 * 重定向全局Debug打印PluginDepend对象的函数
267 * @param out
268 * @param depend
269 * @return
270 */
271Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginDepend &depend)
272{
273 DPF_USE_NAMESPACE
274 out << "PluginDepend(" << QString("0x%0").arg(qint64(&depend),0,16) << "){";
275 out << PLUGIN_NAME << " : " << depend.name() << "; ";
276 out << PLUGIN_VERSION << " : " << depend.version() << "; ";
277 out << "}";
278 return out;
279}
280
281/**
282 * @brief operator <<
283 * 重定向全局Debug打印PluginMetaObject对象的函数
284 * @param out
285 * @param metaObj
286 * @return
287 */
288Q_CORE_EXPORT QDebug operator<< (QDebug out, const DPF_NAMESPACE::PluginMetaObject &metaObj)
289{
290 DPF_USE_NAMESPACE
291 out << "PluginMetaObject(" << QString("0x%0").arg(qint64(&metaObj),0,16) << "){";
292 out << "IID" << ":" << metaObj.iid() << "; ";
293 out << PLUGIN_NAME << ":" << metaObj.name() << "; ";
294 out << PLUGIN_VERSION << ":" << metaObj.version() << "; ";
295 out << PLUGIN_COMPATVERSION << ":" << metaObj.compatVersion() << "; ";
296 out << PLUGIN_CATEGORY << ":" << metaObj.category() << "; ";
297 out << PLUGIN_VENDOR << ":" << metaObj.vendor() << "; ";
298 out << PLUGIN_COPYRIGHT << ":" << metaObj.copyright() << "; ";
299 out << PLUGIN_DESCRIPTION << ":" << metaObj.description() << "; ";
300 out << PLUGIN_LICENSE << ":" << metaObj.license() << "; ";
301 out << PLUGIN_URLLINK << ":" << metaObj.urlLink() << "; ";
302 out << PLUGIN_DEPENDS << ":" << metaObj.depends() << ";";
303 out << "}";
304 return out;
305}
306
307/**
308 * @brief operator <<
309 * 重定向全局Debug入口函数
310 * @param out
311 * @param pointer
312 * @return
313 */
314Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginMetaObjectPointer &pointer)
315{
316 out << *pointer;
317 return out;
318}
319
320QT_END_NAMESPACE
321
322DPF_END_NAMESPACE
323