on xenial help sign in
Adapt to api changes in the playlist implementation
commit6835e04e6533d90182b71b07d7716639aaee939c authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 1 Dec 2015, 15:02 (11 years ago) parenta051153
11 files changed+38−71
plugins/Dash/AudioProgressBar.qml+1−1 plugins/Dash/CardAudioProgress.qml+2−2 plugins/Dash/CardCreator.js+2−2 plugins/Dash/DashAudioPlayer.qml+3−13 qml/Dash/Previews/PreviewAudioPlayback.qml+1−1 tests/mocks/QtMultimedia/audio.cpp+1−26 tests/mocks/QtMultimedia/audio.h−5 tests/mocks/QtMultimedia/declarativeplaylist.cpp+12−5 tests/mocks/QtMultimedia/declarativeplaylist.h+6−6 tests/plugins/Dash/cardcreator/9.res+8−8 tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+2−2
plugins/Dash/AudioProgressBar.qml+1−1
@@ -24,7 +24,7 @@ Item {
2424 height: progressBarImage.height
2525
2626 property url source
27− readonly property double progress: DashAudioPlayer.isCurrentSource(source) ? DashAudioPlayer.progress : 0
27+ readonly property double progress: AudioUrlComparer.compare(source, DashAudioPlayer.currentSource) ? DashAudioPlayer.progress : 0
2828
2929 Image {
3030 id: progressBarImage
plugins/Dash/CardAudioProgress.qml+2−2
@@ -22,12 +22,12 @@ Item {
2222 id: root
2323
2424 implicitHeight: positionLabel.y + positionLabel.height
25− visible: DashAudioPlayer.isCurrentSource(source)
25+ visible: AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)
2626
2727 property int duration: 0
2828 property url source
2929 property color color: theme.palette.normal.baseText
30− readonly property int position: DashAudioPlayer.isCurrentSource(source) ? DashAudioPlayer.position / 1000 : 0
30+ readonly property int position: root.visible ? DashAudioPlayer.position / 1000 : 0
3131
3232 AudioProgressBar {
3333 id: progress
plugins/Dash/CardCreator.js+2−2
@@ -147,10 +147,10 @@ var kAudioButtonCode = 'AbstractButton { \n\
147147 anchors.fill: parent; \n\
148148 anchors.margins: parent.height > units.gu(5) ? units.gu(2) : units.gu(0); \n\
149149 opacity: 0.9; \n\
150− name: DashAudioPlayer.isCurrentSource(parent.source) && DashAudioPlayer.playing ? "media-playback-pause" : "media-playback-start"; \n\
150+ name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start"; \n\
151151 } \n\
152152 onClicked: { \n\
153− if (DashAudioPlayer.isCurrentSource(source)) { \n\
153+ if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) { \n\
154154 if (DashAudioPlayer.playing) { \n\
155155 DashAudioPlayer.pause(); \n\
156156 } else { \n\
plugins/Dash/DashAudioPlayer.qml+3−13
@@ -25,17 +25,7 @@ QtObject {
2525 readonly property bool paused: audio.playbackState === Audio.PausedState
2626 readonly property bool stopped: audio.playbackState === Audio.StoppedState
2727 readonly property alias position: audio.position
28−
29− function isCurrentSource(source) {
30− if (source != "") {
31− if (audio.playlist) {
32− return AudioUrlComparer.compare(source, audio.playlist.currentSource);
33− } else {
34− return AudioUrlComparer.compare(source, audio.source);
35− }
36− }
37− return false;
38− }
28+ readonly property url currentSource: audio.playlist.currentItemSource
3929
4030 function playSource(newSource, newPlaylist) {
4131 stop();
@@ -58,10 +48,10 @@ QtObject {
5848 for (var i in newPlaylist) {
5949 urls.push(newPlaylist[i]);
6050 }
61− audio.playlist.addSources(urls);
51+ audio.playlist.addItems(urls);
6252 audio.playlist.currentIndex = sourceIndex;
6353 } else {
64− audio.playlist.addSource(newSource);
54+ audio.playlist.addItem(newSource);
6555 audio.playlist.currentIndex = 0;
6656 }
6757 play();
qml/Dash/Previews/PreviewAudioPlayback.qml+1−1
@@ -50,7 +50,7 @@ PreviewWidget {
5050 objectName: "trackItem" + index
5151
5252 readonly property url sourceUrl: modelData["source"]
53− readonly property bool isPlayingItem: DashAudioPlayer.isCurrentSource(sourceUrl)
53+ readonly property bool isPlayingItem: AudioUrlComparer.compare(sourceUrl, DashAudioPlayer.currentSource)
5454
5555 anchors { left: parent.left; right: parent.right }
5656 height: units.gu(5)
tests/mocks/QtMultimedia/audio.cpp+1−26
@@ -34,29 +34,6 @@ Audio::Audio(QObject* parent):
3434 Q_EMIT durationChanged(m_duration);
3535}
3636
37−QUrl Audio::source() const
38−{
39− return m_source;
40−}
41−
42−void Audio::setSource(const QUrl &source)
43−{
44− if (source == m_source && m_playlist == NULL)
45− return;
46−
47− m_playlist = NULL;
48− Q_EMIT playlistChanged();
49−
50− m_source = source;
51− Q_EMIT sourceChanged(source);
52−
53− m_position = 0;
54− Q_EMIT positionChanged(m_position);
55−
56− m_duration = (qrand() % 20000) + 10000;
57− Q_EMIT durationChanged(m_duration);
58−}
59−
6037Audio::PlaybackState Audio::playbackState() const
6138{
6239 return m_playbackState;
@@ -134,11 +111,9 @@ DeclarativePlaylist *Audio::playlist() const
134111
135112void Audio::setPlaylist(DeclarativePlaylist *playlist)
136113{
137− if (playlist == m_playlist && m_source.isEmpty())
114+ if (playlist == m_playlist)
138115 return;
139116
140− m_source.clear();
141− Q_EMIT sourceChanged(m_source);
142117 m_playlist = playlist;
143118 Q_EMIT playlistChanged();
144119}
tests/mocks/QtMultimedia/audio.h−5
@@ -29,7 +29,6 @@ class Audio: public QObject
2929 Q_OBJECT
3030 Q_ENUMS(PlaybackState)
3131 Q_ENUMS(AudioRole)
32− Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
3332 Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
3433 Q_PROPERTY(int position READ position NOTIFY positionChanged)
3534 Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
@@ -52,9 +51,6 @@ public:
5251
5352 explicit Audio(QObject *parent = 0);
5453
55− QUrl source() const;
56− void setSource(const QUrl &source);
57−
5854 DeclarativePlaylist *playlist() const;
5955 void setPlaylist(DeclarativePlaylist *playlist);
6056
@@ -86,7 +82,6 @@ private Q_SLOTS:
8682 void timerEvent();
8783
8884private:
89− QUrl m_source;
9085 PlaybackState m_playbackState;
9186 QTimer m_timer;
9287 int m_position;
tests/mocks/QtMultimedia/declarativeplaylist.cpp+12−5
@@ -23,9 +23,9 @@ DeclarativePlaylist::DeclarativePlaylist(QObject *parent)
2323{
2424}
2525
26−QUrl DeclarativePlaylist::currentSource() const
26+QUrl DeclarativePlaylist::currentItemSource() const
2727{
28− return source(currentIndex());
28+ return itemSource(currentIndex());
2929}
3030
3131int DeclarativePlaylist::currentIndex() const
@@ -40,27 +40,34 @@ void DeclarativePlaylist::setCurrentIndex(int index)
4040
4141 m_currentIndex = index;
4242 Q_EMIT currentIndexChanged();
43+ Q_EMIT currentItemSourceChanged();
4344}
4445
45−QUrl DeclarativePlaylist::source(int index) const
46+QUrl DeclarativePlaylist::itemSource(int index) const
4647{
48+ if (index < 0 || index >= m_medias.count())
49+ return QUrl();
4750 return m_medias[index];
4851}
4952
50−bool DeclarativePlaylist::addSource(const QUrl &source)
53+bool DeclarativePlaylist::addItem(const QUrl &source)
5154{
5255 m_medias << source;
56+ setCurrentIndex(0);
5357 return true;
5458}
5559
56−bool DeclarativePlaylist::addSources(const QList<QUrl> &sources)
60+bool DeclarativePlaylist::addItems(const QList<QUrl> &sources)
5761{
5862 m_medias << sources;
63+ if (!sources.isEmpty())
64+ setCurrentIndex(0);
5965 return true;
6066}
6167
6268bool DeclarativePlaylist::clear()
6369{
6470 m_medias.clear();
71+ setCurrentIndex(-1);
6572 return true;
6673}
tests/mocks/QtMultimedia/declarativeplaylist.h+6−6
@@ -24,24 +24,24 @@
2424class DeclarativePlaylist : public QObject
2525{
2626 Q_OBJECT
27− Q_PROPERTY(QUrl currentSource READ currentSource NOTIFY currentSourceChanged)
27+ Q_PROPERTY(QUrl currentItemSource READ currentItemSource NOTIFY currentItemSourceChanged)
2828 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
2929
3030public:
3131 DeclarativePlaylist(QObject *parent = 0);
3232
33− QUrl currentSource() const;
33+ QUrl currentItemSource() const;
3434 int currentIndex() const;
3535 void setCurrentIndex(int currentIndex);
3636
3737public Q_SLOTS:
38− QUrl source(int index) const;
39− bool addSource(const QUrl &source);
40− bool addSources(const QList<QUrl> &sources);
38+ QUrl itemSource(int index) const;
39+ bool addItem(const QUrl &source);
40+ bool addItems(const QList<QUrl> &sources);
4141 bool clear();
4242
4343Q_SIGNALS:
44− void currentSourceChanged();
44+ void currentItemSourceChanged();
4545 void currentIndexChanged();
4646
4747private:
tests/plugins/Dash/cardcreator/9.res+8−8
@@ -2,7 +2,7 @@ AbstractButton {
22 id: root;
33 property var components;
44 property var cardData;
5− property var artShapeBorderSource: undefined;
5+ property string artShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
88 property int titleAlignment: Text.AlignLeft;
@@ -31,7 +31,7 @@ top: parent.top;
3131 wrapMode: Text.Wrap;
3232 maximumLineCount: 2;
3333 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
34− color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
34+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
3535 visible: showHeader ;
3636 width: undefined;
3737 text: root.title;
@@ -52,7 +52,7 @@ top: titleLabel.bottom;
5252 maximumLineCount: 1;
5353 fontSize: "x-small";
5454 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
55− color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
55+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
5656 visible: titleLabel.visible && titleLabel.text;
5757 text: cardData && cardData["subtitle"] || "";
5858 font.weight: Font.Light;
@@ -74,7 +74,7 @@ CardAudioProgress {
7474 width: height;
7575 height: (root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1);
7676 readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || "";
77− UbuntuShape {
77+ UbuntuShape {
7878 anchors.fill: parent;
7979 visible: parent.pressed;
8080 radius: "medium";
@@ -84,17 +84,17 @@ CardAudioProgress {
8484 anchors.fill: parent;
8585 anchors.margins: parent.height > units.gu(5) ? units.gu(2) : units.gu(0);
8686 opacity: 0.9;
87− name: DashAudioPlayer.isCurrentSource(parent.source) && DashAudioPlayer.playing ? "media-playback-pause" : "media-playback-start";
87+ name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start";
8888 }
8989 onClicked: {
90− if (DashAudioPlayer.isCurrentSource(source)) {
90+ if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) {
9191 if (DashAudioPlayer.playing) {
9292 DashAudioPlayer.pause();
9393 } else {
9494 DashAudioPlayer.play();
9595 }
9696 } else {
97− var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null;
97+ var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null;
9898 DashAudioPlayer.playSource(source, playlist);
9999 }
100100 }
@@ -105,7 +105,7 @@ CardAudioProgress {
105105 id: touchdown;
106106 objectName: "touchdown";
107107 anchors { fill: root }
108− visible: root.pressed;
108+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
109109 radius: "medium";
110110 borderSource: "radius_pressed.sci"
111111 }
tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+2−2
@@ -102,7 +102,7 @@ Rectangle {
102102
103103 function checkPlayerSource(index) {
104104 var modelFilename = previewAudioPlayback.widgetData["tracks"][index]["source"].replace(/^.*[\\\/]/, '');
105− var playerFilename = DashAudioPlayer.d.source.toString().replace(/^.*[\\\/]/, '');
105+ var playerFilename = DashAudioPlayer.currentSource.toString().replace(/^.*[\\\/]/, '');
106106
107107 compare(modelFilename, playerFilename, "Player source is not set correctly.");
108108 }
@@ -123,7 +123,7 @@ Rectangle {
123123 var track1PlayButton = findChild(track1Item, "playButton");
124124 var track2PlayButton = findChild(track2Item, "playButton");
125125
126− var audio = DashAudioPlayer.d;
126+ var audio = DashAudioPlayer.audio;
127127
128128 // All progress bars must be hidden in the beginning
129129 compare(track0ProgressBar.visible, false);