File indexing completed on 2025-02-23 04:35:15
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include "videobasicinfo.h" 0007 0008 #include <QAbstractListModel> 0009 #include <QFutureWatcher> 0010 #include <QtQml> 0011 0012 #include <abstractapi.h> 0013 0014 class VideoQueue : public QAbstractListModel 0015 { 0016 Q_OBJECT 0017 QML_ELEMENT 0018 QML_UNCREATABLE("Use PlasmaTube.videoController") 0019 0020 Q_PROPERTY(bool shouldBeVisible READ shouldBeVisible NOTIFY queueChanged) 0021 0022 public: 0023 explicit VideoQueue(QObject *parent = nullptr); 0024 0025 void replace(const QStringList &videoIds); 0026 void queueNext(const QString &videoId); 0027 Q_INVOKABLE void clear(); 0028 0029 Q_INVOKABLE void playInQueue(int index); 0030 Q_INVOKABLE void loadPlaylist(const QString &playlistId); 0031 0032 bool shouldBeVisible() const; 0033 0034 void next(); 0035 bool canGoNext() const; 0036 0037 void previous(); 0038 bool canGoPrevious() const; 0039 0040 QString getCurrentVideoId() const; 0041 0042 // TODO: we should have an AbstractVideoListModel, and combine these roles with VideoLisTModel 0043 enum Roles : int { 0044 IdRole = Qt::UserRole + 1, 0045 TitleRole, 0046 ThumbnailRole, 0047 LengthRole, 0048 ViewCountRole, 0049 AuthorRole, 0050 AuthorIdRole, 0051 AuthorUrlRole, 0052 PublishedRole, 0053 PublishedTextRole, 0054 DescriptionRole, 0055 DescriptionHtmlRole, 0056 LiveNowRole, 0057 PaidRole, 0058 PremiumRole, 0059 WatchedRole, 0060 PlayingRole 0061 }; 0062 0063 [[nodiscard]] int rowCount(const QModelIndex &index) const override; 0064 0065 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; 0066 0067 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0068 0069 Q_SIGNALS: 0070 void currentVideoChanged(); 0071 void queueChanged(); 0072 0073 private: 0074 void setCurrentIndex(int newIndex); 0075 void requestMissingVideoInformation(); 0076 0077 QList<QString> m_videoIds; 0078 QList<std::optional<QInvidious::VideoBasicInfo>> m_videoInfo; 0079 int m_currentIndex = 0; 0080 };