Remove SMACK rule file(.rule) according three domain model
[apps/core/preloaded/calendar.git] / ug / edit / edit-repeat.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-repeat.h"
20 #include "radio-group.h"
21 #include "save-cancel.h"
22
23 enum __cal_edit_repeat_freq {
24         CAL_EDIT_REPEAT_FREQ_OFF = 0,
25         CAL_EDIT_REPEAT_FREQ_EVERY_DAY,
26         CAL_EDIT_REPEAT_FREQ_EVERY_3_DAY,
27         CAL_EDIT_REPEAT_FREQ_EVERY_WEEK,
28         CAL_EDIT_REPEAT_FREQ_EVERY_2_WEEK,
29         CAL_EDIT_REPEAT_FREQ_EVERY_MONTH,
30         CAL_EDIT_REPEAT_FREQ_EVERY_YEAR,
31         CAL_EDIT_REPEAT_FREQ_MAX
32 };
33
34 typedef struct {
35         Evas_Object *window;
36         Evas_Object *conformant;
37         Evas_Object *naviframe;
38         Evas_Object *ly; // self
39         Evas_Object *genlist;
40
41         cal_radio_group_h freq_radio_group;
42         cal_radio_group_h range_radio_group;
43
44         Evas_Object *day_selector;
45         Evas_Object *repeat_occurrence_entry;
46         Evas_Object *end_date;
47
48         struct tm *start_date_time;
49
50         int count;
51         struct tm until;
52
53         int selected_freq_radio;
54         int prev_selected_freq_radio;
55         int selected_range_radio;
56
57         cal_edit_repeat_destroy_callback callback_func;
58         void *callback_data;
59
60         cal_save_cancel_h save_cancel;
61
62 } cal_edit_repeat_data;
63
64 static int __cal_edit_repeat_get_radio_index(int freq)
65 {
66         switch (freq) {
67         case CALENDAR_RECURRENCE_NONE:
68                 return CAL_EDIT_REPEAT_FREQ_OFF;
69         case CALENDAR_RECURRENCE_DAILY:
70                 return CAL_EDIT_REPEAT_FREQ_EVERY_DAY;
71         case CAL_REPEAT_EVERY_3_DAY:
72                 return CAL_EDIT_REPEAT_FREQ_EVERY_3_DAY;
73         case CALENDAR_RECURRENCE_WEEKLY:
74                 return CAL_EDIT_REPEAT_FREQ_EVERY_WEEK;
75         case CAL_REPEAT_EVERY_2_WEEK:
76                 return CAL_EDIT_REPEAT_FREQ_EVERY_2_WEEK;
77         case CALENDAR_RECURRENCE_MONTHLY:
78                 return CAL_EDIT_REPEAT_FREQ_EVERY_MONTH;
79         case CALENDAR_RECURRENCE_YEARLY:
80                 return CAL_EDIT_REPEAT_FREQ_EVERY_YEAR;
81         default:
82                 ERR("Invalid value : %d", freq);
83                 return 0;
84         }
85 }
86
87 static int __cal_edit_repeat_get_freq(int radio_index)
88 {
89         switch (radio_index) {
90         case CAL_EDIT_REPEAT_FREQ_OFF:
91                 return CALENDAR_RECURRENCE_NONE;
92         case CAL_EDIT_REPEAT_FREQ_EVERY_DAY:
93                 return CALENDAR_RECURRENCE_DAILY;
94         case CAL_EDIT_REPEAT_FREQ_EVERY_3_DAY:
95                 return CAL_REPEAT_EVERY_3_DAY;
96         case CAL_EDIT_REPEAT_FREQ_EVERY_WEEK:
97                 return CALENDAR_RECURRENCE_WEEKLY;
98         case CAL_EDIT_REPEAT_FREQ_EVERY_2_WEEK:
99                 return CAL_REPEAT_EVERY_2_WEEK;
100         case CAL_EDIT_REPEAT_FREQ_EVERY_MONTH:
101                 return CALENDAR_RECURRENCE_MONTHLY;
102         case CAL_EDIT_REPEAT_FREQ_EVERY_YEAR:
103                 return CALENDAR_RECURRENCE_YEARLY;
104         default:
105                 ERR("Invalid value : %d", radio_index);
106                 return CALENDAR_RECURRENCE_NONE;
107         }
108 }
109
110 static int __cal_edit_repeat_range_index[] = {
111         CALENDAR_RANGE_NONE,
112         CALENDAR_RANGE_COUNT,
113         CALENDAR_RANGE_UNTIL,
114 };
115
116 typedef enum {
117         CAL_EDIT_REPEAT_SEPARATOR_FREQ,
118         CAL_EDIT_REPEAT_ITEM_FREQ,
119         CAL_EDIT_REPEAT_SEPARATOR_RANGE,
120         CAL_EDIT_REPEAT_ITEM_RANGE,
121 }cal_edit_repeat_item_type;
122
123 static Elm_Entry_Filter_Limit_Size _limit_2char = {
124         .max_char_count = 2,
125 };
126 static Elm_Entry_Filter_Accept_Set _digit_only = {
127         .accepted = "0123456789",
128 };
129
130 static Elm_Genlist_Item_Class itc_seperator, itc_1icon_1text, itc_1icon, itc_2icon_1text;
131
132 typedef struct __cal_edit_repeat_item_data cal_edit_repeat_item_data;
133 struct __cal_edit_repeat_item_data
134 {
135         cal_edit_repeat_data *p;
136         int index;
137         cal_edit_repeat_item_type type;
138         Elm_Object_Item *it;
139         Evas_Object *radio;
140 };
141
142 #define is_leap_year_tm(y)  (((y+1900)%4 == 0 && ((y+1900)%100 != 0 || (y+1900)%400 == 0))? 1 : 0)
143
144 static void __cal_edit_repeat_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
145 {
146         CAL_FN_START;
147
148         cal_edit_repeat_data *p = data;
149
150         cal_radio_group_destroy(p->freq_radio_group);
151         cal_radio_group_destroy(p->range_radio_group);
152
153         if (p->save_cancel)
154                 cal_save_cancel_destroy(p->save_cancel);
155
156         free(p);
157 }
158
159 static void __cal_edit_repeat_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
160 {
161         cal_edit_repeat_data *p;
162         Evas_Event_Mouse_Up *ev = ei;
163         int val = (int)data;
164
165         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
166                 return;
167
168         p = CAL_UTIL_GET_PRIV_DATA(obj);
169         cal_radio_group_select_radio(p->freq_radio_group, val);
170         p->prev_selected_freq_radio = p->selected_freq_radio;
171         p->selected_freq_radio = val;
172 }
173
174 static void __cal_edit_repeat_entry_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
175 {
176         c_ret_if(!ei);
177         c_ret_if(!data);
178
179         Evas_Event_Mouse_Up *ev = ei;
180         int val = (int)data;
181
182         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
183                 return;
184
185         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
186         cal_radio_group_select_radio(p->range_radio_group, val);
187
188         if (CALENDAR_RANGE_COUNT == val) {
189                 elm_object_focus_set(p->repeat_occurrence_entry, EINA_TRUE);
190                 elm_entry_cursor_end_set(p->repeat_occurrence_entry);
191         }
192
193         p->selected_range_radio = val;
194
195         const char* str = elm_entry_entry_get(p->repeat_occurrence_entry);
196         c_ret_if(!CAL_STRLEN(str));
197
198         p->count = atoi(str);
199 }
200
201 int cal_edit_repeat_get_repeat(Evas_Object *ly, calendar_range_type_e *range, struct tm *until, int *count)
202 {
203         c_retvm_if(!ly, CALENDAR_RECURRENCE_NONE, "ly is null");
204
205         const char* text = NULL;
206
207         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
208         c_retvm_if(!p, CALENDAR_RECURRENCE_NONE, "p is null");
209
210         c_retvm_if(!p->freq_radio_group, CALENDAR_RECURRENCE_NONE, "p->freq_radio_group is null");
211         c_retvm_if(!p->range_radio_group, CALENDAR_RECURRENCE_NONE, "p->range_radio_group is null");
212
213         *range = __cal_edit_repeat_range_index[p->selected_range_radio];
214
215         switch (*range) {
216                 case CALENDAR_RANGE_NONE:
217                         *count = 10;
218
219                         *until = *p->start_date_time;
220                         cal_util_update_tm_month(until, 1);
221                         break;
222
223                 case CALENDAR_RANGE_COUNT:
224                         text = elm_entry_entry_get(p->repeat_occurrence_entry);
225                         c_retvm_if(!text, CALENDAR_RECURRENCE_NONE, "text is null");
226
227                         *count = atoi(text);
228
229                         *until = *p->start_date_time;
230                         cal_util_update_tm_month(until, 1);
231
232                         break;
233
234                 case CALENDAR_RANGE_UNTIL:
235                         *count = 10;
236
237                         *until = p->until;
238                         break;
239
240                 default:
241                         break;
242         }
243
244         return __cal_edit_repeat_get_freq(p->selected_freq_radio);
245 }
246
247 void _cal_edit_repeat_get_freq_str(int freq, char *buf, int size)
248 {
249         c_ret_if(!buf);
250
251         char *format = NULL;
252
253         switch (freq) {
254
255                 case CALENDAR_RECURRENCE_DAILY:
256
257                         snprintf(buf, size, "%s", C_("IDS_KC_BODY_EVERY_DAY"));
258                         break;
259
260                 case CAL_REPEAT_EVERY_3_DAY:
261
262                         format = C_("IDS_CLD_BODY_EVERY_PD_DAYS");
263                         snprintf(buf, size, format, 3);
264                         break;
265
266                 case CALENDAR_RECURRENCE_WEEKLY:
267
268                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_WEEK"));
269                         break;
270
271                 case CAL_REPEAT_EVERY_2_WEEK:
272
273                         format = C_("IDS_CLD_BODY_EVERY_PD_WEEKS");
274                         snprintf(buf, size, format, 2);
275                         break;
276
277                 case CALENDAR_RECURRENCE_MONTHLY:
278
279                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_MONTH"));
280                         break;
281
282                 case CALENDAR_RECURRENCE_YEARLY:
283
284                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_YEAR"));
285                         break;
286
287                 default:
288
289                         snprintf(buf, size, "%s", S_("IDS_COM_BODY_OFF"));
290                         break;
291
292         }
293
294         buf[size-1] = '\0';
295 }
296
297 static char *__cal_edit_repeat_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
298 {
299         CAL_FN_START;
300
301         c_retv_if(!data, NULL);
302
303         cal_edit_repeat_item_data *item_data = data;
304
305         char string[32] = {0};
306
307         if (!CAL_STRCMP(part, "elm.text")) {
308                 switch (item_data->type) {
309                         case CAL_EDIT_REPEAT_SEPARATOR_FREQ:
310                                 return strdup(C_("IDS_CLD_BODY_REPEAT"));
311
312                         case CAL_EDIT_REPEAT_ITEM_FREQ:
313                                 _cal_edit_repeat_get_freq_str(__cal_edit_repeat_get_freq(item_data->index), string, sizeof(string));
314                                 return strdup(string);
315
316                         case CAL_EDIT_REPEAT_SEPARATOR_RANGE:
317                                 return strdup(C_("IDS_CLD_BODY_REPEAT_UNTIL"));
318
319                         case CAL_EDIT_REPEAT_ITEM_RANGE:
320                                 if (__cal_edit_repeat_range_index[item_data->index] == CALENDAR_RANGE_NONE)
321                                         return strdup(S_("IDS_COM_BODY_NONE"));
322
323                         default:
324                                 return NULL;
325                 }
326         } else if (!CAL_STRCMP(part, "text")) {
327                 return strdup(C_("IDS_COM_POP_TIMES_LC"));
328         }
329
330         return NULL;
331 }
332
333 static void __cal_edit_repeat_genlist_item_delete_callback(void *data, Evas_Object *obj)
334 {
335         CAL_FN_START;
336
337         c_ret_if(!data);
338         cal_edit_repeat_item_data *item_data = data;
339
340         free(item_data);
341 }
342
343 static Eina_Bool __cal_edit_repeat_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
344 {
345         return EINA_FALSE;
346 }
347
348 static Evas_Object* __cal_edit_repeat_add_radio(Evas_Object *obj, cal_edit_repeat_item_data *item_data)
349 {
350         c_retvm_if(!obj, NULL, "dg is NULL.");
351         c_retvm_if(!item_data, NULL, "item_data is NULL.");
352
353         cal_edit_repeat_data *p = item_data->p;
354         c_retv_if(!p, NULL);
355
356         Evas_Object *rd = elm_radio_add(obj);
357         c_retv_if(!rd, NULL);
358
359         evas_object_propagate_events_set(rd, EINA_TRUE);
360
361         cal_edit_repeat_item_type type = item_data->type;
362
363         if (type == CAL_EDIT_REPEAT_ITEM_FREQ)
364                 cal_radio_group_set_radio_object(p->freq_radio_group, item_data->index, rd);
365         else if (type == CAL_EDIT_REPEAT_ITEM_RANGE)
366                 cal_radio_group_set_radio_object(p->range_radio_group, item_data->index, rd);
367
368         item_data->radio = rd;
369
370         evas_object_show(rd);
371         evas_object_data_set(rd, "priv", p);
372
373         if (item_data->type == CAL_EDIT_REPEAT_ITEM_FREQ)
374                 evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_clicked_callback, (void *)item_data->index);
375         else if (0 == item_data->index || 1 == item_data->index)
376                         evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_entry_clicked_callback, (void *)item_data->index);
377
378         return rd;
379 }
380
381 static void __cal_edit_repeat_entry_unfocused(void *data, Evas_Object *obj, void *event_info)
382 {
383         cal_edit_repeat_data *p = (cal_edit_repeat_data *)data;
384
385         char times[8] = {0,};
386         snprintf(times, 7, "%d", p->count);
387         elm_entry_entry_set(p->repeat_occurrence_entry, times);
388
389 }
390
391 static void __cal_edit_repeat_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
392 {
393         CAL_ASSERT(data);
394         cal_edit_repeat_data *p = data;
395
396         const char *s = elm_entry_entry_get(p->repeat_occurrence_entry);
397         if (s != NULL)
398                 p->count = atoi(s);
399 }
400
401 static Evas_Object* __cal_edit_repeat_add_entry(Evas_Object *parent, cal_edit_repeat_data *p)
402 {
403         Evas_Object *e;
404         Ecore_IMF_Context *ic;
405
406         e = elm_entry_add(parent);
407         if (!e)
408                 return NULL;
409
410         elm_object_style_set(e, "font_color_black");
411         elm_entry_single_line_set(e, EINA_TRUE);
412         elm_entry_markup_filter_append(e, elm_entry_filter_limit_size, &_limit_2char);
413         elm_entry_markup_filter_append(e, elm_entry_filter_accept_set, &_digit_only);
414         elm_entry_input_panel_layout_set(e, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
415         elm_entry_context_menu_disabled_set(e, EINA_TRUE);
416
417         ic = elm_entry_imf_context_get(e);
418         if (!ic)
419                 return NULL;
420
421         evas_object_smart_callback_add(e, "unfocused", __cal_edit_repeat_entry_unfocused, p);
422         evas_object_smart_callback_add(e, "changed", __cal_edit_repeat_entry_changed_callback, p);
423
424         elm_entry_text_style_user_push(e, "DEFAULT='align=center'");
425
426         return e;
427 }
428
429 static void __cal_edit_repeat_end_date_changed_callback(void *data, Evas_Object *obj, void *ei)
430 {
431         cal_edit_repeat_data *p = data;
432
433         elm_datetime_value_get(obj, &p->until);
434 }
435
436 static Evas_Object* __cal_edit_repeat_add_radio_tm(Evas_Object *obj, cal_edit_repeat_item_data *item_data)
437 {
438         c_retv_if(!obj, NULL);
439         c_retv_if(!item_data, NULL);
440
441         cal_edit_repeat_data *p = item_data->p;
442         c_retv_if(!p, NULL);
443
444         Evas_Object *ly = cal_util_add_layout(obj, "dialoguegroup/tm");
445         c_retvm_if(!ly, NULL, "ly is null");
446
447         evas_object_show(ly);
448         evas_object_data_set(ly, "priv", p);
449
450         Evas_Object *rd = elm_radio_add(obj);
451         if (!rd) {
452                 evas_object_del(ly);
453                 return NULL;
454         }
455
456         evas_object_propagate_events_set(rd, EINA_TRUE);
457
458         elm_object_part_content_set(ly, "content", rd);
459         item_data->radio = rd;
460
461         cal_radio_group_set_radio_object(p->range_radio_group, item_data->index, rd);
462
463         Evas_Object *datetime = cal_util_add_datetime(ly, NULL, &p->until);
464         c_retvm_if(!datetime, NULL, "datetime is null");
465
466         evas_object_propagate_events_set(datetime, EINA_TRUE);
467
468         elm_datetime_field_visible_set(datetime, ELM_DATETIME_HOUR, EINA_FALSE);
469         elm_datetime_field_visible_set(datetime, ELM_DATETIME_MINUTE, EINA_FALSE);
470         elm_datetime_field_visible_set(datetime, ELM_DATETIME_AMPM, EINA_FALSE);
471
472         elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 137);
473
474         evas_object_smart_callback_add(datetime,"changed", __cal_edit_repeat_end_date_changed_callback, p);
475
476         elm_object_part_content_set(ly, "datefield", datetime);
477
478         return ly;
479 }
480
481 static Evas_Object* __cal_edit_repeat_add_radio_group(Evas_Object *obj, cal_edit_repeat_item_data *item_data)
482 {
483         CAL_FN_START;
484
485         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
486         c_retv_if(!p, NULL);
487
488         if (item_data->type == CAL_EDIT_REPEAT_ITEM_FREQ) {
489
490                 return __cal_edit_repeat_add_radio(obj,  item_data);
491
492         } else if (item_data->type == CAL_EDIT_REPEAT_ITEM_RANGE){
493
494                 switch (__cal_edit_repeat_range_index[item_data->index]) {
495
496                 case CALENDAR_RANGE_NONE:
497                         return __cal_edit_repeat_add_radio(obj, item_data);
498
499                 case CALENDAR_RANGE_UNTIL:
500                         return __cal_edit_repeat_add_radio_tm(obj, item_data);
501
502                 default:
503                         return NULL;
504                 }
505         } else {
506
507                 ERR("Error!!");
508
509                 return NULL;
510         }
511
512         CAL_FN_END;
513 }
514
515 static void __cal_edit_repeat_set_selected_freq_state(cal_edit_repeat_data *p)
516 {
517         cal_radio_group_select_radio(p->freq_radio_group, p->selected_freq_radio);
518 }
519
520 static void __cal_edit_repeat_set_selected_range_state(cal_edit_repeat_data *p)
521 {
522         CAL_FN_START;
523
524         c_ret_if(!p);
525
526         char times[10] = {0};
527
528         snprintf(times,sizeof(times),"%d", p->count);
529         elm_entry_entry_set(p->repeat_occurrence_entry, times);
530         cal_radio_group_select_radio(p->range_radio_group, p->selected_range_radio);
531
532         CAL_FN_END;
533 }
534
535 static Evas_Object *__cal_edit_repeat_get_genlist_times_content(void *data, Evas_Object *obj, const char *part)
536 {
537         c_retv_if(!data, NULL);
538         c_retv_if(!obj, NULL);
539         c_retv_if(!part, NULL);
540
541         cal_edit_repeat_item_data *item_data = data;
542
543         cal_edit_repeat_data *p = item_data->p;
544         c_retv_if(!p, NULL);
545
546         if (!CAL_STRCMP(part, "radio")) {
547
548                 Evas_Object* radio = elm_radio_add(obj);
549                 c_retv_if(!radio, NULL);
550
551                 if (item_data->type == CAL_EDIT_REPEAT_ITEM_FREQ)
552                         cal_radio_group_set_radio_object(p->freq_radio_group, item_data->index, radio);
553                 else if (item_data->type == CAL_EDIT_REPEAT_ITEM_RANGE)
554                         cal_radio_group_set_radio_object(p->range_radio_group, item_data->index, radio);
555
556                 item_data->radio = radio;
557                 return radio;
558
559         } else if (!CAL_STRCMP(part, "input_sw")) {
560
561                 Evas_Object* entry = __cal_edit_repeat_add_entry(obj, p);
562                 c_retv_if(!entry, NULL);
563
564                 char times[8] = {0};
565                 snprintf(times, sizeof(times), "%d", p->count);
566                 elm_entry_entry_set(entry, times);
567
568                 p->repeat_occurrence_entry = entry;
569                 return entry;
570         }
571
572         return NULL;
573 }
574
575 static Evas_Object *__cal_edit_repeat_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
576 {
577         CAL_FN_START;
578
579         c_retv_if(!data, NULL);
580         c_retv_if(!obj, NULL);
581
582         Evas_Object *e_obj = NULL;
583
584         if (!CAL_STRCMP(part, "elm.icon")) {
585                 cal_edit_repeat_item_data *item_data = data;
586
587                 cal_edit_repeat_data *p = item_data->p;
588                 cal_edit_repeat_item_type type = item_data->type;
589
590                 if (type == CAL_EDIT_REPEAT_ITEM_FREQ) {
591
592                         e_obj = __cal_edit_repeat_add_radio_group(obj, item_data);
593
594                         __cal_edit_repeat_set_selected_freq_state(p);
595
596                 } else if (type == CAL_EDIT_REPEAT_ITEM_RANGE){
597
598                         e_obj = __cal_edit_repeat_add_radio_group(obj, item_data);
599
600                         __cal_edit_repeat_set_selected_range_state(p);
601
602                 } else {
603
604                         ERR("!Error");
605
606                         return NULL;
607                 }
608         }
609
610         CAL_FN_END;
611
612         return e_obj;
613
614 }
615
616 static void __cal_edit_repeat_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
617 {
618         CAL_FN_START;
619
620         c_ret_if(!obj);
621
622         Elm_Object_Item *it = elm_genlist_selected_item_get(obj);
623         c_ret_if(!it);
624
625         elm_genlist_item_selected_set(it, EINA_FALSE);
626
627         cal_edit_repeat_item_data *item_data = elm_object_item_data_get(it);
628         c_ret_if(!item_data);
629
630         cal_edit_repeat_data *p = item_data->p;
631         c_ret_if(!p);
632
633         cal_edit_repeat_item_type type = item_data->type;
634         int index = item_data->index;
635
636         if (type == CAL_EDIT_REPEAT_ITEM_FREQ) {
637
638                 p->selected_freq_radio = index;
639                 cal_radio_group_select_radio(p->freq_radio_group, index);
640                 elm_object_focus_set(p->repeat_occurrence_entry, EINA_FALSE);
641
642         } else if (type == CAL_EDIT_REPEAT_ITEM_RANGE){
643
644                 cal_radio_group_select_radio(p->range_radio_group, index);
645                 p->selected_range_radio = index;
646
647                 if (index != __cal_edit_repeat_range_index[CALENDAR_RANGE_COUNT])
648                         elm_object_focus_set(p->repeat_occurrence_entry, EINA_FALSE);
649         } else {
650
651                 ERR("Error!!");
652
653                 return;
654         }
655
656         CAL_FN_END;
657 }
658
659 static void __cal_edit_repeat_add_separator(Evas_Object *genlist, cal_edit_repeat_data *p, cal_edit_repeat_item_type type)
660 {
661         CAL_FN_START;
662
663         cal_edit_repeat_item_data *item_data = calloc(1, sizeof(cal_edit_repeat_item_data));
664         c_ret_if(!item_data);
665
666         item_data->type = type;
667         item_data->p = p;
668
669         item_data->it = elm_genlist_item_append(genlist, &itc_seperator, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_repeat_genlist_item_select_callback, NULL);
670
671         elm_genlist_item_select_mode_set(item_data->it, ELM_OBJECT_SELECT_MODE_NONE);
672
673         CAL_FN_END;
674 }
675
676 static void __cal_edit_repeat_add_freq(Evas_Object *genlist, cal_edit_repeat_data *p)
677 {
678         CAL_FN_START;
679
680         int i;
681         for (i = 0; i < CAL_EDIT_REPEAT_FREQ_MAX; i++) {
682                 cal_edit_repeat_item_data *item_data = calloc(1, sizeof(cal_edit_repeat_item_data));
683                 c_ret_if(!item_data);
684
685                 item_data->p = p;
686                 item_data->index = i;
687                 item_data->type = CAL_EDIT_REPEAT_ITEM_FREQ;
688
689                 item_data->it = elm_genlist_item_append(genlist, &itc_1icon_1text, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_repeat_genlist_item_select_callback, item_data);
690         }
691
692         CAL_FN_END;
693 }
694
695 static void __cal_edit_repeat_add_range(Evas_Object *genlist, cal_edit_repeat_data *p)
696 {
697         CAL_FN_START;
698
699         int i;
700         for (i = 0; i < sizeof(__cal_edit_repeat_range_index)/sizeof(__cal_edit_repeat_range_index[0]); i++) {
701                 cal_edit_repeat_item_data *item_data = calloc(1, sizeof(cal_edit_repeat_item_data));
702                 c_ret_if(!item_data);
703
704                 item_data->p = p;
705                 item_data->index = i;
706                 item_data->type = CAL_EDIT_REPEAT_ITEM_RANGE;
707
708                 if (__cal_edit_repeat_range_index[item_data->index] == CALENDAR_RANGE_COUNT)
709                         item_data->it = elm_genlist_item_append(genlist, &itc_2icon_1text, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_repeat_genlist_item_select_callback, item_data);
710                 else
711                         item_data->it = elm_genlist_item_append(genlist, &itc_1icon_1text, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_repeat_genlist_item_select_callback, item_data);
712         }
713
714         CAL_FN_END;
715 }
716
717 static void __cal_edit_repeat_add_genlist_item(Evas_Object *genlist, cal_edit_repeat_data *p)
718 {
719         CAL_FN_START;
720
721         __cal_edit_repeat_add_separator(genlist, p, CAL_EDIT_REPEAT_SEPARATOR_FREQ);
722
723         __cal_edit_repeat_add_freq(genlist, p);
724
725         __cal_edit_repeat_add_separator(genlist, p, CAL_EDIT_REPEAT_SEPARATOR_RANGE);
726
727         __cal_edit_repeat_add_range(genlist, p);
728
729         CAL_FN_END;
730 }
731
732 static int __cal_edit_repeat_add_content(cal_edit_repeat_data *p)
733 {
734         CAL_FN_START;
735
736         p->genlist = elm_genlist_add(p->ly);
737         c_retv_if(!p->genlist, -1);
738
739         evas_object_data_set(p->genlist, "priv", p);
740
741         itc_seperator.item_style = "dialogue/title";
742         itc_seperator.func.text_get = __cal_edit_repeat_get_genlist_item_label;
743         itc_seperator.func.state_get = __cal_edit_repeat_get_genlist_item_state;
744         itc_seperator.func.del = __cal_edit_repeat_genlist_item_delete_callback;
745
746         itc_1icon_1text.item_style = "dialogue/1text.1icon.2";
747         itc_1icon_1text.func.text_get = __cal_edit_repeat_get_genlist_item_label;
748         itc_1icon_1text.func.del = __cal_edit_repeat_genlist_item_delete_callback;
749         itc_1icon_1text.func.content_get = __cal_edit_repeat_get_genlist_item_icon;
750
751         itc_2icon_1text.item_style = "dialogue/2icon.1text.custom";
752         itc_2icon_1text.func.text_get = __cal_edit_repeat_get_genlist_item_label;
753         itc_2icon_1text.func.del = __cal_edit_repeat_genlist_item_delete_callback;
754         itc_2icon_1text.func.content_get = __cal_edit_repeat_get_genlist_times_content;
755
756         itc_1icon.item_style = "dialogue/1icon";
757         itc_1icon.func.text_get = __cal_edit_repeat_get_genlist_item_label;
758         itc_1icon.func.del = __cal_edit_repeat_genlist_item_delete_callback;
759         itc_1icon.func.content_get = __cal_edit_repeat_get_genlist_item_icon;
760
761         __cal_edit_repeat_add_genlist_item(p->genlist, p);
762
763         elm_object_part_content_set(p->ly, "sw", p->genlist);
764
765         CAL_FN_END;
766
767         return 0;
768 }
769
770 static void __cal_edit_repeat_set_state(cal_edit_repeat_data *p, int freq, calendar_range_type_e range, struct tm* until, int* occurrency)
771 {
772         p->selected_freq_radio = __cal_edit_repeat_get_radio_index(freq);
773         p->prev_selected_freq_radio = __cal_edit_repeat_get_radio_index(freq);
774         p->selected_range_radio = __cal_edit_repeat_range_index[range];
775 }
776
777 static void __cal_edit_repeat_save_button_callback(void *data, Evas_Object *obj, void *ei)
778 {
779         CAL_FN_START;
780
781         c_retm_if(!data, "data is null");
782
783         cal_edit_repeat_data *p = data;
784
785         p->callback_func(p->callback_data);
786         elm_naviframe_item_pop(p->naviframe);
787 }
788
789 static void __cal_edit_repeat_cancel_button_callback(void *data, Evas_Object *obj, void *ei)
790 {
791         CAL_FN_START;
792
793         c_retm_if(!data, "data is null");
794
795         cal_edit_repeat_data *p = data;
796
797         Ecore_IMF_Context *imf_context = elm_entry_imf_context_get((Evas_Object *)p->repeat_occurrence_entry);
798         c_retm_if(!imf_context, "elm_entry_imf_context_get returned null");
799
800         Ecore_IMF_Input_Panel_State state = ecore_imf_context_input_panel_state_get(imf_context);
801
802         if(state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)   {
803                 ecore_imf_context_input_panel_hide(imf_context);
804         }
805         else
806                 elm_naviframe_item_pop(p->naviframe);
807 }
808
809 Evas_Object *cal_edit_repeat_create_view(Evas_Object *window, Evas_Object *conformant, Evas_Object *naviframe,
810         int freq, calendar_range_type_e range, struct tm* start_date_time, struct tm* until, int* count,
811         cal_edit_repeat_destroy_callback callback_func, void *callback_data)
812 {
813         CAL_FN_START;
814
815         c_retv_if(!window, NULL);
816         c_retv_if(!conformant, NULL);
817         c_retv_if(!naviframe, NULL);
818
819         cal_edit_repeat_data *p = calloc(1, sizeof(cal_edit_repeat_data));
820         c_retvm_if(!p, NULL, "p is null");
821
822         p->window = window;
823         p->conformant = conformant;
824         p->naviframe = naviframe;
825
826         Evas_Object *ly = cal_util_add_layout(naviframe, "edit");
827         if (!ly) {
828                 ERR("ly is null");
829                 free(p);
830                 return NULL;
831         }
832
833         p->ly = ly;
834         p->count = *count;
835         p->start_date_time = start_date_time;
836         p->until = *until;
837         p->callback_func = callback_func;
838         p->callback_data = callback_data;
839
840         p->freq_radio_group = cal_radio_group_create(CAL_EDIT_REPEAT_FREQ_MAX, ly);
841         p->range_radio_group = cal_radio_group_create(3, ly);;
842
843         evas_object_data_set(ly, "priv", p);
844
845         Elm_Object_Item *navi_item = NULL;
846         navi_item = elm_naviframe_item_push(p->naviframe, C_("IDS_CLD_BODY_REPEAT"), NULL, NULL, ly, NULL);
847         c_retv_if(!navi_item, NULL);
848
849         p->save_cancel = cal_save_cancel_create(p->window, p->conformant, p->naviframe, __cal_edit_repeat_save_button_callback, __cal_edit_repeat_cancel_button_callback, p);
850
851         __cal_edit_repeat_set_state(p, freq, range, until, count);
852
853         int r = __cal_edit_repeat_add_content(p);
854         if (r) {
855                 evas_object_del(ly);
856                 free(p);
857                 return NULL;
858         }
859
860         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_edit_repeat_delete_layout, p);
861
862         return ly;
863 }