File indexing completed on 2026-07-12 13:30:34
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include <QCommandLineParser> 0009 #include <QIcon> 0010 #include <QMetaObject> 0011 #include <QQmlApplicationEngine> 0012 #include <QQmlContext> 0013 #include <QQmlEngine> 0014 #include <QQuickStyle> 0015 #include <QUrl> 0016 #include <QtQml> 0017 0018 #ifdef Q_OS_ANDROID 0019 #include <QGuiApplication> 0020 #else 0021 #include <QApplication> 0022 #endif 0023 0024 #include <KAboutData> 0025 #include <KConfig> 0026 #include <KLocalizedContext> 0027 #include <KLocalizedString> 0028 0029 #include "formatter.h" 0030 #include "kweathersettings.h" 0031 #include "locationquerymodel.h" 0032 #include "temperaturechartdata.h" 0033 #include "version.h" 0034 #ifndef Q_OS_ANDROID 0035 #include "weatherbackground.h" 0036 #endif 0037 #include "weatherlocation.h" 0038 #include "weatherlocationlistmodel.h" 0039 0040 class AbstractHourlyWeatherForecast; 0041 class AbstractDailyWeatherForecast; 0042 0043 Q_DECL_EXPORT int main(int argc, char *argv[]) 0044 { 0045 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 0046 0047 #ifdef Q_OS_ANDROID 0048 QGuiApplication app(argc, argv); 0049 QQuickStyle::setStyle(QStringLiteral("org.kde.breeze")); 0050 #else 0051 // set default style 0052 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { 0053 QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); 0054 } 0055 // if using org.kde.desktop, ensure we use kde style if possible 0056 if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORMTHEME")) { 0057 qputenv("QT_QPA_PLATFORMTHEME", "kde"); 0058 } 0059 0060 QApplication app(argc, argv); 0061 #endif 0062 QQmlApplicationEngine engine; 0063 0064 KLocalizedString::setApplicationDomain("kweather"); 0065 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0066 KAboutData aboutData(QStringLiteral("kweather"), 0067 i18n("Weather"), 0068 QStringLiteral(KWEATHER_VERSION_STRING), 0069 i18n("A convergent weather application for Plasma"), 0070 KAboutLicense::GPL, 0071 i18n("© 2020-2022 Plasma Development Team")); 0072 aboutData.setBugAddress("https://bugs.kde.org/describecomponents.cgi?product=kweather"); 0073 aboutData.addAuthor(i18n("Han Young"), QString(), QStringLiteral("hanyoung@protonmail.com")); 0074 aboutData.addAuthor(i18n("Devin Lin"), QString(), QStringLiteral("espidev@gmail.com"), QStringLiteral("https://espi.dev")); 0075 KAboutData::setApplicationData(aboutData); 0076 0077 QCommandLineParser parser; 0078 aboutData.setupCommandLine(&parser); 0079 parser.process(app); 0080 aboutData.processCommandLine(&parser); 0081 0082 qmlRegisterSingletonType("kweather", 1, 0, "AboutData", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { 0083 return engine->toScriptValue(KAboutData::applicationData()); 0084 }); 0085 0086 qmlRegisterSingletonType<WeatherLocationListModel>("kweather", 1, 0, "WeatherLocationListModel", [](QQmlEngine *engine, QJSEngine *) -> QObject * { 0087 return WeatherLocationListModel::inst(); 0088 }); 0089 0090 engine.rootContext()->setContextProperty(QStringLiteral("settingsModel"), KWeatherSettings::self()); 0091 0092 WeatherLocation *emptyWeatherLocation = new WeatherLocation(); 0093 engine.rootContext()->setContextProperty(QStringLiteral("emptyWeatherLocation"), emptyWeatherLocation); 0094 #ifdef Q_OS_ANDROID 0095 engine.rootContext()->setContextProperty(QStringLiteral("KWEATHER_IS_ANDROID"), true); 0096 #else 0097 engine.rootContext()->setContextProperty(QStringLiteral("KWEATHER_IS_ANDROID"), false); 0098 #endif 0099 Formatter formatter; 0100 qmlRegisterSingletonInstance<Formatter>("kweather", 1, 0, "Formatter", &formatter); 0101 0102 qmlRegisterType<TemperatureChartData>("kweather", 1, 0, "TemperatureChartData"); 0103 qmlRegisterType<LocationQueryModel>("kweather", 1, 0, "LocationQueryModel"); 0104 qmlRegisterType<WeatherLocation>("kweather", 1, 0, "WeatherLocation"); 0105 #ifndef Q_OS_ANDROID 0106 qmlRegisterType<WeatherBackgroundRenderer>("kweather", 1, 0, "WeatherBackground"); 0107 #endif 0108 0109 qRegisterMetaType<KWeatherCore::HourlyWeatherForecast>(); 0110 qRegisterMetaType<KWeatherCore::DailyWeatherForecast>(); 0111 qRegisterMetaType<QList<WeatherLocation *>>(); 0112 0113 // load setup wizard if first launch 0114 engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); 0115 0116 // required for X11 0117 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.kweather"))); 0118 0119 if (engine.rootObjects().isEmpty()) { 0120 return -1; 0121 } 0122 0123 return app.exec(); 0124 }