2 // Open Service Platform
\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Apache License, Version 2.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
19 * @file FUiIme_InputMethodInfoImpl.cpp
\r
20 * @brief This is the implementation file for the %_InputMethodInfoImpl class.
\r
22 * This implementation file contains definition of the %_InputMethodInfoImpl class.
\r
28 #include <FBaseColTypes.h>
\r
29 #include <FBaseSysLog.h>
\r
31 #include <FBase_StringConverter.h>
\r
33 #include "FUiIme_InputMethodInfoImpl.h"
\r
34 #include "FUiIme_ScimDataConverter.h"
\r
36 using namespace Tizen::Base;
\r
37 using namespace Tizen::Base::Collection;
\r
38 using namespace Tizen::Locales;
\r
40 namespace Tizen { namespace Ui { namespace Ime {
\r
42 _InputMethodInfoImpl::_InputMethodInfoImpl(void)
\r
45 result r = E_SUCCESS;
\r
47 __pLanguageList = new(std::nothrow) ArrayList(SingleObjectDeleter);
\r
48 SysTryReturnVoidResult(NID_UI_IME, __pLanguageList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
50 r = __pLanguageList->Construct();
\r
51 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
56 delete __pLanguageList;
\r
57 __pLanguageList = null;
\r
62 _InputMethodInfoImpl::_InputMethodInfoImpl(const _InputMethodInfoImpl& impl)
\r
64 result r = E_SUCCESS;
\r
66 __appId = impl.__appId;
\r
67 __name = impl.__name;
\r
69 __pLanguageList = new(std::nothrow) ArrayList(SingleObjectDeleter);
\r
70 SysTryReturnVoidResult(NID_UI_IME, __pLanguageList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
72 r = __pLanguageList->Construct();
\r
73 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
75 r = SetLanguageList(*(impl.__pLanguageList));
\r
76 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
78 __pUuid = _StringConverter::CopyToCharArrayN(impl.__uuid);
\r
83 delete __pLanguageList;
\r
84 __pLanguageList = null;
\r
89 _InputMethodInfoImpl::~_InputMethodInfoImpl(void)
\r
91 delete __pLanguageList;
\r
92 __pLanguageList = null;
\r
98 _InputMethodInfoImpl*
\r
99 _InputMethodInfoImpl::CreateInputMethodInfoImplN(void)
\r
101 _InputMethodInfoImpl* pInputMethodInfoImpl = new(std::nothrow) _InputMethodInfoImpl();
\r
102 SysTryReturn(NID_UI_IME, pInputMethodInfoImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
104 return pInputMethodInfoImpl;
\r
107 _InputMethodInfoImpl*
\r
108 _InputMethodInfoImpl::CreateInputMethodInfoImplN(const _InputMethodInfoImpl& impl)
\r
110 _InputMethodInfoImpl* pInputMethodInfoImpl = new(std::nothrow) _InputMethodInfoImpl(impl);
\r
111 SysTryReturn(NID_UI_IME, pInputMethodInfoImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
113 return pInputMethodInfoImpl;
\r
116 _InputMethodInfoImpl*
\r
117 _InputMethodInfoImpl::GetInstance(InputMethodInfo& inputMethodInfo)
\r
119 return inputMethodInfo.__pInputMethodInfoImpl;
\r
122 _InputMethodInfoImpl&
\r
123 _InputMethodInfoImpl::operator=(const _InputMethodInfoImpl& impl)
\r
125 result r = E_SUCCESS;
\r
129 __appId = impl.__appId;
\r
130 __name = impl.__name;
\r
132 r = SetLanguageList(*(impl.__pLanguageList));
\r
133 SysTryReturn(NID_UI_IME, r == E_SUCCESS, *this, r, "[%s] Propagating.", GetErrorMessage(r));
\r
139 __pUuid = _StringConverter::CopyToCharArrayN(impl.__uuid);
\r
146 _InputMethodInfoImpl::Equals(const Object& object) const
\r
148 const _InputMethodInfoImpl* pInputMethodInfoImpl = static_cast<const _InputMethodInfoImpl*>(&object);
\r
149 SysTryReturn(NID_UI_IME, pInputMethodInfoImpl, false, E_INVALID_ARG, "Invalid argument(s) is used. The object is not the _InputMethodInfoImpl.");
\r
151 return __appId.Equals(pInputMethodInfoImpl->__appId, true);
\r
155 _InputMethodInfoImpl::GetAppId(void) const
\r
160 const Tizen::Base::Collection::IList*
\r
161 _InputMethodInfoImpl::GetLanguageList(void) const
\r
163 return __pLanguageList;
\r
166 Tizen::Base::String
\r
167 _InputMethodInfoImpl::GetName(void) const
\r
173 _InputMethodInfoImpl::GetUuid(void) const
\r
179 _InputMethodInfoImpl::SetAppId(Tizen::App::AppId id)
\r
187 _InputMethodInfoImpl::SetUuid(Tizen::Base::String id)
\r
195 __pUuid = _StringConverter::CopyToCharArrayN(id);
\r
201 _InputMethodInfoImpl::SetLanguageList(const Tizen::Base::Collection::IList& list)
\r
203 result r = E_SUCCESS;
\r
205 __pLanguageList->RemoveAll();
\r
207 const ArrayList* pLanguageList = static_cast<const ArrayList*>(&list);
\r
208 int languageCount = pLanguageList->GetCount();
\r
210 r = __pLanguageList->SetCapacity(languageCount);
\r
211 SysTryReturnResult(NID_UI_IME, r == E_SUCCESS, r, "Propagating.");
\r
213 Locale* pDestLanguage = null;
\r
214 for (int i = 0; i < languageCount; i++)
\r
216 const Locale* pLanguage = static_cast<const Locale*>(pLanguageList->GetAt(i));
\r
217 r = GetLastResult();
\r
218 SysTryReturnResult(NID_UI_IME, pLanguage, r, "Propagating.");
\r
220 pDestLanguage = new(std::nothrow) Locale(*pLanguage);
\r
221 SysTryCatch(NID_UI_IME, pDestLanguage, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
223 r = __pLanguageList->Add(pDestLanguage);
\r
224 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
230 __pLanguageList->RemoveAll();
\r
232 delete pDestLanguage;
\r
238 _InputMethodInfoImpl::SetName(const Tizen::Base::String& name)
\r
246 _InputMethodInfoImpl::SetName(const scim::String& name)
\r
248 _ScimDataConverter converter;
\r
249 converter.ConvertString(name, __name);
\r
255 _InputMethodInfoImpl::AddLanguage(const char* language)
\r
257 result r = E_SUCCESS;
\r
259 // verify the input parameter
\r
260 const int ISO_639_2_LENGTH = 6;
\r
261 const int ISO_639_2_LANGUAGE_CODE_LENGTH = 3;
\r
262 const int COUNTRY_CODE_LENGTH = 2;
\r
264 int length = strlen(language);
\r
265 SysTryReturnResult(NID_UI_IME, (length == ISO_639_2_LENGTH), E_INVALID_ARG,
\r
266 "Invalid argument(s) is used. The language is not a type of ISO 639-2 and is %s.", language);
\r
268 LanguageCode languageCode = LANGUAGE_INVALID;
\r
269 CountryCode countryCode = COUNTRY_INVALID;
\r
272 char srcLanguage[ISO_639_2_LANGUAGE_CODE_LENGTH + 1];
\r
273 strncpy(srcLanguage, language, ISO_639_2_LANGUAGE_CODE_LENGTH);
\r
274 srcLanguage[ISO_639_2_LANGUAGE_CODE_LENGTH] = '\0';
\r
276 languageCode = Locale::StringToLanguageCode(srcLanguage);
\r
277 SysTryReturnResult(NID_UI_IME, languageCode != LANGUAGE_INVALID, E_INVALID_ARG,
\r
278 "Invalid argument(s) is used. The srcLanguage is %s.", srcLanguage);
\r
281 char srcCountry[COUNTRY_CODE_LENGTH + 1];
\r
282 strncpy(srcCountry, language + ISO_639_2_LANGUAGE_CODE_LENGTH + 1, COUNTRY_CODE_LENGTH);
\r
283 srcCountry[COUNTRY_CODE_LENGTH] = '\0';
\r
285 countryCode = Locale::StringToCountryCode(srcCountry);
\r
286 SysTryReturnResult(NID_UI_IME, countryCode != COUNTRY_INVALID, E_INVALID_ARG,
\r
287 "Invalid argument(s) is used. The srcCountry is %s.", srcCountry);
\r
289 // add the language
\r
290 Locale* pLanguage = new(std::nothrow) Locale(languageCode, countryCode);
\r
291 SysTryReturnResult(NID_UI_IME, pLanguage, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
\r
293 r = __pLanguageList->Add(pLanguage);
\r
294 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
304 }}} // Tizen::Ui::Ime
\r