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