e0087e77fd7610f26a73334b5022d63829f60913
[apps/home/message-app.git] / composer / src / ui-composer / msg-ui-composer-recipient-callback.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license
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 "msg-ui-composer-common.h"
19 #include "msg-ui-composer-util.h"
20 #include "msg-ui-composer-popup.h"
21 #include "msg-ui-composer-external.h"
22 #include "msg-ui-composer-predictsearch.h"
23 #include "msg-ui-composer-recipient.h"
24 #include "msg-ui-composer-recipient-callback.h"
25 #include "msg-ui-composer-attachment.h"
26 #include "msg-ui-composer-body.h"
27 #include "msg-ui-composer-main.h"       /*for page duration, it should be removed if more option concept is changed*/
28
29 /*==================================================================================================
30 *                                                               FUNCTION IMPLEMENTATIONS
31 *==================================================================================================*/
32 /*change number popup cb*/
33 void msg_ui_recipient_change_number_popup_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
34 {
35         D_ENTER;
36         MSG_COMPOSER_VIEW_DATA_S *cd = data;
37         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
38
39         RECIPIENT_S *rd = cd->recipient;
40         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
41
42         MSGC_EVAS_OBJECT_DEL(rd->popup_change_number);
43         D_LEAVE;
44 }
45
46 void msg_ui_recipient_change_number_popup_list_clicked_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48         D_ENTER;
49         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
50         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
51
52         RECIPIENT_S *rd = cd->recipient;
53         D_MSG_RETM_IF(rd == NULL, "recipient data Data is NULL");
54
55         RECIPIENT_ITEM_S *r_item = evas_object_data_get(obj, "selected_item");;
56         D_MSG_RETM_IF(r_item == NULL, "Recipient Data is NULL");
57
58         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
59         elm_genlist_item_selected_set(item, EINA_FALSE);
60
61         CONTACT_ITEM_S *ct_item = (CONTACT_ITEM_S *)elm_object_item_data_get(item);
62         D_MSG_RETM_IF(ct_item == NULL, "ct_item is NULL");
63
64         if (g_strcmp0(r_item->recipient, ct_item->recipient) == 0) {
65                 D_MSG("same recipient %s", ct_item->recipient);
66                 MSGC_EVAS_OBJECT_DEL(rd->popup_change_number);
67                 return;
68         }
69
70         if (COMPOSER_RETURN_RECIPIENT_DUPLICATE == msg_ui_composer_recipient_duplicate_check(cd->recipient, ct_item->recipient)) {
71                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
72         } else {
73                 memset(r_item->recipient, 0x00, sizeof(r_item->recipient));
74                 strncpy(r_item->recipient, ct_item->recipient, sizeof(r_item->recipient) - 1);
75                 r_item->type = msg_ui_composer_recipient_type_get(r_item->recipient);
76                 msg_ui_composer_message_type_check_and_change(cd);
77         }
78
79         MSGC_EVAS_OBJECT_DEL(rd->popup_change_number);
80         return;
81 }
82
83 static char *__contact_type_string_get(int type, int contact_type)
84 {
85         static char return_string[DEF_BUF_LEN + 1] = { 0, };
86         memset(return_string, 0, DEF_BUF_LEN + 1);
87
88         if (type == COMPOSER_ADDR_TYPE_NUMBER) {
89                 switch (contact_type) {
90                 case CONTACTS_NUMBER_TYPE_HOME:
91                         strncpy(return_string, _SYSSTR("IDS_COM_BODY_HOME"), sizeof(return_string) - 1);
92                         break;
93                 case CONTACTS_NUMBER_TYPE_WORK:
94                         strncpy(return_string, _SYSSTR("IDS_COM_BODY_WORK"), sizeof(return_string) - 1);
95                         break;
96                 case CONTACTS_NUMBER_TYPE_CELL:
97                         strncpy(return_string, _SYSSTR("IDS_COM_BODY_MOBILE"), sizeof(return_string) - 1);
98                         break;
99                 default:
100                         strncpy(return_string, _MSGSTR("IDS_MSGF_BODY_OTHER"), sizeof(return_string) - 1);
101                         break;
102                 }
103         } else if (type == COMPOSER_ADDR_TYPE_EMAIL) {
104                 switch (contact_type) {
105                 case CONTACTS_EMAIL_TYPE_HOME:
106                         strncpy(return_string, _SYSSTR("IDS_COM_BODY_HOME"), sizeof(return_string) - 1);
107                         break;
108                 case CONTACTS_EMAIL_TYPE_WORK:
109                         strncpy(return_string, _SYSSTR("IDS_COM_BODY_WORK"), sizeof(return_string) - 1);
110                         break;
111                 default:
112                         strncpy(return_string, _MSGSTR("IDS_MSGF_BODY_OTHER"), sizeof(return_string) - 1);
113                         break;
114                 }
115         } else {
116                 D_EMSG("Invalid number type !!!");
117                 strncpy(return_string, _MSGSTR("IDS_MSGF_BODY_OTHER"), sizeof(return_string) - 1);
118         }
119
120         return return_string;
121 }
122
123 char *msg_ui_recipient_change_number_gl_text_get(void *data, Evas_Object *obj, const char *part)
124 {
125         D_MSG_RETVM_IF(data == NULL, NULL, "data param is NULL");
126         CONTACT_ITEM_S *ct_item = (CONTACT_ITEM_S *)data;
127
128         if (!strcmp(part, "elm.text.1")) {
129                 return strdup(ct_item->recipient);
130         } else {
131                 return strdup(__contact_type_string_get(ct_item->type, ct_item->contact_type));
132         }
133 }
134
135 void msg_ui_recipient_change_number_gl_del(void *data, Evas_Object *obj)
136 {
137         D_MSG_RETM_IF(data == NULL, "RECIPIENT_ITEM_S data is NULL");
138         CONTACT_ITEM_S *ct_item = (CONTACT_ITEM_S *)data;
139
140         if (ct_item)
141                 free(ct_item);
142 }
143
144 /*select popup cb*/
145 void msg_ui_recipient_select_popup_list_clicked_cb(void *data, Evas_Object *obj, void *event_info)
146 {
147         D_ENTER;
148         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
149         RECIPIENT_S *rd = cd->recipient;
150         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
151
152         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
153         elm_list_item_selected_set(item, EINA_FALSE);
154
155         elm_multibuttonentry_item_selected_set(rd->sel_mbe_item, EINA_FALSE);
156
157         char *label = (char *)elm_object_item_text_get(item);
158
159         if (cd->isAppControl) {
160                 if (!strcmp(label, _SYSSTR("IDS_COM_OPT_DELETE"))) {
161                         msg_ui_composer_recipient_selected_delete(cd);
162                 } else if (!strcmp(label,_SYSSTR("IDS_COM_BODY_EDIT"))) {
163                         msg_ui_composer_recipient_selected_edit(cd);
164                 } else {
165                         D_EMSG("Invalid list type!!");
166                 }
167         } else {
168                 if (!strcmp(label, _SYSSTR("IDS_COM_OPT_DELETE"))) {
169                         msg_ui_composer_recipient_selected_delete(cd);
170                 } else if (!strcmp(label,_SYSSTR("IDS_COM_BODY_EDIT"))) {
171                         msg_ui_composer_recipient_selected_edit(cd);
172                 } else if (!strcmp(label, _MSGSTR("IDS_MSGC_OPT_USE_OTHER_CONTACT_INFO_ABB"))) {
173                         msg_ui_composer_recipient_create_change_number_popup(cd);
174                 } else if (!strcmp(label, _MSGSTR("IDS_MSGC_OPT_VIEW_CONTACT"))) {
175                         RECIPIENT_ITEM_S *r_item = msg_ui_composer_recipient_selected_item_data_get(cd);
176                         msg_ui_composer_launch_contact_detail_ug(cd, r_item->index);
177
178                         /* set focus to back_btn to resolve invalid focus tree issue */
179                         elm_object_focus_set(cd->back_btn, EINA_TRUE);
180                 } else if (!strcmp(label, _SYSSTR("IDS_COM_OPT_ADD_TO_CONTACTS"))) {
181                         RECIPIENT_ITEM_S *r_item = msg_ui_composer_recipient_selected_item_data_get(cd);
182                         int type = MSG_CT_UG_REQUEST_UPDATE_WITH_NUM;
183
184                         if (IsVaildEmailAddress(r_item->recipient))
185                                 type = MSG_CT_UG_REQUEST_UPDATE_WITH_EMAIL;
186
187                         msg_ui_composer_launch_contact_list_ug(cd, type, r_item->recipient);
188
189                         /* set focus to back_btn to resolve invalid focus tree issue */
190                         elm_object_focus_set(cd->back_btn, EINA_TRUE);
191                 } else {
192                         D_EMSG("Invalid list type!!");
193                 }
194         }
195
196         rd->sel_r_item = NULL;
197         rd->sel_mbe_item = NULL;
198         MSGC_EVAS_OBJECT_DEL(rd->popup_selected);
199
200         D_LEAVE;
201 }
202
203 void msg_ui_recipient_select_popup_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
204 {
205         D_ENTER;
206         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
207         RECIPIENT_S *rd = cd->recipient;
208
209         elm_multibuttonentry_item_selected_set(rd->sel_mbe_item, EINA_FALSE);
210         rd->sel_r_item = NULL;
211         rd->sel_mbe_item = NULL;
212         MSGC_EVAS_OBJECT_DEL(rd->popup_selected);
213
214         D_LEAVE;
215 }
216
217 void msg_ui_recipient_contact_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
218 {
219         D_ENTER;
220
221         MSG_COMPOSER_VIEW_DATA_S *cd = data;
222         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
223         /*set focus to back_btn to resolve invalid focus tree issue regarding contact_btn show/hide*/
224         elm_object_focus_set(cd->back_btn, EINA_TRUE);
225         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_CONTACT_PHONEUI, NULL);
226
227         D_LEAVE;
228 }
229
230 /* multibuttonentry cb */
231 void msg_ui_recipient_mbe_focused_cb(void *data, Evas_Object *obj, void *event_info)
232 {
233         D_ENTER;
234         MSG_COMPOSER_VIEW_DATA_S *cd = NULL;
235         RECIPIENT_S *rd = NULL;
236         PREDICTSEARCH_S *ps = NULL;
237
238         cd = data;
239         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
240
241         rd = cd->recipient;
242         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
243
244         ps = cd->predictsearch;
245         D_MSG_RETM_IF(rd == NULL, "Predict Data is NULL");
246
247         msg_ui_composer_last_focused_entry_set(cd, obj);
248         /* it is added to prevent unfocused_cb of entry on mbe */
249         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(obj);
250         elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
251
252         elm_multibuttonentry_expanded_set(obj, EINA_TRUE);
253
254         if (!cd->isAppControl || !cd->isEmulator)
255                 edje_object_signal_emit(_EDJ(rd->ly_to), "show.ct_button", "*");
256
257         D_LEAVE;
258 }
259
260 void msg_ui_recipient_mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
261 {
262         D_ENTER;
263         MSG_COMPOSER_VIEW_DATA_S *cd = data;
264         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
265         RECIPIENT_S *rd = cd->recipient;
266
267         /*If it exist Selected item popup, then it should not shrink mode set == 1*/
268         if (msg_ui_composer_popup_exist(cd) == EINA_TRUE)
269                 return;
270
271         elm_multibuttonentry_expanded_set(obj, EINA_FALSE);
272
273         if (!cd->isAppControl || !cd->isEmulator)
274                 edje_object_signal_emit(_EDJ(rd->ly_to), "hide.ct_button", "*");
275
276         D_LEAVE;
277 }
278
279 void msg_ui_recipient_mbe_clicked_cb(void *data, Evas_Object *obj, void *event_info)
280 {
281         D_ENTER;
282         MSG_COMPOSER_VIEW_DATA_S *cd = data;
283         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
284
285         int attach_count = msg_ui_composer_get_attach_count(cd);
286
287         if (attach_count > 1)
288                 msg_ui_composer_contract_attach_list(cd);
289
290         if(msg_ui_composer_popup_exist(cd) == EINA_TRUE) {
291                 msg_ui_composer_popup_focus(cd);
292                 return;
293         }
294
295         D_LEAVE;
296 }
297
298 void msg_ui_recipient_mbe_item_clicked_cb(void *data, Evas_Object *obj, void *event_info)
299 {
300         D_ENTER;
301         MSG_COMPOSER_VIEW_DATA_S *cd = data;
302         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
303
304         RECIPIENT_S *rd = cd->recipient;
305         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
306
307         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
308         D_MSG_RETM_IF(item == NULL, "Selected Object Item is NULL");
309
310         RECIPIENT_ITEM_S *r_item;
311
312         r_item = elm_object_item_data_get(item);
313         if (r_item == NULL) {
314                 D_MSG("There are no item data");
315                 return;
316         }
317
318         rd->sel_r_item = r_item;
319         rd->sel_mbe_item = item;
320         msg_ui_composer_last_focused_entry_set(cd, rd->mbe);
321         msg_ui_composer_recipient_select_popup_create(cd);
322
323         D_LEAVE;
324 }
325
326 Eina_Bool msg_ui_recipient_mbe_item_verify_cb(Evas_Object *obj, const char *item_label, const void *item_data, const void *data)
327 {
328         D_ENTER;
329         D_MSG_RETVM_IF(item_label == NULL, EINA_FALSE, "item_label is NULL");
330
331         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
332         D_MSG_RETVM_IF(cd == NULL, EINA_FALSE, "Composer Data is NULL");
333
334         RECIPIENT_S *rd = cd->recipient;
335         D_MSG_RETVM_IF(rd == NULL, EINA_FALSE, "Recipient Data is NULL");
336
337         RECIPIENT_ITEM_S *r_item = NULL;
338
339         if (cd->state == COMPOSER_STATE_TYPE_PAUSE)
340                 return EINA_FALSE;
341
342         msg_ui_composer_recipient_addr_type_set(rd, COMPOSER_RECP_ADDR_NONE);
343
344         /*Check recipient count*/
345         int r_count = msg_ui_composer_recipient_count_get(rd);
346         if (r_count >= COMPOSER_RECIPIENT_COUNT_MAX) {
347                 D_EMSG("recipient is over max count %d ", COMPOSER_RECIPIENT_COUNT_MAX);
348                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
349                 msg_ui_composer_recipient_entry_text_set(rd, "");
350                 return EINA_FALSE;
351         }
352
353         if (item_data) {
354                 D_MSG("This is a checked item before append");
355                 return EINA_TRUE;
356         }
357
358         if (msg_ui_composer_recipient_duplicate_check(cd->recipient, item_label) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
359                 D_EMSG("Input recipient is duplication");
360                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
361                 msg_ui_composer_recipient_entry_text_set(rd, "");
362                 return EINA_FALSE;
363         }
364
365         r_item = msg_ui_composer_recipient_item_make_by_string(item_label);
366         if (r_item == NULL)
367                 return EINA_FALSE;
368
369         if (r_item->type == COMPOSER_RECP_ADDR_INVALID) {
370                 D_EMSG("recipient is invalid recipient");
371                 msg_ui_composer_recipient_addr_type_set(rd, COMPOSER_RECP_ADDR_INVALID);
372
373                 if (rd->notify_popup_idler) {
374                         ecore_idler_del(rd->notify_popup_idler);
375                         rd->notify_popup_idler = NULL;
376                 }
377                 rd->notify_popup_idler = ecore_idler_add(msg_ui_composer_recipient_show_invalid_address_popup, cd);
378
379                 g_free(r_item);
380                 return EINA_FALSE;
381         }
382
383         g_free(r_item);
384         D_LEAVE;
385         return EINA_TRUE;
386 }
387
388 void msg_ui_recipient_mbe_item_added_cb(void *data, Evas_Object *obj, void *event_info)
389 {
390         D_ENTER;
391         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;;
392         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
393
394         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
395         D_MSG_RETM_IF(item == NULL, "Mbe item is NULL");
396
397         RECIPIENT_ITEM_S *recipient_item = NULL;
398
399         if (elm_object_item_data_get(item) == NULL) {
400                 char *bt_label = elm_entry_markup_to_utf8(elm_object_item_text_get(item));
401                 if (bt_label) {
402                         recipient_item = msg_ui_composer_recipient_item_make_by_string(bt_label);
403                         if (recipient_item) {
404                                 elm_object_item_text_set(item, recipient_item->display_name);
405                                 elm_object_item_data_set(item, recipient_item);
406                         } else {
407                                 elm_object_item_del(item);
408                         }
409
410                         g_free(bt_label);
411                 } else {
412                         D_EMSG("button label is null");
413                 }
414         } else {
415                 recipient_item = elm_object_item_data_get(item);
416                 D_MSG(" recipient_item index [%d], recipient_item recipient [%s], recipient_item display_name [%s], recipient_item->image_path [%s]", recipient_item->index, recipient_item->recipient, recipient_item->display_name, recipient_item->image_path);
417         }
418
419         if (recipient_item) {
420                 if (recipient_item->type == COMPOSER_RECP_ADDR_VALID_NUMBER || recipient_item->type == COMPOSER_RECP_ADDR_VALID_EMAIL) {
421                         msg_ui_composer_message_type_check_and_change(cd);
422                 } else {
423                         D_EMSG("Invalid recipient added!!");
424                 }
425         } else {
426                 D_EMSG("No recipient item");
427         }
428 }
429
430 void msg_ui_recipient_mbe_item_deleted_cb(void *data, Evas_Object *obj, void *event_info)
431 {
432         D_ENTER;
433         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;;
434         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
435
436         RECIPIENT_ITEM_S *recipient_item = elm_object_item_data_get(event_info);
437         D_MSG_RETM_IF(recipient_item == NULL,"reicpient item is NULL");
438
439         D_MSG("===== START of recipient_item free =====");
440         D_MSG("recipient_item index [%d]", recipient_item->index);
441         D_MSG("recipient_item recipient [%s]", recipient_item->recipient);
442         D_MSG("recipient_item display_name [%s]", recipient_item->display_name);
443         D_MSG("===== END of recipient_item free =====");
444         g_free(recipient_item);
445
446         msg_ui_composer_message_type_check_and_change(cd);
447         D_LEAVE;
448 }
449
450 static Eina_Bool __move_to_scroll_end(void *data)
451 {
452         D_ENTER;
453         RECIPIENT_S *rd = (RECIPIENT_S *)data;
454         D_MSG_RETVM_IF(rd == NULL, EINA_FALSE, "recipient data is NULL");
455
456         rd->scroll_down_idler = NULL;
457
458         Evas_Coord scr_w;
459         Evas_Coord scr_h;
460         Evas_Coord box_h;
461         evas_render(evas_object_evas_get(rd->bx_main));
462
463         elm_scroller_region_get(rd->sc, NULL, NULL, &scr_w, &scr_h);
464         D_PRINT("scroller region w = %d, h = %d ", scr_w, scr_h);
465
466         evas_object_geometry_get(rd->mbe, NULL, NULL, NULL, &box_h);
467         D_PRINT("mbe geometry h = %d ", box_h);
468
469         elm_scroller_region_show(rd->sc, 0, box_h - scr_h, scr_w, scr_h);
470         D_PRINT("scroller region show x = %d, y = %d, w = %d, h = %d ", 0, box_h - scr_h, scr_w, scr_h);
471
472         D_LEAVE;
473         return EINA_FALSE;
474 }
475
476 void msg_ui_recipient_mbe_expanded_cb(void *data, Evas_Object *obj, void *event_info)
477 {
478         D_ENTER;
479         RECIPIENT_S *rd = (RECIPIENT_S *)data;
480         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
481
482         if (rd->scroll_down_idler) {
483                 ecore_idler_del(rd->scroll_down_idler);
484                 rd->scroll_down_idler = NULL;
485         }
486
487         int r_count = msg_ui_composer_recipient_count_get(rd);
488         if (r_count > 1)
489                 rd->scroll_down_idler = ecore_idler_add(__move_to_scroll_end, rd);
490
491         D_LEAVE;
492 }
493
494 void msg_ui_recipient_mbe_contracted_cb(void *data, Evas_Object *obj, void *event_info)
495 {
496         D_ENTER;
497         RECIPIENT_S *rd = (RECIPIENT_S *)data;
498         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
499
500         if (rd->scroll_down_idler) {
501                 ecore_idler_del(rd->scroll_down_idler);
502                 rd->scroll_down_idler = NULL;
503         }
504
505         D_LEAVE;
506 }
507
508 void msg_ui_recipient_mbe_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
509 {
510         D_ENTER;
511         D_MSG_RETM_IF(obj == NULL,"Mbe object is NULL point");
512
513         RECIPIENT_ITEM_S *r_item;
514         Elm_Object_Item *mbe_item = elm_multibuttonentry_first_item_get(obj);
515
516         D_MSG("===== START of mbe_items free =====");
517         while (mbe_item) {
518                 r_item = elm_object_item_data_get(mbe_item);
519                 if (r_item) {
520                         D_MSG("===== START of r_item free =====");
521                         D_MSG("r_item index [%d]", r_item->index);
522                         D_MSG("r_item recipient [%s]", r_item->recipient);
523                         D_MSG("r_item display_name [%s]", r_item->display_name);
524                         D_MSG("===== END of r_item free =====");
525                         g_free(r_item);
526                 }
527
528                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
529         }
530         D_MSG("===== END of mbe_items free =====");
531
532         D_LEAVE;
533 }
534
535 static void __msg_ui_recipient_process_delimiter_char(void *data, char *full_str, char **text, int type)
536 {
537         D_ENTER;
538
539         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
540         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
541         D_MSG_RETM_IF(full_str == NULL, "param is NULL");
542
543         RECIPIENT_S *rd = cd->recipient;
544         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
545
546         int full_str_len = strlen(full_str);
547         bool is_required_parsing = false;
548
549         if (full_str_len < 1) {
550                 D_EMSG("full_str_len is %d", full_str_len);
551                 return;
552         }
553
554         if (type == RECIPIENT_PARSING_TYPE_ENTER_KEY) { /*enter key case*/
555                 is_required_parsing = true;
556         } else {
557                 /* check last character is either ',' or ';' */
558                 if (full_str[full_str_len - 1] == ',' || full_str[full_str_len - 1] == ';') {
559                         D_MSG("full_str [%s]", full_str);
560
561                         /* remove last ',' or ';' */
562                         full_str[full_str_len - 1] = '\0';
563                         --full_str_len;
564
565                         is_required_parsing = true;
566                 }
567         }
568
569         if (is_required_parsing) {
570                 /* parse full str with delimeter , ; */
571                 gchar **split_str = NULL;
572                 split_str = g_strsplit_set(full_str, ",;", -1);
573
574                 if (split_str) {
575                         int count = g_strv_length(split_str);
576                         int i = 0;
577                         MSG_BOOL is_added = FALSE;
578                         MSG_BOOL is_count_max = FALSE;
579                         MSG_BOOL *is_used_list = NULL;
580
581                         D_MSG("splitted string count = %d", count);
582
583                         is_used_list = (MSG_BOOL *)calloc(count, sizeof(MSG_BOOL));
584
585                         if (is_used_list) {
586                                 for (i = 0; i < count; i++) {
587                                         D_MSG("%dth string is [%s]", i+1, split_str[i]);
588
589                                         if (split_str[i] && strlen(split_str[i])) {
590                                                 if (msg_ui_composer_recipient_vaild_check(split_str[i]) == EINA_TRUE) {
591                                                         /*Check recipient count*/
592                                                         int r_count = msg_ui_composer_recipient_count_get(rd);
593                                                         if (r_count >= COMPOSER_RECIPIENT_COUNT_MAX) {
594                                                                 D_EMSG("recipient is over max count %d ", COMPOSER_RECIPIENT_COUNT_MAX);
595                                                                 is_count_max = TRUE;
596                                                                 is_added = TRUE;
597                                                                 is_used_list[i] = TRUE;
598                                                                 continue;
599                                                         }
600
601                                                         if (msg_ui_composer_recipient_duplicate_check(rd, split_str[i]) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
602                                                                 D_EMSG("Input recipient is duplicated");
603                                                                 is_added = TRUE;
604                                                                 is_used_list[i] = TRUE;
605                                                                 continue;
606                                                         }
607
608                                                         if (msg_ui_composer_recipient_append(cd->recipient, split_str[i], 0) == COMPOSER_RETURN_SUCCESS) {
609                                                                 is_added = TRUE;
610                                                                 is_used_list[i] = TRUE;
611                                                         }
612                                                 }
613                                         }
614                                 }
615
616                                 if (is_count_max)
617                                         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
618
619                                 /* re-assemble string */
620                                 if (is_added) {
621                                         char *re_assembled_str = NULL;
622
623                                         re_assembled_str = (char *)calloc(full_str_len + 1, sizeof(char));
624
625                                         if (re_assembled_str) {
626                                                 for (i = 0; i < count - 1; i++) {
627                                                         if (split_str[i] && strlen(split_str[i])) {
628                                                                 if (!is_used_list[i]) {
629                                                                         strncat(re_assembled_str, split_str[i], strlen(split_str[i]));
630                                                                         strncat(re_assembled_str, ",", 1);
631                                                                 }
632                                                         } else {
633                                                                 strncat(re_assembled_str, ",", 1);
634                                                         }
635                                                 }
636                                                 /* append last parsted string */
637                                                 if (split_str[i] && strlen(split_str[i])) {
638                                                         if (!is_used_list[i])
639                                                                 strncat(re_assembled_str, split_str[i], strlen(split_str[i]));
640                                                 }
641
642                                                 /* remove ',' ';' of last position */
643                                                 int str_len = strlen(re_assembled_str);
644                                                 if (str_len > 1) {
645                                                         while (re_assembled_str[str_len - 1] == ',' || re_assembled_str[str_len - 1] == ';') {
646                                                                 re_assembled_str[str_len - 1] = '\0';
647                                                                 --str_len;
648
649                                                                 if (str_len == 0)
650                                                                         break;
651                                                         }
652                                                 }
653
654                                                 D_MSG("reassembeld str = [%s]", re_assembled_str);
655                                                 /*set re-assembed str to text */
656                                                 Evas_Object *entry = elm_multibuttonentry_entry_get(rd->mbe);
657
658                                                 if (type == RECIPIENT_PARSING_TYPE_DELETE_CHAR ||
659                                                         type == RECIPIENT_PARSING_TYPE_ENTER_KEY) {     /* entry_changed_cb | enter key case */
660                                                         elm_entry_entry_set(entry, re_assembled_str);
661                                                         elm_entry_cursor_end_set(entry);
662
663                                                         if (strlen(re_assembled_str)) {
664                                                                 rd->is_required_address_popup = true;
665                                                         }
666                                                 } else {        /* entry_filter_cb */
667                                                         elm_entry_entry_set(entry, "");
668                                                         free(*text);
669
670                                                         if (strlen(re_assembled_str)) {
671                                                                 rd->is_required_address_popup = true;
672                                                                 *text = strdup(re_assembled_str);
673                                                         } else {
674                                                                 *text = NULL;
675                                                         }
676                                                 }
677
678                                                 free(re_assembled_str);
679                                         } else {
680                                                 D_EMSG("calloc is failed");
681                                         }
682                                 }
683
684                                 free(is_used_list);
685                         } else {
686                                 D_EMSG("calloc is failed");
687                         }
688
689                         g_strfreev(split_str);
690                 } else {
691                         D_EMSG("g_strsplit_set is failed");
692                 }
693         }
694 }
695
696 void msg_ui_recipient_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
697 {
698         D_ENTER;
699         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
700         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
701
702         RECIPIENT_S *rd = cd->recipient;
703         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
704
705         char *recipient_str;
706         static char saved_str[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX + 1] = { 0, };
707
708         /* show invalid address popup, after either inserting text(keypad, paste) or deleting text  */
709         if (rd->is_required_address_popup) {
710                 msg_ui_composer_recipient_addr_type_set(rd, COMPOSER_RECP_ADDR_INVALID);
711
712                 if (rd->notify_popup_idler) {
713                         ecore_idler_del(rd->notify_popup_idler);
714                         rd->notify_popup_idler = NULL;
715                 }
716                 rd->notify_popup_idler = ecore_idler_add(msg_ui_composer_recipient_show_invalid_address_popup, cd);
717
718                 rd->is_required_address_popup = false;
719         }
720
721         recipient_str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
722         if (recipient_str == NULL)
723                 return;
724
725         COMPOSER_RECP_ADDR_E addr_type = COMPOSER_RECP_ADDR_NONE;
726
727         if (recipient_str && strlen(recipient_str)) {
728                 addr_type = msg_ui_composer_recipient_type_get(recipient_str);
729
730                 int str_len = strlen(recipient_str);
731
732                 if (str_len > 1) {
733                         /* remove ',' ';' character of last position, it is used for deleting character case  */
734                         if (recipient_str[str_len - 1] == ',' || recipient_str[str_len - 1] == ';') {
735                                 __msg_ui_recipient_process_delimiter_char(cd, recipient_str, NULL, RECIPIENT_PARSING_TYPE_DELETE_CHAR);
736                                 free(recipient_str);
737                                 return;
738                         }
739                 }
740         }
741
742         D_MSG("changed_str = %s", recipient_str);
743         D_MSG("saved_str = %s", saved_str);
744
745         msg_ui_composer_recipient_addr_type_set(rd, addr_type);
746         D_MSG("recipient is invalid recipient addr_type = %d", addr_type);
747
748         if (g_strcmp0(saved_str, recipient_str) == 0) {
749                 D_MSG("It is same string before str(%s), current str(%s)", saved_str, recipient_str);
750                 g_free(recipient_str);
751                 return;
752         }
753
754         strncpy(saved_str, recipient_str, sizeof(saved_str) - 1);
755         saved_str[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX] = '\0';
756
757         if (strlen(recipient_str) > 0 ) {
758                 msg_ui_composer_predictsearch_request(cd, recipient_str);
759         } else {
760                 msg_ui_composer_predictsearch_clear(cd);
761         }
762
763         g_free(recipient_str);
764         D_LEAVE;
765 }
766
767 void msg_ui_recipient_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
768 {
769         D_ENTER;
770         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
771         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
772
773         char *recipient_str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
774         if (recipient_str == NULL)
775                 return;
776
777         __msg_ui_recipient_process_delimiter_char(cd, recipient_str, NULL, RECIPIENT_PARSING_TYPE_ENTER_KEY);
778
779         free(recipient_str);
780
781         msg_ui_composer_body_focus_set(cd, 0);
782
783         D_LEAVE;
784 }
785
786 void msg_ui_recipient_entry_filter_cb(void *data, Evas_Object *entry, char **text)
787 {
788         D_ENTER;
789         D_MSG_RETM_IF(text == NULL || *text == NULL, "New Text is NULL");
790
791         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
792         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
793
794         RECIPIENT_S *rd = cd->recipient;
795         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
796
797         const char *pre_str = NULL;
798         char *utf8_text = NULL;
799         gchar *full_str = NULL;
800
801         utf8_text  = elm_entry_markup_to_utf8(*text);
802         if (utf8_text) {
803                 /* get previous entered str */
804                 pre_str = elm_entry_entry_get(entry);
805
806                 /* make full str */
807                 if (pre_str)
808                         full_str = g_strconcat(pre_str, utf8_text, NULL);
809                 else
810                         full_str = g_strdup(utf8_text);
811
812                 if (full_str) {
813                         __msg_ui_recipient_process_delimiter_char(data, full_str, text, RECIPIENT_PARSING_TYPE_ADD_CHAR);
814                         g_free(full_str);
815                 } else {
816                         D_EMSG("full_str is NULL");
817                 }
818
819                 free(utf8_text);
820         }
821
822         D_LEAVE;
823 }
824
825 void msg_ui_recipient_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
826 {
827         D_ENTER;
828         RECIPIENT_S *rd = (RECIPIENT_S *)data;
829         D_MSG_RETM_IF(rd == NULL, "rd is NULL");
830         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
831         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)rd->cd;
832         Evas_Coord x = 0;
833         Evas_Coord y = 0;
834         Evas_Coord w = 0;
835         Evas_Coord h = 0;
836
837         evas_object_geometry_get(obj, &x, &y, &w, &h);
838         D_MSG("recipient box x = %d, y = %d, w = %d, h = %d", x, y, w, h);
839         if (rd->recipient_h != h) {
840                 rd->recipient_h = h;
841
842                 if (cd->isclosed == false) {    /* evas_object_resize makes bs during closing composer*/
843                         Evas_Object *entry = elm_multibuttonentry_entry_get(rd->mbe);
844                         int keypad_h = msg_ui_composer_get_keypad_height(entry);
845
846                         msg_ui_composer_change_body_scroll_size(cd, keypad_h);
847                 }
848         }
849
850         D_LEAVE;
851 }
852