File indexing completed on 2024-05-19 05:57:22

0001 // SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #include "config-telly-skout.h"
0005 #include "telly-skout-version.h"
0006 
0007 #include "TellySkoutSettings.h"
0008 #include "channelsmodel.h"
0009 #include "channelsproxymodel.h"
0010 #include "database.h"
0011 #include "fetcher.h"
0012 #include "groupsmodel.h"
0013 #include "programsmodel.h"
0014 #include "programsproxymodel.h"
0015 
0016 #include <KAboutData>
0017 #if HAVE_KCRASH
0018 #include <KCrash>
0019 #endif
0020 #include <KLocalizedContext>
0021 #include <KLocalizedString>
0022 
0023 #include <QCommandLineParser>
0024 #include <QIcon>
0025 #include <QQmlApplicationEngine>
0026 #include <QQmlContext>
0027 #include <QQuickStyle>
0028 #include <QString>
0029 
0030 #ifdef Q_OS_ANDROID
0031 #include <QGuiApplication>
0032 #else
0033 #include <QApplication>
0034 #endif
0035 
0036 #ifdef Q_OS_ANDROID
0037 Q_DECL_EXPORT
0038 #endif
0039 
0040 int main(int argc, char *argv[])
0041 {
0042 #ifdef Q_OS_ANDROID
0043     QGuiApplication app(argc, argv);
0044     QQuickStyle::setStyle(QStringLiteral("Material"));
0045 #else
0046     QApplication app(argc, argv);
0047     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0048         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0049     }
0050 #endif
0051 
0052 #if HAVE_KCRASH
0053     KCrash::initialize();
0054 #endif
0055 
0056     KLocalizedString::setApplicationDomain("telly-skout");
0057 
0058     // about
0059     const QString applicationDescription = i18n("Convergent TV guide based on Kirigami");
0060 
0061     KAboutData about(QStringLiteral("telly-skout"),
0062                      i18n("Telly Skout"),
0063                      QStringLiteral(TELLY_SKOUT_VERSION_STRING),
0064                      applicationDescription,
0065                      KAboutLicense::LGPL_V2_1,
0066                      i18n("© 2020 KDE Community"));
0067     about.addAuthor("Plata", QString(), QStringLiteral("plata.hill@kdemail.net"));
0068     KAboutData::setApplicationData(about);
0069 
0070     QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.telly-skout")));
0071 
0072     // command line parser
0073     QCommandLineParser parser;
0074     about.setupCommandLine(&parser);
0075     parser.process(app);
0076     about.processCommandLine(&parser);
0077 
0078     // trigger fetching of favorites before loading QML such that e.g. network requests can already run in the background
0079     Database::instance();
0080     Fetcher::instance().fetchFavorites();
0081 
0082     // register qml types
0083     qmlRegisterType<GroupsModel>("org.kde.TellySkout", 1, 0, "GroupsModel");
0084     qmlRegisterType<ChannelsModel>("org.kde.TellySkout", 1, 0, "ChannelsModel");
0085     qmlRegisterType<ChannelsProxyModel>("org.kde.TellySkout", 1, 0, "ChannelsProxyModel");
0086     qmlRegisterType<ProgramsProxyModel>("org.kde.TellySkout", 1, 0, "ProgramsProxyModel");
0087 
0088     qmlRegisterUncreatableType<ProgramsModel>("org.kde.TellySkout", 1, 0, "ProgramsModel", QStringLiteral("Get from Channel"));
0089 
0090     qmlRegisterSingletonInstance("org.kde.TellySkout", 1, 0, "Fetcher", &Fetcher::instance());
0091 
0092     // setup engine
0093     QQmlApplicationEngine engine;
0094     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0095 
0096     engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about));
0097 
0098     engine.rootContext()->setContextProperty(QStringLiteral("_settings"), TellySkoutSettings::self());
0099 
0100     QObject::connect(&app, &QCoreApplication::aboutToQuit, TellySkoutSettings::self(), &TellySkoutSettings::save);
0101 
0102     engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
0103 
0104     if (engine.rootObjects().isEmpty()) {
0105         return -1;
0106     }
0107 
0108     return app.exec();
0109 }