Merge "[security,password] remove unused code" into 2.0_beta
[apps/core/preloaded/settings.git] / setting-network / src / setting-network-preferred-network.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.h>
22
23 static int setting_network_preferred_network_create(void *cb);
24 static int setting_network_preferred_network_destroy(void *cb);
25 static int setting_network_preferred_network_update(void *cb);
26 static int setting_network_preferred_network_cleanup(void *cb);
27
28 setting_view setting_view_network_preferred_network = {
29         .create = setting_network_preferred_network_create,
30         .destroy = setting_network_preferred_network_destroy,
31         .update = setting_network_preferred_network_update,
32         .cleanup = setting_network_preferred_network_cleanup,
33 };
34
35 static void setting_network_preferred_network_Gendial_list_item_mouse_up_cb(void
36                                                                             *data,
37                                                                             Evas_Object
38                                                                             *obj,
39                                                                             void
40                                                                             *event_info);
41 static void setting_network_preferred_network_click_softkey_add_cb(void *data,
42                                                                    Evas_Object *
43                                                                    obj, void
44                                                                    *event_info);
45 static void setting_network_preferred_network_click_softkey_delete_cb(void
46                                                                       *data,
47                                                                       Evas_Object
48                                                                          *obj,
49                                                                       void
50                                                                       *event_info);
51 static void setting_network_preferred_network_click_softkey_back_cb(void *data,
52                                                                     Evas_Object
53                                                                          *obj, void
54                                                                     *event_info);
55 static void setting_network_preferred_network_click_ctxpopup_menu_1_cb(void
56                                                                        *data,
57                                                                        Evas_Object
58                                                                            *obj,
59                                                                        void
60                                                                        *event_info);
61 static void setting_network_preferred_network_click_ctxpopup_menu_2_cb(void
62                                                                        *data,
63                                                                        Evas_Object
64                                                                                 *obj,
65                                                                        void
66                                                                        *event_info);
67
68 static int setting_network_preferred_network_draw_network_list(void *data);
69
70 /* ***************************************************
71  *
72  *basic func
73  *
74  ***************************************************/
75
76 static int setting_network_preferred_network_create(void *cb)
77 {
78         SETTING_TRACE_BEGIN;
79         /* error check */
80         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
81         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
82
83         int tapi_ret = TAPI_API_SUCCESS;
84
85         bool keep = TRUE;
86         tapi_ret = tel_get_network_preferred_plmn(ad->handle, setting_tapi_get_preferred_plmn_cb, ad);
87         if (tapi_ret != TAPI_API_SUCCESS) {
88                 SETTING_TRACE_DEBUG
89                     ("%s*** [ERR] tel_get_network_preferred_plmn. err=%d ***%s",
90                      SETTING_FONT_RED, tapi_ret, SETTING_FONT_BLACK);
91                 keep = FALSE;
92         }
93
94         ad->scl_pref = elm_genlist_add(ad->win_main_layout);
95         elm_object_style_set(ad->scl_pref , "dialogue");
96         retvm_if(ad->scl_pref == NULL, SETTING_RETURN_FAIL,
97                  "Cannot set scroller object as contento of layout");
98         elm_genlist_clear(ad->scl_pref);        /* first to clear list */
99
100         setting_push_layout_navi_bar(_("IDS_ST_BODY_PREFERRED_NETWORKS"),
101                                      _("IDS_COM_BODY_BACK"), _("IDS_COM_ADD"),
102                                      _("IDS_COM_SK_DELETE"),
103                                      setting_network_preferred_network_click_softkey_back_cb,
104                                      setting_network_preferred_network_click_softkey_add_cb,
105                                      setting_network_preferred_network_click_softkey_delete_cb,
106                                      ad, ad->scl_pref, ad->navi_bar, NULL);
107
108         /* create preffered network list */
109         setting_network_preferred_network_draw_network_list(ad);
110         /* ad->pop_pref_sch = setting_network_preferred_network_create_search_popup(ad); */
111         ad->network_ug_pop =
112             setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_COM_POP_SEARCHING"),
113                                              NULL, 0.0, TRUE, TRUE);
114
115         setting_view_network_preferred_network.is_create = 1;
116
117         return SETTING_RETURN_SUCCESS;
118 }
119
120 static int setting_network_preferred_network_destroy(void *cb)
121 {
122         /* error check */
123         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
124
125         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
126         if (ad->popup) {
127                 evas_object_del(ad->popup);
128                 ad->popup = NULL;
129         }
130         elm_naviframe_item_pop(ad->navi_bar);
131         setting_view_network_preferred_network.is_create = 0;
132         return SETTING_RETURN_SUCCESS;
133 }
134
135 static int setting_network_preferred_network_update(void *cb)
136 {
137         /* error check */
138         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
139
140         SettingNetworkUG *ad = (SettingNetworkUG *) cb;
141
142         setting_network_preferred_network_refresh_view(ad);
143
144         return SETTING_RETURN_SUCCESS;
145 }
146
147 static int setting_network_preferred_network_cleanup(void *cb)
148 {
149         return setting_network_preferred_network_destroy(cb);
150 }
151
152 /* ***************************************************
153  *
154  *general func
155  *
156  ***************************************************/
157
158 int setting_network_preferred_network_refresh_view(void *data)
159 {
160         /* error check */
161         retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
162         SettingNetworkUG *ad = (SettingNetworkUG *) data;
163
164         setting_network_preferred_network_draw_network_list(ad);
165
166         return 0;
167 }
168
169 static int setting_network_preferred_network_draw_network_list(void *data)
170 {
171         /* error check */
172         retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
173         SettingNetworkUG *ad = (SettingNetworkUG *) data;
174
175         int i = 0;
176         elm_genlist_clear(ad->scl_pref);        /* first to clear list */
177         for (i = 0; i < ad->pref_list.NumOfPrefPlmns; i++) {
178                 setting_create_Gendial_field_def(ad->scl_pref, &itc_1text,
179                                                  setting_network_preferred_network_Gendial_list_item_mouse_up_cb,
180                                                  ad, SWALLOW_Type_INVALID, NULL,
181                                                  NULL, 0,
182                                                  ad->
183                                                  pref_list.PrefPlmnRecord
184                                                  [i].network_name, NULL, NULL);
185         }
186
187         return 0;
188 }
189
190 /* ***************************************************
191  *
192  *call back func
193  *
194  ***************************************************/
195
196 static void
197 setting_network_preferred_network_Gendial_list_item_mouse_up_cb(void *data,
198                                                                 Evas_Object *
199                                                                 obj, void
200                                                                 *event_info)
201 {
202         SETTING_TRACE_BEGIN;
203         /* error check */
204         setting_retm_if(data == NULL, "Data parameter is NULL");
205         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
206         elm_genlist_item_selected_set(item, 0);
207         Setting_GenGroupItem_Data *list_item =
208             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
209
210         SettingNetworkUG *ad = (SettingNetworkUG *) data;
211
212         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
213         int i;
214
215         for (i = 0; i < ad->pref_list.NumOfPrefPlmns; i++) {
216                 if (!safeStrCmp
217                     (ad->pref_list.PrefPlmnRecord[i].network_name,
218                      list_item->keyStr)) {
219                         break;
220                 }
221         }
222
223         SETTING_TRACE("i:%d", i);
224         ad->sel_pref_idx = ad->pref_list.PrefPlmnRecord[i].Index;
225         setting_view_change(&setting_view_network_preferred_network,
226                             &setting_view_network_preferred_network_edit, ad);
227 }
228
229 static void
230 setting_network_preferred_network_click_softkey_back_cb(void *data,
231                                                         Evas_Object *obj,
232                                                         void *event_info)
233 {
234         /* error check */
235         retm_if(data == NULL,
236                 "[Setting > Network > Preferred Net] Data parameter is NULL");
237         SettingNetworkUG *ad = (SettingNetworkUG *) data;
238
239         setting_view_change(&setting_view_network_preferred_network,
240                             &setting_view_network_main, ad);
241 }
242
243 static void
244 setting_network_preferred_network_click_ctxpopup_menu_1_cb(void *data,
245                                                            Evas_Object *obj,
246                                                            void *event_info)
247 {
248         /* error check */
249         retm_if(data == NULL,
250                 "[Setting > Network > Preferred Net] Data parameter is NULL");
251
252         SettingNetworkUG *ad = (SettingNetworkUG *) data;
253
254         evas_object_del(ad->popup);
255
256         setting_view_change(&setting_view_network_preferred_network,
257                             &setting_view_network_preferred_network_list, ad);
258 }
259
260 static void
261 setting_network_preferred_network_click_ctxpopup_menu_2_cb(void *data,
262                                                            Evas_Object *obj,
263                                                            void *event_info)
264 {
265         /* error check */
266         retm_if(data == NULL,
267                 "[Setting > Network > Preferred Net] Data parameter is NULL");
268
269         SettingNetworkUG *ad = (SettingNetworkUG *) data;
270
271         evas_object_del(ad->popup);
272
273         setting_view_change(&setting_view_network_preferred_network,
274                             &setting_view_network_preferred_network_new, ad);
275 }
276
277 static void
278 setting_network_preferred_network_click_softkey_add_cb(void *data,
279                                                        Evas_Object *obj,
280                                                        void *event_info)
281 {
282         SETTING_TRACE_BEGIN;
283         /* error check */
284         retm_if(data == NULL,
285                 "[Setting > Network > Preferred Net] Data parameter is NULL");
286
287         SettingNetworkUG *ad = (SettingNetworkUG *) data;
288
289         ad->popup = elm_ctxpopup_add(ad->navi_bar);
290         /* evas_object_smart_callback_add(ad->popup, "hide", _ctxpopup_cb, ad->popup); */
291
292         elm_ctxpopup_item_append(ad->popup, _("IDS_ST_BODY_NETWORK_LIST"), NULL,
293                                  setting_network_preferred_network_click_ctxpopup_menu_1_cb,
294                                  ad);
295         elm_ctxpopup_item_append(ad->popup, _("IDS_ST_POP_TEXT_NEW_NETWORK"),
296                                  NULL,
297                                  setting_network_preferred_network_click_ctxpopup_menu_2_cb,
298                                  ad);
299
300         evas_object_resize(ad->popup, 480 * WIDGET_SCALE_FACTOR,
301                            300 * WIDGET_SCALE_FACTOR);
302
303         Evas_Coord x, y, w, h;
304         evas_object_geometry_get(obj, &x, &y, &w, &h);
305         evas_object_move(ad->popup, (x + w / 2) * WIDGET_SCALE_FACTOR,
306                          (y + h) * WIDGET_SCALE_FACTOR);
307         evas_object_show(ad->popup);
308 }
309
310 static void
311 setting_network_preferred_network_click_softkey_delete_cb(void *data,
312                                                           Evas_Object *obj,
313                                                           void *event_info)
314 {
315         /* error check */
316         retm_if(data == NULL,
317                 "[Setting > Network > Preferred Net] Data parameter is NULL");
318
319         SettingNetworkUG *ad = (SettingNetworkUG *) data;
320
321         if (ad->pref_list.NumOfPrefPlmns == 0) {
322                 setting_create_simple_popup(ad, ad->win_get,
323                                             NULL, _("No Network to delete!"));
324         } else {
325                 setting_view_change(&setting_view_network_preferred_network,
326                                     &setting_view_network_preferred_network_delete,
327                                     ad);
328         }
329 }