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 <QAbstractListModel> 0007 #include <QDateTime> 0008 #include <QNetworkAccessManager> 0009 #include <QUrl> 0010 #include <QtQml> 0011 0012 class InvidiousInstancesModel : public QAbstractListModel 0013 { 0014 Q_OBJECT 0015 QML_ELEMENT 0016 0017 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0018 0019 public: 0020 enum CustomRoles { URLRole = Qt::UserRole }; 0021 0022 explicit InvidiousInstancesModel(QObject *parent = nullptr); 0023 0024 bool loading() const; 0025 void setLoading(bool loading); 0026 0027 QVariant data(const QModelIndex &index, int role) const override; 0028 int rowCount(const QModelIndex &parent) const override; 0029 QHash<int, QByteArray> roleNames() const override; 0030 0031 Q_SIGNALS: 0032 void loadingChanged(); 0033 0034 private: 0035 void fill(); 0036 0037 struct InvidiousInstance { 0038 QString url; 0039 }; 0040 0041 QList<InvidiousInstance> m_instances; 0042 bool m_loading = false; 0043 InvidiousInstance fromSourceData(const QJsonArray &object) const; 0044 QNetworkAccessManager m_netManager; 0045 };