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_record_time(cal_edit_ug_data *p, calendar_record_h record)
251 if (!p->timezone_path)
252 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
254 c_ret_if(!p->timezone_path);
256 calendar_error_e error = CALENDAR_ERROR_NONE;
258 error = calendar_record_set_str(record, _calendar_event.start_tzid, p->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, p->timezone_path);
262 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
264 calendar_time_s start_time = {0};
266 _calendar_get_start_time(record, &start_time);
268 calendar_time_s end_time = {0};
270 _calendar_get_end_time(record, &end_time);
272 if (_calendar_is_allday_record(record)) {
274 start_time.time.date.year = p->stm.tm_year + 1900;
275 start_time.time.date.month = p->stm.tm_mon + 1;
276 start_time.time.date.mday = p->stm.tm_mday;
278 end_time.time.date.year = p->stm.tm_year + 1900;
279 end_time.time.date.month = p->stm.tm_mon + 1;
280 end_time.time.date.mday = p->stm.tm_mday;
283 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
284 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
287 error = calendar_record_set_caltime(record, _calendar_event.start_time, start_time);
288 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
290 error = calendar_record_set_caltime(record, _calendar_event.end_time, end_time);
291 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
294 static void __cal_edit_ug_set_rrule_wday(calendar_record_h record, enum __cal_edit_wday tm_wday)
298 calendar_error_e error = CALENDAR_ERROR_NONE;
301 case CAL_EDIT_WDAY_SUNDAY:
302 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
305 case CAL_EDIT_WDAY_MONDAY:
306 error = calendar_record_set_str(record, _calendar_event.byday, "MO");
309 case CAL_EDIT_WDAY_TUESDAY:
310 error = calendar_record_set_str(record, _calendar_event.byday, "TU");
313 case CAL_EDIT_WDAY_WEDNESDAY:
314 error = calendar_record_set_str(record, _calendar_event.byday, "WE");
317 case CAL_EDIT_WDAY_THURSDAY:
318 error = calendar_record_set_str(record, _calendar_event.byday, "TH");
321 case CAL_EDIT_WDAY_FRIDAY:
322 error = calendar_record_set_str(record, _calendar_event.byday, "FR");
325 case CAL_EDIT_WDAY_SATURDAY:
326 error = calendar_record_set_str(record, _calendar_event.byday, "SA");
330 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
334 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
337 static void __cal_edit_ug_set_rrule_month(calendar_record_h record, int tm_mon)
341 char buffer[8] = {0};
343 snprintf(buffer, sizeof(buffer), "%d", tm_mon + 1);
345 calendar_error_e error = CALENDAR_ERROR_NONE;
347 error = calendar_record_set_str(record, _calendar_event.bymonth, buffer);
348 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
351 static void __cal_edit_ug_set_rrule_mday(calendar_record_h record, int tm_mday)
355 char buffer[8] = {0};
357 snprintf(buffer, sizeof(buffer), "%d", tm_mday);
359 calendar_error_e error = CALENDAR_ERROR_NONE;
361 error = calendar_record_set_str(record, _calendar_event.bymonthday, buffer);
362 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
365 static int __cal_edit_ug_g_list_compare(const void* data1, const void* data2)
367 const Cal_Reminder* reminder1 = (Cal_Reminder*)data1;
368 const Cal_Reminder* reminder2 = (Cal_Reminder*)data2;
370 if (reminder1->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
371 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
372 long long int dt1, dt2;
373 cal_util_convert_tm_to_lli(NULL, &reminder1->datetime, &dt1);
374 cal_util_convert_tm_to_lli(NULL, &reminder2->datetime, &dt2);
385 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
388 return reminder1->alarm_value - reminder2->alarm_value;
392 static int __cal_edit_ug_g_list_compare_with_data(const void* data1, const void* data2, void* user_data)
394 return __cal_edit_ug_g_list_compare(data1, data2);
398 static void __cal_edit_ug_set_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
402 c_retm_if(!p, "p is null");
403 c_retm_if(!record, "record is null");
407 Eina_Bool is_task = _calendar_is_task_record(record);
410 _calendar_clear_child_record(record, _calendar_todo.calendar_alarm);
412 _calendar_clear_child_record(record, _calendar_event.calendar_alarm);
415 Eina_List* list = NULL;
416 Evas_Object *item = NULL;
417 EINA_LIST_FOREACH(p->alarm_item_list, list, item) {
419 Cal_Reminder* reminder = evas_object_data_get(item, "data");
421 if (g_list_find_custom(temp, reminder, __cal_edit_ug_g_list_compare))
424 temp = g_list_insert_sorted_with_data(temp, reminder, __cal_edit_ug_g_list_compare_with_data, NULL);
426 calendar_record_h calendar_alarm = cal_reminder_get_cal_val(reminder);
428 calendar_error_e error = CALENDAR_ERROR_NONE;
431 error = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, calendar_alarm);
433 error = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, calendar_alarm);
435 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() is failed(%x)", error);
440 static void __cal_edit_ug_set_record_repeat(cal_edit_ug_data *p)
442 c_retm_if(!p, "p is null");
444 calendar_error_e error = CALENDAR_ERROR_NONE;
446 switch (p->repeat_freq) {
447 case CALENDAR_RECURRENCE_NONE:
450 case CALENDAR_RECURRENCE_DAILY:
451 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
454 case CAL_REPEAT_EVERY_3_DAY:
455 p->repeat_freq = CALENDAR_RECURRENCE_DAILY;
456 error = calendar_record_set_int(p->event, _calendar_event.interval, 3);
459 case CALENDAR_RECURRENCE_WEEKLY:
460 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
461 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
464 case CAL_REPEAT_EVERY_2_WEEK:
465 p->repeat_freq = CALENDAR_RECURRENCE_WEEKLY;
466 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
467 error = calendar_record_set_int(p->event, _calendar_event.interval, 2);
470 case CALENDAR_RECURRENCE_YEARLY:
471 __cal_edit_ug_set_rrule_month(p->event, p->stm.tm_mon);
472 case CALENDAR_RECURRENCE_MONTHLY:
473 __cal_edit_ug_set_rrule_mday(p->event, p->stm.tm_mday);
474 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
481 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
483 error = calendar_record_set_int(p->event, _calendar_event.freq, p->repeat_freq);
484 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
486 error = calendar_record_set_int(p->event, _calendar_event.range_type, p->repeat_range);
487 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
489 if (CALENDAR_RECURRENCE_NONE != p->repeat_freq) {
491 if (p->repeat_range == CALENDAR_RANGE_COUNT) {
492 error = calendar_record_set_int(p->event, _calendar_event.count, p->repeat_count);
493 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
494 } else if (p->repeat_range == CALENDAR_RANGE_UNTIL) {
496 error = calendar_record_set_int(p->event, _calendar_event.count, 0);
497 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
499 calendar_time_s until_time = {0};
501 until_time.type = CALENDAR_TIME_UTIME;
502 cal_util_convert_tm_to_lli(NULL, &p->repeat_until, &until_time.time.utime);
504 error = calendar_record_set_caltime(p->event, _calendar_event.until_time, until_time);
505 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
510 static void __cal_edit_ug_set_record_save_to( calendar_record_h record, int calendar_book_id)
512 calendar_error_e error = CALENDAR_ERROR_NONE;
514 if (_calendar_is_task_record(record)) {
515 error = calendar_record_set_int(record, _calendar_todo.calendar_book_id, calendar_book_id);
516 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
518 error = calendar_record_set_int(record, _calendar_event.calendar_book_id, calendar_book_id);
519 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
521 calendar_record_h calendar_book = NULL;
523 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
524 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
526 char *organizer_name = NULL;
528 error = calendar_record_get_str(calendar_book, _calendar_book.description, &organizer_name);
529 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
531 error = calendar_record_set_str(record, _calendar_event.organizer_name, organizer_name);
532 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
534 CAL_FREE(organizer_name);
536 error = calendar_record_destroy(calendar_book, true);
537 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
541 static void __cal_edit_ug_set_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
543 c_retm_if(!p, "p is null");
544 c_retm_if(!record, "record is null");
546 calendar_error_e error = CALENDAR_ERROR_NONE;
548 calendar_time_s due_time = {0};
550 _calendar_get_end_time(record, &due_time);
552 error = calendar_record_set_str(record, _calendar_todo.due_tzid, p->timezone_path);
553 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
555 if (p->is_no_due_date) {
556 due_time.time.utime = CALENDAR_TODO_NO_DUE_DATE;
558 cal_util_convert_tm_to_lli(NULL, &p->etm, &due_time.time.utime);
561 error = calendar_record_set_caltime(record, _calendar_todo.due_time, due_time);
562 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
565 static void __cal_edit_ug_set_record_priority(calendar_record_h record, int priority)
567 c_retm_if(!record, "record is null");
569 calendar_error_e error = CALENDAR_ERROR_NONE;
571 error = calendar_record_set_int(record, _calendar_todo.priority, priority);
572 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
575 static void __cal_edit_ug_initialize_event_record(cal_edit_ug_data *p)
579 c_retm_if(!p, "p is null");
581 calendar_error_e error = CALENDAR_ERROR_NONE;
584 error = calendar_record_create(_calendar_event._uri, &p->event);
585 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
588 p->stm = p->base_time;
589 p->stm.tm_min = p->stm.tm_sec = 0;
591 if (0 <= p->base_time.tm_hour)
592 p->stm.tm_hour = p->base_time.tm_hour;
594 cal_util_update_tm_hour(&p->stm,1);
597 cal_util_update_tm_hour(&p->etm,1);
599 calendar_time_s start_time = {0};
600 calendar_time_s end_time = {0};
602 start_time.type = CALENDAR_TIME_UTIME;
603 end_time.type = CALENDAR_TIME_UTIME;
605 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
606 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
608 error = calendar_record_set_caltime(p->event, _calendar_event.start_time, start_time);
609 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
611 error = calendar_record_set_caltime(p->event, _calendar_event.end_time, end_time);
612 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
614 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
615 __cal_edit_ug_set_record_time(p, p->event);
617 struct tm repeat_until = p->stm;
618 cal_util_update_tm_month (&repeat_until, 1);
619 p->repeat_freq = CALENDAR_RECURRENCE_NONE;
620 p->repeat_range = CALENDAR_RANGE_NONE;
621 p->repeat_count = 10;
622 __cal_edit_ug_set_record_repeat(p);
624 __cal_edit_ug_set_record_save_to(p->event, DEFAULT_EVENT_CALENDAR_BOOK_ID);
631 static void __cal_edit_ug_initialize_todo_record(cal_edit_ug_data *p)
635 c_retm_if(!p, "p is null");
637 calendar_error_e error = CALENDAR_ERROR_NONE;
640 error = calendar_record_create(_calendar_todo._uri, &p->todo);
641 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
644 p->stm = p->base_time;
645 p->stm.tm_min = p->stm.tm_sec = 0;
647 if (0 <= p->base_time.tm_hour)
648 p->stm.tm_hour = p->base_time.tm_hour;
650 cal_util_update_tm_hour(&p->stm,1);
653 cal_util_update_tm_hour(&p->etm,1);
655 calendar_time_s end_time = {0};
656 end_time.type = CALENDAR_TIME_UTIME;
658 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
660 error = calendar_record_set_caltime(p->todo, _calendar_todo.due_time, end_time);
661 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
663 __cal_edit_ug_set_record_save_to(p->todo, DEFAULT_TODO_CALENDAR_BOOK_ID);
665 __cal_edit_ug_set_record_priority(p->todo, CALENDAR_TODO_PRIORITY_NORMAL);
672 static inline char * __cal_edit_ug_get_record_title(calendar_record_h record)
674 c_retvm_if(!record, NULL, "record is null");
676 calendar_error_e error = CALENDAR_ERROR_NONE;
677 char *summary = NULL;
679 if (_calendar_is_task_record(record))
680 error = calendar_record_get_str(record, _calendar_todo.summary, &summary);
682 error = calendar_record_get_str(record, _calendar_event.summary, &summary);
684 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
689 static inline void __cal_edit_ug_get_record_location(cal_edit_ug_data *p, calendar_record_h record)
691 calendar_error_e error = CALENDAR_ERROR_NONE;
693 p->address = _calendar_get_location(record);
695 if (_calendar_is_task_record(record))
697 error = calendar_record_get_double(record, _calendar_todo.latitude, &p->latitude);
698 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
699 error = calendar_record_get_double(record, _calendar_todo.longitude, &p->longitude);
700 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
704 error = calendar_record_get_double(record, _calendar_event.latitude, &p->latitude);
705 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
706 error = calendar_record_get_double(record, _calendar_event.longitude, &p->longitude);
707 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
711 static inline char * __cal_edit_ug_get_record_note(calendar_record_h record)
713 c_retvm_if(!record, NULL, "record is null");
715 calendar_error_e error = CALENDAR_ERROR_NONE;
718 if (_calendar_is_task_record(record))
719 error = calendar_record_get_str(record, _calendar_todo.description, ¬e);
721 error = calendar_record_get_str(record, _calendar_event.description, ¬e);
723 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
728 static int __cal_edit_ug_get_timezone_offset_with_standard_name(const char *standard_name)
730 int timezone_offset = 0;
732 c_retv_if(!CAL_STRLEN(standard_name), timezone_offset);
734 calendar_error_e error = CALENDAR_ERROR_NONE;
736 calendar_query_h query = NULL;
738 error = calendar_query_create(_calendar_timezone._uri, &query);
739 c_retvm_if(error != CALENDAR_ERROR_NONE, timezone_offset, "calendar_query_create() is failed(%x)", error);
741 calendar_filter_h filter = NULL;
743 error = calendar_filter_create(_calendar_timezone._uri, &filter);
744 if (error != CALENDAR_ERROR_NONE) {
746 ERR("calendar_filter_create() is failed(%x)", error);
747 calendar_query_destroy(query);
751 error = calendar_filter_add_str(filter, _calendar_timezone.standard_name, CALENDAR_MATCH_EXACTLY, standard_name);
752 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
754 error = calendar_query_set_filter(query, filter);
755 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
757 calendar_list_h list = NULL;
759 error = calendar_db_get_records_with_query(query, 0, 1, &list);
760 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
762 error = calendar_list_first(list);
763 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
765 calendar_record_h timezone = NULL;
767 error = calendar_list_get_current_record_p(list, &timezone);
768 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
770 error = calendar_record_get_int(timezone, _calendar_timezone.tz_offset_from_gmt, &timezone_offset);
771 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
773 error = calendar_list_destroy(list, true);
774 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
776 error = calendar_filter_destroy(filter);
777 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
779 error = calendar_query_destroy(query);
780 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
782 return timezone_offset;
785 static void __cal_edit_ug_get_timezone_for_eas(cal_edit_ug_data *p, calendar_record_h record)
790 calendar_error_e error = CALENDAR_ERROR_NONE;
792 char *standard_name = NULL;
794 if (_calendar_is_task_record(record))
795 error = calendar_record_get_str_p(record, _calendar_todo.due_tzid, &standard_name);
797 error = calendar_record_get_str_p(record, _calendar_event.start_tzid, &standard_name);
799 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
801 c_ret_if(!CAL_STRLEN(standard_name));
803 int timezone_offset = __cal_edit_ug_get_timezone_offset_with_standard_name(standard_name);
805 cal_util_get_timezone_id(timezone_offset, &p->timezone_path);
808 static void __cal_edit_ug_get_record_time_zone(cal_edit_ug_data *p, calendar_record_h record)
813 calendar_error_e error = CALENDAR_ERROR_NONE;
815 if (_calendar_is_eas_record(record))
816 __cal_edit_ug_get_timezone_for_eas(p, record);
818 if (_calendar_is_task_record(record))
819 error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
821 error = calendar_record_get_str(record, _calendar_event.start_tzid, &p->timezone_path);
823 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
826 c_ret_if(!CAL_STRLEN(p->timezone_path));
828 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
831 static void __cal_edit_ug_get_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
833 c_retm_if(!p, "p is null");
834 c_retm_if(!record, "record is null");
837 g_list_free(p->alarm_list);
838 p->alarm_list = NULL;
843 Eina_Bool is_task = _calendar_is_task_record(record);
844 calendar_error_e error = CALENDAR_ERROR_NONE;
848 error = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, (unsigned int *)&alarm_count);
849 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
853 error = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, (unsigned int *)&alarm_count);
854 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
858 for (i = 0; i < alarm_count; i++) {
859 calendar_record_h calendar_alarm = NULL;
863 error = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, i, &calendar_alarm);
864 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
868 error = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, i, &calendar_alarm);
869 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
872 Cal_Reminder* reminder = cal_reminder_create(calendar_alarm);
873 p->alarm_list = g_list_append(p->alarm_list,(void *)reminder);
876 p->alarm_list = g_list_first(p->alarm_list);
879 static void __cal_edit_ug_get_record_repeat(cal_edit_ug_data *p, calendar_record_h record)
884 calendar_record_h original_record = NULL;
885 int original_event_id = 0;
886 calendar_error_e error = CALENDAR_ERROR_NONE;
888 error = calendar_record_get_int(record, _calendar_event.original_event_id, &original_event_id);
889 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
891 if (0 < original_event_id) {
893 error = calendar_db_get_record(_calendar_event._uri, original_event_id, &original_record);
894 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
897 if (!original_record)
898 original_record = record;
900 error = calendar_record_get_int(record, _calendar_event.freq, &p->repeat_freq);
901 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
903 if (p->repeat_freq == CALENDAR_RECURRENCE_WEEKLY) {
907 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
908 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
911 p->repeat_freq = CAL_REPEAT_EVERY_2_WEEK;
913 } else if (p->repeat_freq == CALENDAR_RECURRENCE_DAILY) {
917 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
918 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
921 p->repeat_freq = CAL_REPEAT_EVERY_3_DAY;
924 error = calendar_record_get_int(record, _calendar_event.range_type, (int *)&p->repeat_range);
925 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
927 if (p->repeat_range == CALENDAR_RANGE_NONE) {
928 p->repeat_count = 10;
930 p->repeat_until = p->stm;
931 cal_util_update_tm_month (&p->repeat_until, 1);
934 error = calendar_record_get_int(record, _calendar_event.count, &p->repeat_count);
935 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
937 calendar_time_s until_utime = {0};
939 error = calendar_record_get_caltime(record, _calendar_event.until_time, &until_utime);
940 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
942 cal_util_convert_lli_to_tm(NULL, until_utime.time.utime, &p->repeat_until);
945 if (original_record != record) {
946 error = calendar_record_destroy(original_record, true);
947 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
951 static int __cal_edit_ug_get_record_priority(calendar_record_h record)
953 c_retv_if(!record, 0);
955 calendar_error_e error = CALENDAR_ERROR_NONE;
959 error = calendar_record_get_int(record, _calendar_todo.priority, (int *)&priority);
960 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
965 static void __cal_edit_ug_get_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
967 c_retm_if(!p, "p is null");
968 c_retm_if(!record, "record is null");
970 calendar_error_e error = CALENDAR_ERROR_NONE;
972 calendar_time_s due_time = {0};
974 _calendar_get_end_time(record, &due_time);
976 cal_util_convert_lli_to_tm(NULL, due_time.time.utime, &p->etm);
978 if (due_time.time.utime == CALENDAR_TODO_NO_DUE_DATE) {
979 p->is_no_due_date = EINA_TRUE;
980 //p->etm = p->base_time;
983 error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
984 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
986 c_ret_if(!p->timezone_path);
988 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
991 static void __cal_edit_ug_update_title_item(Evas_Object *entry, calendar_record_h record)
993 c_retm_if(!entry, "entry is null");
994 c_retm_if(!record, "record is null");
996 char* title = __cal_edit_ug_get_record_title(record);
998 elm_entry_entry_set(entry, title);
1003 static void __cal_edit_ug_update_note_item(Evas_Object *entry, calendar_record_h record)
1005 c_retm_if(!entry, "entry is null");
1006 c_retm_if(!record, "record is null");
1008 char* note = __cal_edit_ug_get_record_note(record);
1010 elm_entry_entry_set(entry, note);
1015 static void __cal_edit_ug_update_location_item(cal_edit_ug_data *p, calendar_record_h record)
1017 c_retm_if(!p, "p is null");
1018 c_retm_if(!record, "record is null");
1020 __cal_edit_ug_get_record_location(p, record);
1021 elm_entry_entry_set(p->location_entry, p->address);
1024 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz);
1026 static void __cal_edit_ug_update_save_to_item(cal_edit_ug_data *p, calendar_record_h record)
1028 c_retm_if(!p, "p is null");
1030 int calendar_book_id = _calendar_get_calendar_index(record);
1033 char* saveto_text = NULL;
1034 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
1035 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
1036 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
1037 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
1039 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
1040 saveto_text = strdup(buf);
1043 elm_object_part_text_set(p->saveto, "elm.text.1", saveto_text);
1045 CAL_FREE(saveto_text);
1048 static void __cal_edit_ug_update_priority_item(cal_edit_ug_data *p, calendar_record_h record)
1050 c_retm_if(!p, "p is null");
1051 c_retm_if(!record, "record is null");
1053 char* priority_text = NULL;
1054 int priority = __cal_edit_ug_get_record_priority(record);
1056 case CALENDAR_TODO_PRIORITY_LOW:
1057 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
1059 case CALENDAR_TODO_PRIORITY_NORMAL:
1060 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
1062 case CALENDAR_TODO_PRIORITY_HIGH:
1063 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
1069 elm_object_part_text_set(p->priority, "elm.text.1", priority_text);
1070 CAL_FREE(priority_text);
1074 static void __cal_edit_ug_update_start_language(Evas_Object *item)
1078 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_FROM"));
1081 static void __cal_edit_ug_update_end_language(Evas_Object *item)
1085 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_TO"));
1088 static void __cal_edit_ug_update_due_language(Evas_Object *item)
1092 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_DUE_DATE"));
1095 static Evas_Object *__cal_edit_ug_insert_padding_after(cal_edit_ug_data* p, const char* title, Evas_Object *after)
1097 c_retv_if(!p, NULL);
1098 c_retv_if(!after, NULL);
1100 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "title", after, NULL, NULL);
1101 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1103 if (CAL_STRLEN(title))
1104 elm_object_part_text_set(item, "elm.text", title);
1109 static void __cal_edit_ug_title_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1112 cal_edit_ug_data* p = (cal_edit_ug_data *)data;
1116 str = elm_entry_entry_get(p->title_entry);
1117 if (!str || str[0] == '\0')
1118 p->title_str = NULL;
1120 p->title_str = elm_entry_markup_to_utf8(str);
1122 if(p->item_type == ITEM_TYPE_TODO)
1123 __cal_edit_ug_set_record_title(p->todo, p->title_str);
1125 __cal_edit_ug_set_record_title(p->event, p->title_str);
1128 static Evas_Object * __cal_edit_ug_title_icon(cal_edit_ug_data* p, Evas_Object *obj)
1130 c_retv_if(!p, NULL);
1131 c_retv_if(!obj, NULL);
1133 Evas_Object *ef = cal_util_add_edit_field(obj, S_("IDS_COM_BODY_DETAILS_TITLE"), EINA_FALSE, EINA_TRUE);
1134 c_retvm_if(!ef, NULL, "ef is null");
1136 Evas_Object *entry = elm_object_part_content_get(ef, "elm.swallow.content");
1137 c_retvm_if(!entry, ef, "entry is null");
1139 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1141 p->title_entry = entry;
1143 if (p->item_type == ITEM_TYPE_TODO)
1144 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
1146 __cal_edit_ug_update_title_item(p->title_entry, p->event);
1148 evas_object_smart_callback_add(p->title_entry, "changed", __cal_edit_ug_title_entry_changed_callback, p);
1149 evas_object_smart_callback_add(p->title_entry, "preedit,changed", __cal_edit_ug_title_entry_changed_callback, p);
1151 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->title_entry);
1157 static void __cal_edit_ug_update_title_language(Evas_Object *item)
1161 Evas_Object *edit_field = elm_object_part_content_get(item, "elm.icon");
1162 c_ret_if(!edit_field);
1164 elm_object_part_text_set(edit_field, "elm.guidetext", S_("IDS_COM_BODY_DETAILS_TITLE"));
1167 static Evas_Object *__cal_edit_ug_add_title(cal_edit_ug_data* p)
1169 c_retv_if(!p, NULL);
1171 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1172 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1174 Evas_Object *editfield = __cal_edit_ug_title_icon(p, item);
1175 c_retvm_if(!editfield, NULL, "__cal_edit_ug_title_icon() is failed");
1177 elm_object_part_content_set(item, "elm.icon", editfield);
1182 static void __cal_edit_ug_location_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1186 cal_edit_ug_data *p = data;
1189 CAL_FREE(p->address);
1191 p->address = elm_entry_markup_to_utf8(elm_entry_entry_get(p->location_entry));
1193 if (!CAL_STRLEN(p->address)) {
1195 p->longitude = p->latitude = CALENDAR_RECORD_NO_COORDINATE;
1199 if (p->item_type == ITEM_TYPE_TODO)
1200 __cal_edit_ug_set_record_location(p->todo, p->address, p->latitude, p->longitude);
1202 __cal_edit_ug_set_record_location(p->event, p->address, p->latitude, p->longitude);
1205 static Evas_Object * __cal_edit_ug_location_icon(cal_edit_ug_data* p, Evas_Object *obj)
1207 c_retv_if(!p, NULL);
1208 c_retv_if(!obj, NULL);
1210 Evas_Object *ly = NULL;
1212 Evas_Object *ef = cal_util_add_edit_field(obj, C_("IDS_COM_BODY_DETAILS_LOCATION"), EINA_FALSE, EINA_TRUE);
1215 p->location_entry = elm_object_part_content_get(ef, "elm.swallow.content");
1216 c_retv_if(!p->location_entry, ly);
1218 evas_object_smart_callback_add(p->location_entry, "changed", __cal_edit_ug_location_entry_changed_callback, p);
1219 evas_object_smart_callback_add(p->location_entry, "preedit,changed", __cal_edit_ug_location_entry_changed_callback, p);
1220 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->location_entry);
1222 elm_entry_cnp_mode_set(p->location_entry, ELM_CNP_MODE_PLAINTEXT);
1224 if (p->item_type == ITEM_TYPE_TODO)
1225 __cal_edit_ug_update_location_item(p, p->todo);
1227 __cal_edit_ug_update_location_item(p, p->event);
1232 static void __cal_edit_ug_update_location_language(Evas_Object *item)
1236 Evas_Object *layout = elm_object_part_content_get(item, "elm.icon");
1239 Evas_Object *edit_field = elm_object_part_content_get(layout, "editfield/sw");
1240 c_ret_if(!edit_field);
1242 elm_object_part_text_set(edit_field, "elm.guidetext", C_("IDS_COM_BODY_DETAILS_LOCATION"));
1244 Evas_Object *button = elm_object_part_content_get(layout, "button/sw");
1247 elm_object_text_set(button, C_("IDS_LBS_BODY_MAP"));
1250 static Evas_Object *__cal_edit_ug_add_location(cal_edit_ug_data* p)
1252 c_retv_if(!p, NULL);
1254 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1255 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1257 Evas_Object *editfield = __cal_edit_ug_location_icon(p, item);
1258 c_retvm_if(!editfield, NULL, "__cal_edit_ug_note_icon() is failed");
1260 elm_object_part_content_set(item, "elm.icon", editfield);
1262 __cal_edit_ug_insert_padding_after(p, NULL, item);
1267 static void __cal_edit_ug_note_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1269 char *email_link = NULL;
1270 cal_edit_ug_data *p = data;
1271 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(p->note_entry));
1273 if (CAL_STRLEN(p->note_str))
1274 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1276 if ((NULL != email_link) && CAL_STRLEN(str) && (NULL != strstr(p->note_str, str))) {
1277 char *strnote = NULL;
1278 int strnote_len = 0;
1279 strnote_len = strlen(str) + strlen(email_link);
1280 CAL_CALLOC(strnote, strnote_len+1, char);
1281 if (NULL != strnote)
1283 snprintf(strnote, strnote_len + 1, "%s%s", str, email_link);
1284 p->note_str = strdup(strnote);
1294 p->note_str = CAL_STRDUP(str);
1299 if(p->item_type == ITEM_TYPE_TODO)
1300 __cal_edit_ug_set_record_note(p->todo, p->note_str);
1302 __cal_edit_ug_set_record_note(p->event, p->note_str);
1306 static Evas_Object * __cal_edit_ug_note_icon(cal_edit_ug_data* p, Evas_Object *obj)
1308 c_retv_if(!p, NULL);
1309 c_retv_if(!obj, NULL);
1311 Evas_Object *ef = cal_util_add_edit_field(obj, C_("IDS_CLD_BODY_CREATE_DESCRITION"), EINA_FALSE, EINA_TRUE );
1314 Evas_Object *entry = elm_object_part_content_get(ef, "elm.swallow.content");
1315 c_retvm_if(!entry, ef, "entry is null");
1317 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1318 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
1319 //elm_entry_autocapital_type_set(entry, EINA_TRUE);
1320 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1322 p->note_entry = entry;
1326 char *email_link = NULL;
1327 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1329 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(p->note_str));
1332 char *snote_display = NULL;
1333 int nsize = email_link - p->note_str + 1;
1334 snote_display = calloc(nsize, sizeof(char));
1335 c_retvm_if(!snote_display , NULL, "calloc(nsize, sizeof(char)) is failed");
1337 CAL_STRNCPY(snote_display, p->note_str, nsize-1);
1339 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(snote_display));
1340 free(snote_display);
1344 if (p->item_type == ITEM_TYPE_TODO)
1345 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
1347 __cal_edit_ug_update_note_item(p->note_entry, p->event);
1349 evas_object_smart_callback_add(p->note_entry, "changed", __cal_edit_ug_note_entry_changed_callback, p);
1350 evas_object_smart_callback_add(p->note_entry, "preedit,changed", __cal_edit_ug_note_entry_changed_callback, p);
1351 cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, p->note_entry);
1359 static void __cal_edit_ug_update_description_language(Evas_Object *item)
1363 Evas_Object *edit_field = elm_object_part_content_get(item, "elm.icon");
1364 c_ret_if(!edit_field);
1366 elm_object_part_text_set(edit_field, "elm.guidetext", C_("IDS_CLD_BODY_CREATE_DESCRITION"));
1369 static Evas_Object *__cal_edit_ug_add_note(cal_edit_ug_data* p)
1371 c_retv_if(!p, NULL);
1373 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1374 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1376 Evas_Object *editfield = __cal_edit_ug_note_icon(p, item);
1377 c_retvm_if(!editfield, NULL, "__cal_edit_ug_location_icon() is failed");
1380 elm_object_part_content_set(item, "elm.icon", editfield);
1385 static Evas_Object * __cal_edit_ug_edit_time_icon(Evas_Object *obj, struct tm* value, Eina_Bool allday)
1387 c_retvm_if(!obj, NULL, "obj is null");
1389 Evas_Object* icon_obj = cal_util_add_datetime(obj, NULL, value);
1390 c_retvm_if(!icon_obj, NULL, "icon_obj is null");
1392 elm_object_part_content_set(obj, "datefield", icon_obj);
1395 elm_datetime_format_set(icon_obj, "%b %d , %Y %H : %M");
1397 elm_datetime_format_set(icon_obj, "%b %d , %Y %I : %M %p");
1401 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1402 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1404 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1406 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1410 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1411 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1412 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1415 elm_datetime_field_limit_set(icon_obj, ELM_DATETIME_YEAR, 70, 136);
1420 static Eina_Bool __cal_edit_ug_check_date_validity(void *data)
1422 c_retv_if(!data, EINA_FALSE);
1423 cal_edit_ug_data* p = data;
1425 time_t start_t = mktime(&p->stm);
1426 time_t end_t = mktime(&p->etm);
1434 static void __cal_edit_ug_start_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1436 c_retm_if(data == NULL, "data is null");
1437 cal_edit_ug_data *p = data;
1440 time_t t = time(NULL);
1441 localtime_r(&t, &value); // to fill hidden field
1443 elm_datetime_value_get(obj, &value);
1445 // Remember the time difference in before updating start time
1446 time_t start_t = mktime(&p->stm);
1447 time_t end_t = mktime(&p->etm);
1448 time_t diff = end_t - start_t;
1450 // Update start time variable
1453 Eina_Bool result =__cal_edit_ug_check_date_validity(p);
1455 // Calculate end time from start time to retain the time difference
1456 end_t = mktime(&p->stm) + diff;
1457 localtime_r(&end_t, &p->etm);
1459 // Update end time on the screen
1460 Evas_Object *end_date_obj = elm_object_part_content_get(p->end_date, "elm.icon");
1461 elm_datetime_value_set(end_date_obj, &p->etm);
1464 __cal_edit_ug_set_record_time(p, p->event);
1467 static void __cal_edit_ug_end_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1469 c_retm_if(!data, "data is null");
1470 cal_edit_ug_data *p = data;
1473 time_t t = time(NULL);
1474 localtime_r(&t, &value); // to fill hidden field
1476 elm_datetime_value_get(obj, &value);
1480 __cal_edit_ug_set_record_time(p, p->event);
1483 static void __cal_edit_ug_due_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1485 c_retm_if(!data, "data is null");
1486 cal_edit_ug_data *p = data;
1489 time_t t = time(NULL);
1490 localtime_r(&t, &value); // to fill hidden field
1492 elm_datetime_value_get(obj, &value);
1496 __cal_edit_ug_set_record_due_time(p, p->todo);
1500 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)
1504 Evas_Object *datetime = NULL;
1506 datetime = elm_object_part_content_unset(item, "elm.icon");
1508 evas_object_del(datetime);
1510 datetime = __cal_edit_ug_edit_time_icon(item, tm, is_allday);
1511 c_ret_if(!datetime);
1513 elm_object_part_content_set(item, "elm.icon", datetime);
1515 evas_object_smart_callback_add(datetime, "changed", callback, callback_data);
1518 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)
1520 c_retv_if(!p, NULL);
1521 c_retv_if(!after, NULL);
1523 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1icon", after, NULL, NULL);
1524 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1526 __cal_edit_ug_update_datetime_region(item, value, allday, callback, p);
1531 static void __cal_edit_ug_all_day_update(Evas_Object* date_obj, Eina_Bool allday)
1533 Evas_Object *edit_time_obj = elm_object_part_content_get(date_obj, "elm.icon");
1536 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1537 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1539 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1541 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1542 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1543 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1547 static void __cal_edit_ug_set_record_allday(calendar_record_h record, Eina_Bool is_allday, cal_edit_ug_data *p)
1552 if (is_allday == _calendar_is_allday_record(record))
1555 calendar_time_s start_time = {0};
1557 _calendar_get_start_time(record, &start_time);
1559 calendar_time_s end_time = {0};
1561 _calendar_get_end_time(record, &end_time);
1563 struct tm start_tm = {0};
1564 struct tm end_tm = {0};
1568 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &start_tm);
1569 cal_util_convert_lli_to_tm(NULL, end_time.time.utime, &end_tm);
1571 start_time.type = CALENDAR_TIME_LOCALTIME;
1572 end_time.type = CALENDAR_TIME_LOCALTIME;
1574 start_time.time.date.year = start_tm.tm_year + 1900;
1575 start_time.time.date.month = start_tm.tm_mon + 1;
1576 start_time.time.date.mday = start_tm.tm_mday;
1578 end_time.time.date.year = end_tm.tm_year + 1900;
1579 end_time.time.date.month = end_tm.tm_mon + 1;
1580 end_time.time.date.mday = end_tm.tm_mday;
1584 start_time.type = CALENDAR_TIME_UTIME;
1585 end_time.type = CALENDAR_TIME_UTIME;
1587 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
1588 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
1591 _calendar_set_start_time(record, &start_time);
1593 _calendar_set_end_time(record, &end_time);
1596 static void __cal_edit_ug_all_day_clicked_callback(Evas_Object *obj, void *data)
1600 c_retm_if(!data, "data is null");
1601 cal_edit_ug_data *p = data;
1603 Evas_Object *all_obj = elm_object_part_content_get(p->allday, "elm.icon");
1606 Eina_Bool is_allday = !elm_check_state_get(all_obj);
1608 elm_check_state_set(all_obj, is_allday);
1610 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1611 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1613 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1617 static void __cal_edit_ug_all_day_changed_callback(void *data, Evas_Object* obj, void *ei)
1621 c_retm_if(!data, "data is null");
1622 c_retm_if(!obj, "obj is null");
1624 cal_edit_ug_data *p = data;
1626 Eina_Bool is_allday = elm_check_state_get(obj);
1628 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1629 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1631 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1634 static void __cal_edit_ug_update_allday_language(Evas_Object *item)
1638 elm_object_part_text_set(item, "elm.text", C_("IDS_COM_BODY_ALL_DAY"));
1641 static Evas_Object *__cal_edit_ug_add_all_day(cal_edit_ug_data* p, Eina_Bool allday)
1643 c_retv_if(!p, NULL);
1645 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1text.1icon", p->timezone, __cal_edit_ug_all_day_clicked_callback, p);
1646 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1648 Evas_Object *check_obj;
1649 check_obj = elm_check_add(item);
1650 elm_check_state_set(check_obj, allday);
1651 elm_object_style_set(check_obj, "on&off");
1652 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_all_day_changed_callback, p);
1653 elm_check_state_set(check_obj, allday);
1654 evas_object_propagate_events_set(check_obj, EINA_FALSE);
1656 elm_object_part_content_set(item, "elm.icon", check_obj);
1658 __cal_edit_ug_update_allday_language(item);
1663 static void __cal_edit_ug_worldclock_ug_destroy_callback(ui_gadget_h ug, void *priv)
1667 cal_edit_ug_data* p = (cal_edit_ug_data*) priv;
1669 if (p->ug_worldclock) {
1670 ug_destroy(p->ug_worldclock);
1671 p->ug_worldclock= NULL;
1674 Elm_Object_Item* navi_item = elm_naviframe_top_item_get(p->naviframe);
1675 Evas_Object *back_btn = elm_object_item_part_content_get(navi_item, "prev_btn");
1676 if (back_btn != NULL) {
1677 elm_object_style_set(back_btn, "naviframe/back_btn/default"); /* take into effect */
1681 static void __cal_edit_ug_worldclock_ug_result_callback(ui_gadget_h ug, service_h result, void *priv)
1685 c_retm_if(!priv, "priv is null");
1686 c_retm_if(!result, "result is null");
1688 cal_edit_ug_data *p = priv;
1690 if (p->timezone_city) {
1691 free(p->timezone_city);
1692 p->timezone_city = NULL;
1695 if (p->timezone_path) {
1696 free(p->timezone_path);
1697 p->timezone_path = NULL;
1700 if (p->timezone_offset) {
1701 free(p->timezone_offset);
1702 p->timezone_offset = NULL;
1705 char *tzpath = NULL;
1707 int r = service_get_extra_data(result, "tzpath", &tzpath);
1708 c_ret_if(r != SERVICE_ERROR_NONE);
1710 p->timezone_path= tzpath;
1712 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
1714 p->is_selected_timezone = EINA_TRUE;
1717 char* timezone_text = NULL;
1718 timezone_text = g_strdup_printf("%s, %s", S_(p->timezone_city), p->timezone_offset);
1719 elm_object_part_text_set(p->timezone, "elm.text.1", timezone_text);
1720 CAL_FREE(timezone_text);
1723 static void __cal_edit_ug_worldclock_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
1727 c_retm_if(!ug, "ug is null");
1729 Evas_Object *base = ug_get_layout(ug);
1737 case UG_MODE_FULLVIEW:
1738 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1740 evas_object_show(base);
1743 DBG("Unsupported ug layout");
1749 static void __cal_edit_ug_timezone_select_callback(Evas_Object *obj, void *data)
1751 c_retm_if(!data, "data is null");
1753 cal_edit_ug_data *p = data;
1756 memset(&uc, 0, sizeof(struct ug_cbs));
1757 uc.destroy_cb = __cal_edit_ug_worldclock_ug_destroy_callback;
1758 uc.layout_cb = __cal_edit_ug_worldclock_ug_layout_callback;
1759 uc.result_cb = __cal_edit_ug_worldclock_ug_result_callback;
1762 ug = ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, NULL, &uc);
1763 p->ug_worldclock = ug;
1766 static void __cal_edit_ug_update_time_zone_language(Evas_Object *item, const char *timezone_city, const char *timezone_offset)
1768 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_TIME_ZONE"));
1770 char buffer[128] = {0};
1772 snprintf(buffer, sizeof(buffer), "%s, %s", S_(timezone_city), timezone_offset);
1774 elm_object_part_text_set(item, "elm.text.1", buffer);
1777 static Evas_Object *__cal_edit_ug_add_time_zone(cal_edit_ug_data* p)
1779 c_retv_if(!p, NULL);
1781 Evas_Object *item = __cal_edit_ug_insert_padding_after(p, NULL, p->end_date);
1782 c_retvm_if(!item, NULL, "__cal_edit_ug_insert_padding_after() is failed");
1784 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", item, __cal_edit_ug_timezone_select_callback, p);
1785 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1787 __cal_edit_ug_get_record_time_zone(p, p->event);
1789 __cal_edit_ug_update_time_zone_language(item, p->timezone_city, p->timezone_offset);
1794 static void __cal_edit_ug_alarm_changed_callback(const Cal_Reminder* reminder, void* data)
1798 c_retm_if(!data, "data is null");
1800 Evas_Object *obj = data;
1802 char* alarm_text = NULL;
1803 char buf[128] = {0};
1804 cal_reminder_get_string(reminder, buf, sizeof(buf));
1805 alarm_text = strdup(buf);
1807 elm_object_part_text_set(obj, "elm.text.1", alarm_text);
1808 CAL_FREE(alarm_text);
1810 Cal_Reminder* reminder_temp = evas_object_data_get(obj, "data");
1811 reminder_temp->alarm_value = reminder->alarm_value;
1812 reminder_temp->datetime = reminder->datetime;
1813 reminder_temp->tick_unit = reminder->tick_unit;
1816 static void __cal_edit_ug_alarm_select_callback(Evas_Object *obj, void *data)
1820 c_retm_if(!data, "data is null");
1822 cal_edit_ug_data* p = data;
1823 Cal_Reminder* reminder = (Cal_Reminder*)evas_object_data_get(obj, "data");
1824 cal_edit_alarm_type alarm_type = ALARM_TYPE_EVENT;
1826 if(p->item_type == ITEM_TYPE_EVENT)
1827 alarm_type = ALARM_TYPE_EVENT;
1828 else if(p->item_type == ITEM_TYPE_TODO && p->is_no_due_date)
1829 alarm_type = ALARM_TYPE_TODO_CUSTOM_ONLY;
1831 alarm_type = ALARM_TYPE_TODO;
1833 cal_edit_alarm_create_view(p->naviframe, reminder, alarm_type, __cal_edit_ug_alarm_changed_callback, obj);
1837 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after);
1839 static void __cal_edit_ug_delete_reminder_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
1849 static void __cal_edit_ug_alarm_plus_button_callback(void *data, Evas_Object *obj, void *event_info)
1853 c_retm_if(!data, "data is null");
1854 c_retm_if(!obj, "obj is null");
1856 cal_edit_ug_data* p = data;
1858 if (eina_list_count(p->alarm_item_list)>=4) {
1859 evas_object_del(p->alarm_plus_button);
1860 p->alarm_plus_button = NULL;
1863 Cal_Reminder* reminder = calloc(1, sizeof(Cal_Reminder));
1864 c_retm_if(!reminder, "reminder is null");
1865 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1866 reminder->datetime = p->stm;
1868 Eina_List *list = eina_list_last(p->alarm_item_list);
1869 Evas_Object *last_item = eina_list_data_get(list);
1870 __cal_edit_ug_add_alarm(p, reminder, EINA_FALSE, last_item);
1874 static Evas_Object * __cal_edit_ug_alarm_plus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1876 c_retv_if(!p, NULL);
1877 c_retv_if(!obj, NULL);
1879 Evas_Object *button = NULL;
1881 button = elm_button_add(obj);
1882 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1884 elm_object_style_set(button, "icon_plus");
1885 evas_object_propagate_events_set(button, EINA_FALSE);
1886 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_plus_button_callback, p);
1887 evas_object_show(button);
1888 p->alarm_plus_button = button;
1893 static void __cal_edit_ug_alarm_minus_button_callback(void *data, Evas_Object *obj, void *event_info)
1897 c_retm_if(!data, "data is null");
1898 c_retm_if(!obj, "obj is null");
1900 cal_edit_ug_data* p = data;
1902 if (!p->alarm_plus_button) {
1903 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
1904 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
1905 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
1908 evas_object_smart_callback_del(obj, "clicked", __cal_edit_ug_alarm_minus_button_callback);
1910 Evas_Object *parent_item = evas_object_data_get(obj, "button");
1911 p->alarm_item_list = eina_list_remove(p->alarm_item_list, parent_item);
1913 cal_dialogue_delete_item(p->dialogue, parent_item);
1914 evas_object_del(obj);
1920 static Evas_Object * __cal_edit_ug_alarm_minus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1922 c_retv_if(!p, NULL);
1923 c_retv_if(!obj, NULL);
1925 Evas_Object *button = NULL;
1927 button = elm_button_add(obj);
1928 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1930 elm_object_style_set(button, "icon_minus");
1931 evas_object_data_set(button, "button", obj);
1932 evas_object_propagate_events_set(button, EINA_FALSE);
1933 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_minus_button_callback, p);
1934 evas_object_show(button);
1939 static void __cal_edit_ug_update_reminder_language(Eina_List *item_list)
1941 c_ret_if(!item_list);
1943 Eina_List *cursor = NULL;
1944 Evas_Object *item = NULL;
1946 EINA_LIST_FOREACH(item_list, cursor, item) {
1950 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1952 Cal_Reminder *reminder = NULL;
1954 reminder = evas_object_data_get(item, "data");
1956 char buffer[128] = {0};
1957 cal_reminder_get_string(reminder, buffer, sizeof(buffer));
1959 elm_object_part_text_set(item, "elm.text.1", buffer);
1963 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after)
1965 c_retv_if(!p, NULL);
1966 Evas_Object *item = NULL;
1968 item = cal_dialogue_insert_item_after(p->dialogue, "2text.1icon.5", after, __cal_edit_ug_alarm_select_callback, p);
1969 c_retvm_if(!item, NULL, "cal_dialogue_insert_item_after() is failed");
1972 item = cal_dialogue_append_item(p->dialogue, "2text.1icon.5", __cal_edit_ug_alarm_select_callback, p);
1973 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1976 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1978 const char* alarm_text = NULL;
1979 char buf[128] = {0};
1980 cal_reminder_get_string(reminder, buf, sizeof(buf));
1981 alarm_text = strdup(buf);
1983 elm_object_part_text_set(item, "elm.text.1", alarm_text);
1984 p->alarm_item_list = eina_list_append(p->alarm_item_list, (void*)item);
1986 if(p->item_type == ITEM_TYPE_EVENT) {
1987 Evas_Object *button_obj = NULL;
1989 button_obj = __cal_edit_ug_alarm_plus_button_icon(p, item);
1991 button_obj = __cal_edit_ug_alarm_minus_button_icon(p, item);
1993 elm_object_part_content_set(item, "elm.icon", button_obj);
1996 evas_object_data_set(item, "data", reminder);
1997 evas_object_event_callback_add(item, EVAS_CALLBACK_DEL, __cal_edit_ug_delete_reminder_callback, reminder);
2002 static void __cal_edit_ug_add_multi_alarm(cal_edit_ug_data* p)
2004 c_retm_if(!p, "p is null");
2006 Cal_Reminder* reminder = NULL;
2007 reminder = calloc(1, sizeof(Cal_Reminder));
2008 c_retm_if(!reminder, "reminder is null");
2010 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
2011 reminder->datetime = p->stm;
2012 Evas_Object *after = NULL;
2013 Evas_Object *item = NULL;
2015 if(p->is_edit_mode) {
2016 if (p->item_type == ITEM_TYPE_EVENT)
2017 __cal_edit_ug_get_record_alarm(p, p->event);
2019 __cal_edit_ug_get_record_alarm(p, p->todo);
2021 if(!p->alarm_list) {
2022 reminder->tick_unit = CALENDAR_ALARM_NONE;\
2026 GList *temp = p->alarm_list;
2028 __cal_edit_ug_add_alarm(p, reminder, EINA_TRUE, NULL);
2035 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_TRUE, after);
2038 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_FALSE, after);
2040 c_retm_if(!item, "item is null");
2042 temp = g_list_next(temp);
2047 static void __cal_edit_ug_reponse_event_callback(void *data, Evas_Object *obj, void *ei)
2049 c_retm_if(!data, "data is null");
2051 Evas_Object *popup = data;
2052 evas_object_del(popup);
2055 static void __cal_edit_ug_repeat_callback(void *data)
2057 c_retm_if(!data, "data is null");
2059 cal_edit_ug_data *p = data;
2061 calendar_range_type_e range = CALENDAR_RANGE_NONE;
2062 struct tm until = {0};
2065 int repeat = cal_edit_repeat_get_repeat(p->repeat_layout, &range, &until, &count);
2067 if (CALENDAR_RECURRENCE_NONE != repeat) {
2069 if (range == CALENDAR_RANGE_UNTIL) {
2071 if (timegm(&until) <= timegm(&p->stm)) {
2072 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2073 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2077 else if (range == CALENDAR_RANGE_COUNT) {
2080 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2081 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2087 p->repeat_freq = repeat;
2088 p->repeat_range = range;
2089 p->repeat_until = until;
2090 p->repeat_count = count;
2092 char buf[1024] = {0};
2093 _cal_edit_repeat_get_freq_str(p->repeat_freq, buf, sizeof(buf));
2094 elm_object_part_text_set(p->repeat, "elm.text.1", buf);
2096 __cal_edit_ug_set_record_repeat(p);
2100 static void __cal_edit_ug_repeat_select_callback(Evas_Object *obj, void *data)
2102 c_retm_if(!data, "data is null");
2104 cal_edit_ug_data* p = data;
2106 p->repeat_layout = cal_edit_repeat_create_view(p->naviframe, p->repeat_freq, p->repeat_range, &(p->stm), &(p->repeat_until),&(p->repeat_count),
2107 (cal_edit_repeat_destroy_callback)__cal_edit_ug_repeat_callback, p);
2108 c_retm_if(!p->repeat_layout, "p->repeat_layout is null");
2112 static void __cal_edit_ug_update_recurrence_language(Evas_Object *item, int repeat_frequency)
2116 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REPEAT"));
2118 char buffer[128] = {0};
2120 _cal_edit_repeat_get_freq_str(repeat_frequency, buffer, sizeof(buffer));
2122 elm_object_part_text_set(item, "elm.text.1", buffer);
2125 static Evas_Object *__cal_edit_ug_add_repeat(cal_edit_ug_data* p)
2127 c_retv_if(!p, NULL);
2129 Eina_List *list = eina_list_last(p->alarm_item_list);
2130 Evas_Object *last_item = eina_list_data_get(list);
2132 Evas_Object *item = NULL;
2136 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, NULL, NULL);
2137 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2140 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, __cal_edit_ug_repeat_select_callback, p);
2142 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2144 __cal_edit_ug_get_record_repeat(p, p->event);
2146 __cal_edit_ug_update_recurrence_language(item, p->repeat_freq);
2151 static void __cal_edit_ug_popup_hide_callback(void *data, Evas_Object *obj, void *event_info)
2153 c_retm_if(!data, "data is null");
2154 c_retm_if(!obj, "obj is null");
2156 Evas_Object *popup = data;
2158 cal_edit_ug_data *p = evas_object_data_get(popup, "data");
2160 evas_object_del(popup);
2162 c_retm_if(!p, "p is null");
2167 static char *__cal_edit_ug_get_genlist_save_to_item_label(void *data, Evas_Object *obj, const char *part)
2169 c_retvm_if(!data, NULL, "data is null");
2170 c_retvm_if(!part, NULL, "part is null");
2172 calendar_record_h record = (calendar_record_h)data;
2177 calendar_error_e error = CALENDAR_ERROR_NONE;
2179 calendar_record_h calendar_book = NULL;
2181 _calendar_record_type record_type = _calendar_get_record_type(record);
2183 if (record_type == _CALENDAR_RECORD_TYPE_CALENDARBOOK)
2184 calendar_book = record;
2186 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &cid);
2187 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2189 error = calendar_db_get_record(_calendar_book._uri, cid, &calendar_book);
2190 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_db_get_record() is failed(%x)", error);
2193 error = calendar_record_get_int(record, _calendar_book.id, &cid);
2194 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2196 if (!CAL_STRCMP(part,"elm.text.1")) {
2198 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2199 return strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2200 else if (cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2201 return strdup(C_("IDS_TASK_BODY_MY_TASK"));
2203 error = calendar_record_get_str(calendar_book, _calendar_book.name, &name);
2204 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2206 if (record != calendar_book) {
2207 error = calendar_record_destroy(calendar_book, true);
2208 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2211 if (CAL_STRLEN(name))
2216 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2218 } else if (!CAL_STRCMP(part,"elm.text.2")) {
2220 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2221 return strdup(C_("IDS_CLD_POP_MY_PHONE"));
2223 error = calendar_record_get_str(calendar_book, _calendar_book.description, &description);
2224 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2226 if (record != calendar_book) {
2227 error = calendar_record_destroy(calendar_book, true);
2228 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2231 if (CAL_STRLEN(description))
2234 CAL_FREE(description);
2236 return strdup(S_("IDS_COM_POP_NO_ACCOUNTS"));
2239 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2242 static Evas_Object* __cal_edit_ug_add_save_to_icon(void *item_data, Evas_Object *obj, const char *part)
2246 ERR("item_data is null");
2250 Evas_Object *icon = NULL;
2251 char* icon_path = NULL;
2252 calendar_record_h record = (calendar_record_h)item_data;
2253 Eina_Bool r = EINA_FALSE;
2254 int cid = _calendar_get_calendar_index(record);
2255 int aid = _calendar_get_account_id(record);
2257 if (!CAL_STRCMP(part, "elm.icon"))
2259 icon = elm_icon_add(obj);
2263 ERR("elm_icon_add fail");
2267 if ( cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID) {
2268 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
2269 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2271 icon_path = cal_account_svc_get_account_icon_path(aid);
2273 r = elm_icon_file_set(icon, icon_path, NULL);
2274 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
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);
2286 evas_object_del(icon);
2290 evas_object_show(icon);
2296 static Eina_Bool __cal_edit_ug_popup_idler_callback(void *data)
2298 c_retv_if(!data, ECORE_CALLBACK_CANCEL);
2300 cal_edit_ug_data *p = data;
2303 evas_object_del(p->popup);
2309 return ECORE_CALLBACK_CANCEL;
2312 static void __cal_edit_ug_save_to_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2316 c_retm_if(!data, "data is null");
2317 c_retm_if(!obj, "obj is null");
2319 calendar_record_h calendar_book = data;
2320 int calendar_book_id = 0;
2322 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2323 c_retm_if(!p, "p is null");
2325 Elm_Object_Item *item = elm_genlist_selected_item_get(obj);
2326 c_retm_if(!item, "elm_genlist_selected_item_get() returned null");
2328 elm_genlist_item_selected_set(item, EINA_FALSE);
2330 calendar_error_e error = CALENDAR_ERROR_NONE;
2332 error = calendar_record_get_int(calendar_book, _calendar_book.id, &calendar_book_id);
2333 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2335 if (p->item_type == ITEM_TYPE_TODO) {
2336 __cal_edit_ug_set_record_save_to(p->todo, calendar_book_id);
2337 __cal_edit_ug_update_save_to_item(p, p->todo);
2340 __cal_edit_ug_set_record_save_to(p->event, calendar_book_id);
2341 __cal_edit_ug_update_save_to_item(p, p->event);
2345 ecore_idler_del(p->idler);
2349 p->idler = ecore_idler_add(__cal_edit_ug_popup_idler_callback, p);
2350 c_ret_if(!p->idler);
2354 static Elm_Genlist_Item_Class itc_2text_1icon_2 = {
2355 .item_style = "dialogue/2text.1icon.2",
2356 .func.text_get = __cal_edit_ug_get_genlist_save_to_item_label,
2357 .func.content_get = __cal_edit_ug_add_save_to_icon,
2360 static Evas_Object* __cal_edit_ug_create_save_to_popup(cal_edit_ug_data* p)
2362 c_retv_if(!p, NULL);
2364 Evas_Object *popup = NULL;
2365 Evas_Object *genlist = NULL;
2369 calendar_error_e error = CALENDAR_ERROR_NONE;
2371 if (!p->calendar_book_list)
2373 p->calendar_book_list = _calendar_get_calendar_book_list_with_account_id(_CALENDAR_ALL_ACCOUNT_ID);
2376 popup = cal_util_add_popup(p->window, "liststyle", C_("IDS_ST_BODY_SAVE_TO"), NULL,
2377 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2378 c_retvm_if(!popup, NULL, "popup is null");
2380 genlist = elm_genlist_add(popup);
2382 ERR("elm_genlist_add(popup) returned null");
2383 evas_object_del(popup);
2387 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2388 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2389 evas_object_data_set(genlist, "priv", p);
2391 calendar_record_h calendar_book = NULL;
2393 EINA_LIST_FOREACH(p->calendar_book_list, l, calendar_book) {
2397 error = calendar_record_get_int(calendar_book, _calendar_book.store_type, &store_type);
2398 if (error != CALENDAR_ERROR_NONE) {
2399 ERR("calendar_record_get_int() is failed(%x)", calendar_book);
2404 error = calendar_record_get_int(calendar_book, _calendar_book.sync_event, &sync_event);
2405 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2409 if (p->item_type == ITEM_TYPE_TODO) {
2410 if (store_type == CALENDAR_BOOK_TYPE_TODO)
2411 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);
2413 if (store_type == CALENDAR_BOOK_TYPE_EVENT)
2414 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);
2419 elm_object_content_set(popup, genlist);
2420 evas_object_show(genlist);
2425 static void __cal_edit_ug_saveto_select_callback(Evas_Object *obj, void *data)
2427 c_retm_if(!data, "data is null");
2429 cal_edit_ug_data* p = data;
2430 Evas_Object *popup = __cal_edit_ug_create_save_to_popup(p);
2431 c_retm_if(!popup, "popup is NULL");
2436 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz)
2438 calendar_record_h calendar_book = NULL;
2441 calendar_error_e error = CALENDAR_ERROR_NONE;
2443 error = calendar_db_get_record(_calendar_book._uri, calid, &calendar_book);
2444 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
2446 if (calid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2447 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
2450 error = calendar_record_get_str(calendar_book, _calendar_book.name, &str);
2451 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
2455 snprintf(buf, sz, "%s", str);
2460 error = calendar_record_destroy(calendar_book, true);
2461 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2464 static void __cal_edit_ug_update_saveto_language(Evas_Object *item, calendar_record_h record)
2468 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2470 int calendar_book_id = _calendar_get_calendar_index(record);
2472 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2473 elm_object_part_text_set(item, "elm.text.1", C_("IDS_CLD_BODY_MY_CALENDAR"));
2474 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2475 elm_object_part_text_set(item, "elm.text.1", C_("IDS_TASK_BODY_MY_TASK"));
2478 static Evas_Object *__cal_edit_ug_add_saveto(cal_edit_ug_data* p)
2480 c_retv_if(!p, NULL);
2482 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "2text.2", __cal_edit_ug_saveto_select_callback, p);
2483 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2485 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2488 char* saveto_text = NULL;
2489 int calendar_book_id = 0;
2490 if(p->item_type == ITEM_TYPE_TODO) {
2491 calendar_book_id = _calendar_get_calendar_index(p->todo);
2492 p->account_id = _calendar_get_account_id(p->todo);
2495 calendar_book_id = _calendar_get_calendar_index(p->event);
2496 p->account_id = _calendar_get_account_id(p->event);
2498 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2499 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2500 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2501 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
2503 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
2504 saveto_text = strdup(buf);
2507 elm_object_part_text_set(item, "elm.text.1", saveto_text);
2508 CAL_FREE(saveto_text);
2511 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2516 static void __cal_edit_ug_no_due_date_clicked_callback(Evas_Object *obj, void *data)
2518 c_retm_if(!data, "data is NULL.");
2519 c_retm_if(!obj, "obj is NULL.");
2521 cal_edit_ug_data *p = data;
2523 Evas_Object *check_obj = elm_object_part_content_get(p->no_due_date, "elm.icon");
2525 if(p->is_no_due_date)
2527 elm_check_state_set(check_obj, EINA_FALSE);
2528 p->is_no_due_date = elm_check_state_get(check_obj);
2529 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2533 elm_check_state_set(check_obj, EINA_TRUE);
2534 p->is_no_due_date = elm_check_state_get(check_obj);
2535 __cal_edit_ug_set_record_due_time(p, p->todo);
2536 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2539 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2540 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2543 static void __cal_edit_ug_no_due_date_changed_callback(void *data, Evas_Object *obj, void *ei)
2545 c_retm_if(!data, "data is NULL.");
2546 c_retm_if(!obj, "obj is NULL.");
2548 cal_edit_ug_data *p = data;
2550 p->is_no_due_date = elm_check_state_get(obj);
2552 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2553 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2554 if(p->is_no_due_date)
2556 __cal_edit_ug_set_record_due_time(p, p->todo);
2557 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2561 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2565 static void __cal_edit_ug_update_no_due_date_language(Evas_Object *item)
2567 elm_object_part_text_set(item, "elm.text", C_("IDS_TASK_MBODY_NO_DUE_DATE"));
2570 static Evas_Object *__cal_edit_ug_add_no_due_date(cal_edit_ug_data* p)
2572 c_retv_if(!p, NULL);
2574 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);
2575 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2577 Evas_Object *check_obj;
2578 check_obj = elm_check_add(item);
2579 __cal_edit_ug_get_record_due_time(p, p->todo);
2580 elm_check_state_set(check_obj, p->is_no_due_date);
2582 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_no_due_date_changed_callback, p);
2583 elm_check_state_set(check_obj, p->is_no_due_date);
2584 evas_object_propagate_events_set(check_obj, EINA_FALSE);
2586 __cal_edit_ug_update_no_due_date_language(item);
2588 elm_object_part_content_set(item, "elm.icon", check_obj);
2593 static void __cal_edit_ug_priority_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2598 int priority = (int)data;
2600 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2603 __cal_edit_ug_set_record_priority(p->todo, priority);
2604 __cal_edit_ug_update_priority_item(p, p->todo);
2606 evas_object_del(p->popup);
2610 static Evas_Object* __cal_edit_ug_create_priority_popup(cal_edit_ug_data* p)
2612 c_retv_if(!p, NULL);
2614 Evas_Object *popup = cal_util_add_popup(p->window, NULL, C_("IDS_CLD_BODY_PRIORITY"), NULL,
2615 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2616 c_retv_if(!popup, NULL);
2618 evas_object_data_set(popup, "priv", p);
2620 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);
2621 c_retv_if(!popup_item, NULL);
2623 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);
2624 c_retv_if(!popup_item, NULL);
2626 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);
2627 c_retv_if(!popup_item, NULL);
2632 static void __cal_edit_ug_priority_select_callback(Evas_Object *obj, void *data)
2634 c_retm_if(!data, "data is null");
2635 cal_edit_ug_data* p = data;
2637 Evas_Object *popup = __cal_edit_ug_create_priority_popup(p);
2638 c_retm_if(!popup, "popup is NULL");
2644 static void __cal_edit_ug_update_priority_language(Evas_Object *item, calendar_record_h record)
2646 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_PRIORITY"));
2648 char* priority_text = NULL;
2649 int priority = __cal_edit_ug_get_record_priority(record);
2651 case CALENDAR_TODO_PRIORITY_LOW:
2652 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
2654 case CALENDAR_TODO_PRIORITY_NORMAL:
2655 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
2657 case CALENDAR_TODO_PRIORITY_HIGH:
2658 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
2664 elm_object_part_text_set(item, "elm.text.1", priority_text);
2665 CAL_FREE(priority_text);
2668 static Evas_Object *__cal_edit_ug_add_priority(cal_edit_ug_data* p)
2670 c_retv_if(!p, NULL);
2672 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", p->no_due_date, __cal_edit_ug_priority_select_callback, p);
2673 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2675 __cal_edit_ug_update_priority_language(item, p->todo);
2680 static void __cal_edit_ug_show_result_popup(cal_edit_ug_data *p, calendar_error_e error)
2686 case CALENDAR_ERROR_DB_FAILED:
2687 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2688 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2691 case CALENDAR_ERROR_OUT_OF_MEMORY:
2692 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2693 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2696 case CALENDAR_ERROR_INVALID_PARAMETER:
2697 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_INVALID_TIME"),
2698 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2702 snprintf(buf,100,"not saved(internal error-%x)!",error);
2703 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), buf,
2704 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2709 int __cal_edit_ug_save(cal_edit_ug_data *p, calendar_record_h record)
2713 calendar_error_e error = CALENDAR_ERROR_NONE;
2715 int record_index = 0;
2717 calendar_record_type_e record_type = CALENDAR_RECORD_TYPE_EVENT;
2719 if (_calendar_is_task_record(record))
2720 record_type = CALENDAR_RECORD_TYPE_TODO;
2722 __cal_edit_ug_set_record_alarm(p, record);
2724 if (p->is_edit_mode) {
2727 calendar_record_h exception_record = NULL;
2728 error = calendar_record_clone(record, &exception_record);
2729 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
2731 int index = _calendar_get_record_index(record);
2732 error = calendar_record_set_int(exception_record, _calendar_event.original_event_id, index);
2733 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
2735 __cal_edit_ug_set_record_time(p, exception_record);
2736 _calendar_edit_recurrence_instance(exception_record, index);
2738 error = calendar_db_insert_record(exception_record, &record_index);
2739 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_insert_record() is failed(%x)", error);
2741 if (error != CALENDAR_ERROR_NONE) {
2742 __cal_edit_ug_show_result_popup(p, error);
2744 error = calendar_record_destroy(exception_record, true);
2745 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2750 error = calendar_record_destroy(exception_record, true);
2751 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2755 if (p->account_id == _calendar_get_account_id(record))
2757 error = calendar_db_update_record(record);
2758 if (error != CALENDAR_ERROR_NONE) {
2760 ERR("calendar_db_update_record() is failed(%x)", error);
2762 __cal_edit_ug_show_result_popup(p, error);
2766 record_index = _calendar_get_record_index(record);
2770 _calendar_delete_record(record);
2772 error = calendar_db_insert_record(record, &record_index);
2773 if (error != CALENDAR_ERROR_NONE) {
2775 ERR("calendar_db_insert_record() is failed(%x)", error);
2776 __cal_edit_ug_show_result_popup(p, error);
2785 error = calendar_db_insert_record(record, &record_index);
2786 if (error != CALENDAR_ERROR_NONE) {
2788 ERR("calendar_db_insert_record() is failed(%x)", error);
2790 __cal_edit_ug_show_result_popup(p, error);
2796 return record_index;
2799 static void __cal_edit_ug_send_result_to_detail_ug(cal_edit_ug_data *p, int record_index)
2801 c_retm_if(!p, "p is null");
2802 c_retm_if(record_index < 0, "record_index < 0");
2804 service_h service = NULL;
2806 int ret = service_create(&service);
2807 c_ret_if(ret != SERVICE_ERROR_NONE);
2809 char value[64] = {0};
2810 snprintf(value, sizeof(value), "%d", record_index);
2812 ret = service_add_extra_data(service, "record_index", value);
2813 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2815 memset(value, 0x00, sizeof(value));
2817 long long int lli_time = 0;
2818 cal_util_convert_tm_to_lli(NULL, &p->stm, &lli_time);
2820 snprintf(value, sizeof(value), "%lli", lli_time);
2822 ret = service_add_extra_data(service, "base_time", value);
2823 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2825 ug_send_result(p->ug, service);
2827 ret = service_destroy(service);
2828 c_warn_if(ret != SERVICE_ERROR_NONE, "service_destroy() is failed(%x)", ret);
2831 static void __cal_edit_ug_save_button_callback(void *data, Evas_Object *obj, void *event_info)
2835 c_retm_if(!data, "data is null");
2836 cal_edit_ug_data* p = data;
2839 Eina_Bool result = __cal_edit_ug_check_date_validity(p);
2841 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_END_TIME_SHOULD_BE_SET_AFTER_START_TIME"),
2842 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2846 if (p->item_type == ITEM_TYPE_TODO)
2847 record_index = __cal_edit_ug_save(p, p->todo);
2849 record_index = __cal_edit_ug_save(p, p->event);
2851 c_retm_if(record_index < 0, "cal_edit_save() is failed");
2853 __cal_edit_ug_send_result_to_detail_ug(p, record_index);
2855 ug_destroy_me(p->ug);
2860 static void __cal_edit_ug_back_button_callback(void *user_data, Evas_Object *obj, void *ei)
2864 c_ret_if(!user_data);
2866 cal_edit_ug_data *data = user_data;
2868 c_ret_if(!data->ug);
2870 ug_destroy_me(data->ug);
2873 static void __cal_edit_ug_show_multi_alarms (cal_edit_ug_data *p)
2875 c_retm_if(!p, "p is null");
2877 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2879 if(eina_list_count(p->alarm_item_list)<5){
2880 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
2881 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
2883 Eina_List *list = eina_list_next(p->alarm_item_list);
2885 Evas_Object *item = NULL;
2887 EINA_LIST_FOREACH(list, l, item) {
2889 cal_dialogue_show_item_after(p->dialogue, item, first_item);
2895 static void __cal_edit_ug_show_event_items (cal_edit_ug_data *p)
2897 c_retm_if(!p, "p is null");
2899 if (!p->start_date_title)
2900 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
2902 cal_dialogue_show_item_after(p->dialogue, p->start_date_title, p->title);
2904 Eina_Bool is_allday = EINA_FALSE;
2906 if (!p->start_date) {
2908 is_allday = _calendar_is_allday_record(p->event);
2910 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);
2913 cal_dialogue_show_item_after(p->dialogue, p->start_date, p->start_date_title);
2915 if (!p->end_date_title)
2916 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
2918 cal_dialogue_show_item_after(p->dialogue, p->end_date_title, p->start_date);
2921 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);
2923 cal_dialogue_show_item_after(p->dialogue, p->end_date, p->end_date_title);
2926 p->timezone = __cal_edit_ug_add_time_zone(p);
2928 cal_dialogue_show_item_after(p->dialogue, p->timezone, p->end_date);
2931 p->allday = __cal_edit_ug_add_all_day(p, is_allday);
2933 cal_dialogue_show_item_after(p->dialogue, p->allday, p->timezone);
2935 __cal_edit_ug_show_multi_alarms(p);
2937 Eina_List *list = eina_list_last(p->alarm_item_list);
2938 Evas_Object *last_item = eina_list_data_get(list);
2941 p->repeat = __cal_edit_ug_add_repeat(p);
2943 cal_dialogue_show_item_after(p->dialogue, p->repeat, last_item);
2947 static void __cal_edit_ug_show_todo_items (cal_edit_ug_data *p)
2949 c_retm_if(!p, "p is null");
2951 if (!p->due_date_title)
2952 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
2954 cal_dialogue_show_item_after(p->dialogue, p->due_date_title, p->title);
2957 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);
2959 cal_dialogue_show_item_after(p->dialogue, p->due_date, p->due_date_title);
2961 if (!p->no_due_date)
2962 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
2964 cal_dialogue_show_item_after(p->dialogue, p->no_due_date, p->due_date);
2966 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2968 p->priority = __cal_edit_ug_add_priority(p);
2970 cal_dialogue_show_item_after(p->dialogue, p->priority, first_item);
2973 static void __cal_edit_ug_hide_multi_alarms (cal_edit_ug_data *p)
2975 c_retm_if(!p, "p is null");
2977 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2978 Evas_Object *button_obj = elm_object_part_content_get(first_item, "elm.icon");
2980 evas_object_del(button_obj);
2984 Eina_List *list = p->alarm_item_list;
2985 list = eina_list_next(list);
2987 Evas_Object *item = NULL;
2989 EINA_LIST_FOREACH(list, l, item) {
2991 cal_dialogue_hide_item(p->dialogue, item);
2996 static void __cal_edit_ug_hide_event_items (cal_edit_ug_data *p)
2998 c_retm_if(!p, "p is null");
3000 cal_dialogue_hide_item(p->dialogue, p->start_date_title);
3001 cal_dialogue_hide_item(p->dialogue, p->start_date);
3002 cal_dialogue_hide_item(p->dialogue, p->end_date_title);
3003 cal_dialogue_hide_item(p->dialogue, p->end_date);
3004 cal_dialogue_hide_item(p->dialogue, p->allday);
3005 cal_dialogue_hide_item(p->dialogue, p->timezone);
3006 cal_dialogue_hide_item(p->dialogue, p->repeat);
3007 __cal_edit_ug_hide_multi_alarms(p);
3011 static void __cal_edit_ug_hide_todo_items (cal_edit_ug_data *p)
3013 c_retm_if(!p, "p is null");
3015 cal_dialogue_hide_item(p->dialogue, p->due_date_title);
3016 cal_dialogue_hide_item(p->dialogue, p->due_date);
3017 cal_dialogue_hide_item(p->dialogue, p->no_due_date);
3018 cal_dialogue_hide_item(p->dialogue, p->priority);
3022 static void __cal_edit_ug_update_event_info (cal_edit_ug_data *p)
3024 c_retm_if(!p, "p is null");
3026 __cal_edit_ug_update_title_item(p->title_entry, p->event);
3027 __cal_edit_ug_update_note_item(p->note_entry, p->event);
3028 __cal_edit_ug_update_location_item(p, p->event);
3030 __cal_edit_ug_update_save_to_item(p, p->event);
3033 static void __cal_edit_ug_update_todo_info (cal_edit_ug_data *p)
3035 c_retm_if(!p, "p is null");
3037 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
3038 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
3039 __cal_edit_ug_update_location_item(p, p->todo);
3041 __cal_edit_ug_update_save_to_item(p, p->todo);
3045 static void __cal_edit_ug_new_event_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3049 c_retm_if(!data, "data null");
3051 cal_edit_ug_data *p = data;
3053 if(p->item_type == ITEM_TYPE_EVENT)
3056 p->item_type = ITEM_TYPE_EVENT;
3058 __cal_edit_ug_hide_todo_items(p);
3059 __cal_edit_ug_show_event_items(p);
3060 __cal_edit_ug_update_event_info(p);
3064 static void __cal_edit_ug_new_todo_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3068 c_retm_if(!data, "data null");
3070 cal_edit_ug_data *p = data;
3072 if(p->item_type == ITEM_TYPE_TODO)
3075 p->item_type = ITEM_TYPE_TODO;
3077 __cal_edit_ug_hide_event_items(p);
3078 __cal_edit_ug_show_todo_items(p);
3079 __cal_edit_ug_update_todo_info(p);
3083 static void __cal_edit_ug_add_dialogue_items(cal_edit_ug_data *p)
3087 c_retm_if(!p, "p is null");
3089 p->title = __cal_edit_ug_add_title(p);
3091 calendar_time_s time = {0};
3093 if (p->item_type == ITEM_TYPE_TODO) {
3095 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
3097 _calendar_get_end_time(p->todo, &time);
3098 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3099 // __cal_edit_ug_get_record_due_time(p, p->todo);
3101 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);
3103 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3105 p->priority = __cal_edit_ug_add_priority(p);
3108 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
3111 _calendar_get_start_time(p->instance, &time);
3113 _calendar_get_start_time(p->event, &time);
3115 _calendar_convert_calendar_time_to_tm(&time, &p->stm);
3116 Eina_Bool allday = _calendar_is_allday_record(p->event);
3118 p->start_date = __cal_edit_ug_insert_timepicker_after(p, &p->stm, allday, p->start_date_title, __cal_edit_ug_start_date_changed_callback);
3120 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
3123 _calendar_get_end_time(p->instance, &time);
3125 _calendar_get_end_time(p->event, &time);
3127 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3128 p->end_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, allday, p->end_date_title, __cal_edit_ug_end_date_changed_callback);
3130 p->timezone = __cal_edit_ug_add_time_zone(p);
3132 p->allday = __cal_edit_ug_add_all_day(p, allday);
3136 p->note = __cal_edit_ug_add_note(p);
3138 p->location = __cal_edit_ug_add_location(p);
3140 __cal_edit_ug_add_multi_alarm(p);
3142 if (p->item_type == ITEM_TYPE_EVENT) {
3143 p->repeat = __cal_edit_ug_add_repeat(p);
3146 p->saveto = __cal_edit_ug_add_saveto(p);
3149 static void __cal_edit_ug_update_naviframe_language(cal_edit_ug_data *data)
3151 c_ret_if(!data->naviframe);
3153 Elm_Object_Item *item = elm_naviframe_top_item_get(data->naviframe);
3156 if (data->is_edit_mode) {
3158 if (data->item_type == ITEM_TYPE_TODO)
3159 elm_object_item_part_text_set(item, "default", C_("IDS_TASK_HEADER_EDIT_TASK"));
3161 elm_object_item_part_text_set(item, "default", C_("IDS_CLD_HEADER_EDIT_EVENT"));
3164 elm_object_item_part_text_set(item, "default", S_("IDS_COM_BODY_CREATE"));
3167 static void __cal_edit_ug_update_tabbar_language(cal_edit_ug_data *data)
3169 if (data->is_edit_mode)
3172 c_ret_if(!data->event_item);
3173 c_ret_if(!data->todo_item);
3175 elm_object_item_part_text_set(data->event_item, "default", C_("IDS_CLD_SK3_CREATE_EVENT"));
3176 elm_object_item_part_text_set(data->todo_item, "default", C_("IDS_TASK_SK_CREATE_TASK"));
3179 static void __cal_edit_ug_add_toolbar(cal_edit_ug_data *data, Evas_Object *scroller)
3183 c_retm_if(!data, "data is null");
3185 Elm_Object_Item *navi_item = NULL;
3187 if (data->is_edit_mode) {
3188 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, NULL);
3189 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3191 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, "tabbar");
3192 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3194 data->tabbar = elm_toolbar_add(data->naviframe);
3195 c_ret_if(!data->tabbar);
3197 elm_object_item_part_content_set(navi_item, "tabbar", data->tabbar);
3198 elm_toolbar_reorder_mode_set(data->tabbar, EINA_FALSE);
3199 elm_toolbar_transverse_expanded_set(data->tabbar, EINA_TRUE);
3200 elm_toolbar_shrink_mode_set(data->tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
3201 elm_object_style_set(data->tabbar, "tabbar");
3203 if (data->item_type == ITEM_TYPE_TODO) {
3204 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3206 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3208 data->event_item = elm_toolbar_item_insert_before(data->tabbar, data->todo_item, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3210 data->event_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3211 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3213 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3216 if (data->item_type == ITEM_TYPE_TODO)
3217 elm_toolbar_item_selected_set(data->todo_item, EINA_TRUE);
3219 elm_toolbar_item_selected_set(data->event_item, EINA_TRUE);
3221 __cal_edit_ug_update_tabbar_language(data);
3225 __cal_edit_ug_update_naviframe_language(data);
3227 data->save_cancel = cal_save_cancel_create(data->naviframe, NULL, __cal_edit_ug_save_button_callback, __cal_edit_ug_back_button_callback, data);
3231 static void __cal_edit_ug_dialogue_item_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
3236 cal_edit_ug_data* p = data;
3239 static Evas_Object *__cal_edit_ug_create_dialogue(Evas_Object *parent, cal_edit_ug_data* p)
3241 c_retv_if(!p, NULL);
3243 Evas_Object *scroller = cal_dialogue_create(parent);
3244 c_retvm_if(!scroller, NULL, "cal_dialogue_create() is failed");
3245 __cal_edit_ug_add_toolbar(p, scroller);
3247 Evas_Object *dialogue = cal_dialogue_get_box(scroller);
3249 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_UP, __cal_edit_ug_dialogue_item_clicked_callback, p);
3250 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_DOWN, __cal_edit_ug_dialogue_item_clicked_callback, p);
3251 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_MOVE, __cal_edit_ug_dialogue_item_clicked_callback, p);
3257 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, cal_edit_ug_data *data)
3261 c_retv_if(!parent, NULL);
3262 c_retv_if(!data, NULL);
3264 data->parent = parent;
3266 if (data->item_type == ITEM_TYPE_TODO)
3267 data->todo = data->record;
3269 data->event = data->record;
3271 if(!data->is_edit_mode)
3273 __cal_edit_ug_initialize_todo_record(data);
3274 __cal_edit_ug_initialize_event_record(data);
3277 Evas_Object *base_layout = cal_util_add_layout(parent, NULL);
3278 c_retv_if(!base_layout, NULL);
3280 Evas_Object *naviframe = elm_naviframe_add(base_layout);
3282 ERR("elm_naviframe_add() is failed");
3284 evas_object_del(base_layout);
3289 evas_object_show(naviframe);
3291 Evas_Object *bg = cal_util_add_bg(base_layout, EINA_FALSE);
3293 ERR("cal_util_add_bg() is failed");
3295 evas_object_del(base_layout);
3300 data->base_layout = base_layout;
3301 data->naviframe = naviframe;
3303 cal_util_initialize_timezone();
3305 data->dialogue = __cal_edit_ug_create_dialogue(naviframe, data);
3306 c_warn_if(!data->dialogue, "__cal_edit_ug_create_dialogue() is failed");
3308 __cal_edit_ug_add_dialogue_items(data);
3311 elm_object_part_content_set(base_layout, "elm.swallow.content", naviframe);
3312 elm_object_part_content_set(base_layout, "elm.swallow.bg", bg);
3317 static calendar_record_h inline __cal_edit_ug_get_origin_record(const calendar_record_h instance)
3321 c_retv_if(!instance, NULL);
3323 int index = _calendar_get_record_index(instance);
3325 return _calendar_get_record_with_index(index);
3328 static void *__cal_edit_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
3332 c_retv_if(!ug, NULL);
3333 c_retv_if(!service, NULL);
3334 c_retv_if(!priv, NULL);
3335 c_retv_if(mode != UG_MODE_FULLVIEW, NULL);
3337 cal_edit_ug_data *data = priv;
3342 char *item_type = NULL;
3345 calendar_error_e error = CALENDAR_ERROR_NONE;
3347 int r = service_get_extra_data(service, "index", &index);
3349 if (r == SERVICE_ERROR_NONE)
3352 r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
3353 if (r == SERVICE_ERROR_NONE) {
3355 if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_EVENT)) {
3356 data->item_type = ITEM_TYPE_EVENT;
3357 data->is_edit_mode = EINA_TRUE;
3359 r = service_get_extra_data(service, CAL_APPCONTROL_EVENT_ID, &index);
3360 if (r != SERVICE_ERROR_NONE) {
3361 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_EVENT_ID, r);
3371 calendar_record_h record = _calendar_get_record_with_index(cid);
3372 c_retv_if(!record, NULL);
3374 calendar_record_destroy(record, true);
3376 } else if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_TODO)) {
3378 data->item_type = ITEM_TYPE_TODO;
3379 data->is_edit_mode = EINA_TRUE;
3381 r = service_get_extra_data(service, CAL_APPCONTROL_TODO_ID, &index);
3382 if (r != SERVICE_ERROR_NONE) {
3383 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_TODO_ID, r);
3393 calendar_record_h record = _calendar_get_record_with_index(cid);
3394 c_retv_if(!record, NULL);
3396 calendar_record_destroy(record, true);
3399 else if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_VCS)) {
3401 data->item_type = ITEM_TYPE_VCS;
3403 r = service_get_extra_data(service, CAL_APPCONTROL_VCS_PATH, &path);
3404 if (r != SERVICE_ERROR_NONE) {
3405 ERR("service_get_extra_data(%s) is failed(%x)", CAL_APPCONTROL_VCS_PATH, r);
3414 FILE * file = fopen(path, "r");
3416 ERR("fopen(%s) is failed.", path);
3424 if (stat(path, &st) != 0) {
3425 ERR("Getting file information Error!");
3433 int size = st.st_size;
3434 char *raw_data = calloc(size + 1, sizeof(char));
3436 ERR("raw_data is NULL!");
3445 r = fread(raw_data, 1, size, file);
3447 c_retv_if(r < 0, NULL);
3449 calendar_list_h list = NULL;
3451 error = calendar_vcalendar_parse_to_calendar(raw_data, &list);
3452 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_parse_to_calendar() is failed(%x)", error);
3455 calendar_record_h record = NULL;
3456 error = calendar_list_get_current_record_p(list, &record);
3457 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
3459 error = calendar_record_clone(record, &data->record);
3460 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
3462 error = calendar_list_destroy(list, true);
3469 if (!data->record) {
3471 data->is_edit_mode = EINA_TRUE;
3472 data->record = _calendar_get_record_with_index(cid);
3475 data->is_edit_mode = EINA_FALSE;
3476 char *record_address = NULL;
3478 r = service_get_extra_data(service, "record", &record_address);
3480 data->record = (calendar_record_h)strtoul(record_address, NULL, 16);
3481 c_warn_if(!data->record, "strtol(%s, NULL, 16) is failed", record_address);
3484 char *note_str = NULL;
3485 r = service_get_extra_data(service, "note", ¬e_str);
3488 calendar_record_h record = NULL;
3489 calendar_error_e error = CALENDAR_ERROR_NONE;
3490 error = calendar_record_create(_calendar_event._uri, &record);
3491 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
3493 data->record = record;
3494 __cal_edit_ug_set_record_note(data->record, note_str);
3496 time_t now = time(NULL);
3497 localtime_r(&now, &data->base_time);
3503 int index = _calendar_get_record_index(data->record);
3505 data->is_edit_mode = EINA_TRUE;
3507 _calendar_record_type record_type = _calendar_get_record_type(data->record);
3508 ERR("record_type=%d", record_type);
3510 if (record_type != _CALENDAR_RECORD_TYPE_EVENT && record_type != _CALENDAR_RECORD_TYPE_TODO && record_type != _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR) {
3511 data->instance = data->record;
3512 data->record = __cal_edit_ug_get_origin_record(data->instance);
3516 CAL_FREE(record_address);
3519 if (_calendar_is_task_record(data->record))
3520 data->item_type = ITEM_TYPE_TODO;
3522 data->item_type = ITEM_TYPE_EVENT;
3527 char *base_time = NULL;
3528 r = service_get_extra_data(service, "base_time", &base_time);
3529 c_warn_if(SERVICE_ERROR_NONE != r,"service_get_extra_data is failed(%d).", r);
3532 long long int lli_time = strtoll(base_time, NULL, 10);
3533 cal_util_convert_lli_to_tm(NULL, lli_time, &data->base_time);
3534 CAL_FREE(base_time);
3537 if (error != CALENDAR_ERROR_NONE || data->item_type == ITEM_TYPE_UNKNOWN) {
3538 ERR("ERROR!! Invaild parameter!!");
3542 CAL_FREE(item_type);
3548 Evas_Object *parent = ug_get_parent_layout(ug);
3549 c_retv_if(!parent, NULL);
3551 data->window = ug_get_window();
3552 c_retv_if(!data->window, NULL);
3554 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme.edj");
3555 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme2.edj");
3557 Evas_Object *base = __cal_edit_ug_create_layout(parent, data);
3558 c_retv_if(!base, NULL);
3563 static void __cal_edit_ug_destroy_callback(ui_gadget_h ug, service_h service, void *priv)
3568 cal_edit_ug_data *data = priv;
3570 cal_util_delete_evas_object(&data->base_layout);
3572 if (data->timezone_city)
3573 free(data->timezone_city);
3574 if (data->timezone_path)
3575 free(data->timezone_path);
3576 if (data->timezone_offset)
3577 free(data->timezone_offset);
3579 _calendar_free_record_list(&data->calendar_book_list);
3581 if (data->alarm_list) {
3582 g_list_free(data->alarm_list);
3583 data->alarm_list = NULL;
3586 if (data->alarm_item_list) {
3587 eina_list_free(data->alarm_item_list);
3588 data->alarm_item_list = NULL;
3591 CAL_FREE(data->title_str);
3592 CAL_FREE(data->address);
3593 CAL_FREE(data->note_str);
3595 if (data->save_cancel)
3596 cal_save_cancel_destroy(data->save_cancel);
3599 evas_object_del(data->tabbar);
3602 calendar_record_destroy(data->event, true);
3605 calendar_record_destroy(data->todo, true);
3608 calendar_record_destroy(data->instance, true);
3612 static void __cal_edit_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
3616 DBG("UG: key event %d", evt);
3619 case UG_KEY_EVENT_END:
3627 static void __cal_edit_ug_update_language(cal_edit_ug_data *data)
3631 __cal_edit_ug_update_naviframe_language(data);
3633 __cal_edit_ug_update_tabbar_language(data);
3635 cal_save_cancel_set_button_text(data->save_cancel, S_("IDS_COM_OPT_SAVE"), NULL);
3637 __cal_edit_ug_update_title_language(data->title);
3639 if (data->item_type == ITEM_TYPE_EVENT) {
3641 __cal_edit_ug_update_start_language(data->start_date_title);
3643 __cal_edit_ug_update_end_language(data->end_date_title);
3645 __cal_edit_ug_update_due_language(data->due_date_title);
3647 __cal_edit_ug_update_time_zone_language(data->timezone, data->timezone_city, data->timezone_offset);
3649 if (data->item_type == ITEM_TYPE_TODO) {
3651 __cal_edit_ug_update_no_due_date_language(data->no_due_date);
3653 __cal_edit_ug_update_priority_language(data->priority, data->todo);
3656 if (data->item_type == ITEM_TYPE_EVENT)
3657 __cal_edit_ug_update_allday_language(data->allday);
3659 __cal_edit_ug_update_description_language(data->note);
3661 __cal_edit_ug_update_location_language(data->location);
3663 __cal_edit_ug_update_reminder_language(data->alarm_item_list);
3665 if (data->item_type == ITEM_TYPE_EVENT)
3666 __cal_edit_ug_update_recurrence_language(data->repeat, data->repeat_freq);
3668 if (data->item_type == ITEM_TYPE_EVENT)
3669 __cal_edit_ug_update_saveto_language(data->saveto, data->event);
3671 __cal_edit_ug_update_saveto_language(data->saveto, data->todo);
3674 static void __cal_edit_ug_update_region(cal_edit_ug_data *data)
3678 if (data->item_type == ITEM_TYPE_EVENT) {
3680 Eina_Bool is_allday = _calendar_is_allday_record(data->event);
3682 __cal_edit_ug_update_datetime_region(data->start_date, &data->stm, is_allday, __cal_edit_ug_start_date_changed_callback, data);
3684 __cal_edit_ug_update_datetime_region(data->end_date, &data->etm, is_allday, __cal_edit_ug_end_date_changed_callback, data);
3687 __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);
3690 static void __cal_edit_ug_event_callback(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
3696 case UG_EVENT_LANG_CHANGE:
3697 __cal_edit_ug_update_language((cal_edit_ug_data *)priv);
3699 case UG_EVENT_REGION_CHANGE:
3700 __cal_edit_ug_update_region((cal_edit_ug_data *)priv);
3707 API int UG_MODULE_INIT(struct ug_module_ops *ops)
3711 c_retv_if(!ops, -1);
3713 cal_edit_ug_data *data = calloc(1, sizeof(cal_edit_ug_data));
3715 ops->create = __cal_edit_ug_create_callback;
3716 ops->destroy = __cal_edit_ug_destroy_callback;
3717 ops->key_event = __cal_edit_ug_key_callback;
3718 ops->event = __cal_edit_ug_event_callback;
3720 ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
3722 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
3723 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
3725 __cal_edit_ug_initialize(data);
3730 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
3736 cal_edit_ug_data *data = ops->priv;
3738 __cal_edit_ug_finish(data);