Remove SMACK rule file(.rule) according three domain model
[apps/core/preloaded/calendar.git] / ug / edit / edit-alarm.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.1 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://floralicense.org/license/
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19 #include "edit-alarm.h"
20 #include "radio-group.h"
21 #include "reminder.h"
22 #include "gi-radio-timepicker.h"
23 #include "save-cancel.h"
24
25 typedef struct {
26         Evas_Object *window;
27         Evas_Object *conformant;
28         Evas_Object *naviframe;
29         Evas_Object *ly; // self
30
31         cal_edit_alarm_changed_callback alarm_changed_callback;
32         void* alarm_changed_callback_data;
33
34         Evas_Object *sc; // scroller
35         Evas_Object *bx; // box
36
37         cal_radio_group_h radio_group;
38
39         Elm_Object_Item* on_a_day;
40
41         cal_save_cancel_h save_cancel;
42
43         Evas_Object *e_custom;
44         Evas_Object *b_custom;
45         int bt_idx;
46
47         Elm_Object_Item *pre_selected_it;
48
49         Cal_Reminder reminder;
50
51         Evas_Object *ctx;
52
53         cal_edit_alarm_type alarm_type;
54 } cal_edit_alarm_data;
55
56 struct __cal_edit_alarm_button {
57         const char *label;
58         const char *plural_label;
59         int unit;
60 };
61 static struct __cal_edit_alarm_button cal_edit_alarm_button[] = {
62         { NULL, NULL, 1, },
63         { NULL, NULL, _HOUR, },
64         { NULL, NULL, _DAY, },
65         { NULL, NULL, _WEEK, },
66 };
67
68 static Elm_Entry_Filter_Limit_Size _limit_2char = {
69         .max_char_count = 2,
70 };
71 static Elm_Entry_Filter_Accept_Set _digit_only = {
72         .accepted = "0123456789",
73 };
74
75 static Elm_Genlist_Item_Class itc_seperator, itc_1text_1icon, itc_custom;
76
77 typedef struct
78 {
79         cal_edit_alarm_data *p;
80         int type;
81         int data;
82 } cal_edit_alarm_item_data;
83
84 enum cal_edit_alarm_genlist_item_type{
85         _GTYPE_SPEA = -1,
86         _GTYPE_OFF,
87         _GTYPE_ON_TIME,
88         _GTYPE_5_MIN,
89         _GTYPE_15_MIN,
90         _GTYPE_1_HOUR,
91         _GTYPE_1_DAY,
92         _GTYPE_1_WEEK,
93         _GTYPE_CUSTOMIZE,
94         _GTYPE_ON_A_DAY,
95         _GTYPE_MAX
96 };
97
98 static void __cal_edit_alarm_custom_ctx_selected_callback(void *data, Evas_Object *obj, void *ei);
99
100 static void __cal_edit_alarm_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
101 {
102         CAL_FN_START;
103
104         cal_edit_alarm_data *p = data;
105
106         cal_radio_group_destroy(p->radio_group);
107         if (p->save_cancel)
108                 cal_save_cancel_destroy(p->save_cancel);
109
110         if (p->ctx) {
111                 evas_object_del(p->ctx);
112         }
113
114         free(p);
115 }
116
117 static void __cal_edit_alarm_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
118 {
119         cal_edit_alarm_data *p;
120         Evas_Event_Mouse_Up *ev = ei;
121         int val = (int)data;
122
123         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
124                 return;
125
126         p = CAL_UTIL_GET_PRIV_DATA(obj);
127
128         cal_radio_group_select_radio(p->radio_group, val);
129 }
130
131 static void __cal_edit_alarm_set_custom(cal_edit_alarm_data *p)
132 {
133         elm_object_focus_set(p->e_custom, EINA_TRUE);
134         elm_entry_cursor_end_set(p->e_custom);
135 }
136
137 static inline void __cal_edit_alarm_set_button_label(cal_edit_alarm_data *p)
138 {
139         if (1 < p->reminder.alarm_value)
140                 elm_object_text_set(p->b_custom, _(cal_edit_alarm_button[p->bt_idx].plural_label));
141         else
142                 elm_object_text_set(p->b_custom, _(cal_edit_alarm_button[p->bt_idx].label));
143 }
144
145 static void __cal_edit_alarm_custom_popup_hide_callback(void *data, Evas_Object *obj, void *ei)
146 {
147         c_retm_if(!data, "data is null");
148         c_retm_if(!obj,  "obj is null");
149
150         cal_edit_alarm_data* p = data;
151         p->ctx = NULL;
152         evas_object_del(obj);
153 }
154
155 static void __cal_edit_create_ctx_popup(cal_edit_alarm_data* p)
156 {
157         c_retm_if(!p, "p is NULL.");
158
159         Evas_Object *ctx = p->ctx;
160
161         if (ctx)
162                 evas_object_del(ctx);
163
164         p->ctx = elm_ctxpopup_add(p->naviframe);
165         c_retm_if(!p->ctx, "elm_ctxpopup_add(p->ad->naviframe) returned null");
166         elm_object_focus_allow_set(p->ctx, EINA_FALSE);
167
168         ctx = p->ctx;
169         evas_object_data_set(ctx, "priv", p);
170
171         evas_object_smart_callback_add(ctx, "dismissed", __cal_edit_alarm_custom_popup_hide_callback, p);
172         elm_ctxpopup_item_append(ctx, S_("IDS_COM_BODY_MINUTE_LC"), NULL, __cal_edit_alarm_custom_ctx_selected_callback, (const void *)0);
173         elm_ctxpopup_item_append(ctx, S_("IDS_COM_POP_HOUR_LC"), NULL, __cal_edit_alarm_custom_ctx_selected_callback, (const void *)1);
174         elm_ctxpopup_item_append(ctx, C_("IDS_COM_POP_DAY_LC"), NULL, __cal_edit_alarm_custom_ctx_selected_callback, (const void *)2);
175         elm_ctxpopup_item_append(ctx, C_("IDS_COM_POP_WEEK_LC"), NULL, __cal_edit_alarm_custom_ctx_selected_callback, (const void *)3);
176 }
177
178 static void __cal_edit_alarm_custom_button_callback(void *data, Evas_Object *obj, void *ei)
179 {
180         cal_edit_alarm_data* p = data;
181         c_retm_if(!p, "p is null");
182
183         __cal_edit_create_ctx_popup(p);
184         c_retm_if(!p->ctx, "p is NULL.");
185         Evas_Coord x, y, w, h;
186         evas_object_geometry_get(p->b_custom, &x, &y, &w, &h);
187         evas_object_move(p->ctx, x+w/2, y);
188         evas_object_show(p->ctx);
189 }
190
191 static void __cal_edit_alarm_custom_ctx_selected_callback(void *data, Evas_Object *obj, void *ei)
192 {
193         cal_edit_alarm_data* p = CAL_UTIL_GET_PRIV_DATA(obj);
194         c_retm_if(!p, "p is NULL.");
195
196         int index = (int)data;
197         p->bt_idx = index;
198         __cal_edit_alarm_set_button_label(p);
199
200         __cal_edit_alarm_set_custom(p);
201         cal_radio_group_select_radio(p->radio_group, _GTYPE_CUSTOMIZE);
202         __cal_edit_alarm_custom_popup_hide_callback(p,p->ctx,ei);
203 }
204
205 static Evas_Object* __cal_edit_alarm_add_button(Evas_Object *parent, cal_edit_alarm_data *p)
206 {
207         Evas_Object *bt;
208
209         bt = elm_button_add(parent);
210         if (!bt)
211                 return NULL;
212
213         elm_object_focus_allow_set(bt, EINA_FALSE);
214         evas_object_propagate_events_set(bt, EINA_FALSE);
215         evas_object_smart_callback_add(bt, "clicked", __cal_edit_alarm_custom_button_callback, p);
216
217         return bt;
218 }
219
220 static char *__cal_edit_alarm_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
221 {
222         cal_edit_alarm_item_data *item_data = (cal_edit_alarm_item_data*)data;
223         int type = (int)item_data->type;
224         char buf[1024] = {0};
225
226         if (!CAL_STRCMP(part, "elm.text"))
227         {
228                 Cal_Reminder reminder;
229                 switch (type)
230                 {
231                 case _GTYPE_OFF:
232                         reminder.tick_unit = CALENDAR_ALARM_NONE;
233                         reminder.alarm_value = 0;
234                         cal_reminder_get_string(&reminder, buf, sizeof(buf));
235                         break;
236                 case _GTYPE_ON_TIME:
237                 case _GTYPE_5_MIN:
238                 case _GTYPE_15_MIN:
239                 case _GTYPE_1_HOUR:
240                 case _GTYPE_1_DAY:
241                 case _GTYPE_1_WEEK:
242                         reminder.tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
243                         reminder.alarm_value = item_data->data;
244                         cal_reminder_get_string(&reminder, buf, sizeof(buf));
245                         break;
246                 case _GTYPE_CUSTOMIZE:
247                         break;
248                 case _GTYPE_ON_A_DAY:
249                 default:
250                         // error
251                         break;
252                 }
253         }
254
255         return strdup(buf);
256 }
257
258 static char *__cal_edit_alarm_get_genlist_item_custom_label(void *data, Evas_Object *obj, const char *part)
259 {
260         return strdup(C_("IDS_CLD_BODY_BEFORE_LC"));
261 }
262
263 static void __cal_edit_alarm_genlist_item_delete_callback(void *data, Evas_Object *obj)
264 {
265         CAL_ASSERT(data);
266         cal_edit_alarm_item_data*item_data = (cal_edit_alarm_item_data*)data;
267
268         CAL_ASSERT(item_data->p);
269
270         free(item_data);
271 }
272
273 static Eina_Bool __cal_edit_alarm_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
274 {
275         return EINA_FALSE;
276 }
277
278 static Evas_Object* __cal_edit_alarm_add_radio(Evas_Object *dg, int val, cal_edit_alarm_data *p, cal_edit_alarm_item_data *item_data)
279 {
280         Evas_Object *rd;
281
282         rd = elm_radio_add(dg);
283         c_retvm_if(!rd, NULL, "rd is NULL");
284
285         elm_object_part_content_set(rd, "content", rd);
286         cal_radio_group_set_radio_object(p->radio_group, val, rd);
287
288         evas_object_show(rd);
289         evas_object_data_set(rd, "priv", p);
290         evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_alarm_clicked_callback, (void *)val);
291
292         return rd;
293 }
294
295 static void __cal_edit_alarm_entry_unfocused(void *data, Evas_Object *obj, void *event_info)
296 {
297         cal_edit_alarm_data *p = (cal_edit_alarm_data *)data;
298
299         char min[8] = {0,};
300         snprintf(min, 7, "%d", p->reminder.alarm_value);
301         elm_entry_entry_set(p->e_custom, min);
302 }
303
304 static Evas_Object* __cal_edit_alarm_add_entry(Evas_Object *parent, cal_edit_alarm_data *p, cal_edit_alarm_item_data *item_data)
305 {
306         Evas_Object *e;
307         Ecore_IMF_Context *ic;
308
309         e = elm_entry_add(parent);
310         if (!e)
311                 return NULL;
312
313         elm_object_style_set(e, "font_color_black");
314         elm_entry_single_line_set(e, EINA_TRUE);
315         elm_entry_markup_filter_append(e, elm_entry_filter_limit_size, &_limit_2char);
316         elm_entry_markup_filter_append(e, elm_entry_filter_accept_set, &_digit_only);
317         elm_entry_input_panel_layout_set(e, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
318         elm_entry_context_menu_disabled_set(e, EINA_TRUE);
319
320         ic = elm_entry_imf_context_get(e);
321         if (!ic)
322                 return NULL;
323
324         evas_object_smart_callback_add(e, "unfocused", __cal_edit_alarm_entry_unfocused, p);
325
326         elm_entry_text_style_user_push(e, "DEFAULT='align=center'");
327
328         return e;
329 }
330
331 static void __cal_edit_alarm_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
332 {
333         cal_edit_alarm_item_data *item_data = (cal_edit_alarm_item_data *)data;
334         cal_edit_alarm_data *p = item_data->p;
335         const char *s = elm_entry_entry_get(p->e_custom);
336         p->reminder.alarm_value = atoi(s);
337
338         __cal_edit_alarm_set_button_label(p);
339 }
340
341 static void __cal_edit_alarm_customize_radio_changed_cb(unsigned int index, bool selected, void* data)
342 {
343         cal_edit_alarm_data *p = (cal_edit_alarm_data*)data;
344         if (selected) {
345                 elm_object_focus_set(p->e_custom, EINA_TRUE);
346                 elm_entry_cursor_end_set(p->e_custom);
347         } else {
348                 elm_object_focus_set(p->e_custom, EINA_FALSE);
349         }
350 }
351
352 static Evas_Object* __cal_edit_alarm_get_genlist_item_custom_icon(void *data, Evas_Object *obj, const char *part)
353 {
354         c_retvm_if(!data, NULL, "data is null");
355         c_retvm_if(!obj, NULL, "obj is null");
356
357         cal_edit_alarm_item_data *item_data = (cal_edit_alarm_item_data*)data;
358         cal_edit_alarm_data *p = item_data->p;
359
360         if (!CAL_STRCMP(part, "radio")) {
361                 Evas_Object *rd = elm_radio_add(obj);
362                 c_retv_if(!rd, NULL);
363                 cal_radio_group_set_radio_object(p->radio_group, item_data->type, rd);
364                 cal_radio_group_set_changed_callback(p->radio_group, item_data->type, __cal_edit_alarm_customize_radio_changed_cb, p);
365                 return rd;
366         } else if (!CAL_STRCMP(part, "button")) {
367                 Evas_Object *bt = __cal_edit_alarm_add_button(obj, p);
368                 c_retv_if(!bt, NULL);
369                 elm_object_style_set(bt, "sweep");
370                 elm_object_part_content_set(obj, "", bt);
371                 p->b_custom = bt;
372                 __cal_edit_alarm_set_button_label(p);
373                 return bt;
374         } else if (!CAL_STRCMP(part, "input_sw")) {
375                 Evas_Object *entry = __cal_edit_alarm_add_entry(obj, p, item_data);
376                 c_retv_if(!entry, NULL);
377                 evas_object_smart_callback_add(entry, "changed", __cal_edit_alarm_entry_changed_callback, item_data);
378                 char buf[16];
379                 if (cal_radio_group_get_selected_radio(p->radio_group) == _GTYPE_CUSTOMIZE)
380                         snprintf(buf, sizeof(buf), "%d", p->reminder.alarm_value);
381                 else
382                         snprintf(buf, sizeof(buf), "%d", 0);
383                 elm_entry_entry_set(entry, buf);
384                 p->e_custom = entry;
385                 return entry;
386         } else {
387                 c_retvm_if(1, NULL, "part %s unattended for", part);
388         }
389         return NULL;
390 }
391
392 static Evas_Object *__cal_edit_alarm_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
393 {
394         c_retvm_if(!data, NULL, "data is null");
395         c_retvm_if(!obj, NULL, "obj is null");
396
397         Evas_Object *e_obj = NULL;
398         cal_edit_alarm_item_data *item_data = (cal_edit_alarm_item_data*)data;
399         cal_edit_alarm_data *p = item_data->p;
400
401         if (!CAL_STRCMP(part, "elm.icon")) {
402                 e_obj = __cal_edit_alarm_add_radio(obj, item_data->type, p, item_data);
403         }
404
405         return e_obj;
406 }
407
408 static void __cal_edit_alarm_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
409 {
410         CAL_FN_START;
411
412         cal_edit_alarm_item_data *item_data;
413         Elm_Object_Item *it = elm_genlist_selected_item_get(obj);
414
415         if (it)
416                 elm_genlist_item_selected_set(it, EINA_FALSE);
417
418         item_data = (cal_edit_alarm_item_data *)elm_object_item_data_get(it);
419
420         int type = item_data->type;
421         cal_edit_alarm_data *p = item_data->p;
422
423         switch ( type )
424         {
425         case _GTYPE_OFF:
426         case _GTYPE_ON_TIME:
427         case _GTYPE_5_MIN:
428         case _GTYPE_15_MIN:
429         case _GTYPE_1_HOUR:
430         case _GTYPE_1_DAY:
431         case _GTYPE_1_WEEK:
432         case _GTYPE_CUSTOMIZE:
433                 cal_radio_group_select_radio(p->radio_group, type);
434                 break;
435         default:
436                 break;
437         }
438
439         return;
440 }
441
442 static void __cal_edit_alarm_append_genlist_item_event(
443                                 Evas_Object *genlist, cal_edit_alarm_data *p, int type, int data)
444 {
445         cal_edit_alarm_item_data *item_data;
446         CAL_CALLOC(item_data, 1, cal_edit_alarm_item_data);
447
448         item_data->p = p;
449         item_data->type = type;
450         item_data->data = data;
451
452         if(_GTYPE_SPEA == type) {
453                 Elm_Object_Item *it = elm_genlist_item_append(genlist, &itc_seperator, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
454                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
455         } else {
456                 if(_GTYPE_CUSTOMIZE == item_data->type)
457                         elm_genlist_item_append(genlist, &itc_custom, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
458                 else
459                         elm_genlist_item_append(genlist, &itc_1text_1icon, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
460         }
461 }
462
463 static void __cal_edit_alarm_append_genlist_item_todo(Evas_Object *genlist, cal_edit_alarm_data *p, int type, int data)
464 {
465         cal_edit_alarm_item_data *item_data;
466         CAL_CALLOC(item_data, 1, cal_edit_alarm_item_data);
467
468         item_data->p = p;
469         item_data->type = type;
470         item_data->data = data;
471
472         if(_GTYPE_SPEA == item_data->type) {
473                 Elm_Object_Item *it = elm_genlist_item_append(genlist, &itc_seperator, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
474                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
475         } else {
476                 if(p->alarm_type == ALARM_TYPE_TODO_CUSTOM_ONLY) {
477                         if(_GTYPE_OFF == item_data->type)
478                                 elm_genlist_item_append(genlist, &itc_1text_1icon, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
479                         else
480                                 free(item_data);
481                 }
482                 else {
483                         if(_GTYPE_CUSTOMIZE == item_data->type)
484                                 elm_genlist_item_append(genlist, &itc_custom, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
485                         else if(_GTYPE_5_MIN == item_data->type || _GTYPE_15_MIN == item_data->type || _GTYPE_1_HOUR == item_data->type)
486                                 free(item_data);
487                         else
488                                 elm_genlist_item_append(genlist, &itc_1text_1icon, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_alarm_genlist_item_select_callback, NULL);
489                 }
490         }
491 }
492
493 static void __cal_edit_alarm_genlist_realized_callback(void *data, Evas_Object *obj, void *ei)
494 {
495         cal_edit_alarm_item_data *item_data = elm_object_item_data_get((Elm_Object_Item *)ei);
496         c_ret_if(!item_data);
497
498         if (item_data->type == _GTYPE_OFF) {
499                 elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,top", "");
500                 return;
501         }
502
503         cal_edit_alarm_data *p = item_data->p;
504
505         if (p && p->alarm_type == ALARM_TYPE_EVENT) {
506                 if (item_data->type == _GTYPE_CUSTOMIZE)
507                         elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,bottom", "");
508                 else
509                         elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,center", "");
510         } else {
511                 if (item_data->type == _GTYPE_ON_A_DAY)
512                         elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,bottom", "");
513                 else
514                         elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,center", "");
515         }
516 }
517
518 static int __cal_edit_alarm_add_alarm_content(cal_edit_alarm_data *p)
519 {
520         CAL_ASSERT(p);
521
522         p->sc = elm_genlist_add(p->ly);
523         CAL_ASSERT(p->sc);
524
525         evas_object_smart_callback_add(p->sc, "realized", __cal_edit_alarm_genlist_realized_callback, NULL);
526
527         itc_seperator.item_style = "dialogue/separator/21/with_line";
528         itc_seperator.func.text_get = NULL;
529         itc_seperator.func.state_get = __cal_edit_alarm_get_genlist_item_state;
530         itc_seperator.func.del = __cal_edit_alarm_genlist_item_delete_callback;
531
532         itc_1text_1icon.item_style = "dialogue/1text.1icon.2";
533         itc_1text_1icon.func.del = __cal_edit_alarm_genlist_item_delete_callback;
534         itc_1text_1icon.func.content_get = __cal_edit_alarm_get_genlist_item_icon;
535         itc_1text_1icon.func.text_get = __cal_edit_alarm_get_genlist_item_label;
536
537         itc_custom.item_style = "dialogue/3icon.1text.custom";
538         itc_custom.func.del = __cal_edit_alarm_genlist_item_delete_callback;
539         itc_custom.func.content_get = __cal_edit_alarm_get_genlist_item_custom_icon;
540         itc_custom.func.text_get = __cal_edit_alarm_get_genlist_item_custom_label;
541
542         if(p->alarm_type == ALARM_TYPE_EVENT) {
543                 p->radio_group = cal_radio_group_create(_GTYPE_MAX - 1, p->sc);
544                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_SPEA, 0);
545                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_OFF, -1);
546                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_ON_TIME, 0);
547                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_5_MIN, 5);
548                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_15_MIN, 15);
549                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_1_HOUR, _HOUR);
550                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_1_DAY, _DAY);
551                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_1_WEEK, _WEEK);
552                 __cal_edit_alarm_append_genlist_item_event(p->sc, p, _GTYPE_CUSTOMIZE, 0);
553         } else {
554                 p->radio_group = cal_radio_group_create(_GTYPE_MAX, p->sc);
555                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_SPEA, 0);
556                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_OFF, -1);
557                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_ON_TIME, 0);
558                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_5_MIN, 5);
559                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_15_MIN, 15);
560                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_1_HOUR, _HOUR);
561                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_1_DAY, _DAY);
562                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_1_WEEK, _WEEK);
563                 __cal_edit_alarm_append_genlist_item_todo(p->sc, p, _GTYPE_CUSTOMIZE, 0);
564                 p->on_a_day = cal_genlist_item_radio_timepicker_add(p->sc, p->radio_group, _GTYPE_ON_A_DAY,
565                                                 p->reminder.tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC, &p->reminder.datetime, p);
566         }
567
568         elm_object_part_content_set(p->ly, "sw", p->sc);
569
570         return 0;
571 }
572
573 static void __cal_edit_alarm_set_radio(cal_edit_alarm_data *p, const Cal_Reminder* reminder)
574 {
575         CAL_ASSERT(p);
576
577         p->reminder = *reminder;
578
579         switch(reminder->tick_unit)
580         {
581         case CALENDAR_ALARM_NONE:
582                 cal_radio_group_select_radio(p->radio_group, _GTYPE_OFF);
583                 return;
584         case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
585                 cal_radio_group_select_radio(p->radio_group, _GTYPE_ON_A_DAY);
586                 return;
587         case CALENDAR_ALARM_TIME_UNIT_MINUTE:
588                 break;
589         default:
590                 // error
591                 return;
592         }
593
594         switch(reminder->alarm_value)
595         {
596         case 0:
597                 cal_radio_group_select_radio(p->radio_group, _GTYPE_ON_TIME);
598                 return;
599         case 5:
600                 cal_radio_group_select_radio(p->radio_group, _GTYPE_5_MIN);
601                 return;
602         case 15:
603                 cal_radio_group_select_radio(p->radio_group, _GTYPE_15_MIN);
604                 return;
605         case _HOUR:
606                 cal_radio_group_select_radio(p->radio_group, _GTYPE_1_HOUR);
607                 return;
608         case _DAY:
609                 cal_radio_group_select_radio(p->radio_group, _GTYPE_1_DAY);
610                 return;
611         case _WEEK:
612                 cal_radio_group_select_radio(p->radio_group, _GTYPE_1_WEEK);
613                 return;
614         default:
615                 cal_radio_group_select_radio(p->radio_group, _GTYPE_CUSTOMIZE);
616                 break;
617         }
618
619         int min = reminder->alarm_value;
620
621         if ((min % _WEEK) == 0)
622         {
623                 p->bt_idx = 3;
624                 min = min / _WEEK;
625         }
626         else if ((min % _DAY) == 0)
627         {
628                 p->bt_idx = 2;
629                 min = min / _DAY;
630         }
631         else if ((min % _HOUR) == 0)
632         {
633                 p->bt_idx = 1;
634                 min = min / _HOUR;
635         }
636         else
637                 p->bt_idx = 0;
638
639         p->reminder.alarm_value = min;
640 }
641
642 static void __cal_edit_alarm_save_button_callback(void *data, Evas_Object *obj, void *event_info)
643 {
644         CAL_FN_START;
645
646         cal_edit_alarm_data *p = data;
647
648         if (p->alarm_changed_callback) {
649
650                 int selected = cal_radio_group_get_selected_radio(p->radio_group);
651
652                 p->reminder.tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
653                 switch (selected) {
654                 case _GTYPE_OFF:
655                         p->reminder.tick_unit = CALENDAR_ALARM_NONE;
656                         break;
657                 case _GTYPE_ON_TIME:
658                         p->reminder.alarm_value = 0;
659                         break;
660                 case _GTYPE_5_MIN:
661                         p->reminder.alarm_value = 5;
662                         break;
663                 case _GTYPE_15_MIN:
664                         p->reminder.alarm_value = 15;
665                         break;
666                 case _GTYPE_1_HOUR:
667                         p->reminder.alarm_value = _HOUR;
668                         break;
669                 case _GTYPE_1_DAY:
670                         p->reminder.alarm_value = _DAY;
671                         break;
672                 case _GTYPE_1_WEEK:
673                         p->reminder.alarm_value = _WEEK;
674                         break;
675                 case _GTYPE_ON_A_DAY:
676                         p->reminder.tick_unit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
677                         cal_genlist_item_radio_timepicker_get_time(p->on_a_day, &p->reminder.datetime);
678                         break;
679                 case _GTYPE_CUSTOMIZE:
680                         p->reminder.alarm_value *= cal_edit_alarm_button[p->bt_idx].unit;
681                         break;
682                 default:
683                         // error
684                         break;
685                 }
686
687                 p->alarm_changed_callback(&p->reminder, p->alarm_changed_callback_data);
688         }
689         elm_naviframe_item_pop(p->naviframe);
690 }
691
692 static void __cal_edit_alarm_cancel_button_callback(void *data, Evas_Object *obj, void *event_info)
693 {
694         CAL_FN_START;
695
696         c_retm_if(!data, "data is null");
697
698         cal_edit_alarm_data *p = data;
699
700         Ecore_IMF_Context *imf_context = elm_entry_imf_context_get((Evas_Object *)p->e_custom);
701         c_retm_if(!imf_context, "elm_entry_imf_context_get returned null");
702
703         Ecore_IMF_Input_Panel_State state = ecore_imf_context_input_panel_state_get(imf_context);
704
705         if(state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)   {
706                 ecore_imf_context_input_panel_hide(imf_context);
707         }
708         else
709                 elm_naviframe_item_pop(p->naviframe);
710
711 }
712
713 Evas_Object *cal_edit_alarm_create_view(Evas_Object *window, Evas_Object *conformant, Evas_Object *naviframe,
714         const Cal_Reminder* reminder, cal_edit_alarm_type alarm_type, cal_edit_alarm_changed_callback alarm_changed_callback, void* callback_data)
715 {
716         c_retv_if(!window, NULL);
717         c_retv_if(!conformant, NULL);
718         c_retv_if(!naviframe, NULL);
719
720         cal_edit_alarm_data *p;
721         Evas_Object *ly;
722         int r;
723
724         p = calloc(1, sizeof(cal_edit_alarm_data));
725         c_retvm_if(!p, NULL, "p is null");
726
727         p->window = window;
728         p->conformant = conformant;
729         p->naviframe = naviframe;
730         p->alarm_changed_callback = alarm_changed_callback;
731         p->alarm_changed_callback_data = callback_data;
732         p->alarm_type = alarm_type;
733
734         ly = cal_util_add_layout(naviframe, "edit");
735         if (!ly) {
736                 free(p);
737                 return NULL;
738         }
739         p->ly = ly;
740
741         evas_object_data_set(ly, "priv", p);
742
743         Elm_Object_Item* navi_item = elm_naviframe_item_push(p->naviframe, C_("IDS_CLD_BODY_REMINDER"), NULL, NULL, ly, NULL);
744         c_retv_if(!navi_item, NULL);
745
746         p->save_cancel = cal_save_cancel_create(p->window, p->conformant, p->naviframe,
747                                         __cal_edit_alarm_save_button_callback,
748                                         __cal_edit_alarm_cancel_button_callback, p);
749
750         cal_edit_alarm_button[0].plural_label = C_("IDS_TMR_BODY_MINS_LC_ABB");
751         cal_edit_alarm_button[1].plural_label = C_("IDS_CHATON_BODY_HOURS_LC_ABB");
752         cal_edit_alarm_button[2].plural_label = C_("IDS_CHATON_BODY_DAYS_LC_ABB");
753         cal_edit_alarm_button[3].plural_label = C_("IDS_COM_POP_WEEKS_LC");
754
755         cal_edit_alarm_button[0].label = C_("IDS_TMR_OPT_MIN_LC_ABB");
756         cal_edit_alarm_button[1].label = C_("IDS_CLD_BODY_HOUR_LC_ABB");
757         cal_edit_alarm_button[2].label = C_("IDS_CLD_BODY_DAY_LC_ABB");
758         cal_edit_alarm_button[3].label = C_("IDS_CLD_BODY_WEEK_LC_ABB");
759
760         r = __cal_edit_alarm_add_alarm_content(p);
761         if (r) {
762                 evas_object_del(ly);
763                 free(p);
764                 return NULL;
765         }
766
767         __cal_edit_alarm_set_radio(p, reminder);
768
769         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_edit_alarm_delete_layout, p);
770
771         return ly;
772 }