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";
|
|
32 |
const char VERSION[] = "version";
|
|
33 |
const char VERSION_1_0[] = "1.0";
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
HsWidgetComponentParser::HsWidgetComponentParser(const QString &aComponentManifest, QObject *parent)
|
|
38 |
: QObject(parent),mError(false)
|
|
39 |
{
|
|
40 |
parseFile(aComponentManifest);
|
|
41 |
}
|
|
42 |
|
|
43 |
HsWidgetComponentParser::~HsWidgetComponentParser()
|
|
44 |
{
|
|
45 |
|
|
46 |
}
|
|
47 |
|
|
48 |
HsWidgetComponentDescriptor HsWidgetComponentParser::widgetComponentDescriptor()
|
|
49 |
{
|
|
50 |
return mComponentDescriptor;
|
|
51 |
}
|
|
52 |
|
|
53 |
bool HsWidgetComponentParser::error()
|
|
54 |
{
|
|
55 |
return mError;
|
|
56 |
}
|
|
57 |
|
|
58 |
void HsWidgetComponentParser::parseFile(const QString &aComponentManifest)
|
|
59 |
{
|
|
60 |
QFile file(aComponentManifest);
|
|
61 |
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
62 |
mError = false;
|
|
63 |
return;
|
|
64 |
}
|
|
65 |
mParser.setDevice(&file);
|
|
66 |
if (mParser.readNextStartElement()) {
|
|
67 |
if (mParser.name() == WIDGETMANIFEST){
|
|
68 |
parseWidgetManifestTag();
|
|
69 |
} else if(mParser.name() == WIDGETPROVIDER){
|
|
70 |
parseWidgetProviderTag();
|
|
71 |
} else {
|
|
72 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
73 |
}
|
|
74 |
} else {
|
|
75 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
76 |
}
|
|
77 |
mError = mParser.error();
|
|
78 |
|
|
79 |
}
|
|
80 |
|
|
81 |
void HsWidgetComponentParser::parseWidgetManifestTag()
|
|
82 |
{
|
|
83 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETMANIFEST);
|
|
84 |
|
|
85 |
/* Detect version */
|
|
86 |
if (mParser.attributes().hasAttribute(VERSION)) {
|
|
87 |
QStringRef version = mParser.attributes().value(VERSION);
|
|
88 |
mComponentDescriptor.version = version.toString();
|
|
89 |
if (version == VERSION_1_0) {
|
|
90 |
parseVersion1_0();
|
|
91 |
}
|
|
92 |
} else {
|
|
93 |
// newest is default
|
|
94 |
parseVersion1_0();
|
|
95 |
mComponentDescriptor.version = VERSION_1_0;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
void HsWidgetComponentParser::parseWidgetProviderTag()
|
|
100 |
{
|
|
101 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETPROVIDER);
|
|
102 |
if (!mParser.readNextStartElement() || mParser.name() != WIDGET) {
|
|
103 |
mParser.raiseError(QObject::tr("Malformed manifest"));
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
|
|
107 |
// everything is in attributes
|
|
108 |
QXmlStreamAttributes attrs = mParser.attributes();
|
|
109 |
foreach (QXmlStreamAttribute attr, attrs) {
|
|
110 |
QStringRef name = attr.name();
|
|
111 |
if (name == URI) {
|
|
112 |
mComponentDescriptor.uri = attr.value().toString();
|
|
113 |
} else if (name == ICONURI) {
|
|
114 |
mComponentDescriptor.iconUri = attr.value().toString();
|
|
115 |
} else if (name == TITLE) {
|
|
116 |
mComponentDescriptor.title = attr.value().toString();
|
|
117 |
} else if (name == DESCRIPTION) {
|
|
118 |
mComponentDescriptor.description = attr.value().toString();
|
|
119 |
} else if (name == HIDDEN) {
|
|
120 |
mComponentDescriptor.hidden = attr.value().toString();
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
}
|
|
125 |
void HsWidgetComponentParser::parseVersion1_0()
|
|
126 |
{
|
|
127 |
Q_ASSERT(mParser.isStartElement() && mParser.name() == WIDGETMANIFEST);
|
|
128 |
/* We'll parse the XML until we reach </hswidgetmanifest> tag, end of cml or have an error. */
|
|
129 |
while( !(mParser.tokenType() == QXmlStreamReader::EndElement && mParser.name() == WIDGETMANIFEST) &&
|
|
130 |
!mParser.hasError() && !mParser.atEnd()) {
|
|
131 |
|
|
132 |
mParser.readNext();
|
|
133 |
if (mParser.tokenType() != QXmlStreamReader::StartElement) {
|
|
134 |
continue;
|
|
135 |
}
|
|
136 |
/* Read next start element.*/
|
|
137 |
QStringRef tag = mParser.name();
|
|
138 |
if(tag == URI) {
|
|
139 |
parseUri();
|
|
140 |
} else if (tag == ICON) {
|
|
141 |
parseIcon();
|
|
142 |
} else if (tag == TITLE) {
|
|
143 |
parseTitle();
|
|
144 |
} else if (tag == DESCRIPTION) {
|
|
145 |
parseDescription();
|
|
146 |
} else if (tag == HIDDEN) {
|
|
147 |
parseHidden();
|
|
148 |
} else if (tag == SERVICEXML) {
|
|
149 |
parseServiceXml();
|
|
150 |
}
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
void HsWidgetComponentParser::parseUri()
|
|
156 |
{
|
|
157 |
mParser.readNext();
|
|
158 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
159 |
return;
|
|
160 |
}
|
|
161 |
mComponentDescriptor.uri = mParser.text().toString();
|
|
162 |
}
|
|
163 |
void HsWidgetComponentParser::parseIcon()
|
|
164 |
{
|
|
165 |
mParser.readNext();
|
|
166 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
167 |
return;
|
|
168 |
}
|
|
169 |
mComponentDescriptor.iconUri = mParser.text().toString();
|
|
170 |
}
|
|
171 |
void HsWidgetComponentParser::parseTitle()
|
|
172 |
{
|
|
173 |
mParser.readNext();
|
|
174 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
175 |
return;
|
|
176 |
}
|
|
177 |
mComponentDescriptor.title = mParser.text().toString();
|
|
178 |
}
|
|
179 |
void HsWidgetComponentParser::parseDescription()
|
|
180 |
{
|
|
181 |
mParser.readNext();
|
|
182 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
183 |
return;
|
|
184 |
}
|
|
185 |
mComponentDescriptor.description = mParser.text().toString();
|
|
186 |
}
|
|
187 |
void HsWidgetComponentParser::parseHidden()
|
|
188 |
{
|
|
189 |
mParser.readNext();
|
|
190 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
191 |
return;
|
|
192 |
}
|
|
193 |
mComponentDescriptor.hidden = mParser.text().toString();
|
|
194 |
}
|
|
195 |
void HsWidgetComponentParser::parseServiceXml()
|
|
196 |
{
|
|
197 |
mParser.readNext();
|
|
198 |
if(mParser.tokenType() != QXmlStreamReader::Characters) {
|
|
199 |
return;
|
|
200 |
}
|
|
201 |
mComponentDescriptor.serviceXml = mParser.text().toString();
|
|
202 |
}
|
|
203 |
|
|
204 |
bool HsWidgetComponentParser::isWidgetTagValid()
|
|
205 |
{
|
|
206 |
return true;
|
|
207 |
}
|