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 "videosource.h" 0007 0008 #include <QAbstractListModel> 0009 #include <QtQml> 0010 0011 class SourceManager : public QAbstractListModel 0012 { 0013 Q_OBJECT 0014 QML_ELEMENT 0015 QML_UNCREATABLE("Use PlasmaTube.sourceManager") 0016 0017 Q_PROPERTY(bool hasAnySources READ hasAnySources NOTIFY sourcesChanged) 0018 Q_PROPERTY(bool finishedLoading READ hasFinishedLoading NOTIFY finishedLoading) 0019 Q_PROPERTY(VideoSource *selectedSource READ selectedSource WRITE selectSource NOTIFY sourceSelected) 0020 Q_PROPERTY(int selectedIndex READ selectedIndex NOTIFY sourceSelected) 0021 0022 public: 0023 explicit SourceManager(QObject *parent = nullptr); 0024 0025 void load(); 0026 0027 enum CustomRoles { 0028 SourceRole = Qt::UserRole, 0029 }; 0030 0031 [[nodiscard]] int rowCount(const QModelIndex &index) const override; 0032 0033 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; 0034 0035 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0036 0037 void selectSource(VideoSource *source); 0038 VideoSource *selectedSource() const; 0039 int selectedIndex() const; 0040 0041 Q_INVOKABLE bool canRemove() const; 0042 Q_INVOKABLE void removeSource(VideoSource *source); 0043 0044 bool hasAnySources() const; 0045 bool hasFinishedLoading() const; 0046 0047 Q_INVOKABLE void createInvidiousSource(const QString &url); 0048 Q_INVOKABLE void createPeerTubeSource(const QString &url); 0049 Q_INVOKABLE void createPipedSource(const QString &url); 0050 0051 Q_SIGNALS: 0052 void sourcesChanged(); 0053 void sourceSelected(); 0054 void finishedLoading(); 0055 0056 private: 0057 QVector<VideoSource *> m_sources; 0058 QVector<bool> m_finishedSources; 0059 void insertSource(VideoSource *pSource); 0060 VideoSource *m_selectedSource = nullptr; 0061 bool m_finishedLoading = false; 0062 void checkIfFinishedLoading(); 0063 };