2 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #define IMDATA_STRING_MAX_LEN 32
22 #define IMDATA_ITEM_DELIMETER "&"
23 #define IMDATA_ITEM_MAX_NUM 16
25 #define IMDATA_KEY_LANGUAGE "lang"
26 #define IMDATA_KEY_ACTION "action"
27 #define IMDATA_KEY_VALUE_DELIMETER "="
29 #define IMDATA_VALUE_DISABLE_EMOTICONS "disable_emoticons"
31 static ISELanguageManager _language_manager;
33 /* A macro that frees an array returned by eina_str_split() function -
34 * We need to free the first element and the pointer itself. */
36 static void safe_release_splitted_eina_str(char **string_array)
39 if (string_array[0]) {
40 free(string_array[0]);
46 static void process_imdata_string_language(const char *language_string)
49 if (language_string) {
50 for (scluint loop = 0;loop < _language_manager.get_languages_num() && !found;loop++) {
51 LANGUAGE_INFO *language = _language_manager.get_language_info(loop);
53 if (language->locale_string.compare(language_string) == 0 && language->enabled) {
54 _language_manager.select_language(language->name.c_str());
62 void set_ise_imdata(const char * buf, size_t &len)
65 /* Make sure we're dealing with a NULL-terminated string */
66 char imdatastr[IMDATA_STRING_MAX_LEN + 1] = {0};
67 strncpy(imdatastr, buf, (IMDATA_STRING_MAX_LEN > len) ? len : IMDATA_STRING_MAX_LEN);
69 char **items = eina_str_split(imdatastr, IMDATA_ITEM_DELIMETER, IMDATA_ITEM_MAX_NUM);
72 while (items[loop] && loop < IMDATA_ITEM_MAX_NUM) {
73 char **keyvalue = eina_str_split(items[loop], IMDATA_KEY_VALUE_DELIMETER, 2);
75 LOGD("key (%s), value (%s)\n", keyvalue[0], keyvalue[1]);
76 /* If the key string requests us to change the language */
77 if (strncmp(keyvalue[0], IMDATA_KEY_LANGUAGE, strlen(IMDATA_KEY_LANGUAGE)) == 0) {
78 process_imdata_string_language(keyvalue[1]);
79 } else if (strncmp(keyvalue[0], IMDATA_KEY_ACTION, strlen(IMDATA_KEY_ACTION)) == 0) {
80 if (keyvalue[1] != NULL) {
81 if (strncmp(keyvalue[1], IMDATA_VALUE_DISABLE_EMOTICONS, strlen(IMDATA_VALUE_DISABLE_EMOTICONS)) == 0) { /* Hide Emoticon CM key */
82 ise_set_imdata_state(ise_get_imdata_state() | IMDATA_ACTION_DISABLE_EMOTICONS);
87 safe_release_splitted_eina_str(keyvalue);
90 safe_release_splitted_eina_str(items);