File indexing completed on 2025-02-23 04:35:16
0001 // SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include "abstractapi.h" 0007 #include "abstractlistmodel.h" 0008 0009 #include <searchparameters.h> 0010 #include <videobasicinfo.h> 0011 0012 #include <QAbstractListModel> 0013 #include <QFutureSynchronizer> 0014 #include <QtQml> 0015 0016 class InvidiousManager; 0017 class QNetworkReply; 0018 0019 class VideoListModel : public AbstractListModel 0020 { 0021 Q_OBJECT 0022 QML_ELEMENT 0023 0024 Q_PROPERTY(QString title READ title NOTIFY titleChanged) 0025 0026 public: 0027 enum QueryType : quint8 { 0028 NoQuery, 0029 Feed, 0030 Search, 0031 Top, 0032 Trending, 0033 TrendingGaming, 0034 TrendingMovies, 0035 TrendingMusic, 0036 TrendingNews, 0037 RecommendedVideos, 0038 Channel, 0039 History, 0040 Playlist 0041 }; 0042 Q_ENUM(QueryType) 0043 0044 Q_INVOKABLE static QString queryTypeString(QueryType); 0045 Q_INVOKABLE static QString queryTypeIcon(QueryType); 0046 0047 explicit VideoListModel(QObject *parent = nullptr); 0048 explicit VideoListModel(const QList<QInvidious::VideoBasicInfo> &, QObject *parent = nullptr); 0049 0050 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0051 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0052 void fetchMore(const QModelIndex &parent) override; 0053 bool canFetchMore(const QModelIndex &parent) const override; 0054 0055 QString title() const; 0056 0057 public Q_SLOTS: 0058 void requestChannel(const QString &ucid); 0059 void requestQuery(VideoListModel::QueryType type); 0060 void requestPlaylist(const QString &id); 0061 void refresh() override; 0062 void markAsWatched(int index) override; 0063 void markAsUnwatched(int index) override; 0064 void removeFromPlaylist(const QString &plid, int index) override; 0065 0066 Q_SIGNALS: 0067 void titleChanged(); 0068 0069 private: 0070 void handleQuery(QFuture<QInvidious::VideoListResult> future, QueryType, bool reset = true); 0071 0072 void setQueryType(QueryType); 0073 void clearAll(); 0074 0075 QueryType m_queryType = NoQuery; 0076 qint32 m_currentPage = 1; 0077 SearchParameters m_searchParameters; 0078 QString m_channel; 0079 QFutureWatcher<QInvidious::VideoListResult> *m_futureWatcher = nullptr; 0080 0081 // history 0082 QFutureWatcher<QInvidious::HistoryResult> *m_historyPageWatcher = nullptr; 0083 QFutureSynchronizer<QInvidious::VideoResult> m_historyFutureSync; 0084 QFutureWatcher<void> *m_historyFetchFinishWatcher = nullptr; 0085 0086 // playlist 0087 QString m_playlist; 0088 0089 QList<QInvidious::VideoBasicInfo> m_results; 0090 0091 void requestHistory(); 0092 void processHistoryResult(const QList<QString> &result); 0093 };