author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 3 | 41300fa6a67c |
child 25 | e24348a560a6 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
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 QtCore module 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 <QDate> |
|
43 |
#include <QLocale> |
|
44 |
#include <QTime> |
|
45 |
#include <QVariant> |
|
46 |
#include <QThread> |
|
47 |
||
48 |
#include <e32std.h> |
|
49 |
#include "private/qcore_symbian_p.h" |
|
50 |
||
51 |
||
52 |
QT_BEGIN_NAMESPACE |
|
53 |
||
54 |
// Located in qlocale.cpp |
|
55 |
extern void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Country &cntry); |
|
56 |
||
57 |
static TExtendedLocale _s60Locale; |
|
58 |
||
59 |
// Type definitions for runtime resolved function pointers |
|
60 |
typedef void (*FormatFunc)(TTime&, TDes&, const TDesC&, const TLocale&); |
|
61 |
typedef TPtrC (*FormatSpecFunc)(TExtendedLocale&); |
|
62 |
||
63 |
// Runtime resolved functions |
|
64 |
static FormatFunc ptrTimeFormatL = NULL; |
|
65 |
static FormatSpecFunc ptrGetTimeFormatSpec = NULL; |
|
66 |
static FormatSpecFunc ptrGetLongDateFormatSpec = NULL; |
|
67 |
static FormatSpecFunc ptrGetShortDateFormatSpec = NULL; |
|
68 |
||
69 |
// Default functions if functions cannot be resolved |
|
70 |
static void defaultTimeFormatL(TTime&, TDes& des, const TDesC&, const TLocale&) |
|
71 |
{ |
|
72 |
des.Zero(); |
|
73 |
} |
|
74 |
||
75 |
static TPtrC defaultFormatSpec(TExtendedLocale&) |
|
76 |
{ |
|
77 |
return TPtrC(KNullDesC); |
|
78 |
} |
|
79 |
||
80 |
/* |
|
81 |
Definition of struct for mapping Symbian to ISO locale |
|
82 |
*/ |
|
83 |
struct symbianToISO { |
|
84 |
int symbian_language; |
|
85 |
char iso_name[8]; |
|
86 |
}; |
|
87 |
||
88 |
||
89 |
/* |
|
90 |
Mapping from Symbian to ISO locale |
|
91 |
*/ |
|
92 |
static const symbianToISO symbian_to_iso_list[] = { |
|
93 |
{ ELangEnglish, "en_GB" }, |
|
94 |
{ ELangFrench, "fr_FR" }, |
|
95 |
{ ELangGerman, "de_DE" }, |
|
96 |
{ ELangSpanish, "es_ES" }, |
|
97 |
{ ELangItalian, "it_IT" }, |
|
98 |
{ ELangSwedish, "sv_SE" }, |
|
99 |
{ ELangDanish, "da_DK" }, |
|
100 |
{ ELangNorwegian, "no_NO" }, |
|
101 |
{ ELangFinnish, "fi_FI" }, |
|
102 |
{ ELangAmerican, "en_US" }, |
|
103 |
{ ELangPortuguese, "pt_PT" }, |
|
104 |
{ ELangTurkish, "tr_TR" }, |
|
105 |
{ ELangIcelandic, "is_IS" }, |
|
106 |
{ ELangRussian, "ru_RU" }, |
|
107 |
{ ELangHungarian, "hu_HU" }, |
|
108 |
{ ELangDutch, "nl_NL" }, |
|
109 |
{ ELangBelgianFlemish, "nl_BE" }, |
|
110 |
{ ELangCzech, "cs_CZ" }, |
|
111 |
{ ELangSlovak, "sk_SK" }, |
|
112 |
{ ELangPolish, "pl_PL" }, |
|
113 |
{ ELangSlovenian, "sl_SI" }, |
|
114 |
{ ELangTaiwanChinese, "zh_TW" }, |
|
115 |
{ ELangHongKongChinese, "zh_HK" }, |
|
116 |
{ ELangPrcChinese, "zh_CN" }, |
|
117 |
{ ELangJapanese, "ja_JP" }, |
|
118 |
{ ELangThai, "th_TH" }, |
|
119 |
{ ELangArabic, "ar_AE" }, |
|
120 |
{ ELangTagalog, "tl_PH" }, |
|
121 |
{ ELangBulgarian, "bg_BG" }, |
|
122 |
{ ELangCatalan, "ca_ES" }, |
|
123 |
{ ELangCroatian, "hr_HR" }, |
|
124 |
{ ELangEstonian, "et_EE" }, |
|
125 |
{ ELangFarsi, "fa_IR" }, |
|
126 |
{ ELangCanadianFrench, "fr_CA" }, |
|
127 |
{ ELangGreek, "el_GR" }, |
|
128 |
{ ELangHebrew, "he_IL" }, |
|
129 |
{ ELangHindi, "hi_IN" }, |
|
130 |
{ ELangIndonesian, "id_ID" }, |
|
131 |
{ ELangLatvian, "lv_LV" }, |
|
132 |
{ ELangLithuanian, "lt_LT" }, |
|
133 |
{ ELangMalay, "ms_MY" }, |
|
134 |
{ ELangBrazilianPortuguese, "pt_BR" }, |
|
135 |
{ ELangRomanian, "ro_RO" }, |
|
136 |
{ ELangSerbian, "sr_YU" }, |
|
137 |
{ ELangLatinAmericanSpanish, "es" }, |
|
138 |
{ ELangUkrainian, "uk_UA" }, |
|
139 |
{ ELangUrdu, "ur_PK" }, // India/Pakistan |
|
140 |
{ ELangVietnamese, "vi_VN" }, |
|
141 |
#ifdef __E32LANG_H__ |
|
142 |
// 5.0 |
|
143 |
{ ELangBasque, "eu_ES" }, |
|
144 |
{ ELangGalician, "gl_ES" }, |
|
145 |
#endif |
|
146 |
#if !defined(__SERIES60_31__) |
|
147 |
{ ELangEnglish_Apac, "en" }, |
|
148 |
{ ELangEnglish_Taiwan, "en_TW" }, |
|
149 |
{ ELangEnglish_HongKong, "en_HK" }, |
|
150 |
{ ELangEnglish_Prc, "en_CN" }, |
|
151 |
{ ELangEnglish_Japan, "en_JP"}, |
|
152 |
{ ELangEnglish_Thailand, "en_TH" }, |
|
153 |
{ ELangMalay_Apac, "ms" } |
|
154 |
#endif |
|
155 |
}; |
|
156 |
||
157 |
/*! |
|
158 |
Returns ISO name corresponding to the Symbian locale code \a sys_fmt. |
|
159 |
*/ |
|
160 |
QByteArray qt_symbianLocaleName(int code) |
|
161 |
{ |
|
162 |
//Number of Symbian to ISO locale mappings |
|
163 |
static const int symbian_to_iso_count |
|
164 |
= sizeof(symbian_to_iso_list)/sizeof(symbianToISO); |
|
165 |
||
166 |
int cmp = code - symbian_to_iso_list[0].symbian_language; |
|
167 |
if (cmp < 0) |
|
168 |
return 0; |
|
169 |
||
170 |
if (cmp == 0) |
|
171 |
return symbian_to_iso_list[0].iso_name; |
|
172 |
||
173 |
int begin = 0; |
|
174 |
int end = symbian_to_iso_count; |
|
175 |
||
176 |
while (end - begin > 1) { |
|
177 |
uint mid = (begin + end)/2; |
|
178 |
||
179 |
const symbianToISO *elt = symbian_to_iso_list + mid; |
|
180 |
int cmp = code - elt->symbian_language; |
|
181 |
if (cmp < 0) |
|
182 |
end = mid; |
|
183 |
else if (cmp > 0) |
|
184 |
begin = mid; |
|
185 |
else |
|
186 |
return elt->iso_name; |
|
187 |
} |
|
188 |
||
189 |
return 0; |
|
190 |
} |
|
191 |
||
192 |
||
193 |
// order is: normal, abbr, nmode, nmode+abbr |
|
194 |
static const char *us_locale_dep[] = { |
|
195 |
"MM", "dd", "yyyy", "MM", "dd", |
|
196 |
"M", "d", "yy", "M", "d", |
|
197 |
"MMMM", "dd", "yyyy", "MMMM", "dd", |
|
198 |
"MMM", "d", "yy", "MMM", "d" }; |
|
199 |
||
200 |
static const char *eu_locale_dep[] = { |
|
201 |
"dd", "MM", "yyyy", "dd", "MM", |
|
202 |
"d", "M", "yy", "d", "M", |
|
203 |
"dd", "MMMM", "yyyy", "dd", "MMMM", |
|
204 |
"d", "MMM", "yy", "d", "MMM" }; |
|
205 |
||
206 |
static const char *jp_locale_dep[] = { |
|
207 |
"yyyy", "MM", "dd", "MM", "dd", |
|
208 |
"yy", "M", "d", "M", "d", |
|
209 |
"yyyy", "MMMM", "dd", "MMMM", "dd", |
|
210 |
"yy", "MMM", "d", "MMM", "d" }; |
|
211 |
||
212 |
/*! |
|
213 |
Returns a Qt version of the given \a sys_fmt Symbian locale format string. |
|
214 |
*/ |
|
215 |
static QString s60ToQtFormat(const QString &sys_fmt) |
|
216 |
{ |
|
217 |
TLocale *locale = _s60Locale.GetLocale(); |
|
218 |
||
219 |
QString result; |
|
220 |
QString other; |
|
221 |
QString qtformatchars = QString::fromLatin1("adhmsyzAHM"); |
|
222 |
||
223 |
QChar c; |
|
224 |
int i = 0; |
|
225 |
bool open_escape = false; |
|
226 |
bool abbrev_next = false; |
|
227 |
bool locale_indep_ordering = false; |
|
228 |
bool minus_mode = false; |
|
229 |
bool plus_mode = false; |
|
230 |
bool n_mode = false; |
|
231 |
TTimeFormat tf = locale->TimeFormat(); |
|
232 |
||
233 |
while (i < sys_fmt.size()) { |
|
234 |
||
235 |
c = sys_fmt.at(i); |
|
236 |
||
237 |
// let formatting thru |
|
238 |
if (c.unicode() == '%') { |
|
239 |
// if we have gathered string, concat it |
|
240 |
if (!other.isEmpty()) { |
|
241 |
result += other; |
|
242 |
other.clear(); |
|
243 |
} |
|
244 |
// if we have open escape, end it |
|
245 |
if (open_escape) { |
|
246 |
result += QLatin1Char('\''); |
|
247 |
open_escape = false; |
|
248 |
} |
|
249 |
||
250 |
++i; |
|
251 |
if (i >= sys_fmt.size()) |
|
252 |
break; |
|
253 |
||
254 |
c = sys_fmt.at(i); |
|
255 |
||
256 |
// process specials |
|
257 |
abbrev_next = c.unicode() == '*'; |
|
258 |
plus_mode = c.unicode() == '+'; |
|
259 |
minus_mode = c.unicode() == '-'; |
|
260 |
||
261 |
if (abbrev_next || plus_mode || minus_mode) { |
|
262 |
++i; |
|
263 |
if (i >= sys_fmt.size()) |
|
264 |
break; |
|
265 |
||
266 |
c = sys_fmt.at(i); |
|
267 |
||
268 |
if (plus_mode || minus_mode) { |
|
269 |
// break on undefined plus/minus mode |
|
270 |
if (c.unicode() != 'A' && c.unicode() != 'B') |
|
271 |
break; |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
switch (c.unicode()) { |
|
276 |
case 'F': |
|
277 |
{ |
|
278 |
// locale indep mode on |
|
279 |
locale_indep_ordering = true; |
|
280 |
break; |
|
281 |
} |
|
282 |
||
283 |
case '/': |
|
284 |
{ |
|
285 |
// date sep 0-3 |
|
286 |
++i; |
|
287 |
if (i >= sys_fmt.size()) |
|
288 |
break; |
|
289 |
||
290 |
c = sys_fmt.at(i); |
|
291 |
if (c.isDigit() && c.digitValue() <= 3) { |
|
292 |
TChar s = locale->DateSeparator(c.digitValue()); |
|
293 |
TUint val = s; |
|
294 |
// some indexes return zero for empty |
|
295 |
if (val > 0) |
|
296 |
result += QChar(val); |
|
297 |
} |
|
298 |
break; |
|
299 |
} |
|
300 |
||
301 |
case 'D': |
|
302 |
{ |
|
303 |
if (!locale_indep_ordering) |
|
304 |
break; |
|
305 |
||
306 |
if (!abbrev_next) |
|
307 |
result += QLatin1String("dd"); |
|
308 |
else |
|
309 |
result += QLatin1Char('d'); |
|
310 |
||
311 |
break; |
|
312 |
} |
|
313 |
||
314 |
case 'M': |
|
315 |
{ |
|
316 |
if (!locale_indep_ordering) |
|
317 |
break; |
|
318 |
||
319 |
if (!n_mode) { |
|
320 |
if (!abbrev_next) |
|
321 |
result += QLatin1String("MM"); |
|
322 |
else |
|
323 |
result += QLatin1String("M"); |
|
324 |
} else { |
|
325 |
if (!abbrev_next) |
|
326 |
result += QLatin1String("MMMM"); |
|
327 |
else |
|
328 |
result += QLatin1String("MMM"); |
|
329 |
} |
|
330 |
||
331 |
break; |
|
332 |
} |
|
333 |
||
334 |
case 'N': |
|
335 |
{ |
|
336 |
n_mode = true; |
|
337 |
||
338 |
if (!locale_indep_ordering) |
|
339 |
break; |
|
340 |
||
341 |
if (!abbrev_next) |
|
342 |
result += QLatin1String("MMMM"); |
|
343 |
else |
|
344 |
result += QLatin1String("MMM"); |
|
345 |
||
346 |
break; |
|
347 |
} |
|
348 |
||
349 |
case 'Y': |
|
350 |
{ |
|
351 |
if (!locale_indep_ordering) |
|
352 |
break; |
|
353 |
||
354 |
if (!abbrev_next) |
|
355 |
result += QLatin1String("yyyy"); |
|
356 |
else |
|
357 |
result += QLatin1String("yy"); |
|
358 |
||
359 |
break; |
|
360 |
} |
|
361 |
||
362 |
case 'E': |
|
363 |
{ |
|
364 |
if (!abbrev_next) |
|
365 |
result += QLatin1String("dddd"); |
|
366 |
else |
|
367 |
result += QLatin1String("ddd"); |
|
368 |
||
369 |
break; |
|
370 |
} |
|
371 |
||
372 |
case ':': |
|
373 |
{ |
|
374 |
// timesep 0-3 |
|
375 |
++i; |
|
376 |
if (i >= sys_fmt.size()) |
|
377 |
break; |
|
378 |
||
379 |
c = sys_fmt.at(i); |
|
380 |
if (c.isDigit() && c.digitValue() <= 3) { |
|
381 |
TChar s = locale->TimeSeparator(c.digitValue()); |
|
382 |
TUint val = s; |
|
383 |
// some indexes return zero for empty |
|
384 |
if (val > 0) |
|
385 |
result += QChar(val); |
|
386 |
} |
|
387 |
||
388 |
break; |
|
389 |
} |
|
390 |
||
391 |
case 'J': |
|
392 |
{ |
|
393 |
if (tf == ETime24 && !abbrev_next) |
|
394 |
result += QLatin1String("hh"); |
|
395 |
else |
|
396 |
result += QLatin1Char('h'); |
|
397 |
||
398 |
break; |
|
399 |
} |
|
400 |
||
401 |
case 'H': |
|
402 |
{ |
|
403 |
if (!abbrev_next) |
|
404 |
result += QLatin1String("hh"); |
|
405 |
else |
|
406 |
result += QLatin1Char('h'); |
|
407 |
||
408 |
break; |
|
409 |
} |
|
410 |
||
411 |
case 'I': |
|
412 |
{ |
|
413 |
result += QLatin1Char('h'); |
|
414 |
break; |
|
415 |
} |
|
416 |
||
417 |
case 'T': |
|
418 |
{ |
|
419 |
if (!abbrev_next) |
|
420 |
result += QLatin1String("mm"); |
|
421 |
else |
|
422 |
result += QLatin1Char('m'); |
|
423 |
||
424 |
break; |
|
425 |
} |
|
426 |
||
427 |
case 'S': |
|
428 |
{ |
|
429 |
if (!abbrev_next) |
|
430 |
result += QLatin1String("ss"); |
|
431 |
else |
|
432 |
result += QLatin1Char('s'); |
|
433 |
||
434 |
break; |
|
435 |
} |
|
436 |
||
437 |
case 'B': |
|
438 |
{ |
|
439 |
// only done for 12h clock |
|
440 |
if (tf == ETime24) |
|
441 |
break; |
|
442 |
} |
|
443 |
||
444 |
// fallthru to A |
|
445 |
case 'A': { |
|
446 |
// quickie to get capitalization, can't use s60 string as is because Qt 'hh' format's am/pm logic |
|
447 |
TAmPmName ampm = TAmPmName(); |
|
448 |
TChar first(ampm[0]); |
|
449 |
QString qtampm = QString::fromLatin1(first.IsUpper() ? "AP" : "ap"); |
|
450 |
||
451 |
int pos = locale->AmPmSymbolPosition(); |
|
452 |
||
453 |
if ((minus_mode && pos != ELocaleBefore) || |
|
454 |
(plus_mode && pos != ELocaleAfter)) |
|
455 |
break; |
|
456 |
||
457 |
if (!abbrev_next && locale->AmPmSpaceBetween()) { |
|
458 |
if (pos == ELocaleBefore) |
|
459 |
qtampm.append(QLatin1Char(' ')); |
|
460 |
else |
|
461 |
qtampm.prepend(QLatin1Char(' ')); |
|
462 |
} |
|
463 |
||
464 |
result += qtampm; |
|
465 |
} |
|
466 |
break; |
|
467 |
||
468 |
case '.': { |
|
469 |
// decimal sep |
|
470 |
TChar s = locale->DecimalSeparator(); |
|
471 |
TUint val = s; |
|
472 |
if (val > 0) |
|
473 |
result += QChar(val); |
|
474 |
} |
|
475 |
break; |
|
476 |
||
477 |
case 'C': |
|
478 |
{ |
|
479 |
// six digits in s60, three digits in qt |
|
480 |
if (!abbrev_next) { |
|
481 |
result += QLatin1String("zzz"); |
|
482 |
} else { |
|
483 |
// next char is number from 0-6, how many digits to display |
|
484 |
++i; |
|
485 |
if (i >= sys_fmt.size()) |
|
486 |
break; |
|
487 |
||
488 |
c = sys_fmt.at(i); |
|
489 |
||
490 |
if (c.isDigit()) { |
|
491 |
// try to match wanted digits |
|
492 |
QChar val(c.digitValue()); |
|
493 |
||
494 |
if (val >= 3) { |
|
495 |
result += QLatin1String("zzz"); |
|
496 |
} else if (val > 0) { |
|
497 |
result += QLatin1Char('z'); |
|
498 |
} |
|
499 |
} |
|
500 |
} |
|
501 |
break; |
|
502 |
} |
|
503 |
||
504 |
// these cases fallthru |
|
505 |
case '1': |
|
506 |
case '2': |
|
507 |
case '3': |
|
508 |
case '4': |
|
509 |
case '5': |
|
510 |
{ |
|
511 |
||
512 |
// shouldn't parse these with %F |
|
513 |
if (locale_indep_ordering) |
|
514 |
break; |
|
515 |
||
516 |
TDateFormat df = locale->DateFormat(); |
|
517 |
||
518 |
const char **locale_dep; |
|
519 |
switch (df) { |
|
520 |
default: // fallthru to american |
|
521 |
case EDateAmerican: |
|
522 |
locale_dep = us_locale_dep; |
|
523 |
break; |
|
524 |
case EDateEuropean: |
|
525 |
locale_dep = eu_locale_dep; |
|
526 |
break; |
|
527 |
case EDateJapanese: |
|
528 |
locale_dep = jp_locale_dep; |
|
529 |
break; |
|
530 |
} |
|
531 |
int offset = 0; |
|
532 |
if (abbrev_next) |
|
533 |
offset += 5; |
|
534 |
if (n_mode) |
|
535 |
offset += 10; |
|
536 |
||
537 |
result += QLatin1String(locale_dep[offset + (c.digitValue()-1)]); |
|
538 |
break; |
|
539 |
} |
|
540 |
||
541 |
case '%': // fallthru percent |
|
542 |
{ |
|
543 |
// any junk gets copied as is |
|
544 |
} |
|
545 |
default: |
|
546 |
{ |
|
547 |
result += c; |
|
548 |
break; |
|
549 |
} |
|
550 |
||
551 |
case 'Z': // Qt doesn't support these :( |
|
552 |
case 'X': |
|
553 |
case 'W': |
|
554 |
{ |
|
555 |
break; |
|
556 |
} |
|
557 |
} |
|
558 |
} else { |
|
559 |
// double any single quotes, don't begin escape |
|
560 |
if (c.unicode() == '\'') { |
|
561 |
// end open escape |
|
562 |
if (open_escape) { |
|
563 |
result += other; |
|
564 |
other.clear(); |
|
565 |
result += QLatin1Char('\''); |
|
566 |
open_escape = false; |
|
567 |
} |
|
568 |
||
569 |
other += c; |
|
570 |
} |
|
571 |
||
572 |
// gather chars and escape them in one go if any format chars are found |
|
573 |
if (!open_escape && qtformatchars.indexOf(c) != -1) { |
|
574 |
result += QLatin1Char('\''); |
|
575 |
open_escape = true; |
|
576 |
} |
|
577 |
other += c; |
|
578 |
} |
|
579 |
||
580 |
++i; |
|
581 |
} |
|
582 |
||
583 |
if (!other.isEmpty()) |
|
584 |
result += other; |
|
585 |
if (open_escape) |
|
586 |
result += QLatin1Char('\''); |
|
587 |
||
588 |
return result; |
|
589 |
} |
|
590 |
||
591 |
/*! |
|
592 |
Retrieves Symbian locale decimal separator. |
|
593 |
*/ |
|
594 |
static QString symbianDecimalPoint() |
|
595 |
{ |
|
596 |
TLocale *locale = _s60Locale.GetLocale(); |
|
597 |
||
598 |
TChar decPoint = locale->DecimalSeparator(); |
|
599 |
int val = decPoint; |
|
600 |
return QChar(val); |
|
601 |
} |
|
602 |
||
603 |
/*! |
|
604 |
Retrieves Symbian locale group separator. |
|
605 |
*/ |
|
606 |
static QString symbianGroupSeparator() |
|
607 |
{ |
|
608 |
TLocale *locale = _s60Locale.GetLocale(); |
|
609 |
||
610 |
TChar grpSep = locale->ThousandsSeparator(); |
|
611 |
int val = grpSep; |
|
612 |
return QChar(val); |
|
613 |
} |
|
614 |
||
615 |
/*! |
|
616 |
Retrieves Symbian locale zero digit. |
|
617 |
*/ |
|
618 |
static QString symbianZeroDigit() |
|
619 |
{ |
|
620 |
TLocale *locale = _s60Locale.GetLocale(); |
|
621 |
||
622 |
// TDigitType enumeration value returned by TLocale |
|
623 |
// will always correspond to zero digit unicode value. |
|
624 |
TDigitType digit = locale->DigitType(); |
|
625 |
return QChar(digit); |
|
626 |
} |
|
627 |
||
628 |
/*! |
|
629 |
Retrieves a day name from Symbian locale. The \a day is an integer |
|
630 |
from 1 to 7. When \a short_format is true the method returns |
|
631 |
the day in short format. Otherwise it returns the day in a long format. |
|
632 |
*/ |
|
633 |
static QString symbianDayName(int day, bool short_format) |
|
634 |
{ |
|
635 |
day -= 1; |
|
636 |
||
637 |
if (day < 0 || day > 6) |
|
638 |
return QString(); |
|
639 |
||
640 |
if (short_format) { |
|
641 |
return qt_TDes2QString(TDayNameAbb(TDay(day))); |
|
642 |
} else { |
|
643 |
return qt_TDes2QString(TDayName(TDay(day))); |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
/*! |
|
648 |
Retrieves a month name from Symbian locale. The \a month is an integer |
|
649 |
from 1 to 12. When \a short_format is true the method returns |
|
650 |
the month in short format. Otherwise it returns the month in a long format. |
|
651 |
*/ |
|
652 |
static QString symbianMonthName(int month, bool short_format) |
|
653 |
{ |
|
654 |
month -= 1; |
|
655 |
if (month < 0 || month > 11) |
|
656 |
return QString(); |
|
657 |
||
658 |
if (short_format) { |
|
659 |
return qt_TDes2QString(TMonthNameAbb(TMonth(month))); |
|
660 |
} else { |
|
661 |
return qt_TDes2QString(TMonthName(TMonth(month))); |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
/*! |
|
666 |
Retrieves date format from Symbian locale and |
|
667 |
transforms it to Qt format. |
|
668 |
||
669 |
When \a short_format is true the method returns |
|
670 |
short date format. Otherwise it returns the long format. |
|
671 |
*/ |
|
672 |
static QString symbianDateFormat(bool short_format) |
|
673 |
{ |
|
674 |
TPtrC dateFormat; |
|
675 |
||
676 |
if (short_format) { |
|
677 |
dateFormat.Set(ptrGetShortDateFormatSpec(_s60Locale)); |
|
678 |
} else { |
|
679 |
dateFormat.Set(ptrGetLongDateFormatSpec(_s60Locale)); |
|
680 |
} |
|
681 |
||
682 |
return s60ToQtFormat(qt_TDesC2QString(dateFormat)); |
|
683 |
} |
|
684 |
||
685 |
/*! |
|
686 |
Retrieves time format from Symbian locale and |
|
687 |
transforms it to Qt format. |
|
688 |
*/ |
|
689 |
static QString symbianTimeFormat() |
|
690 |
{ |
|
691 |
return s60ToQtFormat(qt_TDesC2QString(ptrGetTimeFormatSpec(_s60Locale))); |
|
692 |
} |
|
693 |
||
694 |
/*! |
|
695 |
Returns localized string representation of given \a date |
|
696 |
formatted with Symbian locale date format. |
|
697 |
||
698 |
If \a short_format is true the format will be a short version. |
|
699 |
Otherwise it uses a longer version. |
|
700 |
*/ |
|
701 |
static QString symbianDateToString(const QDate &date, bool short_format) |
|
702 |
{ |
|
703 |
int month = date.month() - 1; |
|
704 |
int day = date.day() - 1; |
|
705 |
int year = date.year(); |
|
706 |
||
707 |
TDateTime dateTime; |
|
708 |
dateTime.Set(year, TMonth(month), day, 0, 0, 0, 0); |
|
709 |
||
710 |
TTime timeStr(dateTime); |
|
711 |
TBuf<KMaxLongDateFormatSpec*2> buffer; |
|
712 |
||
713 |
TPtrC dateFormat; |
|
714 |
if (short_format) { |
|
715 |
dateFormat.Set(ptrGetShortDateFormatSpec(_s60Locale)); |
|
716 |
} else { |
|
717 |
dateFormat.Set(ptrGetLongDateFormatSpec(_s60Locale)); |
|
718 |
} |
|
719 |
||
720 |
TRAPD(err, ptrTimeFormatL(timeStr, buffer, dateFormat, *_s60Locale.GetLocale());) |
|
721 |
||
722 |
if (err == KErrNone) |
|
723 |
return qt_TDes2QString(buffer); |
|
724 |
else |
|
725 |
return QString(); |
|
726 |
} |
|
727 |
||
728 |
/*! |
|
729 |
Returns localized string representation of given \a time |
|
730 |
formatted with Symbian locale time format. |
|
731 |
*/ |
|
732 |
static QString symbianTimeToString(const QTime &time) |
|
733 |
{ |
|
734 |
int hour = time.hour(); |
|
735 |
int minute = time.minute(); |
|
736 |
int second = time.second(); |
|
737 |
int milliseconds = 0; |
|
738 |
||
739 |
TDateTime dateTime; |
|
740 |
dateTime.Set(0, TMonth(0), 0, hour, minute, second, milliseconds); |
|
741 |
||
742 |
TTime timeStr(dateTime); |
|
743 |
TBuf<KMaxTimeFormatSpec*2> buffer; |
|
744 |
||
745 |
TRAPD(err, ptrTimeFormatL( |
|
746 |
timeStr, |
|
747 |
buffer, |
|
748 |
ptrGetTimeFormatSpec(_s60Locale), |
|
749 |
*_s60Locale.GetLocale()); |
|
750 |
) |
|
751 |
||
752 |
if (err == KErrNone) |
|
753 |
return qt_TDes2QString(buffer); |
|
754 |
else |
|
755 |
return QString(); |
|
756 |
} |
|
757 |
||
758 |
/*! |
|
759 |
Returns the measurement system stored in Symbian locale |
|
760 |
||
761 |
\sa QLocale::MeasurementSystem |
|
762 |
*/ |
|
763 |
static QLocale::MeasurementSystem symbianMeasurementSystem() |
|
764 |
{ |
|
765 |
TLocale *locale = _s60Locale.GetLocale(); |
|
766 |
||
767 |
TUnitsFormat unitFormat = locale->UnitsGeneral(); |
|
768 |
if (unitFormat == EUnitsImperial) |
|
769 |
return QLocale::ImperialSystem; |
|
770 |
else |
|
771 |
return QLocale::MetricSystem; |
|
772 |
} |
|
773 |
||
774 |
QLocale QSystemLocale::fallbackLocale() const |
|
775 |
{ |
|
776 |
// load system data before query calls |
|
777 |
static QBasicAtomicInt initDone = Q_BASIC_ATOMIC_INITIALIZER(0); |
|
778 |
if (initDone.testAndSetRelaxed(0, 1)) { |
|
779 |
_s60Locale.LoadSystemSettings(); |
|
780 |
||
781 |
// Initialize platform version dependent function pointers |
|
782 |
ptrTimeFormatL = reinterpret_cast<FormatFunc> |
|
783 |
(qt_resolveS60PluginFunc(S60Plugin_TimeFormatL)); |
|
784 |
ptrGetTimeFormatSpec = reinterpret_cast<FormatSpecFunc> |
|
785 |
(qt_resolveS60PluginFunc(S60Plugin_GetTimeFormatSpec)); |
|
786 |
ptrGetLongDateFormatSpec = reinterpret_cast<FormatSpecFunc> |
|
787 |
(qt_resolveS60PluginFunc(S60Plugin_GetLongDateFormatSpec)); |
|
788 |
ptrGetShortDateFormatSpec = reinterpret_cast<FormatSpecFunc> |
|
789 |
(qt_resolveS60PluginFunc(S60Plugin_GetShortDateFormatSpec)); |
|
790 |
if (!ptrTimeFormatL) |
|
791 |
ptrTimeFormatL = &defaultTimeFormatL; |
|
792 |
if (!ptrGetTimeFormatSpec) |
|
793 |
ptrGetTimeFormatSpec = &defaultFormatSpec; |
|
794 |
if (!ptrGetLongDateFormatSpec) |
|
795 |
ptrGetLongDateFormatSpec = &defaultFormatSpec; |
|
796 |
if (!ptrGetShortDateFormatSpec) |
|
797 |
ptrGetShortDateFormatSpec = &defaultFormatSpec; |
|
798 |
bool ret = initDone.testAndSetRelease(1, 2); |
|
799 |
Q_ASSERT(ret); |
|
800 |
Q_UNUSED(ret); |
|
801 |
} |
|
802 |
while(initDone != 2) |
|
803 |
QThread::yieldCurrentThread(); |
|
804 |
||
805 |
TLanguage lang = User::Language(); |
|
806 |
QString locale = QLatin1String(qt_symbianLocaleName(lang)); |
|
807 |
return QLocale(locale); |
|
808 |
} |
|
809 |
||
810 |
/*! |
|
811 |
Generic query method for locale data. Provides indirection. |
|
812 |
Denotes the \a type of the query |
|
813 |
with \a in as input data depending on the query. |
|
814 |
||
815 |
\sa QSystemLocale::QueryType |
|
816 |
*/ |
|
817 |
QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const |
|
818 |
{ |
|
819 |
switch(type) { |
|
820 |
case DecimalPoint: |
|
821 |
return symbianDecimalPoint(); |
|
822 |
case GroupSeparator: |
|
823 |
return symbianGroupSeparator(); |
|
824 |
||
825 |
case ZeroDigit: |
|
826 |
return symbianZeroDigit(); |
|
827 |
||
828 |
case DayNameLong: |
|
829 |
case DayNameShort: |
|
830 |
return symbianDayName(in.toInt(), (type == DayNameShort) ); |
|
831 |
||
832 |
case MonthNameLong: |
|
833 |
case MonthNameShort: |
|
834 |
return symbianMonthName(in.toInt(), (type == MonthNameShort) ); |
|
835 |
||
836 |
case DateFormatLong: |
|
837 |
case DateFormatShort: |
|
838 |
return symbianDateFormat( (type == DateFormatShort) ); |
|
839 |
case TimeFormatLong: |
|
840 |
case TimeFormatShort: |
|
841 |
return symbianTimeFormat(); |
|
842 |
case DateTimeFormatLong: |
|
843 |
case DateTimeFormatShort: |
|
844 |
return symbianDateFormat( (type == DateTimeFormatShort) ) + QLatin1Char(' ') + symbianTimeFormat(); |
|
845 |
case DateToStringShort: |
|
846 |
case DateToStringLong: |
|
847 |
return symbianDateToString(in.toDate(), (type == DateToStringShort) ); |
|
848 |
case TimeToStringShort: |
|
849 |
case TimeToStringLong: |
|
850 |
return symbianTimeToString(in.toTime()); |
|
851 |
case DateTimeToStringShort: |
|
852 |
case DateTimeToStringLong: { |
|
853 |
const QDateTime dt = in.toDateTime(); |
|
854 |
return symbianDateToString(dt.date(), (type == DateTimeToStringShort) ) |
|
855 |
+ QLatin1Char(' ') + symbianTimeToString(dt.time()); |
|
856 |
} |
|
857 |
case MeasurementSystem: |
|
858 |
return static_cast<int>(symbianMeasurementSystem()); |
|
859 |
case LanguageId: |
|
860 |
case CountryId: { |
|
861 |
TLanguage language = User::Language(); |
|
862 |
QString locale = QLatin1String(qt_symbianLocaleName(language)); |
|
863 |
QLocale::Language lang; |
|
864 |
QLocale::Country cntry; |
|
865 |
getLangAndCountry(locale, lang, cntry); |
|
866 |
if (type == LanguageId) |
|
867 |
return lang; |
|
868 |
// few iso codes have no country and will use this |
|
869 |
if (cntry == QLocale::AnyCountry) |
|
870 |
return fallbackLocale().country(); |
|
871 |
||
872 |
return cntry; |
|
873 |
} |
|
874 |
case NegativeSign: |
|
875 |
case PositiveSign: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
break; |
0 | 877 |
case AMText: |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
878 |
return qt_TDes2QString(TAmPmName(TAmPm(EAm))); |
0 | 879 |
case PMText: |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
return qt_TDes2QString(TAmPmName(TAmPm(EPm))); |
0 | 881 |
default: |
882 |
break; |
|
883 |
} |
|
884 |
return QVariant(); |
|
885 |
} |
|
886 |
||
887 |
QT_END_NAMESPACE |