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