[misc] Sync from master branch.
[apps/core/preloaded/calendar.git] / ug / edit / edit-ug.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
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
8   *
9   *       http://floralicense.org/license/
10   *
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.
16   */
17
18 #include <ui-gadget-module.h>
19 #include <vconf.h>
20 #include <libintl.h>
21
22 #include "view.h"
23 #include "dialogue.h"
24 #include "edit-alarm.h"
25 #include "edit-repeat.h"
26 #include "reminder.h"
27 #include "acct-svc.h"
28 #include "gi-timepicker.h"
29 #include "save-cancel.h"
30 #include "external-ug.h"
31 #include "cld-images.h"
32 #include "dialogue.h"
33 #include "appcontrol.h"
34
35 #define INVALID_TIMEZONE_VALUE (100)
36 #define CAL_EDIT_UG_MAX_ATTACHMENT_COUNT 6
37
38 typedef struct {
39
40         Elm_Theme *theme;
41
42         ui_gadget_h ug;
43         cal_appcontrol_item_type item_type;
44
45         struct tm base_time;
46         Evas_Object *base_layout;
47         Evas_Object *naviframe;
48         Evas_Object *window;
49         Evas_Object *conformant;
50
51         Evas_Object *parent;
52         Evas_Object *popup;
53         Ecore_Idler *idler;
54
55         calendar_record_h event;
56         calendar_record_h todo;
57         calendar_record_h record;
58         calendar_record_h instance;
59
60         Eina_Bool is_edit_mode;
61
62         Evas_Object *dialogue;
63
64         Evas_Object *title_entry;
65         Evas_Object *title;
66         Evas_Object *start_date;
67         Evas_Object *start_date_title;
68         Evas_Object *end_date;
69         Evas_Object *end_date_title;
70         Evas_Object *allday;
71         Evas_Object *timezone;
72         Evas_Object *location;
73         Evas_Object *location_entry;
74
75         Evas_Object *note;
76         Evas_Object *note_entry;
77         Eina_List *alarm_item_list;
78         Evas_Object *alarm_plus_button;
79
80         Evas_Object *repeat;
81         Evas_Object *repeat_layout;
82
83         Evas_Object *saveto;
84
85         Evas_Object *multibuttonentry; // entry participants
86
87         Evas_Object *due_date;
88         Evas_Object *due_date_title;
89         Evas_Object *no_due_date;
90         Evas_Object *priority;
91
92         cal_save_cancel_h save_cancel;
93         Evas_Object *tabbar;
94
95         int repeat_freq; // repeat_freq off, daily, ...
96         calendar_range_type_e repeat_range;
97         int repeat_count;
98         struct tm repeat_until;
99
100         GList  *alarm_list;
101
102         int account_id;
103
104         ui_gadget_h ug_worldclock;
105
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 */
110
111         Eina_List *calendar_book_list; //For save to
112
113         Elm_Object_Item *event_item;
114         Elm_Object_Item *todo_item;
115
116         char *title_str;
117         char *address;
118         double latitude;
119         double longitude;
120         char *note_str;
121
122         struct tm stm; // start
123         struct tm etm; // end
124
125         Eina_Bool is_no_due_date;
126
127 }cal_edit_ug_data;
128
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,
137         CAL_EDIT_WDAY_NODAY,
138 };
139
140 static int __cal_edit_ug_initialize(cal_edit_ug_data *data)
141 {
142         CAL_FN_START;
143
144         c_retv_if(!data, -1);
145
146         calendar_error_e error = CALENDAR_ERROR_NONE;
147
148         error = calendar_connect();
149         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_connect() is failed(%x)", error);
150
151         _calendar_init_hash();
152
153         const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
154         c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
155
156         cal_util_connect_pattern_generator();
157
158         return 0;
159 }
160
161 static int __cal_edit_ug_finish(cal_edit_ug_data *data)
162 {
163         CAL_FN_START;
164
165         c_retv_if(!data, -1);
166
167         calendar_error_e error = CALENDAR_ERROR_NONE;
168
169         error = calendar_disconnect();
170         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
171
172         cal_util_disconnect_pattern_generator();
173
174         int ret = 0;
175
176         if(data->item_type == ITEM_TYPE_TODO)
177                 ret = vconf_set_int(CAL_VCONFKEY_CREATE_EVENT_MODE, 0);
178         else
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);
181
182         return 0;
183
184 }
185
186 static inline void __cal_edit_ug_set_record_title(calendar_record_h record, const char *title_str)
187 {
188         calendar_error_e error = CALENDAR_ERROR_NONE;
189
190         if (_calendar_is_task_record(record)) {
191                 error = calendar_record_set_str(record, _calendar_todo.summary, title_str);
192         } else {
193                 error = calendar_record_set_str(record, _calendar_event.summary, title_str);
194         }
195
196         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
197 }
198
199 static inline void __cal_edit_ug_set_record_location(calendar_record_h record, const char *address, double latitude, double longitude)
200 {
201         calendar_error_e error = CALENDAR_ERROR_NONE;
202
203         if (_calendar_is_task_record(record)) {
204
205                 if (CAL_STRLEN(address))
206                         error = calendar_record_set_str(record, _calendar_todo.location, address);
207                 else
208                         error = calendar_record_set_str(record, _calendar_todo.location, "");
209
210                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
211
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);
214
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);
217         } else {
218
219                 if (CAL_STRLEN(address))
220                         error = calendar_record_set_str(record, _calendar_event.location, address);
221                 else
222                         error = calendar_record_set_str(record, _calendar_event.location, "");
223
224                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
225
226
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);
229
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);
232         }
233 }
234
235 static inline void __cal_edit_ug_set_record_note(calendar_record_h record, const char *note_str)
236 {
237         calendar_error_e error = CALENDAR_ERROR_NONE;
238
239         if (_calendar_is_task_record(record))
240                 error = calendar_record_set_str(record, _calendar_todo.description, note_str);
241         else
242                 error = calendar_record_set_str(record, _calendar_event.description, note_str);
243
244         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
245 }
246
247 static void __cal_edit_ug_set_timezone(calendar_record_h record, const char *timezone_path, const char *timezone_city)
248 {
249         c_ret_if(!record);
250         c_ret_if(!CAL_STRLEN(timezone_path));
251         c_ret_if(!CAL_STRLEN(timezone_city));
252
253         calendar_error_e error = CALENDAR_ERROR_NONE;
254
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);
258         } else {
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);
261
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);
264         }
265
266         _calendar_set_timezone_city(record, timezone_city);
267 }
268
269 static void __cal_edit_ug_set_record_time(cal_edit_ug_data *p, calendar_record_h record)
270 {
271         c_ret_if(!p);
272         c_ret_if(!record);
273
274         calendar_error_e error = CALENDAR_ERROR_NONE;
275
276         calendar_time_s start_time = {0};
277
278         _calendar_get_start_time(record, &start_time);
279
280         calendar_time_s end_time = {0};
281
282         _calendar_get_end_time(record, &end_time);
283
284         if (_calendar_is_allday_record(record)) {
285
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;
289
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;
293
294         } else {
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);
297         }
298
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);
301
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);
304
305         __cal_edit_ug_set_timezone(record, p->timezone_path, p->timezone_city);
306 }
307
308 static void __cal_edit_ug_set_rrule_wday(calendar_record_h record, enum __cal_edit_wday tm_wday)
309 {
310         c_ret_if(!record);
311
312         calendar_error_e error = CALENDAR_ERROR_NONE;
313
314         switch (tm_wday) {
315         case CAL_EDIT_WDAY_SUNDAY:
316                 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
317                 break;
318
319         case CAL_EDIT_WDAY_MONDAY:
320                 error = calendar_record_set_str(record, _calendar_event.byday, "MO");
321                 break;
322
323         case CAL_EDIT_WDAY_TUESDAY:
324                 error = calendar_record_set_str(record, _calendar_event.byday, "TU");
325                 break;
326
327         case CAL_EDIT_WDAY_WEDNESDAY:
328                 error = calendar_record_set_str(record, _calendar_event.byday, "WE");
329                 break;
330
331         case CAL_EDIT_WDAY_THURSDAY:
332                 error = calendar_record_set_str(record, _calendar_event.byday, "TH");
333                 break;
334
335         case CAL_EDIT_WDAY_FRIDAY:
336                 error = calendar_record_set_str(record, _calendar_event.byday, "FR");
337                 break;
338
339         case CAL_EDIT_WDAY_SATURDAY:
340                 error = calendar_record_set_str(record, _calendar_event.byday, "SA");
341                 break;
342         default:
343                 ERR("Error!!");
344                 error = calendar_record_set_str(record, _calendar_event.byday, "SU");
345                 break;
346         }
347
348         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
349 }
350
351 static void __cal_edit_ug_set_rrule_month(calendar_record_h record, int tm_mon)
352 {
353         c_ret_if(!record);
354
355         char buffer[8] = {0};
356
357         snprintf(buffer, sizeof(buffer), "%d", tm_mon + 1);
358
359         calendar_error_e error = CALENDAR_ERROR_NONE;
360
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);
363 }
364
365 static void __cal_edit_ug_set_rrule_mday(calendar_record_h record, int tm_mday)
366 {
367         c_ret_if(!record);
368
369         char buffer[8] = {0};
370
371         snprintf(buffer, sizeof(buffer), "%d", tm_mday);
372
373         calendar_error_e error = CALENDAR_ERROR_NONE;
374
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);
377 }
378
379 static int __cal_edit_ug_g_list_compare(const void* data1, const void* data2)
380 {
381         const Cal_Reminder* reminder1 = (Cal_Reminder*)data1;
382         const Cal_Reminder* reminder2 = (Cal_Reminder*)data2;
383
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);
389                         if (dt1 > dt2)
390                                 return 1;
391                         else if (dt1 < dt2)
392                                 return -1;
393                         else
394                                 return 0;
395                 } else {
396                         return 1;
397                 }
398         } else {
399                 if (reminder2->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
400                         return -1;
401                 else
402                         return reminder1->alarm_value - reminder2->alarm_value;
403         }
404 }
405
406 static int __cal_edit_ug_g_list_compare_with_data(const void* data1, const void* data2, void* user_data)
407 {
408         return __cal_edit_ug_g_list_compare(data1, data2);
409 }
410
411
412 static void __cal_edit_ug_set_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
413 {
414         CAL_FN_START;
415
416         c_retm_if(!p, "p is null");
417         c_retm_if(!record, "record is null");
418
419         GList *temp  = NULL;
420
421         Eina_Bool is_task = _calendar_is_task_record(record);
422
423         if (is_task)
424                 _calendar_clear_child_record(record, _calendar_todo.calendar_alarm);
425         else
426                 _calendar_clear_child_record(record, _calendar_event.calendar_alarm);
427
428
429         Eina_List* list = NULL;
430         Evas_Object *item = NULL;
431         EINA_LIST_FOREACH(p->alarm_item_list, list, item)       {
432                 if(item)        {
433                         Cal_Reminder* reminder = evas_object_data_get(item, "data");
434
435                         if (g_list_find_custom(temp, reminder, __cal_edit_ug_g_list_compare))
436                                 continue;
437
438                         temp = g_list_insert_sorted_with_data(temp, reminder, __cal_edit_ug_g_list_compare_with_data, NULL);
439
440                         calendar_record_h calendar_alarm = cal_reminder_get_cal_val(reminder);
441
442                         calendar_error_e error = CALENDAR_ERROR_NONE;
443
444                         if (is_task)
445                                 error = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, calendar_alarm);
446                         else
447                                 error = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, calendar_alarm);
448
449                         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() is failed(%x)", error);
450                 }
451         }
452 }
453
454 static void __cal_edit_ug_set_record_repeat(cal_edit_ug_data *p)
455 {
456         c_retm_if(!p, "p is null");
457
458         calendar_error_e error = CALENDAR_ERROR_NONE;
459
460         switch (p->repeat_freq) {
461                 case CALENDAR_RECURRENCE_NONE:
462                         break;
463
464                 case CALENDAR_RECURRENCE_DAILY:
465                         error = calendar_record_set_int(p->event, _calendar_event.interval, 1);
466                         break;
467
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);
471                         break;
472
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);
476                         break;
477
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);
482                         break;
483
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);
489                         break;
490
491                 default:
492                         break;
493         }
494
495         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
496
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);
499
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);
502
503         if (CALENDAR_RECURRENCE_NONE != p->repeat_freq) {
504
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) {
509
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);
512
513                         calendar_time_s until_time = {0};
514
515                         until_time.type = CALENDAR_TIME_UTIME;
516                         cal_util_convert_tm_to_lli(NULL, &p->repeat_until, &until_time.time.utime);
517
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);
520                 }
521         }
522 }
523
524 static void __cal_edit_ug_set_record_save_to( calendar_record_h record, int calendar_book_id)
525 {
526         calendar_error_e error = CALENDAR_ERROR_NONE;
527
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);
531         } else {
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);
534
535                 calendar_record_h calendar_book = NULL;
536
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);
539
540                 char *organizer_name = NULL;
541
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);
544
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);
547
548                 CAL_FREE(organizer_name);
549
550                 error = calendar_record_destroy(calendar_book, true);
551                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
552         }
553 }
554
555 static void  __cal_edit_ug_set_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
556 {
557         c_retm_if(!p, "p is null");
558         c_retm_if(!record, "record is null");
559
560         calendar_error_e error = CALENDAR_ERROR_NONE;
561
562         calendar_time_s due_time = {0};
563
564         _calendar_get_end_time(record, &due_time);
565
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);
568
569         if (p->is_no_due_date)  {
570                 due_time.time.utime = CALENDAR_TODO_NO_DUE_DATE;
571         } else {
572                 cal_util_convert_tm_to_lli(NULL, &p->etm, &due_time.time.utime);
573         }
574
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);
577 }
578
579 static void __cal_edit_ug_set_record_priority(calendar_record_h record, int priority)
580 {
581         c_retm_if(!record, "record is null");
582
583         calendar_error_e error = CALENDAR_ERROR_NONE;
584
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);
587 }
588
589 static void __cal_edit_ug_initialize_event_record(cal_edit_ug_data *p)
590 {
591         CAL_FN_START;
592
593         c_retm_if(!p, "p is null");
594
595         calendar_error_e error = CALENDAR_ERROR_NONE;
596
597         if(!p->event) {
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);
600         }
601
602         p->stm = p->base_time;
603         p->stm.tm_min = p->stm.tm_sec = 0;
604
605         if (0 <= p->base_time.tm_hour)
606                 p->stm.tm_hour = p->base_time.tm_hour;
607         else
608                 cal_util_update_tm_hour(&p->stm,1);
609
610         p->etm = p->stm;
611         cal_util_update_tm_hour(&p->etm,1);
612
613          __cal_edit_ug_set_record_time(p, p->event);
614
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);
621
622         __cal_edit_ug_set_record_save_to(p->event, DEFAULT_EVENT_CALENDAR_BOOK_ID);
623
624         p->title_str = NULL;
625         p->note_str = NULL;
626         p->address = NULL;
627 }
628
629 static void __cal_edit_ug_initialize_todo_record(cal_edit_ug_data *p)
630 {
631         CAL_FN_START;
632
633         c_retm_if(!p, "p is null");
634
635         calendar_error_e error = CALENDAR_ERROR_NONE;
636
637         if(!p->todo) {
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);
640         }
641
642         p->stm = p->base_time;
643         p->stm.tm_min = p->stm.tm_sec = 0;
644
645         if (0 <= p->base_time.tm_hour)
646                 p->stm.tm_hour = p->base_time.tm_hour;
647         else
648                 cal_util_update_tm_hour(&p->stm,1);
649
650         p->etm = p->stm;
651         cal_util_update_tm_hour(&p->etm,1);
652
653         calendar_time_s end_time = {0};
654         end_time.type = CALENDAR_TIME_UTIME;
655
656         cal_util_convert_tm_to_lli(NULL, &p->etm, &end_time.time.utime);
657
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);
660
661         __cal_edit_ug_set_timezone(p->todo, p->timezone_path, p->timezone_city);
662
663         __cal_edit_ug_set_record_save_to(p->todo, DEFAULT_TODO_CALENDAR_BOOK_ID);
664
665         __cal_edit_ug_set_record_priority(p->todo, CALENDAR_TODO_PRIORITY_NORMAL);
666
667         p->title_str = NULL;
668         p->note_str = NULL;
669         p->address = NULL;
670 }
671
672 static inline char * __cal_edit_ug_get_record_title(calendar_record_h record)
673 {
674         c_retvm_if(!record, NULL, "record is null");
675
676         calendar_error_e error = CALENDAR_ERROR_NONE;
677         char *summary = NULL;
678
679         if (_calendar_is_task_record(record))
680                 error = calendar_record_get_str(record, _calendar_todo.summary, &summary);
681         else
682                 error = calendar_record_get_str(record, _calendar_event.summary, &summary);
683
684         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
685
686         return summary;
687 }
688
689 static inline void __cal_edit_ug_get_record_location(cal_edit_ug_data *p, calendar_record_h record)
690 {
691         calendar_error_e error = CALENDAR_ERROR_NONE;
692
693         p->address = _calendar_get_location(record);
694
695         if (_calendar_is_task_record(record))
696         {
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);
701         }
702         else
703         {
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);
708         }
709 }
710
711 static inline char * __cal_edit_ug_get_record_note(calendar_record_h record)
712 {
713         c_retvm_if(!record, NULL, "record is null");
714
715         calendar_error_e error = CALENDAR_ERROR_NONE;
716         char *note = NULL;
717
718         if (_calendar_is_task_record(record))
719                 error = calendar_record_get_str(record, _calendar_todo.description, &note);
720         else
721                 error = calendar_record_get_str(record, _calendar_event.description, &note);
722
723         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
724
725         return note;
726 }
727
728 static int __cal_edit_ug_get_timezone_offset_with_standard_name(const char *standard_name)
729 {
730         int timezone_offset = 0;
731
732         c_retv_if(!CAL_STRLEN(standard_name), timezone_offset);
733
734         calendar_error_e error = CALENDAR_ERROR_NONE;
735
736         calendar_query_h query = NULL;
737
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);
740
741         calendar_filter_h filter = NULL;
742
743         error = calendar_filter_create(_calendar_timezone._uri, &filter);
744         if (error != CALENDAR_ERROR_NONE) {
745
746                 ERR("calendar_filter_create() is failed(%x)", error);
747                 calendar_query_destroy(query);
748                 return 0;
749         }
750
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);
753
754         error = calendar_query_set_filter(query, filter);
755         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
756
757         calendar_list_h list = NULL;
758
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);
761
762         error = calendar_list_first(list);
763         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
764
765         calendar_record_h timezone = NULL;
766
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);
769
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);
772
773         error = calendar_list_destroy(list, true);
774         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
775
776         error = calendar_filter_destroy(filter);
777         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
778
779         error = calendar_query_destroy(query);
780         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
781
782         return (-1)*timezone_offset;
783 }
784
785 static void __cal_edit_ug_get_timezone_for_eas(cal_edit_ug_data *p, calendar_record_h record)
786 {
787         c_ret_if(!p);
788         c_ret_if(!record);
789
790         calendar_error_e error = CALENDAR_ERROR_NONE;
791
792         char *standard_name = NULL;
793
794         if (_calendar_is_task_record(record))
795                 error = calendar_record_get_str_p(record, _calendar_todo.due_tzid, &standard_name);
796         else
797                 error = calendar_record_get_str_p(record, _calendar_event.start_tzid, &standard_name);
798
799         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
800
801         c_ret_if(!CAL_STRLEN(standard_name));
802
803         int timezone_offset = __cal_edit_ug_get_timezone_offset_with_standard_name(standard_name);
804
805         cal_util_get_timezone_id(timezone_offset, &p->timezone_path);
806 }
807
808 static void  __cal_edit_ug_get_record_time_zone(cal_edit_ug_data *p, calendar_record_h record)
809 {
810         c_ret_if(!p);
811         c_ret_if(!record);
812
813         calendar_error_e error = CALENDAR_ERROR_NONE;
814
815         if (_calendar_is_eas_record(record))
816                 __cal_edit_ug_get_timezone_for_eas(p, record);
817         else {
818                 if (_calendar_is_task_record(record))
819                         error = calendar_record_get_str(record, _calendar_todo.due_tzid, &p->timezone_path);
820                 else
821                         error = calendar_record_get_str(record, _calendar_event.start_tzid, &p->timezone_path);
822
823                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
824
825                 p->timezone_city = _calendar_get_timezone_city(record);
826         }
827
828         cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
829
830         c_ret_if(!CAL_STRLEN(p->timezone_path));
831         c_ret_if(!CAL_STRLEN(p->timezone_city));
832 }
833
834 static void  __cal_edit_ug_get_record_alarm(cal_edit_ug_data *p, calendar_record_h record)
835 {
836         c_retm_if(!p, "p is null");
837         c_retm_if(!record, "record is null");
838
839         if (p->alarm_list) {
840                 g_list_free(p->alarm_list);
841                 p->alarm_list = NULL;
842         }
843
844         int alarm_count = 0;
845
846         Eina_Bool is_task = _calendar_is_task_record(record);
847         calendar_error_e error = CALENDAR_ERROR_NONE;
848
849         if (is_task)
850         {
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);
853         }
854         else
855         {
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);
858         }
859
860         int i = 0;
861         for (i = 0; i < alarm_count; i++) {
862                 calendar_record_h calendar_alarm = NULL;
863
864                 if (is_task)
865                 {
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);
868                 }
869                 else
870                 {
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);
873                 }
874
875                 Cal_Reminder* reminder = cal_reminder_create(calendar_alarm);
876                 p->alarm_list = g_list_append(p->alarm_list,(void *)reminder);
877         }
878
879         p->alarm_list = g_list_first(p->alarm_list);
880 }
881
882 static void  __cal_edit_ug_get_record_repeat(cal_edit_ug_data *p, calendar_record_h record)
883 {
884         c_ret_if(!p);
885         c_ret_if(!record);
886
887         calendar_record_h original_record = NULL;
888         int original_event_id = 0;
889         calendar_error_e error = CALENDAR_ERROR_NONE;
890
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);
893
894         if (0 < original_event_id) {
895
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);
898         }
899
900         if (!original_record)
901                 original_record = record;
902
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);
905
906         if (p->repeat_freq == CALENDAR_RECURRENCE_WEEKLY) {
907
908                 int interval = 0;
909
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);
912
913                 if (2 == interval)
914                         p->repeat_freq = CAL_REPEAT_EVERY_2_WEEK;
915
916         } else if (p->repeat_freq == CALENDAR_RECURRENCE_DAILY) {
917
918                 int interval = 0;
919
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);
922
923                 if (3 == interval)
924                         p->repeat_freq = CAL_REPEAT_EVERY_3_DAY;
925         }
926
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);
929
930         if (p->repeat_range == CALENDAR_RANGE_NONE) {
931                 p->repeat_count = 10;
932
933                 p->repeat_until = p->stm;
934                 cal_util_update_tm_month (&p->repeat_until, 1);
935
936         } else {
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);
939
940                 calendar_time_s until_utime = {0};
941
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);
944
945                 cal_util_convert_lli_to_tm(NULL, until_utime.time.utime, &p->repeat_until);
946         }
947
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);
951         }
952 }
953
954 static int  __cal_edit_ug_get_record_priority(calendar_record_h record)
955 {
956         c_retv_if(!record, 0);
957
958         calendar_error_e error = CALENDAR_ERROR_NONE;
959
960         int priority;
961
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);
964
965         return priority;
966 }
967
968 static void __cal_edit_ug_get_record_due_time(cal_edit_ug_data *p, calendar_record_h record)
969 {
970         c_retm_if(!p, "p is null");
971         c_retm_if(!record, "record is null");
972
973         calendar_error_e error = CALENDAR_ERROR_NONE;
974
975         calendar_time_s due_time = {0};
976
977         _calendar_get_end_time(record, &due_time);
978
979         cal_util_convert_lli_to_tm(NULL, due_time.time.utime, &p->etm);
980
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;
984         }
985
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);
988
989         c_ret_if(!p->timezone_path);
990
991         cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
992 }
993
994 static void __cal_edit_ug_update_title_item(Evas_Object *entry, calendar_record_h record)
995 {
996         c_retm_if(!entry, "entry is null");
997         c_retm_if(!record, "record is null");
998
999         char* title = __cal_edit_ug_get_record_title(record);
1000
1001         elm_entry_entry_set(entry, title);
1002
1003         CAL_FREE(title);
1004 }
1005
1006 static void __cal_edit_ug_update_note_item(Evas_Object *entry, calendar_record_h record)
1007 {
1008         c_retm_if(!entry, "entry is null");
1009         c_retm_if(!record, "record is null");
1010
1011         char* note = __cal_edit_ug_get_record_note(record);
1012
1013         elm_entry_entry_set(entry, note);
1014
1015         CAL_FREE(note);
1016 }
1017
1018 static void __cal_edit_ug_update_location_item(cal_edit_ug_data *p, calendar_record_h record)
1019 {
1020         c_retm_if(!p, "p is null");
1021         c_retm_if(!record, "record is null");
1022
1023         __cal_edit_ug_get_record_location(p, record);
1024         elm_entry_entry_set(p->location_entry, p->address);
1025 }
1026
1027 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz);
1028
1029 static void __cal_edit_ug_update_save_to_item(cal_edit_ug_data *p, calendar_record_h record)
1030 {
1031         c_retm_if(!p, "p is null");
1032
1033         int calendar_book_id = _calendar_get_calendar_index(record);
1034
1035         char buf[1024];
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"));
1041         else {
1042                 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
1043                 saveto_text = strdup(buf);
1044         }
1045
1046         elm_object_part_text_set(p->saveto, "elm.text.1", saveto_text);
1047
1048         CAL_FREE(saveto_text);
1049 }
1050
1051 static void __cal_edit_ug_update_priority_item(cal_edit_ug_data *p, calendar_record_h record)
1052 {
1053         c_retm_if(!p, "p is null");
1054         c_retm_if(!record, "record is null");
1055
1056         char* priority_text = NULL;
1057         int priority = __cal_edit_ug_get_record_priority(record);
1058         switch (priority) {
1059                 case CALENDAR_TODO_PRIORITY_LOW:
1060                         priority_text = strdup(S_("IDS_COM_BODY_LOW"));
1061                         break;
1062                 case CALENDAR_TODO_PRIORITY_NORMAL:
1063                         priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
1064                         break;
1065                 case CALENDAR_TODO_PRIORITY_HIGH:
1066                         priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
1067                         break;
1068                 default:
1069                         break;
1070         }
1071
1072         elm_object_part_text_set(p->priority, "elm.text.1", priority_text);
1073         CAL_FREE(priority_text);
1074
1075 }
1076
1077 static void __cal_edit_ug_update_start_language(Evas_Object *item)
1078 {
1079         c_ret_if(!item);
1080
1081         elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_FROM"));
1082 }
1083
1084 static void __cal_edit_ug_update_end_language(Evas_Object *item)
1085 {
1086         c_ret_if(!item);
1087
1088         elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_TO"));
1089 }
1090
1091 static void __cal_edit_ug_update_due_language(Evas_Object *item)
1092 {
1093         c_ret_if(!item);
1094
1095         elm_object_part_text_set(item, "elm.text", C_("IDS_CLD_BODY_DUE_DATE"));
1096 }
1097
1098 static Evas_Object *__cal_edit_ug_insert_padding_after(cal_edit_ug_data* p, const char* title, Evas_Object *after)
1099 {
1100         c_retv_if(!p, NULL);
1101         c_retv_if(!after, NULL);
1102
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");
1105
1106         if (CAL_STRLEN(title))
1107                 elm_object_part_text_set(item, "elm.text", title);
1108
1109         return item;
1110 }
1111
1112 static void __cal_edit_ug_title_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1113 {
1114         const char *str;
1115         cal_edit_ug_data* p = (cal_edit_ug_data *)data;
1116
1117         free(p->title_str);
1118
1119         str = elm_entry_entry_get(p->title_entry);
1120         if (!str || str[0] == '\0')
1121                 p->title_str = NULL;
1122         else
1123                 p->title_str = elm_entry_markup_to_utf8(str);
1124
1125         if(p->item_type == ITEM_TYPE_TODO)
1126                 __cal_edit_ug_set_record_title(p->todo, p->title_str);
1127         else
1128                 __cal_edit_ug_set_record_title(p->event, p->title_str);
1129 }
1130
1131 static Evas_Object * __cal_edit_ug_title_item(cal_edit_ug_data* p, Evas_Object *obj)
1132 {
1133         c_retv_if(!p, NULL);
1134         c_retv_if(!obj, NULL);
1135
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");
1138
1139         Evas_Object *entry = elm_object_part_content_get(ef, "elm.icon.entry");
1140         c_retvm_if(!entry, ef, "entry is null");
1141
1142         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1143
1144         p->title_entry = entry;
1145
1146         if (p->item_type == ITEM_TYPE_TODO)
1147                 __cal_edit_ug_update_title_item(p->title_entry, p->todo);
1148         else
1149                 __cal_edit_ug_update_title_item(p->title_entry, p->event);
1150
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);
1153
1154         return ef;
1155
1156 }
1157
1158 static void __cal_edit_ug_update_title_language(Evas_Object *item)
1159 {
1160         c_ret_if(!item);
1161
1162         Evas_Object *entry = elm_object_part_content_get(item, "elm.icon.entry");
1163         c_retm_if(!entry, "entry is null");
1164
1165         elm_object_part_text_set(entry, "elm.guide", S_("IDS_COM_BODY_DETAILS_TITLE"));
1166 }
1167
1168 static Evas_Object *__cal_edit_ug_add_title(cal_edit_ug_data* p)
1169 {
1170         c_retv_if(!p, NULL);
1171
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");
1174
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);
1179
1180         return item;
1181 }
1182
1183 static void __cal_edit_ug_location_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1184 {
1185         c_ret_if(!data);
1186
1187         cal_edit_ug_data *p = data;
1188         c_ret_if(!p);
1189
1190         CAL_FREE(p->address);
1191
1192         p->address = elm_entry_markup_to_utf8(elm_entry_entry_get(p->location_entry));
1193
1194         if (!CAL_STRLEN(p->address)) {
1195
1196                 p->longitude = p->latitude = CALENDAR_RECORD_NO_COORDINATE;
1197
1198         }
1199
1200         if (p->item_type == ITEM_TYPE_TODO)
1201                 __cal_edit_ug_set_record_location(p->todo, p->address, p->latitude, p->longitude);
1202         else
1203                 __cal_edit_ug_set_record_location(p->event, p->address, p->latitude, p->longitude);
1204 }
1205
1206 static Evas_Object * __cal_edit_ug_location_icon(cal_edit_ug_data* p, Evas_Object *obj)
1207 {
1208         c_retv_if(!p, NULL);
1209         c_retv_if(!obj, NULL);
1210
1211         Evas_Object *ly = NULL;
1212
1213         Evas_Object *ef = cal_util_add_edit_field(obj, NULL, C_("IDS_COM_BODY_DETAILS_LOCATION"), EINA_FALSE, EINA_TRUE, EINA_TRUE);
1214         ly = ef;
1215
1216         p->location_entry = elm_object_part_content_get(ef, "elm.icon.entry");
1217         c_retv_if(!p->location_entry, ly);
1218
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);
1221
1222         elm_entry_cursor_end_set(p->location_entry);
1223
1224         elm_entry_cnp_mode_set(p->location_entry, ELM_CNP_MODE_PLAINTEXT);
1225
1226         if (p->item_type == ITEM_TYPE_TODO)
1227                 __cal_edit_ug_update_location_item(p, p->todo);
1228         else
1229                 __cal_edit_ug_update_location_item(p, p->event);
1230
1231         return ly;
1232 }
1233
1234 static void __cal_edit_ug_update_location_language(Evas_Object *item)
1235 {
1236         c_ret_if(!item);
1237
1238         Evas_Object *layout = elm_object_part_content_get(item, "elm.icon");
1239         c_ret_if(!layout);
1240
1241         Evas_Object *edit_field = elm_object_part_content_get(layout, "editfield/sw");
1242         c_ret_if(!edit_field);
1243
1244         Evas_Object *entry = elm_object_part_content_get(edit_field, "elm.icon.entry");
1245         c_retm_if(!entry, "entry is null");
1246
1247         elm_object_part_text_set(entry, "elm.guide", C_("IDS_COM_BODY_DETAILS_LOCATION"));
1248
1249 }
1250
1251 static Evas_Object *__cal_edit_ug_add_location(cal_edit_ug_data* p)
1252 {
1253         c_retv_if(!p, NULL);
1254
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");
1257
1258         Evas_Object *editfield = __cal_edit_ug_location_icon(p, item);
1259         c_retvm_if(!editfield, NULL, "__cal_edit_ug_note_icon() is failed");
1260
1261         elm_object_part_content_set(item, "elm.icon", editfield);
1262
1263         __cal_edit_ug_insert_padding_after(p, NULL, item);
1264
1265         return item;
1266 }
1267
1268 static void __cal_edit_ug_note_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
1269 {
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));
1273
1274         if (CAL_STRLEN(p->note_str))
1275                 email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1276
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)
1283                 {
1284                         snprintf(strnote, strnote_len + 1, "%s%s", str, email_link);
1285                         p->note_str = strdup(strnote);
1286
1287                         free(strnote);
1288                 }
1289                 else
1290                 {
1291                         p->note_str = NULL;
1292                 }
1293
1294         } else {
1295                 p->note_str = CAL_STRDUP(str);
1296         }
1297
1298         free(str);
1299
1300         if(p->item_type == ITEM_TYPE_TODO)
1301                 __cal_edit_ug_set_record_note(p->todo, p->note_str);
1302         else
1303                 __cal_edit_ug_set_record_note(p->event, p->note_str);
1304 }
1305
1306
1307 static Evas_Object * __cal_edit_ug_note_item(cal_edit_ug_data* p, Evas_Object *obj)
1308 {
1309         c_retv_if(!p, NULL);
1310         c_retv_if(!obj, NULL);
1311
1312         Evas_Object *ef = cal_util_add_edit_field(obj, NULL, C_("IDS_CLD_BODY_CREATE_DESCRITION"), EINA_FALSE, EINA_TRUE, EINA_FALSE);
1313
1314         if (ef) {
1315                 Evas_Object *entry = elm_object_part_content_get(ef, "elm.icon.entry");
1316                 c_retvm_if(!entry, ef, "entry is null");
1317
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);
1322
1323                 p->note_entry = entry;
1324
1325                 if (p->note_str) {
1326
1327                         char *email_link = NULL;
1328                         email_link = strstr(p->note_str, EMAIL_LINK_FLAG);
1329                         if(!email_link)
1330                                 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(p->note_str));
1331                         else {
1332
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");
1337
1338                                 CAL_STRNCPY(snote_display, p->note_str, nsize-1);
1339
1340                                 elm_entry_entry_set(p->note_entry, elm_entry_utf8_to_markup(snote_display));
1341                                 free(snote_display);
1342                         }
1343                 }
1344
1345                 if (p->item_type == ITEM_TYPE_TODO)
1346                         __cal_edit_ug_update_note_item(p->note_entry, p->todo);
1347                 else
1348                         __cal_edit_ug_update_note_item(p->note_entry, p->event);
1349
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);
1353
1354                 return ef;
1355         }
1356
1357         return NULL;
1358 }
1359
1360 static void __cal_edit_ug_update_description_language(Evas_Object *item)
1361 {
1362         c_ret_if(!item);
1363
1364         Evas_Object *entry = elm_object_part_content_get(item, "elm.icon.entry");
1365         c_retm_if(!entry, "entry is null");
1366
1367         elm_object_part_text_set(entry, "elm.guide", C_("IDS_CLD_BODY_CREATE_DESCRITION"));
1368
1369 }
1370
1371 static Evas_Object *__cal_edit_ug_add_note(cal_edit_ug_data* p)
1372 {
1373         c_retv_if(!p, NULL);
1374
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");
1377
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);
1382
1383         return item;
1384 }
1385
1386 static Evas_Object * __cal_edit_ug_edit_time_icon(Evas_Object *obj, struct tm* value, Eina_Bool allday)
1387 {
1388         c_retvm_if(!obj, NULL, "obj is null");
1389
1390         Evas_Object* icon_obj = cal_util_add_datetime(obj, NULL, value);
1391         c_retvm_if(!icon_obj, NULL, "icon_obj is null");
1392
1393         elm_object_part_content_set(obj, "datefield", icon_obj);
1394
1395         if (is_hour24)
1396                 elm_datetime_format_set(icon_obj, "%b %d , %Y %H : %M");
1397         else
1398                 elm_datetime_format_set(icon_obj, "%b %d , %Y %I : %M %p");
1399
1400         if (!allday)
1401         {
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);
1404                 if (is_hour24)
1405                         elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_FALSE);
1406                 else
1407                         elm_datetime_field_visible_set(icon_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1408         }
1409         else
1410         {
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);
1414         }
1415
1416         elm_datetime_field_limit_set(icon_obj, ELM_DATETIME_YEAR, 70, 136);
1417
1418         return icon_obj;
1419 }
1420
1421 static Eina_Bool __cal_edit_ug_check_date_validity(void *data)
1422 {
1423         c_retv_if(!data, EINA_FALSE);
1424         cal_edit_ug_data* p = data;
1425
1426         time_t start_t = mktime(&p->stm);
1427         time_t end_t = mktime(&p->etm);
1428
1429         if(start_t > end_t)
1430                 return EINA_FALSE;
1431
1432         return EINA_TRUE;
1433 }
1434
1435 static void __cal_edit_ug_start_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1436 {
1437         c_retm_if(data == NULL, "data is null");
1438         cal_edit_ug_data *p = data;
1439
1440         struct tm value;
1441         time_t t = time(NULL);
1442         localtime_r(&t, &value); // to fill hidden field
1443
1444         elm_datetime_value_get(obj, &value);
1445
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;
1450
1451         // Update start time variable
1452         p->stm = value;
1453
1454         Eina_Bool result =__cal_edit_ug_check_date_validity(p);
1455         if(!result)     {
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);
1459
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);
1463         }
1464
1465         __cal_edit_ug_set_record_time(p, p->event);
1466 }
1467
1468 static void __cal_edit_ug_end_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1469 {
1470         c_retm_if(!data, "data is null");
1471         cal_edit_ug_data *p = data;
1472
1473         struct tm value;
1474         time_t t = time(NULL);
1475         localtime_r(&t, &value); // to fill hidden field
1476
1477         elm_datetime_value_get(obj, &value);
1478
1479         p->etm = value;
1480
1481         Eina_Bool result = __cal_edit_ug_check_date_validity(p);
1482         if(!result)     {
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);
1485         } else
1486                 __cal_edit_ug_set_record_time(p, p->event);
1487
1488 }
1489
1490 static void __cal_edit_ug_due_date_changed_callback(void *data, Evas_Object* obj, void *ei)
1491 {
1492         c_retm_if(!data, "data is null");
1493         cal_edit_ug_data *p = data;
1494
1495         struct tm value;
1496         time_t t = time(NULL);
1497         localtime_r(&t, &value); // to fill hidden field
1498
1499         elm_datetime_value_get(obj, &value);
1500
1501         p->etm = value;
1502
1503         __cal_edit_ug_set_record_due_time(p, p->todo);
1504
1505 }
1506
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)
1508 {
1509         c_ret_if(!item);
1510
1511         Evas_Object *datetime = NULL;
1512
1513         datetime = elm_object_part_content_unset(item, "elm.icon");
1514         if (datetime)
1515                 evas_object_del(datetime);
1516
1517         datetime = __cal_edit_ug_edit_time_icon(item, tm, is_allday);
1518         c_ret_if(!datetime);
1519
1520         elm_object_part_content_set(item, "elm.icon", datetime);
1521
1522         evas_object_smart_callback_add(datetime, "changed", callback, callback_data);
1523 }
1524
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)
1526 {
1527         c_retv_if(!p, NULL);
1528         c_retv_if(!after, NULL);
1529
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");
1532
1533         __cal_edit_ug_update_datetime_region(item, value, allday, callback, p);
1534
1535         return item;
1536 }
1537
1538 static void __cal_edit_ug_all_day_update(Evas_Object* date_obj, Eina_Bool allday)
1539 {
1540         Evas_Object *edit_time_obj = elm_object_part_content_get(date_obj, "elm.icon");
1541
1542         if (!allday) {
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);
1545                 if (!is_hour24)
1546                         elm_datetime_field_visible_set(edit_time_obj, ELM_DATETIME_AMPM, EINA_TRUE);
1547         } else {
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);
1551         }
1552 }
1553
1554 static void __cal_edit_ug_set_record_allday(calendar_record_h record, Eina_Bool is_allday, cal_edit_ug_data *p)
1555 {
1556         c_ret_if(!record);
1557         c_ret_if(!p);
1558
1559         if (is_allday == _calendar_is_allday_record(record))
1560                 return;
1561
1562         calendar_time_s start_time = {0};
1563
1564         _calendar_get_start_time(record, &start_time);
1565
1566         calendar_time_s end_time = {0};
1567
1568         _calendar_get_end_time(record, &end_time);
1569
1570         struct tm start_tm = {0};
1571         struct tm end_tm = {0};
1572
1573         if (is_allday) {
1574
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);
1577
1578                 start_time.type = CALENDAR_TIME_LOCALTIME;
1579                 end_time.type = CALENDAR_TIME_LOCALTIME;
1580
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;
1584
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;
1588
1589         } else {
1590
1591                 start_time.type = CALENDAR_TIME_UTIME;
1592                 end_time.type = CALENDAR_TIME_UTIME;
1593
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);
1596         }
1597
1598         _calendar_set_start_time(record, &start_time);
1599
1600         _calendar_set_end_time(record, &end_time);
1601 }
1602
1603 static void __cal_edit_ug_all_day_clicked_callback(Evas_Object *obj, void *data)
1604 {
1605         CAL_FN_START;
1606
1607         c_retm_if(!data, "data is null");
1608         cal_edit_ug_data *p = data;
1609
1610         Evas_Object *all_obj = elm_object_part_content_get(p->allday, "elm.icon");
1611         c_ret_if(!all_obj);
1612
1613         Eina_Bool is_allday = !elm_check_state_get(all_obj);
1614
1615         elm_check_state_set(all_obj, is_allday);
1616
1617         __cal_edit_ug_all_day_update(p->start_date, is_allday);
1618         __cal_edit_ug_all_day_update(p->end_date, is_allday);
1619
1620         __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1621
1622 }
1623
1624 static void __cal_edit_ug_all_day_changed_callback(void *data, Evas_Object* obj, void *ei)
1625 {
1626         CAL_FN_START;
1627
1628         c_retm_if(!data, "data is null");
1629         c_retm_if(!obj, "obj is null");
1630
1631         cal_edit_ug_data *p = data;
1632
1633         Eina_Bool is_allday = elm_check_state_get(obj);
1634
1635         __cal_edit_ug_all_day_update(p->start_date, is_allday);
1636         __cal_edit_ug_all_day_update(p->end_date, is_allday);
1637
1638         __cal_edit_ug_set_record_allday(p->event, is_allday, p);
1639 }
1640
1641 static void __cal_edit_ug_update_allday_language(Evas_Object *item)
1642 {
1643         c_ret_if(!item);
1644
1645         elm_object_part_text_set(item, "elm.text", C_("IDS_COM_BODY_ALL_DAY"));
1646 }
1647
1648 static Evas_Object *__cal_edit_ug_add_all_day(cal_edit_ug_data* p, Eina_Bool allday)
1649 {
1650         c_retv_if(!p, NULL);
1651
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");
1654
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);
1662
1663         elm_object_part_content_set(item, "elm.icon", check_obj);
1664
1665         __cal_edit_ug_update_allday_language(item);
1666
1667         return item;
1668 }
1669
1670 static void __cal_edit_ug_worldclock_ug_destroy_callback(ui_gadget_h ug, void *priv)
1671 {
1672         CAL_FN_START;
1673
1674         cal_edit_ug_data* p = (cal_edit_ug_data*) priv;
1675
1676         if (p->ug_worldclock) {
1677                 ug_destroy(p->ug_worldclock);
1678                 p->ug_worldclock= NULL;
1679         }
1680
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 */
1685         }
1686 }
1687
1688 static void __cal_edit_ug_worldclock_ug_result_callback(ui_gadget_h ug, service_h result, void *priv)
1689 {
1690         CAL_FN_START;
1691
1692         c_retm_if(!priv, "priv is null");
1693         c_retm_if(!result, "result is null");
1694
1695         cal_edit_ug_data *p = priv;
1696
1697         if (p->timezone_city) {
1698                 free(p->timezone_city);
1699                 p->timezone_city = NULL;
1700         }
1701
1702         if (p->timezone_path) {
1703                 free(p->timezone_path);
1704                 p->timezone_path = NULL;
1705         }
1706
1707         if (p->timezone_offset) {
1708                 free(p->timezone_offset);
1709                 p->timezone_offset = NULL;
1710         }
1711
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);
1714
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);
1717
1718         __cal_edit_ug_set_timezone(p->record, p->timezone_path, p->timezone_city);
1719
1720         cal_util_get_timezone(&p->timezone_path, &p->timezone_city, &p->timezone_offset);
1721
1722         p->is_selected_timezone = EINA_TRUE;
1723
1724         char* timezone_text = NULL;
1725         timezone_text = g_strdup_printf("%s, %s", S_(p->timezone_city), p->timezone_offset);
1726
1727         elm_object_part_text_set(p->timezone, "elm.text.1", timezone_text);
1728
1729         CAL_FREE(timezone_text);
1730 }
1731
1732 static void __cal_edit_ug_worldclock_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
1733 {
1734         CAL_FN_START;
1735
1736         c_retm_if(!ug, "ug is null");
1737
1738         Evas_Object *base = ug_get_layout(ug);
1739         if (!base) {
1740                 ug_destroy(ug);
1741                 return;
1742         }
1743
1744         switch (mode)
1745         {
1746         case UG_MODE_FULLVIEW:
1747                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1748                                 EVAS_HINT_EXPAND);
1749                 evas_object_show(base);
1750                 break;
1751         default:
1752                 DBG("Unsupported ug layout");
1753                 break;
1754         }
1755
1756 }
1757
1758 static void __cal_edit_ug_timezone_select_callback(Evas_Object *obj, void *data)
1759 {
1760         c_retm_if(!data, "data is null");
1761
1762         cal_edit_ug_data *p = data;
1763         struct ug_cbs uc;
1764         ui_gadget_h ug;
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;
1769         uc.priv = p;
1770
1771         ug = ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, NULL, &uc);
1772         p->ug_worldclock = ug;
1773 }
1774
1775 static void __cal_edit_ug_update_time_zone_language(Evas_Object *item, const char *timezone_city, const char *timezone_offset)
1776 {
1777         elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_TIME_ZONE"));
1778
1779         char buffer[128] = {0};
1780
1781         snprintf(buffer, sizeof(buffer), "%s, %s", S_(timezone_city), timezone_offset);
1782
1783         elm_object_part_text_set(item, "elm.text.1", buffer);
1784 }
1785
1786 static Evas_Object *__cal_edit_ug_add_time_zone(cal_edit_ug_data* p)
1787 {
1788         c_retv_if(!p, NULL);
1789
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");
1792
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");
1795
1796         __cal_edit_ug_get_record_time_zone(p, p->event);
1797
1798         __cal_edit_ug_update_time_zone_language(item, p->timezone_city, p->timezone_offset);
1799
1800         return item;
1801 }
1802
1803 static void __cal_edit_ug_alarm_changed_callback(const Cal_Reminder* reminder, void* data)
1804 {
1805         CAL_FN_START;
1806
1807         c_retm_if(!data, "data is null");
1808
1809         Evas_Object *obj = data;
1810
1811         char* alarm_text = NULL;
1812         char buf[128] = {0};
1813         cal_reminder_get_string(reminder, buf, sizeof(buf));
1814         alarm_text = strdup(buf);
1815
1816         elm_object_part_text_set(obj, "elm.text.1", alarm_text);
1817         CAL_FREE(alarm_text);
1818
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;
1823 }
1824
1825 static void __cal_edit_ug_alarm_select_callback(Evas_Object *obj, void *data)
1826 {
1827         CAL_FN_START;
1828
1829         c_retm_if(!data, "data is null");
1830
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;
1834
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;
1839         else
1840                 alarm_type = ALARM_TYPE_TODO;
1841
1842         cal_edit_alarm_create_view(p->window, p->conformant, p->naviframe, reminder, alarm_type, __cal_edit_ug_alarm_changed_callback, obj);
1843
1844 }
1845
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);
1847
1848 static void __cal_edit_ug_delete_reminder_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
1849 {
1850         CAL_FN_START;
1851
1852         c_ret_if(!data);
1853
1854         free(data);
1855 }
1856
1857
1858 static void __cal_edit_ug_alarm_plus_button_callback(void *data, Evas_Object *obj, void *event_info)
1859 {
1860         CAL_FN_START;
1861
1862         c_retm_if(!data, "data is null");
1863         c_retm_if(!obj, "obj is null");
1864
1865         cal_edit_ug_data* p = data;
1866
1867         if (eina_list_count(p->alarm_item_list)>=4) {
1868                 evas_object_del(p->alarm_plus_button);
1869                 p->alarm_plus_button = NULL;
1870         }
1871
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;
1876
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);
1880
1881 }
1882
1883 static Evas_Object * __cal_edit_ug_alarm_plus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1884 {
1885         c_retv_if(!p, NULL);
1886         c_retv_if(!obj, NULL);
1887
1888         Evas_Object *button = NULL;
1889
1890         button = elm_button_add(obj);
1891         c_retvm_if(!button, NULL, "elm_button_add() is failed");
1892
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;
1898
1899         return button;
1900 }
1901
1902 static void __cal_edit_ug_alarm_minus_button_callback(void *data, Evas_Object *obj, void *event_info)
1903 {
1904         CAL_FN_START;
1905
1906         c_retm_if(!data, "data is null");
1907         c_retm_if(!obj, "obj is null");
1908
1909         cal_edit_ug_data* p = data;
1910
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);
1915         }
1916
1917         evas_object_smart_callback_del(obj, "clicked", __cal_edit_ug_alarm_minus_button_callback);
1918
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);
1921
1922         cal_dialogue_delete_item(p->dialogue, parent_item);
1923         evas_object_del(obj);
1924
1925
1926 }
1927
1928
1929 static Evas_Object * __cal_edit_ug_alarm_minus_button_icon(cal_edit_ug_data* p, Evas_Object *obj)
1930 {
1931         c_retv_if(!p, NULL);
1932         c_retv_if(!obj, NULL);
1933
1934         Evas_Object *button = NULL;
1935
1936         button = elm_button_add(obj);
1937         c_retvm_if(!button, NULL, "elm_button_add() is failed");
1938
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);
1944
1945         return button;
1946 }
1947
1948 static void __cal_edit_ug_update_reminder_language(Eina_List *item_list)
1949 {
1950         c_ret_if(!item_list);
1951
1952         Eina_List *cursor = NULL;
1953         Evas_Object *item = NULL;
1954
1955         EINA_LIST_FOREACH(item_list, cursor, item) {
1956                 if (!item)
1957                         continue;
1958
1959                 elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1960
1961                 Cal_Reminder *reminder = NULL;
1962
1963                 reminder = evas_object_data_get(item, "data");
1964
1965                 char buffer[128] = {0};
1966                 cal_reminder_get_string(reminder, buffer, sizeof(buffer));
1967
1968                 elm_object_part_text_set(item, "elm.text.1", buffer);
1969         }
1970 }
1971
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)
1973 {
1974         c_retv_if(!p, NULL);
1975         Evas_Object *item = NULL;
1976         if(after) {
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");
1979         }
1980         else {
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");
1983         }
1984
1985         elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REMINDER"));
1986
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);
1991
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);
1994
1995         if(p->item_type == ITEM_TYPE_EVENT)     {
1996                 Evas_Object *button_obj = NULL;
1997                 if(is_add_mode)
1998                         button_obj = __cal_edit_ug_alarm_plus_button_icon(p, item);
1999                 else
2000                         button_obj = __cal_edit_ug_alarm_minus_button_icon(p, item);
2001
2002                 elm_object_part_content_set(item, "elm.icon", button_obj);
2003         }
2004
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);
2007
2008         return item;
2009 }
2010
2011 static void __cal_edit_ug_add_multi_alarm(cal_edit_ug_data* p)
2012 {
2013         c_retm_if(!p, "p is null");
2014
2015         Cal_Reminder* reminder = NULL;
2016         reminder = calloc(1, sizeof(Cal_Reminder));
2017         c_retm_if(!reminder, "reminder is null");
2018
2019         reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
2020         reminder->datetime = p->stm;
2021         Evas_Object *after = NULL;
2022         Evas_Object *item = NULL;
2023
2024         if(p->is_edit_mode)     {
2025                 if (p->item_type == ITEM_TYPE_EVENT)
2026                         __cal_edit_ug_get_record_alarm(p, p->event);
2027                 else
2028                         __cal_edit_ug_get_record_alarm(p, p->todo);
2029
2030                 if(!p->alarm_list) {
2031                         reminder->tick_unit = CALENDAR_ALARM_NONE;\
2032                 }
2033         }
2034
2035         GList *temp = p->alarm_list;
2036         if (!temp) {
2037                  __cal_edit_ug_add_alarm(p, reminder, EINA_TRUE, NULL);
2038         }
2039         else {
2040                 free(reminder);
2041
2042                 while (temp) {
2043                         if(!after)      {
2044                                 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_TRUE, after);
2045                         }
2046                         else    {
2047                                 item = __cal_edit_ug_add_alarm( p, (Cal_Reminder*)temp->data, EINA_FALSE, after);
2048                         }
2049                         c_retm_if(!item, "item is null");
2050                         after = item;
2051                         temp = g_list_next(temp);
2052                 }
2053         }
2054 }
2055
2056 static void __cal_edit_ug_reponse_event_callback(void *data, Evas_Object *obj, void *ei)
2057 {
2058         c_retm_if(!data, "data is null");
2059
2060         Evas_Object *popup = data;
2061         evas_object_del(popup);
2062 }
2063
2064 static void __cal_edit_ug_repeat_callback(void *data)
2065 {
2066         c_retm_if(!data, "data is null");
2067
2068         cal_edit_ug_data *p = data;
2069
2070         calendar_range_type_e range = CALENDAR_RANGE_NONE;
2071         struct tm until = {0};
2072         int count = 0;
2073
2074         int repeat = cal_edit_repeat_get_repeat(p->repeat_layout, &range, &until, &count);
2075
2076         if (CALENDAR_RECURRENCE_NONE != repeat) {
2077
2078                 if (range == CALENDAR_RANGE_UNTIL) {
2079
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);
2083                                 return;
2084                         }
2085                 }
2086                 else if (range == CALENDAR_RANGE_COUNT) {
2087
2088                         if (!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);
2091                                 return;
2092                         }
2093                 }
2094         }
2095
2096         p->repeat_freq = repeat;
2097         p->repeat_range = range;
2098         p->repeat_until = until;
2099         p->repeat_count = count;
2100
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);
2104
2105         __cal_edit_ug_set_record_repeat(p);
2106
2107 }
2108
2109 static void __cal_edit_ug_repeat_select_callback(Evas_Object *obj, void *data)
2110 {
2111         c_retm_if(!data, "data is null");
2112
2113         cal_edit_ug_data* p = data;
2114
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");
2118
2119 }
2120
2121 static void __cal_edit_ug_update_recurrence_language(Evas_Object *item, int repeat_frequency)
2122 {
2123         c_ret_if(!item);
2124
2125         elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_REPEAT"));
2126
2127         char buffer[128] = {0};
2128
2129         _cal_edit_repeat_get_freq_str(repeat_frequency, buffer, sizeof(buffer));
2130
2131         elm_object_part_text_set(item, "elm.text.1", buffer);
2132 }
2133
2134 static Evas_Object *__cal_edit_ug_add_repeat(cal_edit_ug_data* p)
2135 {
2136         c_retv_if(!p, NULL);
2137
2138         Eina_List *list = eina_list_last(p->alarm_item_list);
2139         Evas_Object *last_item = eina_list_data_get(list);
2140
2141         Evas_Object *item = NULL;
2142
2143         if (p->instance) {
2144
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");
2147
2148         } else
2149                 item = cal_dialogue_insert_item_after(p->dialogue, "2text.2", last_item, __cal_edit_ug_repeat_select_callback, p);
2150
2151         c_retvm_if(!item, NULL, "cal_dialogue_append_item() is failed");
2152
2153         __cal_edit_ug_get_record_repeat(p, p->event);
2154
2155         __cal_edit_ug_update_recurrence_language(item, p->repeat_freq);
2156
2157         return item;
2158 }
2159
2160 static void  __cal_edit_ug_popup_hide_callback(void *data, Evas_Object *obj, void *event_info)
2161 {
2162         c_retm_if(!data, "data is null");
2163         c_retm_if(!obj, "obj is null");
2164
2165         Evas_Object *popup = data;
2166
2167         cal_edit_ug_data *p = evas_object_data_get(popup, "data");
2168
2169         evas_object_del(popup);
2170
2171         c_retm_if(!p, "p is null");
2172
2173         p->popup = NULL;
2174 }
2175
2176 static char *__cal_edit_ug_get_genlist_save_to_item_label(void *data, Evas_Object *obj, const char *part)
2177 {
2178         c_retvm_if(!data, NULL, "data is null");
2179         c_retvm_if(!part, NULL, "part is null");
2180
2181         calendar_record_h record = (calendar_record_h)data;
2182         char *name;
2183         int cid;
2184         char* description;
2185
2186         calendar_error_e error = CALENDAR_ERROR_NONE;
2187
2188         calendar_record_h calendar_book = NULL;
2189
2190         _calendar_record_type record_type = _calendar_get_record_type(record);
2191
2192         if (record_type == _CALENDAR_RECORD_TYPE_CALENDARBOOK)
2193                 calendar_book = record;
2194         else {
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);
2197
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);
2200         }
2201
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);
2204
2205         if (!CAL_STRCMP(part,"elm.text.1")) {
2206
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"));
2211
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);
2214
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);
2218                 }
2219
2220                 if (CAL_STRLEN(name))
2221                         return name;
2222                 else
2223                         CAL_FREE(name);
2224
2225                 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2226
2227         } else if (!CAL_STRCMP(part,"elm.text.2")) {
2228
2229                 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID || cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
2230                         return strdup(C_("IDS_CLD_POP_MY_PHONE"));
2231
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);
2234
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);
2238                 }
2239
2240                 if (CAL_STRLEN(description))
2241                         return description;
2242                 else
2243                         CAL_FREE(description);
2244
2245                 return strdup(S_("IDS_COM_POP_NO_ACCOUNTS"));
2246         }
2247
2248         return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
2249 }
2250
2251 static Evas_Object* __cal_edit_ug_add_save_to_icon(void *item_data, Evas_Object *obj, const char *part)
2252 {
2253         if (!item_data)
2254         {
2255                 ERR("item_data is null");
2256                 return NULL;
2257         }
2258
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);
2265
2266         if (!CAL_STRCMP(part, "elm.icon"))
2267         {
2268                 icon = elm_icon_add(obj);
2269
2270                 if (!icon)
2271                 {
2272                         ERR("elm_icon_add fail");
2273                         return NULL;
2274                 }
2275
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);
2279                 } else {
2280                         icon_path = cal_account_svc_get_account_icon_path(aid);
2281                         if (icon_path) {
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);
2284                                 free(icon_path);
2285                         }
2286                         else {
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);
2289                         }
2290
2291                 }
2292
2293                 if (!r) {
2294                         ERR("");
2295                         evas_object_del(icon);
2296                         icon = NULL;
2297                 }
2298                 else
2299                         evas_object_show(icon);
2300         }
2301
2302         return icon;
2303 }
2304
2305 static Eina_Bool __cal_edit_ug_popup_idler_callback(void *data)
2306 {
2307         c_retv_if(!data, ECORE_CALLBACK_CANCEL);
2308
2309         cal_edit_ug_data *p = data;
2310
2311         if (p->popup) {
2312                 evas_object_del(p->popup);
2313                 p->popup = NULL;
2314         }
2315
2316         p->idler = NULL;
2317
2318         return ECORE_CALLBACK_CANCEL;
2319 }
2320
2321 static void __cal_edit_ug_save_to_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2322 {
2323         CAL_FN_START;
2324
2325         c_retm_if(!data, "data is null");
2326         c_retm_if(!obj, "obj is null");
2327
2328         calendar_record_h calendar_book = data;
2329         int calendar_book_id = 0;
2330
2331         cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2332         c_retm_if(!p, "p is null");
2333
2334         Elm_Object_Item *item = elm_genlist_selected_item_get(obj);
2335         c_retm_if(!item, "elm_genlist_selected_item_get() returned null");
2336
2337         elm_genlist_item_selected_set(item, EINA_FALSE);
2338
2339         calendar_error_e error = CALENDAR_ERROR_NONE;
2340
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);
2343
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);
2347         }
2348         else    {
2349                 __cal_edit_ug_set_record_save_to(p->event, calendar_book_id);
2350                 __cal_edit_ug_update_save_to_item(p, p->event);
2351         }
2352
2353         if (p->idler) {
2354                 ecore_idler_del(p->idler);
2355                 p->idler = NULL;
2356         }
2357
2358         p->idler = ecore_idler_add(__cal_edit_ug_popup_idler_callback, p);
2359         c_ret_if(!p->idler);
2360
2361 }
2362
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,
2367 };
2368
2369 static Evas_Object* __cal_edit_ug_create_save_to_popup(cal_edit_ug_data* p)
2370 {
2371         c_retv_if(!p, NULL);
2372
2373         Evas_Object *popup = NULL;
2374         Evas_Object *genlist = NULL;
2375
2376         Eina_List *l;
2377
2378         calendar_error_e error = CALENDAR_ERROR_NONE;
2379
2380         if (!p->calendar_book_list)
2381         {
2382                 p->calendar_book_list = _calendar_get_calendar_book_list_with_account_id(_CALENDAR_ALL_ACCOUNT_ID);
2383         }
2384
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");
2388
2389         genlist = elm_genlist_add(popup);
2390         if (!genlist) {
2391                 ERR("elm_genlist_add(popup) returned null");
2392                 evas_object_del(popup);
2393                 return NULL;
2394         }
2395
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);
2399
2400         calendar_record_h calendar_book = NULL;
2401
2402         EINA_LIST_FOREACH(p->calendar_book_list, l, calendar_book) {
2403
2404                 int store_type = 0;
2405
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);
2409                         continue;
2410                 }
2411
2412                 int sync_event = 0;
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);
2415                 if(!sync_event)
2416                         continue;
2417
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);
2421                 } else {
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);
2424                 }
2425
2426         }
2427
2428         elm_object_content_set(popup, genlist);
2429         evas_object_show(genlist);
2430
2431         return popup;
2432 }
2433
2434 static void __cal_edit_ug_saveto_select_callback(Evas_Object *obj, void *data)
2435 {
2436         c_retm_if(!data, "data is null");
2437
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");
2441
2442         p->popup = popup;
2443 }
2444
2445 static void __cal_edit_ug_get_save_to_str(int calid, char *buf, int sz)
2446 {
2447         calendar_record_h calendar_book = NULL;
2448         char *str;
2449
2450         calendar_error_e error = CALENDAR_ERROR_NONE;
2451
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);
2454
2455         if (calid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
2456                 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
2457         else
2458         {
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);
2461
2462         }
2463
2464         snprintf(buf, sz, "%s", str);
2465
2466         if (str)
2467                 free(str);
2468
2469         error = calendar_record_destroy(calendar_book, true);
2470         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2471 }
2472
2473 static void __cal_edit_ug_update_saveto_language(Evas_Object *item, calendar_record_h record)
2474 {
2475         c_ret_if(!item);
2476
2477         elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2478
2479         int calendar_book_id = _calendar_get_calendar_index(record);
2480
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"));
2485 }
2486
2487 static Evas_Object *__cal_edit_ug_add_saveto(cal_edit_ug_data* p)
2488 {
2489         c_retv_if(!p, NULL);
2490
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");
2493
2494         elm_object_part_text_set(item, "elm.text.2", C_("IDS_ST_BODY_SAVE_TO"));
2495
2496         char buf[1024];
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);
2502         }
2503         else    {
2504                 calendar_book_id = _calendar_get_calendar_index(p->event);
2505                 p->account_id = _calendar_get_account_id(p->event);
2506         }
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"));
2511         else {
2512                 __cal_edit_ug_get_save_to_str(calendar_book_id, buf, sizeof(buf));
2513                 saveto_text = strdup(buf);
2514         }
2515
2516         elm_object_part_text_set(item, "elm.text.1", saveto_text);
2517         CAL_FREE(saveto_text);
2518
2519         if (p->instance)
2520                 elm_object_signal_emit(item, "elm,state,disabled", "elm");
2521
2522         return item;
2523 }
2524
2525 static void __cal_edit_ug_no_due_date_clicked_callback(Evas_Object *obj, void *data)
2526 {
2527         c_retm_if(!data, "data is NULL.");
2528         c_retm_if(!obj, "obj is NULL.");
2529
2530         cal_edit_ug_data *p = data;
2531
2532         Evas_Object *check_obj = elm_object_part_content_get(p->no_due_date, "elm.icon");
2533
2534         if(p->is_no_due_date)
2535         {
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");
2539         }
2540         else
2541         {
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");
2546         }
2547
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);
2550 }
2551
2552 static void __cal_edit_ug_no_due_date_changed_callback(void *data, Evas_Object *obj, void *ei)
2553 {
2554         c_retm_if(!data, "data is NULL.");
2555         c_retm_if(!obj, "obj is NULL.");
2556
2557         cal_edit_ug_data *p = data;
2558
2559         p->is_no_due_date = elm_check_state_get(obj);
2560
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)
2564         {
2565                 __cal_edit_ug_set_record_due_time(p, p->todo);
2566                 elm_object_signal_emit(p->due_date, "elm,state,disabled", "elm");
2567         }
2568         else
2569         {
2570                 elm_object_signal_emit(p->due_date, "elm,state,enabled", "elm");
2571         }
2572 }
2573
2574 static void __cal_edit_ug_update_no_due_date_language(Evas_Object *item)
2575 {
2576         elm_object_part_text_set(item, "elm.text", C_("IDS_TASK_MBODY_NO_DUE_DATE"));
2577 }
2578
2579 static Evas_Object *__cal_edit_ug_add_no_due_date(cal_edit_ug_data* p)
2580 {
2581         c_retv_if(!p, NULL);
2582
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");
2585
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);
2590
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);
2594
2595         __cal_edit_ug_update_no_due_date_language(item);
2596
2597         elm_object_part_content_set(item, "elm.icon", check_obj);
2598
2599         return item;
2600 }
2601
2602 static void __cal_edit_ug_priority_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
2603 {
2604         c_ret_if(!data);
2605         c_ret_if(!obj);
2606
2607         int priority = (int)data;
2608
2609         cal_edit_ug_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
2610         c_ret_if(!p);
2611
2612         __cal_edit_ug_set_record_priority(p->todo, priority);
2613         __cal_edit_ug_update_priority_item(p, p->todo);
2614
2615         evas_object_del(p->popup);
2616         p->popup = NULL;
2617 }
2618
2619 static Evas_Object* __cal_edit_ug_create_priority_popup(cal_edit_ug_data* p)
2620 {
2621         c_retv_if(!p, NULL);
2622
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);
2626
2627         evas_object_data_set(popup, "priv", p);
2628
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);
2631
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);
2634
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);
2637
2638         return popup;
2639 }
2640
2641 static void __cal_edit_ug_priority_select_callback(Evas_Object *obj, void *data)
2642 {
2643         c_retm_if(!data, "data is null");
2644         cal_edit_ug_data* p = data;
2645
2646         Evas_Object *popup = __cal_edit_ug_create_priority_popup(p);
2647         c_retm_if(!popup, "popup is NULL");
2648
2649         p->popup = popup;
2650
2651 }
2652
2653 static void __cal_edit_ug_update_priority_language(Evas_Object *item, calendar_record_h record)
2654 {
2655         elm_object_part_text_set(item, "elm.text.2", C_("IDS_CLD_BODY_PRIORITY"));
2656
2657         char* priority_text = NULL;
2658         int priority = __cal_edit_ug_get_record_priority(record);
2659         switch (priority) {
2660                 case CALENDAR_TODO_PRIORITY_LOW:
2661                         priority_text = strdup(S_("IDS_COM_BODY_LOW"));
2662                         break;
2663                 case CALENDAR_TODO_PRIORITY_NORMAL:
2664                         priority_text =strdup(C_("IDS_IDLE_BODY_NORMAL"));
2665                         break;
2666                 case CALENDAR_TODO_PRIORITY_HIGH:
2667                         priority_text =strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
2668                         break;
2669                 default:
2670                         break;
2671         }
2672
2673         elm_object_part_text_set(item, "elm.text.1", priority_text);
2674         CAL_FREE(priority_text);
2675 }
2676
2677 static Evas_Object *__cal_edit_ug_add_priority(cal_edit_ug_data* p)
2678 {
2679         c_retv_if(!p, NULL);
2680
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");
2683
2684         __cal_edit_ug_update_priority_language(item, p->todo);
2685
2686         return item;
2687 }
2688
2689 static void __cal_edit_ug_show_result_popup(cal_edit_ug_data *p, calendar_error_e error)
2690 {
2691         char buf[100]={0,};
2692
2693         // TODO: i18n
2694         switch(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);
2698                 break;
2699
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);
2703                 break;
2704
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);
2708                 break;
2709
2710         default:
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);
2714                 break;
2715         }
2716 }
2717
2718 int __cal_edit_ug_save(cal_edit_ug_data *p, calendar_record_h record)
2719 {
2720         CAL_FN_START;
2721
2722         calendar_error_e error = CALENDAR_ERROR_NONE;
2723
2724         int record_index = 0;
2725
2726         calendar_record_type_e record_type = CALENDAR_RECORD_TYPE_EVENT;
2727
2728         if (_calendar_is_task_record(record))
2729                 record_type = CALENDAR_RECORD_TYPE_TODO;
2730
2731         __cal_edit_ug_set_record_alarm(p, record);
2732
2733         if (p->is_edit_mode) {
2734                 if (p->instance) {
2735
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);
2739
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);
2743
2744                         __cal_edit_ug_set_record_time(p, exception_record);
2745                         _calendar_edit_recurrence_instance(exception_record, index);
2746
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);
2749
2750                         if (error != CALENDAR_ERROR_NONE) {
2751                                 __cal_edit_ug_show_result_popup(p, error);
2752
2753                                 error = calendar_record_destroy(exception_record, true);
2754                                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2755
2756                                 return -1;
2757                         }
2758
2759                         error = calendar_record_destroy(exception_record, true);
2760                         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2761
2762                 } else {
2763
2764                         if (p->account_id == _calendar_get_account_id(record))
2765                         {
2766                                 error = calendar_db_update_record(record);
2767                                 if (error != CALENDAR_ERROR_NONE) {
2768
2769                                         ERR("calendar_db_update_record() is failed(%x)", error);
2770
2771                                         __cal_edit_ug_show_result_popup(p, error);
2772
2773                                         return -1;
2774                                 }
2775                                 record_index = _calendar_get_record_index(record);
2776                         }
2777                         else
2778                         {
2779                                 _calendar_delete_record(record);
2780
2781                                 error = calendar_db_insert_record(record, &record_index);
2782                                 if (error != CALENDAR_ERROR_NONE) {
2783
2784                                         ERR("calendar_db_insert_record() is failed(%x)", error);
2785                                         __cal_edit_ug_show_result_popup(p, error);
2786
2787                                         return -1;
2788                                 }
2789                         }
2790                 }
2791
2792         } else {
2793
2794                 error = calendar_db_insert_record(record, &record_index);
2795                 if (error != CALENDAR_ERROR_NONE) {
2796
2797                         ERR("calendar_db_insert_record() is failed(%x)", error);
2798
2799                         __cal_edit_ug_show_result_popup(p, error);
2800
2801                         return -1;
2802                 }
2803         }
2804
2805         return record_index;
2806 }
2807
2808 static void __cal_edit_ug_send_result_to_detail_ug(cal_edit_ug_data *p, int record_index)
2809 {
2810         c_retm_if(!p, "p is null");
2811         c_retm_if(record_index < 0, "record_index < 0");
2812
2813         service_h service = NULL;
2814
2815         int ret = service_create(&service);
2816         c_ret_if(ret != SERVICE_ERROR_NONE);
2817
2818         char value[64] = {0};
2819         snprintf(value, sizeof(value), "%d", record_index);
2820
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);
2823
2824         memset(value, 0x00, sizeof(value));
2825
2826         long long int lli_time = 0;
2827         cal_util_convert_tm_to_lli(NULL, &p->stm, &lli_time);
2828
2829         snprintf(value, sizeof(value), "%lli", lli_time);
2830
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);
2833
2834         ug_send_result(p->ug, service);
2835
2836         ret = service_destroy(service);
2837         c_warn_if(ret != SERVICE_ERROR_NONE, "service_destroy() is failed(%x)", ret);
2838 }
2839
2840 static void __cal_edit_ug_save_button_callback(void *data, Evas_Object *obj, void *event_info)
2841 {
2842         CAL_FN_START;
2843
2844         c_retm_if(!data, "data is null");
2845         cal_edit_ug_data* p = data;
2846         int record_index;
2847
2848         Eina_Bool result = __cal_edit_ug_check_date_validity(p);
2849         if(!result)     {
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);
2852                 return;
2853         }
2854
2855         if (p->item_type == ITEM_TYPE_TODO)
2856                 record_index = __cal_edit_ug_save(p, p->todo);
2857         else
2858                 record_index = __cal_edit_ug_save(p, p->event);
2859
2860         c_retm_if(record_index < 0, "cal_edit_save() is failed");
2861
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);
2864
2865         __cal_edit_ug_send_result_to_detail_ug(p, record_index);
2866
2867         ug_destroy_me(p->ug);
2868
2869 }
2870
2871 static Eina_Bool __cal_edit_ug_input_panel_is_shown(cal_edit_ug_data *p)
2872 {
2873         c_retv_if(!p, EINA_FALSE);
2874
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");
2878
2879         if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW)     {
2880                 ecore_imf_context_input_panel_hide(ic);
2881                 return EINA_TRUE;
2882         }
2883
2884         ic = elm_entry_imf_context_get(p->note_entry);
2885         c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2886
2887         if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW)     {
2888                 ecore_imf_context_input_panel_hide(ic);
2889                 return EINA_TRUE;
2890         }
2891
2892         ic = elm_entry_imf_context_get(p->location_entry);
2893         c_retvm_if(!ic, EINA_FALSE, "elm_entry_imf_context_get returned null");
2894
2895         if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW)     {
2896                 ecore_imf_context_input_panel_hide(ic);
2897                 return EINA_TRUE;
2898         }
2899
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");
2903
2904                 if(ecore_imf_context_input_panel_state_get(ic) == ECORE_IMF_INPUT_PANEL_STATE_SHOW)     {
2905                         ecore_imf_context_input_panel_hide(ic);
2906                         return EINA_TRUE;
2907                 }
2908         }
2909
2910         return EINA_FALSE;
2911 }
2912
2913 static void __cal_edit_ug_back_button_callback(void *user_data, Evas_Object *obj, void *ei)
2914 {
2915         CAL_FN_START;
2916
2917         c_ret_if(!user_data);
2918
2919         cal_edit_ug_data *data = user_data;
2920
2921         c_ret_if(!data->ug);
2922
2923         if(!__cal_edit_ug_input_panel_is_shown(data))
2924                 ug_destroy_me(data->ug);
2925 }
2926
2927 static void __cal_edit_ug_show_multi_alarms (cal_edit_ug_data *p)
2928 {
2929         c_retm_if(!p, "p is null");
2930
2931         Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
2932
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);
2936         }
2937         Eina_List *list = eina_list_next(p->alarm_item_list);
2938         Eina_List *l;
2939         Evas_Object *item = NULL;
2940
2941         EINA_LIST_FOREACH(list, l, item)        {
2942                 if(item){
2943                         cal_dialogue_show_item_after(p->dialogue, item, first_item);
2944                         first_item = item;
2945                 }
2946         }
2947 }
2948
2949 static void __cal_edit_ug_show_event_items (cal_edit_ug_data *p)
2950 {
2951         c_retm_if(!p, "p is null");
2952
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);
2955         else
2956                 cal_dialogue_show_item_after(p->dialogue, p->start_date_title, p->title);
2957
2958         Eina_Bool is_allday = EINA_FALSE;
2959
2960         if (!p->start_date) {
2961
2962                 is_allday = _calendar_is_allday_record(p->event);
2963
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);
2965
2966         } else
2967                 cal_dialogue_show_item_after(p->dialogue, p->start_date, p->start_date_title);
2968
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);
2971         else
2972                 cal_dialogue_show_item_after(p->dialogue, p->end_date_title, p->start_date);
2973
2974         if (!p->end_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);
2976         else
2977                 cal_dialogue_show_item_after(p->dialogue, p->end_date, p->end_date_title);
2978
2979         if (!p->timezone)
2980                 p->timezone = __cal_edit_ug_add_time_zone(p);
2981         else
2982                 cal_dialogue_show_item_after(p->dialogue, p->timezone, p->end_date);
2983
2984         if (!p->allday)
2985                 p->allday = __cal_edit_ug_add_all_day(p, is_allday);
2986         else
2987                 cal_dialogue_show_item_after(p->dialogue, p->allday, p->timezone);
2988
2989         __cal_edit_ug_show_multi_alarms(p);
2990
2991         Eina_List *list = eina_list_last(p->alarm_item_list);
2992         Evas_Object *last_item = eina_list_data_get(list);
2993
2994         if (!p->repeat)
2995                 p->repeat = __cal_edit_ug_add_repeat(p);
2996         else
2997                 cal_dialogue_show_item_after(p->dialogue, p->repeat, last_item);
2998
2999 }
3000
3001 static void __cal_edit_ug_show_todo_items (cal_edit_ug_data *p)
3002 {
3003         c_retm_if(!p, "p is null");
3004
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);
3007         else
3008                 cal_dialogue_show_item_after(p->dialogue, p->due_date_title, p->title);
3009
3010         if (!p->due_date)
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);
3012         else
3013                 cal_dialogue_show_item_after(p->dialogue, p->due_date, p->due_date_title);
3014
3015         if (!p->no_due_date)
3016                 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3017         else
3018                 cal_dialogue_show_item_after(p->dialogue, p->no_due_date, p->due_date);
3019
3020         Evas_Object *first_item = eina_list_nth(p->alarm_item_list, 0);
3021         if (!p->priority)
3022                 p->priority = __cal_edit_ug_add_priority(p);
3023         else
3024                 cal_dialogue_show_item_after(p->dialogue, p->priority, first_item);
3025 }
3026
3027 static void __cal_edit_ug_hide_multi_alarms (cal_edit_ug_data *p)
3028 {
3029         c_retm_if(!p, "p is null");
3030
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");
3033         if(button_obj)  {
3034                 evas_object_del(button_obj);
3035                 button_obj = NULL;
3036         }
3037
3038         Eina_List *list = p->alarm_item_list;
3039         list = eina_list_next(list);
3040         Eina_List *l;
3041         Evas_Object *item = NULL;
3042
3043         EINA_LIST_FOREACH(list, l, item)        {
3044                 if(item){
3045                         cal_dialogue_hide_item(p->dialogue, item);
3046                 }
3047         }
3048 }
3049
3050 static void __cal_edit_ug_hide_event_items (cal_edit_ug_data *p)
3051 {
3052         c_retm_if(!p, "p is null");
3053
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);
3062
3063 }
3064
3065 static void __cal_edit_ug_hide_todo_items (cal_edit_ug_data *p)
3066 {
3067         c_retm_if(!p, "p is null");
3068
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);
3073
3074 }
3075
3076 static void __cal_edit_ug_update_event_info (cal_edit_ug_data *p)
3077 {
3078         c_retm_if(!p, "p is null");
3079
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);
3083
3084         __cal_edit_ug_update_save_to_item(p, p->event);
3085 }
3086
3087 static void __cal_edit_ug_update_todo_info (cal_edit_ug_data *p)
3088 {
3089         c_retm_if(!p, "p is null");
3090
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);
3094
3095         __cal_edit_ug_update_save_to_item(p, p->todo);
3096
3097 }
3098
3099 static void __cal_edit_ug_new_event_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3100 {
3101         CAL_FN_START;
3102
3103         c_retm_if(!data, "data null");
3104
3105         cal_edit_ug_data *p = data;
3106
3107         if(p->item_type == ITEM_TYPE_EVENT)
3108                 return;
3109
3110         p->item_type = ITEM_TYPE_EVENT;
3111
3112         __cal_edit_ug_hide_todo_items(p);
3113         __cal_edit_ug_show_event_items(p);
3114         __cal_edit_ug_update_event_info(p);
3115
3116 }
3117
3118 static void __cal_edit_ug_new_todo_clicked_callback (void *data, Evas_Object * obj, void *event_info)
3119 {
3120         CAL_FN_START;
3121
3122         c_retm_if(!data, "data null");
3123
3124         cal_edit_ug_data *p = data;
3125
3126         if(p->item_type == ITEM_TYPE_TODO)
3127                 return;
3128
3129         p->item_type = ITEM_TYPE_TODO;
3130
3131         __cal_edit_ug_hide_event_items(p);
3132         __cal_edit_ug_show_todo_items(p);
3133         __cal_edit_ug_update_todo_info(p);
3134
3135 }
3136
3137 static void __cal_edit_ug_add_dialogue_items(cal_edit_ug_data *p)
3138 {
3139         CAL_FN_START;
3140
3141         c_retm_if(!p, "p is null");
3142
3143         p->title = __cal_edit_ug_add_title(p);
3144
3145         calendar_time_s time = {0};
3146
3147         if (p->item_type == ITEM_TYPE_TODO) {
3148
3149                 p->due_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_DUE_DATE"), p->title);
3150
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);
3154
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);
3156
3157                 p->no_due_date = __cal_edit_ug_add_no_due_date(p);
3158
3159                 p->priority = __cal_edit_ug_add_priority(p);
3160         } else {
3161
3162                 p->start_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_FROM"), p->title);
3163
3164                 if (p->instance)
3165                         _calendar_get_start_time(p->instance, &time);
3166                 else
3167                         _calendar_get_start_time(p->event, &time);
3168
3169                 _calendar_convert_calendar_time_to_tm(&time, &p->stm);
3170                 Eina_Bool allday = _calendar_is_allday_record(p->event);
3171
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);
3173
3174                 p->end_date_title = __cal_edit_ug_insert_padding_after(p, C_("IDS_CLD_BODY_TO"), p->start_date);
3175
3176                 if (p->instance)
3177                         _calendar_get_end_time(p->instance, &time);
3178                 else
3179                         _calendar_get_end_time(p->event, &time);
3180
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);
3183
3184                 p->timezone = __cal_edit_ug_add_time_zone(p);
3185
3186                 p->allday = __cal_edit_ug_add_all_day(p, allday);
3187
3188         }
3189
3190         p->note = __cal_edit_ug_add_note(p);
3191
3192         p->location = __cal_edit_ug_add_location(p);
3193
3194         __cal_edit_ug_add_multi_alarm(p);
3195
3196         if (p->item_type == ITEM_TYPE_EVENT) {
3197                 p->repeat = __cal_edit_ug_add_repeat(p);
3198         }
3199
3200         p->saveto = __cal_edit_ug_add_saveto(p);
3201 }
3202
3203 static void __cal_edit_ug_update_naviframe_language(cal_edit_ug_data *data)
3204 {
3205         c_ret_if(!data->naviframe);
3206
3207         Elm_Object_Item *item = elm_naviframe_top_item_get(data->naviframe);
3208         c_ret_if(!item);
3209
3210         if (data->is_edit_mode) {
3211
3212                 if (data->item_type == ITEM_TYPE_TODO)
3213                         elm_object_item_part_text_set(item, "default", C_("IDS_TASK_HEADER_EDIT_TASK"));
3214                 else
3215                         elm_object_item_part_text_set(item, "default", C_("IDS_CLD_HEADER_EDIT_EVENT"));
3216
3217         } else
3218                 elm_object_item_part_text_set(item, "default", S_("IDS_COM_BODY_CREATE"));
3219 }
3220
3221 static void __cal_edit_ug_update_tabbar_language(cal_edit_ug_data *data)
3222 {
3223         if (data->is_edit_mode)
3224                 return;
3225
3226         c_ret_if(!data->event_item);
3227         c_ret_if(!data->todo_item);
3228
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"));
3231 }
3232
3233 static void __cal_edit_ug_add_toolbar(cal_edit_ug_data *data, Evas_Object *scroller)
3234 {
3235         CAL_FN_START;
3236
3237         c_retm_if(!data, "data is null");
3238
3239         Elm_Object_Item *navi_item = NULL;
3240
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");
3244         } else {
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");
3247
3248                 data->tabbar = elm_toolbar_add(data->naviframe);
3249                 c_ret_if(!data->tabbar);
3250
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");
3256
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);
3259
3260                         elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3261
3262                         data->event_item = elm_toolbar_item_insert_before(data->tabbar, data->todo_item, NULL, NULL, __cal_edit_ug_new_event_clicked_callback, data);
3263                 } else {
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);
3266
3267                         elm_toolbar_select_mode_set(data->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
3268                 }
3269
3270                 if (data->item_type == ITEM_TYPE_TODO)
3271                         elm_toolbar_item_selected_set(data->todo_item, EINA_TRUE);
3272                 else
3273                         elm_toolbar_item_selected_set(data->event_item, EINA_TRUE);
3274
3275                 __cal_edit_ug_update_tabbar_language(data);
3276
3277         }
3278
3279         __cal_edit_ug_update_naviframe_language(data);
3280
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);
3282
3283 }
3284
3285 static void __cal_edit_ug_dialogue_item_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
3286 {
3287         c_ret_if(!data);
3288         c_ret_if(!obj);
3289
3290         cal_edit_ug_data* p = data;
3291 }
3292
3293 static Evas_Object *__cal_edit_ug_create_dialogue(Evas_Object *parent, cal_edit_ug_data* p)
3294 {
3295         c_retv_if(!p, NULL);
3296
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);
3300
3301         Evas_Object *dialogue = cal_dialogue_get_box(scroller);
3302
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);
3306
3307         return dialogue;
3308
3309 }
3310
3311 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, cal_edit_ug_data *data)
3312 {
3313         CAL_FN_START;
3314
3315         c_retv_if(!parent, NULL);
3316         c_retv_if(!data, NULL);
3317
3318         data->parent = parent;
3319
3320         if (data->item_type == ITEM_TYPE_TODO)
3321                 data->todo = data->record;
3322         else
3323                 data->event = data->record;
3324
3325         if (data->is_edit_mode) {
3326                 __cal_edit_ug_get_record_time_zone(data, data->record);
3327         } else {
3328                 cal_util_get_timezone(&data->timezone_path, &data->timezone_city, &data->timezone_offset);
3329
3330                 __cal_edit_ug_initialize_todo_record(data);
3331                 __cal_edit_ug_initialize_event_record(data);
3332         }
3333
3334         Evas_Object *base_layout = cal_util_add_layout(parent, NULL);
3335         c_retv_if(!base_layout, NULL);
3336
3337         Evas_Object *naviframe = elm_naviframe_add(base_layout);
3338         if (!naviframe) {
3339                 ERR("elm_naviframe_add() is failed");
3340
3341                 evas_object_del(base_layout);
3342
3343                 return NULL;
3344         }
3345
3346         evas_object_show(naviframe);
3347
3348         Evas_Object *bg = cal_util_add_bg(base_layout, EINA_FALSE);
3349         if (!bg) {
3350                 ERR("cal_util_add_bg() is failed");
3351
3352                 evas_object_del(base_layout);
3353
3354                 return NULL;
3355         }
3356
3357         data->base_layout = base_layout;
3358         data->naviframe = naviframe;
3359
3360         cal_util_initialize_timezone();
3361
3362         data->dialogue = __cal_edit_ug_create_dialogue(naviframe, data);
3363         c_warn_if(!data->dialogue, "__cal_edit_ug_create_dialogue() is failed");
3364
3365         __cal_edit_ug_add_dialogue_items(data);
3366
3367
3368         elm_object_part_content_set(base_layout, "elm.swallow.content", naviframe);
3369         elm_object_part_content_set(base_layout, "elm.swallow.bg", bg);
3370
3371         return base_layout;
3372 }
3373
3374 static calendar_record_h inline __cal_edit_ug_get_origin_record(const calendar_record_h instance)
3375 {
3376         CAL_FN_START;
3377
3378         c_retv_if(!instance, NULL);
3379
3380         int index = _calendar_get_record_index(instance);
3381
3382         return _calendar_get_record_with_index(index);
3383 }
3384
3385 static void __cal_edit_ug_get_appcontrol_input_data(service_h service, cal_edit_ug_data *data)
3386 {
3387         CAL_FN_START;
3388
3389         int r = 0;
3390         char *index = 0;
3391         char *item_type = NULL;
3392
3393         r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
3394         c_ret_if(r != SERVICE_ERROR_NONE);
3395
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);
3399
3400                 CAL_FREE(item_type);
3401
3402                 return;
3403         }
3404
3405         CAL_FREE(item_type);
3406
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);
3410
3411                 CAL_FREE(index);
3412
3413                 return;
3414         }
3415
3416         data->is_edit_mode = EINA_TRUE;
3417         data->record = _calendar_get_record_with_index(atoi(index));
3418
3419         if (_calendar_is_task_record(data->record))
3420                 data->item_type == ITEM_TYPE_TODO;
3421         else
3422                 data->item_type == ITEM_TYPE_EVENT;
3423 }
3424
3425 static void __cal_edit_ug_get_appcontrol_input_data_old(service_h service, cal_edit_ug_data *data)
3426 {
3427         CAL_FN_START;
3428
3429         int r = 0;
3430
3431         char *item_type = NULL;
3432
3433         r = service_get_extra_data(service, "itemType", &item_type);
3434         if (r == SERVICE_ERROR_NONE) {
3435
3436                 if (!CAL_STRCMP(item_type, "event")) {
3437                         data->item_type = ITEM_TYPE_EVENT;
3438                         data->is_edit_mode = EINA_TRUE;
3439
3440                         char *index = NULL;
3441
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);
3445
3446                                 CAL_FREE(index);
3447
3448                                 return;
3449                         }
3450
3451                         calendar_record_h record = _calendar_get_record_with_index(atoi(index));
3452                         c_retv_if(!record, NULL);
3453
3454                         CAL_FREE(index);
3455
3456                         data->record = record;
3457
3458                 } else if (!CAL_STRCMP(item_type, "todo")) {
3459
3460                         data->item_type = ITEM_TYPE_TODO;
3461                         data->is_edit_mode = EINA_TRUE;
3462
3463                         char *index = NULL;
3464
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);
3468
3469                                 CAL_FREE(index);
3470
3471                                 return;
3472                         }
3473
3474                         calendar_record_h record = _calendar_get_record_with_index(atoi(index));
3475                         c_retv_if(!record, NULL);
3476
3477                         CAL_FREE(index);
3478
3479                         data->record = record;
3480
3481                 } else if (!CAL_STRCMP(item_type, "vcs")) {
3482
3483                         data->item_type = ITEM_TYPE_VCS;
3484
3485                         char *path = NULL;
3486
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);
3490
3491                                 CAL_FREE(path);
3492
3493                                 return;
3494                         }
3495
3496                         FILE * file = fopen(path, "r");
3497                         if (!file) {
3498                                 ERR("fopen(%s) is failed.", path);
3499
3500                                 CAL_FREE(path);
3501
3502                                 return;
3503                         }
3504
3505                         struct stat st = {0};
3506                         if (stat(path, &st) != 0) {
3507                                 ERR("Getting file information Error!");
3508                                 fclose(file);
3509                                 CAL_FREE(path);
3510
3511                                 return;
3512                         }
3513
3514                         CAL_FREE(path);
3515
3516                         int size = st.st_size;
3517                         char *raw_data = calloc(size + 1, sizeof(char));
3518                         if(!raw_data){
3519                                 ERR("raw_data is NULL!");
3520                                 fclose(file);
3521                                 free(raw_data);
3522
3523                                 return;
3524                         }
3525
3526                         r = fread(raw_data, 1, size, file);
3527                         fclose( file );
3528                         if (r < 0) {
3529                                 ERR("fread() is failed(%d)", errno);
3530
3531                                 return;
3532                         }
3533
3534                         calendar_list_h list = NULL;
3535
3536                         calendar_error_e error = CALENDAR_ERROR_NONE;
3537
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);
3540
3541                         if (list) {
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);
3545
3546                                 error = calendar_record_clone(record, &data->record);
3547                                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
3548
3549                                 error = calendar_list_destroy(list, true);
3550                         }
3551
3552                         free(raw_data);
3553                 }
3554         }
3555
3556         CAL_FREE(item_type);
3557 }
3558
3559 static void __cal_edit_ug_get_ug_input_data(service_h service, cal_edit_ug_data *data)
3560 {
3561         CAL_FN_START;
3562
3563         int r = 0;
3564
3565         char *index = NULL;
3566
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;
3571         }
3572
3573         char *record_address = NULL;
3574
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);
3578
3579                 if (0 < _calendar_get_record_index(data->record))
3580                         data->is_edit_mode = EINA_TRUE;
3581
3582                 _calendar_record_type record_type = _calendar_get_record_type(data->record);
3583
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;
3586
3587                         data->record = __cal_edit_ug_get_origin_record(data->instance);
3588                 }
3589
3590                 if (_calendar_is_task_record(data->record))
3591                         data->item_type = ITEM_TYPE_TODO;
3592                 else
3593                         data->item_type = ITEM_TYPE_EVENT;
3594         } else {
3595                 calendar_error_e error = CALENDAR_ERROR_NONE;
3596
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);
3599
3600                 data->is_edit_mode = EINA_FALSE;
3601
3602                 data->item_type = ITEM_TYPE_EVENT;
3603         }
3604
3605         CAL_FREE(record_address);
3606
3607         //base_time
3608         char *base_time = NULL;
3609
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);
3612
3613         if (base_time) {
3614                 long long int lli_time = strtoll(base_time, NULL, 10);
3615                 cal_util_convert_lli_to_tm(NULL, lli_time, &data->base_time);
3616
3617                 free(base_time);
3618         } else {
3619                 struct tm t = {0};
3620                 struct tm* returned_tm = NULL;
3621                 time_t now = 0;
3622
3623                 now = time(NULL);
3624
3625                 returned_tm = gmtime_r(&now, &t);
3626                 if (!returned_tm)
3627                         ERR("localtime_r is failed.");
3628                 else
3629                         CAL_MEMCPY(&data->base_time, &t, struct tm);
3630         }
3631 }
3632
3633 static void *__cal_edit_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
3634 {
3635         CAL_FN_START;
3636
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);
3641
3642         cal_edit_ug_data *data = priv;
3643
3644         data->ug = ug;
3645
3646         char *operation = NULL;
3647
3648         int r = service_get_operation(service, &operation);
3649         c_retv_if(r != SERVICE_ERROR_NONE, NULL);
3650
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);
3655         else
3656                 __cal_edit_ug_get_ug_input_data(service, data);
3657
3658         CAL_FREE(operation);
3659
3660         if (!data->record) {
3661                 ERR("ERROR!! Invaild parameter!!");
3662                 ug_destroy_me(ug);
3663         }
3664
3665         Evas_Object *parent = ug_get_parent_layout(ug);
3666         c_retv_if(!parent, NULL);
3667
3668         data->window = ug_get_window();
3669         c_retv_if(!data->window, NULL);
3670
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);
3675
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);
3679         }
3680
3681         data->theme = elm_theme_new();
3682         c_retv_if(!data->theme, NULL);
3683
3684         elm_theme_ref_set(data->theme, NULL);
3685
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");
3688
3689         Evas_Object *base = __cal_edit_ug_create_layout(parent, data);
3690         c_retv_if(!base, NULL);
3691
3692         return base;
3693 }
3694
3695 static void __cal_edit_ug_destroy_callback(ui_gadget_h ug, service_h service, void *priv)
3696 {
3697         CAL_FN_START;
3698         c_ret_if(!priv);
3699
3700         cal_edit_ug_data *data = priv;
3701
3702         if (data->save_cancel)
3703                 cal_save_cancel_destroy(data->save_cancel);
3704
3705         cal_util_delete_evas_object(&data->base_layout);
3706
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);
3713
3714         _calendar_free_record_list(&data->calendar_book_list);
3715
3716         if (data->alarm_list) {
3717                 g_list_free(data->alarm_list);
3718                 data->alarm_list = NULL;
3719         }
3720
3721         if (data->alarm_item_list) {
3722                 eina_list_free(data->alarm_item_list);
3723                 data->alarm_item_list = NULL;
3724         }
3725
3726         CAL_FREE(data->title_str);
3727         CAL_FREE(data->address);
3728         CAL_FREE(data->note_str);
3729
3730         if (data->tabbar)
3731                 evas_object_del(data->tabbar);
3732
3733         if (data->event)
3734                 calendar_record_destroy(data->event, true);
3735
3736         if (data->todo)
3737                 calendar_record_destroy(data->todo, true);
3738
3739         if (data->instance)
3740                 calendar_record_destroy(data->instance, true);
3741
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");
3744
3745         elm_theme_free(data->theme);
3746
3747 }
3748
3749 static void __cal_edit_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
3750 {
3751         c_ret_if(!ug);
3752
3753         DBG("UG: key event %d", evt);
3754
3755         switch (evt) {
3756         case UG_KEY_EVENT_END:
3757                 ug_destroy_me(ug);
3758                 break;
3759         default:
3760                 break;
3761         }
3762 }
3763
3764 static void __cal_edit_ug_update_language(cal_edit_ug_data *data)
3765 {
3766         c_ret_if(!data);
3767
3768         __cal_edit_ug_update_naviframe_language(data);
3769
3770         __cal_edit_ug_update_tabbar_language(data);
3771
3772         cal_save_cancel_set_button_text(data->save_cancel, S_("IDS_COM_OPT_SAVE"), NULL);
3773
3774         __cal_edit_ug_update_title_language(data->title);
3775
3776         if (data->item_type == ITEM_TYPE_EVENT) {
3777
3778                 __cal_edit_ug_update_start_language(data->start_date_title);
3779
3780                 __cal_edit_ug_update_end_language(data->end_date_title);
3781         } else
3782                 __cal_edit_ug_update_due_language(data->due_date_title);
3783
3784         __cal_edit_ug_update_time_zone_language(data->timezone, data->timezone_city, data->timezone_offset);
3785
3786         if (data->item_type == ITEM_TYPE_TODO) {
3787
3788                 __cal_edit_ug_update_no_due_date_language(data->no_due_date);
3789
3790                 __cal_edit_ug_update_priority_language(data->priority, data->todo);
3791         }
3792
3793         if (data->item_type == ITEM_TYPE_EVENT)
3794                 __cal_edit_ug_update_allday_language(data->allday);
3795
3796         __cal_edit_ug_update_description_language(data->note);
3797
3798         __cal_edit_ug_update_location_language(data->location);
3799
3800         __cal_edit_ug_update_reminder_language(data->alarm_item_list);
3801
3802         if (data->item_type == ITEM_TYPE_EVENT)
3803                 __cal_edit_ug_update_recurrence_language(data->repeat, data->repeat_freq);
3804
3805         if (data->item_type == ITEM_TYPE_EVENT)
3806                 __cal_edit_ug_update_saveto_language(data->saveto, data->event);
3807         else
3808                 __cal_edit_ug_update_saveto_language(data->saveto, data->todo);
3809 }
3810
3811 static void __cal_edit_ug_update_region(cal_edit_ug_data *data)
3812 {
3813         c_ret_if(!data);
3814
3815         if (data->item_type == ITEM_TYPE_EVENT) {
3816
3817                 Eina_Bool is_allday = _calendar_is_allday_record(data->event);
3818
3819                 __cal_edit_ug_update_datetime_region(data->start_date, &data->stm, is_allday, __cal_edit_ug_start_date_changed_callback, data);
3820
3821                 __cal_edit_ug_update_datetime_region(data->end_date, &data->etm, is_allday, __cal_edit_ug_end_date_changed_callback, data);
3822
3823         } else
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);
3825 }
3826
3827 static void __cal_edit_ug_event_callback(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
3828 {
3829         c_ret_if(!ug);
3830         c_ret_if(!priv);
3831
3832         switch (event) {
3833         case UG_EVENT_LANG_CHANGE:
3834                 __cal_edit_ug_update_language((cal_edit_ug_data *)priv);
3835                 break;
3836         case UG_EVENT_REGION_CHANGE:
3837                 __cal_edit_ug_update_region((cal_edit_ug_data *)priv);
3838                 break;
3839         default:
3840                 break;
3841         }
3842 }
3843
3844 API int UG_MODULE_INIT(struct ug_module_ops *ops)
3845 {
3846         CAL_FN_START;
3847
3848         c_retv_if(!ops, -1);
3849
3850         cal_edit_ug_data *data = calloc(1, sizeof(cal_edit_ug_data));
3851
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;
3856         ops->priv = data;
3857         ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
3858
3859         const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
3860         c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
3861
3862         __cal_edit_ug_initialize(data);
3863
3864         return 0;
3865 }
3866
3867 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
3868 {
3869         CAL_FN_START;
3870
3871         c_ret_if(!ops);
3872
3873         cal_edit_ug_data *data = ops->priv;
3874
3875         __cal_edit_ug_finish(data);
3876
3877         free(data);
3878 }