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-connection-create.h>
22 #define MAX_PDP_APN_LEN_MAX 100
23 #define MAX_PDP_AUTH_USERNAME_LEN_MAX 32
24 #define MAX_PDP_AUTH_PASSWORD_LEN_MAX 32
25 #define MAX_HOME_URL_LEN_MAX 512
26 #define MAX_PROXY_LEN_MAX 64
28 static int setting_network_connection_create(void *cb);
29 static int setting_network_connection_destroy(void *cb);
30 static int setting_network_connection_update(void *cb);
31 static int setting_network_connection_cleanup(void *cb);
33 setting_view setting_view_network_connection_create = {
34 .create = setting_network_connection_create,
35 .destroy = setting_network_connection_destroy,
36 .update = setting_network_connection_update,
37 .cleanup = setting_network_connection_cleanup,
40 SettingNetworkUG *g_networkUG = NULL;
41 #define SUPPORT_EXPANDABLE_AUTHTYPE 1
42 #define URL_HEAD "http://"
43 /* ***************************************************
47 ***************************************************/
50 __network_connection_gl_mouse_up(void *data, Evas *e, Evas_Object *obj,
55 SettingNetworkUG *ad = (SettingNetworkUG *) data;
57 if (ad->data_acs_name) {
58 setting_hide_input_pannel_cb(ad->data_acs_name->eo_check);
60 if (ad->data_user_name) {
61 setting_hide_input_pannel_cb(ad->data_user_name->eo_check);
64 setting_hide_input_pannel_cb(ad->data_pwd->eo_check);
66 if (ad->data_pxy_addr) {
67 setting_hide_input_pannel_cb(ad->data_pxy_addr->eo_check);
69 if (ad->data_pxy_port) {
70 setting_hide_input_pannel_cb(ad->data_pxy_port->eo_check);
72 if (ad->data_hm_url) {
73 setting_hide_input_pannel_cb(ad->data_hm_url->eo_check);
78 void __sub_list_rd_change(void *data, Evas_Object *obj, void *event_info)
81 retm_if(data == NULL, "Data parameter is NULL");
82 Setting_GenGroupItem_Data *list_item =
83 (Setting_GenGroupItem_Data *) data;
84 list_item->chk_status = elm_radio_value_get(obj); /* for update */
86 Elm_Object_Item *subItem = list_item->item;
87 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subItem);
89 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subItem); /* subItem data */
90 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
92 ret_if(NULL == data_subItem || NULL == data_parentItem);
94 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
95 elm_object_item_data_set(data_parentItem->item, data_parentItem);
96 elm_genlist_item_update(data_parentItem->item);
97 setting_network_edit_connection_display_auth_type
98 (data_parentItem->userdata, list_item->chk_status);
101 void __sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
105 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
106 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
107 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
108 elm_genlist_item_selected_set(subitem, 0);
109 Setting_GenGroupItem_Data *data_subItem =
110 elm_object_item_data_get(subitem);
111 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
112 ret_if(NULL == data_subItem || NULL == data_parentItem);
114 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
116 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
117 elm_object_item_data_set(data_parentItem->item, data_parentItem);
118 elm_genlist_item_update(data_parentItem->item);
119 setting_network_edit_connection_display_auth_type(data,
120 data_subItem->chk_status);
123 static void __setting_network_connection_exp_cb(void *data, Evas_Object *obj,
126 ret_if(NULL == data || NULL == event_info);
128 SettingNetworkUG *ad = (SettingNetworkUG *) data;
129 Elm_Object_Item *parentItem = event_info; /* parent item */
130 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
131 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
134 if (data_parentItem == ad->data_auth_type) {
135 rgd = elm_radio_add(scroller);
136 elm_radio_value_set(rgd, -1);
138 setting_create_Gendial_exp_sub_field(scroller,
139 &itc_1icon_1text_sub,
140 __sub_list_sel_cb, ad,
142 SWALLOW_Type_1RADIO, rgd,
143 CONNECTION_CELLULAR_AUTH_TYPE_PAP,
145 __sub_list_rd_change);
147 setting_create_Gendial_exp_sub_field(scroller,
148 &itc_1icon_1text_sub,
149 __sub_list_sel_cb, ad,
151 SWALLOW_Type_1RADIO, rgd,
152 CONNECTION_CELLULAR_AUTH_TYPE_CHAP,
154 __sub_list_rd_change);
156 setting_create_Gendial_exp_sub_field(scroller,
157 &itc_1icon_1text_sub,
158 __sub_list_sel_cb, ad,
160 SWALLOW_Type_1RADIO, rgd,
161 CONNECTION_CELLULAR_AUTH_TYPE_NONE,
163 __sub_list_rd_change);
165 elm_radio_value_set(rgd, ad->chkType);
169 static void __genlist_disable_set(Evas_Object *genlist, bool disabled)
173 Elm_Object_Item *item = elm_genlist_first_item_get(genlist);
174 for(;item != elm_genlist_last_item_get(genlist);
175 item = elm_genlist_item_next_get(item))
177 elm_object_item_disabled_set(item, disabled);
179 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
180 if (item_data == NULL) {
181 //SETTING_TRACE("item_data is null");
184 if (item_data->swallow_type == SWALLOW_Type_LAYOUT_ENTRY) {
185 elm_entry_context_menu_disabled_set(item_data->eo_check, disabled);
187 //elm_object_item_signal_emit(item, "elm,state,enabled", "elm");
189 elm_object_item_disabled_set(item, disabled);//the last one item
190 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
191 if (item_data == NULL) {
192 SETTING_TRACE("item_data is null");
195 if (item_data->swallow_type == SWALLOW_Type_LAYOUT_ENTRY) {
196 elm_entry_context_menu_disabled_set(item_data->eo_check, disabled);
199 static Eina_Bool __connection_idler(void *data)
202 retv_if (!data, FALSE);
203 SettingNetworkUG *ad = data;
204 __genlist_disable_set(ad->scl_edit, TRUE);
205 setting_network_connection_hide_input_pannel(ad);
208 void __get_connection_info(void *cb)
212 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
214 G_FREE(ad->ed_acs_name_desc);
215 G_FREE(ad->ed_user_name_desc);
216 G_FREE(ad->ed_pwd_desc);
218 G_FREE(ad->ed_pxy_addr_desc);
219 G_FREE(ad->ed_pxy_port_desc);
221 G_FREE(ad->ed_hm_url_desc);
222 ad->ed_auth_type_desc = NULL;
223 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
225 SETTING_TRACE("ad->con_name:%s", ad->con_name);
226 int ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
227 if (0 == safeStrCmp(ad->con_name,"IDS_ST_BODY_INTERNET_CONNECTION"))
229 ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
231 else if (0 == safeStrCmp(ad->con_name,STR_SETTING_MMS_CONNECTIONS))
233 ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
235 const char *con_name_utf8 = elm_entry_markup_to_utf8(ad->con_name);
238 //match with the correct profile
239 connection_profile_iterator_h profile_iter = NULL;
240 connection_profile_h profile_h = NULL;
241 char *profile_name = NULL;
243 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
244 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
245 int err = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
246 if (err != CONNECTION_ERROR_NONE) {
247 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", err);
254 while (connection_profile_iterator_has_next(profile_iter)) {
255 //reset and release..
257 G_FREE(profile_name);
259 if (cnt >= MAX_PROFILE_NUM || connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE)
264 connection_profile_get_type(profile_h, &profile_type);
265 connection_profile_get_cellular_service_type(profile_h, &service_type);
266 connection_profile_get_cellular_apn(profile_h, &apn);
267 connection_profile_get_name(profile_h, &profile_name);
268 SETTING_TRACE("Record[%d] apn[%s], profile_name[%s], profile_type[%d], service_type[%d]",
269 cnt, apn, profile_name, profile_type, service_type);
270 if(CONNECTION_PROFILE_TYPE_CELLULAR != profile_type)
273 if (CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION != service_type)
275 //match with ServiceType
276 if (ServiceType == service_type)
278 ad->sel_profile_h = profile_h;
283 else //the customer's profiles
285 if (0 == safeStrCmp(con_name_utf8, apn))
287 ad->sel_profile_h = profile_h;
295 if (found)//found sucessfully
297 SETTING_TRACE("found the following record:");
298 SETTING_TRACE("\tapn:%s", apn);
299 SETTING_TRACE("\tprofile_name:%s", profile_name);
300 SETTING_TRACE("\tservice_type:%d", service_type);
301 SETTING_TRACE("\tprofile_type:%d", profile_type);
302 /* load access name */
303 //ad->ed_acs_name_desc = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.Apn;
304 connection_profile_get_cellular_apn(ad->sel_profile_h, &(ad->ed_acs_name_desc));
305 /*ad->ed_user_name_desc =
306 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.UserName;
308 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.AuthType;
310 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.Password;*/
311 connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
312 connection_profile_get_cellular_auth_info(ad->sel_profile_h, &auth_type, &(ad->ed_user_name_desc), &(ad->ed_pwd_desc));
313 ad->chkType = auth_type;
315 switch (ad->chkType) {
316 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
317 ad->ed_auth_type_desc = _("IDS_ST_MBODY_PAP");
319 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
320 ad->ed_auth_type_desc = _("IDS_ST_POP_CHAP");
322 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
323 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
326 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
327 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
332 char *full_addr = NULL;
335 //Fix the Port 'NULL' issue when enter connection view repeatly..
336 connection_profile_get_proxy_address(ad->sel_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &full_addr);
337 char ProxyAddr[MAX_PROXY_LEN_MAX+1] = {0,};
338 safeCopyStr(ProxyAddr, full_addr, MAX_PROXY_LEN_MAX);
341 SETTING_TRACE("ProxyAddr:%s", ProxyAddr);
342 //several real format after removing "http://":
343 // ":80", "1.1.1.1:80","1.1.1.1: ", "127.0.0.1/", "127.0.0.1"
344 full_addr = ProxyAddr;
345 int url_head_len = strlen(URL_HEAD);
346 if (0 == safeStrNCmp(full_addr, URL_HEAD, url_head_len))
348 full_addr += url_head_len;
350 addr = strsep(&full_addr, ":");
351 if (NULL == full_addr)//format like "http://127.0.0.1/" or "http://127.0.0.1"
353 SETTING_TRACE("NULL == full_addr");
354 addr = strsep(&addr, "/");
356 if (is_ip_string(addr))
358 port = strsep(&full_addr, "/");
360 else //invalid format,let addr and port to be NULL.
364 SETTING_TRACE("addr:%s", addr);
365 SETTING_TRACE("port:%s", port);
366 ad->ed_pxy_addr_desc = g_strdup(addr);
367 ad->ed_pxy_port_desc = g_strdup(port);
368 //if (ad->con_type == NET_SERVICE_MMS) { /* Message Connection */
369 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* Message Connection */
370 //ad->ed_hm_url_desc = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.HomeURL;
371 connection_profile_get_cellular_home_url(ad->sel_profile_h, &(ad->ed_hm_url_desc));
374 SETTING_TRACE("Didn't find any record, to let add a new one:");
375 ad->sel_profile_h = NULL;
376 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
377 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
380 //release the memory..
382 G_FREE(profile_name);
385 void __update_genlist_info(void *cb)
389 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
390 if (ad->data_acs_name)
392 ad->data_acs_name->sub_desc = g_strdup(ad->ed_acs_name_desc);
395 if (ad->data_auth_type)
397 ad->data_auth_type->sub_desc = g_strdup(ad->ed_auth_type_desc);
398 if (ad->sel_profile_h) {
399 //int authType = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.AuthType;
400 connection_cellular_auth_type_e authType = 0;
403 connection_profile_get_cellular_auth_info(ad->sel_profile_h, &authType, &user_name, &pwd);
404 ad->chkType = !ad->chkType;
405 setting_network_edit_connection_display_auth_type(ad, authType);
408 if (ad->data_user_name)
410 ad->data_user_name->sub_desc = g_strdup(ad->ed_user_name_desc);
414 ad->data_pwd->sub_desc = g_strdup(ad->ed_pwd_desc);
417 if (ad->data_pxy_addr)
419 ad->data_pxy_addr->sub_desc = g_strdup(ad->ed_pxy_addr_desc);
421 if (ad->data_pxy_port)
423 ad->data_pxy_port->sub_desc = g_strdup(ad->ed_pxy_port_desc);
427 ad->data_hm_url->sub_desc = g_strdup(ad->ed_hm_url_desc);
429 elm_genlist_realized_items_update(ad->scl_edit);
433 static int setting_network_connection_create(void *cb)
436 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
438 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
440 setting_retvm_if(!ad->con_name, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "!ad->con_name")
442 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
443 elm_object_style_set(scroller, "dialogue");
444 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
445 "Cannot set scroller object as contento of layout");
446 elm_genlist_clear(scroller); /* first to clear list */
448 /* connection intializes */
449 ad->data_hm_url = NULL;
451 ad->data_user_name = NULL;
452 ad->data_pxy_addr = NULL;
453 ad->data_acs_name = NULL;
454 ad->data_auth_type = NULL;
456 ad->navi_it = setting_push_layout_navi_bar(_(ad->con_name),
457 _("IDS_COM_BODY_BACK"),
459 NULL,//_(KeyStr_Reset_Def),
460 setting_network_edit_connection_click_softkey_back_cb,
461 setting_network_edit_connection_click_softkey_eidt_cb,
463 ad, scroller, ad->navi_bar, NULL);
465 retv_if(!ad->navi_it, SETTING_RETURN_FAIL);
466 ad->has_form_changed = FALSE;
468 setting_enable_expandable_genlist(scroller, ad,
469 __setting_network_connection_exp_cb,
471 evas_object_event_callback_add(scroller, EVAS_CALLBACK_MOUSE_UP,
472 __network_connection_gl_mouse_up, ad);
473 __get_connection_info(ad);
474 Elm_Object_Item *item;
476 /* item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
478 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
479 ELM_GENLIST_ITEM_NONE, NULL, NULL);
480 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
482 setting_create_Gendial_field_def(scroller,
484 NULL, SWALLOW_Type_LAYOUT_ENTRY,
486 "IDS_ST_BODY_ACCESS_NAME",
487 (char *)ad->ed_acs_name_desc,
488 setting_network_connection_entry_changed_cb);
489 if (ad->data_acs_name) {
490 ad->data_acs_name->userdata = ad;
491 ad->data_acs_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
492 if (ad->data_acs_name->limit_filter_data) {
493 ad->data_acs_name->limit_filter_data->max_byte_count = MAX_PDP_APN_LEN_MAX - 1;
494 ad->data_acs_name->win_main = ad->win_get;
498 SETTING_TRACE_ERROR("ad->data_acs_name is NULL");
502 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
503 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
504 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
507 setting_create_Gendial_exp_parent_field(scroller,
510 SWALLOW_Type_INVALID,
511 "IDS_ST_BODY_AUTH_TYPE",
512 (char *)ad->ed_auth_type_desc);
513 /* ad->data_auth_type->int_slp_setting_binded = INT_SLP_SETTING_INVALID; */
514 if (ad->data_auth_type) {
515 ad->data_auth_type->userdata = ad;
517 SETTING_TRACE_ERROR("ad->data_auth_type is NULL");
520 ad->item_above_user_name = item =
521 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
522 ELM_GENLIST_ITEM_NONE, NULL, NULL);
523 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
525 ad->is_show_user = 0;
526 if (CONNECTION_CELLULAR_AUTH_TYPE_NONE != ad->chkType) {
528 setting_create_Gendial_field_def(scroller,
531 SWALLOW_Type_LAYOUT_ENTRY,
533 "IDS_COM_BODY_USER_NAME",
535 ad->ed_user_name_desc,
536 setting_network_connection_entry_changed_cb);
537 if (ad->data_user_name) {
538 ad->data_user_name->userdata = ad;
539 ad->data_user_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
540 if (ad->data_user_name->limit_filter_data) {
541 ad->data_user_name->limit_filter_data->max_byte_count = MAX_PDP_AUTH_USERNAME_LEN_MAX - 1;
542 ad->data_user_name->win_main = ad->win_get;
545 SETTING_TRACE_ERROR("ad->data_user_name is NULL");
549 setting_create_Gendial_field_def(scroller,
552 SWALLOW_Type_LAYOUT_ENTRY,
554 "IDS_COM_BODY_PASSWORD",
555 (char *)ad->ed_pwd_desc,
556 setting_network_connection_entry_changed_cb);
558 ad->data_pwd->userdata = ad;
559 ad->is_show_user = 1;
560 ad->data_pwd->isPasswordFlag = TRUE;
561 ad->data_pwd->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
562 if (ad->data_pwd->limit_filter_data) {
563 ad->data_pwd->limit_filter_data->max_byte_count = MAX_PDP_AUTH_PASSWORD_LEN_MAX - 1;
564 ad->data_pwd->win_main = ad->win_get;
567 SETTING_TRACE_ERROR("ad->data_pwd is NULL");
570 ad->item_above_proxy_add = item =
571 elm_genlist_item_append(scroller, &itc_seperator,
572 NULL, NULL, ELM_GENLIST_ITEM_NONE,
574 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
578 setting_create_Gendial_field_def(scroller,
580 NULL, SWALLOW_Type_LAYOUT_ENTRY,
582 "IDS_ST_BODY_CONNECTIONSETTINGS_PROXY_ADDRESS",
583 (char *)ad->ed_pxy_addr_desc,
584 setting_network_connection_entry_changed_cb);
585 if (ad->data_pxy_addr) {
586 ad->data_pxy_addr->userdata = ad;
587 ad->data_pxy_addr->input_type = ELM_INPUT_PANEL_LAYOUT_IP;
589 SETTING_TRACE_ERROR("ad->data_pxy_addr is NULL");
593 setting_create_Gendial_field_def(scroller,
595 NULL, SWALLOW_Type_LAYOUT_ENTRY,
597 "IDS_ST_BODY_PROXY_PORT",
598 (char *)ad->ed_pxy_port_desc,
599 setting_network_connection_entry_changed_cb);
600 if (ad->data_pxy_port) {
601 ad->data_pxy_port->userdata = ad;
602 ad->data_pxy_port->input_type = ELM_INPUT_PANEL_LAYOUT_NUMBERONLY;
604 SETTING_TRACE_ERROR("ad->data_pxy_port is NULL");
607 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* mms Connection */
609 setting_create_Gendial_field_def(scroller,
612 SWALLOW_Type_LAYOUT_ENTRY,
614 "IDS_ST_BODY_HOME_URL",
615 (char *)ad->ed_hm_url_desc,
616 setting_network_connection_entry_changed_cb);
617 if (ad->data_hm_url) {
618 ad->data_hm_url->userdata = ad;
619 ad->data_hm_url->input_type = ELM_INPUT_PANEL_LAYOUT_URL;
620 ad->data_hm_url->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
621 if (ad->data_hm_url->limit_filter_data) {
622 ad->data_hm_url->limit_filter_data->max_byte_count = MAX_HOME_URL_LEN_MAX - 1;
623 ad->data_hm_url->win_main = ad->win_get;
626 SETTING_TRACE_ERROR("ad->data_hm_url is NULL");
628 /* ad->is_show_url = 1; */
631 item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
632 ELM_GENLIST_ITEM_NONE, NULL, NULL);
633 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
635 setting_view_network_connection_create.is_create = 1;
636 ad->scl_edit = scroller;
637 __genlist_disable_set(ad->scl_edit, TRUE);
638 ecore_idler_add(__connection_idler, ad);
639 return SETTING_RETURN_SUCCESS;
642 static int setting_network_connection_destroy(void *cb)
646 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
648 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
650 ad->bottom_btn = NULL;
655 evas_object_del(ad->l_button);
660 evas_object_del(ad->m_button);
665 evas_object_del(ad->r_button);
669 G_FREE(ad->ed_acs_name_desc);
670 G_FREE(ad->ed_user_name_desc);
671 G_FREE(ad->ed_pwd_desc);
673 G_FREE(ad->ed_pxy_addr_desc);
674 G_FREE(ad->ed_pxy_port_desc);
676 G_FREE(ad->ed_hm_url_desc);
679 // connection_profile_destroy(ad->prof_list);
680 // ad->prof_list = NULL;
683 elm_naviframe_item_pop(ad->navi_bar);
684 setting_view_network_connection_create.is_create = 0;
685 return SETTING_RETURN_SUCCESS;
688 static int setting_network_connection_update(void *cb)
691 return SETTING_RETURN_SUCCESS;
694 static int setting_network_connection_cleanup(void *cb)
696 return setting_network_connection_destroy(cb);
699 /* ***************************************************
703 ***************************************************/
705 static int __save_connection(void *data)
709 retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
711 SettingNetworkUG *ad = (SettingNetworkUG *) data;
712 const char *acs_name = NULL;
713 const char *usr_name = NULL;
714 const char *pwd = NULL;
715 const char *addr = NULL;
716 const char *port = NULL;
717 const char *home = NULL;
719 if (ad->data_acs_name)
720 acs_name = elm_entry_markup_to_utf8(ad->data_acs_name->sub_desc);
721 if (ad->data_user_name)
722 usr_name = elm_entry_markup_to_utf8(ad->data_user_name->sub_desc);
724 pwd = elm_entry_markup_to_utf8(ad->data_pwd->sub_desc);
725 if (ad->data_pxy_addr)
726 addr = elm_entry_markup_to_utf8(ad->data_pxy_addr->sub_desc);
727 if (ad->data_pxy_port)
728 port = elm_entry_markup_to_utf8(ad->data_pxy_port->sub_desc);
731 acs_name = strdup("");
733 usr_name = strdup("");
740 SETTING_TRACE("acs_name:%s", acs_name);
741 SETTING_TRACE("usr_name:%s", usr_name);
742 SETTING_TRACE("pwd:%s", pwd);
744 SETTING_TRACE("addr:%s", addr);
745 SETTING_TRACE("port:%s", port);
746 SETTING_TRACE("home:%s", home);
748 char sz_text[MAX_PROXY_LEN_MAX + 1] = { 0, };
750 int ret = SETTING_RETURN_SUCCESS;
753 if (!safeStrCmp(acs_name, "")) {
754 setting_create_simple_popup(ad, ad->win_get,
755 NULL, _(Insert_Access_Name_desc));
761 return SETTING_DNET_RETURN_NULL_ACCESS_NAME;
763 //if (test_update_cellular_info(profile) == -1)
764 bool add_flag = FALSE;//add a new profile
765 connection_profile_h con_info = NULL;
766 if (ad->sel_profile_h) {
767 con_info = ad->sel_profile_h;
768 if(0 != safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)
769 && 0 != safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION"))
771 //need to change con_name
773 ad->con_name = strdup(acs_name);
775 SETTING_TRACE("ad->con_name:%s", ad->con_name);
778 SETTING_TRACE("ad->con_name:%s", ad->con_name);
779 if(!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS))
781 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
782 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
784 else if(!safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION"))
786 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
787 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
791 //need to change con_name
793 ad->con_name = strdup(acs_name);
794 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
795 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
798 SETTING_TRACE("ad->con_name:%s", ad->con_name);
802 /* save access name */
803 connection_profile_set_cellular_apn(con_info, acs_name);
807 /* type = elm_radio_value_get(ad->chk_type); */
810 if (!safeStrCmp(usr_name, "")
811 && CONNECTION_CELLULAR_AUTH_TYPE_NONE != type) {
812 setting_create_simple_popup(ad, ad->win_get,
813 NULL, _(Insert_User_Name_Desc));
818 return SETTING_DNET_RETURN_NULL_USER_NAME;
822 if (!safeStrCmp(pwd, "")
823 && CONNECTION_CELLULAR_AUTH_TYPE_NONE != type) {
824 setting_create_simple_popup(ad, ad->win_get,
825 NULL, _("IDS_ST_BODY_ENTER_PASSWORD"));
830 return SETTING_DNET_RETURN_NULL_PASSWORD;
833 connection_profile_set_cellular_auth_info(con_info, type, usr_name, pwd);
835 /* save proxy addr */
836 SETTING_TRACE("addr:port[%s:%s]", addr, port);
837 if (!safeStrCmp(addr, "")) {
838 /* check proxy port */
839 if (!safeStrCmp(port, ""))
841 //it is the normal case.
843 else //like ":80",it's forbiden
845 setting_create_simple_popup(ad, ad->win_get,
846 NULL, _("Incorrect proxy address, please add correct adress or clear the port field."));
851 return SETTING_DNET_RETURN_INVALID_PROXY_ADDR;
853 } else if (!is_ip_string(addr)) {
854 setting_create_simple_popup(ad, ad->win_get,
855 NULL, _("IDS_ST_HEADER_INCORRECT_PROXY_ADDRESS"));
860 return SETTING_DNET_RETURN_INVALID_PROXY_ADDR;
863 ret = snprintf(sz_text, sizeof(sz_text), "%s:%s", addr, port);
864 retv_if(ret < 0, SETTING_DNET_RETURN_ERR);
865 connection_profile_set_proxy_address(con_info, CONNECTION_ADDRESS_FAMILY_IPV4, sz_text);
867 /* save home url(message connection only) */
868 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* Message Connection */
869 home = elm_entry_markup_to_utf8(ad->data_hm_url->sub_desc);
870 if (home == (char *)NULL) {
871 connection_profile_set_cellular_home_url(con_info, URL_HEAD);
873 if (!safeStrCmp(home, "")) {
875 home = strdup(URL_HEAD);
876 ret = SETTING_DNET_RETURN_NULL_HOMEURL;
878 connection_profile_set_cellular_home_url(con_info, home);
880 } else if (!safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION")) {
883 //For internet, it needs call following api to set the default profile.
884 connection_set_default_cellular_service_profile(ad->connection, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, con_info);
893 //SETTING_TRACE("ad->con_type:%d", ad->con_type);
894 /* save connection */
896 //con_info->profile_type = NET_DEVICE_CELLULAR;
897 //con_info->ProfileState = NET_STATE_TYPE_UNKNOWN;
898 //con_info->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
899 err = connection_add_profile(ad->connection, con_info);
900 if (err != CONNECTION_ERROR_NONE) {
902 ("%s*** [ERR] connection_add_profile. err=%d ***%s",
903 SETTING_FONT_RED, err, SETTING_FONT_BLACK);
904 ret = SETTING_DNET_RETURN_ERR;
905 setting_create_simple_popup(ad, ad->win_get,
906 NULL, _("IDS_COM_POP_FAILED"));
909 connection_profile_destroy(con_info);
912 err = connection_update_profile(ad->connection, con_info);
913 if (err != CONNECTION_ERROR_NONE) {
915 ("%s*** [ERR] net_modify_profile. err=%d ***%s",
916 SETTING_FONT_RED, err, SETTING_FONT_BLACK);
917 ret = SETTING_DNET_RETURN_ERR;
918 setting_create_simple_popup(ad, ad->win_get,
919 NULL, _("IDS_COM_POP_FAILED"));
925 /* ***************************************************
929 ***************************************************/
931 setting_network_edit_connection_click_softkey_eidt_cb(void *data,
937 retm_if(data == NULL, "Data parameter is NULL");
939 SettingNetworkUG *ad = (SettingNetworkUG *) data;
940 //setting_enable_evas_object(ad->scl_edit);
941 __genlist_disable_set(ad->scl_edit, FALSE);
943 if (!ad->l_button) //go into first time
945 ad->l_button = setting_create_button(ad->navi_bar, _("IDS_COM_SK_DONE"),
946 "naviframe/title/icon/edit",
947 setting_network_edit_connection_click_softkey_save_cb,
951 if (!ad->r_button) //go into first time
953 ad->r_button = setting_create_button(ad->navi_bar, _("IDS_COM_SK_CANCEL"),
954 NAVI_BACK_BUTTON_STYLE,
955 setting_network_edit_connection_click_softkey_cancel_cb,
958 /*if (!ad->m_button) //go into first time
960 ad->m_button = setting_create_button(ad->navi_bar, NULL,
965 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_LEFT, ad->l_button);
966 evas_object_show(ad->l_button);
969 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_RIGHT, ad->r_button);
970 ad->has_form_changed = TRUE;//intialize
971 setting_network_connection_check_entry_empty(ad);
972 ad->has_form_changed = FALSE;//restore
974 /*if (ad->m_button) {
975 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_MORE, ad->m_button);
976 evas_object_show(ad->r_button);
980 ad->back_btn = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_PREV);
981 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_PREV, NULL);
982 evas_object_hide(ad->back_btn);
984 //remove other buttons
985 ad->bottom_btn = elm_object_item_part_content_unset(ad->navi_it, "toolbar_button1");
986 elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", NULL);
987 evas_object_hide(ad->bottom_btn);
992 setting_network_edit_connection_click_softkey_save_cb(void *data,
998 retm_if(data == NULL, "Data parameter is NULL");
1000 SettingNetworkUG *ad = (SettingNetworkUG *) data;
1001 /* elm_box_unpack_all(ad->bx_blk); */
1002 /* elm_dialoguegroup_remove_all(ad->dg_blk); */
1004 int ret = __save_connection(ad);
1005 /* need special handle */
1006 if (SETTING_DNET_RETURN_NULL_ACCESS_NAME == ret
1007 || SETTING_DNET_RETURN_NULL_USER_NAME == ret
1008 || SETTING_DNET_RETURN_NULL_PASSWORD == ret
1009 || SETTING_DNET_RETURN_INVALID_PROXY_ADDR == ret
1010 || SETTING_DNET_RETURN_ERR == ret) {
1013 if (ret != SETTING_RETURN_SUCCESS) {
1015 ("%s*** [ERR] __save_connection ***%s",
1016 SETTING_FONT_RED, SETTING_FONT_BLACK);
1019 setting_create_popup_without_btn(ad, ad->win_get, NULL, _(KeyStr_Saved), NULL, POPUP_INTERVAL, FALSE, FALSE);
1020 //re-fetch connection info..
1021 __get_connection_info(ad);
1024 elm_object_item_text_set(ad->navi_it, _(ad->con_name));
1025 setting_network_edit_connection_click_softkey_cancel_cb(ad, ad->r_button, NULL);
1029 setting_network_edit_connection_click_softkey_back_cb(void *data,
1033 SETTING_TRACE_BEGIN;
1035 retm_if(data == NULL, "Data parameter is NULL");
1037 SettingNetworkUG *ad = (SettingNetworkUG *) data;
1038 /* elm_box_unpack_all(ad->bx_blk); */
1039 /* elm_dialoguegroup_remove_all(ad->dg_blk); */
1040 setting_view_change(&setting_view_network_connection_create,
1041 &setting_view_network_con, ad);
1044 setting_network_edit_connection_click_softkey_cancel_cb(void *data,
1048 SETTING_TRACE_BEGIN;
1050 retm_if(data == NULL, "Data parameter is NULL");
1052 SettingNetworkUG *ad = (SettingNetworkUG *) data;
1053 ad->l_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_LEFT);
1054 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_LEFT, NULL);
1055 evas_object_hide(ad->l_button);
1057 ad->m_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_MORE);
1058 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_MORE, NULL);
1059 evas_object_hide(ad->m_button);*/
1061 ad->r_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_RIGHT);
1062 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_RIGHT, NULL);
1063 evas_object_hide(ad->r_button);
1064 //setting_disable_evas_object(ad->r_button);
1065 setting_undo_dim_evas_object(ad->r_button, TRUE);
1067 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_PREV, ad->back_btn);
1068 elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", ad->bottom_btn);
1069 evas_object_show(ad->back_btn);
1070 evas_object_show(ad->bottom_btn);
1072 __get_connection_info(ad);
1073 __update_genlist_info(ad);
1074 if(ad->data_auth_type) elm_genlist_item_expanded_set(ad->data_auth_type->item, FALSE);
1075 ecore_idler_add(__connection_idler, ad);
1077 static void _gl_Gendial_sel(void *data, Evas_Object *obj, void *event_info)
1079 /* SETTING_TRACE_BEGIN; */
1080 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1081 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1082 elm_genlist_item_selected_set(item, 0);
1086 static void setting_network_connection_check_entry_empty(SettingNetworkUG *ad)
1088 SETTING_TRACE_BEGIN;
1089 if (!ad->has_form_changed)
1091 SETTING_TRACE_DEBUG("ad->has_form_changed == FALSE!");
1094 bool isFoundEmptyEntry = FALSE;
1097 if (ad->data_acs_name && isEmptyStr(ad->data_acs_name->sub_desc)) {
1098 SETTING_TRACE("entry_str:%s", ad->data_acs_name->sub_desc);
1099 isFoundEmptyEntry = TRUE;
1102 if (ad->data_user_name && isEmptyStr(ad->data_user_name->sub_desc)) {
1103 SETTING_TRACE("entry_str:%s", ad->data_user_name->sub_desc);
1104 isFoundEmptyEntry = TRUE;
1107 if (ad->data_pwd && isEmptyStr(ad->data_pwd->sub_desc)) {
1108 SETTING_TRACE("entry_str:%s", ad->data_pwd->sub_desc);
1109 isFoundEmptyEntry = TRUE;
1112 if (ad->data_hm_url && isEmptyStr(ad->data_hm_url->sub_desc)) {
1113 SETTING_TRACE("entry_str:%s", ad->data_hm_url->sub_desc);
1114 isFoundEmptyEntry = TRUE;
1118 Evas_Object *done_btn = elm_object_item_part_content_get(ad->navi_it, NAVI_BTN_STYLE_LEFT);
1119 if (isFoundEmptyEntry) {
1120 if (!evas_object_pass_events_get(done_btn)) {//it had not yet been disabled
1121 setting_disable_evas_object(done_btn);
1122 setting_dim_evas_object(done_btn, TRUE);
1126 //do nothing..if invoke setting_dim_evas_object many times, the done button will be dimer until it cannot be see.
1127 //refer to the API of setting_dim_evas_object(). The API is supplied by Setting itself, winset doesn't support until now as I now.
1130 setting_enable_evas_object(done_btn);
1131 setting_undo_dim_evas_object(done_btn, TRUE);
1136 setting_network_edit_connection_display_auth_type(SettingNetworkUG *ad,
1139 SETTING_TRACE_BEGIN;
1140 retm_if(ad == NULL, "Data parameter is NULL");
1141 if (ad->chkType == auth_type) return;
1143 ad->chkType = auth_type; /* for update genlist */
1144 if (CONNECTION_CELLULAR_AUTH_TYPE_NONE != auth_type) { /* to show */
1145 SETTING_TRACE("ad->is_show_user:%d", ad->is_show_user);
1146 if (ad->is_show_user == 0) { /* do only when hiden */
1147 SETTING_TRACE("to create");
1149 ad->data_user_name =
1150 (Setting_GenGroupItem_Data *) calloc(1,
1152 (Setting_GenGroupItem_Data));
1153 setting_retm_if(ad->data_user_name == NULL, "calloc failed");
1154 ad->data_user_name->keyStr =
1155 (char *)g_strdup("IDS_COM_BODY_USER_NAME");
1156 ad->data_user_name->sub_desc =
1157 (char *)g_strdup(ad->ed_user_name_desc);
1158 ad->data_user_name->swallow_type =
1159 SWALLOW_Type_LAYOUT_ENTRY;
1160 ad->data_user_name->userdata = ad;
1161 ad->data_user_name->chk_change_cb =
1162 setting_network_connection_entry_changed_cb;
1163 ad->data_user_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
1164 if (ad->data_user_name->limit_filter_data) {
1165 ad->data_user_name->limit_filter_data->max_byte_count = MAX_PDP_AUTH_USERNAME_LEN_MAX - 1;
1166 ad->data_user_name->win_main = ad->win_get;
1168 ad->data_user_name->item =
1169 elm_genlist_item_insert_after(ad->scl_edit,
1173 ad->item_above_user_name,
1174 ELM_GENLIST_ITEM_NONE,
1175 _gl_Gendial_sel, ad);
1178 (Setting_GenGroupItem_Data *) calloc(1,
1180 (Setting_GenGroupItem_Data));
1182 setting_retm_if(ad->data_pwd == NULL, "calloc failed");
1183 ad->data_pwd->keyStr =
1184 (char *)g_strdup("IDS_COM_BODY_PASSWORD");
1185 ad->data_pwd->sub_desc =
1186 (char *)g_strdup(ad->ed_pwd_desc);
1187 ad->data_pwd->swallow_type = SWALLOW_Type_LAYOUT_ENTRY;
1188 ad->data_pwd->userdata = ad;
1189 ad->data_pwd->chk_change_cb =
1190 setting_network_connection_entry_changed_cb;
1191 ad->data_pwd->isPasswordFlag = TRUE;
1192 /* ad->data_pwd->chk_change_cb = chk_change_cb; */
1193 ad->data_pwd->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
1194 if (ad->data_pwd->limit_filter_data) {
1195 ad->data_pwd->limit_filter_data->max_byte_count = MAX_PDP_AUTH_PASSWORD_LEN_MAX - 1;
1196 ad->data_pwd->win_main = ad->win_get;
1198 ad->data_pwd->item =
1199 elm_genlist_item_insert_after(ad->scl_edit,
1203 data_user_name->item,
1204 ELM_GENLIST_ITEM_NONE,
1205 _gl_Gendial_sel, ad);
1207 ad->item_above_proxy_add =
1208 elm_genlist_item_insert_after(ad->scl_edit,
1212 ELM_GENLIST_ITEM_NONE,
1214 elm_genlist_item_select_mode_set
1215 (ad->item_above_proxy_add, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1217 ad->has_form_changed = TRUE;
1218 setting_network_connection_check_entry_empty(ad);
1219 /* ad->is_show_user = 1; */
1221 ad->is_show_user = 1;
1222 } else { /* to hide */
1224 SETTING_TRACE("ad->is_show_user:%d", ad->is_show_user);
1225 if (ad->is_show_user == 1) { /* do only when shown */
1226 SETTING_TRACE("to destroy");
1227 if (ad->data_user_name) {
1228 elm_object_item_del(ad->data_user_name->item);
1229 ad->data_user_name = NULL;
1232 elm_object_item_del(ad->data_pwd->item);
1233 ad->data_pwd = NULL;
1235 if (ad->item_above_proxy_add) {
1236 elm_object_item_del(ad->item_above_proxy_add);
1237 ad->item_above_proxy_add = NULL;
1241 ad->has_form_changed = TRUE;
1242 setting_network_connection_check_entry_empty(ad);
1243 ad->is_show_user = 0;
1249 setting_network_connection_entry_changed_cb(void *data, Evas_Object *obj,
1252 SETTING_TRACE_BEGIN;
1253 retm_if(data == NULL, "Data parameter is NULL");
1254 Setting_GenGroupItem_Data *list_item =
1255 (Setting_GenGroupItem_Data *) data;
1256 SettingNetworkUG *ad = list_item->userdata;
1257 const char *entry_str = elm_entry_entry_get(obj);
1258 list_item->sub_desc = (char *)g_strdup(entry_str);
1259 //SETTING_TRACE("list_item->sub_desc:%s", list_item->sub_desc);
1260 ad->has_form_changed = TRUE;
1261 setting_network_connection_check_entry_empty(ad);
1264 setting_network_connection_hide_input_pannel(void *data)
1266 SETTING_TRACE_BEGIN;
1267 retm_if(data == NULL, "Data parameter is NULL");
1268 SettingNetworkUG *ad = data;
1269 if (ad->data_acs_name) {
1270 setting_hide_input_pannel_cb(ad->data_acs_name->eo_check);
1272 if (ad->data_user_name) {
1273 setting_hide_input_pannel_cb(ad->data_user_name->eo_check);
1276 setting_hide_input_pannel_cb(ad->data_pwd->eo_check);
1278 if (ad->data_pxy_addr) {
1279 setting_hide_input_pannel_cb(ad->data_pxy_addr->eo_check);
1281 if (ad->data_pxy_port) {
1282 setting_hide_input_pannel_cb(ad->data_pxy_port->eo_check);
1284 if (ad->data_hm_url) {
1285 setting_hide_input_pannel_cb(ad->data_hm_url->eo_check);