File indexing completed on 2024-05-19 15:54:38

0001 // SPDX-FileCopyrightText: 2021 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 #include <QUrl>
0009 
0010 #include <optional>
0011 
0012 #include <ytmusic.h>
0013 
0014 #include "multiiterableview.h"
0015 #include "abstractytmusicmodel.h"
0016 
0017 
0018 class ArtistModel : public AbstractYTMusicModel
0019 {
0020     Q_OBJECT
0021 
0022     Q_PROPERTY(QString channelId READ channelId WRITE setChannelId NOTIFY channelIdChanged REQUIRED)
0023 
0024     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
0025     Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl NOTIFY thumbnailUrlChanged)
0026     Q_PROPERTY(QUrl webUrl READ webUrl NOTIFY channelIdChanged)
0027 
0028 public:
0029     enum Type {
0030         Song,
0031         Album,
0032         Single,
0033         Video
0034     };
0035     Q_ENUM(Type)
0036 
0037     enum Role {
0038         Title,
0039         TypeRole,
0040         Artists,
0041         VideoId,
0042         ThumbnailUrl
0043     };
0044 
0045     explicit ArtistModel(QObject *parent = nullptr);
0046 
0047     int rowCount(const QModelIndex &parent) const override;
0048     QVariant data(const QModelIndex &index, int role) const override;
0049     QHash<int, QByteArray> roleNames() const override;
0050 
0051     QString channelId() const;
0052     void setChannelId(const QString &channelId);
0053     Q_SIGNAL void channelIdChanged();
0054 
0055     QString title() const;
0056     Q_SIGNAL void titleChanged();
0057 
0058     QUrl thumbnailUrl() const;
0059     Q_SIGNAL void thumbnailUrlChanged();
0060 
0061     QUrl webUrl() const;
0062 
0063     Q_INVOKABLE void triggerItem(int row);
0064 
0065     Q_SIGNAL void openAlbum(const QString &browseId);
0066     Q_SIGNAL void openSong(const QString &videoId);
0067     Q_SIGNAL void openVideo(const QString &videoId, const QString &title);
0068 
0069 private:
0070     QString m_channelId;
0071 
0072     artist::Artist m_artist;
0073 
0074     std::vector<artist::Artist::Album> albums;
0075     std::vector<artist::Artist::Single> singles;
0076     std::vector<artist::Artist::Song> songs;
0077     std::vector<artist::Artist::Video> videos;
0078 
0079     MultiIterableView<
0080         artist::Artist::Album, artist::Artist::Single, artist::Artist::Song, artist::Artist::Video
0081     > m_view;
0082 };