summaryrefslogtreecommitdiff
path: root/lib/log/ph-log-check-view.c
blob: bc151bd08521d883eda5f3c48773a37e85e1efcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* 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"


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);
}