syncthingtray/syncthingmodel/syncthingfilemodel.h

99 lines
3.2 KiB
C
Raw Normal View History

2024-04-01 18:57:18 +02:00
#ifndef DATA_SYNCTHINGFILEMODEL_H
#define DATA_SYNCTHINGFILEMODEL_H
#include "./syncthingmodel.h"
2024-04-07 23:29:23 +02:00
#include <syncthingconnector/syncthingconnection.h>
2024-05-13 20:15:10 +02:00
#include <QFuture>
#include <QFutureWatcher>
#include <map>
2024-04-07 23:29:23 +02:00
#include <memory>
2024-04-01 18:57:18 +02:00
QT_FORWARD_DECLARE_CLASS(QAction)
2024-04-01 18:57:18 +02:00
namespace Data {
class LIB_SYNCTHING_MODEL_EXPORT SyncthingFileModel : public SyncthingModel {
Q_OBJECT
Q_PROPERTY(bool selectionModeEnabled READ isSelectionModeEnabled WRITE setSelectionModeEnabled)
2024-04-01 18:57:18 +02:00
public:
2024-05-04 22:37:31 +02:00
enum SyncthingFileModelRole {
NameRole = SyncthingModelUserRole + 1,
SizeRole,
ModificationTimeRole,
PathRole,
Actions,
ActionNames,
ActionIcons
};
2024-04-01 18:57:18 +02:00
2024-04-07 23:29:23 +02:00
explicit SyncthingFileModel(SyncthingConnection &connection, const SyncthingDir &dir, QObject *parent = nullptr);
2024-04-01 18:57:18 +02:00
~SyncthingFileModel() override;
public Q_SLOTS:
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
2024-04-07 23:29:23 +02:00
QModelIndex index(const QString &path) const;
2024-04-01 18:57:18 +02:00
QModelIndex parent(const QModelIndex &child) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
2024-04-01 18:57:18 +02:00
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;
int columnCount(const QModelIndex &parent) const override;
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
void triggerAction(const QString &action, const QModelIndex &index);
QList<QAction *> selectionActions();
bool isSelectionModeEnabled() const;
void setSelectionModeEnabled(bool selectionModeEnabled);
2024-04-01 18:57:18 +02:00
public:
QString path(const QModelIndex &path) const;
2024-05-13 20:15:10 +02:00
Q_SIGNALS:
void fetchQueueEmpty();
2024-04-01 18:57:18 +02:00
private Q_SLOTS:
void handleConfigInvalidated() override;
void handleNewConfigAvailable() override;
void handleForkAwesomeIconsChanged() override;
2024-05-13 20:15:10 +02:00
void handleBrightColorsChanged() override;
void handleLocalLookupFinished();
2024-04-01 18:57:18 +02:00
private:
void setCheckState(const QModelIndex &index, Qt::CheckState checkState);
2024-05-13 20:15:10 +02:00
void processFetchQueue(const QString &lastItemPath = QString());
2024-04-01 18:57:18 +02:00
private:
2024-05-13 20:15:10 +02:00
using SyncthingItems = std::vector<std::unique_ptr<SyncthingItem>>;
using LocalLookupRes = std::shared_ptr<std::map<QString, SyncthingItem>>;
struct QueryResult : SyncthingConnection::QueryResult {
QString forPath;
QFuture<LocalLookupRes> localLookup;
QPersistentModelIndex refreshedIndex;
QueryResult &operator=(SyncthingConnection::QueryResult &&);
};
2024-04-01 18:57:18 +02:00
SyncthingConnection &m_connection;
QString m_dirId;
2024-05-04 22:37:31 +02:00
QString m_localPath;
2024-04-07 23:29:23 +02:00
QStringList m_fetchQueue;
2024-05-13 20:15:10 +02:00
QueryResult m_pendingRequest;
QFutureWatcher<LocalLookupRes> m_localItemLookup;
2024-04-07 23:29:23 +02:00
std::unique_ptr<SyncthingItem> m_root;
bool m_selectionMode;
2024-04-01 18:57:18 +02:00
};
inline bool SyncthingFileModel::isSelectionModeEnabled() const
{
return m_selectionMode;
}
2024-04-01 18:57:18 +02:00
} // namespace Data
#endif // DATA_SYNCTHINGFILEMODEL_H