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: HsRuntime provider manifest.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "hsruntimeprovidermanifest.h"
|
|
20 |
#include "hsruntimeprovidermanifest_p.h"
|
|
21 |
#include "hstest_global.h"
|
|
22 |
|
|
23 |
#include <QDomDocument>
|
|
24 |
#include <QFile>
|
|
25 |
|
|
26 |
HsRuntimeProviderManifestPrivate::HsRuntimeProviderManifestPrivate(HsRuntimeProviderManifest* aPublic)
|
|
27 |
: QObject(aPublic),
|
|
28 |
mQ(aPublic),
|
|
29 |
mLoadOnQuery(false)
|
|
30 |
{
|
|
31 |
|
|
32 |
}
|
|
33 |
|
|
34 |
HsRuntimeProviderManifestPrivate::~HsRuntimeProviderManifestPrivate()
|
|
35 |
{
|
|
36 |
|
|
37 |
}
|
|
38 |
|
|
39 |
bool HsRuntimeProviderManifestPrivate::loadFromXml(const QString& aFileName)
|
|
40 |
{
|
|
41 |
mRuntimeTokens.clear();
|
|
42 |
|
|
43 |
QFile file(aFileName);
|
|
44 |
if(!file.exists())
|
|
45 |
{
|
|
46 |
return false;
|
|
47 |
}
|
|
48 |
|
|
49 |
QDomDocument document;
|
|
50 |
if(!document.setContent(&file))
|
|
51 |
{
|
|
52 |
return false;
|
|
53 |
}
|
|
54 |
|
|
55 |
QDomElement element = document.documentElement();
|
|
56 |
if(element.tagName() != "runtimeprovider")
|
|
57 |
{
|
|
58 |
return false;
|
|
59 |
}
|
|
60 |
|
|
61 |
mLoadOnQuery = false;
|
|
62 |
QDomAttr attribute = element.attributeNode("loadonquery");
|
|
63 |
if(attribute.value().toLower() == "true")
|
|
64 |
{
|
|
65 |
mLoadOnQuery = true;
|
|
66 |
}
|
|
67 |
|
|
68 |
QList<HsRuntimeToken> tokens;
|
|
69 |
HsRuntimeToken token;
|
|
70 |
|
|
71 |
QDomNodeList runtimes = element.elementsByTagName("runtime");
|
|
72 |
|
|
73 |
for(int i = 0; i < runtimes.count(); ++i)
|
|
74 |
{
|
|
75 |
element = runtimes.at(i).toElement();
|
|
76 |
token.mLibrary = parseAttribute(element, "library");
|
|
77 |
token.mUri = parseAttribute(element, "uri");
|
|
78 |
tokens << token;
|
|
79 |
}
|
|
80 |
|
|
81 |
mRuntimeTokens = tokens;
|
|
82 |
return true;
|
|
83 |
}
|
|
84 |
|
|
85 |
QList<HsRuntimeToken> HsRuntimeProviderManifestPrivate::runtimes() const
|
|
86 |
{
|
|
87 |
return mRuntimeTokens;
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
QString HsRuntimeProviderManifestPrivate::parseAttribute(QDomElement& aElement,
|
|
94 |
const QString& aAttributeName,
|
|
95 |
bool aIsRequired) const
|
|
96 |
{
|
|
97 |
QDomAttr attribute = aElement.attributeNode(aAttributeName);
|
|
98 |
if(attribute.isNull() || attribute.value().isEmpty())
|
|
99 |
{
|
|
100 |
if(aIsRequired)
|
|
101 |
{
|
|
102 |
HSDEBUG("Required attribute missing")
|
|
103 |
}
|
|
104 |
else
|
|
105 |
{
|
|
106 |
HSDEBUG("Attribute missing")
|
|
107 |
}
|
|
108 |
|
|
109 |
return QString();
|
|
110 |
}
|
|
111 |
|
|
112 |
return attribute.value();
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
/*!
|
|
117 |
\class HsRuntimeProviderManifest
|
|
118 |
\ingroup group_hsruntimemodel
|
|
119 |
\brief Loads home screen HsRuntime tokens from an XML manifest file.
|
|
120 |
Used by the HsRuntimeFactory for loading HsRuntime tokens from an XML
|
|
121 |
manifest file.
|
|
122 |
|
|
123 |
*/
|
|
124 |
|
|
125 |
/*!
|
|
126 |
Constructor. Loads runtimes as HsRuntime tokens from the given
|
|
127 |
manifest file.
|
|
128 |
\a aParent Parent object.
|
|
129 |
*/
|
|
130 |
HsRuntimeProviderManifest::HsRuntimeProviderManifest(QObject* aParent)
|
|
131 |
: QObject(aParent)
|
|
132 |
{
|
|
133 |
mD = new HsRuntimeProviderManifestPrivate(this);
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
/*!
|
|
138 |
Destructor.
|
|
139 |
*/
|
|
140 |
HsRuntimeProviderManifest::~HsRuntimeProviderManifest()
|
|
141 |
{
|
|
142 |
|
|
143 |
}
|
|
144 |
|
|
145 |
/*!
|
|
146 |
return loaded runtimes as HsRuntime tokens.
|
|
147 |
*/
|
|
148 |
QList<HsRuntimeToken> HsRuntimeProviderManifest::runtimes() const
|
|
149 |
{
|
|
150 |
return mD->runtimes();
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
Tells if the HsRuntime tokens must be asked from plugin
|
|
155 |
instead of manifest file.
|
|
156 |
|
|
157 |
return True if loading required, false otherwise.
|
|
158 |
*/
|
|
159 |
bool HsRuntimeProviderManifest::loadOnQuery() const
|
|
160 |
{
|
|
161 |
return mD->mLoadOnQuery;
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
/*!
|
|
166 |
Loads runtimes as HsRuntime tokens from a manifest file.
|
|
167 |
\a aFileName Manifest file name.
|
|
168 |
|
|
169 |
return true if load was succesfull, false otherwise
|
|
170 |
*/
|
|
171 |
bool HsRuntimeProviderManifest::loadFromXml(const QString& aFileName) const
|
|
172 |
{
|
|
173 |
return mD->loadFromXml(aFileName);
|
|
174 |
}
|