diff options
Diffstat (limited to 'lib/details/ct-input-utils.c')
-rwxr-xr-x | lib/details/ct-input-utils.c | 1487 |
1 files changed, 1487 insertions, 0 deletions
diff --git a/lib/details/ct-input-utils.c b/lib/details/ct-input-utils.c new file mode 100755 index 0000000..1146631 --- /dev/null +++ b/lib/details/ct-input-utils.c @@ -0,0 +1,1487 @@ +/* +* 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 <regex.h> +#include <errno.h> +#include <aul.h> +#include <ui-gadget-module.h> +#include <vconf.h> +#include <vconf-keys.h> +#include <fcntl.h> +#include <app_service.h> +#include <assert.h> + +#include "phone.h" +#include "ct-list.h" +#include "ct-detail.h" +#include "ct-detail-utils.h" +#include "ct-input-utils.h" +#include "ct-input-view.h" + +#define CT_INPUT_BASE_ADDRBOOK UGDATAIDR"/base_addrbook" + +static void input_set_base_ab(char* ab_name) +{ + int fd; + char buf[PH_TEXT_MAX_LEN+1] = {0}; + p_ret_if (NULL == ab_name); + fd = open(CT_INPUT_BASE_ADDRBOOK, O_WRONLY|O_CREAT|O_TRUNC, 0644); + p_retm_if(fd < 0, "Open(%s) Failed", CT_INPUT_BASE_ADDRBOOK); + snprintf(buf, sizeof(buf), "%s", ab_name); + if (-1 == write(fd, buf, strlen(buf))) + ERR("write()... Failed(%s)", strerror(errno)); + close(fd); +} + +int ct_input_get_base_ab(void) +{ + int fd = 0; + int size = 0; + char buf[PH_TEXT_MAX_LEN+1] ={0,}; + + fd = open(CT_INPUT_BASE_ADDRBOOK, O_RDONLY); + p_retvm_if(fd < 0, 0, "Open(%s) Failed", CT_INPUT_BASE_ADDRBOOK); + size = read(fd, buf, sizeof(buf)); + close(fd); + + if (size > 0) + return ctui_get_addressbook_id(buf); + else + return 0; +} + +static void input_change_photo(ct_input_data *cinput_d, const char *normal, const char *full) +{ + contacts_record_h record = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + + record = ctui_get_record_image(cinput_d->contact); + p_retm_if(NULL == record, "ctui_get_record_image() Failed(%d)"); + + err = contacts_record_set_str(record, _contacts_image.path, normal); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)"); + + ct_input_update_image(cinput_d); +} + +static void input_img_crop_result(ui_gadget_h ug, service_h service, void *data) +{ + char *normal = NULL; + char *full = NULL; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == ug || NULL == data, "ug or data is NULL"); + + if (service) { + service_get_extra_data(service, "crop_image_path", &normal); + p_retm_if(!normal, "return value is NULL.\n"); + + service_get_extra_data(service, "image_path", &full); + input_change_photo(cinput_d, normal, full); + free(normal); + } +} + +static void input_src_ug_destroy(ui_gadget_h ug, void *priv) +{ + ct_input_data *cinput_d = priv; + p_retm_if(NULL == ug, "ug is NULL"); + + if (cinput_d->src_ug) { + ug_destroy(cinput_d->src_ug); + cinput_d->src_ug = NULL; + } + + elm_object_tree_focus_allow_set(cinput_d->cdetail_d->navi, EINA_TRUE); +} + +static void input_crop_ug_destroy(ui_gadget_h ug, void *priv) +{ + PH_FN_CALL; + ct_input_data *cinput_d = priv; + + elm_object_tree_focus_allow_set(cinput_d->cdetail_d->navi, EINA_TRUE); + p_retm_if(NULL == ug, "ug is NULL"); + + if (cinput_d->crop_ug) { + ug_destroy(ug); + cinput_d->crop_ug = NULL; + } + if (cinput_d->src_ug) { + ug_destroy(cinput_d->src_ug); + cinput_d->src_ug = NULL; + } +} + +static void input_gallery_result(ui_gadget_h ug, service_h service, void *data) +{ + char *val = NULL; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == ug || NULL == data, "ug or data is NULL"); + + if (service) { + struct ug_cbs cbs = {0}; + + service_get_extra_data(service, "path", &val); + p_retm_if(!val, "return value is NULL.\n"); + + cbs.result_cb = input_img_crop_result; + cbs.destroy_cb = input_crop_ug_destroy; + cbs.priv = cinput_d; + cinput_d->crop_ug = phone_image_crop_ug(cinput_d->cdetail_d->ug, val, &cbs); + free(val); + } +} + +void ct_input_gallery(ct_input_data *cinput_d) +{ + struct ug_cbs cbs = {0}; + service_h service = NULL; + + elm_object_tree_focus_allow_set(cinput_d->cdetail_d->navi, EINA_FALSE); + + service_create(&service); + service_add_extra_data(service, "launch-type", "select-one"); + service_add_extra_data(service, "file-type", "image"); + + cbs.result_cb = input_gallery_result; + cbs.destroy_cb = input_src_ug_destroy; + cbs.layout_cb = ug_common_layout_cb; + cbs.priv = cinput_d; + + cinput_d->src_ug = ug_create(cinput_d->cdetail_d->ug, GALLERY_UG, UG_MODE_FULLVIEW, service, &cbs); + p_warn_if(NULL == cinput_d->src_ug, "ug_create() Failed"); + + service_destroy(service); + + if (cinput_d->cdetail_d->popup) { + evas_object_del(cinput_d->cdetail_d->popup); + cinput_d->cdetail_d->popup = NULL; + } +} + +static void input_camera_result(service_h service, service_h reply, service_result_e result, void* user_data) +{ + char *normal = NULL; + char *full = NULL; + ct_input_data *cinput_d = user_data; + + cinput_d->camera_service_launched = false; + + elm_object_tree_focus_allow_set(cinput_d->cdetail_d->navi, EINA_TRUE); + + service_get_extra_data(reply, "crop_image_path", &normal); + p_retm_if(!normal, "return value is NULL.\n"); + + service_get_extra_data(reply, "image_path", &full); + input_change_photo(cinput_d, normal, full); + + free(normal); + free(full); +} + +void ct_input_camera(ct_input_data *cinput_d) +{ + int ret; + service_h service; + + p_retm_if(NULL == cinput_d, "paramter(ct_input_data) is NULL"); + p_retm_if(NULL == cinput_d->cdetail_d, "cinput_d->cdetail_d is NULL.\n"); + p_ret_if(true == cinput_d->camera_service_launched); + + if (cinput_d->cdetail_d && cinput_d->cdetail_d->popup) + ct_detail_popup_hide_cb(cinput_d->cdetail_d, NULL, NULL); + + service = NULL; + ret = service_create(&service); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_create() Failed(%d)", ret); + + if(NULL == cinput_d->cdetail_d->win) { + ERR("cinput_d->cdetail_d->win is NULL.\n"); + ret = service_destroy(service); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + ret = service_set_window(service, elm_win_xwindow_get(cinput_d->cdetail_d->win)); + if (SERVICE_ERROR_NONE != ret) { + ERR("service_set_package() Failed(%d)", ret); + ret = service_destroy(service); + p_warn_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + ret = service_set_operation(service, SERVICE_OPERATION_CREATE_CONTENT); + if (SERVICE_ERROR_NONE != ret) { + ERR("service_set_operation() Failed(%d)", ret); + ret = service_destroy(service); + p_warn_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + ret = service_set_mime(service, "image/jpg"); + if (SERVICE_ERROR_NONE != ret) { + ERR("service_set_mime() Failed(%d)", ret); + ret = service_destroy(service); + p_warn_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + ret = service_add_extra_data(service, "CALLER", "contacts"); + if (SERVICE_ERROR_NONE != ret) { + ERR("service_add_extra_data() Failed(%d)", ret); + ret = service_destroy(service); + p_warn_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + ret = service_send_launch_request(service, input_camera_result, cinput_d); + if (SERVICE_ERROR_NONE != ret) { + ERR("service_send_launch_request() Failed(%d)", ret); + ret = service_destroy(service); + p_warn_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); + return; + } + + cinput_d->camera_service_launched = true; + + ret = service_destroy(service); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_destroy() Failed(%d)", ret); +} + +static void input_myfile_ringtone_result(ui_gadget_h ug, service_h service, void *data) +{ + char *val = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == ug || NULL == data, "ug or data is NULL"); + + if (service) { + service_get_extra_data(service, "result", &val); + p_retm_if(!val, "return value is NULL.\n"); + + err = contacts_record_set_str(cinput_d->contact, _contacts_contact.ringtone_path, val); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + + free(val); + + ct_input_update_ringtone(cinput_d->contact, cinput_d->ly_ringtone); + } +} + +static void input_vibration_result(ui_gadget_h ug, service_h service, void *data) +{ + char *val = NULL; + ct_input_data *cinput_d = data; + contacts_error_e err = CONTACTS_ERROR_NONE; + + p_retm_if(NULL == ug || NULL == data, "ug or data is NULL"); + + if (service) { + service_get_extra_data(service, "result", &val); + p_retm_if(!val, "return value is NULL"); + + p_retm_if(NULL == cinput_d->contact, "contact is NULL"); + err = contacts_record_set_str(cinput_d->contact, _contacts_contact.vibration, (const char *)val); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + + ct_input_update_vibration(cinput_d->contact, cinput_d->ly_vibration); + free(val); + } +} + +static inline ui_gadget_h input_myfile_ug(struct ug_cbs cbs, + service_h service, ct_input_data *cinput_d) +{ + ui_gadget_h ug; + + cbs.layout_cb = ug_common_layout_cb; + cbs.priv = cinput_d; + + ug = ug_create(cinput_d->cdetail_d->ug, MYFILES_UG, UG_MODE_FULLVIEW, service, &cbs); + p_warn_if(NULL == ug, "ug_create() Failed"); + + return ug; +} + +static inline ui_gadget_h input_vibration_ug(struct ug_cbs cbs, + service_h service, ct_input_data *cinput_d) +{ + ui_gadget_h ug; + + cbs.layout_cb = ug_common_layout_cb; + cbs.priv = cinput_d; + + ug = ug_create(cinput_d->cdetail_d->ug, VIBRATION_UG, UG_MODE_FULLVIEW, service, &cbs); + p_warn_if(NULL == ug, "ug_create() Failed"); + + return ug; +} + +void ct_input_myfile_vibration(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + struct ug_cbs cbs = {0}; + ct_input_data *cinput_d = data; + char *vibration_path = NULL; + + service_h service; + + service_create(&service); + service_add_extra_data(service, "caller", "org.tizen.phone"); + + err = contacts_record_get_str_p(cinput_d->contact, _contacts_contact.vibration, &vibration_path); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)",err); + + if (vibration_path) { + service_add_extra_data(service, "selected", vibration_path); + } + + cbs.result_cb = input_vibration_result; + cbs.destroy_cb = input_src_ug_destroy; + cinput_d->src_ug = input_vibration_ug(cbs, service, cinput_d); + p_warn_if(NULL == cinput_d->src_ug, "input_vibration_ug() Failed"); + + service_destroy(service); + + if (cinput_d->popup) { + evas_object_del(cinput_d->popup); + cinput_d->popup = NULL; + } +} + +void ct_input_myfile_ringtone(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + struct ug_cbs cbs = {0}; + ct_input_data *cinput_d = data; + const char *ringtone_path = NULL; + char *str = NULL; + char buf[PH_TEXT_MAX_LEN+1]; + + service_h service; + + service_create(&service); + + service_add_extra_data(service, "path", "/opt/share/settings/Ringtones"); + service_add_extra_data(service, "select_type", "SINGLE_FILE"); + service_add_extra_data(service, "file_type", "SOUND"); + + err = contacts_record_get_str_p(cinput_d->contact, _contacts_contact.ringtone_path, &str); + if(CONTACTS_ERROR_NONE == err) + ringtone_path = ct_detail_get_ringtone_display_name(str); + + if (ringtone_path && *ringtone_path) { + snprintf(buf, sizeof(buf), "/opt/share/settings/Ringtones/%s", ringtone_path); + service_add_extra_data(service, "marked_mode", buf); + } + + cbs.result_cb = input_myfile_ringtone_result; + cbs.destroy_cb = input_src_ug_destroy; + cinput_d->src_ug = input_myfile_ug(cbs, service, cinput_d); + + if (cinput_d->popup) { + evas_object_del(cinput_d->popup); + cinput_d->popup = NULL; + } + + service_destroy(service); +} + +#define ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+[.])*[a-z0-9!#$%&'*+/=?^_`{|}~-]+" +#define DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+[.])+[a-z0-9!#$%&'*+/=?^_`{|}~-]+" +#define EMAIL_RGEX ACCOUNT_RGEX"@"DOMAIN_RGEX + +int ct_input_valid_email(contacts_record_h record_contact) +{ + int len; + int index = 0; + int result = TRUE; + char *email = NULL; + regex_t compiled; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.email, index++, &record)) { + err = contacts_record_get_str_p(record, _contacts_email.email, &email); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_str_p() Failed(%d)", err); + continue; + } + if (email && strlen(email) >0) { + len = strlen(email) + 1; + regmatch_t str[len]; + + if (regcomp(&compiled, EMAIL_RGEX, REG_ICASE | REG_EXTENDED)) + result = FALSE; + if (regexec(&compiled, email, len, str, 0) == REG_NOMATCH) + result = FALSE; + + regfree(&compiled); + } + if (!result) + break; + } + return result; +} + +static int input_is_name_empty(contacts_record_h record_contact) +{ + contacts_record_h record = NULL; + char *name = NULL; + + record = ct_input_get_record_name(record_contact); + p_retvm_if(NULL == record, TRUE, "ct_input_get_record_name() return NULL"); + + contacts_record_get_str_p(record, _contacts_name.first, &name); + if (NULL == name || '\0' == *name) { + contacts_record_get_str_p(record, _contacts_name.last, &name); + if (NULL == name || '\0' == *name) { + return TRUE; + } + } + return FALSE; +} + +static int input_is_num_empty(contacts_record_h record_contact) +{ + int index = 0; + char *number; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.number, index++, &record)) { + err = contacts_record_get_str_p(record, _contacts_number.number, &number); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_str_p() Failed(%d)", err); + continue; + } + if (number && *number) + return FALSE; + } + return TRUE; +} + +static int input_is_email_empty(contacts_record_h record_contact) +{ + int index = 0; + char *email; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.email, index++, &record)) { + err = contacts_record_get_str_p(record, _contacts_email.email, &email); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_str_p() Failed(%d)", err); + continue; + } + if (email && *email) + return FALSE; + } + return TRUE; +} + +static void input_btn_popup(ct_detail_data *cdetail_d, const char *desc) +{ + Evas_Object *popup; + Evas_Object *btn; + + popup = elm_popup_add(cdetail_d->navi); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_text_set(popup, desc); + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_OK)); + elm_object_part_content_set(popup, "button1", btn); + elm_object_style_set(btn, "popup_button/default"); + evas_object_smart_callback_add(btn, "clicked", ct_detail_popup_hide_cb, cdetail_d); + + cdetail_d->popup = popup; + evas_object_show(popup); +} + +void ct_input_save_cb(void *data, Evas_Object *obj, void *event_info) +{ + int ret; + int ret_id = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_detail_data *cdetail_d; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == cinput_d, "cinput_d is NULL"); + + cdetail_d = cinput_d->cdetail_d; + + err = contacts_record_set_int(cinput_d->contact, _contacts_contact.address_book_id, cinput_d->base_ab); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + + if (TRUE != (ret = ct_input_valid_email(cinput_d->contact))) { + input_btn_popup(cdetail_d, T_(CT_GET_TEXT_ERR, CTTEXT_INVALID_EMAIL)); + return; + } + + if (input_is_name_empty(cinput_d->contact) + && input_is_num_empty(cinput_d->contact) + && input_is_email_empty(cinput_d->contact)) { + input_btn_popup(cdetail_d, T_(CT_GET_TEXT_ERR, CTTEXT_SAVE_FAIL)); + return; + } + + if (cinput_d->contact_id) { + err = contacts_db_update_record(cinput_d->contact); + if (CONTACTS_ERROR_NONE != err) { + ctui_create_contacts_error_popup(cdetail_d->navi, err); + return; + } + else { + cinput_d->saved = true; + } + } + else { + err = contacts_db_insert_record(cinput_d->contact, &ret_id); + if (CONTACTS_ERROR_NONE != err) { + ctui_create_contacts_error_popup(cdetail_d->navi, err); + return; + } + cinput_d->saved = true; + input_set_base_ab(cinput_d->base_ab_name); + if (NULL == cdetail_d->prev_view_data && cdetail_d->ug) + phone_ug_return_id(cdetail_d->ug, ret_id, 0, 0); + } + + /* evas_object_smart_callback_del() func will be deleted */ + evas_object_smart_callback_del(obj, "clicked", ct_input_save_cb); + + if (cdetail_d->prev_view_data && ((CT_UG_REQUEST_UPDATE_CONTACT <= cdetail_d->ug_request && + cdetail_d->ug_request <= CT_UG_REQUEST_SAVE_RINGTONE) || + (PH_UG_REQUEST_SET_WITH_NUM <= cdetail_d->ug_request && + cdetail_d->ug_request <= PH_UG_REQUEST_SET_WITH_RINGTONE))){ + ug_destroy_me(cdetail_d->ug); + } + else if (cdetail_d->ug && !cdetail_d->has_detail && NULL == cdetail_d->prev_view_data) { + ug_destroy_me(cdetail_d->ug); + } + else if (cdetail_d->vcard_path) + elm_exit(); + else + elm_naviframe_item_pop(cdetail_d->navi); +} + +void ct_input_custom_type_rename_cb(void *data, char *str) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + Evas_Object *btn_type; + ct_input_typed_data *typed_data = data; + p_retm_if(NULL == typed_data, "parameter(typed_data)"); + + if (0 == strcmp(typed_data->view_uri, _contacts_number._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_number.type, CONTACTS_NUMBER_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_number.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_email._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_email.type, CONTACTS_EMAIL_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_email.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_address._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_address.type, CONTACTS_ADDRESS_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_address.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_url._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_url.type, CONTACTS_URL_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_url.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_messenger._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_messenger.type, CONTACTS_MESSENGER_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_messenger.label, str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str() Failed(%d)", err); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_relationship._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_relationship.type, CONTACTS_RELATIONSHIP_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + 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); + } + else if (0 == strcmp(typed_data->view_uri, _contacts_event._uri)) { + err = contacts_record_set_int(typed_data->record, _contacts_event.type, CONTACTS_EVENT_TYPE_CUSTOM); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + err = contacts_record_set_str(typed_data->record, _contacts_event.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); +} + +int ct_input_get_number_type(int ct_num_type) +{ + int ret_type; + + switch (ct_num_type) { + case CTTEXT_TYPE_MOBILE: + ret_type = CONTACTS_NUMBER_TYPE_CELL; + break; + case CTTEXT_TYPE_HOME: + ret_type = CONTACTS_NUMBER_TYPE_VOICE | CONTACTS_NUMBER_TYPE_HOME; + break; + case CTTEXT_TYPE_HOME2: + ret_type = CONTACTS_NUMBER_TYPE_CELL | CONTACTS_NUMBER_TYPE_HOME; + break; + case CTTEXT_TYPE_WORK: + ret_type = CONTACTS_NUMBER_TYPE_VOICE | CONTACTS_NUMBER_TYPE_WORK; + break; + case CTTEXT_TYPE_WORK2: + ret_type = CONTACTS_NUMBER_TYPE_CELL | CONTACTS_NUMBER_TYPE_WORK; + break; + case CTTEXT_TYPE_FAX_HOME: + ret_type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME; + break; + case CTTEXT_TYPE_FAX_WORK: + ret_type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK; + break; + case CTTEXT_TYPE_ASSISTANT: + ret_type = CONTACTS_NUMBER_TYPE_ASSISTANT; + break; + case CTTEXT_TYPE_PAGER: + ret_type = CONTACTS_NUMBER_TYPE_PAGER; + break; + case CTTEXT_TYPE_CAR: + ret_type = CONTACTS_NUMBER_TYPE_CAR; + break; + case CTTEXT_TYPE_CUSTOM: + ret_type = CONTACTS_NUMBER_TYPE_CUSTOM; + break; + case CTTEXT_TYPE_OTHER: + default: + ret_type = CONTACTS_NUMBER_TYPE_OTHER; + break; + } + + return ret_type; +} + +void ct_input_entry_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + if (elm_object_focus_get(obj)) return; + evas_object_smart_callback_call(obj, "unfocused", NULL); +} + +Evas_Object* ct_input_add_editfield(Evas_Object *parent, const char* guide_txt, + Evas_Smart_Cb unfocused_cb, void *unfocused_cb_data) +{ + Evas_Object *editfield; + Evas_Object *entry; + + editfield = ctui_create_editfield(parent, NULL, guide_txt, false); + p_retvm_if(NULL == editfield, NULL, "ctui_create_editfield() return NULL"); + + entry = elm_object_part_content_get(editfield, "elm.swallow.content"); + evas_object_smart_callback_add(entry, "changed", ct_input_entry_changed_cb, editfield); + + if (unfocused_cb) + evas_object_smart_callback_add(entry, "unfocused", unfocused_cb, unfocused_cb_data); + + return editfield; +} + +int ct_input_next_number_type(contacts_record_h record_contact) +{ + int i; + int used[CTTEXT_TYPE_RADIO+1] = {0}; + int cts_type; + int type; + int index = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.number, index++, &record)) { + err = contacts_record_get_int(record, _contacts_number.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + type = phone_detail_log_get_phonenumber_type(cts_type); + used[type] = 1; + } + + for (i=CTTEXT_TYPE_MOBILE;i<CTTEXT_TYPE_OTHER;i++) { + if (0 == used[i]) + return ct_input_get_number_type(i); + } + return CTTEXT_TYPE_OTHER; +} + +int ct_input_next_email_type(contacts_record_h record_contact) +{ + int i; + int used = 0; + int cts_type; + int index = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.email, index++, &record)) { + err = contacts_record_get_int(record, _contacts_email.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + used |= cts_type; + } + for (i=1;(1<<i)<=CONTACTS_EMAIL_TYPE_WORK;i++) { + if (!(used & (1<<i))) + return 1<<i; + } + + return CONTACTS_EMAIL_TYPE_OTHER; +} + +int ct_input_next_event_type(contacts_record_h record_contact) +{ + int index = 0; + int cts_type; + bool used_birthday = false; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.event, index++, &record)) { + err = contacts_record_get_int(record, _contacts_event.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + if (CONTACTS_EVENT_TYPE_BIRTH == cts_type) { + used_birthday = true; + break; + } + } + + if (used_birthday) + return CONTACTS_EVENT_TYPE_ANNIVERSARY; + + return CONTACTS_EVENT_TYPE_BIRTH; +} + +int ct_input_next_address_type(contacts_record_h record_contact) +{ + int i; + int used = 0; + int cts_type; + int index = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.address, index++, &record)) { + err = contacts_record_get_int(record, _contacts_address.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + used |= cts_type; + } + for (i=1;(1<<i)<=CONTACTS_ADDRESS_TYPE_WORK;i++) { + if (!(used & (1<<i))) + return 1<<i; + } + + return CONTACTS_ADDRESS_TYPE_OTHER; +} + +int ct_input_next_web_type(contacts_record_h record_contact) +{ + int i; + int index = 0; + int cts_type; + int used[CONTACTS_URL_TYPE_WORK+1] = {0}; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.url, index++, &record)) { + err = contacts_record_get_int(record, _contacts_url.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + used[cts_type] = 1; + } + + for (i=CONTACTS_URL_TYPE_HOME;i<=CONTACTS_URL_TYPE_WORK;i++) { + if (0 == used[i]) + return i; + } + return CONTACTS_URL_TYPE_OTHER; +} + +int ct_input_next_relationship_type(contacts_record_h record_contact) +{ + int i; + int index = 0; + int cts_type; + int used[CONTACTS_RELATIONSHIP_TYPE_SPOUSE+1] = {0}; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.relationship, index++, &record)) { + err = contacts_record_get_int(record, _contacts_relationship.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + used[cts_type] = 1; + } + + for (i=CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;i<=CONTACTS_RELATIONSHIP_TYPE_SPOUSE;i++) { + if (!used[i]) + return i; + } + return CONTACTS_RELATIONSHIP_TYPE_CUSTOM; +} + +int ct_input_next_messenger_type(contacts_record_h record_contact) +{ + int i; + int index = 0; + int cts_type; + int used[CONTACTS_MESSENGER_TYPE_IRC+1] = {0}; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(record_contact, _contacts_contact.messenger, index++, &record)) { + err = contacts_record_get_int(record, _contacts_messenger.type, &cts_type); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + continue; + } + used[cts_type] = 1; + } + + for (i=CONTACTS_MESSENGER_TYPE_GOOGLE;i<=CONTACTS_MESSENGER_TYPE_IRC;i++) { + if (0 == used[i]) + return i; + } + + return CONTACTS_MESSENGER_TYPE_OTHER; +} + + +Evas_Object* ct_input_create_dg_layout(Evas_Object *parent, const char *theme) +{ + Evas_Object *layout = elm_layout_add(parent); + p_retvm_if(NULL == layout, NULL, "elm_layout_add() return NULL"); + + elm_layout_theme_set(layout, "layout", "dialogue", theme); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0.0); + + evas_object_show(layout); + return layout; +} + +void ct_input_typed_layout_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + ct_input_typed_data *typed_data = data; + p_retm_if(NULL == typed_data, "parameter(typed_data) is NULL"); + free(typed_data); +} + +void ct_input_update_ringtone(contacts_record_h record_contact, Evas_Object *ly_content) +{ + const char *display; + char *temp; + contacts_error_e err = CONTACTS_ERROR_NONE; + + err = contacts_record_get_str_p(record_contact, _contacts_contact.ringtone_path, &temp); + p_retm_if(CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err, "contacts_record_get_str_p() Failed(%d)", err); + + display = ct_detail_get_ringtone_display_name((const char *)temp); + + elm_object_part_text_set(ly_content, "elm.text.2", display); +} + +void ct_input_update_vibration(contacts_record_h record_contact, Evas_Object *ly_content) +{ + const char *display; + char *temp; + contacts_error_e err = CONTACTS_ERROR_NONE; + + err = contacts_record_get_str_p(record_contact, _contacts_contact.vibration, &temp); + p_retm_if(CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err, "contacts_record_get_str_p() Failed(%d)", err); + + display = ct_detail_get_vibration_display_name((const char *)temp); + + elm_object_part_text_set(ly_content, "elm.text.2", display); +} + +unsigned int ct_input_box_idx_get(Evas_Object *box, Evas_Object *obj) +{ + int count = 0; + Eina_List *list, *cursor; + Evas_Object *data; + list = elm_box_children_get(box); + + EINA_LIST_FOREACH(list, cursor, data) { + if (data == obj) + break; + count++; + } + eina_list_free(list); + return count; +} + +void ct_input_update_group(void *data) +{ + Evas_Object *ly_content; + char display[PH_TEXT_MAX_LEN+1]; + ct_input_data *cinput_d = data; + + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + p_retm_if(NULL == cinput_d->contact || NULL == cinput_d->ly_group, "parameter is NULL"); + + ct_detail_get_group_names(cinput_d->contact, display, sizeof(display)); + ly_content = cinput_d->ly_group; + elm_object_part_text_set(ly_content, "elm.text.2", display); +} + +void ct_input_save_button_update(ct_input_data *cinput_d) +{ + PH_FN_CALL; + Evas_Object *save_btn; + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + + save_btn = elm_object_item_part_content_get(cinput_d->navi_item, "title_left_btn"); + if (save_btn) + elm_object_disabled_set(save_btn, cinput_d->save_disable); + + if (cinput_d->save_button) + elm_object_disabled_set(cinput_d->save_button, cinput_d->save_disable); +} + +static inline Eina_Bool input_is_editfield_empty(Evas_Object *editfield) +{ + const char *val; + Evas_Object *entry; + + p_retvm_if(NULL == editfield, EINA_TRUE, "parameter(editfield) is NULL"); + + entry = elm_object_part_content_get(editfield, "elm.swallow.content"); + p_retvm_if(NULL == entry, EINA_TRUE, "elm_object_part_content_get() return NULL"); + + val = elm_entry_entry_get(entry); + if (val && *val) + return EINA_FALSE; + + return EINA_TRUE; +} + +static bool __input_is_field_filled(Evas_Object *box, Eina_List *list, Evas_Object *first, Evas_Object *last, const char *part) +{ + int idx = 0;; + Evas_Object *ly_content = NULL; + Evas_Object *edit_field = NULL; + + p_retvm_if(NULL == box, false, "parameter(box) is NULL"); + p_retvm_if(NULL == list, false, "parameter(list) is NULL"); + p_retvm_if(NULL == first, false, "parameter(first) is NULL"); + p_retvm_if(NULL == last, false, "parameter(last) is NULL"); + + ly_content = first; + idx = ct_input_box_idx_get(box, ly_content); + while (ly_content) { + edit_field = elm_object_part_content_get(ly_content, part); + if (EINA_FALSE == input_is_editfield_empty(edit_field)) + return true; + + if (ly_content == last) + break; + ly_content = eina_list_nth(list, ++idx); + } + return false; + +} + +static void __input_mandatory_field_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_FN_CALL; + bool exist_valid_field = false; + Eina_List *list = NULL; + Evas_Object *edit_field = NULL; + ct_input_data *cinput_d = data; + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_middle_name, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_last_name, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_suffix, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_nickname, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_job_title, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_department, "elm.icon"); + if (EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + edit_field = elm_object_part_content_get(cinput_d->ly_basic_info_company, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + list = elm_box_children_get(cinput_d->box); + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_number_first, cinput_d->ly_number_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = number"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_email_first, cinput_d->ly_email_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = email"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_addr_first, cinput_d->ly_addr_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = address"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_messenger_first, cinput_d->ly_messenger_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = messenger"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_url_first, cinput_d->ly_url_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = url"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + exist_valid_field = __input_is_field_filled(cinput_d->box, list, cinput_d->ly_relationship_first, cinput_d->ly_relationship_last, "elm.icon"); + if (exist_valid_field) { + PH_DBG("valid field = url"); + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + eina_list_free(list); + return; + } + + eina_list_free(list); + + edit_field = elm_object_part_content_get(cinput_d->ly_note, "elm.icon"); + if (edit_field && EINA_FALSE == input_is_editfield_empty(edit_field)) { + cinput_d->save_disable = EINA_FALSE; + ct_input_save_button_update(cinput_d); + return; + } + + PH_DBG("cinput_d->save_disable=%d",cinput_d->save_disable); + if (EINA_TRUE == cinput_d->save_disable) + return; + + cinput_d->save_disable = EINA_TRUE; + ct_input_save_button_update(cinput_d); +} + +void ct_input_add_name_field(Evas_Object *editfield, ct_input_data *cinput_d) +{ + Evas_Object *entry; + + p_retm_if(NULL == cinput_d, "parameter(cinput_d) is NULL"); + p_retm_if(NULL == editfield, "parameter(editfield) is NULL"); + + entry = elm_object_part_content_get(editfield, "elm.swallow.content"); + p_retm_if(NULL == cinput_d, "elm_object_part_content_get() return NULL"); + + evas_object_smart_callback_add(entry, "changed", __input_mandatory_field_changed_cb, cinput_d); + evas_object_smart_callback_add(entry, "preedit,changed", __input_mandatory_field_changed_cb, cinput_d); +} + +int ct_input_get_full_address(contacts_record_h record_postal, char *buf, int buf_len) +{ + char *code = NULL; + char *region = NULL; + char *locality = NULL; + char *street = NULL; + char *extended = NULL; + char *country = NULL; + char *pobox = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + + err = contacts_record_get_str_p(record_postal, _contacts_address.postal_code, &code); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.extended, &extended); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.postbox, &pobox); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.street, &street); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.locality, &locality); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.region, ®ion); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_postal, _contacts_address.country, &country); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + snprintf(buf, buf_len, "%s%s%s%s%s%s%s%s%s%s%s%s%s", SAFE_STR(code), STR_BLANK(code, extended), STR_BLANK(extended, pobox), + STR_BLANK(pobox, street), STR_BLANK(street, locality), STR_BLANK(locality, region), STR_BLANK(region, country)); + + return 0; +} + +static contacts_record_h input_get_record(contacts_record_h record_contact, int property_id) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + p_retvm_if(NULL == record_contact, NULL, "parameter(record_contact) is NULL"); + + err = contacts_record_get_child_record_at_p(record_contact, property_id, 0, &record); + p_retvm_if (CONTACTS_ERROR_NONE != err, NULL, "contacts_record_get_child_record_at_p() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record(contacts_record_h contact, int property_id, const char *view_uri) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + err = contacts_record_create(view_uri, &record); + p_retvm_if(CONTACTS_ERROR_NONE != err, NULL, "contacts_record_create() Failed(%d)", err); + + err = contacts_record_add_child_record(contact, property_id, record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_add_child_record() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_relationship(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_relationship_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.relationship, _contacts_relationship._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_relationship.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_address(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_address_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.address, _contacts_address._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_address.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_web(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_web_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.url, _contacts_url._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_url.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_number(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_number_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.number, _contacts_number._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_number.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_email(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_email_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.email, _contacts_email._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_email.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + + +contacts_record_h ct_input_new_record_messenger(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_messenger_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.messenger, _contacts_messenger._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_messenger.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_new_record_event(contacts_record_h contact) +{ + int type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + type = ct_input_next_event_type(contact); + PH_DBG("type=%d",type); + + record = ct_input_new_record(contact, _contacts_contact.event, _contacts_event._uri); + p_retvm_if(NULL == record, NULL, "ct_input_new_record() return NULL"); + + err = contacts_record_set_int(record, _contacts_event.type, type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_int() Failed(%d)", err); + + return record; +} + +contacts_record_h ct_input_get_record_nickname(contacts_record_h record_contact) +{ + PH_FN_CALL; + contacts_record_h record = NULL; + record = input_get_record(record_contact, _contacts_contact.nickname); + if (NULL == record) + record = ct_input_new_record(record_contact, _contacts_contact.nickname, _contacts_nickname._uri); + return record; +} + +contacts_record_h ct_input_get_record_name(contacts_record_h record_contact) +{ + PH_FN_CALL; + contacts_record_h record = NULL; + record = input_get_record(record_contact, _contacts_contact.name); + if (NULL == record) { + record = ct_input_new_record(record_contact, _contacts_contact.name, _contacts_name._uri); + PH_DBG("record=%p", record); + } + + return record; +} + +contacts_record_h ct_input_get_record_company(contacts_record_h record_contact) +{ + PH_FN_CALL; + contacts_record_h record = NULL; + record = input_get_record(record_contact, _contacts_contact.company); + if (NULL == record) + record = ct_input_new_record(record_contact, _contacts_contact.company, _contacts_company._uri); + return record; +} + +contacts_record_h ct_input_get_record_note(contacts_record_h record_contact) +{ + PH_FN_CALL; + contacts_record_h record = NULL; + record = input_get_record(record_contact, _contacts_contact.note); + if (NULL == record) + record = ct_input_new_record(record_contact, _contacts_contact.note, _contacts_note._uri); + return record; +} + +static void input_remove_empty_field(contacts_record_h record_contact, int property_id, int property_id_str) +{ + int i; + unsigned int count; + char *str; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + p_retm_if(NULL == record_contact, "parameter(record_contact) is NULL"); + + err = contacts_record_get_child_record_count(record_contact, property_id, &count); + p_retm_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_child_record_count() Failed(%d)", err); + + for (i=count-1;0<=i;i--) { + err = contacts_record_get_child_record_at_p(record_contact, property_id, i, &record); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_child_record_at_p() Failed(%d)", err); + continue; + } + + err = contacts_record_get_str(record, property_id_str, &str); + if (CONTACTS_ERROR_NONE != err || NULL == str || '\0' == *str) { + err = contacts_record_remove_child_record(record_contact, property_id, record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_remove_child_record() Failed(%d)", err); + + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + } + free(str); + } +} + +static void input_remove_empty_field_address(contacts_record_h record_contact) +{ + int i; + unsigned int count; + char str[PH_TEXT_MAX_LEN]; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + p_retm_if(NULL == record_contact, "parameter(record_contact) is NULL"); + + err = contacts_record_get_child_record_count(record_contact, _contacts_contact.address, &count); + p_retm_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_child_record_count() Failed(%d)", err); + + for (i=count-1;0<=i;i--) { + err = contacts_record_get_child_record_at_p(record_contact, _contacts_contact.address, i, &record); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_child_record_at_p() Failed(%d)", err); + continue; + } + str[0] = '\0'; + ct_detail_get_full_addr(record, str, sizeof(str)); + + if ('\0' == *str) { + err = contacts_record_remove_child_record(record_contact, _contacts_contact.address, record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_remove_child_record() Failed(%d)", err); + + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + } + } + +} + +void ct_input_remove_empty_fields(contacts_record_h record_contact) +{ + PH_FN_CALL; + p_retm_if(NULL == record_contact, "parameter(record_contact) is NULL"); + input_remove_empty_field(record_contact, _contacts_contact.number, _contacts_number.number); + input_remove_empty_field(record_contact, _contacts_contact.email, _contacts_email.email); + input_remove_empty_field_address(record_contact); + input_remove_empty_field(record_contact, _contacts_contact.url, _contacts_url.url); + input_remove_empty_field(record_contact, _contacts_contact.messenger, _contacts_messenger.im_id); + input_remove_empty_field(record_contact, _contacts_contact.note, _contacts_note.note); + input_remove_empty_field(record_contact, _contacts_contact.relationship, _contacts_relationship.name); +} + + |