-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransferwindow.cpp
More file actions
213 lines (156 loc) · 5.43 KB
/
transferwindow.cpp
File metadata and controls
213 lines (156 loc) · 5.43 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "transferwindow.h"
#include <QLayout>
#include <QMessageBox>
#include <QLabel>
#include <QTreeWidget>
#include <QPushButton>
// Constructor
TransferWindow::TransferWindow(QWidget *parent) : QMainWindow(parent), _client(new Client)
{
_buildUI();
_connectSlots();
}
// Destructor
TransferWindow::~TransferWindow()
{
qDebug() << "Execute TransferWindow::~TransferWindow()";
_client->deleteLater();
_client = nullptr;
}
// Public Methods
void TransferWindow::setAccount(const Account &account)
{
_client->setAccount(account);
}
void TransferWindow::setBucket(const QString &bucket)
{
_client->setBucket(bucket);
}
void TransferWindow::setDirMode(const QString &dirMode)
{
_dirMode = dirMode;
}
// Private Methods
void TransferWindow::_buildUI()
{
_icon.addFile(":/dir-o-20.png", QSize(20, 20), QIcon::Normal, QIcon::On);
_icon.addFile(":/dir-20.png", QSize(20, 20), QIcon::Normal, QIcon::Off);
QWidget *container = new QWidget(this);
this->setCentralWidget(container);
QVBoxLayout *vbLayout = new QVBoxLayout(container);
vbLayout->setSpacing(0);
vbLayout->setContentsMargins(0, 0, 0, 0);
QWidget *pathsContainer = new QWidget(container);
pathsContainer->setFixedHeight(30);
QHBoxLayout *pathsLayout = new QHBoxLayout(pathsContainer);
pathsLayout->setContentsMargins(10, 0, 10, 0);
pathsLayout->setAlignment(Qt::AlignLeft);
QLabel *label = new QLabel("当前选择路径: ", pathsContainer);
label->setFixedSize(110, 30);
pathsLayout->addWidget(label);
_currentPathLabel = new QLabel("/", pathsContainer);
_currentPathLabel->setFixedHeight(30);
pathsLayout->addWidget(_currentPathLabel);
vbLayout->addWidget(pathsContainer);
_tree = new QTreeWidget(container);
_tree->setFixedSize(600, 320);
_tree->setHeaderHidden(true);
_tree->setColumnCount(1);
_tree->setFrameStyle(QFrame::NoFrame);
_tree->setRootIsDecorated(false);
_tree->setFocusPolicy(Qt::NoFocus);
QTreeWidgetItem *root = new QTreeWidgetItem(_tree, QStringList("/"));
root->setData(0, Qt::UserRole, QVariant(""));
root->setIcon(0, _icon);
_tree->insertTopLevelItem(0, root);
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(_tree);
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->setContentsMargins(10, 10, 10, 10);
bottomLayout->addStretch();
_saveButton = new QPushButton("确定", container);
_saveButton->setFixedSize(100, 30);
QFont font = _saveButton->font();
font.setBold(true);
font.setPixelSize(14);
_saveButton->setFont(font);
bottomLayout->addWidget(_saveButton);
_cancelButton = new QPushButton("取消", container);
_cancelButton->setFixedSize(100, 30);
bottomLayout->addWidget(_cancelButton);
vbLayout->addLayout(topLayout);
vbLayout->addLayout(bottomLayout);
}
void TransferWindow::_connectSlots() const
{
connect(_tree, &QTreeWidget::itemClicked, this, &TransferWindow::_itemClicked);
connect(this, &TransferWindow::listObject, _client, &Client::listObject, Qt::QueuedConnection);
connect(_client, &Client::listObjectResponse, this, &TransferWindow::_listObjectResponse, Qt::QueuedConnection);
connect(_saveButton, &QPushButton::clicked, this, &TransferWindow::_saveButtonClicked);
connect(_cancelButton, &QPushButton::clicked, this, &TransferWindow::_cancelButtonClicked);
}
void TransferWindow::_listObject(const ListObjectParams ¶ms)
{
emit listObject(params);
}
// Private Slots
void TransferWindow::_listObjectResponse(QNetworkReply::NetworkError error,
const QStringHash ¶ms,
const QStringVector &dirs,
const QVector<File> &files)
{
Q_UNUSED(files);
qDebug() << "receive TransferWindow listObjectResponse";
if (error != QNetworkReply::NoError)
{
QMessageBox::warning(this, "警告", "获取对象列表失败");
return;
}
qDebug() << "params:" << params;
qDebug() << "dirs:" << dirs;
_storeDirs += dirs;
_storeDirs.removeOne(params["prefix"]);
if (params["isTruncated"] == "true")
{
ListObjectParams listParams(params["prefix"], params["nextMarker"]);
_listObject(listParams);
return;
}
QTreeWidgetItem *item = _tree->currentItem();
QList<QTreeWidgetItem*> children;
foreach (auto dir, _storeDirs)
{
QString text = _path == "" ? dir : dir.replace(dir.indexOf(_path), _path.size(), "");
QTreeWidgetItem *child = new QTreeWidgetItem(item, QStringList(text));
child->setData(0, Qt::UserRole, QVariant(_path + text));
child->setIcon(0, _icon);
children.append(child);
}
item->addChildren(children);
item->setExpanded(true);
_storeDirs.clear();
}
void TransferWindow::_itemClicked(QTreeWidgetItem *item, int)
{
QString fullPath = item->data(0, Qt::UserRole).toString();
qDebug() << "fullPath:" << fullPath;
_path = fullPath;
_currentPathLabel->setText("/" + _path);
if (item->childCount() == 0 && !item->isExpanded())
{
ListObjectParams params(_path);
_listObject(params);
}
else
item->setExpanded(true);
}
void TransferWindow::_saveButtonClicked()
{
emit transferPathSelected(_dirMode, _path);
close();
}
void TransferWindow::_cancelButtonClicked()
{
// emit transferCanceled();
close();
}