Debian Codegraph @

src/qml/player.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Ugo Riboni <[email protected]>
6 * MichaƂ Sawicz <[email protected]>
7 * Renato Araujo Oliveira Filho <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 import QtQuick 2.4
23 import QtQuick.Window 2.2
24 import QtMultimedia 5.0
25 import Lomiri.Action 1.1 as LomiriAction
26 import Lomiri.Components 1.3
27 import Lomiri.Components.Popups 1.3 as Popups
28 import Lomiri.Content 1.3
29
30 Item {
31 id: mediaPlayer
32 width: screenWidth
33 height: screenHeight
34
35 property string orientation: "0"
36 property string formFactor: "phone"
37 property real volume: playerLoader.item.volume
38 property bool appActive: Qt.application.active
39 property variant nativeOrientation: Screen.primaryOrientation
40
41 function pickAFile()
42 {
43 if (playerLoader.item.playing)
44 playerLoader.item.pause()
45 videoImport.requestMedia()
46 }
47
48 onAppActiveChanged: {
49 if (!appActive &&
50 !mpApplication.desktopMode &&
51 playerLoader.item &&
52 playerLoader.item.playing) {
53 playerLoader.item.pause()
54 }
55 }
56
57 Screen.onOrientationChanged: {
58 // Rotate the UI when the device orientation changes
59 mediaPlayer.orientation = Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
60 }
61
62 Component {
63 id: dialogNoUrl
64
65 Popups.Dialog {
66 id: dialogue
67 objectName: "noMediaDialog"
68
69 title: i18n.tr("Error")
70 text: i18n.tr("No video selected to play. Connect your phone to your computer to transfer videos to the phone. Then select video from Videos scope.")
71
72 Button {
73 text: i18n.tr("Ok")
74 onClicked: Qt.quit()
75 }
76 }
77 }
78
79 Loader {
80 id: playerLoader
81
82 source: "player/VideoPlayer.qml"
83 focus: true
84 anchors.fill: parent
85 onLoaded: {
86 item.focus = true
87 item.rotating = Qt.binding(function () { return rotatingTransition.running } )
88 if (mpApplication.playUri.toString() !== "") {
89 lateUrlCheck.stop()
90 item.playUri(mpApplication.playUri)
91 }
92 }
93
94 state: mediaPlayer.orientation != "" ? mediaPlayer.orientation : (screenHeight <= screenWidth ? "0" : "270")
95 Component.onCompleted: {
96 state = Qt.binding(function () {
97 return mediaPlayer.orientation != "" ? mediaPlayer.orientation : (screenHeight <= screenWidth ? "0" : "270")
98 })
99 }
100
101 states: [
102 State {
103 name: "0"
104 PropertyChanges {
105 target: mediaPlayer
106 rotation: 0
107 width: screenWidth
108 height: screenHeight
109 x: 0
110 y: 0
111 }
112 },
113 State {
114 name: "180"
115 PropertyChanges {
116 target: mediaPlayer
117 rotation: 180
118 width: screenWidth
119 height: screenHeight
120 x: 0
121 y: 0
122 }
123 },
124 State {
125 name: "270"
126 PropertyChanges {
127 target: mediaPlayer
128 rotation: 270
129 width: screenHeight
130 height: screenWidth
131 x: (screenWidth - screenHeight) / 2
132 y: -(screenWidth - screenHeight) / 2
133 }
134 },
135 State {
136 name: "90"
137 PropertyChanges {
138 target: mediaPlayer
139 rotation: 90
140 width: screenHeight
141 height: screenWidth
142 x: (screenWidth - screenHeight) / 2
143 y: -(screenWidth - screenHeight) / 2
144 }
145 }
146 ]
147
148 transitions: [
149 Transition {
150 id: rotatingTransition
151 ParallelAnimation {
152 RotationAnimation {
153 properties: "rotation"
154 duration: 250
155 direction: RotationAnimation.Shortest
156 }
157 PropertyAnimation {
158 target: mediaPlayer
159 properties: "x,y,width,height"
160 duration: 250
161 }
162 }
163 }
164 ]
165 }
166
167 Connections {
168 target: playerLoader.item
169 onStatusChanged: {
170 if (playerLoader.item.status === MediaPlayer.EndOfMedia) {
171 playerLoader.item.stop()
172 playerLoader.item.controlsActive = true
173 }
174 }
175 onPlayEmptyFile: mediaPlayer.pickAFile()
176 }
177
178 LomiriAction.ActionManager {
179 actions: [
180 LomiriAction.Action {
181 text: i18n.tr("Play / Pause")
182 keywords: i18n.tr("Pause or Resume Playhead")
183 onTriggered: playerLoader.item.playPause()
184 },
185 LomiriAction.Action {
186 text: i18n.tr("Share")
187 keywords: i18n.tr("Post;Upload;Attach")
188 onTriggered: playerLoader.item.startSharing()
189 }
190 ]
191 }
192
193 function rotateClockwise() {
194 if (orientation == "") orientation = playerLoader.state
195 if (orientation == "0") orientation = "270"
196 else if (orientation == "270") orientation = "180"
197 else if (orientation == "180") orientation = "90"
198 else orientation = "0"
199 }
200
201 function rotateCounterClockwise() {
202 if (orientation == "") orientation = playerLoader.state
203 if (orientation == "0") orientation = "90"
204 else if (orientation == "90") orientation = "180"
205 else if (orientation == "180") orientation = "270"
206 else orientation = "0"
207 }
208
209 Keys.onReleased: {
210 if (!event.isAutoRepeat && event.key === Qt.Key_BracketLeft) {
211 event.accepted = true
212 rotateClockwise()
213 } else if (!event.isAutoRepeat && event.key === Qt.Key_BracketRight) {
214 event.accepted = true
215 rotateCounterClockwise()
216 }
217 }
218
219 Connections {
220 target: UriHandler
221 onOpened: {
222 for (var i = 0; i < uris.length; ++i) {
223 lateUrlCheck.stop()
224 if (uris[i].startsWith("video://")) {
225 playerLoader.item.playUri(uris[i].replace("video://", "file://"))
226 } else if (uris[i].startsWith("audio://")) {
227 playerLoader.item.playUri(uris[i].replace("audio://", "file://"))
228 }
229 }
230 }
231 }
232
233 Connections {
234 target: ContentHub
235 onImportRequested: {
236 lateUrlCheck.stop()
237 if (transfer.state === ContentTransfer.Charged) {
238 var urls = []
239 for(var i=0; i < transfer.items.length; i++) {
240 urls.push(transfer.items[i].url)
241 }
242
243 if (urls.length > 0) {
244 playerLoader.item.playUri(urls[0])
245 }
246 }
247 }
248 }
249
250 MediaImport {
251 id: videoImport
252
253 onMediaReceived: {
254 playerLoader.item.playUri(url)
255 }
256 }
257
258 Timer {
259 id: lateUrlCheck
260
261 interval: 1000
262 repeat: false
263 running: true
264 onTriggered: {
265 if (playerLoader.item && (playerLoader.item.source == "") && !ContentHub.hasPending) {
266 mediaPlayer.pickAFile()
267 }
268 }
269 }
270 }