~mzanetti/+junk/ubtd

« back to all changes in this revision

Viewing changes to app/Main.qml

  • Committer: Michael Zanetti
  • Date: 2016-04-14 23:34:10 UTC
  • Revision ID: michael.zanetti@canonical.com-20160414233410-17jg7ez3w1qc5e16
make it work, polish a bit, 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 2.0
 
1
import QtQuick 2.4
2
2
import QtQuick.Layouts 1.1
3
 
import Ubuntu.Components 1.2
 
3
import Ubuntu.Components 1.3
 
4
import Ubuntu.Content 1.3
 
5
import ubtd 1.0
4
6
 
5
7
MainView {
6
8
    applicationName: "ubtd.mzanetti"
9
11
    width: units.gu(100)
10
12
    height: units.gu(75)
11
13
 
 
14
    PageStack {
 
15
        id: pageStack
 
16
        Component.onCompleted: push(mainPage)
 
17
    }
 
18
 
12
19
    Page {
13
 
        title: i18n.tr("Bluetooth file transfer")
 
20
        id: mainPage
 
21
        header: PageHeader {
 
22
            title: i18n.tr("Bluetooth file transfer")
 
23
            leadingActionBar.actions: []
 
24
        }
14
25
 
15
26
        ColumnLayout {
16
27
            spacing: units.gu(1)
17
28
            anchors {
18
 
                margins: units.gu(1)
 
29
                margins: units.gu(2)
19
30
                fill: parent
 
31
                topMargin: mainPage.header.height + units.gu(1)
20
32
            }
21
33
 
22
34
            Label {
39
51
                model: obexd
40
52
 
41
53
                delegate: ListItem {
 
54
                    id: listItem
42
55
                    height: units.gu(10)
 
56
                    onClicked: {
 
57
                        pageStack.push(pickerPageComponent, {contentType: listItem.contentType, filePath: model.filePath + "/" + model.filename})
 
58
                    }
 
59
 
 
60
                    property var contentType: null
 
61
 
43
62
                    RowLayout {
44
63
                        anchors { fill: parent; margins: units.gu(1) }
45
 
                        Image {
 
64
 
 
65
 
 
66
                        Item {
46
67
                            Layout.fillHeight: true
47
68
                            Layout.preferredWidth: height
48
 
                            source: completed ? (success ? "file://" + filePath + filename : "image://theme/close") : "image://theme/empty-symbolic"
49
 
                            fillMode: Image.PreserveAspectFit
 
69
 
 
70
                            Image {
 
71
                                id: transferredImage
 
72
                                anchors.fill: parent
 
73
                                source: model.status === Transfer.StatusComplete ? "file://" + filePath + "/" + filename : ""
 
74
                                fillMode: Image.PreserveAspectFit
 
75
                            }
 
76
                            Icon {
 
77
                                anchors.fill: parent
 
78
                                visible: status !== Transfer.StatusComplete || transferredImage.status === Image.Error
 
79
                                name: {
 
80
                                    var extension = filename.split(".").pop()
 
81
                                    switch(extension) {
 
82
                                    case "pdf":
 
83
                                        listItem.contentType = ContentType.Documents;
 
84
                                        return "application-pdf-symbolic";
 
85
                                    case "tar":
 
86
                                    case "gz":
 
87
                                    case "gzip":
 
88
                                    case "zip":
 
89
                                    case "xz":
 
90
                                        listItem.contentType = ContentType.Unknown;
 
91
                                        return "application-x-archive-symbolic";
 
92
                                    case "mp3":
 
93
                                    case "ogg":
 
94
                                    case "wav":
 
95
                                    case "flac":
 
96
                                        listItem.contentType = ContentType.Music;
 
97
                                        return "audio-x-generic-symbolic";
 
98
                                    case "jpg":
 
99
                                    case "gif":
 
100
                                    case "jpeg":
 
101
                                    case "png":
 
102
                                    case "webp":
 
103
                                        listItem.contentType = ContentType.Pictures;
 
104
                                        return "image-x-generic-symbolic";
 
105
                                    case "click":
 
106
                                    case "deb":
 
107
                                        listItem.contentType = ContentType.Unknown;
 
108
                                        return "package-x-generic-symbolic";
 
109
                                    case "txt":
 
110
                                        listItem.contentType = ContentType.Text;
 
111
                                        return "text-generic-symbolic";
 
112
                                    case "mp4":
 
113
                                    case "mkv":
 
114
                                    case "avi":
 
115
                                    case "mpeg":
 
116
                                    case "mpg":
 
117
                                        listItem.contentType = ContentType.Videos;
 
118
                                        return "video-x-generic-symbolic";
 
119
                                    default:
 
120
                                        listItem.contentType = ContentType.Unknown;
 
121
                                        return "empty-symbolic";
 
122
                                    }
 
123
                                }
 
124
                            }
50
125
                        }
51
126
 
52
127
                        ColumnLayout {
59
134
                                Layout.preferredHeight: units.dp(5)
60
135
                                UbuntuShape {
61
136
                                    anchors.fill: parent
62
 
                                    color: UbuntuColors.orange
 
137
                                    color: UbuntuColors.blue
63
138
                                    // trans : total = x : width
64
139
                                    anchors.rightMargin: parent.width - (transferred * parent.width / size)
65
140
                                }
66
141
                            }
67
142
                            Label {
68
 
                                text: completed ? (success ? "Completed" : "Failed") : "Transferring..."
 
143
                                text: {
 
144
                                    switch (status) {
 
145
                                    case Transfer.StatusQueued:
 
146
                                        return "Waiting...";
 
147
                                    case Transfer.StatusActive:
 
148
                                        return "Transferring...";
 
149
                                    case Transfer.StatusSuspended:
 
150
                                        return "Paused"
 
151
                                    case Transfer.StatusComplete:
 
152
                                        return "Complete";
 
153
                                    case Transfer.StatusError:
 
154
                                        return "Failed";
 
155
                                    }
 
156
                                    return "Uunknown";
 
157
                                }
69
158
                            }
70
159
                        }
71
160
                    }
73
162
            }
74
163
        }
75
164
    }
 
165
 
 
166
    ContentItem {
 
167
        id: exportItem
 
168
        name: i18n.tr("Attachment")
 
169
    }
 
170
 
 
171
    Component {
 
172
        id: pickerPageComponent
 
173
 
 
174
        Page {
 
175
            id: pickerPage
 
176
            property alias contentType: picker.contentType
 
177
            property string filePath
 
178
 
 
179
            head {
 
180
                visible: false
 
181
                locked: true
 
182
            }
 
183
 
 
184
            ContentPeerPicker {
 
185
                id: picker
 
186
                anchors.fill: parent
 
187
                handler: ContentHandler.Destination
 
188
 
 
189
                onPeerSelected: {
 
190
                     var transfer = peer.request();
 
191
                     if (transfer.state === ContentTransfer.InProgress) {
 
192
                         var items = new Array()
 
193
                         var path = "file://" + pickerPage.filePath;
 
194
                         exportItem.url = path
 
195
                         items.push(exportItem);
 
196
                         transfer.items = items;
 
197
                         transfer.stateChanged.connect(function() {
 
198
                             if (transfer.state == ContentTransfer.Finalized && pageStack.depth > 1) {
 
199
                                 pageStack.pop();
 
200
                             }
 
201
                         })
 
202
                         transfer.state = ContentTransfer.Charged;
 
203
                     }
 
204
                 }
 
205
                 onCancelPressed: pageStack.pop();
 
206
            }
 
207
        }
 
208
    }
 
209
 
76
210
}
77
211