on 2139c25 help sign in
unity8/Dash/Apps/AppPreview.qml
200 lines 6.3 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 ListItem
20import Ubuntu.DownloadDaemonListener 0.1
21import ".."
22import "../../Components"
23import "../../Components/IconUtil.js" as IconUtil
25DashPreview {
26 id: root
28 signal sendUserReview(string review)
30 title: root.previewData.title
32 header: ListView {
33 spacing: units.gu(1)
34 orientation: ListView.Horizontal
35 height: units.gu(22)
36 anchors {
37 left: parent.left
38 right: parent.right
39 margins: units.gu(1)
40 }
41 model: previewData.infoMap["more-screenshots"] != null ? previewData.infoMap["more-screenshots"].value : [previewData.image]
43 delegate: UbuntuShape {
44 id: shape
45 anchors {
46 top: parent.top
47 bottom: parent.bottom
48 }
49 width: units.gu(12)
50 radius: "medium"
51 borderSource: ""
52 image: Image {
53 asynchronous: true
54 sourceSize { width: shape.width; height: shape.height }
55 source: modelData ? modelData : ""
56 fillMode: Image.PreserveAspectCrop
57 }
58 }
59 }
61 Component {
62 id: buttonsComponent
64 GridView {
65 id: buttonsGrid
66 objectName: "gridButtons"
68 property int numOfRows: (count + 1) / 2
69 property int spacing: units.gu(1)
70 height: Math.max(units.gu(5), units.gu(5)*numOfRows + spacing*(numOfRows - 1))
72 interactive: false
73 cellWidth: Math.max(units.gu(9), width / 2)
74 cellHeight: buttonHeight + spacing
75 property int buttonWidth: count > 1 ? Math.max(0, width / 2 - spacing) : width
76 property int buttonHeight: units.gu(5)
78 delegate: Button {
79 width: Math.max(units.gu(4), buttonsGrid.buttonWidth)
80 height: buttonsGrid.buttonHeight
81 color: Theme.palette.selected.foreground
82 text: modelData.displayName
83 iconSource: modelData.iconHint
84 iconPosition: "right"
85 onClicked: root.previewData.execute(modelData.id, { })
86 }
87 }
88 }
90 Component {
91 id: progressComponent
93 ProgressBar {
94 id: progressBar
95 objectName: "progressBar"
96 value: 0
97 maximumValue: 100
98 height: units.gu(5)
100 property var model
102 DownloadTracker {
103 service: "com.canonical.applications.Downloader"
104 dbusPath: root.previewData.infoMap["progressbar_source"] ? root.previewData.infoMap["progressbar_source"].value : ""
106 onProgress: {
107 var percentage = parseInt(received * 100 / total);
108 progressBar.value = percentage;
109 }
111 onFinished: {
112 root.previewData.execute(progressBar.model[0].id, { })
113 }
114 }
116 }
117 }
119 buttons: Loader {
120 anchors {
121 left: parent.left
122 right: parent.right
123 }
125 sourceComponent: root.previewData.infoMap["show_progressbar"] ? progressComponent : buttonsComponent
127 onLoaded: {
128 item.model = root.previewData.actions;
129 }
130 }
132 body: Column {
133 spacing: units.gu(1)
135 AppInfo {
136 objectName: "appInfo"
137 anchors { left: parent.left; right: parent.right }
139 appName: root.previewData.title
140 icon: IconUtil.from_gicon(root.previewData.appIcon)
141 rating: Math.round(root.previewData.rating * 10)
142 reviews: root.previewData.numRatings
143 rated: root.previewData.infoMap["rated"] ? root.previewData.infoMap["rated"].value : 0
144 }
146 Label {
147 anchors { left: parent.left; right: parent.right }
148 text: root.previewData.description
149 fontSize: "medium"
150 color: Theme.palette.selected.backgroundText
151 opacity: .6
152 wrapMode: Text.WordWrap
153 style: Text.Raised
154 styleColor: "black"
155 }
157 Column {
158 visible: root.previewData.rating >= 0
159 anchors { left: parent.left; right: parent.right }
160 spacing: parent.spacing
162 ListItem.ThinDivider { }
164 Item {
165 anchors { left: parent.left; right: parent.right }
166 height: rateLabel.height
168 Label {
169 id: rateLabel
170 fontSize: "medium"
171 color: "white"
172 style: Text.Raised
173 styleColor: "black"
174 opacity: .9
175 text: i18n.tr("Rate this")
177 anchors.left: parent.left
178 anchors.verticalCenter: parent.verticalCenter
179 }
181 // FIXME these need to be made interactive and connected to the scope
182 RatingStars {
183 anchors.right: parent.right
184 anchors.verticalCenter: parent.verticalCenter
185 }
186 }
188 ListItem.ThinDivider { }
190 AppReviews {
191 objectName: "appReviews"
192 anchors { left: parent.left; right: parent.right }
194 model: root.previewData.infoMap["comments"] ? root.previewData.infoMap["comments"].value : undefined
196 onSendReview: root.sendUserReview(review);
197 }
198 }
199 }