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

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 #pragma once
0005 
0006 #include <ytmusic.h>
0007 
0008 #include "abstractytmusicmodel.h"
0009 #include "library.h"
0010 
0011 class PlaylistModel;
0012 class AlbumModel;
0013 class LocalPlaylistModel;
0014 
0015 class UserPlaylistModel : public AbstractYTMusicModel
0016 {
0017     Q_OBJECT
0018 
0019     // input
0020     Q_PROPERTY(QString initialVideoId READ initialVideoId WRITE setInitialVideoId NOTIFY initialVideoIdChanged)
0021     Q_PROPERTY(QString playlistId READ playlistId WRITE setPlaylistId NOTIFY playlistIdChanged)
0022     Q_PROPERTY(bool shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged)
0023 
0024     // output
0025     Q_PROPERTY(QString currentVideoId READ currentVideoId NOTIFY currentVideoIdChanged)
0026     Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
0027     Q_PROPERTY(bool canSkip READ canSkip NOTIFY canSkipChanged)
0028     Q_PROPERTY(bool canSkipBack READ canSkipBack NOTIFY canSkipBackChanged)
0029     Q_PROPERTY(QString lyrics READ lyrics NOTIFY lyricsChanged)
0030     Q_PROPERTY(QUrl webUrl READ webUrl NOTIFY currentVideoIdChanged)
0031 
0032 
0033 public:
0034     enum Role {
0035         Title = Qt::UserRole + 1,
0036         VideoId,
0037         Artists,
0038         Album,
0039         IsCurrent,
0040     };
0041     Q_ENUM(Role);
0042 
0043     explicit UserPlaylistModel(QObject *parent = nullptr);
0044 
0045     int rowCount(const QModelIndex &parent) const override;
0046     QVariant data(const QModelIndex &index, int role) const override;
0047     QHash<int, QByteArray> roleNames() const override;
0048     Q_INVOKABLE bool moveRow(int sourceRow, int destinationRow);
0049 
0050     QString initialVideoId() const;
0051     void setInitialVideoId(const QString &videoId);
0052     Q_SIGNAL void initialVideoIdChanged();
0053 
0054     QString nextVideoId() const;
0055     QString previousVideoId() const;
0056 
0057     QString currentVideoId() const;
0058     void setCurrentVideoId(const QString &videoId);
0059     Q_SIGNAL void currentVideoIdChanged();
0060     Q_SIGNAL void currentIndexChanged();
0061 
0062     int currentIndex() const;
0063 
0064     bool canSkip() const;
0065     bool canSkipBack() const;
0066 
0067     Q_SIGNAL void canSkipChanged();
0068     Q_SIGNAL void canSkipBackChanged();
0069 
0070 
0071     QString playlistId() const;
0072     void setPlaylistId(const QString &playlistId);
0073     Q_SIGNAL void playlistIdChanged();
0074 
0075     void setShuffle(bool shuffle);
0076     bool shuffle() const;
0077     Q_SIGNAL void shuffleChanged();
0078 
0079     QString lyrics() const;
0080     Q_SIGNAL void lyricsChanged();
0081     Q_SIGNAL void noLyrics();
0082 
0083     QUrl webUrl() const;
0084 
0085     Q_INVOKABLE void next();
0086     Q_INVOKABLE void previous();
0087 
0088     Q_INVOKABLE void skipTo(const QString &videoId);
0089     Q_INVOKABLE void playNext(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists);
0090     Q_INVOKABLE void append(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists);
0091     Q_INVOKABLE void clear();
0092     Q_INVOKABLE void clearExceptCurrent();
0093     Q_INVOKABLE void remove(const QString &videoId);
0094     Q_INVOKABLE void shufflePlaylist();
0095     Q_INVOKABLE void appendPlaylist(PlaylistModel *playlistModel);
0096     Q_INVOKABLE void appendAlbum(AlbumModel *albumModel);
0097 
0098     Q_INVOKABLE void playFavourites(FavouritesModel *favouriteModel, bool shuffled);
0099     Q_INVOKABLE void appendFavourites(FavouritesModel *favouriteModel, bool shuffled);
0100     Q_INVOKABLE void playPlaybackHistory(PlaybackHistoryModel *playbackHistory, bool shuffled);
0101     Q_INVOKABLE void appendPlaybackHistory(PlaybackHistoryModel *playbackHistory, bool shuffled);
0102     Q_INVOKABLE void playLocalPlaylist(LocalPlaylistModel *playlistModel, bool shuffled);
0103     Q_INVOKABLE void appendLocalPlaylist(LocalPlaylistModel *playlistModel, bool shuffled);
0104 
0105 private:
0106     void emitCurrentVideoChanged(const QString &oldVideoId);
0107 
0108     void fetchLyrics(const QString &videoId);
0109 
0110     QString m_initialVideoId;
0111     QString m_playlistId;
0112     QString m_currentVideoId;
0113     bool m_shuffle = false;
0114 
0115     watch::Playlist m_playlist;
0116     ::Lyrics m_lyrics;
0117 };