~mzanetti/+junk/ubtd

« back to all changes in this revision

Viewing changes to shareplugin/Main.qml

  • Committer: Michael Zanetti
  • Date: 2016-08-21 10:28:36 UTC
  • Revision ID: michael.zanetti@canonical.com-20160821102836-mam1manqthov2um9
improve!

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    width: units.gu(100)
13
13
    height: units.gu(75)
14
14
 
15
 
    property string fileName
 
15
    property var fileNames: []
16
16
    property bool peerSelected: false
17
17
 
18
18
    BtTransfer {
23
23
        target: ContentHub
24
24
 
25
25
        onShareRequested: {
26
 
            var filePath = String(transfer.items[0].url).replace('file://', '')
27
 
            print("Should share file", filePath)
28
 
            root.fileName = filePath;
 
26
            var tmp = []
 
27
            for (var i = 0; i < transfer.items.length; i++) {
 
28
                var filePath = String(transfer.items[i].url).replace('file://', '')
 
29
                print("Should share file", filePath)
 
30
                tmp.push(filePath);
 
31
            }
 
32
            root.fileNames = tmp
29
33
        }
30
34
    }
31
35
 
131
135
            columns: width > height ? 2 : 1
132
136
 
133
137
            Item {
 
138
                Layout.fillWidth: true
134
139
                Layout.fillHeight: true
135
 
                Layout.fillWidth: true
136
 
 
137
 
                Image {
138
 
                    id: transferredImage
139
 
                    anchors.fill: parent
140
 
                    anchors.margins: units.gu(2)
141
 
                    source: "file://" + root.fileName
142
 
                    fillMode: Image.PreserveAspectFit
143
 
                }
144
 
                Icon {
145
 
                    anchors.fill: parent
146
 
                    anchors.margins: units.gu(2)
147
 
                    visible: transferredImage.status === Image.Error || !root.fileName
148
 
                    name: {
149
 
                        var extension = root.fileName.split(".").pop()
150
 
                        switch(extension) {
151
 
                        case "pdf":
152
 
                            return "application-pdf-symbolic";
153
 
                        case "tar":
154
 
                        case "gz":
155
 
                        case "gzip":
156
 
                        case "zip":
157
 
                        case "xz":
158
 
                            return "application-x-archive-symbolic";
159
 
                        case "mp3":
160
 
                        case "ogg":
161
 
                        case "wav":
162
 
                        case "flac":
163
 
                            return "audio-x-generic-symbolic";
164
 
                        case "jpg":
165
 
                        case "gif":
166
 
                        case "jpeg":
167
 
                        case "png":
168
 
                        case "webp":
169
 
                            return "image-x-generic-symbolic";
170
 
                        case "click":
171
 
                        case "deb":
172
 
                            return "package-x-generic-symbolic";
173
 
                        case "txt":
174
 
                            return "text-generic-symbolic";
175
 
                        case "mp4":
176
 
                        case "mkv":
177
 
                        case "avi":
178
 
                        case "mpeg":
179
 
                        case "mpg":
180
 
                            return "video-x-generic-symbolic";
181
 
                        default:
182
 
                            return "empty-symbolic";
 
140
                GridLayout {
 
141
                    anchors.fill: parent
 
142
                    columns: Math.ceil(Math.sqrt(root.fileNames.length))
 
143
 
 
144
                    Repeater {
 
145
                        model: root.fileNames
 
146
                        Item {
 
147
                            Layout.fillHeight: true
 
148
                            Layout.fillWidth: true
 
149
 
 
150
                            UbuntuShape {
 
151
                                anchors.fill: parent
 
152
                                anchors.margins: units.gu(2)
 
153
                                aspect: UbuntuShape.DropShadow
 
154
                                sourceFillMode: Image.PreserveAspectCrop
 
155
                                source: Image {
 
156
                                    id: transferredImage
 
157
                                    source: "file://" + modelData
 
158
                                }
 
159
                            }
 
160
 
 
161
                            Icon {
 
162
                                anchors.fill: parent
 
163
                                anchors.margins: units.gu(2)
 
164
                                visible: transferredImage.status === Image.Error
 
165
                                name: {
 
166
                                    var extension = modelData.split(".").pop()
 
167
                                    switch(extension) {
 
168
                                    case "pdf":
 
169
                                        return "application-pdf-symbolic";
 
170
                                    case "tar":
 
171
                                    case "gz":
 
172
                                    case "gzip":
 
173
                                    case "zip":
 
174
                                    case "xz":
 
175
                                        return "application-x-archive-symbolic";
 
176
                                    case "mp3":
 
177
                                    case "ogg":
 
178
                                    case "wav":
 
179
                                    case "flac":
 
180
                                        return "audio-x-generic-symbolic";
 
181
                                    case "jpg":
 
182
                                    case "gif":
 
183
                                    case "jpeg":
 
184
                                    case "png":
 
185
                                    case "webp":
 
186
                                        return "image-x-generic-symbolic";
 
187
                                    case "click":
 
188
                                    case "deb":
 
189
                                        return "package-x-generic-symbolic";
 
190
                                    case "txt":
 
191
                                        return "text-generic-symbolic";
 
192
                                    case "mp4":
 
193
                                    case "mkv":
 
194
                                    case "avi":
 
195
                                    case "mpeg":
 
196
                                    case "mpg":
 
197
                                        return "video-x-generic-symbolic";
 
198
                                    default:
 
199
                                        return "empty-symbolic";
 
200
                                    }
 
201
                                }
 
202
                            }
 
203
 
 
204
                            Rectangle {
 
205
                                anchors.centerIn: parent
 
206
                                color: "white"
 
207
                                border.width: units.dp(2)
 
208
                                border.color: UbuntuColors.blue
 
209
                                radius: width / 2
 
210
                                height: units.gu(8)
 
211
                                width: height
 
212
                                visible: isInProgress || isDone || isError
 
213
 
 
214
                                property bool isInProgress: transfer.currentFile === modelData
 
215
                                property bool isDone: false
 
216
                                property bool isError: false
 
217
                                onIsInProgressChanged: {
 
218
                                    print("isinprogresschanged:", isInProgress, transfer.error)
 
219
                                    if (!isInProgress) {
 
220
                                        isDone = !transfer.error;
 
221
                                        isError = !!transfer.error
 
222
                                    }
 
223
                                }
 
224
 
 
225
                                ActivityIndicator {
 
226
                                    anchors.centerIn: parent
 
227
                                    visible: running
 
228
                                    running: !transfer.finished && transfer.progress > 0 && !parent.isDone
 
229
                                }
 
230
 
 
231
                                Icon {
 
232
                                    anchors.centerIn: parent
 
233
                                    width: units.gu(6)
 
234
                                    height: width
 
235
                                    name: parent.isDone ? "tick" : "close"
 
236
                                    color: parent.isDone ? UbuntuColors.green : UbuntuColors.red
 
237
                                    visible: parent.isDone || parent.isError
 
238
                                }
 
239
                            }
 
240
 
183
241
                        }
184
242
                    }
185
243
                }
196
254
                    clip: true
197
255
 
198
256
                    delegate: ListItem {
199
 
                        height: units.gu(6)
200
 
                        Label {
201
 
                            anchors.centerIn: parent
202
 
                            text: (deviceName ? deviceName : name)
 
257
                        ListItemLayout {
 
258
                            title.text: (deviceName ? deviceName : name)
203
259
                        }
 
260
 
204
261
                        onClicked: {
205
262
                            btModel.continuousDiscovery = false;
206
 
                            transfer.sendFile(remoteAddress, root.fileName)
 
263
                            for (var i = 0; i < root.fileNames.length; i++) {
 
264
                                transfer.sendFile(remoteAddress, root.fileNames[i])
 
265
                            }
207
266
                            root.peerSelected = true;
208
267
                        }
209
268
                    }
218
277
                        Layout.fillWidth: true
219
278
                        wrapMode: Text.WordWrap
220
279
                        text: transfer.error ? "Transfer failed."
221
 
                                : transfer.finished ? "File transferred."
222
 
                                : "Transferring file..."
 
280
                                : transfer.finished ? (root.fileNames.length == 1 ? "File transferred." : "All files transferred.")
 
281
                                : "Transferring..."
223
282
                        fontSize: "large"
224
283
                    }
225
284