玉兔远程控制 0.1.0-bate8
载入中...
搜索中...
未找到
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
9class CRemoteFileSystem : public QObject
10{
11 Q_OBJECT
12public:
13 enum class TYPE {
14 NO = 0x00,
15 FILE = 0x01,
16 DRIVE = 0x02,
17 DIR = 0x04,
18 SYMLINK = 0x08,
19 SPECIAL = 0x10,
20 DIRS = DRIVE | DIR | SYMLINK | SPECIAL,
21 ALL = DIRS | FILE
22 };
23 Q_ENUM(TYPE)
24 Q_DECLARE_FLAGS(TYPES, TYPE)
25 Q_FLAG(TYPES)
26
27 explicit CRemoteFileSystem(const QString& szPath, TYPES type);
28 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]] static 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
103// 在类外部声明操作符(通常放在头文件末尾)
104Q_DECLARE_OPERATORS_FOR_FLAGS(CRemoteFileSystem::TYPES)
105
106class CRemoteFileSystemModel : public QAbstractItemModel
107{
108 Q_OBJECT
109
110public:
111 explicit CRemoteFileSystemModel(
112 QObject *parent = nullptr,
113 CRemoteFileSystem::TYPES filter = CRemoteFileSystem::TYPE::ALL
114 );
115 virtual ~CRemoteFileSystemModel();
116
117 QModelIndex SetRootPath(const QString &szPath);
118 [[nodiscard]] CRemoteFileSystem* GetRoot();
119 [[nodiscard]] CRemoteFileSystem* GetRemoteFileSystemFromIndex(const QModelIndex &index) const;
120 [[nodiscard]] CRemoteFileSystem::TYPES GetFilter();
121
122 void CreateDir(QModelIndex index, const QString& dir);
123 void RemoveDir(QModelIndex index);
124
125 QVariant headerData(int section,
126 Qt::Orientation orientation,
127 int role = Qt::DisplayRole) const override;
128
129 [[nodiscard]] QModelIndex index(CRemoteFileSystem *node, int column = 0) const;
130 [[nodiscard]] QModelIndex index(const QString& szPath) const;
131 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
132 QModelIndex parent(const QModelIndex &index) const override;
133
134 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
135 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
136
137 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
138 virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
139 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
140 virtual void fetchMore(const QModelIndex &parent) override;
141 virtual bool canFetchMore(const QModelIndex &parent) const override;
142
143Q_SIGNALS:
144 void sigGetDir(CRemoteFileSystem* p);
145 void sigMakeDir(const QString& dir);
146 void sigRemoveDir(const QString& szPath);
147 void sigRemoveFile(const QString& szFile);
148 void sigRename(const QString& oldName, const QString& newName);
149public Q_SLOTS:
150 void slotGetDir(CRemoteFileSystem* p,
151 QVector<QSharedPointer<CRemoteFileSystem> > contents,
152 bool bEnd);
153
154private:
155 CRemoteFileSystem* m_pRoot;
156 CRemoteFileSystem::TYPES m_Filter;
157 QList<CRemoteFileSystem*> m_GetFolder;
158
159private:
160 void DeleteRemoteFileSystem(CRemoteFileSystem* p);
161};
int AppendChild(CRemoteFileSystem *pChild)
Append child