File indexing completed on 2024-05-19 05:51:35
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 #include <QCommandLineOption> 0007 #include <QCommandLineParser> 0008 #include <QIcon> 0009 #include <QObject> 0010 #include <QQmlApplicationEngine> 0011 #include <QQmlContext> 0012 #include <QQuickStyle> 0013 0014 #ifdef Q_OS_ANDROID 0015 #include <QGuiApplication> 0016 #else 0017 #include <QApplication> 0018 #endif 0019 0020 #include <KAboutData> 0021 #include <KLocalizedContext> 0022 #include <KLocalizedString> 0023 0024 #include "historymanager.h" 0025 #include "inputmanager.h" 0026 #include "kalkconfig.h" 0027 #include "unitmodel.h" 0028 #include "version.h" 0029 0030 #ifdef Q_OS_ANDROID 0031 Q_DECL_EXPORT 0032 #endif 0033 int main(int argc, char *argv[]) 0034 { 0035 QCommandLineParser parser; 0036 0037 #ifdef Q_OS_ANDROID 0038 QGuiApplication app(argc, argv); 0039 QQuickStyle::setStyle(QStringLiteral("org.kde.breeze")); 0040 #else 0041 QApplication app(argc, argv); 0042 // set default style and icon theme 0043 QIcon::setFallbackThemeName(QStringLiteral("breeze")); 0044 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { 0045 QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); 0046 } 0047 // if using org.kde.desktop, ensure we use kde style if possible 0048 if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORMTHEME")) { 0049 qputenv("QT_QPA_PLATFORMTHEME", "kde"); 0050 } 0051 #endif 0052 QQmlApplicationEngine engine; 0053 KLocalizedString::setApplicationDomain(QByteArrayLiteral("kalk")); 0054 parser.addVersionOption(); 0055 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0056 0057 engine.rootContext()->setContextProperty(QStringLiteral("historyManager"), HistoryManager::inst()); 0058 engine.rootContext()->setContextProperty(QStringLiteral("inputManager"), InputManager::inst()); 0059 engine.rootContext()->setContextProperty(QStringLiteral("unitModel"), UnitModel::inst()); 0060 0061 KAboutData aboutData(QStringLiteral("kalk"), 0062 i18n("Calculator"), 0063 QStringLiteral(KALK_VERSION_STRING), 0064 i18n("Calculator for Plasma"), 0065 KAboutLicense::GPL, 0066 i18n("© 2020-2022 KDE Community")); 0067 aboutData.setBugAddress("https://bugs.kde.org/describecomponents.cgi?product=kalk"); 0068 KAboutData::setApplicationData(aboutData); 0069 0070 parser.process(app); 0071 0072 qmlRegisterSingletonInstance("org.kde.kalk.config", 1, 0, "Config", KalkConfig::self()); 0073 qmlRegisterSingletonType("org.kde.kalk", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { 0074 return engine->toScriptValue(KAboutData::applicationData()); 0075 }); 0076 #ifdef QT_DEBUG 0077 engine.rootContext()->setContextProperty(QStringLiteral("debug"), true); 0078 #else 0079 engine.rootContext()->setContextProperty(QStringLiteral("debug"), false); 0080 #endif 0081 // load main ui 0082 engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); 0083 0084 // required for X11 0085 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.kalk"))); 0086 0087 return app.exec(); 0088 }