File indexing completed on 2024-06-02 05:00:33

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 PipedInstancesModel : 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 { NameRole = Qt::UserRole, URLRole };
0021 
0022     explicit PipedInstancesModel(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     void filterStringChanged();
0034 
0035 private:
0036     void fill();
0037 
0038     struct PipedInstance {
0039         QString name, url;
0040     };
0041 
0042     QList<PipedInstance> m_instances;
0043     bool m_loading = false;
0044     QString m_filterString;
0045     QNetworkAccessManager m_netManager;
0046 };