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 Eina_Bool __add_other_apn(void *data) {
38 SettingNetworkUG *ad = (SettingNetworkUG *)data;
40 //show other APN whose type is not internet/APN
41 connection_profile_iterator_h profile_iter = NULL;
42 connection_profile_h profile_h = NULL;
44 char *profile_name = NULL;
46 bool profile_bhidden = false;
47 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
48 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
50 int rv = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
51 if (rv != CONNECTION_ERROR_NONE) {
52 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", rv);
53 ad->add_apn_timer = NULL;
59 Elm_Object_Item *last_item = NULL;
61 Setting_GenGroupItem_Data *item_data = NULL;
63 int before_groupstyle = SETTING_GROUP_STYLE_NONE;
65 while (connection_profile_iterator_has_next(profile_iter)) {
66 if (cnt >= MAX_PROFILE_NUM)
70 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
71 SETTING_TRACE_ERROR("Fail to get profile handle");
75 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
76 SETTING_TRACE_ERROR("Fail to get profile type");
79 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
80 SETTING_TRACE_ERROR("Fail to get service type");
84 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
85 SETTING_TRACE_ERROR("Fail to get profile name");
89 if (connection_profile_is_cellular_hidden(profile_h, &profile_bhidden) != CONNECTION_ERROR_NONE) {
90 SETTING_TRACE_ERROR("Fail to get profile hidden attr (true/false)");
94 if (connection_profile_get_cellular_apn(profile_h, &apn) != CONNECTION_ERROR_NONE) {
95 SETTING_TRACE_ERROR("Fail to get apn");
100 SETTING_TRACE("Record[%d:%s], profile_name:%s, profile_type:%d, service_type:%d",
101 cnt, apn, profile_name, profile_type, service_type);
102 if(CONNECTION_PROFILE_TYPE_CELLULAR != profile_type)
105 G_FREE(profile_name);
108 if ( profile_bhidden == false
109 && CONNECTION_CELLULAR_SERVICE_TYPE_MMS != service_type
110 && CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET != service_type) //unknow, match with ad->con_name
112 if ( before_groupstyle == SETTING_GROUP_STYLE_NONE )
114 last_item = elm_genlist_item_append(ad->connections_gl, &itc_seperator,
116 ELM_GENLIST_ITEM_NONE, NULL, NULL);
117 elm_genlist_item_select_mode_set(last_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
120 #ifdef SUPPORT_REVERSED_ORDER
121 item_data = setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
122 setting_network_con_item_Gendial_mouse_up_cb,
123 ad, SWALLOW_Type_INVALID, NULL, NULL,
127 item_data = calloc(1, sizeof(Setting_GenGroupItem_Data));
128 setting_retvm_if(!item_data, FALSE, "calloc failed");
129 item_data->keyStr = (char *)g_strdup(profile_name);
130 item_data->sub_desc = (char *)g_strdup(apn);
131 item_data->swallow_type = SWALLOW_Type_INVALID;
133 item_data->item = elm_genlist_item_insert_after(ad->connections_gl,
134 &itc_2text, item_data, NULL, last_item,
135 ELM_GENLIST_ITEM_NONE,
136 setting_network_con_item_Gendial_mouse_up_cb,ad);
138 last_item = item_data->item;
141 item_data->chk_status = service_type;//record the service type
144 if ( before_groupstyle == SETTING_GROUP_STYLE_NONE )
146 elm_object_item_signal_emit(item_data->item, "elm,state,top", "");
147 before_groupstyle = SETTING_GROUP_STYLE_TOP;
150 if ( before_groupstyle == SETTING_GROUP_STYLE_TOP )
152 elm_object_item_signal_emit(item_data->item, "elm,state,center", "");
153 before_groupstyle = SETTING_GROUP_STYLE_CENTER;
156 SETTING_TRACE("profile hidden attribute : %d ", profile_bhidden);
158 SETTING_TRACE("profile hidden attribute : %d ", profile_bhidden);
161 G_FREE(profile_name);
166 elm_object_item_signal_emit(item_data->item, "elm,state,normal", "");
167 } else if (item_cnt > 1) {
168 elm_object_item_signal_emit(item_data->item, "elm,state,bottom", "");
171 ad->add_apn_timer = NULL;
175 static void __setting_network_con_genlist_create(void *data)
178 setting_retm_if(data == NULL, "data is NULL");
179 SettingNetworkUG *ad = (SettingNetworkUG *) data;
180 elm_genlist_clear(ad->connections_gl); /* first to clear list */
182 Elm_Object_Item *item = NULL;
183 item = elm_genlist_item_append(ad->connections_gl, &itc_seperator, NULL, NULL,
184 ELM_GENLIST_ITEM_NONE, NULL, NULL);
185 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
187 /* scroller is a genlist */
189 /* [UI] Internet Connections */
190 SETTING_TRACE("ad->apn_internet:%d, ad->apn_MMS:%d", ad->apn_internet, ad->apn_MMS);
191 ad->apn_internet = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, ad);
192 Setting_GenGroupItem_Data * internet_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
193 setting_network_con_item_Gendial_mouse_up_cb,
194 ad, SWALLOW_Type_INVALID, NULL, NULL,
195 0, "IDS_ST_BODY_INTERNET_CONNECTION",
196 g_strdup(ad->apn_internet), NULL);
198 //internet_conn->group_style = SETTING_GROUP_STYLE_NONE;
199 setting_genlist_item_groupstyle_set(internet_conn, SETTING_GROUP_STYLE_NONE);
201 SETTING_TRACE_ERROR("internet_conn is NULL");
203 ad->internet_conn = internet_conn;
206 setting_genlist_item_groupstyle_set(internet_conn, SETTING_GROUP_STYLE_TOP);
208 ad->apn_MMS = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_MMS, ad);
209 /* [MMS Connections] Internet Connections */
210 Setting_GenGroupItem_Data * mms_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
211 setting_network_con_item_Gendial_mouse_up_cb,
212 ad, SWALLOW_Type_INVALID, NULL, NULL,
213 0, STR_SETTING_MMS_CONNECTIONS,
214 g_strdup(ad->apn_MMS), NULL);
216 setting_genlist_item_groupstyle_set(mms_conn, SETTING_GROUP_STYLE_BOTTOM);
218 SETTING_TRACE_ERROR("mms_conn is NULL");
221 ad->mms_conn = mms_conn;
224 #ifdef ENABLED_PREFERRED_NETWORKS
225 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
226 setting_network_con_item_Gendial_mouse_up_cb,
227 ad, SWALLOW_Type_INVALID, NULL, NULL,
228 0, "IDS_ST_BODY_PREFERRED_NETWORKS",
231 #ifdef ENABLED_2G3G_NETWORK
232 /* create 3g connection option */
233 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
234 setting_network_con_item_Gendial_mouse_up_cb,
235 ad, SWALLOW_Type_INVALID, NULL, NULL,
236 0, "2G/3G Connection", NULL, NULL);
241 if (!ad->is_update) {
242 if (ad->add_apn_timer) {
243 ecore_idler_del(ad->add_apn_timer);
244 ad->add_apn_timer = NULL;
246 ad->add_apn_timer = ecore_timer_add(0.5, (Ecore_Task_Cb) __add_other_apn, ad);
251 // __add_other_apn(ad);
256 /* ***************************************************
260 ***************************************************/
265 static int setting_network_con_create(void *cb)
268 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
270 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
272 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
273 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
274 "Cannot set scroller object as contento of layout");
275 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
276 elm_object_style_set(scroller, "dialogue");
277 ad->connections_gl = scroller;
278 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
280 Elm_Object_Item * navi_it = setting_push_layout_navi_bar(_("IDS_ST_BODY_CONNECTIONS"),
281 _("IDS_COM_BODY_BACK"),
282 NULL,//_(KeyStr_Reset_Def),
283 _(KeyStr_Reset_Def),//_("IDS_COM_BODY_CREATE"),
285 NULL,//setting_network_con_click_softkey_reset_cb,
286 setting_network_con_click_softkey_reset_cb,//setting_network_con_click_softkey_create_cb,
287 ad, scroller, ad->navi_bar, NULL);
289 elm_naviframe_item_pop_cb_set(navi_it, setting_network_con_click_softkey_cancel_cb, ad);
291 __setting_network_con_genlist_create(ad);
293 setting_view_network_con.is_create = 1;
296 return SETTING_RETURN_SUCCESS;
299 static int setting_network_con_destroy(void *cb)
303 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
305 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
307 //FREE(ad->con_name);
308 ad->connections_gl = NULL;
309 if (setting_view_network_con.is_create)
311 #if SUPPORT_TETHERING
312 if (ad->th_connections)
314 SETTING_TRACE("tethering destruction ");
315 tethering_destroy(ad->th_connections);
316 ad->th_connections = NULL;
319 if (ad->add_apn_timer) {
320 ecore_idler_del(ad->add_apn_timer);
321 ad->add_apn_timer = NULL;
324 elm_naviframe_item_pop(ad->navi_bar);
325 setting_view_network_con.is_create = 0;
327 SETTING_TRACE("why is this is_create == 0 ?? !!!");
331 return SETTING_RETURN_SUCCESS;
334 static int setting_network_con_update(void *cb)
337 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
338 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
339 __setting_network_con_genlist_create(ad);
340 return SETTING_RETURN_SUCCESS;
343 static int setting_network_con_cleanup(void *cb)
346 return setting_network_con_destroy(cb);
349 /* ***************************************************
353 ***************************************************/
355 /* ***************************************************
359 ***************************************************/
362 setting_network_con_item_Gendial_mouse_up_cb(void *data, Evas_Object *obj,
367 setting_retm_if(data == NULL, "Data parameter is NULL");
368 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
369 elm_genlist_item_selected_set(item, 0);
370 Setting_GenGroupItem_Data *list_item =
371 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
373 SettingNetworkUG *ad = (SettingNetworkUG *) data;
374 ad->profile_topper_view = NULL;
376 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
378 ad->profile_service_type = 0;
380 if (!safeStrCmp("IDS_COM_BODY_NETWORK_OPERATORS", list_item->keyStr)) {
381 setting_view_change(&setting_view_network_con,
382 &setting_view_network_select_network,
385 #ifdef ENABLED_PREFERRED_NETWORKS
386 else if (!safeStrCmp("IDS_ST_BODY_PREFERRED_NETWORKS",
387 list_item->keyStr)) {
392 setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value,
394 /** @todo check 'err' variable for exception handling */
395 SETTING_TRACE("INT_SLP_SETTING_SIM_SLOT value:%d", value);
397 case VCONFKEY_TELEPHONY_SIM_INSERTED:
398 /* To Recreate the view in order to search the perferred network again. */
399 /* ret = setting_view_destroy(&setting_view_network_preferred_network, ad); */
401 setting_view_change(&setting_view_network_con,
402 &setting_view_network_preferred_network,
407 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
409 setting_create_simple_popup(NULL, ad->win_get,
410 NULL, _(""));/*this code is not used now, so remove the ID which is not in po file*/
412 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
413 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
418 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
419 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
421 setting_create_simple_popup(NULL, ad->win_get,
422 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
424 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
425 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
430 SETTING_TRACE("Unknown SIM information from vconf");
435 #ifdef ENABLED_2G3G_NETWORK
436 else if (!safeStrCmp("2G/3G Connection", list_item->keyStr)) {
437 setting_view_change(&setting_view_network_con,
438 &setting_view_network_3gcon, ad);
441 else if (!safeStrCmp("IDS_ST_BODY_INTERNET_CONNECTION", list_item->keyStr)) {//connections..
444 SETTING_TRACE("list_item->keyStr:%s, ad->con_name:%s", list_item->keyStr, ad->con_name);
445 ad->con_name = strdup(list_item->keyStr);
446 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
447 setting_view_change(&setting_view_network_con,
448 &setting_view_network_con_list,
451 else if (!safeStrCmp(STR_SETTING_MMS_CONNECTIONS, list_item->keyStr))
454 ad->profile_topper_view = &setting_view_network_con;
455 ad->con_name = strdup(STR_SETTING_MMS_CONNECTIONS);
456 ad->access_name = strdup(STR_SETTING_MMS_CONNECTIONS);
457 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
458 setting_view_create(&setting_view_network_connection_create, ad);
463 ad->profile_topper_view = &setting_view_network_con;
464 ad->con_name = strdup(list_item->sub_desc);
465 ad->access_name = strdup(list_item->sub_desc);
466 ad->profile_service_type = list_item->chk_status;
467 setting_view_create(&setting_view_network_connection_create, ad);
473 setting_network_con_click_softkey_reset_cb(void *data, Evas_Object *obj, void *event_info)
477 retm_if(data == NULL, "Data parameter is NULL");
479 SettingNetworkUG *ad = (SettingNetworkUG *) data;
481 ad->popup_conreset = setting_create_popup_with_btn(ad, ad->win_get,
482 NULL, _("IDS_ST_POP_RESET_TO_DEFAULT_Q"),
483 setting_network_con_reset_popup_cb,
484 0, 2, _("IDS_ST_BUTTON_OK"), _("IDS_COM_SK_CANCEL"));
489 void _reset_cb(connection_error_e result, void* user_data) {
491 setting_retm_if(NULL == user_data, "NULL == data");
492 SettingNetworkUG *ad = (SettingNetworkUG *) user_data;
494 if (ad->network_ug_pop) {
495 evas_object_del(ad->network_ug_pop);
496 ad->network_ug_pop = NULL;
498 if (result == CONNECTION_ERROR_NONE) {
499 SETTING_TRACE("reset successfully");
500 FREE(ad->apn_internet);
502 __setting_network_con_genlist_create(ad);
504 SETTING_TRACE_ERROR("failed to reset ret = %d", result);
509 setting_network_con_reset_popup_cb(void *data, Evas_Object *obj, void *event_info)
514 setting_retm_if(NULL == data, "NULL == data");
516 int response_type = btn_type( obj );
519 SettingNetworkUG *ad = (SettingNetworkUG *) data;
523 evas_object_del( ad->popup_conreset );
524 ad->popup_conreset = NULL;
527 if ( response_type == POPUP_RESPONSE_OK )
529 //setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_COM_POP_SUCCESS"));
530 setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_COM_POP_SUCCESS"),
531 NULL, POPUP_INTERVAL, TRUE, FALSE);
533 if ( ad->connection ) {
534 ret = connection_reset_profile(ad->connection, CONNECTION_RESET_DEFAULT_PROFILE,
536 if (CONNECTION_ERROR_NONE == ret) {
537 SETTING_TRACE("Reset successfully");
539 SETTING_TRACE("Failed to reset, ret = %d", ret);
549 setting_network_con_click_softkey_create_cb(void *data, Evas_Object *obj,
553 retm_if(data == NULL, "Data parameter is NULL");
554 SettingNetworkUG *ad = (SettingNetworkUG *) data;
556 //setting_create_simple_popup(ad, ad->win_get, NULL, _("UX Undefined"));
559 //to add a new connection
562 ad->con_name = strdup(STR_SETTING_NEW_CONNECTIONS);
563 ad->profile_topper_view = &setting_view_network_con;
564 //not normal view realtion,so need to change manully
565 //setting_view_change(&setting_view_network_con, &setting_view_network_connection_create, ad);
566 setting_view_create(&setting_view_network_connection_create, ad);
571 setting_network_con_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
574 retvm_if(data == NULL, EINA_FALSE,"Data parameter is NULL");
576 SettingNetworkUG *ad = (SettingNetworkUG *) data;
578 setting_view_change(&setting_view_network_con,
579 &setting_view_network_main, ad);