diff options
Diffstat (limited to 'lib/details/ct-input-num-email.c')
-rwxr-xr-x | lib/details/ct-input-num-email.c | 1090 |
1 files changed, 1090 insertions, 0 deletions
diff --git a/lib/details/ct-input-num-email.c b/lib/details/ct-input-num-email.c new file mode 100755 index 0000000..6c4d9fd --- /dev/null +++ b/lib/details/ct-input-num-email.c @@ -0,0 +1,1090 @@ +/* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://floralicense.org/license/ +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "phone.h" +#include "ct-detail.h" +#include "ct-detail-utils.h" +#include "ct-input-utils.h" +#include "ct-input-view.h" + + +#include "ct-input-num-email.h" +#include "ct-input-change-name.h" + +static Evas_Object* input_fill_layout_number(ct_input_data *cinput_d, contacts_record_h record); +static Evas_Object* input_fill_layout_email(ct_input_data *cinput_d, contacts_record_h record); +static Evas_Object* input_new_layout_number(ct_input_data *cinput_d); +static Evas_Object* input_new_layout_email(ct_input_data *cinput_d); + +static void input_email_default_reset(ct_input_data *cinput_d); + +static void input_email_del(ct_input_data *cinput_d, ct_input_typed_data *typed_data) +{ + int idx; + Eina_List *list = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + p_retm_if(NULL == typed_data, "parameter(typed_data) is NULL"); + + err = contacts_record_remove_child_record(cinput_d->contact, _contacts_contact.email, typed_data->record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_remove_child_record() Failed(%d)", err); + + + if (typed_data->ly_content == cinput_d->ly_email_first) { + idx = ct_input_box_idx_get(cinput_d->box, typed_data->ly_content); + list = elm_box_children_get(cinput_d->box); + cinput_d->ly_email_first = eina_list_nth(list, idx + 1); + eina_list_free(list); + } + + if (typed_data->ly_content == cinput_d->ly_email_default) + input_email_default_reset(cinput_d); + + err = contacts_record_destroy(typed_data->record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + elm_box_unpack(cinput_d->box, typed_data->ly_content); + evas_object_del(typed_data->ly_content); +} + +static void input_email_del_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + int count; + ct_input_data *cinput_d = data; + ct_input_typed_data *typed_data; + + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + input_email_del(cinput_d, typed_data); + +} + +static void input_number_default_reset(ct_input_data *cinput_d) +{ + int cnt = 0; + int idx; + Evas_Object *ly_content; + Eina_List *list; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_input_typed_data *typed_data; + + idx = ct_input_box_idx_get(cinput_d->box, cinput_d->ly_number_first); + list = elm_box_children_get(cinput_d->box); + ly_content = cinput_d->ly_number_first; + + cinput_d->ly_number_default = NULL; + + while (ly_content != cinput_d->ly_number_last) { + typed_data = evas_object_data_get(ly_content, "typed_data"); + if (NULL == typed_data) { + ly_content = eina_list_nth(list, ++cnt); + continue; + } + + err = contacts_record_set_bool(typed_data->record, _contacts_number.is_default, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_bool() Failed(%d)", err); + + cinput_d->ly_number_default = typed_data->ly_content; + edje_object_signal_emit(_EDJ(typed_data->ly_content), "elm,state,contact,default_number,enabled", "elm"); + break; + } + eina_list_free(list); +} + +static void input_email_default_reset(ct_input_data *cinput_d) +{ + int cnt = 0; + int idx; + Evas_Object *ly_content; + Eina_List *list; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_input_typed_data *typed_data; + + idx = ct_input_box_idx_get(cinput_d->box, cinput_d->ly_email_first); + list = elm_box_children_get(cinput_d->box); + ly_content = cinput_d->ly_email_first; + + cinput_d->ly_email_default = NULL; + + while (ly_content != cinput_d->ly_email_last) { + typed_data = evas_object_data_get(ly_content, "typed_data"); + if (NULL == typed_data) { + ly_content = eina_list_nth(list, ++cnt); + continue; + } + + err = contacts_record_set_bool(typed_data->record, _contacts_email.is_default, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_bool() Failed(%d)", err); + + cinput_d->ly_email_default = typed_data->ly_content; + edje_object_signal_emit(_EDJ(typed_data->ly_content), "elm,state,contact,default_number,enabled", "elm"); + + break; + } + eina_list_free(list); +} + +static void input_number_del(ct_input_data *cinput_d, ct_input_typed_data *typed_data) +{ + int idx; + Eina_List *list = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + p_retm_if(NULL == typed_data, "parameter(typed_data) is NULL"); + + err = contacts_record_remove_child_record(cinput_d->contact, _contacts_contact.number, typed_data->record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_remove_child_record() Failed(%d)", err); + + cinput_d->cnt_num--; + + + if (typed_data->ly_content == cinput_d->ly_number_first) { + idx = ct_input_box_idx_get(cinput_d->box, typed_data->ly_content); + list = elm_box_children_get(cinput_d->box); + cinput_d->ly_number_first = eina_list_nth(list, idx + 1); + eina_list_free(list); + } + + if (typed_data->ly_content == cinput_d->ly_number_default) + input_number_default_reset(cinput_d); + + err = contacts_record_destroy(typed_data->record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + elm_box_unpack(cinput_d->box, typed_data->ly_content); + evas_object_del(typed_data->ly_content); +} + +static void input_number_del_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + int count; + ct_input_typed_data *typed_data; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + input_number_del(cinput_d, typed_data); + +} + +static Evas_Object* input_new_layout_email(ct_input_data *cinput_d) +{ + contacts_record_h record = NULL; + Evas_Object *layout; + + record = ct_input_new_record_email(cinput_d->contact); + p_retvm_if(NULL == record, NULL, "ct_input_new_record_email() return NULL"); + + layout = input_fill_layout_email(cinput_d, record); + p_retvm_if(NULL == layout, NULL, "input_fill_layout_email() return NULL"); + + if (NULL == cinput_d->ly_email_first) + cinput_d->ly_email_first = layout; + cinput_d->ly_email_last = layout; + + return layout; +} + +static void input_number_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + int num_type; + char buf[PH_TEXT_MAX_LEN+1]; + ct_input_data *cinput_d; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + contacts_error_e err = CONTACTS_ERROR_NONE; + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + num_type = ct_input_get_number_type(type); + if (CONTACTS_NUMBER_TYPE_CUSTOM == num_type){ + ct_input_change_name_view(cinput_d->cdetail_d->navi, ct_input_custom_type_rename_cb, typed_data); + evas_object_del(obj); + return; + } + + err = contacts_record_set_int(typed_data->record, _contacts_number.type, num_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + ctui_get_number_type_str(typed_data->record, num_type, buf, sizeof(buf)); + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + elm_object_text_set(btn_type, buf); + evas_object_del(obj); +} + +static void input_email_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + ct_input_data *cinput_d; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + contacts_error_e err = CONTACTS_ERROR_NONE; + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + if (CONTACTS_EMAIL_TYPE_CUSTOM == type){ + ct_input_change_name_view(cinput_d->cdetail_d->navi, ct_input_custom_type_rename_cb, typed_data); + evas_object_del(obj); + return; + } + + err = contacts_record_set_int(typed_data->record, _contacts_email.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + elm_object_text_set(btn_type, T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(type))); + evas_object_del(obj); +} + +static void input_website_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + ct_input_data *cinput_d; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + contacts_error_e err = CONTACTS_ERROR_NONE; + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + if (CONTACTS_URL_TYPE_CUSTOM == type){ + ct_input_change_name_view(cinput_d->cdetail_d->navi, ct_input_custom_type_rename_cb, typed_data); + evas_object_del(obj); + return; + } + + err = contacts_record_set_int(typed_data->record, _contacts_url.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + elm_object_text_set(btn_type, T_(CT_GET_TEXT_WEBSITE_TYPE, ct_detail_get_website_type_index(type))); + evas_object_del(obj); +} + +static void input_messenger_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + ct_input_data *cinput_d; + contacts_error_e err = CONTACTS_ERROR_NONE; + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + if (CONTACTS_MESSENGER_TYPE_CUSTOM == type){ + ct_input_change_name_view(cinput_d->cdetail_d->navi, ct_input_custom_type_rename_cb, typed_data); + evas_object_del(obj); + return; + } + + err = contacts_record_set_int(typed_data->record, _contacts_messenger.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + elm_object_text_set(btn_type, T_(CT_GET_TEXT_IM_TYPE, type)); + evas_object_del(obj); +} + +static void input_relationship_type_rename_cb(void *data, char *str) +{ + Evas_Object *btn_type; + ct_input_typed_data *typed_data = data; + contacts_error_e err = CONTACTS_ERROR_NONE; + p_retm_if(NULL == typed_data, "parameter(typed_data)"); + + err = contacts_record_set_str(typed_data->record, _contacts_relationship.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + if (str && *str) + elm_object_text_set(btn_type, str); +} + +static void input_relationship_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + ct_input_data *cinput_d; + contacts_error_e err = CONTACTS_ERROR_NONE; + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + if (CONTACTS_RELATIONSHIP_TYPE_CUSTOM == type) + ct_input_change_name_view(cinput_d->cdetail_d->navi, input_relationship_type_rename_cb, typed_data); + + err = contacts_record_set_int(typed_data->record, _contacts_relationship.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + elm_object_text_set(btn_type, T_(CT_GET_TEXT_RELATIONSHIP_TYPE, type)); + evas_object_del(obj); +} + +static void input_event_type_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int type = (int)data; + ct_input_typed_data *typed_data; + Evas_Object *btn_type; + contacts_error_e err = CONTACTS_ERROR_NONE; + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + err = contacts_record_set_int(typed_data->record, _contacts_event.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + btn_type = elm_object_part_content_get(typed_data->ly_content, "elm.icon.type"); + p_retm_if(NULL == btn_type, "elm_object_part_content_get() return NULL"); + + elm_object_text_set(btn_type, T_(CT_GET_TEXT_EVENT_TYPE, type)); + evas_object_del(obj); +} + +void ct_input_data_type_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + bool used_birthday; + int i; + int type_int; + int used = 0; + int rotate; + int idx; + Eina_List *list; + Evas_Object *ly_event; + Evas_Object *popup; + ct_input_data *cinput_d; + ct_input_typed_data *typed_data = data; + ct_input_typed_data *typed_data_event; + contacts_error_e err = CONTACTS_ERROR_NONE; + + p_retm_if(NULL == typed_data, "parameter(typed_data) is NULL"); + + cinput_d = evas_object_data_get(obj, "cinput_d"); + p_retm_if(NULL == cinput_d, "evas_object_data_get() return NULL"); + + if (cinput_d->cdetail_d->popup) + ct_detail_popup_hide_cb(cinput_d->cdetail_d, NULL, NULL); + + popup = elm_ctxpopup_add(cinput_d->cdetail_d->win); + p_retm_if(NULL == popup, "elm_ctxpopup_add() return NULL"); + cinput_d->cdetail_d->popup = popup; + + rotate = (int)evas_object_data_get(cinput_d->cdetail_d->navi, "phone_rotate"); + if (0 == rotate || 180 == rotate) + elm_ctxpopup_direction_priority_set(popup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT); + + evas_object_smart_callback_add(popup, "dismissed", ct_detail_popup_hide_cb, cinput_d->cdetail_d); + evas_object_data_set(popup, "typed_data", typed_data); + evas_object_data_set(popup, "cinput_d", cinput_d); + + if (0 == strcmp(typed_data->view_uri, _contacts_number._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_number.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + for (i=CTTEXT_TYPE_MOBILE;i<=CTTEXT_TYPE_OTHER;i++) { + if (type_int == ct_input_get_number_type(i)) continue; + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_NUM_TYPE, i), NULL, + input_number_type_changed_cb, (void *)i); + } + if(CONTACTS_NUMBER_TYPE_CUSTOM != type_int){ + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_NUM_TYPE, CTTEXT_TYPE_CUSTOM), NULL, + input_number_type_changed_cb, (void *)CTTEXT_TYPE_CUSTOM); + } + } + else if (0 == strcmp(typed_data->view_uri, _contacts_email._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_email.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + int temp_type = CONTACTS_EMAIL_TYPE_HOME; + while(temp_type<=CONTACTS_EMAIL_TYPE_WORK) { + if (type_int == temp_type) { + temp_type = temp_type<<1; + continue; + } + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(temp_type)), NULL, + input_email_type_changed_cb, (void *)temp_type); + temp_type = temp_type<<1; + } + if (CONTACTS_EMAIL_TYPE_OTHER != type_int) { + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(CONTACTS_EMAIL_TYPE_OTHER)), NULL, + input_email_type_changed_cb, (void *)CONTACTS_EMAIL_TYPE_OTHER); + } + if (CONTACTS_EMAIL_TYPE_CUSTOM != type_int) { + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(CONTACTS_EMAIL_TYPE_CUSTOM)), NULL, + input_email_type_changed_cb, (void *)CONTACTS_EMAIL_TYPE_CUSTOM); + } + } + else if (0 == strcmp(typed_data->view_uri, _contacts_url._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_url.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + + for (i=CONTACTS_URL_TYPE_HOME;i<=CONTACTS_URL_TYPE_WORK;i++) { + if (type_int == i) continue; + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_WEBSITE_TYPE, ct_detail_get_website_type_index(i)), NULL, + input_website_type_changed_cb, (void *)i); + } + if (CONTACTS_URL_TYPE_CUSTOM != type_int) { + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_WEBSITE_TYPE, ct_detail_get_website_type_index(CONTACTS_URL_TYPE_CUSTOM)), NULL, + input_website_type_changed_cb, (void *)CONTACTS_URL_TYPE_CUSTOM); + } + } + else if (0 == strcmp(typed_data->view_uri, _contacts_messenger._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_messenger.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + for (i=CONTACTS_MESSENGER_TYPE_GOOGLE;i<=CONTACTS_MESSENGER_TYPE_SKYPE;i++) { + if (type_int == i) continue; + if(CONTACTS_MESSENGER_TYPE_FACEBOOK == i) continue;//Jira issue S1-4557 + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_IM_TYPE, i), NULL, + input_messenger_type_changed_cb, (void *)i); + } + if (type_int != CONTACTS_MESSENGER_TYPE_OTHER) { + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_IM_TYPE, CONTACTS_MESSENGER_TYPE_CUSTOM), NULL, + input_messenger_type_changed_cb, (void *)CONTACTS_MESSENGER_TYPE_CUSTOM); + } + } + else if (0 == strcmp(typed_data->view_uri, _contacts_relationship._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_relationship.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + for (i=CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;i<=CONTACTS_RELATIONSHIP_TYPE_SPOUSE;i++) { + if (type_int == i) continue; + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_RELATIONSHIP_TYPE, i), NULL, + input_relationship_type_changed_cb, (void *)i); + } + } + + else if (0 == strcmp(typed_data->view_uri, _contacts_event._uri)) { + err = contacts_record_get_int(typed_data->record, _contacts_event.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + idx = ct_input_box_idx_get(cinput_d->box, cinput_d->ly_event_first); + + list = elm_box_children_get(cinput_d->box); + used_birthday = false; + do { + int type_event; + ly_event = eina_list_nth(list, idx++); + typed_data_event = evas_object_data_get(ly_event, "typed_data"); + + err = contacts_record_get_int(typed_data_event->record, _contacts_event.type, &type_event); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if (CONTACTS_EVENT_TYPE_BIRTH == type_event) { + used_birthday = true; + break; + } + } while (ly_event != cinput_d->ly_event_last); + eina_list_free(list); + + for (i=CONTACTS_EVENT_TYPE_BIRTH;i<=CONTACTS_EVENT_TYPE_ANNIVERSARY;i++) { + if (type_int == i) + continue; + else if (i == CONTACTS_EVENT_TYPE_BIRTH && used_birthday) + continue; + elm_ctxpopup_item_append(popup, T_(CT_GET_TEXT_EVENT_TYPE, i), NULL, + input_event_type_changed_cb, (void *)i); + } + } + else { + ERR("Unknown type"); + return; + } + + phone_move_ctxpopup(popup, obj); + evas_object_show(popup); +} + +static Evas_Object* input_new_layout_number(ct_input_data *cinput_d) +{ + contacts_record_h record = NULL; + Evas_Object *layout; + + record = ct_input_new_record_number(cinput_d->contact); + p_retvm_if(NULL == record, NULL, "input_new_number() return NULL"); + + layout = input_fill_layout_number(cinput_d, record); + p_retvm_if(NULL == layout, NULL, "input_fill_layout_number() return NULL"); + + if (NULL == cinput_d->ly_number_first) + cinput_d->ly_number_first = layout; + cinput_d->ly_number_last = layout; + + return layout; +} + +static inline bool input_num_email_check_dirty_number(char digit) +{ + switch (digit) + { + case '0' ... '9': + case 'p': + case 'w': + case 'P': + case 'W': + case '#': + case '*': + case '(': + case '/': + case ')': + case 'N': + case ',': + case '.': + case ';': + return false; + case '+': //only first position + default: + return true; + } +} + +static inline int input_check_utf8(char c) +{ + if (c < 128) + return 1; + else if ((c & (char)0xe0) == (char)0xc0) + return 2; + else if ((c & (char)0xf0) == (char)0xe0) + return 3; + else if ((c & (char)0xf8) == (char)0xf0) + return 4; + else if ((c & (char)0xfc) == (char)0xf8) + return 5; + else if ((c & (char)0xfe) == (char)0xfc) + return 6; + else + return CONTACTS_ERROR_INTERNAL; +} + +static int input_num_email_clean_number(const char *src, char *dest, int dest_size) +{ + int s_pos=0, d_pos=0, char_type; + + if (NULL == src) + ERR("The parameter(src) is NULL"); + else + { + if ('+' == src[s_pos]) + dest[d_pos++] = src[s_pos++]; + + while (src[s_pos] != 0) + { + if (d_pos >= dest_size-2) break; + char_type = input_check_utf8(src[s_pos]); + if (char_type <= 1) { + if (input_num_email_check_dirty_number(src[s_pos])) { + s_pos++; + continue; + } + dest[d_pos++] = src[s_pos++]; + } + else + s_pos += char_type; + } + } + + dest[d_pos] = 0; + return d_pos; +} + +static void input_number_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + int len; + char *tmp; + char buf[PH_TEXT_MAX_LEN]; + Evas_Object *btn_minus; + ct_input_data *cinput_d = data; + ct_input_typed_data *typed_data; + + p_retm_if(NULL == cinput_d, "parameter(ct_input_data) is NULL"); + + tmp = ctui_entry_markup_to_utf8(elm_entry_entry_get(obj)); + p_retm_if(NULL == tmp, "ctui_entry_markup_to_utf8() return NULL"); + len = input_num_email_clean_number(tmp, buf, sizeof(buf)); + + if (strlen(tmp) != len) { + ctui_entry_entry_set(obj, buf); + elm_entry_cursor_end_set(obj); + phone_show_popup(cinput_d->cdetail_d->win, T_(CT_GET_TEXT_ERR, CTTEXT_INVALID_NUMBER), 2.0); + free(tmp); + return; + } + free(tmp); + if (0 == len) + return; + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + cinput_d->cnt_num++; + + if (typed_data->ly_content == cinput_d->ly_number_last) { + btn_minus = elm_button_add(typed_data->ly_content); + p_retm_if(NULL == btn_minus, "elm_button_add() return NULL"); + + elm_object_style_set(btn_minus, "minus"); + evas_object_data_set(btn_minus, "typed_data", typed_data); + elm_object_part_content_set(typed_data->ly_content, "elm.icon.edit", btn_minus); + evas_object_smart_callback_add(btn_minus, "clicked", input_number_del_clicked_cb, cinput_d); + + p_retm_if(NULL == input_new_layout_number(cinput_d), "input_new_layout_number() return NULL"); + + return; + } +} + + +static void input_email_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_input_data *cinput_d = data; + Evas_Object *btn_minus; + ct_input_typed_data *typed_data; + const char *tmp; + + tmp = elm_entry_entry_get(obj); + p_retm_if(NULL == tmp || '\0' == tmp[0], "elm_entry_entry_get() return NULL"); + + evas_object_smart_callback_del(obj, "changed", input_email_changed_cb); + p_retm_if(NULL == cinput_d, "parameter(ct_input_data) is NULL"); + + typed_data = evas_object_data_get(obj, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + if (typed_data->ly_content == cinput_d->ly_email_last) { + btn_minus = elm_button_add(typed_data->ly_content); + p_retm_if(NULL == btn_minus, "elm_button_add() return NULL"); + + elm_object_style_set(btn_minus, "minus"); + evas_object_data_set(btn_minus, "typed_data", typed_data); + elm_object_part_content_set(typed_data->ly_content, "elm.icon.edit", btn_minus); + evas_object_smart_callback_add(btn_minus, "clicked", input_email_del_clicked_cb, cinput_d); + + + p_retm_if(NULL == input_new_layout_email(cinput_d), "input_new_layout_email() return NULL"); + } +} + +static void input_number_unfocused_cb(void *data, Evas_Object *obj, void *event_info) +{ + char *input; + Evas_Object *entry = obj; + ct_input_data *cinput_d = data; + ct_input_typed_data *typed_data; + contacts_error_e err = CONTACTS_ERROR_NONE; + + typed_data = evas_object_data_get(entry, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + input = ctui_entry_markup_to_utf8(elm_entry_entry_get(entry)); + p_retm_if(NULL == input, "ctui_entry_markup_to_utf8() return NULL"); + + if (*input) { + err = contacts_record_set_str(typed_data->record, _contacts_number.number, input); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() failed(%d)", err); + + if (NULL == cinput_d->ly_number_default) { + cinput_d->ly_number_default = typed_data->ly_content; + edje_object_signal_emit(_EDJ(typed_data->ly_content), "elm,state,contact,default_number,enabled", "elm"); + + err = contacts_record_set_bool(typed_data->record, _contacts_number.is_default, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_bool() failed(%d)", err); + } + } + else if (typed_data->ly_content == cinput_d->ly_number_default) { + edje_object_signal_emit(_EDJ(typed_data->ly_content), "elm,state,contact,default_number,disabled", "elm"); + input_number_default_reset(cinput_d); + } + free(input); +} + +static void input_email_unfocused_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_FN_CALL; + char *input = NULL; + Evas_Object *entry = obj; + ct_input_data *cinput_d = data; + ct_input_typed_data *typed_data; + contacts_error_e err = CONTACTS_ERROR_NONE; + + typed_data = evas_object_data_get(entry, "typed_data"); + p_retm_if(NULL == typed_data, "evas_object_data_get() return NULL"); + + input = ctui_entry_markup_to_utf8(elm_entry_entry_get(entry)); + p_retm_if(NULL == input, "ctui_entry_markup_to_utf8() return NULL"); + + err = contacts_record_set_str(typed_data->record, _contacts_email.email, input); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() failed(%d)", err); + + if (NULL == cinput_d->ly_email_default) { + cinput_d->ly_email_default = typed_data->ly_content; + edje_object_signal_emit(_EDJ(typed_data->ly_content), "elm,state,contact,default_number,enabled", "elm"); + + err = contacts_record_set_bool(typed_data->record, _contacts_email.is_default, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_bool() failed(%d)", err); + } + + free(input); +} + + +static Evas_Object *input_number_get_edit_rename(ct_input_data *cinput_d, ct_input_typed_data *typed_data) +{ + char *val_str; + Evas_Object *entry; + Evas_Object *editfield; + Evas_Object *ly_content = typed_data->ly_content; + contacts_error_e err = CONTACTS_ERROR_NONE; + + editfield = ct_input_add_editfield(ly_content, T_(CT_GET_TEXT_BASIC, CTTEXT_NUMBER), + input_number_unfocused_cb, cinput_d); + p_retvm_if(NULL == editfield, NULL, "ct_input_add_editfield() return NULL"); + + entry = elm_object_part_content_get(editfield, "elm.swallow.content"); + typed_data->data = entry; + + evas_object_data_set(entry, "typed_data", typed_data); + elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PHONENUMBER); + + err = contacts_record_get_str_p(typed_data->record, _contacts_number.number, &val_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (val_str && *val_str) + ctui_entry_entry_set(entry, val_str); + else + evas_object_smart_callback_add(entry, "changed", input_number_changed_cb, cinput_d); + + return editfield; +} + + +static Evas_Object *input_email_get_edit_rename(ct_input_data *cinput_d, + ct_input_typed_data *typed_data) +{ + char *val_str; + Evas_Object *entry; + Evas_Object *editfield; + Evas_Object *ly_content = typed_data->ly_content; + contacts_error_e err = CONTACTS_ERROR_NONE; + + editfield = ct_input_add_editfield(ly_content, T_(CT_GET_TEXT_BASIC, CTTEXT_EMAIL), + input_email_unfocused_cb, cinput_d); + p_retvm_if(NULL == editfield, NULL, "ct_input_add_editfield() return NULL"); + + entry = elm_object_part_content_get(editfield, "elm.swallow.content"); + typed_data->data = entry; + + evas_object_data_set(entry, "typed_data", typed_data); + elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_EMAIL); + + err = contacts_record_get_str_p(typed_data->record, _contacts_email.email, &val_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (val_str && *val_str) + ctui_entry_entry_set(entry, val_str); + else + evas_object_smart_callback_add(entry, "changed", input_email_changed_cb, cinput_d); + + return editfield; +} + +static Evas_Object* input_fill_layout_number(ct_input_data *cinput_d, contacts_record_h record) +{ + bool is_default; + char *val_str; + int type_int; + char buf[PH_TEXT_MAX_LEN+1]; + Evas_Object *ly_content; + Evas_Object *ef; + Evas_Object *btn_minus; + Evas_Object *btn_type = NULL; + Evas_Object *ico_check; + Evas_Object *box = cinput_d->box; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_input_typed_data *typed_data; + + ly_content = elm_layout_add(box); + p_retvm_if(NULL == ly_content, NULL, "ct_input_create_dg_layout() return NULL"); + elm_layout_file_set(ly_content, CONTACTS_EDJ, "dialogue/1icon.1type.1edit"); + evas_object_size_hint_align_set(ly_content, EVAS_HINT_FILL, 0.0); + + evas_object_show(ly_content); + + cinput_d->ly_number_base = ly_content; + + err = contacts_record_get_bool(record, _contacts_number.is_default, &is_default); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_bool() Failed(%d)", err); + + if (is_default) { + edje_object_signal_emit(_EDJ(ly_content), "elm,state,contact,default_number,enabled", "elm"); + cinput_d->ly_number_default = ly_content; + } + + err = contacts_record_get_int(record, _contacts_number.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + ctui_get_number_type_str(record, type_int, buf, sizeof(buf)); + + btn_type = elm_button_add(ly_content); + if (NULL == btn_type) { + ERR("elm_button_add() return NULL"); + evas_object_del(ly_content); + return NULL; + } + elm_object_text_set(btn_type, buf); + evas_object_data_set(btn_type, "cinput_d", cinput_d); + elm_object_part_content_set(ly_content, "elm.icon.type", btn_type); + + ico_check = elm_icon_add(ly_content); + if (NULL == ico_check) { + ERR("elm_icon_add() return NULL"); + evas_object_del(ly_content); + return NULL; + } + elm_icon_file_set(ico_check, CTUI_IMG_CHECK, NULL); + evas_object_size_hint_aspect_set(ico_check, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + elm_object_part_content_set(ly_content, "elm.icon", ico_check); + + typed_data = calloc(1, sizeof(ct_input_typed_data)); + p_retvm_if(NULL == typed_data, NULL, "calloc() return NULL"); + typed_data->record = record; + typed_data->ly_content = ly_content; + typed_data->view_uri = _contacts_number._uri; + + err = contacts_record_get_str_p(record, _contacts_number.number, &val_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (val_str && *val_str) { + btn_minus = elm_button_add(ly_content); + if (NULL == btn_minus) { + ERR("elm_button_add() return NULL"); + free(typed_data); + return NULL; + } + elm_object_style_set(btn_minus, "minus"); + evas_object_data_set(btn_minus, "typed_data", typed_data); + elm_object_part_content_set(ly_content, "elm.icon.edit", btn_minus); + evas_object_smart_callback_add(btn_minus, "clicked", input_number_del_clicked_cb, cinput_d); + } + + ef = input_number_get_edit_rename(cinput_d, typed_data); + if (NULL == ef) { + ERR("input_number_get_edit_rename() return NULL"); + free(typed_data); + return NULL; + } + elm_object_part_content_set(ly_content, "elm.icon", ef); + ct_input_add_name_field(ef, cinput_d); + + evas_object_smart_callback_add(btn_type, "clicked", ct_input_data_type_clicked_cb, typed_data); + evas_object_event_callback_add(ly_content, EVAS_CALLBACK_DEL, ct_input_typed_layout_del_cb, typed_data); + + if (cinput_d->ly_number_last) + elm_box_pack_after(box, ly_content, cinput_d->ly_number_last); + else + elm_box_pack_end(box, ly_content); + + return ly_content; +} + +void ct_input_fill_layout_numbers(ct_input_data *cinput_d) +{ + int index = 0; + Evas_Object *ly = NULL; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(cinput_d->contact, _contacts_contact.number, index++, &record)) { + ly = input_fill_layout_number(cinput_d, record); + p_retm_if(NULL == ly, "input_fill_layout_number() return NULL"); + + cinput_d->cnt_num++; + if (NULL == cinput_d->ly_number_first) + cinput_d->ly_number_first = ly; + } + + if (NULL != ly) + cinput_d->ly_number_last = ly; + + p_retm_if(NULL == input_new_layout_number(cinput_d), "input_new_layout_number() return NULL"); +} + +static Evas_Object* input_fill_layout_email(ct_input_data *cinput_d, contacts_record_h record) +{ + bool is_default; + char *val_str; + char *custom_type; + int type_int; + Evas_Object *ly_content, *btn_type; + Evas_Object *ef; + Evas_Object *btn_minus; + Evas_Object *ico_check; + Evas_Object *box = cinput_d->box; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_input_typed_data *typed_data; + + ly_content = elm_layout_add(box); + p_retvm_if(NULL == ly_content, NULL, "elm_layout_add() return NULL"); + elm_layout_file_set(ly_content, CONTACTS_EDJ, "dialogue/1icon.1type.1edit"); + evas_object_size_hint_align_set(ly_content, EVAS_HINT_FILL, 0.0); + evas_object_show(ly_content); + + err = contacts_record_get_bool(record, _contacts_email.is_default, &is_default); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_bool() Failed(%d)", err); + + if (is_default) { + edje_object_signal_emit(_EDJ(ly_content), "elm,state,contact,default_number,enabled", "elm"); + cinput_d->ly_email_default = ly_content; + } + + err = contacts_record_get_int(record, _contacts_email.type, &type_int); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + btn_type = elm_button_add(ly_content); + if (NULL == btn_type) { + ERR("elm_button_add() return NULL"); + evas_object_del(ly_content); + return NULL; + } + custom_type = (char *)T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(type_int)); + if(CONTACTS_EMAIL_TYPE_CUSTOM == type_int){ + err = contacts_record_get_str_p(record, _contacts_email.label, &custom_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (NULL == custom_type || '\0' == custom_type[0]) + custom_type = (char *)T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(CONTACTS_EMAIL_TYPE_OTHER)); + } + + elm_object_text_set(btn_type, custom_type); + evas_object_data_set(btn_type, "cinput_d", cinput_d); + elm_object_part_content_set(ly_content, "elm.icon.type", btn_type); + + ico_check = elm_icon_add(ly_content); + if (NULL == ico_check) { + ERR("elm_icon_add() return NULL"); + evas_object_del(ly_content); + return NULL; + } + elm_icon_file_set(ico_check, CTUI_IMG_CHECK, NULL); + evas_object_size_hint_aspect_set(ico_check, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + elm_object_part_content_set(ly_content, "elm.icon", ico_check); + + typed_data = calloc(1, sizeof(ct_input_typed_data)); + p_retvm_if(NULL == typed_data, NULL, "calloc() return NULL"); + typed_data->record = record; + typed_data->ly_content = ly_content; + typed_data->view_uri = _contacts_email._uri; + evas_object_data_set(ly_content, "typed_data", typed_data); + + err = contacts_record_get_str_p(record, _contacts_email.email, &val_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + if (val_str && *val_str) { + btn_minus = elm_button_add(ly_content); + if (NULL == btn_minus) { + ERR("elm_button_add() return NULL"); + evas_object_del(ly_content); + free(typed_data); + return NULL; + } + elm_object_style_set(btn_minus, "minus"); + evas_object_data_set(btn_minus, "typed_data", typed_data); + elm_object_part_content_set(ly_content, "elm.icon.edit", btn_minus); + evas_object_smart_callback_add(btn_minus, "clicked", input_email_del_clicked_cb, cinput_d); + } + + ef = input_email_get_edit_rename(cinput_d, typed_data); + if (NULL == ef) { + ERR("input_email_get_edit_rename() return NULL"); + evas_object_del(ly_content); + free(typed_data); + return NULL; + } + elm_object_part_content_set(ly_content, "elm.icon", ef); + + evas_object_event_callback_add(ly_content, EVAS_CALLBACK_DEL, ct_input_typed_layout_del_cb, typed_data); + evas_object_smart_callback_add(btn_type, "clicked", ct_input_data_type_clicked_cb, typed_data); + + if (cinput_d->ly_email_last) + elm_box_pack_after(box, ly_content, cinput_d->ly_email_last); + else + elm_box_pack_end(box, ly_content); + + ct_input_add_name_field(ef, cinput_d); + + return ly_content; +} + +int ct_input_fill_layout_emails(ct_input_data *cinput_d) +{ + int cnt = 0; + int index = 0; + Evas_Object *ly; + contacts_record_h record = NULL; + + ly = NULL; + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(cinput_d->contact, _contacts_contact.email, index++, &record)) { + ly = input_fill_layout_email(cinput_d, record); + p_retvm_if(NULL == ly, cnt, "input_fill_layout_email() return NULL"); + + if (NULL == cinput_d->ly_email_first) + cinput_d->ly_email_first = ly; + cnt++; + } + + if (NULL != ly) + cinput_d->ly_email_last = ly; + + p_retvm_if(NULL == input_new_layout_email(cinput_d), cnt, "input_new_layout_email() return NULL"); + + return cnt; +} + |