85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: HsWidget provider manifest.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QDomDocument>
|
|
19 |
#include <QFile>
|
|
20 |
|
|
21 |
#include "hswidgetprovidermanifest.h"
|
|
22 |
#include "hswidgetprovidermanifest_p.h"
|
|
23 |
#include "hstest_global.h"
|
|
24 |
|
|
25 |
|
98
|
26 |
/*DEPRECATED
|
85
|
27 |
\class HsWidgetProviderManifest
|
|
28 |
\ingroup group_hswidgetmodel
|
|
29 |
\brief Loads home screen widget tokens from an XML manifest file.
|
|
30 |
|
|
31 |
Used by the HsWidgetFactory for loading widget tokens from an XML
|
|
32 |
manifest file.
|
|
33 |
|
|
34 |
*/
|
|
35 |
|
|
36 |
|
|
37 |
HsWidgetProviderManifestPrivate::HsWidgetProviderManifestPrivate(
|
|
38 |
HsWidgetProviderManifest *handle):
|
|
39 |
mPublic(handle),
|
|
40 |
mLoadOnQuery(false)
|
|
41 |
{
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
HsWidgetProviderManifestPrivate::~HsWidgetProviderManifestPrivate()
|
|
46 |
{
|
|
47 |
|
|
48 |
}
|
|
49 |
|
|
50 |
QList<HsWidgetToken> HsWidgetProviderManifestPrivate::widgets() const
|
|
51 |
{
|
|
52 |
return mWidgetTokens;
|
|
53 |
}
|
|
54 |
|
|
55 |
bool HsWidgetProviderManifestPrivate::loadFromXml(const QString &fileName)
|
|
56 |
{
|
|
57 |
mWidgetTokens.clear();
|
|
58 |
|
|
59 |
QFile file(fileName);
|
|
60 |
if (!file.exists()) {
|
|
61 |
return false;
|
|
62 |
}
|
|
63 |
|
|
64 |
QDomDocument document;
|
|
65 |
if (!document.setContent(&file)) {
|
|
66 |
return false;
|
|
67 |
}
|
|
68 |
|
|
69 |
QDomElement element = document.documentElement();
|
|
70 |
if (element.tagName() != "widgetprovider") {
|
|
71 |
return false;
|
|
72 |
}
|
|
73 |
|
|
74 |
mLoadOnQuery = false;
|
|
75 |
QDomAttr attribute = element.attributeNode("loadonquery");
|
|
76 |
if (attribute.value().toLower() == "true") {
|
|
77 |
mLoadOnQuery = true;
|
|
78 |
}
|
|
79 |
|
|
80 |
QList<HsWidgetToken> tokens;
|
|
81 |
HsWidgetToken token;
|
|
82 |
|
|
83 |
QDomNodeList widgets = element.elementsByTagName("widget");
|
|
84 |
|
|
85 |
bool required(true);
|
|
86 |
|
|
87 |
if (mLoadOnQuery) {
|
|
88 |
required = false;
|
|
89 |
}
|
|
90 |
|
|
91 |
for(int i = 0; i < widgets.count(); ++i) {
|
|
92 |
element = widgets.at(i).toElement();
|
|
93 |
token.mLibrary = parseAttribute(element, "library");
|
|
94 |
token.mUri = parseAttribute(element, "uri");
|
|
95 |
token.mTitle = parseAttribute(element, "title", required);
|
|
96 |
token.mIconUri = parseAttribute(element, "iconuri", false);
|
|
97 |
token.mDescription = parseAttribute(element, "description");
|
|
98 |
tokens << token;
|
|
99 |
}
|
|
100 |
|
|
101 |
mWidgetTokens = tokens;
|
|
102 |
|
|
103 |
return true;
|
|
104 |
}
|
|
105 |
|
|
106 |
QString HsWidgetProviderManifestPrivate::parseAttribute(
|
|
107 |
QDomElement &element,
|
|
108 |
const QString &attributeName,
|
|
109 |
bool isRequired) const
|
|
110 |
{
|
|
111 |
QDomAttr attribute = element.attributeNode(attributeName);
|
|
112 |
if (attribute.isNull() || attribute.value().isEmpty()) {
|
|
113 |
if (isRequired) {
|
|
114 |
HSDEBUG("Required attribute missing")
|
|
115 |
return QString();
|
|
116 |
}
|
|
117 |
else {
|
|
118 |
return QString();
|
|
119 |
}
|
|
120 |
}
|
|
121 |
return attribute.value();
|
|
122 |
}
|
|
123 |
|
|
124 |
/*!
|
|
125 |
\fn HsWidgetProviderManifest::HsWidgetProviderManifest(QObject* aParent)
|
|
126 |
|
|
127 |
Constructor
|
|
128 |
*/
|
|
129 |
HsWidgetProviderManifest::HsWidgetProviderManifest(QObject *parent)
|
|
130 |
: QObject(parent),
|
|
131 |
mD(new HsWidgetProviderManifestPrivate(this))
|
|
132 |
{
|
|
133 |
}
|
|
134 |
|
|
135 |
/*!
|
|
136 |
\fn HsWidgetProviderManifest::~HsWidgetProviderManifest()
|
|
137 |
|
|
138 |
Destructor
|
|
139 |
*/
|
|
140 |
HsWidgetProviderManifest::~HsWidgetProviderManifest()
|
|
141 |
{
|
|
142 |
delete mD;
|
|
143 |
}
|
|
144 |
|
|
145 |
/*!
|
|
146 |
\fn QList<HsWidgetToken> HsWidgetProviderManifest::widgets() const
|
|
147 |
|
|
148 |
Returns widget tokens found from manifest
|
|
149 |
*/
|
|
150 |
QList<HsWidgetToken> HsWidgetProviderManifest::widgets() const
|
|
151 |
{
|
|
152 |
return mD->widgets();
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
|
156 |
\fn bool HsWidgetProviderManifest::loadOnQuery() const
|
|
157 |
|
|
158 |
Returns whether widget tokens should be quered dynamically
|
|
159 |
*/
|
|
160 |
bool HsWidgetProviderManifest::loadOnQuery() const
|
|
161 |
{
|
|
162 |
return mD->mLoadOnQuery;
|
|
163 |
}
|
|
164 |
|
|
165 |
/*!
|
|
166 |
\fn bool HsWidgetProviderManifest::loadFromXml(const QString& aFileName)
|
|
167 |
|
|
168 |
Returns true if given \a fileName manifest parsing succeeded
|
|
169 |
*/
|
|
170 |
bool HsWidgetProviderManifest::loadFromXml(const QString &fileName)
|
|
171 |
{
|
|
172 |
return mD->loadFromXml(fileName);
|
|
173 |
}
|
|
174 |
|