File indexing completed on 2024-05-19 05:55:48

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 <QApplication>
0009 #include <QCommandLineParser>
0010 #include <QIcon>
0011 #include <QMetaObject>
0012 #include <QQmlApplicationEngine>
0013 #include <QQmlContext>
0014 #include <QQmlEngine>
0015 #include <QQuickStyle>
0016 #include <QUrl>
0017 #include <QtQml>
0018 
0019 #include <KAboutData>
0020 #include <KConfig>
0021 #include <KLocalizedContext>
0022 #include <KLocalizedString>
0023 
0024 #include "kweathersettings.h"
0025 #include "version.h"
0026 #include "weatherlocation.h"
0027 
0028 class AbstractHourlyWeatherForecast;
0029 class AbstractDailyWeatherForecast;
0030 
0031 Q_DECL_EXPORT int main(int argc, char *argv[])
0032 {
0033     // We always NEED QApplication, since we use QtCharts
0034     QApplication app(argc, argv);
0035 
0036 #ifdef Q_OS_ANDROID
0037     QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
0038 #else
0039     // set default style
0040     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0041         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0042     }
0043     // if using org.kde.desktop, ensure we use kde style if possible
0044     if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORMTHEME")) {
0045         qputenv("QT_QPA_PLATFORMTHEME", "kde");
0046     }
0047 #endif
0048 
0049     QQmlApplicationEngine engine;
0050 
0051     KLocalizedString::setApplicationDomain(QByteArrayLiteral("kweather"));
0052     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0053     KAboutData aboutData(QStringLiteral("kweather"),
0054                          i18n("Weather"),
0055                          QStringLiteral(KWEATHER_VERSION_STRING),
0056                          i18n("A convergent weather application for Plasma"),
0057                          KAboutLicense::GPL,
0058                          i18n("© 2020-2022 Plasma Development Team"));
0059     aboutData.setBugAddress("https://bugs.kde.org/describecomponents.cgi?product=kweather");
0060     aboutData.addAuthor(i18n("Han Young"), QString(), QStringLiteral("hanyoung@protonmail.com"));
0061     aboutData.addAuthor(i18n("Devin Lin"), QString(), QStringLiteral("espidev@gmail.com"), QStringLiteral("https://espi.dev"));
0062     KAboutData::setApplicationData(aboutData);
0063 
0064     QCommandLineParser parser;
0065     aboutData.setupCommandLine(&parser);
0066     parser.process(app);
0067     aboutData.processCommandLine(&parser);
0068 
0069     engine.rootContext()->setContextProperty(QStringLiteral("settingsModel"), KWeatherSettings::self());
0070 
0071     WeatherLocation *emptyWeatherLocation = new WeatherLocation();
0072     engine.rootContext()->setContextProperty(QStringLiteral("emptyWeatherLocation"), emptyWeatherLocation);
0073 #ifdef Q_OS_ANDROID
0074     engine.rootContext()->setContextProperty(QStringLiteral("KWEATHER_IS_ANDROID"), true);
0075 #else
0076     engine.rootContext()->setContextProperty(QStringLiteral("KWEATHER_IS_ANDROID"), false);
0077 #endif
0078 
0079     // load setup wizard if first launch
0080     engine.loadFromModule("org.kde.kweather", "Main");
0081 
0082     // required for X11
0083     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.kweather")));
0084 
0085     if (engine.rootObjects().isEmpty()) {
0086         return -1;
0087     }
0088 
0089     return app.exec();
0090 }