Update to get the tzlist from file
authorHokwon Song <hokwon.song@samsung.com>
Sat, 13 Apr 2013 07:47:35 +0000 (16:47 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Sat, 13 Apr 2013 07:47:35 +0000 (16:47 +0900)
Change-Id: Ieb29a6864d3e90619605b33d45af5cf2069f1152
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/locales/FLcl_LocaleManagerImpl.cpp
src/locales/inc/FLcl_LocaleManagerImpl.h

index 714aca0..02e5f86 100644 (file)
@@ -27,6 +27,7 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
+#include <FIo.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
 
 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<ArrayList, AllElementsDeleter> 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<IList, AllElementsDeleter> pLocaleList (GetAvailableLocalesN());
        std::unique_ptr<HashMap> 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<HashMap, AllElementsDeleter> 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<String> 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<String> 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<HashMap, AllElementsDeleter> 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)
 {
index ff0b3ec..16a0ec0 100644 (file)
@@ -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);