|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cppluginconfigreader.h" |
|
19 #include <QFile> |
|
20 #include <QXmlStreamReader> |
|
21 #include <cplogger.h> |
|
22 |
|
23 const QString CHILD_PLUGINS_TAG = "childplugins"; |
|
24 const QString PLUGIN_TAG = "plugin"; |
|
25 const QString PLUGIN_ID_ATTR = "id"; |
|
26 const QString PLUGIN_DLL_ATTR = "dll"; |
|
27 const QString PLUGIN_DISPALYNAME_ATTR = "displayname"; |
|
28 const QString DESC_TAG = "desc"; |
|
29 |
|
30 CpPluginConfigReader::CpPluginConfigReader(const QString &configPath) |
|
31 : mConfigPath (configPath) |
|
32 { |
|
33 } |
|
34 |
|
35 CpPluginConfigReader::~CpPluginConfigReader() |
|
36 { |
|
37 } |
|
38 |
|
39 QList<CpPluginConfig> CpPluginConfigReader::readCpPluginConfigs() |
|
40 { |
|
41 CPFW_LOG(QLatin1String("reading cpcfg file:") + mConfigPath); |
|
42 |
|
43 if (mConfigPath.isNull() || mConfigPath.isEmpty()) { |
|
44 CPFW_LOG("CpPluginConfigReader::readCpPluginConfigs() mConfigPath is empty."); |
|
45 return QList<CpPluginConfig> (); |
|
46 } |
|
47 |
|
48 QFile file(mConfigPath); |
|
49 |
|
50 if (!file.exists()) { |
|
51 CPFW_LOG( mConfigPath + " does not exist."); |
|
52 return QList<CpPluginConfig> (); |
|
53 } |
|
54 |
|
55 if (!file.open(QFile::ReadOnly | QFile::Text)) { |
|
56 CPFW_LOG(QString("CpPluginConfigReader::readCpPluginConfigs() open file failed. Error:%1") |
|
57 .arg(static_cast<int>(file.error()),0,10)); |
|
58 return QList<CpPluginConfig> (); |
|
59 } |
|
60 |
|
61 QXmlStreamReader reader(&file); |
|
62 |
|
63 QList<CpPluginConfig> cpPluginConfigList; |
|
64 |
|
65 readCpPluginConfigs(reader, cpPluginConfigList); |
|
66 |
|
67 file.close(); |
|
68 |
|
69 return cpPluginConfigList; |
|
70 } |
|
71 |
|
72 void CpPluginConfigReader::readCpPluginConfigs(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
|
73 { |
|
74 xmlReader.readNext(); |
|
75 |
|
76 while (!xmlReader.atEnd()) { |
|
77 |
|
78 if (xmlReader.isStartElement()) { |
|
79 if (xmlReader.name() == CHILD_PLUGINS_TAG) { |
|
80 readChildPluginsElement(xmlReader, cpPluginConfigList); |
|
81 } |
|
82 else { |
|
83 xmlReader.raiseError("Not a valid file with the right format."); |
|
84 } |
|
85 } |
|
86 |
|
87 else { |
|
88 xmlReader.readNext(); |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 void CpPluginConfigReader::readChildPluginsElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
|
94 { |
|
95 xmlReader.readNext(); |
|
96 |
|
97 while (!xmlReader.atEnd()) { |
|
98 |
|
99 if (xmlReader.isEndElement()) { |
|
100 xmlReader.readNext(); |
|
101 break; |
|
102 } |
|
103 |
|
104 if (xmlReader.isStartElement()) { |
|
105 if (xmlReader.name() == PLUGIN_TAG) { |
|
106 readPluginElement(xmlReader, cpPluginConfigList); |
|
107 } |
|
108 else { |
|
109 skipUnknownElement(xmlReader); |
|
110 } |
|
111 } |
|
112 |
|
113 else { |
|
114 xmlReader.readNext(); |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 void CpPluginConfigReader::readPluginElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
|
120 { |
|
121 CpPluginConfig cpPluginConfig; |
|
122 |
|
123 QXmlStreamAttributes xmlAttributes = xmlReader.attributes(); |
|
124 |
|
125 if (xmlAttributes.hasAttribute(PLUGIN_ID_ATTR)) { |
|
126 cpPluginConfig.mUid |
|
127 = (xmlAttributes.value(PLUGIN_ID_ATTR)).toString().toUInt(0,16); |
|
128 } |
|
129 |
|
130 if (xmlAttributes.hasAttribute(PLUGIN_DLL_ATTR)) { |
|
131 cpPluginConfig.mPluginFile |
|
132 = (xmlAttributes.value(PLUGIN_DLL_ATTR)).toString(); |
|
133 } |
|
134 |
|
135 if (xmlAttributes.hasAttribute(PLUGIN_DISPALYNAME_ATTR)) { |
|
136 cpPluginConfig.mDisplayName |
|
137 = (xmlAttributes.value(PLUGIN_DISPALYNAME_ATTR)).toString(); |
|
138 } |
|
139 |
|
140 readDescElement(xmlReader,cpPluginConfig); |
|
141 |
|
142 cpPluginConfig.dump(); |
|
143 |
|
144 cpPluginConfigList.append(cpPluginConfig); |
|
145 } |
|
146 |
|
147 void CpPluginConfigReader::readDescElement(QXmlStreamReader &xmlReader,CpPluginConfig &cpPluginConfig) |
|
148 { |
|
149 xmlReader.readNext(); |
|
150 |
|
151 while (!xmlReader.atEnd()) { |
|
152 |
|
153 if (xmlReader.isEndElement()) { |
|
154 xmlReader.readNext(); |
|
155 break; |
|
156 } |
|
157 |
|
158 if (xmlReader.isStartElement()) { |
|
159 if (xmlReader.name() == DESC_TAG) { |
|
160 cpPluginConfig.mDescription = xmlReader.readElementText(); |
|
161 if (xmlReader.isEndElement()) { |
|
162 xmlReader.readNext(); |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 else { |
|
168 xmlReader.readNext(); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 void CpPluginConfigReader::skipUnknownElement(QXmlStreamReader &xmlReader) |
|
174 { |
|
175 xmlReader.readNext(); |
|
176 |
|
177 while (!xmlReader.atEnd()) { |
|
178 |
|
179 if (xmlReader.isEndElement()) { |
|
180 xmlReader.readNext(); |
|
181 break; |
|
182 } |
|
183 |
|
184 if (xmlReader.isStartElement()) { |
|
185 skipUnknownElement(xmlReader); |
|
186 } |
|
187 else { |
|
188 xmlReader.readNext(); |
|
189 } |
|
190 } |
|
191 } |