Merge "Remove fallback routines and memory leak." into tizen_2.1
[platform/framework/native/appfw.git] / src / locales / FLclLocaleManager.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            FLclLocaleManager.cpp
19  * @brief           This is the implementation file for LocaleManager class.
20  */
21
22 // Includes
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FLclLocaleManager.h>
26 #include "FLcl_LocaleManagerImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31
32 namespace Tizen { namespace Locales
33 {
34
35 LocaleManager::LocaleManager(void)
36         : __pLocaleManagerImpl(null)
37 {
38 }
39
40
41 LocaleManager::~LocaleManager(void)
42 {
43 }
44
45
46 result
47 LocaleManager::Construct(void)
48 {
49         return E_SUCCESS;
50 }
51
52
53 Locale
54 LocaleManager::GetSystemLocale(void) const
55 {
56         ClearLastResult();
57         return _LocaleManagerImpl::GetSystemLocale();
58 }
59
60
61 IList*
62 LocaleManager::GetAvailableLocalesN(void) const
63 {
64         ClearLastResult();
65         return _LocaleManagerImpl::GetAvailableLocalesN();
66 }
67
68
69 String
70 LocaleManager::GetSelectedLanguage(void) const
71 {
72         ClearLastResult();
73         return _LocaleManagerImpl::GetSelectedLanguage();
74 }
75
76
77 IList*
78 LocaleManager::GetAvailableLanguagesN(void) const
79 {
80         ClearLastResult();
81         return _LocaleManagerImpl::GetAvailableLanguagesN();
82 }
83
84
85 IList*
86 LocaleManager::GetAvailableTimeZonesN(void) const
87 {
88         ClearLastResult();
89         std::unique_ptr<IMap> pTimeZoneMap(_LocaleManagerImpl::GetAvailableTimeZonesN());
90         std::unique_ptr<IList> pList(pTimeZoneMap->GetKeysN());
91         std::unique_ptr<ArrayList> pArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
92         SysTryReturn(NID_LCL, pArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
93
94         pArrayList->Construct();
95
96         for (int i = 0; i < pList->GetCount(); i++)
97         {
98                 std::unique_ptr<String> pTz(new (std::nothrow) String(*((String*)(pList->GetAt(i)))));
99                 SysTryReturn(NID_LCL, pTz, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
100                 result r = pArrayList->Add(*(pTz.get()));
101                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to get the tz list.");
102                 pTz.release();
103         }
104         return pArrayList.release();
105 }
106
107
108 IList*
109 LocaleManager::GetAvailableTimeZonesN(int rawOffset) const
110 {
111         ClearLastResult();
112         std::unique_ptr<IMap> pTimeZoneMap(_LocaleManagerImpl::GetAvailableTimeZonesN(rawOffset));
113         std::unique_ptr<IList> pList(pTimeZoneMap->GetKeysN());
114         std::unique_ptr<ArrayList> pArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
115         SysTryReturn(NID_LCL, pArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
116
117         pArrayList->Construct();
118
119         for (int i = 0; i < pList->GetCount(); i++)
120         {
121                 std::unique_ptr<String> pTz(new (std::nothrow) String(*((String*)(pList->GetAt(i)))));
122                 SysTryReturn(NID_LCL, pTz, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
123                 result r = pArrayList->Add(*(pTz.get()));
124                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to get the tz list.");
125                 pTz.release();
126         }
127         return pArrayList.release();
128 }
129
130 TimeZone
131 LocaleManager::GetSystemTimeZone(void) const
132 {
133         ClearLastResult();
134         return _LocaleManagerImpl::GetSystemTimeZone();
135 }
136
137 result
138 LocaleManager::IsSupportedLocale(const Locale& locale, bool& isSupportedLocale)
139 {
140         ClearLastResult();
141         return _LocaleManagerImpl::IsSupportedLocale(locale, isSupportedLocale);
142 }
143
144
145 };
146 };      // Tizen::Locales