94
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
93
|
18 |
#include "hswidgetcomponentparser.h"
|
|
19 |
#include <QFile>
|
|
20 |
|
|
21 |
const char WIDGETPROVIDER[] = "widgetprovider";
|
|
22 |
const char WIDGET[] = "widget";
|
|
23 |
const char WIDGETMANIFEST[] = "hswidgetmanifest";
|
|
24 |
|
|
25 |
const char URI[] = "uri";
|
|
26 |
const char TITLE[] = "title";
|
|
27 |
const char ICONURI[] = "iconuri";
|
|
28 |
const char ICON[] = "icon";
|
|
29 |
const char DESCRIPTION[] = "description";
|
|
30 |
const char HIDDEN[] = "hidden";
|
|
31 |
const char SERVICEXML[] = "servicexml";
|
99
|
32 |
const char PREVIEWIAMGE[] = "previewimage";
|
93
|
33 |
const char VERSION[] = "version";
|
|
34 |
const char VERSION_1_0[] = "1.0";
|
99
|
35 |
const char TRANSLATIONFILENAME[] = "translationfile";
|
93
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
HsWidgetComponentParser::HsWidgetComponentParser(const QString &aComponentManifest, QObject *parent)
|
|
40 |
: QObject(parent),mError(false)
|
|
41 |
{
|
|
42 |
parseFile(aComponentManifest);
|
|
43 |
}
|
|
44 |
|
|
45 |
HsWidgetComponentParser::~HsWidgetComponentParser()
|
|
46 |
{
|
|
47 |
|
|
48 |
}
|
|
49 |
|
|
50 |
HsWidgetComponentDescriptor HsWidgetComponentParser::widgetComponentDescriptor()
|
|
51 |
{
|
|
52 |
return mComponentDescriptor;
|
|
53 |
}
|
|
54 |
|
|
55 |
bool HsWidgetComponentParser::error()
|
|
56 |
{
|
|
57 |
return mError;
|
|
58 |
}
|
|
59 |
|
|
60 |
void HsWidgetComponentParser::parseFile(const QString &aComponentManifest)
|
|
61 |
{
|
|
62 |
QFile file(aComponentManifest);
|
|
63 |
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
64 |
mError = false;
|
|
65 |
return;
|
|
66 |
}
|
|
67 |
mParser.setDevice(&file);
|
|
68 |
if (mParser.readNextStartElement()) {
|
|
69 |
if (mParser.name() == WIDGETMANIFEST){
|
|
70 |
parseWidgetManifestTag();
|
|
71 |
} else if(mParser.name() == WIDGETPROVIDER){
|
|
72 |
parseWidgetProviderTag();
|
|
73 |
} else {
|
|
74 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
75 |
}
|
|
76 |
} else {
|
|
77 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
78 |
}
|
|
79 |
mError = mParser.error();
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
void HsWidgetComponentParser::parseWidgetManifestTag()
|
|
84 |
{
|
|
85 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETMANIFEST);
|
|
86 |
|
|
87 |
/* Detect version */
|
|
88 |
if (mParser.attributes().hasAttribute(VERSION)) {
|
|
89 |
QStringRef version = mParser.attributes().value(VERSION);
|
|
90 |
mComponentDescriptor.version = version.toString();
|
|
91 |
if (version == VERSION_1_0) {
|
|
92 |
parseVersion1_0();
|
|
93 |
}
|
|
94 |
} else {
|
|
95 |
// newest is default
|
|
96 |
parseVersion1_0();
|
|
97 |
mComponentDescriptor.version = VERSION_1_0;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
void HsWidgetComponentParser::parseWidgetProviderTag()
|
|
102 |
{
|
|
103 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETPROVIDER);
|
|
104 |
if (!mParser.readNextStartElement() || mParser.name() != WIDGET) {
|
|
105 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
106 |
return;
|
|
107 |
}
|
|
108 |
|
|
109 |
// everything is in attributes
|
|
110 |
QXmlStreamAttributes attrs = mParser.attributes();
|
|
111 |
foreach (QXmlStreamAttribute attr, attrs) {
|
|
112 |
QStringRef name = attr.name();
|
|
113 |
if (name == URI) {
|
|
114 |
mComponentDescriptor.uri = attr.value().toString();
|
|
115 |
} else if (name == ICONURI) {
|
|
116 |
mComponentDescriptor.iconUri = attr.value().toString();
|
|
117 |
} else if (name == TITLE) {
|
|
118 |
mComponentDescriptor.title = attr.value().toString();
|
|
119 |
} else if (name == DESCRIPTION) {
|
|
120 |
mComponentDescriptor.description = attr.value().toString();
|
|
121 |
} else if (name == HIDDEN) {
|
|
122 |
mComponentDescriptor.hidden = attr.value().toString();
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
}
|
|
127 |
void HsWidgetComponentParser::parseVersion1_0()
|
|
128 |
{
|
|
129 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETMANIFEST);
|
|
130 |
/* We'll parse the XML until we reach </hswidgetmanifest> tag, end of cml or have an error. */
|
|
131 |
while( !(mParser.tokenType() == QXmlStreamReader::EndElement && mParser.name() == WIDGETMANIFEST) &&
|
|
132 |
!mParser.hasError() && !mParser.atEnd()) {
|
|
133 |
|
|
134 |
mParser.readNext();
|
|
135 |
if (mParser.tokenType() != QXmlStreamReader::StartElement) {
|
|
136 |
continue;
|
|
137 |
}
|
|
138 |
/* Read next start element.*/
|
|
139 |
QStringRef tag = mParser.name();
|
|
140 |
if(tag == URI) {
|
|
141 |
parseUri();
|
|
142 |
} else if (tag == ICON) {
|
|
143 |
parseIcon();
|
|
144 |
} else if (tag == TITLE) {
|
|
145 |
parseTitle();
|
|
146 |
} else if (tag == DESCRIPTION) {
|
|
147 |
parseDescription();
|
|
148 |
} else if (tag == HIDDEN) {
|
|
149 |
parseHidden();
|
|
150 |
} else if (tag == SERVICEXML) {
|
|
151 |
parseServiceXml();
|
99
|
152 |
} else if (tag == PREVIEWIAMGE) {
|
|
153 |
parsePreviewImage();
|
|
154 |
} else if (tag == TRANSLATIONFILENAME) {
|
|
155 |
parseTranslationFileName();
|
|
156 |
}
|
|
157 |
}
|
93
|
158 |
}
|
|
159 |
|
|
160 |
|
|
161 |
void HsWidgetComponentParser::parseUri()
|
|
162 |
{
|
|
163 |
mParser.readNext();
|
|
164 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
165 |
return;
|
|
166 |
}
|
|
167 |
mComponentDescriptor.uri = mParser.text().toString();
|
|
168 |
}
|
99
|
169 |
|
93
|
170 |
void HsWidgetComponentParser::parseIcon()
|
|
171 |
{
|
|
172 |
mParser.readNext();
|
|
173 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
174 |
return;
|
|
175 |
}
|
|
176 |
mComponentDescriptor.iconUri = mParser.text().toString();
|
|
177 |
}
|
99
|
178 |
|
93
|
179 |
void HsWidgetComponentParser::parseTitle()
|
|
180 |
{
|
|
181 |
mParser.readNext();
|
|
182 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
183 |
return;
|
|
184 |
}
|
|
185 |
mComponentDescriptor.title = mParser.text().toString();
|
|
186 |
}
|
99
|
187 |
|
93
|
188 |
void HsWidgetComponentParser::parseDescription()
|
|
189 |
{
|
|
190 |
mParser.readNext();
|
|
191 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
192 |
return;
|
|
193 |
}
|
|
194 |
mComponentDescriptor.description = mParser.text().toString();
|
|
195 |
}
|
99
|
196 |
|
93
|
197 |
void HsWidgetComponentParser::parseHidden()
|
|
198 |
{
|
|
199 |
mParser.readNext();
|
|
200 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
201 |
return;
|
|
202 |
}
|
|
203 |
mComponentDescriptor.hidden = mParser.text().toString();
|
|
204 |
}
|
99
|
205 |
|
93
|
206 |
void HsWidgetComponentParser::parseServiceXml()
|
|
207 |
{
|
|
208 |
mParser.readNext();
|
|
209 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
210 |
return;
|
|
211 |
}
|
|
212 |
mComponentDescriptor.serviceXml = mParser.text().toString();
|
|
213 |
}
|
|
214 |
|
99
|
215 |
void HsWidgetComponentParser::parsePreviewImage()
|
|
216 |
{
|
|
217 |
mParser.readNext();
|
|
218 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
219 |
return;
|
|
220 |
}
|
|
221 |
mComponentDescriptor.previewImage = mParser.text().toString();
|
|
222 |
}
|
|
223 |
|
|
224 |
void HsWidgetComponentParser::parseTranslationFileName()
|
|
225 |
{
|
|
226 |
mParser.readNext();
|
|
227 |
if (mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
228 |
return;
|
|
229 |
}
|
|
230 |
mComponentDescriptor.translationFilename = mParser.text().toString();
|
|
231 |
}
|
|
232 |
|
93
|
233 |
bool HsWidgetComponentParser::isWidgetTagValid()
|
|
234 |
{
|
|
235 |
return true;
|
|
236 |
}
|