author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
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 |
|
14 |
** this package. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "localeselector.h" |
|
43 |
#include <QLocale> |
|
44 |
||
45 |
struct SupportedLocale |
|
46 |
{ |
|
47 |
int lang, country; |
|
48 |
}; |
|
49 |
||
50 |
const SupportedLocale SUPPORTED_LOCALES[] = { |
|
51 |
{ 1, 0 }, // C/AnyCountry |
|
52 |
{ 3, 69 }, // Afan/Ethiopia |
|
53 |
{ 3, 111 }, // Afan/Kenya |
|
54 |
{ 4, 59 }, // Afar/Djibouti |
|
55 |
{ 4, 67 }, // Afar/Eritrea |
|
56 |
{ 4, 69 }, // Afar/Ethiopia |
|
57 |
{ 5, 195 }, // Afrikaans/SouthAfrica |
|
58 |
{ 5, 148 }, // Afrikaans/Namibia |
|
59 |
{ 6, 2 }, // Albanian/Albania |
|
60 |
{ 7, 69 }, // Amharic/Ethiopia |
|
61 |
{ 8, 186 }, // Arabic/SaudiArabia |
|
62 |
{ 8, 3 }, // Arabic/Algeria |
|
63 |
{ 8, 17 }, // Arabic/Bahrain |
|
64 |
{ 8, 64 }, // Arabic/Egypt |
|
65 |
{ 8, 103 }, // Arabic/Iraq |
|
66 |
{ 8, 109 }, // Arabic/Jordan |
|
67 |
{ 8, 115 }, // Arabic/Kuwait |
|
68 |
{ 8, 119 }, // Arabic/Lebanon |
|
69 |
{ 8, 122 }, // Arabic/LibyanArabJamahiriya |
|
70 |
{ 8, 145 }, // Arabic/Morocco |
|
71 |
{ 8, 162 }, // Arabic/Oman |
|
72 |
{ 8, 175 }, // Arabic/Qatar |
|
73 |
{ 8, 201 }, // Arabic/Sudan |
|
74 |
{ 8, 207 }, // Arabic/SyrianArabRepublic |
|
75 |
{ 8, 216 }, // Arabic/Tunisia |
|
76 |
{ 8, 223 }, // Arabic/UnitedArabEmirates |
|
77 |
{ 8, 237 }, // Arabic/Yemen |
|
78 |
{ 9, 11 }, // Armenian/Armenia |
|
79 |
{ 10, 100 }, // Assamese/India |
|
80 |
{ 12, 15 }, // Azerbaijani/Azerbaijan |
|
81 |
{ 14, 197 }, // Basque/Spain |
|
82 |
{ 15, 18 }, // Bengali/Bangladesh |
|
83 |
{ 15, 100 }, // Bengali/India |
|
84 |
{ 16, 25 }, // Bhutani/Bhutan |
|
85 |
{ 20, 33 }, // Bulgarian/Bulgaria |
|
86 |
{ 22, 20 }, // Byelorussian/Belarus |
|
87 |
{ 23, 36 }, // Cambodian/Cambodia |
|
88 |
{ 24, 197 }, // Catalan/Spain |
|
89 |
{ 25, 44 }, // Chinese/China |
|
90 |
{ 25, 97 }, // Chinese/HongKong |
|
91 |
{ 25, 126 }, // Chinese/Macau |
|
92 |
{ 25, 190 }, // Chinese/Singapore |
|
93 |
{ 25, 208 }, // Chinese/Taiwan |
|
94 |
{ 27, 54 }, // Croatian/Croatia |
|
95 |
{ 28, 57 }, // Czech/CzechRepublic |
|
96 |
{ 29, 58 }, // Danish/Denmark |
|
97 |
{ 30, 151 }, // Dutch/Netherlands |
|
98 |
{ 30, 21 }, // Dutch/Belgium |
|
99 |
{ 31, 225 }, // English/UnitedStates |
|
100 |
{ 31, 4 }, // English/AmericanSamoa |
|
101 |
{ 31, 13 }, // English/Australia |
|
102 |
{ 31, 21 }, // English/Belgium |
|
103 |
{ 31, 22 }, // English/Belize |
|
104 |
{ 31, 28 }, // English/Botswana |
|
105 |
{ 31, 38 }, // English/Canada |
|
106 |
{ 31, 89 }, // English/Guam |
|
107 |
{ 31, 97 }, // English/HongKong |
|
108 |
{ 31, 100 }, // English/India |
|
109 |
{ 31, 104 }, // English/Ireland |
|
110 |
{ 31, 107 }, // English/Jamaica |
|
111 |
{ 31, 133 }, // English/Malta |
|
112 |
{ 31, 134 }, // English/MarshallIslands |
|
113 |
{ 31, 148 }, // English/Namibia |
|
114 |
{ 31, 154 }, // English/NewZealand |
|
115 |
{ 31, 160 }, // English/NorthernMarianaIslands |
|
116 |
{ 31, 163 }, // English/Pakistan |
|
117 |
{ 31, 170 }, // English/Philippines |
|
118 |
{ 31, 190 }, // English/Singapore |
|
119 |
{ 31, 195 }, // English/SouthAfrica |
|
120 |
{ 31, 215 }, // English/TrinidadAndTobago |
|
121 |
{ 31, 224 }, // English/UnitedKingdom |
|
122 |
{ 31, 226 }, // English/UnitedStatesMinorOutlyingIslands |
|
123 |
{ 31, 234 }, // English/USVirginIslands |
|
124 |
{ 31, 240 }, // English/Zimbabwe |
|
125 |
{ 33, 68 }, // Estonian/Estonia |
|
126 |
{ 34, 71 }, // Faroese/FaroeIslands |
|
127 |
{ 36, 73 }, // Finnish/Finland |
|
128 |
{ 37, 74 }, // French/France |
|
129 |
{ 37, 21 }, // French/Belgium |
|
130 |
{ 37, 38 }, // French/Canada |
|
131 |
{ 37, 125 }, // French/Luxembourg |
|
132 |
{ 37, 142 }, // French/Monaco |
|
133 |
{ 37, 206 }, // French/Switzerland |
|
134 |
{ 40, 197 }, // Galician/Spain |
|
135 |
{ 41, 81 }, // Georgian/Georgia |
|
136 |
{ 42, 82 }, // German/Germany |
|
137 |
{ 42, 14 }, // German/Austria |
|
138 |
{ 42, 21 }, // German/Belgium |
|
139 |
{ 42, 123 }, // German/Liechtenstein |
|
140 |
{ 42, 125 }, // German/Luxembourg |
|
141 |
{ 42, 206 }, // German/Switzerland |
|
142 |
{ 43, 85 }, // Greek/Greece |
|
143 |
{ 43, 56 }, // Greek/Cyprus |
|
144 |
{ 44, 86 }, // Greenlandic/Greenland |
|
145 |
{ 46, 100 }, // Gujarati/India |
|
146 |
{ 47, 83 }, // Hausa/Ghana |
|
147 |
{ 47, 156 }, // Hausa/Niger |
|
148 |
{ 47, 157 }, // Hausa/Nigeria |
|
149 |
{ 48, 105 }, // Hebrew/Israel |
|
150 |
{ 49, 100 }, // Hindi/India |
|
151 |
{ 50, 98 }, // Hungarian/Hungary |
|
152 |
{ 51, 99 }, // Icelandic/Iceland |
|
153 |
{ 52, 101 }, // Indonesian/Indonesia |
|
154 |
{ 57, 104 }, // Irish/Ireland |
|
155 |
{ 58, 106 }, // Italian/Italy |
|
156 |
{ 58, 206 }, // Italian/Switzerland |
|
157 |
{ 59, 108 }, // Japanese/Japan |
|
158 |
{ 61, 100 }, // Kannada/India |
|
159 |
{ 63, 110 }, // Kazakh/Kazakhstan |
|
160 |
{ 64, 179 }, // Kinyarwanda/Rwanda |
|
161 |
{ 65, 116 }, // Kirghiz/Kyrgyzstan |
|
162 |
{ 66, 114 }, // Korean/RepublicOfKorea |
|
163 |
{ 67, 102 }, // Kurdish/Iran |
|
164 |
{ 67, 103 }, // Kurdish/Iraq |
|
165 |
{ 67, 207 }, // Kurdish/SyrianArabRepublic |
|
166 |
{ 67, 217 }, // Kurdish/Turkey |
|
167 |
{ 69, 117 }, // Laothian/Lao |
|
168 |
{ 71, 118 }, // Latvian/Latvia |
|
169 |
{ 72, 49 }, // Lingala/DemocraticRepublicOfCongo |
|
170 |
{ 72, 50 }, // Lingala/PeoplesRepublicOfCongo |
|
171 |
{ 73, 124 }, // Lithuanian/Lithuania |
|
172 |
{ 74, 127 }, // Macedonian/Macedonia |
|
173 |
{ 76, 130 }, // Malay/Malaysia |
|
174 |
{ 76, 32 }, // Malay/BruneiDarussalam |
|
175 |
{ 77, 100 }, // Malayalam/India |
|
176 |
{ 78, 133 }, // Maltese/Malta |
|
177 |
{ 80, 100 }, // Marathi/India |
|
178 |
{ 82, 143 }, // Mongolian/Mongolia |
|
179 |
{ 84, 150 }, // Nepali/Nepal |
|
180 |
{ 85, 161 }, // Norwegian/Norway |
|
181 |
{ 87, 100 }, // Oriya/India |
|
182 |
{ 88, 1 }, // Pashto/Afghanistan |
|
183 |
{ 89, 102 }, // Persian/Iran |
|
184 |
{ 89, 1 }, // Persian/Afghanistan |
|
185 |
{ 90, 172 }, // Polish/Poland |
|
186 |
{ 91, 173 }, // Portuguese/Portugal |
|
187 |
{ 91, 30 }, // Portuguese/Brazil |
|
188 |
{ 92, 100 }, // Punjabi/India |
|
189 |
{ 92, 163 }, // Punjabi/Pakistan |
|
190 |
{ 95, 177 }, // Romanian/Romania |
|
191 |
{ 96, 178 }, // Russian/RussianFederation |
|
192 |
{ 96, 222 }, // Russian/Ukraine |
|
193 |
{ 99, 100 }, // Sanskrit/India |
|
194 |
{ 100, 241 }, // Serbian/SerbiaAndMontenegro |
|
195 |
{ 100, 27 }, // Serbian/BosniaAndHerzegowina |
|
196 |
{ 100, 238 }, // Serbian/Yugoslavia |
|
197 |
{ 101, 241 }, // SerboCroatian/SerbiaAndMontenegro |
|
198 |
{ 101, 27 }, // SerboCroatian/BosniaAndHerzegowina |
|
199 |
{ 101, 238 }, // SerboCroatian/Yugoslavia |
|
200 |
{ 102, 195 }, // Sesotho/SouthAfrica |
|
201 |
{ 103, 195 }, // Setswana/SouthAfrica |
|
202 |
{ 107, 195 }, // Siswati/SouthAfrica |
|
203 |
{ 108, 191 }, // Slovak/Slovakia |
|
204 |
{ 109, 192 }, // Slovenian/Slovenia |
|
205 |
{ 110, 194 }, // Somali/Somalia |
|
206 |
{ 110, 59 }, // Somali/Djibouti |
|
207 |
{ 110, 69 }, // Somali/Ethiopia |
|
208 |
{ 110, 111 }, // Somali/Kenya |
|
209 |
{ 111, 197 }, // Spanish/Spain |
|
210 |
{ 111, 10 }, // Spanish/Argentina |
|
211 |
{ 111, 26 }, // Spanish/Bolivia |
|
212 |
{ 111, 43 }, // Spanish/Chile |
|
213 |
{ 111, 47 }, // Spanish/Colombia |
|
214 |
{ 111, 52 }, // Spanish/CostaRica |
|
215 |
{ 111, 61 }, // Spanish/DominicanRepublic |
|
216 |
{ 111, 63 }, // Spanish/Ecuador |
|
217 |
{ 111, 65 }, // Spanish/ElSalvador |
|
218 |
{ 111, 90 }, // Spanish/Guatemala |
|
219 |
{ 111, 96 }, // Spanish/Honduras |
|
220 |
{ 111, 139 }, // Spanish/Mexico |
|
221 |
{ 111, 155 }, // Spanish/Nicaragua |
|
222 |
{ 111, 166 }, // Spanish/Panama |
|
223 |
{ 111, 168 }, // Spanish/Paraguay |
|
224 |
{ 111, 169 }, // Spanish/Peru |
|
225 |
{ 111, 174 }, // Spanish/PuertoRico |
|
226 |
{ 111, 225 }, // Spanish/UnitedStates |
|
227 |
{ 111, 227 }, // Spanish/Uruguay |
|
228 |
{ 111, 231 }, // Spanish/Venezuela |
|
229 |
{ 113, 111 }, // Swahili/Kenya |
|
230 |
{ 113, 210 }, // Swahili/Tanzania |
|
231 |
{ 114, 205 }, // Swedish/Sweden |
|
232 |
{ 114, 73 }, // Swedish/Finland |
|
233 |
{ 116, 209 }, // Tajik/Tajikistan |
|
234 |
{ 117, 100 }, // Tamil/India |
|
235 |
{ 118, 178 }, // Tatar/RussianFederation |
|
236 |
{ 119, 100 }, // Telugu/India |
|
237 |
{ 120, 211 }, // Thai/Thailand |
|
238 |
{ 122, 67 }, // Tigrinya/Eritrea |
|
239 |
{ 122, 69 }, // Tigrinya/Ethiopia |
|
240 |
{ 124, 195 }, // Tsonga/SouthAfrica |
|
241 |
{ 125, 217 }, // Turkish/Turkey |
|
242 |
{ 129, 222 }, // Ukrainian/Ukraine |
|
243 |
{ 130, 100 }, // Urdu/India |
|
244 |
{ 130, 163 }, // Urdu/Pakistan |
|
245 |
{ 131, 228 }, // Uzbek/Uzbekistan |
|
246 |
{ 131, 1 }, // Uzbek/Afghanistan |
|
247 |
{ 132, 232 }, // Vietnamese/VietNam |
|
248 |
{ 134, 224 }, // Welsh/UnitedKingdom |
|
249 |
{ 136, 195 }, // Xhosa/SouthAfrica |
|
250 |
{ 138, 157 }, // Yoruba/Nigeria |
|
251 |
{ 140, 195 }, // Zulu/SouthAfrica |
|
252 |
{ 141, 161 }, // Nynorsk/Norway |
|
253 |
{ 142, 27 }, // Bosnian/BosniaAndHerzegowina |
|
254 |
{ 143, 131 }, // Divehi/Maldives |
|
255 |
{ 144, 224 }, // Manx/UnitedKingdom |
|
256 |
{ 145, 224 }, // Cornish/UnitedKingdom |
|
257 |
{ 146, 83 }, // Akan/Ghana |
|
258 |
{ 147, 100 }, // Konkani/India |
|
259 |
{ 148, 83 }, // Ga/Ghana |
|
260 |
{ 149, 157 }, // Igbo/Nigeria |
|
261 |
{ 150, 111 }, // Kamba/Kenya |
|
262 |
{ 151, 207 }, // Syriac/SyrianArabRepublic |
|
263 |
{ 152, 67 }, // Blin/Eritrea |
|
264 |
{ 153, 67 }, // Geez/Eritrea |
|
265 |
{ 153, 69 }, // Geez/Ethiopia |
|
266 |
{ 154, 157 }, // Koro/Nigeria |
|
267 |
{ 155, 69 }, // Sidamo/Ethiopia |
|
268 |
{ 156, 157 }, // Atsam/Nigeria |
|
269 |
{ 157, 67 }, // Tigre/Eritrea |
|
270 |
{ 158, 157 }, // Jju/Nigeria |
|
271 |
{ 159, 106 }, // Friulian/Italy |
|
272 |
{ 160, 195 }, // Venda/SouthAfrica |
|
273 |
{ 161, 83 }, // Ewe/Ghana |
|
274 |
{ 161, 212 }, // Ewe/Togo |
|
275 |
{ 163, 225 }, // Hawaiian/UnitedStates |
|
276 |
{ 164, 157 }, // Tyap/Nigeria |
|
277 |
{ 165, 129 } // Chewa/Malawi |
|
278 |
}; |
|
279 |
||
280 |
const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale); |
|
281 |
||
282 |
typedef QPair<int, int> IntPair; |
|
283 |
Q_DECLARE_METATYPE(SupportedLocale) |
|
284 |
||
285 |
LocaleSelector::LocaleSelector(QWidget *parent) |
|
286 |
: QComboBox(parent) |
|
287 |
{ |
|
288 |
int curIndex = -1; |
|
289 |
QLocale curLocale; |
|
290 |
||
291 |
for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) { |
|
292 |
const SupportedLocale &l = SUPPORTED_LOCALES[i]; |
|
293 |
if (l.lang == curLocale.language() && l.country == curLocale.country()) |
|
294 |
curIndex = i; |
|
295 |
QString text = QLocale::languageToString(QLocale::Language(l.lang)) |
|
296 |
+ QLatin1Char('/') |
|
297 |
+ QLocale::countryToString(QLocale::Country(l.country)); |
|
298 |
addItem(text, qVariantFromValue(l)); |
|
299 |
} |
|
300 |
||
301 |
setCurrentIndex(curIndex); |
|
302 |
||
303 |
connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int))); |
|
304 |
} |
|
305 |
||
306 |
void LocaleSelector::emitLocaleSelected(int index) |
|
307 |
{ |
|
308 |
QVariant v = itemData(index); |
|
309 |
if (!v.isValid()) |
|
310 |
return; |
|
311 |
SupportedLocale l = qVariantValue<SupportedLocale>(v); |
|
312 |
emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country))); |
|
313 |
} |