File indexing completed on 2025-01-05 04:29:52
0001 /** 0002 * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be> 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 <QAbstractListModel> 0010 #include <QHash> 0011 #include <QItemSelection> 0012 #include <QObject> 0013 #include <QQmlEngine> 0014 #include <QVariant> 0015 0016 #include "enclosure.h" 0017 #include "entry.h" 0018 0019 class DownloadModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 QML_ELEMENT 0023 QML_SINGLETON 0024 0025 public: 0026 static DownloadModel &instance() 0027 { 0028 static DownloadModel _instance; 0029 return _instance; 0030 } 0031 static DownloadModel *create(QQmlEngine *engine, QJSEngine *) 0032 { 0033 engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership); 0034 return &instance(); 0035 } 0036 0037 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0038 QHash<int, QByteArray> roleNames() const override; 0039 int rowCount(const QModelIndex &parent) const override; 0040 0041 Q_INVOKABLE QItemSelection createSelection(int rowa, int rowb); 0042 0043 public Q_SLOTS: 0044 void monitorDownloadStatus(); 0045 0046 private: 0047 explicit DownloadModel(); 0048 0049 void updateInternalState(); 0050 0051 QStringList m_downloadingIds; 0052 QStringList m_partiallyDownloadedIds; 0053 QStringList m_downloadedIds; 0054 QStringList m_entryIds; 0055 0056 int m_downloadingCount = 0; 0057 int m_partiallyDownloadedCount = 0; 0058 int m_downloadedCount = 0; 0059 int m_entryCount = 0; 0060 };