main.cpp 4.05 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
#else
26
#include <QApplication>
27
#include <QtWebEngine>
28
#endif
Camilo Higuita's avatar
Camilo Higuita committed
29

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

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

43 44 45
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
46

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

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

Camilo Higuita's avatar
Camilo Higuita committed
58 59
    app.setApplicationName(BAE::App);
    app.setApplicationVersion(BAE::Version);
60
    app.setWindowIcon(QIcon("qrc:/assets/vvave.png"));
61 62 63
    app.setDesktopFileName(BAE::App);

    QCommandLineParser parser;
64 65
    parser.setApplicationDescription(BAE::Description);

66 67 68
    const QCommandLineOption versionOption = parser.addVersionOption();
    parser.process(app);

69 70 71 72 73
    const QStringList args = parser.positionalArguments();
    QStringList urls;
    if(!args.isEmpty())
        urls = args;

74
    vvave vvave;
75

76 77
    /* Services */
    YouTube youtube;
Camilo higuita's avatar
Camilo higuita committed
78
//    Spotify spotify;
79

80
    QFontDatabase::addApplicationFont(":/assets/materialdesignicons-webfont.ttf");
81

82
    QQmlApplicationEngine engine;
83

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

93
    auto context = engine.rootContext();
94
    context->setContextProperty("vvave", &vvave);
95
    context->setContextProperty("youtube", &youtube);
Camilo higuita's avatar
Camilo higuita committed
96 97
//    context->setContextProperty("spotify", &spotify);
//    context->setContextProperty("link", &bae.link);
98

99 100 101 102
    qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));

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

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

Camilo higuita's avatar
Camilo higuita committed
109 110 111 112 113 114 115
//    qmlRegisterUncreatableMetaObject(
//                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
//                );
116

117
#ifdef STATIC_KIRIGAMI
118
    KirigamiPlugin::getInstance().registerTypes();
119 120 121
#endif

#ifdef STATIC_MAUIKIT
Camilo Higuita's avatar
Camilo Higuita committed
122
    MauiKit::getInstance().registerTypes();
123 124 125
#endif

#ifdef Q_OS_ANDROID
126
    QtWebView::initialize();
127
#else
128 129
    //    if(QQuickStyle::availableStyles().contains("nomad"))
    //        QQuickStyle::setStyle("nomad");
130

131 132
    if(!BAE::isMobile())
        QtWebEngine::initialize();
133 134
#endif

Camilo Higuita's avatar
Camilo Higuita committed
135 136 137 138 139 140
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}