Initialize Tizen 2.3
[apps/home/settings.git] / setting-network / src / setting-network-preferred-network-new.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-preferred-network-new.h>
18 #include <setting-network-preferred-network.h>
19
20 static int setting_network_preferred_network_new_create(void *cb);
21 static int setting_network_preferred_network_new_destroy(void *cb);
22 static int setting_network_preferred_network_new_update(void *cb);
23 static int setting_network_preferred_network_new_cleanup(void *cb);
24
25 setting_view setting_view_network_preferred_network_new = {
26         .create = setting_network_preferred_network_new_create,
27         .destroy = setting_network_preferred_network_new_destroy,
28         .update = setting_network_preferred_network_new_update,
29         .cleanup = setting_network_preferred_network_new_cleanup,
30 };
31
32 /* ***************************************************
33  *
34  *basic func
35  *
36  ***************************************************/
37
38 static int setting_network_preferred_network_new_create(void *cb)
39 {
40         /* error check */
41         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
42         SETTING_TRACE_BEGIN;
43         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
44
45         Evas_Object *scroller = NULL;
46         /* Add basic layout */
47         setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
48                                              _("IDS_ST_HEADER_NEW_NETWORK"),
49                                              _("IDS_COM_SK_CANCEL"),
50                                              _("IDS_COM_SK_DONE"),
51                                              setting_network_preferred_network_new_click_softkey_cancel_cb,
52                                              setting_network_preffered_network_new_click_softkey_save_cb,
53                                              ad, &scroller, ad->navi_bar);
54         Elm_Object_Item *item = NULL;;
55
56         item =
57             elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
58                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
59         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
60
61         ad->data_new_mcc =
62             setting_create_Gendial_field_def(scroller,
63                                              &itc_1icon, NULL,
64                                              NULL, SWALLOW_Type_LAYOUT_ENTRY,
65                                              NULL, NULL, 0,
66                                              "IDS_ST_BODY_COUNTRY_CODE",
67                                              _("000"),
68                                              setting_network_preferred_network_new_entry_changed_cb);
69         if (ad->data_new_mcc) {
70                 ad->data_new_mcc->userdata = ad;
71                 ad->data_new_mcc->input_type = ELM_INPUT_PANEL_LAYOUT_NUMBERONLY;
72         } else {
73                 SETTING_TRACE_ERROR("ad->data_new_mcc is NULL");
74         }
75
76         ad->data_new_mnc =
77             setting_create_Gendial_field_def(scroller,
78                                              &itc_1icon, NULL,
79                                              NULL, SWALLOW_Type_LAYOUT_ENTRY,
80                                              NULL, NULL, 0,
81                                              "IDS_ST_BODY_NETWORK_CODE",
82                                              _("000"),
83                                              setting_network_preferred_network_new_entry_changed_cb);
84         if (ad->data_new_mnc) {
85                 ad->data_new_mnc->userdata = ad;
86                 ad->data_new_mnc->input_type = ELM_INPUT_PANEL_LAYOUT_NUMBERONLY;
87         } else {
88                 SETTING_TRACE_ERROR("ad->data_new_mnc is NULL");
89         }
90
91         (void)setting_create_Gendial_field_titleItem(scroller,
92                                                      &itc_group_item,
93                                                      "IDS_ST_BODY_NETWORK_TYPE",
94                                                      NULL);
95         ad->chk_new_type = elm_radio_add(scroller);
96         elm_radio_state_value_set(ad->chk_new_type, 0);
97
98         setting_create_Gendial_field_1radio(scroller, &itc_1text_1icon_2,
99                                             setting_mouse_up_Gendial_list_radio_cb,
100                                             ad->chk_new_type,
101                                             SWALLOW_Type_1RADIO,
102                                             ad->chk_new_type, 0, "IDS_ST_BODY_GSM", NULL);
103
104         setting_create_Gendial_field_1radio(scroller, &itc_1text_1icon_2,
105                                             setting_mouse_up_Gendial_list_radio_cb,
106                                             ad->chk_new_type,
107                                             SWALLOW_Type_1RADIO,
108                                             ad->chk_new_type, 1, "UMTS", NULL);
109         setting_view_network_preferred_network_new.is_create = 1;
110         return SETTING_RETURN_SUCCESS;
111 }
112
113 static int setting_network_preferred_network_new_destroy(void *cb)
114 {
115         /* error check */
116         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
117
118         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
119
120         elm_naviframe_item_pop(ad->navi_bar);
121         setting_view_network_preferred_network_new.is_create = 0;
122         return SETTING_RETURN_SUCCESS;
123 }
124
125 static int setting_network_preferred_network_new_update(void *cb)
126 {
127         return SETTING_RETURN_SUCCESS;
128 }
129
130 static int setting_network_preferred_network_new_cleanup(void *cb)
131 {
132         return setting_network_preferred_network_new_destroy(cb);
133 }
134
135 /* ***************************************************
136  *
137  *general func
138  *
139  ***************************************************/
140
141 /* ***************************************************
142  *
143  *call back func
144  *
145  ***************************************************/
146 static void
147 setting_network_preferred_network_new_entry_changed_cb(void *data,
148                                                        Evas_Object *obj,
149                                                        void *event_info)
150 {
151         retm_if(data == NULL, "Data parameter is NULL");
152         Setting_GenGroupItem_Data *list_item =
153             (Setting_GenGroupItem_Data *) data;
154         /* SettingNetworkUG *ad = list_item->userdata; */
155         const char *entry_str = elm_entry_entry_get(obj);
156         /* SETTING_TRACE("entry_str:%s", entry_str); */
157         list_item->sub_desc = (char *)g_strdup(entry_str);
158 }
159
160 static void
161 setting_network_preffered_network_new_click_softkey_save_cb(void *data,
162                                                             Evas_Object *obj,
163                                                             void *event_info)
164 {
165         SETTING_TRACE_BEGIN;
166         /* error check */
167         retm_if(data == NULL,
168                 "[Setting > Netwrok > Preferred New] Data parameter is NULL");
169
170         SettingNetworkUG *ad = (SettingNetworkUG *) data;
171
172         int tapi_ret = TAPI_API_SUCCESS;
173
174         TelNetworkPreferredPlmnInfo_t pref_plmn_info = { 0, };
175
176         int network_type = 0;
177         const char *mcc = NULL;
178         const char *mnc = NULL;
179         if (ad->data_new_mcc) {
180                 mcc = ad->data_new_mcc->sub_desc;
181         }
182         if (ad->data_new_mnc) {
183                 mnc = ad->data_new_mnc->sub_desc;
184         }
185
186         setting_retm_if(isEmptyStr(mcc)
187                         || isEmptyStr(mnc),
188                         "mcc or mnc got from editfiled error");
189         int mcc_len = strlen(mcc);
190         int mnc_len = strlen(mnc);
191         if (COUNTRY_CODE_LEN != mcc_len) {
192                 if ((NETWORK_CODE_LEN < mnc_len) || (mnc_len <= 0)) {
193                         setting_create_popup_without_btn(ad, ad->win_get,
194                                              NULL, _("please input country code made up of 3 digital number and network code made up of 1 ~ 3 digital number"),
195                                              NULL, POPUP_INTERVAL, FALSE, FALSE);
196                 } else {
197                         setting_create_popup_without_btn(ad, ad->win_get,
198                                              NULL, _("please input country code made up of 3 digital number"),
199                                              NULL, POPUP_INTERVAL, FALSE, FALSE);
200                 }
201                 return;
202         }
203
204         if ((NETWORK_CODE_LEN < mnc_len) || (mnc_len <= 0)) {
205                 setting_create_popup_without_btn(ad, ad->win_get,
206                                      NULL, _("please input network code made up of 1 ~ 3 digital number"),
207                                      NULL, POPUP_INTERVAL, FALSE, FALSE);
208                 return;
209         }
210
211         network_type = elm_radio_value_get(ad->chk_new_type);
212
213         /* save mcc, mnc */
214         safeCopyStr((char *)pref_plmn_info.Plmn, (char *)mcc, 3);
215         safeCopyStr((char *)pref_plmn_info.Plmn + 3, (char *)mnc, 3);
216
217         SETTING_TRACE_DEBUG("%s*** mcc=%s, mnc=%s, plmn=%s ***%s",
218                             SETTING_FONT_BGREEN, mcc, mnc,
219                             (char *)(pref_plmn_info.Plmn), SETTING_FONT_BLACK);
220
221         /* save network type */
222         if (network_type == 0) {
223                 pref_plmn_info.SystemType = TAPI_NETWORK_SYSTEM_GSM;
224         } else {
225                 pref_plmn_info.SystemType = TAPI_NETWORK_SYSTEM_UMTS;
226         }
227
228         pref_plmn_info.Index =
229             ad->pref_list.PrefPlmnRecord[ad->pref_list.NumOfPrefPlmns -
230                                           1].Index + 1;
231
232         ad->network_ug_pop =
233             setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_ST_POP_SAVING"),
234                                              NULL, 0.0, TRUE, TRUE);
235         tapi_ret =
236             tel_set_network_preferred_plmn(ad->handle, TAPI_NETWORK_PREF_PLMN_ADD,
237                                            &pref_plmn_info, setting_tapi_set_preferred_plmn_cb, ad);
238         if (tapi_ret != TAPI_API_SUCCESS) {
239                 SETTING_TRACE_DEBUG
240                     ("%s*** [ERR]  tel_set_network_preferred_plmn(PLMN_ADD) err=%d ***%s",
241                      SETTING_FONT_RED, tapi_ret, SETTING_FONT_BLACK);
242                 setting_create_popup_without_btn(ad, ad->win_get, NULL, _("Save Failed!"), NULL, POPUP_INTERVAL, FALSE, FALSE);
243         }
244
245         ad->op_type = SETTING_NETWORK_PREFERRED_NETWORK_NEW;
246 }
247
248 static void
249 setting_network_preferred_network_new_click_softkey_cancel_cb(void *data,
250                                                               Evas_Object *obj,
251                                                               void *event_info)
252 {
253         SettingNetworkUG *ad = (SettingNetworkUG *) data;
254
255         /* error check */
256         retm_if(data == NULL,
257                 "[Setting > Network > Preferred New] Data parameter is NULL");
258         ad->op_type = SETTING_NETWORK_PREFERRED_NETWORK_NONE;
259         setting_view_change(&setting_view_network_preferred_network_new,
260                             &setting_view_network_preferred_network, ad);
261 }