diff options
author | Nicholas Young <nicholas.young@nokia.com> | 2010-02-04 00:45:43 (GMT) |
---|---|---|
committer | Nicholas Young <nicholas.young@nokia.com> | 2010-02-04 00:45:43 (GMT) |
commit | 1d48062f758ae82129583b0e95b18d06faf57547 (patch) | |
tree | b9037132db7e725b0f9997a0258a8cb0c4fdc414 | |
parent | 5588657ba3b2a060e60bf8d83fd5ba60bbdc9c64 (diff) | |
download | Qt-1d48062f758ae82129583b0e95b18d06faf57547.zip Qt-1d48062f758ae82129583b0e95b18d06faf57547.tar.gz Qt-1d48062f758ae82129583b0e95b18d06faf57547.tar.bz2 |
Added QNetworkRequest constructor to QMediaResource.
-rw-r--r-- | src/multimedia/base/base.pri | 1 | ||||
-rw-r--r-- | src/multimedia/base/qmediaresource.cpp | 24 | ||||
-rw-r--r-- | src/multimedia/base/qmediaresource.h | 6 | ||||
-rw-r--r-- | tests/auto/qmediaresource/qmediaresource.pro | 2 | ||||
-rw-r--r-- | tests/auto/qmediaresource/tst_qmediaresource.cpp | 45 |
5 files changed, 74 insertions, 4 deletions
diff --git a/src/multimedia/base/base.pri b/src/multimedia/base/base.pri index fb2784d..5aebbf0 100644 --- a/src/multimedia/base/base.pri +++ b/src/multimedia/base/base.pri @@ -1,4 +1,5 @@ +QT += network contains(QT_CONFIG, opengl):QT += opengl HEADERS += \ diff --git a/src/multimedia/base/qmediaresource.cpp b/src/multimedia/base/qmediaresource.cpp index ab18ce7..515e432 100644 --- a/src/multimedia/base/qmediaresource.cpp +++ b/src/multimedia/base/qmediaresource.cpp @@ -93,7 +93,17 @@ QMediaResource::QMediaResource() */ QMediaResource::QMediaResource(const QUrl &url, const QString &mimeType) { - values.insert(Url, qVariantFromValue(url)); + values.insert(Url, url); + values.insert(MimeType, mimeType); +} + +/*! + Constructs a media resource with the given \a mimeType from a network \a request. +*/ +QMediaResource::QMediaResource(const QNetworkRequest &request, const QString &mimeType) +{ + values.insert(Request, QVariant::fromValue(request)); + values.insert(Url, request.url()); values.insert(MimeType, mimeType); } @@ -162,6 +172,17 @@ QUrl QMediaResource::url() const } /*! + Returns the network request associated with this media resource. +*/ +QNetworkRequest QMediaResource::request() const +{ + if(values.contains(Request)) + return qvariant_cast<QNetworkRequest>(values.value(Request)); + + return QNetworkRequest(url()); +} + +/*! Returns the MIME type of a media resource. This may be null if the MIME type is unknown. @@ -373,6 +394,5 @@ void QMediaResource::setResolution(int width, int height) else values.remove(Resolution); } - QT_END_NAMESPACE diff --git a/src/multimedia/base/qmediaresource.h b/src/multimedia/base/qmediaresource.h index 33b5a79..516120a 100644 --- a/src/multimedia/base/qmediaresource.h +++ b/src/multimedia/base/qmediaresource.h @@ -44,6 +44,7 @@ #include <QtCore/qmap.h> #include <QtCore/qmetatype.h> +#include <QtNetwork/qnetworkrequest.h> QT_BEGIN_HEADER @@ -58,6 +59,7 @@ class Q_MULTIMEDIA_EXPORT QMediaResource public: QMediaResource(); QMediaResource(const QUrl &url, const QString &mimeType = QString()); + QMediaResource(const QNetworkRequest &request, const QString &mimeType = QString()); QMediaResource(const QMediaResource &other); QMediaResource &operator =(const QMediaResource &other); ~QMediaResource(); @@ -68,6 +70,7 @@ public: bool operator !=(const QMediaResource &other) const; QUrl url() const; + QNetworkRequest request() const; QString mimeType() const; QString language() const; @@ -103,6 +106,7 @@ private: enum Property { Url, + Request, MimeType, Language, AudioCodec, @@ -112,7 +116,7 @@ private: VideoBitRate, SampleRate, ChannelCount, - Resolution, + Resolution }; QMap<int, QVariant> values; }; diff --git a/tests/auto/qmediaresource/qmediaresource.pro b/tests/auto/qmediaresource/qmediaresource.pro index 2741608..c8e3d9c 100644 --- a/tests/auto/qmediaresource/qmediaresource.pro +++ b/tests/auto/qmediaresource/qmediaresource.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaresource.cpp -QT = core multimedia +QT = core multimedia network diff --git a/tests/auto/qmediaresource/tst_qmediaresource.cpp b/tests/auto/qmediaresource/tst_qmediaresource.cpp index 55ddcab..127144d 100644 --- a/tests/auto/qmediaresource/tst_qmediaresource.cpp +++ b/tests/auto/qmediaresource/tst_qmediaresource.cpp @@ -63,6 +63,7 @@ void tst_QMediaResource::constructNull() QCOMPARE(resource.isNull(), true); QCOMPARE(resource.url(), QUrl()); + QCOMPARE(resource.request(), QNetworkRequest()); QCOMPARE(resource.mimeType(), QString()); QCOMPARE(resource.language(), QString()); QCOMPARE(resource.audioCodec(), QString()); @@ -78,6 +79,7 @@ void tst_QMediaResource::constructNull() void tst_QMediaResource::construct_data() { QTest::addColumn<QUrl>("url"); + QTest::addColumn<QNetworkRequest>("request"); QTest::addColumn<QString>("mimeType"); QTest::addColumn<QString>("language"); QTest::addColumn<QString>("audioCodec"); @@ -91,6 +93,7 @@ void tst_QMediaResource::construct_data() QTest::newRow("audio content") << QUrl(QString::fromLatin1("http:://test.com/test.mp3")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.mp3"))) << QString::fromLatin1("audio/mpeg") << QString::fromLatin1("eng") << QString::fromLatin1("mp3") @@ -103,6 +106,7 @@ void tst_QMediaResource::construct_data() << QSize(); QTest::newRow("image content") << QUrl(QString::fromLatin1("http:://test.com/test.jpg")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.jpg"))) << QString::fromLatin1("image/jpeg") << QString() << QString() @@ -115,6 +119,7 @@ void tst_QMediaResource::construct_data() << QSize(640, 480); QTest::newRow("video content") << QUrl(QString::fromLatin1("http:://test.com/test.mp4")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.mp4"))) << QString::fromLatin1("video/mp4") << QString() << QString::fromLatin1("aac") @@ -127,6 +132,7 @@ void tst_QMediaResource::construct_data() << QSize(720, 576); QTest::newRow("thumbnail") << QUrl(QString::fromLatin1("file::///thumbs/test.png")) + << QNetworkRequest(QUrl(QString::fromLatin1("file::///thumbs/test.png"))) << QString::fromLatin1("image/png") << QString() << QString() @@ -142,6 +148,7 @@ void tst_QMediaResource::construct_data() void tst_QMediaResource::construct() { QFETCH(QUrl, url); + QFETCH(QNetworkRequest, request); QFETCH(QString, mimeType); QFETCH(QString, language); QFETCH(QString, audioCodec); @@ -174,6 +181,44 @@ void tst_QMediaResource::construct() QCOMPARE(resource.isNull(), false); QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); + QCOMPARE(resource.mimeType(), mimeType); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); + + resource.setLanguage(language); + resource.setAudioCodec(audioCodec); + resource.setVideoCodec(videoCodec); + resource.setDataSize(dataSize); + resource.setAudioBitRate(audioBitRate); + resource.setSampleRate(sampleRate); + resource.setChannelCount(channelCount); + resource.setVideoBitRate(videoBitRate); + resource.setResolution(resolution); + + QCOMPARE(resource.language(), language); + QCOMPARE(resource.audioCodec(), audioCodec); + QCOMPARE(resource.videoCodec(), videoCodec); + QCOMPARE(resource.dataSize(), dataSize); + QCOMPARE(resource.audioBitRate(), audioBitRate); + QCOMPARE(resource.sampleRate(), sampleRate); + QCOMPARE(resource.channelCount(), channelCount); + QCOMPARE(resource.videoBitRate(), videoBitRate); + QCOMPARE(resource.resolution(), resolution); + } + { + QMediaResource resource(request, mimeType); + + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); QCOMPARE(resource.mimeType(), mimeType); QCOMPARE(resource.language(), QString()); QCOMPARE(resource.audioCodec(), QString()); |