From 3c286ace3aa6c895495979acf9e118a8b733513a Mon Sep 17 00:00:00 2001 From: Hokwon Song Date: Sat, 13 Apr 2013 16:47:35 +0900 Subject: [PATCH] Update to get the tzlist from file Change-Id: Ieb29a6864d3e90619605b33d45af5cf2069f1152 Signed-off-by: Hokwon Song --- src/locales/FLcl_LocaleManagerImpl.cpp | 69 ++++++++++++++++++++++++++++---- src/locales/inc/FLcl_LocaleManagerImpl.h | 3 +- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/locales/FLcl_LocaleManagerImpl.cpp b/src/locales/FLcl_LocaleManagerImpl.cpp index 714aca0..02e5f86 100644 --- a/src/locales/FLcl_LocaleManagerImpl.cpp +++ b/src/locales/FLcl_LocaleManagerImpl.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -38,10 +39,12 @@ using namespace Tizen::Base; using namespace Tizen::Base::Utility; using namespace Tizen::Base::Collection; +using namespace Tizen::Io; namespace Tizen { namespace Locales { -static const char* LANGLIST_FILE_PATH ="/opt/data/setting/langlist.xml"; +static const char* LANGUAGE_LIST_FILE_PATH ="/opt/data/setting/langlist.xml"; +static const char* TIMEZONE_LIST_FILE_PATH = "/opt/data/setting/tzlist.ini"; static const int TIMEZONE_MAX = 224; static const char* TimeZoneList[TIMEZONE_MAX] = { @@ -352,7 +355,7 @@ _LocaleManagerImpl::GetAvailableLanguagesN(void) std::unique_ptr pAvailableLanguageList(new (std::nothrow) ArrayList()); SysTryCatch(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); - doc = xmlParseFile(LANGLIST_FILE_PATH); + doc = xmlParseFile(LANGUAGE_LIST_FILE_PATH); SysTryCatch(NID_LCL, doc != null, , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource."); cur = xmlDocGetRootElement(doc); @@ -394,12 +397,12 @@ CATCH: xmlFreeDoc(doc); } SysLog(NID_LCL, "It is calling fallback api."); - return GetAvailableLanguagesFallBackN(); + return GetAvailableLanguagesFallbackN(); } IList* -_LocaleManagerImpl::GetAvailableLanguagesFallBackN(void) +_LocaleManagerImpl::GetAvailableLanguagesFallbackN(void) { std::unique_ptr pLocaleList (GetAvailableLocalesN()); std::unique_ptr pLanguageMap(new (std::nothrow) HashMap()); @@ -485,24 +488,73 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* p return pTimeZoneMap.release(); } + IMap* _LocaleManagerImpl::GetAvailableTimeZonesN(void) { + File file; + String tzFilePath(TIMEZONE_LIST_FILE_PATH); + result r = E_SUCCESS; + std::unique_ptr pTimeZoneMap(new (std::nothrow) HashMap()); + SysTryCatch(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY, + "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); + r = file.Construct(tzFilePath, "r"); + SysTryCatch(NID_LCL, r == E_SUCCESS, ,E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the tzlist from the ini file."); + pTimeZoneMap->Construct(); + + do + { + std::unique_ptr pTimeZone(new (std::nothrow) String()); + SysTryCatch(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY, + "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + r = file.Read(*(pTimeZone.get())); + if ( r == E_END_OF_FILE) + { + break; + } + SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] It is failed to read the tzlist.", GetErrorMessage(r)); + pTimeZone->Replace(L"\n", L"\0"); + + if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get()))) + { + std::unique_ptr pDummyValue(new (std::nothrow) String()); + SysTryCatch(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY, + "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get())); + SysTryCatch(NID_LCL, r == E_SUCCESS, , r,"[%s] It is failed to add the tz into the tz map.", GetErrorMessage(r)); + pTimeZone.release(); + pDummyValue.release(); + } + }while (1); + + SetLastResult(E_SUCCESS); + return pTimeZoneMap.release(); + +CATCH: + return GetAvailableTimeZonesFallbackN(); +} + + +IMap* +_LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void) +{ + std::unique_ptr pTimeZoneMap(new (std::nothrow) HashMap()); SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); result r = E_SUCCESS; int index = 0; - + pTimeZoneMap->Construct(); - + do { - String* pTimeZone = new (std::nothrow) String(TimeZoneList[index++]); + String* pTimeZone = new (std::nothrow) String(TimeZoneList[index++]); SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY, - "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); if (!pTimeZoneMap->ContainsKey(*pTimeZone)) { @@ -523,6 +575,7 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(void) return pTimeZoneMap.release(); } + IMap* _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset) { diff --git a/src/locales/inc/FLcl_LocaleManagerImpl.h b/src/locales/inc/FLcl_LocaleManagerImpl.h index ff0b3ec..16a0ec0 100644 --- a/src/locales/inc/FLcl_LocaleManagerImpl.h +++ b/src/locales/inc/FLcl_LocaleManagerImpl.h @@ -45,10 +45,11 @@ public: static Tizen::Base::String GetSelectedLanguage(void); static Tizen::Base::Collection::IList* GetAvailableLanguagesN(void); - static Tizen::Base::Collection::IList* GetAvailableLanguagesFallBackN(void); + static Tizen::Base::Collection::IList* GetAvailableLanguagesFallbackN(void); static Tizen::Base::Collection::IMap* GetAvailableTimeZonesN(void); static Tizen::Base::Collection::IMap* GetAvailableTimeZonesN(int rawOffset); + static Tizen::Base::Collection::IMap* GetAvailableTimeZonesFallbackN(void); static Tizen::Base::Collection::IMap* GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* pIcuTZStrList); -- 2.7.4