File indexing completed on 2025-01-05 03:29:15

0001 /*
0002  * SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 #include "config-kontrast.h"
0007 #include "savedcolormodel.h"
0008 #include <KAboutData>
0009 #include <KLocalizedContext>
0010 #include <KLocalizedString>
0011 #ifndef Q_OS_ANDROID
0012 #include <QApplication>
0013 #else
0014 #include <QGuiApplication>
0015 #endif
0016 #include "clipboard.h"
0017 #include "kontrast.h"
0018 #include <QCommandLineParser>
0019 #include <QDir>
0020 #include <QIcon>
0021 #include <QQmlApplicationEngine>
0022 #include <QQmlContext>
0023 #include <QSqlDatabase>
0024 #include <QSqlError>
0025 #include <QStandardPaths>
0026 #include <QUrl>
0027 
0028 const QString DRIVER(QStringLiteral("QSQLITE"));
0029 
0030 Q_DECL_EXPORT int main(int argc, char *argv[])
0031 {
0032 #ifndef Q_OS_ANDROID
0033     QApplication app(argc, argv);
0034 #else
0035     QGuiApplication app(argc, argv);
0036 #endif
0037     KLocalizedString::setApplicationDomain(QByteArrayLiteral("kontrast"));
0038 
0039     KAboutData aboutData(QStringLiteral("kontrast"),
0040                          i18nc("@title", "Kontrast"),
0041                          QStringLiteral(KONTRAST_VERSION_STRING),
0042                          i18nc("@title", "A contrast checker application"),
0043                          KAboutLicense::GPL_V3);
0044 
0045     aboutData.addAuthor(i18nc("@info:credit", "Carl Schwan"),
0046                         i18nc("@info:credit", "Maintainer and creator"),
0047                         QStringLiteral("carl@carlschwan.eu"),
0048                         QStringLiteral("https://carlschwan.eu"),
0049                         QUrl{QStringLiteral("https://carlschwan.eu/avatar.png")});
0050     aboutData.addCredit(i18nc("@info:credit", "Wikipedia"), i18nc("@info:credit", "Text on the main page CC-BY-SA-4.0"));
0051     aboutData.addAuthor(i18nc("@info:credit", "Carson Black"), i18nc("@info:credit", "SQLite backend for favorite colors"));
0052     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0053 
0054     KAboutData::setApplicationData(aboutData);
0055     QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.kontrast")));
0056 
0057     Q_ASSERT(QSqlDatabase::isDriverAvailable(DRIVER));
0058     bool success = QDir().mkpath(QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)));
0059     Q_ASSERT(success);
0060 
0061     QCommandLineParser parser;
0062     aboutData.setupCommandLine(&parser);
0063     parser.process(app);
0064     aboutData.processCommandLine(&parser);
0065 
0066     Kontrast kontrast;
0067     kontrast.random();
0068 
0069     QQmlApplicationEngine engine;
0070 
0071     qmlRegisterSingletonInstance("org.kde.kontrast.private", 1, 0, "Kontrast", &kontrast);
0072     qmlRegisterSingletonInstance("org.kde.kontrast.private", 1, 0, "ColorStore", new SavedColorModel(qApp));
0073     qmlRegisterType<Clipboard>("org.kde.kontrast.private", 1, 0, "Clipboard");
0074     qmlRegisterSingletonType("org.kde.kontrast.private", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0075         return engine->toScriptValue(KAboutData::applicationData());
0076     });
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 }