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