on xenial help sign in
Fixed things in review, added test for NAN
658f97bAndrea Cimitan
qml/Dash/Previews/PreviewAudioPlayback.qml+22−22
@@ -34,7 +34,7 @@ import Ubuntu.Components 0.1
34
34
35PreviewWidget {
35PreviewWidget {
36 id: root
36 id: root
37− implicitHeight: childrenRect.height
37+ height: childrenRect.height
38
38
39 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
39 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
40
40
@@ -46,24 +46,24 @@ PreviewWidget {
46 property Item playingItem
46 property Item playingItem
47
47
48 Component.onDestruction: {
48 Component.onDestruction: {
49− // destructing the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
49+ // destroying the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
50 audio.stop();
50 audio.stop();
51 }
51 }
52
52
53 onErrorStringChanged: console.warn("Audio player error:", errorString)
53 onErrorStringChanged: console.warn("Audio player error:", errorString)
54
54
55 function lengthToString(s) {
55 function lengthToString(s) {
56− if (s <= 0 || s === undefined) return ""
56+ if (s <= 0 || typeof(s) !== "number") return "";
57
57
58− var sec = "" + s % 60
58+ var sec = "" + s % 60;
59− if (sec.length == 1) sec = "0" + sec
59+ if (sec.length == 1) sec = "0" + sec;
60− var hour = Math.floor(s / 3600)
60+ var hour = Math.floor(s / 3600);
61 if (hour < 1) {
61 if (hour < 1) {
62− return Math.floor(s / 60) + ":" + sec
62+ return Math.floor(s / 60) + ":" + sec;
63 } else {
63 } else {
64− var min = "" + Math.floor(s / 60) % 60
64+ var min = "" + Math.floor(s / 60) % 60;
65− if (min.length == 1) min = "0" + min
65+ if (min.length == 1) min = "0" + min;
66− return hour + ":" + min + ":" + sec
66+ return hour + ":" + min + ":" + sec;
67 }
67 }
68 }
68 }
69 }
69 }
@@ -77,6 +77,15 @@ PreviewWidget {
77 objectName: "trackRepeater"
77 objectName: "trackRepeater"
78 model: root.widgetData["tracks"]
78 model: root.widgetData["tracks"]
79
79
80+ function play(item, source) {
81+ audio.stop();
82+ // Make sure we change the source, even if two items point to the same uri location
83+ audio.source = "";
84+ audio.source = source;
85+ audio.playingItem = item;
86+ audio.play();
87+ }
88+
80 delegate: Item {
89 delegate: Item {
81 id: trackItem
90 id: trackItem
82 objectName: "trackItem" + index
91 objectName: "trackItem" + index
@@ -86,15 +95,6 @@ PreviewWidget {
86 anchors { left: parent.left; right: parent.right }
95 anchors { left: parent.left; right: parent.right }
87 height: units.gu(5)
96 height: units.gu(5)
88
97
89− function play() {
90− audio.stop();
91− // Make sure we change the source, even if two items point to the same uri location
92− audio.source = "";
93− audio.source = modelData["source"];
94− audio.playingItem = trackItem;
95− audio.play();
96− }
97−
98 Row {
98 Row {
99 id: trackRow
99 id: trackRow
100
100
@@ -120,11 +120,11 @@ PreviewWidget {
120 if (trackItem.isPlayingItem) {
120 if (trackItem.isPlayingItem) {
121 if (audio.playbackState == Audio.PlayingState) {
121 if (audio.playbackState == Audio.PlayingState) {
122 audio.pause();
122 audio.pause();
123− } else if (audio.playbackState == Audio.PausedState){
123+ } else if (audio.playbackState == Audio.PausedState) {
124 audio.play();
124 audio.play();
125 }
125 }
126 } else {
126 } else {
127− trackItem.play();
127+ trackRepeater.play(trackItem, modelData["source"]);
128 }
128 }
129 }
129 }
130 }
130 }
@@ -155,7 +155,7 @@ PreviewWidget {
155 color: Theme.palette.selected.backgroundText
155 color: Theme.palette.selected.backgroundText
156 fontSize: "small"
156 fontSize: "small"
157 horizontalAlignment: Text.AlignLeft
157 horizontalAlignment: Text.AlignLeft
158− text: modelData["subtitle"] !== undefined ? modelData["subtitle"] : ""
158+ text: (modelData["subtitle"] && modelData["subtitle"] !== undefined) ? modelData["subtitle"] : ""
159 elide: Text.ElideRight
159 elide: Text.ElideRight
160 }
160 }
161
161
qml/Dash/Previews/PreviewWidget.qml+2−2
@@ -19,9 +19,9 @@ import QtQuick 2.0
19/*! Interface for preview widgets. */
19/*! Interface for preview widgets. */
20
20
21Item {
21Item {
22− /// type:bool Specifies the preview widget being currently used or not
22+ //! Specifies the preview widget being currently used or not
23 property bool isCurrentPreview: true
23 property bool isCurrentPreview: true
24
24
25− /// Variable used to contain widget's data
25+ //! Variable used to contain widget's data
26 property var widgetData
26 property var widgetData
27}
27}
tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
@@ -57,6 +57,7 @@ Rectangle {
57
57
58 function test_time_formatter_data() {
58 function test_time_formatter_data() {
59 return [
59 return [
60+ { tag: "NaN", value: "not a number", result: "" },
60 { tag: "0", value: 0, result: "" },
61 { tag: "0", value: 0, result: "" },
61 { tag: "-1", value: -1, result: "" },
62 { tag: "-1", value: -1, result: "" },
62 { tag: "30", value: 30, result: "0:30" },
63 { tag: "30", value: 30, result: "0:30" },