ee0fac6bc8cdfca213478ceeeff59a5ae75eec0d
[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 #include <aul.h>
20 #include <appsvc.h>
21
22 #include "view.h"
23 #include "edit-repeat.h"
24 #include "edit-alarm.h"
25 #include "detail.h"
26
27
28 #include "external-ug.h"
29
30 static const char *_name = "view/detail";
31 #define CAL_REPEAT_EVERY_2_WEEK (CALS_FREQ_SECONDLY+1)
32 #define CAL_REPEAT_EVERY_3_DAY (CAL_REPEAT_EVERY_2_WEEK+1)
33
34 #define ARRAY_SIZE(array) \
35         ((int)(sizeof(array) / sizeof(array[0])))
36
37 #define APP_CALL "org.tizen.call"
38 #define APP_VTCALL "org.tizen.vtmain"
39 #define APP_CONTACT_S "org.tizen.contacts-shortcut"
40
41 static char messagebody[2048] = {0};
42
43 static int is_hour24;
44
45 static void __cal_detail_autolink_send_email_selected_callback(void *data, Evas_Object *obj, void *event_info);
46 static void __cal_detail_autolink_add_to_contact_selected_callback(void *data, Evas_Object *obj, void *event_info);
47 static void __cal_detail_voice_call_selected_callback(void *data, Evas_Object *obj, void *event_info);
48 static void __cal_detail_autolink_send_message_selected_callback(void *data, Evas_Object *obj, void *event_info);
49 static void __cal_detail_autolink_video_call_selected_callback(void *data, Evas_Object *obj, void *event_info);
50 static void __cal_detail_autolink_phone_add_to_contact_selected_callback(void *data, Evas_Object *obj, void *event_info);
51 static void __cal_detail_update_view(void *data);
52 static void __cal_detail_edit_button_callback(void *data, Evas_Object *obj, void *ei);
53 static void __cal_detail_update_view_todo(void *data);
54
55 struct anchor_popup_item_t {
56         char *label;
57         void (*response) (void *data, Evas_Object *obj, void *event_info);
58 };
59
60 static struct anchor_popup_item_t g_email_list[] = {
61         {"Send email", __cal_detail_autolink_send_email_selected_callback},
62         {"Add to contact", __cal_detail_autolink_add_to_contact_selected_callback},
63 };
64
65 static struct anchor_popup_item_t g_phone_list[] = {
66         {"Voice call", __cal_detail_voice_call_selected_callback},
67         {"Send message", __cal_detail_autolink_send_message_selected_callback},
68         {"Video call", __cal_detail_autolink_video_call_selected_callback},
69         {"Add to contact", __cal_detail_autolink_phone_add_to_contact_selected_callback},
70 };
71
72 enum genlist_item_type{
73         _GTYPE_TITLE_LOC = 1,
74         _GTYPE_START_AND_END_TIME,
75         _GTYPE_DUE,
76         _GTYPE_REMINDER_AND_REPEAT,
77         _GTYPE_NOTE,
78
79         _GTYPE_LINKED_CAL,
80         _GTYPE_PRIORITY,
81         _GTYPE_MAX
82 };
83
84 enum anchor_t {
85         NOT_ANCHOR = 0,
86         ANCHOR_PHONE,
87         ANCHOR_EMAIL,
88         ANCHOR_URL,
89         ANCHOR_EMAIL_LINK
90 };
91
92 struct autolink_data_t {
93         Evas_Object *popup;
94         Elm_Genlist_Item_Class itc;
95
96         enum anchor_t type;
97         char *info;
98 };
99
100 typedef struct {
101         const char *name;
102         struct appdata *ad;
103         Evas_Object *parent;
104         Evas_Object *ly; // self
105
106         const char *text;
107         Evas_Object *entry;
108         Evas_Object *genlist;
109         Evas_Object *bt_one;
110         Evas_Object *bt_all;
111         Evas_Object *popup;
112         Evas_Object *ctx;
113
114         Ecore_Event_Handler *evt; // button down event
115         Evas_Coord x;
116         Evas_Coord y;
117         cal_struct *cs;
118
119         int cid;
120
121         Eina_Bool is_deleted; //When event is deleted, updating view is not needed.
122         GList   *alarm_list;
123
124         Eina_Bool is_todo_mode;
125         int priority;
126 }cal_detail_data;
127
128 typedef struct {
129         cal_detail_data *p;
130         int type;
131         Elm_Object_Item *it;
132         int alarm_value;
133 }cal_detail_genlist_item_data;
134
135 static Elm_Genlist_Item_Class itc_seperator, itc_2text, itc_4text, itc_mutilline, itc_parts, itc_linked_cal;
136
137 static void __cal_detail_autolink_send_email_selected_callback(void *data, Evas_Object *obj, void *event_info)
138 {
139         struct autolink_data_t *ald = (struct autolink_data_t *)data;
140
141         cal_launch_ug_with_var(EMAIL_COMPOSER_UG, NULL, "RUN_TYPE", "5", "TO", ald->info, NULL);
142
143         evas_object_del(ald->popup);
144         ald->popup = NULL;
145 }
146
147 static void __cal_detail_autolink_add_to_contact_selected_callback(void *data, Evas_Object *obj,
148                 void *event_info)
149 {
150         struct autolink_data_t *ald = (struct autolink_data_t *)data;
151
152         char buf[10];
153         snprintf(buf, sizeof(buf), "%d", 22);
154
155         cal_launch_ug_with_var(CONTACT_UG, NULL, "type", buf, "ct_email", ald->info, NULL);
156
157         evas_object_del(ald->popup);
158         ald->popup = NULL;
159 }
160
161 static void __cal_detail_autolink_send_message_selected_callback(void *data, Evas_Object *obj, void *event_info)
162 {
163         struct autolink_data_t *ald = (struct autolink_data_t *)data;
164
165         cal_launch_ug_with_var(MESSAGE_COMPOSER_UG, NULL, "TO", ald->info, NULL);
166
167         evas_object_del(ald->popup);
168         ald->popup = NULL;
169 }
170
171 static void __cal_detail_voice_call_selected_callback(void *data, Evas_Object *obj, void *event_info)
172 {
173         struct autolink_data_t *ald = (struct autolink_data_t *)data;
174
175         bundle *b = NULL;
176         char telnum[255]={0,};
177         b = bundle_create();
178         appsvc_set_operation(b, APPSVC_OPERATION_CALL);
179         snprintf(telnum, sizeof(telnum), "tel:%s", ald->info);
180         appsvc_set_uri(b, telnum);
181         appsvc_add_data(b, "ctindex", "-1");
182         appsvc_run_service(b, 0, NULL, NULL);
183
184         bundle_free(b);
185
186         evas_object_del(ald->popup);
187         ald->popup = NULL;
188 }
189
190 static void __cal_detail_autolink_video_call_selected_callback(void *data, Evas_Object *obj, void *event_info)
191 {
192         struct autolink_data_t *ald = (struct autolink_data_t *)data;
193
194         bundle *bd = bundle_create();
195         bundle_add(bd, "KEY_CALL_TYPE", "mo");
196         bundle_add(bd, "KEY_CALL_HANDLE", "1");
197         bundle_add(bd, "KEY_CALLING_PARTY_NUMBER", ald->info);
198         bundle_add(bd, "KEY_CLI_CAUSE", "-1");
199         bundle_add(bd, "KEY_FORWARDED", "-1");
200
201         aul_launch_app("org.tizen.vtmain", bd);
202
203         bundle_free(bd);
204
205         evas_object_del(ald->popup);
206         ald->popup = NULL;
207 }
208
209 static void __cal_detail_autolink_phone_add_to_contact_selected_callback(void *data, Evas_Object *obj, void *event_info)
210 {
211         c_retm_if(!data, "data is null");
212
213         struct autolink_data_t *ald = data;
214
215         char buf[10] = {0};
216         snprintf(buf, sizeof(buf), "%d", 21);
217
218         cal_launch_ug_with_var(CONTACT_UG, NULL, "type", buf, "ct_num", ald->info, NULL);
219
220         evas_object_del(ald->popup);
221         ald->popup = NULL;
222 }
223
224 static void __cal_detail_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
225 {
226         CAL_FN_START;
227
228         c_retm_if(!data, "Input parameter is null");
229
230         cal_detail_data *p = data;
231
232         if (p->evt)
233                 ecore_event_handler_del(p->evt);
234
235         if (p->cs && NULL == p->ad->ical)
236                 CALENDAR_SVC_STRUCT_FREE(&(p->cs));
237
238         if (!p->is_todo_mode)
239                 CALENDAR_SVC_DEL_EVENT_CHANGED_CALLBACK(__cal_detail_update_view);
240         else
241                 CALENDAR_SVC_DEL_EVENT_CHANGED_CALLBACK(__cal_detail_update_view_todo);
242
243         free(p);
244 }
245
246 static cal_struct* __cal_detail_get_event(cal_detail_data *p, int idx)
247 {
248         c_retvm_if(!p, NULL, "p parameter is null");
249         c_retvm_if(idx < 0, NULL, "idx is invalied(%d)", idx);
250
251         int r;
252         cal_struct *cs = NULL;
253
254         if (!p->is_todo_mode)
255                 r = CALENDAR_SVC_GET(CAL_STRUCT_SCHEDULE, idx, NULL, &cs);
256         else
257                 r = CALENDAR_SVC_GET(CAL_STRUCT_TODO, idx, NULL, &cs);
258
259         c_retvm_if(r != CAL_SUCCESS, NULL, "CALENDAR_SVC_GET(%d) is failed(%d)", idx, r);
260
261         return cs;
262 }
263
264 static void __cal_detail_get_time_text(struct tm *tm, Eina_Bool is_allday, char *buf, int sz)
265 {
266         const char* time;
267
268         if (is_hour24)
269                 time = CAL_UTIL_TIME_FORMAT_6;
270         else
271                 time = CAL_UTIL_TIME_FORMAT_1;
272
273         if (is_allday)
274                 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, NULL, tm);
275         else
276                 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, time, tm);
277 }
278
279 static void __cal_detail_get_start_time(cal_struct *cs, char *buf, int sz, cal_detail_data* p)
280 {
281         c_ret_if(!cs);
282         c_ret_if(!p);
283
284         __cal_detail_get_time_text(&p->ad->tm_start, CALENDAR_SVC_IS_ALLDAY_EVENT(cs), buf, sz);
285 }
286
287 static void __cal_detail_get_end_time(cal_struct *cs, char *buf, int sz, cal_detail_data* p)
288 {
289         c_ret_if(!cs);
290         c_ret_if(!p);
291
292         __cal_detail_get_time_text(&p->ad->tm_end, CALENDAR_SVC_IS_ALLDAY_EVENT(cs), buf, sz);
293 }
294
295 static void __cal_detail_get_alarm(cal_detail_data * p,cal_struct *cs)
296 {
297         c_retm_if(!p, "p is null");
298         c_retm_if(!cs, "cs is null");
299
300         GList *al = NULL;
301
302         g_list_free(p->alarm_list);
303         p->alarm_list = NULL;
304
305         int r = CALENDAR_SVC_STRUCT_GET_LIST(cs, CAL_VALUE_LST_ALARM, &al);
306         c_retm_if(r != CAL_SUCCESS, "CALENDAR_SVC_STRUCT_GET_LIST(CAL_VALUE_LST_ALARM) is failed(%d)", r);
307
308         c_retm_if(!al, "al is null");
309
310         while (al) {
311                 cal_value *val = al->data;
312                 c_retm_if(!val, "val is null");
313
314                 int tick = CALENDAR_SVC_VALUE_GET_INT(val, CAL_VALUE_INT_ALARMS_TICK);
315                 cal_sch_remind_tick_unit_t unit = CALENDAR_SVC_VALUE_GET_INT(val, CAL_VALUE_INT_ALARMS_TICK_UNIT);
316                 int min = cal_edit_alarm_get_min(tick, unit);
317                 p->alarm_list = g_list_append(p->alarm_list,(void *)min);
318                 al = g_list_next(al);
319         }
320
321         p->alarm_list = g_list_first(p->alarm_list);
322 }
323
324 static void __cal_detail_get_repeat(cal_struct *cs, char *buf, int size)
325 {
326         c_ret_if(!cs);
327
328         cal_struct *original_cs = NULL;
329
330         int original_event_id = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_ORIGINAL_EVENT_ID);
331         if (0 < original_event_id) {
332                 int r = CALENDAR_SVC_GET(CAL_STRUCT_SCHEDULE, original_event_id, NULL, &original_cs);
333                 c_retm_if(r != CAL_SUCCESS, "CALENDAR_SVC_GET(%d) is failed(%d)", original_event_id, r);
334         }
335
336         if (!original_cs)
337                 original_cs = cs;
338
339         int freq = CALENDAR_SVC_STRUCT_GET_INT(original_cs, CALS_VALUE_INT_RRULE_FREQ);
340
341         if (freq == CALS_FREQ_WEEKLY) {
342
343                 int interval = CALENDAR_SVC_STRUCT_GET_INT(original_cs, CALS_VALUE_INT_RRULE_INTERVAL);
344                 if (2 == interval)
345                         freq = CAL_REPEAT_EVERY_2_WEEK;
346
347         } else if (freq == CALS_FREQ_DAILY) {
348
349                 int interval = CALENDAR_SVC_STRUCT_GET_INT(original_cs, CALS_VALUE_INT_RRULE_INTERVAL);
350                 if (3 == interval)
351                         freq = CAL_REPEAT_EVERY_3_DAY;
352         }
353
354         _cal_edit_repeat_get_freq_str(freq, buf, size);
355
356         if (original_cs != cs)
357                 CALENDAR_SVC_STRUCT_FREE(&original_cs);
358 }
359
360 static void __cal_detail_get_save_to_str(int calid, char *buf, int sz)
361 {
362         cal_struct *cs = NULL;
363         const char *str = NULL;
364         int r;
365
366         r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, calid, NULL, &cs);
367         if (r != CAL_SUCCESS)
368         {
369                 snprintf(buf, sz, "%s", _("Phone"));
370                 if (cs)
371                         CALENDAR_SVC_STRUCT_FREE(&cs);
372
373                 return;
374         }
375
376         if (calid == DEFAULT_CALENDAR_ID)
377                 str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
378         else
379         {
380                 str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_TABLE_TXT_NAME);
381                 if (!str)
382                         str = C_("IDS_CLD_OPT_PHONE_CALENDAR");
383         }
384
385         snprintf(buf, sz, "%s", str);
386
387         CALENDAR_SVC_STRUCT_FREE(&cs);
388 }
389
390 static void __cal_detail_get_save_to(cal_struct *cs, char *buf, int sz)
391 {
392         int idx;
393
394         idx = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_CALENDAR_ID);
395         if (idx == -1)
396         {
397                 snprintf(buf, sz, "%s", C_("IDS_CLD_OPT_PHONE_CALENDAR"));
398                 return;
399         }
400
401         __cal_detail_get_save_to_str(idx, buf, sz);
402 }
403
404 static void __cal_detail_popup_hide_callback(void *data, Evas_Object *obj, void *ei)
405 {
406         c_retm_if(!data, "data is null");
407
408         cal_detail_data* p = data;
409
410         p->ctx = NULL;
411
412         evas_object_del(obj);
413
414 }
415
416 static inline const char* __cal_detail_get_note(cal_struct *cs)
417 {
418         c_retvm_if(!cs, NULL, "cs is null");
419
420         return CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_DESCRIPTION);
421 }
422
423 static void __cal_detail_via_message_callback(void *data, Evas_Object *obj, void *ei)
424 {
425         c_retm_if(!data, "data is null");
426         c_retm_if(!obj, "obj is null");
427
428         cal_detail_data *p = data;
429         c_retm_if(!p->cs, "p->cs is null");
430
431         int r = cal_util_create_vcs_file_from_cs(p->cs, MESSAGE_VCS);
432         if (CAL_SUCCESS != r) {
433                 ERR("send via message failed: save vcs %d", r);
434                 return;
435         }
436
437         cal_launch_ug_with_var(MESSAGE_COMPOSER_UG, NULL, "ATTACHFILE", MESSAGE_VCS, NULL);
438
439         evas_object_del(obj);
440         p->ctx = NULL;
441 }
442
443 static void __cal_detail_via_email_callback(void *data, Evas_Object *obj, void *ei)
444 {
445         c_retm_if(!data, "data is null");
446         c_retm_if(!obj, "obj is null");
447
448         cal_detail_data *p = data;
449         c_retm_if(!p->cs, "p->cs is null");
450
451         int r = cal_util_create_vcs_file_from_cs(p->cs, EMAIL_VCS);
452         if (CAL_SUCCESS != r) {
453                 ERR("send via email failed: save vcs %d", r);
454                 return;
455         }
456
457         cal_launch_ug_with_var(EMAIL_COMPOSER_UG, NULL, "RUN_TYPE", "5", "ATTACHMENT", EMAIL_VCS, NULL);
458
459         evas_object_del(obj);
460         p->ctx = NULL;
461 }
462
463 static void __cal_detail_via_bluetooth_callback(void *data, Evas_Object *obj, void *ei)
464 {
465         c_retm_if(!data, "data is null");
466         c_retm_if(!obj, "obj is null");
467
468         cal_detail_data *p = data;
469         c_retm_if(!p->cs, "p->cs is null");
470
471         int r = cal_util_create_vcs_file_from_cs(p->cs, BLUETOOTH_VCS);
472         if (CAL_SUCCESS != r) {
473                 ERR("send via bluetooth failed: save cvs %d", r);
474                 return;
475         }
476
477         cal_launch_ug_with_var(BLUETOOTH_UG, NULL, "launch-type", "send", "filecount", "1", "files", BLUETOOTH_VCS, NULL);
478
479         evas_object_del(obj);
480         p->ctx = NULL;
481 }
482
483 static void __cal_detail_send_button_callback(void *data, Evas_Object *obj, void *ei)
484 {
485         c_retm_if(!data, "data is null");
486         c_retm_if(!obj, "obj is null");
487
488         Evas_Object *ly = data;
489
490         cal_detail_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
491         c_retm_if(!p, "CAL_UTIL_GET_PRIV_DATA(ly) is failed");
492
493         Evas_Object *ctx = p->ctx;
494
495         if (ctx)
496                 evas_object_del(ctx);
497
498         p->ctx = elm_ctxpopup_add(p->ad->nv);
499         c_retm_if(!p->ctx, "elm_ctxpopup_add(p->ad->nv) returned null");
500
501         ctx = p->ctx;
502
503         evas_object_smart_callback_add(ctx, "dismissed", __cal_detail_popup_hide_callback, p);
504         elm_ctxpopup_item_append(ctx, S_("IDS_COM_BODY_MESSAGE"), NULL, __cal_detail_via_message_callback, p);
505         elm_ctxpopup_item_append(ctx, S_("IDS_COM_BODY_EMAIL"), NULL, __cal_detail_via_email_callback, p);
506         elm_ctxpopup_item_append(ctx, S_("IDS_COM_BODY_BLUETOOTH"), NULL, __cal_detail_via_bluetooth_callback, p);
507
508         int x, y, w, h;
509         evas_object_geometry_get(p->ad->cbar, &x, &y, &w, &h);
510         evas_object_move(ctx, w / 2, y + h / 5);
511         evas_object_show(ctx);
512 }
513
514 static void __cal_detail_back_button_callback(void *data, Evas_Object *obj, void *ei)
515 {
516         CAL_FN_START;
517
518         cal_detail_data *p = data;
519
520         if((NULL != p->ad->ug) && (UG_DETAIL == p->ad->u_type))
521         {
522                 ug_destroy_me(p->ad->ug);
523         }
524         else
525         {
526                 if(p->ad->request_view == CV_DETAIL)
527                 {
528                         if(elm_naviframe_top_item_get(p->ad->nv) != elm_naviframe_bottom_item_get(p->ad->nv))
529                         {
530                                 p->ad->request_view = CV_UNKNOWN;
531                                 p->ad->is_aul = EINA_FALSE;
532
533                                 elm_win_lower(p->ad->win);
534                         }
535                         else
536                                 elm_exit();
537                 }
538
539                 if(p->ad->is_update_view)
540                         edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->parent), "update", "prog");
541         }
542
543         struct appdata * ad = p->ad;
544         c_retm_if(!ad, "ad is null");
545
546         ad->current_view = CV_UNKNOWN;
547 }
548
549 static void __cal_detail_viewer_back_button_callback(void *data, Evas_Object *obj, void *ei)
550 {
551         CAL_FN_START;
552
553         struct appdata *ad = data;
554         c_retm_if(!ad, "ad is NULL");
555         c_retm_if(!ad->nv, "ad->nv is NULL");
556
557         elm_naviframe_item_pop(ad->nv);
558 }
559
560 static void __cal_detail_error_popup_response_event_callback(void *data, Evas_Object *obj, void *ei)
561 {
562         CAL_FN_START;
563
564         c_retm_if(!data, "data is null");
565
566         Evas_Object *popup = data;
567         struct appdata *ad = evas_object_data_get(popup, "data");
568
569         c_retm_if(!ad, "ad is null");
570         c_retm_if(!ad->win, "p->ad->win is null");
571
572         if (!elm_naviframe_top_item_get(ad->nv))
573                 elm_exit();
574         else
575                 elm_win_lower(ad->win);
576
577         evas_object_del(popup);
578 }
579
580 static void __cal_detail_delete_event(cal_detail_data* p, Eina_Bool is_delete_all)
581 {
582         CAL_FN_START;
583
584         c_retm_if(!p, "p is null");
585
586         int r = 0;
587
588         if (!is_delete_all) {
589
590                 long long int lli_time;
591                 cal_util_convert_tm_to_lli(NULL, &p->ad->tm_start, &lli_time);
592
593                 r = calendar_svc_event_delete_normal_instance(p->cid, lli_time);
594                 if (r != CAL_SUCCESS)
595                         ERR("calendar_svc_event_delete_normal_instance() is failed(%d)", r);
596                 else
597                         p->is_deleted = EINA_TRUE;
598
599         } else {
600
601                 if (!p->is_todo_mode)
602                         r = CALENDAR_SVC_DELETE(CAL_STRUCT_SCHEDULE, p->cid);
603                 else
604                         r = CALENDAR_SVC_DELETE(CAL_STRUCT_TODO, p->cid);
605
606                 c_retm_if(r != CAL_SUCCESS, "CALENDAR_SVC_DELETE(CAL_STRUCT_SCHEDULE, %d) is failed(%d)", p->cid, r);
607
608                 p->is_deleted = EINA_TRUE;
609         }
610
611         evas_object_del(p->popup);
612
613         if ((p->ad->ug) && (UG_DETAIL == p->ad->u_type))
614                 ug_destroy_me(p->ad->ug);
615         else {
616
617                 if (elm_naviframe_top_item_get(p->ad->nv) == elm_naviframe_bottom_item_get(p->ad->nv))
618                         elm_exit();
619                 else
620                         elm_naviframe_item_pop(p->ad->nv);
621         }
622
623         struct appdata * ad = p->ad;
624         c_retm_if(!ad, "ad is null");
625
626         ad->current_view = CV_UNKNOWN;
627 }
628
629 static void __cal_detail_delete_popup_response_event_callback(void *data, Evas_Object *obj, void *event_info)
630 {
631         c_retm_if(!data, "data is null");
632         c_retm_if(!obj, "obj is null");
633
634         Evas_Object *popup = data;
635         Evas_Object *button = obj;
636
637         cal_detail_data* p = evas_object_data_get(popup, "data");
638         c_retm_if(!p, "p is null");
639
640         if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT")))
641                 __cal_detail_delete_event(p, EINA_FALSE);
642         else if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"))
643                 || !strcmp(elm_object_text_get(button), S_("IDS_COM_SK_OK")))
644                 __cal_detail_delete_event(p, EINA_TRUE);
645
646         evas_object_del(popup);
647         p->popup = NULL;
648 }
649
650 static void __cal_detail_event_edit_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
651 {
652         c_retm_if(!data, "data is null");
653         c_retm_if(!obj, "obj is null");
654
655         Evas_Object *popup = data;
656         Evas_Object *button = obj;
657
658         cal_detail_data* p = evas_object_data_get(popup, "data");
659         c_retm_if(!p, "p is null");
660
661         struct appdata* ad = p->ad;
662         c_retm_if(!ad, "ad is null");
663
664         if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_BODY_ONLY_THIS_EVENT")))
665                 ad->edit_special_one = EINA_TRUE;
666         else    if (!strcmp(elm_object_text_get(button), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"))
667                 || !strcmp(elm_object_text_get(button), S_("IDS_COM_SK_OK")))
668                 ad->edit_special_one = EINA_FALSE;
669         else {
670                 evas_object_del(popup);
671                 p->popup = NULL;
672                 return;
673         }
674
675         cal_edit_create_view(ad, p->ly);
676
677         evas_object_del(popup);
678         p->popup = NULL;
679 }
680
681 static inline void __cal_detail_show_event_edit_popup(cal_detail_data *p, cal_struct *cs)
682 {
683         CAL_FN_START;
684
685         if (CALENDAR_SVC_STRUCT_GET_INT(cs, CALS_VALUE_INT_RRULE_ID)) {
686                 p->popup = cal_util_add_popup(p->ad->win, "verticalbuttonstyle", NULL, C_("IDS_CLD_HEADER_EDIT_EVENT"), __cal_detail_event_edit_popup_response_callback, p,
687                         C_("IDS_CLD_BODY_ONLY_THIS_EVENT"), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"),
688                         S_("IDS_COM_SK_CANCEL"), NULL);
689         }
690         else {
691                 p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, C_("IDS_CLD_HEADER_EDIT_EVENT"), __cal_detail_event_edit_popup_response_callback, p,
692                         S_("IDS_COM_SK_OK"),S_("IDS_COM_SK_CANCEL"), NULL);
693         }
694 }
695
696 static inline void __cal_detail_show_event_delete_popup(cal_detail_data *p, cal_struct *cs)
697 {
698         CAL_FN_START;
699
700         if (CALENDAR_SVC_STRUCT_GET_INT(cs, CALS_VALUE_INT_RRULE_ID)) {
701                 p->popup = cal_util_add_popup(p->ad->win, "verticalbuttonstyle", NULL, C_("IDS_CLD_OPT_DELETE_EVENT"), __cal_detail_delete_popup_response_event_callback, p,
702                         C_("IDS_CLD_BODY_ONLY_THIS_EVENT"), C_("IDS_CLD_POP_ALL_REPETITIVE_EVENTS"),
703                         S_("IDS_COM_SK_CANCEL"), NULL);
704         }
705         else {
706                 p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, C_("IDS_CLD_OPT_DELETE_EVENT"), __cal_detail_delete_popup_response_event_callback, p,
707                         S_("IDS_COM_SK_OK"),S_("IDS_COM_SK_CANCEL"), NULL);
708         }
709 }
710
711 static void __cal_detail_task_edit_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
712 {
713         c_retm_if(!data, "data is null");
714         c_retm_if(!obj, "obj is null");
715
716         Evas_Object *popup = data;
717         Evas_Object *button = obj;
718
719         cal_detail_data* p = evas_object_data_get(popup, "data");
720         c_retm_if(!p, "p is null");
721
722         struct appdata* ad = p->ad;
723         c_retm_if(!ad, "ad is null");
724
725         if (!strcmp(elm_object_text_get(button), S_("IDS_COM_SK_OK")))
726                 cal_edit_create_view_todo(ad, p->ly);
727
728         evas_object_del(popup);
729         p->popup = NULL;
730 }
731
732 static inline void __cal_detail_show_task_edit_popup(cal_detail_data *p, cal_struct *cs)
733 {
734         CAL_FN_START;
735
736         p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, C_("IDS_TASK_HEADER_EDIT_TASK"), __cal_detail_task_edit_popup_response_callback, p,
737                                 S_("IDS_COM_SK_OK"),S_("IDS_COM_SK_CANCEL"), NULL);
738 }
739
740 static inline void __cal_detail_show_task_delete_popup(cal_detail_data *p, cal_struct *cs)
741 {
742         CAL_FN_START;
743
744         p->popup = cal_util_add_popup(p->ad->win, NULL, NULL, C_("IDS_CLD_OPT_DELETE_TASK"), __cal_detail_delete_popup_response_event_callback, p,
745                                 S_("IDS_COM_SK_OK"),S_("IDS_COM_SK_CANCEL"), NULL);
746 }
747
748 static void __cal_detail_delete_button_callback(void *data, Evas_Object *obj, void *ei)
749 {
750         CAL_FN_START;
751
752         c_ret_if(!data);
753
754         Evas_Object *ly = data;
755
756         cal_detail_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
757         c_ret_if(!p);
758
759         cal_struct *cs = __cal_detail_get_event(p, p->cid);
760         c_ret_if(!cs);
761
762         /*CAL_STRUCT_TYPE_TODO == 2*/
763         if (CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_TYPE) == 2)
764                 __cal_detail_show_task_delete_popup(p, cs);
765         else
766                 __cal_detail_show_event_delete_popup(p, cs);
767
768         CALENDAR_SVC_STRUCT_FREE(&cs);
769 }
770
771 static Eina_Bool __cal_detail_mouse_button_down_callback(void *data, int type, void *event)
772 {
773         Ecore_Event_Mouse_Button *ev = event;
774         cal_detail_data *p = data;
775
776         p->x = ev->x;
777         p->y = ev->y;
778
779         return ECORE_CALLBACK_RENEW;
780 }
781
782 static void __cal_detail_edit_button_callback(void *data, Evas_Object *obj, void *ei)
783 {
784         CAL_FN_START;
785
786         c_ret_if(!data);
787
788         Evas_Object *ly = data;
789
790         cal_detail_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
791         c_ret_if(!p);
792
793         cal_struct *cs = __cal_detail_get_event(p, p->cid);
794         c_ret_if(!cs);
795
796         /*CAL_STRUCT_TYPE_TODO == 2*/
797         if (CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_TYPE) == 2)
798                 __cal_detail_show_task_edit_popup(p, cs);
799         else
800                 __cal_detail_show_event_edit_popup(p, cs);
801
802         CALENDAR_SVC_STRUCT_FREE(&cs);
803 }
804
805 static char* __cal_detail_get_title_location_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
806 {
807         c_retvm_if(!item_data, NULL, "item_data is null");
808
809         const char *title;
810         const char *loc;
811         cal_detail_data *p = item_data->p;
812         c_retvm_if(!p, NULL, "p is null");
813
814         cal_struct *cs = p->cs;
815         c_retvm_if(!cs, NULL, "cs is null");
816
817         if (!CAL_STRCMP(part, "elm.text.1"))
818         {
819                 title = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
820                 if (title && title[0] != '\0')
821                         return strdup(title);
822                 else
823                         return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
824         }
825
826         if (!CAL_STRCMP(part, "elm.text.2"))
827         {
828                 loc = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_LOCATION);
829                 if (loc && loc[0] != '\0')
830                         return strdup(loc);
831                 else
832                         return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
833         }
834
835         return NULL;
836 }
837
838 static  char* __cal_detail_get_save_to_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
839 {
840         cal_detail_data *p = item_data->p;
841         char buf[1024];
842         cal_struct *cs;
843         cs = p->cs;
844         if(NULL == cs)
845         {
846                 return NULL;
847         }
848
849         if (!CAL_STRCMP(part, "elm.text.1"))
850         {
851                 return strdup(C_("IDS_ST_BODY_SAVE_TO"));
852         }
853
854         if(!CAL_STRCMP(part, "elm.text.2"))
855         {
856                 __cal_detail_get_save_to(cs, buf, sizeof(buf));
857                 return strdup(buf);
858         }
859
860         return NULL;
861 }
862
863 static char* __cal_detail_get_start_time_and_end_time_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
864 {
865         c_retv_if(!item_data, NULL);
866
867         cal_detail_data *p = item_data->p;
868         c_retv_if(!p, NULL);
869
870         cal_struct *cs = p->cs;
871         c_retv_if(!cs, NULL);
872
873         if (CAL_STRCMP(part, "elm.text.1") == 0) {
874
875                 if (p->is_todo_mode)
876                         return strdup(C_("IDS_CLD_BODY_DUE_DATE"));
877                 else
878                         return strdup(S_("IDS_COM_BODY_START"));
879         }
880
881         if (CAL_STRCMP(part, "elm.text.3") == 0) {
882
883                 if (p->is_todo_mode)
884                         return strdup(C_("IDS_CLD_BODY_DUE_DATE"));
885                 else
886                         return strdup(S_("IDS_COM_BODY_END"));
887         }
888
889         char buf[1024];
890
891         if (CAL_STRCMP(part, "elm.text.2") == 0) {
892
893                 __cal_detail_get_start_time(cs, buf, sizeof(buf), p);
894
895                 return strdup(buf);
896         }
897
898         if (CAL_STRCMP(part, "elm.text.4") == 0) {
899
900                 __cal_detail_get_end_time(cs, buf, sizeof(buf), p);
901
902                 return strdup(buf);
903         }
904
905         return NULL;
906 }
907
908 static char* __cal_detail_get_due_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
909 {
910         c_retv_if(!item_data, NULL);
911
912         cal_detail_data *p = item_data->p;
913         c_retv_if(!p, NULL);
914
915         cal_struct *cs = p->cs;
916         c_retv_if(!cs, NULL);
917
918         if (!CAL_STRCMP(part, "elm.text.1")) {
919
920                 if (p->is_todo_mode)
921                         return strdup(C_("IDS_CLD_BODY_DUE_DATE"));
922                 else
923                         return strdup(S_("IDS_COM_BODY_END"));
924         }
925
926         char buf[1024];
927
928         if (!CAL_STRCMP(part, "elm.text.2")) {
929
930                 __cal_detail_get_end_time(cs, buf, sizeof(buf), p);
931
932                 return strdup(buf);
933         }
934
935         return NULL;
936 }
937
938 static void __cal_detail_get_alarm_text(cal_detail_genlist_item_data *data, char* buf, int buf_size)
939 {
940         c_retm_if(!data, "data is null");
941         cal_edit_alarm_get_alarm_str(data->alarm_value, buf, buf_size);
942 }
943
944 static char* __cal_detail_add_reminder_and_repeat_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
945 {
946         cal_struct *cs;
947         char buf[1024] = {0};
948         cal_detail_data *p = item_data->p;
949         cs = p->cs;
950         if(NULL == cs)
951         {
952                 return NULL;
953         }
954
955         if (!CAL_STRCMP(part, "elm.text.1"))
956         {
957                 return strdup(C_("IDS_CLD_BODY_REMINDER"));
958         }
959
960         if(!CAL_STRCMP(part, "elm.text.2"))
961         {
962                 __cal_detail_get_alarm_text(item_data, buf, sizeof(buf));
963                 return strdup(buf);
964         }
965
966         if (!CAL_STRCMP(part, "elm.text.3"))
967         {
968                 return strdup(C_("IDS_CLD_BODY_REPEAT"));
969         }
970
971         if(!CAL_STRCMP(part, "elm.text.4"))
972         {
973                 __cal_detail_get_repeat(cs, buf, sizeof(buf));
974
975                 return strdup(buf);
976         }
977
978         return NULL;
979 }
980
981 static Eina_Bool __cal_detail_check_autolink_delimiter(char ch)
982 {
983         if (isdigit(ch) || isalpha(ch))
984         {
985                 return false;
986         }
987
988         char undeli[] = "@-_.+";        /* The char in the string is not a delimiter */
989
990         int i = 0;
991         for (i = 0; i < sizeof(undeli) / sizeof(undeli[0]); ++i)
992         {
993                 if (ch == undeli[i])
994                 {
995                         return false;
996                 }
997         }
998         return true;
999 }
1000
1001 static int __cal_detail_check_autolink_phone_number(const char *word)
1002 {
1003         const int min_phone_num_len = 3;
1004         const int max_phone_num_len = 15;
1005         int i = 0;
1006         int num_counter = 0;
1007
1008         if (word[0] == '+')
1009         {
1010                 i++;
1011         }
1012
1013         while (isdigit(word[i]) || word[i] == '-')
1014         {
1015                 if (isdigit(word[i]))
1016                 {
1017                         num_counter++;
1018                         if (num_counter > max_phone_num_len)
1019                         {
1020                                 break;
1021                         }
1022                 }
1023                 else if (i == 0 || word[i - 1] == '-')
1024                 {
1025                         /* The first char is '-' or two consecutive '-' */
1026                         break;
1027                 }
1028                 i++;
1029         }
1030
1031         /* Make sure that the last char is digit */
1032         while (!isdigit(word[i]))
1033         {
1034                 i--;
1035         }
1036
1037         if (num_counter < min_phone_num_len)
1038         {
1039                 return 0;
1040         }
1041         else
1042         {
1043                 return i + 1;
1044         }
1045 }
1046
1047 static enum anchor_t __cal_detail_get_autolink_anchor_type(const char *word)
1048 {
1049         CAL_ASSERT(word);
1050         int i = 0;
1051
1052         if (NULL != strstr(word, EMAIL_LINK_FLAG))
1053         {
1054                 return ANCHOR_EMAIL_LINK;
1055         }
1056
1057         /* Email */
1058         if (strchr(word, '@') != NULL)
1059         {
1060                 return ANCHOR_EMAIL;
1061         }
1062
1063         /* Url */
1064         char *url_prefix[] = { "http://", "HTTP://", "www.", "WWW." };
1065         for (i = 0; i < sizeof(url_prefix) / sizeof(url_prefix[0]); ++i)
1066         {
1067                 if (g_str_has_prefix(word, url_prefix[i]))
1068                 {
1069                         return ANCHOR_URL;
1070                 }
1071         }
1072
1073         /* Phone number */
1074         if (__cal_detail_check_autolink_phone_number(word))
1075         {
1076                 return ANCHOR_PHONE;
1077         }
1078
1079         return NOT_ANCHOR;
1080 }
1081
1082 static void __cal_detail_process_autolink_anchor_word(GString *anchor)
1083 {
1084         CAL_ASSERT(anchor);
1085
1086         int len = 0;
1087         GString *word = g_string_new(anchor->str);
1088         g_string_assign(anchor, "");    /* clear */
1089         char *snote_display = NULL;
1090         char *email_link = NULL;
1091
1092         switch (__cal_detail_get_autolink_anchor_type(word->str))
1093         {
1094         case ANCHOR_EMAIL:
1095                 g_string_append(anchor, "<color=#72b1f2FF>");
1096                 g_string_append_printf(anchor,
1097                                 "<a href=email|%s underline=on underline_color=#72b1f2FF>",
1098                                 word->str);
1099                 g_string_append(anchor, word->str);
1100                 g_string_append(anchor, "</a></color>");
1101                 break;
1102
1103         case ANCHOR_URL:
1104                 g_string_append(anchor, "<color=#72b1f2FF>");
1105                 g_string_append_printf(anchor,
1106                                 "<a href=url|%s underline=on underline_color=#72b1f2FF>",
1107                                 word->str);
1108                 g_string_append(anchor, word->str);
1109                 g_string_append(anchor, "</a></color>");
1110                 break;
1111
1112         case ANCHOR_PHONE:
1113                 len = __cal_detail_check_autolink_phone_number(word->str);
1114                 char num[32] = { 0 };
1115                 snprintf(num, len + 1, "%s", word->str);
1116
1117                 g_string_append(anchor, "<color=#72b1f2FF>");
1118                 g_string_append_printf(anchor,
1119                                 "<a href=phone_num|%s underline=on underline_color=#72b1f2FF>",
1120                                 num);
1121                 g_string_append(anchor, num);
1122                 g_string_append(anchor, "</a></color>");
1123                 g_string_append(anchor, word->str + len);
1124                 break;
1125         case ANCHOR_EMAIL_LINK:
1126
1127                 email_link = strstr(word->str, EMAIL_LINK_FLAG);
1128                 int nsize = email_link - word->str + 1;
1129                 CAL_CALLOC(snote_display, nsize, char);
1130                 if(NULL != snote_display)
1131                 {
1132                         strncpy(snote_display, word->str, nsize-1);
1133                 }
1134                 g_string_append(anchor, "<color=#72b1f2FF>");
1135                 g_string_append_printf(anchor,
1136                                 "<a href=email_link|%s underline=on underline_color=#72b1f2FF>",
1137                                 email_link+strlen(EMAIL_LINK_FLAG));
1138
1139                 g_string_append(anchor, snote_display);
1140                 g_string_append(anchor, "</a></color>");
1141                 free(snote_display);
1142                 break;
1143         default:
1144                 g_string_append(anchor, word->str);
1145                 break;
1146         }
1147 }
1148
1149 static GString *__cal_detail_add_autolink_anchor(const char *content)
1150 {
1151         c_retvm_if(!content, NULL, "Input parameter is null");
1152
1153         const char *p = content;
1154         char *gt = NULL;
1155         GString *text = g_string_new("");
1156         GString *buf = g_string_new("");
1157
1158         while (*p != '\0') {
1159                 g_string_assign(buf, "");       /* reset buffer */
1160
1161                 if(NULL != strstr(p, EMAIL_LINK_FLAG))
1162                 {
1163
1164                         g_string_append_len(buf, p, CAL_STRLEN(content));
1165                         __cal_detail_process_autolink_anchor_word(buf);
1166                         g_string_append(text, buf->str);
1167                         break;;
1168                 }
1169                 else if (__cal_detail_check_autolink_delimiter(p[0]))
1170                 {
1171                         g_string_append_c(text, p[0]);
1172                         p++;
1173                 }
1174                 else if (p[0] == '<')
1175                 {       /* tag begin */
1176                         gt = strchr(p, '>');    /* search tag end */
1177                         CAL_ASSERT(gt); /* assert '<' and '>' are matched */
1178                         g_string_append_len(text, p, gt - p + 1);
1179                         p = gt + 1;
1180                 }
1181                 else
1182                 {
1183                         int i = 0;
1184                         while (p[i] != '\0')
1185                         {
1186                                 if (__cal_detail_check_autolink_delimiter(p[i]) || p[i] == '<')
1187                                 {
1188                                         break;
1189                                 }
1190                                 i++;
1191                         }
1192
1193                         g_string_append_len(buf, p, i);
1194                         p = p + i;
1195
1196                         __cal_detail_process_autolink_anchor_word(buf);
1197                         g_string_append(text, buf->str);
1198                 }
1199         }
1200
1201         g_string_free(buf, TRUE);
1202
1203         return text;
1204 }
1205
1206 static char* __cal_detail_get_note_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
1207 {
1208         cal_struct *cs;
1209
1210         cal_detail_data *p = item_data->p;
1211         cs = p->cs;
1212         if (NULL == cs)
1213         {
1214                 return NULL;
1215         }
1216
1217         return NULL;
1218 }
1219
1220 static void __cal_detail_autolink_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
1221 {
1222         c_retm_if(!data, "data is null");
1223         c_retm_if(!obj, "obj is null");
1224
1225         struct autolink_data_t *ald = data;
1226
1227         free(ald->info);
1228         free(ald);
1229
1230         evas_object_del(obj);
1231 }
1232
1233 void __cal_detail_show_autolink_popup(struct autolink_data_t *ald, cal_detail_data* p)
1234 {
1235         c_retm_if(!ald, "ald is null");
1236         c_retm_if(!p, "p is null");
1237
1238         struct anchor_popup_item_t *list = NULL;
1239         int count = 0;
1240         int i = 0;
1241         Evas_Object *ctx;
1242         Elm_Object_Item *item = NULL;
1243
1244         switch (ald->type)
1245         {
1246         case ANCHOR_EMAIL:
1247                 list = g_email_list;
1248                 count = ARRAY_SIZE(g_email_list);
1249                 break;
1250         case ANCHOR_PHONE:
1251                 list = g_phone_list;
1252                 count = ARRAY_SIZE(g_phone_list);
1253                 break;
1254         default:
1255                 break;
1256         }
1257
1258         ctx = elm_ctxpopup_add(p->ly);
1259         c_retm_if(!ctx, "elm_ctxpopup_add is failed");
1260
1261         evas_object_smart_callback_add(ctx, "dismissed", __cal_detail_autolink_popup_response_callback, ald);
1262
1263         for (i = 0; i < count; ++i)
1264         {
1265                 item = elm_ctxpopup_item_append(ctx, list[i].label, NULL, list[i].response, ald);
1266                 if (!item)
1267                 {
1268                         ERR("elm_ctxpopup_item_append returned null");
1269                         evas_object_del(ctx);
1270                 }
1271         }
1272
1273         evas_object_move(ctx, p->x, p->y);
1274         evas_object_show(ctx);
1275 }
1276
1277 static char *__cal_detail_get_autolink_anchor_type_str(enum anchor_t type)
1278 {
1279         switch (type) {
1280         case ANCHOR_EMAIL:
1281                 return "email";
1282         case ANCHOR_PHONE:
1283                 return "phone_num";
1284         case ANCHOR_URL:
1285                 return "url";
1286         case ANCHOR_EMAIL_LINK:
1287                 return "email_link";
1288         default:
1289                 return "";
1290         }
1291 }
1292
1293 static enum anchor_t __cal_detail_parse_autolink_anchor_type(char *s)
1294 {
1295         int i = 0;
1296         for (i = NOT_ANCHOR + 1; i < NOT_ANCHOR + 5; ++i)
1297         {
1298                 if (CAL_STRCMP(s, __cal_detail_get_autolink_anchor_type_str(i)) == 0)
1299                 {
1300                         return (enum anchor_t)i;
1301                 }
1302         }
1303         return NOT_ANCHOR;
1304 }
1305
1306
1307 static void __cal_detail_autolink_email_link_clicked(char *info)
1308 {
1309         c_retm_if(!info, "Input parameter is null");
1310         bundle *req = NULL;
1311         char *account_id= NULL;
1312         char *email_id= NULL;
1313         char *src_box= NULL;
1314         char *temp= NULL;
1315         int ret = 0;
1316
1317         req = bundle_create();
1318         c_retm_if(!req, "bundle_create is failed");
1319
1320         char livemagazine[30] = { 0, };
1321         snprintf(livemagazine, sizeof(livemagazine), "%d", 0);
1322         char internal[30] = { 0, };
1323         snprintf(internal, sizeof(internal), "%d", 1);
1324         account_id = info;
1325         temp = strchr(info, '_');
1326         if (NULL != temp)
1327         {
1328                 *temp = '\0';
1329                 bundle_add(req, "ACCOUNT_ID", account_id);
1330         }
1331
1332         if (NULL != temp)
1333         {
1334                 email_id = temp+1;
1335                 temp = NULL;
1336                 temp = strchr(email_id, '_');
1337                 if(NULL != temp)
1338                 {
1339                         *temp = '\0';
1340                         bundle_add(req, "MAIL_ID", email_id);
1341                 }
1342         }
1343
1344         if (NULL != temp)
1345         {
1346                 src_box= temp+1;
1347                 bundle_add(req, "MAILBOX", src_box);
1348         }
1349
1350
1351         bundle_add(req, "RUN_TYPE", "7");
1352         ret = aul_launch_app("org.tizen.email", req);
1353         c_warn_if(!ret, "aul_launch_app(org.tizen.email) is failed(%d)", ret);
1354
1355         bundle_free(req);
1356 }
1357
1358 static void __cal_detail_autolink_anchor_clicked_callback(void *data, Evas_Object *obj, void *event_info)
1359 {
1360         c_retm_if(!data, "data is null");
1361
1362         struct autolink_data_t *s_ald = NULL;
1363         cal_detail_data* p = data;
1364         char buf[128] = { 0 };
1365
1366         Elm_Entry_Anchor_Info *ei = (Elm_Entry_Anchor_Info *)event_info;
1367
1368         char *temp = strchr(ei->name, ' ');
1369         if (!temp)
1370         {
1371                 ERR("strchr(ei->name, ' ') is failed");
1372                 return;
1373         }
1374
1375         CAL_STRNCPY(buf, ei->name, temp - ei->name);
1376
1377         temp = strchr(buf, '|');
1378         if (!temp)
1379         {
1380                 ERR("strchr(buf '|') is failed");
1381                 return;
1382         }
1383
1384         s_ald = calloc(1, sizeof(struct autolink_data_t));
1385         c_retm_if(!s_ald, "calloc(1, struct autolink_data_t) is failed");
1386
1387         s_ald->info = calloc(128, sizeof(char));
1388         if (!s_ald->info)
1389         {
1390                 ERR("calloc(128, char) is failed");
1391                 free(s_ald);
1392                 return;
1393         }
1394
1395         *temp = '\0';
1396         CAL_STRNCPY(s_ald->info, temp + 1, 128);
1397
1398         s_ald->type = __cal_detail_parse_autolink_anchor_type(buf);
1399
1400         switch (s_ald->type)
1401         {
1402         case ANCHOR_EMAIL:
1403         case ANCHOR_PHONE:
1404                 __cal_detail_show_autolink_popup(s_ald, p);
1405                 return;
1406         case ANCHOR_URL:
1407                 aul_open_content(s_ald->info);  /* launch browser */
1408                 break;
1409         case ANCHOR_EMAIL_LINK:
1410                 __cal_detail_autolink_email_link_clicked(s_ald->info);
1411                 break;
1412         default:
1413                 break;
1414         }
1415
1416         free(s_ald->info);
1417         free(s_ald);
1418 }
1419
1420 static Evas_Object* __cal_detail_add_note_object(cal_detail_data *p, Evas_Object *parent, const char *text)
1421 {
1422         c_retvm_if(!p, NULL, "p is null");
1423         c_retvm_if(!parent, NULL, "parent is null");
1424         c_retvm_if(!text, NULL, "text is null");
1425         c_retvm_if(!strlen(text), NULL, "strlen(text) is zero");
1426
1427         Evas_Object *layout = cal_util_add_edit_field(parent, S_("IDS_COM_BODY_NOTE"), NULL, EINA_FALSE, EINA_FALSE);
1428         c_retvm_if(!layout, NULL, "layout is null");
1429
1430         Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
1431         c_retvm_if(!entry, layout, "entry is null");
1432
1433         p->entry = entry;
1434         p->text = text;
1435
1436         evas_object_smart_callback_add(entry, "anchor,clicked", __cal_detail_autolink_anchor_clicked_callback, p);
1437         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1438         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
1439         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
1440         elm_entry_autocapital_type_set(entry, EINA_TRUE);
1441
1442         elm_entry_entry_set(entry, text);
1443
1444         return layout;
1445 }
1446
1447 static Evas_Object* __cal_detail_add_note_icon(Evas_Object *obj, const char *part,  cal_detail_genlist_item_data *item_data)
1448 {
1449         c_retvm_if(!obj, NULL, "obj is null");
1450         c_retvm_if(!part, NULL, "part is null");
1451         c_retvm_if(!item_data, NULL, "item_data is null");
1452
1453         cal_detail_data *p = item_data->p;
1454         Evas_Object *edit_field = NULL;
1455         const char *note = NULL;
1456         GString *text = NULL;
1457         cal_struct *cs = p->cs;
1458         c_retvm_if(!cs, NULL, "cs is null");
1459
1460         if (!CAL_STRCMP(part, "elm.icon"))
1461         {
1462                 note = __cal_detail_get_note(cs);
1463                 if (!CAL_STRLEN(note))
1464                         return NULL;
1465
1466                 text = __cal_detail_add_autolink_anchor(elm_entry_utf8_to_markup(note));
1467                 g_string_prepend(text, "<font_size=35>");
1468                 edit_field = __cal_detail_add_note_object(p, obj, text->str);
1469         }
1470
1471         return edit_field;
1472 }
1473
1474 static Evas_Object *__cal_detail_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
1475 {
1476         c_retvm_if(!data, NULL, "data is null");
1477
1478         Evas_Object *e_obj = NULL;
1479
1480         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
1481         int type = item_data->type;
1482
1483         switch ( type )
1484         {
1485
1486         case _GTYPE_NOTE:
1487                 e_obj = __cal_detail_add_note_icon(obj, part, item_data);
1488                 break;
1489         default:
1490                 break;
1491         }
1492
1493         return e_obj;
1494 }
1495
1496 static  char* __cal_detail_get_priority_text(Evas_Object *obj, const char *part, cal_detail_genlist_item_data *item_data)
1497 {
1498         cal_detail_data *p = item_data->p;
1499         cal_struct *cs;
1500         cs = p->cs;
1501         c_retvm_if(!cs, NULL, "cs is null");
1502
1503         if (!CAL_STRCMP(part, "elm.text.1"))
1504                 return strdup(C_("IDS_CLD_BODY_PRIORITY"));
1505
1506         if (!CAL_STRCMP(part, "elm.text.2")) {
1507                 switch (p->priority) {
1508                         case EVENT_PRIORITY_LOW:
1509                                 return strdup(S_("IDS_COM_BODY_LOW"));
1510                         case EVENT_PRIORITY_NORMAL:
1511                                 return strdup(C_("IDS_IDLE_BODY_NORMAL"));
1512                         case EVENT_PRIORITY_HIGH:
1513                                 return strdup(S_("IDS_COM_OPT_HIGH_M_QUALITY"));
1514                         default:
1515                                 return NULL;
1516                 }
1517         }
1518
1519         return NULL;
1520 }
1521
1522 static char *__cal_detail_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
1523 {
1524         c_retvm_if(!data, NULL, "data is null");
1525
1526         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
1527         int type = item_data->type;
1528
1529         switch ( type )
1530         {
1531         case _GTYPE_TITLE_LOC:
1532                 return __cal_detail_get_title_location_text(obj, part, item_data);
1533         case _GTYPE_START_AND_END_TIME:
1534                 return __cal_detail_get_start_time_and_end_time_text(obj, part, item_data);
1535         case _GTYPE_DUE:
1536                 return __cal_detail_get_due_text(obj, part, item_data);
1537         case _GTYPE_REMINDER_AND_REPEAT:
1538                 return __cal_detail_add_reminder_and_repeat_text(obj, part, item_data);
1539         case _GTYPE_NOTE:
1540                 return __cal_detail_get_note_text(obj, part, item_data);
1541
1542         case _GTYPE_LINKED_CAL:
1543                 return __cal_detail_get_save_to_text(obj, part, item_data);
1544         case _GTYPE_PRIORITY:
1545                 return __cal_detail_get_priority_text(obj, part, item_data);
1546         default:
1547                 return NULL;
1548         }
1549 }
1550
1551 static void __cal_detail_genlist_item_delete_callback(void *data, Evas_Object *obj)
1552 {
1553         c_retm_if(!data, "data is null");
1554
1555         cal_detail_genlist_item_data *item_data = (cal_detail_genlist_item_data*)data;
1556
1557         free(item_data);
1558
1559         return;
1560 }
1561
1562 static Eina_Bool __cal_detail_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
1563 {
1564         return EINA_FALSE;
1565 }
1566
1567 static void __cal_detail_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
1568 {
1569         return;
1570 }
1571
1572 static Elm_Object_Item* __cal_detail_add_genlist_item(Evas_Object *parent, Elm_Genlist_Item_Class *itc, int type, cal_detail_data *p)
1573 {
1574         c_retvm_if(!parent, NULL, "parent is null");
1575         c_retvm_if(!itc, NULL, "itc is null");
1576         c_retvm_if(!p, NULL, "p is null");
1577
1578         cal_detail_genlist_item_data *item_data = calloc(1, sizeof(cal_detail_genlist_item_data));
1579         c_retvm_if(!item_data, NULL, "calloc(1, sizeof(cal_detail_genlist_item_data)) is failed");
1580
1581         item_data->p = p;
1582
1583         item_data->type = type;
1584
1585         item_data->it = elm_genlist_item_append(parent, itc, (void*)(item_data), NULL, ELM_GENLIST_ITEM_NONE, __cal_detail_genlist_item_select_callback, NULL);
1586         c_retvm_if(!item_data->it, NULL, "elm_genlist_item_append() is failed");
1587
1588         return item_data->it;
1589 }
1590
1591 static Elm_Object_Item* __cal_detail_add_separator(Evas_Object *genlist, cal_detail_data *p)
1592 {
1593         c_retvm_if(!p, NULL, "p is null");
1594         c_retvm_if(!genlist, NULL, "genlist is null");
1595
1596         if (p->is_todo_mode)
1597                 return NULL;
1598
1599         Elm_Object_Item *git = __cal_detail_add_genlist_item(genlist, &itc_seperator, 0, p);
1600         c_retvm_if(!git, NULL, "__cal_detail_add_genlist_item returned null");
1601
1602         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1603
1604         return git;
1605 }
1606
1607
1608 static Elm_Object_Item* __cal_detail_add_title_location(Evas_Object *genlist, cal_detail_data *p)
1609 {
1610         __cal_detail_add_separator(genlist, p);
1611         return __cal_detail_add_genlist_item(genlist, &itc_2text, _GTYPE_TITLE_LOC, p);
1612 }
1613
1614 static Elm_Object_Item* __cal_detail_add_start_and_end_time(Evas_Object *genlist, cal_detail_data *p)
1615 {
1616 //      __cal_detail_add_separator(genlist, p);
1617         return __cal_detail_add_genlist_item(genlist, &itc_4text, _GTYPE_START_AND_END_TIME, p);
1618 }
1619
1620 static Elm_Object_Item* __cal_detail_add_due(Evas_Object *genlist, cal_detail_data *p)
1621 {
1622 //      __cal_detail_add_separator(genlist, p);
1623         return __cal_detail_add_genlist_item(genlist, &itc_2text, _GTYPE_DUE, p);
1624 }
1625
1626 static void __cal_detail_add_reminder_and_repeat_item(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, int type, cal_detail_data *p, int alarm)
1627 {
1628         c_retm_if(!genlist, "genlist is null");
1629         c_retm_if(!itc, "itc is null");
1630         c_retm_if(!p, "p is null");
1631
1632         cal_detail_genlist_item_data *item_data = calloc(1, sizeof(cal_detail_genlist_item_data));
1633         c_retm_if(!item_data, "calloc is failed");
1634
1635         item_data->p = p;
1636         item_data->type = type;
1637         item_data->alarm_value = alarm;
1638
1639         item_data->it = elm_genlist_item_append(genlist, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1640
1641         if (!item_data->it)
1642         {
1643                 ERR("elm_genlist_item_append returned null");
1644                 free(item_data);
1645                 return ;
1646         }
1647 }
1648
1649 static void __cal_detail_add_reminder_and_repeat(Evas_Object *genlist, cal_detail_data *p)
1650 {
1651         c_retm_if(!genlist, "genlist is null");
1652         c_retm_if(!p, "p is null");
1653         c_retm_if(!p->cs, "p->cs is null");
1654
1655 //      __cal_detail_add_separator(genlist, p);
1656         __cal_detail_get_alarm(p, p->cs);
1657
1658         if (!p->alarm_list) {
1659                 __cal_detail_add_reminder_and_repeat_item(genlist, &itc_4text, _GTYPE_REMINDER_AND_REPEAT, p, -1);
1660         } else {
1661                 GList *alarm = p->alarm_list;
1662                 int alarm_min;
1663
1664                 while (alarm) {
1665                         alarm_min = (int)alarm->data;
1666                         __cal_detail_add_reminder_and_repeat_item(genlist, &itc_4text, _GTYPE_REMINDER_AND_REPEAT, p, alarm_min);
1667                         alarm = g_list_next(alarm);
1668                 }
1669         }
1670         return;
1671 }
1672
1673 static Elm_Object_Item* __cal_detail_add_note(Evas_Object *genlist, cal_detail_data *p)
1674 {
1675         c_retvm_if(!p, NULL, "p is null");
1676         c_retvm_if(!genlist, NULL, "genlist is null");
1677
1678         cal_struct *cs = p->cs;
1679         c_retvm_if(!cs, NULL, "cs is null");
1680
1681         const char *note = __cal_detail_get_note(cs);
1682         if (!CAL_STRLEN(note))
1683                 return NULL;
1684
1685 //      __cal_detail_add_separator(genlist, p);
1686
1687         return __cal_detail_add_genlist_item(genlist, &itc_mutilline, _GTYPE_NOTE, p);
1688 }
1689
1690 static Elm_Object_Item* __cal_detail_add_save_to(Evas_Object *genlist, cal_detail_data *p)
1691 {
1692 //      __cal_detail_add_separator(genlist, p);
1693
1694         return __cal_detail_add_genlist_item(genlist, &itc_linked_cal, _GTYPE_LINKED_CAL, p);
1695 }
1696
1697 static void __cal_detail_show_error_popup(cal_detail_data *p)
1698 {
1699         CAL_FN_START;
1700
1701         c_retm_if(!p, "p is null");
1702         c_retm_if(!p->ad, "p->ad is null");
1703         c_retm_if(!p->ad->win, "p->ad->win is null");
1704
1705         if (p->popup)
1706                 evas_object_del(p->popup);
1707
1708         p->popup = cal_util_add_popup(p->ad->win, NULL, S_("IDS_COM_POP_WARNING"), C_("IDS_CLD_BODY_NO_EVENTS"),
1709                 __cal_detail_error_popup_response_event_callback, p->ad, S_("IDS_COM_SK_OK"), NULL);
1710         c_retm_if(!p->popup, "cal_util_add_popup(p->ad->win) returned null");
1711 }
1712
1713 static Evas_Object *__cal_detail_create_genlist(cal_detail_data *p)
1714 {
1715         c_retvm_if(!p, NULL, "p is null");
1716         c_retvm_if(!p->ad, NULL, "p->ad is null");
1717
1718         Evas_Object *genlist;
1719
1720         if (p->ad->ical)
1721                 p->cs = p->ad->ical;
1722         else {
1723                 if (p->cs)
1724                         CALENDAR_SVC_STRUCT_FREE(&p->cs);
1725
1726                 p->cs = __cal_detail_get_event(p, p->ad->cid);
1727         }
1728
1729         cal_main_set_cs(p->ad, p->cs);
1730
1731         if (!p->cs) {
1732                 __cal_detail_show_error_popup(p);
1733                 return NULL;
1734         }
1735
1736         genlist = elm_genlist_add(p->ly);
1737         c_retvm_if(!genlist, NULL, "elm_genlist_add(p->ly) returned null");
1738
1739         elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_NONE);
1740
1741         itc_seperator.item_style = "dialogue/seperator";
1742         itc_seperator.func.text_get = NULL;
1743         itc_seperator.func.state_get = __cal_detail_get_genlist_item_state;
1744         itc_seperator.func.del = __cal_detail_genlist_item_delete_callback;
1745
1746         itc_2text.item_style = "dialogue/2text";
1747         itc_2text.func.text_get = __cal_detail_get_genlist_item_label;
1748         itc_2text.func.del = __cal_detail_genlist_item_delete_callback;
1749
1750         itc_4text.item_style = "dialogue/4text";
1751         itc_4text.func.text_get = __cal_detail_get_genlist_item_label;
1752         itc_4text.func.del = __cal_detail_genlist_item_delete_callback;
1753
1754         itc_mutilline.item_style = "dialogue/1icon";
1755         itc_mutilline.func.text_get = __cal_detail_get_genlist_item_label;
1756         itc_mutilline.func.del = __cal_detail_genlist_item_delete_callback;
1757         itc_mutilline.func.content_get = __cal_detail_get_genlist_item_icon;
1758
1759         itc_parts.item_style = "dialogue/1icon.fill";
1760         itc_parts.func.text_get = __cal_detail_get_genlist_item_label;
1761         itc_parts.func.del = __cal_detail_genlist_item_delete_callback;
1762         itc_parts.func.content_get = __cal_detail_get_genlist_item_icon;
1763
1764         itc_linked_cal.item_style = "dialogue/2text";
1765         itc_linked_cal.func.text_get = __cal_detail_get_genlist_item_label;
1766         itc_linked_cal.func.del = __cal_detail_genlist_item_delete_callback;
1767
1768         __cal_detail_add_title_location(genlist, p);
1769         __cal_detail_add_start_and_end_time(genlist, p);
1770         __cal_detail_add_reminder_and_repeat(genlist, p);
1771         __cal_detail_add_note(genlist, p);
1772
1773         __cal_detail_add_save_to(genlist, p);
1774
1775         return genlist;
1776 }
1777
1778 static void __cal_detail_update_view(void *data)
1779 {
1780         CAL_FN_START;
1781
1782         c_retm_if(!data, "data is null");
1783
1784         cal_detail_data *p = data;
1785
1786         if (p->is_deleted)
1787                 return;
1788
1789         Evas_Object *genlist;
1790         struct appdata* ad = p->ad;
1791         c_retm_if(!ad, "ad is null");
1792
1793         is_hour24 = ad->is_hour24;
1794
1795         cal_util_delete_evas_object(&p->genlist);
1796         genlist = __cal_detail_create_genlist(p);
1797         if (genlist)
1798         {
1799                 elm_object_part_content_set(p->ly, "sw", genlist);
1800                 p->genlist = genlist;
1801         }
1802 }
1803
1804
1805 static Evas_Object *__cal_detail_create_layout(struct appdata *ad, Evas_Object *parent)
1806 {
1807         Evas_Object *ly;
1808         cal_detail_data *p;
1809         Evas_Object *genlist;
1810         p = calloc(1, sizeof(cal_detail_data));
1811
1812         p->name = _name;
1813         p->parent = parent;
1814
1815         ly = cal_util_add_layout(parent, "edit");
1816         if (!ly)
1817         {
1818                 free(p);
1819                 return NULL;
1820         }
1821         evas_object_data_set(ly, "priv", p);
1822         p->ad = ad;
1823         p->ly = ly;
1824         p->cid = ad->cid;
1825         p->alarm_list  = NULL;
1826         p->is_todo_mode  = EINA_FALSE;
1827
1828         is_hour24 = ad->is_hour24;
1829
1830         genlist = __cal_detail_create_genlist(p);
1831         if (!genlist)
1832         {
1833                 evas_object_del(ly);
1834                 free(p);
1835                 return NULL;
1836         }
1837
1838         elm_object_part_content_set(p->ly, "sw", genlist);
1839         p->genlist = genlist;
1840
1841         p->evt = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, __cal_detail_mouse_button_down_callback, p);
1842
1843         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_detail_delete_layout, p);
1844
1845         CALENDAR_SVC_ADD_EVENT_CHANGED_CALLBACK(__cal_detail_update_view, p);
1846
1847         return ly;
1848 }
1849
1850 static void __cal_detail_save_to_calendar_button_callback(void *data, Evas_Object *obj, void *ei)
1851 {
1852         CAL_FN_START;
1853
1854         struct appdata *ad = data;
1855         c_retm_if(!ad || !ad->nv, "ad or ad->nv is null");
1856
1857         int r = CALENDAR_SVC_INSERT(ad->ical);
1858         if (CAL_SUCCESS != r)
1859                 ERR("Calendar service delete failed: %d", r);
1860
1861 }
1862
1863 void cal_detail_create_view(struct appdata *ad, Evas_Object *parent)
1864 {
1865         CAL_FN_START;
1866
1867         c_retm_if(!ad || !parent, "Input parameter is null");
1868
1869         if (ad->current_view == CV_DETAIL)
1870                 return;
1871
1872         Evas_Object *ly;
1873         Evas_Object *back_button;
1874         Evas_Object *controlbar;
1875         Elm_Object_Item* navi_item;
1876
1877         ly = __cal_detail_create_layout(ad, parent);
1878         c_retm_if(!ly, "__cal_detail_create_layout(ad, parent) is failed");
1879
1880         navi_item = elm_naviframe_item_push(ad->nv, C_("IDS_CLD_BODY_EVENT_DETAILS"), NULL, NULL, ly, NULL);
1881         if (!navi_item)
1882         {
1883                 ERR("elm_naviframe_item_push is failed");
1884                 evas_object_del(ly);
1885                 return;
1886         }
1887
1888         controlbar = cal_util_add_controlbar(ad->nv);
1889         if (!controlbar)
1890         {
1891                 ERR("cal_util_add_controlbar(ad->nv) is failed");
1892                 elm_naviframe_item_pop(ad->nv);
1893                 return;
1894         }
1895
1896         elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_EDIT, NULL, __cal_detail_edit_button_callback, ly);
1897
1898         if (ad->item_type == ITEM_TYPE_UNKNOWN) {
1899                 elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_SHARE, NULL, __cal_detail_send_button_callback, ly);
1900                 elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_DELETE, NULL, __cal_detail_delete_button_callback, ly);
1901         }
1902
1903         elm_object_item_part_content_set( navi_item, "controlbar", controlbar);
1904
1905         back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
1906         if (!back_button)
1907         {
1908                 back_button = elm_button_add(ad->nv);
1909                 if (!back_button)
1910                 {
1911                         ERR("elm_button_add is failed.");
1912                         return;
1913                 }
1914                 elm_object_style_set(back_button, "naviframe/back_btn/default");
1915                 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
1916         }
1917         elm_object_style_set(back_button, "naviframe/back_btn/default");
1918         evas_object_smart_callback_add(back_button, "clicked",  __cal_detail_back_button_callback, CAL_UTIL_GET_PRIV_DATA(ly));
1919
1920         ad->current_view = CV_DETAIL;
1921
1922         CAL_FN_END;
1923 }
1924
1925 void cal_detail_create_viewer(struct appdata *ad, Evas_Object *parent, cal_struct *cs)
1926 {
1927         CAL_FN_START;
1928
1929         c_retm_if(!ad || !parent || !cs, "Input parameter is null");
1930
1931         Evas_Object *ly;
1932         Evas_Object *back_button;
1933         Elm_Object_Item* navi_item;
1934
1935         ad->ical = cs;
1936         ly = __cal_detail_create_layout(ad, parent);
1937         c_retm_if(!ly, "__cal_detail_create_layout(ad, parent) is failed");
1938
1939         navi_item = elm_naviframe_item_push(ad->nv, _("VCS Viewer"), NULL, NULL, ly, NULL);
1940         if (!navi_item) {
1941                 ERR("elm_naviframe_item_push is failed");
1942                 evas_object_del(ly);
1943                 return;
1944         }
1945
1946         Evas_Object *controlbar = cal_util_add_controlbar(ad->nv);
1947         if (!controlbar) {
1948                 ERR("cal_util_add_controlbar(ad->nv) is failed");
1949                 elm_naviframe_item_pop(ad->nv);
1950                 return;
1951         }
1952
1953         elm_toolbar_item_append(controlbar, NULL, S_("IDS_COM_OPT_SAVE"), __cal_detail_save_to_calendar_button_callback, ad);
1954         elm_object_item_part_content_set(navi_item, "controlbar", controlbar);
1955
1956         back_button = elm_button_add(ad->nv);
1957         c_retm_if(!back_button, "elm_button_add is failed.");
1958
1959         elm_object_style_set(back_button, "naviframe/back_btn/default");
1960         elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
1961
1962         evas_object_smart_callback_add(back_button, "clicked",  __cal_detail_viewer_back_button_callback, ad);
1963 }
1964
1965 static int __cal_detail_get_priority(cal_struct *cs)
1966 {
1967         c_retvm_if(!cs, 0, "cs is null");
1968
1969         return CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_PRIORITY);
1970 }
1971
1972 static void __cal_detail_add_priority(Evas_Object *genlist, cal_detail_data *p)
1973 {
1974         c_retm_if(!genlist, "genlist is null");
1975         c_retm_if(!p, "p is null");
1976         c_retm_if(!p->cs, "p->cs is null");
1977
1978         p->priority = __cal_detail_get_priority(p->cs);
1979
1980         __cal_detail_add_genlist_item(genlist, &itc_4text, _GTYPE_PRIORITY, p);
1981
1982         return;
1983 }
1984
1985 static Evas_Object *__cal_detail_create_genlist_todo(cal_detail_data *p)
1986 {
1987         c_retvm_if(!p, NULL, "p is null");
1988         c_retvm_if(!p->ad, NULL, "p->ad is null");
1989
1990         Evas_Object *genlist;
1991
1992         if(p->ad->is_aul && p->ad->ical)
1993                 p->cs = p->ad->ical;
1994         else
1995                 p->cs = __cal_detail_get_event(p, p->ad->cid);
1996
1997         if(!p->cs)
1998                 __cal_detail_show_error_popup(p);
1999
2000         genlist = elm_genlist_add(p->ly);
2001         c_retvm_if(!genlist, NULL, "elm_genlist_add(p->ly) returned null");
2002
2003         if (NULL != p->ad->theme)
2004         {
2005                 elm_object_theme_set(genlist, p->ad->theme);
2006         }
2007
2008         elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_NONE);
2009
2010         itc_seperator.item_style = "dialogue/seperator";
2011         itc_seperator.func.text_get = NULL;
2012         itc_seperator.func.state_get = __cal_detail_get_genlist_item_state;
2013         itc_seperator.func.del = __cal_detail_genlist_item_delete_callback;
2014
2015         itc_2text.item_style = "dialogue/2text";
2016         itc_2text.func.text_get = __cal_detail_get_genlist_item_label;
2017         itc_2text.func.del = __cal_detail_genlist_item_delete_callback;
2018
2019         itc_4text.item_style = "dialogue/2text";
2020         itc_4text.func.text_get = __cal_detail_get_genlist_item_label;
2021         itc_4text.func.del = __cal_detail_genlist_item_delete_callback;
2022
2023         itc_mutilline.item_style = "dialogue/1icon";
2024         itc_mutilline.func.text_get = __cal_detail_get_genlist_item_label;
2025         itc_mutilline.func.del = __cal_detail_genlist_item_delete_callback;
2026         itc_mutilline.func.content_get = __cal_detail_get_genlist_item_icon;
2027
2028         Elm_Object_Item *git = __cal_detail_add_genlist_item(genlist, &itc_seperator, 0, p);
2029         c_retvm_if(!git, NULL, "__cal_detail_add_genlist_item returned null");
2030         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2031
2032         __cal_detail_add_title_location(genlist, p);
2033         __cal_detail_add_due(genlist, p);
2034         __cal_detail_add_priority(genlist, p);
2035         __cal_detail_add_reminder_and_repeat(genlist, p);
2036         __cal_detail_add_note(genlist, p);
2037
2038         return genlist;
2039 }
2040
2041 static Evas_Object *__cal_detail_create_layout_todo(struct appdata *ad, Evas_Object *parent)
2042 {
2043         Evas_Object *ly;
2044         cal_detail_data *p;
2045         Evas_Object *genlist;
2046         p = calloc(1, sizeof(cal_detail_data));
2047
2048         p->name = _name;
2049         p->parent = parent;
2050
2051         ly = cal_util_add_layout(parent, "edit");
2052         if (!ly)
2053         {
2054                 free(p);
2055                 return NULL;
2056         }
2057         evas_object_data_set(ly, "priv", p);
2058         p->ad = ad;
2059         p->ly = ly;
2060         p->cid = ad->cid;
2061         p->alarm_list  = NULL;
2062         p->is_todo_mode  = EINA_TRUE;
2063
2064         is_hour24 = ad->is_hour24;
2065
2066         genlist = __cal_detail_create_genlist_todo(p);
2067         if (!genlist)
2068         {
2069                 evas_object_del(ly);
2070                 free(p);
2071                 return NULL;
2072         }
2073
2074         elm_object_part_content_set(p->ly, "sw", genlist);
2075         p->genlist = genlist;
2076
2077         p->evt = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, __cal_detail_mouse_button_down_callback, p);
2078
2079         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_detail_delete_layout, p);
2080
2081         CALENDAR_SVC_ADD_EVENT_CHANGED_CALLBACK(__cal_detail_update_view_todo, p);
2082
2083         return ly;
2084 }
2085
2086 void cal_detail_create_view_todo(struct appdata *ad, Evas_Object *parent)
2087 {
2088         CAL_FN_START;
2089
2090         c_retm_if(!ad || !parent, "Input parameter is null");
2091
2092         Evas_Object *ly;
2093         Evas_Object *back_button;
2094         Evas_Object *controlbar;
2095         Elm_Object_Item* navi_item;
2096
2097         ly = __cal_detail_create_layout_todo(ad, parent);
2098         c_retm_if(!ly, "__cal_detail_create_layout(ad, parent) is failed");
2099
2100         navi_item = elm_naviframe_item_push(ad->nv, C_("IDS_CLD_BODY_TASK_DETAILS"), NULL, NULL, ly, NULL);
2101         if (!navi_item)
2102         {
2103                 ERR("elm_naviframe_item_push is failed");
2104                 evas_object_del(ly);
2105                 return;
2106         }
2107
2108         controlbar = cal_util_add_controlbar(ad->nv);
2109         if (!controlbar)
2110         {
2111                 ERR("cal_util_add_controlbar(ad->nv) is failed");
2112                 elm_naviframe_item_pop(ad->nv);
2113                 return;
2114         }
2115
2116         elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_EDIT, NULL, __cal_detail_edit_button_callback, ly);
2117         elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_SHARE, NULL, __cal_detail_send_button_callback, ly);
2118         elm_toolbar_item_append(controlbar, CAL_CBAR_ICON_DELETE, NULL, __cal_detail_delete_button_callback, ly);
2119
2120         elm_object_item_part_content_set( navi_item, "controlbar", controlbar);
2121
2122         back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
2123         if (!back_button)
2124         {
2125                 back_button = elm_button_add(ad->nv);
2126                 if (!back_button)
2127                 {
2128                         ERR("elm_button_add is failed.");
2129                         return;
2130                 }
2131                 elm_object_style_set(back_button, "naviframe/back_btn/default");
2132                 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
2133         }
2134         elm_object_style_set(back_button, "naviframe/back_btn/default");
2135         evas_object_smart_callback_add(back_button, "clicked",  __cal_detail_back_button_callback, CAL_UTIL_GET_PRIV_DATA(ly));
2136 }
2137
2138 static void __cal_detail_update_view_todo(void *data)
2139 {
2140         CAL_FN_START;
2141
2142         c_retm_if(!data, "data is null");
2143
2144         cal_detail_data *p = data;
2145
2146         if (p->is_deleted)
2147                 return;
2148
2149         Evas_Object *genlist;
2150         struct appdata* ad = p->ad;
2151         c_retm_if(!ad, "ad is null");
2152
2153         is_hour24 = ad->is_hour24;
2154
2155         cal_util_delete_evas_object(&p->genlist);
2156         genlist = __cal_detail_create_genlist_todo(p);
2157         if (genlist)
2158         {
2159                 elm_object_part_content_set(p->ly, "sw", genlist);
2160                 p->genlist = genlist;
2161         }
2162 }
2163
2164