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