File indexing completed on 2022-09-27 15:54:07

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Jonah Brüchert <jbb@kaidan.im>
0003  *  SPDX-FileCopyrightText: 2019 Simon Schmeisser <s.schmeisser@gmx.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 #include <qglobal.h>
0009 #ifndef Q_OS_ANDROID
0010 #include <QApplication>
0011 #else
0012 #include <QGuiApplication>
0013 #endif
0014 #include <QCommandLineParser>
0015 #include <QIcon>
0016 #include <QQmlApplicationEngine>
0017 #include <QUrl>
0018 #include <QtQml>
0019 
0020 #include <KAboutData>
0021 #include <KLocalizedContext>
0022 #include <KLocalizedString>
0023 
0024 #include "QrCodeContent.h"
0025 // #include "QrCodeScannerFilter.h"
0026 #include "Qrca.h"
0027 #include "notificationmanager.h"
0028 #include "clipboard.h"
0029 
0030 Q_DECL_EXPORT int main(int argc, char *argv[])
0031 {
0032     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0033 #ifndef Q_OS_ANDROID
0034     QApplication app(argc, argv);
0035 #else
0036     QGuiApplication app(argc, argv);
0037 #endif
0038     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0039     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0040     QCoreApplication::setApplicationName(QStringLiteral("qrca"));
0041 
0042     QCommandLineParser parser;
0043     parser.addHelpOption();
0044     parser.addOption(QCommandLineOption(QStringLiteral("encode"), QStringLiteral("Text to encode into a QR-Code"), QStringLiteral("encode"), {}));
0045     parser.process(app);
0046 
0047     // setup translation string domain for the i18n calls
0048     KLocalizedString::setApplicationDomain("qrca");
0049     // create a KAboutData object to use for setting the application metadata
0050     KAboutData aboutData(
0051         QStringLiteral("qrca"), i18n("Qrca"), QStringLiteral("0.1"), i18n("A simple QR scanner"), KAboutLicense::GPL_V3, i18n("Copyright 2016-2019 Qrca and Kaidan authors"), QString(), QStringLiteral("https://www.plasma-mobile.org"));
0052     // overwrite default-generated values of organizationDomain & desktopFileName
0053     aboutData.addAuthor(i18n("Jonah Brüchert"), QString(), QStringLiteral("jbb@kaidan.im"), QStringLiteral("https://jbbgameich.github.io"));
0054     aboutData.addAuthor(i18n("Simon Schmeißer"));
0055     aboutData.setOrganizationDomain("kde.org");
0056     aboutData.setDesktopFileName(QStringLiteral("org.kde.qrca"));
0057     // set the application metadata
0058     KAboutData::setApplicationData(aboutData);
0059     // in GUI apps set the window icon manually, not covered by KAboutData
0060     // needed for environments where the icon name is not extracted from
0061     // the information in the application's desktop file
0062     QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.qrca")));
0063     aboutData.setProgramLogo(app.windowIcon());
0064 
0065     qmlRegisterUncreatableType<QrCodeContent>("org.kde.qrca", 1, 0, "QrCodeContent", {});
0066     qmlRegisterSingletonType<NotificationManager>("org.kde.qrca", 1, 0, "NotificationManager", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
0067         Q_UNUSED(engine)
0068         Q_UNUSED(scriptEngine)
0069 
0070         return new NotificationManager();
0071     });
0072     qmlRegisterSingletonType<Clipboard>("org.kde.qrca", 1, 0, "Clipboard", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
0073         Q_UNUSED(engine)
0074         Q_UNUSED(scriptEngine)
0075 
0076         return new Clipboard();
0077     });
0078     qRegisterMetaType<QrCodeContent>();
0079 
0080     Qrca qrca;
0081     qrca.setAboutData(aboutData);
0082     qrca.setEncodeText(parser.value(QStringLiteral("encode")));
0083     qmlRegisterSingletonInstance<Qrca>("org.kde.qrca", 1, 0, "Qrca", &qrca);
0084 
0085     QQmlApplicationEngine engine;
0086     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0087 
0088     engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
0089 
0090     if (engine.rootObjects().isEmpty()) {
0091         return -1;
0092     }
0093 
0094     return app.exec();
0095 }