on xenial help sign in
use a singleton to store some temp data across preview widgets
commit06823d687a73ec18779aafdad3daf35dcce8626c authorAndrea Cimitan <andrea.cimitan@gmail.com> dateFri 22 Jul 2016, 16:46 (10 years ago) parenta0eac07
3 files changed+68
qml/Dash/Previews/PreviewInlineVideo.qml+42 qml/Dash/Previews/PreviewSingleton/PreviewSingleton.qml+25 qml/Dash/Previews/PreviewSingleton/qmldir+1
qml/Dash/Previews/PreviewInlineVideo.qml+42
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtMultimedia 5.0
1919import Ubuntu.Components 1.3
2020import Ubuntu.Thumbnailer 0.1
21+import "PreviewSingleton"
2122import "../../Components"
2223import "../../Components/MediaServices"
2324
@@ -36,6 +37,23 @@ PreviewWidget {
3637 orientationLock: services.fullscreen
3738
3839 property alias rootItem: services.rootItem
40+ readonly property string widgetExtraDataKey: services.source.toString()
41+
42+ function seek() {
43+ services.mediaPlayer.seek(services.initialPosition);
44+ services.initialPosition = -1;
45+ }
46+
47+ function storePlaybackState() {
48+ PreviewSingleton.widgetExtraData[widgetExtraDataKey] = services.mediaPlayer.position;
49+ }
50+
51+
52+ function restorePlaybackState() {
53+ if (PreviewSingleton.widgetExtraData[widgetExtraDataKey] > 0) {
54+ services.initialPosition = PreviewSingleton.widgetExtraData[widgetExtraDataKey];
55+ }
56+ }
3957
4058 MediaServices {
4159 id: services
@@ -49,6 +67,30 @@ PreviewWidget {
4967
5068 onClose: fullscreen = false
5169
70+ readonly property var mediaPlayer: footer.mediaPlayer
71+ readonly property url source: mediaPlayer.source
72+ readonly property int position: mediaPlayer.position
73+
74+ onSourceChanged: {
75+ root.restorePlaybackState();
76+ }
77+
78+ onPositionChanged: {
79+ if (mediaPlayer.playbackState === MediaPlayer.StoppedState) return;
80+ root.storePlaybackState();
81+ }
82+
83+ property int initialPosition: -1
84+
85+ Connections {
86+ target: services.mediaPlayer
87+ ignoreUnknownSignals: true
88+ onPlaying: {
89+ // at the first playback of the file, do a seek()
90+ if (services.initialPosition > 0) root.seek();
91+ }
92+ }
93+
5294 Action {
5395 id: sharingAction
5496 iconName: "share"
qml/Dash/Previews/PreviewSingleton/PreviewSingleton.qmlnew file+25
@@ -0,0 +1,25 @@
1+/*
2+ * Copyright (C) 2016 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+pragma Singleton
18+import QtQuick 2.4
19+
20+QtObject {
21+ id: root
22+
23+ property string videoUrl
24+ property var widgetExtraData: { "foo" : "bar" }
25+}
qml/Dash/Previews/PreviewSingleton/qmldirnew file+1
@@ -0,0 +1 @@
1+singleton PreviewSingleton 1.0 PreviewSingleton.qml