diff options
Diffstat (limited to 'lib/common/ct-group-edit-view.c')
-rwxr-xr-x | lib/common/ct-group-edit-view.c | 832 |
1 files changed, 832 insertions, 0 deletions
diff --git a/lib/common/ct-group-edit-view.c b/lib/common/ct-group-edit-view.c new file mode 100755 index 0000000..e297a08 --- /dev/null +++ b/lib/common/ct-group-edit-view.c @@ -0,0 +1,832 @@ +/* + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * This file is part of ug-contacts-efl + * + * Written by Youngjae Shin <yj99.shin@samsung.com> + * Donghee Ye <donghee.ye@samsung.com> + * Sunggoo Kim <sung.goo.kim@samsung.com> + * + * 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 "contacts.h" +#include "ct-list.h" + +enum GEDIT_ITC_TYPE{ + GEDIT_ITC_ADDRBOOK, + GEDIT_ITC_GROUP, + GEDIT_ITC_GROUP_CREATE, + GEDIT_ITC_BTN, + GEDIT_ITC_SEPARATOR, +}; + +static Elm_Genlist_Item_Class gedit_itcs[] = { + {.item_style="dialogue/title"}, + {.item_style="dialogue/1text.2icon.2"}, + {.item_style="dialogue/1text"}, + {.item_style="dialogue/bg/1icon"}, + {.item_style="dialogue/separator/10"}, +}; + +static void gedit_popup_hide_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_group_edit_data *gedit_d = data; + + evas_object_del(gedit_d->popup); + gedit_d->popup = NULL; +} + +static void gedit_gl_del(void *data, Evas_Object *obj) +{ + ct_group_list *info = data; + c_retm_if(NULL == data, "data is NULL"); + + free(info->name); + free(info); +} + +enum +{ + DELETE_GROUP_ONLY, + DELETE_GROUP_WITH_MEMBER, +}; + +static void gedit_notify_update(ct_group_edit_data *cgedit_d) +{ + Evas_Object *notify; + if (0 < cgedit_d->count) { + char buf[CT_TEXT_SHORT_LEN]; + snprintf(buf, sizeof(buf), "%s (%d)", S_(CT_SYS_POP_SELECTED), cgedit_d->count); + notify = ctui_show_notify(cgedit_d->navi, buf, 0.0); + } + else { + notify = evas_object_data_get(cgedit_d->navi, "notify"); + if (notify) + evas_object_hide(notify); + } +} + + +static void gedit_navi_item_update(ct_group_edit_data *cgedit_d) +{ + if (0 < cgedit_d->count) + elm_object_item_disabled_set(cgedit_d->btn_op, EINA_FALSE); + else + elm_object_item_disabled_set(cgedit_d->btn_op, EINA_TRUE); +} + + +static void gedit_navi_item_clear(Elm_Object_Item *item) +{ + Evas_Object *btn; + + btn = elm_object_item_part_content_get(item, "title_left_btn"); + if (btn) + evas_object_del(btn); + + btn = elm_object_item_part_content_get(item, "title_right_btn"); + if (btn) + evas_object_del(btn); +} + +static void gedit_gl_sel(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *genlist; + ct_group_edit_data *cgedit_d; + ct_group_list *info = data; + + elm_genlist_item_selected_set(event_info, EINA_FALSE); + + c_retm_if(NULL == data, "data is NULL"); + + genlist = elm_object_item_widget_get(info->item); + cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + if (EINA_FALSE == elm_genlist_decorate_mode_get(genlist) + || EINA_TRUE == elm_genlist_item_flip_get(info->item)) + return; + + info->selected = !info->selected; + elm_genlist_item_update(info->item); + + if (EINA_TRUE == info->selected) + cgedit_d->count++; + else + cgedit_d->count--; + + gedit_navi_item_update(cgedit_d); + gedit_notify_update(cgedit_d); +} + +static void gedit_group_delete(int op_code, Evas_Object *genlist) +{ + int ret; + bool completed = true; + Elm_Object_Item *item; + GSList *deleted = NULL; + ct_group_edit_data *cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + gedit_popup_hide_cb(cgedit_d, NULL, NULL); + + ret = contacts_svc_begin_trans(); + c_retm_if(CTS_SUCCESS != ret, "contacts_svc_begin_trans() Failed(%d)", ret); + + item = elm_genlist_first_item_get(genlist); + while (item) { + ct_group_list *info = elm_object_item_data_get(item); + if (info && info->selected) { + if (DELETE_GROUP_WITH_MEMBER == op_code) { + ret = contacts_svc_delete_group_with_members(info->id_grp); + if (CTS_SUCCESS != ret) { + ERR("Error : contacts_svc_delete_group_with_members() Failed(%d)", ret); + completed = false; + break; + } + } + else { + ret = contacts_svc_delete_group(info->id_grp); + if (CTS_SUCCESS != ret) { + ERR("Error : contacts_svc_delete_group() Failed(%d)", ret); + completed = false; + break; + } + } + deleted = g_slist_append (deleted, item); + } + item = elm_genlist_item_next_get(item); + } + + if (completed) { + GSList *l; + ret = contacts_svc_end_trans(true); + c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); + for (l=deleted; l; l=l->next) { + elm_object_item_del(l->data); + cgedit_d->count--; + } + if (deleted) + g_slist_free(deleted); + + ctui_show_notify(cgedit_d->navi, S_(CT_SYS_POP_DELETED), 2.0); + elm_naviframe_item_pop(cgedit_d->navi); + } + else { + ret = contacts_svc_end_trans(false); + c_warn_if(ret < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret); + ctui_show_notify(cgedit_d->navi, S_(CT_SYS_POP_FAILED), 2.0); + } +} + +static void gedit_group_delete_only(void *data, Evas_Object *obj, void *event_info) +{ + gedit_group_delete(DELETE_GROUP_ONLY, data); +} + +static void gedit_group_delete_with_member(void *data, Evas_Object *obj, void *event_info) +{ + gedit_group_delete(DELETE_GROUP_WITH_MEMBER, data); +} + +static void gedit_group_delete_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *popup; + Evas_Object *list; + Evas_Object *genlist = data; + ct_group_edit_data *cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + popup = elm_popup_add(cgedit_d->navi); + elm_object_style_set(popup, "min_liststyle"); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + ctui_create_popup_button(popup, 1, S_(CT_SYS_POP_CLOSE), gedit_popup_hide_cb, cgedit_d); + + list = elm_list_add(popup); + elm_list_item_append(list, T_(CT_GET_TEXT_BASIC, CTTEXT_REMOVE_GROUP_ONLY), + NULL, NULL, gedit_group_delete_only, data); + elm_list_item_append(list, T_(CT_GET_TEXT_BASIC, CTTEXT_REMOVE_GROUP_WITH_MEMBER), + NULL, NULL, gedit_group_delete_with_member, data); + elm_list_mode_set(list, ELM_LIST_EXPAND); + elm_object_content_set(popup, list); + + cgedit_d->popup = popup; + evas_object_show(popup); +} + + +static void gedit_navi_item_disabled_set(Elm_Object_Item *item, Eina_Bool disabled) +{ + Evas_Object *btn; + btn = elm_object_item_part_content_get(item, "title_left_btn"); + c_retm_if(NULL == btn, "elm_object_item_part_content_get() return NULL"); + elm_object_focus_set(btn, EINA_FALSE); + elm_object_disabled_set(btn, disabled); +} + + +static void gedit_entry_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + char *text; + Evas_Object *genlist; + ct_group_list *info = data; + ct_group_edit_data *cgedit_d; + + genlist = elm_object_item_widget_get(info->item); + cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + c_ret_if(cgedit_d->name_old); + + text = ctui_entry_markup_to_utf8(elm_entry_entry_get(obj)); + c_retm_if(NULL == text, "ctui_entry_markup_to_utf8() return NULL"); + + if (*text && strcmp(info->name, text)) + gedit_navi_item_disabled_set(cgedit_d->navi_it, EINA_FALSE); + else + gedit_navi_item_disabled_set(cgedit_d->navi_it, EINA_TRUE); + + free(text); +} + + +static void gedit_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); +} + +void ctui_gedit_navi_create_btn(ct_group_edit_data *cgedit_d) +{ + Eina_Bool disable; + Evas_Object *cbar; + Evas_Object *l_btn; + + disable = (0 < cgedit_d->count) ? EINA_FALSE: EINA_TRUE; + + cbar = elm_toolbar_add(cgedit_d->navi); + c_retm_if(NULL == cbar, "elm_toolbar_add() return NULL"); + elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND); + + cgedit_d->btn_op = elm_toolbar_item_append(cbar, cgedit_d->ctr_btn_info.icon_path, NULL, + cgedit_d->ctr_btn_info.cb, cgedit_d->ctr_btn_info.user_data); + + ct_toolbar_disalbed_item_append(cbar, 3); + + elm_object_item_disabled_set(cgedit_d->btn_op, disable); + elm_object_item_part_content_set(cgedit_d->navi_it, "controlbar", cbar); + + l_btn = ctui_naviframe_btn(cgedit_d->navi, S_(CT_SYS_SK_CANCEL)); + evas_object_smart_callback_add(l_btn, "clicked", gedit_back_btn_cb, cgedit_d); + elm_object_item_part_content_set(cgedit_d->navi_it, "prev_btn", l_btn); +} + +static void gedit_redraw_genlist(ct_group_edit_data *cgedit_d) +{ + Evas_Object *genlist = cgedit_d->genlist; + Elm_Object_Item *item; + + gedit_navi_item_clear(cgedit_d->navi_it); + ctui_gedit_navi_create_btn(cgedit_d); + + item = elm_genlist_first_item_get(genlist); + while (item) { + elm_object_item_disabled_set(item, EINA_FALSE); + item = elm_genlist_item_next_get(item); + } + cgedit_d->is_rename = false; +} + +static int gedit_group_create(int id_ab, const char *grp_name, ct_group_edit_data *cgedit_d) +{ + int ret = CTS_ERR_FAIL; + + if (*grp_name) { + CTSvalue *group; + group = contacts_svc_value_new(CTS_VALUE_GROUP); + contacts_svc_value_set_str(group, CTS_GROUP_VAL_NAME_STR, grp_name); + ret = contacts_svc_insert_group(id_ab, group); + contacts_svc_value_free(group); + } + + return ret; +} + +static int gedit_group_rename(int grp_id, const char *grp_name, ct_group_edit_data *cgedit_d) +{ + int ret; + int ret_trans; + CTSvalue *group; + bool success = true; + + ret = contacts_svc_begin_trans(); + if (ret < CTS_SUCCESS) + return ret; + + if (*grp_name) { + ret = contacts_svc_get_group(grp_id, &group); + if (CTS_SUCCESS != ret) { + ERR("contacts_svc_get_group(%d) Failed", ret); + success = false; + } + else { + ret = contacts_svc_value_set_str(group, CTS_GROUP_VAL_NAME_STR, grp_name); + if (CTS_SUCCESS != ret) { + ERR("contacts_svc_value_set_str() Failed(%d)", ret); + success = false; + } + else { + ret = contacts_svc_update_group(group); + if (ret < CTS_SUCCESS) + success = false; + } + contacts_svc_value_free(group); + } + if (cgedit_d->popup) + evas_object_smart_callback_add(cgedit_d->popup, "timeout", gedit_popup_hide_cb, cgedit_d); + } + + if (success) + ret_trans = contacts_svc_end_trans(true); + else + ret_trans = contacts_svc_end_trans(false); + c_warn_if(ret_trans < CTS_SUCCESS, "contacts_svc_end_trans() Failed(%d)", ret_trans); + + return ret; +} + +static void gedit_err_entry_focused_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_group_edit_data *cgedit_d = data; + evas_object_smart_callback_del(obj, "focused", gedit_err_entry_focused_cb); + ctui_entry_entry_set(obj, cgedit_d->name_old); + elm_entry_cursor_end_set(obj); + free(cgedit_d->name_old); + cgedit_d->name_old = NULL; +} + +static void gedit_entry_set_err_message(Evas_Object *entry, const char *err_msg, ct_group_edit_data *cgedit_d) { + char msg[256]; + snprintf(msg, sizeof(msg), "<color=#FF0000>%s</>", err_msg); + elm_entry_entry_set(entry, msg); + evas_object_smart_callback_add(entry, "focused", gedit_err_entry_focused_cb, cgedit_d); +} + +static void gedit_save_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + int ret; + ct_group_list *info; + Evas_Object *genlist; + Evas_Object *entry; + char *text; + ct_group_edit_data *cgedit_d; + + info = elm_object_item_data_get(data); + genlist = elm_object_item_widget_get(data); + entry = evas_object_data_get(genlist, "entry"); + + text = ctui_entry_markup_to_utf8(elm_entry_entry_get(entry)); + c_retm_if(NULL == text, "ctui_entry_markup_to_utf8() return NULL"); + + cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + if (info->id_grp) + ret = gedit_group_rename(info->id_grp, text, cgedit_d); + else { + ret = gedit_group_create(info->id_ab, text, cgedit_d); + if (CTS_SUCCESS < ret) + info->id_grp = ret; + } + + if (ret < CTS_SUCCESS) { + const char *err_msg; + cgedit_d->name_old = text; + + switch (ret) { + case CTS_ERR_DB_LOCK: + err_msg = T_(CT_GET_TEXT_ERR, CTTEXT_ERR_DB_LOCKED); + break; + case CTS_ERR_NO_SPACE: + err_msg = S_(CT_SYS_POP_NOT_ENOUGH_MEMORY); + break; + case CTS_ERR_ALREADY_EXIST: + err_msg = T_(CT_GET_TEXT_ERR, CTTEXT_ALREADY_EXIST); + break; + default: + err_msg = S_(CT_SYS_POP_FAILED); + break; + } + + gedit_entry_set_err_message(entry, err_msg, cgedit_d); + gedit_navi_item_disabled_set(cgedit_d->navi_it, EINA_TRUE); + return; + } + evas_object_data_del(genlist, "entry"); + free(text); + + elm_naviframe_item_pop(cgedit_d->navi); +} + +static void gedit_cancel_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_group_list *info = elm_object_item_data_get(data); + Evas_Object *genlist = elm_object_item_widget_get(data); + ct_group_edit_data *cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + elm_genlist_item_flip_set(data, EINA_FALSE); + + if (!info->id_grp) + elm_object_item_del(data); + + if (cgedit_d->name_old) { + free(cgedit_d->name_old); + cgedit_d->name_old = NULL; + } + gedit_redraw_genlist(cgedit_d); +} + +static void gedit_enter_name_mode(Elm_Object_Item *item, ct_group_edit_data *cgedit_d) +{ + Elm_Object_Item *tmp_item; + Evas_Object *r_btn; + Evas_Object *l_btn; + + elm_object_item_part_content_set(cgedit_d->navi_it, "controlbar", NULL); + elm_object_item_part_content_set(cgedit_d->navi_it, "prev_btn", NULL); + ctui_hide_notify(cgedit_d->navi); + + r_btn = ctui_naviframe_btn(cgedit_d->navi, S_(CT_SYS_SK_CANCEL)); + evas_object_smart_callback_add(r_btn, "clicked", gedit_cancel_btn_cb, item); + evas_object_show(r_btn); + elm_object_item_part_content_set(cgedit_d->navi_it, "title_right_btn", r_btn); + + l_btn = ctui_naviframe_btn(cgedit_d->navi, S_(CT_SYS_SK_SAVE)); + evas_object_smart_callback_add(l_btn, "clicked", gedit_save_btn_cb, item); + evas_object_show(l_btn); + elm_object_item_part_content_set(cgedit_d->navi_it, "title_left_btn", l_btn); + + tmp_item = elm_genlist_first_item_get(cgedit_d->genlist); + while (tmp_item) { + elm_object_item_disabled_set(tmp_item, EINA_TRUE); + tmp_item = elm_genlist_item_next_get(tmp_item); + } + /** Defence code for genlist bug */ + elm_object_item_disabled_set(item, EINA_FALSE); + + cgedit_d->is_rename = true; +} + +static void gedit_group_create_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + ct_group_list *info = data; + ct_group_list *new_info; + ct_group_edit_data *cgedit_d; + Evas_Object *genlist; + Elm_Object_Item *item_separator; + + genlist = elm_object_item_widget_get(info->item); + cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + if (!cgedit_d || cgedit_d->is_rename) return; + + elm_genlist_item_selected_set(info->item, EINA_FALSE); + + item_separator = elm_genlist_item_prev_get(info->item); + + new_info = calloc(1, sizeof(ct_group_list)); + new_info->id_ab = info->id_ab; + new_info->id_grp = 0; + new_info->name = strdup(""); + new_info->item = elm_genlist_item_insert_before(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_GROUP_CREATE], new_info, + elm_genlist_item_parent_get(info->item), item_separator, + ELM_GENLIST_ITEM_NONE, gedit_gl_sel, new_info); + + elm_genlist_item_flip_set(new_info->item, EINA_TRUE); + gedit_enter_name_mode(new_info->item, cgedit_d); +} + +static char* gedit_gl_label_get(void *data, Evas_Object *obj, const char *part) +{ + ct_group_list *info = data; + c_retvm_if(NULL == data, NULL, "The parameter(data) is NULL"); + + if (!strcmp(part, "elm.text") && info->name) + return strndup(info->name, CT_TEXT_MAX_LEN); + return NULL; +} + +static void gedit_check_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *genlist; + ct_group_list *info = data; + ct_group_edit_data *cgedit_d; + c_retm_if(NULL == data, "data is NULL"); + + genlist = elm_object_item_widget_get(info->item); + cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + + if (EINA_TRUE == info->selected) + cgedit_d->count++; + else + cgedit_d->count--; + + if (!cgedit_d->is_rename) { + gedit_navi_item_update(cgedit_d); + gedit_notify_update(cgedit_d); + } +} + +static void gedit_group_rename_btn_cb(void *data, Evas_Object *obj, + void *event_info) +{ + ct_group_list *info = data; + Evas_Object *genlist = elm_object_item_widget_get(info->item); + ct_group_edit_data *cgedit_d = evas_object_data_get(genlist, "cgedit_d"); + if (!cgedit_d || cgedit_d->is_rename) return; + if (info->item) { + elm_genlist_item_flip_set(info->item, EINA_TRUE); + gedit_enter_name_mode(info->item, cgedit_d); + } +} + +static Evas_Object* gedit_gl_icon_get(void *data, Evas_Object *obj, const char *part) +{ + ct_group_list *info = data; + c_retvm_if(NULL== data, NULL, "The parameter(data) is NULL"); + + if (!strcmp(part, "elm.icon")) { + Evas_Object *btn; + btn = ctui_create_btn(obj, T_(CT_GET_TEXT_BASE_OP, CTTEXT_NEW_GROUP)); + evas_object_smart_callback_add(btn, "clicked", gedit_group_create_btn_cb, info); + return btn; + } + else if (elm_genlist_decorate_mode_get(obj) && 0 <= info->id_grp) { + if (0 == strcmp(part, "elm.icon.1")) { + Evas_Object *check = elm_check_add(obj); + elm_check_state_pointer_set(check, &info->selected); + evas_object_propagate_events_set(check, EINA_FALSE); + evas_object_smart_callback_add(check, "changed", gedit_check_changed_cb, info); + return check; + } + else if (0 == strcmp(part, "elm.icon.2")) { + Evas_Object *btn = elm_button_add(obj); + evas_object_propagate_events_set(btn, EINA_FALSE); + elm_object_style_set(btn, "rename"); + evas_object_smart_callback_add(btn, "clicked", gedit_group_rename_btn_cb, info); + return btn; + } + else if (0 == strcmp(part, "elm.flip.content")) { + static Elm_Entry_Filter_Limit_Size limit_filter_data; + Evas_Object *edit_field; + Evas_Object *entry; + + edit_field = ctui_create_editfield(obj, NULL, NULL, false); + evas_object_propagate_events_set(edit_field, EINA_FALSE); + + entry = elm_object_part_content_get(edit_field, "elm.swallow.content"); + elm_object_signal_emit(edit_field, "elm,state,guidetext,hide", "elm"); + ctui_entry_entry_set(entry, info->name); + evas_object_data_set(obj,"entry", entry); + + limit_filter_data.max_char_count = 0; + limit_filter_data.max_byte_count = 20; + elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data); + evas_object_smart_callback_add(entry, "changed", gedit_entry_changed_cb, info); + + evas_object_show(entry); + elm_object_focus_set(entry, EINA_TRUE); + + return edit_field; + } + } + return NULL; +} + +static void gedit_fill_genlist_with_addrbook(ct_group_edit_data *cgedit_d, + Elm_Object_Item *parent, int id_ab) +{ + int ret; + CTSiter *iter; + ct_group_list *info; + Elm_Object_Item *item; + + ret = contacts_svc_get_list_with_int(CTS_LIST_GROUPS_OF_ADDRESSBOOK_ID, id_ab, &iter); + c_retm_if(CTS_SUCCESS != ret, "contacts_svc_get_list_with_int() Failed(%d)", ret); + + while (CTS_SUCCESS == contacts_svc_iter_next(iter)) { + CTSvalue *value; + int grp_id; + + value = contacts_svc_iter_get_info(iter); + grp_id = contacts_svc_value_get_int(value, CTS_LIST_GROUP_ID_INT); + + if (grp_id != cgedit_d->grp_id) { + info = calloc(1, sizeof(ct_group_list)); + info->id_ab = id_ab; + info->id_grp = grp_id; + info->name = contacts_svc_value_steal_str(value, CTS_LIST_GROUP_NAME_STR); + info->item = elm_genlist_item_append(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_GROUP], info, NULL, + ELM_GENLIST_ITEM_NONE, gedit_gl_sel, info); + } + contacts_svc_value_free(value); + } + contacts_svc_iter_remove(iter); + item = elm_genlist_item_append(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_SEPARATOR], NULL, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); + + // "Create group" button + info = calloc(1, sizeof(ct_group_list)); + info->id_ab = id_ab; + info->id_grp = -1; + info->item = elm_genlist_item_append(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_BTN], info, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + + item = elm_genlist_item_append(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_SEPARATOR], NULL, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); +} + +static void gedit_fill_genlist_with_all_addrbook(ct_group_edit_data *cgedit_d) +{ + int ret; + CTSiter *iter; + ct_group_list *info; + Evas_Object *genlist = cgedit_d->genlist; + + // phone group + info = calloc(1, sizeof(ct_group_list)); + info->id_ab = 0; + info->name = strdup(T_(CT_GET_TEXT_BASIC, CTTEXT_PHONE)); + info->item = elm_genlist_item_append(genlist, &gedit_itcs[GEDIT_ITC_ADDRBOOK], info, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + gedit_fill_genlist_with_addrbook(cgedit_d, info->item, info->id_ab); + + ret = contacts_svc_get_list(CTS_LIST_ALL_ADDRESSBOOK, &iter); + c_retm_if(CTS_SUCCESS != ret, "contacts_svc_get_list() Failed(%d)", ret); + + while (CTS_SUCCESS == contacts_svc_iter_next(iter)) { + int mode; + CTSvalue *ab; + ct_group_list *info; + + info = calloc(1, sizeof(ct_group_list)); + if (NULL == info) { + ERR("calloc() return NULL"); + continue; + } + + ab = contacts_svc_iter_get_info(iter); + mode = contacts_svc_value_get_int(ab, CTS_LIST_ADDRESSBOOK_MODE_INT); + if (CTS_ADDRESSBOOK_MODE_READONLY == mode) { + free(info); + ret = contacts_svc_value_free(ab); + c_warn_if(CTS_SUCCESS != ret, "contacts_svc_value_free() Failed(%d)", ret); + continue; + } + + info->id_ab = contacts_svc_value_get_int(ab, CTS_LIST_ADDRESSBOOK_ID_INT); + info->name = contacts_svc_value_steal_str(ab, CTS_LIST_ADDRESSBOOK_NAME_STR); + info->item = elm_genlist_item_append(cgedit_d->genlist, &gedit_itcs[GEDIT_ITC_ADDRBOOK], info, NULL, + ELM_GENLIST_ITEM_NONE, NULL, NULL); + gedit_fill_genlist_with_addrbook(cgedit_d, info->item, info->id_ab); + + ret = contacts_svc_value_free(ab); + c_warn_if(CTS_SUCCESS != ret, "contacts_svc_value_free() Failed(%d)", ret); + } + contacts_svc_iter_remove(iter); +} + +static void gedit_group_changed(void *data) +{ + ct_group_edit_data *cgedit_d = data; + + elm_genlist_clear(cgedit_d->genlist); + cgedit_d->count = 0; + if (elm_genlist_decorate_mode_get(cgedit_d->genlist) == EINA_FALSE) + elm_genlist_decorate_mode_set(cgedit_d->genlist, EINA_TRUE); + + ctui_genlist_append_separator_20px(cgedit_d->genlist); + + if (-1 == cgedit_d->base_ab || cgedit_d->is_move_copy_view) + gedit_fill_genlist_with_all_addrbook(cgedit_d); + else + gedit_fill_genlist_with_addrbook(cgedit_d, NULL, cgedit_d->base_ab); + + if (cgedit_d->is_rename) + gedit_redraw_genlist(cgedit_d); + else + gedit_navi_item_update(cgedit_d); +} + +static void gedit_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + int ret; + ct_group_edit_data *cgedit_d = data; + + ret = contacts_svc_unsubscribe_change_with_data(CTS_SUBSCRIBE_GROUP_CHANGE, gedit_group_changed, cgedit_d); + c_warn_if(CTS_SUCCESS != ret, "contacts_svc_unsubscribe_change_with_data() Failed(%d)", ret); + + free(cgedit_d->name_old); + free(cgedit_d); +} + +static void gedit_genlist_style_set(void) +{ + gedit_itcs[GEDIT_ITC_ADDRBOOK].func.text_get = gedit_gl_label_get; + gedit_itcs[GEDIT_ITC_ADDRBOOK].func.del = gedit_gl_del; + + gedit_itcs[GEDIT_ITC_GROUP].func.text_get = gedit_gl_label_get; + gedit_itcs[GEDIT_ITC_GROUP].func.content_get = gedit_gl_icon_get; + gedit_itcs[GEDIT_ITC_GROUP].func.del = gedit_gl_del; + + gedit_itcs[GEDIT_ITC_GROUP_CREATE].func.content_get = gedit_gl_icon_get; + gedit_itcs[GEDIT_ITC_GROUP_CREATE].func.del = gedit_gl_del; + + gedit_itcs[GEDIT_ITC_BTN].func.content_get = gedit_gl_icon_get; + gedit_itcs[GEDIT_ITC_BTN].func.del = gedit_gl_del; +} + +Evas_Object * ctui_gedit_create_view(ct_group_edit_data *cgedit_d) +{ + Evas_Object *conform, *base, *bg; + int ret; + + base = ctui_create_base_layout(cgedit_d->navi, false); + bg = ctui_set_bg(base); + if (NULL == bg) { + ERR("ctui_set_bg() return NULL"); + evas_object_del(base); + return NULL; + } + elm_object_style_set(bg, "group_list"); + + elm_win_conformant_set(cgedit_d->win, EINA_TRUE); + conform = elm_conformant_add(base); + elm_object_style_set(conform, "internal_layout"); + evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(conform); + + cgedit_d->genlist = elm_genlist_add(base); + elm_genlist_decorate_mode_set(cgedit_d->genlist, EINA_TRUE); + elm_genlist_select_mode_set(cgedit_d->genlist, ELM_OBJECT_SELECT_MODE_NONE); + gedit_genlist_style_set(); + evas_object_size_hint_weight_set(cgedit_d->genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(cgedit_d->genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(cgedit_d->genlist); + evas_object_data_set(cgedit_d->genlist, "cgedit_d", cgedit_d); + elm_object_content_set(conform, cgedit_d->genlist); + elm_object_part_content_set(base, "elm.swallow.content", conform); + + ctui_genlist_append_separator_20px(cgedit_d->genlist); + + if (-1 == cgedit_d->base_ab || cgedit_d->is_move_copy_view) + gedit_fill_genlist_with_all_addrbook(cgedit_d); + else + gedit_fill_genlist_with_addrbook(cgedit_d, NULL, cgedit_d->base_ab); + + evas_object_event_callback_add(base, EVAS_CALLBACK_DEL, + gedit_view_delete_cb, (void*)cgedit_d); + + ret = contacts_svc_subscribe_change(CTS_SUBSCRIBE_GROUP_CHANGE, gedit_group_changed, cgedit_d); + c_warn_if(CTS_SUCCESS != ret, "contacts_svc_subscribe_change() Failed(%d)", ret); + + return base; +} + +void ctui_gedit_push_view(Evas_Object *win, Evas_Object *navi, int id_ab) +{ + ct_group_edit_data *cgedit_d; + Evas_Object *layout; + + cgedit_d = calloc(1, sizeof(ct_group_edit_data)); + c_retm_if(NULL == cgedit_d, "calloc() return NULL"); + + cgedit_d->win = win; + cgedit_d->navi = navi; + cgedit_d->base_ab = id_ab; + cgedit_d->count = 0; + cgedit_d->is_move_copy_view = false; + + layout = ctui_gedit_create_view(cgedit_d); + + cgedit_d->ctr_btn_info.cb = gedit_group_delete_btn_cb; + cgedit_d->ctr_btn_info.icon_path= CTUI_IMG_ICON_DELETE; + cgedit_d->ctr_btn_info.user_data = cgedit_d->genlist; + + cgedit_d->navi_it = elm_naviframe_item_push(cgedit_d->navi, + T_(CT_GET_TEXT_BASE_OP, CTTEXT_SELECT_GROUP), NULL, NULL, layout, NULL); + + ctui_gedit_navi_create_btn(cgedit_d); +} + |