Debian Codegraph @

plugins/plugman/src/PluginInfo.cpp

raw symbols SCIP
1 /* Copyright (C) 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "PluginInfo.h"
19 #include <QDebug>
20 #include <QFile>
21 #include <QFileInfo>
22 #include <QJsonDocument>
23 #include <QJsonObject>
24 #include <QJsonArray>
25 #include <QJsonParseError>
26 #include <QByteArray>
27 #include <QStringBuilder>
28
29 Q_LOGGING_CATEGORY(PLUGIN_INFO, "dekko.plugman.info")
30
31 PluginInfo::PluginInfo(QObject *parent) : QObject(parent)
32 {
33 }
34
35
36 DekkoPlugin::DekkoPlugin(QObject *parent) : PluginInfo(parent)
37 {
38 }
39
40 DekkoPlugin* DekkoPlugin::fromSpec(const QString &specPath, QObject *parent)
41 {
42 QFile specFile(specPath);
43 specFile.open(QFile::ReadOnly);
44 QJsonParseError error;
45 QJsonDocument p_spec = QJsonDocument().fromJson(specFile.readAll(), &error);
46 if (p_spec.isObject()) {
47 QJsonObject spec = p_spec.object();
48 DekkoPlugin *p = new DekkoPlugin(parent);
49 p->setSpec(spec);
50 return p;
51 } else {
52 qCWarning(PLUGIN_INFO) << "Plugin failed to load at >> " << specPath;
53 if (!error.errorString().isEmpty()) {
54 qCWarning(PLUGIN_INFO) << "Error: " << error.errorString();
55 } else {
56 qCWarning(PLUGIN_INFO) << "Plugin Spec not a json object!!!!!!!!";
57 }
58 return Q_NULLPTR;
59 }
60 }
61
62 QString DekkoPlugin::pluginId() const
63 {
64 return m_spec.value(QStringLiteral("id")).toString();
65 }
66
67 QString DekkoPlugin::location() const
68 {
69 return m_spec.value(QStringLiteral("register")).toString();
70 }
71
72 QString DekkoPlugin::component()
73 {
74 const QString path = m_pluginPath % "/" % m_spec.value(QStringLiteral("component")).toString();
75 if (QFileInfo(path).exists()) {
76 return path;
77 } else {
78 qCWarning(PLUGIN_INFO) << "Failed to find component component: " << path;
79 return QString();
80 }
81 }
82
83 QString DekkoPlugin::i18n() const
84 {
85 return m_spec.value(QStringLiteral("i18n")).toString();
86 }
87
88 QVariantMap DekkoPlugin::documentation() const
89 {
90 return m_spec.value(QStringLiteral("documentation")).toObject().toVariantMap();
91 }
92
93 QVariantMap DekkoPlugin::settings() const
94 {
95 return m_spec.value(QStringLiteral("settings")).toObject().toVariantMap();
96 }
97
98 QString DekkoPlugin::pluginPath() const
99 {
100 return m_pluginPath;
101 }
102
103 void DekkoPlugin::setSpec(const QJsonObject &spec)
104 {
105 m_spec = spec;
106 }
107
108 void DekkoPlugin::setPluginDirectory(const QString &path)
109 {
110 m_pluginPath = path;
111 }
112
113 ServicePlugin::ServicePlugin(QObject *parent) : PluginInfo(parent)
114 {
115 }
116
117 void ServicePlugin::messageReceived(const QString &key, const QVariant &value)
118 {
119 Q_UNUSED(key);
120 Q_UNUSED(value);
121 }