1ef897b2582f6979bc16d372651b45292dea5bdc
[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.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://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 *parent;
36         Evas_Object *ly; // self
37         Evas_Object *genlist;
38
39         cal_radio_group_h freq_radio_group;
40         cal_radio_group_h range_radio_group;
41
42         Evas_Object *day_selector;
43         Evas_Object *repeat_occurrence_entry;
44         Evas_Object *end_date;
45
46         struct tm *start_date_time;
47
48         int count;
49         struct tm until;
50
51         int selected_freq_radio;
52         int prev_selected_freq_radio;
53         int selected_range_radio;
54
55         cal_edit_repeat_destroy_callback callback_func;
56         void *callback_data;
57
58         cal_save_cancel_h save_cancel;
59
60 } cal_edit_repeat_data;
61
62 static int __cal_edit_repeat_get_radio_index(int freq)
63 {
64         switch (freq) {
65         case CALENDAR_RECURRENCE_NONE:
66                 return CAL_EDIT_REPEAT_FREQ_OFF;
67         case CALENDAR_RECURRENCE_DAILY:
68                 return CAL_EDIT_REPEAT_FREQ_EVERY_DAY;
69         case CAL_REPEAT_EVERY_3_DAY:
70                 return CAL_EDIT_REPEAT_FREQ_EVERY_3_DAY;
71         case CALENDAR_RECURRENCE_WEEKLY:
72                 return CAL_EDIT_REPEAT_FREQ_EVERY_WEEK;
73         case CAL_REPEAT_EVERY_2_WEEK:
74                 return CAL_EDIT_REPEAT_FREQ_EVERY_2_WEEK;
75         case CALENDAR_RECURRENCE_MONTHLY:
76                 return CAL_EDIT_REPEAT_FREQ_EVERY_MONTH;
77         case CALENDAR_RECURRENCE_YEARLY:
78                 return CAL_EDIT_REPEAT_FREQ_EVERY_YEAR;
79         default:
80                 ERR("Invalid value : %d", freq);
81                 return 0;
82         }
83 }
84
85 static int __cal_edit_repeat_get_freq(int radio_index)
86 {
87         switch (radio_index) {
88         case CAL_EDIT_REPEAT_FREQ_OFF:
89                 return CALENDAR_RECURRENCE_NONE;
90         case CAL_EDIT_REPEAT_FREQ_EVERY_DAY:
91                 return CALENDAR_RECURRENCE_DAILY;
92         case CAL_EDIT_REPEAT_FREQ_EVERY_3_DAY:
93                 return CAL_REPEAT_EVERY_3_DAY;
94         case CAL_EDIT_REPEAT_FREQ_EVERY_WEEK:
95                 return CALENDAR_RECURRENCE_WEEKLY;
96         case CAL_EDIT_REPEAT_FREQ_EVERY_2_WEEK:
97                 return CAL_REPEAT_EVERY_2_WEEK;
98         case CAL_EDIT_REPEAT_FREQ_EVERY_MONTH:
99                 return CALENDAR_RECURRENCE_MONTHLY;
100         case CAL_EDIT_REPEAT_FREQ_EVERY_YEAR:
101                 return CALENDAR_RECURRENCE_YEARLY;
102         default:
103                 ERR("Invalid value : %d", radio_index);
104                 return CALENDAR_RECURRENCE_NONE;
105         }
106 }
107
108 static int __cal_edit_repeat_range_index[] = {
109         CALENDAR_RANGE_NONE,
110         CALENDAR_RANGE_COUNT,
111         CALENDAR_RANGE_UNTIL,
112 };
113
114 typedef enum {
115         CAL_EDIT_REPEAT_SEPARATOR_FREQ,
116         CAL_EDIT_REPEAT_ITEM_FREQ,
117         CAL_EDIT_REPEAT_SEPARATOR_RANGE,
118         CAL_EDIT_REPEAT_ITEM_RANGE,
119 }cal_edit_repeat_item_type;
120
121 static Elm_Entry_Filter_Limit_Size _limit_2char = {
122         .max_char_count = 2,
123 };
124 static Elm_Entry_Filter_Accept_Set _digit_only = {
125         .accepted = "0123456789",
126 };
127
128 static Elm_Genlist_Item_Class itc_seperator, itc_1icon_1text, itc_1icon, itc_2icon_1text;
129
130 typedef struct __cal_edit_repeat_item_data cal_edit_repeat_item_data;
131 struct __cal_edit_repeat_item_data
132 {
133         cal_edit_repeat_data *p;
134         int index;
135         cal_edit_repeat_item_type type;
136         Elm_Object_Item *it;
137         Evas_Object *radio;
138 };
139
140 #define is_leap_year_tm(y)  (((y+1900)%4 == 0 && ((y+1900)%100 != 0 || (y+1900)%400 == 0))? 1 : 0)
141
142 static void __cal_edit_repeat_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
143 {
144         CAL_FN_START;
145
146         cal_edit_repeat_data *p = data;
147
148         cal_radio_group_destroy(p->freq_radio_group);
149         cal_radio_group_destroy(p->range_radio_group);
150
151         if (p->save_cancel)
152                 cal_save_cancel_destroy(p->save_cancel);
153
154         free(p);
155 }
156
157 static void __cal_edit_repeat_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
158 {
159         cal_edit_repeat_data *p;
160         Evas_Event_Mouse_Up *ev = ei;
161         int val = (int)data;
162
163         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
164                 return;
165
166         p = CAL_UTIL_GET_PRIV_DATA(obj);
167         cal_radio_group_select_radio(p->freq_radio_group, val);
168         p->prev_selected_freq_radio = p->selected_freq_radio;
169         p->selected_freq_radio = val;
170 }
171
172 static void __cal_edit_repeat_entry_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
173 {
174         c_ret_if(!ei);
175         c_ret_if(!data);
176
177         Evas_Event_Mouse_Up *ev = ei;
178         int val = (int)data;
179
180         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
181                 return;
182
183         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
184         cal_radio_group_select_radio(p->range_radio_group, val);
185
186         if (CALENDAR_RANGE_COUNT == val) {
187                 elm_object_focus_set(p->repeat_occurrence_entry, EINA_TRUE);
188                 elm_entry_cursor_end_set(p->repeat_occurrence_entry);
189         }
190
191         p->selected_range_radio = val;
192
193         const char* str = elm_entry_entry_get(p->repeat_occurrence_entry);
194         c_ret_if(!CAL_STRLEN(str));
195
196         p->count = atoi(str);
197 }
198
199 int cal_edit_repeat_get_repeat(Evas_Object *ly, calendar_range_type_e *range, struct tm *until, int *count)
200 {
201         c_retvm_if(!ly, CALENDAR_RECURRENCE_NONE, "ly is null");
202
203         const char* text = NULL;
204
205         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
206         c_retvm_if(!p, CALENDAR_RECURRENCE_NONE, "p is null");
207
208         c_retvm_if(!p->freq_radio_group, CALENDAR_RECURRENCE_NONE, "p->freq_radio_group is null");
209         c_retvm_if(!p->range_radio_group, CALENDAR_RECURRENCE_NONE, "p->range_radio_group is null");
210
211         *range = __cal_edit_repeat_range_index[p->selected_range_radio];
212
213         switch (*range) {
214                 case CALENDAR_RANGE_NONE:
215                         *count = 10;
216
217                         *until = *p->start_date_time;
218                         cal_util_update_tm_month(until, 1);
219                         break;
220
221                 case CALENDAR_RANGE_COUNT:
222                         text = elm_entry_entry_get(p->repeat_occurrence_entry);
223                         c_retvm_if(!text, CALENDAR_RECURRENCE_NONE, "text is null");
224
225                         *count = atoi(text);
226
227                         *until = *p->start_date_time;
228                         cal_util_update_tm_month(until, 1);
229
230                         break;
231
232                 case CALENDAR_RANGE_UNTIL:
233                         *count = 10;
234
235                         *until = p->until;
236                         break;
237
238                 default:
239                         break;
240         }
241
242         return __cal_edit_repeat_get_freq(p->selected_freq_radio);
243 }
244
245 void _cal_edit_repeat_get_freq_str(int freq, char *buf, int size)
246 {
247         c_ret_if(!buf);
248
249         char *format = NULL;
250
251         switch (freq) {
252
253                 case CALENDAR_RECURRENCE_DAILY:
254
255                         snprintf(buf, size, "%s", C_("IDS_KC_BODY_EVERY_DAY"));
256                         break;
257
258                 case CAL_REPEAT_EVERY_3_DAY:
259
260                         format = C_("IDS_CLD_BODY_EVERY_PD_DAYS");
261                         snprintf(buf, size, format, 3);
262                         break;
263
264                 case CALENDAR_RECURRENCE_WEEKLY:
265
266                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_WEEK"));
267                         break;
268
269                 case CAL_REPEAT_EVERY_2_WEEK:
270
271                         format = C_("IDS_CLD_BODY_EVERY_PD_WEEKS");
272                         snprintf(buf, size, format, 2);
273                         break;
274
275                 case CALENDAR_RECURRENCE_MONTHLY:
276
277                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_MONTH"));
278                         break;
279
280                 case CALENDAR_RECURRENCE_YEARLY:
281
282                         snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_YEAR"));
283                         break;
284
285                 default:
286
287                         snprintf(buf, size, "%s", S_("IDS_COM_BODY_OFF"));
288                         break;
289
290         }
291
292         buf[size-1] = '\0';
293 }
294
295 static char *__cal_edit_repeat_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
296 {
297         CAL_FN_START;
298
299         c_retv_if(!data, NULL);
300
301         cal_edit_repeat_item_data *item_data = data;
302
303         char string[32] = {0};
304
305         if (!CAL_STRCMP(part, "elm.text")) {
306                 switch (item_data->type) {
307                         case CAL_EDIT_REPEAT_SEPARATOR_FREQ:
308                                 return strdup(C_("IDS_CLD_BODY_REPEAT"));
309
310                         case CAL_EDIT_REPEAT_ITEM_FREQ:
311                                 _cal_edit_repeat_get_freq_str(__cal_edit_repeat_get_freq(item_data->index), string, sizeof(string));
312                                 return strdup(string);
313
314                         case CAL_EDIT_REPEAT_SEPARATOR_RANGE:
315                                 return strdup(C_("IDS_CLD_BODY_REPEAT_UNTIL"));
316
317                         case CAL_EDIT_REPEAT_ITEM_RANGE:
318                                 if (__cal_edit_repeat_range_index[item_data->index] == CALENDAR_RANGE_NONE)
319                                         return strdup(S_("IDS_COM_BODY_NONE"));
320
321                         default:
322                                 return NULL;
323                 }
324         } else if (!CAL_STRCMP(part, "text")) {
325                 return strdup(C_("IDS_COM_POP_TIMES_LC"));
326         }
327
328         return NULL;
329 }
330
331 static void __cal_edit_repeat_genlist_item_delete_callback(void *data, Evas_Object *obj)
332 {
333         CAL_FN_START;
334
335         c_ret_if(!data);
336         cal_edit_repeat_item_data *item_data = data;
337
338         free(item_data);
339 }
340
341 static Eina_Bool __cal_edit_repeat_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
342 {
343         return EINA_FALSE;
344 }
345
346 static Evas_Object* __cal_edit_repeat_add_radio(Evas_Object *obj, cal_edit_repeat_item_data *item_data)
347 {
348         c_retvm_if(!obj, NULL, "dg is NULL.");
349         c_retvm_if(!item_data, NULL, "item_data is NULL.");
350
351         cal_edit_repeat_data *p = item_data->p;
352         c_retv_if(!p, NULL);
353
354         Evas_Object *rd = elm_radio_add(obj);
355         c_retv_if(!rd, NULL);
356
357         evas_object_propagate_events_set(rd, EINA_TRUE);
358
359         cal_edit_repeat_item_type type = item_data->type;
360
361         if (type == CAL_EDIT_REPEAT_ITEM_FREQ)
362                 cal_radio_group_set_radio_object(p->freq_radio_group, item_data->index, rd);
363         else if (type == CAL_EDIT_REPEAT_ITEM_RANGE)
364                 cal_radio_group_set_radio_object(p->range_radio_group, item_data->index, rd);
365
366         item_data->radio = rd;
367
368         evas_object_show(rd);
369         evas_object_data_set(rd, "priv", p);
370
371         if (item_data->type == CAL_EDIT_REPEAT_ITEM_FREQ)
372                 evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_clicked_callback, (void *)item_data->index);
373         else if (0 == item_data->index || 1 == item_data->index)
374                         evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_entry_clicked_callback, (void *)item_data->index);
375
376         return rd;
377 }
378
379 static void __cal_edit_repeat_entry_unfocused(void *data, Evas_Object *obj, void *event_info)
380 {
381         cal_edit_repeat_data *p = (cal_edit_repeat_data *)data;
382
383         char times[8] = {0,};
384         snprintf(times, 7, "%d", p->count);
385         elm_entry_entry_set(p->repeat_occurrence_entry, times);
386
387 }
388
389 static void __cal_edit_repeat_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
390 {
391         CAL_ASSERT(data);
392         cal_edit_repeat_data *p = data;
393
394         const char *s = elm_entry_entry_get(p->repeat_occurrence_entry);
395         if (s != NULL)
396                 p->count = atoi(s);
397 }
398
399 static Evas_Object* __cal_edit_repeat_add_entry(Evas_Object *parent, cal_edit_repeat_data *p)
400 {
401         Evas_Object *e;
402         Ecore_IMF_Context *ic;
403
404         e = elm_entry_add(parent);
405         if (!e)
406                 return NULL;
407
408         elm_object_style_set(e, "font_color_black");
409         elm_entry_single_line_set(e, EINA_TRUE);
410         elm_entry_markup_filter_append(e, elm_entry_filter_limit_size, &_limit_2char);
411         elm_entry_markup_filter_append(e, elm_entry_filter_accept_set, &_digit_only);
412         elm_entry_input_panel_layout_set(e, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
413         elm_entry_context_menu_disabled_set(e, EINA_TRUE);
414
415         ic = elm_entry_imf_context_get(e);
416         if (!ic)
417                 return NULL;
418
419         cal_save_cancel_set_input_panel_callback_for_ug(p->save_cancel, e);
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->parent);
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
794
795 Evas_Object *cal_edit_repeat_create_view(Evas_Object *parent, int freq, calendar_range_type_e range, struct tm* start_date_time, struct tm* until, int* count,
796                                                                                                                                                                 cal_edit_repeat_destroy_callback callback_func, void *callback_data)
797 {
798         CAL_FN_START;
799
800         c_retvm_if(!parent, NULL, "parent is null");
801
802         cal_edit_repeat_data *p = calloc(1, sizeof(cal_edit_repeat_data));
803         c_retvm_if(!p, NULL, "p is null");
804
805         p->parent = parent;
806
807         Evas_Object *ly = cal_util_add_layout(parent, "edit");
808         if (!ly) {
809                 ERR("ly is null");
810                 free(p);
811                 return NULL;
812         }
813
814         p->ly = ly;
815         p->count = *count;
816         p->start_date_time = start_date_time;
817         p->until = *until;
818         p->callback_func = callback_func;
819         p->callback_data = callback_data;
820
821         p->freq_radio_group = cal_radio_group_create(CAL_EDIT_REPEAT_FREQ_MAX, ly);
822         p->range_radio_group = cal_radio_group_create(3, ly);;
823
824         evas_object_data_set(ly, "priv", p);
825
826         Elm_Object_Item *navi_item = NULL;
827         navi_item = elm_naviframe_item_push(p->parent, C_("IDS_CLD_BODY_REPEAT"), NULL, NULL, ly, NULL);
828         c_retv_if(!navi_item, NULL);
829
830         p->save_cancel = cal_save_cancel_create(p->parent, NULL, __cal_edit_repeat_save_button_callback, __cal_edit_repeat_cancel_button_callback, p);
831
832         __cal_edit_repeat_set_state(p, freq, range, until, count);
833
834         int r = __cal_edit_repeat_add_content(p);
835         if (r) {
836                 evas_object_del(ly);
837                 free(p);
838                 return NULL;
839         }
840
841         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_edit_repeat_delete_layout, p);
842
843         return ly;
844 }