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)
39 SettingNetworkUG *ad = (SettingNetworkUG *)data;
41 /*show other APN whose type is not internet/APN */
42 connection_profile_iterator_h profile_iter = NULL;
43 connection_profile_h profile_h = NULL;
45 char *profile_name = NULL;
47 bool profile_bhidden = false;
48 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
49 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
51 int rv = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
52 if (rv != CONNECTION_ERROR_NONE) {
53 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", rv);
54 ad->add_apn_timer = NULL;
60 Elm_Object_Item *last_item = NULL;
62 Setting_GenGroupItem_Data *item_data = NULL;
64 int before_groupstyle = SETTING_GROUP_STYLE_NONE;
66 while (connection_profile_iterator_has_next(profile_iter)) {
67 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) {
104 G_FREE(profile_name);
107 if (profile_bhidden == false
108 && CONNECTION_CELLULAR_SERVICE_TYPE_MMS != service_type
109 && CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET != service_type) { /*unknow, match with ad->con_name */
110 if (before_groupstyle == SETTING_GROUP_STYLE_NONE) {
111 last_item = elm_genlist_item_append(ad->connections_gl, &itc_seperator,
113 ELM_GENLIST_ITEM_NONE, NULL, NULL);
114 elm_genlist_item_select_mode_set(last_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
117 #ifdef SUPPORT_REVERSED_ORDER
118 item_data = setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
119 setting_network_con_item_Gendial_mouse_up_cb,
120 ad, SWALLOW_Type_INVALID, NULL, NULL,
124 item_data = calloc(1, sizeof(Setting_GenGroupItem_Data));
125 setting_retvm_if(!item_data, FALSE, "calloc failed");
126 item_data->keyStr = (char *)g_strdup(profile_name);
127 item_data->sub_desc = (char *)g_strdup(apn);
128 item_data->swallow_type = SWALLOW_Type_INVALID;
130 item_data->item = elm_genlist_item_insert_after(ad->connections_gl,
131 &itc_2text, item_data, NULL, last_item,
132 ELM_GENLIST_ITEM_NONE,
133 setting_network_con_item_Gendial_mouse_up_cb, ad);
135 last_item = item_data->item;
138 item_data->chk_status = service_type;/*record the service type */
141 if (before_groupstyle == SETTING_GROUP_STYLE_NONE) {
142 elm_object_item_signal_emit(item_data->item, "elm,state,top", "");
143 before_groupstyle = SETTING_GROUP_STYLE_TOP;
144 } else if (before_groupstyle == SETTING_GROUP_STYLE_TOP) {
145 elm_object_item_signal_emit(item_data->item, "elm,state,center", "");
146 before_groupstyle = SETTING_GROUP_STYLE_CENTER;
149 SETTING_TRACE("profile hidden attribute : %d ", profile_bhidden);
151 SETTING_TRACE("profile hidden attribute : %d ", profile_bhidden);
154 G_FREE(profile_name);
159 elm_object_item_signal_emit(item_data->item, "elm,state,normal", "");
160 } else if (item_cnt > 1) {
161 elm_object_item_signal_emit(item_data->item, "elm,state,bottom", "");
164 ad->add_apn_timer = NULL;
168 static void __setting_network_con_genlist_create(void *data)
171 setting_retm_if(data == NULL, "data is NULL");
172 SettingNetworkUG *ad = (SettingNetworkUG *) data;
173 elm_genlist_clear(ad->connections_gl); /* first to clear list */
175 Elm_Object_Item *item = NULL;
176 item = elm_genlist_item_append(ad->connections_gl, &itc_seperator, NULL, NULL,
177 ELM_GENLIST_ITEM_NONE, NULL, NULL);
178 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
180 /* scroller is a genlist */
182 /* [UI] Internet Connections */
183 SETTING_TRACE("ad->apn_internet:%d, ad->apn_MMS:%d", ad->apn_internet, ad->apn_MMS);
184 ad->apn_internet = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, ad);
185 Setting_GenGroupItem_Data *internet_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
186 setting_network_con_item_Gendial_mouse_up_cb,
187 ad, SWALLOW_Type_INVALID, NULL, NULL,
188 0, "IDS_ST_BODY_INTERNET_CONNECTION",
189 g_strdup(ad->apn_internet), NULL);
191 /*internet_conn->group_style = SETTING_GROUP_STYLE_NONE; */
192 setting_genlist_item_groupstyle_set(internet_conn, SETTING_GROUP_STYLE_NONE);
194 SETTING_TRACE_ERROR("internet_conn is NULL");
196 ad->internet_conn = internet_conn;
199 setting_genlist_item_groupstyle_set(internet_conn, SETTING_GROUP_STYLE_TOP);
201 ad->apn_MMS = __get_profile_name(CONNECTION_CELLULAR_SERVICE_TYPE_MMS, ad);
202 /* [MMS Connections] Internet Connections */
203 Setting_GenGroupItem_Data *mms_conn = setting_create_Gendial_field_def(ad->connections_gl, &itc_2text_3,
204 setting_network_con_item_Gendial_mouse_up_cb,
205 ad, SWALLOW_Type_INVALID, NULL, NULL,
206 0, STR_SETTING_MMS_CONNECTIONS,
207 g_strdup(ad->apn_MMS), NULL);
209 setting_genlist_item_groupstyle_set(mms_conn, SETTING_GROUP_STYLE_BOTTOM);
211 SETTING_TRACE_ERROR("mms_conn is NULL");
214 ad->mms_conn = mms_conn;
217 #ifdef ENABLED_PREFERRED_NETWORKS
218 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
219 setting_network_con_item_Gendial_mouse_up_cb,
220 ad, SWALLOW_Type_INVALID, NULL, NULL,
221 0, "IDS_ST_BODY_PREFERRED_NETWORKS",
224 #ifdef ENABLED_2G3G_NETWORK
225 /* create 3g connection option */
226 setting_create_Gendial_field_def(ad->connections_gl, &itc_1text,
227 setting_network_con_item_Gendial_mouse_up_cb,
228 ad, SWALLOW_Type_INVALID, NULL, NULL,
229 0, "2G/3G Connection", NULL, NULL);
234 if (!ad->is_update) {
235 if (ad->add_apn_timer) {
236 ecore_idler_del(ad->add_apn_timer);
237 ad->add_apn_timer = NULL;
239 ad->add_apn_timer = ecore_timer_add(0.5, (Ecore_Task_Cb) __add_other_apn, ad);
244 /* __add_other_apn(ad); */
249 /* ***************************************************
253 ***************************************************/
258 static int setting_network_con_create(void *cb)
261 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
263 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
265 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
266 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
267 "Cannot set scroller object as contento of layout");
268 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
269 elm_object_style_set(scroller, "dialogue");
270 ad->connections_gl = scroller;
271 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
273 Elm_Object_Item *navi_it = setting_push_layout_navi_bar(_("IDS_ST_BODY_CONNECTIONS"),
274 _("IDS_COM_BODY_BACK"),
275 NULL,/*_(KeyStr_Reset_Def), */
276 _(KeyStr_Reset_Def),/*_("IDS_COM_BODY_CREATE"), */
278 NULL,/*setting_network_con_click_softkey_reset_cb, */
279 setting_network_con_click_softkey_reset_cb,/*setting_network_con_click_softkey_create_cb, */
280 ad, scroller, ad->navi_bar, NULL);
282 elm_naviframe_item_pop_cb_set(navi_it, setting_network_con_click_softkey_cancel_cb, ad);
284 __setting_network_con_genlist_create(ad);
286 setting_view_network_con.is_create = 1;
289 return SETTING_RETURN_SUCCESS;
292 static int setting_network_con_destroy(void *cb)
296 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
298 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
300 /*FREE(ad->con_name); */
301 ad->connections_gl = NULL;
302 if (setting_view_network_con.is_create) {
303 #if SUPPORT_TETHERING
304 if (ad->th_connections) {
305 SETTING_TRACE("tethering destruction ");
306 tethering_destroy(ad->th_connections);
307 ad->th_connections = NULL;
310 if (ad->add_apn_timer) {
311 ecore_idler_del(ad->add_apn_timer);
312 ad->add_apn_timer = NULL;
315 elm_naviframe_item_pop(ad->navi_bar);
316 setting_view_network_con.is_create = 0;
318 SETTING_TRACE("why is this is_create == 0 ?? !!!");
322 return SETTING_RETURN_SUCCESS;
325 static int setting_network_con_update(void *cb)
328 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
329 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
330 __setting_network_con_genlist_create(ad);
331 return SETTING_RETURN_SUCCESS;
334 static int setting_network_con_cleanup(void *cb)
337 return setting_network_con_destroy(cb);
340 /* ***************************************************
344 ***************************************************/
346 /* ***************************************************
350 ***************************************************/
353 setting_network_con_item_Gendial_mouse_up_cb(void *data, Evas_Object *obj,
358 setting_retm_if(data == NULL, "Data parameter is NULL");
359 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
360 elm_genlist_item_selected_set(item, 0);
361 Setting_GenGroupItem_Data *list_item =
362 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
364 SettingNetworkUG *ad = (SettingNetworkUG *) data;
365 ad->profile_topper_view = NULL;
367 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
369 ad->profile_service_type = 0;
371 if (!safeStrCmp("IDS_COM_BODY_NETWORK_OPERATORS", list_item->keyStr)) {
372 setting_view_change(&setting_view_network_con,
373 &setting_view_network_select_network,
376 #ifdef ENABLED_PREFERRED_NETWORKS
377 else if (!safeStrCmp("IDS_ST_BODY_PREFERRED_NETWORKS",
378 list_item->keyStr)) {
383 setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value,
385 /** @todo check 'err' variable for exception handling */
386 SETTING_TRACE("INT_SLP_SETTING_SIM_SLOT value:%d", value);
388 case VCONFKEY_TELEPHONY_SIM_INSERTED:
389 /* To Recreate the view in order to search the perferred network again. */
390 /* ret = setting_view_destroy(&setting_view_network_preferred_network, ad); */
392 setting_view_change(&setting_view_network_con,
393 &setting_view_network_preferred_network,
398 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
400 setting_create_simple_popup(NULL, ad->win_get,
401 NULL, _(""));/*this code is not used now, so remove the ID which is not in po file*/
403 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
404 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
409 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
410 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
412 setting_create_simple_popup(NULL, ad->win_get,
413 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
415 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
416 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
421 SETTING_TRACE("Unknown SIM information from vconf");
426 #ifdef ENABLED_2G3G_NETWORK
427 else if (!safeStrCmp("2G/3G Connection", list_item->keyStr)) {
428 setting_view_change(&setting_view_network_con,
429 &setting_view_network_3gcon, ad);
432 else if (!safeStrCmp("IDS_ST_BODY_INTERNET_CONNECTION", list_item->keyStr)) {/*connections.. */
435 SETTING_TRACE("list_item->keyStr:%s, ad->con_name:%s", list_item->keyStr, ad->con_name);
436 ad->con_name = strdup(list_item->keyStr);
437 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
438 setting_view_change(&setting_view_network_con,
439 &setting_view_network_con_list,
441 } else if (!safeStrCmp(STR_SETTING_MMS_CONNECTIONS, list_item->keyStr)) {
443 ad->profile_topper_view = &setting_view_network_con;
444 ad->con_name = strdup(STR_SETTING_MMS_CONNECTIONS);
445 ad->access_name = strdup(STR_SETTING_MMS_CONNECTIONS);
446 ad->profile_service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
447 setting_view_create(&setting_view_network_connection_create, ad);
450 ad->profile_topper_view = &setting_view_network_con;
451 ad->con_name = strdup(list_item->sub_desc);
452 ad->access_name = strdup(list_item->sub_desc);
453 ad->profile_service_type = list_item->chk_status;
454 setting_view_create(&setting_view_network_connection_create, ad);
460 setting_network_con_click_softkey_reset_cb(void *data, Evas_Object *obj, void *event_info)
464 retm_if(data == NULL, "Data parameter is NULL");
466 SettingNetworkUG *ad = (SettingNetworkUG *) data;
468 ad->popup_conreset = setting_create_popup_with_btn(ad, ad->win_get,
469 NULL, _("IDS_ST_POP_RESET_TO_DEFAULT_Q"),
470 setting_network_con_reset_popup_cb,
471 0, 2, _("IDS_ST_BUTTON_OK"), _("IDS_COM_SK_CANCEL"));
476 void _reset_cb(connection_error_e result, void *user_data)
479 setting_retm_if(NULL == user_data, "NULL == data");
480 SettingNetworkUG *ad = (SettingNetworkUG *) user_data;
482 if (ad->network_ug_pop) {
483 evas_object_del(ad->network_ug_pop);
484 ad->network_ug_pop = NULL;
486 if (result == CONNECTION_ERROR_NONE) {
487 SETTING_TRACE("reset successfully");
488 FREE(ad->apn_internet);
490 __setting_network_con_genlist_create(ad);
492 SETTING_TRACE_ERROR("failed to reset ret = %d", result);
497 setting_network_con_reset_popup_cb(void *data, Evas_Object *obj, void *event_info)
502 setting_retm_if(NULL == data, "NULL == data");
504 int response_type = btn_type(obj);
507 SettingNetworkUG *ad = (SettingNetworkUG *) data;
510 evas_object_del(ad->popup_conreset);
511 ad->popup_conreset = NULL;
514 if (response_type == POPUP_RESPONSE_OK) {
515 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_COM_POP_SUCCESS")); */
516 setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_COM_POP_SUCCESS"),
517 NULL, POPUP_INTERVAL, TRUE, FALSE);
519 if (ad->connection) {
520 ret = connection_reset_profile(ad->connection, CONNECTION_RESET_DEFAULT_PROFILE,
522 if (CONNECTION_ERROR_NONE == ret) {
523 SETTING_TRACE("Reset successfully");
525 SETTING_TRACE("Failed to reset, ret = %d", ret);
535 setting_network_con_click_softkey_create_cb(void *data, Evas_Object *obj,
539 retm_if(data == NULL, "Data parameter is NULL");
540 SettingNetworkUG *ad = (SettingNetworkUG *) data;
542 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("UX Undefined")); */
545 /*to add a new connection */
546 /*ad->con_type = -1; */
548 ad->con_name = strdup(STR_SETTING_NEW_CONNECTIONS);
549 ad->profile_topper_view = &setting_view_network_con;
550 /*not normal view realtion,so need to change manully */
551 /*setting_view_change(&setting_view_network_con, &setting_view_network_connection_create, ad); */
552 setting_view_create(&setting_view_network_connection_create, ad);
557 setting_network_con_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
560 retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
562 SettingNetworkUG *ad = (SettingNetworkUG *) data;
564 setting_view_change(&setting_view_network_con,
565 &setting_view_network_main, ad);