3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
8 PROPRIETARY/CONFIDENTIAL
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
30 static const char *_name = "list/base";
32 ///TODO: get full path from caller
33 #define VFILE_PATH "/opt/data/ug-calendar"
35 static Elm_Entry_Filter_Limit_Size _limit_20char = {
39 #define MAX_FETCH_COUNT 10
41 #define ACCOUNT_LABLE_STRING_LENGTH 128
48 Evas_Object *no_contents;
53 Evas_Object *conformant;
56 Eina_List *event_list;
58 Evas_Object *select_all_layout;
59 Evas_Object *select_all_check;
68 Evas_Object* searchbar;
69 const char * searchtext;
70 Elm_Object_Item *navi_item;
72 Evas_Object * notify_layout;
76 Elm_Object_Item *it; // Genlist Item pointer
77 Eina_Bool checked; // Check status
81 Elm_Genlist_Item_Type it_flag;
82 }cal_list_ug_item_data;
84 static Eina_Bool is_ug_list_view_destory;
88 static void __cal_list_ug_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info);
89 static void __cal_list_ug_update(cal_list_ug_data *p);
90 static void __cal_list_ug_searchbar_entry_changed_callback(void *data, Evas_Object *obj, void *event_info);
91 static void __cal_list_ug_cancel_button_callback(void *data, Evas_Object *obj, void *event_info);
92 static void __cal_list_ug_searchbar_entry_unfocused_callback(void *data, Evas_Object *obj, void *event_info);
93 static void __cal_list_ug_searchbar_clicked_callback(void *data, Evas_Object *obj, void *event_info);
94 static void __cal_list_ug_create_searchbar(cal_list_ug_data *p);
95 static char* __cal_list_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part);
96 static Evas_Object *__cal_list_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part);
97 static void __cal_list_ug_update_all_check(cal_list_ug_data* p);
98 static void __cal_list_ug_create_searchbar(cal_list_ug_data *p);
99 static void __cal_list_ug_append_with_idler(void* data);
101 static Elm_Genlist_Item_Class itc = {
102 .item_style = "3text.5icon",
103 .func.text_get = __cal_list_ug_get_genlist_item_label,
104 .func.content_get = __cal_list_ug_get_genlist_item_icon,
105 .decorate_all_item_style = "edit_default",
108 static Calendar_color calendar_color;
111 #define ELM_GENLIST_ITEM_GROUP (1<<1)
113 static void __cal_list_ug_add_small_info(cal_list_ug_data *p, int count)
115 c_retm_if(!p, "p is null");
116 struct ug_data *ad = p->ugd;
117 c_retm_if(!ad, "ug data is null");
119 Evas_Object *nv = ad->nv;
120 c_retm_if(!nv, "nv is null");
122 Evas_Object *notify = NULL;
123 Evas_Object *notify_layout = NULL;
124 char lable_str[ACCOUNT_LABLE_STRING_LENGTH] = { '\0'};
129 notify = elm_notify_add(nv);
131 c_retm_if(!notify, "notify is null");
133 elm_notify_orient_set(notify, ELM_NOTIFY_ORIENT_BOTTOM);
137 notify_layout = elm_layout_add(notify);
138 if (!notify_layout) {
139 evas_object_del(p->notify);
144 p->notify_layout = notify_layout;
145 elm_layout_theme_set(notify_layout, "standard", "selectioninfo", "vertical/bottom_64");
146 elm_object_content_set(notify, notify_layout);
149 snprintf(lable_str, sizeof(lable_str), "%s (%d)", S_("IDS_COM_POP_SELECTED"), count);
150 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(p->notify_layout), "elm.text", lable_str);
153 evas_object_show(p->notify);
155 evas_object_hide(p->notify);
159 static void __cal_list_ug_genlist_item_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
161 c_retm_if(!data, "data is null");
163 cal_list_ug_item_data *item_data = data;
165 Eina_List* realized_list, *l;
167 cal_list_ug_data* p = CAL_UTIL_GET_PRIV_DATA(obj);
168 c_retm_if(!p, "p is null");
170 if (p->genlist_count <= 0) {
174 item_data->checked = elm_check_state_get(obj);
175 if (item_data->checked)
180 if (item_data->checked || 0 < p->num_check)
181 elm_object_item_disabled_set(p->bt, EINA_FALSE);
183 elm_object_item_disabled_set(p->bt, EINA_TRUE);
185 realized_list = elm_genlist_realized_items_get(p->genlist);
186 EINA_LIST_FOREACH(realized_list, l, it) {
188 elm_genlist_item_update(it);
191 if (p->num_check == p->genlist_count) {
192 elm_check_state_set(p->select_all_check,EINA_TRUE);
193 __cal_list_ug_update_all_check(p);
195 elm_check_state_set(p->select_all_check,EINA_FALSE);
196 __cal_list_ug_add_small_info(p, p->num_check);
200 static Evas_Object *__cal_list_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
202 c_retvm_if(!part, NULL, "part is null");
203 c_retvm_if(!obj, NULL, "obj is null");
204 c_retvm_if(!data, NULL, "data is null");
206 Evas_Object *icon = NULL;
207 cal_struct *calendar = NULL;
208 cal_list_ug_data* p = CAL_UTIL_GET_PRIV_DATA(obj);
209 c_retvm_if(!p, NULL, "p is null");
211 cal_list_ug_item_data *item_data = data;
213 cal_struct *cs = item_data->cs;
214 c_retvm_if(!cs, NULL, "cs is null");
216 if (!CAL_STRCMP(part, "elm.edit.icon.1") ) {
217 icon = elm_check_add(obj);
218 c_retvm_if(!icon, NULL, "elm_check_add returned null");
220 elm_check_state_pointer_set(icon, &item_data->checked);
221 evas_object_smart_callback_add(icon, "changed", __cal_list_ug_genlist_item_check_changed_callback, item_data);
222 evas_object_propagate_events_set(icon, EINA_FALSE);
223 evas_object_data_set(icon, "priv", p);
227 else if (!CAL_STRCMP(part, "elm.swallow.colorbar"))
229 r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, CALENDAR_SVC_STRUCT_GET_INT(cs,CAL_VALUE_INT_CALENDAR_ID), NULL, &calendar);
230 c_retvm_if(r != CAL_SUCCESS, NULL, "calendar_svc_get is failed(%d)", r);
232 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
233 c_retvm_if(!icon, NULL, "evas_object_rectangle_add returned null");
234 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
236 CALENDAR_SVC_GET_CALENDAR_COLOR(calendar, &calendar_color);
238 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
240 CALENDAR_SVC_STRUCT_FREE(&calendar);
248 static void __cal_list_ug_clear_event_list(cal_list_ug_data *p)
252 c_retm_if(!p, "p is null");
254 cal_list_ug_item_data *item;
257 EINA_LIST_FOREACH(p->event_list, l, item) {
259 calendar_svc_struct_free(&item->cs);
267 eina_list_free(p->event_list);
268 p->event_list = NULL;
272 static void __cal_list_ug_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
276 c_retm_if(!data, "data is null");
278 cal_list_ug_data *p = data;
280 is_ug_list_view_destory = TRUE;
282 ecore_idler_del(p->idler);
286 __cal_list_ug_clear_event_list(p);
288 if (p->no_contents) {
289 evas_object_del(p->no_contents);
293 evas_object_smart_callback_del(elm_object_part_content_get(p->searchbar, "elm.swallow.content"), "changed", __cal_list_ug_searchbar_entry_changed_callback);
294 evas_object_smart_callback_del(p->searchbar, "cancel,clicked", __cal_list_ug_cancel_button_callback);
295 evas_object_del(p->searchbar);
299 CALENDAR_SVC_DEL_EVENT_CHANGED_CALLBACK((void(*)(void*))__cal_list_ug_update);
302 evas_object_del(p->notify);
306 elm_box_clear(p->box);
312 static char* __cal_list_ug_get_cs(cal_struct *cs)
322 time = CAL_UTIL_TIME_FORMAT_6;
324 time = CAL_UTIL_TIME_FORMAT_1;
326 st = CALENDAR_SVC_STRUCT_GET_TIME(cs, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_GMT);
327 localtime_r(&st, &tm);
329 repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
330 if (repeat == CAL_REPEAT_NONE)
332 cal_util_get_time_text(stime, sizeof(stime), NULL, time, &tm);
333 snprintf(buf, sizeof(buf), "%s", stime);
335 cal_util_get_time_text(stime, sizeof(stime), NULL, time, &tm);
336 snprintf(buf, sizeof(buf), "%s", stime);
342 static char* __cal_list_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
344 c_retvm_if(!part, NULL, "part is null");
345 c_retvm_if(!data, NULL, "data is null");
347 const char *str = NULL;
348 cal_list_ug_item_data *item = data;
349 cal_struct *cs = item->cs;
350 c_retvm_if(!cs, NULL, "cs is null");
352 if (!CAL_STRCMP(part, "elm.text.1"))
354 str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
358 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
361 if (!CAL_STRCMP(part, "elm.text.2"))
363 str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_LOCATION);
367 return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
370 if (!CAL_STRCMP(part, "elm.text.3"))
371 return __cal_list_ug_get_cs(cs);
376 static void __cal_list_ug_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
378 c_retm_if(!data, "data is null");
379 c_retm_if(!obj, "obj is null");
381 Eina_List* realized_list, *l;
383 cal_list_ug_item_data* item = data;
384 cal_list_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
385 c_retm_if(!p, "p is null");
387 if (p->genlist_count <= 0) {
391 item->checked = !(item->checked);
398 if (item->checked || 0 < p->num_check) {
399 elm_object_item_disabled_set(p->bt, EINA_FALSE);
400 } else if (p->num_check <= 0) {
401 elm_object_item_disabled_set(p->bt, EINA_TRUE);
404 it = elm_genlist_selected_item_get(obj);
406 elm_genlist_item_selected_set(it, EINA_FALSE);
409 realized_list = elm_genlist_realized_items_get(obj);
410 EINA_LIST_FOREACH(realized_list, l, it) {
412 elm_genlist_item_update(it);
416 if (p->num_check == p->genlist_count) {
417 elm_check_state_set(p->select_all_check,EINA_TRUE);
418 __cal_list_ug_update_all_check(p);
420 elm_check_state_set(p->select_all_check,EINA_FALSE);
421 __cal_list_ug_add_small_info(p, p->num_check);
426 Eina_Bool __cal_list_ug_update_fetch_list_idler(void* data)
430 cal_list_ug_data *p = data;
432 c_retvm_if(!p, ECORE_CALLBACK_CANCEL, "priv is null.");
439 cal_list_ug_item_data *item;
440 Eina_Bool is_finished = EINA_FALSE;
442 if(is_ug_list_view_destory == EINA_TRUE)
443 return ECORE_CALLBACK_CANCEL;
446 return ECORE_CALLBACK_CANCEL;
448 r = CALENDAR_SVC_GET_LIST(ALL_VISIBILITY_ACCOUNT, ALL_CALENDAR_ID, CAL_STRUCT_SCHEDULE, CAL_VALUE_LIST_FILED, p->offset, MAX_FETCH_COUNT, &it);
449 if (r != CAL_SUCCESS)
450 return ECORE_CALLBACK_CANCEL;
452 while (CALENDAR_SVC_ITER_NEXT(it) == CAL_SUCCESS) {
454 item = calloc(1, sizeof(cal_list_ug_item_data));
455 c_retvm_if(!item, ECORE_CALLBACK_CANCEL, "item is null");
457 r = CALENDAR_SVC_ITER_GET_INFO(it, &item->cs);
458 if (r != CAL_SUCCESS)
461 p->event_list = eina_list_append(p->event_list, item);
464 CALENDAR_SVC_ITER_REMOVE(&it);
466 if(eina_list_count(p->event_list) < MAX_FETCH_COUNT)
467 is_finished = EINA_TRUE;
469 __cal_list_ug_append_with_idler(p);
471 if(is_finished || (p->offset == p->totalcnt))
475 ecore_idler_del(p->idler);
481 return ECORE_CALLBACK_CANCEL;
485 return ECORE_CALLBACK_RENEW;
488 return ECORE_CALLBACK_CANCEL;
491 static void __cal_list_ug_get_event_list(cal_list_ug_data *p)
495 c_retm_if(!p, "p is null");
499 cal_list_ug_item_data *item;
501 p->totalcnt = CALENDAR_SVC_GET_COUNT(ALL_ACCOUNT_ID,ALL_CALENDAR_ID,CAL_STRUCT_SCHEDULE);
505 r = CALENDAR_SVC_GET_LIST(ALL_ACCOUNT_ID, ALL_CALENDAR_ID, CAL_STRUCT_SCHEDULE, CAL_VALUE_LIST_FILED, 0, MAX_FETCH_COUNT, &it);
507 if (r != CAL_SUCCESS)
510 while (CALENDAR_SVC_ITER_NEXT(it) == CAL_SUCCESS) {
512 item = calloc(1, sizeof(cal_list_ug_item_data));
513 c_retm_if(!item, "item is null");
515 r = CALENDAR_SVC_ITER_GET_INFO(it, &item->cs);
516 if (r != CAL_SUCCESS)
519 p->event_list = eina_list_append(p->event_list, item);
522 CALENDAR_SVC_ITER_REMOVE(&it);
523 if (eina_list_count(p->event_list) < p->totalcnt) {
525 p->idler = ecore_idler_add(__cal_list_ug_update_fetch_list_idler,p);
529 static bool __cal_list_ug_strstr(const char *pszParent, const char * pszChild)
532 if (!pszParent || !pszChild) {
536 GString * gSrc = g_string_new(pszParent);
541 GString * gDes = g_string_new(pszChild);
543 g_string_free(gSrc,true);
547 gSrc = g_string_ascii_up(gSrc);
549 g_string_free(gDes,true);
553 gDes = g_string_ascii_up(gDes);
555 g_string_free(gSrc,true);
559 if (g_strrstr(gSrc->str,gDes->str)) {
565 g_string_free(gSrc,true);
566 g_string_free(gDes,true);
569 static void __cal_list_ug_append_with_idler(void* data)
571 c_retm_if(!data, "data is null");
573 cal_list_ug_data* p = data;
574 Eina_List *event_list, *l = NULL;
575 cal_list_ug_item_data *item = NULL;
576 Elm_Object_Item *it = NULL;
577 const char* summary = NULL;
579 event_list = eina_list_nth_list(p->event_list, p->offset-1);
581 event_list = eina_list_next(event_list);
582 c_retm_if(NULL == event_list, "eina_list_nth_list(append_list, 1) is null");
584 c_retm_if(!event_list, "eina_list_nth(list, %d) returned null", p->offset);
586 EINA_LIST_FOREACH(event_list, l, item) {
587 if (item && item->cs) {
588 if (p->searchtext && 0 < strlen(p->searchtext)) {
589 summary = CALENDAR_SVC_STRUCT_GET_STR(item->cs, CAL_VALUE_TXT_SUMMARY);
591 if (summary && __cal_list_ug_strstr(summary, p->searchtext)) {
592 it = elm_genlist_item_append(p->genlist, &itc, item, NULL, ELM_GENLIST_ITEM_NONE, __cal_list_ug_genlist_item_select_callback, item);
593 c_retm_if(!it, "elm_genlist_item_append is failed");
595 if (item && item->checked)
603 if (item && item->checked)
606 it = elm_genlist_item_append(p->genlist, &itc, item, NULL, ELM_GENLIST_ITEM_NONE, __cal_list_ug_genlist_item_select_callback, item);
607 c_retm_if(!it, "elm_genlist_item_append is failed");
617 static void __cal_list_ug_append_genlist(cal_list_ug_data *p)
621 c_retm_if(!p, "p is null");
622 c_ret_if(p->event_list <= 0);
625 cal_list_ug_item_data *item = NULL;
626 Elm_Object_Item *it = NULL;
627 const char* summary = NULL;
628 p->genlist_count = 0;
630 EINA_LIST_FOREACH(p->event_list, l, item) {
631 if (item && item->cs) {
632 if (p->searchtext && 0 < strlen(p->searchtext)) {
633 summary = CALENDAR_SVC_STRUCT_GET_STR(item->cs, CAL_VALUE_TXT_SUMMARY);
635 if (summary && __cal_list_ug_strstr(summary, p->searchtext)) {
636 it = elm_genlist_item_append(p->genlist, &itc, item, NULL, ELM_GENLIST_ITEM_NONE, __cal_list_ug_genlist_item_select_callback, item);
637 c_retm_if(!it, "elm_genlist_item_append is failed");
638 if (item && item->checked)
646 if (item && item->checked)
649 it = elm_genlist_item_append(p->genlist, &itc, item, NULL, ELM_GENLIST_ITEM_NONE, __cal_list_ug_genlist_item_select_callback, item);
650 c_retm_if(!it, "elm_genlist_item_append is failed");
661 if (p->genlist_count == p->num_check)
662 elm_check_state_set(p->select_all_check, EINA_TRUE);
664 elm_check_state_set(p->select_all_check, EINA_FALSE);
666 if (p->num_check <= 0) {
667 evas_object_hide(p->notify);
668 elm_object_item_disabled_set(p->bt, EINA_TRUE);
670 elm_object_item_disabled_set(p->bt, EINA_FALSE);
673 static void __cal_list_ug_create_searchbar(cal_list_ug_data *p)
675 c_retm_if(!p, "priv is null.");
676 c_retm_if(!p->ly, "p->ly is null.");
678 Evas_Object *searchbar = cal_util_add_searchbar(p->ly, NULL, NULL, EINA_TRUE);
679 c_retm_if(!searchbar, "cal_util_add_searchbar() returned null.");
681 Evas_Object *en = elm_object_part_content_get(searchbar, "elm.swallow.content");
682 c_retm_if(!en, "elm_object_part_content_get returned null.");
684 elm_entry_input_panel_layout_set(en, ELM_INPUT_PANEL_LAYOUT_NORMAL);
685 elm_entry_markup_filter_append(en, elm_entry_filter_limit_size, &_limit_20char);
687 evas_object_size_hint_weight_set(searchbar, EVAS_HINT_EXPAND, 0.1);
688 evas_object_size_hint_align_set(searchbar, EVAS_HINT_FILL, 0.6);
690 evas_object_smart_callback_add(en, "changed", __cal_list_ug_searchbar_entry_changed_callback, p);
691 evas_object_smart_callback_add(en, "unfocused", __cal_list_ug_searchbar_entry_unfocused_callback, p);
692 evas_object_smart_callback_add(searchbar, "clicked", __cal_list_ug_searchbar_clicked_callback, p);
693 evas_object_smart_callback_add(searchbar, "cancel,clicked", __cal_list_ug_cancel_button_callback, p);
695 evas_object_show(searchbar);
697 elm_object_part_content_set(p->ly, "searchbar", searchbar);
698 p->searchbar = searchbar;
701 static void __cal_list_ug_select_all_mouse_up_callback(void *data, Evas *e, Evas_Object *obj, void *event_info)
703 c_retm_if(!data, "data is null");
704 cal_list_ug_data *p = data;
706 Evas_Event_Mouse_Up *ev = event_info;
707 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
710 if (p->genlist_count <= 0) {
713 elm_check_state_set(p->select_all_check, !elm_check_state_get(p->select_all_check));
715 __cal_list_ug_update_all_check(p);
718 static void __cal_list_ug_select_all_changed_callback(void *data, Evas_Object *obj, void *event_info)
720 c_retm_if(!obj, "obj is null");
722 cal_list_ug_data* p = data;
723 c_retm_if(!p, "p is null");
724 if (p->genlist_count <= 0) {
728 __cal_list_ug_update_all_check(p);
731 static void __cal_list_ug_create_select_all(cal_list_ug_data* p)
735 c_retm_if(!p, "p is null");
736 c_retm_if(!p->ly, "p->lu is null");
737 c_retm_if(!p->box, "p->box is null");
739 Evas_Object* layout = p->select_all_layout = elm_layout_add(p->box);
740 c_retm_if(!layout, "elm_layout_add returned null");
742 elm_layout_theme_set(layout, "genlist", "item", "select_all/default");
743 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
744 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
745 evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_UP, __cal_list_ug_select_all_mouse_up_callback, p);
747 Evas_Object* check = p->select_all_check = elm_check_add(p->select_all_layout);
749 c_retm_if(!check, "elm_check_add returned null");
750 evas_object_smart_callback_add(check, "changed", __cal_list_ug_select_all_changed_callback, p);
751 evas_object_propagate_events_set(check, EINA_FALSE);
753 elm_object_part_content_set(layout, "elm.icon", check);
754 evas_object_data_set(p->select_all_check, "layout", p->select_all_layout);
755 elm_object_part_text_set(p->select_all_layout, "elm.text", S_("IDS_COM_BODY_SELECT_ALL"));
756 elm_box_pack_start(p->box, p->select_all_layout);
757 evas_object_show(p->select_all_layout);
760 static void __cal_list_ug_update_event_list(cal_list_ug_data *p)
762 __cal_list_ug_clear_event_list(p);
767 __cal_list_ug_get_event_list(p);
770 static void __cal_list_ug_update(cal_list_ug_data *p)
774 c_retm_if(!p, "p is null");
777 ecore_idler_del(p->idler);
781 __cal_list_ug_update_event_list(p);
783 if (p->event_list && 0 < eina_list_count(p->event_list)) {
784 p->no_contents = NULL;
786 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->ly), "searchbar,show", "prog");
788 if (!p->conformant) {
789 Evas_Object *conformant = elm_conformant_add(p->ly);
790 c_retm_if(!conformant, "conformant is null");
792 elm_object_style_set(conformant, "internal_layout");
793 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
795 elm_object_part_content_set(p->ly, "sw", conformant);
797 p->conformant = conformant;
800 __cal_list_ug_create_searchbar(p);
803 Evas_Object *box = elm_box_add(p->conformant);
804 c_retm_if(!box, "box is null");
806 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
808 elm_object_content_set(p->conformant, box);
813 __cal_list_ug_create_select_all(p);
817 Evas_Object *genlist = elm_genlist_add(p->ly);
818 c_retm_if(!genlist, "genlist is null");
820 elm_genlist_decorate_mode_set(genlist, EINA_TRUE);
821 evas_object_data_set(genlist, "priv", p);
822 elm_genlist_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF,ELM_SCROLLER_POLICY_OFF);
823 elm_genlist_block_count_set(genlist, 20);
824 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
825 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
826 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
827 evas_object_show(genlist);
828 elm_box_pack_end(p->box, genlist);
830 p->genlist = genlist;
833 elm_genlist_clear(p->genlist);
835 __cal_list_ug_append_genlist(p);
838 p->conformant = NULL;
840 p->select_all_layout = NULL;
844 evas_object_hide(p->notify);
846 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->ly), "searchbar,hide", "prog");
848 if (!p->no_contents) {
849 Evas_Object *no_contents = cal_util_add_nocontents(p->ly, C_("IDS_CLD_BODY_NO_EVENTS"));
850 c_retm_if(!no_contents, "no_contents is null.");
852 elm_object_part_content_set(p->ly, "sw", no_contents);
854 p->no_contents = no_contents;
857 elm_object_item_disabled_set(p->bt, EINA_TRUE);
864 static void __cal_list_ug_update_all_check(cal_list_ug_data* p)
866 c_retm_if(!p, "p is null");
867 c_retm_if(!p->genlist, "p is null");
870 Eina_List *realized_list, *l;
871 cal_list_ug_item_data* item_data;
873 if (elm_check_state_get(p->select_all_check)) {
874 p->num_check = p->genlist_count;
875 elm_object_item_disabled_set(p->bt, EINA_FALSE);
876 __cal_list_ug_add_small_info(p, p->genlist_count);
879 elm_object_item_disabled_set(p->bt, EINA_TRUE);
880 evas_object_hide(p->notify);
883 it = elm_genlist_first_item_get(p->genlist);
885 item_data = elm_object_item_data_get(it);
887 item_data->checked = elm_check_state_get(p->select_all_check);
889 it = elm_genlist_item_next_get(it);
892 realized_list = elm_genlist_realized_items_get(p->genlist);
893 EINA_LIST_FOREACH(realized_list, l, it)
896 elm_genlist_item_update(it);
901 static Evas_Object* __cal_list_ug_create_layout(Evas_Object *parent, struct ug_data *ugd)
905 c_retvm_if(!parent, NULL, "parent is null");
906 c_retvm_if(!ugd, NULL, "ugd is null");
908 cal_list_ug_data *p = calloc(1, sizeof(cal_list_ug_data));
909 c_retvm_if(!p, NULL, "p is null");
914 p->searchtext = NULL;
915 p->notify_layout = NULL;
918 p->genlist_count = 0;
921 is_ug_list_view_destory = EINA_FALSE;
923 Evas_Object *ly = cal_util_add_layout(parent, p->name);
926 ERR("cal_util_add_layout returned null");
931 evas_object_data_set(ly, "priv", p);
933 p->bg = cal_util_add_bg(ly,EINA_FALSE);
935 ERR("cal_util_add_bg returned null");
941 elm_object_part_content_set(ly, "base", p->bg);
943 __cal_list_ug_update(p);
945 evas_object_show(ly);
946 evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_list_ug_delete_layout, p);
947 CALENDAR_SVC_ADD_EVENT_CHANGED_CALLBACK((void(*)(void*))__cal_list_ug_update, p);
953 static void __cal_list_ug_get_time_text(time_t t, int allday, char *buf, int sz)
958 localtime_r(&t, &tm);
961 time = CAL_UTIL_TIME_FORMAT_6;
963 time = CAL_UTIL_TIME_FORMAT_1;
966 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, NULL, &tm);
968 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, time, &tm);
971 static void __cal_list_ug_get_start_time_text(cal_struct *cs, char *buf, int sz)
976 allday = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_ALL_DAY_EVENT);
978 t = mktime(CALENDAR_SVC_STRUCT_GET_TM(cs, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL));
980 __cal_list_ug_get_time_text(t, allday, buf, sz);
983 static void __cal_list_ug_get_end_time_text(cal_struct *cs, char *buf, int sz)
988 allday = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_ALL_DAY_EVENT);
990 t = mktime(CALENDAR_SVC_STRUCT_GET_TM(cs, CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL));
992 __cal_list_ug_get_time_text(t, allday, buf, sz);
996 static void __cal_list_ug_get_message_content(cal_struct *cs, char *body , int nsize)
998 c_retm_if(!cs, "cs is null");
1000 char *content = NULL;
1002 char *location = NULL;
1003 char start[1024] = "Start\n";
1004 char end[1024] = "End\n";
1005 char buf[1024] = {0};
1007 content = _("Check this schedule,please");
1009 title = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
1011 title = C_("IDS_CLD_BODY_NO_TITLE");
1013 location = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_LOCATION);
1015 location = _("No location");
1017 __cal_list_ug_get_start_time_text(cs, buf, sizeof(buf));
1018 CAL_STRNCAT(start,buf,sizeof start)
1020 __cal_list_ug_get_end_time_text(cs, buf, sizeof(buf));
1021 CAL_STRNCAT(end,buf,sizeof end)
1023 snprintf(body, nsize, "%s\n%s\n%s\n%s\n%s",content, title, location, start, end);
1027 static void __cal_list_ug_add_bundle_event(bundle *b, cal_struct *cs, int idx)
1029 char txt_content[1024*5] = {0};
1031 __cal_list_ug_get_message_content(cs, txt_content,sizeof txt_content);
1033 bundle_add(b, "BODY", txt_content);
1036 static void __cal_list_ug_add_bundle_vcs(bundle *b, cal_struct *cs, int idx, const char *caller)
1040 char buf[FILENAME_MAX];
1041 char path[FILENAME_MAX];
1043 cid = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_INDEX);
1045 snprintf(buf, sizeof(buf), "vfile%d", idx);
1046 snprintf(path, sizeof(path), "%s/Calendar_%d.vcs", VFILE_PATH, cid);
1048 r = CALENDAR_SVC_UTIL_SAVE_VCS_BY_INDEX(cid, path);
1049 if (r == CAL_SUCCESS)
1050 bundle_add(b, buf, path);
1053 static void __cal_list_ug_add_bundle(bundle *b, cal_struct *cs, int idx, struct ug_data *ugd)
1055 switch (ugd->mode) {
1057 __cal_list_ug_add_bundle_event(b, cs, idx);
1060 __cal_list_ug_add_bundle_vcs(b, cs, idx, ugd->caller);
1068 static bundle* __cal_list_ug_make_bundle(cal_list_ug_data *p, struct ug_data *ugd)
1070 c_retvm_if(!p, NULL, "p is null");
1071 c_retvm_if(!ugd, NULL, "ugd is null");
1075 cal_list_ug_item_data* item_data;
1077 char buf[32] = {'\0'};
1079 b = bundle_create();
1080 c_retvm_if(!b, NULL, "bundle_create returned null");
1082 EINA_LIST_FOREACH(p->event_list, l, item_data)
1084 if (item_data && item_data->checked)
1087 __cal_list_ug_add_bundle(b, item_data->cs, count, ugd);
1091 snprintf(buf, sizeof(buf), "%d", count);
1092 bundle_add(b, "count", buf);
1097 static void __cal_list_ug_attach(void *data, Evas_Object *obj, void *ei)
1099 c_retm_if(!data, "data is null");
1101 Evas_Object *ly = data;
1102 cal_list_ug_data *p;
1103 struct ug_data *ugd;
1106 p = CAL_UTIL_GET_PRIV_DATA(ly);
1107 c_retm_if(!p, "p is null");
1110 c_retm_if(!ugd, "ugd is null");
1116 b = __cal_list_ug_make_bundle(p, ugd);
1117 c_retm_if(!b, "b is null");
1126 ug_send_result(ugd->ug, b);
1130 ug_destroy_me(ugd->ug);
1133 static void __cal_list_ug_add_controlbar( struct ug_data *ugd, Evas_Object *ly, const char* title)
1135 Evas_Object *cbar = NULL;
1136 Elm_Object_Item* navi_item = NULL;
1137 Elm_Object_Item * attach_button = NULL;
1138 cal_list_ug_data* p = evas_object_data_get(ly,"priv");
1139 c_retm_if(!p, "p is null");
1141 cbar = cal_util_add_controlbar(ugd->nv);
1142 c_retm_if(!cbar, "cal_util_add_controlbar returned null");
1144 elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL);
1146 attach_button = elm_toolbar_item_append(cbar, NULL, S_("IDS_COM_POP_ATTACH"), __cal_list_ug_attach, ly);
1147 c_retm_if(!attach_button, "elm_toolbar_item_append returned null");
1148 p->bt = attach_button;
1150 elm_object_item_disabled_set(p->bt, EINA_TRUE);
1152 is_hour24 = ugd->is_hour24;
1154 navi_item = elm_naviframe_item_push(ugd->nv, title, NULL, NULL, ly, NULL);
1157 ERR("elm_naviframe_item_push returned null");
1158 evas_object_del(cbar);
1162 elm_object_item_part_content_set(navi_item, "controlbar", cbar);
1165 void cal_list_ug_create(const char *title, struct ug_data *ugd)
1167 Evas_Object *ly = __cal_list_ug_create_layout(ugd->nv, ugd);
1173 __cal_list_ug_add_controlbar(ugd, ly, title);
1176 static void __cal_list_ug_searchbar_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1180 cal_list_ug_data *p = data;
1181 c_retm_if(!p, "priv is null.");
1183 p->searchtext = elm_object_text_get(elm_object_part_content_get(p->searchbar, "elm.swallow.content"));
1185 elm_genlist_clear(p->genlist);
1188 p->genlist = elm_genlist_add(p->parent);
1189 c_retm_if(!p->genlist, "p->genlist is null");
1190 elm_genlist_decorate_mode_set(p->genlist, EINA_TRUE);
1191 evas_object_data_set(p->genlist, "priv", p);
1196 __cal_list_ug_append_genlist(p);
1197 if (p->genlist_count == p->num_check) {
1198 if (p->num_check == 0) {
1199 elm_check_state_set(p->select_all_check,EINA_FALSE);
1200 elm_object_disabled_set(p->select_all_check,EINA_TRUE);
1202 elm_check_state_set(p->select_all_check,EINA_TRUE);
1205 elm_check_state_set(p->select_all_check,EINA_FALSE);
1208 if (p->genlist_count > 0) {
1209 elm_object_disabled_set(p->select_all_check,EINA_FALSE);
1212 if (0 < p->num_check)
1213 elm_object_item_disabled_set(p->bt, EINA_FALSE);
1215 elm_object_item_disabled_set(p->bt, EINA_TRUE);
1217 __cal_list_ug_add_small_info(p,p->num_check);
1220 static void __cal_list_ug_cancel_button_callback(void *data, Evas_Object *obj, void *event_info)
1224 c_retm_if(!data, "data is null");
1225 cal_list_ug_data *p = data;
1226 Eina_List *l = NULL;
1227 cal_list_ug_item_data *item =NULL;
1229 Evas_Object *en = elm_object_part_content_get(p->searchbar, "elm.swallow.content");
1230 c_retm_if(!en, "elm_object_part_content_get returned null");
1232 Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(en);
1233 c_retm_if(!imf_context, "elm_entry_imf_context_get returned null");
1236 ecore_imf_context_input_panel_hide(imf_context);
1238 if (0 < p->num_check)
1239 elm_object_item_disabled_set(p->bt, EINA_FALSE);
1241 elm_object_item_disabled_set(p->bt, EINA_TRUE);
1245 EINA_LIST_FOREACH(p->event_list, l, item) {
1246 if (item != NULL && item->checked) {
1251 if (p->genlist_count == p->num_check && p->num_check != 0) {
1252 elm_check_state_set(p->select_all_check, EINA_TRUE);
1254 elm_check_state_set(p->select_all_check, EINA_FALSE);
1256 elm_object_disabled_set(p->select_all_check,EINA_FALSE);
1258 __cal_list_ug_add_small_info(p,p->num_check);
1261 static void __cal_list_ug_searchbar_entry_unfocused_callback(void *data, Evas_Object *obj, void *event_info)
1263 c_retm_if(!data, "data is null.");
1264 cal_list_ug_data *p = data;
1266 if (p->num_check <= 0) {
1267 elm_object_item_disabled_set(p->bt, EINA_TRUE);
1269 elm_object_item_disabled_set(p->bt, EINA_FALSE);
1272 __cal_list_ug_add_small_info(p,p->num_check);
1275 static void __cal_list_ug_searchbar_clicked_callback(void *data, Evas_Object *obj, void *event_info)
1277 c_retm_if(!data, "data is null.");
1278 cal_list_ug_data *p = data;
1280 elm_object_item_disabled_set(p->bt, EINA_TRUE);