source: trunk/examples/widgets/validators/localeselector.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 12.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "localeselector.h"
42#include <QLocale>
43
44struct SupportedLocale
45{
46 int lang, country;
47};
48
49const SupportedLocale SUPPORTED_LOCALES[] = {
50 { 1, 0 }, // C/AnyCountry
51 { 3, 69 }, // Afan/Ethiopia
52 { 3, 111 }, // Afan/Kenya
53 { 4, 59 }, // Afar/Djibouti
54 { 4, 67 }, // Afar/Eritrea
55 { 4, 69 }, // Afar/Ethiopia
56 { 5, 195 }, // Afrikaans/SouthAfrica
57 { 5, 148 }, // Afrikaans/Namibia
58 { 6, 2 }, // Albanian/Albania
59 { 7, 69 }, // Amharic/Ethiopia
60 { 8, 186 }, // Arabic/SaudiArabia
61 { 8, 3 }, // Arabic/Algeria
62 { 8, 17 }, // Arabic/Bahrain
63 { 8, 64 }, // Arabic/Egypt
64 { 8, 103 }, // Arabic/Iraq
65 { 8, 109 }, // Arabic/Jordan
66 { 8, 115 }, // Arabic/Kuwait
67 { 8, 119 }, // Arabic/Lebanon
68 { 8, 122 }, // Arabic/LibyanArabJamahiriya
69 { 8, 145 }, // Arabic/Morocco
70 { 8, 162 }, // Arabic/Oman
71 { 8, 175 }, // Arabic/Qatar
72 { 8, 201 }, // Arabic/Sudan
73 { 8, 207 }, // Arabic/SyrianArabRepublic
74 { 8, 216 }, // Arabic/Tunisia
75 { 8, 223 }, // Arabic/UnitedArabEmirates
76 { 8, 237 }, // Arabic/Yemen
77 { 9, 11 }, // Armenian/Armenia
78 { 10, 100 }, // Assamese/India
79 { 12, 15 }, // Azerbaijani/Azerbaijan
80 { 14, 197 }, // Basque/Spain
81 { 15, 18 }, // Bengali/Bangladesh
82 { 15, 100 }, // Bengali/India
83 { 16, 25 }, // Bhutani/Bhutan
84 { 20, 33 }, // Bulgarian/Bulgaria
85 { 22, 20 }, // Byelorussian/Belarus
86 { 23, 36 }, // Cambodian/Cambodia
87 { 24, 197 }, // Catalan/Spain
88 { 25, 44 }, // Chinese/China
89 { 25, 97 }, // Chinese/HongKong
90 { 25, 126 }, // Chinese/Macau
91 { 25, 190 }, // Chinese/Singapore
92 { 25, 208 }, // Chinese/Taiwan
93 { 27, 54 }, // Croatian/Croatia
94 { 28, 57 }, // Czech/CzechRepublic
95 { 29, 58 }, // Danish/Denmark
96 { 30, 151 }, // Dutch/Netherlands
97 { 30, 21 }, // Dutch/Belgium
98 { 31, 225 }, // English/UnitedStates
99 { 31, 4 }, // English/AmericanSamoa
100 { 31, 13 }, // English/Australia
101 { 31, 21 }, // English/Belgium
102 { 31, 22 }, // English/Belize
103 { 31, 28 }, // English/Botswana
104 { 31, 38 }, // English/Canada
105 { 31, 89 }, // English/Guam
106 { 31, 97 }, // English/HongKong
107 { 31, 100 }, // English/India
108 { 31, 104 }, // English/Ireland
109 { 31, 107 }, // English/Jamaica
110 { 31, 133 }, // English/Malta
111 { 31, 134 }, // English/MarshallIslands
112 { 31, 148 }, // English/Namibia
113 { 31, 154 }, // English/NewZealand
114 { 31, 160 }, // English/NorthernMarianaIslands
115 { 31, 163 }, // English/Pakistan
116 { 31, 170 }, // English/Philippines
117 { 31, 190 }, // English/Singapore
118 { 31, 195 }, // English/SouthAfrica
119 { 31, 215 }, // English/TrinidadAndTobago
120 { 31, 224 }, // English/UnitedKingdom
121 { 31, 226 }, // English/UnitedStatesMinorOutlyingIslands
122 { 31, 234 }, // English/USVirginIslands
123 { 31, 240 }, // English/Zimbabwe
124 { 33, 68 }, // Estonian/Estonia
125 { 34, 71 }, // Faroese/FaroeIslands
126 { 36, 73 }, // Finnish/Finland
127 { 37, 74 }, // French/France
128 { 37, 21 }, // French/Belgium
129 { 37, 38 }, // French/Canada
130 { 37, 125 }, // French/Luxembourg
131 { 37, 142 }, // French/Monaco
132 { 37, 206 }, // French/Switzerland
133 { 40, 197 }, // Galician/Spain
134 { 41, 81 }, // Georgian/Georgia
135 { 42, 82 }, // German/Germany
136 { 42, 14 }, // German/Austria
137 { 42, 21 }, // German/Belgium
138 { 42, 123 }, // German/Liechtenstein
139 { 42, 125 }, // German/Luxembourg
140 { 42, 206 }, // German/Switzerland
141 { 43, 85 }, // Greek/Greece
142 { 43, 56 }, // Greek/Cyprus
143 { 44, 86 }, // Greenlandic/Greenland
144 { 46, 100 }, // Gujarati/India
145 { 47, 83 }, // Hausa/Ghana
146 { 47, 156 }, // Hausa/Niger
147 { 47, 157 }, // Hausa/Nigeria
148 { 48, 105 }, // Hebrew/Israel
149 { 49, 100 }, // Hindi/India
150 { 50, 98 }, // Hungarian/Hungary
151 { 51, 99 }, // Icelandic/Iceland
152 { 52, 101 }, // Indonesian/Indonesia
153 { 57, 104 }, // Irish/Ireland
154 { 58, 106 }, // Italian/Italy
155 { 58, 206 }, // Italian/Switzerland
156 { 59, 108 }, // Japanese/Japan
157 { 61, 100 }, // Kannada/India
158 { 63, 110 }, // Kazakh/Kazakhstan
159 { 64, 179 }, // Kinyarwanda/Rwanda
160 { 65, 116 }, // Kirghiz/Kyrgyzstan
161 { 66, 114 }, // Korean/RepublicOfKorea
162 { 67, 102 }, // Kurdish/Iran
163 { 67, 103 }, // Kurdish/Iraq
164 { 67, 207 }, // Kurdish/SyrianArabRepublic
165 { 67, 217 }, // Kurdish/Turkey
166 { 69, 117 }, // Laothian/Lao
167 { 71, 118 }, // Latvian/Latvia
168 { 72, 49 }, // Lingala/DemocraticRepublicOfCongo
169 { 72, 50 }, // Lingala/PeoplesRepublicOfCongo
170 { 73, 124 }, // Lithuanian/Lithuania
171 { 74, 127 }, // Macedonian/Macedonia
172 { 76, 130 }, // Malay/Malaysia
173 { 76, 32 }, // Malay/BruneiDarussalam
174 { 77, 100 }, // Malayalam/India
175 { 78, 133 }, // Maltese/Malta
176 { 80, 100 }, // Marathi/India
177 { 82, 143 }, // Mongolian/Mongolia
178 { 84, 150 }, // Nepali/Nepal
179 { 85, 161 }, // Norwegian/Norway
180 { 87, 100 }, // Oriya/India
181 { 88, 1 }, // Pashto/Afghanistan
182 { 89, 102 }, // Persian/Iran
183 { 89, 1 }, // Persian/Afghanistan
184 { 90, 172 }, // Polish/Poland
185 { 91, 173 }, // Portuguese/Portugal
186 { 91, 30 }, // Portuguese/Brazil
187 { 92, 100 }, // Punjabi/India
188 { 92, 163 }, // Punjabi/Pakistan
189 { 95, 177 }, // Romanian/Romania
190 { 96, 178 }, // Russian/RussianFederation
191 { 96, 222 }, // Russian/Ukraine
192 { 99, 100 }, // Sanskrit/India
193 { 100, 241 }, // Serbian/SerbiaAndMontenegro
194 { 100, 27 }, // Serbian/BosniaAndHerzegowina
195 { 100, 238 }, // Serbian/Yugoslavia
196 { 101, 241 }, // SerboCroatian/SerbiaAndMontenegro
197 { 101, 27 }, // SerboCroatian/BosniaAndHerzegowina
198 { 101, 238 }, // SerboCroatian/Yugoslavia
199 { 102, 195 }, // Sesotho/SouthAfrica
200 { 103, 195 }, // Setswana/SouthAfrica
201 { 107, 195 }, // Siswati/SouthAfrica
202 { 108, 191 }, // Slovak/Slovakia
203 { 109, 192 }, // Slovenian/Slovenia
204 { 110, 194 }, // Somali/Somalia
205 { 110, 59 }, // Somali/Djibouti
206 { 110, 69 }, // Somali/Ethiopia
207 { 110, 111 }, // Somali/Kenya
208 { 111, 197 }, // Spanish/Spain
209 { 111, 10 }, // Spanish/Argentina
210 { 111, 26 }, // Spanish/Bolivia
211 { 111, 43 }, // Spanish/Chile
212 { 111, 47 }, // Spanish/Colombia
213 { 111, 52 }, // Spanish/CostaRica
214 { 111, 61 }, // Spanish/DominicanRepublic
215 { 111, 63 }, // Spanish/Ecuador
216 { 111, 65 }, // Spanish/ElSalvador
217 { 111, 90 }, // Spanish/Guatemala
218 { 111, 96 }, // Spanish/Honduras
219 { 111, 139 }, // Spanish/Mexico
220 { 111, 155 }, // Spanish/Nicaragua
221 { 111, 166 }, // Spanish/Panama
222 { 111, 168 }, // Spanish/Paraguay
223 { 111, 169 }, // Spanish/Peru
224 { 111, 174 }, // Spanish/PuertoRico
225 { 111, 225 }, // Spanish/UnitedStates
226 { 111, 227 }, // Spanish/Uruguay
227 { 111, 231 }, // Spanish/Venezuela
228 { 113, 111 }, // Swahili/Kenya
229 { 113, 210 }, // Swahili/Tanzania
230 { 114, 205 }, // Swedish/Sweden
231 { 114, 73 }, // Swedish/Finland
232 { 116, 209 }, // Tajik/Tajikistan
233 { 117, 100 }, // Tamil/India
234 { 118, 178 }, // Tatar/RussianFederation
235 { 119, 100 }, // Telugu/India
236 { 120, 211 }, // Thai/Thailand
237 { 122, 67 }, // Tigrinya/Eritrea
238 { 122, 69 }, // Tigrinya/Ethiopia
239 { 124, 195 }, // Tsonga/SouthAfrica
240 { 125, 217 }, // Turkish/Turkey
241 { 129, 222 }, // Ukrainian/Ukraine
242 { 130, 100 }, // Urdu/India
243 { 130, 163 }, // Urdu/Pakistan
244 { 131, 228 }, // Uzbek/Uzbekistan
245 { 131, 1 }, // Uzbek/Afghanistan
246 { 132, 232 }, // Vietnamese/VietNam
247 { 134, 224 }, // Welsh/UnitedKingdom
248 { 136, 195 }, // Xhosa/SouthAfrica
249 { 138, 157 }, // Yoruba/Nigeria
250 { 140, 195 }, // Zulu/SouthAfrica
251 { 141, 161 }, // Nynorsk/Norway
252 { 142, 27 }, // Bosnian/BosniaAndHerzegowina
253 { 143, 131 }, // Divehi/Maldives
254 { 144, 224 }, // Manx/UnitedKingdom
255 { 145, 224 }, // Cornish/UnitedKingdom
256 { 146, 83 }, // Akan/Ghana
257 { 147, 100 }, // Konkani/India
258 { 148, 83 }, // Ga/Ghana
259 { 149, 157 }, // Igbo/Nigeria
260 { 150, 111 }, // Kamba/Kenya
261 { 151, 207 }, // Syriac/SyrianArabRepublic
262 { 152, 67 }, // Blin/Eritrea
263 { 153, 67 }, // Geez/Eritrea
264 { 153, 69 }, // Geez/Ethiopia
265 { 154, 157 }, // Koro/Nigeria
266 { 155, 69 }, // Sidamo/Ethiopia
267 { 156, 157 }, // Atsam/Nigeria
268 { 157, 67 }, // Tigre/Eritrea
269 { 158, 157 }, // Jju/Nigeria
270 { 159, 106 }, // Friulian/Italy
271 { 160, 195 }, // Venda/SouthAfrica
272 { 161, 83 }, // Ewe/Ghana
273 { 161, 212 }, // Ewe/Togo
274 { 163, 225 }, // Hawaiian/UnitedStates
275 { 164, 157 }, // Tyap/Nigeria
276 { 165, 129 } // Chewa/Malawi
277};
278
279const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale);
280
281typedef QPair<int, int> IntPair;
282Q_DECLARE_METATYPE(SupportedLocale)
283
284LocaleSelector::LocaleSelector(QWidget *parent)
285 : QComboBox(parent)
286{
287 int curIndex = -1;
288 QLocale curLocale;
289
290 for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) {
291 const SupportedLocale &l = SUPPORTED_LOCALES[i];
292 if (l.lang == curLocale.language() && l.country == curLocale.country())
293 curIndex = i;
294 QString text = QLocale::languageToString(QLocale::Language(l.lang))
295 + QLatin1Char('/')
296 + QLocale::countryToString(QLocale::Country(l.country));
297 addItem(text, qVariantFromValue(l));
298 }
299
300 setCurrentIndex(curIndex);
301
302 connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int)));
303}
304
305void LocaleSelector::emitLocaleSelected(int index)
306{
307 QVariant v = itemData(index);
308 if (!v.isValid())
309 return;
310 SupportedLocale l = qVariantValue<SupportedLocale>(v);
311 emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country)));
312}
Note: See TracBrowser for help on using the repository browser.