25 const QString PLUGIN_ID_ATTR = "id"; |
25 const QString PLUGIN_ID_ATTR = "id"; |
26 const QString PLUGIN_DLL_ATTR = "dll"; |
26 const QString PLUGIN_DLL_ATTR = "dll"; |
27 const QString PLUGIN_DISPALYNAME_ATTR = "displayname"; |
27 const QString PLUGIN_DISPALYNAME_ATTR = "displayname"; |
28 const QString DESC_TAG = "desc"; |
28 const QString DESC_TAG = "desc"; |
29 |
29 |
|
30 /* |
|
31 * Constructor. |
|
32 * @configPath : the full path of the config file. |
|
33 */ |
30 CpPluginConfigReader::CpPluginConfigReader(const QString &configPath) |
34 CpPluginConfigReader::CpPluginConfigReader(const QString &configPath) |
31 : mConfigPath (configPath) |
35 : mConfigPath (configPath) |
32 { |
36 { |
33 } |
37 } |
34 |
38 |
|
39 /* |
|
40 * Desctructor |
|
41 */ |
35 CpPluginConfigReader::~CpPluginConfigReader() |
42 CpPluginConfigReader::~CpPluginConfigReader() |
36 { |
43 { |
37 } |
44 } |
38 |
45 |
|
46 /* |
|
47 * Reads a cpcfg file, returns a list of CpPluginConfig. |
|
48 */ |
39 QList<CpPluginConfig> CpPluginConfigReader::readCpPluginConfigs() |
49 QList<CpPluginConfig> CpPluginConfigReader::readCpPluginConfigs() |
40 { |
50 { |
41 CPFW_LOG(QLatin1String("reading cpcfg file:") + mConfigPath); |
51 CPFW_LOG(QLatin1String("reading cpcfg file:") + mConfigPath); |
42 |
52 |
|
53 // Empty config file |
43 if (mConfigPath.isNull() || mConfigPath.isEmpty()) { |
54 if (mConfigPath.isNull() || mConfigPath.isEmpty()) { |
44 CPFW_LOG("CpPluginConfigReader::readCpPluginConfigs() mConfigPath is empty."); |
55 CPFW_LOG("CpPluginConfigReader::readCpPluginConfigs() mConfigPath is empty."); |
45 return QList<CpPluginConfig> (); |
56 return QList<CpPluginConfig> (); |
46 } |
57 } |
47 |
58 |
48 QFile file(mConfigPath); |
59 QFile file(mConfigPath); |
49 |
60 |
|
61 // Config file doesn't exist |
50 if (!file.exists()) { |
62 if (!file.exists()) { |
51 CPFW_LOG( mConfigPath + " does not exist."); |
63 CPFW_LOG( mConfigPath + " does not exist."); |
52 return QList<CpPluginConfig> (); |
64 return QList<CpPluginConfig> (); |
53 } |
65 } |
54 |
66 |
|
67 // Open config file failed |
55 if (!file.open(QFile::ReadOnly | QFile::Text)) { |
68 if (!file.open(QFile::ReadOnly | QFile::Text)) { |
56 CPFW_LOG(QString("CpPluginConfigReader::readCpPluginConfigs() open file failed. Error:%1") |
69 CPFW_LOG(QString("CpPluginConfigReader::readCpPluginConfigs() open file failed. Error:%1") |
57 .arg(static_cast<int>(file.error()),0,10)); |
70 .arg(static_cast<int>(file.error()),0,10)); |
58 return QList<CpPluginConfig> (); |
71 return QList<CpPluginConfig> (); |
59 } |
72 } |
67 file.close(); |
80 file.close(); |
68 |
81 |
69 return cpPluginConfigList; |
82 return cpPluginConfigList; |
70 } |
83 } |
71 |
84 |
|
85 /* |
|
86 * Read a list of CpPluginConfig from a xml stream. |
|
87 */ |
72 void CpPluginConfigReader::readCpPluginConfigs(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
88 void CpPluginConfigReader::readCpPluginConfigs(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
73 { |
89 { |
74 xmlReader.readNext(); |
90 xmlReader.readNext(); |
75 |
91 |
76 while (!xmlReader.atEnd()) { |
92 while (!xmlReader.atEnd()) { |
77 |
93 |
78 if (xmlReader.isStartElement()) { |
94 if (xmlReader.isStartElement()) { |
|
95 // Read <childplugins> node |
79 if (xmlReader.name() == CHILD_PLUGINS_TAG) { |
96 if (xmlReader.name() == CHILD_PLUGINS_TAG) { |
80 readChildPluginsElement(xmlReader, cpPluginConfigList); |
97 readChildPluginsElement(xmlReader, cpPluginConfigList); |
81 } |
98 } |
82 else { |
99 else { |
83 xmlReader.raiseError("Not a valid file with the right format."); |
100 xmlReader.raiseError("Not a valid file with the right format."); |
100 xmlReader.readNext(); |
120 xmlReader.readNext(); |
101 break; |
121 break; |
102 } |
122 } |
103 |
123 |
104 if (xmlReader.isStartElement()) { |
124 if (xmlReader.isStartElement()) { |
|
125 // Read <plugin> node |
105 if (xmlReader.name() == PLUGIN_TAG) { |
126 if (xmlReader.name() == PLUGIN_TAG) { |
106 readPluginElement(xmlReader, cpPluginConfigList); |
127 readPluginElement(xmlReader, cpPluginConfigList); |
107 } |
128 } |
|
129 // Skip invalid node |
108 else { |
130 else { |
109 skipUnknownElement(xmlReader); |
131 skipUnknownElement(xmlReader); |
110 } |
132 } |
111 } |
133 } |
112 |
134 |
114 xmlReader.readNext(); |
136 xmlReader.readNext(); |
115 } |
137 } |
116 } |
138 } |
117 } |
139 } |
118 |
140 |
|
141 /* |
|
142 * Read <plugin> node. |
|
143 */ |
119 void CpPluginConfigReader::readPluginElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
144 void CpPluginConfigReader::readPluginElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList) |
120 { |
145 { |
121 CpPluginConfig cpPluginConfig; |
146 CpPluginConfig cpPluginConfig; |
122 |
147 |
123 QXmlStreamAttributes xmlAttributes = xmlReader.attributes(); |
148 QXmlStreamAttributes xmlAttributes = xmlReader.attributes(); |
124 |
149 |
|
150 // Read <id> attribute |
125 if (xmlAttributes.hasAttribute(PLUGIN_ID_ATTR)) { |
151 if (xmlAttributes.hasAttribute(PLUGIN_ID_ATTR)) { |
126 cpPluginConfig.mUid |
152 cpPluginConfig.mUid |
127 = (xmlAttributes.value(PLUGIN_ID_ATTR)).toString().toUInt(0,16); |
153 = (xmlAttributes.value(PLUGIN_ID_ATTR)).toString().toUInt(0,16); |
128 } |
154 } |
129 |
155 |
|
156 // Read <dll> attribute |
130 if (xmlAttributes.hasAttribute(PLUGIN_DLL_ATTR)) { |
157 if (xmlAttributes.hasAttribute(PLUGIN_DLL_ATTR)) { |
131 cpPluginConfig.mPluginFile |
158 cpPluginConfig.mPluginFile |
132 = (xmlAttributes.value(PLUGIN_DLL_ATTR)).toString(); |
159 = (xmlAttributes.value(PLUGIN_DLL_ATTR)).toString(); |
133 } |
160 } |
134 |
161 |
|
162 // Read <displayname> attribute |
135 if (xmlAttributes.hasAttribute(PLUGIN_DISPALYNAME_ATTR)) { |
163 if (xmlAttributes.hasAttribute(PLUGIN_DISPALYNAME_ATTR)) { |
136 cpPluginConfig.mDisplayName |
164 cpPluginConfig.mDisplayName |
137 = (xmlAttributes.value(PLUGIN_DISPALYNAME_ATTR)).toString(); |
165 = (xmlAttributes.value(PLUGIN_DISPALYNAME_ATTR)).toString(); |
138 } |
166 } |
139 |
167 |
|
168 // Read <description> node |
140 readDescElement(xmlReader,cpPluginConfig); |
169 readDescElement(xmlReader,cpPluginConfig); |
141 |
170 |
|
171 #ifdef ENABLE_CPFW_LOG |
142 cpPluginConfig.dump(); |
172 cpPluginConfig.dump(); |
|
173 #endif |
143 |
174 |
144 cpPluginConfigList.append(cpPluginConfig); |
175 cpPluginConfigList.append(cpPluginConfig); |
145 } |
176 } |
146 |
177 |
|
178 /* |
|
179 * Read <description> node. |
|
180 */ |
147 void CpPluginConfigReader::readDescElement(QXmlStreamReader &xmlReader,CpPluginConfig &cpPluginConfig) |
181 void CpPluginConfigReader::readDescElement(QXmlStreamReader &xmlReader,CpPluginConfig &cpPluginConfig) |
148 { |
182 { |
149 xmlReader.readNext(); |
183 xmlReader.readNext(); |
150 |
184 |
151 while (!xmlReader.atEnd()) { |
185 while (!xmlReader.atEnd()) { |
154 xmlReader.readNext(); |
188 xmlReader.readNext(); |
155 break; |
189 break; |
156 } |
190 } |
157 |
191 |
158 if (xmlReader.isStartElement()) { |
192 if (xmlReader.isStartElement()) { |
|
193 // valid description node |
159 if (xmlReader.name() == DESC_TAG) { |
194 if (xmlReader.name() == DESC_TAG) { |
160 cpPluginConfig.mDescription = xmlReader.readElementText(); |
195 cpPluginConfig.mDescription = xmlReader.readElementText(); |
161 if (xmlReader.isEndElement()) { |
196 if (xmlReader.isEndElement()) { |
162 xmlReader.readNext(); |
197 xmlReader.readNext(); |
163 } |
198 } |
164 } |
199 } |
165 } |
200 // invalid node, skip it |
166 |
201 else { |
167 else { |
202 skipUnknownElement(xmlReader); |
168 xmlReader.readNext(); |
203 } |
169 } |
204 } |
170 } |
205 |
171 } |
206 else { |
172 |
207 xmlReader.readNext(); |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 /* |
|
213 * ignore invalid node. |
|
214 */ |
173 void CpPluginConfigReader::skipUnknownElement(QXmlStreamReader &xmlReader) |
215 void CpPluginConfigReader::skipUnknownElement(QXmlStreamReader &xmlReader) |
174 { |
216 { |
175 xmlReader.readNext(); |
217 xmlReader.readNext(); |
176 |
218 |
177 while (!xmlReader.atEnd()) { |
219 while (!xmlReader.atEnd()) { |