File indexing completed on 2024-05-12 16:21:17

0001 // SPDX-FileCopyrightText: 2022 Jonah BrĂ¼chert <jbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #pragma once
0006 
0007 #include <QAbstractListModel>
0008 
0009 #include <vector>
0010 
0011 struct PlaylistEntry {
0012     using ColumnTypes = std::tuple<QString, QString, QString, QString>;
0013 
0014     static PlaylistEntry fromSql(ColumnTypes tuple) {
0015         auto [videoId, title, artists, album] = tuple;
0016         return PlaylistEntry { videoId, title, artists, album };
0017     }
0018 
0019     QString videoId;
0020     QString title;
0021     QString artists;
0022     QString album;
0023 };
0024 
0025 class LocalPlaylistModel : public QAbstractListModel
0026 {
0027     Q_OBJECT
0028     Q_PROPERTY(QString playlistId READ playlistId WRITE setPlaylistId NOTIFY playlistIdChanged)
0029 
0030     enum Roles {
0031         VideoId = Qt::UserRole + 1,
0032         Title,
0033         Artists,
0034         ArtistsDisplayString
0035     };
0036 
0037 public:
0038     LocalPlaylistModel(QObject *parent = nullptr);
0039     int rowCount(const QModelIndex &index) const override;
0040     QHash<int, QByteArray> roleNames() const override;
0041     QVariant data(const QModelIndex &index, int role) const override;
0042 
0043     QString playlistId() const;
0044     void setPlaylistId(const QString &playlistId);
0045     Q_SIGNAL void playlistIdChanged();
0046     Q_INVOKABLE void removeSong(QString videoId, qint64 playlistId);
0047 
0048     void refreshModel();
0049     const std::vector<PlaylistEntry> &entries() const;
0050 
0051 private:
0052     QString m_playlistId;
0053     std::vector<PlaylistEntry> m_entries;
0054 };
0055