9f68f611476c8b2c38ca1016af2d02a546fbe26e
[apps/core/preloaded/calendar.git] / src / view-detail.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://www.tizenopensource.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
19
20
21
22 #include <aul.h>
23 #include <appsvc.h>
24
25 #include "view.h"
26 #include "edit-repeat.h"
27 #include "edit-alarm.h"
28 #include "detail.h"
29 #include "alm-mgr.h"
30 #include "external-ug.h"
31
32
33 static const char *_name = "view/detail";
34
35 #define CAL_REPEAT_EVERY_2_WEEK (CAL_REPEAT_EVERY_YEAR+1)
36 #define CAL_REPEAT_EVERY_3_DAY (CAL_REPEAT_EVERY_2_WEEK+1)
37
38 #define ARRAY_SIZE(array) \
39         ((int)(sizeof(array) / sizeof(array[0])))
40
41 static int is_hour24;
42
43 static void __cal_detail_update_view(void *data);
44 static void __cal_detail_edit_button_callback(void *data, Evas_Object *obj, void *ei);
45
46 enum genlist_item_type{
47         _GTYPE_TITLE_LOC = 1,
48         _GTYPE_START,
49         _GTYPE_END,
50         _GTYPE_ALARM,
51         _GTYPE_REPEAT,
52         _GTYPE_NOTE,
53         _GTYPE_LINKED_CAL,
54         _GTYPE_MAX
55 };
56
57 typedef struct {
58         const char *name;
59         struct appdata *ad;
60         Evas_Object *parent;
61         Evas_Object *ly; // self
62
63         const char *text;
64         Evas_Object *entry;
65         Evas_Object *genlist;
66         Evas_Object *bt_one;
67         Evas_Object *bt_all;
68         Evas_Object *popup;
69
70         cal_struct *cs;
71
72         int cid;
73
74         Eina_Bool is_deleted; //When event is deleted, updating view is not needed.
75         GList   *alarm_list;
76 }cal_detail_data;
77
78 typedef struct {
79         cal_detail_data *p;
80         int type;
81         Elm_Object_Item *it;
82         int alarm_value;
83 }cal_detail_genlist_item_data;
84
85 static Elm_Genlist_Item_Class itc_seperator, itc_title_loc, itc_4_text, itc_mutilline, itc_parts, itc_linked_cal;
86
87 static void __cal_detail_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
88 {
89         CAL_FN_START;
90
91         c_retm_if(!data, "Input parameter is null");
92
93         cal_detail_data *p = data;
94
95         if (p->cs)
96                 CALENDAR_SVC_STRUCT_FREE(&(p->cs));
97
98         free(p);
99
100         CALENDAR_SVC_DEL_EVENT_CHANGED_CALLBACK(__cal_detail_update_view);
101
102 }
103
104 static cal_struct* __cal_detail_get_event(int idx)
105 {
106         int r;
107         cal_struct *cs = NULL;
108         r = CALENDAR_SVC_GET(CAL_STRUCT_SCHEDULE, idx, NULL, &cs);
109         if (r != CAL_SUCCESS || CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_DELETED) ==1)
110         {
111                 if(cs)
112                         CALENDAR_SVC_STRUCT_FREE(&cs);
113                 ERR("CALENDAR_SVC_GET is failed");
114                 return NULL;
115         }
116
117         return cs;
118 }
119
120 static void __cal_detail_get_time_text(time_t t, int allday, char *buf, int sz)
121 {
122         struct tm tm;
123         const char* time;
124
125         localtime_r(&t, &tm);
126
127         if (is_hour24)
128                 time = CAL_UTIL_TIME_FORMAT_6;
129         else
130                 time = CAL_UTIL_TIME_FORMAT_1;
131
132         if (allday)
133                 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, NULL, &tm);
134         else
135                 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, time, &tm);
136 }
137
138 static void __cal_detail_get_start_time(cal_struct *cs, char *buf, int sz, cal_detail_data* p)
139 {
140         CAL_ASSERT(p);
141         CAL_ASSERT(p->ad);
142
143         int allday;
144         time_t t;
145         int repeat;
146
147         allday = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_ALL_DAY_EVENT);
148         repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
149
150         if (repeat && !p->ad->is_aul)
151                 t = p->ad->tm->st;
152         else
153                 t = mktime(CALENDAR_SVC_STRUCT_GET_TM(cs, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL));
154
155         __cal_detail_get_time_text(t, allday, buf, sz);
156 }
157
158 static void __cal_detail_get_end_time(cal_struct *cs, char *buf, int sz, cal_detail_data* p)
159 {
160         CAL_ASSERT(p);
161         CAL_ASSERT(p->ad);
162
163         int allday;
164         time_t t;
165         int repeat;
166
167         allday = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_ALL_DAY_EVENT);
168         repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
169
170         if (repeat && !p->ad->is_aul)
171                 t = p->ad->tm->et;
172         else
173                 t = mktime(CALENDAR_SVC_STRUCT_GET_TM(cs, CAL_VALUE_GMT_END_DATE_TIME,  CAL_TZ_FLAG_LOCAL));
174
175         __cal_detail_get_time_text(t, allday, buf, sz);
176 }
177
178 static void __cal_detail_get_alarm(cal_detail_data * p,cal_struct *cs)
179 {
180         c_retm_if(!p, "p is null");
181         c_retm_if(!cs, "cs is null");
182
183         GList *al = NULL;
184
185         g_list_free(p->alarm_list);
186         p->alarm_list = NULL;
187
188         int r = CALENDAR_SVC_STRUCT_GET_LIST(cs, CAL_VALUE_LST_ALARM, &al);
189         c_retm_if(r != CAL_SUCCESS, "CALENDAR_SVC_STRUCT_GET_LIST(CAL_VALUE_LST_ALARM) is failed(%d)", r);
190
191         c_retm_if(!al, "al is null");
192
193         while (al) {
194                 cal_value *val = al->data;
195                 c_retm_if(!val, "val is null");
196
197                 int tick = CALENDAR_SVC_VALUE_GET_INT(val, CAL_VALUE_INT_ALARMS_TICK);
198                 cal_sch_remind_tick_unit_t unit = CALENDAR_SVC_VALUE_GET_INT(val, CAL_VALUE_INT_ALARMS_TICK_UNIT);
199                 int min = cal_edit_alarm_get_min(tick, unit);
200                 p->alarm_list = g_list_append(p->alarm_list,(void *)min);
201                 al = g_list_next(al);
202         }
203
204         p->alarm_list = g_list_first(p->alarm_list);
205 }
206
207 static void __cal_detail_get_repeat(cal_struct *cs, char *buf, int sz)
208 {
209         c_retm_if(!cs, "cs is null");
210
211         int term;
212         int flag;
213
214         flag = 0;
215         term = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
216
217         if (term == CAL_REPEAT_EVERY_WEEK) {
218                 int interval = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_INTERVAL);
219                 if (2 == interval)
220                         term = CAL_REPEAT_EVERY_2_WEEK;
221         }
222
223         if (term == CAL_REPEAT_EVERY_DAY) {
224                 int interval = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_INTERVAL);
225                 if (3 == interval)
226                         term = CAL_REPEAT_EVERY_3_DAY;
227         }
228
229         cal_edit_repeat_get_repeat_str(term, flag, buf, sz);
230 }
231
232 static void __cal_detail_get_save_to_str(int calid, char *buf, int sz)
233 {
234         cal_struct *cs = NULL;
235         const char *str = NULL;
236         int r;
237
238         r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, calid, NULL, &cs);
239         if (r != CAL_SUCCESS)
240         {
241                 snprintf(buf, sz, "%s", _("Phone"));
242                 if (cs)
243                         CALENDAR_SVC_STRUCT_FREE(&cs);
244
245                 return;
246         }
247
248         if (calid == DEFAULT_CALENDAR_ID)
249                 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
250         else
251         {
252                 str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_TABLE_TXT_NAME);
253                 if (!str)
254                         str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
255         }
256
257         snprintf(buf, sz, "%s", str);
258
259         CALENDAR_SVC_STRUCT_FREE(&cs);
260 }
261
262 static void __cal_detail_get_save_to(cal_struct *cs, char *buf, int sz)
263 {
264         int idx;
265
266         idx = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_CALENDAR_ID);
267         if (idx == -1)
268         {
269                 snprintf(buf, sz, "%s", C_("IDS_CLD_OPT_PHONE_CALENDAR"));
270                 return;
271         }
272
273         __cal_detail_get_save_to_str(idx, buf, sz);
274 }
275
276 static inline const char* __cal_detail_get_note(cal_struct *cs)
277 {
278         c_retvm_if(!cs, NULL, "cs is null");
279
280         return CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_DESCRIPTION);
281 }
282
283 static void __cal_detail_back_button_callback(void *data, Evas_Object *obj, void *ei)
284 {
285         CAL_FN_START;
286
287         cal_detail_data *p = data;
288
289         if((NULL != p->ad->ug) && (UG_DETAIL == p->ad->u_type))
290         {
291                 ug_destroy_me(p->ad->ug);
292         }
293         else
294         {
295                 if(p->ad->request_view == CV_DETAIL)
296                 {
297                         if(elm_naviframe_top_item_get(p->ad->nv) != elm_naviframe_bottom_item_get(p->ad->nv))
298                         {
299                                 p->ad->request_view = CV_UNKNOWN;
300                                 p->ad->is_aul = EINA_FALSE;
301
302                                 elm_win_lower(p->ad->win);
303                         }
304                         else
305                                 elm_exit();
306                 }
307
308                 if(p->ad->is_update_view)
309                         edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->parent), "update", "prog");
310         }
311
312         struct appdata * ad = p->ad;
313         c_retm_if(!ad, "ad is null");
314
315         ad->current_view = CV_UNKNOWN;
316 }
317
318 static void __cal_viewer_back_button_callback(void *data, Evas_Object *obj, void *ei)
319 {
320         CAL_FN_START;
321
322         elm_exit();
323 }
324
325 static void __cal_detail_error_popup_response_event_callback(void *data, Evas_Object *obj, void *ei)
326 {
327         CAL_FN_START;
328
329         c_retm_if(!data, "data is null");
330
331         Evas_Object *popup = data;
332         struct appdata *ad = evas_object_data_get(popup, "data");
333
334         c_retm_if(!ad, "ad is null");
335         c_retm_if(!ad->win, "p->ad->win is null");
336
337         if (!elm_naviframe_top_item_get(ad->nv))
338                 elm_exit();
339         else
340                 elm_win_lower(ad->win);
341
342         evas_object_del(popup);
343 }
344
345 static void __cal_detail_delete_event(cal_detail_data* p, Eina_Bool is_delete_all)
346 {
347         CAL_FN_START;
348
349         c_retm_if(!p, "p is null");
350
351         GList* list = NULL;
352         cal_value* value = NULL;
353         time_t t = 0;
354         int r = 0;
355
356         if (!is_delete_all) {
357                 cal_struct *cs = __cal_detail_get_event(p->cid);
358                 c_retm_if(!cs, "cs is null");
359
360                 t = p->ad->tm->st;
361                 value = CALENDAR_SVC_VALUE_NEW(CAL_VALUE_LST_EXCEPTION_DATE);
362                 CALENDAR_SVC_VALUE_SET_TIME(value,CAL_VALUE_GMT_EXCEPTION_DATE_TIME,CAL_TZ_FLAG_GMT,t);
363                 CALENDAR_SVC_STRUCT_GET_LIST(cs,CAL_VALUE_LST_EXCEPTION_DATE,&list);
364                 list = g_list_append(list,value);
365
366                 CALENDAR_SVC_STRUCT_SET_LIST(cs,CAL_VALUE_LST_EXCEPTION_DATE,list);
367                 r = CALENDAR_SVC_UPDATE(cs);
368                 if (r != CAL_SUCCESS)
369                         ERR("CALENDAR_SVC_UPDATE is failed %d", r);
370                 else
371                         p->is_deleted = EINA_TRUE;
372
373                 CALENDAR_SVC_STRUCT_FREE(&cs);
374         }
375         else    {
376                 r = CALENDAR_SVC_DELETE(CAL_STRUCT_SCHEDULE, p->cid);
377                 c_retm_if(r!=CAL_SUCCESS, "CALENDAR_SVC_DELETE(CAL_STRUCT_SCHEDULE, %d) is failed(%d)", p->cid, r);
378
379                 p->is_deleted = EINA_TRUE;
380         }
381
382         evas_object_del(p->popup);
383
384         if ((p->ad->ug) && (UG_DETAIL == p->ad->u_type))
385                 ug_destroy_me(p->ad->ug);
386         else {
387                 if (elm_naviframe_top_item_get(p->ad->nv) == elm_naviframe_bottom_item_get(p->ad->nv))
388                         elm_exit();
389                 else
390                         elm_naviframe_item_pop(p->ad->nv);
391         }
392
393         struct appdata * ad = p->ad;
394         c_retm_if(!ad, "ad is null");
395
396         ad->current_view = CV_UNKNOWN;
397 }
398
399 static void __cal_detail_delete_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
400 {
401         c_retm_if(!data, "data is null");
402         c_retm_if(!obj, "obj is null");
403
404         Evas_Object *popup = data;
405         Evas_Object *button = obj;
406
407         cal_detail_data* p = evas_object_data_get(popup, "data");
408         c_retm_if(!p, "p is null");
409
410         if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT")))
411                 __cal_detail_delete_event(p, EINA_FALSE);
412         else if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"))
413                 || !strcmp(elm_object_text_get(button), S_("IDS_COM_SK_OK")))
414                 __cal_detail_delete_event(p, EINA_TRUE);
415
416         evas_object_del(popup);
417         p->popup = NULL;
418 }
419
420 static void __cal_detail_edit_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
421 {
422         c_retm_if(!data, "data is null");
423         c_retm_if(!obj, "obj is null");
424
425         Evas_Object *popup = data;
426         Evas_Object *button = obj;
427
428         cal_detail_data* p = evas_object_data_get(popup, "data");
429         c_retm_if(!p, "p is null");
430
431         struct appdata* ad = p->ad;
432         c_retm_if(!ad, "ad is null");
433
434         if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT")))
435                 ad->edit_special_one = EINA_TRUE;
436         else    if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS")))
437                 ad->edit_special_one = EINA_FALSE;
438         else {
439                 evas_object_del(popup);
440                 p->popup = NULL;
441                 return;
442         }
443
444         cal_edit_create_view(ad, p->ly);
445
446         evas_object_del(popup);
447         p->popup = NULL;
448 }
449
450 static void __cal_detail_show_popup(cal_detail_data *p, const char *tit, Eina_Bool is_edit)
451 {
452         void (*callback_func)(void *data, Evas_Object *obj, void *ei) = NULL;
453
454         if (is_edit)
455                         callback_func = __cal_detail_edit_popup_response_event_callback;
456                 else
457                         callback_func = __cal_detail_delete_popup_response_event_callback;
458
459         cal_struct *cs = __cal_detail_get_event(p->cid);
460         c_retm_if(!cs, "__cal_detail_get_event(%d) is failed", p->cid);
461
462         if (CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM)) {
463                 p->popup = cal_util_add_popup(p->ad->win, "verticalbuttonstyle", NULL, tit, callback_func, p,
464                         C_("IDS_CLD_BODY_ONLY_THIS_EVENT"), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"),
465                         S_("IDS_COM_SK_CANCEL"), NULL);
466         }
467         else {
468                 p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, tit, callback_func, p,
469                         S_("IDS_COM_SK_OK"),S_("IDS_COM_SK_CANCEL"), NULL);
470         }
471
472         c_retm_if(!p->popup, "elm_popup_add(p->ad->win) returned null");
473 }
474
475 static void __cal_detail_delete_button_callback(void *data, Evas_Object *obj, void *ei)
476 {
477         CAL_FN_START;
478
479         Evas_Object *ly = data;
480         cal_detail_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
481         cal_struct *cs = NULL;
482
483         // TODO: add
484
485
486         if (p->cid) {
487                 cs = __cal_detail_get_event(p->cid);
488
489                 __cal_detail_show_popup(p, C_("IDS_CLD_OPT_DELETE_EVENT"), EINA_FALSE);
490         }
491
492         if(cs)
493                 CALENDAR_SVC_STRUCT_FREE(&cs);
494 }
495
496 static void __cal_detail_edit_button_callback(void *data, Evas_Object *obj, void *ei)
497 {
498         CAL_FN_START;
499
500         Evas_Object *ly = data;
501         cal_detail_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
502         cal_struct *cs = NULL;
503
504         p = CAL_UTIL_GET_PRIV_DATA(ly);
505         CAL_ASSERT(p);
506
507         cs = __cal_detail_get_event(p->cid);
508
509         if (0 != CALENDAR_SVC_STRUCT_GET_INT(cs,CAL_VALUE_INT_REPEAT_TERM))
510                 __cal_detail_show_popup(p, C_("IDS_CLD_HEADER_EDIT_EVENT"), EINA_TRUE);
511         else
512                 cal_edit_create_view(p->ad, ly);
513
514         if (cs)
515                 CALENDAR_SVC_STRUCT_FREE(&cs);
516
517 }
518
519 static char* __cal_detail_get_title_location_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
520 {
521         c_retvm_if(!item_data, NULL, "item_data is null");
522
523         const char *title;
524         const char *loc;
525         cal_detail_data *p = item_data->p;
526         c_retvm_if(!p, NULL, "p is null");
527
528         cal_struct *cs = p->cs;
529         c_retvm_if(!cs, NULL, "cs is null");
530
531         if (!CAL_STRCMP(part, "elm.text.1"))
532         {
533                 title = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
534                 if (title)
535                         return strdup(title);
536         }
537
538         if (!CAL_STRCMP(part, "elm.text.2"))
539         {
540                 loc = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_LOCATION);
541                 if (loc)
542                         return strdup(loc);
543         }
544
545         return NULL;
546 }
547
548 static  char* __cal_detail_get_save_to_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
549 {
550         cal_detail_data *p = item_data->p;
551         char buf[1024];
552         cal_struct *cs;
553         cs = p->cs;
554         if(NULL == cs)
555         {
556                 return NULL;
557         }
558
559         if (!CAL_STRCMP(part, "elm.text.1"))
560         {
561                 return strdup(C_("IDS_ST_BODY_SAVE_TO"));
562         }
563
564         if(!CAL_STRCMP(part, "elm.text.2"))
565         {
566                 __cal_detail_get_save_to(cs, buf, sizeof(buf));
567                 return strdup(buf);
568         }
569
570         return NULL;
571 }
572
573 static char* __cal_detail_get_start_time_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
574 {
575         cal_struct *cs;
576         char buf[1024];
577         cal_detail_data *p = item_data->p;
578         cs = p->cs;
579         if(NULL == cs)
580         {
581                 return NULL;
582         }
583
584         if (!CAL_STRCMP(part, "elm.text.1"))
585         {
586                 return strdup(S_("IDS_COM_BODY_START"));
587         }
588
589         if(!CAL_STRCMP(part, "elm.text.2"))
590         {
591                 __cal_detail_get_start_time(cs, buf, sizeof(buf), p);
592                 return strdup(buf);
593         }
594
595         return NULL;
596 }
597
598 static char* __cal_detail_get_end_time_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
599 {
600         cal_struct *cs;
601         char buf[1024];
602         cal_detail_data *p = item_data->p;
603         cs = p->cs;
604         if(NULL == cs)
605         {
606                 return NULL;
607         }
608
609         if (!CAL_STRCMP(part, "elm.text.1"))
610         {
611                 return strdup(S_("IDS_COM_BODY_END"));
612         }
613
614         if(!CAL_STRCMP(part, "elm.text.2"))
615         {
616                 __cal_detail_get_end_time(cs, buf, sizeof(buf), p);
617                 return strdup(buf);
618         }
619
620         return NULL;
621 }
622
623 static void __cal_detail_get_alarm_text(cal_detail_genlist_item_data *data, char* buf, int buf_size)
624 {
625         c_retm_if(!data, "data is null");
626         cal_edit_alarm_get_alarm_str(data->alarm_value, buf, buf_size);
627 }
628
629 static char* __cal_detail_add_alarm_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
630 {
631         cal_struct *cs;
632         char buf[1024] = {0};
633         cal_detail_data *p = item_data->p;
634         cs = p->cs;
635         if(NULL == cs)
636         {
637                 return NULL;
638         }
639
640         if (!CAL_STRCMP(part, "elm.text.1"))
641         {
642                 return strdup(S_("IDS_COM_BODY_ALARM"));
643         }
644
645         if(!CAL_STRCMP(part, "elm.text.2"))
646         {
647                 __cal_detail_get_alarm_text(item_data, buf, sizeof(buf));
648                 return strdup(buf);
649         }
650
651         return NULL;
652 }
653
654
655 static char* __cal_detail_get_repeat_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
656 {
657         cal_struct *cs;
658         char buf[1024] = {0};
659         cal_detail_data *p = item_data->p;
660         cs = p->cs;
661         if(NULL == cs)
662         {
663                 return NULL;
664         }
665
666         if (!CAL_STRCMP(part, "elm.text.1"))
667         {
668                 return strdup(C_("IDS_CLD_BODY_REPEAT"));
669         }
670
671         if(!CAL_STRCMP(part, "elm.text.2"))
672         {
673                 __cal_detail_get_repeat(cs, buf, sizeof(buf));
674
675                 return strdup(buf);
676         }
677
678         return NULL;
679 }
680
681 static char* __cal_detail_get_note_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
682 {
683         cal_struct *cs;
684
685         cal_detail_data *p = item_data->p;
686         cs = p->cs;
687         if (NULL == cs)
688         {
689                 return NULL;
690         }
691
692         return NULL;
693 }
694
695 static Evas_Object* __cal_detail_add_note_object(cal_detail_data *p, Evas_Object *parent, const char *text)
696 {
697         c_retvm_if(!p, NULL, "p is null");
698         c_retvm_if(!parent, NULL, "parent is null");
699         c_retvm_if(!text, NULL, "text is null");
700         c_retvm_if(!strlen(text), NULL, "strlen(text) is zero");
701
702         Evas_Object *layout = cal_util_add_edit_field(parent, C_("IDS_COM_BODY_NOTE"), NULL, EINA_FALSE, EINA_FALSE);
703         c_retvm_if(!layout, NULL, "layout is null");
704
705         Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
706         c_retvm_if(!entry, layout, "entry is null");
707
708         p->entry = entry;
709         p->text = text;
710
711         elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
712         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
713         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
714         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
715         elm_entry_autocapital_type_set(entry, EINA_TRUE);
716         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
717
718         elm_entry_entry_set(entry, text);
719
720         return layout;
721 }
722
723 static Evas_Object* __cal_detail_add_note_icon(Evas_Object *obj, const char *part,  cal_detail_genlist_item_data *item_data)
724 {
725         c_retvm_if(!obj, NULL, "obj is null");
726         c_retvm_if(!part, NULL, "part is null");
727         c_retvm_if(!item_data, NULL, "item_data is null");
728
729         cal_detail_data *p = item_data->p;
730         Evas_Object *edit_field = NULL;
731         const char *note = NULL;
732
733         cal_struct *cs = p->cs;
734         c_retvm_if(!cs, NULL, "cs is null");
735
736         if (!CAL_STRCMP(part, "elm.icon"))
737         {
738                 note = __cal_detail_get_note(cs);
739                 if (!CAL_STRLEN(note))
740                         return NULL;
741
742                 edit_field = __cal_detail_add_note_object(p, obj, elm_entry_utf8_to_markup(note));
743         }
744
745         return edit_field;
746 }
747
748 static Evas_Object *__cal_detail_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
749 {
750         c_retvm_if(!data, NULL, "data is null");
751
752         Evas_Object *e_obj = NULL;
753
754         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
755         int type = item_data->type;
756
757         switch ( type )
758         {
759         case _GTYPE_NOTE:
760                 e_obj = __cal_detail_add_note_icon(obj, part, item_data);
761                 break;
762         default:
763                 break;
764         }
765
766         return e_obj;
767 }
768
769
770 static char *__cal_detail_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
771 {
772         c_retvm_if(!data, NULL, "data is null");
773
774         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
775         int type = item_data->type;
776
777         switch ( type )
778         {
779         case _GTYPE_TITLE_LOC:
780                 return __cal_detail_get_title_location_text(obj, part, item_data);
781                 break;
782         case _GTYPE_START:
783                 return __cal_detail_get_start_time_text(obj, part, item_data);
784                 break;
785         case _GTYPE_END:
786                 return __cal_detail_get_end_time_text(obj, part, item_data);
787                 break;
788         case _GTYPE_ALARM:
789                 return __cal_detail_add_alarm_text(obj, part, item_data);
790                 break;
791         case _GTYPE_REPEAT:
792                 return __cal_detail_get_repeat_text(obj, part, item_data);
793                 break;
794         case _GTYPE_NOTE:
795                 return __cal_detail_get_note_text(obj, part, item_data);
796                 break;
797         case _GTYPE_LINKED_CAL:
798                 return __cal_detail_get_save_to_text(obj, part, item_data);
799                 break;
800         default:
801                 break;
802         }
803
804         return NULL;
805 }
806
807 static void __cal_detail_genlist_item_delete_callback(void *data, Evas_Object *obj)
808 {
809         c_retm_if(!data, "data is null");
810
811         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
812
813         free(item_data);
814
815         return;
816 }
817
818 static Eina_Bool __cal_detail_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
819 {
820         return EINA_FALSE;
821 }
822
823 static void __cal_detail_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
824 {
825         return;
826 }
827
828 static Elm_Object_Item* __cal_detail_add_genlist_item(Evas_Object *parent, Elm_Genlist_Item_Class *itc, int type, cal_detail_data *p)
829 {
830         c_retvm_if(!parent, NULL, "parent is null");
831         c_retvm_if(!itc, NULL, "itc is null");
832         c_retvm_if(!p, NULL, "p is null");
833
834         cal_detail_genlist_item_data *item_data = calloc(1, sizeof(cal_detail_genlist_item_data));
835         c_retvm_if(!item_data, NULL, "calloc(1, sizeof(cal_detail_genlist_item_data)) is failed");
836
837         item_data->p = p;
838
839         item_data->type = type;
840
841         item_data->it = elm_genlist_item_append(parent, itc, (void*)(item_data), NULL, ELM_GENLIST_ITEM_NONE, __cal_detail_genlist_item_select_callback, NULL);
842         c_retvm_if(!item_data->it, NULL, "elm_genlist_item_append() is failed");
843
844         return item_data->it;
845 }
846
847 static Elm_Object_Item* __cal_detail_add_separator(Evas_Object *genlist, cal_detail_data *p)
848 {
849         c_retvm_if(!p, NULL, "p is null");
850         c_retvm_if(!genlist, NULL, "genlist is null");
851
852         Elm_Object_Item *git = __cal_detail_add_genlist_item(genlist, &itc_seperator, 0, p);
853         c_retvm_if(!git, NULL, "__cal_detail_add_genlist_item returned null");
854
855         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_NONE);
856
857         return git;
858 }
859
860
861 static Elm_Object_Item* __cal_detail_add_title_location(Evas_Object *genlist, cal_detail_data *p)
862 {
863         __cal_detail_add_separator(genlist, p);
864         return __cal_detail_add_genlist_item(genlist, &itc_title_loc, _GTYPE_TITLE_LOC, p);
865 }
866
867 static Elm_Object_Item* __cal_detail_add_start_time(Evas_Object *genlist, cal_detail_data *p)
868 {
869         __cal_detail_add_separator(genlist, p);
870         return __cal_detail_add_genlist_item(genlist, &itc_4_text, _GTYPE_START, p);
871 }
872
873 static void __cal_detail_add_alarm_item(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, int type, cal_detail_data *p, int alarm)
874 {
875         c_retm_if(!genlist, "genlist is null");
876         c_retm_if(!itc, "itc is null");
877         c_retm_if(!p, "p is null");
878
879         cal_detail_genlist_item_data *item_data = calloc(1, sizeof(cal_detail_genlist_item_data));
880         c_retm_if(!item_data, "calloc is failed");
881
882         item_data->p = p;
883         item_data->type = type;
884         item_data->alarm_value = alarm;
885
886         item_data->it = elm_genlist_item_append(genlist, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
887
888         if (!item_data->it)
889         {
890                 ERR("elm_genlist_item_append returned null");
891                 free(item_data);
892                 return ;
893         }
894 }
895
896 static void __cal_detail_add_alarm(Evas_Object *genlist, cal_detail_data *p)
897 {
898         c_retm_if(!genlist, "genlist is null");
899         c_retm_if(!p, "p is null");
900         c_retm_if(!p->cs, "p->cs is null");
901
902         __cal_detail_add_separator(genlist, p);
903         __cal_detail_get_alarm(p, p->cs);
904
905         if (!p->alarm_list) {
906                 __cal_detail_add_alarm_item(genlist, &itc_4_text, _GTYPE_ALARM, p, -1);
907         } else {
908                 GList *alarm = p->alarm_list;
909                 int alarm_min;
910
911                 while (alarm) {
912                         alarm_min = (int)alarm->data;
913                         __cal_detail_add_alarm_item(genlist, &itc_4_text, _GTYPE_ALARM, p, alarm_min);
914                         alarm = g_list_next(alarm);
915                 }
916         }
917         return;
918 }
919
920 static Elm_Object_Item* __cal_detail_add_end_time(Evas_Object *genlist, cal_detail_data *p)
921 {
922         __cal_detail_add_separator(genlist, p);
923         return __cal_detail_add_genlist_item(genlist, &itc_4_text, _GTYPE_END, p);
924 }
925
926
927 static Elm_Object_Item* __cal_detail_add_repeat(Evas_Object *genlist, cal_detail_data *p)
928 {
929         __cal_detail_add_separator(genlist, p);
930         return __cal_detail_add_genlist_item(genlist, &itc_4_text, _GTYPE_REPEAT, p);
931 }
932
933
934 static Elm_Object_Item* __cal_detail_add_note(Evas_Object *genlist, cal_detail_data *p)
935 {
936         c_retvm_if(!p, NULL, "p is null");
937         c_retvm_if(!genlist, NULL, "genlist is null");
938
939         cal_struct *cs = p->cs;
940         c_retvm_if(!cs, NULL, "cs is null");
941
942         const char *note = __cal_detail_get_note(cs);
943         if (!CAL_STRLEN(note))
944                 return NULL;
945
946         __cal_detail_add_separator(genlist, p);
947
948         return __cal_detail_add_genlist_item(genlist, &itc_mutilline, _GTYPE_NOTE, p);
949 }
950
951 static Elm_Object_Item* __cal_detail_add_save_to(Evas_Object *genlist, cal_detail_data *p)
952 {
953         __cal_detail_add_separator(genlist, p);
954
955         return __cal_detail_add_genlist_item(genlist, &itc_linked_cal, _GTYPE_LINKED_CAL, p);
956 }
957
958 static void __cal_detail_show_error_popup(cal_detail_data *p)
959 {
960         CAL_FN_START;
961
962         c_retm_if(!p, "p is null");
963         c_retm_if(!p->ad, "p->ad is null");
964         c_retm_if(!p->ad->win, "p->ad->win is null");
965
966         if (p->popup)
967                 evas_object_del(p->popup);
968
969         p->popup = cal_util_add_popup(p->ad->win, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_NO_EVENTS"),
970                 __cal_detail_error_popup_response_event_callback, p->ad, S_("IDS_COM_SK_OK"), NULL);
971         c_retm_if(!p->popup, "cal_util_add_popup(p->ad->win) returned null");
972 }
973
974 static Evas_Object *__cal_detail_create_genlist(cal_detail_data *p)
975 {
976         c_retvm_if(!p, NULL, "p is null");
977         c_retvm_if(!p->ad, NULL, "p->ad is null");
978
979         Evas_Object *genlist;
980
981         if(p->ad->is_aul && p->ad->ical)
982                 p->cs = p->ad->ical;
983         else
984                 p->cs = __cal_detail_get_event(p->ad->cid);
985
986         if (!p->cs) {
987                 __cal_detail_show_error_popup(p);
988                 return NULL;
989         }
990
991         genlist = elm_genlist_add(p->ly);
992         c_retvm_if(!genlist, NULL, "elm_genlist_add(p->ly) returned null");
993
994         elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_NONE);
995
996         itc_seperator.item_style = "dialogue/seperator";
997         itc_seperator.func.text_get = NULL;
998         itc_seperator.func.state_get = __cal_detail_get_genlist_item_state;
999         itc_seperator.func.del = __cal_detail_genlist_item_delete_callback;
1000
1001
1002         itc_title_loc.item_style = "dialogue/2text";
1003         itc_title_loc.func.text_get = __cal_detail_get_genlist_item_label;
1004         itc_title_loc.func.del = __cal_detail_genlist_item_delete_callback;
1005
1006         itc_4_text.item_style = "dialogue/2text";
1007         itc_4_text.func.text_get = __cal_detail_get_genlist_item_label;
1008         itc_4_text.func.del = __cal_detail_genlist_item_delete_callback;
1009
1010         itc_mutilline.item_style = "dialogue/1icon";
1011         itc_mutilline.func.text_get = __cal_detail_get_genlist_item_label;
1012         itc_mutilline.func.del = __cal_detail_genlist_item_delete_callback;
1013         itc_mutilline.func.content_get = __cal_detail_get_genlist_item_icon;
1014
1015         itc_parts.item_style = "dialogue/1icon";
1016         itc_parts.func.text_get = __cal_detail_get_genlist_item_label;
1017         itc_parts.func.del = __cal_detail_genlist_item_delete_callback;
1018         itc_parts.func.content_get = __cal_detail_get_genlist_item_icon;
1019
1020         itc_linked_cal.item_style = "dialogue/2text";
1021         itc_linked_cal.func.text_get = __cal_detail_get_genlist_item_label;
1022         itc_linked_cal.func.del = __cal_detail_genlist_item_delete_callback;
1023
1024         __cal_detail_add_title_location(genlist, p);
1025         __cal_detail_add_start_time(genlist, p);
1026         __cal_detail_add_end_time(genlist, p);
1027         __cal_detail_add_alarm(genlist, p);
1028         __cal_detail_add_repeat(genlist, p);
1029         __cal_detail_add_note(genlist, p);
1030         __cal_detail_add_save_to(genlist, p);
1031
1032         return genlist;
1033 }
1034
1035 static void __cal_detail_update_view(void *data)
1036 {
1037         CAL_FN_START;
1038
1039         c_retm_if(!data, "data is null");
1040
1041         cal_detail_data *p = data;
1042
1043         if (p->is_deleted)
1044                 return;
1045
1046         Evas_Object *genlist;
1047         struct appdata* ad = p->ad;
1048         c_retm_if(!ad, "ad is null");
1049
1050         is_hour24 = ad->is_hour24;
1051
1052         cal_util_delete_evas_object(&p->genlist);
1053         genlist = __cal_detail_create_genlist(p);
1054         if (genlist)
1055         {
1056                 elm_object_part_content_set(p->ly, "sw", genlist);
1057                 p->genlist = genlist;
1058         }
1059 }
1060
1061
1062 static Evas_Object *__cal_detail_create_layout(struct appdata *ad, Evas_Object *parent)
1063 {
1064         Evas_Object *ly;
1065         cal_detail_data *p;
1066         Evas_Object *genlist;
1067         p = calloc(1, sizeof(cal_detail_data));
1068
1069         p->name = _name;
1070         p->parent = parent;
1071
1072         ly = cal_util_add_layout(parent, "edit");
1073         if (!ly)
1074         {
1075                 free(p);
1076                 return NULL;
1077         }
1078         evas_object_data_set(ly, "priv", p);
1079         p->ad = ad;
1080         p->ly = ly;
1081         p->cid = ad->cid;
1082         p->alarm_list  = NULL;
1083
1084         is_hour24 = ad->is_hour24;
1085
1086         elm_layout_theme_set(CAL_UTIL_GET_EDJ_DATA(ly),"layout", "application", "controlbar");
1087
1088         genlist = __cal_detail_create_genlist(p);
1089         if (!genlist)
1090         {
1091                 evas_object_del(ly);
1092                 free(p);
1093                 return NULL;
1094         }
1095
1096         elm_object_part_content_set(p->ly, "sw", genlist);
1097         p->genlist = genlist;
1098
1099         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_detail_delete_layout, p);
1100
1101         CALENDAR_SVC_ADD_EVENT_CHANGED_CALLBACK(__cal_detail_update_view, p);
1102
1103         return ly;
1104 }
1105
1106 static void __cal_detail_save_to_calendar_button_callback(void *data, Evas_Object *obj, void *ei)
1107 {
1108         CAL_FN_START;
1109
1110         c_retm_if(!data, "data is null");
1111
1112         Evas_Object *ly = data;
1113         cal_detail_data *p;
1114
1115         p = CAL_UTIL_GET_PRIV_DATA(ly);
1116         c_retm_if(!p, "CAL_UTIL_GET_PRIV_DATA(ly) returned null");
1117
1118         cal_edit_create_view(p->ad, p->parent);
1119 }
1120
1121 void cal_detail_create_view(struct appdata *ad, Evas_Object *parent)
1122 {
1123         CAL_FN_START;
1124
1125         c_retm_if(!ad || !parent, "Input parameter is null");
1126
1127         if (ad->current_view == CV_DETAIL)
1128                 return;
1129
1130         Evas_Object *ly;
1131         Evas_Object *back_button;
1132         Evas_Object *controlbar;
1133         Elm_Object_Item* navi_item;
1134
1135         ly = __cal_detail_create_layout(ad, parent);
1136         c_retm_if(!ly, "__cal_detail_create_layout(ad, parent) is failed");
1137
1138         navi_item = elm_naviframe_item_push(ad->nv, C_("IDS_COM_BODY_DETAILS"), NULL, NULL, ly, NULL);
1139         if (!navi_item)
1140         {
1141                 ERR("elm_naviframe_item_push is failed");
1142                 evas_object_del(ly);
1143                 return;
1144         }
1145
1146         controlbar = cal_util_add_controlbar(ad->nv);
1147         if (!controlbar)
1148         {
1149                 ERR("cal_util_add_controlbar(ad->nv) is failed");
1150                 elm_naviframe_item_pop(ad->nv);
1151                 return;
1152         }
1153
1154         elm_toolbar_item_append(controlbar, NULL, S_("IDS_COM_SK_EDIT"), __cal_detail_edit_button_callback, ly);
1155         elm_toolbar_item_append(controlbar, NULL, S_("IDS_COM_BODY_DELETE"), __cal_detail_delete_button_callback, ly);
1156
1157         elm_object_item_part_content_set( navi_item, "controlbar", controlbar);
1158
1159         back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
1160         if (!back_button)
1161         {
1162                 back_button = elm_button_add(ad->nv);
1163                 if (!back_button)
1164                 {
1165                         ERR("elm_button_add is failed.");
1166                         return;
1167                 }
1168                 elm_object_style_set(back_button, "naviframe/back_btn/default");
1169                 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
1170         }
1171         elm_object_style_set(back_button, "naviframe/back_btn/default");
1172         evas_object_smart_callback_add(back_button, "clicked",  __cal_detail_back_button_callback, CAL_UTIL_GET_PRIV_DATA(ly));
1173
1174         ad->current_view = CV_DETAIL;
1175
1176         CAL_FN_END;
1177 }
1178
1179 void cal_viewer_create_view(struct appdata *ad, Evas_Object *parent, char* raw_data)
1180 {
1181         CAL_FN_START;
1182
1183         c_retm_if(!ad || !parent || !raw_data, "Input parameter is null");
1184
1185         Evas_Object *ly;
1186         Evas_Object *back_button;
1187         Evas_Object *controlbar;
1188         Elm_Object_Item* navi_item;
1189
1190         int r = CALENDAR_SVC_UTIL_CONVERT_VCS_TO_EVENT(raw_data, VCALENDAR_DATA_LEN, &ad->ical);
1191         if (r != CAL_SUCCESS)
1192                 ERR("CALENDAR_SVC_UTIL_CONVERT_VCS_TO_EVENT fail. : %d", r);
1193
1194         ly = __cal_detail_create_layout(ad, parent);
1195         c_retm_if(!ly, "__cal_detail_create_layout(ad, parent) is failed");
1196
1197         navi_item = elm_naviframe_item_push(ad->nv, _("VCS Viewer"), NULL, NULL, ly, NULL);
1198         if (!navi_item)
1199         {
1200                 ERR("elm_naviframe_item_push is failed");
1201                 evas_object_del(ly);
1202                 return;
1203         }
1204
1205         controlbar = cal_util_add_controlbar(ad->nv);
1206         if (!controlbar)
1207         {
1208                 ERR("cal_util_add_controlbar(ad->nv) is failed");
1209                 elm_naviframe_item_pop(ad->nv);
1210                 return;
1211         }
1212
1213         elm_toolbar_item_append(controlbar, NULL, _("Save to Calendar"), __cal_detail_save_to_calendar_button_callback, ly);
1214
1215         elm_object_item_part_content_set(navi_item, "controlbar", controlbar);
1216
1217         back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
1218         if (!back_button)
1219         {
1220                 back_button = elm_button_add(ad->nv);
1221                 if (!back_button)
1222                 {
1223                         ERR("elm_button_add is failed.");
1224                         return;
1225                 }
1226                 elm_object_style_set(back_button, "naviframe/back_btn/default");
1227                 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
1228         }
1229         elm_object_style_set(back_button, "naviframe/back_btn/default");
1230         evas_object_smart_callback_add(back_button, "clicked",  __cal_viewer_back_button_callback, CAL_UTIL_GET_PRIV_DATA(ly));
1231 }