main.cpp 3.41 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2
#include <QQmlApplicationEngine>
#include <QFontDatabase>
Camilo Higuita's avatar
Camilo Higuita committed
3 4
#include <QQmlContext>
#include <QApplication>
Camilo Higuita's avatar
Camilo Higuita committed
5
#include <QIcon>
6
#include <QLibrary>
7
#include <QStyleHints>
8
#include <QCommandLineParser>
Camilo Higuita's avatar
Camilo Higuita committed
9 10 11
#include "babe.h"
#include "services/local/player.h"

12

Camilo Higuita's avatar
Camilo Higuita committed
13

14
#ifdef STATIC_KIRIGAMI
15
#include "./3rdparty/kirigami/src/kirigamiplugin.h"
16 17 18
#endif

#ifdef Q_OS_ANDROID
19
#include <QtWebView/QtWebView>
20 21
#include <QGuiApplication>
#include <QIcon>
22
#else
23
#include <QApplication>
24
#include <QtWebEngine>
25
#endif
Camilo Higuita's avatar
Camilo Higuita committed
26

27
#include "utils/bae.h"
28
#include "services/web/youtube.h"
29
#include "services/web/Spotify/spotify.h"
30 31
#include "services/local/linking.h"
#include "mauikit/src/mauikit.h"
32

33 34 35
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
36

Camilo Higuita's avatar
Camilo Higuita committed
37 38
int main(int argc, char *argv[])
{
39
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Camilo Higuita's avatar
Camilo Higuita committed
40

41 42 43
#ifdef Q_OS_ANDROID
    QGuiApplication app(argc, argv);
#else
Camilo Higuita's avatar
Camilo Higuita committed
44
    QApplication app(argc, argv);
45 46
#endif

Camilo Higuita's avatar
Camilo Higuita committed
47 48
    app.setApplicationName(BAE::App);
    app.setApplicationVersion(BAE::Version);
49
    app.setWindowIcon(QIcon("qrc:/assets/vvave.png"));
50 51
    app.setDesktopFileName(BAE::App);

52 53 54 55 56 57
    /*needed for mobile*/
    if(BAE::isMobile())
    {
        int pressAndHoldInterval = 1000; // in [ms]
        QGuiApplication::styleHints()->setMousePressAndHoldInterval(pressAndHoldInterval);
    }
58 59

    QCommandLineParser parser;
60
    parser.setApplicationDescription("vvave music player");
61 62 63 64 65 66 67 68 69 70 71 72 73
    const QCommandLineOption versionOption = parser.addVersionOption();
    parser.process(app);

    const QStringList args = parser.positionalArguments();
    bool version = parser.isSet(versionOption);

    if(version)
    {
        printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
               qPrintable(QCoreApplication::applicationVersion()));
        return 0;
    }

74
    Babe bae;
75

76 77
    /* Services */
    YouTube youtube;
78
    Spotify spotify;
79

Camilo Higuita's avatar
Camilo Higuita committed
80
    QFontDatabase::addApplicationFont(":/utils/materialdesignicons-webfont.ttf");
81

82
    QQmlApplicationEngine engine;
83

84 85 86 87 88 89
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
    {
        qDebug()<<"FINISHED LOADING QML APP";
        bae.refreshCollection();
    });

Camilo Higuita's avatar
Camilo Higuita committed
90
    auto context = engine.rootContext();
91
    context->setContextProperty("player", &bae.player);
92
    context->setContextProperty("bae", &bae);
93
    context->setContextProperty("youtube", &youtube);
94
    context->setContextProperty("spotify", &spotify);
95 96 97
    context->setContextProperty("link", &bae.link);

    qmlRegisterUncreatableMetaObject(
98 99 100 101 102 103
                LINK::staticMetaObject, // static meta object
                "Link.Codes",                // import statement (can be any string)
                1, 0,                          // major and minor version of the import
                "LINK",                 // name in QML (does not have to match C++ name)
                "Error: only enums"            // error in case someone tries to create a MyNamespace object
                );
104

105
#ifdef STATIC_KIRIGAMI
106
    KirigamiPlugin::getInstance().registerTypes();
107 108 109
#endif

#ifdef Q_OS_ANDROID
110
    QIcon::setThemeName("Luv");
111
    QtWebView::initialize();
112
#else
113 114
    //    if(QQuickStyle::availableStyles().contains("nomad"))
    //        QQuickStyle::setStyle("nomad");
camilo higuita's avatar
camilo higuita committed
115

116 117
    if(!BAE::isMobile())
        QtWebEngine::initialize();
118 119
#endif

120 121 122 123
#ifdef MAUI_APP
    MauiKit::getInstance().registerTypes();
#endif

Camilo Higuita's avatar
Camilo Higuita committed
124 125 126 127 128 129
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}