apply FSL license
[apps/home/settings.git] / setting-network / src / setting-network-3gcon-option.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17
18 #include <setting-network-3gcon-option.h>
19
20 static int setting_network_3gcon_create(void *cb);
21 static int setting_network_3gcon_destroy(void *cb);
22 static int setting_network_3gcon_update(void *cb);
23 static int setting_network_3gcon_cleanup(void *cb);
24
25 setting_view setting_view_network_3gcon = {
26         .create = setting_network_3gcon_create,
27         .destroy = setting_network_3gcon_destroy,
28         .update = setting_network_3gcon_update,
29         .cleanup = setting_network_3gcon_cleanup,
30 };
31
32 static void setting_network_3gcon_click_softkey_set_cb(void *data,
33                                                        Evas_Object *obj,
34                                                        void *event_info);
35 static void setting_network_3gcon_click_softkey_cancel_cb(void *data,
36                                                           Evas_Object *obj,
37                                                           void *event_info);
38
39 /* ***************************************************
40  *
41  *basic func
42  *
43  ***************************************************/
44
45 static int setting_network_3gcon_create(void *cb)
46 {
47         SETTING_TRACE_BEGIN;
48         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
49
50         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
51
52         Evas_Object *scroller;
53         setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
54                                              _("2G/3G connection"),
55                                              dgettext("sys_string", "IDS_COM_SK_CANCEL"),
56                                              dgettext("sys_string", "IDS_COM_SK_SET"),
57                                              setting_network_3gcon_click_softkey_cancel_cb,
58                                              setting_network_3gcon_click_softkey_set_cb,
59                                              ad, &scroller, ad->navi_bar);
60
61         /* scroller is a genlist */
62         ad->chk_3gcon = elm_radio_add(scroller);
63         elm_radio_state_value_set(ad->chk_3gcon, -1);
64
65         setting_create_Gendial_field_1radio(scroller, &(ad->itc_1text_1icon_2),
66                                             setting_mouse_up_Gendial_list_radio_cb,
67                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
68                                             ad->chk_3gcon,
69                                             SETTING_NETWORK_3GCON_NOT_USE,
70                                             "Do not use", NULL);
71
72         setting_create_Gendial_field_1radio(scroller, &(ad->itc_1text_1icon_2),
73                                             setting_mouse_up_Gendial_list_radio_cb,
74                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
75                                             ad->chk_3gcon,
76                                             SETTING_NETWORK_3GCON_ASK_ON_CON,
77                                             _("IDS_ST_BODY_USB_ASK_ON_CONNECTION"), NULL);
78         setting_create_Gendial_field_1radio(scroller, &(ad->itc_1text_1icon_2),
79                                             setting_mouse_up_Gendial_list_radio_cb,
80                                             ad->chk_3gcon, SWALLOW_Type_1RADIO,
81                                             ad->chk_3gcon,
82                                             SETTING_NETWORK_3GCON_USE_WO_ASK,
83                                             "Use without asking", NULL);
84
85         int value = -1;
86         int err = -1;
87         err = vconf_get_int(VCONFKEY_3G_ENABLE, &value);
88         if (err < 0) {
89                 elm_radio_value_set(ad->chk_3gcon,
90                                     SETTING_NETWORK_3GCON_NOT_USE);
91         } else {
92                 elm_radio_value_set(ad->chk_3gcon, value);
93         }
94
95         setting_view_network_3gcon.is_create = 1;
96
97         return SETTING_RETURN_SUCCESS;
98 }
99
100 static int setting_network_3gcon_destroy(void *cb)
101 {
102         SETTING_TRACE_BEGIN;
103         /* error check */
104         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
105
106         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
107
108         elm_naviframe_item_pop(ad->navi_bar);
109         setting_view_network_3gcon.is_create = 0;
110
111         return SETTING_RETURN_SUCCESS;
112 }
113
114 static int setting_network_3gcon_update(void *cb)
115 {
116         return SETTING_RETURN_SUCCESS;
117 }
118
119 static int setting_network_3gcon_cleanup(void *cb)
120 {
121         return setting_network_3gcon_destroy(cb);
122 }
123
124 /* ***************************************************
125  *
126  *general func
127  *
128  ***************************************************/
129
130 /* ***************************************************
131  *
132  *call back func
133  *
134  ***************************************************/
135
136 static void
137 setting_network_3gcon_click_softkey_set_cb(void *data, Evas_Object *obj,
138                                            void *event_info)
139 {
140         /* error check */
141         retm_if(data == NULL, "Data parameter is NULL");
142
143         SettingNetworkUG *ad = (SettingNetworkUG *) data;
144         int value;
145         int err;
146
147         value = elm_radio_value_get(ad->chk_3gcon);
148
149         err = vconf_set_int(VCONFKEY_3G_ENABLE, value);
150
151         if (err < 0) {
152                 SETTING_TRACE_DEBUG
153                     ("%s*** [ERR] Failed to set 3G connection option ***%s",
154                      SETTING_FONT_RED, SETTING_FONT_BLACK);
155         }
156
157         setting_view_change(&setting_view_network_3gcon,
158                             &setting_view_network_main, ad);
159 }
160
161 static void
162 setting_network_3gcon_click_softkey_cancel_cb(void *data, Evas_Object *obj,
163                                               void *event_info)
164 {
165         /* error check */
166         retm_if(data == NULL, "Data parameter is NULL");
167
168         SettingNetworkUG *ad = (SettingNetworkUG *) data;
169
170         setting_view_change(&setting_view_network_3gcon,
171                             &setting_view_network_main, ad);
172 }