Revert "Add commit_content API"
[platform/core/uifw/libscl-core.git] / src / sclcoreimpl.cpp
1 /*
2  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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 #include "sclcoreimpl.h"
19 #include <app_common.h>
20 #include <dlog.h>
21
22 using namespace scl;
23
24 CSCLCoreImpl::CSCLCoreImpl()
25 {
26     m_event_callback = NULL;
27     m_display = NULL;
28     m_uuid = NULL;
29 }
30
31 CSCLCoreImpl::~CSCLCoreImpl()
32 {
33     if (m_display) {
34         free(m_display);
35         m_display = NULL;
36     }
37     if (m_uuid) {
38         free(m_uuid);
39         m_uuid = NULL;
40     }
41 }
42
43 CSCLCoreImpl*
44 CSCLCoreImpl::get_instance()
45 {
46     static CSCLCoreImpl instance;
47     return &instance;
48 }
49
50 void CSCLCoreImpl::init(const sclchar *display)
51 {
52     m_connection.init();
53     m_core_ui.init();
54
55     m_connection.open_connection(display);
56
57     if (m_event_callback) {
58         m_event_callback->on_init();
59     }
60 }
61
62 void CSCLCoreImpl::fini()
63 {
64     if (m_event_callback) {
65         m_event_callback->on_exit();
66     }
67
68     m_connection.close_connection();
69
70     m_core_ui.fini();
71     m_connection.fini();
72 }
73
74 void CSCLCoreImpl::set_core_event_callback(ISCLCoreEventCallback *callback)
75 {
76     m_event_callback = callback;
77 }
78
79 ISCLCoreEventCallback* CSCLCoreImpl::get_core_event_callback()
80 {
81     ISCLCoreEventCallback* ret = m_event_callback;
82     return ret;
83 }
84
85 CSCLCoreUI* CSCLCoreImpl::get_core_ui()
86 {
87     return &m_core_ui;
88 }
89
90 CSCLConnection* CSCLCoreImpl::get_connection()
91 {
92     return &m_connection;
93 }
94
95 sclchar* CSCLCoreImpl::get_uuid()
96 {
97     return m_uuid;
98 }
99
100 void CSCLCoreImpl::config_reload()
101 {
102     m_connection.config_reload();
103 }
104
105 sclboolean CSCLCoreImpl::config_read_int(const sclchar *name, sclint &value)
106 {
107     return m_connection.config_read_int(name, value);
108 }
109
110 sclboolean CSCLCoreImpl::config_read_string(const sclchar *name, std::string &value)
111 {
112     return m_connection.config_read_string(name, value);
113 }
114
115 sclboolean CSCLCoreImpl::config_write_int(const sclchar *name, sclint value)
116 {
117     return m_connection.config_write_int(name, value);
118 }
119
120 sclboolean CSCLCoreImpl::config_write_string(const sclchar *name, const std::string value)
121 {
122     return m_connection.config_write_string(name, value);
123 }
124
125 sclboolean CSCLCoreImpl::config_erase(const sclchar *name)
126 {
127     return m_connection.config_erase(name);
128 }
129
130 sclboolean CSCLCoreImpl::config_flush(void)
131 {
132     return m_connection.config_flush();
133 }
134
135 void CSCLCoreImpl::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
136 {
137     m_connection.send_imengine_event(ic, ic_uuid, command, value);
138 }
139
140 void CSCLCoreImpl::reset_keyboard_ise()
141 {
142     m_connection.reset_keyboard_ise();
143 }
144
145 void CSCLCoreImpl::flush_keyboard_ise()
146 {
147     m_connection.flush_keyboard_ise();
148 }
149
150 void CSCLCoreImpl::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
151 {
152     m_connection.send_key_event(ic, ic_uuid, keycode, keymask);
153 }
154
155 void CSCLCoreImpl::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
156 {
157     m_connection.forward_key_event(ic, ic_uuid, keycode, keymask);
158 }
159
160 void CSCLCoreImpl::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
161 {
162     m_connection.commit_string(ic, ic_uuid, str);
163 }
164
165 void CSCLCoreImpl::select_candidate(int index)
166 {
167     m_connection.select_candidate(index);
168 }
169
170 void CSCLCoreImpl::show_preedit_string(sclint ic, const sclchar *ic_uuid)
171 {
172     m_connection.show_preedit_string(ic, ic_uuid);
173 }
174
175 void CSCLCoreImpl::show_aux_string(void)
176 {
177     m_connection.show_aux_string();
178 }
179
180 void CSCLCoreImpl::show_candidate_string(void)
181 {
182     m_connection.show_candidate_string();
183 }
184
185 void CSCLCoreImpl::show_associate_string(void)
186 {
187     m_connection.show_associate_string();
188 }
189
190 void CSCLCoreImpl::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
191 {
192     m_connection.hide_preedit_string(ic, ic_uuid);
193 }
194
195 void CSCLCoreImpl::hide_aux_string(void)
196 {
197     m_connection.hide_aux_string();
198 }
199
200 void CSCLCoreImpl::hide_candidate_string(void)
201 {
202     m_connection.hide_candidate_string();
203 }
204
205 void CSCLCoreImpl::hide_associate_string(void)
206 {
207     m_connection.hide_associate_string();
208 }
209
210 void CSCLCoreImpl::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
211 {
212     m_connection.update_preedit_string(ic, ic_uuid, str);
213 }
214
215 void CSCLCoreImpl::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
216 {
217     m_connection.update_preedit_string(ic, ic_uuid, str, attrs);
218 }
219
220 void CSCLCoreImpl::update_aux_string(const sclchar *str)
221 {
222     m_connection.update_aux_string(str);
223 }
224
225 void CSCLCoreImpl::update_input_context(sclu32 type, sclu32 value)
226 {
227     m_connection.update_input_context(type, value);
228 }
229
230 void CSCLCoreImpl::update_geometry(sclint x, sclint y, sclint width, sclint height)
231 {
232     m_connection.update_geometry(x, y, width, height);
233 }
234
235 void CSCLCoreImpl::get_surrounding_text(const sclchar* ic_uuid, sclint maxlen_before, sclint maxlen_after) const
236 {
237     m_connection.get_surrounding_text(ic_uuid, maxlen_before, maxlen_after);
238 }
239
240 sclint CSCLCoreImpl::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
241 {
242     return m_connection.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
243 }
244
245 void CSCLCoreImpl::delete_surrounding_text(sclint offset, sclint len) const
246 {
247     m_connection.delete_surrounding_text(offset, len);
248 }
249
250 void CSCLCoreImpl::set_candidate_position(sclint left, sclint top)
251 {
252     m_connection.set_candidate_position(left, top);
253 }
254
255 void CSCLCoreImpl::enable_soft_candidate(sclboolean enable)
256 {
257     m_connection.enable_soft_candidate(enable);
258 }
259
260 void CSCLCoreImpl::candidate_hide(void)
261 {
262     m_connection.candidate_hide();
263 }
264
265 void CSCLCoreImpl::set_keyboard_ise_by_uuid(const sclchar *uuid)
266 {
267     m_connection.set_keyboard_ise_by_uuid(uuid);
268 }
269
270 void CSCLCoreImpl::get_keyboard_ise(const sclchar *uuid)
271 {
272     m_connection.get_keyboard_ise(uuid);
273 }
274
275 void CSCLCoreImpl::on_run(const sclchar *uuid, const sclchar *display)
276 {
277     m_core_ui.init();
278     m_connection.init();
279
280     LOGD("uuid : '%s', display : '%s'\n", uuid, display);
281
282     if (uuid && strlen(uuid) > 0) {
283         if (m_uuid) {
284             free(m_uuid);
285         }
286
287         m_uuid = strdup(uuid);
288     }
289
290     if (display) {
291         if (m_display) {
292             free(m_display);
293         }
294
295         m_display = strdup(display);
296     }
297
298     if (m_event_callback) {
299         m_event_callback->on_run(0, NULL);
300     }
301 }
302
303 void CSCLCoreImpl::run()
304 {
305     m_core_ui.init();
306     m_connection.init();
307
308     if (!m_uuid) {
309         char *appid = NULL;
310         app_get_id(&appid);
311
312         LOGD("appid : '%s'\n", appid);
313
314         if (appid) {
315             m_uuid = strdup(appid);
316             free(appid);
317         }
318     }
319
320     if (!m_display) {
321         const char *display = getenv("DISPLAY");
322         LOGD("display env : '%s'\n", display);
323         m_display = display ? strdup(display) : strdup(":0");
324     }
325
326     m_core_ui.run(m_display);
327
328     m_connection.fini();
329     m_core_ui.fini();
330 }
331
332 sclwindow CSCLCoreImpl::get_main_window()
333 {
334     return m_core_ui.get_main_window();
335 }
336
337 int CSCLCoreImpl::get_screen_rotation_degree()
338 {
339     return m_core_ui.get_screen_rotation_degree();
340 }
341
342 void CSCLCoreImpl::set_keyboard_size_hints(SclSize portrait, SclSize landscape)
343 {
344     m_core_ui.set_keyboard_size_hints(portrait, landscape);
345 }
346
347 sclwindow CSCLCoreImpl::create_option_window()
348 {
349     return m_core_ui.create_option_window(OPTION_WINDOW_TYPE_NORMAL);
350 }
351
352 void CSCLCoreImpl::destroy_option_window(sclwindow window)
353 {
354     m_core_ui.destroy_option_window(window);
355 }
356
357 void CSCLCoreImpl::set_selection(sclint start, sclint end)
358 {
359     m_connection.set_selection(start, end);
360 }
361
362 void CSCLCoreImpl::send_private_command(const sclchar *command)
363 {
364     m_connection.send_private_command(command);
365 }
366
367 void CSCLCoreImpl::get_selection_text(sclchar **text)
368 {
369     m_connection.get_selection_text(text);
370 }
371
372 void CSCLCoreImpl::request_ise_hide()
373 {
374     m_connection.request_ise_hide();
375 }