on fec22fa help sign in
unity8/Dash/Apps/AppPreview.qml
210 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 ListItem
20import Ubuntu.DownloadDaemonListener 0.1
21import ".."
22import "../../Components"
24DashPreview {
25 id: root
27 signal sendUserReview(string review)
29 title: root.previewData.title
31 header: ListView {
32 spacing: units.gu(1)
33 orientation: ListView.Horizontal
34 height: units.gu(22)
35 anchors {
36 left: parent.left
37 right: parent.right
38 margins: units.gu(1)
39 }
40 model: previewData.infoMap["more-screenshots"] != null ? previewData.infoMap["more-screenshots"].value : [previewData.image]
42 delegate: UbuntuShape {
43 id: shape
44 anchors {
45 top: parent.top
46 bottom: parent.bottom
47 }
48 width: units.gu(12)
49 radius: "medium"
50 borderSource: ""
51 image: Image {
52 asynchronous: true
53 sourceSize { width: shape.width; height: shape.height }
54 source: modelData ? modelData : ""
55 fillMode: Image.PreserveAspectCrop
56 }
57 }
58 }
60 Component {
61 id: buttonsComponent
63 GridView {
64 id: buttonsGrid
65 objectName: "gridButtons"
67 property int numOfRows: (count + 1) / 2
68 property int spacing: units.gu(1)
69 height: Math.max(units.gu(5), units.gu(5)*numOfRows + spacing*(numOfRows - 1))
71 interactive: false
72 cellWidth: Math.max(units.gu(9), width / 2)
73 cellHeight: buttonHeight + spacing
74 property int buttonWidth: count > 1 ? Math.max(0, width / 2 - spacing) : width
75 property int buttonHeight: units.gu(5)
77 delegate: Button {
78 width: Math.max(units.gu(4), buttonsGrid.buttonWidth)
79 height: buttonsGrid.buttonHeight
80 color: Theme.palette.selected.foreground
81 text: modelData.displayName
82 iconSource: modelData.iconHint
83 iconPosition: "right"
84 onClicked: root.previewData.execute(modelData.id, { })
85 }
86 }
87 }
89 Component {
90 id: progressComponent
92 ProgressBar {
93 id: progressBar
94 objectName: "progressBar"
95 value: 0
96 maximumValue: 100
97 height: units.gu(5)
99 property var model
101 DownloadTracker {
102 service: "com.canonical.applications.Downloader"
103 dbusPath: root.previewData.infoMap["progressbar_source"] ? root.previewData.infoMap["progressbar_source"].value : ""
105 onProgress: {
106 var percentage = parseInt(received * 100 / total);
107 progressBar.value = percentage;
108 }
110 onFinished: {
111 root.previewData.execute(progressBar.model[0].id, { })
112 }
114 onError: {
115 root.previewData.execute(progressBar.model[1].id, { "error": error });
116 }
117 }
119 }
120 }
122 buttons: Loader {
123 anchors {
124 left: parent.left
125 right: parent.right
126 }
128 sourceComponent: root.previewData.infoMap["show_progressbar"] ? progressComponent : buttonsComponent
130 onLoaded: {
131 item.model = root.previewData.actions;
132 }
133 }
135 body: Column {
136 spacing: units.gu(1)
138 AppInfo {
139 objectName: "appInfo"
140 anchors { left: parent.left; right: parent.right }
142 appName: root.previewData.title
143 icon: root.previewData.appIcon
144 rating: Math.round(root.previewData.rating * 10)
145 reviews: root.previewData.numRatings
146 rated: root.previewData.infoMap["rated"] ? root.previewData.infoMap["rated"].value : 0
147 }
149 Label {
150 anchors { left: parent.left; right: parent.right }
151 text: root.previewData.description
152 fontSize: "medium"
153 color: Theme.palette.selected.backgroundText
154 opacity: .6
155 wrapMode: Text.WordWrap
156 style: Text.Raised
157 styleColor: "black"
158 }
160 Column {
161 visible: root.previewData.rating >= 0
162 anchors { left: parent.left; right: parent.right }
163 spacing: parent.spacing
165 ListItem.ThinDivider { }
167 Item {
168 anchors { left: parent.left; right: parent.right }
169 height: rateLabel.height
171 Label {
172 id: rateLabel
173 fontSize: "medium"
174 color: "white"
175 style: Text.Raised
176 styleColor: "black"
177 opacity: .9
178 text: i18n.tr("Rate this")
180 anchors.left: parent.left
181 anchors.verticalCenter: parent.verticalCenter
182 }
184 // FIXME these need to be made interactive and connected to the scope
185 RatingStars {
186 anchors.right: parent.right
187 anchors.verticalCenter: parent.verticalCenter
188 }
189 }
191 ListItem.ThinDivider { }
193 AppReviews {
194 id: appReviews
195 objectName: "appReviews"
196 // TODO: This should make this visible when the feature for reviews/comments is complete.
197 visible: false
198 anchors { left: parent.left; right: parent.right }
200 model: root.previewData.infoMap["comments"] ? root.previewData.infoMap["comments"].value : undefined
202 onSendReview: root.sendUserReview(review);
204 onEditing: {
205 root.ensureVisible(appReviews.textArea);
206 }
207 }
208 }
209 }