/* * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved * * This file is part of ug-contacts-efl * * Written by Youngjae Shin * Donghee Ye * Sunggoo Kim * * PROPRIETARY/CONFIDENTIAL * * This software is the confidential and proprietary information of * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with SAMSUNG ELECTRONICS. * SAMSUNG make no representations or warranties about the suitability * of the software, either express or implied, including but not limited * to the implied warranties of merchantability, fitness for a particular * purpose, or non-infringement. SAMSUNG shall not be liable for any * damages suffered by licensee as a result of using, modifying or * distributing this software or its derivatives. * */ #include #include #include "contacts.h" #include "ct-list.h" #include "ct-list-utils.h" #include "ct-list-view-ug.h" #include "ct-list-contact-view.h" #define TIMER_DURATION 0.2 static inline void list_edit_realized_items_checked_set(Evas_Object *genlist, Eina_Bool checked) { Elm_Object_Item *item; item = elm_genlist_first_item_get(genlist); while (item) { ct_contact_list *info = elm_object_item_data_get(item); item = elm_genlist_item_next_get(item); if (NULL == info) { ERR("elm_object_item_data_get() return NULL"); continue; } info->checked = checked; } elm_genlist_realized_items_update(genlist); } static inline void list_edit_all_items_checked_set(Eina_List *list, Eina_Bool checked) { Eina_List *l; ct_contact_list *info; EINA_LIST_FOREACH(list, l, info) { if (NULL == info) { ERR("elm_object_item_data_get() return NULL"); continue; } info->checked = checked; } } void ct_list_edit_mode_end(ct_list_data *clist_d) { Evas_Object *layout; Evas_Object *en; char buf[CT_TEXT_SHORT_LEN]; clist_d->list_mode = CT_LIST_VIEW_NORMAL; if (clist_d->select_all_checkbox) { layout = evas_object_data_get(clist_d->select_all_checkbox, "layout"); elm_box_unpack(clist_d->box, layout); evas_object_del(layout); clist_d->select_all_checkbox = NULL; } clist_d->cnt_checked = 0; clist_d->select_all_checked = EINA_FALSE; list_edit_all_items_checked_set(clist_d->list, EINA_FALSE); elm_genlist_decorate_mode_set(clist_d->genlist, EINA_FALSE); ct_list_navi_set(CT_LIST_MODE_DEFAULT, clist_d); snprintf(buf, sizeof(buf), "%s (%d)", clist_d->title, clist_d->cnt_list); elm_object_item_text_set(clist_d->navi_item, buf); en = elm_object_part_content_get(clist_d->searchbar, "elm.swallow.content"); elm_entry_entry_set(en, NULL); } static void list_edit_cancel_cb(void *data, Evas_Object *obj, void *event_info) { ct_list_data *clist_d = data; ctui_hide_notify(clist_d->navi); ct_list_edit_mode_end(data); } static PTHREAD_FN list_edit_del_contacts(void *data) { Elm_Object_Item *item; ct_list_data *clist_d = data; ct_progress_info *p_info = clist_d->p_info; item = elm_genlist_first_item_get(clist_d->genlist); while (item) { ct_contact_list *info; if (!p_info->alive) { p_info->result = FALSE; break; } info = elm_object_item_data_get(item); if (info && info->checked) { if (CTS_SUCCESS != contacts_svc_delete_contact(info->id)) { p_info->result = FALSE; p_info->completed = true; break; } if (++p_info->cnt == p_info->cnt_checked_total) break; } item = elm_genlist_item_next_get(item); } pthread_exit(NULL); } static void list_edit_process_end(void *data) { ct_list_data *clist_d = data; ct_progress_info *p_info = clist_d->p_info; clist_d->p_info = NULL; if (p_info->result) ct_list_edit_mode_end(clist_d); free(p_info); } static Eina_Bool list_edit_del_timer_cb(void *data) { ct_list_data *clist_d = data; ct_progress_info *p_info = clist_d->p_info; c_retvm_if(NULL == p_info, ECORE_CALLBACK_CANCEL, "parameter(clist_d) is NULL"); if (!p_info->completed) { char count[CT_TEXT_SHORT_LEN]; char percent[CT_TEXT_SHORT_LEN]; double value = (double)p_info->cnt / (double)p_info->cnt_checked_total; if (!p_info->alive) { p_info->result = FALSE; p_info->completed = true; return ECORE_CALLBACK_RENEW; } elm_progressbar_value_set(p_info->progressbar, value); snprintf(percent, sizeof(percent), "%d%%", (int)(100.0 * (double)p_info->cnt/(double)p_info->cnt_checked_total)); snprintf(count, sizeof(count), "%d/%d", p_info->cnt, p_info->cnt_checked_total); edje_object_part_text_set(elm_layout_edje_get(p_info->layout), "elm.text.subtext1", percent); edje_object_part_text_set(elm_layout_edje_get(p_info->layout), "elm.text.subtext2", count); if (p_info->cnt == p_info->cnt_checked_total) p_info->completed = true; return ECORE_CALLBACK_RENEW; } else { int ret; const char *message; pthread_join(p_info->thread, NULL); if (TRUE == p_info->result) { message = S_(CT_SYS_POP_DELETED); ret = contacts_svc_end_trans(true); } else { message = S_(CT_SYS_POP_FAILED); ret = contacts_svc_end_trans(false); } c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); evas_object_del(clist_d->popup); list_edit_process_end(clist_d); ctui_show_notify(clist_d->navi, message, 2.0); return ECORE_CALLBACK_CANCEL; } } static void list_edit_del_cb(void *data, Evas_Object *obj, void *event_info) { int ret; ct_list_data *clist_d = data; ct_progress_info *p_info; Evas_Object *btn; p_info = calloc(1, sizeof(ct_progress_info)); c_retm_if(NULL == p_info, "calloc return NULL"); clist_d->p_info = p_info; p_info->cnt_checked_total = clist_d->cnt_checked; p_info->alive = true; p_info->result = TRUE; ret = contacts_svc_begin_trans(); if (CTS_SUCCESS != ret) { ERR("contacts_svc_begin_trans() Failed(%d)", ret); free(p_info); clist_d->p_info = NULL; return; } ret = pthread_create(&p_info->thread, NULL, list_edit_del_contacts, clist_d); if (0 != ret) { ERR("Thread creation failed(%d)", ret); free(p_info); clist_d->p_info = NULL; ret = contacts_svc_end_trans(false); c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); return; } p_info->timer = ecore_timer_add(TIMER_DURATION, list_edit_del_timer_cb, clist_d); if (NULL == p_info->timer) { ERR("ecore_timer_add() return NULL"); p_info->alive = false; pthread_join(p_info->thread, NULL); free(p_info); clist_d->p_info = NULL; ret = contacts_svc_end_trans(false); c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); return; } clist_d->popup = ctui_progressbar_popup(clist_d->win, p_info); elm_object_text_set(p_info->label, T_(CT_GET_TEXT_BASIC, CTTEXT_DELETING_CONTACTS)); btn = ctui_create_popup_button(clist_d->popup, 1, S_(CT_SYS_SK_CANCEL), ctui_progress_popup_hide_cb, &p_info->alive); evas_object_data_set(btn, "p_popup", &clist_d->popup); } enum { CT_LIST_EDIT_MOVE = 1, CT_LIST_EDIT_COPY = 2, }; struct list_ginfo{ int id_grp; int id_ab; }; static int list_copy_and_add_contact(int index, struct list_ginfo *sel_grp_info) { int cur_ab; int ret; int i = 0; CTSstruct *new_contact = NULL; GSList *list, *l; c_retvm_if(NULL == sel_grp_info, -1, "parameter is null"); ret = contacts_svc_get_contact(index, &new_contact); c_retvm_if(ret < CTS_SUCCESS, -1, "contacts_svc_get_contact is failed(%d)", ret); list = NULL; contacts_svc_struct_get_list(new_contact, CTS_CF_GROUPREL_LIST, &list); for (l=list;l;l=l->next) contacts_svc_value_set_bool(l->data, CTS_GROUPREL_VAL_DELETE_BOOL, true); cur_ab = sel_grp_info[i].id_ab; for (;sel_grp_info[i].id_ab == cur_ab && 0 < sel_grp_info[i].id_grp;i++) { CTSvalue *group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION); if (group) { contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT, sel_grp_info[i].id_grp); list = g_slist_append(list, group); } else { ERR("contacts_svc_value_new is failed: CTS_VALUE_GROUP_RELATION"); contacts_svc_struct_free(new_contact); return -1; } } if (g_slist_length(list) != 0) contacts_svc_struct_store_list(new_contact, CTS_CF_GROUPREL_LIST, list); ret = contacts_svc_insert_contact(cur_ab , new_contact); if (ret < CTS_SUCCESS){ ERR("contacts_svc_insert_contact is failed(%d)", ret); contacts_svc_struct_free(new_contact); return -1; } contacts_svc_struct_free(new_contact); return i; } static int list_edit_move_copy_contact_to_group(int contact_id, struct list_ginfo *sel_grp_info, int count, int cur_ab, int cur_grp, bool rm_cur_grp) { CTSstruct *contact; GSList *list, *cursor; int i, ret, group_count; bool changed = false; contact = NULL; ret = contacts_svc_get_contact(contact_id, &contact); c_retvm_if(ret < CTS_SUCCESS, FALSE, "contacts_svc_get_contact failed (%d)", ret); list = NULL; contacts_svc_struct_get_list(contact, CTS_CF_GROUPREL_LIST, &list); for (i=0;i < count;) { bool exist = false; int jump = 0; if (sel_grp_info[i].id_ab != cur_ab){ jump = list_copy_and_add_contact(contact_id, &sel_grp_info[i]); if (jump < 0) { ERR("list_copy_and_add_contact failed(%d)", jump); contacts_svc_struct_free(contact); return FALSE; } i += jump; continue; } for (cursor=list;cursor;cursor=cursor->next) { int grp_id = contacts_svc_value_get_int(cursor->data, CTS_GROUPREL_VAL_ID_INT); if (sel_grp_info[i].id_grp == grp_id){ exist = true; break; } } if (!exist) { CTSvalue *group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION); if (NULL == group) { ERR("contacts_svc_value_new failed : CTS_VALUE_GROUP_RELATION"); contacts_svc_struct_free(contact); return FALSE; } contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT, sel_grp_info[i].id_grp); list = g_slist_append(list, group); changed = true; } i++; } if (rm_cur_grp) { if ( 0 < cur_grp){ for (cursor = list;cursor;cursor=cursor->next) { int grp_id = contacts_svc_value_get_int(cursor->data, CTS_GROUPREL_VAL_ID_INT); if (cur_grp == grp_id) { contacts_svc_value_set_bool(cursor->data, CTS_GROUPREL_VAL_DELETE_BOOL, true); changed = true; break; } } } group_count = 0; for (cursor = list;cursor;cursor=cursor->next) { if (!contacts_svc_value_get_bool(cursor->data, CTS_GROUPREL_VAL_DELETE_BOOL)) group_count++; } } if (rm_cur_grp && 0 == group_count) ret = contacts_svc_delete_contact(contact_id); else if (changed){ contacts_svc_struct_store_list(contact, CTS_CF_GROUPREL_LIST, list); ret = contacts_svc_update_contact(contact); } contacts_svc_struct_free(contact); if (ret < CTS_SUCCESS) return FALSE; else return TRUE; } static PTHREAD_FN list_edit_move_copy_contacts(void *data) { int i; int *result_list; Elm_Object_Item *item; ct_list_data *clist_d = data; ct_group_edit_data *cgedit_d = clist_d->cgedit_d; ct_progress_info *p_info = clist_d->p_info; bool remove = false; struct list_ginfo *sel_grp_info; i = 0; item = elm_genlist_first_item_get(clist_d->genlist); result_list = calloc(clist_d->cnt_checked, sizeof(int)); while (item) { ct_contact_list *contact = elm_object_item_data_get(item); if (contact && contact->checked) result_list[i++] = contact->id; item = elm_genlist_item_next_get(item); } i = 0; item = elm_genlist_first_item_get(cgedit_d->genlist); sel_grp_info = calloc(cgedit_d->count, sizeof(struct list_ginfo)); while (item) { ct_group_list *info = elm_object_item_data_get(item); if (info && info->selected) { sel_grp_info[i].id_grp = info->id_grp; sel_grp_info[i++].id_ab = info->id_ab; } item = elm_genlist_item_next_get(item); } if (CT_LIST_EDIT_MOVE == clist_d->edit_op) remove = true; else remove = false; for (i=0;i < clist_d->cnt_checked && p_info->cnt != p_info->cnt_checked_total;i++, p_info->cnt++){ int ret; if (!p_info->alive){ p_info->result = FALSE; break; } ret = list_edit_move_copy_contact_to_group(result_list[i], sel_grp_info, cgedit_d->count, clist_d->base_ab, clist_d->base_grp, remove); if (FALSE == ret){ p_info->result = FALSE; p_info->completed = true; break; } } free(sel_grp_info); pthread_exit(NULL); } static Eina_Bool list_edit_move_copy_timer_cb(void *data) { ct_list_data *clist_d = data; ct_progress_info *p_info = clist_d->p_info; c_retvm_if(NULL == p_info, ECORE_CALLBACK_CANCEL, "parameter(ct_list_data) is NULL"); if (!p_info->completed) { char count[CT_TEXT_SHORT_LEN]; char percent[CT_TEXT_SHORT_LEN]; double value = (double)p_info->cnt / (double)p_info->cnt_checked_total; if (!p_info->alive) { p_info->result = FALSE; p_info->completed = true; return ECORE_CALLBACK_RENEW; } elm_progressbar_value_set(p_info->progressbar, value); snprintf(percent, sizeof(percent), "%d%%", (int)(100.0 * (double)p_info->cnt/(double)p_info->cnt_checked_total)); snprintf(count, sizeof(count), "%d/%d", p_info->cnt, p_info->cnt_checked_total); edje_object_part_text_set(elm_layout_edje_get(p_info->layout), "elm.text.subtext1", percent); edje_object_part_text_set(elm_layout_edje_get(p_info->layout), "elm.text.subtext2", count); if (p_info->cnt == p_info->cnt_checked_total) p_info->completed = true; return ECORE_CALLBACK_RENEW; } else { int ret; const char *message; pthread_join(p_info->thread, NULL); clist_d->cgedit_d = NULL; elm_naviframe_item_pop(clist_d->navi); if (TRUE == p_info->result) { if (CT_LIST_EDIT_MOVE == clist_d->edit_op) message = S_(CT_SYS_POP_MOVED); else message = T_(CT_GET_TEXT_BASIC, CTTEXT_COPIED); ret = contacts_svc_end_trans(true); } else { message = S_(CT_SYS_POP_FAILED); ret = contacts_svc_end_trans(false); } c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); evas_object_del(clist_d->popup); list_edit_process_end(clist_d); ctui_show_notify(clist_d->navi, message, 2.0); return ECORE_CALLBACK_CANCEL; } } static void list_edit_move_copy_contacts_btn_cb(void *data, Evas_Object *obj, void *event_info) { int ret; ct_list_data *clist_d = data; ct_progress_info *p_info; Evas_Object *btn; c_retm_if(clist_d->p_info, "thread is running"); p_info = calloc(1, sizeof(ct_progress_info)); c_retm_if(NULL == p_info, "calloc return NULL"); clist_d->p_info = p_info; p_info->cnt_checked_total = clist_d->cnt_checked; p_info->alive = true; p_info->result = TRUE; ret = contacts_svc_begin_trans(); if (CTS_SUCCESS != ret) { ERR("contacts_svc_begin_trans() Failed(%d)", ret); free(p_info); clist_d->p_info = NULL; if (clist_d->cgedit_d) elm_naviframe_item_pop(clist_d->cgedit_d->navi); clist_d->cgedit_d = NULL; return; } ret = pthread_create(&p_info->thread, NULL, list_edit_move_copy_contacts, clist_d); if (0 != ret) { ERR("Thread creation failed(%d)", ret); free(p_info); clist_d->p_info = NULL; if (clist_d->cgedit_d) elm_naviframe_item_pop(clist_d->cgedit_d->navi); clist_d->cgedit_d = NULL; ret = contacts_svc_end_trans(false); c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); return; } p_info->timer = ecore_timer_add(TIMER_DURATION, list_edit_move_copy_timer_cb, clist_d); if (NULL == p_info->timer) { ERR("ecore_timer_add() return NULL"); p_info->alive = false; pthread_join(p_info->thread, NULL); free(p_info); clist_d->p_info = NULL; ret = contacts_svc_end_trans(false); c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); return; } clist_d->popup = ctui_progressbar_popup(clist_d->win, p_info); if (CT_LIST_EDIT_MOVE == clist_d->edit_op) elm_object_text_set(p_info->label, T_(CT_GET_TEXT_BASIC, CTTEXT_MOVING_CONTACTS)); else elm_object_text_set(p_info->label, T_(CT_GET_TEXT_BASIC, CTTEXT_COPYING_CONTACTS)); btn = ctui_create_popup_button(clist_d->popup, 1, S_(CT_SYS_SK_CANCEL), ctui_progress_popup_hide_cb, &p_info->alive); evas_object_data_set(btn, "p_popup", &clist_d->popup); } static void list_edit_back_btn_cb(void *data, Evas_Object *obj, void *event_info) { ct_group_edit_data *cgedit_d = data; ctui_hide_notify(cgedit_d->navi); elm_naviframe_item_pop(cgedit_d->navi); } static void list_edit_move_copy_cb(ct_list_data *clist_d) { Evas_Object *l_btn; Evas_Object *layout; ct_group_edit_data *cgedit_d; const char *title; cgedit_d = calloc(1, sizeof(ct_group_edit_data)); cgedit_d->win = clist_d->win; cgedit_d->navi = clist_d->navi; cgedit_d->base_ab = clist_d->base_ab; cgedit_d->is_move_copy_view = true; cgedit_d->grp_id = clist_d->base_grp; clist_d->cgedit_d = cgedit_d; layout = ctui_gedit_create_view(cgedit_d); if (CT_LIST_EDIT_MOVE == clist_d->edit_op) { cgedit_d->ctr_btn_info.cb = list_edit_move_copy_contacts_btn_cb; cgedit_d->ctr_btn_info.icon_path = CTUI_IMG_ICON_MOVE; cgedit_d->ctr_btn_info.user_data = clist_d; title = S_(CT_SYS_BODY_MOVE); } else { cgedit_d->ctr_btn_info.cb = list_edit_move_copy_contacts_btn_cb; cgedit_d->ctr_btn_info.icon_path = CTUI_IMG_ICON_COPY; cgedit_d->ctr_btn_info.user_data = clist_d; title = S_(CT_SYS_BODY_COPY); } l_btn = ctui_naviframe_btn(cgedit_d->navi, S_(CT_SYS_SK_CANCEL)); evas_object_smart_callback_add(l_btn, "clicked", list_edit_back_btn_cb, cgedit_d); cgedit_d->navi_it = elm_naviframe_item_push(cgedit_d->navi, title, l_btn, NULL, layout, NULL); ctui_gedit_navi_create_btn(cgedit_d); } static void list_edit_move_cb(void *data, Evas_Object *obj, void *event_info) { ct_list_data *clist_d = data; clist_d->edit_op = CT_LIST_EDIT_MOVE; list_edit_move_copy_cb(clist_d); } static void list_edit_copy_cb(void *data, Evas_Object *obj, void *event_info) { ct_list_data *clist_d = data; clist_d->edit_op = CT_LIST_EDIT_COPY; list_edit_move_copy_cb(clist_d); } void ct_list_edit_make_edit_cbar(ct_list_data *clist_d) { Evas_Object *l_btn; Elm_Object_Item *delete_item; Elm_Object_Item *move_item; Elm_Object_Item *copy_item; if (0 < clist_d->list_op) { copy_item = elm_toolbar_item_append(clist_d->cbar, CTUI_IMG_ICON_COPY, NULL, list_edit_copy_cb, clist_d); evas_object_data_set(clist_d->cbar, "copy_item", copy_item); move_item = elm_toolbar_item_append(clist_d->cbar, CTUI_IMG_ICON_MOVE, NULL, list_edit_move_cb, clist_d); evas_object_data_set(clist_d->cbar, "move_item", move_item); } delete_item = elm_toolbar_item_append(clist_d->cbar, CTUI_IMG_ICON_DELETE, NULL, list_edit_del_cb, clist_d); evas_object_data_set(clist_d->cbar, "delete_item", delete_item); if (0 >= clist_d->list_op) { ct_toolbar_disalbed_item_append(clist_d->cbar, 3); } l_btn = ctui_naviframe_btn(clist_d->navi, S_(CT_SYS_SK_CANCEL)); evas_object_smart_callback_add(l_btn, "clicked", list_edit_cancel_cb, clist_d); elm_object_item_part_content_set(clist_d->navi_item, "prev_btn", l_btn); } static int list_edit_checked_cnt_get(Eina_List *list) { int cnt = 0; Eina_List *l; ct_contact_list *contact; EINA_LIST_FOREACH(list, l, contact) { if (NULL == contact) continue; if (contact->checked) cnt++; } return cnt; } void ct_list_edit_update_selection_info(ct_list_data *clist_d) { int checked_cnt = 0; Evas_Object *notify; char buf[CT_TEXT_SHORT_LEN]; if (clist_d->ug_request) { checked_cnt = list_edit_checked_cnt_get(clist_d->list); } else { if (0 != clist_d->cnt_total && clist_d->cnt_checked == clist_d->cnt_total) elm_check_state_set(clist_d->select_all_checkbox, EINA_TRUE); else if (0 == clist_d->cnt_total || clist_d->cnt_checked != clist_d->cnt_total) elm_check_state_set(clist_d->select_all_checkbox, EINA_FALSE); checked_cnt = clist_d->cnt_checked; } if (0 == checked_cnt) { ctui_cbar_btn_disabled_set(clist_d->cbar, EINA_TRUE); notify = evas_object_data_get(clist_d->navi, "notify"); if (notify) evas_object_hide(notify); return; } else { ctui_cbar_btn_disabled_set(clist_d->cbar, EINA_FALSE); } snprintf(buf, sizeof(buf), "%s (%d)", S_(CT_SYS_POP_SELECTED), clist_d->cnt_checked); ctui_show_notify(clist_d->navi, buf, 0.0); } void ct_list_edit_select_all(ct_list_data *clist_d) { list_edit_realized_items_checked_set(clist_d->genlist, clist_d->select_all_checked); elm_genlist_realized_items_update(clist_d->genlist); if (clist_d->select_all_checked) clist_d->cnt_checked = clist_d->cnt_total; else clist_d->cnt_checked = 0; ct_list_edit_update_selection_info(clist_d); } void ct_list_item_checked_set(Elm_Object_Item *item, ct_list_data *clist_d) { ct_contact_list *contact = elm_object_item_data_get(item); c_retm_if(NULL == contact, "elm_object_item_data_get() returns NULL"); if (contact->checked) { if (clist_d->cnt_max) { if (clist_d->cnt_max <= clist_d->cnt_checked) { ctui_create_popup(clist_d->win, T_(CT_GET_TEXT_ERR, CTTEXT_EXCEED_LIMIT), 2.0); contact->checked = EINA_FALSE; return; } } clist_d->cnt_checked++; } else clist_d->cnt_checked--; elm_genlist_item_fields_update(item, "elm.edit.icon.1", ELM_GENLIST_ITEM_FIELD_CONTENT); } static void list_edit_item_check_cb(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *item; ct_contact_list *ct_info; ct_list_data *clist_d = data; ct_info = evas_object_data_get(obj, "ct_info"); c_retm_if(NULL == ct_info, "evas_object_data_get() return NULL"); item = ct_info->item; c_retm_if(NULL == item, "ct_info->item is NULL"); ct_list_item_checked_set(ct_info->item, clist_d); if (!ct_info->checked) { ct_list_edit_update_selection_info(clist_d); return; } if (CT_UG_REQUEST_CHECK_FOR_NUMBER == clist_d->ug_request) ct_list_ug_handle_check_for_number(item, clist_d); else if (CT_UG_REQUEST_CHECK_FOR_EMAIL == clist_d->ug_request) ct_list_ug_handle_check_for_email(item, clist_d); else ct_list_edit_update_selection_info(clist_d); } Evas_Object* ct_list_edit_add_check(Evas_Object *parent, Eina_Bool *checked, ct_list_data *clist_d) { Evas_Object *check = elm_check_add(parent); elm_check_state_pointer_set(check, checked); evas_object_propagate_events_set(check, EINA_FALSE); evas_object_smart_callback_add(check, "changed", list_edit_item_check_cb, clist_d); return check; } static void list_select_all_check_cb(void *data, Evas_Object *obj, void *event_info) { ct_list_edit_select_all(data); } static void list_select_all_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { int x, y, w, h; ct_list_data *clist_d = data; Evas_Event_Mouse_Up *ev = event_info; if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; evas_object_geometry_get(obj, &x, &y, &w, &h); if (ev->output.y < y || y + h < ev->output.y) return; elm_check_state_set(clist_d->select_all_checkbox, !clist_d->select_all_checked); ct_list_edit_select_all(clist_d); } void ct_list_edit_mode_start(ct_list_data *clist_d) { Evas_Object *layout; Evas_Object *check; const char *title; clist_d->list_mode = CT_LIST_VIEW_EDIT; // Append 'Select All' layout if (!clist_d->ug_request && (0 == clist_d->cnt_max || clist_d->cnt_total <= clist_d->cnt_max)) { layout = elm_layout_add(clist_d->box); elm_layout_theme_set(layout, "genlist", "item", "select_all/default"); evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_FILL); evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_UP, list_select_all_mouse_up_cb, clist_d); check = clist_d->select_all_checkbox = elm_check_add(layout); elm_check_state_pointer_set(check, &clist_d->select_all_checked); evas_object_smart_callback_add(check, "changed", list_select_all_check_cb, clist_d); evas_object_propagate_events_set(check, EINA_FALSE); elm_object_part_content_set(layout, "elm.icon", check); evas_object_data_set(clist_d->select_all_checkbox, "layout", layout); elm_object_part_text_set(layout, "elm.text", S_(CT_SYS_BODY_SELECT_ALL)); elm_box_pack_start(clist_d->box, layout); evas_object_show(layout); } elm_genlist_decorate_mode_set(clist_d->genlist, EINA_TRUE); clist_d->select_all_checked = EINA_FALSE; title = T_(CT_GET_TEXT_BASIC, CTTEXT_SELECT_CONTACTS); elm_object_item_text_set(clist_d->navi_item, title); } void ct_list_edit_button_cb(void *data, Evas_Object *obj, void *event_info) { ct_list_data *clist_d = data; c_retm_if(NULL == clist_d->navi_item, "parameter(navi_item) is NULL"); ct_list_navi_set(CT_LIST_MODE_EDIT, clist_d); if (!clist_d->ug_request) ctui_cbar_btn_disabled_set(clist_d->cbar, EINA_TRUE); ct_list_edit_mode_start(clist_d); } void ct_list_edit_check_done(void *data, Evas_Object *obj, void *event_info) { int i = 0; int cnt_checked; int *result_list; Eina_List *l; ct_contact_list *contact; ct_list_data *clist_d = data; cnt_checked = list_edit_checked_cnt_get(clist_d->list); result_list = calloc(cnt_checked, sizeof(int)); EINA_LIST_FOREACH(clist_d->list, l, contact) { if (NULL == contact || !contact->checked) continue; if (CT_UG_REQUEST_CHECK_FOR_NUMBER == clist_d->ug_request) result_list[i++] = contact->id_ret; else if (CT_UG_REQUEST_CHECK_FOR_EMAIL == clist_d->ug_request) result_list[i++] = contact->id_ret; else result_list[i++] = contact->id; } if (CT_UG_REQUEST_CHECK_FOR_NUMBER == clist_d->ug_request) ct_list_ug_return_ids(clist_d->ug, result_list, cnt_checked, CT_UG_BUNDLE_RESULT_NUMBER_ID_LIST); else if (CT_UG_REQUEST_CHECK_FOR_EMAIL == clist_d->ug_request) ct_list_ug_return_ids(clist_d->ug, result_list, cnt_checked, CT_UG_BUNDLE_RESULT_EMAIL_ID_LIST); else ct_list_ug_return_ids(clist_d->ug, result_list, cnt_checked, CT_UG_BUNDLE_RESULT_CONTACT_ID_LIST); free(result_list); ug_destroy_me(clist_d->ug); }