|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtCore/qurl.h> |
|
43 #include <QtCore/qvariant.h> |
|
44 |
|
45 #include "qmediacontent.h" |
|
46 |
|
47 QT_BEGIN_NAMESPACE |
|
48 |
|
49 |
|
50 class QMediaContentPrivate : public QSharedData |
|
51 { |
|
52 public: |
|
53 QMediaContentPrivate() {} |
|
54 QMediaContentPrivate(const QMediaResourceList &r): |
|
55 resources(r) {} |
|
56 |
|
57 QMediaContentPrivate(const QMediaContentPrivate &other): |
|
58 QSharedData(other), |
|
59 resources(other.resources) |
|
60 {} |
|
61 |
|
62 bool operator ==(const QMediaContentPrivate &other) const |
|
63 { |
|
64 return resources == other.resources; |
|
65 } |
|
66 |
|
67 QMediaResourceList resources; |
|
68 private: |
|
69 QMediaContentPrivate& operator=(const QMediaContentPrivate &other); |
|
70 }; |
|
71 |
|
72 |
|
73 /*! |
|
74 \class QMediaContent |
|
75 \preliminary |
|
76 \brief The QMediaContent class provides access to the resources relating to a media content. |
|
77 |
|
78 \ingroup multimedia |
|
79 |
|
80 QMediaContent is used within the multimedia framework as the logical handle |
|
81 to media content. A QMediaContent object is composed of one or more |
|
82 \l {QMediaResource}s where each resource provides the URL and format |
|
83 information of a different encoding of the content. |
|
84 |
|
85 A non-null QMediaContent will always have a primary or canonical reference to |
|
86 the content available through the canonicalUrl() or canonicalResource() |
|
87 methods, any additional resources are optional. |
|
88 */ |
|
89 |
|
90 |
|
91 /*! |
|
92 Constructs a null QMediaContent. |
|
93 */ |
|
94 |
|
95 QMediaContent::QMediaContent() |
|
96 { |
|
97 } |
|
98 |
|
99 /*! |
|
100 Constructs a media content with \a url providing a reference to the content. |
|
101 */ |
|
102 |
|
103 QMediaContent::QMediaContent(const QUrl &url): |
|
104 d(new QMediaContentPrivate) |
|
105 { |
|
106 d->resources << QMediaResource(url); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Constructs a media content with \a request providing a reference to the content. |
|
111 |
|
112 This constructor can be used to reference media content via network protocols such as HTTP. |
|
113 This may include additional information required to obtain the resource, such as Cookies or HTTP headers. |
|
114 */ |
|
115 |
|
116 QMediaContent::QMediaContent(const QNetworkRequest &request): |
|
117 d(new QMediaContentPrivate) |
|
118 { |
|
119 d->resources << QMediaResource(request); |
|
120 } |
|
121 |
|
122 /*! |
|
123 Constructs a media content with \a resource providing a reference to the content. |
|
124 */ |
|
125 |
|
126 QMediaContent::QMediaContent(const QMediaResource &resource): |
|
127 d(new QMediaContentPrivate) |
|
128 { |
|
129 d->resources << resource; |
|
130 } |
|
131 |
|
132 /*! |
|
133 Constructs a media content with \a resources providing a reference to the content. |
|
134 */ |
|
135 |
|
136 QMediaContent::QMediaContent(const QMediaResourceList &resources): |
|
137 d(new QMediaContentPrivate(resources)) |
|
138 { |
|
139 } |
|
140 |
|
141 /*! |
|
142 Constructs a copy of the media content \a other. |
|
143 */ |
|
144 |
|
145 QMediaContent::QMediaContent(const QMediaContent &other): |
|
146 d(other.d) |
|
147 { |
|
148 } |
|
149 |
|
150 /*! |
|
151 Destroys the media content object. |
|
152 */ |
|
153 |
|
154 QMediaContent::~QMediaContent() |
|
155 { |
|
156 } |
|
157 |
|
158 /*! |
|
159 Assigns the value of \a other to this media content. |
|
160 */ |
|
161 |
|
162 QMediaContent& QMediaContent::operator=(const QMediaContent &other) |
|
163 { |
|
164 d = other.d; |
|
165 return *this; |
|
166 } |
|
167 |
|
168 /*! |
|
169 Returns true if \a other is equivalent to this media content; false otherwise. |
|
170 */ |
|
171 |
|
172 bool QMediaContent::operator==(const QMediaContent &other) const |
|
173 { |
|
174 return (d.constData() == 0 && other.d.constData() == 0) || |
|
175 (d.constData() != 0 && other.d.constData() != 0 && |
|
176 *d.constData() == *other.d.constData()); |
|
177 } |
|
178 |
|
179 /*! |
|
180 Returns true if \a other is not equivalent to this media content; false otherwise. |
|
181 */ |
|
182 |
|
183 bool QMediaContent::operator!=(const QMediaContent &other) const |
|
184 { |
|
185 return !(*this == other); |
|
186 } |
|
187 |
|
188 /*! |
|
189 Returns true if this media content is null (uninitialized); false otherwise. |
|
190 */ |
|
191 |
|
192 bool QMediaContent::isNull() const |
|
193 { |
|
194 return d.constData() == 0; |
|
195 } |
|
196 |
|
197 /*! |
|
198 Returns a QUrl that represents that canonical resource for this media content. |
|
199 */ |
|
200 |
|
201 QUrl QMediaContent::canonicalUrl() const |
|
202 { |
|
203 return canonicalResource().url(); |
|
204 } |
|
205 |
|
206 /*! |
|
207 Returns a QNetworkRequest that represents that canonical resource for this media content. |
|
208 */ |
|
209 |
|
210 QNetworkRequest QMediaContent::canonicalRequest() const |
|
211 { |
|
212 return canonicalResource().request(); |
|
213 } |
|
214 |
|
215 /*! |
|
216 Returns a QMediaResource that represents that canonical resource for this media content. |
|
217 */ |
|
218 |
|
219 QMediaResource QMediaContent::canonicalResource() const |
|
220 { |
|
221 return d.constData() != 0 |
|
222 ? d->resources.value(0) |
|
223 : QMediaResource(); |
|
224 } |
|
225 |
|
226 /*! |
|
227 Returns a list of alternative resources for this media content. The first item in this list |
|
228 is always the canonical resource. |
|
229 */ |
|
230 |
|
231 QMediaResourceList QMediaContent::resources() const |
|
232 { |
|
233 return d.constData() != 0 |
|
234 ? d->resources |
|
235 : QMediaResourceList(); |
|
236 } |
|
237 |
|
238 QT_END_NAMESPACE |
|
239 |