Initialize Tizen 2.3
[apps/home/settings.git] / setting-network / src / setting-network-3gcon-option.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (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 #include <setting-network-3gcon-option.h>
18
19 static int setting_network_3gcon_create(void *cb);
20 static int setting_network_3gcon_destroy(void *cb);
21 static int setting_network_3gcon_update(void *cb);
22 static int setting_network_3gcon_cleanup(void *cb);
23
24 setting_view setting_view_network_3gcon = {
25         .create = setting_network_3gcon_create,
26         .destroy = setting_network_3gcon_destroy,
27         .update = setting_network_3gcon_update,
28         .cleanup = setting_network_3gcon_cleanup,
29 };
30
31 static void setting_network_3gcon_click_softkey_set_cb(void *data,
32                                                        Evas_Object *obj,
33                                                        void *event_info);
34 static void setting_network_3gcon_click_softkey_cancel_cb(void *data,
35                                                           Evas_Object *obj,
36                                                           void *event_info);
37
38 /* ***************************************************
39  *
40  *basic func
41  *
42  ***************************************************/
43
44 static int setting_network_3gcon_create(void *cb)
45 {
46         SETTING_TRACE_BEGIN;
47         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
48
49         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
50
51         Evas_Object *scroller;
52         setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
53                                              _("2G/3G connection"),
54                                              dgettext("sys_string", "IDS_COM_SK_CANCEL"),
55                                              dgettext("sys_string", "IDS_COM_SK_SET"),
56                                              setting_network_3gcon_click_softkey_cancel_cb,
57                                              setting_network_3gcon_click_softkey_set_cb,
58                                              ad, &scroller, ad->navi_bar);
59
60         /* scroller is a genlist */
61         ad->chk_3gcon = elm_radio_add(scroller);
62         elm_radio_state_value_set(ad->chk_3gcon, -1);
63
64         setting_create_Gendial_field_1radio(scroller, &itc_1text_1icon_2,
65                                             setting_mouse_up_Gendial_list_radio_cb,
66                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
67                                             ad->chk_3gcon,
68                                             SETTING_NETWORK_3GCON_NOT_USE,
69                                             "Do not use", NULL);
70
71         setting_create_Gendial_field_1radio(scroller, &itc_1text_1icon_2,
72                                             setting_mouse_up_Gendial_list_radio_cb,
73                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
74                                             ad->chk_3gcon,
75                                             SETTING_NETWORK_3GCON_ASK_ON_CON,
76                                             _("IDS_ST_BODY_USB_ASK_ON_CONNECTION"), NULL);
77         setting_create_Gendial_field_1radio(scroller, &itc_1text_1icon_2,
78                                             setting_mouse_up_Gendial_list_radio_cb,
79                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
80                                             ad->chk_3gcon,
81                                             SETTING_NETWORK_3GCON_USE_WO_ASK,
82                                             "Use without asking", NULL);
83
84         int value = -1;
85         int err = -1;
86         err = vconf_get_int(VCONFKEY_3G_ENABLE, &value);
87         if (err < 0) {
88                 elm_radio_value_set(ad->chk_3gcon,
89                                     SETTING_NETWORK_3GCON_NOT_USE);
90         } else {
91                 elm_radio_value_set(ad->chk_3gcon, value);
92         }
93
94         setting_view_network_3gcon.is_create = 1;
95
96         return SETTING_RETURN_SUCCESS;
97 }
98
99 static int setting_network_3gcon_destroy(void *cb)
100 {
101         SETTING_TRACE_BEGIN;
102         /* error check */
103         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
104
105         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
106
107         elm_naviframe_item_pop(ad->navi_bar);
108         setting_view_network_3gcon.is_create = 0;
109
110         return SETTING_RETURN_SUCCESS;
111 }
112
113 static int setting_network_3gcon_update(void *cb)
114 {
115         return SETTING_RETURN_SUCCESS;
116 }
117
118 static int setting_network_3gcon_cleanup(void *cb)
119 {
120         return setting_network_3gcon_destroy(cb);
121 }
122
123 /* ***************************************************
124  *
125  *general func
126  *
127  ***************************************************/
128
129 /* ***************************************************
130  *
131  *call back func
132  *
133  ***************************************************/
134
135 static void
136 setting_network_3gcon_click_softkey_set_cb(void *data, Evas_Object *obj,
137                                            void *event_info)
138 {
139         /* error check */
140         retm_if(data == NULL, "Data parameter is NULL");
141
142         SettingNetworkUG *ad = (SettingNetworkUG *) data;
143         int value;
144         int err;
145
146         value = elm_radio_value_get(ad->chk_3gcon);
147
148         err = vconf_set_int(VCONFKEY_3G_ENABLE, value);
149
150         if (err < 0) {
151                 SETTING_TRACE_DEBUG
152                     ("%s*** [ERR] Failed to set 3G connection option ***%s",
153                      SETTING_FONT_RED, SETTING_FONT_BLACK);
154         }
155
156         setting_view_change(&setting_view_network_3gcon,
157                             &setting_view_network_main, ad);
158 }
159
160 static void
161 setting_network_3gcon_click_softkey_cancel_cb(void *data, Evas_Object *obj,
162                                               void *event_info)
163 {
164         /* error check */
165         retm_if(data == NULL, "Data parameter is NULL");
166
167         SettingNetworkUG *ad = (SettingNetworkUG *) data;
168
169         setting_view_change(&setting_view_network_3gcon,
170                             &setting_view_network_main, ad);
171 }