Apply sip back key concept in composer
[apps/home/message-app.git] / composer / src / ui-composer / msg-ui-composer-recipient.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 /* includes*/
19 #include "msg-ui-composer-recipient.h"
20 #include "msg-ui-composer-util.h"
21 #include "msg-ui-composer-common.h"
22 #include "msg-ui-composer-recipient-callback.h"
23 #include "msg-ui-composer-message.h"
24 #include "msg-ui-composer-popup.h"
25 #include "msg-ui-composer-external.h"
26
27 #define CONTACT_NAME_IS_NOT_SUPPORT
28 /*==================================================================================================
29 *                                                               FUNCTION IMPLEMENTATIONS
30 *==================================================================================================*/
31 void msg_ui_composer_recipient_create_change_number_popup(void *data)
32 {
33         D_ENTER;
34         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
35         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
36
37         RECIPIENT_S *rd = cd->recipient;
38         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
39
40         Evas_Object *popup = NULL;
41         Evas_Object *genlist = NULL;
42         int ct_err = CONTACTS_ERROR_NONE;
43         int count = 0;
44         RECIPIENT_ITEM_S *r_item = NULL;
45         CONTACT_ITEM_S *ct_item = NULL;
46
47         contacts_list_h list = NULL;
48         contacts_query_h query = NULL;
49         contacts_filter_h filter = NULL;
50
51         r_item = msg_ui_composer_recipient_selected_item_data_get(cd);
52         D_MSG_RETM_IF(r_item == NULL, "Selected Data is NULL");
53         D_MSG_RETM_IF(r_item->index <= 0, "Selected index <= 0");
54
55         rd->change_number_itc.item_style = "2text.3";
56         rd->change_number_itc.func.text_get = msg_ui_recipient_change_number_gl_text_get;
57         rd->change_number_itc.func.content_get = NULL;
58         rd->change_number_itc.func.state_get = NULL;
59         rd->change_number_itc.func.del = msg_ui_recipient_change_number_gl_del;
60
61         genlist = elm_genlist_add(cd->main_window);
62         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
63         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
64         evas_object_data_set(genlist, "selected_item", r_item);
65
66         /* create query and get list for numbers */
67         contacts_query_create(_contacts_person_number._uri, &query);
68         contacts_filter_create(_contacts_person_number._uri, &filter);
69         contacts_filter_add_int(filter, _contacts_person_number.person_id, CONTACTS_MATCH_EXACTLY, r_item->index);
70         contacts_query_set_filter(query, filter);
71
72         ct_err = contacts_db_get_records_with_query(query, 0, 0, &list);
73         contacts_filter_destroy(filter);
74         contacts_query_destroy(query);
75         filter = NULL;
76         query = NULL;
77
78         if (ct_err != CONTACTS_ERROR_NONE) {
79                 D_EMSG("contacts_db_get_records_with_query is failed error_code = %d", ct_err);
80                 contacts_list_destroy(list, true);
81                 return;
82         }
83
84         while (CONTACTS_ERROR_NONE == ct_err) {
85                 contacts_record_h ct_value = NULL;
86                 int type;
87
88                 contacts_list_get_current_record_p(list, &ct_value);
89
90                 if (ct_value) {
91                         contacts_record_get_int(ct_value, _contacts_person_number.type, &type);
92
93                         if (type != CONTACTS_NUMBER_TYPE_ASSISTANT) {
94                                 char *content = NULL;
95
96                                 contacts_record_get_str_p(ct_value, _contacts_person_number.number, &content);
97                                 D_MSG("[%d][%d]%s", r_item->index, type, content);
98
99                                 if (content) {
100                                         if (strcmp(r_item->recipient, content)) {
101                                                 ct_item = (CONTACT_ITEM_S *)calloc(1, sizeof(CONTACT_ITEM_S));
102                                                 if (ct_item) {
103                                                         ct_item->type = COMPOSER_ADDR_TYPE_NUMBER;
104                                                         ct_item->contact_type = type;
105                                                         strncpy(ct_item->recipient, content, sizeof(ct_item->recipient) - 1);
106
107                                                         elm_genlist_item_append(genlist, &rd->change_number_itc, ct_item, NULL, ELM_GENLIST_ITEM_NONE, msg_ui_recipient_change_number_popup_list_clicked_cb, cd);
108
109                                                         count++;
110                                                 } else {
111                                                         D_EMSG("calloc is failed");
112                                                 }
113                                         }
114                                 }
115                         }
116                 }
117
118                 ct_err = contacts_list_next(list);
119         }
120
121         contacts_list_destroy(list, true);
122         list = NULL;
123
124         /* create query and get list for emails */
125         contacts_query_create(_contacts_person_email._uri, &query);
126         contacts_filter_create(_contacts_person_email._uri, &filter);
127         contacts_filter_add_int(filter, _contacts_person_email.person_id, CONTACTS_MATCH_EXACTLY, r_item->index);
128         contacts_query_set_filter(query, filter);
129
130         ct_err = contacts_db_get_records_with_query(query, 0, 0, &list);
131         contacts_filter_destroy(filter);
132         contacts_query_destroy(query);
133
134         if (ct_err != CONTACTS_ERROR_NONE) {
135                 D_EMSG("contacts_db_get_records_with_query is failed error_code = %d", ct_err);
136                 contacts_list_destroy(list, true);
137                 return;
138         }
139
140         while (CONTACTS_ERROR_NONE == ct_err) {
141                 contacts_record_h ct_value = NULL;
142                 int type;
143
144                 contacts_list_get_current_record_p(list, &ct_value);
145
146                 if (ct_value) {
147                         char *content = NULL;
148
149                         contacts_record_get_int(ct_value, _contacts_person_email.type, &type);
150                         contacts_record_get_str_p(ct_value, _contacts_person_email.email, &content);
151
152                         D_MSG("[%d][%d]%s", r_item->index, type, content);
153
154                         if (content) {
155                                 if (strcmp(r_item->recipient, content)) {
156                                         ct_item = (CONTACT_ITEM_S *)calloc(1, sizeof(CONTACT_ITEM_S));
157                                         if (ct_item) {
158                                                 ct_item->type = COMPOSER_ADDR_TYPE_EMAIL;
159                                                 ct_item->contact_type = type;
160                                                 strncpy(ct_item->recipient, (char *)content, sizeof(ct_item->recipient) - 1);
161
162                                                 elm_genlist_item_append(genlist, &rd->change_number_itc, ct_item, NULL, ELM_GENLIST_ITEM_NONE, msg_ui_recipient_change_number_popup_list_clicked_cb, cd);
163
164                                                 count++;
165                                         } else {
166                                                 D_EMSG("calloc is failed");
167                                         }
168                                 }
169                         }
170                 }
171
172                 ct_err = contacts_list_next(list);
173         }
174
175         contacts_list_destroy(list, true);
176
177         if (count >= 5)
178                 count = 4;
179
180         Evas_Object *box = elm_box_add(cd->main_window);
181         evas_object_size_hint_min_set(box, 0, MSGC_POPUP_GENLIST_H * count * elm_config_scale_get());
182         evas_object_show(genlist);
183         elm_box_pack_end(box, genlist);
184         popup = msg_ui_composer_list_popup_create(cd, _SYSSTR("IDS_COM_SK_SELECT"), box, "min_menustyle");
185
186         Evas_Object *btn1 = elm_button_add(popup);
187         elm_object_style_set(btn1, "popup_button/default");
188         elm_object_text_set(btn1, _SYSSTR("IDS_COM_SK_CANCEL"));
189         elm_object_part_content_set(popup, "button1", btn1);
190         evas_object_smart_callback_add(btn1, "clicked", msg_ui_recipient_change_number_popup_btn_clicked_cb, cd);
191
192         elm_object_focus_allow_set(popup, EINA_TRUE);
193         elm_object_focus_set(popup, EINA_TRUE);
194
195         rd->popup_change_number = popup;
196
197         D_LEAVE;
198 }
199
200 Eina_Bool msg_ui_composer_recipient_show_invalid_address_popup(void *data)
201 {
202         D_ENTER;
203         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
204         D_MSG_RETVM_IF(cd == NULL, EINA_FALSE, "Composer Data is NULL");
205
206         RECIPIENT_S *rd = cd->recipient;
207         D_MSG_RETVM_IF(rd == NULL, EINA_FALSE, "recipient data is NULL");
208
209         rd->notify_popup_idler = NULL;
210
211         if (!msg_ui_composer_popup_exist(cd) && !cd->loaded_ug && !cd->loaded_aul) {
212                 /* show popup when message window has a top focus.(active state of app) */
213                 if (elm_win_focus_get(cd->main_window) == EINA_TRUE) {
214                         if (cd->isclosed == false) {
215                                 if (cd->hide_keypad_op == false) {
216                                         msg_ui_composer_status_btn_popup_show(cd, MSGC_STR_NOTI_RECIPIENT_INVALID, 0, MSGC_STR_BUTTON_OK);
217                                 } else {
218                                         /* skip showing invalid popup if back btn of composer should be worked for hiding keypad operation - sip concept */
219                                         /* move focus to MBE */
220                                         msg_ui_composer_last_focus_load(cd);
221                                         /* hide keypad */
222                                         Evas_Object *last_focus_eo = msg_ui_composer_last_focused_entry_get(cd);
223                                         Evas_Object *entry = elm_multibuttonentry_entry_get(last_focus_eo);
224                                         elm_entry_input_panel_hide(entry);
225
226                                         /* reset hide_keypad_op */
227                                         cd->hide_keypad_op = false;
228                                 }
229                         }
230
231                 }
232         }
233
234         D_LEAVE;
235         return EINA_FALSE;
236 }
237
238 RECIPIENT_ITEM_S *msg_ui_composer_recipient_selected_item_data_get(MSG_COMPOSER_VIEW_DATA_S *cd)
239 {
240         D_ENTER;
241         D_MSG_RETVM_IF(cd == NULL, NULL, "Composer Data is NULL");
242
243         RECIPIENT_S *rd = cd->recipient;
244         D_MSG_RETVM_IF(rd == NULL, NULL, "Recipient Data is NULL");
245
246         RECIPIENT_ITEM_S *r_item = NULL;
247
248         r_item = rd->sel_r_item;
249         if (!r_item) {
250                 D_EMSG("No data in Selected MBE item");
251                 return NULL;
252         }
253
254         D_LEAVE;
255
256         return r_item;
257 }
258
259 void msg_ui_composer_recipient_selected_delete(MSG_COMPOSER_VIEW_DATA_S *cd)
260 {
261         D_ENTER;
262         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
263
264         RECIPIENT_S *rd = cd->recipient;
265         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
266
267         Elm_Object_Item *mbe_item = NULL;
268         mbe_item = rd->sel_mbe_item;
269         if (!mbe_item) {
270                 D_EMSG("There is no Selected MBE item");
271                 return;
272         }
273
274         elm_object_item_del(mbe_item);
275         msg_ui_composer_message_type_check_and_change(cd);
276
277         D_LEAVE;
278 }
279
280 void msg_ui_composer_recipient_selected_edit(MSG_COMPOSER_VIEW_DATA_S *cd)
281 {
282         D_ENTER;
283         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
284
285         RECIPIENT_S *rd = cd->recipient;
286         D_MSG_RETM_IF(rd == NULL, "Recipient Data is NULL");
287
288         Elm_Object_Item *mbe_item = NULL;
289         Evas_Object *sc_entry = NULL;
290 #ifdef CONTACT_NAME_IS_NOT_SUPPORT
291         RECIPIENT_ITEM_S *r_item = NULL;
292 #else
293         const char *label_selected_bt = NULL;
294 #endif
295
296         mbe_item = rd->sel_mbe_item;
297         if (!mbe_item) {
298                 D_EMSG("There is no Selected MBE item");
299                 return;
300         }
301
302 #ifdef CONTACT_NAME_IS_NOT_SUPPORT
303         r_item = msg_ui_composer_recipient_selected_item_data_get(cd);
304         D_MSG_RETM_IF(r_item == NULL, "Selected Data is NULL");
305
306         sc_entry = elm_multibuttonentry_entry_get(rd->mbe);
307         elm_entry_entry_set(sc_entry, r_item->recipient);
308         elm_entry_cursor_line_end_set(sc_entry);
309 #else
310         label_selected_bt = elm_object_item_text_get(mbe_item);
311
312         sc_entry = elm_multibuttonentry_entry_get(rd->mbe);
313         elm_entry_entry_set(sc_entry, label_selected_bt);
314         elm_entry_cursor_line_end_set(sc_entry);
315 #endif
316         elm_object_item_del(mbe_item);
317         msg_ui_composer_message_type_check_and_change(cd);
318
319         D_LEAVE;
320 }
321
322 void msg_ui_composer_recipient_select_popup_create(void *data)
323 {
324         D_ENTER;
325         D_MSG_RETM_IF(data == NULL, "data param is NULL");
326         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
327         RECIPIENT_S *rd = cd->recipient;
328         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
329
330         Evas_Object *popup = NULL;
331         Evas_Object *list = NULL;
332         Evas_Object *btn1 = NULL;
333         RECIPIENT_ITEM_S *r_item = NULL;
334         char title_str[DEF_BUF_LEN + 1] = {0,};
335         char *markup_title_str = NULL;
336
337         r_item = msg_ui_composer_recipient_selected_item_data_get(cd);
338         if (!r_item) {
339                 D_EMSG("r_item is NULL");
340                 return;
341         }
342
343         /*list */
344         list = elm_list_add(cd->main_window);
345         elm_list_mode_set(list, ELM_LIST_EXPAND);
346
347         elm_list_item_append(list, _SYSSTR("IDS_COM_OPT_DELETE"), NULL, NULL, msg_ui_recipient_select_popup_list_clicked_cb, cd);
348         elm_list_item_append(list, _SYSSTR("IDS_COM_BODY_EDIT"), NULL, NULL, msg_ui_recipient_select_popup_list_clicked_cb, cd);
349
350         if (cd->isAppControl && cd->isEmulator) {
351                 snprintf(title_str, sizeof(title_str), "%s", r_item->recipient);
352         } else {
353                 if (r_item->index > 0) {
354                         if (IsMultipleNumber(r_item->index)) {
355                                 elm_list_item_append(list, _MSGSTR("IDS_MSGC_OPT_USE_OTHER_CONTACT_INFO_ABB"), NULL, NULL, msg_ui_recipient_select_popup_list_clicked_cb, cd);
356                         } else {
357                                 elm_list_item_append(list, _MSGSTR("IDS_MSGC_OPT_VIEW_CONTACT"), NULL, NULL, msg_ui_recipient_select_popup_list_clicked_cb, cd);
358                         }
359
360                         if (r_item->display_name[0] != '\0')
361                                 snprintf(title_str, sizeof(title_str), "%s <%s>", r_item->display_name, r_item->recipient);
362                         else
363                                 snprintf(title_str, sizeof(title_str), "%s", r_item->recipient);
364                 } else {
365                         elm_list_item_append(list, _SYSSTR("IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, NULL, msg_ui_recipient_select_popup_list_clicked_cb, cd);
366                         snprintf(title_str, sizeof(title_str), "%s", r_item->recipient);
367                 }
368         }
369
370         elm_list_go(list);
371
372         markup_title_str = elm_entry_utf8_to_markup(title_str);
373         popup = msg_ui_composer_list_popup_create(data, markup_title_str, list, "min_menustyle");
374
375         if (markup_title_str)
376                 g_free(markup_title_str);
377
378         btn1 = elm_button_add(popup);
379         elm_object_style_set(btn1, "popup_button/default");
380         elm_object_text_set(btn1, _SYSSTR("IDS_COM_BODY_CLOSE"));
381         elm_object_part_content_set(popup, "button1", btn1);
382         evas_object_smart_callback_add(btn1, "clicked", msg_ui_recipient_select_popup_btn_clicked_cb, cd);
383
384         elm_object_focus_allow_set(popup, EINA_TRUE);
385         elm_object_focus_set(popup, EINA_TRUE);
386
387         rd->popup_selected = popup;
388
389         D_LEAVE;
390 }
391
392 static Evas_Object *__mbe_create(RECIPIENT_S *rd)
393 {
394         D_ENTER;
395         Evas_Object *mbe = NULL;
396         Evas_Object *entry = NULL;
397         Ecore_IMF_Context *context = NULL;
398         Elm_Entry_Filter_Limit_Size limit_filter;
399
400         char label_txt[TO_FIELD_LABEL_SIZE_MAX] = { 0, };
401         gsize len = 0;
402
403         mbe = elm_multibuttonentry_add(rd->parent);
404         evas_object_size_hint_weight_set(mbe, EVAS_HINT_EXPAND, 0.0);
405         evas_object_size_hint_align_set(mbe, EVAS_HINT_FILL, 0.0);
406         evas_object_show(mbe);
407
408         /* set mbe label */
409         len = snprintf(label_txt, (gsize)sizeof(label_txt), "%s:", MSGC_STR_TO);
410         if (len == -1) {
411                 D_EMSG("len = %d", len);
412         } else if (len > 0) {
413                 label_txt[len] = '\0';
414                 elm_object_text_set(mbe, label_txt);
415         } else {
416                 D_EMSG("len = %d", len);
417         }
418
419         /* set guide text */
420         elm_object_part_text_set(mbe, "guide", MSGC_STR_ADD_RECIPIENT);
421
422         /* set mbe callback */
423         evas_object_smart_callback_add(mbe, "item,added", msg_ui_recipient_mbe_item_added_cb, rd->cd);
424         evas_object_smart_callback_add(mbe, "item,deleted", msg_ui_recipient_mbe_item_deleted_cb, rd->cd);
425         evas_object_smart_callback_add(mbe, "item,clicked", msg_ui_recipient_mbe_item_clicked_cb, rd->cd);
426         evas_object_smart_callback_add(mbe, "expanded", msg_ui_recipient_mbe_expanded_cb, rd);
427         evas_object_smart_callback_add(mbe, "contracted", msg_ui_recipient_mbe_contracted_cb, rd);
428
429         evas_object_smart_callback_add(mbe, "focused", msg_ui_recipient_mbe_focused_cb, rd->cd);
430         evas_object_smart_callback_add(mbe, "clicked", msg_ui_recipient_mbe_clicked_cb, rd->cd);
431         evas_object_smart_callback_add(mbe, "unfocused", msg_ui_recipient_mbe_unfocused_cb, rd->cd);
432         evas_object_event_callback_add(mbe, EVAS_CALLBACK_DEL, msg_ui_recipient_mbe_delete_cb, rd->cd);
433
434         elm_multibuttonentry_item_filter_append(mbe, msg_ui_recipient_mbe_item_verify_cb, rd->cd);
435
436         entry = elm_multibuttonentry_entry_get(mbe);
437         evas_object_smart_callback_add(entry, "changed", msg_ui_recipient_entry_changed_cb, rd->cd);
438         evas_object_smart_callback_add(entry, "preedit,changed", msg_ui_recipient_entry_changed_cb, rd->cd);
439         /* activated is added for enter key of keypad */
440         evas_object_smart_callback_add(entry, "activated", msg_ui_recipient_entry_activated_cb, rd->cd);
441
442         elm_entry_markup_filter_prepend(entry, msg_ui_recipient_entry_filter_cb, rd->cd);
443
444         /* set entry max character count*/
445         limit_filter.max_char_count = COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX;
446         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter);
447
448         context = elm_entry_imf_context_get(entry);
449         ecore_imf_context_input_panel_event_callback_add((Ecore_IMF_Context *)context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, msg_ui_composer_entry_imf_state_cb, rd->cd);
450         ecore_imf_context_input_panel_event_callback_add((Ecore_IMF_Context *)context, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, msg_ui_composer_entry_imf_resize_cb, rd->cd);
451
452         D_LEAVE;
453         return mbe;
454 }
455
456 static Evas_Object *__scroller_create(Evas_Object *parent)
457 {
458         D_ENTER;
459         Evas_Object *scroller;
460         scroller = elm_scroller_add(parent);
461         evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, 0.0);
462         evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
463         elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE);
464         elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
465         evas_object_show(scroller);
466
467         D_LEAVE;
468         return scroller;
469 }
470
471 static Evas_Object *__msg_ui_composer_recipient_to_layout_create(RECIPIENT_S *rd)
472 {
473         D_ENTER;
474         if (rd == NULL)
475                 return NULL;
476
477         Evas_Object *layout = NULL;
478         Evas_Object *parent  = rd->parent;
479
480         layout = msg_ui_composer_load_edj(parent, MSGC_UI_DEFAULT_EDJ, MSGC_EDJ_GRP_RECIPIENT_TO_FIELD);
481         if (!layout) {
482                 D_EMSG("layout is NULL");
483                 return NULL;
484         }
485
486         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
487         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
488         evas_object_show(layout);
489
490         Evas_Object *to_sc = __scroller_create(parent);
491         rd->sc = to_sc;
492
493         Evas_Object *box = elm_box_add(parent);
494         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
495         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
496         evas_object_show(box);
497
498         Evas_Object *box2 = elm_box_add(parent);
499         evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
500         evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, 0.0);
501         evas_object_show(box2);
502
503         elm_box_pack_end(box, box2);
504
505         Evas_Object *mbe = __mbe_create(rd);
506         rd->mbe = mbe;
507
508         elm_object_content_set(to_sc, box);
509         elm_box_pack_end(box2, mbe);
510         elm_object_part_content_set(layout, "swl.mbe_scroll", to_sc);
511
512         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)rd->cd;
513
514         if (!cd->isAppControl || !cd->isEmulator) {
515                 Evas_Object *contact_btn = elm_button_add(rd->parent);
516                 elm_object_theme_set(contact_btn, cd->th);
517                 elm_object_style_set(contact_btn, "msg/contact_btn");
518
519                 Evas_Object *icon = elm_icon_add(contact_btn);
520                 elm_image_file_set(icon, MSG_IMAGES_EDJ, MSGC_IMG_CONTACT_BUTTON_ICON);
521
522                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
523                 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
524
525                 elm_object_part_content_set(contact_btn, "icon", icon);
526
527                 evas_object_smart_callback_add(contact_btn, "clicked", msg_ui_recipient_contact_btn_clicked_cb, rd->cd);
528                 elm_object_part_content_set(layout, "swl.closed_btn", contact_btn);
529         } else {
530                 edje_object_signal_emit(_EDJ(layout), "hide.ct_button", "*");
531         }
532
533         D_LEAVE;
534         return layout;
535 }
536
537 static void __msg_ui_composer_recipient_layout_create(RECIPIENT_S *r)
538 {
539         D_ENTER;
540         D_MSG_RETM_IF(r->parent == NULL, "r->parent is NULL");
541
542         /*Create layout*/
543         Evas_Object *bx;
544         bx = elm_box_add(r->parent);
545         evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0.0);
546         evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
547         evas_object_show(bx);
548
549         r->bx_main = bx;
550
551         r->ly_to = __msg_ui_composer_recipient_to_layout_create(r);
552         elm_box_pack_end(r->bx_main, r->ly_to);
553
554         evas_object_event_callback_add(r->bx_main, EVAS_CALLBACK_RESIZE, msg_ui_recipient_resize_cb, r);
555
556         D_LEAVE;
557 }
558
559 static RECIPIENT_ITEM_S *__msg_ui_composer_recipient_item_make(
560                                                                                         COMPOSER_RECP_ADDR_E type,
561                                                                                         int index,
562                                                                                         const char *display_name,
563                                                                                         const char *recipient,
564                                                                                         const char *image_path)
565 {
566         RECIPIENT_ITEM_S *recipient_item;
567         RECIPIENT_ITEM_S r_item;
568
569         bzero(&r_item, sizeof(r_item));
570
571         r_item.type = type;
572         r_item.index = index;
573
574         if (recipient)
575                 strncpy(r_item.recipient, recipient, sizeof(r_item.recipient) - 1);
576
577         if (display_name)
578                 strncpy(r_item.display_name, display_name, sizeof(r_item.display_name) - 1);
579
580         if (image_path)
581                 strncpy(r_item.image_path, image_path, sizeof(r_item.image_path) - 1);
582
583         recipient_item = calloc(1, sizeof(RECIPIENT_ITEM_S));
584         if (!recipient_item) return NULL;
585
586         memcpy(recipient_item, &r_item, sizeof(RECIPIENT_ITEM_S));
587
588         D_MSG("---------- make item start----------");
589         D_MSG(">>type = %d", r_item.type);
590         D_MSG(">>index = %d", r_item.index);
591         D_MSG(">>displayname = %s", r_item.display_name);
592         D_MSG(">>recipient = %s", r_item.recipient);
593         D_MSG(">>image path = %s", r_item.image_path);
594         D_MSG("---------- make item end----------");
595         return recipient_item;
596 }
597
598 RECIPIENT_ITEM_S *msg_ui_composer_recipient_item_make_by_string(const char *str)
599 {
600         D_MSG_RETVM_IF(str == NULL, NULL, "str is NULL");
601
602         COMPOSER_UTIL_ADDRTYPE_E type;
603         RECIPIENT_ITEM_S r_item;
604         RECIPIENT_ITEM_S *recipient_item;
605 #ifndef CONTACT_NAME_IS_NOT_SUPPORT
606         int ret;
607         char tmp_display_name1[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
608         char tmp_display_name2[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
609 #endif
610
611         bzero(&r_item, sizeof(r_item));
612
613         type = get_address_type(str);
614         if (type == COMPOSER_UTIL_ADDRTYPE_NUMBER || type == COMPOSER_UTIL_ADDRTYPE_EMAIL) {
615
616                 strncpy(r_item.recipient, str, sizeof(r_item.recipient)-1);
617                 r_item.type = msg_ui_composer_recipient_type_get(r_item.recipient);
618                 r_item.index = get_contact_index_by_recipient(str);
619                 if (r_item.index <= 0 || get_contact_display_name_by_index(r_item.index, r_item.display_name, sizeof(r_item.display_name))) {
620                                 strncpy(r_item.display_name, str, sizeof(r_item.display_name)-1);
621                 }
622
623         } else {
624 #ifdef CONTACT_NAME_IS_NOT_SUPPORT
625                 /* contact name is not supported */
626                 r_item.type = COMPOSER_RECP_ADDR_INVALID;
627                 strncpy(r_item.recipient, str, sizeof(r_item.recipient)-1);
628                 strncpy(r_item.display_name, str, sizeof(r_item.display_name)-1);
629 #else
630                 /*IF string is name*/
631                 r_item.index = get_contact_index_by_name(str);
632                 if (r_item.index > 0) {
633                         ret = get_contact_display_name_by_index(r_item.index, r_item.display_name, sizeof(r_item.display_name)-1);
634                         if (COMPOSER_RETURN_SUCCESS != ret){
635                                 return NULL;
636                         }
637
638                         remove_space(r_item.display_name, tmp_display_name1, sizeof(tmp_display_name1)-1);
639                         remove_space(str, tmp_display_name2, sizeof(tmp_display_name2)-1);
640                         if (g_ascii_strncasecmp(tmp_display_name1, tmp_display_name2, strlen(tmp_display_name1))==0){
641                                 D_MSG("Contact's name %s = Inputted name %s", r_item.display_name, str);
642                                 ret = get_contact_default_recipient_by_index(r_item.index, r_item.recipient ,sizeof(r_item.recipient)-1);
643                                 if (CONTACTS_ERROR_NONE != ret){
644                                         return NULL;
645                                 }
646
647                                 r_item.type = msg_ui_composer_recipient_type_get(r_item.recipient);
648                         } else {
649                                 D_MSG("Contact's name %s != Inputted name %s", r_item.display_name, str);
650                                 r_item.type = COMPOSER_RECP_ADDR_INVALID;
651                                 r_item.index = 0;
652                                 bzero(r_item.display_name, sizeof(r_item.display_name));
653                                 strncpy(r_item.display_name, str, sizeof(r_item.display_name)-1);
654                         }
655
656
657                 } else {
658                         r_item.type = COMPOSER_RECP_ADDR_INVALID;
659                         strncpy(r_item.display_name, str, sizeof(r_item.display_name)-1);
660                 }
661 #endif
662         }
663
664         /*make recipient Item*/
665         recipient_item = __msg_ui_composer_recipient_item_make(r_item.type, r_item.index, r_item.display_name, r_item.recipient, NULL);
666         if (!recipient_item) {
667                 D_MSG("Fail of msg_ui_composer_recipient_item_make");
668                 return NULL;
669         }
670
671         return recipient_item;
672 }
673
674 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_duplicate_check(RECIPIENT_S *rd, const char *recipient)
675 {
676         D_ENTER;
677         D_MSG_RETVM_IF(rd == NULL, COMPOSER_RETURN_FAIL, "rd is NULL");
678         D_MSG_RETVM_IF(recipient == NULL, COMPOSER_RETURN_FAIL, "recipient is NULL");
679
680         RECIPIENT_ITEM_S *recipient_item;
681         Elm_Object_Item *mbe_item;
682         COMPOSER_UTIL_ADDRTYPE_E inp_type;
683         COMPOSER_UTIL_ADDRTYPE_E tmp_type;
684
685         char inp_str[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX + 1] = { 0, };
686         char tmp_str[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX + 1] = { 0, };
687
688         bool is_dup = FALSE;
689         int len = 0;
690
691         len = strlen(recipient);
692         inp_type = get_address_type(recipient);
693
694         mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
695         while (mbe_item) {
696                 recipient_item = elm_object_item_data_get(mbe_item);
697
698                 if (recipient_item) {
699                         tmp_type = get_address_type(recipient_item->recipient);
700
701                         if (inp_type == tmp_type) {
702                                 if (inp_type == COMPOSER_UTIL_ADDRTYPE_NUMBER) {
703                                         int tlen = strlen(recipient_item->recipient);
704
705                                         if (len >= COMPARE_STRING_NUM && tlen >= COMPARE_STRING_NUM) {
706                                                 strncpy(inp_str, recipient, sizeof(inp_str) - 1);
707                                                 strncpy(tmp_str, recipient_item->recipient, sizeof(tmp_str) - 1);
708
709                                                 g_strreverse(inp_str);
710                                                 g_strreverse(tmp_str);
711
712                                                 if (!strncmp(inp_str, tmp_str, COMPARE_STRING_NUM)) {
713                                                         is_dup = TRUE;
714                                                         break;
715                                                 }
716                                         } else if (len == tlen) {
717                                                 if (!g_strcmp0(recipient_item->recipient, recipient)) {
718                                                         D_MSG("DUP TRUE");
719                                                         is_dup = TRUE;
720                                                         break;
721                                                 }
722                                         }
723                                 } else if (inp_type == COMPOSER_UTIL_ADDRTYPE_EMAIL){
724                                         if (!g_strcmp0(recipient_item->recipient, recipient)) {
725                                                 is_dup = TRUE;
726                                                 break;
727                                         }
728                                 } else {
729                                         D_EMSG("Unknown type recipient TODO check recipient");
730                                 }
731                         }
732
733                 }
734
735                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
736         }
737
738         if (is_dup) {
739                 D_MSG("Found dup recipient = [%s(%d)] with [%s(%d)]", recipient, strlen(recipient), recipient_item->recipient, strlen(recipient_item->recipient));
740                 return COMPOSER_RETURN_RECIPIENT_DUPLICATE;
741         }
742
743         return COMPOSER_RETURN_SUCCESS;
744 }
745
746 int msg_ui_composer_recipient_count_get(RECIPIENT_S *rd)
747 {
748         D_ENTER;
749         D_MSG_RETVM_IF(rd == NULL, 0, "recipient data is NULL");
750         D_MSG_RETVM_IF(rd->mbe == NULL, 0, "mbe is NULL");
751
752         int r_count = 0;
753         Elm_Object_Item *mbe_item;
754
755         mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
756         while (mbe_item) {
757                 r_count++;
758                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
759         }
760
761         D_MSG("recipient count ---------->[%d]", r_count);
762         D_LEAVE;
763         return r_count;
764 }
765
766 void msg_ui_composer_recipient_addr_type_set(RECIPIENT_S *rd, COMPOSER_RECP_ADDR_E type)
767 {
768         D_ENTER;
769         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
770
771         rd->type = type;
772 }
773
774 COMPOSER_RECP_ADDR_E msg_ui_composer_recipient_addr_type_get(RECIPIENT_S *rd)
775 {
776         D_ENTER;
777         D_MSG_RETVM_IF(rd == NULL, COMPOSER_RECP_ADDR_NONE, "recipient data is NULL");
778         D_MSG("rd->type = [%d]", rd->type);
779
780         return rd->type;
781 }
782
783 COMPOSER_RECP_ADDR_E msg_ui_composer_recipient_type_get(const char *recipient)
784 {
785         int len = 0;
786         COMPOSER_RECP_ADDR_E ret = COMPOSER_RECP_ADDR_INVALID;
787         COMPOSER_UTIL_ADDRTYPE_E type;
788
789         if (!recipient) {
790                 D_PRINT("No Input recipient");
791                 return ret;
792         }
793
794         len = strlen(recipient);
795         if (len == 0) {
796                 D_PRINT("input recipient length is [%d]", len);
797                 return ret;
798         }
799
800         type = get_address_type(recipient);
801         if (type == COMPOSER_UTIL_ADDRTYPE_NUMBER) {
802
803                 if (len >= COMPOSER_RECIPIENT_PHONE_NUMBER_LEN_MIN
804                          && len <= COMPOSER_RECIPIENT_PHONE_NUMBER_LEN_MAX) {
805
806                         ret = COMPOSER_RECP_ADDR_VALID_NUMBER;
807                 }
808
809         } else if (type == COMPOSER_UTIL_ADDRTYPE_EMAIL) {
810                 if (len <= COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX ) {
811
812                         ret = COMPOSER_RECP_ADDR_VALID_EMAIL;
813                 }
814         }
815
816         return ret;
817 }
818
819 Eina_Bool msg_ui_composer_recipient_vaild_check(const char *recipient)
820 {
821         D_ENTER;
822
823         int len = 0;
824         COMPOSER_UTIL_ADDRTYPE_E type;
825
826         if (!recipient) {
827                 D_PRINT("No Input recipient");
828                 return EINA_FALSE;
829         }
830
831         type = get_address_type(recipient);
832         len = strlen(recipient);
833
834         if (len == 0) {
835                 D_PRINT("input recipient length is [%d]", len);
836                 return EINA_FALSE;
837         }
838
839         if (type == COMPOSER_UTIL_ADDRTYPE_NUMBER) {
840                 if (len > COMPOSER_RECIPIENT_PHONE_NUMBER_LEN_MAX) {
841                         D_PRINT("NUMBER type recipient Too Long [%d]", len);
842                         return EINA_FALSE;
843                 }
844
845                 if (len < COMPOSER_RECIPIENT_PHONE_NUMBER_LEN_MIN) {
846                         D_PRINT("NUMBER type recipient Too Short [%d]", len);
847                         return EINA_FALSE;
848                 }
849         } else if (type == COMPOSER_UTIL_ADDRTYPE_EMAIL) {
850                 if (len > COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX) {
851                         D_PRINT("Email type recipient Too Long [%d]", len);
852                         return EINA_FALSE;
853                 }
854
855                 if (len < COMPOSER_RECIPIENT_PHONE_NUMBER_LEN_MIN) {
856                         D_PRINT("Email type recipient Too Short [%d]", len);
857                         return EINA_FALSE;
858                 }
859         } else {
860                 D_PRINT("Unknown type recipient[%d]", type);
861                 return EINA_FALSE;
862         }
863
864         D_LEAVE;
865         return EINA_TRUE;
866 }
867
868 Eina_Bool msg_ui_composer_recipient_is_mms(MSG_COMPOSER_VIEW_DATA_S *cd)
869 {
870         D_ENTER;
871         D_MSG_RETVM_IF(cd == NULL, EINA_FALSE, "composer data is NULL");
872
873         RECIPIENT_ITEM_S *recipient_item = NULL;
874         Elm_Object_Item *mbe_item = NULL;
875         Eina_Bool is_mms = EINA_FALSE;
876         COMPOSER_UTIL_ADDRTYPE_E addrtype;
877         RECIPIENT_S *rd = cd->recipient;
878
879         if (!cd) {
880                 D_EMSG("cd is NULL");
881                 return is_mms;
882         }
883
884         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
885                 if (rd->mode == 1) {
886                         mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
887
888                         while (mbe_item) {
889                                 recipient_item = elm_object_item_data_get(mbe_item);
890
891                                 if (recipient_item) {
892                                         addrtype = get_address_type(recipient_item->recipient);
893
894                                         if (addrtype == COMPOSER_UTIL_ADDRTYPE_EMAIL) {
895                                                 is_mms = EINA_TRUE;
896                                                 break;
897                                         }
898                                 }
899
900                                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
901                         }
902                 }
903         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
904                 Eina_List *list = NULL;
905                 RECIPIENT_ITEM_S *r_item = NULL;
906
907                 EINA_LIST_FOREACH(cd->recipient_list, list, r_item) {
908                         if (r_item) {
909                                 addrtype = get_address_type(r_item->recipient);
910
911                                 if (addrtype == COMPOSER_UTIL_ADDRTYPE_EMAIL) {
912                                         is_mms = EINA_TRUE;
913                                         break;
914                                 }
915                         }
916                 }
917         } else {
918                 D_EMSG("Invalid composer ug mode = %d", cd->msg_ug_mode);
919         }
920
921         D_LEAVE;
922         return is_mms;
923 }
924
925 void msg_ui_composer_recipient_focus_set(RECIPIENT_S *rd)
926 {
927         D_ENTER;
928         if (rd->mbe == NULL)
929                 return;
930
931         elm_object_focus_set(rd->mbe, EINA_TRUE);
932         D_LEAVE;
933 }
934
935 void msg_ui_composer_recipient_expanded_set(RECIPIENT_S *rd, Eina_Bool expanded)
936 {
937         D_ENTER;
938         D_MSG_RETM_IF(rd == NULL, "rd is NULL");
939
940         if (rd->mbe == NULL)
941                 return;
942
943         elm_multibuttonentry_expanded_set(rd->mbe, expanded);
944         D_LEAVE;
945 }
946
947 Eina_List *msg_ui_composer_recipient_invalid_recipient_list_get(RECIPIENT_S *rd)
948 {
949         D_ENTER;
950         RECIPIENT_ITEM_S *r_item;
951         Elm_Object_Item *mbe_item;
952         Eina_List *invalid_list = NULL;
953
954         if (rd->mode == 1) {
955                 if (rd->mbe == NULL)
956                         return NULL;
957
958                 mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
959                 while (mbe_item) {
960                         r_item = elm_object_item_data_get(mbe_item);
961                         if (!r_item) {
962                                 D_EMSG("elm_multibuttonentry data is null");
963                                 continue;
964                         }
965
966                         if (msg_ui_composer_recipient_vaild_check(r_item->recipient) == EINA_FALSE) {
967                                 invalid_list = eina_list_append(invalid_list, r_item);
968                         }
969
970                         mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
971                 }
972
973         } /*else if (rd->mode == 0) {
974                 r_item  = &cd->recipient_frame;
975                 if (msg_ui_composer_recipient_vaild_check(r_item->recipient) == EINA_FALSE) {
976                         invalid_list = eina_list_append(invalid_list,r_item);
977                 }
978
979         } */else {
980                 return NULL;
981         }
982         return invalid_list;
983 }
984
985 const char *msg_ui_composer_recipient_entry_text_get(RECIPIENT_S *rd)
986 {
987         D_ENTER;
988         D_MSG_RETVM_IF(rd == NULL, NULL, "recipient data is NULL");
989         D_MSG_RETVM_IF(rd->mbe == NULL, NULL, "mbe is NULL");
990
991         Evas_Object *entry = elm_multibuttonentry_entry_get(rd->mbe);
992         if (entry == NULL)
993                 return NULL;
994
995         const char *str = elm_entry_entry_get(entry);
996
997         D_MSG("string = %s", str);
998
999         D_LEAVE;
1000         return str;
1001 }
1002
1003 void msg_ui_composer_recipient_entry_text_set(RECIPIENT_S *rd, const char *str)
1004 {
1005         D_ENTER;
1006
1007         if (rd->mbe == NULL)
1008                 return;
1009
1010         Evas_Object *entry = elm_multibuttonentry_entry_get(rd->mbe);
1011         elm_entry_entry_set(entry, str);
1012
1013         D_LEAVE;
1014 }
1015
1016 RECIPIENT_S *msg_ui_composer_recipient_create(Evas_Object *p, int mode, void *data)
1017 {
1018         D_ENTER;
1019         RECIPIENT_S *rd;
1020
1021         rd = calloc(1, sizeof(RECIPIENT_S));
1022         if (rd == NULL)
1023                 return NULL;
1024
1025         rd->parent = p;
1026         rd->cd = data;
1027         rd->mode = mode;
1028
1029         if (mode == 1)
1030                 __msg_ui_composer_recipient_layout_create(rd);
1031
1032         D_LEAVE;
1033         return rd;
1034 }
1035
1036 void msg_ui_composer_recipient_delete(RECIPIENT_S *rd)
1037 {
1038         D_ENTER;
1039
1040         if (rd == NULL)
1041                 return;
1042
1043         if (rd->scroll_down_idler) {
1044                 ecore_idler_del(rd->scroll_down_idler);
1045                 rd->scroll_down_idler = NULL;
1046         }
1047
1048         if (rd->notify_popup_idler) {
1049                 ecore_idler_del(rd->notify_popup_idler);
1050                 rd->notify_popup_idler = NULL;
1051         }
1052
1053         MSGC_EVAS_OBJECT_DEL(rd->mbe);
1054         MSGC_EVAS_OBJECT_DEL(rd->ly_to);
1055         MSGC_EVAS_OBJECT_DEL(rd->bx_main);
1056         MSGC_EVAS_OBJECT_DEL(rd->popup_change_number);
1057         g_free(rd);
1058
1059         D_LEAVE;
1060 }
1061
1062 void msg_ui_composer_recipient_clear(RECIPIENT_S *rd)
1063 {
1064         D_ENTER;
1065         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
1066         D_MSG_RETM_IF(rd->mbe == NULL, "Multibuttonentry is NULL");
1067
1068         RECIPIENT_ITEM_S *r_item;
1069         Elm_Object_Item * mbe_item;
1070
1071         mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
1072         while (mbe_item) {
1073                 r_item = elm_object_item_data_get(mbe_item);
1074                 if (r_item) {
1075                         g_free(r_item);
1076                         elm_object_item_data_set(mbe_item, NULL);
1077                 }
1078
1079                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1080         }
1081
1082         elm_multibuttonentry_clear(rd->mbe);
1083
1084         MSGC_EVAS_OBJECT_DEL(rd->popup_change_number);
1085         D_LEAVE;
1086 }
1087
1088 void msg_ui_composer_recipient_update(RECIPIENT_S *rd)
1089 {
1090         D_ENTER;
1091         D_MSG_RETM_IF(rd == NULL, "recipient data is NULL");
1092         D_MSG_RETM_IF(rd->mbe == NULL, "Multibuttonentry is NULL");
1093
1094         RECIPIENT_ITEM_S *r_item;
1095         Elm_Object_Item *mbe_item;
1096
1097         mbe_item = elm_multibuttonentry_first_item_get(rd->mbe);
1098         while (mbe_item) {
1099                 r_item = elm_object_item_data_get(mbe_item);
1100                 if (!r_item) {
1101                         D_EMSG("elm_multibuttonentry data is null");
1102                         mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1103                         continue;
1104                 }
1105
1106                 /*Check changed contact && change display name && recipient*/
1107                 if (strlen(r_item->recipient) > 0) {
1108
1109                         bzero(r_item->display_name, sizeof(r_item->display_name));
1110                         r_item->index = get_contact_index_by_recipient(r_item->recipient);
1111                         if (r_item->index > 0) {
1112                                 if (get_contact_display_name_by_index(r_item->index, r_item->display_name, sizeof(r_item->display_name)-1) != COMPOSER_RETURN_SUCCESS) {
1113                                         strncpy(r_item->display_name, r_item->recipient, sizeof(r_item->display_name)-1);
1114                                 }
1115                         } else {
1116                                 strncpy(r_item->display_name, r_item->recipient, sizeof(r_item->display_name)-1);
1117                         }
1118                         elm_object_item_text_set(mbe_item, r_item->display_name);
1119
1120                 } else if (strlen(r_item->display_name) > 0) {
1121
1122                         bzero(r_item->recipient, sizeof(r_item->recipient));
1123                         r_item->index = get_contact_index_by_name(r_item->display_name);
1124                         if (r_item->index > 0) {
1125                                 char tmp_display_name1[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
1126                                 char tmp_display_name2[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
1127
1128                                 get_contact_display_name_by_index(r_item->index, tmp_display_name1, sizeof(tmp_display_name1)-1);
1129                                 D_MSG("display_name = %s, get contact displayname = %s", r_item->display_name, tmp_display_name1);
1130                                 remove_space(r_item->display_name, tmp_display_name2, sizeof(tmp_display_name2)-1);
1131                                 remove_space(tmp_display_name1, tmp_display_name1, sizeof(tmp_display_name1)-1);
1132                                 if (g_ascii_strncasecmp(tmp_display_name1, tmp_display_name2, strlen(tmp_display_name1)) == 0) {
1133                                         get_contact_default_recipient_by_index(r_item->index, r_item->recipient ,sizeof(r_item->recipient)-1);
1134                                         r_item->type = msg_ui_composer_recipient_type_get(r_item->recipient);
1135                                 } else {
1136                                         r_item->type = COMPOSER_RECP_ADDR_INVALID;
1137                                         r_item->index = 0;
1138                                 }
1139                         } else {
1140                                 D_EMSG("No contact id of %s", r_item->display_name);
1141                         }
1142                 }
1143
1144                 D_MSG("type [%d]", r_item->type);
1145                 D_MSG("index [%d]", r_item->index);
1146                 D_MSG("recipient [%s]", r_item->recipient);
1147                 D_MSG("display_name [%s]", r_item->display_name);
1148
1149                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1150         }
1151
1152         D_LEAVE;
1153 }
1154
1155 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_append(RECIPIENT_S *rd, const char *recipient, int index)
1156 {
1157         D_ENTER;
1158         D_MSG_RETVM_IF(rd == NULL, COMPOSER_RETURN_FAIL, "recipient data is NULL");
1159         D_MSG_RETVM_IF(rd->mbe == NULL, COMPOSER_RETURN_FAIL, "mbe is NULL");
1160         D_MSG_RETVM_IF(recipient == NULL, COMPOSER_RETURN_FAIL, "recipient is NULL");
1161         D_MSG("Recipient Append Parameter [recipient = %s, index = %d]", recipient, index);
1162
1163         RECIPIENT_ITEM_S *recipient_item;
1164         COMPOSER_RECP_ADDR_E type;
1165         int tmp_index;
1166         char tmp_recipient[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
1167         char tmp_displayname[COMPOSER_RECIPIENT_ADDRESS_VAL_LEN_MAX+1] = {0,};
1168
1169         /*Get recipient*/
1170         strncpy(tmp_recipient, recipient, sizeof(tmp_recipient)-1);
1171
1172         /*get type*/
1173         type = msg_ui_composer_recipient_type_get(tmp_recipient);
1174
1175         /*Get index*/
1176         if (index > 0) {
1177                 tmp_index = index;
1178         } else {
1179                 tmp_index = get_contact_index_by_recipient(tmp_recipient);
1180         }
1181
1182         /*get display name*/
1183         if (tmp_index > 0) {
1184                 if (get_contact_display_name_by_index(tmp_index, tmp_displayname, sizeof(tmp_displayname)) != COMPOSER_RETURN_SUCCESS) {
1185                         strncpy(tmp_displayname, tmp_recipient, sizeof(tmp_displayname)-1);
1186                 }
1187         } else {
1188                 strncpy(tmp_displayname, tmp_recipient, sizeof(tmp_displayname)-1);
1189         }
1190
1191         /*make recipient item*/
1192         recipient_item = __msg_ui_composer_recipient_item_make(type, tmp_index, tmp_displayname, tmp_recipient, NULL);
1193         if (recipient_item == NULL) {
1194                 D_MSG("Fail of msg_ui_composer_recipient_item_make");
1195                 return COMPOSER_RETURN_FAIL;
1196         }
1197
1198         /*append recipient item to mbe*/
1199         if (elm_multibuttonentry_item_append(rd->mbe, recipient_item->display_name, NULL, recipient_item) == NULL) {
1200                 D_EMSG("error elm_multibuttonentry_item_add!!");
1201                 return COMPOSER_RETURN_FAIL;
1202         }
1203
1204         D_LEAVE;
1205         return COMPOSER_RETURN_SUCCESS;
1206 }
1207
1208 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_read_data(MSG_COMPOSER_VIEW_DATA_S *cd)
1209 {
1210         D_ENTER;
1211         RECIPIENT_S *r;
1212         RECIPIENT_ITEM_S *r_item;
1213         Elm_Object_Item *mbe_item;
1214         int r_count = 0;
1215         if (!cd)
1216                 return COMPOSER_RETURN_FAIL;
1217
1218         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1219                 Eina_List *recipient_list = cd->recipient_list;
1220
1221                 if (recipient_list) {
1222                         int recipient_cnt = eina_list_count(recipient_list);
1223                         int i = 0;
1224                         RECIPIENT_ITEM_S *r_item = NULL;
1225                         D_MSG("recipient_cnt = %d", recipient_cnt);
1226
1227                         for (i = 0; i < recipient_cnt; i++) {
1228                                 r_item = (RECIPIENT_ITEM_S *)eina_list_nth(recipient_list, i);
1229                                 if (r_item) {
1230                                         D_MSG("r_item->recipient = %s", r_item->recipient);
1231                                         if (msg_ui_composer_message_add_address(r_item->recipient) == COMPOSER_RETURN_SUCCESS)
1232                                                 r_count++;
1233                                 } else {
1234                                         D_EMSG("r_item is null");
1235                                 }
1236                         }
1237                 } else {
1238                         D_EMSG("There is no recipient address");
1239                 }
1240         } else {
1241                 r = cd->recipient;
1242                 if (!r)
1243                         return COMPOSER_RETURN_FAIL;
1244
1245                 mbe_item = elm_multibuttonentry_first_item_get(r->mbe);
1246                 while (mbe_item) {
1247                         r_item = elm_object_item_data_get(mbe_item);
1248                         if (r_item) {
1249                                 D_MSG("[%s]", r_item->recipient);
1250                                 if (msg_ui_composer_message_add_address(r_item->recipient) == COMPOSER_RETURN_SUCCESS)
1251                                         r_count++;
1252                         }
1253                         mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1254                 }
1255         }
1256
1257         if (r_count == 0)
1258                 return COMPOSER_RETURN_FAIL;
1259
1260         D_LEAVE;
1261         return COMPOSER_RETURN_SUCCESS;
1262 }
1263
1264 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_set_recipient_list(MSG_COMPOSER_VIEW_DATA_S *cd, msg_thread_id_t thread_id)
1265 {
1266         D_ENTER;
1267         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "param is NULL");
1268
1269         /* set recipient list for bubble composer */
1270         msg_struct_list_s addrList;
1271         int i = 0;
1272
1273         memset(&addrList, 0x00, sizeof(msg_struct_list_s));
1274
1275         if (msg_get_address_list(cd->msg_handle, thread_id, &addrList) != COMPOSER_RETURN_SUCCESS)
1276                 return COMPOSER_RETURN_FAIL;
1277
1278         char address[MAX_ADDRESS_VAL_LEN + 1] = {0,};
1279         int address_len = sizeof(address);
1280
1281         for (i = 0; i < addrList.nCount; i++) {
1282                 memset(&address, 0, address_len);
1283                 msg_get_str_value(addrList.msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, address_len);
1284                 if (msg_ui_composer_recipient_add_recipient_list(cd, address) != COMPOSER_RETURN_SUCCESS) {
1285                         msg_release_list_struct(&addrList);
1286                         return COMPOSER_RETURN_FAIL;
1287                 }
1288         }
1289
1290         msg_release_list_struct(&addrList);
1291
1292         D_LEAVE;
1293         return COMPOSER_RETURN_SUCCESS;
1294 }
1295
1296 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_add_recipient_list(MSG_COMPOSER_VIEW_DATA_S *cd, const char *recipient)
1297 {
1298         D_ENTER;
1299         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "param is NULL");
1300         D_MSG_RETVM_IF(recipient == NULL, COMPOSER_RETURN_FAIL, "param is NULL");
1301         D_MSG_RETVM_IF(!strlen(recipient), COMPOSER_RETURN_FAIL, "strlen(recipient) is 0");
1302
1303         RECIPIENT_ITEM_S *r_item = NULL;
1304
1305         r_item = (RECIPIENT_ITEM_S *)calloc(1, sizeof(RECIPIENT_ITEM_S));
1306         if (!r_item) {
1307                 D_EMSG("calloc is failed");
1308                 return COMPOSER_RETURN_FAIL;
1309         }
1310         strncpy(r_item->recipient, recipient, sizeof(r_item->recipient)-1);
1311
1312         cd->recipient_list = eina_list_append(cd->recipient_list, r_item);
1313
1314         D_LEAVE;
1315         return COMPOSER_RETURN_SUCCESS;
1316 }
1317
1318 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_clear_recipient_list(MSG_COMPOSER_VIEW_DATA_S *cd)
1319 {
1320         D_ENTER;
1321         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "param is NULL");
1322         D_MSG_RETVM_IF(cd->recipient_list == NULL, COMPOSER_RETURN_FAIL, "cd->recipient_list is NULL");
1323
1324         RECIPIENT_ITEM_S *r_item = NULL;
1325         D_MSG("recipient_cnt = %d", eina_list_count(cd->recipient_list));
1326
1327         EINA_LIST_FREE(cd->recipient_list, r_item) {
1328                 if (r_item)
1329                         g_free(r_item);
1330                 else
1331                         D_EMSG("r_item is null");
1332         }
1333
1334         cd->recipient_list = NULL;
1335
1336         D_LEAVE;
1337         return COMPOSER_RETURN_SUCCESS;
1338 }
1339
1340 COMPOSER_RETURN_TYPE_E msg_ui_composer_recipient_set_loaded_data(void *data, const char *recipient, int index)
1341 {
1342         D_MSG_RETVM_IF(data == NULL, COMPOSER_RETURN_FAIL, "data is NULL");
1343         D_MSG_RETVM_IF(recipient == NULL, COMPOSER_RETURN_FAIL, "recipient is NULL");
1344         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1345
1346         if (msg_ui_composer_recipient_count_get(cd->recipient) >= COMPOSER_RECIPIENT_COUNT_MAX)
1347                 return COMPOSER_RETURN_RECIPIENT_COUNTMAX;
1348
1349         if (msg_ui_composer_recipient_duplicate_check(cd->recipient, recipient) == COMPOSER_RETURN_RECIPIENT_DUPLICATE)
1350                 return COMPOSER_RETURN_RECIPIENT_DUPLICATE;
1351
1352         if (msg_ui_composer_recipient_vaild_check(recipient) == EINA_FALSE)
1353                 return COMPOSER_RETURN_RECIPIENT_INVALID;
1354         else
1355                 return msg_ui_composer_recipient_append(cd->recipient, recipient, index);
1356 }
1357
1358 void msg_ui_composer_recipient_apply_font_size(MSG_COMPOSER_VIEW_DATA_S *cd, const char *font_sytle)
1359 {
1360         D_ENTER;
1361         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1362         D_MSG_RETM_IF(font_sytle == NULL, "font_sytle is NULL");
1363
1364         Evas_Object* entry = NULL;
1365
1366         if (cd->recipient && cd->recipient->mbe) {
1367                 entry = elm_multibuttonentry_entry_get(cd->recipient->mbe);
1368                 elm_entry_text_style_user_push(entry, font_sytle);
1369         }
1370
1371         D_LEAVE;
1372 }
1373