File indexing completed on 2024-05-05 04:47:13

0001 #include <QQmlApplicationEngine>
0002 #include <QQmlContext>
0003 #include <QDebug>
0004 #include <QCommandLineParser>
0005 #include <QIcon>
0006 
0007 #include <KI18n/KLocalizedString>
0008 
0009 #if defined Q_OS_ANDROID || defined Q_OS_IOS
0010 #include <QGuiApplication>
0011 #else
0012 #include <QApplication>
0013 #endif
0014 
0015 #include "kde/mpris2/mpris2.h"
0016 
0017 #if (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined Q_OS_ANDROID
0018 #include "kde/mpris2/mediaplayer2player.h"
0019 #endif
0020 
0021 #ifdef Q_OS_ANDROID
0022 #include <MauiKit3/Core/mauiandroid.h>
0023 #include <QAndroidService>
0024 #include <QAndroidJniEnvironment>
0025 #include <QAndroidJniObject>
0026 #endif
0027 
0028 #ifdef Q_OS_MACOS
0029 #include <MauiKit3/Core/mauimacos.h>
0030 #endif
0031 
0032 #include <MauiKit3/FileBrowsing/fmstatic.h>
0033 #include <MauiKit3/Core/mauiapp.h>
0034 #include <MauiKit3/FileBrowsing/moduleinfo.h>
0035 
0036 #include <taglib/taglib.h>
0037 
0038 #include "../vvave_version.h"
0039 
0040 #include "vvave.h"
0041 
0042 #include "services/local/artworkprovider.h"
0043 #include "services/local/player.h"
0044 #include "services/local/playlist.h"
0045 #include "services/local/trackinfo.h"
0046 #include "services/local/metadataeditor.h"
0047 
0048 #include "models/albums/albumsmodel.h"
0049 #include "models/cloud/cloud.h"
0050 #include "models/playlists/playlistsmodel.h"
0051 #include "models/tracks/tracksmodel.h"
0052 #include "models/folders/foldersmodel.h"
0053 
0054 #include "kde/server.h"
0055 
0056 #define VVAVE_URI "org.maui.vvave"
0057 
0058 Q_DECL_EXPORT int main(int argc, char *argv[])
0059 {
0060   qDebug() << "APP LOADING SPEED TESTS" << 0;
0061 
0062   #ifdef Q_OS_ANDROID
0063  if (argc > 1 && strcmp(argv[1], "-service") == 0)
0064   {
0065       qDebug() << "Service starting with from the same .so file";
0066       QAndroidService app(argc, argv);
0067       return app.exec();
0068   }
0069 #endif
0070 
0071     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0072     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0073 
0074 #ifdef Q_OS_WIN32
0075     qputenv("QT_MULTIMEDIA_PREFERRED_PLUGINS", "w");
0076 #endif
0077 
0078 #if defined Q_OS_ANDROID || defined Q_OS_IOS
0079     QGuiApplication app(argc, argv);
0080 #else
0081     QApplication app(argc, argv);
0082 #endif
0083 
0084 #ifdef Q_OS_ANDROID
0085     if (!MAUIAndroid::checkRunTimePermissions({"android.permission.WRITE_EXTERNAL_STORAGE"}))
0086         return -1;
0087 
0088 //    QAndroidJniObject::callStaticMethod<void>(
0089 //        "org/vvave/mediasession/QMediaSessionManager",
0090 //        "startQtAndroidService",
0091 //        "(Landroid/content/Context;)V",
0092 //        QtAndroid::androidActivity().object());
0093 #endif
0094 
0095     qDebug() << "APP LOADING SPEED TESTS" << 2;
0096 
0097     app.setOrganizationName(QStringLiteral("Maui"));
0098     app.setWindowIcon(QIcon("qrc:/assets/vvave.png"));
0099 
0100     KLocalizedString::setApplicationDomain("vvave");
0101     KAboutData about(QStringLiteral("vvave"),
0102                      QStringLiteral("Vvave"),
0103                      VVAVE_VERSION_STRING,
0104                      i18n("Organize and listen to your music."),
0105                      KAboutLicense::LGPL_V3,
0106                      APP_COPYRIGHT_NOTICE,
0107                      QString(GIT_BRANCH) + "/" + QString(GIT_COMMIT_HASH));
0108 
0109     about.addAuthor("Camilo Higuita", i18n("Developer"), QStringLiteral("milo.h@aol.com"));
0110     about.addAuthor("Will Chen", i18n("Developer"), QStringLiteral("intralexical@gmail.com"));
0111 
0112     about.setHomepage("https://mauikit.org");
0113     about.setProductName("maui/vvave");
0114     about.setBugAddress("https://invent.kde.org/maui/vvave/-/issues");
0115     about.setOrganizationDomain(VVAVE_URI);
0116     about.setProgramLogo(app.windowIcon());
0117     about.setDesktopFileName("org.kde.vvave");
0118 
0119     about.addComponent("TagLib",
0120                        "",
0121                        QString("%1.%2.%3").arg(QString::number(TAGLIB_MAJOR_VERSION),QString::number(TAGLIB_MINOR_VERSION),QString::number(TAGLIB_PATCH_VERSION)),
0122                        "https://taglib.org/api/index.html");
0123 
0124     const auto FBData = MauiKitFileBrowsing::aboutData();
0125     about.addComponent(FBData.name(), MauiKitFileBrowsing::buildVersion(), FBData.version(), FBData.webAddress());
0126 
0127     KAboutData::setApplicationData(about);
0128 
0129     MauiApp::instance()->setIconName("qrc:/assets/vvave.png");
0130 
0131     QCommandLineParser parser;
0132     about.setupCommandLine(&parser);
0133     parser.process(app);
0134     about.processCommandLine(&parser);
0135 
0136     const QStringList args = parser.positionalArguments();
0137     QStringList paths;
0138 
0139     if (!args.isEmpty())
0140     {
0141         for(const auto &path : args)
0142             paths << QUrl::fromUserInput(path).toString();
0143     }
0144 
0145 #if (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined Q_OS_ANDROID
0146     if (AppInstance::attachToExistingInstance(QUrl::fromStringList(paths)))
0147     {
0148         // Successfully attached to existing instance of Nota
0149         return 0;
0150     }
0151 
0152     AppInstance::registerService();
0153 #endif
0154 
0155     auto server =  std::make_unique<Server>();
0156 
0157     QQmlApplicationEngine engine;
0158     const QUrl url(QStringLiteral("qrc:/main.qml"));
0159 
0160     qDebug() << "APP LOADING SPEED TESTS" << 3;
0161 
0162     QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url, args, &server](QObject *obj, const QUrl &objUrl)
0163     {
0164         if (!obj && url == objUrl)
0165             QCoreApplication::exit(-1);
0166 
0167         server->setQmlObject(obj);
0168 
0169         if (!args.isEmpty())
0170             server->openFiles(args);
0171 
0172     }, Qt::QueuedConnection);
0173 
0174     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0175 
0176     qmlRegisterSingletonInstance<vvave>(VVAVE_URI, 1, 0, "Vvave", vvave::instance());
0177     qmlRegisterSingletonInstance<Server>(VVAVE_URI, 1, 0, "Server", server.get());
0178 
0179     qmlRegisterType<TracksModel>(VVAVE_URI, 1, 0, "Tracks");
0180     qmlRegisterType<AlbumsModel>(VVAVE_URI, 1, 0, "Albums");
0181     qmlRegisterType<Cloud>(VVAVE_URI, 1, 0, "Cloud");
0182     qmlRegisterType<FoldersModel>(VVAVE_URI, 1, 0, "Folders");
0183 
0184     qmlRegisterType<Player>(VVAVE_URI, 1, 0, "Player");
0185     qmlRegisterType<Playlist>(VVAVE_URI, 1, 0, "Playlist");
0186     qmlRegisterType<Mpris2>(VVAVE_URI, 1, 0, "Mpris2");
0187 
0188     qmlRegisterType<TrackInfo>(VVAVE_URI, 1, 0, "TrackInfo");
0189     qmlRegisterType<MetadataEditor>(VVAVE_URI, 1, 0, "MetadataEditor");
0190 
0191     qmlRegisterType<PlaylistsModel>(VVAVE_URI, 1, 0, "Playlists");
0192 
0193     engine.addImageProvider("artwork", new ArtworkProvider());
0194 
0195 #if (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined Q_OS_ANDROID
0196     qRegisterMetaType<MediaPlayer2Player *>();
0197 #endif
0198 
0199     qDebug() << "APP LOADING SPEED TESTS" << 4;
0200 
0201     engine.load(url);
0202 
0203     qDebug() << "APP LOADING SPEED TESTS" << 5;
0204 
0205 #ifdef Q_OS_MACOS
0206     //  MAUIMacOS::removeTitlebarFromWindow();
0207 #endif
0208 
0209     return app.exec();
0210 }