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

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

#ifdef STATIC_MAUIKIT
18
#include "3rdparty/mauikit/src/mauikit.h"
19 20 21
#endif

#ifdef Q_OS_ANDROID
22
#include <QtWebView/QtWebView>
23 24
#include <QGuiApplication>
#include <QIcon>
25
#include "mauiandroid.h"
26
#else
27
#include <QApplication>
28
#include <QtWebEngine>
29
#endif
Camilo Higuita's avatar
Camilo Higuita committed
30

31
#include "utils/bae.h"
32
#include "services/web/youtube.h"
Camilo higuita's avatar
Camilo higuita committed
33 34
//#include "services/web/Spotify/spotify.h"
//#include "services/local/linking.h"
35
#include "services/local/player.h"
36 37

#include "models/tracks/tracksmodel.h"
38
#include "models/albums/albumsmodel.h"
39
#include "models/playlists/playlistsmodel.h"
Camilo higuita's avatar
Camilo higuita committed
40
//#include "models/cloud/cloud.h"
41

42 43 44
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
45

Camilo Higuita's avatar
Camilo Higuita committed
46 47
int main(int argc, char *argv[])
{
48
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Camilo Higuita's avatar
Camilo Higuita committed
49

50 51
#ifdef Q_OS_ANDROID
    QGuiApplication app(argc, argv);
52
    QGuiApplication::styleHints()->setMousePressAndHoldInterval(1000); // in [ms]
53 54
    if (!MAUIAndroid::checkRunTimePermissions())
            return -1;
55
#else
56
    QApplication app(argc, argv);
57 58
#endif

camilo higuita's avatar
camilo higuita committed
59 60 61 62 63
    app.setApplicationName(BAE::appName);
    app.setApplicationVersion(BAE::version);
    app.setApplicationDisplayName(BAE::displayName);
    app.setOrganizationName(BAE::orgName);
    app.setOrganizationDomain(BAE::orgDomain);
64
    app.setWindowIcon(QIcon("qrc:/assets/vvave.png"));
65 66

    QCommandLineParser parser;
camilo higuita's avatar
camilo higuita committed
67
    parser.setApplicationDescription(BAE::description);
68

69 70 71
    const QCommandLineOption versionOption = parser.addVersionOption();
    parser.process(app);

72 73 74 75 76
    const QStringList args = parser.positionalArguments();
    QStringList urls;
    if(!args.isEmpty())
        urls = args;

77
    vvave vvave;
78

79 80
    /* Services */
    YouTube youtube;
Camilo higuita's avatar
Camilo higuita committed
81
//    Spotify spotify;
82

83
    QFontDatabase::addApplicationFont(":/assets/materialdesignicons-webfont.ttf");
84

85
    QQmlApplicationEngine engine;
86

87 88 89
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
    {
        qDebug()<<"FINISHED LOADING QML APP";
Camilo higuita's avatar
Camilo higuita committed
90
        const auto currentSources = vvave.getSourceFolders();
camilo higuita's avatar
camilo higuita committed
91
        vvave.scanDir(currentSources.isEmpty() ? BAE::defaultSources : currentSources);
Camilo higuita's avatar
Camilo higuita committed
92 93
        if(!urls.isEmpty())
            vvave.openUrls(urls);
94 95
    });

96
    auto context = engine.rootContext();
97
    context->setContextProperty("vvave", &vvave);
98
    context->setContextProperty("youtube", &youtube);
99

100
    qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
101
    qmlRegisterType<PlaylistsModel>("PlaylistsList", 1, 0, "Playlists");
102
    qmlRegisterType<AlbumsModel>("AlbumsList", 1, 0, "Albums");
Camilo higuita's avatar
Camilo higuita committed
103
//    qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
104 105 106

    qmlRegisterType<Player>("Player", 1, 0, "Player");

107
#ifdef STATIC_KIRIGAMI
108
    KirigamiPlugin::getInstance().registerTypes();
109 110 111
#endif

#ifdef STATIC_MAUIKIT
Camilo Higuita's avatar
Camilo Higuita committed
112
    MauiKit::getInstance().registerTypes();
113 114 115
#endif

#ifdef Q_OS_ANDROID
116
    QtWebView::initialize();
117
#else
camilo higuita's avatar
camilo higuita committed
118
    QtWebEngine::initialize();
119 120
#endif

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

    return app.exec();
}