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