on xenial help sign in
add Movie preview.
bf461a2Ying-Chun Liu
Dash/Movie/MoviePreview.qmlnew file+163
@@ -0,0 +1,163 @@
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+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Components 0.1
19+import ".."
20+import "../../Components"
21+
22+DashPreview {
23+ id: root
24+
25+ property bool ready: previewData ? true : false
26+ property bool playable: false
27+ property url url: ready ? previewData.image : ""
28+
29+ title: root.ready ? previewData.title : ""
30+ previewWidthRatio: 0.6
31+
32+ onPreviewImageClicked: {
33+ if (playable) {
34+ shell.activateApplication('/usr/share/applications/mediaplayer-app.desktop', root.fileUri);
35+ }
36+ }
37+
38+ // TODO: replace this UbuntuShape with the Video component once that lands
39+ // with the player.
40+ header: UbuntuShape {
41+ id: urlLoader
42+ anchors.left: parent.left
43+ anchors.right: parent.right
44+ radius: "medium"
45+ image: Image {
46+ id: previewImage
47+ asynchronous: true
48+ source: root.url
49+ fillMode: Image.PreserveAspectCrop
50+ }
51+
52+ Image {
53+ objectName: "playButton"
54+ anchors.centerIn: parent
55+ visible: root.playable
56+ readonly property bool bigButton: parent.width > units.gu(40)
57+ width: bigButton ? units.gu(8) : units.gu(4.5)
58+ height: width
59+ source: "../graphics/play_button%1%2.png".arg(previewImageMouseArea.pressed ? "_active" : "").arg(bigButton ? "_big" : "")
60+ }
61+
62+ MouseArea {
63+ id: previewImageMouseArea
64+ anchors.fill: parent
65+ onClicked: root.previewImageClicked()
66+ }
67+ }
68+
69+ buttons: GridView {
70+ id: buttons
71+ objectName: "gridButtons"
72+ model: root.previewData.actions
73+
74+ property int numOfRows: (count + 1) / 2
75+ property int spacing: units.gu(1)
76+ height: Math.max(units.gu(4), units.gu(4)*numOfRows + spacing*(numOfRows - 1))
77+
78+ cellWidth: Math.max(units.gu(9), width / 2)
79+ cellHeight: buttonHeight + spacing
80+ property int buttonWidth: Math.max(0, width / 2 - spacing)
81+ property int buttonHeight: units.gu(4)
82+
83+ delegate: Button {
84+ width: Math.max(units.gu(4), buttons.buttonWidth)
85+ height: buttons.buttonHeight
86+ color: "#dd4814"
87+ text: modelData.displayName
88+ iconSource: modelData.iconHint
89+ iconPosition: "right"
90+ visible: true
91+ onClicked: {
92+ root.previewData.execute(modelData.id, { })
93+ }
94+ }
95+ focus: false
96+ }
97+
98+ body: Column {
99+ spacing: units.gu(2)
100+ RatingStars {
101+ maximumRating: 10 // FIXME: this should happen on the backend side
102+ rating: ready ? previewData.rating: 0
103+ }
104+
105+ Label {
106+ text: ready ? previewData.description : ""
107+ color: Theme.palette.selected.backgroundText
108+ opacity: .6
109+ fontSize: "medium"
110+ width: parent.width
111+ wrapMode: Text.WordWrap
112+ style: Text.Raised
113+ styleColor: "black"
114+ }
115+
116+ Grid {
117+ columns: 2
118+ spacing: units.gu(1)
119+ width: parent.width
120+ property int firstColWidth: units.gu(9)
121+ property int secondColWidth: width - firstColWidth - spacing
122+ Label {
123+ visible: directedLabel.visible
124+ fontSize: "small"
125+ opacity: 0.9
126+ color: "white"
127+ horizontalAlignment: Text.AlignRight
128+ width: parent.firstColWidth
129+ text: i18n.tr("Directed by:")
130+ style: Text.Raised
131+ styleColor: "black"
132+ }
133+ Label {
134+ id: directedLabel
135+ visible: text != ""
136+ fontSize: "small"
137+ opacity: 0.6
138+ color: "white"
139+ width: parent.secondColWidth
140+ text: ready ? previewData.subtitle : ""
141+ style: Text.Raised
142+ styleColor: "black"
143+ wrapMode: Text.WordWrap
144+ }
145+ }
146+
147+ Label {
148+ fontSize: "small"
149+ opacity: 0.6
150+ color: "white"
151+ text: {
152+ var parts = []
153+ if (ready) {
154+ if (previewData.year) parts.push(previewData.year)
155+ //if (nfo.video.runtime) parts.push("%1 minutes".arg(nfo.video.runtime))
156+ }
157+ return parts.join(", ");
158+ }
159+ style: Text.Raised
160+ styleColor: "black"
161+ }
162+ }
163+}
Dash/PreviewDelegateMapper.qml+1
@@ -22,6 +22,7 @@ QtObject {
22 readonly property string appPreview: "Apps/AppPreview.qml"
22 readonly property string appPreview: "Apps/AppPreview.qml"
23 property var previewDelegateMapping: {"preview-generic": genericPreview,
23 property var previewDelegateMapping: {"preview-generic": genericPreview,
24 "preview-application": appPreview,
24 "preview-application": appPreview,
25+ "preview-movie": "Movie/MoviePreview.qml",
25 }
26 }
26 }
27 }
27
28
tests/qmltests/CMakeLists.txt+1
@@ -52,6 +52,7 @@ add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMA
52add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
52add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
53add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
53add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
54add_qml_test(Dash/Video VideoPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
54add_qml_test(Dash/Video VideoPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55+add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
56add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
56 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
57 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
57add_qml_test(Greeter Tablet IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
58add_qml_test(Greeter Tablet IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
tests/qmltests/Dash/Movie/tst_MoviePreview.qmlnew file+95
@@ -0,0 +1,95 @@
1+/*
2+ * Copyright 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+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import "../../../../Dash/Movie"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ id: root
24+ width: units.gu(60)
25+ height: units.gu(80)
26+
27+ property var calls
28+
29+ function get_actions() {
30+ var a1 = new Object();
31+ a1.id = 123;
32+ a1.displayName = "Play";
33+ a1.iconHint = "image://gicon/gtk-yes";
34+ var a2 = new Object();
35+ a2.id = 456;
36+ a2.displayName = "Buy";
37+ a2.iconHint = "image://gicon/gtk-yes";
38+ var a3 = new Object();
39+ a3.id = 789;
40+ a3.displayName = "Delete";
41+ a3.iconHint = "image://gicon/gtk-yes";
42+
43+ return [a1, a2, a3];
44+ }
45+
46+ function get_data() {
47+ var objData = new Object();
48+ objData.rendererName = "preview-movie";
49+ objData.title = "Unity Movie";
50+ objData.subtitle = "Subtitle";
51+ objData.description = "This is the description";
52+ objData.image = "image://gicon/gtk-stop";
53+ objData.actions = get_actions();
54+ objData.year = "2013"
55+ objData.rating = 3
56+ objData.numRatings = 1
57+ objData.execute = prueba;
58+
59+ return objData;
60+ }
61+
62+ function prueba(id, data){
63+ root.calls[root.calls.length] = id;
64+ }
65+
66+ // The component under test
67+ MoviePreview {
68+ id: moviePreview
69+ anchors.fill: parent
70+
71+ previewData: get_data()
72+ }
73+
74+ UT.UnityTestCase {
75+ name: "MoviePreviewTest"
76+ when: windowShown
77+
78+ function test_actions() {
79+ root.calls = new Array();
80+ var buttons = findChild(moviePreview, "gridButtons");
81+ wait(10000);
82+ compare(buttons.count, 3);
83+
84+ for(var i = 0; i < buttons.count; i++) {
85+ buttons.currentIndex = i;
86+ buttons.currentItem.clicked();
87+ }
88+
89+ var actions = get_actions();
90+ for(var i = 0; i < actions.length; i++) {
91+ compare(root.calls[i], actions[i].id);
92+ }
93+ }
94+ }
95+}