// SPDX-FileCopyrightText: 2024 Gary Wang // // SPDX-License-Identifier: MIT #pragma once #include class PlaylistModel : public QAbstractListModel { Q_OBJECT public: enum PlaylistRole { UrlRole = Qt::UserRole }; Q_ENUM(PlaylistRole) Q_PROPERTY(QStringList autoLoadFilterSuffixes MEMBER m_autoLoadSuffixes NOTIFY autoLoadFilterSuffixesChanged) explicit PlaylistModel(QObject *parent = nullptr); ~PlaylistModel(); void setPlaylist(const QList & urls); QModelIndex loadPlaylist(const QList & urls); QModelIndex loadPlaylist(const QUrl & url); QModelIndex appendToPlaylist(const QUrl & url); bool removeAt(int index); int indexOf(const QUrl & url) const; QStringList autoLoadFilterSuffixes() const; QModelIndex createIndex(int row) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; signals: void autoLoadFilterSuffixesChanged(QStringList suffixes); private: // model data QList m_playlist; // properties QStringList m_autoLoadSuffixes = {}; // internal QString m_currentDir; }; class PlaylistManager : public QObject { Q_OBJECT public: Q_PROPERTY(int currentIndex MEMBER m_currentIndex NOTIFY currentIndexChanged) explicit PlaylistManager(QObject *parent = nullptr); ~PlaylistManager(); const PlaylistModel * model() const; void setPlaylist(const QList & url); QModelIndex loadPlaylist(const QList & urls); int totalCount() const; QModelIndex previousIndex() const; QModelIndex nextIndex() const; QModelIndex curIndex() const; void setCurrentIndex(const QModelIndex & index); QUrl urlByIndex(const QModelIndex & index); QString localFileByIndex(const QModelIndex & index); bool removeAt(const QModelIndex & index); void setAutoLoadFilterSuffixes(const QStringList &nameFilters); static QList convertToUrlList(const QStringList & files); signals: void currentIndexChanged(int index); void totalCountChanged(int count); private: int m_currentIndex; PlaylistModel m_model; };