Warning, file /utilities/skanpage/src/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * SPDX-FileCopyrightText: 2015 by Kåre Särs <kare.sars@iki .fi>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include <QApplication>
0008 #include <QQmlApplicationEngine>
0009 #include <QQmlContext>
0010 #include <QCommandLineParser>
0011 #include <QIcon>
0012 #include <QImage>
0013 
0014 #include <KAboutData>
0015 #include <KCrash>
0016 #include <KLocalizedContext>
0017 #include <KLocalizedString>
0018 #include <Option>
0019 
0020 #include "DevicesModel.h"
0021 #include "DocumentModel.h"
0022 #include "FormatModel.h"
0023 #include "FilteredOptionsModel.h"
0024 #include "OCRLanguageModel.h"
0025 #include "InProgressPainter.h"
0026 #include "Skanpage.h"
0027 #include "SkanpageUtils.h"
0028 #include "skanpage_version.h"
0029 #include "skanpage_config.h"
0030 #include "skanpage_state.h"
0031 
0032 int main(int argc, char *argv[])
0033 {
0034 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0035     QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0036     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0037 #endif
0038     QApplication app(argc, argv);
0039 
0040     qmlRegisterUncreatableType<DocumentModel>("org.kde.skanpage", 1, 0, "DocumentModel", QStringLiteral("Document model class uncreateable"));
0041     qmlRegisterUncreatableType<DevicesModel>("org.kde.skanpage", 1, 0, "DevicesModel", QStringLiteral("Device model class uncreateable"));
0042     qmlRegisterUncreatableType<FormatModel>("org.kde.skanpage", 1, 0, "FormatModel", QStringLiteral("Format model class uncreateable"));
0043     qmlRegisterUncreatableType<FilteredOptionsModel>("org.kde.skanpage", 1, 0, "FilteredOptionsModel", QStringLiteral("Filtered options model class uncreateable"));
0044     qmlRegisterUncreatableType<OCRLanguageModel>("org.kde.skanpage", 1, 0, "OCRLanguageModel", QStringLiteral("OCR language model class uncreateable"));;
0045     qmlRegisterUncreatableType<KSaneCore::Option>("org.kde.skanpage", 1, 0, "KSaneOption", QStringLiteral("KSaneOption class uncreateable"));
0046     qmlRegisterUncreatableType<Skanpage>("org.kde.skanpage", 1, 0, "Skanpage", QStringLiteral("Skanpage application class uncreateable"));
0047     qmlRegisterUncreatableType<SkanpageConfiguration>("org.kde.skanpage", 1, 0, "Configuration", QStringLiteral("Confguration class uncreatable"));
0048     qmlRegisterUncreatableType<SkanpageState>("org.kde.skanpage", 1, 0, "StateConfiguration", QStringLiteral("State class uncreatable"));
0049     qmlRegisterUncreatableMetaObject(SkanpageUtils::staticMetaObject, "org.kde.skanpage", 1, 0, "SkanpageUtils", QStringLiteral("Error: only enums"));
0050     qmlRegisterType<InProgressPainter>("org.kde.skanpage", 1, 0, "InProgressPainter");
0051     qRegisterMetaType<SkanpageUtils::MessageLevel>();
0052     qRegisterMetaType<SkanpageUtils::FileType>();
0053     qRegisterMetaType<SkanpageUtils::PageProperties>();
0054     qRegisterMetaType<SkanpageUtils::DocumentPages>();
0055     qRegisterMetaType<QImage>();
0056 
0057     KLocalizedString::setApplicationDomain("skanpage");
0058 
0059     KAboutData aboutData(QLatin1String("skanpage"),
0060                          i18n("Skanpage"),
0061                          QLatin1String(SKANPAGE_VERSION_STRING),
0062                          i18n("Multi-page scanning application by KDE."),
0063                          KAboutLicense::GPL,
0064                          i18n("© 2015-2022 Kåre Särs, Alexander Stippich")
0065     );
0066 
0067     aboutData.addAuthor(QStringLiteral("Kåre Särs"), i18n("developer"), QLatin1String("kare.sars@iki.fi"));
0068     aboutData.addAuthor(QStringLiteral("Alexander Stippich"), i18n("developer"), QLatin1String("a.stippich@gmx.net"));
0069     aboutData.setBugAddress("https://bugs.kde.org/enter_bug.cgi?product=skanpage");
0070 
0071     app.setWindowIcon(QIcon::fromTheme(QLatin1String("skanpage")));
0072 
0073     KAboutData::setApplicationData(aboutData);
0074     KCrash::initialize();
0075 
0076     QCommandLineParser parser;
0077     aboutData.setupCommandLine(&parser);
0078     QCommandLineOption deviceOption(
0079         QStringList({QLatin1String("d"), QLatin1String("device")}), i18n("Sane scanner device name. Use 'test' for test device."), i18n("device"));
0080     parser.addOption(deviceOption);
0081     parser.process(app);
0082     // the --author and --license is shown anyway but they work only with the following line
0083     aboutData.processCommandLine(&parser);
0084 
0085     const QString deviceName = parser.value(deviceOption);
0086 
0087     Skanpage skanpageApp = Skanpage(deviceName);
0088 
0089     QQmlApplicationEngine engine;
0090 
0091     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0092     engine.rootContext()->setContextProperty(QStringLiteral("skanpage"), &skanpageApp);
0093     engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(aboutData));
0094     engine.load(QUrl(QStringLiteral("qrc:/qml/MainWindow.qml")));
0095 
0096     return app.exec();
0097 }