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.
18 #include <ui-gadget-module.h>
24 #include "edit-alarm.h"
25 #include "edit-repeat.h"
28 #include "gi-timepicker.h"
29 #include "save-cancel.h"
30 #include "external-ug.h"
31 #include "cld-images.h"
34 #define INVALID_TIMEZONE_VALUE (100)
35 #define CAL_EDIT_UG_MAX_ATTACHMENT_COUNT 6
40 cal_appcontrol_item_type item_type;
43 Evas_Object *base_layout;
44 Evas_Object *naviframe;
51 calendar_record_h event;
52 calendar_record_h todo;
53 calendar_record_h record;
54 calendar_record_h instance;
56 Eina_Bool is_edit_mode;
58 Evas_Object *dialogue;
60 Evas_Object *title_entry;
62 Evas_Object *start_date;
63 Evas_Object *start_date_title;
64 Evas_Object *end_date;
65 Evas_Object *end_date_title;
67 Evas_Object *timezone;
68 Evas_Object *location;
69 Evas_Object *location_entry;
72 Evas_Object *note_entry;
73 Eina_List *alarm_item_list;
74 Evas_Object *alarm_plus_button;
77 Evas_Object *repeat_layout;
81 Evas_Object *multibuttonentry; // entry participants
83 Evas_Object *due_date;
84 Evas_Object *due_date_title;
85 Evas_Object *no_due_date;
86 Evas_Object *priority;
88 cal_save_cancel_h save_cancel;
91 int repeat_freq; // repeat_freq off, daily, ...
92 calendar_range_type_e repeat_range;
94 struct tm repeat_until;
100 ui_gadget_h ug_worldclock;
102 Eina_Bool is_selected_timezone;
103 char * timezone_path; /* Asia/Seoul */
104 char * timezone_city; /* IDS_WCL_BODY_CITYNAME_SEOUL */
105 char * timezone_offset; /* GMT+9 */
107 Eina_List *calendar_book_list; //For save to
109 Elm_Object_Item *event_item;
110 Elm_Object_Item *todo_item;
118 struct tm stm; // start
119 struct tm etm; // end
121 Eina_Bool is_no_due_date;
125 enum __cal_edit_wday {
126 CAL_EDIT_WDAY_SUNDAY,
127 CAL_EDIT_WDAY_MONDAY,
128 CAL_EDIT_WDAY_TUESDAY,
129 CAL_EDIT_WDAY_WEDNESDAY,
130 CAL_EDIT_WDAY_THURSDAY,
131 CAL_EDIT_WDAY_FRIDAY,
132 CAL_EDIT_WDAY_SATURDAY,
136 static int __cal_edit_ug_initialize(cal_edit_ug_data *data)
140 c_retv_if(!data, -1);
142 calendar_error_e error = CALENDAR_ERROR_NONE;
144 error = calendar_connect();
145 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_connect() is failed(%x)", error);
147 _calendar_init_hash();
149 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
150 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
152 cal_util_connect_pattern_generator();
157 static int __cal_edit_ug_finish(cal_edit_ug_data *data)
161 c_retv_if(!data, -1);
163 calendar_error_e error = CALENDAR_ERROR_NONE;
165 error = calendar_disconnect();
166 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
168 elm_theme_extension_del(NULL, EDJDIR "/calendar_theme.edj");
169 elm_theme_extension_del(NULL, EDJDIR "/calendar_theme2.edj");
171 cal_util_disconnect_pattern_generator();
175 if(data->item_type == ITEM_TYPE_TODO)
176 ret = vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, 0);
178 ret = vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, 1);
179 c_warn_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, %d) is failed(%d)", 0, ret);
185 static inline void __cal_edit_ug_set_record_title(calendar_record_h record, const char *title_str)
187 calendar_error_e error = CALENDAR_ERROR_NONE;
189 if (_calendar_is_task_record(record)) {
190 error = calendar_record_set_str(record, _calendar_todo.summary, title_str);
192 error = calendar_record_set_str(record, _calendar_event.summary, title_str);
195 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
198 static inline void __cal_edit_ug_set_record_location(calendar_record_h record, const char *address, double latitude, double longitude)
200 calendar_error_e error = CALENDAR_ERROR_NONE;
202 if (_calendar_is_task_record(record)) {
204 if (CAL_STRLEN(address))
205 error = calendar_record_set_str(record, _calendar_todo.location, address);
207 error = calendar_record_set_str(record, _calendar_todo.location, "");
209 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
211 error = calendar_record_set_double(record, _calendar_todo.latitude, latitude);
212 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
214 error = calendar_record_set_double(record, _calendar_todo.longitude, longitude);
215 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
218 if (CAL_STRLEN(address))
219 error = calendar_record_set_str(record, _calendar_event.location, address);
221 error = calendar_record_set_str(record, _calendar_event.location, "");
223 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
226 error = calendar_record_set_double(record, _calendar_event.latitude, latitude);
227 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
229 error = calendar_record_set_double(record, _calendar_event.longitude, longitude);
230 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
234 static inline void __cal_edit_ug_set_record_note(calendar_record_h record, const char *note_str)
236 calendar_error_e error = CALENDAR_ERROR_NONE;
238 if (_calendar_is_task_record(record))
239 error = calendar_record_set_str(record, _calendar_todo.description, note_str);
241 error = calendar_record_set_str(record, _calendar_event.description, note_str);
243 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
246 static void __cal_edit_ug_set_timezone(calendar_record_h record, const char *timezone_path, const char *timezone_city)
249 c_ret_if(!CAL_STRLEN(timezone_path));
250 c_ret_if(!CAL_STRLEN(timezone_city));
252 calendar_error_e error = CALENDAR_ERROR_NONE;
254 if (_calendar_is_task_record(record)) {
255 error = calendar_record_set_str(record, _calendar_todo.due_tzid, timezone_path);
256 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
258 error = calendar_record_set_str(record, _calendar_event.start_tzid, timezone_path);
259 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
261 error = calendar_record_set_str(record, _calendar_event.end_tzid, timezone_path);
262 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
265 _calendar_set_timezone_city(record, timezone_city);
268 static void __cal_edit_ug_set_record_time(cal_edit_ug_data *p, calendar_record_h record)
273 calendar_error_e error = CALENDAR_ERROR_NONE;
275 calendar_time_s start_time = {0};
277 _calendar_get_start_time(record, &start_time);
279 calendar_time_s end_time = {0};
281 _calendar_get_end_time(record, &end_time);
283 if (_calendar_is_allday_record(record)) {
285 start_time.time.date.year = p->stm.tm_year + 1900;
286 start_time.time.date.month = p->stm.tm_mon + 1;
287 start_time.time.date.mday = p->stm.tm_mday;
289 end_time.time.date.year = p->stm.tm_year + 1900;
290 end_time.time.date.month = p->stm.tm_mon + 1;
291 end_time.time.date.mday = p->stm.tm_mday;
294 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
295 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
298 error = calendar_record_set_caltime(record, _calendar_event.start_time, start_time);
299 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
301 error = calendar_record_set_caltime(record, _calendar_event.end_time, end_time);
302 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
304 __cal_edit_ug_set_timezone(record, p->timezone_path, p->timezone_city);
307 static void __cal_edit_ug_set_rrule_wday(calendar_record_h record, enum __cal_edit_wday tm_wday)
311 calendar_error_e error = CALENDAR_ERROR_NONE;
314 case CAL_EDIT_WDAY_SUNDAY:
315 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
318 case CAL_EDIT_WDAY_MONDAY:
319 error = calendar_record_set_str(record, _calendar_event.byday, "MO");
322 case CAL_EDIT_WDAY_TUESDAY:
323 error = calendar_record_set_str(record, _calendar_event.byday, "TU");
326 case CAL_EDIT_WDAY_WEDNESDAY:
327 error = calendar_record_set_str(record, _calendar_event.byday, "WE");
330 case CAL_EDIT_WDAY_THURSDAY:
331 error = calendar_record_set_str(record, _calendar_event.byday, "TH");
334 case CAL_EDIT_WDAY_FRIDAY:
335 error = calendar_record_set_str(record, _calendar_event.byday, "FR");
338 case CAL_EDIT_WDAY_SATURDAY:
339 error = calendar_record_set_str(record, _calendar_event.byday, "SA");
343 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
347 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
350 static void __cal_edit_ug_set_rrule_month(calendar_record_h record, int tm_mon)
354 char buffer[8] = {0};
356 snprintf(buffer, sizeof(buffer), "%d", tm_mon + 1);
358 calendar_error_e error = CALENDAR_ERROR_NONE;
360 error = calendar_record_set_str(record, _calendar_event.bymonth, buffer);
361 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
364 static void __cal_edit_ug_set_rrule_mday(calendar_record_h record, int tm_mday)
368 char buffer[8] = {0};
370 snprintf(buffer, sizeof(buffer), "%d", tm_mday);
372 calendar_error_e error = CALENDAR_ERROR_NONE;
374 error = calendar_record_set_str(record, _calendar_event.bymonthday, buffer);
375 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
378 static int __cal_edit_ug_g_list_compare(const void* data1, const void* data2)
380 const Cal_Reminder* reminder1 = (Cal_Reminder*)data1;
381 const Cal_Reminder* reminder2 = (Cal_Reminder*)data2;
383 if (reminder1->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
384 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
385 long long int dt1, dt2;
386 cal_util_convert_tm_to_lli(NULL, &reminder1->datetime, &dt1);
387 cal_util_convert_tm_to_lli(NULL, &reminder2->datetime, &dt2);
398 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
401 return reminder1->alarm_value - reminder2->alarm_value;
405 static int __cal_edit_ug_g_list_compare_with_data(const void* data1, const void* data2, void* user_data)
407 return __cal_edit_ug_g_list_compare(data1, data2);
411 static void __cal_edit_ug_set_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
415 c_retm_if(!p, "p is null");
416 c_retm_if(!record, "record is null");
420 Eina_Bool is_task = _calendar_is_task_record(record);
423 _calendar_clear_child_record(record, _calendar_todo.calendar_alarm);
425 _calendar_clear_child_record(record, _calendar_event.calendar_alarm);
428 Eina_List* list = NULL;
429 Evas_Object *item = NULL;
430 EINA_LIST_FOREACH(p->alarm_item_list, list, item) {
432 Cal_Reminder* reminder = evas_object_data_get(item, "data");
434 if (g_list_find_custom(temp, reminder, __cal_edit_ug_g_list_compare))
437 temp = g_list_insert_sorted_with_data(temp, reminder, __cal_edit_ug_g_list_compare_with_data, NULL);
439 calendar_record_h calendar_alarm = cal_reminder_get_cal_val(reminder);
441 calendar_error_e error = CALENDAR_ERROR_NONE;
444 error = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, calendar_alarm);
446 error = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, calendar_alarm);
448 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() is failed(%x)", error);
453 static void __cal_edit_ug_set_record_repeat(cal_edit_ug_data *p)
455 c_retm_if(!p, "p is null");
457 calendar_error_e error = CALENDAR_ERROR_NONE;
459 switch (p->repeat_freq) {
460 case CALENDAR_RECURRENCE_NONE:
463 case CALENDAR_RECURRENCE_DAILY:
464 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
467 case CAL_REPEAT_EVERY_3_DAY:
468 p->repeat_freq = CALENDAR_RECURRENCE_DAILY;
469 error = calendar_record_set_int(p->event, _calendar_event.interval, 3);
472 case CALENDAR_RECURRENCE_WEEKLY:
473 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
474 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
477 case CAL_REPEAT_EVERY_2_WEEK:
478 p->repeat_freq = CALENDAR_RECURRENCE_WEEKLY;
479 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
480 error = calendar_record_set_int(p->event, _calendar_event.interval, 2);
483 case CALENDAR_RECURRENCE_YEARLY:
484 __cal_edit_ug_set_rrule_month(p->event, p->stm.tm_mon);
485 case CALENDAR_RECURRENCE_MONTHLY:
486 __cal_edit_ug_set_rrule_mday(p->event, p->stm.tm_mday);
487 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
494 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
496 error = calendar_record_set_int(p->event, _calendar_event.freq, p->repeat_freq);
497 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
499 error = calendar_record_set_int(p->event, _calendar_event.range_type, p->repeat_range);
500 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
502 if (CALENDAR_RECURRENCE_NONE != p->repeat_freq) {
504 if (p->repeat_range == CALENDAR_RANGE_COUNT) {
505 error = calendar_record_set_int(p->event, _calendar_event.count, p->repeat_count);
506 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
507 } else if (p->repeat_range == CALENDAR_RANGE_UNTIL) {
509 error = calendar_record_set_int(p->event, _calendar_event.count, 0);
510 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
512 calendar_time_s until_time = {0};
514 until_time.type = CALENDAR_TIME_UTIME;
515 cal_util_convert_tm_to_lli(NULL, &p->repeat_until, &until_time.time.utime);
517 error = calendar_record_set_caltime(p->event, _calendar_event.until_time, until_time);
518 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
523 static void __cal_edit_ug_set_record_save_to( calendar_record_h record, int calendar_book_id)
525 calendar_error_e error = CALENDAR_ERROR_NONE;
527 if (_calendar_is_task_record(record)) {
528 error = calendar_record_set_int(record, _calendar_todo.calendar_book_id, calendar_book_id);
529 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
531 error = calendar_record_set_int(record, _calendar_event.calendar_book_id, calendar_book_id);
532 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
534 calendar_record_h calendar_book = NULL;
536 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
537 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
539 char *organizer_name = NULL;
541 error = calendar_record_get_str(calendar_book, _calendar_book.description, &organizer_name);
542 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
544 error = calendar_record_set_str(record, _calendar_event.organizer_name, organizer_name);
545 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
547 CAL_FREE(organizer_name);
549 error = calendar_record_destroy(calendar_book, true);
550 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
554 static void __cal_edit_ug_set_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
556 c_retm_if(!p, "p is null");
557 c_retm_if(!record, "record is null");
559 calendar_error_e error = CALENDAR_ERROR_NONE;
561 calendar_time_s due_time = {0};
563 _calendar_get_end_time(record, &due_time);
565 error = calendar_record_set_str(record, _calendar_todo.due_tzid, p->timezone_path);
566 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
568 if (p->is_no_due_date) {
569 due_time.time.utime = CALENDAR_TODO_NO_DUE_DATE;
571 cal_util_convert_tm_to_lli(NULL, &p->etm, &due_time.time.utime);
574 error = calendar_record_set_caltime(record, _calendar_todo.due_time, due_time);
575 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
578 static void __cal_edit_ug_set_record_priority(calendar_record_h record, int priority)
580 c_retm_if(!record, "record is null");
582 calendar_error_e error = CALENDAR_ERROR_NONE;
584 error = calendar_record_set_int(record, _calendar_todo.priority, priority);
585 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
588 static void __cal_edit_ug_initialize_event_record(cal_edit_ug_data *p)
592 c_retm_if(!p, "p is null");
594 calendar_error_e error = CALENDAR_ERROR_NONE;
597 error = calendar_record_create(_calendar_event._uri, &p->event);
598 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
601 p->stm = p->base_time;
602 p->stm.tm_min = p->stm.tm_sec = 0;
604 if (0 <= p->base_time.tm_hour)
605 p->stm.tm_hour = p->base_time.tm_hour;
607 cal_util_update_tm_hour(&p->stm,1);
610 cal_util_update_tm_hour(&p->etm,1);
612 __cal_edit_ug_set_record_time(p, p->event);
614 struct tm repeat_until = p->stm;
615 cal_util_update_tm_month (&repeat_until, 1);
616 p->repeat_freq = CALENDAR_RECURRENCE_NONE;
617 p->repeat_range = CALENDAR_RANGE_NONE;
618 p->repeat_count = 10;
619 __cal_edit_ug_set_record_repeat(p);
621 __cal_edit_ug_set_record_save_to(p->event, DEFAULT_EVENT_CALENDAR_BOOK_ID);
628 static void __cal_edit_ug_initialize_todo_record(cal_edit_ug_data *p)
632 c_retm_if(!p, "p is null");
634 calendar_error_e error = CALENDAR_ERROR_NONE;
637 error = calendar_record_create(_calendar_todo._uri, &p->todo);
638 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
641 p->stm = p->base_time;
642 p->stm.tm_min = p->stm.tm_sec = 0;
644 if (0 <= p->base_time.tm_hour)
645 p->stm.tm_hour = p->base_time.tm_hour;
647 cal_util_update_tm_hour(&p->stm,1);
650 cal_util_update_tm_hour(&p->etm,1);
652 calendar_time_s end_time = {0};
653 end_time.type = CALENDAR_TIME_UTIME;
655 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
657 error = calendar_record_set_caltime(p->todo, _calendar_todo.due_time, end_time);
658 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
660 __cal_edit_ug_set_timezone(p->todo, p->timezone_path, p->timezone_city);
662 __cal_edit_ug_set_record_save_to(p->todo, DEFAULT_TODO_CALENDAR_BOOK_ID);
664 __cal_edit_ug_set_record_priority(p->todo, CALENDAR_TODO_PRIORITY_NORMAL);
671 static inline char * __cal_edit_ug_get_record_title(calendar_record_h record)
673 c_retvm_if(!record, NULL, "record is null");
675 calendar_error_e error = CALENDAR_ERROR_NONE;
676 char *summary = NULL;
678 if (_calendar_is_task_record(record))
679 error = calendar_record_get_str(record, _calendar_todo.summary, &summary);
681 error = calendar_record_get_str(record, _calendar_event.summary, &summary);
683 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
688 static inline void __cal_edit_ug_get_record_location(cal_edit_ug_data *p, calendar_record_h record)
690 calendar_error_e error = CALENDAR_ERROR_NONE;
692 p->address = _calendar_get_location(record);
694 if (_calendar_is_task_record(record))
696 error = calendar_record_get_double(record, _calendar_todo.latitude, &p->latitude);
697 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
698 error = calendar_record_get_double(record, _calendar_todo.longitude, &p->longitude);
699 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
703 error = calendar_record_get_double(record, _calendar_event.latitude, &p->latitude);
704 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
705 error = calendar_record_get_double(record, _calendar_event.longitude, &p->longitude);
706 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
710 static inline char * __cal_edit_ug_get_record_note(calendar_record_h record)
712 c_retvm_if(!record, NULL, "record is null");
714 calendar_error_e error = CALENDAR_ERROR_NONE;
717 if (_calendar_is_task_record(record))
718 error = calendar_record_get_str(record, _calendar_todo.description, ¬e);
720 error = calendar_record_get_str(record, _calendar_event.description, ¬e);
722 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
727 static int __cal_edit_ug_get_timezone_offset_with_standard_name(const char *standard_name)
729 int timezone_offset = 0;
731 c_retv_if(!CAL_STRLEN(standard_name), timezone_offset);
733 calendar_error_e error = CALENDAR_ERROR_NONE;
735 calendar_query_h query = NULL;
737 error = calendar_query_create(_calendar_timezone._uri, &query);
738 c_retvm_if(error != CALENDAR_ERROR_NONE, timezone_offset, "calendar_query_create() is failed(%x)", error);
740 calendar_filter_h filter = NULL;
742 error = calendar_filter_create(_calendar_timezone._uri, &filter);
743 if (error != CALENDAR_ERROR_NONE) {
745 ERR("calendar_filter_create() is failed(%x)", error);
746 calendar_query_destroy(query);
750 error = calendar_filter_add_str(filter, _calendar_timezone.standard_name, CALENDAR_MATCH_EXACTLY, standard_name);
751 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
753 error = calendar_query_set_filter(query, filter);
754 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
756 calendar_list_h list = NULL;
758 error = calendar_db_get_records_with_query(query, 0, 1, &list);
759 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
761 error = calendar_list_first(list);
762 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
764 calendar_record_h timezone = NULL;
766 error = calendar_list_get_current_record_p(list, &timezone);
767 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
769 error = calendar_record_get_int(timezone, _calendar_timezone.tz_offset_from_gmt, &timezone_offset);
770 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
772 error = calendar_list_destroy(list, true);
773 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
775 error = calendar_filter_destroy(filter);
776 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
778 error = calendar_query_destroy(query);
779 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
781 return (-1)*timezone_offset;
784 static void __cal_edit_ug_get_timezone_for_eas(cal_edit_ug_data *p, calendar_record_h record)
789 calendar_error_e error = CALENDAR_ERROR_NONE;
791 char *standard_name = NULL;
793 if (_calendar_is_task_record(record))
794 error = calendar_record_get_str_p(record, _calendar_todo.due_tzid, &standard_name);
796 error = calendar_record_get_str_p(record, _calendar_event.start_tzid, &standard_name);
798 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
800 c_ret_if(!CAL_STRLEN(standard_name));
802 int timezone_offset = __cal_edit_ug_get_timezone_offset_with_standard_name(standard_name);
804 cal_util_get_timezone_id(timezone_offset, &p->timezone_path);
807 static void __cal_edit_ug_get_record_time_zone(cal_edit_ug_data *p, calendar_record_h record)
812 calendar_error_e error = CALENDAR_ERROR_NONE;
814 if (_calendar_is_eas_record(record))
815 __cal_edit_ug_get_timezone_for_eas(p, record);
817 if (_calendar_is_task_record(record))
818 error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
820 error = calendar_record_get_str(record, _calendar_event.start_tzid, &p->timezone_path);
822 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
824 p->timezone_city = _calendar_get_timezone_city(record);
827 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
829 c_ret_if(!CAL_STRLEN(p->timezone_path));
830 c_ret_if(!CAL_STRLEN(p->timezone_city));
833 static void __cal_edit_ug_get_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
835 c_retm_if(!p, "p is null");
836 c_retm_if(!record, "record is null");
839 g_list_free(p->alarm_list);
840 p->alarm_list = NULL;
845 Eina_Bool is_task = _calendar_is_task_record(record);
846 calendar_error_e error = CALENDAR_ERROR_NONE;
850 error = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, (unsigned int *)&alarm_count);
851 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
855 error = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, (unsigned int *)&alarm_count);
856 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
860 for (i = 0; i < alarm_count; i++) {
861 calendar_record_h calendar_alarm = NULL;
865 error = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, i, &calendar_alarm);
866 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
870 error = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, i, &calendar_alarm);
871 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
874 Cal_Reminder* reminder = cal_reminder_create(calendar_alarm);
875 p->alarm_list = g_list_append(p->alarm_list,(void *)reminder);
878 p->alarm_list = g_list_first(p->alarm_list);
881 static void __cal_edit_ug_get_record_repeat(cal_edit_ug_data *p, calendar_record_h record)
886 calendar_record_h original_record = NULL;
887 int original_event_id = 0;
888 calendar_error_e error = CALENDAR_ERROR_NONE;
890 error = calendar_record_get_int(record, _calendar_event.original_event_id, &original_event_id);
891 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
893 if (0 < original_event_id) {
895 error = calendar_db_get_record(_calendar_event._uri, original_event_id, &original_record);
896 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
899 if (!original_record)
900 original_record = record;
902 error = calendar_record_get_int(record, _calendar_event.freq, &p->repeat_freq);
903 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
905 if (p->repeat_freq == CALENDAR_RECURRENCE_WEEKLY) {
909 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
910 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
913 p->repeat_freq = CAL_REPEAT_EVERY_2_WEEK;
915 } else if (p->repeat_freq == CALENDAR_RECURRENCE_DAILY) {
919 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
920 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
923 p->repeat_freq = CAL_REPEAT_EVERY_3_DAY;
926 error = calendar_record_get_int(record, _calendar_event.range_type, (int *)&p->repeat_range);
927 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
929 if (p->repeat_range == CALENDAR_RANGE_NONE) {
930 p->repeat_count = 10;
932 p->repeat_until = p->stm;
933 cal_util_update_tm_month (&p->repeat_until, 1);
936 error = calendar_record_get_int(record, _calendar_event.count, &p->repeat_count);
937 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
939 calendar_time_s until_utime = {0};
941 error = calendar_record_get_caltime(record, _calendar_event.until_time, &until_utime);
942 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
944 cal_util_convert_lli_to_tm(NULL, until_utime.time.utime, &p->repeat_until);
947 if (original_record != record) {
948 error = calendar_record_destroy(original_record, true);
949 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
953 static int __cal_edit_ug_get_record_priority(calendar_record_h record)
955 c_retv_if(!record, 0);
957 calendar_error_e error = CALENDAR_ERROR_NONE;
961 error = calendar_record_get_int(record, _calendar_todo.priority, (int *)&priority);
962 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
967 static void __cal_edit_ug_get_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
969 c_retm_if(!p, "p is null");
970 c_retm_if(!record, "record is null");
972 calendar_error_e error = CALENDAR_ERROR_NONE;
974 calendar_time_s due_time = {0};
976 _calendar_get_end_time(record, &due_time);
978 cal_util_convert_lli_to_tm(NULL, due_time.time.utime, &p->etm);
980 if (due_time.time.utime == CALENDAR_TODO_NO_DUE_DATE) {
981 p->is_no_due_date = EINA_TRUE;
982 //p->etm = p->base_time;
985 error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
986 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
988 c_ret_if(!p->timezone_path);
990 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
993 static void __cal_edit_ug_update_title_item(Evas_Object *entry, calendar_record_h record)
995 c_retm_if(!entry, "entry is null");
996 c_retm_if(!record, "record is null");
998 char* title = __cal_edit_ug_get_record_title(record);
1000 elm_entry_entry_set(entry, title);
1005 static void __cal_edit_ug_update_note_item(Evas_Object *entry, calendar_record_h record)
1007 c_retm_if(!entry, "entry is null");
1008 c_retm_if(!record, "record is null");
1010 char* note = __cal_edit_ug_get_record_note(record);
1012 elm_entry_entry_set(entry, note);
1017 static void __cal_edit_ug_update_location_item(cal_edit_ug_data *p, calendar_record_h record)
1019 c_retm_if(!p, "p is null");
1020 c_retm_if(!record, "record is null");
1022 __cal_edit_ug_get_record_location(p, record);
1023 elm_entry_entry_set(p->location_entry, p->address);
1026 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz);
1028 static void __cal_edit_ug_update_save_to_item(cal_edit_ug_data *p, calendar_record_h record)
1030 c_retm_if(!p, "p is null");
1032 int calendar_book_id = _calendar_get_calendar_index(record);
1035 char* saveto_text = NULL;
1036 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
1037 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
1038 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
1039 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
1041 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
1042 saveto_text = strdup(buf);
1045 elm_object_part_text_set(p->saveto, "elm.text.1", saveto_text);
1047 CAL_FREE(saveto_text);
1050 static void __cal_edit_ug_update_priority_item(cal_edit_ug_data *p, calendar_record_h record)
1052 c_retm_if(!p, "p is null");
1053 c_retm_if(!record, "record is null");
1055 char* priority_text = NULL;
1056 int priority = __cal_edit_ug_get_record_priority(record);
1058 case CALENDAR_TODO_PRIORITY_LOW:
1059 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
1061 case CALENDAR_TODO_PRIORITY_NORMAL:
1062 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
1064 case CALENDAR_TODO_PRIORITY_HIGH:
1065 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
1071 elm_object_part_text_set(p->priority, "elm.text.1", priority_text);
1072 CAL_FREE(priority_text);
1076 static void __cal_edit_ug_update_start_language(Evas_Object *item)
1080 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_FROM"));
1083 static void __cal_edit_ug_update_end_language(Evas_Object *item)
1087 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_TO"));
1090 static void __cal_edit_ug_update_due_language(Evas_Object *item)
1094 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_DUE_DATE"));
1097 static Evas_Object *__cal_edit_ug_insert_padding_after(cal_edit_ug_data* p, const char* title, Evas_Object *after)
1099 c_retv_if(!p, NULL);
1100 c_retv_if(!after, NULL);
1102 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "title", after, NULL, NULL);
1103 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1105 if (CAL_STRLEN(title))
1106 elm_object_part_text_set(item, "elm.text", title);
1111 static void __cal_edit_ug_title_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1114 cal_edit_ug_data* p = (cal_edit_ug_data *)data;
1118 str = elm_entry_entry_get(p->title_entry);
1119 if (!str || str[0] == '\0')
1120 p->title_str = NULL;
1122 p->title_str = elm_entry_markup_to_utf8(str);
1124 if(p->item_type == ITEM_TYPE_TODO)
1125 __cal_edit_ug_set_record_title(p->todo, p->title_str);
1127 __cal_edit_ug_set_record_title(p->event, p->title_str);
1130 static Evas_Object * __cal_edit_ug_title_icon(cal_edit_ug_data* p, Evas_Object *obj)
1132 c_retv_if(!p, NULL);
1133 c_retv_if(!obj, NULL);
1135 Evas_Object *ef = cal_util_add_edit_field(obj, S_("IDS_COM_BODY_DETAILS_TITLE"), EINA_FALSE, EINA_TRUE);
1136 c_retvm_if(!ef, NULL, "ef is null");
1138 Evas_Object *entry = elm_object_part_content_get(ef, "elm.swallow.content");
1139 c_retvm_if(!entry, ef, "entry is null");
1141 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1143 p->title_entry = entry;
1145 if (p->item_type == ITEM_TYPE_TODO)
1146 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
1148 __cal_edit_ug_update_title_item(p->title_entry, p->event);
1150 evas_object_smart_callback_add(p->title_entry, "changed", __cal_edit_ug_title_entry_changed_callback, p);
1151 evas_object_smart_callback_add(p->title_entry, "preedit,changed", __cal_edit_ug_title_entry_changed_callback, p);
1153 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->title_entry);
1159 static void __cal_edit_ug_update_title_language(Evas_Object *item)
1163 Evas_Object *edit_field = elm_object_part_content_get(item, "elm.icon");
1164 c_ret_if(!edit_field);
1166 elm_object_part_text_set(edit_field, "elm.guidetext", S_("IDS_COM_BODY_DETAILS_TITLE"));
1169 static Evas_Object *__cal_edit_ug_add_title(cal_edit_ug_data* p)
1171 c_retv_if(!p, NULL);
1173 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1174 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1176 Evas_Object *editfield = __cal_edit_ug_title_icon(p, item);
1177 c_retvm_if(!editfield, NULL, "__cal_edit_ug_title_icon() is failed");
1179 elm_object_part_content_set(item, "elm.icon", editfield);
1184 static void __cal_edit_ug_location_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1188 cal_edit_ug_data *p = data;
1191 CAL_FREE(p->address);
1193 p->address = elm_entry_markup_to_utf8(elm_entry_entry_get(p->location_entry));
1195 if (!CAL_STRLEN(p->address)) {
1197 p->longitude = p->latitude = CALENDAR_RECORD_NO_COORDINATE;
1201 if (p->item_type == ITEM_TYPE_TODO)
1202 __cal_edit_ug_set_record_location(p->todo, p->address, p->latitude, p->longitude);
1204 __cal_edit_ug_set_record_location(p->event, p->address, p->latitude, p->longitude);
1207 static Evas_Object * __cal_edit_ug_location_icon(cal_edit_ug_data* p, Evas_Object *obj)
1209 c_retv_if(!p, NULL);
1210 c_retv_if(!obj, NULL);
1212 Evas_Object *ly = NULL;
1214 Evas_Object *ef = cal_util_add_edit_field(obj, C_("IDS_COM_BODY_DETAILS_LOCATION"), EINA_FALSE, EINA_TRUE);
1217 p->location_entry = elm_object_part_content_get(ef, "elm.swallow.content");
1218 c_retv_if(!p->location_entry, ly);
1220 evas_object_smart_callback_add(p->location_entry, "changed", __cal_edit_ug_location_entry_changed_callback, p);
1221 evas_object_smart_callback_add(p->location_entry, "preedit,changed", __cal_edit_ug_location_entry_changed_callback, p);
1222 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->location_entry);
1224 elm_entry_cnp_mode_set(p->location_entry, ELM_CNP_MODE_PLAINTEXT);
1226 if (p->item_type == ITEM_TYPE_TODO)
1227 __cal_edit_ug_update_location_item(p, p->todo);
1229 __cal_edit_ug_update_location_item(p, p->event);
1234 static void __cal_edit_ug_update_location_language(Evas_Object *item)
1238 Evas_Object *layout = elm_object_part_content_get(item, "elm.icon");
1241 Evas_Object *edit_field = elm_object_part_content_get(layout, "editfield/sw");
1242 c_ret_if(!edit_field);
1244 elm_object_part_text_set(edit_field, "elm.guidetext", C_("IDS_COM_BODY_DETAILS_LOCATION"));
1246 Evas_Object *button = elm_object_part_content_get(layout, "button/sw");
1249 elm_object_text_set(button, C_("IDS_LBS_BODY_MAP"));
1252 static Evas_Object *__cal_edit_ug_add_location(cal_edit_ug_data* p)
1254 c_retv_if(!p, NULL);
1256 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1257 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1259 Evas_Object *editfield = __cal_edit_ug_location_icon(p, item);
1260 c_retvm_if(!editfield, NULL, "__cal_edit_ug_note_icon() is failed");
1262 elm_object_part_content_set(item, "elm.icon", editfield);
1264 __cal_edit_ug_insert_padding_after(p, NULL, item);
1269 static void __cal_edit_ug_note_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1271 char *email_link = NULL;
1272 cal_edit_ug_data *p = data;
1273 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(p->note_entry));
1275 if (CAL_STRLEN(p->note_str))
1276 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1278 if ((NULL != email_link) && CAL_STRLEN(str) && (NULL != strstr(p->note_str, str))) {
1279 char *strnote = NULL;
1280 int strnote_len = 0;
1281 strnote_len = strlen(str) + strlen(email_link);
1282 CAL_CALLOC(strnote, strnote_len+1, char);
1283 if (NULL != strnote)
1285 snprintf(strnote, strnote_len + 1, "%s%s", str, email_link);
1286 p->note_str = strdup(strnote);
1296 p->note_str = CAL_STRDUP(str);
1301 if(p->item_type == ITEM_TYPE_TODO)
1302 __cal_edit_ug_set_record_note(p->todo, p->note_str);
1304 __cal_edit_ug_set_record_note(p->event, p->note_str);
1308 static Evas_Object * __cal_edit_ug_note_icon(cal_edit_ug_data* p, Evas_Object *obj)
1310 c_retv_if(!p, NULL);
1311 c_retv_if(!obj, NULL);
1313 Evas_Object *ef = cal_util_add_edit_field(obj, C_("IDS_CLD_BODY_CREATE_DESCRITION"), EINA_FALSE, EINA_TRUE );
1316 Evas_Object *entry = elm_object_part_content_get(ef, "elm.swallow.content");
1317 c_retvm_if(!entry, ef, "entry is null");
1319 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1320 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
1321 //elm_entry_autocapital_type_set(entry, EINA_TRUE);
1322 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1324 p->note_entry = entry;
1328 char *email_link = NULL;
1329 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1331 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(p->note_str));
1334 char *snote_display = NULL;
1335 int nsize = email_link - p->note_str + 1;
1336 snote_display = calloc(nsize, sizeof(char));
1337 c_retvm_if(!snote_display , NULL, "calloc(nsize, sizeof(char)) is failed");
1339 CAL_STRNCPY(snote_display, p->note_str, nsize-1);
1341 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(snote_display));
1342 free(snote_display);
1346 if (p->item_type == ITEM_TYPE_TODO)
1347 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
1349 __cal_edit_ug_update_note_item(p->note_entry, p->event);
1351 evas_object_smart_callback_add(p->note_entry, "changed", __cal_edit_ug_note_entry_changed_callback, p);
1352 evas_object_smart_callback_add(p->note_entry, "preedit,changed", __cal_edit_ug_note_entry_changed_callback, p);
1353 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->note_entry);
1361 static void __cal_edit_ug_update_description_language(Evas_Object *item)
1365 Evas_Object *edit_field = elm_object_part_content_get(item, "elm.icon");
1366 c_ret_if(!edit_field);
1368 elm_object_part_text_set(edit_field, "elm.guidetext", C_("IDS_CLD_BODY_CREATE_DESCRITION"));
1371 static Evas_Object *__cal_edit_ug_add_note(cal_edit_ug_data* p)
1373 c_retv_if(!p, NULL);
1375 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1376 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1378 Evas_Object *editfield = __cal_edit_ug_note_icon(p, item);
1379 c_retvm_if(!editfield, NULL, "__cal_edit_ug_location_icon() is failed");
1382 elm_object_part_content_set(item, "elm.icon", editfield);
1387 static Evas_Object * __cal_edit_ug_edit_time_icon(Evas_Object *obj, struct tm* value, Eina_Bool allday)
1389 c_retvm_if(!obj, NULL, "obj is null");
1391 Evas_Object* icon_obj = cal_util_add_datetime(obj, NULL, value);
1392 c_retvm_if(!icon_obj, NULL, "icon_obj is null");
1394 elm_object_part_content_set(obj, "datefield", icon_obj);
1397 elm_datetime_format_set(icon_obj, "%b %d , %Y %H : %M");
1399 elm_datetime_format_set(icon_obj, "%b %d , %Y %I : %M %p");
1403 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1404 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1406 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1408 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1412 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1413 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1414 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1417 elm_datetime_field_limit_set(icon_obj, ELM_DATETIME_YEAR, 70, 136);
1422 static Eina_Bool __cal_edit_ug_check_date_validity(void *data)
1424 c_retv_if(!data, EINA_FALSE);
1425 cal_edit_ug_data* p = data;
1427 time_t start_t = mktime(&p->stm);
1428 time_t end_t = mktime(&p->etm);
1436 static void __cal_edit_ug_start_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1438 c_retm_if(data == NULL, "data is null");
1439 cal_edit_ug_data *p = data;
1442 time_t t = time(NULL);
1443 localtime_r(&t, &value); // to fill hidden field
1445 elm_datetime_value_get(obj, &value);
1447 // Remember the time difference in before updating start time
1448 time_t start_t = mktime(&p->stm);
1449 time_t end_t = mktime(&p->etm);
1450 time_t diff = end_t - start_t;
1452 // Update start time variable
1455 Eina_Bool result =__cal_edit_ug_check_date_validity(p);
1457 // Calculate end time from start time to retain the time difference
1458 end_t = mktime(&p->stm) + diff;
1459 localtime_r(&end_t, &p->etm);
1461 // Update end time on the screen
1462 Evas_Object *end_date_obj = elm_object_part_content_get(p->end_date, "elm.icon");
1463 elm_datetime_value_set(end_date_obj, &p->etm);
1466 __cal_edit_ug_set_record_time(p, p->event);
1469 static void __cal_edit_ug_end_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1471 c_retm_if(!data, "data is null");
1472 cal_edit_ug_data *p = data;
1475 time_t t = time(NULL);
1476 localtime_r(&t, &value); // to fill hidden field
1478 elm_datetime_value_get(obj, &value);
1482 Eina_Bool result = __cal_edit_ug_check_date_validity(p);
1484 int r = status_message_post(C_("IDS_CLD_POP_END_TIME_SHOULD_BE_SET_AFTER_START_TIME"));
1485 c_warn_if(r != STATUS_ERROR_NONE, "status_message_post() is failed(%d)", r);
1487 __cal_edit_ug_set_record_time(p, p->event);
1491 static void __cal_edit_ug_due_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1493 c_retm_if(!data, "data is null");
1494 cal_edit_ug_data *p = data;
1497 time_t t = time(NULL);
1498 localtime_r(&t, &value); // to fill hidden field
1500 elm_datetime_value_get(obj, &value);
1504 __cal_edit_ug_set_record_due_time(p, p->todo);
1508 static void __cal_edit_ug_update_datetime_region(Evas_Object *item, struct tm *tm, Eina_Bool is_allday, Evas_Smart_Cb callback, void *callback_data)
1512 Evas_Object *datetime = NULL;
1514 datetime = elm_object_part_content_unset(item, "elm.icon");
1516 evas_object_del(datetime);
1518 datetime = __cal_edit_ug_edit_time_icon(item, tm, is_allday);
1519 c_ret_if(!datetime);
1521 elm_object_part_content_set(item, "elm.icon", datetime);
1523 evas_object_smart_callback_add(datetime, "changed", callback, callback_data);
1526 static Evas_Object *__cal_edit_ug_insert_timepicker_after(cal_edit_ug_data* p, struct tm* value, Eina_Bool allday, Evas_Object *after, Evas_Smart_Cb callback)
1528 c_retv_if(!p, NULL);
1529 c_retv_if(!after, NULL);
1531 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1icon", after, NULL, NULL);
1532 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1534 __cal_edit_ug_update_datetime_region(item, value, allday, callback, p);
1539 static void __cal_edit_ug_all_day_update(Evas_Object* date_obj, Eina_Bool allday)
1541 Evas_Object *edit_time_obj = elm_object_part_content_get(date_obj, "elm.icon");
1544 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1545 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1547 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1549 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1550 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1551 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1555 static void __cal_edit_ug_set_record_allday(calendar_record_h record, Eina_Bool is_allday, cal_edit_ug_data *p)
1560 if (is_allday == _calendar_is_allday_record(record))
1563 calendar_time_s start_time = {0};
1565 _calendar_get_start_time(record, &start_time);
1567 calendar_time_s end_time = {0};
1569 _calendar_get_end_time(record, &end_time);
1571 struct tm start_tm = {0};
1572 struct tm end_tm = {0};
1576 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &start_tm);
1577 cal_util_convert_lli_to_tm(NULL, end_time.time.utime, &end_tm);
1579 start_time.type = CALENDAR_TIME_LOCALTIME;
1580 end_time.type = CALENDAR_TIME_LOCALTIME;
1582 start_time.time.date.year = start_tm.tm_year + 1900;
1583 start_time.time.date.month = start_tm.tm_mon + 1;
1584 start_time.time.date.mday = start_tm.tm_mday;
1586 end_time.time.date.year = end_tm.tm_year + 1900;
1587 end_time.time.date.month = end_tm.tm_mon + 1;
1588 end_time.time.date.mday = end_tm.tm_mday;
1592 start_time.type = CALENDAR_TIME_UTIME;
1593 end_time.type = CALENDAR_TIME_UTIME;
1595 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
1596 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
1599 _calendar_set_start_time(record, &start_time);
1601 _calendar_set_end_time(record, &end_time);
1604 static void __cal_edit_ug_all_day_clicked_callback(Evas_Object *obj, void *data)
1608 c_retm_if(!data, "data is null");
1609 cal_edit_ug_data *p = data;
1611 Evas_Object *all_obj = elm_object_part_content_get(p->allday, "elm.icon");
1614 Eina_Bool is_allday = !elm_check_state_get(all_obj);
1616 elm_check_state_set(all_obj, is_allday);
1618 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1619 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1621 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1625 static void __cal_edit_ug_all_day_changed_callback(void *data, Evas_Object* obj, void *ei)
1629 c_retm_if(!data, "data is null");
1630 c_retm_if(!obj, "obj is null");
1632 cal_edit_ug_data *p = data;
1634 Eina_Bool is_allday = elm_check_state_get(obj);
1636 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1637 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1639 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1642 static void __cal_edit_ug_update_allday_language(Evas_Object *item)
1646 elm_object_part_text_set(item, "elm.text", C_("IDS_COM_BODY_ALL_DAY"));
1649 static Evas_Object *__cal_edit_ug_add_all_day(cal_edit_ug_data* p, Eina_Bool allday)
1651 c_retv_if(!p, NULL);
1653 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1text.1icon", p->timezone, __cal_edit_ug_all_day_clicked_callback, p);
1654 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1656 Evas_Object *check_obj;
1657 check_obj = elm_check_add(item);
1658 elm_check_state_set(check_obj, allday);
1659 elm_object_style_set(check_obj, "on&off");
1660 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_all_day_changed_callback, p);
1661 elm_check_state_set(check_obj, allday);
1662 evas_object_propagate_events_set(check_obj, EINA_FALSE);
1664 elm_object_part_content_set(item, "elm.icon", check_obj);
1666 __cal_edit_ug_update_allday_language(item);
1671 static void __cal_edit_ug_worldclock_ug_destroy_callback(ui_gadget_h ug, void *priv)
1675 cal_edit_ug_data* p = (cal_edit_ug_data*) priv;
1677 if (p->ug_worldclock) {
1678 ug_destroy(p->ug_worldclock);
1679 p->ug_worldclock= NULL;
1682 Elm_Object_Item* navi_item = elm_naviframe_top_item_get(p->naviframe);
1683 Evas_Object *back_btn = elm_object_item_part_content_get(navi_item, "prev_btn");
1684 if (back_btn != NULL) {
1685 elm_object_style_set(back_btn, "naviframe/back_btn/default"); /* take into effect */
1689 static void __cal_edit_ug_worldclock_ug_result_callback(ui_gadget_h ug, service_h result, void *priv)
1693 c_retm_if(!priv, "priv is null");
1694 c_retm_if(!result, "result is null");
1696 cal_edit_ug_data *p = priv;
1698 if (p->timezone_city) {
1699 free(p->timezone_city);
1700 p->timezone_city = NULL;
1703 if (p->timezone_path) {
1704 free(p->timezone_path);
1705 p->timezone_path = NULL;
1708 if (p->timezone_offset) {
1709 free(p->timezone_offset);
1710 p->timezone_offset = NULL;
1713 int r = service_get_extra_data(result, "tzpath", &p->timezone_path);
1714 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data(tzpath) is failed(%x)", r);
1716 r = service_get_extra_data(result, "city", &p->timezone_city);
1717 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data(city) is failed(%x)", r);
1719 __cal_edit_ug_set_timezone(p->record, p->timezone_path, p->timezone_city);
1721 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
1723 p->is_selected_timezone = EINA_TRUE;
1725 char* timezone_text = NULL;
1726 timezone_text = g_strdup_printf("%s, %s", S_(p->timezone_city), p->timezone_offset);
1728 elm_object_part_text_set(p->timezone, "elm.text.1", timezone_text);
1730 CAL_FREE(timezone_text);
1733 static void __cal_edit_ug_worldclock_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
1737 c_retm_if(!ug, "ug is null");
1739 Evas_Object *base = ug_get_layout(ug);
1747 case UG_MODE_FULLVIEW:
1748 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1750 evas_object_show(base);
1753 DBG("Unsupported ug layout");
1759 static void __cal_edit_ug_timezone_select_callback(Evas_Object *obj, void *data)
1761 c_retm_if(!data, "data is null");
1763 cal_edit_ug_data *p = data;
1766 memset(&uc, 0, sizeof(struct ug_cbs));
1767 uc.destroy_cb = __cal_edit_ug_worldclock_ug_destroy_callback;
1768 uc.layout_cb = __cal_edit_ug_worldclock_ug_layout_callback;
1769 uc.result_cb = __cal_edit_ug_worldclock_ug_result_callback;
1772 ug = ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, NULL, &uc);
1773 p->ug_worldclock = ug;
1776 static void __cal_edit_ug_update_time_zone_language(Evas_Object *item, const char *timezone_city, const char *timezone_offset)
1778 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_TIME_ZONE"));
1780 char buffer[128] = {0};
1782 snprintf(buffer, sizeof(buffer), "%s, %s", S_(timezone_city), timezone_offset);
1784 elm_object_part_text_set(item, "elm.text.1", buffer);
1787 static Evas_Object *__cal_edit_ug_add_time_zone(cal_edit_ug_data* p)
1789 c_retv_if(!p, NULL);
1791 Evas_Object *item = __cal_edit_ug_insert_padding_after(p, NULL, p->end_date);
1792 c_retvm_if(!item, NULL, "__cal_edit_ug_insert_padding_after() is failed");
1794 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", item, __cal_edit_ug_timezone_select_callback, p);
1795 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1797 __cal_edit_ug_get_record_time_zone(p, p->event);
1799 __cal_edit_ug_update_time_zone_language(item, p->timezone_city, p->timezone_offset);
1804 static void __cal_edit_ug_alarm_changed_callback(const Cal_Reminder* reminder, void* data)
1808 c_retm_if(!data, "data is null");
1810 Evas_Object *obj = data;
1812 char* alarm_text = NULL;
1813 char buf[128] = {0};
1814 cal_reminder_get_string(reminder, buf, sizeof(buf));
1815 alarm_text = strdup(buf);
1817 elm_object_part_text_set(obj, "elm.text.1", alarm_text);
1818 CAL_FREE(alarm_text);
1820 Cal_Reminder* reminder_temp = evas_object_data_get(obj, "data");
1821 reminder_temp->alarm_value = reminder->alarm_value;
1822 reminder_temp->datetime = reminder->datetime;
1823 reminder_temp->tick_unit = reminder->tick_unit;
1826 static void __cal_edit_ug_alarm_select_callback(Evas_Object *obj, void *data)
1830 c_retm_if(!data, "data is null");
1832 cal_edit_ug_data* p = data;
1833 Cal_Reminder* reminder = (Cal_Reminder*)evas_object_data_get(obj, "data");
1834 cal_edit_alarm_type alarm_type = ALARM_TYPE_EVENT;
1836 if(p->item_type == ITEM_TYPE_EVENT)
1837 alarm_type = ALARM_TYPE_EVENT;
1838 else if(p->item_type == ITEM_TYPE_TODO && p->is_no_due_date)
1839 alarm_type = ALARM_TYPE_TODO_CUSTOM_ONLY;
1841 alarm_type = ALARM_TYPE_TODO;
1843 cal_edit_alarm_create_view(p->naviframe, reminder, alarm_type, __cal_edit_ug_alarm_changed_callback, obj);
1847 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after);
1849 static void __cal_edit_ug_delete_reminder_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
1859 static void __cal_edit_ug_alarm_plus_button_callback(void *data, Evas_Object *obj, void *event_info)
1863 c_retm_if(!data, "data is null");
1864 c_retm_if(!obj, "obj is null");
1866 cal_edit_ug_data* p = data;
1868 if (eina_list_count(p->alarm_item_list)>=4) {
1869 evas_object_del(p->alarm_plus_button);
1870 p->alarm_plus_button = NULL;
1873 Cal_Reminder* reminder = calloc(1, sizeof(Cal_Reminder));
1874 c_retm_if(!reminder, "reminder is null");
1875 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1876 reminder->datetime = p->stm;
1878 Eina_List *list = eina_list_last(p->alarm_item_list);
1879 Evas_Object *last_item = eina_list_data_get(list);
1880 __cal_edit_ug_add_alarm(p, reminder, EINA_FALSE, last_item);
1884 static Evas_Object * __cal_edit_ug_alarm_plus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1886 c_retv_if(!p, NULL);
1887 c_retv_if(!obj, NULL);
1889 Evas_Object *button = NULL;
1891 button = elm_button_add(obj);
1892 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1894 elm_object_style_set(button, "icon_plus");
1895 evas_object_propagate_events_set(button, EINA_FALSE);
1896 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_plus_button_callback, p);
1897 evas_object_show(button);
1898 p->alarm_plus_button = button;
1903 static void __cal_edit_ug_alarm_minus_button_callback(void *data, Evas_Object *obj, void *event_info)
1907 c_retm_if(!data, "data is null");
1908 c_retm_if(!obj, "obj is null");
1910 cal_edit_ug_data* p = data;
1912 if (!p->alarm_plus_button) {
1913 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
1914 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
1915 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
1918 evas_object_smart_callback_del(obj, "clicked", __cal_edit_ug_alarm_minus_button_callback);
1920 Evas_Object *parent_item = evas_object_data_get(obj, "button");
1921 p->alarm_item_list = eina_list_remove(p->alarm_item_list, parent_item);
1923 cal_dialogue_delete_item(p->dialogue, parent_item);
1924 evas_object_del(obj);
1930 static Evas_Object * __cal_edit_ug_alarm_minus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1932 c_retv_if(!p, NULL);
1933 c_retv_if(!obj, NULL);
1935 Evas_Object *button = NULL;
1937 button = elm_button_add(obj);
1938 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1940 elm_object_style_set(button, "icon_minus");
1941 evas_object_data_set(button, "button", obj);
1942 evas_object_propagate_events_set(button, EINA_FALSE);
1943 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_minus_button_callback, p);
1944 evas_object_show(button);
1949 static void __cal_edit_ug_update_reminder_language(Eina_List *item_list)
1951 c_ret_if(!item_list);
1953 Eina_List *cursor = NULL;
1954 Evas_Object *item = NULL;
1956 EINA_LIST_FOREACH(item_list, cursor, item) {
1960 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1962 Cal_Reminder *reminder = NULL;
1964 reminder = evas_object_data_get(item, "data");
1966 char buffer[128] = {0};
1967 cal_reminder_get_string(reminder, buffer, sizeof(buffer));
1969 elm_object_part_text_set(item, "elm.text.1", buffer);
1973 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after)
1975 c_retv_if(!p, NULL);
1976 Evas_Object *item = NULL;
1978 item = cal_dialogue_insert_item_after(p->dialogue, "2text.1icon.5", after, __cal_edit_ug_alarm_select_callback, p);
1979 c_retvm_if(!item, NULL, "cal_dialogue_insert_item_after() is failed");
1982 item = cal_dialogue_append_item(p->dialogue, "2text.1icon.5", __cal_edit_ug_alarm_select_callback, p);
1983 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1986 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1988 const char* alarm_text = NULL;
1989 char buf[128] = {0};
1990 cal_reminder_get_string(reminder, buf, sizeof(buf));
1991 alarm_text = strdup(buf);
1993 elm_object_part_text_set(item, "elm.text.1", alarm_text);
1994 p->alarm_item_list = eina_list_append(p->alarm_item_list, (void*)item);
1996 if(p->item_type == ITEM_TYPE_EVENT) {
1997 Evas_Object *button_obj = NULL;
1999 button_obj = __cal_edit_ug_alarm_plus_button_icon(p, item);
2001 button_obj = __cal_edit_ug_alarm_minus_button_icon(p, item);
2003 elm_object_part_content_set(item, "elm.icon", button_obj);
2006 evas_object_data_set(item, "data", reminder);
2007 evas_object_event_callback_add(item, EVAS_CALLBACK_DEL, __cal_edit_ug_delete_reminder_callback, reminder);
2012 static void __cal_edit_ug_add_multi_alarm(cal_edit_ug_data* p)
2014 c_retm_if(!p, "p is null");
2016 Cal_Reminder* reminder = NULL;
2017 reminder = calloc(1, sizeof(Cal_Reminder));
2018 c_retm_if(!reminder, "reminder is null");
2020 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
2021 reminder->datetime = p->stm;
2022 Evas_Object *after = NULL;
2023 Evas_Object *item = NULL;
2025 if(p->is_edit_mode) {
2026 if (p->item_type == ITEM_TYPE_EVENT)
2027 __cal_edit_ug_get_record_alarm(p, p->event);
2029 __cal_edit_ug_get_record_alarm(p, p->todo);
2031 if(!p->alarm_list) {
2032 reminder->tick_unit = CALENDAR_ALARM_NONE;\
2036 GList *temp = p->alarm_list;
2038 __cal_edit_ug_add_alarm(p, reminder, EINA_TRUE, NULL);
2045 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_TRUE, after);
2048 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_FALSE, after);
2050 c_retm_if(!item, "item is null");
2052 temp = g_list_next(temp);
2057 static void __cal_edit_ug_reponse_event_callback(void *data, Evas_Object *obj, void *ei)
2059 c_retm_if(!data, "data is null");
2061 Evas_Object *popup = data;
2062 evas_object_del(popup);
2065 static void __cal_edit_ug_repeat_callback(void *data)
2067 c_retm_if(!data, "data is null");
2069 cal_edit_ug_data *p = data;
2071 calendar_range_type_e range = CALENDAR_RANGE_NONE;
2072 struct tm until = {0};
2075 int repeat = cal_edit_repeat_get_repeat(p->repeat_layout, &range, &until, &count);
2077 if (CALENDAR_RECURRENCE_NONE != repeat) {
2079 if (range == CALENDAR_RANGE_UNTIL) {
2081 if (timegm(&until) <= timegm(&p->stm)) {
2082 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2083 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2087 else if (range == CALENDAR_RANGE_COUNT) {
2090 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2091 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2097 p->repeat_freq = repeat;
2098 p->repeat_range = range;
2099 p->repeat_until = until;
2100 p->repeat_count = count;
2102 char buf[1024] = {0};
2103 _cal_edit_repeat_get_freq_str(p->repeat_freq, buf, sizeof(buf));
2104 elm_object_part_text_set(p->repeat, "elm.text.1", buf);
2106 __cal_edit_ug_set_record_repeat(p);
2110 static void __cal_edit_ug_repeat_select_callback(Evas_Object *obj, void *data)
2112 c_retm_if(!data, "data is null");
2114 cal_edit_ug_data* p = data;
2116 p->repeat_layout = cal_edit_repeat_create_view(p->naviframe, p->repeat_freq, p->repeat_range, &(p->stm), &(p->repeat_until),&(p->repeat_count),
2117 (cal_edit_repeat_destroy_callback)__cal_edit_ug_repeat_callback, p);
2118 c_retm_if(!p->repeat_layout, "p->repeat_layout is null");
2122 static void __cal_edit_ug_update_recurrence_language(Evas_Object *item, int repeat_frequency)
2126 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REPEAT"));
2128 char buffer[128] = {0};
2130 _cal_edit_repeat_get_freq_str(repeat_frequency, buffer, sizeof(buffer));
2132 elm_object_part_text_set(item, "elm.text.1", buffer);
2135 static Evas_Object *__cal_edit_ug_add_repeat(cal_edit_ug_data* p)
2137 c_retv_if(!p, NULL);
2139 Eina_List *list = eina_list_last(p->alarm_item_list);
2140 Evas_Object *last_item = eina_list_data_get(list);
2142 Evas_Object *item = NULL;
2146 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, NULL, NULL);
2147 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2150 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, __cal_edit_ug_repeat_select_callback, p);
2152 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2154 __cal_edit_ug_get_record_repeat(p, p->event);
2156 __cal_edit_ug_update_recurrence_language(item, p->repeat_freq);
2161 static void __cal_edit_ug_popup_hide_callback(void *data, Evas_Object *obj, void *event_info)
2163 c_retm_if(!data, "data is null");
2164 c_retm_if(!obj, "obj is null");
2166 Evas_Object *popup = data;
2168 cal_edit_ug_data *p = evas_object_data_get(popup, "data");
2170 evas_object_del(popup);
2172 c_retm_if(!p, "p is null");
2177 static char *__cal_edit_ug_get_genlist_save_to_item_label(void *data, Evas_Object *obj, const char *part)
2179 c_retvm_if(!data, NULL, "data is null");
2180 c_retvm_if(!part, NULL, "part is null");
2182 calendar_record_h record = (calendar_record_h)data;
2187 calendar_error_e error = CALENDAR_ERROR_NONE;
2189 calendar_record_h calendar_book = NULL;
2191 _calendar_record_type record_type = _calendar_get_record_type(record);
2193 if (record_type == _CALENDAR_RECORD_TYPE_CALENDARBOOK)
2194 calendar_book = record;
2196 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &cid);
2197 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2199 error = calendar_db_get_record(_calendar_book._uri, cid, &calendar_book);
2200 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_db_get_record() is failed(%x)", error);
2203 error = calendar_record_get_int(record, _calendar_book.id, &cid);
2204 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2206 if (!CAL_STRCMP(part,"elm.text.1")) {
2208 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2209 return strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2210 else if (cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2211 return strdup(C_("IDS_TASK_BODY_MY_TASK"));
2213 error = calendar_record_get_str(calendar_book, _calendar_book.name, &name);
2214 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2216 if (record != calendar_book) {
2217 error = calendar_record_destroy(calendar_book, true);
2218 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2221 if (CAL_STRLEN(name))
2226 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2228 } else if (!CAL_STRCMP(part,"elm.text.2")) {
2230 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2231 return strdup(C_("IDS_CLD_POP_MY_PHONE"));
2233 error = calendar_record_get_str(calendar_book, _calendar_book.description, &description);
2234 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2236 if (record != calendar_book) {
2237 error = calendar_record_destroy(calendar_book, true);
2238 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2241 if (CAL_STRLEN(description))
2244 CAL_FREE(description);
2246 return strdup(S_("IDS_COM_POP_NO_ACCOUNTS"));
2249 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2252 static Evas_Object* __cal_edit_ug_add_save_to_icon(void *item_data, Evas_Object *obj, const char *part)
2256 ERR("item_data is null");
2260 Evas_Object *icon = NULL;
2261 char* icon_path = NULL;
2262 calendar_record_h record = (calendar_record_h)item_data;
2263 Eina_Bool r = EINA_FALSE;
2264 int cid = _calendar_get_calendar_index(record);
2265 int aid = _calendar_get_account_id(record);
2267 if (!CAL_STRCMP(part, "elm.icon"))
2269 icon = elm_icon_add(obj);
2273 ERR("elm_icon_add fail");
2277 if ( cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID) {
2278 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
2279 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2281 icon_path = cal_account_svc_get_account_icon_path(aid);
2283 r = elm_icon_file_set(icon, icon_path, NULL);
2284 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2288 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
2289 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2296 evas_object_del(icon);
2300 evas_object_show(icon);
2306 static Eina_Bool __cal_edit_ug_popup_idler_callback(void *data)
2308 c_retv_if(!data, ECORE_CALLBACK_CANCEL);
2310 cal_edit_ug_data *p = data;
2313 evas_object_del(p->popup);
2319 return ECORE_CALLBACK_CANCEL;
2322 static void __cal_edit_ug_save_to_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2326 c_retm_if(!data, "data is null");
2327 c_retm_if(!obj, "obj is null");
2329 calendar_record_h calendar_book = data;
2330 int calendar_book_id = 0;
2332 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2333 c_retm_if(!p, "p is null");
2335 Elm_Object_Item *item = elm_genlist_selected_item_get(obj);
2336 c_retm_if(!item, "elm_genlist_selected_item_get() returned null");
2338 elm_genlist_item_selected_set(item, EINA_FALSE);
2340 calendar_error_e error = CALENDAR_ERROR_NONE;
2342 error = calendar_record_get_int(calendar_book, _calendar_book.id, &calendar_book_id);
2343 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2345 if (p->item_type == ITEM_TYPE_TODO) {
2346 __cal_edit_ug_set_record_save_to(p->todo, calendar_book_id);
2347 __cal_edit_ug_update_save_to_item(p, p->todo);
2350 __cal_edit_ug_set_record_save_to(p->event, calendar_book_id);
2351 __cal_edit_ug_update_save_to_item(p, p->event);
2355 ecore_idler_del(p->idler);
2359 p->idler = ecore_idler_add(__cal_edit_ug_popup_idler_callback, p);
2360 c_ret_if(!p->idler);
2364 static Elm_Genlist_Item_Class itc_2text_1icon_2 = {
2365 .item_style = "dialogue/2text.1icon.2",
2366 .func.text_get = __cal_edit_ug_get_genlist_save_to_item_label,
2367 .func.content_get = __cal_edit_ug_add_save_to_icon,
2370 static Evas_Object* __cal_edit_ug_create_save_to_popup(cal_edit_ug_data* p)
2372 c_retv_if(!p, NULL);
2374 Evas_Object *popup = NULL;
2375 Evas_Object *genlist = NULL;
2379 calendar_error_e error = CALENDAR_ERROR_NONE;
2381 if (!p->calendar_book_list)
2383 p->calendar_book_list = _calendar_get_calendar_book_list_with_account_id(_CALENDAR_ALL_ACCOUNT_ID);
2386 popup = cal_util_add_popup(p->window, "liststyle", C_("IDS_ST_BODY_SAVE_TO"), NULL,
2387 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2388 c_retvm_if(!popup, NULL, "popup is null");
2390 genlist = elm_genlist_add(popup);
2392 ERR("elm_genlist_add(popup) returned null");
2393 evas_object_del(popup);
2397 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2398 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2399 evas_object_data_set(genlist, "priv", p);
2401 calendar_record_h calendar_book = NULL;
2403 EINA_LIST_FOREACH(p->calendar_book_list, l, calendar_book) {
2407 error = calendar_record_get_int(calendar_book, _calendar_book.store_type, &store_type);
2408 if (error != CALENDAR_ERROR_NONE) {
2409 ERR("calendar_record_get_int() is failed(%x)", calendar_book);
2414 error = calendar_record_get_int(calendar_book, _calendar_book.sync_event, &sync_event);
2415 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2419 if (p->item_type == ITEM_TYPE_TODO) {
2420 if (store_type == CALENDAR_BOOK_TYPE_TODO)
2421 elm_genlist_item_append(genlist, &itc_2text_1icon_2, calendar_book, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_ug_save_to_popup_list_sel, calendar_book);
2423 if (store_type == CALENDAR_BOOK_TYPE_EVENT)
2424 elm_genlist_item_append(genlist, &itc_2text_1icon_2, calendar_book, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_ug_save_to_popup_list_sel, calendar_book);
2429 elm_object_content_set(popup, genlist);
2430 evas_object_show(genlist);
2435 static void __cal_edit_ug_saveto_select_callback(Evas_Object *obj, void *data)
2437 c_retm_if(!data, "data is null");
2439 cal_edit_ug_data* p = data;
2440 Evas_Object *popup = __cal_edit_ug_create_save_to_popup(p);
2441 c_retm_if(!popup, "popup is NULL");
2446 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz)
2448 calendar_record_h calendar_book = NULL;
2451 calendar_error_e error = CALENDAR_ERROR_NONE;
2453 error = calendar_db_get_record(_calendar_book._uri, calid, &calendar_book);
2454 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
2456 if (calid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2457 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
2460 error = calendar_record_get_str(calendar_book, _calendar_book.name, &str);
2461 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
2465 snprintf(buf, sz, "%s", str);
2470 error = calendar_record_destroy(calendar_book, true);
2471 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2474 static void __cal_edit_ug_update_saveto_language(Evas_Object *item, calendar_record_h record)
2478 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2480 int calendar_book_id = _calendar_get_calendar_index(record);
2482 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2483 elm_object_part_text_set(item, "elm.text.1", C_("IDS_CLD_BODY_MY_CALENDAR"));
2484 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2485 elm_object_part_text_set(item, "elm.text.1", C_("IDS_TASK_BODY_MY_TASK"));
2488 static Evas_Object *__cal_edit_ug_add_saveto(cal_edit_ug_data* p)
2490 c_retv_if(!p, NULL);
2492 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "2text.2", __cal_edit_ug_saveto_select_callback, p);
2493 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2495 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2498 char* saveto_text = NULL;
2499 int calendar_book_id = 0;
2500 if(p->item_type == ITEM_TYPE_TODO) {
2501 calendar_book_id = _calendar_get_calendar_index(p->todo);
2502 p->account_id = _calendar_get_account_id(p->todo);
2505 calendar_book_id = _calendar_get_calendar_index(p->event);
2506 p->account_id = _calendar_get_account_id(p->event);
2508 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2509 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2510 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2511 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
2513 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
2514 saveto_text = strdup(buf);
2517 elm_object_part_text_set(item, "elm.text.1", saveto_text);
2518 CAL_FREE(saveto_text);
2521 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2526 static void __cal_edit_ug_no_due_date_clicked_callback(Evas_Object *obj, void *data)
2528 c_retm_if(!data, "data is NULL.");
2529 c_retm_if(!obj, "obj is NULL.");
2531 cal_edit_ug_data *p = data;
2533 Evas_Object *check_obj = elm_object_part_content_get(p->no_due_date, "elm.icon");
2535 if(p->is_no_due_date)
2537 elm_check_state_set(check_obj, EINA_FALSE);
2538 p->is_no_due_date = elm_check_state_get(check_obj);
2539 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2543 elm_check_state_set(check_obj, EINA_TRUE);
2544 p->is_no_due_date = elm_check_state_get(check_obj);
2545 __cal_edit_ug_set_record_due_time(p, p->todo);
2546 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2549 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2550 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2553 static void __cal_edit_ug_no_due_date_changed_callback(void *data, Evas_Object *obj, void *ei)
2555 c_retm_if(!data, "data is NULL.");
2556 c_retm_if(!obj, "obj is NULL.");
2558 cal_edit_ug_data *p = data;
2560 p->is_no_due_date = elm_check_state_get(obj);
2562 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2563 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2564 if(p->is_no_due_date)
2566 __cal_edit_ug_set_record_due_time(p, p->todo);
2567 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2571 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2575 static void __cal_edit_ug_update_no_due_date_language(Evas_Object *item)
2577 elm_object_part_text_set(item, "elm.text", C_("IDS_TASK_MBODY_NO_DUE_DATE"));
2580 static Evas_Object *__cal_edit_ug_add_no_due_date(cal_edit_ug_data* p)
2582 c_retv_if(!p, NULL);
2584 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1text.1icon.2", p->due_date, __cal_edit_ug_no_due_date_clicked_callback, p);
2585 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2587 Evas_Object *check_obj;
2588 check_obj = elm_check_add(item);
2589 __cal_edit_ug_get_record_due_time(p, p->todo);
2590 elm_check_state_set(check_obj, p->is_no_due_date);
2592 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_no_due_date_changed_callback, p);
2593 elm_check_state_set(check_obj, p->is_no_due_date);
2594 evas_object_propagate_events_set(check_obj, EINA_FALSE);
2596 __cal_edit_ug_update_no_due_date_language(item);
2598 elm_object_part_content_set(item, "elm.icon", check_obj);
2603 static void __cal_edit_ug_priority_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2608 int priority = (int)data;
2610 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2613 __cal_edit_ug_set_record_priority(p->todo, priority);
2614 __cal_edit_ug_update_priority_item(p, p->todo);
2616 evas_object_del(p->popup);
2620 static Evas_Object* __cal_edit_ug_create_priority_popup(cal_edit_ug_data* p)
2622 c_retv_if(!p, NULL);
2624 Evas_Object *popup = cal_util_add_popup(p->window, NULL, C_("IDS_CLD_BODY_PRIORITY"), NULL,
2625 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2626 c_retv_if(!popup, NULL);
2628 evas_object_data_set(popup, "priv", p);
2630 Elm_Object_Item *popup_item = elm_popup_item_append(popup, S_("IDS_COM_OPT_HIGH_M_QUALITY"), NULL, __cal_edit_ug_priority_popup_list_sel, (const void *)CALENDAR_TODO_PRIORITY_HIGH);
2631 c_retv_if(!popup_item, NULL);
2633 popup_item = elm_popup_item_append(popup, S_("IDS_IDLE_BODY_NORMAL"), NULL, __cal_edit_ug_priority_popup_list_sel, (const void *)CALENDAR_TODO_PRIORITY_NORMAL);
2634 c_retv_if(!popup_item, NULL);
2636 popup_item = elm_popup_item_append(popup, S_("IDS_COM_BODY_LOW"), NULL, __cal_edit_ug_priority_popup_list_sel, (const void *)CALENDAR_TODO_PRIORITY_LOW);
2637 c_retv_if(!popup_item, NULL);
2642 static void __cal_edit_ug_priority_select_callback(Evas_Object *obj, void *data)
2644 c_retm_if(!data, "data is null");
2645 cal_edit_ug_data* p = data;
2647 Evas_Object *popup = __cal_edit_ug_create_priority_popup(p);
2648 c_retm_if(!popup, "popup is NULL");
2654 static void __cal_edit_ug_update_priority_language(Evas_Object *item, calendar_record_h record)
2656 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_PRIORITY"));
2658 char* priority_text = NULL;
2659 int priority = __cal_edit_ug_get_record_priority(record);
2661 case CALENDAR_TODO_PRIORITY_LOW:
2662 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
2664 case CALENDAR_TODO_PRIORITY_NORMAL:
2665 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
2667 case CALENDAR_TODO_PRIORITY_HIGH:
2668 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
2674 elm_object_part_text_set(item, "elm.text.1", priority_text);
2675 CAL_FREE(priority_text);
2678 static Evas_Object *__cal_edit_ug_add_priority(cal_edit_ug_data* p)
2680 c_retv_if(!p, NULL);
2682 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", p->no_due_date, __cal_edit_ug_priority_select_callback, p);
2683 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2685 __cal_edit_ug_update_priority_language(item, p->todo);
2690 static void __cal_edit_ug_show_result_popup(cal_edit_ug_data *p, calendar_error_e error)
2696 case CALENDAR_ERROR_DB_FAILED:
2697 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2698 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2701 case CALENDAR_ERROR_OUT_OF_MEMORY:
2702 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2703 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2706 case CALENDAR_ERROR_INVALID_PARAMETER:
2707 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_INVALID_TIME"),
2708 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2712 snprintf(buf,100,"not saved(internal error-%x)!",error);
2713 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), buf,
2714 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2719 int __cal_edit_ug_save(cal_edit_ug_data *p, calendar_record_h record)
2723 calendar_error_e error = CALENDAR_ERROR_NONE;
2725 int record_index = 0;
2727 calendar_record_type_e record_type = CALENDAR_RECORD_TYPE_EVENT;
2729 if (_calendar_is_task_record(record))
2730 record_type = CALENDAR_RECORD_TYPE_TODO;
2732 __cal_edit_ug_set_record_alarm(p, record);
2734 if (p->is_edit_mode) {
2737 calendar_record_h exception_record = NULL;
2738 error = calendar_record_clone(record, &exception_record);
2739 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
2741 int index = _calendar_get_record_index(record);
2742 error = calendar_record_set_int(exception_record, _calendar_event.original_event_id, index);
2743 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
2745 __cal_edit_ug_set_record_time(p, exception_record);
2746 _calendar_edit_recurrence_instance(exception_record, index);
2748 error = calendar_db_insert_record(exception_record, &record_index);
2749 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_insert_record() is failed(%x)", error);
2751 if (error != CALENDAR_ERROR_NONE) {
2752 __cal_edit_ug_show_result_popup(p, error);
2754 error = calendar_record_destroy(exception_record, true);
2755 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2760 error = calendar_record_destroy(exception_record, true);
2761 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2765 if (p->account_id == _calendar_get_account_id(record))
2767 error = calendar_db_update_record(record);
2768 if (error != CALENDAR_ERROR_NONE) {
2770 ERR("calendar_db_update_record() is failed(%x)", error);
2772 __cal_edit_ug_show_result_popup(p, error);
2776 record_index = _calendar_get_record_index(record);
2780 _calendar_delete_record(record);
2782 error = calendar_db_insert_record(record, &record_index);
2783 if (error != CALENDAR_ERROR_NONE) {
2785 ERR("calendar_db_insert_record() is failed(%x)", error);
2786 __cal_edit_ug_show_result_popup(p, error);
2795 error = calendar_db_insert_record(record, &record_index);
2796 if (error != CALENDAR_ERROR_NONE) {
2798 ERR("calendar_db_insert_record() is failed(%x)", error);
2800 __cal_edit_ug_show_result_popup(p, error);
2806 return record_index;
2809 static void __cal_edit_ug_send_result_to_detail_ug(cal_edit_ug_data *p, int record_index)
2811 c_retm_if(!p, "p is null");
2812 c_retm_if(record_index < 0, "record_index < 0");
2814 service_h service = NULL;
2816 int ret = service_create(&service);
2817 c_ret_if(ret != SERVICE_ERROR_NONE);
2819 char value[64] = {0};
2820 snprintf(value, sizeof(value), "%d", record_index);
2822 ret = service_add_extra_data(service, "record_index", value);
2823 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2825 memset(value, 0x00, sizeof(value));
2827 long long int lli_time = 0;
2828 cal_util_convert_tm_to_lli(NULL, &p->stm, &lli_time);
2830 snprintf(value, sizeof(value), "%lli", lli_time);
2832 ret = service_add_extra_data(service, "base_time", value);
2833 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2835 ug_send_result(p->ug, service);
2837 ret = service_destroy(service);
2838 c_warn_if(ret != SERVICE_ERROR_NONE, "service_destroy() is failed(%x)", ret);
2841 static void __cal_edit_ug_save_button_callback(void *data, Evas_Object *obj, void *event_info)
2845 c_retm_if(!data, "data is null");
2846 cal_edit_ug_data* p = data;
2849 Eina_Bool result = __cal_edit_ug_check_date_validity(p);
2851 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_END_TIME_SHOULD_BE_SET_AFTER_START_TIME"),
2852 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2856 if (p->item_type == ITEM_TYPE_TODO)
2857 record_index = __cal_edit_ug_save(p, p->todo);
2859 record_index = __cal_edit_ug_save(p, p->event);
2861 c_retm_if(record_index < 0, "cal_edit_save() is failed");
2863 int r = status_message_post(S_("IDS_COM_POP_SAVED"));
2864 c_warn_if(r != STATUS_ERROR_NONE, "status_message_post() is failed(%d)", r);
2866 __cal_edit_ug_send_result_to_detail_ug(p, record_index);
2868 ug_destroy_me(p->ug);
2873 static void __cal_edit_ug_back_button_callback(void *user_data, Evas_Object *obj, void *ei)
2877 c_ret_if(!user_data);
2879 cal_edit_ug_data *data = user_data;
2881 c_ret_if(!data->ug);
2883 ug_destroy_me(data->ug);
2886 static void __cal_edit_ug_show_multi_alarms (cal_edit_ug_data *p)
2888 c_retm_if(!p, "p is null");
2890 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2892 if(eina_list_count(p->alarm_item_list)<5){
2893 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
2894 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
2896 Eina_List *list = eina_list_next(p->alarm_item_list);
2898 Evas_Object *item = NULL;
2900 EINA_LIST_FOREACH(list, l, item) {
2902 cal_dialogue_show_item_after(p->dialogue, item, first_item);
2908 static void __cal_edit_ug_show_event_items (cal_edit_ug_data *p)
2910 c_retm_if(!p, "p is null");
2912 if (!p->start_date_title)
2913 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
2915 cal_dialogue_show_item_after(p->dialogue, p->start_date_title, p->title);
2917 Eina_Bool is_allday = EINA_FALSE;
2919 if (!p->start_date) {
2921 is_allday = _calendar_is_allday_record(p->event);
2923 p->start_date = __cal_edit_ug_insert_timepicker_after(p, &p->stm, is_allday, p->start_date_title, __cal_edit_ug_start_date_changed_callback);
2926 cal_dialogue_show_item_after(p->dialogue, p->start_date, p->start_date_title);
2928 if (!p->end_date_title)
2929 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
2931 cal_dialogue_show_item_after(p->dialogue, p->end_date_title, p->start_date);
2934 p->end_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, is_allday, p->end_date_title, __cal_edit_ug_end_date_changed_callback);
2936 cal_dialogue_show_item_after(p->dialogue, p->end_date, p->end_date_title);
2939 p->timezone = __cal_edit_ug_add_time_zone(p);
2941 cal_dialogue_show_item_after(p->dialogue, p->timezone, p->end_date);
2944 p->allday = __cal_edit_ug_add_all_day(p, is_allday);
2946 cal_dialogue_show_item_after(p->dialogue, p->allday, p->timezone);
2948 __cal_edit_ug_show_multi_alarms(p);
2950 Eina_List *list = eina_list_last(p->alarm_item_list);
2951 Evas_Object *last_item = eina_list_data_get(list);
2954 p->repeat = __cal_edit_ug_add_repeat(p);
2956 cal_dialogue_show_item_after(p->dialogue, p->repeat, last_item);
2960 static void __cal_edit_ug_show_todo_items (cal_edit_ug_data *p)
2962 c_retm_if(!p, "p is null");
2964 if (!p->due_date_title)
2965 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
2967 cal_dialogue_show_item_after(p->dialogue, p->due_date_title, p->title);
2970 p->due_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, EINA_FALSE, p->due_date_title, __cal_edit_ug_due_date_changed_callback);
2972 cal_dialogue_show_item_after(p->dialogue, p->due_date, p->due_date_title);
2974 if (!p->no_due_date)
2975 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
2977 cal_dialogue_show_item_after(p->dialogue, p->no_due_date, p->due_date);
2979 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2981 p->priority = __cal_edit_ug_add_priority(p);
2983 cal_dialogue_show_item_after(p->dialogue, p->priority, first_item);
2986 static void __cal_edit_ug_hide_multi_alarms (cal_edit_ug_data *p)
2988 c_retm_if(!p, "p is null");
2990 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2991 Evas_Object *button_obj = elm_object_part_content_get(first_item, "elm.icon");
2993 evas_object_del(button_obj);
2997 Eina_List *list = p->alarm_item_list;
2998 list = eina_list_next(list);
3000 Evas_Object *item = NULL;
3002 EINA_LIST_FOREACH(list, l, item) {
3004 cal_dialogue_hide_item(p->dialogue, item);
3009 static void __cal_edit_ug_hide_event_items (cal_edit_ug_data *p)
3011 c_retm_if(!p, "p is null");
3013 cal_dialogue_hide_item(p->dialogue, p->start_date_title);
3014 cal_dialogue_hide_item(p->dialogue, p->start_date);
3015 cal_dialogue_hide_item(p->dialogue, p->end_date_title);
3016 cal_dialogue_hide_item(p->dialogue, p->end_date);
3017 cal_dialogue_hide_item(p->dialogue, p->allday);
3018 cal_dialogue_hide_item(p->dialogue, p->timezone);
3019 cal_dialogue_hide_item(p->dialogue, p->repeat);
3020 __cal_edit_ug_hide_multi_alarms(p);
3024 static void __cal_edit_ug_hide_todo_items (cal_edit_ug_data *p)
3026 c_retm_if(!p, "p is null");
3028 cal_dialogue_hide_item(p->dialogue, p->due_date_title);
3029 cal_dialogue_hide_item(p->dialogue, p->due_date);
3030 cal_dialogue_hide_item(p->dialogue, p->no_due_date);
3031 cal_dialogue_hide_item(p->dialogue, p->priority);
3035 static void __cal_edit_ug_update_event_info (cal_edit_ug_data *p)
3037 c_retm_if(!p, "p is null");
3039 __cal_edit_ug_update_title_item(p->title_entry, p->event);
3040 __cal_edit_ug_update_note_item(p->note_entry, p->event);
3041 __cal_edit_ug_update_location_item(p, p->event);
3043 __cal_edit_ug_update_save_to_item(p, p->event);
3046 static void __cal_edit_ug_update_todo_info (cal_edit_ug_data *p)
3048 c_retm_if(!p, "p is null");
3050 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
3051 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
3052 __cal_edit_ug_update_location_item(p, p->todo);
3054 __cal_edit_ug_update_save_to_item(p, p->todo);
3058 static void __cal_edit_ug_new_event_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3062 c_retm_if(!data, "data null");
3064 cal_edit_ug_data *p = data;
3066 if(p->item_type == ITEM_TYPE_EVENT)
3069 p->item_type = ITEM_TYPE_EVENT;
3071 __cal_edit_ug_hide_todo_items(p);
3072 __cal_edit_ug_show_event_items(p);
3073 __cal_edit_ug_update_event_info(p);
3077 static void __cal_edit_ug_new_todo_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3081 c_retm_if(!data, "data null");
3083 cal_edit_ug_data *p = data;
3085 if(p->item_type == ITEM_TYPE_TODO)
3088 p->item_type = ITEM_TYPE_TODO;
3090 __cal_edit_ug_hide_event_items(p);
3091 __cal_edit_ug_show_todo_items(p);
3092 __cal_edit_ug_update_todo_info(p);
3096 static void __cal_edit_ug_add_dialogue_items(cal_edit_ug_data *p)
3100 c_retm_if(!p, "p is null");
3102 p->title = __cal_edit_ug_add_title(p);
3104 calendar_time_s time = {0};
3106 if (p->item_type == ITEM_TYPE_TODO) {
3108 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
3110 _calendar_get_end_time(p->todo, &time);
3111 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3112 // __cal_edit_ug_get_record_due_time(p, p->todo);
3114 p->due_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, EINA_FALSE, p->due_date_title, __cal_edit_ug_due_date_changed_callback);
3116 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3118 p->priority = __cal_edit_ug_add_priority(p);
3121 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
3124 _calendar_get_start_time(p->instance, &time);
3126 _calendar_get_start_time(p->event, &time);
3128 _calendar_convert_calendar_time_to_tm(&time, &p->stm);
3129 Eina_Bool allday = _calendar_is_allday_record(p->event);
3131 p->start_date = __cal_edit_ug_insert_timepicker_after(p, &p->stm, allday, p->start_date_title, __cal_edit_ug_start_date_changed_callback);
3133 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
3136 _calendar_get_end_time(p->instance, &time);
3138 _calendar_get_end_time(p->event, &time);
3140 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3141 p->end_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, allday, p->end_date_title, __cal_edit_ug_end_date_changed_callback);
3143 p->timezone = __cal_edit_ug_add_time_zone(p);
3145 p->allday = __cal_edit_ug_add_all_day(p, allday);
3149 p->note = __cal_edit_ug_add_note(p);
3151 p->location = __cal_edit_ug_add_location(p);
3153 __cal_edit_ug_add_multi_alarm(p);
3155 if (p->item_type == ITEM_TYPE_EVENT) {
3156 p->repeat = __cal_edit_ug_add_repeat(p);
3159 p->saveto = __cal_edit_ug_add_saveto(p);
3162 static void __cal_edit_ug_update_naviframe_language(cal_edit_ug_data *data)
3164 c_ret_if(!data->naviframe);
3166 Elm_Object_Item *item = elm_naviframe_top_item_get(data->naviframe);
3169 if (data->is_edit_mode) {
3171 if (data->item_type == ITEM_TYPE_TODO)
3172 elm_object_item_part_text_set(item, "default", C_("IDS_TASK_HEADER_EDIT_TASK"));
3174 elm_object_item_part_text_set(item, "default", C_("IDS_CLD_HEADER_EDIT_EVENT"));
3177 elm_object_item_part_text_set(item, "default", S_("IDS_COM_BODY_CREATE"));
3180 static void __cal_edit_ug_update_tabbar_language(cal_edit_ug_data *data)
3182 if (data->is_edit_mode)
3185 c_ret_if(!data->event_item);
3186 c_ret_if(!data->todo_item);
3188 elm_object_item_part_text_set(data->event_item, "default", C_("IDS_CLD_SK3_CREATE_EVENT"));
3189 elm_object_item_part_text_set(data->todo_item, "default", C_("IDS_TASK_SK_CREATE_TASK"));
3192 static void __cal_edit_ug_add_toolbar(cal_edit_ug_data *data, Evas_Object *scroller)
3196 c_retm_if(!data, "data is null");
3198 Elm_Object_Item *navi_item = NULL;
3200 if (data->is_edit_mode) {
3201 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, NULL);
3202 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3204 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, "tabbar");
3205 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3207 data->tabbar = elm_toolbar_add(data->naviframe);
3208 c_ret_if(!data->tabbar);
3210 elm_object_item_part_content_set(navi_item, "tabbar", data->tabbar);
3211 elm_toolbar_reorder_mode_set(data->tabbar, EINA_FALSE);
3212 elm_toolbar_transverse_expanded_set(data->tabbar, EINA_TRUE);
3213 elm_toolbar_shrink_mode_set(data->tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
3214 elm_object_style_set(data->tabbar, "tabbar");
3216 if (data->item_type == ITEM_TYPE_TODO) {
3217 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3219 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3221 data->event_item = elm_toolbar_item_insert_before(data->tabbar, data->todo_item, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3223 data->event_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3224 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3226 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3229 if (data->item_type == ITEM_TYPE_TODO)
3230 elm_toolbar_item_selected_set(data->todo_item, EINA_TRUE);
3232 elm_toolbar_item_selected_set(data->event_item, EINA_TRUE);
3234 __cal_edit_ug_update_tabbar_language(data);
3238 __cal_edit_ug_update_naviframe_language(data);
3240 data->save_cancel = cal_save_cancel_create(data->naviframe, NULL, __cal_edit_ug_save_button_callback, __cal_edit_ug_back_button_callback, data);
3244 static void __cal_edit_ug_dialogue_item_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
3249 cal_edit_ug_data* p = data;
3252 static Evas_Object *__cal_edit_ug_create_dialogue(Evas_Object *parent, cal_edit_ug_data* p)
3254 c_retv_if(!p, NULL);
3256 Evas_Object *scroller = cal_dialogue_create(parent);
3257 c_retvm_if(!scroller, NULL, "cal_dialogue_create() is failed");
3258 __cal_edit_ug_add_toolbar(p, scroller);
3260 Evas_Object *dialogue = cal_dialogue_get_box(scroller);
3262 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_UP, __cal_edit_ug_dialogue_item_clicked_callback, p);
3263 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_DOWN, __cal_edit_ug_dialogue_item_clicked_callback, p);
3264 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_MOVE, __cal_edit_ug_dialogue_item_clicked_callback, p);
3270 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, cal_edit_ug_data *data)
3274 c_retv_if(!parent, NULL);
3275 c_retv_if(!data, NULL);
3277 data->parent = parent;
3279 if (data->item_type == ITEM_TYPE_TODO)
3280 data->todo = data->record;
3282 data->event = data->record;
3284 if (data->is_edit_mode) {
3285 __cal_edit_ug_get_record_time_zone(data, data->record);
3287 cal_util_get_timezone(&data->timezone_path, &data->timezone_city, &data->timezone_offset);
3289 __cal_edit_ug_initialize_todo_record(data);
3290 __cal_edit_ug_initialize_event_record(data);
3293 Evas_Object *base_layout = cal_util_add_layout(parent, NULL);
3294 c_retv_if(!base_layout, NULL);
3296 Evas_Object *naviframe = elm_naviframe_add(base_layout);
3298 ERR("elm_naviframe_add() is failed");
3300 evas_object_del(base_layout);
3305 evas_object_show(naviframe);
3307 Evas_Object *bg = cal_util_add_bg(base_layout, EINA_FALSE);
3309 ERR("cal_util_add_bg() is failed");
3311 evas_object_del(base_layout);
3316 data->base_layout = base_layout;
3317 data->naviframe = naviframe;
3319 cal_util_initialize_timezone();
3321 data->dialogue = __cal_edit_ug_create_dialogue(naviframe, data);
3322 c_warn_if(!data->dialogue, "__cal_edit_ug_create_dialogue() is failed");
3324 __cal_edit_ug_add_dialogue_items(data);
3327 elm_object_part_content_set(base_layout, "elm.swallow.content", naviframe);
3328 elm_object_part_content_set(base_layout, "elm.swallow.bg", bg);
3333 static calendar_record_h inline __cal_edit_ug_get_origin_record(const calendar_record_h instance)
3337 c_retv_if(!instance, NULL);
3339 int index = _calendar_get_record_index(instance);
3341 return _calendar_get_record_with_index(index);
3344 static void *__cal_edit_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
3348 c_retv_if(!ug, NULL);
3349 c_retv_if(!service, NULL);
3350 c_retv_if(!priv, NULL);
3351 c_retv_if(mode != UG_MODE_FULLVIEW, NULL);
3353 cal_edit_ug_data *data = priv;
3358 char *item_type = NULL;
3361 calendar_error_e error = CALENDAR_ERROR_NONE;
3363 int r = service_get_extra_data(service, "index", &index);
3365 if (r == SERVICE_ERROR_NONE)
3368 r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
3369 if (r == SERVICE_ERROR_NONE) {
3371 if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_EVENT)) {
3372 data->item_type = ITEM_TYPE_EVENT;
3373 data->is_edit_mode = EINA_TRUE;
3375 r = service_get_extra_data(service, CAL_APPCONTROL_EVENT_ID, &index);
3376 if (r != SERVICE_ERROR_NONE) {
3377 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_EVENT_ID, r);
3387 calendar_record_h record = _calendar_get_record_with_index(cid);
3388 c_retv_if(!record, NULL);
3390 calendar_record_destroy(record, true);
3392 } else if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_TODO)) {
3394 data->item_type = ITEM_TYPE_TODO;
3395 data->is_edit_mode = EINA_TRUE;
3397 r = service_get_extra_data(service, CAL_APPCONTROL_TODO_ID, &index);
3398 if (r != SERVICE_ERROR_NONE) {
3399 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_TODO_ID, r);
3409 calendar_record_h record = _calendar_get_record_with_index(cid);
3410 c_retv_if(!record, NULL);
3412 calendar_record_destroy(record, true);
3415 else if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_VCS)) {
3417 data->item_type = ITEM_TYPE_VCS;
3419 r = service_get_extra_data(service, CAL_APPCONTROL_VCS_PATH, &path);
3420 if (r != SERVICE_ERROR_NONE) {
3421 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_VCS_PATH, r);
3430 FILE * file = fopen(path, "r");
3432 ERR("fopen(%s) is failed.", path);
3440 if (stat(path, &st) != 0) {
3441 ERR("Getting file information Error!");
3449 int size = st.st_size;
3450 char *raw_data = calloc(size + 1, sizeof(char));
3452 ERR("raw_data is NULL!");
3461 r = fread(raw_data, 1, size, file);
3463 c_retv_if(r < 0, NULL);
3465 calendar_list_h list = NULL;
3467 error = calendar_vcalendar_parse_to_calendar(raw_data, &list);
3468 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_parse_to_calendar() is failed(%x)", error);
3471 calendar_record_h record = NULL;
3472 error = calendar_list_get_current_record_p(list, &record);
3473 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
3475 error = calendar_record_clone(record, &data->record);
3476 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
3478 error = calendar_list_destroy(list, true);
3485 if (!data->record) {
3487 data->is_edit_mode = EINA_TRUE;
3488 data->record = _calendar_get_record_with_index(cid);
3491 data->is_edit_mode = EINA_FALSE;
3492 char *record_address = NULL;
3494 r = service_get_extra_data(service, "record", &record_address);
3496 data->record = (calendar_record_h)strtoul(record_address, NULL, 16);
3497 c_warn_if(!data->record, "strtol(%s, NULL, 16) is failed", record_address);
3500 char *note_str = NULL;
3501 r = service_get_extra_data(service, "note", ¬e_str);
3504 calendar_record_h record = NULL;
3505 calendar_error_e error = CALENDAR_ERROR_NONE;
3506 error = calendar_record_create(_calendar_event._uri, &record);
3507 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
3509 data->record = record;
3510 __cal_edit_ug_set_record_note(data->record, note_str);
3512 time_t now = time(NULL);
3513 localtime_r(&now, &data->base_time);
3519 int index = _calendar_get_record_index(data->record);
3521 data->is_edit_mode = EINA_TRUE;
3523 _calendar_record_type record_type = _calendar_get_record_type(data->record);
3524 ERR("record_type=%d", record_type);
3526 if (record_type != _CALENDAR_RECORD_TYPE_EVENT && record_type != _CALENDAR_RECORD_TYPE_TODO && record_type != _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR) {
3527 data->instance = data->record;
3528 data->record = __cal_edit_ug_get_origin_record(data->instance);
3532 CAL_FREE(record_address);
3535 if (_calendar_is_task_record(data->record))
3536 data->item_type = ITEM_TYPE_TODO;
3538 data->item_type = ITEM_TYPE_EVENT;
3543 char *base_time = NULL;
3544 r = service_get_extra_data(service, "base_time", &base_time);
3545 c_warn_if(SERVICE_ERROR_NONE != r,"service_get_extra_data is failed(%d).", r);
3548 long long int lli_time = strtoll(base_time, NULL, 10);
3549 cal_util_convert_lli_to_tm(NULL, lli_time, &data->base_time);
3550 CAL_FREE(base_time);
3553 if (error != CALENDAR_ERROR_NONE || data->item_type == ITEM_TYPE_UNKNOWN) {
3554 ERR("ERROR!! Invaild parameter!!");
3558 CAL_FREE(item_type);
3564 Evas_Object *parent = ug_get_parent_layout(ug);
3565 c_retv_if(!parent, NULL);
3567 data->window = ug_get_window();
3568 c_retv_if(!data->window, NULL);
3570 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme.edj");
3571 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme2.edj");
3573 Evas_Object *base = __cal_edit_ug_create_layout(parent, data);
3574 c_retv_if(!base, NULL);
3579 static void __cal_edit_ug_destroy_callback(ui_gadget_h ug, service_h service, void *priv)
3584 cal_edit_ug_data *data = priv;
3586 cal_util_delete_evas_object(&data->base_layout);
3588 if (data->timezone_city)
3589 free(data->timezone_city);
3590 if (data->timezone_path)
3591 free(data->timezone_path);
3592 if (data->timezone_offset)
3593 free(data->timezone_offset);
3595 _calendar_free_record_list(&data->calendar_book_list);
3597 if (data->alarm_list) {
3598 g_list_free(data->alarm_list);
3599 data->alarm_list = NULL;
3602 if (data->alarm_item_list) {
3603 eina_list_free(data->alarm_item_list);
3604 data->alarm_item_list = NULL;
3607 CAL_FREE(data->title_str);
3608 CAL_FREE(data->address);
3609 CAL_FREE(data->note_str);
3611 if (data->save_cancel)
3612 cal_save_cancel_destroy(data->save_cancel);
3615 evas_object_del(data->tabbar);
3618 calendar_record_destroy(data->event, true);
3621 calendar_record_destroy(data->todo, true);
3624 calendar_record_destroy(data->instance, true);
3628 static void __cal_edit_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
3632 DBG("UG: key event %d", evt);
3635 case UG_KEY_EVENT_END:
3643 static void __cal_edit_ug_update_language(cal_edit_ug_data *data)
3647 __cal_edit_ug_update_naviframe_language(data);
3649 __cal_edit_ug_update_tabbar_language(data);
3651 cal_save_cancel_set_button_text(data->save_cancel, S_("IDS_COM_OPT_SAVE"), NULL);
3653 __cal_edit_ug_update_title_language(data->title);
3655 if (data->item_type == ITEM_TYPE_EVENT) {
3657 __cal_edit_ug_update_start_language(data->start_date_title);
3659 __cal_edit_ug_update_end_language(data->end_date_title);
3661 __cal_edit_ug_update_due_language(data->due_date_title);
3663 __cal_edit_ug_update_time_zone_language(data->timezone, data->timezone_city, data->timezone_offset);
3665 if (data->item_type == ITEM_TYPE_TODO) {
3667 __cal_edit_ug_update_no_due_date_language(data->no_due_date);
3669 __cal_edit_ug_update_priority_language(data->priority, data->todo);
3672 if (data->item_type == ITEM_TYPE_EVENT)
3673 __cal_edit_ug_update_allday_language(data->allday);
3675 __cal_edit_ug_update_description_language(data->note);
3677 __cal_edit_ug_update_location_language(data->location);
3679 __cal_edit_ug_update_reminder_language(data->alarm_item_list);
3681 if (data->item_type == ITEM_TYPE_EVENT)
3682 __cal_edit_ug_update_recurrence_language(data->repeat, data->repeat_freq);
3684 if (data->item_type == ITEM_TYPE_EVENT)
3685 __cal_edit_ug_update_saveto_language(data->saveto, data->event);
3687 __cal_edit_ug_update_saveto_language(data->saveto, data->todo);
3690 static void __cal_edit_ug_update_region(cal_edit_ug_data *data)
3694 if (data->item_type == ITEM_TYPE_EVENT) {
3696 Eina_Bool is_allday = _calendar_is_allday_record(data->event);
3698 __cal_edit_ug_update_datetime_region(data->start_date, &data->stm, is_allday, __cal_edit_ug_start_date_changed_callback, data);
3700 __cal_edit_ug_update_datetime_region(data->end_date, &data->etm, is_allday, __cal_edit_ug_end_date_changed_callback, data);
3703 __cal_edit_ug_update_datetime_region(data->due_date, &data->etm, _calendar_is_allday_record(data->todo), __cal_edit_ug_due_date_changed_callback, data);
3706 static void __cal_edit_ug_event_callback(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
3712 case UG_EVENT_LANG_CHANGE:
3713 __cal_edit_ug_update_language((cal_edit_ug_data *)priv);
3715 case UG_EVENT_REGION_CHANGE:
3716 __cal_edit_ug_update_region((cal_edit_ug_data *)priv);
3723 API int UG_MODULE_INIT(struct ug_module_ops *ops)
3727 c_retv_if(!ops, -1);
3729 cal_edit_ug_data *data = calloc(1, sizeof(cal_edit_ug_data));
3731 ops->create = __cal_edit_ug_create_callback;
3732 ops->destroy = __cal_edit_ug_destroy_callback;
3733 ops->key_event = __cal_edit_ug_key_callback;
3734 ops->event = __cal_edit_ug_event_callback;
3736 ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
3738 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
3739 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
3741 __cal_edit_ug_initialize(data);
3746 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
3752 cal_edit_ug_data *data = ops->priv;
3754 __cal_edit_ug_finish(data);