Update package version to 1.10.13
[platform/core/uifw/ise-default.git] / src / imdata.cpp
1 /*
2  * Copyright (c) 2012 - 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 "ise.h"
19
20 #define IMDATA_STRING_MAX_LEN 32
21
22 #define IMDATA_ITEM_DELIMETER "&"
23 #define IMDATA_ITEM_MAX_NUM 16
24
25 #define IMDATA_KEY_LANGUAGE "lang"
26 #define IMDATA_KEY_ACTION   "action"
27 #define IMDATA_KEY_VALUE_DELIMETER "="
28
29 #define IMDATA_VALUE_DISABLE_EMOTICONS  "disable_emoticons"
30
31 static ISELanguageManager _language_manager;
32
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. */
35
36 static void safe_release_splitted_eina_str(char **string_array)
37 {
38     if (string_array) {
39         if (string_array[0]) {
40             free(string_array[0]);
41         }
42         free(string_array);
43     }
44 }
45
46 static void process_imdata_string_language(const char *language_string)
47 {
48     bool found = FALSE;
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);
52             if (language) {
53                 if (language->locale_string.compare(language_string) == 0 && language->enabled) {
54                     _language_manager.select_language(language->name.c_str());
55                     found = TRUE;
56                 }
57             }
58         }
59     }
60 }
61
62 void set_ise_imdata(const char * buf, size_t &len)
63 {
64     if (buf) {
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);
68
69         char **items = eina_str_split(imdatastr, IMDATA_ITEM_DELIMETER, IMDATA_ITEM_MAX_NUM);
70         if (items) {
71             int loop = 0;
72             while (items[loop] && loop < IMDATA_ITEM_MAX_NUM) {
73                 char **keyvalue = eina_str_split(items[loop], IMDATA_KEY_VALUE_DELIMETER, 2);
74                 if (keyvalue[0]) {
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);
83                             }
84                         }
85                     }
86                 }
87                 safe_release_splitted_eina_str(keyvalue);
88                 loop++;
89             }
90             safe_release_splitted_eina_str(items);
91         }
92     }
93 }