1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the utils of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
52 QDomElement
find(const QString
&tagName
, const QDomElement
&e
)
54 QDomNodeList children
= e
.childNodes();
55 for (int i
= 0; i
< children
.size(); ++i
) {
56 const QDomNode
&n
= children
.at(i
);
58 QDomElement c
= n
.toElement();
59 if (c
.tagName() == tagName
)
66 QString
parseVariant(const QDomElement
&e
)
68 QDomElement configItem
= find("configItem", e
);
69 return find("name", configItem
).text();
72 QStringList
findVariants(const QDomElement
&e
)
76 QDomNodeList children
= e
.childNodes();
77 for (int i
= 0; i
< children
.size(); ++i
) {
78 const QDomNode
&n
= children
.at(i
);
80 variants
+= parseVariant(n
.toElement());
86 XKBLayout
parseLayout(const QDomElement
&e
)
88 QDomElement configItem
= find("configItem", e
);
91 layout
.name
= find("name", configItem
).text();
92 layout
.description
= find("description", configItem
).text();
94 QDomElement variantList
= find("variantList", e
);
95 if (!variantList
.isNull())
96 layout
.variants
= findVariants(variantList
);
101 QList
<XKBLayout
> findLayouts(const QDomElement
&layoutList
)
103 QList
<XKBLayout
> layouts
;
105 QDomNodeList children
= layoutList
.childNodes();
106 for (int i
= 0; i
< children
.size(); ++i
) {
107 const QDomNode
&n
= children
.at(i
);
109 layouts
+= parseLayout(n
.toElement());
115 QString
mapCountry(const QString
&v
)
117 static QMap
<QString
, QString
> map
;
118 static bool initialized
= false;
120 map
["U.S. English"] = "UnitedStates";
121 map
["PC-98xx Series"] = "Japan";
122 map
["Bosnia and Herzegovina"] = "BosniaAndHerzegowina";
123 map
["Czechia"] = "CzechRepublic";
124 map
["Faroe Islands"] = "FaroeIslands";
126 map
["Latin American"] = "Mexico";
127 map
["Russia"] = "RussianFederation";
128 map
["Syria"] = "SyrianArabRepublic";
129 map
["Sri Lanka"] = "SriLanka";
130 map
["United Kingdom"] = "UnitedKingdom";
131 map
["Vietnam"] = "VietNam";
132 map
["Macedonian"] = "Macedonia";
133 map
["Serbian"] = "SerbiaAndMontenegro";
134 map
["Turkish "] = "Turkey";
135 map
["Maori"] = "NewZealand";
136 map
["Arabic"] = "UnitedArabEmirates";
139 return map
.value(v
, v
);
142 QString
mapLanguage(const QString
&v
)
144 static QMap
<QString
, QString
> map
;
145 static bool initialized
= false;
147 map
["us"] = "English";
148 map
["us:intl"] = "English";
149 map
["us:alt-intl"] = "English";
150 map
["us:dvorak"] = "English";
151 map
["us:rus"] = "Russian";
152 map
["ara"] = "Arabic";
153 map
["ara:azerty"] = "Arabic";
154 map
["ara:azerty_digits"] = "Arabic";
155 map
["ara:digits"] = "Arabic";
156 map
["ara:qwerty"] = "Arabic";
157 map
["ara:qwerty_digits"] = "Arabic";
158 map
["al"] = "Albanian";
159 map
["am"] = "Armenian";
160 map
["am:phonetic"] = "Armenian";
161 map
["az"] = "Azerbaijani";
162 map
["az:cyrillic"] = "Azerbaijani";
163 map
["by"] = "Byelorussian";
164 map
["by:winkeys"] = "Byelorussian";
166 map
["be:iso-alternate"] = "Dutch";
167 map
["be:nodeadkeys"] = "Dutch";
168 map
["be:sundeadkeys"] = "Dutch";
169 map
["bd"] = "Bengali";
170 map
["bd:probhat"] = "Bengali";
172 map
["in:ben"] = "Bengali";
173 map
["in:ben_probhat"] = "Bengali";
174 map
["in:guj"] = "Gujarati";
175 map
["in:guru"] = "Punjabi";
176 map
["in:kan"] = "Kannada";
177 map
["in:mal"] = "Malayalam";
178 map
["in:ori"] = "Oriya";
179 map
["in:tam_unicode"] = "Tamil";
180 map
["in:tam_TAB"] = "Tamil";
181 map
["in:tam_TSCII"] = "Tamil";
182 map
["in:tam"] = "Tamil";
183 map
["in:tel"] = "Telugu";
184 map
["in:urd"] = "Urdu";
185 map
["ba"] = "Bosnian";
186 map
["br"] = "Portuguese";
187 map
["br:nodeadkeys"] = "Portuguese";
188 map
["bg"] = "Bulgarian";
189 map
["bg:phonetic"] = "Bulgarian";
190 map
["mm"] = "Burmese";
191 map
["ca"] = "English";
192 map
["ca:fr-dvorak"] = "French";
193 map
["ca:fr-legacy"] = "French";
194 map
["ca:multi"] = "English";
195 map
["ca:multi-2gr"] = "English";
196 map
["ca:ike"] = "Inuktitut";
197 map
["hr"] = "Croatian";
198 map
["hr:us"] = "Croatian";
200 map
["cz:bksl"] = "Czech";
201 map
["cz:qwerty"] = "Czech";
202 map
["cz:qwerty_bksl"] = "Czech";
203 map
["dk"] = "Danish";
204 map
["dk:nodeadkeys"] = "Danish";
206 map
["bt"] = "Bhutani";
207 map
["ee"] = "Estonian";
208 map
["ee:nodeadkeys"] = "Estonian";
209 map
["ir"] = "Persian";
210 map
["fo"] = "Faroese";
211 map
["fo:nodeadkeys"] = "Faroese";
212 map
["fi"] = "Finnish";
213 map
["fi:nodeadkeys"] = "Finnish";
214 map
["fi:smi"] = "Finnish";
215 map
["fr"] = "French";
216 map
["fr:nodeadkeys"] = "French";
217 map
["fr:sundeadkeys"] = "French";
218 map
["fr:latin9"] = "French";
219 map
["fr:latin9_nodeadkeys"] = "French";
220 map
["fr:latin9_sundeadkeys"] = "French";
221 map
["fr:dvorak"] = "French";
222 map
["ge"] = "Georgian";
223 map
["ge:ru"] = "Russian";
224 map
["de"] = "German";
225 map
["de:deadacute"] = "German";
226 map
["de:deadgraveacute"] = "German";
227 map
["de:nodeadkeys"] = "German";
228 map
["de:ro"] = "Romanian";
229 map
["de:ro_nodeadkeys"] = "Romanian";
230 map
["de:dvorak"] = "German";
232 map
["gr:extended"] = "Greek";
233 map
["gr:nodeadkeys"] = "Greek";
234 map
["gr:polytonic"] = "Greek";
235 map
["hu"] = "Hungarian";
236 map
["hu:standard"] = "Hungarian";
237 map
["hu:nodeadkeys"] = "Hungarian";
238 map
["hu:qwerty"] = "Hungarian";
239 map
["hu:101_qwertz_comma_dead"] = "Hungarian";
240 map
["hu:101_qwertz_comma_nodead"] = "Hungarian";
241 map
["hu:101_qwertz_dot_dead"] = "Hungarian";
242 map
["hu:101_qwertz_dot_nodead"] = "Hungarian";
243 map
["hu:101_qwerty_comma_dead"] = "Hungarian";
244 map
["hu:101_qwerty_comma_nodead"] = "Hungarian";
245 map
["hu:101_qwerty_dot_dead"] = "Hungarian";
246 map
["hu:101_qwerty_dot_nodead"] = "Hungarian";
247 map
["hu:102_qwertz_comma_dead"] = "Hungarian";
248 map
["hu:102_qwertz_comma_nodead"] = "Hungarian";
249 map
["hu:102_qwertz_dot_dead"] = "Hungarian";
250 map
["hu:102_qwertz_dot_nodead"] = "Hungarian";
251 map
["hu:102_qwerty_comma_dead"] = "Hungarian";
252 map
["hu:102_qwerty_comma_nodead"] = "Hungarian";
253 map
["hu:102_qwerty_dot_dead"] = "Hungarian";
254 map
["hu:102_qwerty_dot_nodead"] = "Hungarian";
255 map
["is"] = "Icelandic";
256 map
["is:Sundeadkeys"] = "Icelandic";
257 map
["is:nodeadkeys"] = "Icelandic";
258 map
["il"] = "Hebrew";
259 map
["il:lyx"] = "Hebrew";
260 map
["il:si1452"] = "Hebrew";
261 map
["il:phonetic"] = "Hebrew";
262 map
["it"] = "Italian";
263 map
["it:nodeadkeys"] = "Italian";
264 map
["jp"] = "Japanese";
265 map
["kg"] = "Kirghiz";
266 map
["la"] = "Laothian";
267 map
["latam"] = "Spanish";
268 map
["latam:nodeadkeys"] = "Spanish";
269 map
["latam:sundeadkeys"] = "Spanish";
270 map
["lt"] = "Lithuanian";
271 map
["lt:std"] = "Lithuanian";
272 map
["lt:us"] = "Lithuanian";
273 map
["lv"] = "Latvian";
274 map
["lv:apostrophe"] = "Latvian";
275 map
["lv:tilde"] = "Latvian";
276 map
["lv:fkey"] = "Latvian";
277 map
["mao"] = "Maori";
278 map
["mkd"] = "Macedonian";
279 map
["mkd:nodeadkeys"] = "Macedonian";
280 map
["mt"] = "Maltese";
281 map
["mt:us"] = "Maltese";
282 map
["mn"] = "Mongolian";
283 map
["no"] = "Norwegian";
284 map
["no:nodeadkeys"] = "Norwegian";
285 map
["no:dvorak"] = "Norwegian";
286 map
["no:smi"] = "Norwegian";
287 map
["no:smi_nodeadkeys"] = "Norwegian";
288 map
["pl"] = "Polish";
289 map
["pl:qwertz"] = "Polish";
290 map
["pl:dvorak"] = "Polish";
291 map
["pl:dvorak_quotes"] = "Polish";
292 map
["pl:dvorak_altquotes"] = "Polish";
293 map
["pt"] = "Portuguese";
294 map
["pt:nodeadkeys"] = "Portuguese";
295 map
["pt:sundeadkeys"] = "Portuguese";
296 map
["ro"] = "Romanian";
297 map
["ro:us"] = "English";
298 map
["ro:de"] = "German";
299 map
["ru"] = "Russian";
300 map
["ru:phonetic"] = "Russian";
301 map
["ru:typewriter"] = "Russian";
302 map
["ru:winkeys"] = "Russian";
303 map
["srp"] = "Serbian";
304 map
["srp:yz"] = "Serbian";
305 map
["srp:latin"] = "Serbian";
306 map
["srp:latinunicode"] = "Serbian";
307 map
["srp:latinyz"] = "Serbian";
308 map
["srp:latinunicodeyz"] = "Serbian";
309 map
["srp:alternatequotes"] = "Serbian";
310 map
["srp:latinalternatequotes"] = "Serbian";
311 map
["si"] = "Slovenian";
312 map
["sk"] = "Slovak";
313 map
["sk:bksl"] = "Slovak";
314 map
["sk:qwerty"] = "Slovak";
315 map
["sk:qwerty_bksl"] = "Slovak";
316 map
["es"] = "Spanish";
317 map
["es:nodeadkeys"] = "Spanish";
318 map
["es:sundeadkeys"] = "Spanish";
319 map
["es:dvorak"] = "Spanish";
320 map
["se"] = "Swedish";
321 map
["se:nodeadkeys"] = "Swedish";
322 map
["se:dvorak"] = "Swedish";
323 map
["se:rus"] = "Russian";
324 map
["se:rus_nodeadkeys"] = "Russian";
325 map
["se:smi"] = "Swedish";
326 map
["ch"] = "German";
327 map
["ch:de_nodeadkeys"] = "German";
328 map
["ch:de_sundeadkeys"] = "German";
329 map
["ch:fr"] = "French";
330 map
["ch:fr_nodeadkeys"] = "French";
331 map
["ch:fr_sundeadkeys"] = "French";
332 map
["sy"] = "Arabic";
333 map
["sy:syc"] = "Arabic";
334 map
["sy:syc_phonetic"] = "Arabic";
336 map
["lk"] = "Singhalese";
337 map
["lk:tam_unicode"] = "Tamil";
338 map
["lk:tam_TAB"] = "Tamil";
339 map
["lk:tam_TSCII"] = "Tamil";
340 map
["lk:sin_phonetic"] = "Singhalese";
342 map
["th:tis"] = "Thai";
343 map
["th:pat"] = "Thai";
344 map
["tr"] = "Turkish";
345 map
["tr:f"] = "Turkish";
346 map
["tr:alt"] = "Turkish";
347 map
["ua"] = "Ukrainian";
348 map
["ua:phonetic"] = "Ukrainian";
349 map
["ua:typewriter"] = "Ukrainian";
350 map
["ua:winkeys"] = "Ukrainian";
351 map
["ua:rstu"] = "Ukrainian";
352 map
["ua:rstu_ru"] = "Ukrainian";
353 map
["gb"] = "English";
354 map
["gb:intl"] = "English";
355 map
["gb:dvorak"] = "English";
357 map
["vn"] = "Vietnamese";
358 map
["nec_vndr/jp"] = "Japanese";
360 map
["ie:CloGaelach"] = "Gaelic";
361 map
["ie:UnicodeExpert"] = "Irish";
362 map
["ie:ogam"] = "Gaelic";
363 map
["ie:ogam_is434"] = "Gaelic";
367 return map
.value(v
, v
);
370 QString
mapDirection(const QString
&v
)
372 static QMap
<QString
, QString
> map
;
373 static bool initialized
= false;
375 // 1. xkbdata-X11R7.0-1.0.1/symbols% grep -l '\([Hh]ebrew\|[Aa]rabic\)' **/*
376 map
["Arabic"] = "Qt::RightToLeft";
377 map
["Persian"] = "Qt::RightToLeft";
378 map
["Urdu"] = "Qt::RightToLeft";
381 return map
.value(v
, "Qt::LeftToRight");
384 int main(int argc
, char **argv
)
387 fprintf(stderr
, "usage: %s <xml input file>\n", argv
[0]);
391 QCoreApplication
app(argc
, argv
);
394 file
.setFileName(argv
[1]);
395 if (!file
.open(QIODevice::ReadOnly
)) {
396 fprintf(stderr
, "cannot open %s: %s\n", qPrintable(file
.fileName()), qPrintable(file
.errorString()));
401 dom
.setContent(&file
);
403 if (dom
.documentElement().tagName() != QLatin1String("xkbConfigRegistry")) {
404 fprintf(stderr
, "cannot parse %s, this is not an XKB config file\n", qPrintable(file
.fileName()));
408 QDomElement layoutList
= find("layoutList", dom
.documentElement());
409 if (layoutList
.isNull()) {
410 fprintf(stderr
, "cannot parse %s, this is not an XKB config file\n", qPrintable(file
.fileName()));
414 QList
<XKBLayout
> layouts
= findLayouts(layoutList
);
416 // copyright and stuff
417 printf("/****************************************************************************\n"
419 "** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n"
420 "** All rights reserved.\n"
421 "** Contact: Nokia Corporation (qt-info@nokia.com)\n"
423 "** This file is part of the QtGui module of the Qt Toolkit.\n"
425 "** $QT_BEGIN_LICENSE:LGPL$\n"
426 "** No Commercial Usage\n"
427 "** This file contains pre-release code and may not be distributed.\n"
428 "** You may use this file in accordance with the terms and conditions\n"
429 "** contained in the Technology Preview License Agreement accompanying\n"
432 "** GNU Lesser General Public License Usage\n"
433 "** Alternatively, this file may be used under the terms of the GNU Lesser\n"
434 "** General Public License version 2.1 as published by the Free Software\n"
435 "** Foundation and appearing in the file LICENSE.LGPL included in the\n"
436 "** packaging of this file. Please review the following information to\n"
437 "** ensure the GNU Lesser General Public License version 2.1 requirements\n"
438 "** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.\n"
440 "** In addition, as a special exception, Nokia gives you certain additional\n"
441 "** rights. These rights are described in the Nokia Qt LGPL Exception\n"
442 "** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.\n"
444 "** If you have questions regarding the use of this file, please contact\n"
445 "** Nokia at qt-info@nokia.com.\n"
454 "** $QT_END_LICENSE$\n"
456 "****************************************************************************/\n"
458 "// This file is auto-generated, do not edit!\n"
462 printf("static struct {\n"
463 " const char *layout;\n"
464 " const char *variant; // 0 means any variant\n"
465 " Qt::LayoutDirection direction;\n"
466 " QLocale::Language language;\n"
467 " QLocale::Country country;\n"
468 "} xkbLayoutData[] = {\n");
471 foreach (const XKBLayout
&l
, layouts
) {
472 const QString country
= mapCountry(l
.description
);
473 QString lang
= mapLanguage(l
.name
);
476 printf(" // name = %s, description = %s\n"
477 " { \"%s\", \"\", %s, QLocale::%s, QLocale::%s },\n",
478 l
.name
.toAscii().constData(),
479 l
.description
.toAscii().constData(),
480 l
.name
.toAscii().constData(),
481 mapDirection(lang
).toAscii().constData(),
482 lang
.toAscii().constData(),
483 country
.toAscii().constData());
484 foreach (const QString
&v
, l
.variants
) {
485 QString vlang
= mapLanguage(l
.name
+ ":" + v
);
488 printf(" // name = %s:%s, description = %s\n"
489 " { \"%s\", \"%s\", %s, QLocale::%s, QLocale::%s },\n",
490 l
.name
.toAscii().constData(),
491 v
.toAscii().constData(),
492 l
.description
.toAscii().constData(),
493 l
.name
.toAscii().constData(),
494 v
.toAscii().constData(),
495 mapDirection(vlang
).toAscii().constData(),
496 vlang
.toAscii().constData(),
497 country
.toAscii().constData());
502 printf(" { 0, 0, Qt::LeftToRight, QLocale::C, QLocale::AnyCountry }\n"