on bbe4a36 help sign in
unity8/Dash/Video/VideoPreview.qml
210 lines 6.9 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 ".."
20import "../../Components"
22DashPreview {
23 id: root
25 property var item
26 property alias ready: nfo.ready
27 property bool playable: fileUri != ""
28 readonly property url fileUri: item ? item.fileUri : ""
29 property url url: item ? item.nfoUri.replace(/\.nfo$/, "-fanart.jpg") : ""
31 VideoInfo {
32 id: nfo
33 source: item ? item.nfoUri : ""
34 }
36 title: nfo.ready ? nfo.video.title : ""
37 previewWidthRatio: 0.6
39 onPreviewImageClicked: {
40 if (playable) {
41 shell.activateApplication('/usr/share/applications/mediaplayer-app.desktop', root.fileUri);
42 }
43 }
45 // TODO: replace this UbuntuShape with the Video component once that lands
46 // with the player.
47 header: UbuntuShape {
48 id: urlLoader
49 anchors.left: parent.left
50 anchors.right: parent.right
51 height: width * previewImage.sourceSize.height / previewImage.sourceSize.width
52 radius: "medium"
53 image: Image {
54 id: previewImage
55 asynchronous: true
56 source: root.url
57 fillMode: Image.PreserveAspectCrop
58 }
60 Image {
61 objectName: "playButton"
62 anchors.centerIn: parent
63 visible: root.playable
64 readonly property bool bigButton: parent.width > units.gu(40)
65 width: bigButton ? units.gu(8) : units.gu(4.5)
66 height: width
67 source: "../graphics/play_button%1%2.png".arg(previewImageMouseArea.pressed ? "_active" : "").arg(bigButton ? "_big" : "")
68 }
70 MouseArea {
71 id: previewImageMouseArea
72 anchors.fill: parent
73 onClicked: root.previewImageClicked()
74 }
75 }
77 buttons: Row {
78 spacing: units.gu(2)
80 property int buttonWidth: Math.min(units.gu(22), (width - spacing) / 2)
81 Button {
82 width: parent.buttonWidth
83 color: Theme.palette.selected.foreground
84 text: nfo.ready && nfo.video.buyPrice != "" ? "Buy for " + nfo.video.buyPrice : ""
85 visible: text != ""
86 iconSource: "graphics/icon_button_amazon.png"
87 iconPosition: "right"
88 }
89 Button {
90 width: parent.buttonWidth
91 color: Theme.palette.selected.foreground
92 text: nfo.ready && nfo.video.buyPrice != "" ? "Rent for " + nfo.video.rentPrice : ""
93 visible: text != ""
94 iconSource: "graphics/icon_button_u1.png"
95 iconPosition: "right"
96 }
97 }
99 body: Column {
100 spacing: units.gu(2)
101 RatingStars {
102 maximumRating: 10 // FIXME: this should happen on the backend side
103 rating: nfo.ready ? nfo.video.rating: 0
104 }
106 Label {
107 text: nfo.ready ? nfo.video.plot : ""
108 color: Theme.palette.selected.backgroundText
109 opacity: .6
110 fontSize: "medium"
111 width: parent.width
112 wrapMode: Text.WordWrap
113 style: Text.Raised
114 styleColor: "black"
115 }
117 Grid {
118 columns: 2
119 spacing: units.gu(1)
120 width: parent.width
121 property int firstColWidth: units.gu(9)
122 property int secondColWidth: width - firstColWidth - spacing
123 Label {
124 visible: directedLabel.visible
125 fontSize: "small"
126 opacity: 0.9
127 color: "white"
128 horizontalAlignment: Text.AlignRight
129 width: parent.firstColWidth
130 text: i18n.tr("Directed by:")
131 style: Text.Raised
132 styleColor: "black"
133 }
134 Label {
135 id: directedLabel
136 visible: text != ""
137 fontSize: "small"
138 opacity: 0.6
139 color: "white"
140 width: parent.secondColWidth
141 text: nfo.ready ? nfo.video.director : ""
142 style: Text.Raised
143 styleColor: "black"
144 wrapMode: Text.WordWrap
145 }
146 Label {
147 visible: starringLabel.visible
148 fontSize: "small"
149 opacity: 0.9
150 horizontalAlignment: Text.AlignRight
151 color: "white"
152 width: parent.firstColWidth
153 text: i18n.tr("Starring:")
154 style: Text.Raised
155 styleColor: "black"
156 }
157 Label {
158 id: starringLabel
159 visible: text != ""
160 fontSize: "small"
161 opacity: 0.6
162 color: "white"
163 width: parent.secondColWidth
164 text: nfo.ready ? nfo.getActors().join(", ") : ""
165 wrapMode: Text.WordWrap
166 style: Text.Raised
167 styleColor: "black"
168 }
169 Label {
170 visible: authorLabel.visible
171 fontSize: "small"
172 opacity: 0.9
173 horizontalAlignment: Text.AlignRight
174 color: "white"
175 width: parent.firstColWidth
176 text: i18n.tr("Author:")
177 style: Text.Raised
178 styleColor: "black"
179 }
180 Label {
181 id: authorLabel
182 visible: text != ""
183 fontSize: "small"
184 opacity: 0.6
185 color: "white"
186 width: parent.secondColWidth
187 text: nfo.ready ? nfo.video.author : ""
188 wrapMode: Text.WordWrap
189 style: Text.Raised
190 styleColor: "black"
191 }
192 }
194 Label {
195 fontSize: "small"
196 opacity: 0.6
197 color: "white"
198 text: {
199 var parts = []
200 if (nfo.ready) {
201 if (nfo.video.year) parts.push(nfo.video.year)
202 if (nfo.video.runtime) parts.push("%1 minutes".arg(nfo.video.runtime))
203 }
204 return parts.join(", ");
205 }
206 style: Text.Raised
207 styleColor: "black"
208 }
209 }