on ac4b821 help sign in
unity8/qml/Dash/Generic/GenericPreview.qml
197 lines 6.8 kB history raw
1/*
2 * Copyright (C) 2013, 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Ubuntu.Components.ListItems 0.1 as ListItems
20import Ubuntu.DownloadDaemonListener 0.1
21import "../../Components"
22import ".."
23import "../Previews"
25DashPreview {
26 id: genericPreview
28 previewImages: previewImagesComponent
29 header: headerComponent
30 actions: (previewData.infoMap !== undefined && previewData.infoMap["show_progressbar"]) ? progressComponent : actionsComponent
31 description: descriptionComponent
33 Component {
34 id: previewImagesComponent
36 LazyImage {
37 objectName: "genericPreviewImage"
38 anchors {
39 left: parent.left
40 right: parent.right
41 }
42 scaleTo: "width"
43 source: genericPreview.previewData.image
44 initialHeight: width
45 }
46 }
48 Component {
49 id: headerComponent
50 Header {
51 title: previewData.title
52 subtitle: previewData.subtitle
53 }
54 }
56 Component {
57 id: actionsComponent
59 Column {
60 id: buttonList
61 spacing: units.gu(1)
62 Repeater {
63 objectName: "buttonList"
64 model: previewData.actions
66 delegate: Button {
67 objectName: "button" + index
68 width: parent.width
69 height: buttonList.buttonHeight
70 color: Theme.palette.selected.foreground
71 text: modelData.displayName
72 iconSource: modelData.iconHint
73 iconPosition: "right"
74 onClicked: {
75 previewData.execute(modelData.id, { })
76 genericPreview.showProcessingAction = true;
77 }
78 }
79 }
80 }
81 }
83 Component {
84 id: progressComponent
86 ProgressBar {
87 id: progressBar
88 objectName: "progressBar"
89 value: 0
90 maximumValue: 100
91 height: units.gu(5)
93 property var model: previewData.actions
95 DownloadTracker {
96 service: "com.canonical.applications.Downloader"
97 dbusPath: previewData.infoMap["progressbar_source"] ? previewData.infoMap["progressbar_source"].value : ""
99 onProgress: {
100 var percentage = parseInt(received * 100 / total);
101 progressBar.value = percentage;
102 }
104 onFinished: {
105 previewData.execute(progressBar.model[0].id, { })
106 }
108 onError: {
109 previewData.execute(progressBar.model[1].id, { "error": error });
110 }
111 }
113 }
114 }
116 Component {
117 id: descriptionComponent
118 Column {
119 spacing: units.gu(2)
121 Label {
122 id: descriptionLabel
123 objectName: "descriptionLabel"
124 anchors { left: parent.left; right: parent.right }
125 visible: text != ""
126 fontSize: "small"
127 opacity: 0.6
128 color: "white"
129 text: previewData.description.replace(/[\r\n]/g, "<br />")
130 style: Text.Raised
131 styleColor: "black"
132 wrapMode: Text.WordWrap
133 textFormat: Text.RichText
134 // FIXME: workaround for https://bugreports.qt-project.org/browse/QTBUG-33020
135 onWidthChanged: { wrapMode = Text.NoWrap; wrapMode = Text.WordWrap }
136 }
138 Column {
139 objectName: "infoHintColumn"
140 anchors {
141 left: parent.left
142 right: parent.right
143 }
144 Repeater {
145 objectName: "infoHintRepeater"
146 model: previewData.infoHints
148 delegate: Item {
149 objectName: "infoHintItem" + index
150 width: parent.width
151 height: units.gu(5)
152 Row {
153 width: parent.width
154 spacing: units.gu(1)
155 property int columnWidth: (width - spacing) / 2
156 anchors.verticalCenter: parent.verticalCenter
158 Label {
159 objectName: "displayNameLabel"
160 visible: valueLabel.visible
161 fontSize: "small"
162 opacity: 0.9
163 color: "white"
164 horizontalAlignment: Text.AlignLeft
165 width: parent.columnWidth
166 text: modelData.displayName
167 style: Text.Raised
168 styleColor: "black"
169 }
170 Label {
171 id: valueLabel
172 objectName: "valueLabel"
173 visible: modelData.value != ""
174 fontSize: "small"
175 opacity: 0.6
176 color: "white"
177 horizontalAlignment: Text.AlignRight
178 width: parent.columnWidth
179 text: modelData.value ? modelData.value : ""
180 style: Text.Raised
181 styleColor: "black"
182 wrapMode: Text.WordWrap
183 }
184 }
185 ListItems.ThinDivider {
186 anchors {
187 left: parent.left
188 bottom: parent.bottom
189 right: parent.right
190 }
191 }
192 }
193 }
194 }
195 }
196 }