Merge "fix default language"
[apps/core/preloaded/settings.git] / setting-datausage / src / setting-datausage-change-cycle.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <setting-datausage-change-cycle.h>
23
24 static int __setting_datausage_change_cycle_create(void *cb);
25 static int __setting_datausage_change_cycle_destroy(void *cb);
26 static int __setting_datausage_change_cycle_update(void *cb);
27 static int __setting_datausage_change_cycle_cleanup(void *cb);
28
29 setting_view setting_view_datausage_change_cycle = {
30         .create = __setting_datausage_change_cycle_create,
31         .destroy = __setting_datausage_change_cycle_destroy,
32         .update = __setting_datausage_change_cycle_update,
33         .cleanup = __setting_datausage_change_cycle_cleanup,
34 };
35
36 static char *_item_label_get(void *data, Evas_Object *obj, const char *part)
37 {
38         SETTING_TRACE_BEGIN;
39         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
40
41         if (!safeStrCmp(part, "elm.text") || !safeStrCmp(part, "elm.text.1")) { /* title */
42                 if (item_data->keyStr) {
43                         return (char *)g_strdup(_(item_data->keyStr));
44                 }
45         } else if (!safeStrCmp(part, "elm.text.2")) {   /* bottom or right */
46                 if (item_data->sub_desc) {
47                         return (char *)g_strdup(item_data->sub_desc);
48                 }
49         }
50
51
52         return NULL;
53 }
54
55 static Evas_Object *_item_content_get(void *data, Evas_Object *obj, const char *part)
56 {
57         SETTING_TRACE_BEGIN;
58         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
59         //int width = (int) (690 * elm_scale_get());
60
61         if (!safeStrCmp(part, "elm.icon") || !safeStrCmp(part, "elm.icon.1")) {
62                 Evas_Object *datetimefield = elm_datetime_add(obj);
63                 item_data->eo_check = datetimefield;
64
65                 elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_YEAR, EINA_FALSE);
66                 elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_MONTH, EINA_FALSE);
67                 elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_HOUR, EINA_FALSE);
68                 elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_MINUTE, EINA_FALSE);
69                 elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_AMPM, EINA_FALSE);
70
71                 evas_object_size_hint_weight_set(datetimefield, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
72                 evas_object_size_hint_align_set(datetimefield, 0.5, 0.5);
73                 evas_object_show(datetimefield);
74
75                 char date_format[MAX_DATETIME_FORMAT_LEN + 1] = {0, };
76                 const char *time_format = "%H : %M";
77
78                 snprintf(date_format, MAX_DATETIME_FORMAT_LEN,
79                                  "%s %s", item_data->sub_desc, time_format);
80                 elm_datetime_format_set(datetimefield, date_format);
81
82                 struct tm ts_ret;
83                 time_t ctime = time(NULL);
84                 struct tm *ts = localtime_r(&ctime, &ts_ret);
85                 retv_if(!ts, NULL);
86                 ts_ret.tm_mday = item_data->chk_status;
87
88                 elm_datetime_value_set(datetimefield, &ts_ret);
89
90                 if (item_data->chk_change_cb) {
91                         evas_object_smart_callback_add(datetimefield, "changed",
92                                                        item_data->chk_change_cb, item_data);
93                 }
94                 return datetimefield;
95         }
96
97         return NULL;
98 }
99
100 static void _item_del(void *data, Evas_Object *obj)
101 {
102         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
103         if (item_data) {
104                 G_FREE(item_data->keyStr);
105                 G_FREE(item_data->sub_desc);
106                 FREE(item_data);
107         }
108 }
109
110 /* ***************************************************
111 **
112 ** basic func
113 **
114 ** **************************************************/
115
116 static int __setting_datausage_change_cycle_create(void *cb)
117 {
118         SETTING_TRACE_BEGIN;
119         //error check
120         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
121
122         SettingDatausageUG *ad = (SettingDatausageUG *) cb;
123         Evas_Object *scroller;
124
125         setting_push_layout_navi_bar_genlist(ad->win_main_layout,
126                                         ad->win_get,
127                                         _(SETTING_DATAUSAGE_CHANGE_CYCLE_STR),
128                                         _("IDS_COM_BODY_BACK"),
129                                         NULL,
130                                         __setting_datausage_change_cycle_back_cb,
131                                         NULL,
132                                         ad, &scroller, ad->navibar);
133
134         setting_retvm_if(scroller == NULL, SETTING_RETURN_FAIL, "scroller is NULL");
135
136         Elm_Object_Item *item = NULL;;
137
138         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
139                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
140         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
141
142         ad->itc_layout.item_style = "dialogue/1text.1icon.5";
143         ad->itc_layout.func.text_get = _item_label_get;
144         ad->itc_layout.func.content_get = _item_content_get;
145         ad->itc_layout.func.state_get = NULL;
146         ad->itc_layout.func.del = _item_del;
147
148
149         int value = 0;
150         int err = 0;
151         int ret = 0;
152
153         ret = setting_get_int_slp_key(INT_SLP_SETTING_DATAUSAGE_DATA_EACH_MONTH_INT, &value, &err);
154         if (ret != 0) {
155                 SETTING_TRACE_ERROR("get vconf failed");
156         }
157
158         ad->change_data = setting_create_Gendial_field_def(scroller, &(ad->itc_layout),
159                                              NULL,
160                                              ad, SWALLOW_Type_LAYOUT_DATEFIELD,
161                                              NULL, NULL, value,
162                                              SETTING_DATAUSAGE_ON_THIS_DATE_EACH_MONTH_STR,
163                                              "%Y %b %d",
164                                              NULL);
165
166         setting_view_datausage_change_cycle.is_create = 1;
167         return SETTING_RETURN_SUCCESS;
168 }
169
170 static int __setting_datausage_change_cycle_destroy(void *cb)
171 {
172         SETTING_TRACE_BEGIN;
173         //error check
174         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
175         SettingDatausageUG *ad = (SettingDatausageUG *) cb;
176
177         elm_naviframe_item_pop(ad->navibar);
178         setting_view_datausage_change_cycle.is_create = 0;
179         return SETTING_RETURN_SUCCESS;
180 }
181
182 static int __setting_datausage_change_cycle_update(void *cb)
183 {
184         SETTING_TRACE_BEGIN;
185         return SETTING_RETURN_SUCCESS;
186 }
187
188 static int __setting_datausage_change_cycle_cleanup(void *cb)
189 {
190         //error check
191         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
192         __setting_datausage_change_cycle_destroy(cb);
193         return SETTING_RETURN_SUCCESS;
194 }
195
196 /* ***************************************************
197 **
198 ** call back func
199 **
200 ** **************************************************/
201 static void __setting_datausage_change_cycle_back_cb(void *data, Evas_Object * obj, void *event_info)
202 {
203         //error check
204         ret_if(data == NULL);
205         SettingDatausageUG *ad = (SettingDatausageUG *) data;
206
207         setting_view_change(&setting_view_datausage_change_cycle, &setting_view_datausage_main, ad);
208 }