~osomon/webbrowser-app/private-downloads

« back to all changes in this revision

Viewing changes to src/app/webbrowser/DownloadDelegate.qml

  • Committer: Olivier Tilloy
  • Date: 2016-10-06 07:46:05 UTC
  • Revision ID: olivier.tilloy@canonical.com-20161006074605-x1urds39z0t3utgk
Use a SlotsLayout for the DownloadDelegate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
    property var downloadManager
27
27
 
28
 
    property alias icon: mimeicon.name
 
28
    property string icon
29
29
    property alias image: thumbimage.source
30
30
    property alias title: title.text
31
31
    property alias url: url.text
33
33
    property bool incomplete: false
34
34
    property string downloadId
35
35
    property var download
36
 
    property int progress: download ? download.progress : 0
 
36
    readonly property int progress: download ? download.progress : 0
37
37
    property bool paused
38
38
    property alias incognito: incognitoIcon.visible
39
39
 
42
42
    signal removed()
43
43
    signal cancelled()
44
44
 
45
 
    height: visible ? (incomplete ? (paused ? units.gu(13) : units.gu(10)) : units.gu(7)) : 0
 
45
    height: visible ? layout.height : 0
46
46
 
47
47
    QtObject {
48
48
        id: internal
61
61
    Component.onCompleted: internal.connectToDownloadObject()
62
62
    onDownloadManagerChanged: internal.connectToDownloadObject()
63
63
 
64
 
    Item {
65
 
        
66
 
        anchors {
67
 
            verticalCenter: parent.verticalCenter
68
 
            left: parent.left
69
 
            leftMargin: units.gu(2)
70
 
            right: parent.right
71
 
            rightMargin: units.gu(2)
72
 
        }
 
64
    SlotsLayout {
 
65
        id: layout
73
66
 
74
67
        Item {
75
 
            id: iconContainer
 
68
            SlotsLayout.position: SlotsLayout.Leading
76
69
            width: units.gu(3)
77
 
            height: width
78
 
            anchors.verticalCenter: parent.verticalCenter
79
 
            anchors.verticalCenterOffset: downloadDelegate.incomplete ? -units.gu(1) : 0
 
70
            height: units.gu(3)
80
71
 
81
72
            Image {
82
73
                id: thumbimage
83
74
                asynchronous: true
84
 
                width: parent.width
85
 
                height: parent.height
 
75
                anchors.fill: parent
86
76
                fillMode: Image.PreserveAspectFit
87
 
                sourceSize.width: parent.width
88
 
                sourceSize.height: parent.height
89
 
                anchors.verticalCenter: parent.verticalCenter
 
77
                sourceSize.width: width
 
78
                sourceSize.height: height
90
79
            }
91
80
 
92
81
            Image {
93
 
                id: mimeicon
94
82
                asynchronous: true
95
83
                anchors.fill: parent
96
84
                anchors.margins: units.gu(0.2)
97
 
                source: "image://theme/%1".arg(name != "" ? name : "save")
 
85
                source: "image://theme/%1".arg(downloadDelegate.icon || "save")
98
86
                visible: thumbimage.status !== Image.Ready
99
87
                cache: true
100
 
                property string name
101
 
            }
102
 
        }
103
 
 
104
 
        Item {
105
 
            anchors.top: iconContainer.top
106
 
            anchors.left: iconContainer.right
107
 
            anchors.leftMargin: units.gu(2)
108
 
            anchors.right: parent.right
109
 
 
110
 
            Column {
111
 
                id: detailsColumn
112
 
                width: parent.width - cancelColumn.width
113
 
                height: parent.height
114
 
 
115
 
                Label {
116
 
                    id: title
117
 
                    fontSize: "x-small"
118
 
                    color: "#5d5d5d"
119
 
                    elide: Text.ElideRight
120
 
                    width: parent.width
121
 
                }
122
 
 
123
 
                Label {
124
 
                    id: url
125
 
                    fontSize: "x-small"
126
 
                    color: "#5d5d5d"
127
 
                    elide: Text.ElideRight
128
 
                    width: parent.width
129
 
                }
130
 
 
131
 
                Item {
132
 
                    height: error.visible ? units.gu(1) : units.gu(2)
133
 
                    width: parent.width
134
 
                    visible: downloadDelegate.incomplete
135
 
                }
136
 
 
137
 
                Item {
138
 
                    id: error
139
 
                    visible: incomplete && download === undefined || errorMessage !== ""
140
 
                    height: units.gu(3)
141
 
                    width: parent.width
142
 
 
143
 
                    Icon {
144
 
                        id: errorIcon
145
 
                        width: units.gu(2)
146
 
                        height: width
147
 
                        anchors.verticalCenter: parent.verticalCenter
148
 
                        name: "dialog-warning-symbolic"
149
 
                        color: theme.palette.normal.negative
150
 
                    }
151
 
 
152
 
                    Label {
153
 
                        width: parent.width - errorIcon.width
154
 
                        anchors.left: errorIcon.right
155
 
                        anchors.leftMargin: units.gu(1)
156
 
                        anchors.verticalCenter: errorIcon.verticalCenter
157
 
                        fontSize: "x-small"
158
 
                        color: theme.palette.normal.negative
159
 
                        text: errorMessage !== "" ? errorMessage 
160
 
                                                  : (incomplete && download === undefined) ? i18n.tr("Download failed") 
161
 
                                                                                           : ""
162
 
                        elide: Text.ElideRight
163
 
                    }
164
 
                }
165
 
 
166
 
                IndeterminateProgressBar {
167
 
                    id: progressBar
168
 
                    width: parent.width
169
 
                    height: units.gu(0.5)
170
 
                    visible: downloadDelegate.incomplete && !error.visible
171
 
                    progress: downloadDelegate.progress
172
 
                    // Work around UDM bug #1450144
173
 
                    indeterminateProgress: downloadDelegate.progress < 0 || downloadDelegate.progress > 100
174
 
                }
175
 
            }
176
 
 
177
 
            Column {
178
 
                id: cancelColumn
179
 
                spacing: units.gu(1)
180
 
                anchors.top: detailsColumn.top
181
 
                anchors.left: detailsColumn.right
182
 
                anchors.leftMargin: units.gu(2)
183
 
                width: downloadDelegate.incomplete && !error.visible ? cancelButton.width + units.gu(2) : 0
184
 
 
185
 
                Button {
186
 
                    visible: downloadDelegate.incomplete && !error.visible
187
 
                    id: cancelButton
188
 
                    text: i18n.tr("Cancel")
189
 
                    onClicked: {
190
 
                        if (download) {
191
 
                            download.cancel()
192
 
                            cancelled()
193
 
                        }
194
 
                    }
195
 
                }
196
 
 
197
 
                Label {
198
 
                    visible: !progressBar.indeterminateProgress && downloadDelegate.incomplete
199
 
                                                                && !error.visible 
200
 
                                                                && !downloadDelegate.paused
201
 
                    width: cancelButton.width
202
 
                    horizontalAlignment: Text.AlignHCenter
203
 
                    fontSize: "x-small"
204
 
                    text: progressBar.progress + "%"
205
 
                }
206
 
 
207
 
                Button {
208
 
                    visible: downloadDelegate.paused
209
 
                    text: i18n.tr("Resume")
210
 
                    width: cancelButton.width
211
 
                    onClicked: {
212
 
                        if (download) {
213
 
                            download.resume()
214
 
                        }
215
 
                    }
216
 
                }
217
 
            }
218
 
 
 
88
            }
 
89
        }
 
90
 
 
91
        mainSlot: Column {
 
92
            Label {
 
93
                id: title
 
94
                fontSize: "x-small"
 
95
                color: "#5d5d5d"
 
96
                elide: Text.ElideRight
 
97
                anchors {
 
98
                    left: parent.left
 
99
                    right: parent.right
 
100
                }
 
101
            }
 
102
 
 
103
            Label {
 
104
                id: url
 
105
                fontSize: "x-small"
 
106
                color: "#5d5d5d"
 
107
                elide: Text.ElideRight
 
108
                anchors {
 
109
                    left: parent.left
 
110
                    right: parent.right
 
111
                }
 
112
            }
 
113
 
 
114
            Item {
 
115
                height: error.visible ? units.gu(1) : units.gu(2)
 
116
                anchors {
 
117
                    left: parent.left
 
118
                    right: parent.right
 
119
                }
 
120
                visible: incomplete
 
121
            }
 
122
 
 
123
            Item {
 
124
                id: error
 
125
                visible: (incomplete && (download === undefined)) || errorMessage
 
126
                height: units.gu(3)
 
127
                anchors {
 
128
                    left: parent.left
 
129
                    right: parent.right
 
130
                }
 
131
 
 
132
                Icon {
 
133
                    id: errorIcon
 
134
                    width: units.gu(2)
 
135
                    height: units.gu(2)
 
136
                    anchors.verticalCenter: parent.verticalCenter
 
137
                    name: "dialog-warning-symbolic"
 
138
                    color: theme.palette.normal.negative
 
139
                }
 
140
 
 
141
                Label {
 
142
                    anchors {
 
143
                        left: errorIcon.right
 
144
                        leftMargin: units.gu(1)
 
145
                        right: parent.right
 
146
                        verticalCenter: parent.verticalCenter
 
147
                    }
 
148
                    fontSize: "x-small"
 
149
                    color: theme.palette.normal.negative
 
150
                    text: errorMessage ||
 
151
                          ((incomplete && download === undefined) ? i18n.tr("Download failed") : "")
 
152
                    elide: Text.ElideRight
 
153
                }
 
154
            }
 
155
 
 
156
            IndeterminateProgressBar {
 
157
                id: progressBar
 
158
                anchors {
 
159
                    left: parent.left
 
160
                    right: parent.right
 
161
                }
 
162
                height: units.gu(0.5)
 
163
                visible: incomplete && !error.visible
 
164
                progress: downloadDelegate.progress
 
165
                // Work around UDM bug #1450144
 
166
                indeterminateProgress: progress < 0 || progress > 100
 
167
            }
 
168
        }
 
169
 
 
170
        Column {
 
171
            SlotsLayout.position: SlotsLayout.Trailing
 
172
            spacing: units.gu(1)
 
173
            width: (incomplete && !error.visible) ? cancelButton.width : 0
 
174
 
 
175
            Button {
 
176
                id: cancelButton
 
177
                visible: incomplete && !error.visible
 
178
                text: i18n.tr("Cancel")
 
179
                onClicked: {
 
180
                    if (download) {
 
181
                        download.cancel()
 
182
                        cancelled()
 
183
                    }
 
184
                }
 
185
            }
 
186
 
 
187
            Label {
 
188
                visible: !progressBar.indeterminateProgress && incomplete
 
189
                            && !error.visible && !paused
 
190
                width: cancelButton.width
 
191
                horizontalAlignment: Text.AlignHCenter
 
192
                fontSize: "x-small"
 
193
                // TRANSLATORS: %1 is the percentage of the download completed so far
 
194
                text: i18n.tr("%1%").arg(progressBar.progress)
 
195
            }
 
196
 
 
197
            Button {
 
198
                visible: paused
 
199
                text: i18n.tr("Resume")
 
200
                width: cancelButton.width
 
201
                onClicked: {
 
202
                    if (download) {
 
203
                        download.resume()
 
204
                    }
 
205
                }
 
206
            }
219
207
        }
220
208
    }
221
209
 
233
221
        name: "private-browsing"
234
222
    }
235
223
 
236
 
    leadingActions: error.visible || !downloadDelegate.incomplete ? deleteActionList : null
 
224
    leadingActions: error.visible || !incomplete ? deleteActionList : null
237
225
 
238
226
    ListItemActions {
239
227
        id: deleteActionList
241
229
            Action {
242
230
                objectName: "leadingAction.delete"
243
231
                iconName: "delete"
244
 
                enabled: error.visible || !downloadDelegate.incomplete
245
 
                onTriggered: error.visible ? downloadDelegate.cancelled() 
246
 
                                           : downloadDelegate.removed()
 
232
                enabled: error.visible || !incomplete
 
233
                onTriggered: error.visible ? cancelled() : removed()
247
234
            }
248
235
        ]
249
236
    }