on ff095ab help sign in
unity8/Dash/Generic/GenericPreview.qml
193 lines 6.6 kB history raw
1/*
2 * Copyright (C) 2013 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: previewData.execute(modelData.id, { })
75 }
76 }
77 }
78 }
80 Component {
81 id: progressComponent
83 ProgressBar {
84 id: progressBar
85 objectName: "progressBar"
86 value: 0
87 maximumValue: 100
88 height: units.gu(5)
90 property var model: previewData.actions
92 DownloadTracker {
93 service: "com.canonical.applications.Downloader"
94 dbusPath: previewData.infoMap["progressbar_source"] ? previewData.infoMap["progressbar_source"].value : ""
96 onProgress: {
97 var percentage = parseInt(received * 100 / total);
98 progressBar.value = percentage;
99 }
101 onFinished: {
102 previewData.execute(progressBar.model[0].id, { })
103 }
105 onError: {
106 previewData.execute(progressBar.model[1].id, { "error": error });
107 }
108 }
110 }
111 }
113 Component {
114 id: descriptionComponent
115 Column {
116 spacing: units.gu(2)
118 Label {
119 id: descriptionLabel
120 anchors { left: parent.left; right: parent.right }
121 visible: text != ""
122 fontSize: "small"
123 opacity: 0.6
124 color: "white"
125 text: previewData.description.replace(/[\r\n]/g, "<br />")
126 style: Text.Raised
127 styleColor: "black"
128 wrapMode: Text.WordWrap
129 textFormat: Text.RichText
130 // FIXME: workaround for https://bugreports.qt-project.org/browse/QTBUG-33020
131 onWidthChanged: { wrapMode = Text.NoWrap; wrapMode = Text.WordWrap }
132 }
134 Column {
135 objectName: "infoHintColumn"
136 anchors {
137 left: parent.left
138 right: parent.right
139 }
140 Repeater {
141 objectName: "infoHintRepeater"
142 model: previewData.infoHints
144 delegate: Item {
145 objectName: "infoHintItem" + index
146 width: parent.width
147 height: units.gu(5)
148 Row {
149 width: parent.width
150 spacing: units.gu(1)
151 property int columnWidth: (width - spacing) / 2
152 anchors.verticalCenter: parent.verticalCenter
154 Label {
155 objectName: "displayNameLabel"
156 visible: valueLabel.visible
157 fontSize: "small"
158 opacity: 0.9
159 color: "white"
160 horizontalAlignment: Text.AlignLeft
161 width: parent.columnWidth
162 text: modelData.displayName
163 style: Text.Raised
164 styleColor: "black"
165 }
166 Label {
167 id: valueLabel
168 objectName: "valueLabel"
169 visible: modelData.value != ""
170 fontSize: "small"
171 opacity: 0.6
172 color: "white"
173 horizontalAlignment: Text.AlignRight
174 width: parent.columnWidth
175 text: modelData.value ? modelData.value : ""
176 style: Text.Raised
177 styleColor: "black"
178 wrapMode: Text.WordWrap
179 }
180 }
181 ListItems.ThinDivider {
182 anchors {
183 left: parent.left
184 bottom: parent.bottom
185 right: parent.right
186 }
187 }
188 }
189 }
190 }
191 }
192 }