3 * Copyright 2012 Samsung Electronics Co., Ltd
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
9 * http://floralicense.org/license/
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.
24 static const char *_name = "list/base";
26 ///TODO: get full path from caller
27 #define VFILE_PATH "/opt/usr/media/Others"
29 static Elm_Entry_Filter_Limit_Size _limit_20char = {
33 #define MAX_FETCH_COUNT 10
35 #define ACCOUNT_LABLE_STRING_LENGTH 128
42 Evas_Object *no_contents;
49 Eina_List *event_list;
50 Eina_List *search_list;
56 int checked_event_count;
57 int added_event_count;
58 Evas_Object* searchbar;
59 const char * searchtext;
60 Elm_Object_Item *navi_item;
64 Elm_Object_Item *it; // Genlist Item pointer
65 Eina_Bool checked; // Check status
67 calendar_record_h record;
69 Elm_Genlist_Item_Type it_flag;
70 }cal_list_ug_item_data;
72 static void __cal_list_ug_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info);
73 static void __cal_list_ug_update_callback(const char* view_uri, void *data);
74 static void __cal_list_ug_searchbar_entry_changed_callback(void *data, Evas_Object *obj, void *event_info);
75 static void __cal_list_ug_cancel_button_callback(void *data, Evas_Object *obj, void *event_info);
76 static void __cal_list_ug_searchbar_entry_unfocused_callback(void *data, Evas_Object *obj, void *event_info);
77 static void __cal_list_ug_searchbar_clicked_callback(void *data, Evas_Object *obj, void *event_info);
78 static void __cal_list_ug_create_searchbar(cal_list_ug_data *p);
79 static char* __cal_list_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part);
80 static Evas_Object *__cal_list_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part);
82 static Elm_Genlist_Item_Class itc = {
83 .item_style = "3text.5icon",
84 .func.text_get = __cal_list_ug_get_genlist_item_label,
85 .func.content_get = __cal_list_ug_get_genlist_item_icon,
86 .decorate_all_item_style = "edit_default",
89 static _calendar_book_color calendar_color;
92 #define ELM_GENLIST_ITEM_GROUP (1<<1)
94 static void __cal_list_ug_update_selection_info(cal_list_ug_data *p)
100 if (!p->checked_event_count) {
101 cal_util_hide_small_information(p->ly);
105 char lable_str[128] = { '\0'};
107 snprintf(lable_str, sizeof(lable_str), "%s (%d)", S_("IDS_COM_POP_SELECTED"), p->checked_event_count);
109 cal_util_show_small_information(p->ly, lable_str, 0.0);
112 static inline void __cal_list_ug_update_button_state(cal_list_ug_data *p)
114 if (0 < p->checked_event_count)
115 elm_object_disabled_set(p->bt, EINA_FALSE);
117 elm_object_disabled_set(p->bt, EINA_TRUE);
120 static inline void __cal_list_ug_update_realized_genlist_item(cal_list_ug_data *p)
122 Eina_List *realized_list = elm_genlist_realized_items_get(p->genlist);
123 c_ret_if(!realized_list);
126 Elm_Object_Item *it = NULL;
128 EINA_LIST_FOREACH(realized_list, l, it) {
130 elm_genlist_item_update(it);
134 static void __cal_list_ug_genlist_item_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
139 cal_list_ug_item_data *item_data = data;
141 cal_list_ug_data* p = CAL_UTIL_GET_PRIV_DATA(obj);
144 item_data->checked = elm_check_state_get(obj);
146 if (item_data->checked)
147 p->checked_event_count++;
149 p->checked_event_count--;
151 __cal_list_ug_update_button_state(p);
153 __cal_list_ug_update_realized_genlist_item(p);
155 __cal_list_ug_update_selection_info(p);
158 static Evas_Object *__cal_list_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
160 c_retv_if(!part, NULL);
161 c_retv_if(!obj, NULL);
162 c_retv_if(!data, NULL);
164 cal_list_ug_item_data *item_data = data;
166 if (!CAL_STRCMP(part, "elm.edit.icon.1")) {
168 cal_list_ug_data* p = CAL_UTIL_GET_PRIV_DATA(obj);
171 Evas_Object *checkbox = elm_check_add(obj);
172 c_retv_if(!checkbox, NULL);
174 elm_check_state_pointer_set(checkbox, &item_data->checked);
175 evas_object_smart_callback_add(checkbox, "changed", __cal_list_ug_genlist_item_check_changed_callback, item_data);
176 evas_object_propagate_events_set(checkbox, EINA_FALSE);
177 evas_object_data_set(checkbox, "priv", p);
181 } else if (!CAL_STRCMP(part, "elm.swallow.colorbar")) {
183 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
184 c_retv_if(!rect, NULL);
186 evas_object_size_hint_align_set(rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
188 _calendar_get_calendar_color(item_data->record, &calendar_color);
190 evas_object_color_set(rect, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
198 static void __cal_list_ug_delete_idler(cal_list_ug_data *p)
207 ecore_idler_del(p->idler);
211 static void __cal_list_ug_delete_no_contents(cal_list_ug_data *p)
221 elm_object_part_content_unset(p->ly, "sw");
223 evas_object_del(p->no_contents);
225 p->no_contents = NULL;
228 static void __cal_list_ug_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
232 c_retm_if(!data, "data is null");
234 cal_list_ug_data *p = data;
236 calendar_error_e error = CALENDAR_ERROR_NONE;
238 error = calendar_db_remove_changed_cb(_calendar_event._uri, __cal_list_ug_update_callback, p);
239 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_remove_changed_cb() is failed(%x)", error);
241 __cal_list_ug_delete_idler(p);
243 _calendar_free_record_list(&p->event_list);
248 static char* __cal_list_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
250 c_retv_if(!part, NULL);
251 c_retv_if(!data, NULL);
253 cal_list_ug_item_data *item = data;
254 calendar_record_h record = item->record;
255 c_retv_if(!record, NULL);
257 if (!CAL_STRCMP(part, "elm.text.1")) {
259 return _calendar_get_summary(record);
262 if (!CAL_STRCMP(part, "elm.text.2")) {
264 return _calendar_get_location(record);
267 if (!CAL_STRCMP(part, "elm.text.3"))
268 return _calendar_get_time_str_for_genlist(record);
273 static void __cal_list_ug_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
275 c_retm_if(!data, "data is null");
276 c_retm_if(!obj, "obj is null");
279 cal_list_ug_item_data* item = data;
280 cal_list_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
281 c_retm_if(!p, "p is null");
283 if (p->ugd->selection_mode == SELECTION_MODE_SINGLE) {
285 int cid = _calendar_get_record_index(item->record);
286 c_retm_if(cid < 0, "CALENDAR_SVC_STRUCT_GET_INT return error!");
290 service_create(&service);
292 char ** value = calloc(1, sizeof(char *));
294 ERR("value is NULL!");
295 service_destroy(service);
300 char path[FILENAME_MAX] = {0};
301 char *vcs_data = NULL;
303 snprintf(path, sizeof(path), "%s/Calendar_%d.vcs", VFILE_PATH, cid);
305 calendar_list_h list = NULL;
307 calendar_error_e error = CALENDAR_ERROR_NONE;
309 error = calendar_list_create(&list);
310 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_create() is failed(%x)");
312 error = calendar_list_add(list, item->record);
313 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_add() is failed(%x)");
315 error = calendar_vcalendar_make_from_records(list, &vcs_data);
316 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_make_from_records() is failed(%x)");
319 int fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
322 ERR("Failed to open file %s.", path);
325 service_destroy(service);
326 error = calendar_list_destroy(list, false);
327 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)");
333 int ret = write(fd, vcs_data, strlen(vcs_data));
335 ERR("write() is failed.");
337 cal_util_update_media_db(path);
345 error = calendar_list_destroy(list, false);
346 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)");
348 value[0] = strdup(path);
350 service_add_extra_data_array(service, CAL_APPCONTROL_PATH, (const char **)value, 1);
355 service_add_extra_data(service, CAL_APPCONTROL_RESULT, CAL_APPCONTROL_RESULT_SUCCESS);
357 if (p->ugd->item_type == ITEM_TYPE_EVENT)
358 service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_EVENT);
360 service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_TODO);
362 ug_send_result(p->ugd->ug, service);
363 service_destroy(service);
365 ug_destroy_me(p->ugd->ug);
370 if (p->added_event_count <= 0) {
374 item->checked = !(item->checked);
376 p->checked_event_count++;
378 p->checked_event_count--;
381 if (item->checked || 0 < p->checked_event_count) {
382 elm_object_disabled_set(p->bt, EINA_FALSE);
383 } else if (p->checked_event_count <= 0) {
384 elm_object_disabled_set(p->bt, EINA_TRUE);
387 it = elm_genlist_selected_item_get(obj);
389 elm_genlist_item_selected_set(it, EINA_FALSE);
392 __cal_list_ug_update_realized_genlist_item(p);
394 __cal_list_ug_update_selection_info(p);
397 static void __cal_list_ug_get_event_list(cal_list_ug_data *p)
403 struct tm tm_start = {0};
404 struct tm tm_end = {0};
406 tm_start.tm_year = 70;
407 tm_end.tm_year = 137;
409 if (p->ugd->item_type == ITEM_TYPE_EVENT)
410 p->event_list = _calendar_get_all_instance_list(&tm_start,&tm_end);
412 p->event_list = _calendar_get_all_task_list2(&tm_start, &tm_end, EINA_TRUE, _CALENDAR_TASK_SORT_TYPE_DUEDATE_ASC);
415 static void __cal_list_ug_add_event_to_genlist(cal_list_ug_data *p)
420 c_ret_if(!p->event_list);
423 calendar_record_h record = NULL;
425 int added_event_count = 0;
427 Eina_List *event_list = eina_list_nth_list(p->event_list, p->added_event_count);
428 c_ret_if(!event_list);
430 EINA_LIST_FOREACH(event_list, l, record) {
432 cal_list_ug_item_data *item_data = calloc(1, sizeof(cal_list_ug_item_data));
433 c_ret_if(!item_data);
435 item_data->record = record;
437 item_data->it = elm_genlist_item_append(p->genlist, &itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_list_ug_genlist_item_select_callback, item_data);
441 if (10 < added_event_count)
446 p->added_event_count += added_event_count;
449 static Eina_Bool __cal_list_ug_check_idler_condition(cal_list_ug_data *p)
451 c_retv_if(!p, ECORE_CALLBACK_CANCEL);
453 if (p->added_event_count < eina_list_count(p->event_list)) {
455 return ECORE_CALLBACK_RENEW;
459 ecore_idler_del(p->idler);
463 return ECORE_CALLBACK_CANCEL;
466 Eina_Bool __cal_list_ug_idler_callback(void* data)
470 c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null.");
472 cal_list_ug_data *p = data;
474 c_retv_if(!p->idler, ECORE_CALLBACK_CANCEL);
476 __cal_list_ug_add_event_to_genlist(p);
480 return __cal_list_ug_check_idler_condition(p);
483 static void __cal_list_ug_add_idler(cal_list_ug_data *p)
487 if (p->added_event_count < eina_list_count(p->event_list)) {
490 ecore_idler_del(p->idler);
492 p->idler = ecore_idler_add(__cal_list_ug_idler_callback, p);
497 static void __cal_list_ug_create_searchbar(cal_list_ug_data *p)
505 Evas_Object *searchbar = cal_util_add_searchbar(p->ly, NULL, NULL, EINA_TRUE, NULL, NULL);
506 c_ret_if(!searchbar);
508 Evas_Object *entry = elm_object_part_content_get(searchbar, "elm.swallow.content");
511 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
512 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &_limit_20char);
514 evas_object_size_hint_weight_set(searchbar, EVAS_HINT_EXPAND, 0.1);
515 evas_object_size_hint_align_set(searchbar, EVAS_HINT_FILL, 0.6);
517 evas_object_smart_callback_add(entry, "changed", __cal_list_ug_searchbar_entry_changed_callback, p);
518 evas_object_smart_callback_add(entry, "unfocused", __cal_list_ug_searchbar_entry_unfocused_callback, p);
519 evas_object_smart_callback_add(searchbar, "clicked", __cal_list_ug_searchbar_clicked_callback, p);
520 evas_object_smart_callback_add(searchbar, "cancel,clicked", __cal_list_ug_cancel_button_callback, p);
522 evas_object_show(searchbar);
524 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->ly), "searchbar,show", "prog");
526 elm_object_part_content_set(p->ly, "searchbar", searchbar);
528 p->searchbar = searchbar;
531 static void __cal_list_ug_create_box(cal_list_ug_data *p)
541 Evas_Object *box = elm_box_add(p->ly);
544 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
545 elm_object_part_content_set(p->ly, "sw", box);
549 static void __cal_list_ug_append_list_with_iter(Eina_List **event_list, calendar_list_h list)
551 c_ret_if(!event_list);
554 calendar_record_h record = NULL;
560 calendar_error_e error = CALENDAR_ERROR_NONE;
562 error = calendar_list_get_count(list, &count);
563 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
565 error = calendar_list_first(list);
566 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
568 for (i = 0; i < count; i++) {
569 error = calendar_list_get_current_record_p(list, &record);
570 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
572 *event_list = eina_list_append(*event_list, record);
574 calendar_list_next(list);
579 static void __cal_list_ug_update_event_list_with_keyword(cal_list_ug_data *p)
583 calendar_list_h list = NULL;
584 if (p->ugd->item_type == ITEM_TYPE_EVENT) {
585 list = _calendar_search_event(p->searchtext);
589 list = _calendar_search_task(p->searchtext);
593 __cal_list_ug_append_list_with_iter(&p->search_list, list);
595 calendar_error_e error = CALENDAR_ERROR_NONE;
597 error = calendar_list_destroy(list, false);
598 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
602 static void __cal_list_ug_update_event_list(cal_list_ug_data *p)
606 p->checked_event_count = 0;
608 p->added_event_count = 0;
610 _calendar_free_record_list(&p->event_list);
612 if (CAL_STRLEN(p->searchtext))
613 __cal_list_ug_update_event_list_with_keyword(p);
615 __cal_list_ug_get_event_list(p);
618 static void __cal_list_ug_create_genlist(cal_list_ug_data *p)
627 elm_genlist_clear(p->genlist);
632 Evas_Object *genlist = elm_genlist_add(p->box);
635 if (p->ugd->selection_mode == SELECTION_MODE_SINGLE)
636 itc.decorate_all_item_style = NULL;
638 elm_genlist_decorate_mode_set(genlist, EINA_TRUE);
640 evas_object_data_set(genlist, "priv", p);
641 elm_genlist_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF,ELM_SCROLLER_POLICY_OFF);
642 elm_genlist_block_count_set(genlist, 20);
643 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
644 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
645 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
646 evas_object_show(genlist);
647 elm_box_pack_end(p->box, genlist);
649 p->genlist = genlist;
652 static void __cal_list_ug_create_no_contents(cal_list_ug_data *p)
659 p->no_contents = cal_util_add_nocontents(p->ly, C_("IDS_CLD_BODY_NO_EVENTS"));
660 c_ret_if(!p->no_contents);
662 elm_object_part_content_set(p->ly, "sw", p->no_contents);
664 evas_object_show(p->no_contents);
667 static void __cal_list_ug_update_callback(const char* view_uri, void *data)
672 cal_list_ug_data *p = data;
674 __cal_list_ug_delete_idler(p);
676 __cal_list_ug_update_event_list(p);
678 if (p->event_list && eina_list_count(p->event_list)) {
680 __cal_list_ug_delete_no_contents(p);
682 __cal_list_ug_create_searchbar(p);
684 __cal_list_ug_create_box(p);
686 __cal_list_ug_create_genlist(p);
688 __cal_list_ug_add_event_to_genlist(p);
690 __cal_list_ug_add_idler(p);
700 __cal_list_ug_create_no_contents(p);
702 elm_object_disabled_set(p->bt, EINA_TRUE);
707 static Evas_Object* __cal_list_ug_create_layout(Evas_Object *parent, struct ug_data *ugd)
711 c_retvm_if(!parent, NULL, "parent is null");
712 c_retvm_if(!ugd, NULL, "ugd is null");
714 cal_list_ug_data *p = calloc(1, sizeof(cal_list_ug_data));
715 c_retvm_if(!p, NULL, "p is null");
721 Evas_Object *ly = cal_util_add_layout(parent, p->name);
724 ERR("cal_util_add_layout returned null");
729 evas_object_data_set(ly, "priv", p);
731 p->bg = cal_util_add_bg(ly,EINA_FALSE);
733 ERR("cal_util_add_bg returned null");
739 elm_object_part_content_set(ly, "base", p->bg);
741 __cal_list_ug_update_callback(_calendar_event._uri, p);
743 evas_object_show(ly);
744 evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_list_ug_delete_layout, p);
746 calendar_error_e error = CALENDAR_ERROR_NONE;
747 error = calendar_db_add_changed_cb(_calendar_event._uri, __cal_list_ug_update_callback, p);
748 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_add_changed_cb() is failed(%x)", error);
753 static void __cal_list_ug_get_message_content(calendar_record_h record, char *body , int nsize)
758 char *title = _calendar_get_summary(record);
760 strncat(body, title, nsize - CAL_STRLEN(body));
761 strncat(body, "\n", nsize - CAL_STRLEN(body));
763 char *location = _calendar_get_location(record);
765 if (CAL_STRLEN(location)) {
766 strncat(body, location, nsize - CAL_STRLEN(body));
767 strncat(body, "\n", nsize - CAL_STRLEN(body));
772 const char *time_format = NULL;
774 time_format = CAL_UTIL_TIME_FORMAT_6;
776 time_format = CAL_UTIL_TIME_FORMAT_1;
778 struct tm tm_start, tm_end;
779 calendar_time_s start_time = {0};
780 calendar_time_s end_time = {0};
781 _calendar_get_start_time(record, &start_time);
782 _calendar_get_end_time(record, &end_time);
784 if (_calendar_is_allday_record(record)) {
785 long long int lli_time = time(NULL);
787 cal_util_convert_lli_to_tm(NULL, lli_time, &tm_start);
791 tm_start.tm_year = start_time.time.date.year - 1900;
792 tm_start.tm_mon = start_time.time.date.month - 1;
793 tm_start.tm_mday = start_time.time.date.mday;
795 tm_end.tm_year = end_time.time.date.year - 1900;
796 tm_end.tm_mon = end_time.time.date.month - 1;
797 tm_end.tm_mday = end_time.time.date.mday;
799 if (tm_start.tm_year == tm_end.tm_year
800 && tm_start.tm_mon == tm_end.tm_mon
801 && tm_start.tm_mday == tm_end.tm_mday) {
802 cal_util_get_time_text(text, sizeof(text), CAL_UTIL_DATE_FORMAT_1, NULL, &tm_start);
803 strncat(body, text, nsize - CAL_STRLEN(body));
805 cal_util_get_time_text(text, sizeof(text), CAL_UTIL_DATE_FORMAT_1, NULL, &tm_start);
806 strncat(body, text, nsize - CAL_STRLEN(body));
808 strncat(body, " ~ ", nsize - CAL_STRLEN(body));
810 cal_util_get_time_text(text, sizeof(text), CAL_UTIL_DATE_FORMAT_1, NULL, &tm_end);
811 strncat(body, text, nsize - CAL_STRLEN(body));
816 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &tm_start);
817 cal_util_convert_lli_to_tm(NULL, end_time.time.utime, &tm_end);
819 cal_util_get_time_text(text, sizeof(text), CAL_UTIL_DATE_FORMAT_1, time_format, &tm_start);
820 strncat(body, text, nsize - CAL_STRLEN(body));
822 strncat(body, " ~ " , nsize - CAL_STRLEN(body));
824 cal_util_get_time_text(text, sizeof(text), CAL_UTIL_DATE_FORMAT_1, time_format, &tm_end);
825 strncat(body, text, nsize - CAL_STRLEN(body));
833 static void __cal_list_ug_add_bundle_event_content(service_h service, int record_index, int result_index)
836 c_ret_if(record_index <= 0);
839 char value[1024*5] = {0};
841 calendar_record_h record = NULL;
843 record = _calendar_get_record_with_index(record_index);
846 __cal_list_ug_get_message_content(record, value, sizeof(value));
848 snprintf(key, sizeof(key), "text%d", result_index);
850 calendar_error_e error = CALENDAR_ERROR_NONE;
852 error = calendar_record_destroy(record, true);
853 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
855 int r = service_add_extra_data(service, key, value);
856 c_ret_if(r != SERVICE_ERROR_NONE);
859 static void __cal_list_ug_add_bundle_vcs(service_h service, int record_index, int result_index)
862 c_ret_if(record_index <= 0);
864 calendar_record_h record = NULL;
866 record = _calendar_get_record_with_index(record_index);
869 calendar_error_e error = CALENDAR_ERROR_NONE;
871 calendar_list_h list = NULL;
873 error = calendar_list_create(&list);
874 if (error != CALENDAR_ERROR_NONE) {
875 ERR("calendar_list_create() is failed(%x)", error);
877 calendar_record_destroy(record, true);
882 error = calendar_list_add(list, record);
883 if (error != CALENDAR_ERROR_NONE) {
884 ERR("calendar_list_add() is failed(%x)", error);
886 calendar_list_destroy(list, false);
888 calendar_record_destroy(record, true);
893 char *vcs_data = NULL;
895 error = calendar_vcalendar_make_from_records(list, &vcs_data);
896 if (error != CALENDAR_ERROR_NONE) {
897 ERR("calendar_vcalendar_make_from_records() is failed(%x)", error);
899 calendar_list_destroy(list, true);
904 if (!CAL_STRLEN(vcs_data)) {
905 ERR("vcs_data is empty");
907 calendar_list_destroy(list, true);
913 char value[FILENAME_MAX] = {0};
915 snprintf(key, sizeof(key), "vfile%d", result_index);
916 snprintf(value, sizeof(value), "%s/Calendar_%d.vcs", VFILE_PATH, record_index);
918 int fd = open(value, O_WRONLY|O_CREAT|O_TRUNC, 0644);
920 ERR("open() is failed.");
922 calendar_list_destroy(list, true);
929 int r = write(fd, vcs_data, strlen(vcs_data));
931 ERR("write() is failed.");
933 cal_util_update_media_db(value);
940 error = calendar_list_destroy(list, true);
941 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)");
943 r = service_add_extra_data(service, key, value);
944 c_ret_if(r != SERVICE_ERROR_NONE);
947 static void __cal_list_ug_add_bundle(service_h service, GList *record_index_list, struct ug_data *ugd)
950 c_ret_if(!record_index_list);
953 record_index_list = g_list_first(record_index_list);
955 int result_index = 0;
957 while (record_index_list && record_index_list->data) {
959 int record_index = (int)record_index_list->data;
963 __cal_list_ug_add_bundle_event_content(service, record_index, ++result_index);
966 __cal_list_ug_add_bundle_vcs(service, record_index, ++result_index);
973 record_index_list = g_list_next(record_index_list);
977 static service_h __cal_list_ug_make_bundle(cal_list_ug_data *p, struct ug_data *ugd)
980 c_retv_if(!ugd, NULL);
982 char buf[32] = {'\0'};
985 int r = service_create(&service);
986 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
988 Elm_Object_Item* item = elm_genlist_first_item_get(p->genlist);
991 service_destroy(service);
995 GList *record_index_list = NULL;
999 cal_list_ug_item_data* item_data = elm_object_item_data_get(item);
1002 ERR("elm_object_item_data_get() is failed!");
1003 service_destroy(service);
1007 if (item_data->checked)
1008 record_index_list = g_list_append(record_index_list, (void *)_calendar_get_record_index(item_data->record));
1010 item = elm_genlist_item_next_get(item);
1015 if (record_index_list) {
1016 __cal_list_ug_add_bundle(service, record_index_list, ugd);
1018 count = g_list_length(record_index_list);
1020 g_list_free(record_index_list);
1023 snprintf(buf, sizeof(buf), "%d", count);
1025 r = service_add_extra_data(service, "count", buf);
1026 if(r != SERVICE_ERROR_NONE)
1028 ERR("service_add_extra_data_array() is failed(%d)", r);
1029 service_destroy(service);
1033 char **value = calloc(count, sizeof(char *));
1035 ERR("value is NULL!");
1036 service_destroy(service);
1043 for (i = 0; i < count; i++) {
1044 snprintf(key, sizeof(key), "vfile%d", i + 1);
1045 service_get_extra_data(service, key, &value[i]);
1048 r = service_add_extra_data_array(service, CAL_APPCONTROL_PATH, (const char **)value, count);
1049 if(r != SERVICE_ERROR_NONE)
1051 ERR("service_add_extra_data_array() is failed(%d)", r);
1053 service_destroy(service);
1057 if (ugd->item_type == ITEM_TYPE_EVENT)
1058 r = service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_EVENT);
1060 r = service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_TODO);
1062 c_warn_if(r != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%d)", r);
1064 r = service_add_extra_data(service, "result", "success");
1065 c_warn_if(r != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%d)", r);
1073 static void __cal_list_ug_attach(void *data, Evas_Object *obj, void *ei)
1075 c_retm_if(!data, "data is null");
1077 Evas_Object *ly = data;
1078 cal_list_ug_data *p;
1079 struct ug_data *ugd;
1080 service_h service = NULL;
1082 p = CAL_UTIL_GET_PRIV_DATA(ly);
1083 c_retm_if(!p, "p is null");
1086 c_retm_if(!ugd, "ugd is null");
1088 cal_util_hide_small_information(p->ly);
1090 switch (ugd->mode) {
1093 service = __cal_list_ug_make_bundle(p, ugd);
1102 ug_send_result(ugd->ug, service);
1103 service_destroy(service);
1106 ug_destroy_me(ugd->ug);
1109 static void __cal_list_ug_add_controlbar( struct ug_data *ugd, Evas_Object *ly, const char* title)
1111 Elm_Object_Item* navi_item = NULL;
1113 cal_list_ug_data* p = evas_object_data_get(ly,"priv");
1114 c_retm_if(!p, "p is null");
1116 navi_item = elm_naviframe_item_push(ugd->naviframe, title, NULL, NULL, ly, NULL);
1119 ERR("elm_naviframe_item_push returned null");
1123 if (ugd->selection_mode == SELECTION_MODE_MULTIPLE) {
1124 Evas_Object * attach_button = cal_util_add_toolbar_button(ugd->naviframe, "toolbar_button1", S_("IDS_COM_POP_ATTACH"), __cal_list_ug_attach, ly);
1125 c_retm_if(!attach_button, "elm_toolbar_item_append returned null");
1127 p->bt = attach_button;
1129 elm_object_disabled_set(p->bt, EINA_TRUE);
1133 void cal_list_ug_create(const char *title, struct ug_data *ugd)
1135 Evas_Object *ly = __cal_list_ug_create_layout(ugd->naviframe, ugd);
1141 __cal_list_ug_add_controlbar(ugd, ly, title);
1144 static void __cal_list_ug_searchbar_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1148 cal_list_ug_data *p = data;
1151 p->searchtext = elm_object_text_get(elm_object_part_content_get(p->searchbar, "elm.swallow.content"));
1153 // TODO: Show search result
1154 __cal_list_ug_update_callback(_calendar_event._uri, p);
1156 if (0 < p->checked_event_count)
1157 elm_object_disabled_set(p->bt, EINA_FALSE);
1159 elm_object_disabled_set(p->bt, EINA_TRUE);
1161 __cal_list_ug_update_selection_info(p);
1164 static void __cal_list_ug_cancel_button_callback(void *data, Evas_Object *obj, void *event_info)
1168 c_retm_if(!data, "data is null");
1169 cal_list_ug_data *p = data;
1170 Eina_List *l = NULL;
1171 cal_list_ug_item_data *item =NULL;
1173 Evas_Object *en = elm_object_part_content_get(p->searchbar, "elm.swallow.content");
1174 c_retm_if(!en, "elm_object_part_content_get returned null");
1176 Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(en);
1177 c_retm_if(!imf_context, "elm_entry_imf_context_get returned null");
1180 ecore_imf_context_input_panel_hide(imf_context);
1182 if (0 < p->checked_event_count)
1183 elm_object_disabled_set(p->bt, EINA_FALSE);
1185 elm_object_disabled_set(p->bt, EINA_TRUE);
1187 p->checked_event_count = 0;
1189 EINA_LIST_FOREACH(p->event_list, l, item) {
1190 if (item != NULL && item->checked) {
1191 p->checked_event_count++;
1195 __cal_list_ug_update_selection_info(p);
1198 static void __cal_list_ug_searchbar_entry_unfocused_callback(void *data, Evas_Object *obj, void *event_info)
1200 c_retm_if(!data, "data is null.");
1201 cal_list_ug_data *p = data;
1203 if (p->checked_event_count <= 0) {
1204 elm_object_disabled_set(p->bt, EINA_TRUE);
1206 elm_object_disabled_set(p->bt, EINA_FALSE);
1209 __cal_list_ug_update_selection_info(p);
1212 static void __cal_list_ug_searchbar_clicked_callback(void *data, Evas_Object *obj, void *event_info)
1214 c_retm_if(!data, "data is null.");
1215 cal_list_ug_data *p = data;
1217 elm_object_disabled_set(p->bt, EINA_TRUE);