[N-SE-37754] Filtering icu locales by available clocales.
authorHokwon Song <hokwon.song@samsung.com>
Fri, 10 May 2013 02:48:39 +0000 (11:48 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Fri, 10 May 2013 02:48:39 +0000 (11:48 +0900)
Change-Id: I17bd34a4ab4651013ec9f41ccbc57284da63822f
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
packaging/osp-appfw.spec
src/locales/FLcl_LocaleManagerImpl.cpp
src/locales/inc/FLcl_LocaleManagerImpl.h

index 125a47b..2a07662 100755 (executable)
@@ -152,6 +152,8 @@ chmod -R 777 /opt/usr/media
 chmod -R 777 /tmp/osp
 
 chown -R 5000:5000 /opt/usr/media
+locale -a > /opt/usr/etc/clocale.list
+chmod 444 /opt/usr/etc/clocale.list
 
 %postun -p /sbin/ldconfig
 
index 2a6272c..86ba89d 100644 (file)
@@ -44,6 +44,8 @@ namespace Tizen { namespace Locales
 {
 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 char* CLOCALE_LIST_FILE_PATH = "/opt/usr/etc/clocale.list";
+
 static const int TIMEZONE_MAX = 224;
 static const char* TimeZoneList[TIMEZONE_MAX] =
 {
@@ -290,6 +292,56 @@ _LocaleManagerImpl::GetSystemLocale(void)
        return Locale(LANGUAGE_INVALID, COUNTRY_INVALID, null);
 }
 
+
+IMap*
+_LocaleManagerImpl::GetAvailableEglibcLocaesN(void)
+{
+       File file;
+       result r = E_SUCCESS;
+       String clocaleFilePath(CLOCALE_LIST_FILE_PATH);
+       
+       std::unique_ptr<HashMap> pClocaleMap(new (std::nothrow) HashMap(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pClocaleMap, null, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+       r = file.Construct(clocaleFilePath, "r");
+       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.");
+
+       pClocaleMap->Construct();
+
+       do
+       {
+               String strBuf;
+               r = file.Read(strBuf);
+               if ( r == E_END_OF_FILE)
+               {
+                       break;
+               }
+               SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the clocale list.", GetErrorMessage(r));
+               std::unique_ptr< String > pClocaleId(new (std::nothrow) String());
+               SysTryReturn(NID_LCL, pClocaleId, null, E_OUT_OF_MEMORY,
+                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+               r = strBuf.SubString(0, 5, *pClocaleId);
+               if (IsFailed(r))
+               {
+                       continue;
+               }
+
+               if (!pClocaleMap->ContainsKey(*(pClocaleId.get())))
+               {
+                       std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
+                       SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
+                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       r = pClocaleMap->Add(*(pClocaleId.get()), *(pDummyValue.get()));
+                       SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,
+                               "[%s] It is failed to add the clocale id into the clocale map.", GetErrorMessage(r));
+                       pClocaleId.release();
+                       pDummyValue.release();
+               }
+       }while(1);
+       return pClocaleMap.release();
+}
+
 IList*
 _LocaleManagerImpl::GetAvailableLocalesN(void)
 {
@@ -297,24 +349,30 @@ _LocaleManagerImpl::GetAvailableLocalesN(void)
        int count = 0;
        const U_ICU_NAMESPACE::Locale* pIcuLocaleList = U_ICU_NAMESPACE::Locale::getAvailableLocales(count);
        SysTryReturn(NID_LCL, count > 0, null, E_SYSTEM,
-                               "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
+               "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
 
-       std::unique_ptr<LinkedList, AllElementsDeleter> pAvailableLocaleList(new (std::nothrow) LinkedList());
+       std::unique_ptr<LinkedList> pAvailableLocaleList(new (std::nothrow) LinkedList(SingleObjectDeleter));
        SysTryReturn(NID_LCL, pAvailableLocaleList, null, E_OUT_OF_MEMORY,
-                               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       std::unique_ptr< IMap > pClocaleMap(GetAvailableEglibcLocaesN());
 
        for (int i = 0; i < count; i++)
        {
-               SysTryReturn(NID_LCL, (pIcuLocaleList + i) != null, null, E_SYSTEM,
-                                       "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
-
-               Locale ospLocale = _LocaleImpl(*(pIcuLocaleList + i)).GetOspLocale();
+               const U_ICU_NAMESPACE::Locale* pIcuLocale = (pIcuLocaleList + i);
+               SysTryReturn(NID_LCL, pIcuLocale, null, E_SYSTEM,
+                       "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
+               Locale ospLocale = _LocaleImpl(*pIcuLocale).GetOspLocale();
                if (_LocaleImpl::IsSupported(ospLocale))
                {
                        std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(ospLocale));
                        SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
                                                "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
-                       if (!pAvailableLocaleList->Contains(*(pLocale.get())))
+
+                       String localeId(pIcuLocale->getLanguage());
+                       localeId = localeId + L"_" + String(pIcuLocale->getCountry());
+
+                       if (!pAvailableLocaleList->Contains(*(pLocale.get())) && pClocaleMap->ContainsKey(localeId))
                        {
                                r = pAvailableLocaleList->Add(*(pLocale.get()));
                                SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make the locale list");
index eef07d1..0b26b74 100644 (file)
@@ -41,6 +41,8 @@ public:
 
        static Tizen::Locales::Locale GetSystemLocale(void);
        static Tizen::Base::Collection::IList* GetAvailableLocalesN(void);
+       // Get available c-locale from file
+       static Tizen::Base::Collection::IMap* GetAvailableEglibcLocaesN(void);
 
        static Tizen::Base::String GetSelectedLanguage(void);
        static Tizen::Base::Collection::IList* GetAvailableLanguagesN(void);