diff options
Diffstat (limited to 'lib/details/ct-detail-view.c')
-rwxr-xr-x | lib/details/ct-detail-view.c | 2617 |
1 files changed, 2617 insertions, 0 deletions
diff --git a/lib/details/ct-detail-view.c b/lib/details/ct-detail-view.c new file mode 100755 index 0000000..507b8dc --- /dev/null +++ b/lib/details/ct-detail-view.c @@ -0,0 +1,2617 @@ +/* +* 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 <ui-gadget-module.h> + +#include <errno.h> +#include <string.h> +#include <vconf.h> +#include <vconf-keys.h> +#include <app.h> +#include <msg.h> +#include <account.h> + +#include "phone.h" +#include "ct-detail.h" +#include "ct-detail-utils.h" +#include "ct-detail-view.h" +#include "ct-detail-history.h" +#include "ct-detail-activity.h" +#include "ct-list.h" +#include "ct-input-view.h" +#include "ct-group.h" +#include "ct-group-assign-view.h" + +#define _CT_LINK + +enum DETAIL_ITC_TYPE { + DETAIL_ITC_NOTE = 0, + DETAIL_ITC_NUM_UTIL_BTN, + DETAIL_ITC_UTIL_BTN, + DETAIL_ITC_ADDRBOOK, + DETAIL_ITC_NUMBER, + DETAIL_ITC_EMAIL, + DETAIL_ITC_URL, + DETAIL_ITC_MESSENGER, + DETAIL_ITC_EVENT, + DETAIL_ITC_RINGTONE, + DETAIL_ITC_VIBRATION, + DETAIL_ITC_GROUP, + DETAIL_ITC_RELATIONSHIP, + DETAIL_ITC_NUMBER_DEFAULT, + DETAIL_ITC_EMAIL_DEFAULT, + DETAIL_ITC_ADDRESS, + DETAIL_ITC_LINK_UNLINK, + DETAIL_ITC_UNLINK_POPUP, + DETAIL_ITC_EDIT_POPUP, + DETAIL_ITC_LINK_LIST, + DETAIL_ITC_LINK_LIST_SUB, + DETAIL_ITC_FIELD_TITLE, + DETAIL_ITC_FIELD, + DETAIL_ITC_TITLE, + DETAIL_ITC_UTIL_1BTN, + DETAIL_ITC_BASEINFO_1TEXT_1ICON, + DETAIL_ITC_BASEINFO_1TEXT_2ICON, + DETAIL_ITC_BASEINFO_2TEXT_1ICON, + DETAIL_ITC_BASEINFO_2TEXT_2ICON, + DETAIL_ITC_BASEINFO_3TEXT_1ICON, + DETAIL_ITC_BASEINFO_3TEXT_2ICON, + DETAIL_ITC_DEFAULT_NUMBER_SET_POPUP, + DETAIL_ITC_DEFAULT_EMAIL_SET_POPUP, + DETAIL_ITC_DEFAULT_NAME_POPUP, + DETAIL_ITC_MAX, +}; + +static Elm_Genlist_Item_Class detail_itcs[] = { + {.item_style="multiline/dialogue/2text"}, /* NOTE */ + {.item_style="detail.3icon"}, /* NUMBER UTIL BUTTON */ + {.item_style="dialogue/bg/2icon"}, /* UTIL BUTTON */ + {.item_style="detail.title"}, /* ADDRESSBOOK */ + {.item_style="detail.field.2text"}, /* NUMBER */ + {.item_style="detail.field.2text"}, /* EMAIL */ + {.item_style="detail.field.2text"}, /* URL */ + {.item_style="dialogue/2text.2"}, /*MESSENGER */ + {.item_style="2text.3"}, /*BIRTH*/ + {.item_style="dialogue/2text.3"}, /* RINGTONE */ + {.item_style="dialogue/2text.3"}, /* VIBRATION */ + {.item_style="dialogue/2text.3"}, /* GROUP */ + {.item_style="2text.3"}, /* RELATIONSHIP */ + {.item_style="baseinfo.1text"}, /* DEFAULT NUMBER */ + {.item_style="detail.field.2text"}, /* DEFAULT EMAIL */ + {.item_style="detail.field.2text"}, /* ADDRESS */ + {.item_style="dialogue/bg/2icon"}, /* LINK, UNLINK */ + {.item_style="1text.1icon.2"}, /* UNLINK POPUP */ + {.item_style="1text.1icon.2"}, /* EDIT POPUP */ + {.item_style="dialogue/1text/expandable"}, /* LINK LIST */ + {.item_style="dialogue/1text.1icon.2/expandable2"}, /* LINK LIST SUB */ + {.item_style="detail.fieldtitle.1text"}, /* FIELD TITLE */ + {.item_style="detail.field.2text"}, /* FIELD */ + {.item_style="dialogue/title"}, /* TITLE */ + {.item_style="dialogue/bg/1icon"}, /* UTIL 1 BUTTON */ + {.item_style="baseinfo.1text.1icon"}, /* BASEINFO 1TEXT 1ICON */ + {.item_style="baseinfo.1text.2icon"}, /* BASEINFO 1TEXT 2ICON */ + {.item_style="baseinfo.2text.1icon"}, /* BASEINFO 2TEXT 1ICON */ + {.item_style="baseinfo.2text.2icon"}, /* BASEINFO 2TEXT 2ICON */ + {.item_style="baseinfo.3text.1icon"}, /* BASEINFO 3TEXT 1ICON */ + {.item_style="baseinfo.3text.2icon"}, /* BASEINFO 3TEXT 2ICON */ + {.item_style="dialogue/2text.6"}, /* DEFAULT NUMBER SET POPUP*/ + {.item_style="dialogue/2text.6"}, /* DEFAULT EMAIL SET POPUP*/ + {.item_style="1text"}, /* DEFAULT NAME */ +}; + +static Elm_Genlist_Item_Class detail_ringtone_itc, detail_vibration_itc; + + +static void detail_fill_number_list(Evas_Object *genlist, Eina_List *list, Evas_Smart_Cb func, int default_num_id); +static void detail_fill_email_list(Evas_Object *genlist, Eina_List *list, Evas_Smart_Cb func, int default_num_id); + +static char* detail_gl_2text_multiline_label_get(void *data, Evas_Object *obj, const char *part) +{ + char *note; + contacts_record_h record = data; + + p_retv_if(NULL == record, NULL); + + if (0 == strcmp(part, "elm.text.1")) { + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_NOTE)); + } + else if (0 == strcmp(part, "elm.text.2")) { + contacts_record_get_str_p(record, _contacts_note.note, ¬e); + if (note && *note) + return elm_entry_utf8_to_markup(note); + } + return NULL; +} + +static char* detail_gl_ringtone_label_get(void *data, Evas_Object *obj, const char *part) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + char *str; + ct_detail_data *cdetail_d = data; + contacts_record_h record_person = cdetail_d->person; + p_retv_if(NULL == record_person, NULL); + + if (0 == strcmp(part, "elm.text.1")) + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_RINGTONE)); + else if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_str_p(record_person, _contacts_person.ringtone_path, &str); + p_retvm_if(CONTACTS_ERROR_NONE != err, FALSE, "contacts_record_get_str_p() Failed(%d)", err); + + if (str && *str && 0 == access(str, F_OK)) + return SAFE_STRDUP(ct_detail_get_ringtone_display_name(str)); + else + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_DEFAULT)); + } + return NULL; +} + +static void detail_ringtone_reset_cb(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_detail_data *cdetail_d = data; + + p_retm_if(NULL == cdetail_d, "parameter(cdetail_d) is NULL"); + p_retm_if(NULL == cdetail_d->person, "parameter(person) is NULL"); + + if (cdetail_d->popup){ + evas_object_del(cdetail_d->popup); + cdetail_d->popup = NULL; + } + + err = contacts_record_set_str(cdetail_d->person, _contacts_person.ringtone_path, NULL); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str(ringtone_path) Failed(%d)", err); + + elm_genlist_item_update(cdetail_d->ringtone_item); +} + +static char *detail_popup_text_get(void *data, Evas_Object *obj, const char *part) +{ + if (0 == strcmp(part, "elm.text")) + return strdup(data); + return NULL; +} + +static void detail_ringtone_gl_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + Evas_Object *popup; + Evas_Object *genlist; + Evas_Object *btn; + Evas_Object *box; + char *temp; + ct_detail_data *cdetail_d = data; + elm_genlist_item_selected_set(event_info, EINA_FALSE); + popup = elm_popup_add(cdetail_d->navi); + elm_object_style_set(popup, "min_menustyle"); + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASIC, CTTEXT_RINGTONE)); + evas_object_smart_callback_add(popup, "block,clicked", ctui_popup_hide_cb, NULL); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_CANCEL)); + elm_object_part_content_set(popup, "button1", btn); + evas_object_smart_callback_add(btn, "clicked", ctui_popup_hide_cb, popup); + + detail_ringtone_itc.item_style = "1text"; + detail_ringtone_itc.func.text_get = detail_popup_text_get; + detail_ringtone_itc.func.content_get = NULL; + detail_ringtone_itc.func.state_get = NULL; + detail_ringtone_itc.func.del = NULL; + + box = elm_box_add(popup); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + genlist = elm_genlist_add(popup); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_genlist_item_append(genlist, &detail_ringtone_itc, S_(CT_SYS_SK_SET), NULL, ELM_GENLIST_ITEM_NONE, ct_detail_myfile_ringtone, data); + + err = contacts_record_get_str_p(cdetail_d->person, _contacts_person.ringtone_path, &temp); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_contact_record_get_str_p() Failed(%d)", err); + + if (temp && *temp) + elm_genlist_item_append(genlist, &detail_ringtone_itc, S_(CT_SYS_SK_RESET), NULL, ELM_GENLIST_ITEM_NONE, detail_ringtone_reset_cb, data); + + elm_box_pack_end(box, genlist); + evas_object_show(genlist); + evas_object_size_hint_min_set(box, 600, 200); + elm_object_content_set(popup, box); + evas_object_show(popup); + cdetail_d->popup = popup; +} + +static char* detail_gl_vibration_label_get(void *data, Evas_Object *obj, const char *part) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + char *str; + ct_detail_data *cdetail_d = data; + contacts_record_h record_person = cdetail_d->person; + p_retv_if(NULL == record_person, NULL); + + if (0 == strcmp(part, "elm.text.1")) + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_VIBRATION_PATTERN)); + else if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_str_p(record_person, _contacts_person.vibration, &str); + p_retvm_if(CONTACTS_ERROR_NONE != err, FALSE, "contacts_record_get_str_p() Failed(%d)", err); + + if (str && *str && 0 == access(str, F_OK)) + return SAFE_STRDUP(ct_detail_get_vibration_display_name(str)); + else + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_DEFAULT)); + } + return NULL; +} +static void detail_vibration_reset_cb(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_detail_data *cdetail_d = data; + + p_retm_if(NULL == cdetail_d, "parameter(cdetail_d) is NULL"); + p_retm_if(NULL == cdetail_d->person, "parameter(person) is NULL"); + + if (cdetail_d->popup) { + evas_object_del(cdetail_d->popup); + cdetail_d->popup = NULL; + } + + err = contacts_record_set_str(cdetail_d->person, _contacts_person.vibration, NULL); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_set_str(vibration) Failed(%d)", err); + + elm_genlist_item_update(cdetail_d->vibration_item); +} + +static void detail_vibration_gl_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + Evas_Object *popup; + Evas_Object *genlist; + Evas_Object *btn; + Evas_Object *box; + char *temp; + ct_detail_data *cdetail_d = data; + elm_genlist_item_selected_set(event_info, EINA_FALSE); + popup = elm_popup_add(cdetail_d->navi); + elm_object_style_set(popup, "min_menustyle"); + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASIC, CTTEXT_VIBRATION_PATTERN)); + evas_object_smart_callback_add(popup, "block,clicked", ctui_popup_hide_cb, NULL); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_CANCEL)); + elm_object_part_content_set(popup, "button1", btn); + evas_object_smart_callback_add(btn, "clicked", ctui_popup_hide_cb, popup); + + detail_vibration_itc.item_style = "1text"; + detail_vibration_itc.func.text_get = detail_popup_text_get; + detail_vibration_itc.func.content_get = NULL; + detail_vibration_itc.func.state_get = NULL; + detail_vibration_itc.func.del = NULL; + + box = elm_box_add(popup); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + genlist = elm_genlist_add(popup); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_genlist_item_append(genlist, &detail_vibration_itc, S_(CT_SYS_SK_SET), NULL, ELM_GENLIST_ITEM_NONE, ct_detail_myfile_vibration, data); + + err = contacts_record_get_str_p(cdetail_d->person, _contacts_person.vibration, &temp); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_contact_record_get_str_p() Failed(%d)", err); + + if (temp && *temp) + elm_genlist_item_append(genlist, &detail_vibration_itc, S_(CT_SYS_SK_RESET), NULL, ELM_GENLIST_ITEM_NONE, detail_vibration_reset_cb, data); + + elm_box_pack_end(box, genlist); + evas_object_show(genlist); + evas_object_size_hint_min_set(box, 600, 200); + elm_object_content_set(popup, box); + evas_object_show(popup); + cdetail_d->popup = popup; +} + +static void detail_update_group(void *data) +{ + PH_FN_CALL; + ct_detail_data *cdetail_d = data; + p_retm_if(NULL == cdetail_d, "parameter(cdetail_d) is NULL"); + cdetail_d->updated = true; + elm_genlist_item_update(cdetail_d->group_item); +} + +typedef struct { + int contact_id; + int addressbook_id; + Eina_Bool checked; + Elm_Object_Item *item; + void *data; +} ct_detail_person_data; + +static void detail_group_gl_sel(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + elm_genlist_item_selected_set(event_info, EINA_FALSE); + ct_person_grp_assign_create_view(cdetail_d->navi, cdetail_d->person_id, detail_update_group, cdetail_d); +} + +static char* detail_gl_group_label_get(void *data, Evas_Object *obj, const char *part) +{ + char display[PH_TEXT_MAX_LEN+1]; + ct_detail_data *cdetail_d = data; + + if (0 == strcmp(part, "elm.text.1")) { + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_GROUP)); + } + else if (0 == strcmp(part, "elm.text.2")) { + display[0] = '\0'; + ct_detail_person_get_group_names(cdetail_d->list_contacts, display, sizeof(display)); + return strdup(display); + } + return NULL; + +} + +static char* detail_gl_relationship_label_get(void *data, Evas_Object *obj, const char *part) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + if (0 == strcmp(part, "elm.text.1")) { + int type; + char *str_type = NULL; + char *str_name = NULL; + char buf[PH_TEXT_MAX_LEN+1]; + + err = contacts_record_get_int(record, _contacts_relationship.type, &type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if (CONTACTS_RELATIONSHIP_TYPE_CUSTOM == type) { + err = contacts_record_get_str_p(record, _contacts_relationship.label, &str_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + } + if (NULL == str_type || '\0' == str_type[0]) + str_type = (char *)T_(CT_GET_TEXT_RELATIONSHIP_TYPE, type); + + err = contacts_record_get_str_p(record, _contacts_relationship.name, &str_name); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (str_name && *str_name) + snprintf(buf, sizeof(buf), "%s %s", str_type, str_name); + else + snprintf(buf, sizeof(buf), "%s", str_type); + return strdup(buf); + } + else if (0 == strcmp(part, "elm.text.2")) { + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_RELATIONSHIP)); + } + return NULL; +} + +static char *detail_gl_address_label_get(void *data, Evas_Object *obj, const char *part) +{ + int val_type; + char *ret_str; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + p_retv_if(NULL == data, NULL); + + if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_address.type, &val_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if(CONTACTS_ADDRESS_TYPE_CUSTOM == val_type){ + err = contacts_record_get_str_p(record, _contacts_address.label, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (NULL == ret_str || '\0' == ret_str[0]) + return strdup(T_(CT_GET_TEXT_POSTAL_TYPE, CONTACTS_ADDRESS_TYPE_OTHER)); + else + return strdup(ret_str); + } + else + return strdup(T_(CT_GET_TEXT_POSTAL_TYPE, ct_detail_get_address_type_index(val_type))); + } + else if (0 == strcmp(part, "elm.text.1")) { + char buf[PH_TEXT_MAX_LEN] = {0,}; + ct_detail_get_full_addr(record, buf, PH_TEXT_MAX_LEN); + return elm_entry_utf8_to_markup(buf); + } + return NULL; +} + +static char* detail_gl_messenger_label_get(void *data, Evas_Object *obj, const char *part) +{ + int val_type; + char *ret_str = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + p_retv_if(NULL == data, NULL); + + ret_str = NULL; + if (0 == strcmp(part, "elm.text.1")) { + err = contacts_record_get_str_p(record, _contacts_messenger.im_id, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + return SAFE_STRDUP(ret_str); + } + else if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_messenger.type, &val_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if(CONTACTS_MESSENGER_TYPE_CUSTOM == val_type){ + err = contacts_record_get_str_p(record, _contacts_messenger.label, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + else { + return strdup(T_(CT_GET_TEXT_IM_TYPE, val_type)); + } + } + return NULL; +} + + +static char* detail_gl_event_label_get(void *data, Evas_Object *obj, const char *part) +{ + int val_type; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + ct_detail_data *cdetail_d = evas_object_data_get(obj, "cdetail_d"); + + p_retv_if(NULL == data, NULL); + + if (0 == strcmp(part, "elm.text.1")) { + int date, day, mon, year; + + err = contacts_record_get_int(record, _contacts_event.date, &date); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + day = date%100; + mon = (date%10000)/100; + year = date/10000; + + p_retvm_if(mon < 1 || 12 < mon || day < 1 || 31 < day, NULL, "Invalid date(mon=%d,day=%d)",mon,day); + return ct_detail_get_datetime_str(cdetail_d->formatter, year, mon, day); + } + else if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_event.type, &val_type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + return strdup(T_(CT_GET_TEXT_EVENT_TYPE, val_type)); + } + return NULL; +} + + +void __detail_update_number_list(ct_detail_data * cdetail_d) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + int list_count = 0; + int number_id = 0; + int i; + Eina_List *cursor; + const Elm_Genlist_Item_Class *itc; + Elm_Object_Item *item = elm_genlist_first_item_get(cdetail_d->genlist); + Elm_Object_Item *item2 = NULL; + contacts_record_h record_number = NULL; + + while(item) { + item2 = elm_genlist_item_next_get(item); + itc = elm_genlist_item_item_class_get(item); + if(itc == &detail_itcs[DETAIL_ITC_NUMBER_DEFAULT] || itc == &detail_itcs[DETAIL_ITC_NUMBER]) { + break; + } + item = item2; + } + + Evas_Smart_Cb num_func = ct_detail_gl_number_sel; + + if (cdetail_d->list_number) + ctui_free_record_list(cdetail_d->list_number); + + cdetail_d->list_number = ctui_person_get_number_list(cdetail_d->list_contacts); + err = phone_cts_get_default_number(cdetail_d->person_id, &record_number); + if (CONTACTS_ERROR_NONE != err) { + ERR("phone_cts_get_default_number() Failed(%d)", err); + } + int default_num_id = 0; + err = contacts_record_get_int(record_number, _contacts_number.id, &default_num_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + if(default_num_id > 0) { + elm_object_item_del(cdetail_d->number_util_item); + elm_genlist_item_insert_before(cdetail_d->genlist, &detail_itcs[DETAIL_ITC_NUMBER_DEFAULT], record_number, NULL, item, + ELM_GENLIST_ITEM_NONE, num_func, record_number); + cdetail_d->number_util_item = elm_genlist_item_insert_before(cdetail_d->genlist, &detail_itcs[DETAIL_ITC_NUM_UTIL_BTN], record_number, NULL, item, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + } + + list_count = eina_list_count(cdetail_d->list_number); + if (list_count > 1) { + EINA_LIST_FOREACH(cdetail_d->list_number, cursor, record_number) { + err = contacts_record_get_int(record_number, _contacts_number.id, &number_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if ((default_num_id != 0) && (number_id == default_num_id)) + continue; + + elm_genlist_item_insert_before(cdetail_d->genlist, &detail_itcs[DETAIL_ITC_NUMBER], record_number, NULL, item, + ELM_GENLIST_ITEM_NONE, num_func, record_number); + } + } + if (default_num_id) + cdetail_d->has_number = true; + + for(i=0;i<list_count;i++) { + item2 = elm_genlist_item_next_get(item); + elm_object_item_del(item); + item = item2; + } +} + +void __detail_update_email_list(ct_detail_data * cdetail_d) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + int email_id = 0; + Eina_List *cursor; + const Elm_Genlist_Item_Class *itc; + Elm_Object_Item *item = elm_genlist_first_item_get(cdetail_d->genlist); + Elm_Object_Item *item2 = NULL; + contacts_record_h record_email = NULL; + + while(item) { + item2 = elm_genlist_item_next_get(item); + itc = elm_genlist_item_item_class_get(item); + if(itc == &detail_itcs[DETAIL_ITC_EMAIL_DEFAULT] || itc == &detail_itcs[DETAIL_ITC_EMAIL]) { + break; + } + item = item2; + } + + Evas_Smart_Cb email_func = ct_detail_gl_email_sel; + + if (cdetail_d->list_email) + ctui_free_record_list(cdetail_d->list_email); + + cdetail_d->list_email = ctui_person_get_email_list(cdetail_d->list_contacts); + err = phone_cts_get_default_email(cdetail_d->person_id, &record_email); + if (CONTACTS_ERROR_NONE != err) { + ERR("phone_cts_get_default_email() Failed(%d)", err); + } + int default_email_id = 0; + + err = contacts_record_get_int(record_email, _contacts_email.id, &default_email_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + if(default_email_id > 0) { + elm_genlist_item_insert_before(cdetail_d->genlist, &detail_itcs[DETAIL_ITC_EMAIL_DEFAULT], record_email, NULL, item, + ELM_GENLIST_ITEM_NONE, email_func, record_email); + } + + int list_count = eina_list_count(cdetail_d->list_email); + if (list_count > 1) { + EINA_LIST_FOREACH(cdetail_d->list_email, cursor, record_email) { + err = contacts_record_get_int(record_email, _contacts_email.id, &email_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if ((default_email_id != 0) && (email_id == default_email_id)) + continue; + + elm_genlist_item_insert_before(cdetail_d->genlist, &detail_itcs[DETAIL_ITC_EMAIL], record_email, NULL, item, + ELM_GENLIST_ITEM_NONE, email_func, record_email); + } + } + + int i = 0; + for(i=0;i<list_count;i++) { + item2 = elm_genlist_item_next_get(item); + elm_object_item_del(item); + item = item2; + } +} + + +void __detail_default_number_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + ct_detail_data *cdetail_d; + int data_id; + + p_retm_if(NULL == record, "parameter(record) is NULL"); + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get(record) return NULL"); + + err = contacts_record_get_int(record, _contacts_number.id, &data_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_person_set_default_property(CONTACTS_PERSON_PROPERTY_NUMBER, cdetail_d->person_id, data_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_person_set_default_property() Failed(%d)", err); + // TODO: ?? + __detail_update_number_list(cdetail_d); + + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); +} + +void __detail_default_email_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + ct_detail_data *cdetail_d; + int data_id; + + p_retm_if(NULL == record, "parameter(record) is NULL"); + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get(record) return NULL"); + + err = contacts_record_get_int(record, _contacts_email.id, &data_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_person_set_default_property(CONTACTS_PERSON_PROPERTY_EMAIL, cdetail_d->person_id, data_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_person_set_default_property() Failed(%d)", err); + + // TODO: ?? + __detail_update_email_list(cdetail_d); + + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); +} + + +void __detail_click_default_number(void *data, Evas_Object *obj, void *event_info) +{ + int default_number_id = 0; + int number_id = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + Eina_List *cursor; + contacts_record_h record_default_number = NULL; + contacts_record_h record_number = NULL; + ct_detail_data *cdetail_d = (ct_detail_data*)data; + Evas_Object *popup; + Evas_Object *btn; + Evas_Object *genlist; + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + popup = elm_popup_add(cdetail_d->navi); + p_retm_if(NULL == popup, "elm_popup_add() return NULL"); + elm_object_style_set(popup, "liststyle"); + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASE_OP, CTTEXT_SET_DEFAULT_NUMBER)); + cdetail_d->popup = popup; + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_CANCEL)); + 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); + evas_object_show(popup); + + genlist = elm_genlist_add(popup); + p_retm_if(NULL == genlist, "elm_genlist_add() return NULL"); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + + err = phone_cts_get_default_number(cdetail_d->person_id, &record_default_number); + p_warn_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_default_number() Failed(%d)", err); + + err = contacts_record_get_int( record_default_number, _contacts_number.id, &default_number_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_destroy(record_default_number, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + EINA_LIST_FOREACH(cdetail_d->list_number, cursor, record_number){ + err = contacts_record_get_int( record_number, _contacts_number.id, &number_id); + if (default_number_id == number_id) + continue; + + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_DEFAULT_NUMBER_SET_POPUP], record_number, NULL, ELM_GENLIST_ITEM_NONE, __detail_default_number_sel, record_number); + } + + evas_object_show(genlist); + elm_object_content_set(popup, genlist); +} + +void __detail_click_default_email(void *data, Evas_Object *obj, void *event_info) +{ + int default_email_id = 0; + int email_id = 0; + contacts_error_e err = CONTACTS_ERROR_NONE; + Eina_List *cursor; + contacts_record_h record_default_email = NULL; + contacts_record_h record_email = NULL; + ct_detail_data *cdetail_d = (ct_detail_data*)data; + Evas_Object *popup; + Evas_Object *btn; + Evas_Object *genlist; + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + popup = elm_popup_add(cdetail_d->navi); + p_retm_if(NULL == popup, "elm_popup_add() return NULL"); + elm_object_style_set(popup, "liststyle"); + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASE_OP, CTTEXT_SET_DEFAULT_EMAIL)); + cdetail_d->popup = popup; + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_CANCEL)); + 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); + evas_object_show(popup); + + genlist = elm_genlist_add(popup); + p_retm_if(NULL == genlist, "elm_genlist_add() return NULL"); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + + err = phone_cts_get_default_email(cdetail_d->person_id, &record_default_email); + p_warn_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_default_email() Failed(%d)", err); + + err = contacts_record_get_int( record_default_email, _contacts_email.id, &default_email_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_destroy(record_default_email, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + EINA_LIST_FOREACH(cdetail_d->list_email, cursor, record_email){ + err = contacts_record_get_int( record_email, _contacts_email.id, &email_id); + if (default_email_id == email_id) + continue; + + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_DEFAULT_EMAIL_SET_POPUP], record_email, NULL, ELM_GENLIST_ITEM_NONE, __detail_default_email_sel, record_email); + } + + evas_object_show(genlist); + elm_object_content_set(popup, genlist); +} + +char* ct_detail_gl_number_label_get(void *data, Evas_Object *obj, const char *part) +{ + int type; + char buf[PH_TEXT_MAX_LEN+1] = {0,}; + char *ret_str = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + p_retvm_if(NULL == data, NULL, "parameter(data) is NULL"); + + ret_str = NULL; + if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_number.type, &type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + ctui_get_number_type_str(record, type, buf, sizeof(buf)); + return strdup(buf); + } + else if (0 == strcmp(part, "elm.text.1")) { + err = contacts_record_get_str_p(record, _contacts_number.number, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + else if ( 0 == strcmp(part, "elm.text")) { + err = contacts_record_get_str_p(record, _contacts_number.number, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + + return NULL; +} + +char* ct_detail_gl_email_label_get(void *data, Evas_Object *obj, const char *part) +{ + int type; + char *ret_str = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + p_retvm_if(NULL == data, NULL, "parameter(data) is NULL"); + + ret_str = NULL; + if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_email.type, &type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if (CONTACTS_EMAIL_TYPE_CUSTOM == type) { + err = contacts_record_get_str_p(record, _contacts_email.label, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + return strdup(T_(CT_GET_TEXT_EMAIL_TYPE, ctui_get_email_type_index(type))); + } + else if (0 == strcmp(part, "elm.text.1")) { + err = contacts_record_get_str_p(record, _contacts_email.email, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + else if (0 == strcmp(part, "elm.text")) { + err = contacts_record_get_str_p(record, _contacts_email.email, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + return SAFE_STRDUP(ret_str); + } + return NULL; + +} + +static char *detail_gl_url_label_get(void *data, Evas_Object *obj, const char *part) +{ + int type; + char *ret_str = NULL; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + + p_retvm_if(NULL == data, NULL, "parameter(data) is NULL"); + + if (0 == strcmp(part, "elm.text.2")) { + err = contacts_record_get_int(record, _contacts_url.type, &type); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if (CONTACTS_URL_TYPE_CUSTOM == type) { + err = contacts_record_get_str_p(record, _contacts_url.label, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + return SAFE_STRDUP(ret_str); + } + return strdup(T_(CT_GET_TEXT_WEBSITE_TYPE, ct_detail_get_website_type_index(type))); + } + else if (0 == strcmp(part, "elm.text.1")) { + err = contacts_record_get_str_p(record, _contacts_url.url, &ret_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + return SAFE_STRDUP(ret_str); + } + return NULL; +} + + +static void detail_number_cb(contacts_record_h record_number, ct_detail_data *cdetail_d) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + char *num_str; + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + err = contacts_record_get_str_p( record_number, _contacts_number.number, &num_str); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + if (num_str && *num_str) { + int rotate; + cdetail_d->popup = elm_ctxpopup_add(cdetail_d->navi); + p_retm_if(NULL == cdetail_d->popup, "elm_ctxpopup_add() return NULL"); + + rotate = (int)evas_object_data_get(cdetail_d->navi, "phone_rotate"); + if (0 == rotate || 180 == rotate) + elm_ctxpopup_direction_priority_set(cdetail_d->popup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UP, + ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT); + + evas_object_smart_callback_add(cdetail_d->popup, "dismissed", ct_detail_popup_hide_cb, cdetail_d); + evas_object_data_set(cdetail_d->popup, "cdetail_d", cdetail_d); + + elm_ctxpopup_item_append(cdetail_d->popup, S_(PH_SYS_BODY_CALL), NULL, + ct_detail_voice_call_cb, num_str); + elm_ctxpopup_item_append(cdetail_d->popup, S_(PH_SYS_BODY_MESSAGE), NULL, + ct_detail_msg_ug_cb, num_str); + + evas_object_move(cdetail_d->popup, cdetail_d->touch_x, cdetail_d->touch_y); + evas_object_show(cdetail_d->popup); + } +} + + + +static void __detail_email_result(service_h service, service_h reply, service_result_e result, void* user_data) +{ + ct_detail_data *cdetail_d = user_data; + + cdetail_d->touch_block = false; +} + + +void ct_detail_gl_email_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + char *email_address; + service_h service; + Ecore_X_Window win_id; + ct_detail_data *cdetail_d; + contacts_record_h record_email = data; + Elm_Object_Item *item = event_info; + + elm_genlist_item_selected_set(item, EINA_FALSE); + + p_retm_if(NULL == record_email, "parameter(record_email) is NULL"); + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get() return NULL"); + + if(cdetail_d->touch_block == true) + return; + + err = contacts_record_get_str_p( record_email, _contacts_email.email, &email_address); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + win_id = elm_win_xwindow_get(cdetail_d->win); + service_create(&service); + service_set_app_id(service, EMAIL_COMPOSER_PKG); + service_set_window(service, win_id); + service_add_extra_data(service, SERVICE_DATA_TO, email_address); + + if(service_send_launch_request(service, __detail_email_result, cdetail_d) == SERVICE_ERROR_NONE) + cdetail_d->touch_block = true; + service_destroy(service); +} + +static void detail_gl_messenger_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_record_h record_email = data; + Elm_Object_Item *item = event_info; + + elm_genlist_item_selected_set(item, EINA_FALSE); + p_retm_if(NULL == record_email, "parameter(record_email) is NULL"); + + ERR("detail_gl_messenger_sel() not implemented"); +} + +static char* detail_gl_address_book_label_get(void *data, Evas_Object *obj, const char *part) +{ + Eina_List *l; + contacts_record_h contact = NULL; + char temp[PH_TEXT_MAX_LEN]; + char display[PH_TEXT_MAX_LEN]; + ct_detail_data *cdetail_d = data; + + if (0 == strcmp(part, "elm.text")) { + display[0] = '\0'; + if (cdetail_d->contact) { + ct_detail_person_get_addressbook_name(cdetail_d->contact, temp, sizeof(temp)); + snprintf(display, sizeof(display), T_(CT_GET_TEXT_BASIC, CTTEXT_SAVED_IN), temp); + } + else { + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, contact) { + ct_detail_person_get_addressbook_name(contact, temp, sizeof(temp)); + snprintf(display, sizeof(display), T_(CT_GET_TEXT_BASIC, CTTEXT_SAVED_IN), temp); + } + } + if ('\0' == *display) + snprintf(display, sizeof(display), T_(CT_GET_TEXT_BASIC, CTTEXT_SAVED_IN), "Noname"); + return strdup(display); + } + return NULL; +} + + +static char* detail_gl_title_label_get(void *data, Evas_Object *obj, const char *part) +{ + char *display = data; + if (0 == strcmp(part, "elm.text") && display && *display) + return strdup(display); + return NULL; +} + +void ct_detail_gl_number_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_record_h record_number = data; + ct_detail_data *cdetail_d; + Elm_Object_Item *item = event_info; + + elm_genlist_item_selected_set(item, EINA_FALSE); + p_retm_if(NULL == record_number, "parameter(CTSstruct) is NULL"); + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get() return NULL"); + + detail_number_cb(record_number, cdetail_d); +} + +static void detail_send_name_card_cb(void *data, Evas_Object *obj, void *event_info) +{ + int rotate; + int x,y,w,h; + ct_detail_data *cdetail_d = data; + p_retm_if(NULL == cdetail_d, "evas_object_data_get() return NULL"); + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + cdetail_d->popup = elm_ctxpopup_add(cdetail_d->navi); + p_retm_if(NULL == cdetail_d->popup, "elm_ctxpopup_add() return NULL"); + + rotate = (int)evas_object_data_get(cdetail_d->navi, "phone_rotate"); + if (0 == rotate || 180 == rotate) + elm_ctxpopup_direction_priority_set(cdetail_d->popup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UP, + ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT); + + evas_object_smart_callback_add(cdetail_d->popup, "dismissed", ct_detail_popup_hide_cb, cdetail_d); + elm_ctxpopup_item_append(cdetail_d->popup, S_(PH_SYS_BODY_MESSAGE), NULL, + ct_detail_send_via_msg, cdetail_d); + elm_ctxpopup_item_append(cdetail_d->popup, S_(CT_SYS_BODY_EMAIL), NULL, + ct_detail_send_via_email, cdetail_d); + elm_ctxpopup_item_append(cdetail_d->popup, S_(CT_SYS_BODY_BLUETOOTH), NULL, + ct_detail_send_via_bluetooth, cdetail_d); + + evas_object_geometry_get(cdetail_d->ctrl_button, &x, &y, &w, &h); + evas_object_move(cdetail_d->popup, w/2, y+h/2); + evas_object_show(cdetail_d->popup); +} + +static void detail_list_gl_sel(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + ct_person_list *person_info; + contacts_error_e err = CONTACTS_ERROR_NONE; + Elm_Object_Item *item = event_info; + + elm_genlist_item_selected_set(item, EINA_FALSE); + + if (cdetail_d->person_id) { + person_info = elm_object_item_data_get(item); + p_retm_if(NULL == person_info, "elm_object_item_data_get() returns NULL"); + + err = contacts_person_link_person(cdetail_d->person_id, person_info->id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_person_link_person() Failed(%d)", err); + + if (CONTACTS_ERROR_NONE == err) { + phone_show_tickernoti(S_(CT_SYS_POP_SUCCESS)); + ct_detail_refresh_view(cdetail_d); + } + else + phone_show_tickernoti(S_(PH_SYS_POP_FAILED)); + + elm_naviframe_item_pop(cdetail_d->navi); + } +} + +static void detail_link_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + ct_detail_create_list_view(cdetail_d, detail_list_gl_sel, cdetail_d, cdetail_d->person_id); +} + +static void detail_unlink_popup_cancel_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); +} + +static void detail_gl_unlink_item_sel(void *data, Evas_Object *obj, void *event_info) +{ + int person_id; + ct_detail_data *cdetail_d; + ct_detail_person_data *person_info = data; + contacts_error_e err; + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get() return NULL"); + + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + err = contacts_person_unlink_contact(cdetail_d->person_id, person_info->contact_id, &person_id); + if (CONTACTS_ERROR_NONE == err) { + phone_show_tickernoti(S_(CT_SYS_POP_SUCCESS)); + ct_detail_refresh_view(cdetail_d); + } + else + phone_show_tickernoti(S_(PH_SYS_POP_FAILED)); +} + +static void detail_unlink_cb(void *data, Evas_Object *obj, void *event_info) +{ + Eina_List *l; + Evas_Object *genlist; + Evas_Object *popup; + Elm_Object_Item *item; + ct_detail_data *cdetail_d = data; + ct_detail_person_data *person_info; + Evas_Object *btn; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + popup = elm_popup_add(cdetail_d->navi); + p_retm_if(NULL == popup, "elm_popup_add() return NULL"); + elm_object_style_set(popup, "liststyle"); + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_POP_CLOSE)); + elm_object_part_content_set(popup, "button1", btn); + elm_object_style_set(btn, "popup_button/default"); + evas_object_smart_callback_add(btn, "clicked", detail_unlink_popup_cancel_btn_cb, cdetail_d); + + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASE_OP, CTTEXT_UNLINK)); + evas_object_show(popup); + cdetail_d->popup = popup; + + genlist = elm_genlist_add(popup); + p_retm_if(NULL == genlist, "elm_genlist_add() return NULL"); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + cdetail_d->genlist_unlink = genlist; + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, record) { + person_info = calloc(1, sizeof(ct_detail_person_data)); + if (NULL == person_info) { + ERR("calloc() return NULL"); + break; + } + + err = contacts_record_get_int(record, _contacts_contact.id, &(person_info->contact_id)); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_get_int(record, _contacts_contact.address_book_id, &(person_info->addressbook_id)); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_UNLINK_POPUP], person_info, + NULL, ELM_GENLIST_ITEM_NONE, detail_gl_unlink_item_sel, person_info); + + person_info->item = item; + } + + evas_object_show(genlist); + elm_object_content_set(popup, genlist); +} + +static char* detail_gl_unlink_popup_label_get(void *data, Evas_Object *obj, const char *part) +{ + char buf[PH_TEXT_MAX_LEN+1]; + char *display; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + ct_detail_person_data *person_info = data; + p_retvm_if(NULL == person_info, NULL, "person_info is NULL"); + + if (0 == strcmp(part, "elm.text") || 0 == strcmp(part, "elm.text.1")) { + buf[0] = '\0'; + + err = contacts_db_get_record(_contacts_simple_contact._uri, person_info->contact_id, &record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + err = contacts_record_get_str_p(record, _contacts_simple_contact.display_name, &display); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + if (display && *display) + snprintf(buf, sizeof(buf), "%s", display); + + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + if (*buf) + return strdup(buf); + } + else if (0 == strcmp(part, "elm.text.2")) { + + buf[0] = '\0'; + ctui_get_addressbook_name(person_info->addressbook_id, buf, sizeof(buf)); + if (*buf) + return strdup(buf); + } + return NULL; +} + +static Evas_Object* detail_gl_unlink_popup_icon_get(void *data, Evas_Object *obj, const char *part) +{ + ct_detail_person_data *person_info = data; + p_retvm_if(NULL == person_info, NULL, "person_info is NULL"); + + if (0 == strcmp(part, "elm.icon")) { + char *icon_path; + Evas_Object *icon; + + icon_path = ctui_get_addressbook_icon_path(person_info->addressbook_id); + if (icon_path && *icon_path) { + icon = elm_icon_add(obj); + p_retvm_if(NULL == icon, NULL, "elm_icon_add() return NULL"); + + elm_icon_file_set(icon, icon_path, NULL); + evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + free(icon_path); + return icon; + } + } + return NULL; +} +static void detail_gl_unlink_popup_del(void *data, Evas_Object *obj) +{ + ct_detail_person_data *person_info = data; + p_retm_if(NULL == person_info, "person_info is NULL"); + free(person_info); +} + +static Evas_Object *detail_gl_link_unlink_icon_get(void *data, Evas_Object *obj, + const char *part) +{ + ct_detail_data *cdetail_d = data; + p_retvm_if(NULL == cdetail_d, NULL, "parameter(ct_detail_data) is NULL"); + + if (0 == strcmp(part, "elm.icon.1")) { + Evas_Object *btn; + + btn = ctui_create_btn(obj, T_(CT_GET_TEXT_BASE_OP, CTTEXT_LINK_CONTACTS)); + p_retvm_if(NULL == btn, NULL, "ctui_create_btn() return NULL"); + if(!cdetail_d->ug) + evas_object_smart_callback_add(btn, "clicked", detail_link_cb, cdetail_d); + + return btn; + } + else if (0 == strcmp(part, "elm.icon.2")) { + Evas_Object *btn; + + btn = ctui_create_btn(obj, T_(CT_GET_TEXT_BASE_OP, CTTEXT_UNLINK)); + p_retvm_if(NULL == btn, NULL, "ctui_create_btn() return NULL"); + + if (cdetail_d->list_contacts && 1 < eina_list_count(cdetail_d->list_contacts)) { + if(!cdetail_d->ug) + evas_object_smart_callback_add(btn, "clicked", detail_unlink_cb, cdetail_d); + } + else + elm_object_disabled_set(btn, EINA_TRUE); + return btn; + } + return NULL; +} + + +static Evas_Object *detail_gl_util_btn_icon_get(void *data, Evas_Object *obj, + const char *part) +{ + Evas_Object *ret_obj; + ct_detail_data *cdetail_d = data; + p_retvm_if(NULL == cdetail_d, NULL, "parameter(ct_detail_data) is NULL"); + + ret_obj = NULL; + if (0 == strcmp(part, "elm.icon.1") || 0 == strcmp(part, "elm.icon")) { + Evas_Object *btn; + btn = ctui_create_btn(obj, T_(CT_GET_TEXT_BASE_OP, CTTEXT_ADD_TO_HOME)); + p_retvm_if(NULL == btn, NULL, "ctui_create_btn() return NULL"); + if (!cdetail_d->has_number) + elm_object_disabled_set(btn, EINA_TRUE); + ret_obj = btn; + } + else if (0 == strcmp(part, "elm.icon.2")) { + Evas_Object *btn; + btn = ctui_create_btn(obj, T_(CT_GET_TEXT_BASE_OP, CTTEXT_SEND_NAME_CARD)); + p_retvm_if(NULL == btn, NULL, "ctui_create_btn() return NULL"); + if(!cdetail_d->ug) + evas_object_smart_callback_add(btn, "clicked", detail_send_name_card_cb, cdetail_d); + + ret_obj = btn; + } + return ret_obj; +} + +static void detail_gl_website_sel(void *data, Evas_Object *obj, void *event_info) +{ + char *website; + contacts_record_h record_website = data; + Elm_Object_Item *item = event_info; + int ret; + service_h service; + + p_retm_if(NULL == record_website, "parameter(value) is NULL"); + + elm_genlist_item_selected_set(item, EINA_FALSE); + + contacts_record_get_str_p( record_website, _contacts_url.url, &website ); + if (website && *website) { + ret = service_create(&service); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_create() Failed(%d)", ret); + + ret = service_set_operation(service, SERVICE_OPERATION_VIEW ); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_set_operation() Failed(%d)", ret); + + if (strstr(website, "http")) + ret = service_set_uri(service, website); + else { + char *new_url = g_strdup_printf("http://%s", website); + ret = service_set_uri(service, new_url); + free(new_url); + } + p_retm_if(SERVICE_ERROR_NONE != ret, "service_set_uri() Failed(%d)", ret); + + ret = service_send_launch_request(service, NULL, NULL); + p_retm_if(SERVICE_ERROR_NONE != ret, "service_send_launch_request() Failed(%d)", ret); + + service_destroy(service); + } +} + +static char* detail_gl_link_list_label_get(void *data, Evas_Object *obj, const char *part) +{ + return strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_ALL_LINKED_CONTACTS)); +} + +static char* detail_gl_link_list_sub_label_get(void *data, Evas_Object *obj, const char *part) +{ + int contact_id = (int)data; + char *display; + char buf[PH_TEXT_MAX_LEN]; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record_contact = NULL; + + if (0 == strcmp(part, "elm.text")) { + buf[0] = '\0'; + + err = contacts_db_get_record(_contacts_contact._uri, contact_id, &record_contact); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record(%d) Failed(%d)", contact_id, err); + + err = contacts_record_get_str_p( record_contact, _contacts_contact.display_name, &display ); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p(display_name) Failed(%d)", err); + + if (display && *display) + snprintf(buf, sizeof(buf), "%s", display); + + err = contacts_record_destroy(record_contact, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + if (*buf) + return strdup(buf); + } + return NULL; +} + +static Evas_Object* detail_gl_link_list_sub_icon_get(void *data, Evas_Object *obj, const char *part) +{ + int addressbook_id; + int contact_id = (int)data; + char *icon_path; + Evas_Object *icon; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + if (0 == strcmp(part, "elm.icon")) { + err = contacts_db_get_record(_contacts_simple_contact._uri, contact_id, &record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + err = contacts_record_get_int(record, _contacts_simple_contact.address_book_id, &addressbook_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + icon_path = ctui_get_addressbook_icon_path(addressbook_id); + if (icon_path && *icon_path) { + icon = elm_icon_add(obj); + p_retvm_if(NULL == icon, NULL, "elm_icon_add() return NULL"); + + elm_icon_file_set(icon, icon_path, NULL); + evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + free(icon_path); + return icon; + } + } + return NULL; +} + + +static void detail_group_changed(const char *view_uri, void *data) +{ + ct_detail_data *cdetail_d = data; + p_retm_if(NULL == cdetail_d, "parameter(cdetail_d) is NULL"); + elm_genlist_item_update(cdetail_d->group_item); +} + +static void detail_filemanager_status_changed_cb(keynode_t *key, void *data) +{ + Elm_Object_Item *item_ringtone = data; + p_retm_if(NULL == item_ringtone, "parameter(item_ringtone) is NULL"); + elm_genlist_item_update(item_ringtone); +} + +static void detail_view_delete_cb(void *data, Evas *e, Evas_Object *obj, + void *event_info) +{ + PH_FN_CALL; + int ret; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_detail_data *cdetail_d = data; + + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + if (cdetail_d->genlist) + evas_object_del(cdetail_d->genlist); + + if (cdetail_d->th) { + elm_theme_extension_del(cdetail_d->th, DETAIL_THEME_EDJ); + elm_theme_free(cdetail_d->th); + } + + ct_detail_delete_namecards(cdetail_d); + + err = contacts_db_remove_changed_cb(_contacts_contact._uri, ct_detail_contact_changed, cdetail_d); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_remove_changed_cb() Failed(%d)", err); + + err = contacts_db_remove_changed_cb(_contacts_group._uri, detail_group_changed, cdetail_d); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_remove_changed_cb() Failed(%d)", err); + + ret = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS, detail_filemanager_status_changed_cb); + p_warn_if(-1 == ret, "vconf_ignore_key_changed() Failed"); + +/* if (cdetail_d->updated) { // group member issue when group member update at detail view + Eina_List *l; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h contact = NULL; + + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, contact) { + // TODO: contacts_db_update_records + err = contacts_db_update_record(contact); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_update_record() Failed(%d)", err); + } + }*/ + + contacts_record_h record = NULL; + EINA_LIST_FREE(cdetail_d->list_number, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_number) Failed(%d)", err); + } + cdetail_d->list_number = NULL; + + EINA_LIST_FREE(cdetail_d->list_email, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_email) Failed(%d)", err); + } + cdetail_d->list_email = NULL; + + EINA_LIST_FREE(cdetail_d->list_postal, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_postal) Failed(%d)", err); + } + cdetail_d->list_postal = NULL; + + EINA_LIST_FREE(cdetail_d->list_relationship, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_relationship) Failed(%d)", err); + } + cdetail_d->list_relationship = NULL; + + EINA_LIST_FREE(cdetail_d->list_event, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_event) Failed(%d)", err); + } + cdetail_d->list_event = NULL; + + EINA_LIST_FREE(cdetail_d->list_messenger, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_messenger) Failed(%d)", err); + } + cdetail_d->list_messenger = NULL; + + EINA_LIST_FREE(cdetail_d->list_website, record) { + if (NULL == record) continue; + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_website) Failed(%d)", err); + } + cdetail_d->list_website = NULL; + + ctui_free_record_list(cdetail_d->list_contacts); + free(cdetail_d->vcard_path); + free(cdetail_d->base_ab_name); + + evas_object_data_del(cdetail_d->navi, "cdetail_d"); + + if (cdetail_d->formatter) + udat_close(cdetail_d->formatter); + + if (cdetail_d->child_ug) + ug_destroy(cdetail_d->child_ug); + cdetail_d->child_ug = NULL; + + cdetail_d->view_destroying = FALSE; + + if (cdetail_d->person) { + err = contacts_record_destroy(cdetail_d->person, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + } + + if (cdetail_d->has_input) + cdetail_d->has_detail = false; + else + free(cdetail_d); + + PH_FN_END; +} + + + +static char *__detail_gl_label_get(void *data, Evas_Object *obj, const char *part) +{ + char *str = NULL; + if(!data) + return NULL; + + str = (char*)data; + if (0 == strcmp(part, "elm.text")) { + + return SAFE_STRDUP(str); + } + return NULL; +} + +static inline void detail_create_itcs() +{ + detail_itcs[DETAIL_ITC_NUMBER].func.text_get = ct_detail_gl_number_label_get; + detail_itcs[DETAIL_ITC_EMAIL].func.text_get = ct_detail_gl_email_label_get; + detail_itcs[DETAIL_ITC_URL].func.text_get = detail_gl_url_label_get; + + detail_itcs[DETAIL_ITC_NUMBER_DEFAULT].func.text_get = ct_detail_gl_number_label_get; + + detail_itcs[DETAIL_ITC_MESSENGER].func.text_get = detail_gl_messenger_label_get; + detail_itcs[DETAIL_ITC_EVENT].func.text_get = detail_gl_event_label_get; + + detail_itcs[DETAIL_ITC_ADDRESS].func.text_get = detail_gl_address_label_get; + + detail_itcs[DETAIL_ITC_NOTE].func.text_get = detail_gl_2text_multiline_label_get; + + detail_itcs[DETAIL_ITC_RINGTONE].func.text_get = detail_gl_ringtone_label_get; + + detail_itcs[DETAIL_ITC_VIBRATION].func.text_get = detail_gl_vibration_label_get; + + detail_itcs[DETAIL_ITC_GROUP].func.text_get = detail_gl_group_label_get; + + detail_itcs[DETAIL_ITC_RELATIONSHIP].func.text_get = detail_gl_relationship_label_get; + + detail_itcs[DETAIL_ITC_NUM_UTIL_BTN].func.content_get = ct_detail_gl_number_util_icon_get; + + detail_itcs[DETAIL_ITC_UTIL_BTN].func.content_get = detail_gl_util_btn_icon_get; + + detail_itcs[DETAIL_ITC_UTIL_1BTN].func.content_get = detail_gl_util_btn_icon_get; + + detail_itcs[DETAIL_ITC_ADDRBOOK].func.text_get = detail_gl_address_book_label_get; + + detail_itcs[DETAIL_ITC_LINK_UNLINK].func.content_get = detail_gl_link_unlink_icon_get; + + detail_itcs[DETAIL_ITC_UNLINK_POPUP].func.text_get = detail_gl_unlink_popup_label_get; + detail_itcs[DETAIL_ITC_UNLINK_POPUP].func.content_get = detail_gl_unlink_popup_icon_get; + detail_itcs[DETAIL_ITC_UNLINK_POPUP].func.del = detail_gl_unlink_popup_del; + + detail_itcs[DETAIL_ITC_EDIT_POPUP].func.text_get = detail_gl_unlink_popup_label_get; + detail_itcs[DETAIL_ITC_EDIT_POPUP].func.content_get = detail_gl_unlink_popup_icon_get; + detail_itcs[DETAIL_ITC_EDIT_POPUP].func.del = detail_gl_unlink_popup_del; + + detail_itcs[DETAIL_ITC_LINK_LIST].func.text_get = detail_gl_link_list_label_get; + + detail_itcs[DETAIL_ITC_LINK_LIST_SUB].func.text_get = detail_gl_link_list_sub_label_get; + detail_itcs[DETAIL_ITC_LINK_LIST_SUB].func.content_get = detail_gl_link_list_sub_icon_get; + + detail_itcs[DETAIL_ITC_FIELD_TITLE].func.text_get = detail_gl_title_label_get; + detail_itcs[DETAIL_ITC_TITLE].func.text_get = detail_gl_title_label_get; + + detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_1ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_1ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_1ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_1ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_1ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_1ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_2ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_2ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_2ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_2ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_2ICON].func.text_get = ct_detail_gl_baseinfo_label_get; + detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_2ICON].func.content_get = ct_detail_gl_baseinfo_icon_get; + + detail_itcs[DETAIL_ITC_DEFAULT_NUMBER_SET_POPUP].func.text_get = ct_detail_gl_number_label_get; + detail_itcs[DETAIL_ITC_DEFAULT_EMAIL_SET_POPUP].func.text_get = ct_detail_gl_email_label_get; + + detail_itcs[DETAIL_ITC_EMAIL_DEFAULT].func.text_get = ct_detail_gl_email_label_get; + + detail_itcs[DETAIL_ITC_DEFAULT_NAME_POPUP].func.text_get = __detail_gl_label_get; +} + +static void detail_genlist_append_separator_line(Evas_Object *genlist) +{ + static Elm_Genlist_Item_Class itc_separator_1px = { .item_style="dialogue/separator/1/with_line" }; + + Elm_Object_Item *item; + item = elm_genlist_item_append(genlist, &itc_separator_1px, NULL, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); + +} + +static void detail_fill_list(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, Eina_List *list, Evas_Smart_Cb func) +{ + Eina_List *cursor; + contacts_record_h record = NULL; + Elm_Object_Item *item; + + EINA_LIST_FOREACH(list, cursor, record) { + item = elm_genlist_item_append(genlist, itc, record, NULL, ELM_GENLIST_ITEM_NONE, func, record); + + if (NULL == func) + elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); + } +} + +static void detail_fill_email_list(Evas_Object *genlist, Eina_List *list, Evas_Smart_Cb func, int default_email_id) +{ + Eina_List *cursor; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record_email = NULL; + int email_id; + + if (eina_list_count(list) < 2 && default_email_id > 0) + return; + + EINA_LIST_FOREACH(list, cursor, record_email) { + err = contacts_record_get_int(record_email, _contacts_email.id, &email_id); + p_retm_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if (default_email_id != 0 && default_email_id == email_id) + continue; + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_EMAIL], record_email, NULL, + ELM_GENLIST_ITEM_NONE, func, record_email); + } +} + +static void detail_fill_number_list(Evas_Object *genlist, Eina_List *list, Evas_Smart_Cb func, int default_num_id) +{ + Eina_List *cursor; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record_number = NULL; + int number_id; + + if (eina_list_count(list) < 2 && default_num_id > 0) + return; + + ctui_genlist_append_separator_20px_with_line(genlist); + + EINA_LIST_FOREACH(list, cursor, record_number) { + err = contacts_record_get_int(record_number, _contacts_number.id, &number_id); + p_retm_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + if ((default_num_id != 0) && (number_id == default_num_id)) + continue; + + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_NUMBER], record_number, NULL, + ELM_GENLIST_ITEM_NONE, func, record_number); + } +} + +static void detail_gl_link_list_exp(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + Eina_List *l; + contacts_record_h record_temp = NULL; + Evas_Object *genlist = obj; + Elm_Object_Item *it_parent = event_info; + Elm_Object_Item *item; + ct_detail_data *cdetail_d = data; + + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, record_temp){ + int contact_id; + err = contacts_record_get_int(record_temp, _contacts_contact.id, &contact_id ); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_LINK_LIST_SUB], + (void *)contact_id, it_parent, ELM_GENLIST_ITEM_NONE, NULL, NULL); + elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_NONE); + } +} + +static void detail_gl_link_list_con(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *item = event_info; + elm_genlist_item_subitems_clear(item); +} + +static void __detail_baseinfo_item_update(ct_detail_data *cdetail_d) +{ + cdetail_d->base_item = cdetail_d->base_info_item; + elm_genlist_item_update(cdetail_d->base_item); +} + +static void detail_popup_cancel_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + evas_object_del(cdetail_d->popup); + cdetail_d->popup = NULL; +} + +static void __detail_set_default_name(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = data; + ct_detail_data *cdetail_d; + int contact_id; + + p_retm_if(NULL == record, "parameter(record) is NULL"); + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get(record) return NULL"); + + err = contacts_record_get_int(record, _contacts_contact.id, &contact_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_person_set_default_property(CONTACTS_PERSON_PROPERTY_NAME_CONTACT, cdetail_d->person_id, contact_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_person_set_default_property() Failed(%d)", err); + + err = contacts_record_destroy(cdetail_d->person, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy(list_event) Failed(%d)", err); + + err = contacts_db_get_record(_contacts_person._uri, cdetail_d->person_id, &(cdetail_d->person)); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + __detail_baseinfo_item_update(cdetail_d); + + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); +} + +static void __detail_select_person_name_cb(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *popup; + Evas_Object *genlist; + Evas_Object *btn; + char *person_name; + char *contact_name; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + Eina_List *l; + ct_detail_data *cdetail_d = data; + + if(2 > eina_list_count(cdetail_d->list_contacts)) + return; + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + popup = elm_popup_add(cdetail_d->navi); + p_retm_if(NULL == popup, "elm_popup_add() return NULL"); + elm_object_style_set(popup, "liststyle"); + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_POP_CLOSE)); + 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); + + elm_object_part_text_set(popup, "title,text", "Set default name"); + evas_object_show(popup); + cdetail_d->popup = popup; + + genlist = elm_genlist_add(popup); + p_retm_if(NULL == genlist, "elm_genlist_add() return NULL"); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + + + err = contacts_record_get_str_p(cdetail_d->person, _contacts_person.display_name, &person_name); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, record) { + err = contacts_record_get_str_p(record, _contacts_contact.display_name, &contact_name); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str() Failed(%d)", err); + + if(strcmp(contact_name, person_name) != 0) { + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_DEFAULT_NAME_POPUP], contact_name, + NULL, ELM_GENLIST_ITEM_NONE, __detail_set_default_name, record); + } + } + + evas_object_show(genlist); + elm_object_content_set(popup, genlist); + + elm_genlist_item_selected_set(event_info, EINA_FALSE); +} + +Elm_Genlist_Item_Class* ct_detail_get_baseinfo_item_class(ct_detail_data *cdetail_d) +{ + PH_FN_CALL; + int cnt; + char *img; + char *str_main; + char *first = NULL; + char *last = NULL; + char str_sub1[CT_EDITFIELD_MAX_CHAR*3+1] = {0,}; + char str_sub2[CT_EDITFIELD_MAX_CHAR*4+1] = {0,}; + contacts_error_e err = CONTACTS_ERROR_NONE; + + str_main = NULL; + if (cdetail_d->person) { + err = contacts_record_get_str_p(cdetail_d->person, _contacts_person.display_name, &str_main); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + } + else if (cdetail_d->contact) { + contacts_record_h record_name; + err = contacts_record_get_str_p(cdetail_d->contact, _contacts_contact.display_name, &str_main); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + if(NULL == str_main){ + err = contacts_record_get_child_record_at_p(cdetail_d->contact, _contacts_contact.name, 0, &record_name); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_child_record_at_p() Failed(%d)", err); + err = contacts_record_get_str_p(record_name, _contacts_name.first, &first); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + PH_DBG("first %s", first); + if(strlen(first)>CT_EDITFIELD_MAX_CHAR){ + first[CT_EDITFIELD_MAX_CHAR] = '\0'; + } + + err = contacts_record_get_str_p(record_name, _contacts_name.last, &last); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + PH_DBG("last %s", last); + if(strlen(last)>CT_EDITFIELD_MAX_CHAR){ + last[CT_EDITFIELD_MAX_CHAR] = '\0'; + } + } + } + + str_sub1[0] = '\0'; + ct_detail_person_get_extra_name(cdetail_d->list_contacts, cdetail_d->person, str_sub1, sizeof(str_sub1)); + if( strlen(str_sub1) > CT_EDITFIELD_MAX_CHAR*3) + str_sub1[CT_EDITFIELD_MAX_CHAR*2+2] = '\0'; + + str_sub2[0] = '\0'; + ct_detail_person_get_company_str(cdetail_d->list_contacts, str_sub2, sizeof(str_sub2)); + if( strlen(str_sub2) > CT_EDITFIELD_MAX_CHAR*4) + str_sub2[CT_EDITFIELD_MAX_CHAR*3+4] = '\0'; + + + img = NULL; + if (cdetail_d->person) { + err = contacts_record_get_str_p(cdetail_d->person, _contacts_person.image_thumbnail_path, &img); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + } + else if (cdetail_d->contact) { + err = contacts_record_get_str_p(cdetail_d->contact, _contacts_contact.image_thumbnail_path, &img); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str_p() Failed(%d)", err); + } + + cnt = 0; + if (str_main && *str_main) + cnt++; + if ( (first && *first) || (last && *last) ) + cnt++; + if (*str_sub1) + cnt++; + if (*str_sub2) + cnt++; + if (img && *img) cnt += 10; + + switch (cnt) { + case 1: return &detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_1ICON]; + case 2: return &detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_1ICON]; + case 3: return &detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_1ICON]; + case 11: return &detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_2ICON]; + case 12: return &detail_itcs[DETAIL_ITC_BASEINFO_2TEXT_2ICON]; + case 13: return &detail_itcs[DETAIL_ITC_BASEINFO_3TEXT_2ICON]; + default: + if (10 <= cnt) + return &detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_2ICON]; + else + return &detail_itcs[DETAIL_ITC_BASEINFO_1TEXT_1ICON]; + } +} + +static void __detail_gl_realized(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d; + + Elm_Object_Item *item = event_info; + Elm_Genlist_Item_Class *item_class; + p_retm_if(NULL == item, "parameter(item) is NULL"); + + cdetail_d = (int)elm_object_item_data_get(item); + item_class = (Elm_Genlist_Item_Class *)elm_genlist_item_item_class_get(item); + p_retm_if(NULL == item_class, "parameter(item_class) is NULL"); + + if(item_class == &detail_itcs[DETAIL_ITC_GROUP]) + elm_object_item_signal_emit(item, "elm,state,top", ""); + else if(item_class == &detail_itcs[DETAIL_ITC_RINGTONE]){ + if (!ct_detail_person_get_readonly(cdetail_d->list_contacts) && !cdetail_d->vcard_path)//check if group field exists. + elm_object_item_signal_emit(item, "elm,state,center", ""); + else + elm_object_item_signal_emit(item, "elm,state,top", ""); + } + else if(item_class == &detail_itcs[DETAIL_ITC_VIBRATION]) + elm_object_item_signal_emit(item, "elm,state,bottom", ""); +} + +API Evas_Object* ctui_detail_genlist_update(ct_detail_data *cdetail_d) +{ + PH_FN_CALL; + int ret; + contacts_error_e err = CONTACTS_ERROR_NONE; + Evas_Object *genlist; + Evas_Object *layout; + int default_num_id = 0; + int default_email_id = 0; + bool need_separator; + + Evas_Smart_Cb num_func = ct_detail_gl_number_sel; + Evas_Smart_Cb email_func = ct_detail_gl_email_sel; + contacts_record_h default_email_record = NULL; + contacts_record_h default_number_record = NULL; + + layout = elm_object_part_content_get(cdetail_d->layout, "contents"); + + // Create genlist + if (NULL == cdetail_d->genlist) { + genlist = elm_genlist_add(layout); + cdetail_d->genlist = genlist; + evas_object_event_callback_add(genlist, EVAS_CALLBACK_MOUSE_UP, ct_detail_mouseup, cdetail_d); + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); + + evas_object_smart_callback_add(genlist, "expanded", detail_gl_link_list_exp, cdetail_d); + evas_object_smart_callback_add(genlist, "contracted", detail_gl_link_list_con, NULL); + elm_object_theme_set(genlist, cdetail_d->th); + } + else { + genlist = cdetail_d->genlist; + elm_genlist_clear(genlist); + + ret = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS, detail_filemanager_status_changed_cb); + p_warn_if(-1 == ret, "vconf_ignore_key_changed() Failed"); + } + ctui_genlist_append_separator_20px(genlist); + + cdetail_d->base_item = elm_genlist_item_append(genlist, ct_detail_get_baseinfo_item_class(cdetail_d), + cdetail_d, NULL, ELM_GENLIST_ITEM_NONE, __detail_select_person_name_cb, cdetail_d); + cdetail_d->base_info_item = cdetail_d->base_item; + + cdetail_d->list_number = ctui_person_get_number_list(cdetail_d->list_contacts); + err = phone_cts_get_default_number(cdetail_d->person_id, &default_number_record); + if (CONTACTS_ERROR_NONE != err) { + ERR("phone_cts_get_default_number() Failed(%d)", err); + } + + if (CONTACTS_ERROR_NONE == err && default_number_record) { + err = contacts_record_get_int(default_number_record, _contacts_number.id, &default_num_id); + + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_NUMBER_DEFAULT], default_number_record, NULL, + ELM_GENLIST_ITEM_NONE, NULL, default_number_record); + + cdetail_d->number_util_item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_NUM_UTIL_BTN], default_number_record, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + } + detail_fill_number_list(genlist, cdetail_d->list_number, num_func, default_num_id); + if (default_num_id) + cdetail_d->has_number = true; + //check block number info + + // email list + cdetail_d->list_email = ctui_person_get_email_list(cdetail_d->list_contacts); + err = phone_cts_get_default_email(cdetail_d->person_id, &default_email_record); + p_warn_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_default_email() Failed(%d)", err); + + if (CONTACTS_ERROR_NONE == err && default_email_record) { + ctui_genlist_append_separator_20px_with_line(genlist); + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_EMAIL), + NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + err = contacts_record_get_int(default_email_record, _contacts_email.id, &default_email_id); + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_EMAIL], default_email_record, NULL, + ELM_GENLIST_ITEM_NONE, email_func, default_email_record); + } + detail_fill_email_list(genlist, cdetail_d->list_email, email_func, default_email_id); + + // POSTAL list + cdetail_d->list_postal = ct_detail_person_get_postal_list(cdetail_d->list_contacts); + if(cdetail_d->list_postal){ + ctui_genlist_append_separator_20px_with_line(genlist); + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_POSTAL_ADDRESS), + NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_ADDRESS], cdetail_d->list_postal, NULL); + } + + evas_object_smart_callback_add(genlist, "realized", __detail_gl_realized, NULL); + + // instant messenger list + cdetail_d->list_messenger = ct_detail_person_get_messenger_list(cdetail_d->list_contacts); + if (cdetail_d->list_messenger) + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_INSTANT_MESSENGER), + NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_MESSENGER], cdetail_d->list_messenger, detail_gl_messenger_sel); + + need_separator = true; + + // website + cdetail_d->list_website = ct_detail_person_get_website_list(cdetail_d->list_contacts); + if (cdetail_d->list_website) { + need_separator = false; + ctui_genlist_append_separator_20px_with_line(genlist); + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_URL), + NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + if(!cdetail_d->ug) + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_URL], cdetail_d->list_website, detail_gl_website_sel); + else + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_URL], cdetail_d->list_website, NULL); + } + + //relationship + cdetail_d->list_relationship = ct_detail_person_get_relationship_list(cdetail_d->list_contacts); + if(cdetail_d->list_relationship){ + //elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_RELATIONSHIP), + // NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_RELATIONSHIP], cdetail_d->list_relationship, NULL); + } + + // event list + cdetail_d->list_event = ct_detail_person_get_event_list(cdetail_d->list_contacts); + if (cdetail_d->list_event && need_separator) { + need_separator = false; + ctui_genlist_append_separator_20px_with_line(genlist); + } + if(cdetail_d->list_event){ + //elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_EVENT), + // NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_EVENT], cdetail_d->list_event, NULL); + } + + //note list + cdetail_d->list_note = ct_detail_person_get_note_list(cdetail_d->list_contacts); + if (cdetail_d->list_note && need_separator) { + need_separator = false; + ctui_genlist_append_separator_20px_with_line(genlist); + } + if(cdetail_d->list_note){ + //elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_FIELD_TITLE], T_(CT_GET_TEXT_BASIC ,CTTEXT_NOTE), + // NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + detail_fill_list(genlist, &detail_itcs[DETAIL_ITC_NOTE], cdetail_d->list_note, NULL); + } + + if (cdetail_d->person_id ) { + ctui_genlist_append_separator_20px_with_line(genlist); + + // group + if (!ct_detail_person_get_readonly(cdetail_d->list_contacts) && !cdetail_d->vcard_path) { + cdetail_d->group_item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_GROUP], cdetail_d, NULL, + ELM_GENLIST_ITEM_NONE, detail_group_gl_sel, cdetail_d); + } + + // Ringtone + cdetail_d->ringtone_item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_RINGTONE], cdetail_d, NULL, + ELM_GENLIST_ITEM_NONE, detail_ringtone_gl_sel, cdetail_d); + + ret = vconf_notify_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS, detail_filemanager_status_changed_cb, cdetail_d->ringtone_item); + p_warn_if(-1 == ret, "vconf_notify_key_changed() Failed"); + + // Vibration + cdetail_d->vibration_item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_VIBRATION], cdetail_d, NULL, + ELM_GENLIST_ITEM_NONE, detail_vibration_gl_sel, cdetail_d); + // Addressbook + elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_ADDRBOOK], cdetail_d, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + + } + + return genlist; +} + +static void detail_back_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = (ct_detail_data *)data; + p_retm_if(true == cdetail_d->view_destroying, "view is being destroyed."); + + elm_naviframe_item_pop(cdetail_d->navi); + cdetail_d->view_destroying = TRUE; +} + +static void __detail_out_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_FN_CALL; + elm_exit(); +} + +static void detail_make_back_btn(ct_detail_data *cdetail_d) +{ + Evas_Object *back_btn; + Elm_Object_Item *item; + back_btn = elm_button_add(cdetail_d->navi); + p_retm_if(NULL == back_btn, "elm_button_add() return NULL"); + elm_object_style_set(back_btn, "naviframe/back_btn/default"); + elm_object_item_part_content_set(cdetail_d->navi_item, "prev_btn", back_btn); + item = elm_naviframe_bottom_item_get(cdetail_d->navi); + if (true == cdetail_d->ug_detail) + evas_object_smart_callback_add(back_btn, "clicked", phone_ug_destroy_me_cb, cdetail_d->ug); + else if (elm_naviframe_top_item_get(cdetail_d->navi) == item) + evas_object_smart_callback_add(back_btn, "clicked", __detail_out_btn_cb, cdetail_d); + //evas_object_smart_callback_add(back_btn, "clicked", phone_back_btn_clicked_cb, cdetail_d->win); + else + evas_object_smart_callback_add(back_btn, "clicked", detail_back_btn_cb, cdetail_d); +} + +static void detail_delete_person_response_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_FN_CALL; + contacts_error_e err = CONTACTS_ERROR_NONE; + ct_detail_data *cdetail_d = data; + + p_retm_if(NULL == cdetail_d, "parameter(cdetail_d) is NULL"); + p_retm_if(cdetail_d->person_id <= 0, "parameter(person_id) is NULL"); + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + evas_object_data_set(cdetail_d->navi, "ct_list_update_ui", (void *)1); + + err = contacts_db_delete_record(_contacts_person._uri, cdetail_d->person_id); + if (CONTACTS_ERROR_NONE == err) { + // FIXME : Improve the logic + err = contacts_db_remove_changed_cb(_contacts_contact._uri, ct_detail_contact_changed, cdetail_d); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_remove_changed_cb() Failed(%d)", err); + + if (cdetail_d->is_shortcut) + elm_exit(); + else if (NULL == cdetail_d->prev_view_data && cdetail_d->ug) + ug_destroy_me(cdetail_d->ug); + else + elm_naviframe_item_pop_to(cdetail_d->prev_navi_item); + } + else { + phone_show_tickernoti(S_(PH_SYS_POP_FAILED)); + ERR("contacts_db_delete_record() Failed(%d)", err); + } + + PH_FN_END; +} + +static void detail_gl_edit_item_sel(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + ct_detail_data *cdetail_d; + ct_detail_person_data *person_info = data; + + cdetail_d = evas_object_data_get(obj, "cdetail_d"); + p_retm_if(NULL == cdetail_d, "evas_object_data_get() return NULL"); + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + err = contacts_db_get_record(_contacts_contact._uri, person_info->contact_id, &record); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + ct_input_push_navi_content(cdetail_d, record, person_info->contact_id); +} + +static void detail_edit_cb(void *data, Evas_Object *obj, void *event_info) +{ + int contact_id; + int addressbook_id; + int addressbook_mode; + Evas_Object *genlist; + Evas_Object *popup; + Evas_Object *btn; + Elm_Object_Item *item; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record_contact = NULL; + contacts_record_h record_addressbook = NULL; + Eina_List *l; + ct_detail_person_data *person_info; + ct_detail_data *cdetail_d = data; + + p_ret_if(NULL == cdetail_d); + + PH_DBG("##### [TSP_TEST] detail->edit start#####"); + + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + if (1 == eina_list_count(cdetail_d->list_contacts)) { + err = contacts_record_clone(cdetail_d->list_contacts->data, &record_contact); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_clone() Failed(%d)", err); + + err = contacts_record_get_int(record_contact, _contacts_contact.id, &contact_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + ct_input_push_navi_content(cdetail_d, record_contact, contact_id); + + return; + } + + popup = elm_popup_add(cdetail_d->navi); + p_retm_if(NULL == popup, "elm_popup_add() return NULL"); + elm_object_style_set(popup, "liststyle"); + elm_object_part_text_set(popup, "title,text", T_(CT_GET_TEXT_BASIC, CTTEXT_LINKED_CONTACTS)); + cdetail_d->popup = popup; + + btn = elm_button_add(popup); + elm_object_text_set(btn, S_(PH_SYS_SK_CANCEL)); + 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); + evas_object_show(popup); + + genlist = elm_genlist_add(popup); + p_retm_if(NULL == genlist, "elm_genlist_add() return NULL"); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(genlist, "cdetail_d", cdetail_d); + + EINA_LIST_FOREACH(cdetail_d->list_contacts, l, record_contact) { + err = contacts_record_get_int(record_contact, _contacts_contact.id, &contact_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_get_int(record_contact, _contacts_contact.address_book_id, &addressbook_id); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_db_get_record(_contacts_address_book._uri, addressbook_id, &record_addressbook); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + err = contacts_record_get_int(record_addressbook, _contacts_address_book.mode, &addressbook_mode); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int() Failed(%d)", err); + + err = contacts_record_destroy(record_addressbook, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + + if (CONTACTS_ADDRESS_BOOK_MODE_READONLY == addressbook_mode) + continue; + + person_info = calloc(1, sizeof(ct_detail_person_data)); + if (NULL == person_info) { + ERR("calloc() return NULL"); + break; + } + person_info->contact_id = contact_id; + person_info->addressbook_id = addressbook_id; + + item = elm_genlist_item_append(genlist, &detail_itcs[DETAIL_ITC_EDIT_POPUP], person_info, + NULL, ELM_GENLIST_ITEM_NONE, detail_gl_edit_item_sel, person_info); + + person_info->item = item; + } + + evas_object_show(genlist); + elm_object_content_set(popup, genlist); +} + +static void detail_delete_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_detail_data *cdetail_d = data; + if (cdetail_d->popup) + evas_object_del(cdetail_d->popup); + + if (cdetail_d->list_contacts && 1 < eina_list_count(cdetail_d->list_contacts)) + phone_create_confirm_popup(&cdetail_d->popup, cdetail_d->win, + T_(CT_GET_TEXT_BASE_OP, CTTEXT_ALL_LINKED_CONTACTS_WILL_BE_DELETED), + detail_delete_person_response_cb, cdetail_d); + else + phone_create_confirm_popup(&cdetail_d->popup, cdetail_d->win, + S_(PH_SYS_POP_DELETE_Q), + detail_delete_person_response_cb, cdetail_d); +} + + + + +static void detail_history_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Theme *th; + ct_detail_data *cdetail_d = data; + + ct_history_data *chistory_d= calloc(1, sizeof(ct_history_data)); + p_retm_if(NULL == chistory_d, "Fail to calloc ct_history_data"); + + chistory_d->win = cdetail_d->win; + chistory_d->navi = cdetail_d->navi; + chistory_d->person_id = cdetail_d->person_id; + chistory_d->formatter = cdetail_d->formatter; + chistory_d->view_mode = DETAIL_VIEW_MODE_HISTORY; + + th = elm_theme_new(); + elm_theme_ref_set(th, NULL); + elm_theme_extension_add(th, DETAIL_THEME_EDJ); + chistory_d->th = th; + + ct_detail_history_create_itcs(); + phone_detail_log_generate_date_format(chistory_d->hformatter); + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + if (!chistory_d->list) + ct_detail_history_load_data(chistory_d); + + ct_detail_history_fill_layout(chistory_d); +} + +static char* detail_get_addressbook_icon_path(int addressbook_id) +{ + int ret; + int account_id; + char *icon_path; + account_h account; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + err = contacts_db_get_record(_contacts_address_book._uri, addressbook_id, &record); + p_retvm_if(CONTACTS_ERROR_NONE != err, NULL, "contacts_db_get_record() Failed(%d)", err); + + err = contacts_record_get_int(record, _contacts_address_book.account_id, &account_id); + if (CONTACTS_ERROR_NONE != err) { + ERR("contacts_record_get_int() Failed(%d)", err); + err = contacts_record_destroy(record, true); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_destroy() Failed(%d)", err); + return NULL; + } + account = NULL; + ret = account_create(&account); + p_retvm_if(ACCOUNT_ERROR_NONE != ret, false, "account_create() Failed(%d)", ret); + + ret = account_query_account_by_account_id(account_id, &account); + if (ACCOUNT_ERROR_NONE != ret) { + ERR("account_query_account_by_account_id() Failed(%d)", ret); + account_destroy(account); + account_disconnect(); + return NULL; + } + p_retvm_if(ACCOUNT_ERROR_NONE != ret, NULL, "account_query_account_by_account_id() Failed(%d)", ret); + + ret = account_get_icon_path(account, &icon_path); + if (ACCOUNT_ERROR_NONE != ret) { + ERR("account_get_icon_path() Failed(%d)", ret); + account_destroy(account); + account_disconnect(); + return NULL; + } + account_destroy(account); + + return icon_path; +} + +static void detail_init_account_data(ct_detail_data *cdetail_d, ct_activity_data *cactivity_d) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + int i = 0; + int addressbook_id = 0; + bool addressbook_exist = false; + Eina_List *l = NULL; + ct_ab_map acc_types[CT_MAX_ADDRBOOK]; + char *addressbook_ids = NULL; + Eina_List *addressbook_id_list; + int ret; + + err = contacts_record_get_str(cdetail_d->person, _contacts_person.addressbook_ids, &addressbook_ids); + p_retm_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_str() Failed(%d)", err); + addressbook_id_list = ctui_get_addressbook_id_list(addressbook_ids, " "); + + ret = account_connect(); + p_retm_if(ACCOUNT_ERROR_NONE != ret, "account_connect() Failed(%d)", ret); + + EINA_LIST_FOREACH(addressbook_id_list, l, addressbook_id) { + acc_types[i].icon_path = detail_get_addressbook_icon_path(addressbook_id); + acc_types[i].id = addressbook_id; + i++; + if (i == sizeof(acc_types)/sizeof(*acc_types)) + break; + } + cactivity_d->acc_cnt = i; + cactivity_d->acc_types = realloc(cactivity_d->acc_types, i * sizeof(ct_ab_map)); + p_retm_if(NULL == cactivity_d->acc_types, "realloc() return NULL"); + + memcpy(cactivity_d->acc_types, acc_types, i * sizeof(ct_ab_map)); + ret = account_disconnect(); + p_warn_if(ACCOUNT_ERROR_NONE != ret, "account_disconnect() Failed(%d)", ret); +} + +static void detail_activity_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Theme *th; + ct_detail_data *cdetail_d = data; + + ct_activity_data *cactivity_d= calloc(1, sizeof(ct_activity_data)); + p_retm_if(NULL == cactivity_d, "Fail to calloc ct_activity_data"); + + cactivity_d->win = cdetail_d->win; + cactivity_d->navi = cdetail_d->navi; + cactivity_d->person_id = cdetail_d->person_id; + cactivity_d->formatter = cdetail_d->formatter; + + th = elm_theme_new(); + elm_theme_ref_set(th, NULL); + elm_theme_extension_add(th, DETAIL_THEME_EDJ); + cactivity_d->th = th; + + ct_detail_activity_create_itcs(); + phone_detail_log_generate_date_format(cactivity_d->hformatter); + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + detail_init_account_data(cdetail_d, cactivity_d); + if (!cactivity_d->list) + ct_detail_activity_load_data(cactivity_d); + + ct_detail_activity_fill_layout(cactivity_d); +} + +static void detail_more_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_list_h list_activity = NULL; + contacts_list_h list_history = NULL; + unsigned int count; + int rotate; + ct_detail_data *cdetail_d = data; + int x,y,w,h; + + if (cdetail_d->popup) + ct_detail_popup_hide_cb(cdetail_d, NULL, NULL); + + cdetail_d->popup = elm_ctxpopup_add(cdetail_d->navi); + p_retm_if(NULL == cdetail_d->popup, "elm_ctxpopup_add() return NULL"); + + rotate = (int)evas_object_data_get(cdetail_d->navi, "phone_rotate"); + if (0 == rotate || 180 == rotate) + elm_ctxpopup_direction_priority_set(cdetail_d->popup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UP, + ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT); + + evas_object_smart_callback_add(cdetail_d->popup, "dismissed", ct_detail_popup_hide_cb, cdetail_d); + + err = phone_cts_get_list(_contacts_person_phone_log._uri, _contacts_person_phone_log.person_id, cdetail_d->person_id, &list_history); + p_retm_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_list(list_activity) Failed(%d)", err); + contacts_list_get_count(list_history, &count); + + if (CONTACTS_ERROR_NONE == err && 0 < count) + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASIC, CTTEXT_HISTORY), NULL, + detail_history_clicked_cb, cdetail_d); + + err = phone_cts_get_list(_contacts_contact_activity._uri, _contacts_contact_activity.person_id, cdetail_d->person_id, &list_activity); + p_retm_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_list(list_activity) Failed(%d)", err); + contacts_list_get_count(list_activity, &count); + + if (CONTACTS_ERROR_NONE == err && 0 < count) + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASIC, CTTEXT_ACTIVITIES), NULL, + detail_activity_clicked_cb, cdetail_d); + + //Edit + if (!ct_detail_person_get_readonly(cdetail_d->list_contacts)) { + elm_ctxpopup_item_append(cdetail_d->popup, S_(PH_SYS_SK_EDIT), NULL, + detail_edit_cb, cdetail_d); + } + + //Delete + elm_ctxpopup_item_append(cdetail_d->popup, S_(PH_SYS_SK_DELETE), NULL, + detail_delete_cb, cdetail_d); + + //Link + if ( eina_list_count(cdetail_d->list_contacts) < 10 ) { + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASE_OP, CTTEXT_LINK_CONTACTS), NULL, + detail_link_cb, cdetail_d); + } + + //Unlink + if (cdetail_d->list_contacts && 1 < eina_list_count(cdetail_d->list_contacts)) { + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASE_OP, CTTEXT_UNLINK), NULL, + detail_unlink_cb, cdetail_d); + } + + + //Send namecard + if (CONTACTS_ADDRESS_BOOK_MODE_READONLY != cdetail_d->base_ab_mode) { + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASE_OP, CTTEXT_SEND_NAME_CARD), NULL, + detail_send_name_card_cb, cdetail_d); + } + + //Default Number + if (eina_list_count(cdetail_d->list_number) > 1){ + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASE_OP, CTTEXT_SET_DEFAULT_NUMBER), NULL, + __detail_click_default_number, cdetail_d); + } + + //Default Email + if (eina_list_count(cdetail_d->list_email) > 1){ + elm_ctxpopup_item_append(cdetail_d->popup, T_(CT_GET_TEXT_BASE_OP, CTTEXT_SET_DEFAULT_EMAIL), NULL, + __detail_click_default_email, cdetail_d); + } + evas_object_geometry_get(cdetail_d->ctrl_button, &x, &y, &w, &h); + evas_object_move(cdetail_d->popup, w/2, y+h/2); + evas_object_show(cdetail_d->popup); +} + +void ct_detail_set_navi(ct_detail_data *cdetail_d, int mode) +{ + Evas_Object *toolbar_button = NULL; + + cdetail_d->view_mode = mode; + p_retm_if(NULL == cdetail_d->navi_item, "navi item is NULL"); + + phone_navi_item_clear(cdetail_d->navi_item); + + switch (mode) { + case DETAIL_VIEW_MODE_INFO: + detail_make_back_btn(cdetail_d); + if (CONTACTS_ADDRESS_BOOK_MODE_READONLY != cdetail_d->base_ab_mode) { + cdetail_d->ctrl_button = ctui_create_more_btn(cdetail_d->navi, detail_more_btn_clicked_cb, cdetail_d); + elm_object_item_part_content_set(cdetail_d->navi_item, "toolbar_more_btn", cdetail_d->ctrl_button); + } + break; + case DETAIL_VIEW_MODE_VCARD: + detail_make_back_btn(cdetail_d); + + toolbar_button = phone_create_toolbar_btn(cdetail_d->navi, S_(PH_SYS_OPT_ADD_TO_CONTACTS), detail_edit_cb, cdetail_d); + elm_object_item_part_content_set(cdetail_d->navi_item, "toolbar_button1", toolbar_button); + + break; + case DETAIL_VIEW_MODE_GAL: + detail_make_back_btn(cdetail_d); + break; + default: + break; + } +} + +Evas_Object* ct_detail_create_content(ct_detail_data *cdetail_d) +{ + Elm_Theme *th; + Evas_Object *bg; + Evas_Object *base; + Evas_Object *layout; + Evas_Object *genlist; + contacts_error_e err = CONTACTS_ERROR_NONE; + + th = elm_theme_new(); + elm_theme_ref_set(th, NULL); + elm_theme_extension_add(th, DETAIL_THEME_EDJ); + cdetail_d->th = th; + + if (cdetail_d->person_id) { + err = contacts_db_get_current_version(&(cdetail_d->view_create_version)); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_current_version() Failed(%d)", err); + + err = contacts_db_get_record(_contacts_person._uri, cdetail_d->person_id, &(cdetail_d->person)); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_get_record() Failed(%d)", err); + + cdetail_d->list_contacts = ctui_person_get_contact_list(cdetail_d->person_id); + + err = contacts_db_add_changed_cb(_contacts_contact._uri, ct_detail_contact_changed, cdetail_d); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_add_changed_cb() Failed(%d)", err); + + err = contacts_db_add_changed_cb(_contacts_group._uri, detail_group_changed, cdetail_d); + p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_db_add_changed_cb() Failed(%d)", err); + } + else if (cdetail_d->contact && NULL == cdetail_d->list_contacts) { + cdetail_d->list_contacts = eina_list_append(cdetail_d->list_contacts, cdetail_d->contact); + } + + detail_create_itcs(); + cdetail_d->formatter = ct_detail_init_time_formatter(); + + base = elm_layout_add(cdetail_d->navi); + p_retvm_if(NULL == base, NULL, "elm_layout_add() return NULL"); + elm_layout_file_set(base, SELECTION_INFO_EDJ, "selectioninfo_layout"); + layout = phone_create_base_layout(base, false); + elm_object_part_content_set(base, "contents", layout); + cdetail_d->layout = base; + bg = phone_create_bg(layout); + if (NULL == bg) { + ERR("phone_create_bg() return NULL"); + evas_object_del(cdetail_d->layout); + return NULL; + } + elm_object_style_set(bg, "group_list"); + phone_detail_log_init_time_format(); + genlist = ctui_detail_genlist_update(cdetail_d); + elm_object_part_content_set(layout, "elm.swallow.content", genlist); + + evas_object_data_set(cdetail_d->navi, "cdetail_d", cdetail_d); + evas_object_event_callback_add(cdetail_d->layout, EVAS_CALLBACK_DEL, detail_view_delete_cb, cdetail_d); + cdetail_d->has_detail = true; + + + return cdetail_d->layout; +} |