merge with master
[framework/osp/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::App;\r
34 using namespace Tizen::Base::Collection;\r
35 using namespace Tizen::Security;\r
36 \r
37 namespace Tizen { namespace Ui { namespace Ime {\r
38 \r
39 static InputMethodManager* __pInputMethodManager = null;\r
40 \r
41 InputMethodManager::InputMethodManager(void)\r
42         :__pInputMethodManagerImpl(null)\r
43 {\r
44 }\r
45 \r
46 InputMethodManager::~InputMethodManager(void)\r
47 {\r
48         __pInputMethodManager = null;\r
49         __pInputMethodManagerImpl = null;\r
50 }\r
51 \r
52 InputMethodManager*\r
53 InputMethodManager::GetInstance(void)\r
54 {\r
55         result r = E_SUCCESS;\r
56 \r
57         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
58         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
59 \r
60         _InputMethodManagerImpl* pImpl = null;\r
61 \r
62         if (__pInputMethodManager == null)\r
63         {\r
64                 __pInputMethodManager = new(std::nothrow) InputMethodManager();\r
65                 SysTryReturn(NID_UI_IME, __pInputMethodManager, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
66 \r
67                 pImpl = new(std::nothrow) _InputMethodManagerImpl();\r
68                 SysTryCatch(NID_UI_IME, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
69 \r
70                 r = pImpl->Construct();\r
71                 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));\r
72 \r
73                 __pInputMethodManager->__pInputMethodManagerImpl = pImpl;\r
74         }\r
75 \r
76         return __pInputMethodManager;\r
77 \r
78 CATCH:\r
79         delete __pInputMethodManager;\r
80         __pInputMethodManager = null;\r
81 \r
82         delete pImpl;\r
83 \r
84         return null;\r
85 }\r
86 \r
87 InputMethodInfo*\r
88 InputMethodManager::GetActiveInputMethodInfoN(void) const\r
89 {\r
90         result r = E_SUCCESS;\r
91 \r
92         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
93         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
94 \r
95         return __pInputMethodManagerImpl->GetActiveInputMethodInfoN();\r
96 }\r
97 \r
98 IList*\r
99 InputMethodManager::GetInputMethodInfoListN(void) const\r
100 {\r
101         result r = E_SUCCESS;\r
102 \r
103         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
104         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
105 \r
106         return __pInputMethodManagerImpl->GetInputMethodInfoListN();\r
107 }\r
108 \r
109 result\r
110 InputMethodManager::SetInputMethod(const AppId& id)\r
111 {\r
112         result r = E_SUCCESS;\r
113 \r
114         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
115         SysTryReturnResult(NID_UI_IME, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");\r
116 \r
117         return __pInputMethodManagerImpl->SetInputMethod(id);\r
118 }\r
119 \r
120 bool\r
121 InputMethodManager::IsActiveInputMethod(const AppId& id) const\r
122 {\r
123         result r = E_SUCCESS;\r
124 \r
125         r = _AccessController::CheckUserPrivilege(_PRV_IMEMANAGER);\r
126         SysTryReturnResult(NID_UI_IME, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");\r
127 \r
128         return __pInputMethodManagerImpl->IsActiveInputMethod(id);\r
129 }\r
130 \r
131 }}} // Tizen::Ui::Ime\r