summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-10-08 18:26:39 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-11 14:53:16 +0000
commit82e135167a5d24f600f006480b78a59511ae5cb3 (patch)
tree0e27d0b2520e42d4b7bfb1db32dd5446df49502f
parent94c33684fe3ba3c08af91d5d465c35f5dc706721 (diff)
Change the way a playlist is bound to a media object.v5.6.0-beta1
The previous behavior was to simply switch from the internal control to the service's control, discarding anything that was added to the playlist before binding. We now carry over the changes made to the playlist when switching controls. This means the switch is now transparent to the user. When the service's control is read-only, we cannot transfer the items, which means the user must be notified of the items that might have been "lost" during the switch. Auto-test modified to reflect this change. Change-Id: Ibf80b650b06425ddbaeb320b72ac5d3082a25960 Reviewed-by: Jim Hodapp <jim.hodapp@canonical.com> Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
-rw-r--r--src/multimedia/playback/qmediaplaylist.cpp72
-rw-r--r--src/multimedia/playback/qmediaplaylist_p.h4
-rw-r--r--tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp304
-rw-r--r--tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h46
-rw-r--r--tests/auto/unit/qmultimedia_common/mockplaylistservice.h2
-rw-r--r--tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h1
6 files changed, 391 insertions, 38 deletions
diff --git a/src/multimedia/playback/qmediaplaylist.cpp b/src/multimedia/playback/qmediaplaylist.cpp
index 06813592..c6334063 100644
--- a/src/multimedia/playback/qmediaplaylist.cpp
+++ b/src/multimedia/playback/qmediaplaylist.cpp
@@ -168,10 +168,13 @@ bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
newControl = d->networkPlaylistControl;
if (d->control != newControl) {
- int oldSize = 0;
+ int removedStart = -1;
+ int removedEnd = -1;
+ int insertedStart = -1;
+ int insertedEnd = -1;
+
if (d->control) {
QMediaPlaylistProvider *playlist = d->control->playlistProvider();
- oldSize = playlist->mediaCount();
disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString)));
@@ -190,6 +193,12 @@ bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
this, SIGNAL(currentMediaChanged(QMediaContent)));
+ // Copy playlist items, sync playback mode and sync current index between
+ // old control and new control
+ d->syncControls(d->control, newControl,
+ &removedStart, &removedEnd,
+ &insertedStart, &insertedEnd);
+
if (d->mediaObject)
d->mediaObject->service()->releaseControl(d->control);
}
@@ -214,14 +223,14 @@ bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
connect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
this, SIGNAL(currentMediaChanged(QMediaContent)));
- if (oldSize) {
- emit mediaAboutToBeRemoved(0, oldSize-1);
- emit mediaRemoved(0, oldSize-1);
+ if (removedStart != -1 && removedEnd != -1) {
+ emit mediaAboutToBeRemoved(removedStart, removedEnd);
+ emit mediaRemoved(removedStart, removedEnd);
}
- if (playlist->mediaCount()) {
- emit mediaAboutToBeInserted(0,playlist->mediaCount()-1);
- emit mediaInserted(0,playlist->mediaCount()-1);
+ if (insertedStart != -1 && insertedEnd != -1) {
+ emit mediaAboutToBeInserted(insertedStart, insertedEnd);
+ emit mediaInserted(insertedStart, insertedEnd);
}
}
@@ -436,6 +445,53 @@ bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer)
}
/*!
+ * \internal
+ * Copy playlist items, sync playback mode and sync current index between old control and new control
+*/
+void QMediaPlaylistPrivate::syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl,
+ int *removedStart, int *removedEnd,
+ int *insertedStart, int *insertedEnd)
+{
+ Q_ASSERT(oldControl != NULL && newControl != NULL);
+ Q_ASSERT(removedStart != NULL && removedEnd != NULL
+ && insertedStart != NULL && insertedEnd != NULL);
+
+ QMediaPlaylistProvider *oldPlaylist = oldControl->playlistProvider();
+ QMediaPlaylistProvider *newPlaylist = newControl->playlistProvider();
+
+ Q_ASSERT(oldPlaylist != NULL && newPlaylist != NULL);
+
+ *removedStart = -1;
+ *removedEnd = -1;
+ *insertedStart = -1;
+ *insertedEnd = -1;
+
+ if (newPlaylist->isReadOnly()) {
+ // we can't transfer the items from the old control.
+ // Report these items as removed.
+ if (oldPlaylist->mediaCount() > 0) {
+ *removedStart = 0;
+ *removedEnd = oldPlaylist->mediaCount() - 1;
+ }
+ // The new control might have some items that can't be cleared.
+ // Report these as inserted.
+ if (newPlaylist->mediaCount() > 0) {
+ *insertedStart = 0;
+ *insertedEnd = newPlaylist->mediaCount() - 1;
+ }
+ } else {
+ const int oldPlaylistSize = oldPlaylist->mediaCount();
+
+ newPlaylist->clear();
+ for (int i = 0; i < oldPlaylistSize; ++i)
+ newPlaylist->addMedia(oldPlaylist->media(i));
+ }
+
+ newControl->setPlaybackMode(oldControl->playbackMode());
+ newControl->setCurrentIndex(oldControl->currentIndex());
+}
+
+/*!
Load playlist using network \a request. If \a format is specified, it is used,
otherwise format is guessed from playlist name and data.
diff --git a/src/multimedia/playback/qmediaplaylist_p.h b/src/multimedia/playback/qmediaplaylist_p.h
index 25571378..1440362d 100644
--- a/src/multimedia/playback/qmediaplaylist_p.h
+++ b/src/multimedia/playback/qmediaplaylist_p.h
@@ -108,6 +108,10 @@ public:
bool readItems(QMediaPlaylistReader *reader);
bool writeItems(QMediaPlaylistWriter *writer);
+ void syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl,
+ int *removedStart, int *removedEnd,
+ int *insertedStart, int *insertedEnd);
+
QMediaPlaylist::Error error;
QString errorString;
diff --git a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp
index daecda82..104046d0 100644
--- a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp
+++ b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp
@@ -51,14 +51,16 @@
QT_USE_NAMESPACE
-class MockReadOnlyPlaylistObject : public QMediaObject
+class MockPlaylistObject : public QMediaObject
{
Q_OBJECT
public:
- MockReadOnlyPlaylistObject(QObject *parent = 0)
- :QMediaObject(parent, new MockPlaylistService)
+ MockPlaylistObject(QObject *parent = 0)
+ : QMediaObject(parent, mockService = new MockPlaylistService)
{
}
+
+ MockPlaylistService *mockService;
};
class tst_QMediaPlaylist : public QObject
@@ -711,7 +713,9 @@ void tst_QMediaPlaylist::shuffle()
void tst_QMediaPlaylist::readOnlyPlaylist()
{
- MockReadOnlyPlaylistObject mediaObject;
+ MockPlaylistObject mediaObject;
+ mediaObject.mockService->mockControl->setReadOnly(true);
+
QMediaPlaylist playlist;
mediaObject.bind(&playlist);
@@ -777,26 +781,280 @@ void tst_QMediaPlaylist::readOnlyPlaylist()
void tst_QMediaPlaylist::setMediaObject()
{
- MockReadOnlyPlaylistObject mediaObject;
-
- QMediaPlaylist playlist;
- QVERIFY(playlist.mediaObject() == 0);
- QVERIFY(!playlist.isReadOnly());
-
- mediaObject.bind(&playlist);
- QCOMPARE(playlist.mediaObject(), qobject_cast<QMediaObject*>(&mediaObject));
- QCOMPARE(playlist.mediaCount(), 3);
- QVERIFY(playlist.isReadOnly());
-
- mediaObject.unbind(&playlist);
- QVERIFY(playlist.mediaObject() == 0);
- QCOMPARE(playlist.mediaCount(), 0);
- QVERIFY(!playlist.isReadOnly());
+ QMediaContent content0(QUrl(QLatin1String("test://audio/song1.mp3")));
+ QMediaContent content1(QUrl(QLatin1String("test://audio/song2.mp3")));
+ QMediaContent content2(QUrl(QLatin1String("test://video/movie1.mp4")));
+ QMediaContent content3(QUrl(QLatin1String("test://video/movie2.mp4")));
- mediaObject.bind(&playlist);
- QCOMPARE(playlist.mediaObject(), qobject_cast<QMediaObject*>(&mediaObject));
- QCOMPARE(playlist.mediaCount(), 3);
- QVERIFY(playlist.isReadOnly());
+ {
+ MockPlaylistObject mediaObject;
+
+ QMediaPlaylist playlist;
+ QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int)));
+ QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
+ QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int)));
+ QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int)));
+ QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int)));
+ QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int)));
+ QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int)));
+
+ QVERIFY(playlist.isEmpty());
+
+ mediaObject.bind(&playlist);
+
+ // Playlist is now using the service's control, nothing should have changed
+ QVERIFY(playlist.isEmpty());
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Sequential);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+
+ // add items to service's playlist control
+ playlist.addMedia(content0);
+ playlist.addMedia(content1);
+ playlist.setCurrentIndex(1);
+ playlist.setPlaybackMode(QMediaPlaylist::Random);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.currentIndex(), 1);
+ QCOMPARE(playlist.currentMedia(), content1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random);
+
+ currentIndexSpy.clear();
+ playbackModeSpy.clear();
+ mediaAboutToBeInsertedSpy.clear();
+ mediaInsertedSpy.clear();
+ mediaAboutToBeRemovedSpy.clear();
+ mediaRemovedSpy.clear();
+ mediaChangedSpy.clear();
+
+ // unbind the playlist, reverting back to the internal control.
+ // playlist content should't have changed.
+ mediaObject.unbind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.currentIndex(), 1);
+ QCOMPARE(playlist.currentMedia(), content1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+ }
+ {
+ MockPlaylistObject mediaObject;
+
+ QMediaPlaylist playlist;
+ QVERIFY(playlist.isEmpty());
+ // Add items to playlist before binding to the service (internal control)
+ playlist.addMedia(content0);
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+ playlist.setCurrentIndex(2);
+ playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
+
+ QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int)));
+ QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
+ QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int)));
+ QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int)));
+ QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int)));
+ QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int)));
+ QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int)));
+
+ // Bind playlist, content should be unchanged
+ mediaObject.bind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 3);
+ QCOMPARE(playlist.currentIndex(), 2);
+ QCOMPARE(playlist.currentMedia(), content2);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+
+ // Clear playlist content (service's playlist control)
+ playlist.clear();
+ playlist.setCurrentIndex(-1);
+ playlist.setPlaybackMode(QMediaPlaylist::Random);
+
+ currentIndexSpy.clear();
+ playbackModeSpy.clear();
+ mediaAboutToBeInsertedSpy.clear();
+ mediaInsertedSpy.clear();
+ mediaAboutToBeRemovedSpy.clear();
+ mediaRemovedSpy.clear();
+ mediaChangedSpy.clear();
+
+ // unbind playlist from service, reverting back to the internal control.
+ // playlist should still be empty
+ mediaObject.unbind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 0);
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.currentMedia(), QMediaContent());
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+ }
+ {
+ MockPlaylistObject mediaObject;
+
+ QMediaPlaylist playlist;
+ QVERIFY(playlist.isEmpty());
+ // Add items to playlist before attaching to media player (internal control)
+ playlist.addMedia(content0);
+ playlist.addMedia(content1);
+ playlist.setCurrentIndex(-1);
+ playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
+
+ // Add items to service's playlist before binding
+ QMediaPlaylistProvider *pp = mediaObject.mockService->mockControl->playlistProvider();
+ pp->addMedia(content2);
+ pp->addMedia(content3);
+ mediaObject.mockService->mockControl->setCurrentIndex(1);
+ mediaObject.mockService->mockControl->setPlaybackMode(QMediaPlaylist::Random);
+
+ QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int)));
+ QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
+ QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int)));
+ QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int)));
+ QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int)));
+ QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int)));
+ QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int)));
+
+ // Bind playlist, it should contain only what was explicitly added to the playlist.
+ // Anything that was present in the service's control should have been cleared
+ mediaObject.bind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+
+ // do some changes
+ playlist.removeMedia(0); // content0
+ playlist.addMedia(content3);
+ playlist.setCurrentIndex(0);
+
+ currentIndexSpy.clear();
+ playbackModeSpy.clear();
+ mediaAboutToBeInsertedSpy.clear();
+ mediaInsertedSpy.clear();
+ mediaAboutToBeRemovedSpy.clear();
+ mediaRemovedSpy.clear();
+ mediaChangedSpy.clear();
+
+ // unbind playlist from service
+ mediaObject.unbind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.currentIndex(), 0);
+ QCOMPARE(playlist.currentMedia(), content1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+
+ // bind again, nothing should have changed
+ mediaObject.bind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.currentIndex(), 0);
+ QCOMPARE(playlist.currentMedia(), content1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+ }
+ {
+ MockPlaylistObject mediaObject;
+ mediaObject.mockService->mockControl->setReadOnly(true);
+
+ QMediaPlaylist playlist;
+ QVERIFY(playlist.isEmpty());
+ // Add items to playlist before binding to the service internal control)
+ playlist.addMedia(content0);
+ playlist.addMedia(content1);
+ playlist.setCurrentIndex(-1);
+ playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
+
+ QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int)));
+ QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
+ QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int)));
+ QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int)));
+ QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int)));
+ QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int)));
+ QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int)));
+
+ // Bind playlist. Since the service's control is read-only, no synchronization
+ // should be done with the internal control. The mediaRemoved() and mediaInserted()
+ // should be emitted to notify about the change.
+ mediaObject.bind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 3);
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 1);
+ QCOMPARE(mediaAboutToBeRemovedSpy.last().at(0).toInt(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.last().at(1).toInt(), 1);
+ QCOMPARE(mediaRemovedSpy.count(), 1);
+ QCOMPARE(mediaRemovedSpy.last().at(0).toInt(), 0);
+ QCOMPARE(mediaRemovedSpy.last().at(1).toInt(), 1);
+
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 1);
+ QCOMPARE(mediaAboutToBeInsertedSpy.last().at(0).toInt(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.last().at(1).toInt(), 2);
+ QCOMPARE(mediaInsertedSpy.count(), 1);
+ QCOMPARE(mediaInsertedSpy.last().at(0).toInt(), 0);
+ QCOMPARE(mediaInsertedSpy.last().at(1).toInt(), 2);
+
+ QCOMPARE(mediaChangedSpy.count(), 0);
+
+ currentIndexSpy.clear();
+ playbackModeSpy.clear();
+ mediaAboutToBeInsertedSpy.clear();
+ mediaInsertedSpy.clear();
+ mediaAboutToBeRemovedSpy.clear();
+ mediaRemovedSpy.clear();
+ mediaChangedSpy.clear();
+
+ // detach playlist from player
+ mediaObject.unbind(&playlist);
+ QCOMPARE(playlist.mediaCount(), 3);
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(currentIndexSpy.count(), 0);
+ QCOMPARE(playbackModeSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0);
+ QCOMPARE(mediaInsertedSpy.count(), 0);
+ QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0);
+ QCOMPARE(mediaRemovedSpy.count(), 0);
+ QCOMPARE(mediaChangedSpy.count(), 0);
+ }
}
void tst_QMediaPlaylist::testCurrentIndexChanged_signal()
diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h
index 6620aa76..9f4eabf3 100644
--- a/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h
+++ b/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h
@@ -36,24 +36,52 @@
#include <private/qmediaplaylistcontrol_p.h>
#include <private/qmediaplaylistnavigator_p.h>
+#include <private/qmedianetworkplaylistprovider_p.h>
#include "mockreadonlyplaylistprovider.h"
-// Hmm, read only.
class MockMediaPlaylistControl : public QMediaPlaylistControl
{
- Q_OBJECT
public:
- MockMediaPlaylistControl(QObject *parent) : QMediaPlaylistControl(parent)
+ MockMediaPlaylistControl(bool readonly = false, QObject *parent = 0)
+ : QMediaPlaylistControl(parent)
+ , m_navigator(0)
+ , m_playlist(0)
+ , m_ownsProvider(false)
+ , m_readOnly(readonly)
{
- m_navigator = new QMediaPlaylistNavigator(new MockReadOnlyPlaylistProvider(this), this);
+ reset();
}
~MockMediaPlaylistControl()
{
}
- QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); }
+ void reset()
+ {
+ delete m_navigator;
+ if (m_ownsProvider)
+ delete m_playlist;
+
+ if (m_readOnly)
+ m_playlist = new MockReadOnlyPlaylistProvider(this);
+ else
+ m_playlist = new QMediaNetworkPlaylistProvider(this);
+
+ m_ownsProvider = true;
+ m_navigator = new QMediaPlaylistNavigator(m_playlist, this);
+ }
+
+ void setReadOnly(bool ro)
+ {
+ if (m_readOnly == ro)
+ return;
+
+ m_readOnly = ro;
+ reset();
+ }
+
+ QMediaPlaylistProvider* playlistProvider() const { return m_playlist; }
bool setPlaylistProvider(QMediaPlaylistProvider *newProvider)
{
bool bMediaContentChanged = false;
@@ -70,6 +98,11 @@ public:
emit currentMediaChanged(newProvider->media(i));
}
+ if (m_ownsProvider)
+ delete m_playlist;
+ m_playlist = newProvider;
+ m_ownsProvider = false;
+
m_navigator->setPlaylist(newProvider);
return true;
}
@@ -99,6 +132,9 @@ public:
private:
QMediaPlaylistNavigator *m_navigator;
+ QMediaPlaylistProvider *m_playlist;
+ bool m_ownsProvider;
+ bool m_readOnly;
};
#endif // MOCKMEDIAPLAYLISTCONTROL_H
diff --git a/tests/auto/unit/qmultimedia_common/mockplaylistservice.h b/tests/auto/unit/qmultimedia_common/mockplaylistservice.h
index 95d95dbf..6c038abf 100644
--- a/tests/auto/unit/qmultimedia_common/mockplaylistservice.h
+++ b/tests/auto/unit/qmultimedia_common/mockplaylistservice.h
@@ -44,7 +44,7 @@ class MockPlaylistService : public QMediaService
public:
MockPlaylistService():QMediaService(0)
{
- mockControl = new MockMediaPlaylistControl(this);
+ mockControl = new MockMediaPlaylistControl(false, this);
}
~MockPlaylistService()
diff --git a/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h b/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h
index 50747c1a..39b1598b 100644
--- a/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h
+++ b/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h
@@ -38,7 +38,6 @@
class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider
{
- Q_OBJECT
public:
MockReadOnlyPlaylistProvider(QObject *parent)
:QMediaPlaylistProvider(parent)