on bf4f7ea help sign in
unity8/Dash/Generic/GenericPreview.qml
196 lines 6.7 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: {
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 anchors { left: parent.left; right: parent.right }
124 visible: text != ""
125 fontSize: "small"
126 opacity: 0.6
127 color: "white"
128 text: previewData.description.replace(/[\r\n]/g, "<br />")
129 style: Text.Raised
130 styleColor: "black"
131 wrapMode: Text.WordWrap
132 textFormat: Text.RichText
133 // FIXME: workaround for https://bugreports.qt-project.org/browse/QTBUG-33020
134 onWidthChanged: { wrapMode = Text.NoWrap; wrapMode = Text.WordWrap }
135 }
137 Column {
138 objectName: "infoHintColumn"
139 anchors {
140 left: parent.left
141 right: parent.right
142 }
143 Repeater {
144 objectName: "infoHintRepeater"
145 model: previewData.infoHints
147 delegate: Item {
148 objectName: "infoHintItem" + index
149 width: parent.width
150 height: units.gu(5)
151 Row {
152 width: parent.width
153 spacing: units.gu(1)
154 property int columnWidth: (width - spacing) / 2
155 anchors.verticalCenter: parent.verticalCenter
157 Label {
158 objectName: "displayNameLabel"
159 visible: valueLabel.visible
160 fontSize: "small"
161 opacity: 0.9
162 color: "white"
163 horizontalAlignment: Text.AlignLeft
164 width: parent.columnWidth
165 text: modelData.displayName
166 style: Text.Raised
167 styleColor: "black"
168 }
169 Label {
170 id: valueLabel
171 objectName: "valueLabel"
172 visible: modelData.value != ""
173 fontSize: "small"
174 opacity: 0.6
175 color: "white"
176 horizontalAlignment: Text.AlignRight
177 width: parent.columnWidth
178 text: modelData.value ? modelData.value : ""
179 style: Text.Raised
180 styleColor: "black"
181 wrapMode: Text.WordWrap
182 }
183 }
184 ListItems.ThinDivider {
185 anchors {
186 left: parent.left
187 bottom: parent.bottom
188 right: parent.right
189 }
190 }
191 }
192 }
193 }
194 }
195 }