
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "audio_plugin.h"

#include <QQmlEngine>
#include <QResource>
#include <QDebug>

#include "mediaplayer.h"

QUrl AudioPlugin::componentUrl(const QString &fileName) const
{
    return QUrl(resolveFileUrl(fileName));
}

void AudioPlugin::registerTypes(const char *uri)
{
    qDebug() << "REGISTER MAUIKITAUDIOTYPES <<<<<<<<<<<<<<<<<<<<<<";

#if defined(Q_OS_ANDROID)
    QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc"));
#endif

    Q_ASSERT(QLatin1String(uri) == QLatin1String("org.mauikit.audio"));
    
    //File Browsing components
    qmlRegisterType<MediaPlayer>(uri, 1, 0, "MediaPlayer");
    // qmlRegisterType<PlacesList>(uri, 1, 0, "PlacesList");
    // qmlRegisterUncreatableType<PathStatus>(uri, 1, 0, "PathStatus", QStringLiteral("cannot be created :: PathStatus"));

    // qmlRegisterType(componentUrl(QStringLiteral("FileBrowser.qml")), uri, 1, 0, "FileBrowser");
    // qmlRegisterType(componentUrl(QStringLiteral("PlacesListBrowser.qml")), uri, 1, 0, "PlacesListBrowser");
    // qmlRegisterType(componentUrl(QStringLiteral("FavButton.qml")), uri, 1, 0, "FavButton");
    // qmlRegisterType(componentUrl(QStringLiteral("FileDialog.qml")), uri, 1, 0, "FileDialog");
    // qmlRegisterType(componentUrl(QStringLiteral("FileListingDialog.qml")), uri, 1, 0, "FileListingDialog");

    // qmlRegisterType<OpenWithModel>(uri, 1, 3, "OpenWithModel");
    // qmlRegisterType(componentUrl(QStringLiteral("OpenWithDialog.qml")), uri, 1, 0, "OpenWithDialog");
    
    // qmlRegisterSingletonType<FMStatic>(uri, 1, 0, "FM", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
    //     Q_UNUSED(engine)
    //     Q_UNUSED(scriptEngine)
    //     return new FMStatic;
    // });
    
    // //File Tagging components
    // qmlRegisterSingletonType<Tagging>(uri, 1, 3, "Tagging", &Tagging::qmlInstance);
    
    // qmlRegisterType<TagsList>(uri, 1, 0, "TagsListModel");
    // qmlRegisterType(componentUrl(QStringLiteral("private/TagList.qml")), uri, 1, 0, "TagList");
    // qmlRegisterType(componentUrl(QStringLiteral("TagsBar.qml")), uri, 1, 0, "TagsBar");
    // qmlRegisterType(componentUrl(QStringLiteral("TagsDialog.qml")), uri, 1, 0, "TagsDialog");
    // qmlRegisterType(componentUrl(QStringLiteral("NewTagDialog.qml")), uri, 1, 3, "NewTagDialog");
    
    //File Syncing components
}

void AudioPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    Q_UNUSED(uri);

    /** IMAGE PROVIDERS **/
    // engine->addImageProvider(QStringLiteral("thumbnailer"), new Thumbnailer());
}
