KHealthCertificate

khealthcertificateqmlplugin.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include <KHealthCertificate/KHealthCertificate>
8 #include <KHealthCertificate/KHealthCertificateParser>
9 #include <KHealthCertificate/KRecoveryCertificate>
10 #include <KHealthCertificate/KTestCertificate>
11 #include <KHealthCertificate/KVaccinationCertificate>
12 
13 #include <QCoreApplication>
14 #include <QQmlContext>
15 #include <QQmlEngine>
16 #include <QQmlExtensionPlugin>
17 
18 class KHealthCertificateQmlPlugin : public QQmlExtensionPlugin
19 {
20  Q_OBJECT
21  Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
22 public:
23  void registerTypes(const char* uri) override;
24 };
25 
26 
27 class KHealthCertificateParserWrapper
28 {
29  Q_GADGET
30 public:
31  Q_INVOKABLE QVariant parse(const QVariant &data) const;
32 };
33 
34 QVariant KHealthCertificateParserWrapper::parse(const QVariant &data) const
35 {
36  if (data.type() == QVariant::ByteArray) {
38  }
39  if (data.type() == QVariant::String) {
41  }
42  return {};
43 }
44 
45 void KHealthCertificateQmlPlugin::registerTypes(const char*)
46 {
47  qRegisterMetaType<KRecoveryCertificate>();
48  qRegisterMetaType<KTestCertificate>();
49  qRegisterMetaType<KVaccinationCertificate>();
50 
51  qmlRegisterUncreatableType<KHealthCertificate>("org.kde.khealthcertificate", 1, 0, "HealthCertificate", {});
52  qmlRegisterUncreatableType<KTestCertificate>("org.kde.khealthcertificate", 1, 0, "TestCertificate", {});
53 
54  // HACK qmlplugindump chokes on gadget singletons, to the point of breaking ecm_find_qmlmodule()
55  if (QCoreApplication::applicationName() != QLatin1String("qmlplugindump")) {
56  qmlRegisterSingletonType("org.kde.khealthcertificate", 1, 0, "HealthCertificateParser", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
57  return engine->toScriptValue(KHealthCertificateParserWrapper());
58  });
59  }
60 }
61 
62 #include "khealthcertificateqmlplugin.moc"
QByteArray toByteArray() const const
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Parse a single digital health certificate.
QJSValue toScriptValue(const T &value)
QVariant::Type type() const const
QVector< QVariant > parse(const QString &message, const QDateTime &externalIssueDateTime=QDateTime())
QString toString() const const
QString applicationName()
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 18 2021 23:21:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.