summaryrefslogtreecommitdiff
path: root/lib/log/ph-log-check-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/log/ph-log-check-view.c')
-rwxr-xr-xlib/log/ph-log-check-view.c324
1 files changed, 324 insertions, 0 deletions
diff --git a/lib/log/ph-log-check-view.c b/lib/log/ph-log-check-view.c
new file mode 100755
index 0000000..5b8c1bb
--- /dev/null
+++ b/lib/log/ph-log-check-view.c
@@ -0,0 +1,324 @@
+/*
+* 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 <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"
+
+
+void ph_log_check_update_button_status(ph_log_data *log_d)
+{
+ 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)
+{
+ if (log_d->cnt_checked == 0)
+ phone_hide_notify(log_d->layout);
+ else {
+ char info_text[PH_TEXT_SHORT_LEN]={0};
+ Elm_Object_Item *item;
+ int count=0;
+
+ item = elm_genlist_first_item_get(log_d->genlist);
+ while (item) {
+ Elm_Genlist_Item_Type type = elm_genlist_item_type_get(item);
+ ph_log_info *l_info = (ph_log_info*)elm_object_item_data_get(item);
+ item = elm_genlist_item_next_get(item);
+ if (ELM_GENLIST_ITEM_GROUP != type && l_info->checked)
+ count++;
+ }
+
+ snprintf(info_text, sizeof(info_text), "%s (%d)", S_(PH_SYS_POP_SELECTED),
+ count);
+ phone_show_notify(log_d->layout, info_text);
+ }
+}
+
+static void log_check_select_all(void *data, Eina_Bool checked)
+{
+ Eina_List *l;
+ ph_log_info *l_info;
+ ph_log_data *log_d = data;
+
+ 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, 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ int i = 0;
+ int *result_list;
+ Eina_List *l;
+ ph_log_info *l_info;
+ ph_log_data *log_d = data;
+
+ result_list = calloc(log_d->cnt_checked, sizeof(int));
+ EINA_LIST_FOREACH(log_d->log_list, l, 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_log_data *log_d = data;
+ ph_progress_info *p_info = log_d->p_info;
+ Eina_List *l;
+ ph_log_info *l_info;
+
+ contacts_connect_on_thread();
+
+ EINA_LIST_FOREACH(log_d->log_list, l, l_info) {
+ if (!p_info->alive) {
+ p_info->completed = true;
+ break;
+ }
+ if (!l_info) continue;
+
+ if (TRUE == l_info->checked) {
+ if (CONTACTS_ERROR_NONE != ph_log_util_del_log_by_id(log_d->log_list, l_info)) {
+ 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_log_data *log_d = 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;
+ }
+}
+
+void ph_log_check_del_btn_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ PH_FN_CALL;
+ int ret;
+ ph_log_data *log_d = data;
+ ph_progress_info *p_info;
+
+ p_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_check_changed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ ph_log_data *log_d = data;
+
+#if 0
+ if (elm_check_state_get(obj))
+ log_d->cnt_checked++;
+ else
+ log_d->cnt_checked--;
+#endif
+
+ ph_log_check_update_select_all(log_d);
+ ph_log_check_update_selection_info(log_d);
+ ph_log_check_update_button_status(log_d);
+}