File indexing completed on 2024-12-15 04:57:02

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0004 */
0005 
0006 #include <QCommandLineParser>
0007 #include <QIcon>
0008 #include <QQmlApplicationEngine>
0009 #include <QQuickStyle>
0010 #include <QUrl>
0011 #include <QtQml>
0012 
0013 #ifdef Q_OS_ANDROID
0014 #include <QGuiApplication>
0015 #else
0016 #include <QApplication>
0017 #endif
0018 
0019 #include <KAboutData>
0020 #include <KLocalizedContext>
0021 #include <KLocalizedString>
0022 
0023 #include "certificatesmodel.h"
0024 #include "version.h"
0025 
0026 Q_DECL_EXPORT int main(int argc, char *argv[])
0027 {
0028 #ifdef Q_OS_ANDROID
0029     QGuiApplication app(argc, argv);
0030     QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
0031 #else
0032     QIcon::setFallbackThemeName(QStringLiteral("breeze"));
0033     QApplication app(argc, argv);
0034     // Default to org.kde.desktop style unless the user forces another style
0035     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0036         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0037     }
0038 #endif
0039 
0040     KLocalizedString::setApplicationDomain("vakzination");
0041 
0042     KAboutData about(QStringLiteral("vakzination"),
0043                      i18n("Vakzination"),
0044                      QStringLiteral(VAKZINATION_VERSION_STRING),
0045                      i18n("Vakzination manages your health certificates like vaccination, test, and recovery certificates."),
0046                      KAboutLicense::GPL_V2,
0047                      i18n("© 2021-2022 KDE Community"));
0048 
0049     about.addAuthor(i18n("Nicolas Fella"), i18n("Maintainer"), QStringLiteral("nicolas.fella@gmx.de"));
0050     about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0051     about.setOrganizationDomain("kde.org");
0052     KAboutData::setApplicationData(about);
0053 
0054     QCommandLineParser parser;
0055     about.setupCommandLine(&parser);
0056     parser.addOption(QCommandLineOption(QStringLiteral("testmode"), i18n("Show with test data")));
0057     QCommandLineOption isTemporaryOpt(QStringLiteral("tempfile"), QStringLiteral("Input file is a temporary file and will be deleted after importing."));
0058     parser.addOption(isTemporaryOpt);
0059     parser.addPositionalArgument(QStringLiteral("file"), i18n("File to import."));
0060     parser.process(app);
0061     about.processCommandLine(&parser);
0062 
0063     const bool testMode = parser.isSet(QStringLiteral("testmode"));
0064 
0065     QQmlApplicationEngine engine;
0066 
0067     CertificatesModel model(testMode);
0068     for (const auto &file : parser.positionalArguments()) {
0069         const auto url = QUrl::fromLocalFile(file);
0070         model.importCertificate(url);
0071         if (parser.isSet(isTemporaryOpt)) {
0072             QFile::remove(url.toLocalFile());
0073         }
0074     }
0075 
0076     qmlRegisterSingletonInstance("org.kde.vakzination", 1, 0, "CertificatesModel", &model);
0077 
0078     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0079     engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
0080 
0081     if (engine.rootObjects().isEmpty()) {
0082         return -1;
0083     }
0084 
0085     return app.exec();
0086 }