Merge "[2.2.1] Modify doxygen example of Encode/DecodeBase64StringN" into tizen_2.2
[platform/framework/native/appfw.git] / src / locales / FLcl_LocaleManagerImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18 * @file         FLcl_LocaleManagerImpl.cpp
19 * @brief        This is the implementation file for _LocaleManagerImpl class.
20 */
21 #include <unique_ptr.h>
22 #include <limits.h>
23 #include <time.h>
24 #include <runtime_info.h>
25 #include <unicode/calendar.h>
26 #include <unicode/timezone.h>
27 #include <unicode/locid.h>
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include <vconf.h>
31
32 #include <FIo.h>
33 #include <FBaseSysLog.h>
34 #include <FBase_StringConverter.h>
35
36 #include "FLcl_LocaleImpl.h"
37 #include "FLcl_TimeZoneImpl.h"
38 #include "FLcl_LocaleManagerImpl.h"
39
40
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Utility;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Io;
45
46 struct FreeXmlDoc
47 {
48         void operator ()(xmlDoc* p)
49         {
50                 if (p != null)
51                 {
52                         xmlFreeDoc(p);
53                 }
54         }
55 };
56
57 struct FreeCharPtr
58 {
59         void operator ()(char* p)
60         {
61                 if (p != null)
62                 {
63                         free(p);
64                 }
65         }
66 };
67
68 namespace Tizen { namespace Locales
69 {
70 static const char* LANGUAGE_LIST_FILE_PATH ="/opt/usr/data/setting/langlist.xml";
71 static const char* TIMEZONE_LIST_FILE_PATH = "/opt/usr/data/clock/tzlist.ini";
72 static const char* CLOCALE_LIST_FILE_PATH = "/opt/usr/etc/clocale.list";
73
74
75 Locale
76 _LocaleManagerImpl::GetSystemLocale(void)
77 {
78         char* pRegionPtr;
79         if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
80         {
81                 SetLastResult(E_SUCCESS);
82
83                 Locale ospLoc = _LocaleImpl(pRegionPtr).GetOspLocale();
84                 free(pRegionPtr);
85                 return ospLoc;
86         }
87
88         SetLastResult(E_SYSTEM);
89         return Locale(LANGUAGE_INVALID, COUNTRY_INVALID, null);
90 }
91
92 U_ICU_NAMESPACE::Locale
93 _LocaleManagerImpl::GetSystemIcuLocale(void)
94 {
95         char* pRegionPtr;
96         if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
97         {
98                 SetLastResult(E_SUCCESS);
99                 U_ICU_NAMESPACE::Locale locale(pRegionPtr);
100
101                 free(pRegionPtr);
102                 return locale;
103         }
104         return U_ICU_NAMESPACE::Locale();
105 }
106
107
108 IMap*
109 _LocaleManagerImpl::GetAvailableEglibcLocaesN(void)
110 {
111         File file;
112         result r = E_SUCCESS;
113         String clocaleFilePath(CLOCALE_LIST_FILE_PATH);
114         
115         std::unique_ptr<HashMap> pClocaleMap(new (std::nothrow) HashMap(SingleObjectDeleter));
116         SysTryReturn(NID_LCL, pClocaleMap, null, E_OUT_OF_MEMORY,
117                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
118         r = file.Construct(clocaleFilePath, "r");
119         SysTryReturn(NID_LCL, r == E_SUCCESS, null,E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the clocale list from the list file.");
120
121         pClocaleMap->Construct();
122
123         do
124         {
125                 String strBuf;
126                 r = file.Read(strBuf);
127                 if ( r == E_END_OF_FILE)
128                 {
129                         break;
130                 }
131                 SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the clocale list.", GetErrorMessage(r));
132                 std::unique_ptr< String > pClocaleId(new (std::nothrow) String());
133                 SysTryReturn(NID_LCL, pClocaleId, null, E_OUT_OF_MEMORY,
134                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
135                 r = strBuf.SubString(0, 5, *pClocaleId);
136                 if (IsFailed(r))
137                 {
138                         continue;
139                 }
140
141                 if (!pClocaleMap->ContainsKey(*(pClocaleId.get())))
142                 {
143                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
144                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
145                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
146
147                         r = pClocaleMap->Add(pClocaleId.get(), pDummyValue.get());
148                         SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,
149                                 "[%s] It is failed to add the clocale id into the clocale map.", GetErrorMessage(r));
150                         pClocaleId.release();
151                         pDummyValue.release();
152                 }
153         }while(1);
154         return pClocaleMap.release();
155 }
156
157 IList*
158 _LocaleManagerImpl::GetAvailableLocalesN(void)
159 {
160         result r = E_SUCCESS;
161         int count = 0;
162         const U_ICU_NAMESPACE::Locale* pIcuLocaleList = U_ICU_NAMESPACE::Locale::getAvailableLocales(count);
163         SysTryReturn(NID_LCL, count > 0, null, E_SYSTEM,
164                 "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
165
166         std::unique_ptr<LinkedList> pAvailableLocaleList(new (std::nothrow) LinkedList(SingleObjectDeleter));
167         SysTryReturn(NID_LCL, pAvailableLocaleList, null, E_OUT_OF_MEMORY,
168                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
169
170         std::unique_ptr< IMap > pClocaleMap(GetAvailableEglibcLocaesN());
171
172         for (int i = 0; i < count; i++)
173         {
174                 const U_ICU_NAMESPACE::Locale* pIcuLocale = (pIcuLocaleList + i);
175                 SysTryReturn(NID_LCL, pIcuLocale, null, E_SYSTEM,
176                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
177                 Locale ospLocale = _LocaleImpl(*pIcuLocale).GetOspLocale();
178                 if (_LocaleImpl::IsSupported(ospLocale))
179                 {
180                         std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(ospLocale));
181                         SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
182                                                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
183
184                         String localeId(pIcuLocale->getLanguage());
185                         localeId = localeId + L"_" + String(pIcuLocale->getCountry());
186
187                         if (!pAvailableLocaleList->Contains(*(pLocale.get())) && pClocaleMap->ContainsKey(localeId))
188                         {
189                                 r = pAvailableLocaleList->Add(pLocale.get());
190                                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make the locale list");
191                                 pLocale.release();
192                         }
193                 }
194         }
195
196         SetLastResult(E_SUCCESS);
197         return pAvailableLocaleList.release();
198 }
199
200 String
201 _LocaleManagerImpl::GetSelectedLanguage(void)
202 {
203         char* pLanguagePtr;
204
205         int ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &pLanguagePtr);
206         SysTryReturn(NID_LCL, ret == RUNTIME_INFO_ERROR_NONE, String(), E_SYSTEM,
207                         "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
208         String language(_LocaleImpl(pLanguagePtr).GetLanguageCodeString(false));
209         free(pLanguagePtr);
210
211         return language;
212 }
213
214 // FALLBACk should be removed after checking the SLP change.
215 IList*
216 _LocaleManagerImpl::GetAvailableLanguagesFallbackN(void)
217 {
218         std::unique_ptr<IList> pLocaleList (GetAvailableLocalesN());
219         std::unique_ptr<HashMap> pLanguageMap(new (std::nothrow) HashMap(SingleObjectDeleter));
220         SysTryReturn(NID_LCL, pLanguageMap, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
221
222         pLanguageMap->Construct();
223
224         std::unique_ptr<ArrayList> pAvailableLanguageList(new (std::nothrow) ArrayList(SingleObjectDeleter));
225         SysTryReturn(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
226         pAvailableLanguageList->Construct();
227
228         for (int i = 0; i < pLocaleList->GetCount() ; i++)
229         {
230                 Locale* pLocale = (Locale*)pLocaleList->GetAt(i);
231                 std::unique_ptr<String> pLanguageCode(new (std::nothrow) String(pLocale->GetLanguageCodeString()));
232                 SysTryReturn(NID_LCL, pLanguageCode, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
233
234                 if (!pLanguageMap->ContainsKey(*pLanguageCode))
235                 {
236                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
237                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
238
239                         result r = pLanguageMap->Add(pLanguageCode.get(), pDummyValue.get());
240                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make a language map.");
241
242                         std::unique_ptr<String> pLangCode(new (std::nothrow) String(*(pLanguageCode.get())));
243                         r = pAvailableLanguageList->Add(pLangCode.get());
244                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make a language list.");
245
246                         pLanguageCode.release();
247                         pDummyValue.release();
248                         pLangCode.release();
249                 }
250         }
251
252         SetLastResult(E_SUCCESS);
253         return pAvailableLanguageList.release(); 
254 }
255 IList*
256 _LocaleManagerImpl::GetAvailableLanguagesN(void)
257 {
258         std::unique_ptr<ArrayList> pAvailableLanguageList(new (std::nothrow) ArrayList(SingleObjectDeleter));
259         SysTryReturn(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
260
261         xmlNodePtr cur = null;
262         std::unique_ptr< xmlDoc, FreeXmlDoc > pDoc(xmlParseFile(LANGUAGE_LIST_FILE_PATH));
263         if (pDoc == null)
264         {
265                 SysLog(NID_LCL, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
266                 return GetAvailableLanguagesFallbackN();
267         }
268 //      SysTryReturn(NID_LCL, pDoc != null, null, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
269
270         cur = xmlDocGetRootElement(pDoc.get());
271         SysTryReturn(NID_LCL, cur != null, null, E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
272         SysTryReturn(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, null, E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
273
274         cur = cur->xmlChildrenNode;
275
276         pAvailableLanguageList->Construct();
277
278         for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
279         {
280                 if (cur_node->type == XML_ELEMENT_NODE)
281                 {
282                         std::unique_ptr < char, FreeCharPtr > pLocId((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
283                         Locale loc = _LocaleImpl(pLocId.get()).GetOspLocale();
284                         std::unique_ptr<String> pLanguageLocaleID(new (std::nothrow) String(loc.GetLanguageCodeString()));
285                         SysTryReturn(NID_LCL, pLanguageLocaleID, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
286
287                         if (!pAvailableLanguageList->Contains(*(pLanguageLocaleID.get())))
288                         {
289                                 result r = pAvailableLanguageList->Add(pLanguageLocaleID.get());
290                                 SysTryReturn(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
291                                         "[%s] It is failed to add a locale string [%ls].", GetErrorMessage(E_SYSTEM), pLanguageLocaleID->GetPointer());
292                                 pLanguageLocaleID.release();
293                         }
294                 }
295         }
296
297         SetLastResult(E_SUCCESS);
298         return pAvailableLanguageList.release();
299 }
300
301 IList*
302 _LocaleManagerImpl::GetAvailableLanguageLocalesN(void)
303 {
304         std::unique_ptr<ArrayList> pAvailableLanguageList(new (std::nothrow) ArrayList(SingleObjectDeleter));
305         SysTryReturn(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
306
307         xmlNodePtr cur = null;
308         std::unique_ptr< xmlDoc, FreeXmlDoc > pDoc(xmlParseFile(LANGUAGE_LIST_FILE_PATH));
309         SysTryReturn(NID_LCL, pDoc != null, null, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
310
311         cur = xmlDocGetRootElement(pDoc.get());
312         SysTryReturn(NID_LCL, cur != null, null, E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
313         SysTryReturn(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, null, E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
314
315         cur = cur->xmlChildrenNode;
316
317         pAvailableLanguageList->Construct();
318
319         for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
320         {
321                 if (cur_node->type == XML_ELEMENT_NODE)
322                 {
323                         std::unique_ptr< char, FreeCharPtr> pLocId((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
324                         Locale loc = _LocaleImpl(pLocId.get()).GetOspLocale();
325                         if (_LocaleImpl::IsSupported(loc))
326                         {
327                                 std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(loc));
328                                 SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
329                                         "[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
330
331                                 if (!pAvailableLanguageList->Contains(*(pLocale.get())))
332                                 {
333                                         result r = pAvailableLanguageList->Add(pLocale.get());
334                                         SysTryReturn(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
335                                                 "[%s] It is failed to add a locale string [%s].", GetErrorMessage(E_SYSTEM), pLocId.get());
336                                         pLocale.release();
337                                 }
338                         }
339                 }
340         }
341
342         SetLastResult(E_SUCCESS);
343         return pAvailableLanguageList.release();
344 }
345
346
347 IMap*
348 _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* pIcuTZStrList)
349 {
350         SysTryReturn(NID_LCL, pIcuTZStrList, null, E_SYSTEM,
351                 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
352
353         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
354         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
355                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
356         pTimeZoneMap->Construct();
357
358         result r = E_SUCCESS;
359         int resultLength = -1;
360         UErrorCode ec = U_ZERO_ERROR;
361         const char* pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
362         std::unique_ptr<IMap> pTZMap(GetAvailableTimeZonesN());
363         r = GetLastResult();
364         SysTryReturn(NID_LCL, pTZMap, null, r, "[%s] Fail to get available time zone list", GetErrorMessage(r));
365
366         while (pIcuTZStr != null)
367         {
368                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(pIcuTZStr));
369                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
370                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
371                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())) && pTZMap->ContainsKey(*(pTimeZone.get())))
372                 {
373                         std::unique_ptr< String > pDummyValue(new  (std::nothrow) String());
374                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
375                         r = pTimeZoneMap->Add(pTimeZone.get(), pDummyValue.get());
376                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to add a TZ into Map.");
377                         pTimeZone.release();
378                         pDummyValue.release();
379                 }
380
381                 pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
382         }
383         SetLastResult(E_SUCCESS);
384         return pTimeZoneMap.release();
385 }
386
387 static const int TIMEZONE_MAX = 224;
388 static const char* TimeZoneList[TIMEZONE_MAX] =
389 {
390         "Africa/Abidjan",
391         "Africa/Accra",
392         "Africa/Addis_Ababa",
393         "Africa/Algiers",
394         "Africa/Asmara",
395         "Africa/Bamako",
396         "Africa/Bangui",
397         "Africa/Bissau",
398         "Africa/Cairo",
399         "Africa/Casablanca",
400         "Africa/Conakry",
401         "Africa/Dakar",
402         "Africa/Dar_es_Salaam",
403         "Africa/Djibouti",
404         "Africa/Douala",
405         "Africa/Freetown",
406         "Africa/Gaborone",
407         "Africa/Harare",
408         "Africa/Johannesburg",
409         "Africa/Kampala",
410         "Africa/Khartoum",
411         "Africa/Kinshasa",
412         "Africa/Lagos",
413         "Africa/Luanda",
414         "Africa/Lubumbashi",
415         "Africa/Lusaka",
416         "Africa/Malabo",
417         "Africa/Maputo",
418         "Africa/Mogadishu",
419         "Africa/Monrovia",
420         "Africa/Nairobi",
421         "Africa/Ndjamena",
422         "Africa/Niamey",
423         "Africa/Nouakchott",
424         "Africa/Ouagadougou",
425         "Africa/Tripoli",
426         "Africa/Tunis",
427         "America/Anchorage",
428         "America/Antigua",
429         "America/Argentina/Buenos_Aires",
430         "America/Asuncion",
431         "America/Barbados",
432         "America/Belize",
433         "America/Bogota",
434         "America/Caracas",
435         "America/Cayenne",
436         "America/Chicago",
437         "America/Costa_Rica",
438         "America/Denver",
439         "America/Detroit",
440         "America/El_Salvador",
441         "America/Godthab",
442         "America/Guadeloupe",
443         "America/Guatemala",
444         "America/Guayaquil",
445         "America/Guyana",
446         "America/Halifax",
447         "America/Havana",
448         "America/Indiana/Indianapolis",
449         "America/Jamaica",
450         "America/Kentucky/Louisville",
451         "America/La_Paz",
452         "America/Lima",
453         "America/Los_Angeles",
454         "America/Managua",
455         "America/Marigot",
456         "America/Martinique",
457         "America/Mazatlan",
458         "America/Mexico_City",
459         "America/Montevideo",
460         "America/Montreal",
461         "America/New_York",
462         "America/Nome",
463         "America/Panama",
464         "America/Paramaribo",
465         "America/Phoenix",
466         "America/Port-au-Prince",
467         "America/Puerto_Rico",
468         "America/Recife",
469         "America/Regina",
470         "America/Santiago",
471         "America/Santo_Domingo",
472         "America/Sao_Paulo",
473         "America/St_Johns",
474         "America/St_Thomas",
475         "America/Tegucigalpa",
476         "America/Tijuana",
477         "America/Toronto",
478         "America/Tortola",
479         "America/Vancouver",
480         "America/Winnipeg",
481         "Asia/Aden",
482         "Asia/Almaty",
483         "Asia/Amman",
484         "Asia/Anadyr",
485         "Asia/Ashgabat",
486         "Asia/Baghdad",
487         "Asia/Bahrain",
488         "Asia/Baku",
489         "Asia/Bangkok",
490         "Asia/Beirut",
491         "Asia/Bishkek",
492         "Asia/Colombo",
493         "Asia/Damascus",
494         "Asia/Dhaka",
495         "Asia/Dubai",
496         "Asia/Dushanbe",
497         "Asia/Ho_Chi_Minh",
498         "Asia/Hong_Kong",
499         "Asia/Hovd",
500         "Asia/Irkutsk",
501         "Asia/Istanbul",
502         "Asia/Jakarta",
503         "Asia/Jayapura",
504         "Asia/Jerusalem",
505         "Asia/Kabul",
506         "Asia/Kamchatka",
507         "Asia/Karachi",
508         "Asia/Kathmandu",
509         "Asia/Kolkata",
510         "Asia/Krasnoyarsk",
511         "Asia/Kuala_Lumpur",
512         "Asia/Kuwait",
513         "Asia/Macau",
514         "Asia/Magadan",
515         "Asia/Makassar",
516         "Asia/Manila",
517         "Asia/Muscat",
518         "Asia/Novokuznetsk",
519         "Asia/Novosibirsk",
520         "Asia/Omsk",
521         "Asia/Phnom_Penh",
522         "Asia/Pyongyang",
523         "Asia/Qatar",
524         "Asia/Rangoon",
525         "Asia/Riyadh",
526         "Asia/Sakhalin",
527         "Asia/Seoul",
528         "Asia/Shanghai",
529         "Asia/Singapore",
530         "Asia/Taipei",
531         "Asia/Tashkent",
532         "Asia/Tbilisi",
533         "Asia/Tehran",
534         "Asia/Tokyo",
535         "Asia/Ulan_Bator",
536         "Asia/Vladivostok",
537         "Asia/Yakutsk",
538         "Asia/Yekaterinburg",
539         "Asia/Yerevan",
540         "Atlantic/Azores",
541         "Atlantic/Canary",
542         "Atlantic/Reykjavik",
543         "Atlantic/South_Georgia",
544         "Australia/Adelaide",
545         "Australia/Brisbane",
546         "Australia/Canberra",
547         "Australia/Darwin",
548         "Australia/Hobart",
549         "Australia/Melbourne",
550         "Australia/Perth",
551         "Australia/Sydney",
552         "CST6CDT",
553         "EST5EDT",
554         "Europe/Amsterdam",
555         "Europe/Athens",
556         "Europe/Belgrade",
557         "Europe/Berlin",
558         "Europe/Bratislava",
559         "Europe/Brussels",
560         "Europe/Bucharest",
561         "Europe/Budapest",
562         "Europe/Chisinau",
563         "Europe/Copenhagen",
564         "Europe/Dublin",
565         "Europe/Helsinki",
566         "Europe/Istanbul",
567         "Europe/Kaliningrad",
568         "Europe/Kiev",
569         "Europe/Lisbon",
570         "Europe/Ljubljana",
571         "Europe/London",
572         "Europe/Luxembourg",
573         "Europe/Madrid",
574         "Europe/Malta",
575         "Europe/Minsk",
576         "Europe/Moscow",
577         "Europe/Paris",
578         "Europe/Podgorica",
579         "Europe/Prague",
580         "Europe/Riga",
581         "Europe/Rome",
582         "Europe/Samara",
583         "Europe/San_Marino",
584         "Europe/Skopje",
585         "Europe/Sofia",
586         "Europe/Stockholm",
587         "Europe/Tallinn",
588         "Europe/Vaduz",
589         "Europe/Vienna",
590         "Europe/Vilnius",
591         "Europe/Volgograd",
592         "Europe/Warsaw",
593         "Europe/Zagreb",
594         "Europe/Zurich",
595         "Indian/Antananarivo",
596         "Indian/Chagos",
597         "Indian/Maldives",
598         "Indian/Mauritius",
599         "Indian/Reunion",
600         "MST7MDT",
601         "Pacific/Auckland",
602         "Pacific/Easter",
603         "Pacific/Fiji",
604         "Pacific/Galapagos",
605         "Pacific/Guam",
606         "Pacific/Honolulu",
607         "Pacific/Midway",
608         "Pacific/Noumea",
609         "Pacific/Pago_Pago",
610         "Pacific/Tahiti",
611         "Pacific/Tarawa",
612         "Pacific/Tongatapu",
613         "PST8PDT"
614 }; 
615
616
617 IMap*
618 _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void)
619 {
620         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
621         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
622                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
623
624         result r = E_SUCCESS;
625         int index = 0;
626
627         pTimeZoneMap->Construct();
628
629         do
630         {
631                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(TimeZoneList[index++]));
632                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
633                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
634
635                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
636                 {
637                         std::unique_ptr< String > pDummyValue (new  (std::nothrow) String());
638                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
639
640                         r = pTimeZoneMap->Add(pTimeZone.get(), pDummyValue.get());
641                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make Timezone list.");
642
643                         pTimeZone.release();
644                         pDummyValue.release();
645                 }
646         }while (index < TIMEZONE_MAX);
647
648         SetLastResult(E_SUCCESS);
649         return pTimeZoneMap.release();
650 }
651
652
653 IMap*
654 _LocaleManagerImpl::GetAvailableTimeZonesN(void)
655 {
656         File file;
657         String tzFilePath(TIMEZONE_LIST_FILE_PATH);
658         result r = E_SUCCESS;
659
660         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
661         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
662                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
663         r = file.Construct(tzFilePath, "r");
664         if (IsFailed(r))
665         {
666                 SysLog(NID_LCL,"[E_FILE_NOT_FOUND] It is failed to get the tzlist from the ini file.");
667                 return GetAvailableTimeZonesFallbackN();
668         }
669 //      SysTryReturn(NID_LCL, r == E_SUCCESS, null,E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the tzlist from the ini file.");
670
671         pTimeZoneMap->Construct();
672
673         do
674         {
675                 std::unique_ptr<String> pTimeZone(new (std::nothrow) String());
676                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
677                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
678                 r = file.Read(*(pTimeZone.get()));
679                 if ( r == E_END_OF_FILE)
680                 {
681                         break;
682                 }
683                 SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the tzlist.", GetErrorMessage(r));
684                 pTimeZone->Replace(L"\n", L"\0");
685
686                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
687                 {
688                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
689                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
690                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
691
692                         r = pTimeZoneMap->Add(pTimeZone.get(), pDummyValue.get());
693                         SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,"[%s] It is failed to make the tz list.", GetErrorMessage(r));
694                         pTimeZone.release();
695                         pDummyValue.release();
696                 }
697         }while (1);
698
699         SetLastResult(E_SUCCESS);
700         return pTimeZoneMap.release();
701 }
702
703
704 IMap*
705 _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset)
706 {
707         std::unique_ptr<U_ICU_NAMESPACE::StringEnumeration> pIcuTzList(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
708         SysTryReturn(NID_LCL, pIcuTzList, null, E_SYSTEM, "[E_SYSTEM] It is failed to get Icu TZ list.");
709         IMap* pTzList =  GetAvailableTimeZonesN(pIcuTzList.get());
710         return pTzList;
711 }
712
713
714 TimeZone
715 _LocaleManagerImpl::GetSystemTimeZone(void)
716 {
717         std::unique_ptr< char, FreeCharPtr> tzId(vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID));
718         SysTryReturn(NID_LCL, tzId, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone.");
719         SysLog(NID_LCL, "System TimeZone id [%s]", tzId.get());
720
721         TimeZone timeZone;
722         DateTime utcTime;
723         struct tm gmTime;
724         struct tm*  pGmTime = null;
725         time_t currTime = time(null);
726
727         pGmTime = gmtime_r(&currTime, &gmTime);
728         SysTryReturn(NID_LCL, pGmTime, TimeZone(-1, ""), E_SYSTEM, "It is failed to convert the time value to UTC time.");
729
730         utcTime.SetValue(gmTime.tm_year + 1900, gmTime.tm_mon + 1, gmTime.tm_mday, gmTime.tm_hour, gmTime.tm_min, gmTime.tm_sec);
731
732         result r = Tizen::Locales::TimeZone::GetTimeZone(String(tzId.get()), utcTime, timeZone);
733         SysTryReturn(NID_LCL, r == E_SUCCESS, TimeZone(-1, ""), r, "[%s] error occurs.", GetErrorMessage(r));
734         return timeZone;
735 }
736
737 result
738 _LocaleManagerImpl::IsSupportedLocale(const Tizen::Locales::Locale& locale, bool& isSupportedLocale)
739 {
740         isSupportedLocale = _LocaleImpl::IsSupported(locale);
741         return E_SUCCESS;
742 }
743
744 };
745 };      // Tizen::Locales