Remove privilege check on setting
[platform/framework/native/appfw.git] / src / locales / FLcl_CurrencyImpl.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_CurrencyImpl.cpp
19  * @brief           This is the implementation file for _CurrencyImpl class.
20  */
21 #include <unique_ptr.h>
22 #include <unicode/dcfmtsym.h>
23
24 #include <FBaseSysLog.h>
25 #include <FApp_AppInfo.h>
26
27 #include "FLcl_LocaleData.h"
28 #include "FLcl_LocaleImpl.h"
29 #include "FLcl_CurrencyImpl.h"
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Locales
34 {
35
36 result
37 _CurrencyImpl::GetCurrencyCodeSymbol(const Locale& locale, Tizen::Base::String& currencyCodeSymbol)
38 {
39         const _LocaleImpl* pLclImpl = _LocaleImpl::GetLocaleImpl(locale);
40         SysTryReturnResult(NID_LCL, pLclImpl != null && pLclImpl->IsSupported(),
41                                         E_INVALID_ARG, "Invalid argument is used. Given locale is not supported");
42
43         UErrorCode ec = U_ZERO_ERROR;
44         IcuDecimalFormatSymbols sym(pLclImpl->GetIcuLocale(), ec);
45         if (U_SUCCESS(ec))
46         {
47                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
48                 String currSym = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
49
50                 if (currCode.IsEmpty() || currSym.IsEmpty())
51                 {
52                         currCode = "";
53                         currSym = "";
54                         return E_SYSTEM;
55                 }
56                 else
57                 {
58                         currencyCodeSymbol = currCode + "_" + currSym;
59                         return E_SUCCESS;
60                 }
61         }
62
63         return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
64 }
65
66 result
67 _CurrencyImpl::GetCurrencyCodeSymbol(const String currencyCode, String& currencyCodeSymbol)
68 {
69         int count = 0;
70         const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
71         SysTryReturnResult(NID_LCL, pIcuLocaleList && (count > 0), E_SYSTEM, "The method cannot proceed due to a severe system error.");
72
73         for (int i = 0; i < count; i++)
74         {
75                 SysTryReturnResult(NID_LCL, (pIcuLocaleList + i) != null, E_SYSTEM, "The method cannot proceed due to a severe system error.");
76
77                 UErrorCode ec = U_ZERO_ERROR;
78                 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
79                 SysTryReturnResult(NID_LCL, U_SUCCESS(ec), E_SYSTEM, "The method cannot proceed due to a severe system error.");
80
81                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
82                 if (currCode == currencyCode)
83                 {
84                         String currencySymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
85                         currencyCodeSymbol = currencyCode + "_" + currencySymbol;
86                         return E_SUCCESS;
87                 }
88         }
89         return E_INVALID_ARG;
90 }
91
92 IList*
93 _CurrencyImpl::GetAvailableCurrenciesN(void)
94 {
95         int count = 0;
96         const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
97         SysTryReturn(NID_LCL, pIcuLocaleList && (count > 0), null,E_SYSTEM,
98                                 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
99
100         std::unique_ptr<ArrayList, AllElementsDeleter> pNewList(new (std::nothrow) ArrayList());
101         SysTryReturn(NID_LCL, pNewList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
102
103         for (int i = 0; i < count; i++)
104         {
105                 SysTryReturn(NID_LCL, (pIcuLocaleList + i) != null, null, E_SYSTEM,
106                                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
107
108                 UErrorCode ec = U_ZERO_ERROR;
109                 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
110                 SysTryReturn(NID_LCL, U_SUCCESS(ec), null, E_SYSTEM,
111                                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
112
113                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
114                 String currSymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
115
116                 if (!currCode.IsEmpty() && !currSymbol.IsEmpty())
117                 {
118                         std::unique_ptr< Currency > pCurr(new (std::nothrow) Currency);
119                         SysTryReturn(NID_LCL, pCurr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
120
121                         pCurr->__currencyCodeSymbol = currCode + "_" + currSymbol;
122                         if (!pNewList->Contains(*(pCurr.get())))
123                         {
124                                 result r = pNewList->Add(pCurr.get());
125                                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "Itis fail to make the currency list.");
126                                 pCurr.release();
127                         }
128                 }
129         }
130
131         SetLastResult(E_SUCCESS);
132         return pNewList.release();
133 }
134
135
136 }}//Tizen::Locales