syncthingtray/syncthingmodel/syncthingdownloadmodel.h

84 lines
2.9 KiB
C
Raw Permalink Normal View History

2016-09-21 21:09:12 +02:00
#ifndef DATA_SYNCTHINGDOWNLOADMODEL_H
#define DATA_SYNCTHINGDOWNLOADMODEL_H
#include "./syncthingmodel.h"
2016-09-21 21:09:12 +02:00
#include <QFileIconProvider>
2017-05-01 03:34:43 +02:00
#include <QIcon>
2016-09-21 21:09:12 +02:00
#include <vector>
namespace Data {
struct SyncthingDir;
struct SyncthingItemDownloadProgress;
2017-05-01 03:34:43 +02:00
class LIB_SYNCTHING_MODEL_EXPORT SyncthingDownloadModel : public SyncthingModel {
2016-09-21 21:09:12 +02:00
Q_OBJECT
Q_PROPERTY(unsigned int pendingDownloads READ pendingDownloads NOTIFY pendingDownloadsChanged)
2016-09-28 00:06:21 +02:00
Q_PROPERTY(bool singleColumnMode READ singleColumnMode WRITE setSingleColumnMode)
2016-09-21 21:09:12 +02:00
public:
explicit SyncthingDownloadModel(SyncthingConnection &connection, QObject *parent = nullptr);
enum SyncthingDownloadModelRole { ItemPercentage = SyncthingModelUserRole + 1, ItemProgressLabel, ItemPath };
2016-09-21 21:09:12 +02:00
public Q_SLOTS:
2018-10-10 21:26:46 +02:00
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;
2018-10-10 21:26:46 +02:00
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
2016-09-21 21:09:12 +02:00
const SyncthingDir *dirInfo(const QModelIndex &index) const;
const SyncthingItemDownloadProgress *progressInfo(const QModelIndex &index) const;
QPair<const SyncthingDir *, const SyncthingItemDownloadProgress *> info(const QModelIndex &index) const;
2016-09-21 21:09:12 +02:00
unsigned int pendingDownloads() const;
2016-09-28 00:06:21 +02:00
bool singleColumnMode() const;
void setSingleColumnMode(bool singleColumnModeEnabled);
2016-09-21 21:09:12 +02:00
Q_SIGNALS:
void pendingDownloadsChanged(unsigned int pendingDownloads);
private Q_SLOTS:
void handleConfigInvalidated() override;
void handleNewConfigAvailable() override;
2016-09-21 21:09:12 +02:00
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;
};
2016-09-21 21:09:12 +02:00
const std::vector<SyncthingDir> &m_dirs;
const QIcon m_unknownIcon;
const QFileIconProvider m_fileIconProvider;
std::vector<PendingDir> m_pendingDirs;
2016-09-21 21:09:12 +02:00
unsigned int m_pendingDownloads;
2016-09-28 00:06:21 +02:00
bool m_singleColumnMode;
2016-09-21 21:09:12 +02:00
};
inline QPair<const SyncthingDir *, const SyncthingItemDownloadProgress *> SyncthingDownloadModel::info(const QModelIndex &index) const
{
return qMakePair(dirInfo(index), progressInfo(index));
}
2016-09-21 21:09:12 +02:00
inline unsigned int SyncthingDownloadModel::pendingDownloads() const
{
return m_pendingDownloads;
}
2016-09-28 00:06:21 +02:00
inline bool SyncthingDownloadModel::singleColumnMode() const
{
return m_singleColumnMode;
}
2016-09-21 21:09:12 +02:00
} // namespace Data
#endif // DATA_SYNCTHINGDOWNLOADMODEL_H