16
|
1 |
/**
|
|
2 |
This file is part of CWRT package **
|
|
3 |
|
|
4 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). **
|
|
5 |
|
|
6 |
This program is free software: you can redistribute it and/or modify
|
|
7 |
it under the terms of the GNU (Lesser) General Public License as
|
|
8 |
published by the Free Software Foundation, version 2.1 of the License.
|
|
9 |
This program is distributed in the hope that it will be useful, but
|
|
10 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
(Lesser) General Public License for more details. You should have
|
|
13 |
received a copy of the GNU (Lesser) General Public License along
|
|
14 |
with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*/
|
|
16 |
|
|
17 |
#include "omaddparser.h"
|
|
18 |
#include <QString>
|
|
19 |
|
|
20 |
const QString nameTag = "name";
|
|
21 |
const QString DDVersionTag = "DDVersion";
|
|
22 |
const QString typeTag = "type";
|
|
23 |
const QString sizeTag = "size";
|
|
24 |
const QString vendorTag = "vendor";
|
|
25 |
const QString descriptionTag = "description";
|
|
26 |
const QString productTag = "product";
|
|
27 |
const QString mediaObjectTag = "mediaObject";
|
|
28 |
const QString progressiveDownloadFlagTag = "progressiveDownloadFlag";
|
|
29 |
const QString serverTag = "server";
|
|
30 |
const QString suppressUserConfirmTag = "suppressUserConfirmation";
|
|
31 |
const QString updatedDDURITag = "updatedDDURI";
|
|
32 |
const QString objectURITag = "objectURI";
|
|
33 |
const QString installNotifyURITag = "installNotifyURI";
|
|
34 |
const QString nextURLTag = "nextURL";
|
|
35 |
|
|
36 |
// private implementation class
|
|
37 |
class OMADownloadDescParserPrivate {
|
|
38 |
DM_DECLARE_PUBLIC(OMADownloadDescParser);
|
|
39 |
public:
|
|
40 |
OMADownloadDescParserPrivate();
|
|
41 |
~OMADownloadDescParserPrivate();
|
|
42 |
OMADownloadDescriptor *m_downloadDesc;
|
|
43 |
QStack<QString> m_stack;
|
|
44 |
QString m_characterData;
|
|
45 |
QString m_errorString;
|
|
46 |
bool m_isProductTag; // flag to indicate if it is product tag
|
|
47 |
bool m_isMediaObjTag; // flag to indicate if it is media object tag
|
|
48 |
OMA2DownloadProduct *m_currProduct;
|
|
49 |
OMA2DownloadMediaObj *m_currMediaObj;
|
|
50 |
};
|
|
51 |
|
|
52 |
class OMADownloadDescriptorPrivate {
|
|
53 |
DM_DECLARE_PUBLIC(OMADownloadDescriptor);
|
|
54 |
public:
|
|
55 |
OMADownloadDescriptorPrivate();
|
|
56 |
~OMADownloadDescriptorPrivate();
|
|
57 |
QMap<QString, QVariant> m_attrMap;
|
|
58 |
ProductList m_productList;
|
|
59 |
};
|
|
60 |
|
|
61 |
class OMA2DownloadProductPrivate {
|
|
62 |
DM_DECLARE_PUBLIC(OMA2DownloadProduct);
|
|
63 |
public:
|
|
64 |
OMA2DownloadProductPrivate();
|
|
65 |
~OMA2DownloadProductPrivate();
|
|
66 |
QMap<QString, QVariant> m_productAttrMap;
|
|
67 |
MediaObjectList m_mediaObjList;
|
|
68 |
};
|
|
69 |
|
|
70 |
class OMA2DownloadMediaObjPrivate {
|
|
71 |
DM_DECLARE_PUBLIC(OMA2DownloadMediaObj);
|
|
72 |
public:
|
|
73 |
QMap<QString, QVariant> m_mediaObjAttrMap;
|
|
74 |
};
|
|
75 |
|
|
76 |
OMADownloadDescParserPrivate::OMADownloadDescParserPrivate():m_downloadDesc(0)
|
|
77 |
,m_isProductTag(false)
|
|
78 |
,m_isMediaObjTag(false)
|
|
79 |
,m_currProduct(0)
|
|
80 |
,m_currMediaObj(0)
|
|
81 |
{ }
|
|
82 |
|
|
83 |
OMADownloadDescParserPrivate::~OMADownloadDescParserPrivate()
|
|
84 |
{
|
|
85 |
if (m_downloadDesc) {
|
|
86 |
delete m_downloadDesc;
|
|
87 |
m_downloadDesc = 0;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
OMADownloadDescParser::OMADownloadDescParser()
|
|
92 |
{
|
|
93 |
DM_INITIALIZE(OMADownloadDescParser);
|
|
94 |
}
|
|
95 |
|
|
96 |
OMADownloadDescParser::~OMADownloadDescParser()
|
|
97 |
{
|
|
98 |
DM_UNINITIALIZE(OMADownloadDescParser);
|
|
99 |
}
|
|
100 |
|
|
101 |
bool OMADownloadDescParser::startDocument()
|
|
102 |
{
|
|
103 |
DM_PRIVATE(OMADownloadDescParser);
|
|
104 |
priv->m_downloadDesc = new OMADownloadDescriptor();
|
|
105 |
return true;
|
|
106 |
}
|
|
107 |
|
|
108 |
bool OMADownloadDescParser::startElement(const QString&, const QString&, const QString& qName, const QXmlAttributes&)
|
|
109 |
{
|
|
110 |
DM_PRIVATE(OMADownloadDescParser);
|
|
111 |
priv->m_characterData = "";
|
|
112 |
priv->m_stack.push(qName);
|
|
113 |
if (qName == productTag) {
|
|
114 |
priv->m_isProductTag = true;
|
|
115 |
priv->m_currProduct = new OMA2DownloadProduct();
|
|
116 |
if (priv->m_currProduct) {
|
|
117 |
priv->m_downloadDesc->addProduct(priv->m_currProduct);
|
|
118 |
return true;
|
|
119 |
}
|
|
120 |
return false;
|
|
121 |
}
|
|
122 |
if (qName == mediaObjectTag) {
|
|
123 |
priv->m_isMediaObjTag = true;
|
|
124 |
priv->m_currMediaObj = new OMA2DownloadMediaObj();
|
|
125 |
if (priv->m_currMediaObj) {
|
|
126 |
priv->m_currProduct->addMediaObject(priv->m_currMediaObj);
|
|
127 |
return true;
|
|
128 |
}
|
|
129 |
return false;
|
|
130 |
}
|
|
131 |
return true;
|
|
132 |
}
|
|
133 |
|
|
134 |
bool OMADownloadDescParser::endElement(const QString&, const QString&, const QString& qName)
|
|
135 |
{
|
|
136 |
DM_PRIVATE(OMADownloadDescParser);
|
|
137 |
QString tagName = priv->m_stack.pop();
|
|
138 |
if (qName == tagName) {
|
|
139 |
if (tagName == productTag)
|
|
140 |
priv->m_isProductTag = false;
|
|
141 |
else if (tagName == mediaObjectTag)
|
|
142 |
priv->m_isMediaObjTag = false;
|
|
143 |
else {
|
|
144 |
if ( priv->m_characterData != "") {
|
|
145 |
if (priv->m_isProductTag) {
|
|
146 |
if (priv->m_isMediaObjTag) {
|
|
147 |
priv->m_currMediaObj->setAttribute(qName, QVariant(priv->m_characterData));
|
|
148 |
priv->m_characterData = "";
|
|
149 |
} else {
|
|
150 |
priv->m_currProduct->setAttribute(qName, QVariant(priv->m_characterData));
|
|
151 |
priv->m_characterData = "";
|
|
152 |
}
|
|
153 |
} else {
|
|
154 |
priv->m_downloadDesc->setAttribute(qName, QVariant(priv->m_characterData));
|
|
155 |
priv->m_characterData = "";
|
|
156 |
}
|
|
157 |
}
|
|
158 |
}
|
|
159 |
return true;
|
|
160 |
} else {
|
|
161 |
priv->m_errorString = QObject::tr("Tag Mismatch. Check content");
|
|
162 |
return false;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
bool OMADownloadDescParser::characters(const QString& ch)
|
|
167 |
{
|
|
168 |
DM_PRIVATE(OMADownloadDescParser);
|
|
169 |
QString str = ch.trimmed();
|
|
170 |
if (str != "")
|
|
171 |
priv->m_characterData += str;
|
|
172 |
return true;
|
|
173 |
}
|
|
174 |
|
|
175 |
QString OMADownloadDescParser::errorString()
|
|
176 |
{
|
|
177 |
DM_PRIVATE(OMADownloadDescParser);
|
|
178 |
return priv->m_errorString;
|
|
179 |
}
|
|
180 |
|
|
181 |
bool OMADownloadDescParser::fatalError(const QXmlParseException &/*exception*/)
|
|
182 |
{
|
|
183 |
return false;
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
OMADownloadDescriptorPrivate::OMADownloadDescriptorPrivate()
|
|
188 |
{
|
|
189 |
}
|
|
190 |
|
|
191 |
OMADownloadDescriptorPrivate::~OMADownloadDescriptorPrivate()
|
|
192 |
{
|
|
193 |
if (!m_productList.isEmpty()) {
|
|
194 |
for (int i=0; i<m_productList.count(); i++)
|
|
195 |
delete m_productList[i];
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
OMADownloadDescriptor* OMADownloadDescParser::downloadDescriptor()
|
|
200 |
{
|
|
201 |
DM_PRIVATE(OMADownloadDescParser);
|
|
202 |
return priv->m_downloadDesc;
|
|
203 |
}
|
|
204 |
|
|
205 |
OMADownloadDescriptor::OMADownloadDescriptor()
|
|
206 |
{
|
|
207 |
DM_INITIALIZE(OMADownloadDescriptor);
|
|
208 |
}
|
|
209 |
|
|
210 |
OMADownloadDescriptor::~OMADownloadDescriptor()
|
|
211 |
{
|
|
212 |
DM_UNINITIALIZE(OMADownloadDescriptor);
|
|
213 |
}
|
|
214 |
|
|
215 |
QVariant OMADownloadDescriptor::getAttribute(OMADownloadAttribute attr)
|
|
216 |
{
|
|
217 |
DM_PRIVATE(OMADownloadDescriptor);
|
|
218 |
switch(attr) {
|
|
219 |
case OMADownloadDescName:
|
|
220 |
return QVariant(priv->m_attrMap[nameTag]);
|
|
221 |
|
|
222 |
case OMADownloadDescVersion:
|
|
223 |
return QVariant(priv->m_attrMap[DDVersionTag]);
|
|
224 |
|
|
225 |
case OMADownloadDescObjectURI:
|
|
226 |
return QVariant(priv->m_attrMap[objectURITag]);
|
|
227 |
|
|
228 |
case OMADownloadDescType:
|
|
229 |
return QVariant(priv->m_attrMap[typeTag]);
|
|
230 |
|
|
231 |
case OMADownloadDescSize:
|
|
232 |
return QVariant(priv->m_attrMap[sizeTag]);
|
|
233 |
|
|
234 |
case OMADownloadDescVendor:
|
|
235 |
return QVariant(priv->m_attrMap[vendorTag]);
|
|
236 |
|
|
237 |
case OMADownloadDescDescription:
|
|
238 |
return QVariant(priv->m_attrMap[descriptionTag]);
|
|
239 |
|
|
240 |
case OMADownloadDescInstallNotifyURI:
|
|
241 |
return QVariant(priv->m_attrMap[installNotifyURITag]);
|
|
242 |
|
|
243 |
case OMA2DownloadDescUpdatedDDURI:
|
|
244 |
return QVariant(priv->m_attrMap[updatedDDURITag]);
|
|
245 |
|
|
246 |
case OMADownloadDescNextURL:
|
|
247 |
return QVariant(priv->m_attrMap[nextURLTag]);
|
|
248 |
|
|
249 |
default:
|
|
250 |
return QVariant();
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
|
254 |
void OMADownloadDescriptor::setAttribute(const QString& attrName, const QVariant& value)
|
|
255 |
{
|
|
256 |
DM_PRIVATE(OMADownloadDescriptor);
|
|
257 |
priv->m_attrMap[attrName] = value;
|
|
258 |
}
|
|
259 |
|
|
260 |
QList<OMA2DownloadProduct*> OMADownloadDescriptor::productList()
|
|
261 |
{
|
|
262 |
DM_PRIVATE(OMADownloadDescriptor);
|
|
263 |
return (priv->m_productList);
|
|
264 |
}
|
|
265 |
|
|
266 |
int OMADownloadDescriptor::productCount()
|
|
267 |
{
|
|
268 |
DM_PRIVATE(OMADownloadDescriptor);
|
|
269 |
return priv->m_productList.count();
|
|
270 |
}
|
|
271 |
|
|
272 |
void OMADownloadDescriptor::addProduct(OMA2DownloadProduct *Obj)
|
|
273 |
{
|
|
274 |
DM_PRIVATE(OMADownloadDescriptor);
|
|
275 |
priv->m_productList.append(Obj);
|
|
276 |
}
|
|
277 |
|
|
278 |
|
|
279 |
OMA2DownloadProductPrivate::OMA2DownloadProductPrivate()
|
|
280 |
{ }
|
|
281 |
|
|
282 |
OMA2DownloadProductPrivate::~OMA2DownloadProductPrivate()
|
|
283 |
{
|
|
284 |
if (!m_mediaObjList.isEmpty()) {
|
|
285 |
for (int i=0; i<m_mediaObjList.count(); i++)
|
|
286 |
delete m_mediaObjList[i];
|
|
287 |
}
|
|
288 |
}
|
|
289 |
|
|
290 |
OMA2DownloadProduct::OMA2DownloadProduct()
|
|
291 |
{
|
|
292 |
DM_INITIALIZE(OMA2DownloadProduct);
|
|
293 |
}
|
|
294 |
|
|
295 |
OMA2DownloadProduct::~OMA2DownloadProduct()
|
|
296 |
{
|
|
297 |
DM_UNINITIALIZE(OMA2DownloadProduct);
|
|
298 |
}
|
|
299 |
|
|
300 |
QVariant OMA2DownloadProduct::getAttribute(OMADownloadAttribute attr)
|
|
301 |
{
|
|
302 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
303 |
switch(attr) {
|
|
304 |
case OMA2DownloadDescProductName:
|
|
305 |
return QVariant(priv->m_productAttrMap[nameTag]);
|
|
306 |
|
|
307 |
case OMA2DownloadDescProductInstallNotifyURI:
|
|
308 |
return QVariant(priv->m_productAttrMap[installNotifyURITag]);
|
|
309 |
|
|
310 |
case OMA2DownloadDescProductSuppressConfirmation:
|
|
311 |
return QVariant(priv->m_productAttrMap[suppressUserConfirmTag]);
|
|
312 |
|
|
313 |
default:
|
|
314 |
return QVariant();
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
void OMA2DownloadProduct::setAttribute(const QString& attrName, const QVariant& value)
|
|
319 |
{
|
|
320 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
321 |
priv->m_productAttrMap[attrName] = value;
|
|
322 |
}
|
|
323 |
|
|
324 |
QList<OMA2DownloadMediaObj*> OMA2DownloadProduct::mediaObjList()
|
|
325 |
{
|
|
326 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
327 |
return (priv->m_mediaObjList);
|
|
328 |
}
|
|
329 |
|
|
330 |
int OMA2DownloadProduct::mediaCount()
|
|
331 |
{
|
|
332 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
333 |
return priv->m_mediaObjList.count();
|
|
334 |
}
|
|
335 |
|
|
336 |
void OMA2DownloadProduct::addMediaObject(OMA2DownloadMediaObj *Obj)
|
|
337 |
{
|
|
338 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
339 |
priv->m_mediaObjList.append(Obj);
|
|
340 |
}
|
|
341 |
|
|
342 |
qint64 OMA2DownloadProduct::albumSize()
|
|
343 |
{
|
|
344 |
DM_PRIVATE(OMA2DownloadProduct);
|
|
345 |
qint64 albumSize = 0;
|
|
346 |
for(int i=0; i<priv->m_mediaObjList.count(); i++)
|
|
347 |
albumSize = albumSize + priv->m_mediaObjList[i]->getAttribute(OMA2DownloadDescMediaObjSize).toInt();
|
|
348 |
return (albumSize);
|
|
349 |
}
|
|
350 |
|
|
351 |
|
|
352 |
OMA2DownloadMediaObj::OMA2DownloadMediaObj()
|
|
353 |
{
|
|
354 |
DM_INITIALIZE(OMA2DownloadMediaObj);
|
|
355 |
}
|
|
356 |
|
|
357 |
OMA2DownloadMediaObj::~OMA2DownloadMediaObj()
|
|
358 |
{
|
|
359 |
DM_UNINITIALIZE(OMA2DownloadMediaObj);
|
|
360 |
}
|
|
361 |
|
|
362 |
QVariant OMA2DownloadMediaObj::getAttribute(OMADownloadAttribute attr)
|
|
363 |
{
|
|
364 |
DM_PRIVATE(OMA2DownloadMediaObj);
|
|
365 |
switch(attr) {
|
|
366 |
case OMA2DownloadDescMediaObjName:
|
|
367 |
return QVariant(priv->m_mediaObjAttrMap[nameTag]);
|
|
368 |
|
|
369 |
case OMA2DownloadDescMediaObjType:
|
|
370 |
return QVariant(priv->m_mediaObjAttrMap[typeTag]);
|
|
371 |
|
|
372 |
case OMA2DownloadDescMediaObjSize:
|
|
373 |
return QVariant(priv->m_mediaObjAttrMap[sizeTag]);
|
|
374 |
|
|
375 |
case OMA2DownloadDescMediaObjProgressiveDl:
|
|
376 |
return QVariant(priv->m_mediaObjAttrMap[progressiveDownloadFlagTag]);
|
|
377 |
|
|
378 |
case OMA2DownloadDescMediaObjServer:
|
|
379 |
return QVariant(priv->m_mediaObjAttrMap[serverTag]);
|
|
380 |
|
|
381 |
case OMA2DownloadDescMediaObjInstallNotifyURI:
|
|
382 |
return QVariant(priv->m_mediaObjAttrMap[installNotifyURITag]); // need to add the rest of private attributes like license, text, order when implemented in future.
|
|
383 |
|
|
384 |
case OMA2DownloadDescMediaObjSuppressConfirmation:
|
|
385 |
return QVariant(priv->m_mediaObjAttrMap[suppressUserConfirmTag]);
|
|
386 |
|
|
387 |
default:
|
|
388 |
return QVariant();
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
void OMA2DownloadMediaObj::setAttribute(const QString& attrName, const QVariant& value)
|
|
393 |
{
|
|
394 |
DM_PRIVATE(OMA2DownloadMediaObj);
|
|
395 |
priv->m_mediaObjAttrMap[attrName] = value;
|
|
396 |
}
|