4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-network-con.h>
22 /*#include <tethering.h> */
24 static int setting_network_con_create(void *cb);
25 static int setting_network_con_destroy(void *cb);
26 static int setting_network_con_update(void *cb);
27 static int setting_network_con_cleanup(void *cb);
29 setting_view setting_view_network_con = {
30 .create = setting_network_con_create,
31 .destroy = setting_network_con_destroy,
32 .update = setting_network_con_update,
33 .cleanup = setting_network_con_cleanup,
36 static void __setting_network_con_genlist_create(void *data)
39 setting_retm_if(data == NULL, "data is NULL");
40 SettingNetworkUG *ad = (SettingNetworkUG *) data;
41 elm_genlist_clear(ad->connections_gl); /* first to clear list */
43 Elm_Object_Item *item = NULL;
44 item = elm_genlist_item_append(ad->connections_gl, &itc_seperator, NULL, NULL,
45 ELM_GENLIST_ITEM_NONE, NULL, NULL);
46 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
48 /* scroller is a genlist */
50 /* [UI] Internet Connections */
51 SETTING_TRACE("ad->apn_internet:%d, ad->apn_MMS:%d", ad->apn_internet, ad->apn_MMS);
52 ad->apn_internet = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, ad);
53 Setting_GenGroupItem_Data *internet_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
54 setting_network_con_item_Gendial_mouse_up_cb,
55 ad, SWALLOW_Type_INVALID, NULL, NULL,
56 0, "IDS_ST_BODY_INTERNET_CONNECTION",
57 g_strdup(ad->apn_internet), NULL);
59 SETTING_TRACE_ERROR("internet_conn is NULL");
61 ad->internet_conn = internet_conn;
65 ad->apn_MMS = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_MMS, ad);
66 /* [MMS Connections] Internet Connections */
67 Setting_GenGroupItem_Data *mms_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
68 setting_network_con_item_Gendial_mouse_up_cb,
69 ad, SWALLOW_Type_INVALID, NULL, NULL,
70 0, STR_SETTING_MMS_CONNECTIONS,
71 g_strdup(ad->apn_MMS), NULL);
72 ad->mms_conn = mms_conn;
75 #ifdef ENABLED_PREFERRED_NETWORKS
76 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
77 setting_network_con_item_Gendial_mouse_up_cb,
78 ad, SWALLOW_Type_INVALID, NULL, NULL,
79 0, "IDS_ST_BODY_PREFERRED_NETWORKS",
82 #ifdef ENABLED_2G3G_NETWORK
83 /* create 3g connection option */
84 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
85 setting_network_con_item_Gendial_mouse_up_cb,
86 ad, SWALLOW_Type_INVALID, NULL, NULL,
87 0, "2G/3G Connection", NULL, NULL);
93 if (ad->add_apn_timer) {
94 ecore_idler_del(ad->add_apn_timer);
95 ad->add_apn_timer = NULL;
97 ad->add_apn_timer = ecore_timer_add(0.5, (Ecore_Task_Cb) __add_other_apn, ad);
102 /* __add_other_apn(ad); */
107 /* ***************************************************
111 ***************************************************/
113 static Evas_Object* ctxpopup;
116 ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
119 evas_object_del(ctxpopup);
124 move_more_ctxpopup(Evas_Object *ctxpopup)
131 /* We convince the top widget is a window */
132 win = elm_object_top_widget_get(ctxpopup);
133 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
134 pos = elm_win_rotation_get(win);
139 evas_object_move(ctxpopup, (w / 2), h);
142 evas_object_move(ctxpopup, (h / 2), w);
145 evas_object_move(ctxpopup, (h / 2), w);
151 naviframe_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
154 Evas_Object *ctxpopup = data;
155 move_more_ctxpopup(ctxpopup);
159 more_ctxpopup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
162 Evas_Object *nf = data;
163 evas_object_event_callback_del_full(nf, EVAS_CALLBACK_RESIZE, naviframe_resize_cb, ctxpopup);
167 win_rotation_changed_cb(void *data, Evas_Object *obj, void *event_info)
170 Evas_Object *ctxpopup = data;
171 move_more_ctxpopup(ctxpopup);
175 ctxpopup_item_select_cb(void *data, Evas_Object *obj, void *event_info)
179 retm_if(data == NULL, "Data parameter is NULL");
180 SettingNetworkUG *ad = (SettingNetworkUG *) data;
181 ad->popup_conreset = setting_create_popup(ad, ad->win_get,
182 NULL, _("IDS_ST_POP_RESET_TO_DEFAULT_Q"),
183 setting_network_con_reset_popup_cb,
185 2, _("IDS_ST_BUTTON_OK"), _("IDS_ST_BUTTON_CANCEL_ABB"));
187 if (ctxpopup != NULL) {
188 evas_object_del(ctxpopup);
194 /* Icon + Text (More button style : Naviframe Toolbar) */
195 static void create_ctxpopup_more_button_cb(void *data, Evas_Object *obj, void *event_info)
198 SettingNetworkUG *ad = (SettingNetworkUG *) data;
200 Evas_Object *nf = ad->navi_bar;
204 if (ctxpopup != NULL) {
205 evas_object_del(ctxpopup);
208 ctxpopup = elm_ctxpopup_add(nf);
209 elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
210 elm_object_style_set(ctxpopup, "more/default");
211 eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK, eext_ctxpopup_back_cb, NULL);
212 eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_MORE, eext_ctxpopup_back_cb, NULL);
213 evas_object_smart_callback_add(ctxpopup, "dismissed", ctxpopup_dismissed_cb, NULL);
214 evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL, more_ctxpopup_del_cb, nf);
215 evas_object_event_callback_add(nf, EVAS_CALLBACK_RESIZE, naviframe_resize_cb, ctxpopup);
217 /* We convince the top widget is a window */
218 win = elm_object_top_widget_get(nf);
219 evas_object_smart_callback_add(win, "rotation,changed", win_rotation_changed_cb, ctxpopup);
221 elm_ctxpopup_item_append(ctxpopup, _(KeyStr_Reset_Def), NULL, ctxpopup_item_select_cb, ad);
222 elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN);
223 move_more_ctxpopup(ctxpopup);
224 evas_object_show(ctxpopup);
230 static int setting_network_con_create(void *cb)
233 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
235 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
237 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
238 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
239 "Cannot set scroller object as contento of layout");
240 elm_genlist_mode_set(scroller, ELM_LIST_COMPRESS);
241 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
242 elm_object_style_set(scroller, "dialogue");
243 ad->connections_gl = scroller;
244 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
246 Elm_Object_Item *navi_it = setting_push_layout_navi_bar(_("IDS_ST_BODY_CONNECTIONS"),
247 NULL, /* ARROR BUTTON */
250 setting_network_con_click_softkey_cancel_cb,
252 setting_network_con_click_softkey_reset_cb,/*setting_network_con_click_softkey_create_cb, */
253 ad, scroller, ad->navi_bar, NULL);
255 elm_naviframe_item_pop_cb_set(navi_it, setting_network_con_click_softkey_cancel_cb, ad);
257 __setting_network_con_genlist_create(ad);
259 Evas_Object* btn = elm_button_add(ad->navi_bar);
260 elm_object_style_set(btn, "naviframe/more/default");
261 evas_object_smart_callback_add(btn, "clicked", create_ctxpopup_more_button_cb, ad);
262 elm_object_item_part_content_set(navi_it, "toolbar_more_btn", btn);
264 setting_view_network_con.is_create = 1;
267 return SETTING_RETURN_SUCCESS;
270 static int setting_network_con_destroy(void *cb)
274 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
276 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
278 /*FREE(ad->con_name); */
279 ad->connections_gl = NULL;
280 if (setting_view_network_con.is_create) {
281 if (ad->add_apn_timer) {
282 ecore_idler_del(ad->add_apn_timer);
283 ad->add_apn_timer = NULL;
286 elm_naviframe_item_pop(ad->navi_bar);
287 setting_view_network_con.is_create = 0;
289 SETTING_TRACE("why is this is_create == 0 ?? !!!");
293 return SETTING_RETURN_SUCCESS;
296 static int setting_network_con_update(void *cb)
299 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
300 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
301 __setting_network_con_genlist_create(ad);
302 return SETTING_RETURN_SUCCESS;
305 static int setting_network_con_cleanup(void *cb)
308 return setting_network_con_destroy(cb);
311 /* ***************************************************
315 ***************************************************/
317 /* ***************************************************
321 ***************************************************/
324 setting_network_con_item_Gendial_mouse_up_cb(void *data, Evas_Object *obj,
329 setting_retm_if(data == NULL, "Data parameter is NULL");
330 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
331 elm_genlist_item_selected_set(item, 0);
332 Setting_GenGroupItem_Data *list_item =
333 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
334 setting_retm_if(NULL == list_item, "list_item is NULL");
336 SettingNetworkUG *ad = (SettingNetworkUG *) data;
337 ad->profile_topper_view = NULL;
339 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
341 ad->profile_service_type = 0;
343 if (!safeStrCmp("IDS_COM_BODY_NETWORK_OPERATORS", list_item->keyStr)) {
344 setting_view_change(&setting_view_network_con,
345 &setting_view_network_select_network,
348 #ifdef ENABLED_PREFERRED_NETWORKS
349 else if (!safeStrCmp("IDS_ST_BODY_PREFERRED_NETWORKS",
350 list_item->keyStr)) {
355 setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value,
357 /** @todo check 'err' variable for exception handling */
358 SETTING_TRACE("INT_SLP_SETTING_SIM_SLOT value:%d", value);
360 case VCONFKEY_TELEPHONY_SIM_INSERTED:
361 /* To Recreate the view in order to search the perferred network again. */
362 /* ret = setting_view_destroy(&setting_view_network_preferred_network, ad); */
364 setting_view_change(&setting_view_network_con,
365 &setting_view_network_preferred_network,
370 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
372 setting_create_popup(NULL, ad->win_get,
373 NULL, _(""), NULL, 0, false, false, 0);/*this code is not used now, so remove the ID which is not in po file*/
375 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
376 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
381 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
382 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
384 setting_create_popup(NULL, ad->win_get,
385 NULL, _("IDS_SIM_BODY_INVALID_SIM_CARD"), NULL, 0, false, false, 0);
387 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
388 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
393 SETTING_TRACE("Unknown SIM information from vconf");
398 #ifdef ENABLED_2G3G_NETWORK
399 else if (!safeStrCmp("2G/3G Connection", list_item->keyStr)) {
400 setting_view_change(&setting_view_network_con,
401 &setting_view_network_3gcon, ad);
404 else if (!safeStrCmp("IDS_ST_BODY_INTERNET_CONNECTION", list_item->keyStr)) {/*connections.. */
407 SETTING_TRACE("list_item->keyStr:%s, ad->con_name:%s", list_item->keyStr, ad->con_name);
408 ad->con_name = strdup(list_item->keyStr);
409 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
410 setting_view_change(&setting_view_network_con,
411 &setting_view_network_con_list,
413 } else if (!safeStrCmp(STR_SETTING_MMS_CONNECTIONS, list_item->keyStr)) {
415 ad->profile_topper_view = &setting_view_network_con;
416 ad->con_name = strdup(STR_SETTING_MMS_CONNECTIONS);
417 ad->access_name = strdup(STR_SETTING_MMS_CONNECTIONS);
418 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
419 setting_view_create(&setting_view_network_connection_create, ad);
422 ad->profile_topper_view = &setting_view_network_con;
423 ad->con_name = strdup(list_item->sub_desc);
424 ad->access_name = strdup(list_item->sub_desc);
425 ad->profile_service_type = list_item->chk_status;
426 setting_view_create(&setting_view_network_connection_create, ad);
432 setting_network_con_click_softkey_reset_cb(void *data, Evas_Object *obj, void *event_info)
436 retm_if(data == NULL, "Data parameter is NULL");
438 SettingNetworkUG *ad = (SettingNetworkUG *) data;
440 ad->popup_conreset = setting_create_popup(ad, ad->win_get,
441 NULL, _("IDS_ST_POP_RESET_TO_DEFAULT_Q"),
442 setting_network_con_reset_popup_cb,
444 2, _("IDS_ST_BUTTON_OK"), _("IDS_ST_BUTTON_CANCEL_ABB"));
448 void _reset_do_default_cb(connection_error_e result, void *user_data)
451 setting_retm_if(NULL == user_data, "NULL == data");
452 SettingNetworkUG *ad = (SettingNetworkUG *) user_data;
454 if (ad->network_ug_pop) {
455 evas_object_del(ad->network_ug_pop);
456 ad->network_ug_pop = NULL;
459 if (ad->popup_conreset_complete) {
460 evas_object_del(ad->popup_conreset_complete);
461 ad->popup_conreset_complete = NULL;
464 if (result == CONNECTION_ERROR_NONE) {
465 SETTING_TRACE("reset successfully");
466 FREE(ad->apn_internet);
468 __setting_network_con_genlist_create(ad);
470 SETTING_TRACE_ERROR("failed to reset ret = %d", result);
475 setting_network_con_reset_popup_cb(void *data, Evas_Object *obj, void *event_info)
480 setting_retm_if(NULL == data, "NULL == data");
482 int response_type = btn_type(obj);
485 SettingNetworkUG *ad = (SettingNetworkUG *) data;
488 evas_object_del(ad->popup_conreset);
489 ad->popup_conreset = NULL;
492 if (response_type == POPUP_RESPONSE_OK) {
494 // waiting popup should be here
495 ad->popup_conreset_complete = setting_create_popup_with_progressbar(ad, ad->win_get,
496 PROGRESSBAR_STYLE, NULL, IDS_ST_SK2_PLEASE_WAIT, NULL, 3, TRUE, TRUE, 0);
498 if (ad->connection) {
499 ret = connection_reset_profile(ad->connection, CONNECTION_RESET_DEFAULT_PROFILE,
500 0, _reset_do_default_cb, ad);
501 if (CONNECTION_ERROR_NONE == ret) {
502 SETTING_TRACE("Reset successfully");
504 SETTING_TRACE("Failed to reset, ret = %d", ret);
513 setting_network_con_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
516 retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
518 SettingNetworkUG *ad = (SettingNetworkUG *) data;
520 setting_view_change(&setting_view_network_con,
521 &setting_view_network_main, ad);