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