Tizen 2.1 base
[platform/framework/native/ime.git] / src / FUiImeInputMethodManager.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
4 //\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
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\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
16 //\r
17 \r
18 /**\r
19  * @file        FUiImeInputMethodManager.cpp\r
20  * @brief       This is the implementation file for the %InputMethodManager class.\r
21  *\r
22  * This implementation file contains definition of the %InputMethodManager class.\r
23  */\r
24 \r
25 #include <new>\r
26 \r
27 #include <FBaseSysLog.h>\r
28 #include <FUiImeInputMethodManager.h>\r
29 \r
30 #include <FSec_AccessController.h>\r
31 #include "FUiIme_InputMethodManagerImpl.h"\r
32 \r
33 using namespace Tizen::Security;\r
34 \r
35 namespace Tizen { namespace Ui { namespace Ime {\r
36 \r
37 static InputMethodManager* __pInputMethodManager = null;\r
38 \r
39 InputMethodManager::InputMethodManager(void)\r
40         :__pInputMethodManagerImpl(null)\r
41 {\r
42 }\r
43 \r
44 InputMethodManager::~InputMethodManager(void)\r
45 {\r
46         __pInputMethodManager = null;\r
47         __pInputMethodManagerImpl = null;\r
48 }\r
49 \r
50 InputMethodManager*\r
51 InputMethodManager::GetInstance(void)\r
52 {\r
53         result r = E_SUCCESS;\r
54 \r
55         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
56         SysTryReturn(NID_UI_IME, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");\r
57 \r
58         if (__pInputMethodManager == null)\r
59         {\r
60                 __pInputMethodManager = new(std::nothrow) InputMethodManager();\r
61                 SysTryReturn(NID_UI_IME, __pInputMethodManager, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
62 \r
63                 __pInputMethodManager->__pInputMethodManagerImpl = _InputMethodManagerImpl::GetInstance(*__pInputMethodManager);\r
64                 r = GetLastResult();\r
65                 SysTryCatch(NID_UI_IME, __pInputMethodManager->__pInputMethodManagerImpl, , r, "[%s] Propagating.", GetErrorMessage(r));\r
66         }\r
67 \r
68         return __pInputMethodManager;\r
69 \r
70 CATCH:\r
71         delete __pInputMethodManager;\r
72         __pInputMethodManager = null;\r
73 \r
74         __pInputMethodManager->__pInputMethodManagerImpl = null;\r
75 \r
76         return null;\r
77 }\r
78 \r
79 Tizen::Base::Collection::IList*\r
80 InputMethodManager::GetInputMethodInfoListN(void) const\r
81 {\r
82         result r = E_SUCCESS;\r
83 \r
84         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
85         SysTryReturn(NID_UI_IME, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");\r
86 \r
87         return __pInputMethodManagerImpl->GetInputMethodInfoListN();\r
88 }\r
89 \r
90 result\r
91 InputMethodManager::SetInputMethod(Tizen::App::AppId id)\r
92 {\r
93         result r = E_SUCCESS;\r
94 \r
95         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
96         SysTryReturnResult(NID_UI_IME, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");\r
97 \r
98         return __pInputMethodManagerImpl->SetInputMethod(id);\r
99 }\r
100 \r
101 }}} // Tizen::Ui::Ime\r