2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSys_SettingLocaleProvider.cpp
19 * @brief This is the implementation for the _SettingLocaleProvider class.
22 #include <unique_ptr.h>
24 #include <libxml/xpath.h>
25 #include <libxml/tree.h>
30 #include <FBaseSysLog.h>
33 #include <FBase_StringConverter.h>
35 #include "FSys_SettingInfo.h"
36 #include "FSys_SettingLocaleProvider.h"
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Base::Utility;
44 using namespace Tizen::Locales;
46 namespace Tizen { namespace System
50 static const wchar_t* _LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
51 static const wchar_t* _LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
52 static const char* _LANGUAGE_LIST_FILE_PATH = "/opt/usr/data/setting/langlist.xml";
55 static const wchar_t* _LOCALE_DATE_FORMAT = L"http://tizen.org/setting/locale.date.format";
56 static const wchar_t* _LOCALE_DATETIME_FORMAT = L"http://tizen.org/setting/locale.date_time.format";
57 static const wchar_t* _LOCALE_TIME_FORMAT = L"http://tizen.org/setting/locale.time.format";
58 static const wchar_t* _LOCALE_TIME_FORMAT_24HOUR = L"http://tizen.org/setting/locale.time.format.24hour";
60 static const wchar_t* _LOCALE_WEEK_FORMAT_FIRSTDAY = L"http://tizen.org/setting/locale.week.format.firstday";
61 static const wchar_t* _LOCALE_WEEK_FORMAT_FIRSTDAY_MONDAY = L"Monday";
62 static const wchar_t* _LOCALE_WEEK_FORMAT_FIRSTDAY_SUNDAY = L"Sunday";
64 static const int _LOCALE_WEEK_FORMAT_VCONF_SUNDAY = 0;
65 static const int _LOCALE_WEEK_FORMAT_VCONF_MONDAY = 1;
68 static const wchar_t* _LOCALE_TIMEZONE = L"http://tizen.org/setting/locale.time_zone";
69 static const wchar_t* _LOCALE_UPDATE_AUTO= L"http://tizen.org/setting/locale.update.auto";
71 static const char* _LOCALE_TIMEZONE_ROOT_PATH = "/usr/share/zoneinfo/";
72 static const char* _LOCALE_TIMEZONE_LINK = "/opt/etc/localtime";
73 static const int _LOCALE_TIMEZONE_ROOT_PATH_LENGTH = 20;
76 static const wchar_t* _LOCALE_DATE = L"http://tizen.org/setting/locale.date";
77 static const wchar_t* _LOCALE_TIME = L"http://tizen.org/setting/locale.time";
78 static const wchar_t* _LOCALE_DATETIME = L"http://tizen.org/setting/locale.date_time";
82 void operator()(char* pValue)
92 _SettingLocaleProvider::_SettingLocaleProvider()
95 errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, SettingEventRuntimeInfo, null);
98 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register region event listener");
101 errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, SettingEventRuntimeInfo, null);
104 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register language event listener");
107 errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, SettingEventRuntimeInfo, null);
110 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register 24hour format event listener");
113 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, SettingEventVConf, null);
116 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
119 errorCode = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, SettingEventVConf, null);
122 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
125 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, SettingEventVConf, null);
128 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
131 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, SettingEventVConf, null);
134 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL event listener");
138 _SettingLocaleProvider::~_SettingLocaleProvider()
141 errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION);
144 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister region event listener");
147 errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE);
150 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register language event listener");
153 errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED);
156 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register 24hour format event listener");
158 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, SettingEventVConf);
161 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
164 errorCode = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, SettingEventVConf);
167 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
170 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, SettingEventVConf);
173 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_TIMEZONE_ID event listener");
176 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, SettingEventVConf);
179 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL event listener");
184 _SettingLocaleProvider::GetValue(const String& key, bool& value)
187 result r = E_OBJ_NOT_FOUND;
188 if(key == _LOCALE_TIME_FORMAT_24HOUR)
190 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support 24hour format feature.");
192 bool is24HoueEnabled = false;
193 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is24HoueEnabled);
194 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the SYSTEM_INFO_KEY__WIFI_SUPPORTED");
195 value = is24HoueEnabled;
197 else if (key == _LOCALE_UPDATE_AUTO)
199 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support locale auto update feature.");
201 int isAutomaticUpdate = 0;
202 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, &isAutomaticUpdate);
203 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL vconf");
204 if(isAutomaticUpdate == 1)
217 _SettingLocaleProvider::SetValue(const String& key, const bool value)
220 result r = E_OBJ_NOT_FOUND;
222 if(key == _LOCALE_TIME_FORMAT_24HOUR)
224 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support 24hour format feature.");
226 errorCode = vconf_set_int(VCONFKEY_REGIONFORMAT_TIME1224, value ? VCONFKEY_TIME_FORMAT_24 : VCONFKEY_TIME_FORMAT_12);
227 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_REGIONFORMAT_TIME1224 vconf");
229 else if(key == _LOCALE_UPDATE_AUTO)
231 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support locale auto update feature.");
233 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, value);
234 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL vconf");
240 _SettingLocaleProvider::GetValue(const String& key, String& value)
243 result r = E_OBJ_NOT_FOUND;
245 if (key == _LOCALE_COUNTRY || key == _LOCALE_LANGUAGE)
247 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support %ls feature.", key.GetPointer());
250 unique_ptr<char, charDeleter> pLocale(null);
252 runtime_info_key_e vconfKey = (key == _LOCALE_COUNTRY)
253 ? RUNTIME_INFO_KEY_REGION // Region locale
254 : RUNTIME_INFO_KEY_LANGUAGE; // Display language locale
256 errorCode = runtime_info_get_value_string(vconfKey, &pTemp);
257 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE && pTemp != null, E_SYSTEM, "[E_SYSTEM] runtime_info_get_value_string [%ls] failed", key.GetPointer());
258 pLocale.reset(pTemp);
259 icu::Locale icuLocale(pLocale.get());
260 String localeString(icuLocale.getISO3Language());
261 String languageScriptTmp(icuLocale.getScript());
263 if (!languageScriptTmp.IsEmpty())
265 String languageScript;
266 languageScriptTmp.ToLowerCase(languageScript);
267 localeString.Append(L"-");
268 localeString.Append(languageScript);
270 localeString.Append("_");
272 localeString.Append(icuLocale.getCountry());
274 value = localeString;
276 else if ( key == _LOCALE_TIME_FORMAT)
278 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support date format feature.");
281 unique_ptr<char, charDeleter> pTimeFormat(null);
283 bool selected24Format = false;
285 r = GetValue(_LOCALE_TIME_FORMAT_24HOUR, selected24Format);
287 if (selected24Format == true)
289 pTemp = __icu.GetDateTimeFormatN(_ICU_TIME_24_FORMAT);
293 pTemp = __icu.GetDateTimeFormatN(_ICU_TIME_12_FORMAT);
295 SysTryReturnResult(NID_SYS, pTemp != null, E_SYSTEM, "Failed to get time format");
296 pTimeFormat.reset(pTemp);
297 r = StringUtil::Utf8ToString(pTimeFormat.get(), value);
299 else if ( key == _LOCALE_DATE_FORMAT)
301 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support date format feature.");
304 unique_ptr<char, charDeleter> pDateFormat(__icu.GetDateTimeFormatN(_ICU_DATE_FORMAT));
305 SysTryReturnResult(NID_SYS, pDateFormat.get() != null, E_SYSTEM, "It is failed to get date format");
307 r = StringUtil::Utf8ToString(pDateFormat.get(), value);
309 else if (key == _LOCALE_DATETIME_FORMAT)
311 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support date time format feature.");
314 unique_ptr<char, charDeleter> pDateFormat(__icu.GetDateTimeFormatN(_ICU_DATE_FORMAT));
315 unique_ptr<char, charDeleter> pTimeFormat(null);
318 bool selected24Format = false;
320 SysLog(NID_SYS, "Date Time format is %s.", pDateFormat.get());
321 SysTryReturnResult(NID_SYS, pDateFormat.get() != null, E_SYSTEM, "It is failed to get date format.");
323 r = GetValue(_LOCALE_TIME_FORMAT_24HOUR, selected24Format);
324 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get time format.");
326 SysLog(NID_SYS, "24hour format, %d", selected24Format);
328 if (selected24Format == true)
330 pTemp = __icu.GetDateTimeFormatN(_ICU_TIME_24_FORMAT);
334 pTemp = __icu.GetDateTimeFormatN(_ICU_TIME_12_FORMAT);
337 SysTryReturnResult(NID_SYS, pTemp != null, E_SYSTEM, "It is failed to get time format.");
338 pTimeFormat.reset(pTemp);
339 r = StringUtil::Utf8ToString(pDateFormat.get(), value);
340 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert string to UTF8.");
341 r = StringUtil::Utf8ToString(pTimeFormat.get(), timeFormat);
342 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert string to UTF8.");
345 value.Append(timeFormat);
347 else if (key == _LOCALE_WEEK_FORMAT_FIRSTDAY)
349 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support week format feature.");
355 errorCode = vconf_get_int(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, &firstDay);
356 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT vconf");
358 if (firstDay == _LOCALE_WEEK_FORMAT_VCONF_SUNDAY)
360 value = _LOCALE_WEEK_FORMAT_FIRSTDAY_SUNDAY;
362 else if (firstDay == _LOCALE_WEEK_FORMAT_VCONF_MONDAY)
364 value = _LOCALE_WEEK_FORMAT_FIRSTDAY_MONDAY;
371 else if (key == _LOCALE_TIMEZONE)
373 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support time zone feature.");
376 char pTZPath[256] = {0,};
377 ssize_t nLen = readlink(_LOCALE_TIMEZONE_LINK, pTZPath, sizeof(pTZPath)-1);
380 pTZPath[nLen] = '\0';
384 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get timezone");
387 value.Append(&pTZPath[_LOCALE_TIMEZONE_ROOT_PATH_LENGTH]);
389 else if (key == _LOCALE_DATE)
391 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support date feature.");
394 DateTime currentTime;
395 SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
396 String currentFormat;
397 GetValue(_LOCALE_DATE_FORMAT, currentFormat);
399 unique_ptr<DateTimeFormatter> pFormatter(DateTimeFormatter::CreateTimeFormatterN());
400 SysTryReturnResult(NID_SYS, pFormatter != null, E_OUT_OF_MEMORY, "It is failed to create DateTimeFomatter");
401 pFormatter->ApplyPattern(currentFormat);
403 pFormatter->Format(currentTime, value);
405 else if (key == _LOCALE_DATETIME)
407 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support date time feature.");
410 DateTime currentTime;
411 SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
412 String currentFormat;
413 GetValue(_LOCALE_DATETIME_FORMAT, currentFormat);
415 unique_ptr<DateTimeFormatter> pFormatter(DateTimeFormatter::CreateTimeFormatterN());
416 pFormatter->ApplyPattern(currentFormat);
418 pFormatter->Format(currentTime, value);
420 else if (key == _LOCALE_TIME)
422 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support time feature.");
425 DateTime currentTime;
426 SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
427 String currentFormat;
428 GetValue(_LOCALE_TIME_FORMAT, currentFormat);
430 unique_ptr<DateTimeFormatter> pFormatter(DateTimeFormatter::CreateTimeFormatterN());
431 pFormatter->ApplyPattern(currentFormat);
433 pFormatter->Format(currentTime, value);
439 _SettingLocaleProvider::SetValue(const String& key, const String value)
442 result r = E_OBJ_NOT_FOUND;
444 if(key == _LOCALE_COUNTRY || key == _LOCALE_LANGUAGE)
446 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support locale country selection feature.");
450 unique_ptr<char []> lang (_StringConverter::CopyToCharArrayN(value));
451 SysTryReturnResult(NID_SYS, lang != null, E_SYSTEM, "It is failed to convert String to string");
453 icu::Locale locale(lang.get());
454 errorCode = locale.isBogus();
455 SysTryReturnResult(NID_SYS, errorCode == 0 && IsValidLocaleString(value, locale) == true, E_INVALID_ARG, "Unknown language format");
457 std::string localeCode(locale.getLanguage());
458 localeCode.append("_");
459 localeCode.append(locale.getCountry());
461 const char* vconfKey = null;
463 if (key == _LOCALE_LANGUAGE)
465 SysTryReturnResult(NID_SYS, IsSupportedDisplayLanguageLocale(localeCode.c_str()),
466 E_INVALID_ARG, "It is not the supported display language locale [%s].", localeCode.c_str());
467 vconfKey = VCONFKEY_LANGSET;
468 localeCode.append(".utf8");
470 else if (key == _LOCALE_COUNTRY)
472 localeCode.append(".utf8");
473 SysTryReturnResult(NID_SYS, IsSupportedRegionLocale(localeCode.c_str()),
474 E_INVALID_ARG, "It is not the supported region locale [%s].", localeCode.c_str());
475 vconfKey = VCONFKEY_REGIONFORMAT;
477 errorCode = vconf_set_str(vconfKey, localeCode.c_str());
478 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on %ls vconf",key.GetPointer());
481 else if(key == _LOCALE_WEEK_FORMAT_FIRSTDAY)
483 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support week format selection feature.");
488 String sunday(_LOCALE_WEEK_FORMAT_FIRSTDAY_SUNDAY);
489 String monday(_LOCALE_WEEK_FORMAT_FIRSTDAY_MONDAY);
491 String requiredValue(value);
492 requiredValue.ToLowerCase();
493 sunday.ToLowerCase();
494 monday.ToLowerCase();
496 if (requiredValue == sunday)
498 firstDay = _LOCALE_WEEK_FORMAT_VCONF_SUNDAY;
500 else if (requiredValue == monday)
502 firstDay = _LOCALE_WEEK_FORMAT_VCONF_MONDAY;
506 return E_INVALID_ARG;
509 errorCode = vconf_set_int(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, firstDay);
510 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT vconf");
512 else if(key == _LOCALE_TIMEZONE)
514 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support time zone feature.");
517 LocaleManager localeManager;
518 localeManager.Construct();
519 unique_ptr<IList, AllElementsDeleter> pSupportedTimeZoneList(localeManager.GetAvailableTimeZonesN());
521 SysTryReturnResult(NID_SYS, pSupportedTimeZoneList != null, E_SYSTEM, "It is failed to get supported timezone list.");
522 SysTryReturnResult(NID_SYS, pSupportedTimeZoneList->Contains(value) == true, E_INVALID_ARG, "Specified timezone id[%S] is not valid", value.GetPointer());
524 unique_ptr<char []> tzpath (_StringConverter::CopyToCharArrayN(value));
525 SysTryReturnResult(NID_SYS, tzpath != null, E_SYSTEM, "It is failed to convert String to string");
526 std::string tzStr(_LOCALE_TIMEZONE_ROOT_PATH);
527 tzStr.append(tzpath.get());
528 unique_ptr<char, charDeleter> cstrTzpath (strdup(tzStr.c_str()));
529 int errorCode = sysman_set_timezone(cstrTzpath.get());
530 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set timezone");
532 errorCode = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, cstrTzpath.get()+_LOCALE_TIMEZONE_ROOT_PATH_LENGTH);
533 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set VCONFKEY_SETAPPL_TIMEZONE_ID vconf");
535 errorCode = vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, -1);
536 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to notify to system about time changing");
542 _SettingLocaleProvider::HasKey(const Tizen::Base::String& key)
544 if(key == _LOCALE_COUNTRY || key == _LOCALE_LANGUAGE)
548 else if(key == _LOCALE_DATE_FORMAT || key == _LOCALE_DATETIME_FORMAT || key == _LOCALE_TIME_FORMAT || key == _LOCALE_TIME_FORMAT_24HOUR || key == _LOCALE_WEEK_FORMAT_FIRSTDAY)
552 else if(key == _LOCALE_TIMEZONE || key == _LOCALE_UPDATE_AUTO)
556 else if(key == _LOCALE_DATE || key == _LOCALE_TIME || _LOCALE_DATETIME)
564 _SettingLocaleProvider::SettingEventRuntimeInfo(runtime_info_key_e key, void* userData)
566 result r = E_SUCCESS;
569 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
570 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
572 if(key == RUNTIME_INFO_KEY_REGION)
574 settingKey = _LOCALE_DATE_FORMAT;
575 pSettingInfo->AnnounceSettingEvent(settingKey);
576 settingKey = _LOCALE_DATETIME_FORMAT;
577 pSettingInfo->AnnounceSettingEvent(settingKey);
578 settingKey = _LOCALE_TIME_FORMAT;
579 pSettingInfo->AnnounceSettingEvent(settingKey);
580 settingKey = _LOCALE_COUNTRY;
581 pSettingInfo->AnnounceSettingEvent(settingKey);
583 else if(key == RUNTIME_INFO_KEY_LANGUAGE)
585 settingKey.Append(_LOCALE_LANGUAGE);
586 pSettingInfo->AnnounceSettingEvent(settingKey);
588 else if(key == RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED)
590 settingKey = _LOCALE_DATETIME_FORMAT;
591 pSettingInfo->AnnounceSettingEvent(settingKey);
592 settingKey = _LOCALE_TIME_FORMAT;
593 pSettingInfo->AnnounceSettingEvent(settingKey);
594 settingKey = _LOCALE_TIME_FORMAT_24HOUR;
596 r = pSettingInfo->AnnounceSettingEvent(settingKey);
597 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
601 _SettingLocaleProvider::SettingEventVConf(keynode_t* node, void* userData)
603 result r = E_SUCCESS;
606 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
607 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
609 if (strcmp(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, vconf_keynode_get_name(node)) == 0)
611 settingKey.Append(_LOCALE_WEEK_FORMAT_FIRSTDAY);
613 else if (strcmp(VCONFKEY_SYSTEM_TIME_CHANGED, vconf_keynode_get_name(node)) == 0)
615 settingKey = _LOCALE_DATETIME;
616 pSettingInfo->AnnounceSettingEvent(settingKey);
617 settingKey = _LOCALE_DATE;
618 pSettingInfo->AnnounceSettingEvent(settingKey);
619 settingKey = _LOCALE_TIME;
621 else if (strcmp(VCONFKEY_SETAPPL_TIMEZONE_ID, vconf_keynode_get_name(node)) == 0)
623 settingKey.Append(_LOCALE_TIMEZONE);
625 else if (strcmp(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, vconf_keynode_get_name(node)) == 0)
627 settingKey.Append(_LOCALE_UPDATE_AUTO);
634 r = pSettingInfo->AnnounceSettingEvent(settingKey);
635 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
639 _SettingLocaleProvider::IsValidLocaleString(const Tizen::Base::String& localeString, const icu::Locale& icuLocale)
641 int indexOfScript = -1;
642 int indexOfCountryCode = -1;
644 localeString.IndexOf(L"-", 0, indexOfScript);
645 localeString.IndexOf(L"_", 0, indexOfCountryCode);
647 SysTryReturnResult(NID_SYS, indexOfCountryCode == 3 || (indexOfScript == 3 && indexOfCountryCode == 8)
648 , E_INVALID_ARG, "localeString %ls is invalid.", localeString.GetPointer());
650 // Tizen locale format languageCode-scriptCode_countryCode (ex: aze-latn_AZ)
655 localeString.SubString(0, 3, languageCode);
657 if (indexOfScript == 3)
659 localeString.SubString(4, 4, scriptCode);
662 int countryCodeLength = (localeString.Contains(L"419") == true) ? 3 : 2;
663 int countryCodeIndex = (indexOfCountryCode == 3) ? 4 : 9;
665 localeString.SubString(countryCodeIndex, countryCodeLength, countryCode);
667 // icu locale format languageCode_ScriptCode_countryCode (ex: az_Latn_AZ)
668 String icuLanguageCode(icuLocale.getISO3Language());
669 String icuScriptCode(icuLocale.getScript());
670 String icuCountryCode(icuLocale.getCountry());
672 if (!icuScriptCode.IsEmpty())
674 icuScriptCode.ToLowerCase();
677 if (languageCode == icuLanguageCode && scriptCode == icuScriptCode && countryCode == icuCountryCode)
686 _SettingLocaleProvider::IsSupportedDisplayLanguageLocale(const char* localeId)
688 xmlDocPtr doc = null;
689 xmlNodePtr cur = null;
691 doc = xmlParseFile(_LANGUAGE_LIST_FILE_PATH);
692 SysTryCatch(NID_SYS, doc != null, , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
694 cur = xmlDocGetRootElement(doc);
695 SysTryCatch(NID_SYS, cur != null, , E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
696 SysTryCatch(NID_SYS, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, , E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
698 cur = cur->xmlChildrenNode;
700 for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
702 if (cur_node->type == XML_ELEMENT_NODE)
704 char* pLocId = (char*)xmlGetProp(cur_node, (const xmlChar *)"id");
705 if (!strcmp(localeId, pLocId))
722 _SettingLocaleProvider::IsSupportedRegionLocale(const char* localeId)
724 locale_t cLoc = newlocale(LC_ALL_MASK, localeId, null);
725 if (cLoc == (locale_t)null)