File indexing completed on 2024-04-14 04:44:00

0001 /*
0002    SPDX-FileCopyrightText: 2015 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 #include "config-upnp-qt.h"
0008 #include "elisa-version.h"
0009 
0010 #include "elisaapplication.h"
0011 #include "elisa_settings.h"
0012 
0013 #include "localFileConfiguration/elisaconfigurationdialog.h"
0014 
0015 //#define QT_QML_DEBUG
0016 
0017 #include <KLocalizedString>
0018 #include <KLocalizedContext>
0019 
0020 #include <KAboutData>
0021 
0022 #if KFCrash_FOUND
0023 #include <KCrash>
0024 #endif
0025 
0026 #include <KQuickIconProvider>
0027 #include <QIcon>
0028 
0029 #include <QQmlContext>
0030 #include <QApplication>
0031 #include <QCommandLineParser>
0032 #include <QStandardPaths>
0033 #include <QSurfaceFormat>
0034 #include <QDir>
0035 
0036 #include <QQmlApplicationEngine>
0037 #include <QQmlFileSelector>
0038 #include <QQuickStyle>
0039 
0040 #if QtAndroidExtras_FOUND
0041 #include <QAndroidService>
0042 #endif
0043 
0044 #include <memory>
0045 
0046 #if QtAndroidExtras_FOUND
0047 #include <QAndroidJniObject>
0048 #include <QtAndroid>
0049 #endif
0050 
0051 #if defined Q_OS_ANDROID
0052 int __attribute__((visibility("default"))) main(int argc, char *argv[])
0053 #else
0054 int main(int argc, char *argv[])
0055 #endif
0056 {
0057     auto format = QSurfaceFormat::defaultFormat();
0058     format.setOption(QSurfaceFormat::ResetNotification);
0059     QSurfaceFormat::setDefaultFormat(format);
0060 
0061 #if defined Q_OS_ANDROID
0062     if(argc > 1 && strcmp(argv[1], "-service") == 0){
0063         QAndroidService app(argc, argv);
0064         qInfo() << "Service starting...";
0065 
0066         // My service stuff
0067 
0068         return app.exec();
0069     }
0070 
0071     qInfo() << "Application starting...";
0072 
0073     qputenv("QT_LOGGING_RULES", "org.kde.elisa*=true");
0074 #endif
0075     qputenv("QT_GSTREAMER_USE_PLAYBIN_VOLUME", "true");
0076 
0077     QApplication app(argc, argv);
0078 
0079 #if defined Q_OS_WIN || defined Q_OS_MAC
0080     QApplication::setStyle(QStringLiteral("breeze"));
0081 #endif
0082 
0083     KLocalizedString::setApplicationDomain(QByteArrayLiteral("elisa"));
0084 
0085 #if QtAndroidExtras_FOUND
0086     qInfo() << QCoreApplication::arguments();
0087 
0088     QAndroidJniObject::callStaticMethod<void>("org/kde/elisa/ElisaService",
0089                                               "startMyService",
0090                                               "(Landroid/content/Context;)V",
0091                                               QtAndroid::androidContext().object());
0092 #endif
0093 
0094 #if KFCrash_FOUND
0095     KCrash::initialize();
0096 #endif
0097 
0098     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("elisa")));
0099 
0100     KAboutData aboutData( QStringLiteral("elisa"),
0101                           i18nc("@title", "Elisa"),
0102                           QStringLiteral(ELISA_VERSION_STRING),
0103                           i18nc("@info", "A Simple Music Player made with love by the KDE community"),
0104                           KAboutLicense::LGPL_V3,
0105                           i18nc("@info", "(c) 2015-2020, Elisa contributors"));
0106 
0107     aboutData.addAuthor(QStringLiteral("Matthieu Gallien"),i18nc("@label", "Creator"), QStringLiteral("mgallien@mgallien.fr"));
0108     aboutData.addAuthor(QStringLiteral("Nate Graham"), i18nc("@label", "Author"), QStringLiteral("nate@kde.org"));
0109 
0110     aboutData.addCredit(QStringLiteral("Andrew Lake"), i18nc("@label", "Concept and design work"), QStringLiteral("jamboarder@gmail.com"));
0111     aboutData.addCredit(QStringLiteral("Luigi Toscano"), i18nc("@label", "Localization support"), QStringLiteral("luigi.toscano@tiscali.it"));
0112     aboutData.addCredit(QStringLiteral("Safa Alfulaij"), i18nc("@label", "Right to left support in interface"), QStringLiteral("safa1996alfulaij@gmail.com"));
0113     aboutData.addCredit(QStringLiteral("Diego Gangl"), i18nc("@label", "Various improvements to the interface"), QStringLiteral("diego@sinestesia.co"));
0114     aboutData.addCredit(QStringLiteral("Jérôme Guidon"), i18nc("@label", "Support for online radios"), QStringLiteral("guidon@live.fr"));
0115 
0116     KAboutData::setApplicationData(aboutData);
0117 
0118     qmlRegisterSingletonType("org.kde.elisa.about", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0119         return engine->toScriptValue(KAboutData::applicationData());
0120     });
0121 
0122     QCommandLineParser parser;
0123     aboutData.setupCommandLine(&parser);
0124     parser.process(app);
0125     aboutData.processCommandLine(&parser);
0126 
0127 
0128     // If styling has not been set via QT_QUICK_CONTROLS_STYLE, default to some
0129     // styles that make sense for desktop and mobile form factors.
0130     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0131 #ifdef Q_OS_ANDROID
0132         QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
0133         QQuickStyle::setFallbackStyle(QStringLiteral("Material"));
0134 #else
0135         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0136         QQuickStyle::setFallbackStyle(QStringLiteral("Fusion"));
0137 #endif
0138     }
0139 
0140     QQmlApplicationEngine engine;
0141     engine.addImportPath(QStringLiteral("qrc:/imports"));
0142     QQmlFileSelector selector(&engine);
0143 
0144     // Allow image:// icon URLs to be loaded as images im QML
0145     engine.addImageProvider(QStringLiteral("icon"), new KQuickIconProvider);
0146 
0147     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0148 
0149     QList<QUrl> urls;
0150     for (const auto &oneArgument : parser.positionalArguments()) {
0151         urls.push_back(QUrl::fromUserInput(oneArgument, QDir::currentPath()));
0152     }
0153 
0154     engine.rootContext()->setContextProperty(QStringLiteral("elisaStartupArguments"), QVariant::fromValue(urls));
0155 
0156     engine.load(QUrl(QStringLiteral("qrc:/qml/ElisaMainWindow.qml")));
0157 
0158     return app.exec();
0159 }