1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#ifndef DATA_SYNCTHINGDOWNLOADMODEL_H
#define DATA_SYNCTHINGDOWNLOADMODEL_H
#include "./syncthingmodel.h"
#include <QFileIconProvider>
#include <QIcon>
#include <vector>
namespace Data {
struct SyncthingDir;
struct SyncthingItemDownloadProgress;
class LIB_SYNCTHING_MODEL_EXPORT SyncthingDownloadModel : public SyncthingModel {
Q_OBJECT
Q_PROPERTY(unsigned int pendingDownloads READ pendingDownloads NOTIFY pendingDownloadsChanged)
public:
explicit SyncthingDownloadModel(SyncthingConnection &connection, QObject *parent = nullptr);
enum SyncthingDownloadModelRole { ItemPercentage = SyncthingModelUserRole + 1, ItemProgressLabel, ItemPath };
public:
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
int rowCount(const QModelIndex &parent) const override;
Q_INVOKABLE const SyncthingDir *dirInfo(const QModelIndex &index) const;
Q_INVOKABLE const SyncthingItemDownloadProgress *progressInfo(const QModelIndex &index) const;
Q_INVOKABLE QPair<const SyncthingDir *, const SyncthingItemDownloadProgress *> info(const QModelIndex &index) const;
unsigned int pendingDownloads() const;
Q_SIGNALS:
void pendingDownloadsChanged(unsigned int pendingDownloads);
private Q_SLOTS:
void handleConfigInvalidated() override;
void handleNewConfigAvailable() override;
void downloadProgressChanged();
private:
struct PendingDir {
const SyncthingDir *syncthingDir;
std::size_t pendingItems;
PendingDir(const SyncthingDir *syncthingDir, unsigned int pendingItems);
bool operator==(const SyncthingDir *dir) const;
};
const std::vector<SyncthingDir> &m_dirs;
const QIcon m_unknownIcon;
const QFileIconProvider m_fileIconProvider;
std::vector<PendingDir> m_pendingDirs;
unsigned int m_pendingDownloads;
};
inline QPair<const SyncthingDir *, const SyncthingItemDownloadProgress *> SyncthingDownloadModel::info(const QModelIndex &index) const
{
return qMakePair(dirInfo(index), progressInfo(index));
}
inline unsigned int SyncthingDownloadModel::pendingDownloads() const
{
return m_pendingDownloads;
}
} // namespace Data
#endif // DATA_SYNCTHINGDOWNLOADMODEL_H
|