Debian Codegraph @

src/qml/player.qml

raw ◀ ▶
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 import GSettings 1.0
30
31 Item {
32 id: mediaPlayer
33 width: screenWidth
34 height: screenHeight
35
36 property string orientation: "0"
37 property string formFactor: "phone"
38 property real volume: playerLoader.item.volume
39 property bool appActive: Qt.application.active
40 property variant nativeOrientation: Screen.primaryOrientation
41
42 function pickAFile()
43 {
44 if (playerLoader.item.playing)
45 playerLoader.item.pause()
46 videoImport.requestMedia()
47 }
48
49 onAppActiveChanged: {
50 if (!appActive &&
•51 settings.usageMode != "Windowed" &&
52 playerLoader.item &&
53 playerLoader.item.playing) {
54 playerLoader.item.pause()
55 }
56 }
57
58 Screen.onOrientationChanged: {
59 // Rotate the UI when the device orientation changes
60 mediaPlayer.orientation = Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
61 }
62
63 Component {
64 id: dialogNoUrl
65
66 Popups.Dialog {
67 id: dialogue
68 objectName: "noMediaDialog"
69
70 title: i18n.tr("Error")
71 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.")
72
73 Button {
74 text: i18n.tr("Ok")
75 onClicked: Qt.quit()
76 }
77 }
78 }
79
80 Loader {
81 id: playerLoader
82
83 source: "player/VideoPlayer.qml"
84 focus: true
85 anchors.fill: parent
86 onLoaded: {
87 item.focus = true
88 item.rotating = Qt.binding(function () { return rotatingTransition.running } )
89 if (mpApplication.playUri.toString() !== "") {
90 lateUrlCheck.stop()
91 item.playUri(mpApplication.playUri)
92 }
93 }
94
95 state: mediaPlayer.orientation != "" ? mediaPlayer.orientation : (screenHeight <= screenWidth ? "0" : "270")
96 Component.onCompleted: {
97 state = Qt.binding(function () {
98 return mediaPlayer.orientation != "" ? mediaPlayer.orientation : (screenHeight <= screenWidth ? "0" : "270")
99 })
100 }
101
102 states: [
103 State {
104 name: "0"
105 PropertyChanges {
106 target: mediaPlayer
107 rotation: 0
108 width: screenWidth
109 height: screenHeight
110 x: 0
111 y: 0
112 }
113 },
114 State {
115 name: "180"
116 PropertyChanges {
117 target: mediaPlayer
118 rotation: 180
119 width: screenWidth
120 height: screenHeight
121 x: 0
122 y: 0
123 }
124 },
125 State {
126 name: "270"
127 PropertyChanges {
128 target: mediaPlayer
129 rotation: 270
130 width: screenHeight
131 height: screenWidth
132 x: (screenWidth - screenHeight) / 2
133 y: -(screenWidth - screenHeight) / 2
134 }
135 },
136 State {
137 name: "90"
138 PropertyChanges {
139 target: mediaPlayer
140 rotation: 90
141 width: screenHeight
142 height: screenWidth
143 x: (screenWidth - screenHeight) / 2
144 y: -(screenWidth - screenHeight) / 2
145 }
146 }
147 ]
148
149 transitions: [
150 Transition {
151 id: rotatingTransition
152 ParallelAnimation {
153 RotationAnimation {
154 properties: "rotation"
155 duration: 250
156 direction: RotationAnimation.Shortest
157 }
158 PropertyAnimation {
159 target: mediaPlayer
160 properties: "x,y,width,height"
161 duration: 250
162 }
163 }
164 }
165 ]
166 }
167
168 Connections {
169 target: playerLoader.item
170 onStatusChanged: {
171 if (playerLoader.item.status === MediaPlayer.EndOfMedia) {
172 playerLoader.item.stop()
173 playerLoader.item.controlsActive = true
174 }
175 }
176 onPlayEmptyFile: mediaPlayer.pickAFile()
177 }
178
179 LomiriAction.ActionManager {
180 actions: [
181 LomiriAction.Action {
182 text: i18n.tr("Play / Pause")
183 keywords: i18n.tr("Pause or Resume Playhead")
184 onTriggered: playerLoader.item.playPause()
185 },
186 LomiriAction.Action {
187 text: i18n.tr("Share")
188 keywords: i18n.tr("Post;Upload;Attach")
189 onTriggered: playerLoader.item.startSharing()
190 }
191 ]
192 }
193
194 function rotateClockwise() {
195 if (orientation == "") orientation = playerLoader.state
196 if (orientation == "0") orientation = "270"
197 else if (orientation == "270") orientation = "180"
198 else if (orientation == "180") orientation = "90"
199 else orientation = "0"
200 }
201
202 function rotateCounterClockwise() {
203 if (orientation == "") orientation = playerLoader.state
204 if (orientation == "0") orientation = "90"
205 else if (orientation == "90") orientation = "180"
206 else if (orientation == "180") orientation = "270"
207 else orientation = "0"
208 }
209
210 Keys.onReleased: {
211 if (!event.isAutoRepeat && event.key === Qt.Key_BracketLeft) {
212 event.accepted = true
213 rotateClockwise()
214 } else if (!event.isAutoRepeat && event.key === Qt.Key_BracketRight) {
215 event.accepted = true
216 rotateCounterClockwise()
217 }
218 }
219
220 Connections {
221 target: UriHandler
222 onOpened: {
223 for (var i = 0; i < uris.length; ++i) {
224 lateUrlCheck.stop()
225 if (uris[i].startsWith("video://")) {
226 playerLoader.item.playUri(uris[i].replace("video://", "file://"))
227 } else if (uris[i].startsWith("audio://")) {
228 playerLoader.item.playUri(uris[i].replace("audio://", "file://"))
229 }
230 }
231 }
232 }
233
234 Connections {
235 target: ContentHub
236 onImportRequested: {
237 lateUrlCheck.stop()
238 if (transfer.state === ContentTransfer.Charged) {
239 var urls = []
240 for(var i=0; i < transfer.items.length; i++) {
241 urls.push(transfer.items[i].url)
242 }
243
244 if (urls.length > 0) {
245 playerLoader.item.playUri(urls[0])
246 }
247 }
248 }
249 }
250
251 MediaImport {
252 id: videoImport
253
254 onMediaReceived: {
255 playerLoader.item.playUri(url)
256 }
257 }
258
259 Timer {
260 id: lateUrlCheck
261
262 interval: 1000
263 repeat: false
264 running: true
265 onTriggered: {
266 if (playerLoader.item && (playerLoader.item.source == "") && !ContentHub.hasPending) {
267 mediaPlayer.pickAFile()
268 }
269 }
270 }
•271
272 GSettings {
273 id: settings
274 schema.id: "com.lomiri.Shell"
275 }
276 }