Added playlist property to QMediaContent

This is a part of changes to QMediaPlayer related to playlist handling.
Updated unit test.

Change-Id: Ic2460dc4d3121788cd5eb08df71e6d45aac032bc
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
Lev Zelenskiy
2012-03-05 12:25:50 +10:00
committed by Qt by Nokia
parent e2eaa283fb
commit 87de0979e5
3 changed files with 100 additions and 6 deletions

View File

@@ -41,7 +41,9 @@
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
#include <QtCore/QWeakPointer>
#include <qmediaplaylist.h>
#include "qmediacontent.h"
QT_BEGIN_NAMESPACE
@@ -62,21 +64,44 @@ namespace
class QMediaContentPrivate : public QSharedData
{
public:
QMediaContentPrivate() {}
QMediaContentPrivate():
isPlaylistOwned(false)
{}
QMediaContentPrivate(const QMediaResourceList &r):
resources(r) {}
resources(r),
isPlaylistOwned(false)
{}
QMediaContentPrivate(const QMediaContentPrivate &other):
QSharedData(other),
resources(other.resources)
resources(other.resources),
playlist(other.playlist),
isPlaylistOwned(false)
{}
QMediaContentPrivate(QMediaPlaylist *pls, const QUrl &url, bool isOwn):
playlist(pls),
isPlaylistOwned(isOwn)
{
resources << QMediaResource(url);
}
~QMediaContentPrivate()
{
if (isPlaylistOwned && !playlist.isNull())
playlist.data()->deleteLater();
}
bool operator ==(const QMediaContentPrivate &other) const
{
return resources == other.resources;
return resources == other.resources && playlist == other.playlist;
}
QMediaResourceList resources;
QMediaResourceList resources;
QWeakPointer<QMediaPlaylist> playlist;
bool isPlaylistOwned;
private:
QMediaContentPrivate& operator=(const QMediaContentPrivate &other);
};
@@ -99,6 +124,10 @@ private:
A non-null QMediaContent will always have a primary or canonical reference to
the content available through the canonicalUrl() or canonicalResource()
methods, any additional resources are optional.
Alternatively QMediaContent can represent a playlist and contain a pointer to a
valid QMediaPlaylist object. In this case URL is optional and can either be empty
or point to the playlist URL.
*/
@@ -161,6 +190,20 @@ QMediaContent::QMediaContent(const QMediaContent &other):
{
}
/*!
Constructs a media content with \a playlist.
\a contentUrl of a playlist is an optional parameter and can be empty.
Set \a takeOwnership to true if you want QMediaContent to take ownership of the playlist.
\a takeOwnership is set to false by default.
*/
QMediaContent::QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl, bool takeOwnership):
d(new QMediaContentPrivate(playlist, contentUrl, takeOwnership))
{
}
/*!
Destroys the media content object.
*/
@@ -249,5 +292,16 @@ QMediaResourceList QMediaContent::resources() const
: QMediaResourceList();
}
/*!
Returns a playlist for this media content or 0 if this QMediaContent is not a playlist.
*/
QMediaPlaylist *QMediaContent::playlist() const
{
return d.constData() != 0
? d->playlist.data()
: 0;
}
QT_END_NAMESPACE

View File

@@ -49,13 +49,13 @@
#include <qtmultimediadefs.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QMediaPlaylist;
class QMediaContentPrivate;
class Q_MULTIMEDIA_EXPORT QMediaContent
@@ -67,6 +67,7 @@ public:
QMediaContent(const QMediaResource &contentResource);
QMediaContent(const QMediaResourceList &resources);
QMediaContent(const QMediaContent &other);
QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl = QUrl(), bool takeOwnership = false);
~QMediaContent();
QMediaContent& operator=(const QMediaContent &other);
@@ -82,6 +83,7 @@ public:
QMediaResourceList resources() const;
QMediaPlaylist *playlist() const;
private:
QSharedDataPointer<QMediaContentPrivate> d;
};