File indexing completed on 2024-05-05 05:29:11

0001 /*
0002  *   SPDX-FileCopyrightText: 2016-2022 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include "resources/AbstractResourcesBackend.h"
0010 #include <QAbstractListModel>
0011 
0012 class AbstractAppsModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015     Q_PROPERTY(int count READ count NOTIFY appsCountChanged)
0016     Q_PROPERTY(bool isFetching READ isFetching NOTIFY isFetchingChanged)
0017     Q_PROPERTY(AbstractResourcesBackend *currentApplicationBackend READ currentApplicationBackend NOTIFY currentApplicationBackendChanged)
0018 public:
0019     AbstractAppsModel();
0020 
0021     void setResources(const QVector<StreamResult> &resources);
0022     QVariant data(const QModelIndex &index, int role) const override;
0023     int rowCount(const QModelIndex &parent) const override;
0024     QHash<int, QByteArray> roleNames() const override;
0025     AbstractResourcesBackend *currentApplicationBackend() const
0026     {
0027         return m_backend;
0028     }
0029 
0030     bool isFetching() const
0031     {
0032         return m_isFetching != 0;
0033     }
0034 
0035     virtual void refresh() = 0;
0036     int count() const
0037     {
0038         return rowCount({});
0039     }
0040 
0041 Q_SIGNALS:
0042     void appsCountChanged();
0043     void isFetchingChanged();
0044     void currentApplicationBackendChanged(AbstractResourcesBackend *currentApplicationBackend);
0045 
0046 protected:
0047     void refreshCurrentApplicationBackend();
0048     void setUris(const QVector<QUrl> &uris);
0049     void removeResource(AbstractResource *resource);
0050 
0051     void acquireFetching(bool f);
0052 
0053 private:
0054     QVector<StreamResult> m_resources;
0055     int m_isFetching = 0;
0056     AbstractResourcesBackend *m_backend = nullptr;
0057     QVector<QUrl> m_uris;
0058 };