diff options
Diffstat (limited to 'lib/log/ph-log-check-view.cpp')
-rwxr-xr-x | lib/log/ph-log-check-view.cpp | 425 |
1 files changed, 425 insertions, 0 deletions
diff --git a/lib/log/ph-log-check-view.cpp b/lib/log/ph-log-check-view.cpp new file mode 100755 index 0000000..7f0ff45 --- /dev/null +++ b/lib/log/ph-log-check-view.cpp @@ -0,0 +1,425 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (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 <bundle.h> +#include <ui-gadget-module.h> + +#include "phone.h" +#include "phone-log.h" +#include "ph-log-utils.h" +#include "ph-log-main-view.h" + +#include "assert.h" + +void ph_log_check_update_button_status(ph_log_data *log_d) +{ + PH_TRACE; + Eina_Bool disabled; + p_retm_if(NULL == log_d, "parameter is NULL"); + p_retm_if(NULL == log_d->ctrl_item, "ctrl_item is NULL"); + + if (0 == log_d->log_list_count) + disabled = EINA_TRUE; + else if (log_d->genlist && elm_genlist_decorate_mode_get(log_d->genlist)) + { + if (0 < log_d->cnt_checked) + disabled = EINA_FALSE; + else + disabled = EINA_TRUE; + } + else + disabled = EINA_FALSE; + + elm_object_disabled_set(log_d->ctrl_item, disabled); +} + +void ph_log_check_update_selection_info(ph_log_data *log_d) +{ + PH_TRACE; + + if (log_d->cnt_checked == 0) + phone_hide_notify(log_d->layout); + else + { + char info_text[PH_TEXT_SHORT_LEN] = { 0 }; + snprintf(info_text, sizeof(info_text), "%s (%d)", + S_(PH_SYS_POP_SELECTED), log_d->cnt_checked); + phone_show_notify(log_d->layout, info_text); + } +} + +static void log_check_select_all(void *data, Eina_Bool checked) +{ + PH_TRACE; + Eina_List *l; + ph_log_data *log_d = (ph_log_data *) data; + void *v_l_info; + + if (checked) + log_d->cnt_checked = log_d->log_list_count; + else + log_d->cnt_checked = 0; + + EINA_LIST_FOREACH(log_d->log_list, l, v_l_info) + { + ph_log_info *l_info = (ph_log_info *) v_l_info; + if (!l_info) + continue; + l_info->checked = checked; + } + elm_genlist_realized_items_update(log_d->genlist); + ph_log_check_update_selection_info(log_d); + ph_log_check_update_button_status(log_d); +} + +API void phone_log_check_mode_start(ph_log_data *log_d) +{ + PH_TRACE; + Elm_Object_Item * item; + p_retm_if(NULL == log_d, "log data is NULL"); + + if (log_d->item_last_sweep) + { + elm_genlist_item_decorate_mode_set(log_d->item_last_sweep, "slide", + EINA_FALSE); + elm_genlist_item_select_mode_set(log_d->item_last_sweep, + ELM_OBJECT_SELECT_MODE_DEFAULT); + log_d->item_last_sweep = NULL; + } + + if (0 < log_d->log_list_count && !log_d->select_all_layout) + { + log_d->select_all_layout = phone_create_select_all(log_d->box, + S_(PH_SYS_BODY_SELECT_ALL), log_check_select_all, log_d); + elm_box_pack_start(log_d->box, log_d->select_all_layout); + } + + if (LOG_VIEW_TYPE_NORMAL == log_d->view_type) + log_d->view_type = LOG_VIEW_TYPE_NORMAL_CHECK; + + elm_genlist_decorate_mode_set(log_d->genlist, EINA_TRUE); + phone_log_set_navi(log_d->navi); + + item = elm_genlist_first_item_get(log_d->genlist); + while (item) + { + elm_genlist_item_fields_update(item, "elm.icon.3", + ELM_GENLIST_ITEM_FIELD_CONTENT); + item = elm_genlist_item_next_get(item); + } +} + +void ph_log_check_mode_end(ph_log_data *log_d, bool redraw) +{ + PH_TRACE; + Elm_Object_Item * item; + + phone_hide_notify(log_d->navi); + + elm_box_unpack(log_d->box, log_d->select_all_layout); + evas_object_del(log_d->select_all_layout); + log_d->select_all_layout = NULL; + + if (log_d->cnt_checked) + log_check_select_all(log_d, EINA_FALSE); + + if (LOG_VIEW_TYPE_NORMAL_CHECK == log_d->view_type) + { + log_d->view_type = LOG_VIEW_TYPE_NORMAL; + if (log_d->timer) + ecore_timer_del(log_d->timer); + log_d->timer = ecore_timer_add(1.0, ph_log_missed_call_count_reset, + (void*) log_d); + } + elm_genlist_decorate_mode_set(log_d->genlist, EINA_FALSE); + + if (redraw) + phone_log_set_navi(log_d->navi); + + item = elm_genlist_first_item_get(log_d->genlist); + while (item) + { + elm_genlist_item_fields_update(item, "elm.icon.3", + ELM_GENLIST_ITEM_FIELD_CONTENT); + item = elm_genlist_item_next_get(item); + } +} + +void ph_log_check_update_select_all(ph_log_data *log_d) +{ + PH_TRACE; + Eina_Bool all_check; + Evas_Object *check; + + p_retm_if(NULL == log_d->select_all_layout, "select_all_layout is NULL"); + + check = elm_object_part_content_get(log_d->select_all_layout, "elm.icon"); + p_retm_if(NULL == check, "elm_object_part_content_get() return NULL"); + + if (log_d->log_list_count == log_d->cnt_checked) + all_check = EINA_TRUE; + else + all_check = EINA_FALSE; + elm_check_state_set(check, all_check); +} + +void ph_log_check_done_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_TRACE; + int i = 0; + int *result_list; + Eina_List *l; + ph_log_data *log_d = (ph_log_data *) data; + void *v_l_info; + + result_list = (int *) calloc(log_d->cnt_checked, sizeof(int)); + EINA_LIST_FOREACH(log_d->log_list, l, v_l_info) + { + ph_log_info *l_info = (ph_log_info *) v_l_info; + if (!l_info) + continue; + if (l_info->checked) + result_list[i++] = l_info->id; + } + phone_list_ug_return_ids(log_d->ug, result_list, log_d->cnt_checked, + PH_UG_BUNDLE_RESULT_PLOG_ID_LIST); + + free(result_list); + ug_destroy_me(log_d->ug); +} + +static PTHREAD_FN log_check_del(void *data) +{ + PH_TRACE; + ph_log_data *log_d = (ph_log_data *) data; + ph_progress_info *p_info = log_d->p_info; + Eina_List *l; + void *v_l_info; + + contacts_connect_on_thread(); + + EINA_LIST_FOREACH(log_d->log_list, l, v_l_info) + { + ph_log_info *l_info = (ph_log_info *) v_l_info; + if (!p_info->alive) + { + p_info->completed = true; + break; + } + if (!l_info) + continue; + + if (TRUE == l_info->checked) + { + if (CONTACTS_ERROR_NONE + != contacts_db_delete_record(_contacts_phone_log._uri, + l_info->id)) + { + ERR("contacts_db_delete_record() failed (id=%d)", l_info->id); + p_info->completed = true; + break; + } + p_info->cnt++; + } + if (p_info->cnt == p_info->cnt_checked_total) + break; + } + + contacts_disconnect_on_thread(); + + pthread_exit (NULL); +} + +static Eina_Bool log_check_del_timer(void *data) +{ + PH_TRACE; + ph_log_data *log_d = (ph_log_data *) data; + ph_progress_info *p_info = log_d->p_info; + + p_retvm_if(NULL == p_info, ECORE_CALLBACK_CANCEL, + "parameter(ph_progress_info) is NULL"); + + if (!p_info->completed) + { + char count[PH_TEXT_SHORT_LEN]; + char percent[5]; + double value = (double) p_info->cnt + / (double) p_info->cnt_checked_total; + + 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 + { + bool deleted = false; + + pthread_join(p_info->thread, NULL); + + if (p_info->cnt == p_info->cnt_checked_total) + { + deleted = true; + } + + evas_object_del(log_d->popup); + log_d->popup = NULL; + + if (NULL != p_info) + { + free(p_info); + log_d->p_info = NULL; + } + + ph_log_check_mode_end(log_d, true); + + if (deleted) + phone_show_tickernoti(S_(PH_SYS_POP_DELETED)); + else + phone_show_tickernoti(S_(PH_SYS_POP_FAILED)); + + ph_log_data_changed_cb(log_d); + return ECORE_CALLBACK_CANCEL; + } +} + +static void ph_log_check_del_reponse_cb(void *data, Evas_Object *obj, + void *event_info) +{ + PH_TRACE; + int ret; + ph_log_data *log_d = (ph_log_data *) data; + ph_progress_info *p_info; + + p_retm_if(NULL == log_d, "log data is NULL"); + evas_object_del(log_d->popup); + log_d->popup = NULL; + + p_info = (ph_progress_info *) calloc(1, sizeof(ph_progress_info)); + p_retm_if(NULL == p_info, "calloc return NULL"); + + log_d->p_info = p_info; + p_info->cnt_checked_total = log_d->cnt_checked; + p_info->alive = true; + + ret = pthread_create(&p_info->thread, NULL, log_check_del, log_d); + if (0 != ret) + { + ERR("Thread creation failed(%d)", ret); + free(p_info); + log_d->p_info = NULL; + return; + } + + p_info->timer = ecore_timer_add(0.2, log_check_del_timer, log_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); + log_d->p_info = NULL; + return; + } + + log_d->popup = phone_progressbar_popup(log_d->win, p_info, + T_(PH_GET_TEXT_BASIC, PHTEXT_DELETING_LOGS)); +} + +void ph_log_check_del_btn_cb(void *data, Evas_Object *obj, void *event_info) +{ + PH_TRACE; + ph_log_data* log_d = (ph_log_data *) data; + ph_log_info *l_info = (ph_log_info *)log_d->log_list; + char buf[PH_TEXT_MAX_LEN] = { 0 }; + Evas_Object *btn; + + if(!log_d || !l_info) + { + return; + } + + snprintf(buf, sizeof(buf), T_(PH_GET_TEXT_BASIC, PHTEXT_DELETING_N_LOGS), log_d->cnt_checked); + btn = phone_create_confirm_popup(&log_d->popup, log_d->win, buf, + ph_log_check_del_reponse_cb, (void *) log_d); + evas_object_data_set(btn, "log_data", log_d); +} + +void ph_log_check_groupped_items(ph_log_data& logData, int logInfoId, Eina_Bool bChecked) +{ + PH_TRACE; + if (elm_genlist_decorate_mode_get(logData.genlist)) + { + Eina_List *list = NULL; + void *v_l_info = NULL; + + EINA_LIST_FOREACH(logData.log_list, list, v_l_info) + { + ph_log_info *l_info = (ph_log_info *) v_l_info; + if (l_info) + { + if (l_info->group_base_id == logInfoId) + { + l_info->checked = bChecked; + } + } + } + } +} + +void ph_log_check_check_changed_cb(void *data, Evas_Object *obj, + void *event_info) +{ + PH_TRACE; + ph_log_data *logData = (ph_log_data *) data; + ph_log_info *logInfo = (ph_log_info *) evas_object_data_get(obj, "person_info"); + + assert(logData && obj && logInfo); + if ((logData == NULL) || (obj == NULL) || (logInfo == NULL)) + { + return; + } + + if(logData) + { + ph_log_check_groupped_items(*logData, logInfo->id, logInfo->checked); + } + + if (elm_check_state_get(obj)) + { + logData->cnt_checked += logInfo->grouped_count; + } + else + { + logData->cnt_checked -= logInfo->grouped_count; + } + + ph_log_check_update_select_all(logData); + ph_log_check_update_selection_info(logData); + ph_log_check_update_button_status(logData); +} |