-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathApplicationRemoteFileDialog.qml
315 lines (265 loc) · 8.57 KB
/
ApplicationRemoteFileDialog.qml
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import QtQuick 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.0
import Machinekit.Application 1.0
Dialog {
property var core: null
property var status: core === null ? {"synced": false} : core.status
property var command: core === null ? {"ready": false} : core.command
property var file: core === null ? {"localPath":"", "remotePath":"", "localFilePath":"", "ready":false} : core.file
property var fileDialog: null
property alias width: content.implicitWidth
property alias height: content.implicitHeight
readonly property bool __ready: status.synced && file.ready && (file.transferState === ApplicationFile.NoTransfer)
id: root
title: qsTr("Remote Files")
QtObject {
id: d
property string rootFolder: ""
property string currentFolder: ""
readonly property string serverFolder: rootFolder + currentFolder
readonly property bool directorySelected: (tableView.currentRow > -1) && tableView.model.getIsDir(tableView.currentRow)
onServerFolderChanged: {
if (root.file !== undefined) {
root.file.serverDirectory = serverFolder;
if (root.file.refreshFiles) {
root.file.refreshFiles();
}
}
}
function folderUp(folder) {
var pos = folder.lastIndexOf("/", folder.length-2);
if (pos > -1) {
folder = folder.slice(0, pos);
}
else if (folder !== "") {
folder = "";
}
return folder;
}
function openFile(row) {
if (row < 0) {
return;
}
var dir = tableView.model.getIsDir(row);
var fileName = tableView.model.getName(row);
if (dir) {
if (currentFolder !== "") {
d.currentFolder += "/" + fileName;
}
else {
d.currentFolder = fileName;
}
deselectRow();
}
else {
var newPath = file.remotePath + '/' + file.serverDirectory + '/' + fileName;
core.executeProgram(newPath);
root.close();
}
}
function removeFile(row) {
if (row < 0) {
return;
}
var fileName = tableView.model.getName(row);
var dir = tableView.model.getIsDir(row);
if (!dir) {
file.removeFile(fileName);
}
else {
file.removeDirectory(fileName);
}
deselectRow();
}
function createDirectory(name) {
file.createDirectory(name);
deselectRow();
}
function uploadFileDialog() {
root.close();
fileDialog.open();
}
function uploadFile(url) {
file.localFilePath = url;
file.startUpload();
}
function deselectRow() {
tableView.currentRow = -1;
}
}
Binding {
target: d
property: "currentFolder"
value: file.serverDirectory
}
SystemPalette { id: systemPalette }
contentItem: Rectangle {
id: content
color: systemPalette.window
ColumnLayout {
anchors.fill: parent
anchors.margins: Screen.pixelDensity
RowLayout {
id: header
Button {
text: qsTr("Up")
iconName: "go-up"
onClicked: d.currentFolder = d.folderUp(d.currentFolder);
}
Label {
text: (".../" + d.currentFolder).split("/").join(" / ")
}
}
TableView {
id: tableView
Layout.fillHeight: true
Layout.fillWidth: true
enabled: __ready
model: file.model
TableViewColumn {
role: "name"
title: qsTr("Name")
width: root.width * 0.4
delegate: nameEdit
}
TableViewColumn {
role: "size"
title: qsTr("Size")
width: root.width * 0.2
}
TableViewColumn {
role: "lastModified"
title: qsTr("Last Modified")
width: root.width * 0.3
}
Component {
id: nameEdit
Item {
Label {
anchors.fill: parent
anchors.leftMargin: 5
anchors.rightMargin: 5
elide: Text.ElideRight
color: styleData.textColor
text: styleData.value
font.bold: file.model.getIsDir(styleData.row)
}
}
}
onDoubleClicked: d.openFile(row)
onPressAndHold: fileMenu.popup()
Keys.onReturnPressed: d.openFile(currentRow)
Keys.onDeletePressed: d.removeFile(currentRow)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
fileMenu.popup();
}
}
DropArea {
anchors.fill: parent
onDropped: {
if (drop.hasUrls) {
d.uploadFile(drop.urls[0]);
}
}
}
Menu {
id: fileMenu
MenuItem {
text: d.directorySelected ? qsTr("Open directory") : qsTr("Open file")
enabled: __ready && (tableView.currentRow > -1)
onTriggered: d.openFile(tableView.currentRow)
}
MenuItem {
text: d.directorySelected ? qsTr("Remove directory") : qsTr("Remove file")
enabled: __ready && (tableView.currentRow > -1)
onTriggered: d.removeFile(tableView.currentRow)
}
MenuItem {
text: qsTr("Upload file...")
enabled: __ready
onTriggered: d.uploadFileDialog()
}
MenuItem {
text: qsTr("Create directory")
enabled: __ready
onTriggered: directoryNameDialog.open()
}
}
}
RowLayout {
Layout.fillWidth: true
ApplicationProgressBar {
Layout.fillWidth: true
}
Item { Layout.fillWidth: true }
Button {
text: qsTr("Refresh")
enabled: __ready
iconName: "view-refresh"
onClicked: file.refreshFiles()
}
Button {
text: qsTr("Upload...")
enabled: __ready
iconName: "document-open"
onClicked: d.uploadFileDialog()
}
Button {
text: qsTr("Remove")
iconName: "edit-delete"
enabled: __ready && (tableView.currentRow > -1)
onClicked: d.removeFile(tableView.currentRow)
}
Button {
text: qsTr("Open")
iconName: "document-open-remote"
enabled: __ready && (tableView.currentRow > -1)
onClicked: d.openFile(tableView.currentRow)
}
Button {
text: qsTr("Close")
iconName: "dialog-close"
onClicked: root.close()
}
}
}
}
Dialog {
id: directoryNameDialog
standardButtons: StandardButton.Ok | StandardButton.Cancel
title: qsTr("Enter Directory Name")
onVisibleChanged: {
if (visible) {
textField.text = "";
textField.forceActiveFocus();
}
}
TextField {
id: textField
anchors.fill: parent
}
onAccepted: d.createDirectory(textField.text)
}
onVisibleChanged: {
if (visible) {
file.refreshFiles();
}
}
Component.onCompleted: {
if (core === null)
{
try {
var x = applicationCore;
core = Qt.binding(function() { return x; });
}
catch (err) {
}
}
}
}