Tizen 2.1 base
[apps/core/preloaded/calendar.git] / common / gi-radio-timepicker.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 #include "cld.h"
19 #include "gi-radio-timepicker.h"
20 #include "gi-timepicker.h"
21
22 typedef struct {
23         void* data;
24         cal_radio_group_h radio_group;
25         Elm_Object_Item* timepicker;
26         struct tm* value;
27         int radio_index;
28 } __cal_genlist_item_radio_timepicker_info;
29
30 static void __cal_genlist_item_radio_timepicker_radio_changed(
31                 unsigned int index, bool selected, void* data)
32 {
33         CAL_FN_START;
34
35         __cal_genlist_item_radio_timepicker_info* info = (__cal_genlist_item_radio_timepicker_info*)data;
36
37         if (!selected) {
38                 elm_object_item_del(info->timepicker);
39                 info->timepicker = NULL;
40         }
41 }
42
43 static Evas_Object *__cal_genlist_item_radio_timepicker_icon(
44                 void *data, Evas_Object *obj, const char *part)
45 {
46         CAL_FN_START;
47
48         __cal_genlist_item_radio_timepicker_info* info = (__cal_genlist_item_radio_timepicker_info*)data;
49
50         Evas_Object* rd = elm_radio_add(obj);
51         c_retvm_if(!rd, NULL, "rd is NULL");
52
53         elm_object_part_content_set(rd, "content", rd);
54
55         cal_radio_group_set_radio_object(info->radio_group, info->radio_index, rd);
56
57         evas_object_show(rd);
58         evas_object_data_set(rd, "priv", info);
59
60         cal_radio_group_set_changed_callback(info->radio_group, info->radio_index,
61                         __cal_genlist_item_radio_timepicker_radio_changed, info);
62
63         return rd;
64 }
65
66 static char *__cal_genlist_item_radio_timepicker_label(void *data, Evas_Object *obj, const char *part)
67 {
68         return strdup(C_("IDS_COM_BODY_CUSTOMISE"));
69 }
70
71 static void __cal_genlist_item_radio_timepicker_select_callback(
72                 void* data, Evas_Object* obj, void* event_info)
73 {
74         CAL_FN_START;
75
76         __cal_genlist_item_radio_timepicker_info* info = (__cal_genlist_item_radio_timepicker_info*)data;
77         Elm_Object_Item* item = elm_genlist_selected_item_get(obj);
78
79         cal_radio_group_select_radio(info->radio_group, info->radio_index);
80         elm_genlist_item_selected_set(item, EINA_FALSE);
81
82         if (info->timepicker == NULL) {
83                 info->timepicker = cal_genlist_item_timepicker_add(obj, " ", info->value, EINA_FALSE, NULL, NULL);
84         }
85 }
86
87 static void __cal_genlist_item_radio_timepicker_delete_callback(void *data, Evas_Object *obj)
88 {
89         __cal_genlist_item_radio_timepicker_info* info = (__cal_genlist_item_radio_timepicker_info*)data;
90         free(info);
91 }
92
93 Elm_Object_Item* cal_genlist_item_radio_timepicker_add(
94                 Evas_Object* genlist, cal_radio_group_h radio_group, int radio_index,
95                 bool expanded, struct tm* value, void* data)
96 {
97         CAL_FN_START;
98
99         static Elm_Genlist_Item_Class* itc = NULL;
100         if (itc == NULL) {
101                 itc = (Elm_Genlist_Item_Class*)calloc(1, sizeof(Elm_Genlist_Item_Class));
102                 itc->item_style = "dialogue/1text.1icon.2";
103                 itc->func.del = __cal_genlist_item_radio_timepicker_delete_callback;
104                 itc->func.content_get = __cal_genlist_item_radio_timepicker_icon;
105                 itc->func.text_get = __cal_genlist_item_radio_timepicker_label;
106         }
107
108         __cal_genlist_item_radio_timepicker_info* info =
109                         (__cal_genlist_item_radio_timepicker_info*)calloc(1, sizeof(__cal_genlist_item_radio_timepicker_info));
110
111         info->data = data;
112         info->radio_group = radio_group;
113         info->radio_index = radio_index;
114         info->value = value;
115
116         Elm_Object_Item* item = elm_genlist_item_append(genlist, itc, info, NULL, ELM_GENLIST_ITEM_NONE,
117                         __cal_genlist_item_radio_timepicker_select_callback, info);
118
119         if (expanded)
120                 info->timepicker = cal_genlist_item_timepicker_add(genlist, " ", info->value, EINA_FALSE, NULL, NULL);
121         else
122                 info->timepicker = NULL;
123
124         CAL_FN_END;
125
126         return item;
127 }
128
129 void cal_genlist_item_radio_timepicker_get_time(Elm_Object_Item* radio_timepicker, struct tm* datetime)
130 {
131         c_retm_if(radio_timepicker == NULL, "radio_timepicker is null");
132
133         __cal_genlist_item_radio_timepicker_info* info =
134                         (__cal_genlist_item_radio_timepicker_info*)elm_object_item_data_get(radio_timepicker);
135
136         cal_genlist_item_radio_timepicker_get_value(info->timepicker, datetime);
137 }