2 * ISF(Input Service Framework)
4 * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5 * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
7 * Contact: Haifeng Deng <haifeng.deng@samsung.com>, Hengliang Luo <hl.luo@samsung.com>
9 * This library is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU Lesser General Public License as published by the
11 * Free Software Foundation; either version 2.1 of the License, or (at your option)
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software Foundation, Inc., 51
21 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #define Uses_SCIM_CONFIG_PATH
26 #define Uses_SCIM_TRANSACTION
27 #define Uses_ISF_IMCONTROL_CLIENT
28 #define Uses_SCIM_COMPOSE_KEY
29 #define Uses_SCIM_PANEL_AGENT
33 #include "isf_control.h"
37 #include <vconf-keys.h>
39 #include "isf_debug.h"
43 #define LOG_TAG "ISF_CONTROL"
48 EXAPI int isf_control_set_active_ise_by_uuid (const char *uuid)
53 IMControlClient imcontrol_client;
55 if (!imcontrol_client.open_connection ())
58 imcontrol_client.prepare ();
59 if (!imcontrol_client.set_active_ise_by_uuid (uuid))
62 imcontrol_client.close_connection ();
67 EXAPI int isf_control_get_active_ise (char **uuid)
73 IMControlClient imcontrol_client;
76 if (!imcontrol_client.open_connection ())
79 imcontrol_client.prepare ();
80 if (!imcontrol_client.get_active_ise (strUuid)) {
84 imcontrol_client.close_connection ();
89 *uuid = strUuid.length () ? strdup (strUuid.c_str ()) : strdup ("");
91 return strUuid.length ();
94 EXAPI int isf_control_get_ise_list (char ***uuid_list)
96 if (uuid_list == NULL)
100 IMControlClient imcontrol_client;
102 if (!imcontrol_client.open_connection ())
105 imcontrol_client.prepare ();
106 if (!imcontrol_client.get_ise_list (&count, uuid_list))
109 imcontrol_client.close_connection ();
114 EXAPI int isf_control_get_ise_info (const char *uuid, char **name, char **language, ISE_TYPE_T *type, int *option)
116 return isf_control_get_ise_info_and_module_name (uuid, name, language, type, option, NULL);
119 EXAPI int isf_control_get_ise_info_and_module_name (const char *uuid, char **name, char **language, ISE_TYPE_T *type, int *option, char **module_name)
127 String strName, strLanguage, strModuleName;
129 IMControlClient imcontrol_client;
130 if (!imcontrol_client.open_connection ())
133 imcontrol_client.prepare ();
134 if (!imcontrol_client.get_ise_info (uuid, strName, strLanguage, nType, nOption, strModuleName)) {
138 imcontrol_client.close_connection ();
144 *name = strName.length () ? strdup (strName.c_str ()) : strdup ("");
146 if (language != NULL)
147 *language = strLanguage.length () ? strdup (strLanguage.c_str ()) : strdup ("");
150 *type = (ISE_TYPE_T)nType;
155 if (module_name != NULL)
156 *module_name = strModuleName.length () ? strdup (strModuleName.c_str ()) : strdup ("");
161 EXAPI int isf_control_set_active_ise_to_default (void)
163 IMControlClient imcontrol_client;
166 if (!imcontrol_client.open_connection ())
169 imcontrol_client.prepare ();
170 imcontrol_client.set_active_ise_to_default ();
171 if (!imcontrol_client.send ())
174 imcontrol_client.close_connection ();
179 EXAPI int isf_control_reset_ise_option (void)
181 IMControlClient imcontrol_client;
183 if (!imcontrol_client.open_connection ())
186 imcontrol_client.prepare ();
187 if (!imcontrol_client.reset_ise_option ())
190 imcontrol_client.close_connection ();
195 EXAPI int isf_control_set_initial_ise_by_uuid (const char *uuid)
201 IMControlClient imcontrol_client;
202 if (!imcontrol_client.open_connection ())
205 imcontrol_client.prepare ();
206 if (!imcontrol_client.set_initial_ise_by_uuid (uuid))
209 imcontrol_client.close_connection ();
214 EXAPI int isf_control_get_initial_ise (char **uuid)
219 String strUuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_INITIAL_ISE_UUID), String (SCIM_COMPOSE_KEY_FACTORY_UUID));
221 *uuid = strUuid.length () ? strdup (strUuid.c_str ()) : strdup ("");
223 return strUuid.length ();
226 EXAPI int isf_control_show_ise_selector (void)
228 return isf_control_show_ime_selector();
231 EXAPI int isf_control_get_ise_count (ISE_TYPE_T type)
233 char **iselist = NULL;
234 int all_ise_count, ise_count = 0;
237 all_ise_count = isf_control_get_ise_list (&iselist);
238 if (all_ise_count < 0) {
244 for (int i = 0; i < all_ise_count; i++) {
246 isf_control_get_ise_info (iselist[i], NULL, NULL, &isetype, NULL);
247 if (isetype == type) {
261 EXAPI int isf_control_show_ise_option_window (void)
263 IMControlClient imcontrol_client;
265 if (!imcontrol_client.open_connection ())
268 imcontrol_client.prepare ();
269 imcontrol_client.show_ise_option_window ();
270 if (!imcontrol_client.send ())
273 imcontrol_client.close_connection ();
278 EXAPI int isf_control_get_all_ime_info (ime_info_s **info)
280 int count = -1, i = 0;
282 HELPER_ISE_INFO helper_info;
283 ime_info_s *ime_info = NULL;
288 IMControlClient imcontrol_client;
289 if (!imcontrol_client.open_connection ())
292 imcontrol_client.prepare ();
293 if (!imcontrol_client.get_all_helper_ise_info (helper_info))
296 imcontrol_client.close_connection ();
301 count = static_cast<int>(helper_info.label.size());
303 ime_info = (ime_info_s *)calloc (count, sizeof (ime_info_s));
305 for (i = 0; i < count; i++) {
306 snprintf(ime_info[i].appid, sizeof (ime_info[i].appid), "%s", helper_info.appid[i].c_str());
307 snprintf(ime_info[i].label, sizeof (ime_info[i].label), "%s", helper_info.label[i].c_str());
308 ime_info[i].is_enabled = static_cast<bool>(helper_info.is_enabled[i]);
309 ime_info[i].is_preinstalled = static_cast<bool>(helper_info.is_preinstalled[i]);
310 ime_info[i].has_option = static_cast<int>(helper_info.has_option[i]);
322 EXAPI int isf_control_open_ime_option_window (void)
324 return isf_control_show_ise_option_window ();
327 EXAPI int isf_control_get_active_ime (char **appid)
334 IMControlClient imcontrol_client;
335 if (!imcontrol_client.open_connection ()) {
336 LOGW ("open_connection failed");
340 imcontrol_client.prepare ();
341 if (!imcontrol_client.get_active_ise (strUuid)) {
342 LOGW ("get_active_ise failed");
346 imcontrol_client.close_connection ();
351 *appid = strUuid.length () ? strdup (strUuid.c_str ()) : NULL;
353 if (*appid == NULL) {
354 LOGW ("appid is invalid");
358 return strUuid.length ();
361 EXAPI int isf_control_set_active_ime (const char *appid)
363 return isf_control_set_active_ise_by_uuid(appid);
366 EXAPI int isf_control_set_enable_ime (const char *appid, bool is_enabled)
371 IMControlClient imcontrol_client;
374 if (!imcontrol_client.open_connection ())
377 imcontrol_client.prepare ();
379 if (!imcontrol_client.set_enable_helper_ise_info (appid, is_enabled))
382 imcontrol_client.close_connection ();
387 EXAPI int isf_control_show_ime_list (void)
389 IMControlClient imcontrol_client;
392 if (!imcontrol_client.open_connection ())
395 imcontrol_client.prepare ();
396 if (!imcontrol_client.show_helper_ise_list ()) {
397 LOGW ("show_helper_ise_list failed");
401 imcontrol_client.close_connection ();
406 EXAPI int isf_control_show_ime_selector (void)
408 IMControlClient imcontrol_client;
411 if (!imcontrol_client.open_connection ())
414 imcontrol_client.prepare ();
415 if (!imcontrol_client.show_helper_ise_selector ()) {
416 LOGW ("show_helper_ise_selector failed");
420 imcontrol_client.close_connection ();
425 EXAPI int isf_control_is_ime_enabled (const char *appid, bool *enabled)
427 if (!appid || !enabled || strlen(appid) < 1) {
428 LOGW ("Invalid parameter");
435 IMControlClient imcontrol_client;
436 if (!imcontrol_client.open_connection ()) {
437 LOGW ("open_connection failed");
441 imcontrol_client.prepare ();
442 if (!imcontrol_client.is_helper_ise_enabled (appid, nEnabled)) {
443 LOGW ("is_helper_ise_enabled failed");
447 imcontrol_client.close_connection ();
453 LOGW ("Failed; appid(%s), nEnabled=%d", appid, nEnabled);
457 *enabled = static_cast<bool>(nEnabled);
462 EXAPI int isf_control_get_recent_ime_geometry (int *x, int *y, int *w, int *h)
464 return isf_control_get_recent_ime_geometry_with_rotation_angle (-1, x, y, w, h);
467 EXAPI int isf_control_get_recent_ime_geometry_with_rotation_angle (int angle, int * x, int * y, int * w, int * h)
469 int ime_x = -1, ime_y = -1, ime_w = -1, ime_h = -1;
471 IMControlClient imcontrol_client;
474 if ((angle != -1) && (angle % 90 != 0))
478 char *geometry = NULL;
483 geometry = vconf_get_str(VCONFKEY_ISF_IME_RECENT_LAND_GEOMETRY);
486 geometry = vconf_get_str(VCONFKEY_ISF_IME_RECENT_PORT_GEOMETRY);
490 arr = eina_str_split(geometry, ",", 0);
493 ime_x = atoi(arr[0]);
496 ime_y = atoi(arr[1]);
499 ime_w = atoi(arr[2]);
502 ime_h = atoi(arr[3]);
511 if (ime_x < 0 && ime_y < 0 && ime_w < 0 && ime_h < 0) {
518 if (!imcontrol_client.open_connection ())
521 imcontrol_client.prepare ();
522 if (!imcontrol_client.get_recent_ime_geometry (&ime_x, &ime_y, &ime_w, &ime_h, angle))
525 imcontrol_client.close_connection ();
548 EXAPI int isf_control_hide_ime (void)
550 IMControlClient imcontrol_client;
553 if (!imcontrol_client.open_connection ())
556 imcontrol_client.prepare ();
557 if (!imcontrol_client.hide_helper_ise ()) {
558 LOGW ("hide_helper_ise failed");
562 imcontrol_client.close_connection ();
569 vi:ts=4:nowrap:ai:expandtab