File: syncthingrecentchangesmodel.h

package info (click to toggle)
syncthingtray 1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,804 kB
  • sloc: cpp: 31,085; xml: 1,694; java: 570; sh: 81; javascript: 53; makefile: 25
file content (74 lines) | stat: -rw-r--r-- 2,355 bytes parent folder | download
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
74
#ifndef DATA_SYNCTHINGRECENTCHANGESMODEL_H
#define DATA_SYNCTHINGRECENTCHANGESMODEL_H

#include "./syncthingmodel.h"

#include <syncthingconnector/syncthingconnectionstatus.h>
#include <syncthingconnector/syncthingdir.h>

#include <deque>

namespace Data {

struct LIB_SYNCTHING_MODEL_EXPORT SyncthingRecentChange {
    QString directoryId;
    QString directoryName;
    QString deviceId;
    QString deviceName;
    SyncthingFileChange fileChange;
};

class LIB_SYNCTHING_MODEL_EXPORT SyncthingRecentChangesModel : public SyncthingModel {
    Q_OBJECT
    Q_PROPERTY(int maxRows READ maxRows WRITE setMaxRows)
public:
    enum SyncthingRecentChangesModelRole {
        Action = SyncthingModelUserRole + 1,
        ActionIcon,
        ModifiedBy,
        DirectoryId,
        DirectoryName,
        Path,
        EventTime,
        ExtendedAction,
        ItemType,
    };

    explicit SyncthingRecentChangesModel(SyncthingConnection &connection, int maxRows = -1, QObject *parent = nullptr);

    QHash<int, QByteArray> roleNames() const override;
    const QVector<int> &colorRoles() 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) 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;
    int maxRows() const;
    void setMaxRows(int maxRows);

private Q_SLOTS:
    void fileChanged(const Data::SyncthingDir &dir, int index, const Data::SyncthingFileChange &change);
    void handleConfigInvalidated() override;
    void handleNewConfigAvailable() override;
    void handleStatusChanged(Data::SyncthingStatus status);
    void handleForkAwesomeIconsChanged() override;

private:
    void ensureWithinLimit();

    std::deque<SyncthingRecentChange> m_changes;
    int m_maxRows;
};

inline int SyncthingRecentChangesModel::maxRows() const
{
    return m_maxRows;
}

} // namespace Data

Q_DECLARE_METATYPE(Data::SyncthingRecentChange)

#endif // DATA_SYNCTHINGRECENTCHANGESMODEL_H