-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.h
More file actions
86 lines (81 loc) · 4.61 KB
/
mainwindow.h
File metadata and controls
86 lines (81 loc) · 4.61 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileSystemModel> //用途:提供一个与用户本地电脑的文件系统直接对应的"数据模型"
#include <QDir>//处理目录和文件路径的辅助工具类
#include "sftpmanager.h"
#include <QThread>
#include <QStandardItemModel>//通用的,空白的模型来手动管理数据
#include <QList> //Qt提供的通用列表容器,类似于一个动态数组。用它作为一个"包裹",批量地从SftpManager传递多个文件的信息
#include <QVariantMap> // <-- 新增
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
struct RemoteFile;//前向声明,接下来有一个RemoteFile的结构体类型
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
signals:
//用于请求SftpManager执行操作地信号
void connectRequested(const QString &host , int port ,const QString &user,const QString &pass);
//emit关键字只能用来发射在signals:区域下声明过的信号
void listDirectoryRequested(const QModelIndex &parentIndex,const QString &path);//定义请求信号,逻辑是主窗口(前台)向SftpManager(后厨)下达指令的通信方式。
//参数,告诉SftpManager应该去获取哪个目录(比如/或/home/user/)的内容
// 新增:请求下载文件的信号
void downloadFileRequested(const QString &remotePath, const QString &localPath);
// 新增:请求上传文件的信号
void uploadFileRequested(const QString &localPath, const QString &remotePath);
// 新增:请求删除文件的信号
void deleteFileRequested(const QString &remotePath);
private slots:
void on_localTree_clicked(const QModelIndex &index);
/*声明有一个私有的槽函数,无返回值,能接收一个代表被点项位置的QModelIndex对象作为参数。这个函数专门用来响应界面上localTree的控件所发出的clicked信号*/
void handleQuickConnect();
void onSftpConnected();
void onSftpError(const QString &message);
void onSftpDirectoryListed(const QModelIndex &parentIndex,const QList<RemoteFile> &files);//定义响应槽,是SftpManager(后厨)向主窗口(前台)汇报工作成果的通信方式
//在setupSftp函数中,将SftpManager的directoryListed信号连接到这个槽函数中;当槽函数被调用时,它就会执行函数体内的代码——遍历files列表,
//并用remoteModel->appendRow()将数据填充到我们的远程视图模型中,最终更新UI
//小结:remoteModel是数据仓库,而listDirectoryRequested信号和onSftpDirectoryListed槽函数 分别是向后台发出数据请求和接收后台数据报告的两个关键通信接口
void on_remoteTree_expanded(const QModelIndex &index);
void on_remoteTree_clicked(const QModelIndex &index);
void handleRemoteDoubleClick(const QModelIndex &index);//实现双击进入目录
// 新增:处理后台进度的槽
void onTransferProgress(qint64 bytesTransferred, qint64 totalBytes);
// 新增:处理下载完成的槽
void onDownloadFinished(const QString &remotePath, const QString &localPath, qint64 size, bool success, const QString &errorMessage);
// 新增:处理上传结果的槽
void onUploadFinished(const QString &localPath, const QString &remotePath, qint64 size, bool success, const QString &errorMessage);
// 新增:处理本地视图双击事件的槽
void handleLocalDoubleClick(const QModelIndex &index);
// 新增:处理删除按钮点击的槽
void onDeleteActionTriggered();
// 新增:处理删除完成的槽
void onRemoteFileDeleted(const QString &remotePath, bool success, const QString &errorMessage);
// 新增:处理刷新按钮点击的槽
void onRefreshActionTriggered();
// 新增:处理站点管理器按钮点击的槽
void onSiteManagerActionTriggered();
// 新增:处理来自站点管理器的连接请求
void onConnectFromSiteManager(const QVariantMap &siteData);
private:
Ui::MainWindow *ui;
QFileSystemModel *localModel;//声明一个私有的,QFileSYstemModel类型的指针变量,周期生命性和MainWindow对象同生共死
SftpManager *sftpManager;//声明"网络管家"SftpManager成员变量,后续在MainWindow的主窗口中实例化对象
void setupQuickConnectBar();//"设置快速连接栏"相关代码封装到这个函数内部,构造函数只需调用setupQuickConnectBar();这一行
/*SftpManager *sftpManager;: 声明了 MainWindow 拥有什么核心组件(一个网络管家)。
void setupQuickConnectBar();: 声明了 MainWindow 内部如何组织它的工作流程(一个用于设置UI的辅助方法)。*/
QThread *sftpThread;//引入多线程,解决UI卡顿现象
QStandardItemModel *remoteModel;//这个remoteModel就是窗口用于管理远程文件数据的"大脑"或"馆藏目录";所有从服务器获取的文件和文件夹信息,最终都会整理并手动添加到这个remoteModel
// 新增:为下方的传输日志标签页创建两个模型
QStandardItemModel *successfulTransfersModel;
QStandardItemModel *failedTransfersModel;
// 新增:一个专门用来添加传输日志条目的辅助函数
void addTransferLogEntry(const QString &localPath, const QString &remotePath, const QString &direction, qint64 size, bool success, const QString &message);
};
#endif // MAINWINDOW_H