remove the legacy code for sms appcontrol
[platform/core/uifw/inputdelegator.git] / src / w-input-emoticon.cpp
1 /*
2  * Copyright (c) 2016 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 #include <app.h>
18 #include <Elementary.h>
19 #include <string>
20 #include <efl_assist.h>
21
22 #include "Debug.h"
23 #include "w-input-selector.h"
24 #include "w-input-smartreply.h"
25
26 #define EMOTICON_CNT 27
27
28 static int previous_icon = -1;
29
30 using namespace std;
31
32 typedef struct {
33     int code;
34     char* name;
35 }Emoticon;
36
37 Emoticon emoticon_info[EMOTICON_CNT] = {
38     {0x1f44c, "IDS_IME_BODY_OK_HAND_SIGN_M_EMOTICON_NAME_TTS"},
39     {0x1f44d, "IDS_IME_BODY_THUMBS_UP_SIGN_M_EMOTICON_NAME"},
40     {0x1f44e, "IDS_IME_BODY_THUMBS_DOWN_SIGN_M_EMOTICON_NAME"},
41     {0x1f604, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_SMILING_EYES_M_EMOTICON_NAME"},
42     {0x1f606, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_TIGHTLY_CLOSED_EYES_M_EMOTICON_NAME"},
43     {0x1f60a, "IDS_IME_BODY_SMILING_FACE_WITH_SMILING_EYES_M_EMOTICON_NAME"},
44     {0x1f60d, "IDS_IME_BODY_SMILING_FACE_WITH_HEART_SHAPED_EYES_M_EMOTICON_NAME"},
45     {0x1f61a, "IDS_IME_BODY_KISSING_FACE_WITH_CLOSED_EYES_M_EMOTICON_NAME"},
46     {0x1f61c, "IDS_IME_BODY_FACE_WITH_STUCK_OUT_TONGUE_AND_WINKING_EYE_M_EMOTICON_NAME"},
47     {0x1f620, "IDS_IME_BODY_ANGRY_FACE_M_EMOTICON_NAME"},
48     {0x1f621, "IDS_IME_BODY_POUTING_FACE_M_EMOTICON_NAME"},
49     {0x1f622, "IDS_IME_BODY_CRYING_FACE_M_EMOTICON_NAME"},
50     {0x1f624, "IDS_IME_BODY_FACE_WITH_LOOK_OF_TRIUMPH_M_EMOTICON_NAME"},
51     {0x1f625, "IDS_IME_BODY_DISAPPOINTED_BUT_RELIEVED_FACE_M_EMOTICON_NAME"},
52     {0x1f62a, "IDS_IME_BODY_SLEEPY_FACE_M_EMOTICON_NAME"},
53     {0x1f62b, "IDS_IME_BODY_TIRED_FACE_M_EMOTICON_NAME"},
54     {0x1f631, "IDS_IME_BODY_FACE_SCREAMING_IN_FEAR_M_EMOTICON_NAME"},
55     {0x1f632, "IDS_IME_BODY_ASTONISHED_FACE_M_EMOTICON_NAME"},
56     {0x1f637, "IDS_IME_BODY_FACE_WITH_MEDICAL_MASK_M_EMOTICON_NAME"},
57     {0x1f495, "IDS_IME_BODY_TWO_HEARTS_M_EMOTICON_NAME"},
58     {0x1f43d, "IDS_IME_BODY_PIG_NOSE_M_EMOTICON_NAME"},
59     {0x1f415, "IDS_IME_BODY_DOG_M_EMOTICON_NAME"},
60     {0x1f408, "IDS_IME_BODY_CAT_M_EMOTICON_NAME"},
61     {0x1f414, "IDS_IME_BODY_CHICKEN_M_EMOTICON_NAME"},
62     {0x1f433, "IDS_IME_BODY_SPOUTING_WHALE_M_EMOTICON_NAME"},
63     {0x1f43c, "IDS_IME_BODY_PANDA_FACE_M_EMOTICON_NAME"},
64     {0x1f42f, "IDS_IME_BODY_TIGER_FACE_M_EMOTICON_NAME"},
65 };
66
67 const char * get_emoticon_file_name(int index)
68 {
69     static string path = get_resource_path() + string("images/u00000.png");
70
71     int ipos = path.size()-9;
72     char str_emoticon_code[10] = {0};
73     snprintf(str_emoticon_code, sizeof(str_emoticon_code), "%x", emoticon_info[index].code);
74     path.erase(ipos, 5);
75     path.insert(ipos, str_emoticon_code);
76     return path.c_str();
77 }
78
79 static Eina_Bool _custom_back_cb(void *data, Elm_Object_Item *it)
80 {
81     _back_to_genlist_for_selector();
82     return EINA_TRUE;
83 }
84
85 static Eina_Bool
86 _rotary_selector_rotary_cb(void *data, Evas_Object *obj, Eext_Rotary_Event_Info *info)
87 {
88     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
89
90    if (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE){
91                 evas_object_smart_callback_call(obj, "item,selected", (void*)data);
92                 eext_rotary_object_event_callback_del(obj, _rotary_selector_rotary_cb);
93    }
94
95         return ECORE_CALLBACK_PASS_ON;
96 }
97
98 static char *_access_info_prepend_cb(void *data, Evas_Object *obj)
99 {
100    PRINTFUNC(DLOG_DEBUG, "%s", __func__);
101
102    std::string text;
103
104    if (previous_icon == 10 || previous_icon == 11){
105                 text = std::string("Page") + " " +std::string(dgettext(PACKAGE, emoticon_info[previous_icon].name));
106                 text = text + " " + gettext("WDS_TTS_TBBODY_DOUBLE_TAP_TO_SEND");
107    } else {
108            text = std::string("Page");
109    }
110    return strdup(text.c_str());
111 }
112
113 static void _rotary_selector_item_clicked(void *data, Evas_Object *obj, void *event_info)
114 {
115     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
116     App_Data* ad = (App_Data*) data;
117     if (!ad)
118         return;
119
120     Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
121     Eina_List *rotary_selector_list = (Eina_List *)eext_rotary_selector_items_get(obj);
122
123     int i = 0;
124     Eina_List *l = rotary_selector_list;
125     Eext_Object_Item *item = (Eext_Object_Item *)eina_list_data_get(l);
126
127     for (i = 0; l != NULL; i++) {
128         if (selected_item == item)
129             break;
130
131         l = eina_list_next(l);
132         item = (Eext_Object_Item *)eina_list_data_get(l);
133     }
134
135     int length;
136     const Eina_Unicode unicode_event[2] = { emoticon_info[i].code, 0 };
137     char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
138
139     input_smartreply_send_feedback(utf_8);
140     reply_to_sender_by_callback((const char*)utf_8, "emoticon");
141
142     PRINTFUNC(SECURE_DEBUG, "[%d]%s", i, utf_8);
143     if (utf_8)
144         free(utf_8);
145
146         if(ad->reply_type == REPLY_APP_NORMAL)
147             elm_exit();
148 }
149
150 static void _rotary_selector_item_selected(void *data, Evas_Object *obj, void *event_info)
151 {
152     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
153 }
154
155 void ise_show_emoticon_popup_rotary(void *data)
156 {
157     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
158     App_Data* ad = (App_Data*) data;
159     if (!ad)
160         return;
161
162     Eext_Object_Item *first_it;
163
164     Evas_Object *rotary_selector = eext_rotary_selector_add(ad->naviframe);
165 //    uxt_theme_object_replace_color(rotary_selector, "B01153", "AO0117");
166     PRINTFUNC(DLOG_DEBUG, "replace color");
167     for (int i = 0; i < EMOTICON_CNT; ++i)
168     {
169         Evas_Object *img = NULL;
170         Eext_Object_Item *item = eext_rotary_selector_item_append(rotary_selector);
171
172         if (i == 0) first_it = item;
173
174         img = elm_image_add(rotary_selector);
175         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
176         eext_rotary_selector_item_part_content_set(item, "item,bg_image", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
177
178         img = elm_image_add(rotary_selector);
179         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
180         eext_rotary_selector_item_part_content_set(item, "selector,icon", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
181     }
182
183     evas_object_smart_callback_add(rotary_selector, "item,selected", _rotary_selector_item_selected, rotary_selector);
184     evas_object_smart_callback_add(rotary_selector, "item,clicked", _rotary_selector_item_clicked, (void*)ad);
185
186     Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, rotary_selector, "empty");
187     elm_naviframe_item_pop_cb_set(nf_item, _custom_back_cb, NULL);
188     eext_rotary_object_event_activated_set(rotary_selector, EINA_TRUE);
189
190     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
191 }