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"
33 #include "appcontrol.h"
35 #define INVALID_TIMEZONE_VALUE (100)
36 #define CAL_EDIT_UG_MAX_ATTACHMENT_COUNT 6
43 cal_appcontrol_item_type item_type;
46 Evas_Object *base_layout;
47 Evas_Object *naviframe;
49 Evas_Object *conformant;
55 calendar_record_h event;
56 calendar_record_h todo;
57 calendar_record_h record;
58 calendar_record_h instance;
60 Eina_Bool is_edit_mode;
62 Evas_Object *dialogue;
64 Evas_Object *title_entry;
66 Evas_Object *start_date;
67 Evas_Object *start_date_title;
68 Evas_Object *end_date;
69 Evas_Object *end_date_title;
71 Evas_Object *timezone;
72 Evas_Object *location;
73 Evas_Object *location_entry;
76 Evas_Object *note_entry;
77 Eina_List *alarm_item_list;
78 Evas_Object *alarm_plus_button;
81 Evas_Object *repeat_layout;
85 Evas_Object *multibuttonentry; // entry participants
87 Evas_Object *due_date;
88 Evas_Object *due_date_title;
89 Evas_Object *no_due_date;
90 Evas_Object *priority;
92 cal_save_cancel_h save_cancel;
95 int repeat_freq; // repeat_freq off, daily, ...
96 calendar_range_type_e repeat_range;
98 struct tm repeat_until;
104 ui_gadget_h ug_worldclock;
106 Eina_Bool is_selected_timezone;
107 char * timezone_path; /* Asia/Seoul */
108 char * timezone_city; /* IDS_WCL_BODY_CITYNAME_SEOUL */
109 char * timezone_offset; /* GMT+9 */
111 Eina_List *calendar_book_list; //For save to
113 Elm_Object_Item *event_item;
114 Elm_Object_Item *todo_item;
122 struct tm stm; // start
123 struct tm etm; // end
125 Eina_Bool is_no_due_date;
129 enum __cal_edit_wday {
130 CAL_EDIT_WDAY_SUNDAY,
131 CAL_EDIT_WDAY_MONDAY,
132 CAL_EDIT_WDAY_TUESDAY,
133 CAL_EDIT_WDAY_WEDNESDAY,
134 CAL_EDIT_WDAY_THURSDAY,
135 CAL_EDIT_WDAY_FRIDAY,
136 CAL_EDIT_WDAY_SATURDAY,
140 static int __cal_edit_ug_initialize(cal_edit_ug_data *data)
144 c_retv_if(!data, -1);
146 calendar_error_e error = CALENDAR_ERROR_NONE;
148 error = calendar_connect();
149 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_connect() is failed(%x)", error);
151 _calendar_init_hash();
153 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
154 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
156 cal_util_connect_pattern_generator();
161 static int __cal_edit_ug_finish(cal_edit_ug_data *data)
165 c_retv_if(!data, -1);
167 calendar_error_e error = CALENDAR_ERROR_NONE;
169 error = calendar_disconnect();
170 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
172 cal_util_disconnect_pattern_generator();
176 if(data->item_type == ITEM_TYPE_TODO)
177 ret = vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, 0);
179 ret = vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, 1);
180 c_warn_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, %d) is failed(%d)", 0, ret);
186 static inline void __cal_edit_ug_set_record_title(calendar_record_h record, const char *title_str)
188 calendar_error_e error = CALENDAR_ERROR_NONE;
190 if (_calendar_is_task_record(record)) {
191 error = calendar_record_set_str(record, _calendar_todo.summary, title_str);
193 error = calendar_record_set_str(record, _calendar_event.summary, title_str);
196 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
199 static inline void __cal_edit_ug_set_record_location(calendar_record_h record, const char *address, double latitude, double longitude)
201 calendar_error_e error = CALENDAR_ERROR_NONE;
203 if (_calendar_is_task_record(record)) {
205 if (CAL_STRLEN(address))
206 error = calendar_record_set_str(record, _calendar_todo.location, address);
208 error = calendar_record_set_str(record, _calendar_todo.location, "");
210 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
212 error = calendar_record_set_double(record, _calendar_todo.latitude, latitude);
213 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
215 error = calendar_record_set_double(record, _calendar_todo.longitude, longitude);
216 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
219 if (CAL_STRLEN(address))
220 error = calendar_record_set_str(record, _calendar_event.location, address);
222 error = calendar_record_set_str(record, _calendar_event.location, "");
224 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
227 error = calendar_record_set_double(record, _calendar_event.latitude, latitude);
228 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
230 error = calendar_record_set_double(record, _calendar_event.longitude, longitude);
231 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
235 static inline void __cal_edit_ug_set_record_note(calendar_record_h record, const char *note_str)
237 calendar_error_e error = CALENDAR_ERROR_NONE;
239 if (_calendar_is_task_record(record))
240 error = calendar_record_set_str(record, _calendar_todo.description, note_str);
242 error = calendar_record_set_str(record, _calendar_event.description, note_str);
244 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
247 static void __cal_edit_ug_set_timezone(calendar_record_h record, const char *timezone_path, const char *timezone_city)
250 c_ret_if(!CAL_STRLEN(timezone_path));
251 c_ret_if(!CAL_STRLEN(timezone_city));
253 calendar_error_e error = CALENDAR_ERROR_NONE;
255 if (_calendar_is_task_record(record)) {
256 error = calendar_record_set_str(record, _calendar_todo.due_tzid, timezone_path);
257 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
259 error = calendar_record_set_str(record, _calendar_event.start_tzid, timezone_path);
260 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
262 error = calendar_record_set_str(record, _calendar_event.end_tzid, timezone_path);
263 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
266 _calendar_set_timezone_city(record, timezone_city);
269 static void __cal_edit_ug_set_record_time(cal_edit_ug_data *p, calendar_record_h record)
274 calendar_error_e error = CALENDAR_ERROR_NONE;
276 calendar_time_s start_time = {0};
278 _calendar_get_start_time(record, &start_time);
280 calendar_time_s end_time = {0};
282 _calendar_get_end_time(record, &end_time);
284 if (_calendar_is_allday_record(record)) {
286 start_time.time.date.year = p->stm.tm_year + 1900;
287 start_time.time.date.month = p->stm.tm_mon + 1;
288 start_time.time.date.mday = p->stm.tm_mday;
290 end_time.time.date.year = p->stm.tm_year + 1900;
291 end_time.time.date.month = p->stm.tm_mon + 1;
292 end_time.time.date.mday = p->stm.tm_mday;
295 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
296 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
299 error = calendar_record_set_caltime(record, _calendar_event.start_time, start_time);
300 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
302 error = calendar_record_set_caltime(record, _calendar_event.end_time, end_time);
303 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
305 __cal_edit_ug_set_timezone(record, p->timezone_path, p->timezone_city);
308 static void __cal_edit_ug_set_rrule_wday(calendar_record_h record, enum __cal_edit_wday tm_wday)
312 calendar_error_e error = CALENDAR_ERROR_NONE;
315 case CAL_EDIT_WDAY_SUNDAY:
316 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
319 case CAL_EDIT_WDAY_MONDAY:
320 error = calendar_record_set_str(record, _calendar_event.byday, "MO");
323 case CAL_EDIT_WDAY_TUESDAY:
324 error = calendar_record_set_str(record, _calendar_event.byday, "TU");
327 case CAL_EDIT_WDAY_WEDNESDAY:
328 error = calendar_record_set_str(record, _calendar_event.byday, "WE");
331 case CAL_EDIT_WDAY_THURSDAY:
332 error = calendar_record_set_str(record, _calendar_event.byday, "TH");
335 case CAL_EDIT_WDAY_FRIDAY:
336 error = calendar_record_set_str(record, _calendar_event.byday, "FR");
339 case CAL_EDIT_WDAY_SATURDAY:
340 error = calendar_record_set_str(record, _calendar_event.byday, "SA");
344 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
348 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
351 static void __cal_edit_ug_set_rrule_month(calendar_record_h record, int tm_mon)
355 char buffer[8] = {0};
357 snprintf(buffer, sizeof(buffer), "%d", tm_mon + 1);
359 calendar_error_e error = CALENDAR_ERROR_NONE;
361 error = calendar_record_set_str(record, _calendar_event.bymonth, buffer);
362 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
365 static void __cal_edit_ug_set_rrule_mday(calendar_record_h record, int tm_mday)
369 char buffer[8] = {0};
371 snprintf(buffer, sizeof(buffer), "%d", tm_mday);
373 calendar_error_e error = CALENDAR_ERROR_NONE;
375 error = calendar_record_set_str(record, _calendar_event.bymonthday, buffer);
376 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
379 static int __cal_edit_ug_g_list_compare(const void* data1, const void* data2)
381 const Cal_Reminder* reminder1 = (Cal_Reminder*)data1;
382 const Cal_Reminder* reminder2 = (Cal_Reminder*)data2;
384 if (reminder1->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
385 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
386 long long int dt1, dt2;
387 cal_util_convert_tm_to_lli(NULL, &reminder1->datetime, &dt1);
388 cal_util_convert_tm_to_lli(NULL, &reminder2->datetime, &dt2);
399 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
402 return reminder1->alarm_value - reminder2->alarm_value;
406 static int __cal_edit_ug_g_list_compare_with_data(const void* data1, const void* data2, void* user_data)
408 return __cal_edit_ug_g_list_compare(data1, data2);
412 static void __cal_edit_ug_set_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
416 c_retm_if(!p, "p is null");
417 c_retm_if(!record, "record is null");
421 Eina_Bool is_task = _calendar_is_task_record(record);
424 _calendar_clear_child_record(record, _calendar_todo.calendar_alarm);
426 _calendar_clear_child_record(record, _calendar_event.calendar_alarm);
429 Eina_List* list = NULL;
430 Evas_Object *item = NULL;
431 EINA_LIST_FOREACH(p->alarm_item_list, list, item) {
433 Cal_Reminder* reminder = evas_object_data_get(item, "data");
435 if (g_list_find_custom(temp, reminder, __cal_edit_ug_g_list_compare))
438 temp = g_list_insert_sorted_with_data(temp, reminder, __cal_edit_ug_g_list_compare_with_data, NULL);
440 calendar_record_h calendar_alarm = cal_reminder_get_cal_val(reminder);
442 calendar_error_e error = CALENDAR_ERROR_NONE;
445 error = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, calendar_alarm);
447 error = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, calendar_alarm);
449 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() is failed(%x)", error);
454 static void __cal_edit_ug_set_record_repeat(cal_edit_ug_data *p)
456 c_retm_if(!p, "p is null");
458 calendar_error_e error = CALENDAR_ERROR_NONE;
460 switch (p->repeat_freq) {
461 case CALENDAR_RECURRENCE_NONE:
464 case CALENDAR_RECURRENCE_DAILY:
465 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
468 case CAL_REPEAT_EVERY_3_DAY:
469 p->repeat_freq = CALENDAR_RECURRENCE_DAILY;
470 error = calendar_record_set_int(p->event, _calendar_event.interval, 3);
473 case CALENDAR_RECURRENCE_WEEKLY:
474 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
475 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
478 case CAL_REPEAT_EVERY_2_WEEK:
479 p->repeat_freq = CALENDAR_RECURRENCE_WEEKLY;
480 __cal_edit_ug_set_rrule_wday(p->event, p->stm.tm_wday);
481 error = calendar_record_set_int(p->event, _calendar_event.interval, 2);
484 case CALENDAR_RECURRENCE_YEARLY:
485 __cal_edit_ug_set_rrule_month(p->event, p->stm.tm_mon);
486 case CALENDAR_RECURRENCE_MONTHLY:
487 __cal_edit_ug_set_rrule_mday(p->event, p->stm.tm_mday);
488 error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
495 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
497 error = calendar_record_set_int(p->event, _calendar_event.freq, p->repeat_freq);
498 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
500 error = calendar_record_set_int(p->event, _calendar_event.range_type, p->repeat_range);
501 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
503 if (CALENDAR_RECURRENCE_NONE != p->repeat_freq) {
505 if (p->repeat_range == CALENDAR_RANGE_COUNT) {
506 error = calendar_record_set_int(p->event, _calendar_event.count, p->repeat_count);
507 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
508 } else if (p->repeat_range == CALENDAR_RANGE_UNTIL) {
510 error = calendar_record_set_int(p->event, _calendar_event.count, 0);
511 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
513 calendar_time_s until_time = {0};
515 until_time.type = CALENDAR_TIME_UTIME;
516 cal_util_convert_tm_to_lli(NULL, &p->repeat_until, &until_time.time.utime);
518 error = calendar_record_set_caltime(p->event, _calendar_event.until_time, until_time);
519 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
524 static void __cal_edit_ug_set_record_save_to( calendar_record_h record, int calendar_book_id)
526 calendar_error_e error = CALENDAR_ERROR_NONE;
528 if (_calendar_is_task_record(record)) {
529 error = calendar_record_set_int(record, _calendar_todo.calendar_book_id, calendar_book_id);
530 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
532 error = calendar_record_set_int(record, _calendar_event.calendar_book_id, calendar_book_id);
533 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
535 calendar_record_h calendar_book = NULL;
537 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
538 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
540 char *organizer_name = NULL;
542 error = calendar_record_get_str(calendar_book, _calendar_book.description, &organizer_name);
543 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
545 error = calendar_record_set_str(record, _calendar_event.organizer_name, organizer_name);
546 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
548 CAL_FREE(organizer_name);
550 error = calendar_record_destroy(calendar_book, true);
551 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
555 static void __cal_edit_ug_set_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
557 c_retm_if(!p, "p is null");
558 c_retm_if(!record, "record is null");
560 calendar_error_e error = CALENDAR_ERROR_NONE;
562 calendar_time_s due_time = {0};
564 _calendar_get_end_time(record, &due_time);
566 error = calendar_record_set_str(record, _calendar_todo.due_tzid, p->timezone_path);
567 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
569 if (p->is_no_due_date) {
570 due_time.time.utime = CALENDAR_TODO_NO_DUE_DATE;
572 cal_util_convert_tm_to_lli(NULL, &p->etm, &due_time.time.utime);
575 error = calendar_record_set_caltime(record, _calendar_todo.due_time, due_time);
576 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
579 static void __cal_edit_ug_set_record_priority(calendar_record_h record, int priority)
581 c_retm_if(!record, "record is null");
583 calendar_error_e error = CALENDAR_ERROR_NONE;
585 error = calendar_record_set_int(record, _calendar_todo.priority, priority);
586 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
589 static void __cal_edit_ug_initialize_event_record(cal_edit_ug_data *p)
593 c_retm_if(!p, "p is null");
595 calendar_error_e error = CALENDAR_ERROR_NONE;
598 error = calendar_record_create(_calendar_event._uri, &p->event);
599 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
602 p->stm = p->base_time;
603 p->stm.tm_min = p->stm.tm_sec = 0;
605 if (0 <= p->base_time.tm_hour)
606 p->stm.tm_hour = p->base_time.tm_hour;
608 cal_util_update_tm_hour(&p->stm,1);
611 cal_util_update_tm_hour(&p->etm,1);
613 __cal_edit_ug_set_record_time(p, p->event);
615 struct tm repeat_until = p->stm;
616 cal_util_update_tm_month (&repeat_until, 1);
617 p->repeat_freq = CALENDAR_RECURRENCE_NONE;
618 p->repeat_range = CALENDAR_RANGE_NONE;
619 p->repeat_count = 10;
620 __cal_edit_ug_set_record_repeat(p);
622 __cal_edit_ug_set_record_save_to(p->event, DEFAULT_EVENT_CALENDAR_BOOK_ID);
629 static void __cal_edit_ug_initialize_todo_record(cal_edit_ug_data *p)
633 c_retm_if(!p, "p is null");
635 calendar_error_e error = CALENDAR_ERROR_NONE;
638 error = calendar_record_create(_calendar_todo._uri, &p->todo);
639 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
642 p->stm = p->base_time;
643 p->stm.tm_min = p->stm.tm_sec = 0;
645 if (0 <= p->base_time.tm_hour)
646 p->stm.tm_hour = p->base_time.tm_hour;
648 cal_util_update_tm_hour(&p->stm,1);
651 cal_util_update_tm_hour(&p->etm,1);
653 calendar_time_s end_time = {0};
654 end_time.type = CALENDAR_TIME_UTIME;
656 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
658 error = calendar_record_set_caltime(p->todo, _calendar_todo.due_time, end_time);
659 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
661 __cal_edit_ug_set_timezone(p->todo, p->timezone_path, p->timezone_city);
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 (-1)*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);
825 p->timezone_city = _calendar_get_timezone_city(record);
828 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
830 c_ret_if(!CAL_STRLEN(p->timezone_path));
831 c_ret_if(!CAL_STRLEN(p->timezone_city));
834 static void __cal_edit_ug_get_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
836 c_retm_if(!p, "p is null");
837 c_retm_if(!record, "record is null");
840 g_list_free(p->alarm_list);
841 p->alarm_list = NULL;
846 Eina_Bool is_task = _calendar_is_task_record(record);
847 calendar_error_e error = CALENDAR_ERROR_NONE;
851 error = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, (unsigned int *)&alarm_count);
852 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
856 error = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, (unsigned int *)&alarm_count);
857 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
861 for (i = 0; i < alarm_count; i++) {
862 calendar_record_h calendar_alarm = NULL;
866 error = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, i, &calendar_alarm);
867 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
871 error = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, i, &calendar_alarm);
872 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
875 Cal_Reminder* reminder = cal_reminder_create(calendar_alarm);
876 p->alarm_list = g_list_append(p->alarm_list,(void *)reminder);
879 p->alarm_list = g_list_first(p->alarm_list);
882 static void __cal_edit_ug_get_record_repeat(cal_edit_ug_data *p, calendar_record_h record)
887 calendar_record_h original_record = NULL;
888 int original_event_id = 0;
889 calendar_error_e error = CALENDAR_ERROR_NONE;
891 error = calendar_record_get_int(record, _calendar_event.original_event_id, &original_event_id);
892 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
894 if (0 < original_event_id) {
896 error = calendar_db_get_record(_calendar_event._uri, original_event_id, &original_record);
897 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
900 if (!original_record)
901 original_record = record;
903 error = calendar_record_get_int(record, _calendar_event.freq, &p->repeat_freq);
904 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
906 if (p->repeat_freq == CALENDAR_RECURRENCE_WEEKLY) {
910 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
911 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
914 p->repeat_freq = CAL_REPEAT_EVERY_2_WEEK;
916 } else if (p->repeat_freq == CALENDAR_RECURRENCE_DAILY) {
920 error = calendar_record_get_int(record, _calendar_event.interval, &interval);
921 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
924 p->repeat_freq = CAL_REPEAT_EVERY_3_DAY;
927 error = calendar_record_get_int(record, _calendar_event.range_type, (int *)&p->repeat_range);
928 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
930 if (p->repeat_range == CALENDAR_RANGE_NONE) {
931 p->repeat_count = 10;
933 p->repeat_until = p->stm;
934 cal_util_update_tm_month (&p->repeat_until, 1);
937 error = calendar_record_get_int(record, _calendar_event.count, &p->repeat_count);
938 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
940 calendar_time_s until_utime = {0};
942 error = calendar_record_get_caltime(record, _calendar_event.until_time, &until_utime);
943 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
945 cal_util_convert_lli_to_tm(NULL, until_utime.time.utime, &p->repeat_until);
948 if (original_record != record) {
949 error = calendar_record_destroy(original_record, true);
950 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
954 static int __cal_edit_ug_get_record_priority(calendar_record_h record)
956 c_retv_if(!record, 0);
958 calendar_error_e error = CALENDAR_ERROR_NONE;
962 error = calendar_record_get_int(record, _calendar_todo.priority, (int *)&priority);
963 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
968 static void __cal_edit_ug_get_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
970 c_retm_if(!p, "p is null");
971 c_retm_if(!record, "record is null");
973 calendar_error_e error = CALENDAR_ERROR_NONE;
975 calendar_time_s due_time = {0};
977 _calendar_get_end_time(record, &due_time);
979 cal_util_convert_lli_to_tm(NULL, due_time.time.utime, &p->etm);
981 if (due_time.time.utime == CALENDAR_TODO_NO_DUE_DATE) {
982 p->is_no_due_date = EINA_TRUE;
983 //p->etm = p->base_time;
986 error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
987 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
989 c_ret_if(!p->timezone_path);
991 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
994 static void __cal_edit_ug_update_title_item(Evas_Object *entry, calendar_record_h record)
996 c_retm_if(!entry, "entry is null");
997 c_retm_if(!record, "record is null");
999 char* title = __cal_edit_ug_get_record_title(record);
1001 elm_entry_entry_set(entry, title);
1006 static void __cal_edit_ug_update_note_item(Evas_Object *entry, calendar_record_h record)
1008 c_retm_if(!entry, "entry is null");
1009 c_retm_if(!record, "record is null");
1011 char* note = __cal_edit_ug_get_record_note(record);
1013 elm_entry_entry_set(entry, note);
1018 static void __cal_edit_ug_update_location_item(cal_edit_ug_data *p, calendar_record_h record)
1020 c_retm_if(!p, "p is null");
1021 c_retm_if(!record, "record is null");
1023 __cal_edit_ug_get_record_location(p, record);
1024 elm_entry_entry_set(p->location_entry, p->address);
1027 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz);
1029 static void __cal_edit_ug_update_save_to_item(cal_edit_ug_data *p, calendar_record_h record)
1031 c_retm_if(!p, "p is null");
1033 int calendar_book_id = _calendar_get_calendar_index(record);
1036 char* saveto_text = NULL;
1037 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
1038 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
1039 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
1040 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
1042 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
1043 saveto_text = strdup(buf);
1046 elm_object_part_text_set(p->saveto, "elm.text.1", saveto_text);
1048 CAL_FREE(saveto_text);
1051 static void __cal_edit_ug_update_priority_item(cal_edit_ug_data *p, calendar_record_h record)
1053 c_retm_if(!p, "p is null");
1054 c_retm_if(!record, "record is null");
1056 char* priority_text = NULL;
1057 int priority = __cal_edit_ug_get_record_priority(record);
1059 case CALENDAR_TODO_PRIORITY_LOW:
1060 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
1062 case CALENDAR_TODO_PRIORITY_NORMAL:
1063 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
1065 case CALENDAR_TODO_PRIORITY_HIGH:
1066 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
1072 elm_object_part_text_set(p->priority, "elm.text.1", priority_text);
1073 CAL_FREE(priority_text);
1077 static void __cal_edit_ug_update_start_language(Evas_Object *item)
1081 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_FROM"));
1084 static void __cal_edit_ug_update_end_language(Evas_Object *item)
1088 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_TO"));
1091 static void __cal_edit_ug_update_due_language(Evas_Object *item)
1095 elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_DUE_DATE"));
1098 static Evas_Object *__cal_edit_ug_insert_padding_after(cal_edit_ug_data* p, const char* title, Evas_Object *after)
1100 c_retv_if(!p, NULL);
1101 c_retv_if(!after, NULL);
1103 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "title", after, NULL, NULL);
1104 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1106 if (CAL_STRLEN(title))
1107 elm_object_part_text_set(item, "elm.text", title);
1112 static void __cal_edit_ug_title_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1115 cal_edit_ug_data* p = (cal_edit_ug_data *)data;
1119 str = elm_entry_entry_get(p->title_entry);
1120 if (!str || str[0] == '\0')
1121 p->title_str = NULL;
1123 p->title_str = elm_entry_markup_to_utf8(str);
1125 if(p->item_type == ITEM_TYPE_TODO)
1126 __cal_edit_ug_set_record_title(p->todo, p->title_str);
1128 __cal_edit_ug_set_record_title(p->event, p->title_str);
1131 static Evas_Object * __cal_edit_ug_title_item(cal_edit_ug_data* p, Evas_Object *obj)
1133 c_retv_if(!p, NULL);
1134 c_retv_if(!obj, NULL);
1136 Evas_Object *ef = cal_util_add_edit_field(obj, NULL, S_("IDS_COM_BODY_DETAILS_TITLE"), EINA_FALSE, EINA_TRUE, EINA_FALSE);
1137 c_retvm_if(!ef, NULL, "ef is null");
1139 Evas_Object *entry = elm_object_part_content_get(ef, "elm.icon.entry");
1140 c_retvm_if(!entry, ef, "entry is null");
1142 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1144 p->title_entry = entry;
1146 if (p->item_type == ITEM_TYPE_TODO)
1147 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
1149 __cal_edit_ug_update_title_item(p->title_entry, p->event);
1151 evas_object_smart_callback_add(p->title_entry, "changed", __cal_edit_ug_title_entry_changed_callback, p);
1152 evas_object_smart_callback_add(p->title_entry, "preedit,changed", __cal_edit_ug_title_entry_changed_callback, p);
1158 static void __cal_edit_ug_update_title_language(Evas_Object *item)
1162 Evas_Object *entry = elm_object_part_content_get(item, "elm.icon.entry");
1163 c_retm_if(!entry, "entry is null");
1165 elm_object_part_text_set(entry, "elm.guide", S_("IDS_COM_BODY_DETAILS_TITLE"));
1168 static Evas_Object *__cal_edit_ug_add_title(cal_edit_ug_data* p)
1170 c_retv_if(!p, NULL);
1172 Evas_Object *item = __cal_edit_ug_title_item(p, p->dialogue);
1173 c_retvm_if(!item, NULL, "__cal_edit_ug_title_item() is failed");
1175 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, 0.0);
1176 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, 0.0);
1177 elm_box_pack_end(p->dialogue, item);
1178 evas_object_show(item);
1183 static void __cal_edit_ug_location_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1187 cal_edit_ug_data *p = data;
1190 CAL_FREE(p->address);
1192 p->address = elm_entry_markup_to_utf8(elm_entry_entry_get(p->location_entry));
1194 if (!CAL_STRLEN(p->address)) {
1196 p->longitude = p->latitude = CALENDAR_RECORD_NO_COORDINATE;
1200 if (p->item_type == ITEM_TYPE_TODO)
1201 __cal_edit_ug_set_record_location(p->todo, p->address, p->latitude, p->longitude);
1203 __cal_edit_ug_set_record_location(p->event, p->address, p->latitude, p->longitude);
1206 static Evas_Object * __cal_edit_ug_location_icon(cal_edit_ug_data* p, Evas_Object *obj)
1208 c_retv_if(!p, NULL);
1209 c_retv_if(!obj, NULL);
1211 Evas_Object *ly = NULL;
1213 Evas_Object *ef = cal_util_add_edit_field(obj, NULL, C_("IDS_COM_BODY_DETAILS_LOCATION"), EINA_FALSE, EINA_TRUE, EINA_TRUE);
1216 p->location_entry = elm_object_part_content_get(ef, "elm.icon.entry");
1217 c_retv_if(!p->location_entry, ly);
1219 evas_object_smart_callback_add(p->location_entry, "changed", __cal_edit_ug_location_entry_changed_callback, p);
1220 evas_object_smart_callback_add(p->location_entry, "preedit,changed", __cal_edit_ug_location_entry_changed_callback, p);
1222 elm_entry_cursor_end_set(p->location_entry);
1224 elm_entry_cnp_mode_set(p->location_entry, ELM_CNP_MODE_PLAINTEXT);
1226 if (p->item_type == ITEM_TYPE_TODO)
1227 __cal_edit_ug_update_location_item(p, p->todo);
1229 __cal_edit_ug_update_location_item(p, p->event);
1234 static void __cal_edit_ug_update_location_language(Evas_Object *item)
1238 Evas_Object *layout = elm_object_part_content_get(item, "elm.icon");
1241 Evas_Object *edit_field = elm_object_part_content_get(layout, "editfield/sw");
1242 c_ret_if(!edit_field);
1244 Evas_Object *entry = elm_object_part_content_get(edit_field, "elm.icon.entry");
1245 c_retm_if(!entry, "entry is null");
1247 elm_object_part_text_set(entry, "elm.guide", C_("IDS_COM_BODY_DETAILS_LOCATION"));
1251 static Evas_Object *__cal_edit_ug_add_location(cal_edit_ug_data* p)
1253 c_retv_if(!p, NULL);
1255 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "1icon", NULL, NULL);
1256 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1258 Evas_Object *editfield = __cal_edit_ug_location_icon(p, item);
1259 c_retvm_if(!editfield, NULL, "__cal_edit_ug_note_icon() is failed");
1261 elm_object_part_content_set(item, "elm.icon", editfield);
1263 __cal_edit_ug_insert_padding_after(p, NULL, item);
1268 static void __cal_edit_ug_note_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1270 char *email_link = NULL;
1271 cal_edit_ug_data *p = data;
1272 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(p->note_entry));
1274 if (CAL_STRLEN(p->note_str))
1275 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1277 if ((NULL != email_link) && CAL_STRLEN(str) && (NULL != strstr(p->note_str, str))) {
1278 char *strnote = NULL;
1279 int strnote_len = 0;
1280 strnote_len = strlen(str) + strlen(email_link);
1281 CAL_CALLOC(strnote, strnote_len+1, char);
1282 if (NULL != strnote)
1284 snprintf(strnote, strnote_len + 1, "%s%s", str, email_link);
1285 p->note_str = strdup(strnote);
1295 p->note_str = CAL_STRDUP(str);
1300 if(p->item_type == ITEM_TYPE_TODO)
1301 __cal_edit_ug_set_record_note(p->todo, p->note_str);
1303 __cal_edit_ug_set_record_note(p->event, p->note_str);
1307 static Evas_Object * __cal_edit_ug_note_item(cal_edit_ug_data* p, Evas_Object *obj)
1309 c_retv_if(!p, NULL);
1310 c_retv_if(!obj, NULL);
1312 Evas_Object *ef = cal_util_add_edit_field(obj, NULL, C_("IDS_CLD_BODY_CREATE_DESCRITION"), EINA_FALSE, EINA_TRUE, EINA_FALSE);
1315 Evas_Object *entry = elm_object_part_content_get(ef, "elm.icon.entry");
1316 c_retvm_if(!entry, ef, "entry is null");
1318 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1319 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
1320 //elm_entry_autocapital_type_set(entry, EINA_TRUE);
1321 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1323 p->note_entry = entry;
1327 char *email_link = NULL;
1328 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1330 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(p->note_str));
1333 char *snote_display = NULL;
1334 int nsize = email_link - p->note_str + 1;
1335 snote_display = calloc(nsize, sizeof(char));
1336 c_retvm_if(!snote_display , NULL, "calloc(nsize, sizeof(char)) is failed");
1338 CAL_STRNCPY(snote_display, p->note_str, nsize-1);
1340 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(snote_display));
1341 free(snote_display);
1345 if (p->item_type == ITEM_TYPE_TODO)
1346 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
1348 __cal_edit_ug_update_note_item(p->note_entry, p->event);
1350 evas_object_smart_callback_add(p->note_entry, "changed", __cal_edit_ug_note_entry_changed_callback, p);
1351 evas_object_smart_callback_add(p->note_entry, "preedit,changed", __cal_edit_ug_note_entry_changed_callback, p);
1352 elm_entry_cursor_end_set(p->note_entry);
1360 static void __cal_edit_ug_update_description_language(Evas_Object *item)
1364 Evas_Object *entry = elm_object_part_content_get(item, "elm.icon.entry");
1365 c_retm_if(!entry, "entry is null");
1367 elm_object_part_text_set(entry, "elm.guide", C_("IDS_CLD_BODY_CREATE_DESCRITION"));
1371 static Evas_Object *__cal_edit_ug_add_note(cal_edit_ug_data* p)
1373 c_retv_if(!p, NULL);
1375 Evas_Object *item = __cal_edit_ug_note_item(p, p->dialogue);
1376 c_retvm_if(!item, NULL, "__cal_edit_ug_note_item() is failed");
1378 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, 0.0);
1379 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, 0.0);
1380 elm_box_pack_end(p->dialogue, item);
1381 evas_object_show(item);
1386 static Evas_Object * __cal_edit_ug_edit_time_icon(Evas_Object *obj, struct tm* value, Eina_Bool allday)
1388 c_retvm_if(!obj, NULL, "obj is null");
1390 Evas_Object* icon_obj = cal_util_add_datetime(obj, NULL, value);
1391 c_retvm_if(!icon_obj, NULL, "icon_obj is null");
1393 elm_object_part_content_set(obj, "datefield", icon_obj);
1396 elm_datetime_format_set(icon_obj, "%b %d , %Y %H : %M");
1398 elm_datetime_format_set(icon_obj, "%b %d , %Y %I : %M %p");
1402 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1403 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1405 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1407 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1411 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1412 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1413 elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1416 elm_datetime_field_limit_set(icon_obj, ELM_DATETIME_YEAR, 70, 136);
1421 static Eina_Bool __cal_edit_ug_check_date_validity(void *data)
1423 c_retv_if(!data, EINA_FALSE);
1424 cal_edit_ug_data* p = data;
1426 time_t start_t = mktime(&p->stm);
1427 time_t end_t = mktime(&p->etm);
1435 static void __cal_edit_ug_start_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1437 c_retm_if(data == NULL, "data is null");
1438 cal_edit_ug_data *p = data;
1441 time_t t = time(NULL);
1442 localtime_r(&t, &value); // to fill hidden field
1444 elm_datetime_value_get(obj, &value);
1446 // Remember the time difference in before updating start time
1447 time_t start_t = mktime(&p->stm);
1448 time_t end_t = mktime(&p->etm);
1449 time_t diff = end_t - start_t;
1451 // Update start time variable
1454 Eina_Bool result =__cal_edit_ug_check_date_validity(p);
1456 // Calculate end time from start time to retain the time difference
1457 end_t = mktime(&p->stm) + diff;
1458 localtime_r(&end_t, &p->etm);
1460 // Update end time on the screen
1461 Evas_Object *end_date_obj = elm_object_part_content_get(p->end_date, "elm.icon");
1462 elm_datetime_value_set(end_date_obj, &p->etm);
1465 __cal_edit_ug_set_record_time(p, p->event);
1468 static void __cal_edit_ug_end_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1470 c_retm_if(!data, "data is null");
1471 cal_edit_ug_data *p = data;
1474 time_t t = time(NULL);
1475 localtime_r(&t, &value); // to fill hidden field
1477 elm_datetime_value_get(obj, &value);
1481 Eina_Bool result = __cal_edit_ug_check_date_validity(p);
1483 int r = notification_status_message_post(C_("IDS_CLD_POP_END_TIME_SHOULD_BE_SET_AFTER_START_TIME"));
1484 c_warn_if(r != NOTIFICATION_ERROR_NONE, "notification_status_message_post() is failed(%d)", r);
1486 __cal_edit_ug_set_record_time(p, p->event);
1490 static void __cal_edit_ug_due_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1492 c_retm_if(!data, "data is null");
1493 cal_edit_ug_data *p = data;
1496 time_t t = time(NULL);
1497 localtime_r(&t, &value); // to fill hidden field
1499 elm_datetime_value_get(obj, &value);
1503 __cal_edit_ug_set_record_due_time(p, p->todo);
1507 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)
1511 Evas_Object *datetime = NULL;
1513 datetime = elm_object_part_content_unset(item, "elm.icon");
1515 evas_object_del(datetime);
1517 datetime = __cal_edit_ug_edit_time_icon(item, tm, is_allday);
1518 c_ret_if(!datetime);
1520 elm_object_part_content_set(item, "elm.icon", datetime);
1522 evas_object_smart_callback_add(datetime, "changed", callback, callback_data);
1525 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)
1527 c_retv_if(!p, NULL);
1528 c_retv_if(!after, NULL);
1530 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1icon", after, NULL, NULL);
1531 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1533 __cal_edit_ug_update_datetime_region(item, value, allday, callback, p);
1538 static void __cal_edit_ug_all_day_update(Evas_Object* date_obj, Eina_Bool allday)
1540 Evas_Object *edit_time_obj = elm_object_part_content_get(date_obj, "elm.icon");
1543 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_TRUE);
1544 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_TRUE);
1546 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1548 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_HOUR, EINA_FALSE);
1549 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_MINUTE, EINA_FALSE);
1550 elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1554 static void __cal_edit_ug_set_record_allday(calendar_record_h record, Eina_Bool is_allday, cal_edit_ug_data *p)
1559 if (is_allday == _calendar_is_allday_record(record))
1562 calendar_time_s start_time = {0};
1564 _calendar_get_start_time(record, &start_time);
1566 calendar_time_s end_time = {0};
1568 _calendar_get_end_time(record, &end_time);
1570 struct tm start_tm = {0};
1571 struct tm end_tm = {0};
1575 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &start_tm);
1576 cal_util_convert_lli_to_tm(NULL, end_time.time.utime, &end_tm);
1578 start_time.type = CALENDAR_TIME_LOCALTIME;
1579 end_time.type = CALENDAR_TIME_LOCALTIME;
1581 start_time.time.date.year = start_tm.tm_year + 1900;
1582 start_time.time.date.month = start_tm.tm_mon + 1;
1583 start_time.time.date.mday = start_tm.tm_mday;
1585 end_time.time.date.year = end_tm.tm_year + 1900;
1586 end_time.time.date.month = end_tm.tm_mon + 1;
1587 end_time.time.date.mday = end_tm.tm_mday;
1591 start_time.type = CALENDAR_TIME_UTIME;
1592 end_time.type = CALENDAR_TIME_UTIME;
1594 cal_util_convert_tm_to_lli(NULL, &p->stm, &start_time.time.utime);
1595 cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
1598 _calendar_set_start_time(record, &start_time);
1600 _calendar_set_end_time(record, &end_time);
1603 static void __cal_edit_ug_all_day_clicked_callback(Evas_Object *obj, void *data)
1607 c_retm_if(!data, "data is null");
1608 cal_edit_ug_data *p = data;
1610 Evas_Object *all_obj = elm_object_part_content_get(p->allday, "elm.icon");
1613 Eina_Bool is_allday = !elm_check_state_get(all_obj);
1615 elm_check_state_set(all_obj, is_allday);
1617 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1618 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1620 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1624 static void __cal_edit_ug_all_day_changed_callback(void *data, Evas_Object* obj, void *ei)
1628 c_retm_if(!data, "data is null");
1629 c_retm_if(!obj, "obj is null");
1631 cal_edit_ug_data *p = data;
1633 Eina_Bool is_allday = elm_check_state_get(obj);
1635 __cal_edit_ug_all_day_update(p->start_date, is_allday);
1636 __cal_edit_ug_all_day_update(p->end_date, is_allday);
1638 __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1641 static void __cal_edit_ug_update_allday_language(Evas_Object *item)
1645 elm_object_part_text_set(item, "elm.text", C_("IDS_COM_BODY_ALL_DAY"));
1648 static Evas_Object *__cal_edit_ug_add_all_day(cal_edit_ug_data* p, Eina_Bool allday)
1650 c_retv_if(!p, NULL);
1652 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "1text.1icon", p->timezone, __cal_edit_ug_all_day_clicked_callback, p);
1653 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1655 Evas_Object *check_obj;
1656 check_obj = elm_check_add(item);
1657 elm_check_state_set(check_obj, allday);
1658 elm_object_style_set(check_obj, "on&off");
1659 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_all_day_changed_callback, p);
1660 elm_check_state_set(check_obj, allday);
1661 evas_object_propagate_events_set(check_obj, EINA_FALSE);
1663 elm_object_part_content_set(item, "elm.icon", check_obj);
1665 __cal_edit_ug_update_allday_language(item);
1670 static void __cal_edit_ug_worldclock_ug_destroy_callback(ui_gadget_h ug, void *priv)
1674 cal_edit_ug_data* p = (cal_edit_ug_data*) priv;
1676 if (p->ug_worldclock) {
1677 ug_destroy(p->ug_worldclock);
1678 p->ug_worldclock= NULL;
1681 Elm_Object_Item* navi_item = elm_naviframe_top_item_get(p->naviframe);
1682 Evas_Object *back_btn = elm_object_item_part_content_get(navi_item, "prev_btn");
1683 if (back_btn != NULL) {
1684 elm_object_style_set(back_btn, "naviframe/back_btn/default"); /* take into effect */
1688 static void __cal_edit_ug_worldclock_ug_result_callback(ui_gadget_h ug, service_h result, void *priv)
1692 c_retm_if(!priv, "priv is null");
1693 c_retm_if(!result, "result is null");
1695 cal_edit_ug_data *p = priv;
1697 if (p->timezone_city) {
1698 free(p->timezone_city);
1699 p->timezone_city = NULL;
1702 if (p->timezone_path) {
1703 free(p->timezone_path);
1704 p->timezone_path = NULL;
1707 if (p->timezone_offset) {
1708 free(p->timezone_offset);
1709 p->timezone_offset = NULL;
1712 int r = service_get_extra_data(result, "tzpath", &p->timezone_path);
1713 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data(tzpath) is failed(%x)", r);
1715 r = service_get_extra_data(result, "city", &p->timezone_city);
1716 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data(city) is failed(%x)", r);
1718 __cal_edit_ug_set_timezone(p->record, p->timezone_path, p->timezone_city);
1720 cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
1722 p->is_selected_timezone = EINA_TRUE;
1724 char* timezone_text = NULL;
1725 timezone_text = g_strdup_printf("%s, %s", S_(p->timezone_city), p->timezone_offset);
1727 elm_object_part_text_set(p->timezone, "elm.text.1", timezone_text);
1729 CAL_FREE(timezone_text);
1732 static void __cal_edit_ug_worldclock_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
1736 c_retm_if(!ug, "ug is null");
1738 Evas_Object *base = ug_get_layout(ug);
1746 case UG_MODE_FULLVIEW:
1747 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1749 evas_object_show(base);
1752 DBG("Unsupported ug layout");
1758 static void __cal_edit_ug_timezone_select_callback(Evas_Object *obj, void *data)
1760 c_retm_if(!data, "data is null");
1762 cal_edit_ug_data *p = data;
1765 memset(&uc, 0, sizeof(struct ug_cbs));
1766 uc.destroy_cb = __cal_edit_ug_worldclock_ug_destroy_callback;
1767 uc.layout_cb = __cal_edit_ug_worldclock_ug_layout_callback;
1768 uc.result_cb = __cal_edit_ug_worldclock_ug_result_callback;
1771 ug = ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, NULL, &uc);
1772 p->ug_worldclock = ug;
1775 static void __cal_edit_ug_update_time_zone_language(Evas_Object *item, const char *timezone_city, const char *timezone_offset)
1777 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_TIME_ZONE"));
1779 char buffer[128] = {0};
1781 snprintf(buffer, sizeof(buffer), "%s, %s", S_(timezone_city), timezone_offset);
1783 elm_object_part_text_set(item, "elm.text.1", buffer);
1786 static Evas_Object *__cal_edit_ug_add_time_zone(cal_edit_ug_data* p)
1788 c_retv_if(!p, NULL);
1790 Evas_Object *item = __cal_edit_ug_insert_padding_after(p, NULL, p->end_date);
1791 c_retvm_if(!item, NULL, "__cal_edit_ug_insert_padding_after() is failed");
1793 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", item, __cal_edit_ug_timezone_select_callback, p);
1794 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1796 __cal_edit_ug_get_record_time_zone(p, p->event);
1798 __cal_edit_ug_update_time_zone_language(item, p->timezone_city, p->timezone_offset);
1803 static void __cal_edit_ug_alarm_changed_callback(const Cal_Reminder* reminder, void* data)
1807 c_retm_if(!data, "data is null");
1809 Evas_Object *obj = data;
1811 char* alarm_text = NULL;
1812 char buf[128] = {0};
1813 cal_reminder_get_string(reminder, buf, sizeof(buf));
1814 alarm_text = strdup(buf);
1816 elm_object_part_text_set(obj, "elm.text.1", alarm_text);
1817 CAL_FREE(alarm_text);
1819 Cal_Reminder* reminder_temp = evas_object_data_get(obj, "data");
1820 reminder_temp->alarm_value = reminder->alarm_value;
1821 reminder_temp->datetime = reminder->datetime;
1822 reminder_temp->tick_unit = reminder->tick_unit;
1825 static void __cal_edit_ug_alarm_select_callback(Evas_Object *obj, void *data)
1829 c_retm_if(!data, "data is null");
1831 cal_edit_ug_data* p = data;
1832 Cal_Reminder* reminder = (Cal_Reminder*)evas_object_data_get(obj, "data");
1833 cal_edit_alarm_type alarm_type = ALARM_TYPE_EVENT;
1835 if(p->item_type == ITEM_TYPE_EVENT)
1836 alarm_type = ALARM_TYPE_EVENT;
1837 else if(p->item_type == ITEM_TYPE_TODO && p->is_no_due_date)
1838 alarm_type = ALARM_TYPE_TODO_CUSTOM_ONLY;
1840 alarm_type = ALARM_TYPE_TODO;
1842 cal_edit_alarm_create_view(p->window, p->conformant, p->naviframe, reminder, alarm_type, __cal_edit_ug_alarm_changed_callback, obj);
1846 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after);
1848 static void __cal_edit_ug_delete_reminder_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
1858 static void __cal_edit_ug_alarm_plus_button_callback(void *data, Evas_Object *obj, void *event_info)
1862 c_retm_if(!data, "data is null");
1863 c_retm_if(!obj, "obj is null");
1865 cal_edit_ug_data* p = data;
1867 if (eina_list_count(p->alarm_item_list)>=4) {
1868 evas_object_del(p->alarm_plus_button);
1869 p->alarm_plus_button = NULL;
1872 Cal_Reminder* reminder = calloc(1, sizeof(Cal_Reminder));
1873 c_retm_if(!reminder, "reminder is null");
1874 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1875 reminder->datetime = p->stm;
1877 Eina_List *list = eina_list_last(p->alarm_item_list);
1878 Evas_Object *last_item = eina_list_data_get(list);
1879 __cal_edit_ug_add_alarm(p, reminder, EINA_FALSE, last_item);
1883 static Evas_Object * __cal_edit_ug_alarm_plus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1885 c_retv_if(!p, NULL);
1886 c_retv_if(!obj, NULL);
1888 Evas_Object *button = NULL;
1890 button = elm_button_add(obj);
1891 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1893 elm_object_style_set(button, "icon_plus");
1894 evas_object_propagate_events_set(button, EINA_FALSE);
1895 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_plus_button_callback, p);
1896 evas_object_show(button);
1897 p->alarm_plus_button = button;
1902 static void __cal_edit_ug_alarm_minus_button_callback(void *data, Evas_Object *obj, void *event_info)
1906 c_retm_if(!data, "data is null");
1907 c_retm_if(!obj, "obj is null");
1909 cal_edit_ug_data* p = data;
1911 if (!p->alarm_plus_button) {
1912 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
1913 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
1914 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
1917 evas_object_smart_callback_del(obj, "clicked", __cal_edit_ug_alarm_minus_button_callback);
1919 Evas_Object *parent_item = evas_object_data_get(obj, "button");
1920 p->alarm_item_list = eina_list_remove(p->alarm_item_list, parent_item);
1922 cal_dialogue_delete_item(p->dialogue, parent_item);
1923 evas_object_del(obj);
1929 static Evas_Object * __cal_edit_ug_alarm_minus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1931 c_retv_if(!p, NULL);
1932 c_retv_if(!obj, NULL);
1934 Evas_Object *button = NULL;
1936 button = elm_button_add(obj);
1937 c_retvm_if(!button, NULL, "elm_button_add() is failed");
1939 elm_object_style_set(button, "icon_minus");
1940 evas_object_data_set(button, "button", obj);
1941 evas_object_propagate_events_set(button, EINA_FALSE);
1942 evas_object_smart_callback_add(button, "clicked", __cal_edit_ug_alarm_minus_button_callback, p);
1943 evas_object_show(button);
1948 static void __cal_edit_ug_update_reminder_language(Eina_List *item_list)
1950 c_ret_if(!item_list);
1952 Eina_List *cursor = NULL;
1953 Evas_Object *item = NULL;
1955 EINA_LIST_FOREACH(item_list, cursor, item) {
1959 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1961 Cal_Reminder *reminder = NULL;
1963 reminder = evas_object_data_get(item, "data");
1965 char buffer[128] = {0};
1966 cal_reminder_get_string(reminder, buffer, sizeof(buffer));
1968 elm_object_part_text_set(item, "elm.text.1", buffer);
1972 static Evas_Object *__cal_edit_ug_add_alarm(cal_edit_ug_data* p, Cal_Reminder* reminder, Eina_Bool is_add_mode, Evas_Object *after)
1974 c_retv_if(!p, NULL);
1975 Evas_Object *item = NULL;
1977 item = cal_dialogue_insert_item_after(p->dialogue, "2text.1icon.5", after, __cal_edit_ug_alarm_select_callback, p);
1978 c_retvm_if(!item, NULL, "cal_dialogue_insert_item_after() is failed");
1981 item = cal_dialogue_append_item(p->dialogue, "2text.1icon.5", __cal_edit_ug_alarm_select_callback, p);
1982 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
1985 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1987 const char* alarm_text = NULL;
1988 char buf[128] = {0};
1989 cal_reminder_get_string(reminder, buf, sizeof(buf));
1990 alarm_text = strdup(buf);
1992 elm_object_part_text_set(item, "elm.text.1", alarm_text);
1993 p->alarm_item_list = eina_list_append(p->alarm_item_list, (void*)item);
1995 if(p->item_type == ITEM_TYPE_EVENT) {
1996 Evas_Object *button_obj = NULL;
1998 button_obj = __cal_edit_ug_alarm_plus_button_icon(p, item);
2000 button_obj = __cal_edit_ug_alarm_minus_button_icon(p, item);
2002 elm_object_part_content_set(item, "elm.icon", button_obj);
2005 evas_object_data_set(item, "data", reminder);
2006 evas_object_event_callback_add(item, EVAS_CALLBACK_DEL, __cal_edit_ug_delete_reminder_callback, reminder);
2011 static void __cal_edit_ug_add_multi_alarm(cal_edit_ug_data* p)
2013 c_retm_if(!p, "p is null");
2015 Cal_Reminder* reminder = NULL;
2016 reminder = calloc(1, sizeof(Cal_Reminder));
2017 c_retm_if(!reminder, "reminder is null");
2019 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
2020 reminder->datetime = p->stm;
2021 Evas_Object *after = NULL;
2022 Evas_Object *item = NULL;
2024 if(p->is_edit_mode) {
2025 if (p->item_type == ITEM_TYPE_EVENT)
2026 __cal_edit_ug_get_record_alarm(p, p->event);
2028 __cal_edit_ug_get_record_alarm(p, p->todo);
2030 if(!p->alarm_list) {
2031 reminder->tick_unit = CALENDAR_ALARM_NONE;\
2035 GList *temp = p->alarm_list;
2037 __cal_edit_ug_add_alarm(p, reminder, EINA_TRUE, NULL);
2044 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_TRUE, after);
2047 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_FALSE, after);
2049 c_retm_if(!item, "item is null");
2051 temp = g_list_next(temp);
2056 static void __cal_edit_ug_reponse_event_callback(void *data, Evas_Object *obj, void *ei)
2058 c_retm_if(!data, "data is null");
2060 Evas_Object *popup = data;
2061 evas_object_del(popup);
2064 static void __cal_edit_ug_repeat_callback(void *data)
2066 c_retm_if(!data, "data is null");
2068 cal_edit_ug_data *p = data;
2070 calendar_range_type_e range = CALENDAR_RANGE_NONE;
2071 struct tm until = {0};
2074 int repeat = cal_edit_repeat_get_repeat(p->repeat_layout, &range, &until, &count);
2076 if (CALENDAR_RECURRENCE_NONE != repeat) {
2078 if (range == CALENDAR_RANGE_UNTIL) {
2080 if (timegm(&until) <= timegm(&p->stm)) {
2081 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2082 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2086 else if (range == CALENDAR_RANGE_COUNT) {
2089 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_REPEAT_WARNING"),
2090 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2096 p->repeat_freq = repeat;
2097 p->repeat_range = range;
2098 p->repeat_until = until;
2099 p->repeat_count = count;
2101 char buf[1024] = {0};
2102 _cal_edit_repeat_get_freq_str(p->repeat_freq, buf, sizeof(buf));
2103 elm_object_part_text_set(p->repeat, "elm.text.1", buf);
2105 __cal_edit_ug_set_record_repeat(p);
2109 static void __cal_edit_ug_repeat_select_callback(Evas_Object *obj, void *data)
2111 c_retm_if(!data, "data is null");
2113 cal_edit_ug_data* p = data;
2115 p->repeat_layout = cal_edit_repeat_create_view(p->window, p->conformant, p->naviframe, p->repeat_freq, p->repeat_range, &(p->stm), &(p->repeat_until),&(p->repeat_count),
2116 (cal_edit_repeat_destroy_callback)__cal_edit_ug_repeat_callback, p);
2117 c_retm_if(!p->repeat_layout, "p->repeat_layout is null");
2121 static void __cal_edit_ug_update_recurrence_language(Evas_Object *item, int repeat_frequency)
2125 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REPEAT"));
2127 char buffer[128] = {0};
2129 _cal_edit_repeat_get_freq_str(repeat_frequency, buffer, sizeof(buffer));
2131 elm_object_part_text_set(item, "elm.text.1", buffer);
2134 static Evas_Object *__cal_edit_ug_add_repeat(cal_edit_ug_data* p)
2136 c_retv_if(!p, NULL);
2138 Eina_List *list = eina_list_last(p->alarm_item_list);
2139 Evas_Object *last_item = eina_list_data_get(list);
2141 Evas_Object *item = NULL;
2145 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, NULL, NULL);
2146 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2149 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, __cal_edit_ug_repeat_select_callback, p);
2151 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2153 __cal_edit_ug_get_record_repeat(p, p->event);
2155 __cal_edit_ug_update_recurrence_language(item, p->repeat_freq);
2160 static void __cal_edit_ug_popup_hide_callback(void *data, Evas_Object *obj, void *event_info)
2162 c_retm_if(!data, "data is null");
2163 c_retm_if(!obj, "obj is null");
2165 Evas_Object *popup = data;
2167 cal_edit_ug_data *p = evas_object_data_get(popup, "data");
2169 evas_object_del(popup);
2171 c_retm_if(!p, "p is null");
2176 static char *__cal_edit_ug_get_genlist_save_to_item_label(void *data, Evas_Object *obj, const char *part)
2178 c_retvm_if(!data, NULL, "data is null");
2179 c_retvm_if(!part, NULL, "part is null");
2181 calendar_record_h record = (calendar_record_h)data;
2186 calendar_error_e error = CALENDAR_ERROR_NONE;
2188 calendar_record_h calendar_book = NULL;
2190 _calendar_record_type record_type = _calendar_get_record_type(record);
2192 if (record_type == _CALENDAR_RECORD_TYPE_CALENDARBOOK)
2193 calendar_book = record;
2195 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &cid);
2196 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2198 error = calendar_db_get_record(_calendar_book._uri, cid, &calendar_book);
2199 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_db_get_record() is failed(%x)", error);
2202 error = calendar_record_get_int(record, _calendar_book.id, &cid);
2203 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_int() is failed(%x)", error);
2205 if (!CAL_STRCMP(part,"elm.text.1")) {
2207 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2208 return strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2209 else if (cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2210 return strdup(C_("IDS_TASK_BODY_MY_TASK"));
2212 error = calendar_record_get_str(calendar_book, _calendar_book.name, &name);
2213 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2215 if (record != calendar_book) {
2216 error = calendar_record_destroy(calendar_book, true);
2217 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2220 if (CAL_STRLEN(name))
2225 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2227 } else if (!CAL_STRCMP(part,"elm.text.2")) {
2229 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2230 return strdup(C_("IDS_CLD_POP_MY_PHONE"));
2232 error = calendar_record_get_str(calendar_book, _calendar_book.description, &description);
2233 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_get_str() is failed(%x)", error);
2235 if (record != calendar_book) {
2236 error = calendar_record_destroy(calendar_book, true);
2237 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_record_destroy() is failed(%x)", error);
2240 if (CAL_STRLEN(description))
2243 CAL_FREE(description);
2245 return strdup(S_("IDS_COM_POP_NO_ACCOUNTS"));
2248 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2251 static Evas_Object* __cal_edit_ug_add_save_to_icon(void *item_data, Evas_Object *obj, const char *part)
2255 ERR("item_data is null");
2259 Evas_Object *icon = NULL;
2260 char* icon_path = NULL;
2261 calendar_record_h record = (calendar_record_h)item_data;
2262 Eina_Bool r = EINA_FALSE;
2263 int cid = _calendar_get_calendar_index(record);
2264 int aid = _calendar_get_account_id(record);
2266 if (!CAL_STRCMP(part, "elm.icon"))
2268 icon = elm_icon_add(obj);
2272 ERR("elm_icon_add fail");
2276 if ( cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID) {
2277 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
2278 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2280 icon_path = cal_account_svc_get_account_icon_path(aid);
2282 r = elm_icon_file_set(icon, icon_path, NULL);
2283 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2287 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
2288 c_warn_if(!r, "elm_icon_file_set(%s) is failed", CAL_IMAGES_PHONE);
2295 evas_object_del(icon);
2299 evas_object_show(icon);
2305 static Eina_Bool __cal_edit_ug_popup_idler_callback(void *data)
2307 c_retv_if(!data, ECORE_CALLBACK_CANCEL);
2309 cal_edit_ug_data *p = data;
2312 evas_object_del(p->popup);
2318 return ECORE_CALLBACK_CANCEL;
2321 static void __cal_edit_ug_save_to_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2325 c_retm_if(!data, "data is null");
2326 c_retm_if(!obj, "obj is null");
2328 calendar_record_h calendar_book = data;
2329 int calendar_book_id = 0;
2331 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2332 c_retm_if(!p, "p is null");
2334 Elm_Object_Item *item = elm_genlist_selected_item_get(obj);
2335 c_retm_if(!item, "elm_genlist_selected_item_get() returned null");
2337 elm_genlist_item_selected_set(item, EINA_FALSE);
2339 calendar_error_e error = CALENDAR_ERROR_NONE;
2341 error = calendar_record_get_int(calendar_book, _calendar_book.id, &calendar_book_id);
2342 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2344 if (p->item_type == ITEM_TYPE_TODO) {
2345 __cal_edit_ug_set_record_save_to(p->todo, calendar_book_id);
2346 __cal_edit_ug_update_save_to_item(p, p->todo);
2349 __cal_edit_ug_set_record_save_to(p->event, calendar_book_id);
2350 __cal_edit_ug_update_save_to_item(p, p->event);
2354 ecore_idler_del(p->idler);
2358 p->idler = ecore_idler_add(__cal_edit_ug_popup_idler_callback, p);
2359 c_ret_if(!p->idler);
2363 static Elm_Genlist_Item_Class itc_2text_1icon_2 = {
2364 .item_style = "dialogue/2text.1icon.2",
2365 .func.text_get = __cal_edit_ug_get_genlist_save_to_item_label,
2366 .func.content_get = __cal_edit_ug_add_save_to_icon,
2369 static Evas_Object* __cal_edit_ug_create_save_to_popup(cal_edit_ug_data* p)
2371 c_retv_if(!p, NULL);
2373 Evas_Object *popup = NULL;
2374 Evas_Object *genlist = NULL;
2378 calendar_error_e error = CALENDAR_ERROR_NONE;
2380 if (!p->calendar_book_list)
2382 p->calendar_book_list = _calendar_get_calendar_book_list_with_account_id(_CALENDAR_ALL_ACCOUNT_ID);
2385 popup = cal_util_add_popup(p->window, "liststyle", C_("IDS_ST_BODY_SAVE_TO"), NULL,
2386 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2387 c_retvm_if(!popup, NULL, "popup is null");
2389 genlist = elm_genlist_add(popup);
2391 ERR("elm_genlist_add(popup) returned null");
2392 evas_object_del(popup);
2396 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2397 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2398 evas_object_data_set(genlist, "priv", p);
2400 calendar_record_h calendar_book = NULL;
2402 EINA_LIST_FOREACH(p->calendar_book_list, l, calendar_book) {
2406 error = calendar_record_get_int(calendar_book, _calendar_book.store_type, &store_type);
2407 if (error != CALENDAR_ERROR_NONE) {
2408 ERR("calendar_record_get_int() is failed(%x)", calendar_book);
2413 error = calendar_record_get_int(calendar_book, _calendar_book.sync_event, &sync_event);
2414 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2418 if (p->item_type == ITEM_TYPE_TODO) {
2419 if (store_type == CALENDAR_BOOK_TYPE_TODO)
2420 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);
2422 if (store_type == CALENDAR_BOOK_TYPE_EVENT)
2423 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);
2428 elm_object_content_set(popup, genlist);
2429 evas_object_show(genlist);
2434 static void __cal_edit_ug_saveto_select_callback(Evas_Object *obj, void *data)
2436 c_retm_if(!data, "data is null");
2438 cal_edit_ug_data* p = data;
2439 Evas_Object *popup = __cal_edit_ug_create_save_to_popup(p);
2440 c_retm_if(!popup, "popup is NULL");
2445 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz)
2447 calendar_record_h calendar_book = NULL;
2450 calendar_error_e error = CALENDAR_ERROR_NONE;
2452 error = calendar_db_get_record(_calendar_book._uri, calid, &calendar_book);
2453 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
2455 if (calid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2456 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
2459 error = calendar_record_get_str(calendar_book, _calendar_book.name, &str);
2460 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
2464 snprintf(buf, sz, "%s", str);
2469 error = calendar_record_destroy(calendar_book, true);
2470 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2473 static void __cal_edit_ug_update_saveto_language(Evas_Object *item, calendar_record_h record)
2477 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2479 int calendar_book_id = _calendar_get_calendar_index(record);
2481 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2482 elm_object_part_text_set(item, "elm.text.1", C_("IDS_CLD_BODY_MY_CALENDAR"));
2483 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2484 elm_object_part_text_set(item, "elm.text.1", C_("IDS_TASK_BODY_MY_TASK"));
2487 static Evas_Object *__cal_edit_ug_add_saveto(cal_edit_ug_data* p)
2489 c_retv_if(!p, NULL);
2491 Evas_Object *item = cal_dialogue_append_item(p->dialogue, "2text.2", __cal_edit_ug_saveto_select_callback, p);
2492 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2494 elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2497 char* saveto_text = NULL;
2498 int calendar_book_id = 0;
2499 if(p->item_type == ITEM_TYPE_TODO) {
2500 calendar_book_id = _calendar_get_calendar_index(p->todo);
2501 p->account_id = _calendar_get_account_id(p->todo);
2504 calendar_book_id = _calendar_get_calendar_index(p->event);
2505 p->account_id = _calendar_get_account_id(p->event);
2507 if (calendar_book_id == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2508 saveto_text = strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
2509 else if (calendar_book_id == DEFAULT_TODO_CALENDAR_BOOK_ID)
2510 saveto_text = strdup(C_("IDS_TASK_BODY_MY_TASK"));
2512 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
2513 saveto_text = strdup(buf);
2516 elm_object_part_text_set(item, "elm.text.1", saveto_text);
2517 CAL_FREE(saveto_text);
2520 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2525 static void __cal_edit_ug_no_due_date_clicked_callback(Evas_Object *obj, void *data)
2527 c_retm_if(!data, "data is NULL.");
2528 c_retm_if(!obj, "obj is NULL.");
2530 cal_edit_ug_data *p = data;
2532 Evas_Object *check_obj = elm_object_part_content_get(p->no_due_date, "elm.icon");
2534 if(p->is_no_due_date)
2536 elm_check_state_set(check_obj, EINA_FALSE);
2537 p->is_no_due_date = elm_check_state_get(check_obj);
2538 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2542 elm_check_state_set(check_obj, EINA_TRUE);
2543 p->is_no_due_date = elm_check_state_get(check_obj);
2544 __cal_edit_ug_set_record_due_time(p, p->todo);
2545 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2548 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2549 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2552 static void __cal_edit_ug_no_due_date_changed_callback(void *data, Evas_Object *obj, void *ei)
2554 c_retm_if(!data, "data is NULL.");
2555 c_retm_if(!obj, "obj is NULL.");
2557 cal_edit_ug_data *p = data;
2559 p->is_no_due_date = elm_check_state_get(obj);
2561 Evas_Object *edit_time_obj = elm_object_part_content_get(p->due_date, "elm.icon");
2562 elm_object_disabled_set(edit_time_obj, p->is_no_due_date);
2563 if(p->is_no_due_date)
2565 __cal_edit_ug_set_record_due_time(p, p->todo);
2566 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2570 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2574 static void __cal_edit_ug_update_no_due_date_language(Evas_Object *item)
2576 elm_object_part_text_set(item, "elm.text", C_("IDS_TASK_MBODY_NO_DUE_DATE"));
2579 static Evas_Object *__cal_edit_ug_add_no_due_date(cal_edit_ug_data* p)
2581 c_retv_if(!p, NULL);
2583 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);
2584 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2586 Evas_Object *check_obj;
2587 check_obj = elm_check_add(item);
2588 __cal_edit_ug_get_record_due_time(p, p->todo);
2589 elm_check_state_set(check_obj, p->is_no_due_date);
2591 evas_object_smart_callback_add(check_obj, "changed", __cal_edit_ug_no_due_date_changed_callback, p);
2592 elm_check_state_set(check_obj, p->is_no_due_date);
2593 evas_object_propagate_events_set(check_obj, EINA_FALSE);
2595 __cal_edit_ug_update_no_due_date_language(item);
2597 elm_object_part_content_set(item, "elm.icon", check_obj);
2602 static void __cal_edit_ug_priority_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2607 int priority = (int)data;
2609 cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2612 __cal_edit_ug_set_record_priority(p->todo, priority);
2613 __cal_edit_ug_update_priority_item(p, p->todo);
2615 evas_object_del(p->popup);
2619 static Evas_Object* __cal_edit_ug_create_priority_popup(cal_edit_ug_data* p)
2621 c_retv_if(!p, NULL);
2623 Evas_Object *popup = cal_util_add_popup(p->window, NULL, C_("IDS_CLD_BODY_PRIORITY"), NULL,
2624 __cal_edit_ug_popup_hide_callback, p, S_("IDS_COM_BODY_CLOSE"), NULL);
2625 c_retv_if(!popup, NULL);
2627 evas_object_data_set(popup, "priv", p);
2629 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);
2630 c_retv_if(!popup_item, NULL);
2632 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);
2633 c_retv_if(!popup_item, NULL);
2635 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);
2636 c_retv_if(!popup_item, NULL);
2641 static void __cal_edit_ug_priority_select_callback(Evas_Object *obj, void *data)
2643 c_retm_if(!data, "data is null");
2644 cal_edit_ug_data* p = data;
2646 Evas_Object *popup = __cal_edit_ug_create_priority_popup(p);
2647 c_retm_if(!popup, "popup is NULL");
2653 static void __cal_edit_ug_update_priority_language(Evas_Object *item, calendar_record_h record)
2655 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_PRIORITY"));
2657 char* priority_text = NULL;
2658 int priority = __cal_edit_ug_get_record_priority(record);
2660 case CALENDAR_TODO_PRIORITY_LOW:
2661 priority_text = strdup(S_("IDS_COM_BODY_LOW"));
2663 case CALENDAR_TODO_PRIORITY_NORMAL:
2664 priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
2666 case CALENDAR_TODO_PRIORITY_HIGH:
2667 priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
2673 elm_object_part_text_set(item, "elm.text.1", priority_text);
2674 CAL_FREE(priority_text);
2677 static Evas_Object *__cal_edit_ug_add_priority(cal_edit_ug_data* p)
2679 c_retv_if(!p, NULL);
2681 Evas_Object *item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", p->no_due_date, __cal_edit_ug_priority_select_callback, p);
2682 c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2684 __cal_edit_ug_update_priority_language(item, p->todo);
2689 static void __cal_edit_ug_show_result_popup(cal_edit_ug_data *p, calendar_error_e error)
2695 case CALENDAR_ERROR_DB_FAILED:
2696 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2697 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2700 case CALENDAR_ERROR_OUT_OF_MEMORY:
2701 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_CALENDAR_SYNC_IN_PROGRESS"),
2702 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2705 case CALENDAR_ERROR_INVALID_PARAMETER:
2706 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_INVALID_TIME"),
2707 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2711 snprintf(buf,100,"not saved(internal error-%x)!",error);
2712 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), buf,
2713 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2718 int __cal_edit_ug_save(cal_edit_ug_data *p, calendar_record_h record)
2722 calendar_error_e error = CALENDAR_ERROR_NONE;
2724 int record_index = 0;
2726 calendar_record_type_e record_type = CALENDAR_RECORD_TYPE_EVENT;
2728 if (_calendar_is_task_record(record))
2729 record_type = CALENDAR_RECORD_TYPE_TODO;
2731 __cal_edit_ug_set_record_alarm(p, record);
2733 if (p->is_edit_mode) {
2736 calendar_record_h exception_record = NULL;
2737 error = calendar_record_clone(record, &exception_record);
2738 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
2740 int index = _calendar_get_record_index(record);
2741 error = calendar_record_set_int(exception_record, _calendar_event.original_event_id, index);
2742 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
2744 __cal_edit_ug_set_record_time(p, exception_record);
2745 _calendar_edit_recurrence_instance(exception_record, index);
2747 error = calendar_db_insert_record(exception_record, &record_index);
2748 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_insert_record() is failed(%x)", error);
2750 if (error != CALENDAR_ERROR_NONE) {
2751 __cal_edit_ug_show_result_popup(p, error);
2753 error = calendar_record_destroy(exception_record, true);
2754 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2759 error = calendar_record_destroy(exception_record, true);
2760 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2764 if (p->account_id == _calendar_get_account_id(record))
2766 error = calendar_db_update_record(record);
2767 if (error != CALENDAR_ERROR_NONE) {
2769 ERR("calendar_db_update_record() is failed(%x)", error);
2771 __cal_edit_ug_show_result_popup(p, error);
2775 record_index = _calendar_get_record_index(record);
2779 _calendar_delete_record(record);
2781 error = calendar_db_insert_record(record, &record_index);
2782 if (error != CALENDAR_ERROR_NONE) {
2784 ERR("calendar_db_insert_record() is failed(%x)", error);
2785 __cal_edit_ug_show_result_popup(p, error);
2794 error = calendar_db_insert_record(record, &record_index);
2795 if (error != CALENDAR_ERROR_NONE) {
2797 ERR("calendar_db_insert_record() is failed(%x)", error);
2799 __cal_edit_ug_show_result_popup(p, error);
2805 return record_index;
2808 static void __cal_edit_ug_send_result_to_detail_ug(cal_edit_ug_data *p, int record_index)
2810 c_retm_if(!p, "p is null");
2811 c_retm_if(record_index < 0, "record_index < 0");
2813 service_h service = NULL;
2815 int ret = service_create(&service);
2816 c_ret_if(ret != SERVICE_ERROR_NONE);
2818 char value[64] = {0};
2819 snprintf(value, sizeof(value), "%d", record_index);
2821 ret = service_add_extra_data(service, "record_index", value);
2822 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2824 memset(value, 0x00, sizeof(value));
2826 long long int lli_time = 0;
2827 cal_util_convert_tm_to_lli(NULL, &p->stm, &lli_time);
2829 snprintf(value, sizeof(value), "%lli", lli_time);
2831 ret = service_add_extra_data(service, "base_time", value);
2832 c_warn_if(ret != SERVICE_ERROR_NONE, "service_add_extra_data() is failed(%x)", ret);
2834 ug_send_result(p->ug, service);
2836 ret = service_destroy(service);
2837 c_warn_if(ret != SERVICE_ERROR_NONE, "service_destroy() is failed(%x)", ret);
2840 static void __cal_edit_ug_save_button_callback(void *data, Evas_Object *obj, void *event_info)
2844 c_retm_if(!data, "data is null");
2845 cal_edit_ug_data* p = data;
2848 Eina_Bool result = __cal_edit_ug_check_date_validity(p);
2850 cal_util_add_popup(p->window, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_POP_END_TIME_SHOULD_BE_SET_AFTER_START_TIME"),
2851 __cal_edit_ug_reponse_event_callback, NULL, NULL);
2855 if (p->item_type == ITEM_TYPE_TODO)
2856 record_index = __cal_edit_ug_save(p, p->todo);
2858 record_index = __cal_edit_ug_save(p, p->event);
2860 c_retm_if(record_index < 0, "cal_edit_save() is failed");
2862 int r = notification_status_message_post(S_("IDS_COM_POP_SAVED"));
2863 c_warn_if(r != NOTIFICATION_ERROR_NONE, "notification_status_message_post() is failed(%d)", r);
2865 __cal_edit_ug_send_result_to_detail_ug(p, record_index);
2867 ug_destroy_me(p->ug);
2871 static Eina_Bool __cal_edit_ug_input_panel_is_shown(cal_edit_ug_data *p)
2873 c_retv_if(!p, EINA_FALSE);
2875 Ecore_IMF_Context* ic = NULL;
2876 ic = elm_entry_imf_context_get(p->title_entry);
2877 c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2879 if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
2880 ecore_imf_context_input_panel_hide(ic);
2884 ic = elm_entry_imf_context_get(p->note_entry);
2885 c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2887 if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
2888 ecore_imf_context_input_panel_hide(ic);
2892 ic = elm_entry_imf_context_get(p->location_entry);
2893 c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2895 if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
2896 ecore_imf_context_input_panel_hide(ic);
2900 if(p->multibuttonentry){
2901 ic = elm_entry_imf_context_get(elm_multibuttonentry_entry_get(p->multibuttonentry));
2902 c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2904 if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
2905 ecore_imf_context_input_panel_hide(ic);
2913 static void __cal_edit_ug_back_button_callback(void *user_data, Evas_Object *obj, void *ei)
2917 c_ret_if(!user_data);
2919 cal_edit_ug_data *data = user_data;
2921 c_ret_if(!data->ug);
2923 if(!__cal_edit_ug_input_panel_is_shown(data))
2924 ug_destroy_me(data->ug);
2927 static void __cal_edit_ug_show_multi_alarms (cal_edit_ug_data *p)
2929 c_retm_if(!p, "p is null");
2931 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2933 if(eina_list_count(p->alarm_item_list)<5){
2934 p->alarm_plus_button = __cal_edit_ug_alarm_plus_button_icon(p, first_item);
2935 elm_object_part_content_set(first_item, "elm.icon", p->alarm_plus_button);
2937 Eina_List *list = eina_list_next(p->alarm_item_list);
2939 Evas_Object *item = NULL;
2941 EINA_LIST_FOREACH(list, l, item) {
2943 cal_dialogue_show_item_after(p->dialogue, item, first_item);
2949 static void __cal_edit_ug_show_event_items (cal_edit_ug_data *p)
2951 c_retm_if(!p, "p is null");
2953 if (!p->start_date_title)
2954 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
2956 cal_dialogue_show_item_after(p->dialogue, p->start_date_title, p->title);
2958 Eina_Bool is_allday = EINA_FALSE;
2960 if (!p->start_date) {
2962 is_allday = _calendar_is_allday_record(p->event);
2964 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);
2967 cal_dialogue_show_item_after(p->dialogue, p->start_date, p->start_date_title);
2969 if (!p->end_date_title)
2970 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
2972 cal_dialogue_show_item_after(p->dialogue, p->end_date_title, p->start_date);
2975 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);
2977 cal_dialogue_show_item_after(p->dialogue, p->end_date, p->end_date_title);
2980 p->timezone = __cal_edit_ug_add_time_zone(p);
2982 cal_dialogue_show_item_after(p->dialogue, p->timezone, p->end_date);
2985 p->allday = __cal_edit_ug_add_all_day(p, is_allday);
2987 cal_dialogue_show_item_after(p->dialogue, p->allday, p->timezone);
2989 __cal_edit_ug_show_multi_alarms(p);
2991 Eina_List *list = eina_list_last(p->alarm_item_list);
2992 Evas_Object *last_item = eina_list_data_get(list);
2995 p->repeat = __cal_edit_ug_add_repeat(p);
2997 cal_dialogue_show_item_after(p->dialogue, p->repeat, last_item);
3001 static void __cal_edit_ug_show_todo_items (cal_edit_ug_data *p)
3003 c_retm_if(!p, "p is null");
3005 if (!p->due_date_title)
3006 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
3008 cal_dialogue_show_item_after(p->dialogue, p->due_date_title, p->title);
3011 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);
3013 cal_dialogue_show_item_after(p->dialogue, p->due_date, p->due_date_title);
3015 if (!p->no_due_date)
3016 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3018 cal_dialogue_show_item_after(p->dialogue, p->no_due_date, p->due_date);
3020 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
3022 p->priority = __cal_edit_ug_add_priority(p);
3024 cal_dialogue_show_item_after(p->dialogue, p->priority, first_item);
3027 static void __cal_edit_ug_hide_multi_alarms (cal_edit_ug_data *p)
3029 c_retm_if(!p, "p is null");
3031 Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
3032 Evas_Object *button_obj = elm_object_part_content_get(first_item, "elm.icon");
3034 evas_object_del(button_obj);
3038 Eina_List *list = p->alarm_item_list;
3039 list = eina_list_next(list);
3041 Evas_Object *item = NULL;
3043 EINA_LIST_FOREACH(list, l, item) {
3045 cal_dialogue_hide_item(p->dialogue, item);
3050 static void __cal_edit_ug_hide_event_items (cal_edit_ug_data *p)
3052 c_retm_if(!p, "p is null");
3054 cal_dialogue_hide_item(p->dialogue, p->start_date_title);
3055 cal_dialogue_hide_item(p->dialogue, p->start_date);
3056 cal_dialogue_hide_item(p->dialogue, p->end_date_title);
3057 cal_dialogue_hide_item(p->dialogue, p->end_date);
3058 cal_dialogue_hide_item(p->dialogue, p->allday);
3059 cal_dialogue_hide_item(p->dialogue, p->timezone);
3060 cal_dialogue_hide_item(p->dialogue, p->repeat);
3061 __cal_edit_ug_hide_multi_alarms(p);
3065 static void __cal_edit_ug_hide_todo_items (cal_edit_ug_data *p)
3067 c_retm_if(!p, "p is null");
3069 cal_dialogue_hide_item(p->dialogue, p->due_date_title);
3070 cal_dialogue_hide_item(p->dialogue, p->due_date);
3071 cal_dialogue_hide_item(p->dialogue, p->no_due_date);
3072 cal_dialogue_hide_item(p->dialogue, p->priority);
3076 static void __cal_edit_ug_update_event_info (cal_edit_ug_data *p)
3078 c_retm_if(!p, "p is null");
3080 __cal_edit_ug_update_title_item(p->title_entry, p->event);
3081 __cal_edit_ug_update_note_item(p->note_entry, p->event);
3082 __cal_edit_ug_update_location_item(p, p->event);
3084 __cal_edit_ug_update_save_to_item(p, p->event);
3087 static void __cal_edit_ug_update_todo_info (cal_edit_ug_data *p)
3089 c_retm_if(!p, "p is null");
3091 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
3092 __cal_edit_ug_update_note_item(p->note_entry, p->todo);
3093 __cal_edit_ug_update_location_item(p, p->todo);
3095 __cal_edit_ug_update_save_to_item(p, p->todo);
3099 static void __cal_edit_ug_new_event_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3103 c_retm_if(!data, "data null");
3105 cal_edit_ug_data *p = data;
3107 if(p->item_type == ITEM_TYPE_EVENT)
3110 p->item_type = ITEM_TYPE_EVENT;
3112 __cal_edit_ug_hide_todo_items(p);
3113 __cal_edit_ug_show_event_items(p);
3114 __cal_edit_ug_update_event_info(p);
3118 static void __cal_edit_ug_new_todo_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3122 c_retm_if(!data, "data null");
3124 cal_edit_ug_data *p = data;
3126 if(p->item_type == ITEM_TYPE_TODO)
3129 p->item_type = ITEM_TYPE_TODO;
3131 __cal_edit_ug_hide_event_items(p);
3132 __cal_edit_ug_show_todo_items(p);
3133 __cal_edit_ug_update_todo_info(p);
3137 static void __cal_edit_ug_add_dialogue_items(cal_edit_ug_data *p)
3141 c_retm_if(!p, "p is null");
3143 p->title = __cal_edit_ug_add_title(p);
3145 calendar_time_s time = {0};
3147 if (p->item_type == ITEM_TYPE_TODO) {
3149 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
3151 _calendar_get_end_time(p->todo, &time);
3152 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3153 // __cal_edit_ug_get_record_due_time(p, p->todo);
3155 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);
3157 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3159 p->priority = __cal_edit_ug_add_priority(p);
3162 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
3165 _calendar_get_start_time(p->instance, &time);
3167 _calendar_get_start_time(p->event, &time);
3169 _calendar_convert_calendar_time_to_tm(&time, &p->stm);
3170 Eina_Bool allday = _calendar_is_allday_record(p->event);
3172 p->start_date = __cal_edit_ug_insert_timepicker_after(p, &p->stm, allday, p->start_date_title, __cal_edit_ug_start_date_changed_callback);
3174 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
3177 _calendar_get_end_time(p->instance, &time);
3179 _calendar_get_end_time(p->event, &time);
3181 _calendar_convert_calendar_time_to_tm(&time, &p->etm);
3182 p->end_date = __cal_edit_ug_insert_timepicker_after(p, &p->etm, allday, p->end_date_title, __cal_edit_ug_end_date_changed_callback);
3184 p->timezone = __cal_edit_ug_add_time_zone(p);
3186 p->allday = __cal_edit_ug_add_all_day(p, allday);
3190 p->note = __cal_edit_ug_add_note(p);
3192 p->location = __cal_edit_ug_add_location(p);
3194 __cal_edit_ug_add_multi_alarm(p);
3196 if (p->item_type == ITEM_TYPE_EVENT) {
3197 p->repeat = __cal_edit_ug_add_repeat(p);
3200 p->saveto = __cal_edit_ug_add_saveto(p);
3203 static void __cal_edit_ug_update_naviframe_language(cal_edit_ug_data *data)
3205 c_ret_if(!data->naviframe);
3207 Elm_Object_Item *item = elm_naviframe_top_item_get(data->naviframe);
3210 if (data->is_edit_mode) {
3212 if (data->item_type == ITEM_TYPE_TODO)
3213 elm_object_item_part_text_set(item, "default", C_("IDS_TASK_HEADER_EDIT_TASK"));
3215 elm_object_item_part_text_set(item, "default", C_("IDS_CLD_HEADER_EDIT_EVENT"));
3218 elm_object_item_part_text_set(item, "default", S_("IDS_COM_BODY_CREATE"));
3221 static void __cal_edit_ug_update_tabbar_language(cal_edit_ug_data *data)
3223 if (data->is_edit_mode)
3226 c_ret_if(!data->event_item);
3227 c_ret_if(!data->todo_item);
3229 elm_object_item_part_text_set(data->event_item, "default", C_("IDS_CLD_SK3_CREATE_EVENT"));
3230 elm_object_item_part_text_set(data->todo_item, "default", C_("IDS_TASK_SK_CREATE_TASK"));
3233 static void __cal_edit_ug_add_toolbar(cal_edit_ug_data *data, Evas_Object *scroller)
3237 c_retm_if(!data, "data is null");
3239 Elm_Object_Item *navi_item = NULL;
3241 if (data->is_edit_mode) {
3242 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, NULL);
3243 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3245 navi_item = elm_naviframe_item_push(data->naviframe, NULL, NULL, NULL, scroller, "tabbar");
3246 c_warn_if(!navi_item, "elm_naviframe_item_push() is failed");
3248 data->tabbar = elm_toolbar_add(data->naviframe);
3249 c_ret_if(!data->tabbar);
3251 elm_object_item_part_content_set(navi_item, "tabbar", data->tabbar);
3252 elm_toolbar_reorder_mode_set(data->tabbar, EINA_FALSE);
3253 elm_toolbar_transverse_expanded_set(data->tabbar, EINA_TRUE);
3254 elm_toolbar_shrink_mode_set(data->tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
3255 elm_object_style_set(data->tabbar, "tabbar");
3257 if (data->item_type == ITEM_TYPE_TODO) {
3258 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3260 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3262 data->event_item = elm_toolbar_item_insert_before(data->tabbar, data->todo_item, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3264 data->event_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3265 data->todo_item = elm_toolbar_item_append(data->tabbar, NULL, NULL, __cal_edit_ug_new_todo_clicked_callback, data);
3267 elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3270 if (data->item_type == ITEM_TYPE_TODO)
3271 elm_toolbar_item_selected_set(data->todo_item, EINA_TRUE);
3273 elm_toolbar_item_selected_set(data->event_item, EINA_TRUE);
3275 __cal_edit_ug_update_tabbar_language(data);
3279 __cal_edit_ug_update_naviframe_language(data);
3281 data->save_cancel = cal_save_cancel_create(data->window, data->conformant, data->naviframe, __cal_edit_ug_save_button_callback, __cal_edit_ug_back_button_callback, data);
3285 static void __cal_edit_ug_dialogue_item_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
3290 cal_edit_ug_data* p = data;
3293 static Evas_Object *__cal_edit_ug_create_dialogue(Evas_Object *parent, cal_edit_ug_data* p)
3295 c_retv_if(!p, NULL);
3297 Evas_Object *scroller = cal_dialogue_create(parent);
3298 c_retvm_if(!scroller, NULL, "cal_dialogue_create() is failed");
3299 __cal_edit_ug_add_toolbar(p, scroller);
3301 Evas_Object *dialogue = cal_dialogue_get_box(scroller);
3303 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_UP, __cal_edit_ug_dialogue_item_clicked_callback, p);
3304 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_DOWN, __cal_edit_ug_dialogue_item_clicked_callback, p);
3305 evas_object_event_callback_add(dialogue, EVAS_CALLBACK_MOUSE_MOVE, __cal_edit_ug_dialogue_item_clicked_callback, p);
3311 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, cal_edit_ug_data *data)
3315 c_retv_if(!parent, NULL);
3316 c_retv_if(!data, NULL);
3318 data->parent = parent;
3320 if (data->item_type == ITEM_TYPE_TODO)
3321 data->todo = data->record;
3323 data->event = data->record;
3325 if (data->is_edit_mode) {
3326 __cal_edit_ug_get_record_time_zone(data, data->record);
3328 cal_util_get_timezone(&data->timezone_path, &data->timezone_city, &data->timezone_offset);
3330 __cal_edit_ug_initialize_todo_record(data);
3331 __cal_edit_ug_initialize_event_record(data);
3334 Evas_Object *base_layout = cal_util_add_layout(parent, NULL);
3335 c_retv_if(!base_layout, NULL);
3337 Evas_Object *naviframe = elm_naviframe_add(base_layout);
3339 ERR("elm_naviframe_add() is failed");
3341 evas_object_del(base_layout);
3346 evas_object_show(naviframe);
3348 Evas_Object *bg = cal_util_add_bg(base_layout, EINA_FALSE);
3350 ERR("cal_util_add_bg() is failed");
3352 evas_object_del(base_layout);
3357 data->base_layout = base_layout;
3358 data->naviframe = naviframe;
3360 cal_util_initialize_timezone();
3362 data->dialogue = __cal_edit_ug_create_dialogue(naviframe, data);
3363 c_warn_if(!data->dialogue, "__cal_edit_ug_create_dialogue() is failed");
3365 __cal_edit_ug_add_dialogue_items(data);
3368 elm_object_part_content_set(base_layout, "elm.swallow.content", naviframe);
3369 elm_object_part_content_set(base_layout, "elm.swallow.bg", bg);
3374 static calendar_record_h inline __cal_edit_ug_get_origin_record(const calendar_record_h instance)
3378 c_retv_if(!instance, NULL);
3380 int index = _calendar_get_record_index(instance);
3382 return _calendar_get_record_with_index(index);
3385 static void __cal_edit_ug_get_appcontrol_input_data(service_h service, cal_edit_ug_data *data)
3391 char *item_type = NULL;
3393 r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
3394 c_ret_if(r != SERVICE_ERROR_NONE);
3396 if (CAL_STRCMP(CAL_APPCONTROL_ITEM_TYPE_EVENT, item_type)
3397 && CAL_STRCMP(CAL_APPCONTROL_ITEM_TYPE_TODO, item_type)) {
3398 ERR("Invaild input : %s, %s", CAL_APPCONTROL_ITEM_TYPE, item_type);
3400 CAL_FREE(item_type);
3405 CAL_FREE(item_type);
3407 r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_ID, &index);
3408 if (r != SERVICE_ERROR_NONE) {
3409 ERR("service_get_extra_data(%s) is failed(%x)", "eventId", r);
3416 data->is_edit_mode = EINA_TRUE;
3417 data->record = _calendar_get_record_with_index(atoi(index));
3419 if (_calendar_is_task_record(data->record))
3420 data->item_type == ITEM_TYPE_TODO;
3422 data->item_type == ITEM_TYPE_EVENT;
3425 static void __cal_edit_ug_get_appcontrol_input_data_old(service_h service, cal_edit_ug_data *data)
3431 char *item_type = NULL;
3433 r = service_get_extra_data(service, "itemType", &item_type);
3434 if (r == SERVICE_ERROR_NONE) {
3436 if (!CAL_STRCMP(item_type, "event")) {
3437 data->item_type = ITEM_TYPE_EVENT;
3438 data->is_edit_mode = EINA_TRUE;
3442 r = service_get_extra_data(service, "eventId", &index);
3443 if (r != SERVICE_ERROR_NONE) {
3444 ERR("service_get_extra_data(%s) is failed(%x)", "eventId", r);
3451 calendar_record_h record = _calendar_get_record_with_index(atoi(index));
3452 c_retv_if(!record, NULL);
3456 data->record = record;
3458 } else if (!CAL_STRCMP(item_type, "todo")) {
3460 data->item_type = ITEM_TYPE_TODO;
3461 data->is_edit_mode = EINA_TRUE;
3465 r = service_get_extra_data(service, "todoId", &index);
3466 if (r != SERVICE_ERROR_NONE) {
3467 ERR("service_get_extra_data(%s) is failed(%x)", "todoId", r);
3474 calendar_record_h record = _calendar_get_record_with_index(atoi(index));
3475 c_retv_if(!record, NULL);
3479 data->record = record;
3481 } else if (!CAL_STRCMP(item_type, "vcs")) {
3483 data->item_type = ITEM_TYPE_VCS;
3487 r = service_get_extra_data(service, "path", &path);
3488 if (r != SERVICE_ERROR_NONE) {
3489 ERR("service_get_extra_data(%s) is failed(%x)", "path", r);
3496 FILE * file = fopen(path, "r");
3498 ERR("fopen(%s) is failed.", path);
3505 struct stat st = {0};
3506 if (stat(path, &st) != 0) {
3507 ERR("Getting file information Error!");
3516 int size = st.st_size;
3517 char *raw_data = calloc(size + 1, sizeof(char));
3519 ERR("raw_data is NULL!");
3526 r = fread(raw_data, 1, size, file);
3529 ERR("fread() is failed(%d)", errno);
3534 calendar_list_h list = NULL;
3536 calendar_error_e error = CALENDAR_ERROR_NONE;
3538 error = calendar_vcalendar_parse_to_calendar(raw_data, &list);
3539 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_parse_to_calendar() is failed(%x)", error);
3542 calendar_record_h record = NULL;
3543 error = calendar_list_get_current_record_p(list, &record);
3544 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
3546 error = calendar_record_clone(record, &data->record);
3547 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
3549 error = calendar_list_destroy(list, true);
3556 CAL_FREE(item_type);
3559 static void __cal_edit_ug_get_ug_input_data(service_h service, cal_edit_ug_data *data)
3567 r = service_get_extra_data(service, "index", &index);
3568 if (r == SERVICE_ERROR_NONE) {
3569 data->record = _calendar_get_record_with_index(atoi(index));
3570 data->is_edit_mode = EINA_TRUE;
3573 char *record_address = NULL;
3575 r = service_get_extra_data(service, "record", &record_address);
3576 if (CAL_STRLEN(record_address)) {
3577 data->record = (calendar_record_h)strtoul(record_address, NULL, 16);
3579 if (0 < _calendar_get_record_index(data->record))
3580 data->is_edit_mode = EINA_TRUE;
3582 _calendar_record_type record_type = _calendar_get_record_type(data->record);
3584 if (record_type != _CALENDAR_RECORD_TYPE_EVENT && record_type != _CALENDAR_RECORD_TYPE_TODO && record_type != _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR) {
3585 data->instance = data->record;
3587 data->record = __cal_edit_ug_get_origin_record(data->instance);
3590 if (_calendar_is_task_record(data->record))
3591 data->item_type = ITEM_TYPE_TODO;
3593 data->item_type = ITEM_TYPE_EVENT;
3595 calendar_error_e error = CALENDAR_ERROR_NONE;
3597 error = calendar_record_create(_calendar_event._uri, &data->record);
3598 c_retm_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
3600 data->is_edit_mode = EINA_FALSE;
3602 data->item_type = ITEM_TYPE_EVENT;
3605 CAL_FREE(record_address);
3608 char *base_time = NULL;
3610 r = service_get_extra_data(service, "base_time", &base_time);
3611 c_warn_if(SERVICE_ERROR_NONE != r,"service_get_extra_data is failed(%d).", r);
3614 long long int lli_time = strtoll(base_time, NULL, 10);
3615 cal_util_convert_lli_to_tm(NULL, lli_time, &data->base_time);
3620 struct tm* returned_tm = NULL;
3625 returned_tm = gmtime_r(&now, &t);
3627 ERR("localtime_r is failed.");
3629 CAL_MEMCPY(&data->base_time, &t, struct tm);
3633 static void *__cal_edit_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
3637 c_retv_if(!ug, NULL);
3638 c_retv_if(!service, NULL);
3639 c_retv_if(!priv, NULL);
3640 c_retv_if(mode != UG_MODE_FULLVIEW, NULL);
3642 cal_edit_ug_data *data = priv;
3646 char *operation = NULL;
3648 int r = service_get_operation(service, &operation);
3649 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
3651 if (!CAL_STRCMP(operation, CAL_APPCONTROL_SOCAIL_EDIT))
3652 __cal_edit_ug_get_appcontrol_input_data(service, data);
3653 else if (!CAL_STRCMP(operation, SERVICE_OPERATION_EDIT))
3654 __cal_edit_ug_get_appcontrol_input_data_old(service, data);
3656 __cal_edit_ug_get_ug_input_data(service, data);
3658 CAL_FREE(operation);
3660 if (!data->record) {
3661 ERR("ERROR!! Invaild parameter!!");
3665 Evas_Object *parent = ug_get_parent_layout(ug);
3666 c_retv_if(!parent, NULL);
3668 data->window = ug_get_window();
3669 c_retv_if(!data->window, NULL);
3671 data->conformant = ug_get_conformant();
3672 if (!data->conformant) {
3673 data->conformant = elm_conformant_add(data->window);
3674 c_retv_if(!data->conformant, NULL);
3676 evas_object_size_hint_weight_set(data->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3677 elm_win_resize_object_add(data->window, data->conformant);
3678 evas_object_show(data->conformant);
3681 data->theme = elm_theme_new();
3682 c_retv_if(!data->theme, NULL);
3684 elm_theme_ref_set(data->theme, NULL);
3686 elm_theme_extension_add(data->theme, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme.edj");
3687 elm_theme_extension_add(data->theme, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme2.edj");
3689 Evas_Object *base = __cal_edit_ug_create_layout(parent, data);
3690 c_retv_if(!base, NULL);
3695 static void __cal_edit_ug_destroy_callback(ui_gadget_h ug, service_h service, void *priv)
3700 cal_edit_ug_data *data = priv;
3702 if (data->save_cancel)
3703 cal_save_cancel_destroy(data->save_cancel);
3705 cal_util_delete_evas_object(&data->base_layout);
3707 if (data->timezone_city)
3708 free(data->timezone_city);
3709 if (data->timezone_path)
3710 free(data->timezone_path);
3711 if (data->timezone_offset)
3712 free(data->timezone_offset);
3714 _calendar_free_record_list(&data->calendar_book_list);
3716 if (data->alarm_list) {
3717 g_list_free(data->alarm_list);
3718 data->alarm_list = NULL;
3721 if (data->alarm_item_list) {
3722 eina_list_free(data->alarm_item_list);
3723 data->alarm_item_list = NULL;
3726 CAL_FREE(data->title_str);
3727 CAL_FREE(data->address);
3728 CAL_FREE(data->note_str);
3731 evas_object_del(data->tabbar);
3734 calendar_record_destroy(data->event, true);
3737 calendar_record_destroy(data->todo, true);
3740 calendar_record_destroy(data->instance, true);
3742 elm_theme_extension_del(data->theme, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme.edj");
3743 elm_theme_extension_del(data->theme, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme2.edj");
3745 elm_theme_free(data->theme);
3749 static void __cal_edit_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
3753 DBG("UG: key event %d", evt);
3756 case UG_KEY_EVENT_END:
3764 static void __cal_edit_ug_update_language(cal_edit_ug_data *data)
3768 __cal_edit_ug_update_naviframe_language(data);
3770 __cal_edit_ug_update_tabbar_language(data);
3772 cal_save_cancel_set_button_text(data->save_cancel, S_("IDS_COM_OPT_SAVE"), NULL);
3774 __cal_edit_ug_update_title_language(data->title);
3776 if (data->item_type == ITEM_TYPE_EVENT) {
3778 __cal_edit_ug_update_start_language(data->start_date_title);
3780 __cal_edit_ug_update_end_language(data->end_date_title);
3782 __cal_edit_ug_update_due_language(data->due_date_title);
3784 __cal_edit_ug_update_time_zone_language(data->timezone, data->timezone_city, data->timezone_offset);
3786 if (data->item_type == ITEM_TYPE_TODO) {
3788 __cal_edit_ug_update_no_due_date_language(data->no_due_date);
3790 __cal_edit_ug_update_priority_language(data->priority, data->todo);
3793 if (data->item_type == ITEM_TYPE_EVENT)
3794 __cal_edit_ug_update_allday_language(data->allday);
3796 __cal_edit_ug_update_description_language(data->note);
3798 __cal_edit_ug_update_location_language(data->location);
3800 __cal_edit_ug_update_reminder_language(data->alarm_item_list);
3802 if (data->item_type == ITEM_TYPE_EVENT)
3803 __cal_edit_ug_update_recurrence_language(data->repeat, data->repeat_freq);
3805 if (data->item_type == ITEM_TYPE_EVENT)
3806 __cal_edit_ug_update_saveto_language(data->saveto, data->event);
3808 __cal_edit_ug_update_saveto_language(data->saveto, data->todo);
3811 static void __cal_edit_ug_update_region(cal_edit_ug_data *data)
3815 if (data->item_type == ITEM_TYPE_EVENT) {
3817 Eina_Bool is_allday = _calendar_is_allday_record(data->event);
3819 __cal_edit_ug_update_datetime_region(data->start_date, &data->stm, is_allday, __cal_edit_ug_start_date_changed_callback, data);
3821 __cal_edit_ug_update_datetime_region(data->end_date, &data->etm, is_allday, __cal_edit_ug_end_date_changed_callback, data);
3824 __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);
3827 static void __cal_edit_ug_event_callback(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
3833 case UG_EVENT_LANG_CHANGE:
3834 __cal_edit_ug_update_language((cal_edit_ug_data *)priv);
3836 case UG_EVENT_REGION_CHANGE:
3837 __cal_edit_ug_update_region((cal_edit_ug_data *)priv);
3844 API int UG_MODULE_INIT(struct ug_module_ops *ops)
3848 c_retv_if(!ops, -1);
3850 cal_edit_ug_data *data = calloc(1, sizeof(cal_edit_ug_data));
3852 ops->create = __cal_edit_ug_create_callback;
3853 ops->destroy = __cal_edit_ug_destroy_callback;
3854 ops->key_event = __cal_edit_ug_key_callback;
3855 ops->event = __cal_edit_ug_event_callback;
3857 ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
3859 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
3860 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
3862 __cal_edit_ug_initialize(data);
3867 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
3873 cal_edit_ug_data *data = ops->priv;
3875 __cal_edit_ug_finish(data);