apply FSL license
[apps/core/preloaded/calendar.git] / src / 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://www.tizenopensource.org/license
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19
20
21
22
23 #include "edit-repeat.h"
24
25 #define CAL_REPEAT_EVERY_2_WEEK (CAL_REPEAT_EVERY_YEAR+1)
26 #define CAL_REPEAT_EVERY_3_DAY (CAL_REPEAT_EVERY_2_WEEK+1)
27
28 static const char *_name = "calendar/edit/repeat";
29
30 typedef struct {
31         const char *name;
32         struct appdata* ad;
33         Evas_Object *parent;
34         Evas_Object *ly; // self
35         Evas_Object *genlist;
36
37         Evas_Object *repeat_radio_group;
38         Evas_Object *repeat_radio_group_member[7];
39         Evas_Object *repeat_until_radio_group;
40
41         Evas_Object *day_selector;
42         Evas_Object *repeat_occurrence_entry;
43         Evas_Object *end_date;
44
45         struct tm *start_date_time;
46
47         int repeat_week_flag;
48         int repeat_occurrence;
49         struct tm repeat_end_date_time;
50
51         Eina_Bool is_repeat_type;
52
53         int selected_repeat_radio;
54         int prev_selected_repeat_radio;
55         int selected_repeat_until_radio;
56
57         cal_repeat_term_t repeat;
58 } cal_edit_repeat_data;
59
60 static char *__cal_edit_repeat_repeat_str[] = {
61         [CAL_REPEAT_NONE] = NULL,
62         [CAL_REPEAT_EVERY_DAY] = NULL,
63         [CAL_REPEAT_EVERY_WEEK] = NULL,
64         [CAL_REPEAT_EVERY_MONTH] = NULL,
65         [CAL_REPEAT_EVERY_YEAR] = NULL,
66         [CAL_REPEAT_EVERY_2_WEEK] = NULL,
67         [CAL_REPEAT_EVERY_3_DAY] = NULL,
68 };
69
70 static int __cal_edit_repeat_repeat_index[] = {
71         CAL_REPEAT_NONE,
72         CAL_REPEAT_EVERY_DAY,
73         CAL_REPEAT_EVERY_WEEK,
74         CAL_REPEAT_EVERY_2_WEEK,
75         CAL_REPEAT_EVERY_MONTH,
76         CAL_REPEAT_EVERY_YEAR,
77         CAL_REPEAT_EVERY_3_DAY,
78 };
79
80 static const char *__cal_edit_repeat_repeat_until_str[] = {
81         [CAL_REPEAT_NONE] = NULL,
82         [CAL_REPEAT_EVERY_DAY] = NULL,
83         [CAL_REPEAT_EVERY_WEEK] = "",
84 };
85
86 static int __cal_edit_repeat_repeat_until_index[] = {
87         CALS_REPEAT_UNTIL_TYPE_NONE,
88         CALS_REPEAT_UNTIL_TYPE_COUNT,
89         CALS_REPEAT_UNTIL_TYPE_DATETIME,
90 };
91
92 static Elm_Entry_Filter_Limit_Size _limit_2char = {
93         .max_char_count = 2,
94 };
95 static Elm_Entry_Filter_Accept_Set _digit_only = {
96         .accepted = "0123456789",
97 };
98
99 static Elm_Genlist_Item_Class itc_seperator, itc_1icon_1text, itc_1icon;
100
101 typedef struct __cal_edit_repeat_item_data cal_edit_repeat_item_data;
102 struct __cal_edit_repeat_item_data
103 {
104         cal_edit_repeat_data *p;
105         int repeat_index;
106         int repeat_type;
107         Elm_Object_Item *it;
108         Evas_Object *item_radio;
109 };
110
111 #define is_leap_year_tm(y)  (((y+1900)%4 == 0 && ((y+1900)%100 != 0 || (y+1900)%400 == 0))? 1 : 0)
112
113 static void __cal_edit_repeat_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
114 {
115         CAL_FN_START;
116
117         cal_edit_repeat_data *p = data;
118
119         free(p);
120 }
121
122 static void __cal_edit_repeat_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
123 {
124         cal_edit_repeat_data *p;
125         Evas_Event_Mouse_Up *ev = ei;
126         int val = (int)data;
127
128         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
129                 return;
130
131         p = CAL_UTIL_GET_PRIV_DATA(obj);
132         elm_radio_value_set(p->repeat_radio_group, val);
133         p->prev_selected_repeat_radio = p->selected_repeat_radio;
134         p->selected_repeat_radio = val;
135 }
136
137 static void __cal_edit_repeat_entry_clicked_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
138 {
139         c_ret_if(!ei);
140         c_ret_if(!data);
141
142         Evas_Event_Mouse_Up *ev = ei;
143         int val = (int)data;
144
145         if (ev && ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
146                 return;
147
148         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
149         elm_radio_value_set(p->repeat_until_radio_group, val);
150
151         if (CALS_REPEAT_UNTIL_TYPE_COUNT == val) {
152                 elm_object_focus_set(p->repeat_occurrence_entry, EINA_TRUE);
153                 elm_entry_cursor_end_set(p->repeat_occurrence_entry);
154         }
155
156         p->selected_repeat_until_radio = val;
157
158         const char* str = elm_entry_entry_get(p->repeat_occurrence_entry);
159         c_ret_if(!CAL_STRLEN(str));
160
161         p->repeat_occurrence = atoi(str);
162 }
163
164 int cal_edit_repeat_get_repeat(Evas_Object *ly, int *flag, cal_repeat_until_type_t *repeat_until_type, struct tm *repeat_end_date_time, int *occurrency)
165 {
166         c_retvm_if(!ly, CAL_REPEAT_NONE, "ly is null");
167
168         const char* text = NULL;
169
170         cal_edit_repeat_data *p = CAL_UTIL_GET_PRIV_DATA(ly);
171         c_retvm_if(!p, CAL_REPEAT_NONE, "p is null");
172
173         c_retvm_if(CAL_STRCMP(p->name, _name), CAL_REPEAT_NONE, "Invaild object.");
174         c_retvm_if(!p->repeat_radio_group, CAL_REPEAT_NONE, "p->repeat_radio_group is null");
175         c_retvm_if(!p->repeat_until_radio_group, CAL_REPEAT_NONE, "p->repeat_until_radio_group is null");
176
177         int repeat = p->selected_repeat_radio;
178
179         int raido_value = p->selected_repeat_until_radio;
180         if (raido_value == 0)
181                 *repeat_until_type = CALS_REPEAT_UNTIL_TYPE_NONE;
182         else if (raido_value == 1)
183                 *repeat_until_type = CALS_REPEAT_UNTIL_TYPE_COUNT;
184         else
185                 *repeat_until_type = CALS_REPEAT_UNTIL_TYPE_DATETIME;
186
187         switch(*repeat_until_type) {
188                 case CALS_REPEAT_UNTIL_TYPE_NONE:
189                         *occurrency = 10;
190
191                         *repeat_end_date_time = *p->start_date_time;
192                         cal_util_update_tm_month(repeat_end_date_time, 1);
193                         break;
194
195                 case CALS_REPEAT_UNTIL_TYPE_COUNT:
196                         text = elm_entry_entry_get(p->repeat_occurrence_entry);
197                         c_retvm_if(!text, CAL_REPEAT_NONE, "text is null");
198
199                         *occurrency = atoi(text);
200
201                         *repeat_end_date_time = *p->start_date_time;
202                         cal_util_update_tm_month(repeat_end_date_time, 1);
203
204                         break;
205
206                 case CALS_REPEAT_UNTIL_TYPE_DATETIME:
207                         *occurrency = 10;
208
209                         *repeat_end_date_time = p->repeat_end_date_time;
210                         break;
211
212                 default:
213                         break;
214         }
215
216         return repeat;
217 }
218
219 void cal_edit_repeat_get_repeat_str(cal_repeat_term_t term, int flag, char *buf, int sz)
220 {
221         const char *s = __cal_edit_repeat_repeat_str[term];
222         if (CAL_REPEAT_NONE == term || !s)
223                 s = S_("IDS_COM_BODY_OFF");
224
225         CAL_STRNCPY(buf, s, sz);
226         buf[sz-1] = '\0';
227 }
228
229 static char *__cal_edit_repeat_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
230 {
231         c_retv_if(!data, NULL);
232
233         cal_edit_repeat_item_data *item_data = data;
234
235         int repeat_type = item_data->repeat_type;
236         int repeat_index = item_data->repeat_index;
237
238         if (!CAL_STRCMP(part, "elm.text")) {
239                 switch (repeat_type) {
240                         case -1:
241                                 return strdup(C_("IDS_CLD_BODY_REPEAT"));
242                         case -2:
243                                 return strdup(C_("IDS_CLD_BODY_REPEAT_UNTIL"));
244                         case 0:
245                                 return strdup(__cal_edit_repeat_repeat_until_str[__cal_edit_repeat_repeat_until_index[repeat_index]]);
246                         case 1:
247                                 return strdup(__cal_edit_repeat_repeat_str[__cal_edit_repeat_repeat_index[repeat_index]]);
248                         default:
249                                 return NULL;
250                 }
251         }
252
253         return NULL;
254 }
255
256 static void __cal_edit_repeat_genlist_item_delete_callback(void *data, Evas_Object *obj)
257 {
258         c_ret_if(!data);
259
260         cal_edit_repeat_item_data *item_data = data;
261
262         if (item_data->repeat_type) {
263
264                 cal_edit_repeat_data* p = item_data->p;
265                 c_ret_if(!p);
266                 c_ret_if(!p->repeat_radio_group_member);
267
268                 p->repeat_radio_group_member[item_data->repeat_index] = NULL;
269         }
270
271         free(item_data);
272 }
273
274 static Eina_Bool __cal_edit_repeat_get_genlist_item_state(void *data, Evas_Object *obj, const char *part)
275 {
276         return EINA_FALSE;
277 }
278
279 static void __cal_edit_repeat_set_radio_group(cal_edit_repeat_data *p, Evas_Object *rd, int val)
280 {
281         if (p->is_repeat_type) {
282                 if (!val) {
283
284                         p->repeat_radio_group = rd;
285
286                         elm_radio_group_add(p->repeat_radio_group_member[1], p->repeat_radio_group);
287                         elm_radio_group_add(p->repeat_radio_group_member[2], p->repeat_radio_group);
288                         elm_radio_group_add(p->repeat_radio_group_member[3], p->repeat_radio_group);
289                         elm_radio_group_add(p->repeat_radio_group_member[4], p->repeat_radio_group);
290                         elm_radio_group_add(p->repeat_radio_group_member[5], p->repeat_radio_group);
291                         elm_radio_group_add(p->repeat_radio_group_member[6], p->repeat_radio_group);
292                 }
293
294                 elm_radio_group_add(rd, p->repeat_radio_group);
295         } else {
296
297                 if (!val)
298                         p->repeat_until_radio_group = rd;
299
300                 elm_radio_group_add(rd, p->repeat_until_radio_group);
301         }
302 }
303
304 static Evas_Object* __cal_edit_repeat_add_custom_text_object(cal_edit_repeat_data *p, Evas_Object *dg, const char *text)
305 {
306         Evas_Object *entry = NULL;
307
308         if (!text || text[0] == '\0')
309                 return entry;
310
311         entry = elm_entry_add(dg);
312         CAL_ASSERT(entry);
313
314         elm_entry_single_line_set(entry, EINA_TRUE);
315         elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
316         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
317         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
318         elm_entry_editable_set(entry, EINA_FALSE);
319         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
320         elm_entry_autocapital_type_set(entry, EINA_TRUE);
321
322         elm_entry_entry_set(entry,text);
323
324         return entry;
325 }
326
327 static Evas_Object* __cal_edit_repeat_add_radio(Evas_Object *dg, int val, cal_edit_repeat_data *p, cal_edit_repeat_item_data *item_data)
328 {
329         c_retvm_if(!dg, NULL, "dg is NULL.");
330         c_retvm_if(!p, NULL, "p is NULL.");
331         c_retvm_if(!item_data, NULL, "item_data is NULL.");
332
333         Evas_Object *rd = elm_radio_add(dg);
334         c_retvm_if(!rd, NULL, "rd is NULL.");
335
336         evas_object_propagate_events_set(rd, EINA_TRUE);
337
338         elm_radio_state_value_set(rd, val);
339
340         item_data->item_radio = rd;
341
342         if (item_data->repeat_type)
343                 *(p->repeat_radio_group_member + val) = rd;
344
345         __cal_edit_repeat_set_radio_group(p, rd, val);
346
347         evas_object_show(rd);
348         evas_object_data_set(rd, "priv", p);
349
350         if (p->is_repeat_type)
351                 evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_clicked_callback, (void *)val);
352         else if (0 == val || 1 == val)
353                         evas_object_event_callback_add(rd, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_entry_clicked_callback, (void *)val);
354
355         return rd;
356 }
357
358 static void __cal_edit_repeat_entry_unfocused(void *data, Evas_Object *obj, void *event_info)
359 {
360         cal_edit_repeat_data *p = (cal_edit_repeat_data *)data;
361
362         char times[8] = {0,};
363         snprintf(times, 7, "%d", p->repeat_occurrence);
364         elm_entry_entry_set(p->repeat_occurrence_entry, times);
365
366 }
367
368 static void __cal_edit_repeat_entry_changed_callback(void *data, Evas_Object *obj, void *event_info)
369 {
370         CAL_ASSERT(data);
371         cal_edit_repeat_data *p = data;
372
373         const char *s = elm_entry_entry_get(p->repeat_occurrence_entry);
374         p->repeat_occurrence = atoi(s);
375 }
376
377 static Evas_Object* __cal_edit_repeat_add_entry(Evas_Object *parent, cal_edit_repeat_data *p)
378 {
379         Evas_Object *e;
380         Ecore_IMF_Context *ic;
381
382         e = elm_entry_add(parent);
383         if (!e)
384                 return NULL;
385
386         elm_object_style_set(e, "font_color_black");
387         elm_entry_single_line_set(e, EINA_TRUE);
388         elm_entry_markup_filter_append(e, elm_entry_filter_limit_size, &_limit_2char);
389         elm_entry_markup_filter_append(e, elm_entry_filter_accept_set, &_digit_only);
390         elm_entry_input_panel_layout_set(e, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
391         elm_entry_context_menu_disabled_set(e, EINA_TRUE);
392
393         ic = elm_entry_imf_context_get(e);
394         if (!ic)
395                 return NULL;
396
397         evas_object_smart_callback_add(e, "unfocused", __cal_edit_repeat_entry_unfocused, p);
398         evas_object_smart_callback_add(e, "changed", __cal_edit_repeat_entry_changed_callback, p);
399
400         return e;
401 }
402
403
404 static Evas_Object* __cal_edit_repeat_add_times(Evas_Object *dg, const char *text, int val,     cal_edit_repeat_data *p,  cal_edit_repeat_item_data *item_data)
405 {
406         Evas_Object *ly;
407         Evas_Object *rd;
408         Evas_Object *entry;
409         Evas_Object *entry_times;
410         char times[8] = {0,};
411
412         ly = cal_util_add_layout(dg, "dialoguegroup/repeat/times");
413         if (!ly)
414                 return NULL;
415
416         entry_times = __cal_edit_repeat_add_custom_text_object(p, dg, text);
417         if (!entry_times)
418         {
419                 evas_object_del(ly);
420                 return NULL;
421         }
422         elm_object_part_content_set(ly, "text", entry_times);
423
424         evas_object_show(ly);
425         evas_object_data_set(ly, "priv", p);
426         evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_UP, __cal_edit_repeat_entry_clicked_callback, (void *)val);
427
428         rd = elm_radio_add(dg);
429         if (!rd) {
430                 evas_object_del(ly);
431                 return NULL;
432         }
433
434         elm_radio_state_value_set(rd, val);
435         elm_object_part_content_set(ly, "content", rd);
436         item_data->item_radio = rd;
437         __cal_edit_repeat_set_radio_group(p, rd, val);
438
439         entry = __cal_edit_repeat_add_entry(ly, p);
440         if (!entry)
441         {
442                 evas_object_del(ly);
443                 return NULL;
444         }
445         elm_object_part_content_set(ly, "input_sw", entry);
446
447         p->repeat_occurrence_entry = entry;
448         snprintf(times, 7, "%d", p->repeat_occurrence);
449         elm_entry_entry_set(p->repeat_occurrence_entry, times);
450
451         return ly;
452 }
453
454 static void __cal_edit_repeat_end_date_changed_callback(void *data, Evas_Object *obj, void *ei)
455 {
456         cal_edit_repeat_data *p = data;
457
458         elm_datetime_value_get(obj, &p->repeat_end_date_time);
459 }
460
461 static Evas_Object* __cal_edit_repeat_add_radio_tm(Evas_Object *dg, struct tm* repeat_end_date, int val, cal_edit_repeat_data *p, cal_edit_repeat_item_data *item_data)
462 {
463         Evas_Object *ly = cal_util_add_layout(dg, "dialoguegroup/tm");
464         c_retvm_if(!ly, NULL, "ly is null");
465
466         evas_object_show(ly);
467         evas_object_data_set(ly, "priv", p);
468
469         Evas_Object *rd = elm_radio_add(dg);
470         if (!rd) {
471                 evas_object_del(ly);
472                 return NULL;
473         }
474
475         evas_object_propagate_events_set(rd, EINA_TRUE);
476
477         elm_radio_state_value_set(rd, val);
478
479         elm_object_part_content_set(ly, "content", rd);
480         item_data->item_radio = rd;
481
482         if (item_data->repeat_type)
483                 *(p->repeat_radio_group_member + val) = rd;
484
485         __cal_edit_repeat_set_radio_group(p, rd, val);
486
487         Evas_Object *datetime = cal_util_add_datetime(dg, NULL, repeat_end_date);
488         c_retvm_if(!datetime, NULL, "datetime is null");
489
490         elm_datetime_field_visible_set(datetime, ELM_DATETIME_HOUR, EINA_FALSE);
491         elm_datetime_field_visible_set(datetime, ELM_DATETIME_MINUTE, EINA_FALSE);
492         elm_datetime_field_visible_set(datetime, ELM_DATETIME_AMPM, EINA_FALSE);
493
494         elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 137);
495
496         evas_object_smart_callback_add(datetime,"changed", __cal_edit_repeat_end_date_changed_callback, p);
497
498         elm_object_part_content_set(ly, "datefield", datetime);
499
500         return ly;
501 }
502
503 static Evas_Object* __cal_edit_repeat_add_radio_group(Evas_Object *dg, const char *text, int val, cal_edit_repeat_data *p, cal_edit_repeat_item_data *item_data)
504 {
505         if (p->is_repeat_type) {
506                 return __cal_edit_repeat_add_radio(dg, val, p, item_data);
507         } else {
508                 switch(val)
509                 {
510                 case 0:
511                         return __cal_edit_repeat_add_radio(dg, val, p, item_data);
512                 case 1:
513                         return __cal_edit_repeat_add_times(dg, text, val, p, item_data);
514                 case 2:
515                         return __cal_edit_repeat_add_radio_tm(dg, &p->repeat_end_date_time, val, p, item_data);
516
517                 default:
518                         return NULL;
519                 }
520         }
521 }
522
523 static void __cal_edit_repeat_set_selected_repeat_state(cal_edit_repeat_data *p)
524 {
525         elm_radio_value_set(p->repeat_radio_group, p->selected_repeat_radio);
526 }
527
528 static void __cal_edit_repeat_set_selected_repeat_until_state(cal_edit_repeat_data *p)
529 {
530         c_ret_if(!p);
531
532         char times[10] = {0};
533
534         switch (p->selected_repeat_until_radio) {
535                 case 1:
536                         elm_radio_value_set(p->repeat_until_radio_group, 1);
537                         snprintf(times,sizeof(times),"%d", p->repeat_occurrence);
538                         elm_entry_entry_set(p->repeat_occurrence_entry,times);
539                         break;
540
541                 case 2:
542                         snprintf(times,sizeof(times),"%d", p->repeat_occurrence);
543                         elm_entry_entry_set(p->repeat_occurrence_entry,times);
544                         elm_radio_value_set(p->repeat_until_radio_group, 2);
545
546                         break;
547
548                 default:
549                         elm_radio_value_set(p->repeat_until_radio_group, 0);
550                         snprintf(times,sizeof(times),"%d", p->repeat_occurrence);
551                         elm_entry_entry_set(p->repeat_occurrence_entry,times);
552
553                         break;
554         }
555 }
556
557 static Evas_Object *__cal_edit_repeat_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
558 {
559         Evas_Object *e_obj = NULL;
560
561         if (!CAL_STRCMP(part, "elm.icon"))
562         {
563                 cal_edit_repeat_item_data *item_data = (cal_edit_repeat_item_data *)data;
564                 cal_edit_repeat_data *p = item_data->p;
565                 int repeat_type = item_data->repeat_type;
566                 int repeat_index = item_data->repeat_index;
567                 if (repeat_type)
568                 {
569                         p->is_repeat_type = repeat_type;
570                         e_obj = __cal_edit_repeat_add_radio_group(obj, __cal_edit_repeat_repeat_str[__cal_edit_repeat_repeat_index[repeat_index]], __cal_edit_repeat_repeat_index[repeat_index], p, item_data);
571                         __cal_edit_repeat_set_selected_repeat_state(p);
572                 }
573                 else
574                 {
575                         p->is_repeat_type = false;
576                         e_obj = __cal_edit_repeat_add_radio_group(obj, __cal_edit_repeat_repeat_until_str[__cal_edit_repeat_repeat_until_index[repeat_index]], __cal_edit_repeat_repeat_until_index[repeat_index], p, item_data);
577                         __cal_edit_repeat_set_selected_repeat_until_state(p);
578                 }
579         }
580
581         return e_obj;
582
583 }
584
585 static void __cal_edit_repeat_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
586 {
587         c_ret_if(!obj);
588
589         Elm_Object_Item *it = elm_genlist_selected_item_get(obj);
590         c_ret_if(!it);
591
592         elm_genlist_item_selected_set(it, EINA_FALSE);
593
594         cal_edit_repeat_item_data *item_data = elm_object_item_data_get(it);
595         c_ret_if(!item_data);
596
597         cal_edit_repeat_data *p = item_data->p;
598         c_ret_if(!p);
599
600         int type = item_data->repeat_type;
601         int index = item_data->repeat_index;
602
603         if (type) {
604
605                 p->selected_repeat_radio = __cal_edit_repeat_repeat_index[index];
606                 elm_radio_value_set(p->repeat_radio_group, __cal_edit_repeat_repeat_index[index]);
607                 elm_object_focus_set(p->repeat_occurrence_entry, EINA_FALSE);
608
609         } else {
610
611                 elm_radio_value_set(p->repeat_until_radio_group, __cal_edit_repeat_repeat_until_index[index]);
612                 p->selected_repeat_until_radio = __cal_edit_repeat_repeat_until_index[index];
613
614                 if (CALS_REPEAT_UNTIL_TYPE_COUNT != __cal_edit_repeat_repeat_until_index[index])
615                         elm_object_focus_set(p->repeat_occurrence_entry, EINA_FALSE);
616         }
617 }
618
619 static void __cal_edit_repeat_add_separator(Evas_Object *genlist, cal_edit_repeat_data *p, int index)
620 {
621         cal_edit_repeat_item_data *item_data = NULL;
622         CAL_CALLOC(item_data, 1, cal_edit_repeat_item_data);
623
624         item_data->repeat_index = index;
625         item_data->repeat_type = index;
626         item_data->p = p;
627         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);
628
629         elm_genlist_item_select_mode_set(item_data->it, ELM_OBJECT_SELECT_MODE_NONE);
630 }
631
632 static void __cal_edit_repeat_add_repeat(Evas_Object *genlist, cal_edit_repeat_data *p)
633 {
634         int i;
635         for (i = 0; i < sizeof(__cal_edit_repeat_repeat_index)/sizeof(__cal_edit_repeat_repeat_index[0]); i++)
636         {
637                 cal_edit_repeat_item_data *item_data = NULL;
638                 CAL_CALLOC(item_data, 1, cal_edit_repeat_item_data);
639
640                 item_data->p = p;
641                 item_data->repeat_index = i;
642                 item_data->repeat_type = EINA_TRUE;
643                 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, NULL);
644         }
645 }
646
647 static void __cal_edit_repeat_add_repeat_until(Evas_Object *genlist, cal_edit_repeat_data *p)
648 {
649         int i;
650         for (i = 0; i < sizeof(__cal_edit_repeat_repeat_until_index)/sizeof(__cal_edit_repeat_repeat_until_index[0]); i++)
651         {
652                 cal_edit_repeat_item_data *item_data = NULL;
653                 CAL_CALLOC(item_data, 1, cal_edit_repeat_item_data);
654
655                 item_data->p = p;
656                 item_data->repeat_index = i;
657                 item_data->repeat_type = EINA_FALSE;
658                 if (CALS_REPEAT_UNTIL_TYPE_NONE != __cal_edit_repeat_repeat_until_index[i])
659                 {
660                         item_data->it = elm_genlist_item_append(genlist, &itc_1icon, (void*)item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_edit_repeat_genlist_item_select_callback, NULL);
661                 }
662                 else
663                 {
664                         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, NULL);
665                 }
666         }
667 }
668
669 static void __cal_edit_repeat_add_genlist_item(Evas_Object *genlist, cal_edit_repeat_data *p)
670 {
671         __cal_edit_repeat_add_separator(genlist, p, -1);
672         __cal_edit_repeat_add_repeat(genlist, p);
673         __cal_edit_repeat_add_separator(genlist, p, -2);
674         __cal_edit_repeat_add_repeat_until(genlist, p);
675
676 }
677
678 static int __cal_edit_repeat_add_content(cal_edit_repeat_data *p)
679 {
680         p->genlist = elm_genlist_add(p->ly);
681         CAL_ASSERT(p->genlist);
682
683         Evas_Object* cf;
684
685         itc_seperator.item_style = "dialogue/title";
686         itc_seperator.func.text_get = __cal_edit_repeat_get_genlist_item_label;
687         itc_seperator.func.state_get = __cal_edit_repeat_get_genlist_item_state;
688         itc_seperator.func.del = __cal_edit_repeat_genlist_item_delete_callback;
689
690         itc_1icon_1text.item_style = "dialogue/1text.1icon.2";
691         itc_1icon_1text.func.text_get = __cal_edit_repeat_get_genlist_item_label;
692         itc_1icon_1text.func.del = __cal_edit_repeat_genlist_item_delete_callback;
693         itc_1icon_1text.func.content_get = __cal_edit_repeat_get_genlist_item_icon;
694
695         itc_1icon.item_style = "dialogue/1icon";
696         itc_1icon.func.text_get = __cal_edit_repeat_get_genlist_item_label;
697         itc_1icon.func.del = __cal_edit_repeat_genlist_item_delete_callback;
698         itc_1icon.func.content_get = __cal_edit_repeat_get_genlist_item_icon;
699
700         __cal_edit_repeat_add_genlist_item(p->genlist, p);
701
702         cf = elm_conformant_add(p->ad->win);
703         CAL_ASSERT(cf);
704
705         evas_object_size_hint_weight_set(cf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
706         evas_object_show(cf);
707         elm_object_content_set(cf, p->genlist);
708         elm_object_style_set(cf, "internal_layout");
709         elm_object_part_content_set(p->ly, "sw", cf);
710
711         return 0;
712 }
713
714 static void __cal_edit_repeat_set_state(cal_edit_repeat_data *p, cal_repeat_term_t term, cal_repeat_until_type_t repeat_until_type, struct tm* repeat_end_date_time, int* occurrency, int flag)
715 {
716         p->selected_repeat_radio = term;
717         p->prev_selected_repeat_radio = term;
718
719         if (repeat_until_type == CALS_REPEAT_UNTIL_TYPE_NONE)
720                 p->selected_repeat_until_radio = 0;
721         else if (repeat_until_type == CALS_REPEAT_UNTIL_TYPE_COUNT)
722                 p->selected_repeat_until_radio = 1;
723         else
724                 p->selected_repeat_until_radio = 2;
725
726         p->repeat_week_flag = flag;
727 }
728
729 Evas_Object *cal_edit_repeat_create_view(Evas_Object *parent, struct appdata* ad, cal_repeat_term_t term, cal_repeat_until_type_t repeat_until_type, struct tm* start_date_time, struct tm* repeat_end_date_time, int* occurrency, int flag)
730 {
731         CAL_FN_START;
732
733         c_retvm_if(!parent, NULL, "parent is null");
734         c_retvm_if(!ad, NULL, "ad is null");
735
736         char buf[256] = {0};
737
738         cal_edit_repeat_data *p = calloc(1, sizeof(cal_edit_repeat_data));
739         c_retvm_if(!p, NULL, "p is null");
740
741         p->name = _name;
742         p->parent = parent;
743         p->repeat_radio_group = NULL;
744         p->repeat_until_radio_group = NULL;
745         p->ad = ad;
746         p->repeat = term;
747
748         Evas_Object *ly = cal_util_add_layout(parent, "edit");
749         if (!ly) {
750                 ERR("ly is null");
751                 free(p);
752                 return NULL;
753         }
754
755         p->ly = ly;
756         p->repeat_occurrence = *occurrency;
757         p->start_date_time = start_date_time;
758         p->repeat_end_date_time = *repeat_end_date_time;
759
760         evas_object_data_set(ly, "priv", p);
761         __cal_edit_repeat_repeat_str[CAL_REPEAT_NONE] = S_("IDS_COM_BODY_OFF");
762         __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_DAY] = C_("IDS_KC_BODY_EVERY_DAY");
763         __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_WEEK] = C_("IDS_CLD_BODY_EVERY_WEEK");
764         __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_MONTH] = C_("IDS_CLD_BODY_EVERY_MONTH");
765         __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_YEAR] = C_("IDS_CLD_BODY_EVERY_YEAR");
766
767         if (!__cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_2_WEEK]) {
768
769                 const char *string = C_("IDS_CLD_BODY_EVERY_PD_WEEKS");
770                 snprintf(buf, sizeof(buf), string, 2);
771                 __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_2_WEEK] = strdup(buf);
772
773         }
774
775         if (!__cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_3_DAY]) {
776
777                 const char *string = C_("IDS_CLD_BODY_EVERY_PD_DAYS");
778                 snprintf(buf, sizeof(buf), string, 3);
779                 __cal_edit_repeat_repeat_str[CAL_REPEAT_EVERY_3_DAY] = strdup(buf);
780         }
781         __cal_edit_repeat_repeat_until_str[CAL_REPEAT_NONE] = S_("IDS_COM_BODY_NONE");
782         __cal_edit_repeat_repeat_until_str[CAL_REPEAT_EVERY_DAY] = C_("IDS_COM_POP_TIMES_LC");
783
784         __cal_edit_repeat_set_state(p, term, repeat_until_type, repeat_end_date_time, occurrency, flag);
785
786         int r = __cal_edit_repeat_add_content(p);
787         if (r) {
788                 evas_object_del(ly);
789                 free(p);
790                 return NULL;
791         }
792
793         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_edit_repeat_delete_layout, p);
794
795         return ly;
796 }