Tizen 2.1 base
[apps/core/preloaded/calendar.git] / src / list-base.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://floralicense.org/license/
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18 #include "cld.h"
19 #include "list-base.h"
20 #include "external-ug.h"
21 #include "view.h"
22 #include "detail-view.h"
23 #include "cld-images.h"
24 #include "edit-view.h"
25
26 typedef struct {
27         struct appdata *ad;
28         Evas_Object *parent;
29         Evas_Object *genlist;
30         calendar_record_h selected_record;
31         Evas_Object *popup;
32         Ecore_Idler *popup_idler;
33         const char *searchtext;
34         Elm_Object_Item *sweep_it;
35         cal_list_callback select_item_callback;
36         void* select_item_callback_data;
37         int item_count;
38 } cal_list_base_s;
39
40 _calendar_book_color calendar_color;
41
42 static Evas_Object *__cal_list_get_genlist_loadmore_item_icon(void *data, Evas_Object *obj, const char *part)
43 {
44         c_retv_if(!data, NULL);
45
46         cal_list_base_s *p = data;
47
48         Evas_Object *progressbar = elm_progressbar_add(p->parent);
49         c_retv_if(!progressbar, NULL);
50
51         elm_object_style_set(progressbar, "list_process");
52         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
53         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54         evas_object_show(progressbar);
55         elm_progressbar_pulse(progressbar, EINA_TRUE);
56         return progressbar;
57 }
58
59 static char* __cal_list_base_share_genlist_item_label(void *data, Evas_Object *obj, const char *part)
60 {
61         c_retvm_if(!data || !obj || !part, NULL, "data is null");
62
63         char *name = (char *)data;
64
65         if (!CAL_STRCMP(part, "elm.text")) {
66                 return strdup(name);
67         }
68
69         return NULL;
70 }
71
72 static char* __cal_list_get_genlist_header_item_label(void *data, Evas_Object *obj, const char *part)
73 {
74         c_retvm_if(!data, NULL, "data is null.");
75
76         char buf[128];
77         cal_list_genlist_item_data *item_data = data;
78         const struct tm *tm = item_data->tm;
79
80         if (!CAL_STRCMP(part, "elm.text")) {
81
82                 if (item_data->todo_group_type == CAL_TASK_NO_DUE_DATE) {
83                         return strdup(C_("IDS_CLD_BODY_NO_DUE_DATE_M_NOUN"));
84                 } else if (item_data->todo_group_type == CAL_TASK_DUE_TODAY) {
85                         return strdup(C_("IDS_CLD_HEADER_DUE_TODAY"));
86                 } else if (item_data->todo_group_type == CAL_TASK_DUE_WITHIN_A_WEEK) {
87                         return strdup("Due within a week");
88                 } else if (item_data->todo_group_type == CAL_TASK_DUE_IN_OVER_ONE_WEEK) {
89                         return strdup(C_("IDS_CLD_HEADER_DUE_IN_OVER_1_WEEK"));
90                 } else if (item_data->todo_group_type == CAL_TASK_OVER_DUE) {
91                         return strdup(C_("IDS_TASK_DROP_OVERDUE"));
92                 }
93
94                 if (!tm) {
95                         return strdup(C_("IDS_CLD_BODY_REPEATING_EVENT"));
96                 } else {
97
98                         cal_util_get_time_text(buf, sizeof(buf), CAL_UTIL_DATE_FORMAT_1, NULL, tm);
99
100                         return strdup(buf);
101                 }
102         }
103
104         return NULL;
105 }
106
107 static char* __cal_list_get_genlist_custom_group_header_item_label(void *data, Evas_Object *obj, const char *part)
108 {
109         c_retvm_if(!data, NULL, "data is null.");
110
111         char buf[128];
112         cal_list_genlist_item_data *item_data = data;
113         const struct tm *tm = item_data->tm;
114
115         if (!CAL_STRCMP(part, "elm.text")) {
116                 if (!tm)
117                         return strdup("ERROR!!!");
118                 cal_util_get_time_text(buf, sizeof(buf), CAL_UTIL_DATE_FORMAT_1, NULL, tm);
119                 return strdup(buf);
120         }
121         return strdup("ERROR!!!");
122 }
123
124 static inline void __get_tm(const calendar_time_s* caltime, struct tm* tm_time)
125 {
126         switch (caltime->type) {
127         case CALENDAR_TIME_UTIME:
128                 cal_util_convert_lli_to_tm(NULL, caltime->time.utime, tm_time);
129                 break;
130         case CALENDAR_TIME_LOCALTIME:
131                 tm_time->tm_year = caltime->time.date.year - 1900;
132                 tm_time->tm_mon = caltime->time.date.month - 1;
133                 tm_time->tm_mday = caltime->time.date.mday;
134                 break;
135         default:
136                 // error
137                 break;
138         }
139 }
140
141 static char* __cal_list_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
142 {
143         c_retv_if(!data, NULL);
144         c_retv_if(!obj, NULL);
145         c_retv_if(!part, NULL);
146
147         cal_list_genlist_item_data *item_data = data;
148
149         cal_list_base_s *p = CAL_UTIL_GET_PRIV_DATA(obj);
150         c_retv_if(!p, NULL);
151
152         char *str = NULL;
153
154         calendar_record_h record = item_data->record;
155         c_retv_if(!record, NULL);
156
157         if (!CAL_STRCMP(part, "elm.text.1")) {
158                 str = _calendar_get_summary(record);
159
160                 if (p->searchtext) {
161                         char *text = cal_util_get_search_color_text(p->searchtext, str);
162                         if(CAL_STRLEN(text))    {
163                                 free(str);
164                                 return text;
165                         }
166                         else
167                                 return str;
168                 }
169
170                 return str;
171         } else if (!CAL_STRCMP(part, "elm.text.2")) {
172
173                 return _calendar_get_location(record);
174
175         } else if (!CAL_STRCMP(part, "elm.text.3")) {
176
177                 return _calendar_get_time_str_for_genlist(record);
178
179         } else if (!CAL_STRCMP(part, "elm.slide.text.1")) {
180
181                 return _calendar_get_summary(record);
182         }
183
184         return NULL;
185 }
186
187 static char* __cal_list_get_genlist_task_item_label(void *data, Evas_Object *obj, const char *part)
188 {
189         c_retv_if(!data, NULL);
190         c_retv_if(!obj, NULL);
191         c_retv_if(!part, NULL);
192
193         cal_list_genlist_item_data *item_data = data;
194
195         cal_list_base_s *p = CAL_UTIL_GET_PRIV_DATA(obj);
196         c_retv_if(!p, NULL);
197
198         calendar_record_h record = item_data->record;
199         c_retv_if(!record, NULL);
200
201         int todo_status;
202         calendar_record_get_int(record, _calendar_todo.todo_status, &todo_status);
203         bool is_done = (todo_status == CALENDAR_TODO_STATUS_COMPLETED);
204
205         if ((CAL_STRCMP(part, "elm.text.1") == 0 && !is_done) ||
206                 (CAL_STRCMP(part, "elm.textblock.1") == 0 && is_done)) {
207
208                 char* text = _calendar_get_summary(record);
209                 c_retv_if(text == NULL, NULL);
210
211                 if (p->searchtext) {
212                         char* text2 = cal_util_get_search_color_text(p->searchtext, text);
213                         if(CAL_STRLEN(text2))   {
214                                 free(text);
215                                 text = text2;
216                         }
217                 }
218
219                 if (is_done) {
220                         char* text3 = calloc(strlen(text) + 100, 1);
221                         if(text3 == NULL){
222                                 free(text);
223                                 c_retv_if(text3 == NULL, NULL);
224                         }
225                         sprintf(text3, "<strikethrough=on strikethrough_color=#D1D1D1>%s</strikethrough>", text);
226                         free(text);
227                         text = text3;
228                 }
229
230
231                 return text;
232
233         } else if (!CAL_STRCMP(part, "elm.textblock.2")) {
234                 if (!is_done)
235                         return NULL;
236
237                 return _calendar_get_location(record);
238         } else if (!CAL_STRCMP(part, "elm.text.3")) {
239                 if (is_done)
240                         return NULL;
241
242                 calendar_time_s due_time;
243                 calendar_record_get_caltime(record, _calendar_todo.due_time, &due_time);
244                 // TODO:mapi
245 //              if (due_time == -1) {
246 //                      return strdup("No due date");
247 //              }
248
249                 return _calendar_get_time_str_for_genlist(record);
250         } else if (!CAL_STRCMP(part, "elm.textblock.3")) {
251                 if (!is_done)
252                         return NULL;
253
254                 calendar_time_s due_time;
255                 calendar_record_get_caltime(record, _calendar_todo.due_time, &due_time);
256                 // TODO:mapi
257 //              if (due_time == -1) {
258 //                      return strdup("No due date");
259 //              }
260
261                 return _calendar_get_time_str_for_genlist(record);
262         }
263
264         return NULL;
265 }
266
267 static void __cal_list_base_set_genlist_item_sweep_off(Elm_Object_Item *it)
268 {
269         c_retm_if(!it, "it is null");
270         elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
271         elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_ALWAYS);
272 }
273
274 static Eina_Bool __cal_list_popup_idler_callback(void *data)
275 {
276         c_retv_if(!data, ECORE_CALLBACK_CANCEL);
277
278         cal_list_base_s *p = data;
279
280         if (p->popup) {
281                 evas_object_del(p->popup);
282                 p->popup = NULL;
283         }
284
285         p->popup_idler = NULL;
286
287         return ECORE_CALLBACK_CANCEL;
288 }
289
290 static inline void __cal_list_base_delete_popup(cal_list_base_s *p)
291 {
292         c_retm_if(!p || !p->popup, "param is null");
293
294         if (p->popup_idler) {
295                 ecore_idler_del(p->popup_idler);
296                 p->popup_idler = NULL;
297         }
298
299         p->popup_idler = ecore_idler_add(__cal_list_popup_idler_callback, p);
300         c_ret_if(!p->popup_idler);
301 }
302
303 static void __cal_list_base_show_popup(cal_list_base_s *p, const char *tit, Eina_Bool is_edit);
304
305 void __cal_list_edit_button_callback(void *data, Evas_Object *obj, void *ei)
306 {
307         cal_list_genlist_item_data *item_data = data;
308         c_retm_if(!item_data, "item_data is NULL.");
309
310         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
311         c_retm_if(!p, "p is NULL.");
312
313         calendar_record_h record = item_data->record;
314         c_retm_if(!record, "record is NULL.");
315
316         p->ad->cid = _calendar_get_record_index(record);
317         p->selected_record = record;
318
319         if (_calendar_is_task_record(record)) {
320
321                 calendar_record_h origin_record = NULL;
322                 int index = _calendar_get_record_index(record);
323                 origin_record = _calendar_get_record_with_index(index);
324
325                 cal_edit_create_view(p->ad, origin_record, NULL, NULL);
326                 calendar_record_destroy(origin_record, true);
327
328                 __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
329
330         } else {
331
332                 if (_calendar_is_recurrent_record(record)) {
333                         __cal_list_base_show_popup(p,C_("IDS_CLD_HEADER_EDIT_EVENT"), EINA_TRUE);
334                 } else {
335                         calendar_record_h origin_record = NULL;
336                         int index = _calendar_get_record_index(record);
337                         origin_record = _calendar_get_record_with_index(index);
338
339                         cal_edit_create_view(p->ad, origin_record, NULL, NULL);
340                         calendar_record_destroy(origin_record, true);
341
342                         __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
343                 }
344
345         }
346 }
347
348 static void __cal_list_delete_norepeat_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
349 {
350         c_retm_if(!data, "data is null");
351         c_retm_if(!obj, "obj is null");
352
353         Evas_Object *popup = data;
354         Evas_Object *button = obj;
355
356         cal_list_base_s* p = evas_object_data_get(popup, "data");
357
358         c_retm_if(!p, "p is null");
359         c_retm_if(!p->ad, "p->ad is null");
360         c_retm_if(!p->popup, "p->popup is null");
361
362         if (NULL != strstr(elm_object_text_get(button), S_("IDS_COM_BODY_DELETE"))) {
363                 _calendar_delete_record_with_index(p->ad->cid);
364         }
365
366         evas_object_del(p->popup);
367         p->popup = NULL;
368 }
369
370 static void __cal_list_edit_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
371 {
372         c_retm_if(!data, "data is null");
373         c_retm_if(!obj, "obj is null");
374
375         Evas_Object *popup = data;
376         Evas_Object *button = obj;
377         cal_list_base_s* p = evas_object_data_get(popup, "data");
378         c_retm_if(!p, "p is null");
379
380         struct appdata* ad = p->ad;
381         c_retm_if(!ad, "ad is null");
382
383         if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT"))) {
384                 cal_edit_create_view(p->ad, p->selected_record, NULL, NULL);
385                 __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
386         }else if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"))) {
387                 calendar_record_h origin_record = NULL;
388                 int index = _calendar_get_record_index(p->selected_record);
389                 origin_record = _calendar_get_record_with_index(index);
390
391                 cal_edit_create_view(p->ad, origin_record, NULL, NULL);
392                 __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
393                 calendar_record_destroy(origin_record, true);
394         }
395
396         evas_object_del(popup);
397         p->popup = NULL;
398 }
399
400 static void __cal_list_delete_event(cal_list_base_s* p, Eina_Bool is_delete_all)
401 {
402         c_ret_if(!p);
403
404         struct appdata* ad = p->ad;
405         c_ret_if(!ad);
406
407         if (!is_delete_all)
408                 _calendar_delete_recurrence_instance(p->selected_record);
409         else
410                 _calendar_delete_record_with_index(ad->cid);
411 }
412
413 static void __cal_list_delete_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
414 {
415         c_retm_if(!data, "data is null");
416         c_retm_if(!obj, "obj is null");
417
418         Evas_Object *popup = data;
419         Evas_Object *button = obj;
420
421         cal_list_base_s* p = evas_object_data_get(popup, "data");
422         c_retm_if(!p, "p is null");
423
424         if (!strcmp(elm_object_text_get(button), S_("IDS_COM_BODY_DELETE"))) {
425                 __cal_list_delete_event(p, EINA_FALSE);
426         } else if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT"))) {
427                 __cal_list_delete_event(p, EINA_FALSE);
428         } else if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"))) {
429                 __cal_list_delete_event(p, EINA_TRUE);
430         }
431
432         evas_object_del(popup);
433         p->popup = NULL;
434 }
435
436 static void __cal_list_base_show_popup(cal_list_base_s *p, const char *tit, Eina_Bool is_edit)
437 {
438         c_retm_if(!p, "p is NULL.");
439
440         void (*callback_func)(void *data, Evas_Object *obj, void *ei) = NULL;
441
442         if (is_edit) {
443                 callback_func = __cal_list_edit_popup_response_event_callback;
444
445         } else {
446                 callback_func = __cal_list_delete_popup_response_event_callback;
447         }
448
449         p->popup = cal_util_add_popup(p->ad->win, "verticalbuttonstyle", NULL, tit,
450                         callback_func, p, C_("IDS_CLD_BODY_ONLY_THIS_EVENT"),
451                         C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"), S_("IDS_COM_SK_CANCEL"), NULL);
452
453         c_retm_if(!p->popup, "cal_util_add_popup(p->ad->win) returned null");
454
455         evas_object_data_set(p->popup, "priv", p);
456 }
457
458 void __cal_list_delete_button_callback(void *data, Evas_Object *obj, void *ei)
459 {
460         cal_list_genlist_item_data *item_data = data;
461         c_retm_if(!item_data, "item_data is NULL.");
462
463         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
464         c_retm_if(!p, "p is NULL.");
465
466         calendar_record_h record = item_data->record;
467         c_retm_if(!record, "record is NULL.");
468
469         p->ad->cid = _calendar_get_record_index(record);
470         p->selected_record = record;
471
472         c_ret_if(p->ad->cid == 0);
473
474         if (_calendar_is_task_record(record)) {
475                 p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, S_("IDS_COM_POP_DELETE_Q"), __cal_list_delete_norepeat_popup_response_event_callback, p,
476                         S_("IDS_COM_BODY_DELETE"),S_("IDS_COM_SK_CANCEL"), NULL);
477         } else {
478                 if (_calendar_is_recurrent_record(record)) {
479                         __cal_list_base_show_popup(p, C_("IDS_CLD_OPT_DELETE_EVENT"), EINA_FALSE);
480                 } else {
481                         p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, S_("IDS_COM_POP_DELETE_Q"), __cal_list_delete_norepeat_popup_response_event_callback, p,
482                                 S_("IDS_COM_BODY_DELETE"),S_("IDS_COM_SK_CANCEL"), NULL);
483                 }
484         }
485 }
486
487 static void __cal_list_base_share_popup_response_callback(void *data, Evas_Object *obj, void *ei)
488 {
489         c_retm_if(!data, "data is null");
490         c_retm_if(!obj, "obj is null");
491
492         Evas_Object *popup = data;
493
494         cal_list_base_s* p = evas_object_data_get(popup, "data");
495         c_retm_if(!p, "p is null");
496
497         evas_object_del(popup);
498         p->popup = NULL;
499
500 }
501
502 static void __cal_list_genlist_item_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
503 {
504         c_ret_if(!data);
505         c_ret_if(!obj);
506
507         cal_list_genlist_item_data *item_data = data;
508
509         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
510         c_ret_if(!p);
511
512         item_data->checked = elm_check_state_get(obj);
513
514         calendar_record_h record = item_data->record;
515         c_ret_if(!record);
516
517         calendar_error_e error = CALENDAR_ERROR_NONE;
518         calendar_record_h todo_original_record = NULL;
519         int todo_id = _calendar_get_record_index(record);
520         error = calendar_db_get_record(_calendar_todo._uri, todo_id, &todo_original_record);
521         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record(%d) is failed(%x)", todo_id, error);
522
523         if (item_data->checked) {
524                 error = calendar_record_set_int(todo_original_record, _calendar_todo.todo_status, CALENDAR_TODO_STATUS_COMPLETED);
525                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
526
527                 error = calendar_record_set_int(record, _calendar_todo_calendar_book.todo_status, CALENDAR_TODO_STATUS_COMPLETED);
528                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
529         }
530         else {
531                 error = calendar_record_set_int(todo_original_record, _calendar_todo.todo_status, CALENDAR_TODO_STATUS_IN_PROCESS);
532                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
533
534                 error = calendar_record_set_int(record, _calendar_todo_calendar_book.todo_status, CALENDAR_TODO_STATUS_IN_PROCESS);
535                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
536         }
537
538         cal_main_remove_db_changed_callback(p->ad);
539
540         error = calendar_db_update_record(todo_original_record);
541         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_update_record() is failed(%x)", error);
542
543         cal_main_add_db_changed_callback(p->ad);
544
545         elm_genlist_item_update(item_data->it);
546
547         // TBD: UX not so good if task item is removed from list immediately.
548         if (!p->ad->is_display_complete_todo && item_data->checked)
549                 elm_object_item_del(item_data->it);
550 }
551
552 void __cal_list_base_send_button_callback(void *data, Evas_Object *obj, void *ei);
553
554 static Evas_Object* __get_action_button(Evas_Object* obj, const char *part, cal_list_base_s *p, cal_list_genlist_item_data *item_data)
555 {
556         Evas_Object *button = elm_button_add(obj);
557         c_retvm_if(!button, NULL, "button is NULL");
558
559         evas_object_data_set(button, "priv", p);
560         Eina_Bool button_disabled_set = EINA_FALSE;
561
562         if (!CAL_STRCMP(part, "elm.slide.swallow.1")) {
563
564                 elm_object_style_set(button, "text_only/sweep");
565                 elm_object_text_set(button, S_("IDS_COM_SK_EDIT"));
566                 evas_object_smart_callback_add(button, "clicked", __cal_list_edit_button_callback, item_data);
567                 evas_object_propagate_events_set(button, EINA_FALSE);
568                 if(button_disabled_set)
569                         elm_object_disabled_set(button, EINA_TRUE);
570
571         } else if (!CAL_STRCMP(part, "elm.slide.swallow.2")) {
572
573                 elm_object_style_set(button, "text_only/sweep");
574                 elm_object_text_set(button, S_("IDS_COM_BUTTON_SHARE"));
575                 evas_object_smart_callback_add(button, "clicked", __cal_list_base_send_button_callback, item_data);
576                 evas_object_propagate_events_set(button, EINA_FALSE);
577
578         } else if (!CAL_STRCMP(part, "elm.slide.swallow.3")) {
579
580                 elm_object_style_set(button, "sweep/delete");
581                 elm_object_text_set(button, S_("IDS_COM_BODY_DELETE"));
582                 evas_object_smart_callback_add(button, "clicked", __cal_list_delete_button_callback, item_data);
583                 evas_object_propagate_events_set(button, EINA_FALSE);
584                 if(button_disabled_set)
585                         elm_object_disabled_set(button, EINA_TRUE);
586
587         }
588
589         return button;
590 }
591
592 static Evas_Object *__cal_list_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
593 {
594         c_retv_if(!data, NULL);
595
596         cal_list_base_s *p = CAL_UTIL_GET_PRIV_DATA(obj);
597         c_retv_if(!p, NULL);
598
599         cal_list_genlist_item_data *item_data = data;
600
601         Evas_Object *icon = NULL;
602
603         calendar_record_h record = item_data->record;
604
605         if (!CAL_STRCMP(part, "elm.swallow.colorbar")) {
606
607                 _calendar_get_calendar_color(record, &calendar_color);
608
609                 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
610                 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
611                 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
612
613                 return icon;
614
615         } else if (CAL_STRCMP(part, "elm.slide.swallow.1") == 0 ||
616                            CAL_STRCMP(part, "elm.slide.swallow.2") == 0 ||
617                            CAL_STRCMP(part, "elm.slide.swallow.3") == 0) {
618
619                 return __get_action_button(obj, part, p, item_data);
620
621         } else if (!CAL_STRCMP(part, "elm.edit.icon.1") ) {
622                 icon = elm_check_add(obj);
623                 c_retvm_if(!icon, NULL, "elm_check_add returned null");
624
625                 int todo_status;
626                 calendar_record_get_int(record, _calendar_todo.todo_status, &todo_status);
627
628                 if (CALENDAR_TODO_STATUS_COMPLETED == todo_status)
629                         item_data->checked = EINA_TRUE;
630                 else if (CALENDAR_TODO_STATUS_IN_PROCESS == todo_status)
631                         item_data->checked = EINA_FALSE;
632
633                 elm_check_state_pointer_set(icon, &item_data->checked);
634                 evas_object_smart_callback_add(icon, "changed", __cal_list_genlist_item_check_changed_callback, item_data);
635                 evas_object_propagate_events_set(icon, EINA_FALSE);
636                 evas_object_data_set(icon, "priv", p);
637
638                 return icon;
639         } else if (!CAL_STRCMP(part, "elm.icon.1")) {
640                 if (!_calendar_has_reminder(record))
641                         return NULL;
642
643                 icon = elm_icon_add(obj);
644                 c_retv_if(!icon, NULL);
645
646                 int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_ALARM);
647                 c_retv_if(!r, NULL);
648
649                 return icon;
650         } else if (!CAL_STRCMP(part, "elm.icon.2")) {
651                 if (!_calendar_is_recurrent_record(record))
652                         return NULL;
653
654                 icon = elm_icon_add(obj);
655                 c_retv_if(!icon, NULL);
656
657                 int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_REPEAT);
658                 c_retv_if(!r, NULL);
659
660                 return icon;
661         } else if (!CAL_STRCMP(part, "elm.icon.3")) {
662                 if (!_calendar_is_facebook_record(record))
663                         return NULL;
664
665                 icon = elm_icon_add(obj);
666                 c_retv_if(!icon, NULL);
667
668                 int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_FACEBOOK);
669                 c_retv_if(!r, NULL);
670
671                 return icon;
672         } else {
673                 DBG("The part %s is unattended for!!!", part);
674         }
675
676         return NULL;
677 }
678
679 static Evas_Object *__cal_list_get_genlist_task_item_icon(void *data, Evas_Object *obj, const char *part)
680 {
681         c_retv_if(!data, NULL);
682
683         cal_list_base_s *p = CAL_UTIL_GET_PRIV_DATA(obj);
684         c_retv_if(!p, NULL);
685
686         cal_list_genlist_item_data *item_data = data;
687
688         Evas_Object *icon = NULL;
689
690         calendar_record_h record = item_data->record;
691         c_retv_if(!_calendar_is_task_record(record), NULL);
692
693         if (!CAL_STRCMP(part, "elm.swallow.colorbar"))
694         {
695                 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
696                 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
697
698                 _calendar_get_calendar_color(record, &calendar_color);
699
700                 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
701
702                 return icon;
703         } else if (CAL_STRCMP(part, "elm.slide.swallow.1") == 0 ||
704                            CAL_STRCMP(part, "elm.slide.swallow.2") == 0 ||
705                            CAL_STRCMP(part, "elm.slide.swallow.3") == 0) {
706
707                 return __get_action_button(obj, part, p, item_data);
708
709         } else if (!CAL_STRCMP(part, "elm.edit.icon")) {
710                 Evas_Object *check = elm_check_add(obj);
711                 c_retvm_if(!check, NULL, "elm_check_add returned null");
712
713                 item_data->checked = EINA_FALSE;
714
715                 calendar_error_e error = CALENDAR_ERROR_NONE;
716
717                 calendar_todo_status_e todo_status = 0;
718
719                 error = calendar_record_get_int(record, _calendar_todo.todo_status, (int *)&todo_status);
720                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
721
722                 if (CALENDAR_TODO_STATUS_COMPLETED == todo_status) {
723                         item_data->checked = EINA_TRUE;
724                 } else if (CALENDAR_TODO_STATUS_IN_PROCESS == todo_status) {
725                         item_data->checked = EINA_FALSE;
726                 }
727
728                 elm_check_state_pointer_set(check, &item_data->checked);
729                 evas_object_smart_callback_add(check, "changed", __cal_list_genlist_item_check_changed_callback, item_data);
730                 evas_object_propagate_events_set(check, EINA_FALSE);
731                 evas_object_data_set(check, "priv", p);
732                 return check;
733         }  else if (!CAL_STRCMP(part, "elm.icon.2")) {
734                 calendar_error_e error = CALENDAR_ERROR_NONE;
735
736                 calendar_todo_priority_e priority = CALENDAR_TODO_PRIORITY_NONE;
737
738                 error = calendar_record_get_int(record, _calendar_todo.priority, (int *)&priority);
739                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
740
741                 if (priority == CALENDAR_TODO_PRIORITY_HIGH) {
742                         icon = elm_icon_add(obj);
743                         c_retvm_if(!icon, NULL, "elm_icon_add returned null");
744                         int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PRIORITY);
745                         c_retv_if(!r, NULL);
746                 } else if (priority == CALENDAR_TODO_PRIORITY_LOW) {
747                         icon = elm_icon_add(obj);
748                         c_retvm_if(!icon, NULL, "elm_icon_add returned null");
749                         int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PRIORITY_LOW);
750                         c_retv_if(!r, NULL);
751                 }
752
753                 return icon;
754         }  else if (!CAL_STRCMP(part, "elm.icon.1")) {
755                 if (!_calendar_has_reminder(record))
756                         return NULL;
757
758                 icon = elm_icon_add(obj);
759                 c_retv_if(!icon, NULL);
760
761                 int r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_ALARM);
762                 c_retv_if(!r, NULL);
763
764                 return icon;
765         }  else {
766                 DBG("The part %s is unattended for!!!", part);
767         }
768
769         return NULL;
770 }
771
772 // TODO: Create new type for header item data
773 static void __cal_list_delete_genlist_header_item(void *data, Evas_Object *obj)
774 {
775         CAL_FN_START;
776
777         c_retm_if(!data, "data is null.");
778
779         cal_list_genlist_item_data *item_data = data;
780
781         free(item_data->tm);
782         free(item_data);
783 }
784
785 static void __cal_list_delete_genlist_item(void *data, Evas_Object *obj)
786 {
787         c_retm_if(!data, "data is null.");
788         cal_list_genlist_item_data *item_data = data;
789         free(item_data);
790 }
791
792 Elm_Genlist_Item_Class cal_list_itc_h = {
793         .item_style = "grouptitle",
794         .func.text_get = __cal_list_get_genlist_header_item_label,
795         .func.del = __cal_list_delete_genlist_header_item,
796 };
797
798 Elm_Genlist_Item_Class cal_list_today_group_itc_h = {
799         .item_style = "today_grouptitle",
800         .func.text_get = __cal_list_get_genlist_custom_group_header_item_label,
801         .func.del = __cal_list_delete_genlist_header_item,
802 };
803
804 Elm_Genlist_Item_Class cal_list_normal_itc = {
805         .item_style = "4text.1icon.3.calendar.search",
806         .func.text_get = __cal_list_get_genlist_item_label,
807         .func.del = __cal_list_delete_genlist_item,
808         .func.content_get = __cal_list_get_genlist_item_icon,
809         .decorate_item_style = "mode/slide3",
810 };
811
812 Elm_Genlist_Item_Class cal_task_itc = {
813         .item_style = "3text.4icon.calendar.check",
814         .func.text_get = __cal_list_get_genlist_task_item_label,
815         .func.del = __cal_list_delete_genlist_item,
816         .func.content_get = __cal_list_get_genlist_task_item_icon,
817         .decorate_item_style = "mode/slide3",
818 };
819
820 Elm_Genlist_Item_Class itc_1text = {
821         .item_style = "1text",
822         .func.content_get = NULL,
823         .func.text_get = __cal_list_base_share_genlist_item_label,
824 };
825
826 Elm_Genlist_Item_Class itc_1icon = {
827         .item_style = "1icon.custom",
828         .func.content_get = NULL,
829         .func.text_get = NULL,
830         .func.content_get = __cal_list_get_genlist_loadmore_item_icon,
831 };
832
833 static void __cal_list_via_message_callback(void *data, Evas_Object *obj, void *ei)
834 {
835         c_retm_if(!data, "data is null");
836         c_retm_if(!obj, "obj is null");
837
838         cal_list_base_s *p = data;
839         c_retm_if(!p->ad, "p->ad is null");
840
841         c_ret_if(!p->selected_record);
842
843         calendar_record_h record = _calendar_get_record_with_index(_calendar_get_record_index(p->selected_record));
844         c_ret_if(!record);
845
846         _calendar_export_record_to_vcs(record, CAL_MESSAGE_VCS);
847
848         p->ad->ug = cal_launch_ug_with_var(NULL, CAL_MESSAGE_COMPOSER_UG, NULL, "ATTACHFILE", CAL_MESSAGE_VCS, NULL);
849
850         __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
851
852         __cal_list_base_delete_popup(p);
853 }
854
855 static void __cal_list_via_email_callback(void *data, Evas_Object *obj, void *ei)
856 {
857         c_retm_if(!data, "data is null");
858         c_retm_if(!obj, "obj is null");
859
860         cal_list_base_s *p = data;
861         c_retm_if(!p->ad, "p->ad is null");
862
863         c_ret_if(!p->selected_record);
864
865         calendar_record_h record = _calendar_get_record_with_index(_calendar_get_record_index(p->selected_record));
866         c_ret_if(!record);
867
868         _calendar_export_record_to_vcs(record, CAL_EMAIL_VCS);
869
870         p->ad->ug = cal_launch_ug_with_var(NULL, CAL_EMAIL_COMPOSER_UG, (struct ug_cbs *)p->ad, "RUN_TYPE", "5", "ATTACHFILE", CAL_EMAIL_VCS, NULL);
871
872         __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
873
874         __cal_list_base_delete_popup(p);
875 }
876
877 static void __cal_list_via_bluetooth_callback(void *data, Evas_Object *obj, void *ei)
878 {
879         c_retm_if(!data, "data is null");
880         c_retm_if(!obj, "obj is null");
881
882         cal_list_base_s *p = data;
883         c_retm_if(!p->ad, "p->ad is null");
884
885         c_ret_if(!p->selected_record);
886
887         calendar_record_h record = _calendar_get_record_with_index(_calendar_get_record_index(p->selected_record));
888         c_ret_if(!record);
889
890         _calendar_export_record_to_vcs(record, CAL_BLUETOOTH_VCS);
891
892         p->ad->ug = cal_launch_ug_with_var(NULL, CAL_BLUETOOTH_UG, NULL, "launch-type", "send", "filecount", "1", "files", CAL_BLUETOOTH_VCS, NULL);
893
894         __cal_list_base_set_genlist_item_sweep_off(p->sweep_it);
895
896         __cal_list_base_delete_popup(p);
897 }
898
899 void __cal_list_base_send_button_callback(void *data, Evas_Object *obj, void *ei)
900 {
901         cal_list_genlist_item_data *item_data = data;
902         c_retm_if(!item_data, "item_data is NULL.");
903
904         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
905         c_retm_if(!p, "p is NULL.");
906
907         calendar_record_h record = item_data->record;
908         c_retm_if(!record, "record is NULL.");
909
910         p->ad->cid = _calendar_get_record_index(record);
911         p->selected_record = record;
912
913         p->popup = cal_util_add_popup(p->ad->win, "menustyle", S_("IDS_COM_BUTTON_SHARE"), NULL,
914                                 __cal_list_base_share_popup_response_callback, p,
915                                 S_("IDS_COM_BODY_CLOSE"),  NULL);
916
917         c_retm_if(!p->popup, "cal_util_add_popup returned null");
918         evas_object_data_set(p->popup, "data", p);
919
920         Evas_Object *genlist = elm_genlist_add(p->popup);
921         c_retm_if(!genlist, "elm_genlist_add returned null");
922
923         elm_genlist_item_append(genlist, &itc_1text, S_("IDS_COM_BODY_EMAIL"), NULL, ELM_GENLIST_ITEM_NONE, __cal_list_via_email_callback, p);
924         elm_genlist_item_append(genlist, &itc_1text, S_("IDS_COM_BODY_MESSAGE"), NULL, ELM_GENLIST_ITEM_NONE, __cal_list_via_message_callback, p);
925         elm_genlist_item_append(genlist, &itc_1text, S_("IDS_COM_BODY_BLUETOOTH"), NULL, ELM_GENLIST_ITEM_NONE, __cal_list_via_bluetooth_callback, p);
926
927         elm_object_content_set(p->popup, genlist);
928         evas_object_show(p->popup);
929 }
930
931 Elm_Object_Item* cal_list_base_append_genlist_group_item(Evas_Object *genlist,
932                 const Elm_Genlist_Item_Class *itc, const struct tm *tm, cal_task_group_item_type type)
933 {
934         CAL_FN_START;
935
936         c_retv_if(!genlist, NULL);
937
938         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(genlist);
939         c_retvm_if(!p, NULL, "p is null.");
940
941         struct tm *t = NULL;
942
943         if (tm) {
944                 t = calloc(1, sizeof(struct tm));
945
946                 *t = *tm;
947         } else {
948                 t = NULL;
949         }
950
951         cal_list_genlist_item_data *item_data = calloc(1, sizeof(cal_list_genlist_item_data));
952
953         item_data->tm = t;
954         item_data->todo_group_type = type;
955
956         item_data->it = elm_genlist_item_append(genlist, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
957         if (item_data->it == NULL) {
958                 ERR("elm_genlist_item_append failed!");
959
960                 free(item_data);
961                 CAL_FREE(t);
962
963                 return NULL;
964         }
965
966         elm_genlist_item_select_mode_set(item_data->it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
967
968         return item_data->it;
969 }
970
971 Elm_Object_Item* cal_list_base_prepend_genlist_group_item(Evas_Object *genlist,
972                 const Elm_Genlist_Item_Class *itc, const struct tm *tm)
973 {
974         CAL_FN_START;
975
976         c_retv_if(!genlist, NULL);
977
978         struct tm *t = calloc(1, sizeof(struct tm));
979
980         *t = *tm;
981
982         cal_list_genlist_item_data *item_data = calloc(1, sizeof(cal_list_genlist_item_data));
983
984         item_data->tm = t;
985
986         item_data->it = elm_genlist_item_prepend(genlist, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
987         if (item_data->it == NULL) {
988                 ERR("elm_genlist_item_prepend failed!");
989                 free(item_data);
990                 return NULL;
991         }
992
993         elm_genlist_item_select_mode_set(item_data->it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
994
995         return item_data->it;
996 }
997
998 static void __cal_list_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
999 {
1000         CAL_FN_START;
1001
1002         c_ret_if(!data);
1003         c_ret_if(!obj);
1004
1005         calendar_record_h record = data;
1006
1007         Elm_Object_Item *it = elm_genlist_selected_item_get(obj);
1008         c_ret_if(!it);
1009
1010         elm_genlist_item_selected_set(it, EINA_FALSE);
1011
1012         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
1013         c_retm_if(!p, "priv is null.");
1014
1015         p->ad->cid = _calendar_get_record_index(record);
1016
1017         if (p->select_item_callback != NULL) {
1018                 p->select_item_callback(p->select_item_callback_data);
1019         } else {
1020                 cal_detail_create_view(p->ad, record, NULL, NULL);
1021         }
1022 }
1023
1024 static Elm_Object_Item* __cal_list_append_genlist_item(Evas_Object *genlist,
1025                 const Elm_Genlist_Item_Class *itc, calendar_record_h record, Elm_Object_Item *parent)
1026 {
1027         CAL_FN_START;
1028
1029         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(genlist);
1030         c_retv_if(!p, NULL);
1031
1032         cal_list_genlist_item_data *item_data = calloc(1, sizeof(cal_list_genlist_item_data));
1033
1034         item_data->record = record;
1035
1036         item_data->it = elm_genlist_item_append(genlist, itc, item_data, parent, ELM_GENLIST_ITEM_NONE, __cal_list_genlist_item_select_callback, record);
1037         if (!item_data->it) {
1038                 ERR("item_data->it is null");
1039
1040                 free(item_data);
1041
1042                 return NULL;
1043         }
1044
1045         return item_data->it;
1046 }
1047
1048 static Elm_Object_Item* __cal_list_prepend_genlist_item(Evas_Object *genlist,
1049                 const Elm_Genlist_Item_Class *itc, calendar_record_h record, Elm_Object_Item *parent)
1050 {
1051         CAL_FN_START;
1052
1053         cal_list_genlist_item_data *item_data = calloc(1, sizeof(cal_list_genlist_item_data));
1054
1055         item_data->record = record;
1056
1057         item_data->it = elm_genlist_item_prepend(genlist, itc, item_data, parent, ELM_GENLIST_ITEM_NONE,  __cal_list_genlist_item_select_callback, record);
1058         c_retv_if(!item_data->it, NULL);
1059
1060         return item_data->it;
1061 }
1062
1063 static void __cal_list_gl_mode_right(void *data, Evas_Object *obj, void *event_info)
1064 {
1065         c_retm_if(!event_info, "event_info is null");
1066         c_retm_if(!obj, "obj is null");
1067
1068         Elm_Object_Item *it = event_info;
1069
1070         elm_genlist_item_decorate_mode_set(it, "slide", EINA_TRUE);
1071
1072         cal_list_base_s* p = CAL_UTIL_GET_PRIV_DATA(obj);
1073         c_retm_if(!p, "p is null");
1074
1075         if (p->sweep_it && it != p->sweep_it)
1076                 elm_genlist_item_decorate_mode_set(p->sweep_it, "slide", EINA_FALSE);
1077
1078         p->sweep_it = it;
1079 }
1080
1081 static void __cal_list_gl_mode_left(void *data, Evas_Object *obj, void *event_info)
1082 {
1083         c_retm_if(!event_info, "event_info is null");
1084         Elm_Object_Item *it = event_info;
1085
1086         elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
1087 }
1088
1089 static void __cal_list_gl_mode_cancel(void *data, Evas_Object *obj, void *event_info)
1090 {
1091         c_retm_if(!obj, "obj is null");
1092
1093         Elm_Object_Item *it = (Elm_Object_Item *)elm_genlist_decorated_item_get(obj);
1094         c_ret_if(!it);
1095
1096         elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
1097 }
1098
1099 Evas_Object* cal_list_base_get_genlist_p(cal_list_base_h list)
1100 {
1101         cal_list_base_s* p = (cal_list_base_s*)list;
1102         c_retv_if(!p, NULL);
1103         return p->genlist;
1104 }
1105
1106 static void __cal_list_base_text_refresh_callback(void *data)
1107 {
1108         CAL_FN_START;
1109
1110         c_retm_if(!data, "data is null");
1111         cal_list_base_s *p = data;
1112
1113         cal_main_update_title_text(p->ad);
1114         elm_object_text_set(p->ad->new_event_button, S_("IDS_COM_BODY_CREATE"));
1115
1116         elm_genlist_realized_items_update(p->genlist);
1117
1118 }
1119
1120 void cal_list_base_clear(cal_list_base_h list)
1121 {
1122         CAL_FN_START;
1123
1124         cal_list_base_s* p = (cal_list_base_s*)list;
1125         c_ret_if(!p);
1126
1127         elm_genlist_clear(p->genlist);
1128         p->item_count = 0;
1129 }
1130
1131 void cal_list_base_delete(cal_list_base_h list)
1132 {
1133         CAL_FN_START;
1134
1135         cal_list_base_s* p = (cal_list_base_s*)list;
1136         c_ret_if(!p);
1137
1138         if (!p->genlist)
1139                 return;
1140
1141         elm_object_part_content_unset(p->parent, "sw");
1142
1143         evas_object_del(p->genlist);
1144
1145         if (p->popup_idler) {
1146                 ecore_idler_del(p->popup_idler);
1147                 p->popup_idler = NULL;
1148         }
1149
1150         if (p->popup) {
1151                 evas_object_del(p->popup);
1152                 p->popup = NULL;
1153         }
1154
1155         p->genlist = NULL;
1156
1157         cal_lang_manager_remove_callback(__cal_list_base_text_refresh_callback, p);
1158 }
1159
1160 cal_list_base_h cal_list_base_create(
1161                                 struct appdata *ad, Evas_Object* parent, const char* part_name, bool enable_sweep_menu,
1162                                 cal_list_callback select_item_callback, void* select_item_callback_data)
1163 {
1164         CAL_FN_START;
1165
1166         c_retv_if(ad == NULL, NULL);
1167         c_retv_if(parent == NULL, NULL);
1168
1169         cal_list_base_s* p = (cal_list_base_s*)calloc(1, sizeof(cal_list_base_s));
1170         c_retv_if(p == NULL, NULL);
1171
1172         Evas_Object *genlist = elm_genlist_add(parent);
1173         if (genlist == NULL) {
1174                 c_warn_if(1, "elm_genlist_add failed");
1175                 free(p);
1176                 return NULL;
1177         }
1178
1179         p->ad = ad;
1180         p->parent = parent;
1181         p->select_item_callback = select_item_callback;
1182         p->select_item_callback_data = select_item_callback_data;
1183
1184         evas_object_data_set(genlist, "priv", p);
1185
1186         if (enable_sweep_menu) {
1187                 evas_object_smart_callback_add(genlist, "drag,start,right", __cal_list_gl_mode_right, NULL);
1188                 evas_object_smart_callback_add(genlist, "drag,start,left", __cal_list_gl_mode_left, NULL);
1189                 evas_object_smart_callback_add(genlist, "drag,start,up", __cal_list_gl_mode_cancel, NULL);
1190                 evas_object_smart_callback_add(genlist, "drag,start,down", __cal_list_gl_mode_cancel, NULL);
1191         }
1192
1193         elm_object_part_content_set(parent, part_name, genlist);
1194
1195         p->genlist = genlist;
1196
1197         cal_lang_manager_add_callback(__cal_list_base_text_refresh_callback, p);
1198
1199         return p;
1200 }
1201
1202 void cal_list_base_delete_popup(cal_list_base_h list)
1203 {
1204         cal_list_base_s* p = (cal_list_base_s*)list;
1205         c_ret_if(!p);
1206
1207         if (p->popup) {
1208                 evas_object_del(p->popup);
1209                 p->popup = NULL;
1210         }
1211 }
1212
1213 void cal_list_base_delete_popup_idler(cal_list_base_h list)
1214 {
1215         cal_list_base_s* p = (cal_list_base_s*)list;
1216         c_ret_if(!p);
1217
1218         if (p->popup_idler) {
1219                 ecore_idler_del(p->popup_idler);
1220                 p->popup_idler = NULL;
1221         }
1222 }
1223
1224 void cal_list_base_add_item(cal_list_base_h list, calendar_record_h record, bool prepend)
1225 {
1226         cal_list_base_s* p = (cal_list_base_s*)list;
1227         c_ret_if(!p);
1228         c_ret_if(!record);
1229
1230         if (prepend) {
1231                 Elm_Object_Item* it = elm_genlist_first_item_get(p->genlist);
1232                 if (_calendar_is_task_record(record))
1233                         __cal_list_prepend_genlist_item(p->genlist, &cal_task_itc, record, NULL);
1234                 else
1235                         __cal_list_prepend_genlist_item(p->genlist, &cal_list_normal_itc, record, NULL);
1236         } else {
1237                 if (_calendar_is_task_record(record))
1238                         __cal_list_append_genlist_item(p->genlist, &cal_task_itc, record, NULL);
1239                 else
1240                         __cal_list_append_genlist_item(p->genlist, &cal_list_normal_itc, record, NULL);
1241         }
1242
1243         p->item_count++;
1244 }
1245
1246 void cal_list_base_add_item_after(cal_list_base_h list, calendar_record_h record, Elm_Object_Item* after)
1247 {
1248         cal_list_base_s* p = (cal_list_base_s*)list;
1249         c_ret_if(!p);
1250         c_ret_if(!record);
1251
1252         cal_list_genlist_item_data *item_data = calloc(1, sizeof(cal_list_genlist_item_data));
1253         item_data->record = record;
1254
1255         if (_calendar_is_task_record(record))
1256                 item_data->it = elm_genlist_item_insert_after(p->genlist, &cal_task_itc, item_data, NULL, after, ELM_GENLIST_ITEM_NONE, __cal_list_genlist_item_select_callback, record);
1257         else
1258                 item_data->it = elm_genlist_item_insert_after(p->genlist, &cal_list_normal_itc, item_data, NULL, after, ELM_GENLIST_ITEM_NONE, __cal_list_genlist_item_select_callback, record);
1259
1260         if (!item_data->it) {
1261                 ERR("item_data->it is null");
1262                 free(item_data);
1263         }
1264 }
1265
1266 int cal_list_base_get_item_count(cal_list_base_h list)
1267 {
1268         const cal_list_base_s* p = (cal_list_base_s*)list;
1269         return p->item_count;
1270 }
1271
1272 void cal_list_base_set_search_text(cal_list_base_h list, const  char *search_text)
1273 {
1274         cal_list_base_s* p = (cal_list_base_s*)list;
1275         c_ret_if(!p);
1276
1277         p->searchtext = search_text;
1278
1279 }