Rabbit Remote Control 0.1.0-bate1
Loading...
Searching...
No Matches
RemoteFileSystemModel.h
1// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2// Author Kang Lin <kl222@126.com>
3
4#pragma once
5#include <QAbstractItemModel>
6#include <QDateTime>
7#include <QFileDevice>
8#include "ChannelSFTP.h"
9
10class CRemoteFileSystem : public QObject
11{
12 Q_OBJECT
13public:
14 enum class TYPE {
15 NO = 0x00,
16 FILE = 0x01,
17 DRIVE = 0x02,
18 DIR = 0x04,
19 SYMLINK = 0x08,
20 SPECIAL = 0x10,
21 DIRS = DRIVE | DIR | SYMLINK | SPECIAL,
22 ALL = DIRS | FILE
23 };
24 Q_ENUM(TYPE)
25 Q_DECLARE_FLAGS(TYPES, TYPE)
26 Q_FLAG(TYPES)
27
28 explicit CRemoteFileSystem(const QString& szPath, TYPES type);
29 virtual ~CRemoteFileSystem();
31
32 enum class ColumnValue {
33 Name = 0,
34 Size,
35 Type,
36 LastModified,
37 Permission,
38 Owner,
39 End
40 };
41 Q_ENUM(ColumnValue)
42 [[nodiscard]] static QString HeaderData(int section);
43 [[nodiscard]] QVariant Data(int column);
44
45 [[nodiscard]] int ChildCount();
46 [[nodiscard]] static int ColumnCount();
47
48 void SetParent(CRemoteFileSystem* pParent);
53 int AppendChild(CRemoteFileSystem* pChild);
54 int RemoveChild(int index);
55 [[nodiscard]] CRemoteFileSystem* GetChild(int nIndex);
56 [[nodiscard]] CRemoteFileSystem* GetParent();
57 [[nodiscard]] int IndexOf(CRemoteFileSystem* pChild);
58 [[nodiscard]] int IndexOf(const QString& szPath);
59 [[nodiscard]] int IndexOfParent();
60
61 enum class State{
62 No,
63 Getting,
64 Ok
65 };
66 Q_ENUM(State)
67 [[nodiscard]] const State GetState() const;
68 void SetState(State s);
69
70 [[nodiscard]] QString GetPath();
71 [[nodiscard]] QString GetName();
72
73 [[nodiscard]] quint64 GetSize();
74 void SetSize(quint64 size);
75
76 [[nodiscard]] TYPES GetType();
77 [[nodiscard]] bool IsDir();
78 [[nodiscard]] QIcon Icon();
79
80 [[nodiscard]] QDateTime GetCreateTime();
81 void SetCreateTime(const QDateTime &date);
82 [[nodiscard]] QDateTime GetLastModified();
83 void SetLastModified(const QDateTime& date);
84
85 void SetPermissions(QFileDevice::Permissions privileges);
86 [[nodiscard]] QFileDevice::Permissions GetPermissions();
87
88 [[nodiscard]] QString GetOwner();
89 void SetOwner(QString szOwner);
90
91private:
92 CRemoteFileSystem* m_pParent;
93 QVector<CRemoteFileSystem*> m_vChild;
94 QString m_szPath;
95 quint64 m_nSize;
96 TYPES m_Type;
97 QDateTime m_createTime;
98 QDateTime m_lastModifed;
99 QFileDevice::Permissions m_Permissions;
100 QString m_szOwner;
101 State m_State;
102};
103
104class CRemoteFileSystemModel : public QAbstractItemModel
105{
106 Q_OBJECT
107
108public:
109 explicit CRemoteFileSystemModel(
110 QObject *parent = nullptr,
111 CRemoteFileSystem::TYPES filter = CRemoteFileSystem::TYPE::ALL
112 );
113 virtual ~CRemoteFileSystemModel();
114
115 QModelIndex SetRootPath(const QString &szPath);
116 [[nodiscard]] CRemoteFileSystem* GetRoot();
117 [[nodiscard]] CRemoteFileSystem* GetRemoteFileSystemFromIndex(const QModelIndex &index) const;
118 [[nodiscard]] CRemoteFileSystem::TYPES GetFilter();
119
120 void CreateDir(QModelIndex index, const QString& dir);
121 void RemoveDir(QModelIndex index);
122
123 QVariant headerData(int section,
124 Qt::Orientation orientation,
125 int role = Qt::DisplayRole) const override;
126
127 [[nodiscard]] QModelIndex index(CRemoteFileSystem *node, int column = 0) const;
128 [[nodiscard]] QModelIndex index(const QString& szPath) const;
129 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
130 QModelIndex parent(const QModelIndex &index) const override;
131
132 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
133 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
134
135 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
136 virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
137 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
138 virtual void fetchMore(const QModelIndex &parent) override;
139 virtual bool canFetchMore(const QModelIndex &parent) const override;
140
141Q_SIGNALS:
142 void sigGetDir(CRemoteFileSystem* p);
143 void sigMakeDir(const QString& dir);
144 void sigRemoveDir(const QString& szPath);
145 void sigRemoveFile(const QString& szFile);
146 void sigRename(const QString& oldName, const QString& newName);
147public Q_SLOTS:
148 void slotGetDir(CRemoteFileSystem* p,
149 QVector<QSharedPointer<CRemoteFileSystem> > contents,
150 bool bEnd);
151
152private:
153 CRemoteFileSystem* m_pRoot;
154 CRemoteFileSystem::TYPES m_Filter;
155 QList<CRemoteFileSystem*> m_GetFolder;
156
157private:
158 void DeleteRemoteFileSystem(CRemoteFileSystem* p);
159};
int AppendChild(CRemoteFileSystem *pChild)
Append child.