3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (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
9 * http://floralicense.org/license/
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.
17 #include <setting-network-connection-create.h>
18 #define MAX_PDP_APN_LEN_MAX 100
19 #define MAX_PDP_AUTH_USERNAME_LEN_MAX 32
20 #define MAX_PDP_AUTH_PASSWORD_LEN_MAX 32
21 #define MAX_HOME_URL_LEN_MAX 512
22 #define MAX_PROXY_LEN_MAX 64
24 static int setting_network_connection_create(void *cb);
25 static int setting_network_connection_destroy(void *cb);
26 static int setting_network_connection_update(void *cb);
27 static int setting_network_connection_cleanup(void *cb);
29 setting_view setting_view_network_connection_create = {
30 .create = setting_network_connection_create,
31 .destroy = setting_network_connection_destroy,
32 .update = setting_network_connection_update,
33 .cleanup = setting_network_connection_cleanup,
36 SettingNetworkUG *g_networkUG = NULL;
37 #define SUPPORT_EXPANDABLE_AUTHTYPE 1
38 #define URL_HEAD "http://"
39 /* ***************************************************
43 ***************************************************/
46 __network_connection_gl_mouse_up(void *data, Evas *e, Evas_Object *obj,
51 SettingNetworkUG *ad = (SettingNetworkUG *) data;
53 if (ad->data_acs_name) {
54 setting_hide_input_pannel_cb(ad->data_acs_name->eo_check);
56 if (ad->data_user_name) {
57 setting_hide_input_pannel_cb(ad->data_user_name->eo_check);
60 setting_hide_input_pannel_cb(ad->data_pwd->eo_check);
62 if (ad->data_pxy_addr) {
63 setting_hide_input_pannel_cb(ad->data_pxy_addr->eo_check);
65 if (ad->data_pxy_port) {
66 setting_hide_input_pannel_cb(ad->data_pxy_port->eo_check);
68 if (ad->data_hm_url) {
69 setting_hide_input_pannel_cb(ad->data_hm_url->eo_check);
74 void __sub_list_rd_change(void *data, Evas_Object *obj, void *event_info)
77 retm_if(data == NULL, "Data parameter is NULL");
78 Setting_GenGroupItem_Data *list_item =
79 (Setting_GenGroupItem_Data *) data;
80 list_item->chk_status = elm_radio_value_get(obj); /* for update */
82 Elm_Object_Item *subItem = list_item->item;
83 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subItem);
85 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subItem); /* subItem data */
86 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
88 ret_if(NULL == data_subItem || NULL == data_parentItem);
90 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
91 elm_object_item_data_set(data_parentItem->item, data_parentItem);
92 elm_genlist_item_update(data_parentItem->item);
93 setting_network_edit_connection_display_auth_type
94 (data_parentItem->userdata, list_item->chk_status);
97 void __sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
101 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
102 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
103 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
104 elm_genlist_item_selected_set(subitem, 0);
105 Setting_GenGroupItem_Data *data_subItem =
106 elm_object_item_data_get(subitem);
107 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
108 ret_if(NULL == data_subItem || NULL == data_parentItem);
110 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
112 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
113 elm_object_item_data_set(data_parentItem->item, data_parentItem);
114 elm_genlist_item_update(data_parentItem->item);
115 setting_network_edit_connection_display_auth_type(data,
116 data_subItem->chk_status);
119 static void __setting_network_connection_exp_cb(void *data, Evas_Object *obj,
122 ret_if(NULL == data || NULL == event_info);
124 SettingNetworkUG *ad = (SettingNetworkUG *) data;
125 Elm_Object_Item *parentItem = event_info; /* parent item */
126 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
127 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
130 if (data_parentItem == ad->data_auth_type) {
131 rgd = elm_radio_add(scroller);
132 elm_radio_value_set(rgd, -1);
134 setting_create_Gendial_exp_sub_field(scroller,
135 &itc_1icon_1text_sub,
136 __sub_list_sel_cb, ad,
138 SWALLOW_Type_1RADIO, rgd,
139 CONNECTION_CELLULAR_AUTH_TYPE_PAP,
141 __sub_list_rd_change);
143 setting_create_Gendial_exp_sub_field(scroller,
144 &itc_1icon_1text_sub,
145 __sub_list_sel_cb, ad,
147 SWALLOW_Type_1RADIO, rgd,
148 CONNECTION_CELLULAR_AUTH_TYPE_CHAP,
150 __sub_list_rd_change);
152 setting_create_Gendial_exp_sub_field(scroller,
153 &itc_1icon_1text_sub,
154 __sub_list_sel_cb, ad,
156 SWALLOW_Type_1RADIO, rgd,
157 CONNECTION_CELLULAR_AUTH_TYPE_NONE,
159 __sub_list_rd_change);
161 elm_radio_value_set(rgd, ad->chkType);
165 static void __genlist_disable_set(Evas_Object *genlist, bool disabled)
169 Elm_Object_Item *item = elm_genlist_first_item_get(genlist);
170 for(;item != elm_genlist_last_item_get(genlist);
171 item = elm_genlist_item_next_get(item))
173 elm_object_item_disabled_set(item, disabled);
175 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
176 if (item_data == NULL) {
177 //SETTING_TRACE("item_data is null");
180 if (item_data->swallow_type == SWALLOW_Type_LAYOUT_ENTRY) {
181 elm_entry_context_menu_disabled_set(item_data->eo_check, disabled);
183 //elm_object_item_signal_emit(item, "elm,state,enabled", "elm");
185 elm_object_item_disabled_set(item, disabled);//the last one item
186 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
187 if (item_data == NULL) {
188 SETTING_TRACE("item_data is null");
191 if (item_data->swallow_type == SWALLOW_Type_LAYOUT_ENTRY) {
192 elm_entry_context_menu_disabled_set(item_data->eo_check, disabled);
195 static Eina_Bool __connection_idler(void *data)
198 retv_if (!data, FALSE);
199 SettingNetworkUG *ad = data;
200 __genlist_disable_set(ad->scl_edit, TRUE);
201 setting_network_connection_hide_input_pannel(ad);
204 void __get_connection_info(void *cb)
208 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
210 G_FREE(ad->ed_acs_name_desc);
211 G_FREE(ad->ed_user_name_desc);
212 G_FREE(ad->ed_pwd_desc);
214 G_FREE(ad->ed_pxy_addr_desc);
215 G_FREE(ad->ed_pxy_port_desc);
217 G_FREE(ad->ed_hm_url_desc);
218 ad->ed_auth_type_desc = NULL;
219 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
221 SETTING_TRACE("ad->con_name:%s", ad->con_name);
222 int ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
223 if (0 == safeStrCmp(ad->con_name,"IDS_ST_BODY_INTERNET_CONNECTION"))
225 ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
227 else if (0 == safeStrCmp(ad->con_name,STR_SETTING_MMS_CONNECTIONS))
229 ServiceType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
231 const char *con_name_utf8 = elm_entry_markup_to_utf8(ad->con_name);
234 //match with the correct profile
235 connection_profile_iterator_h profile_iter = NULL;
236 connection_profile_h profile_h = NULL;
237 char *profile_name = NULL;
239 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
240 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
241 int err = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
242 if (err != CONNECTION_ERROR_NONE) {
243 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", err);
250 while (connection_profile_iterator_has_next(profile_iter)) {
251 //reset and release..
253 G_FREE(profile_name);
255 if (cnt >= MAX_PROFILE_NUM || connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE)
260 connection_profile_get_type(profile_h, &profile_type);
261 connection_profile_get_cellular_service_type(profile_h, &service_type);
262 connection_profile_get_cellular_apn(profile_h, &apn);
263 connection_profile_get_name(profile_h, &profile_name);
264 SETTING_TRACE("Record[%d] apn[%s], profile_name[%s], profile_type[%d], service_type[%d]",
265 cnt, apn, profile_name, profile_type, service_type);
266 if(CONNECTION_PROFILE_TYPE_CELLULAR != profile_type)
269 if (CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION != service_type)
271 //match with ServiceType
272 if (ServiceType == service_type)
274 ad->sel_profile_h = profile_h;
279 else //the customer's profiles
281 if (0 == safeStrCmp(con_name_utf8, apn))
283 ad->sel_profile_h = profile_h;
291 if (found)//found sucessfully
293 SETTING_TRACE("found the following record:");
294 SETTING_TRACE("\tapn:%s", apn);
295 SETTING_TRACE("\tprofile_name:%s", profile_name);
296 SETTING_TRACE("\tservice_type:%d", service_type);
297 SETTING_TRACE("\tprofile_type:%d", profile_type);
298 /* load access name */
299 //ad->ed_acs_name_desc = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.Apn;
300 connection_profile_get_cellular_apn(ad->sel_profile_h, &(ad->ed_acs_name_desc));
301 /*ad->ed_user_name_desc =
302 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.UserName;
304 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.AuthType;
306 ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.Password;*/
307 connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
308 connection_profile_get_cellular_auth_info(ad->sel_profile_h, &auth_type, &(ad->ed_user_name_desc), &(ad->ed_pwd_desc));
309 ad->chkType = auth_type;
311 switch (ad->chkType) {
312 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
313 ad->ed_auth_type_desc = _("IDS_ST_MBODY_PAP");
315 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
316 ad->ed_auth_type_desc = _("IDS_ST_POP_CHAP");
318 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
319 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
322 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
323 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
328 char *full_addr = NULL;
331 //Fix the Port 'NULL' issue when enter connection view repeatly..
332 connection_profile_get_proxy_address(ad->sel_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &full_addr);
333 char ProxyAddr[MAX_PROXY_LEN_MAX+1] = {0,};
334 safeCopyStr(ProxyAddr, full_addr, MAX_PROXY_LEN_MAX);
337 SETTING_TRACE("ProxyAddr:%s", ProxyAddr);
338 //several real format after removing "http://":
339 // ":80", "1.1.1.1:80","1.1.1.1: ", "127.0.0.1/", "127.0.0.1"
340 full_addr = ProxyAddr;
341 int url_head_len = strlen(URL_HEAD);
342 if (0 == safeStrNCmp(full_addr, URL_HEAD, url_head_len))
344 full_addr += url_head_len;
346 addr = strsep(&full_addr, ":");
347 if (NULL == full_addr)//format like "http://127.0.0.1/" or "http://127.0.0.1"
349 SETTING_TRACE("NULL == full_addr");
350 addr = strsep(&addr, "/");
352 if (is_ip_string(addr))
354 port = strsep(&full_addr, "/");
356 else //invalid format,let addr and port to be NULL.
360 SETTING_TRACE("addr:%s", addr);
361 SETTING_TRACE("port:%s", port);
362 ad->ed_pxy_addr_desc = g_strdup(addr);
363 ad->ed_pxy_port_desc = g_strdup(port);
364 //if (ad->con_type == NET_SERVICE_MMS) { /* Message Connection */
365 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* Message Connection */
366 //ad->ed_hm_url_desc = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.HomeURL;
367 connection_profile_get_cellular_home_url(ad->sel_profile_h, &(ad->ed_hm_url_desc));
370 SETTING_TRACE("Didn't find any record, to let add a new one:");
371 ad->sel_profile_h = NULL;
372 ad->ed_auth_type_desc = _("IDS_COM_BODY_NONE");
373 ad->chkType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
376 //release the memory..
378 G_FREE(profile_name);
381 void __update_genlist_info(void *cb)
385 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
386 if (ad->data_acs_name)
388 ad->data_acs_name->sub_desc = g_strdup(ad->ed_acs_name_desc);
391 if (ad->data_auth_type)
393 ad->data_auth_type->sub_desc = g_strdup(ad->ed_auth_type_desc);
394 if (ad->sel_profile_h) {
395 //int authType = ad->prof_list[ad->prof_sel_idx].ProfileInfo.Pdp.AuthInfo.AuthType;
396 connection_cellular_auth_type_e authType = 0;
399 connection_profile_get_cellular_auth_info(ad->sel_profile_h, &authType, &user_name, &pwd);
400 ad->chkType = !ad->chkType;
401 setting_network_edit_connection_display_auth_type(ad, authType);
404 if (ad->data_user_name)
406 ad->data_user_name->sub_desc = g_strdup(ad->ed_user_name_desc);
410 ad->data_pwd->sub_desc = g_strdup(ad->ed_pwd_desc);
413 if (ad->data_pxy_addr)
415 ad->data_pxy_addr->sub_desc = g_strdup(ad->ed_pxy_addr_desc);
417 if (ad->data_pxy_port)
419 ad->data_pxy_port->sub_desc = g_strdup(ad->ed_pxy_port_desc);
423 ad->data_hm_url->sub_desc = g_strdup(ad->ed_hm_url_desc);
425 elm_genlist_realized_items_update(ad->scl_edit);
429 static int setting_network_connection_create(void *cb)
432 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
434 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
436 setting_retvm_if(!ad->con_name, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "!ad->con_name")
438 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
439 elm_object_style_set(scroller, "dialogue");
440 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
441 "Cannot set scroller object as contento of layout");
442 elm_genlist_clear(scroller); /* first to clear list */
444 /* connection intializes */
445 ad->data_hm_url = NULL;
447 ad->data_user_name = NULL;
448 ad->data_pxy_addr = NULL;
449 ad->data_acs_name = NULL;
450 ad->data_auth_type = NULL;
452 ad->navi_it = setting_push_layout_navi_bar(_(ad->con_name),
453 _("IDS_COM_BODY_BACK"),
455 NULL,//_(KeyStr_Reset_Def),
456 setting_network_edit_connection_click_softkey_back_cb,
457 setting_network_edit_connection_click_softkey_eidt_cb,
459 ad, scroller, ad->navi_bar, NULL);
461 retv_if(!ad->navi_it, SETTING_RETURN_FAIL);
462 ad->has_form_changed = FALSE;
464 setting_enable_expandable_genlist(scroller, ad,
465 __setting_network_connection_exp_cb,
467 evas_object_event_callback_add(scroller, EVAS_CALLBACK_MOUSE_UP,
468 __network_connection_gl_mouse_up, ad);
469 __get_connection_info(ad);
470 Elm_Object_Item *item;
472 /* item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
474 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
475 ELM_GENLIST_ITEM_NONE, NULL, NULL);
476 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
478 setting_create_Gendial_field_def(scroller,
480 NULL, SWALLOW_Type_LAYOUT_ENTRY,
482 "IDS_ST_BODY_ACCESS_NAME",
483 (char *)ad->ed_acs_name_desc,
484 setting_network_connection_entry_changed_cb);
485 if (ad->data_acs_name) {
486 ad->data_acs_name->userdata = ad;
487 ad->data_acs_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
488 if (ad->data_acs_name->limit_filter_data) {
489 ad->data_acs_name->limit_filter_data->max_byte_count = MAX_PDP_APN_LEN_MAX - 1;
490 ad->data_acs_name->win_main = ad->win_get;
494 SETTING_TRACE_ERROR("ad->data_acs_name is NULL");
498 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
499 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
500 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
503 setting_create_Gendial_exp_parent_field(scroller,
506 SWALLOW_Type_INVALID,
507 "IDS_ST_BODY_AUTH_TYPE",
508 (char *)ad->ed_auth_type_desc);
509 /* ad->data_auth_type->int_slp_setting_binded = INT_SLP_SETTING_INVALID; */
510 if (ad->data_auth_type) {
511 ad->data_auth_type->userdata = ad;
513 SETTING_TRACE_ERROR("ad->data_auth_type is NULL");
516 ad->item_above_user_name = item =
517 elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
518 ELM_GENLIST_ITEM_NONE, NULL, NULL);
519 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
521 ad->is_show_user = 0;
522 if (CONNECTION_CELLULAR_AUTH_TYPE_NONE != ad->chkType) {
524 setting_create_Gendial_field_def(scroller,
527 SWALLOW_Type_LAYOUT_ENTRY,
529 "IDS_COM_BODY_USER_NAME",
531 ad->ed_user_name_desc,
532 setting_network_connection_entry_changed_cb);
533 if (ad->data_user_name) {
534 ad->data_user_name->userdata = ad;
535 ad->data_user_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
536 if (ad->data_user_name->limit_filter_data) {
537 ad->data_user_name->limit_filter_data->max_byte_count = MAX_PDP_AUTH_USERNAME_LEN_MAX - 1;
538 ad->data_user_name->win_main = ad->win_get;
541 SETTING_TRACE_ERROR("ad->data_user_name is NULL");
545 setting_create_Gendial_field_def(scroller,
548 SWALLOW_Type_LAYOUT_ENTRY,
550 "IDS_COM_BODY_PASSWORD",
551 (char *)ad->ed_pwd_desc,
552 setting_network_connection_entry_changed_cb);
554 ad->data_pwd->userdata = ad;
555 ad->is_show_user = 1;
556 ad->data_pwd->isPasswordFlag = TRUE;
557 ad->data_pwd->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
558 if (ad->data_pwd->limit_filter_data) {
559 ad->data_pwd->limit_filter_data->max_byte_count = MAX_PDP_AUTH_PASSWORD_LEN_MAX - 1;
560 ad->data_pwd->win_main = ad->win_get;
563 SETTING_TRACE_ERROR("ad->data_pwd is NULL");
566 ad->item_above_proxy_add = item =
567 elm_genlist_item_append(scroller, &itc_seperator,
568 NULL, NULL, ELM_GENLIST_ITEM_NONE,
570 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
574 setting_create_Gendial_field_def(scroller,
576 NULL, SWALLOW_Type_LAYOUT_ENTRY,
578 "IDS_ST_BODY_CONNECTIONSETTINGS_PROXY_ADDRESS",
579 (char *)ad->ed_pxy_addr_desc,
580 setting_network_connection_entry_changed_cb);
581 if (ad->data_pxy_addr) {
582 ad->data_pxy_addr->userdata = ad;
583 ad->data_pxy_addr->input_type = ELM_INPUT_PANEL_LAYOUT_IP;
585 SETTING_TRACE_ERROR("ad->data_pxy_addr is NULL");
589 setting_create_Gendial_field_def(scroller,
591 NULL, SWALLOW_Type_LAYOUT_ENTRY,
593 "IDS_ST_BODY_PROXY_PORT",
594 (char *)ad->ed_pxy_port_desc,
595 setting_network_connection_entry_changed_cb);
596 if (ad->data_pxy_port) {
597 ad->data_pxy_port->userdata = ad;
598 ad->data_pxy_port->input_type = ELM_INPUT_PANEL_LAYOUT_NUMBERONLY;
600 SETTING_TRACE_ERROR("ad->data_pxy_port is NULL");
603 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* mms Connection */
605 setting_create_Gendial_field_def(scroller,
608 SWALLOW_Type_LAYOUT_ENTRY,
610 "IDS_ST_BODY_HOME_URL",
611 (char *)ad->ed_hm_url_desc,
612 setting_network_connection_entry_changed_cb);
613 if (ad->data_hm_url) {
614 ad->data_hm_url->userdata = ad;
615 ad->data_hm_url->input_type = ELM_INPUT_PANEL_LAYOUT_URL;
616 ad->data_hm_url->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
617 if (ad->data_hm_url->limit_filter_data) {
618 ad->data_hm_url->limit_filter_data->max_byte_count = MAX_HOME_URL_LEN_MAX - 1;
619 ad->data_hm_url->win_main = ad->win_get;
622 SETTING_TRACE_ERROR("ad->data_hm_url is NULL");
624 /* ad->is_show_url = 1; */
627 item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
628 ELM_GENLIST_ITEM_NONE, NULL, NULL);
629 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
631 setting_view_network_connection_create.is_create = 1;
632 ad->scl_edit = scroller;
633 __genlist_disable_set(ad->scl_edit, TRUE);
634 ecore_idler_add(__connection_idler, ad);
635 return SETTING_RETURN_SUCCESS;
638 static int setting_network_connection_destroy(void *cb)
642 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
644 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
646 ad->bottom_btn = NULL;
651 evas_object_del(ad->l_button);
656 evas_object_del(ad->m_button);
661 evas_object_del(ad->r_button);
665 G_FREE(ad->ed_acs_name_desc);
666 G_FREE(ad->ed_user_name_desc);
667 G_FREE(ad->ed_pwd_desc);
669 G_FREE(ad->ed_pxy_addr_desc);
670 G_FREE(ad->ed_pxy_port_desc);
672 G_FREE(ad->ed_hm_url_desc);
675 // connection_profile_destroy(ad->prof_list);
676 // ad->prof_list = NULL;
679 elm_naviframe_item_pop(ad->navi_bar);
680 setting_view_network_connection_create.is_create = 0;
681 return SETTING_RETURN_SUCCESS;
684 static int setting_network_connection_update(void *cb)
687 return SETTING_RETURN_SUCCESS;
690 static int setting_network_connection_cleanup(void *cb)
692 return setting_network_connection_destroy(cb);
695 /* ***************************************************
699 ***************************************************/
701 static int __save_connection(void *data)
705 retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
707 SettingNetworkUG *ad = (SettingNetworkUG *) data;
708 const char *acs_name = NULL;
709 const char *usr_name = NULL;
710 const char *pwd = NULL;
711 const char *addr = NULL;
712 const char *port = NULL;
713 const char *home = NULL;
715 if (ad->data_acs_name)
716 acs_name = elm_entry_markup_to_utf8(ad->data_acs_name->sub_desc);
717 if (ad->data_user_name)
718 usr_name = elm_entry_markup_to_utf8(ad->data_user_name->sub_desc);
720 pwd = elm_entry_markup_to_utf8(ad->data_pwd->sub_desc);
721 if (ad->data_pxy_addr)
722 addr = elm_entry_markup_to_utf8(ad->data_pxy_addr->sub_desc);
723 if (ad->data_pxy_port)
724 port = elm_entry_markup_to_utf8(ad->data_pxy_port->sub_desc);
727 acs_name = strdup("");
729 usr_name = strdup("");
736 SETTING_TRACE("acs_name:%s", acs_name);
737 SETTING_TRACE("usr_name:%s", usr_name);
738 SETTING_TRACE("pwd:%s", pwd);
740 SETTING_TRACE("addr:%s", addr);
741 SETTING_TRACE("port:%s", port);
742 SETTING_TRACE("home:%s", home);
744 char sz_text[MAX_PROXY_LEN_MAX + 1] = { 0, };
746 int ret = SETTING_RETURN_SUCCESS;
749 if (!safeStrCmp(acs_name, "")) {
750 setting_create_simple_popup(ad, ad->win_get,
751 NULL, _(Insert_Access_Name_desc));
757 return SETTING_DNET_RETURN_NULL_ACCESS_NAME;
759 //if (test_update_cellular_info(profile) == -1)
760 bool add_flag = FALSE;//add a new profile
761 connection_profile_h con_info = NULL;
762 if (ad->sel_profile_h) {
763 con_info = ad->sel_profile_h;
764 if(0 != safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)
765 && 0 != safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION"))
767 //need to change con_name
769 ad->con_name = strdup(acs_name);
771 SETTING_TRACE("ad->con_name:%s", ad->con_name);
774 SETTING_TRACE("ad->con_name:%s", ad->con_name);
775 if(!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS))
777 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
778 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
780 else if(!safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION"))
782 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
783 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
787 //need to change con_name
789 ad->con_name = strdup(acs_name);
790 connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, _(ad->con_name), &con_info);
791 connection_profile_set_cellular_service_type(con_info,CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
794 SETTING_TRACE("ad->con_name:%s", ad->con_name);
798 /* save access name */
799 connection_profile_set_cellular_apn(con_info, acs_name);
803 /* type = elm_radio_value_get(ad->chk_type); */
806 if (!safeStrCmp(usr_name, "")
807 && CONNECTION_CELLULAR_AUTH_TYPE_NONE != type) {
808 setting_create_simple_popup(ad, ad->win_get,
809 NULL, _(Insert_User_Name_Desc));
814 return SETTING_DNET_RETURN_NULL_USER_NAME;
818 if (!safeStrCmp(pwd, "")
819 && CONNECTION_CELLULAR_AUTH_TYPE_NONE != type) {
820 setting_create_simple_popup(ad, ad->win_get,
821 NULL, _("IDS_ST_BODY_ENTER_PASSWORD"));
826 return SETTING_DNET_RETURN_NULL_PASSWORD;
829 connection_profile_set_cellular_auth_info(con_info, type, usr_name, pwd);
831 /* save proxy addr */
832 SETTING_TRACE("addr:port[%s:%s]", addr, port);
833 if (!safeStrCmp(addr, "")) {
834 /* check proxy port */
835 if (!safeStrCmp(port, ""))
837 //it is the normal case.
839 else //like ":80",it's forbiden
841 setting_create_simple_popup(ad, ad->win_get,
842 NULL, _("Incorrect proxy address, please add correct adress or clear the port field."));
847 return SETTING_DNET_RETURN_INVALID_PROXY_ADDR;
849 } else if (!is_ip_string(addr)) {
850 setting_create_simple_popup(ad, ad->win_get,
851 NULL, _("IDS_ST_HEADER_INCORRECT_PROXY_ADDRESS"));
856 return SETTING_DNET_RETURN_INVALID_PROXY_ADDR;
859 ret = snprintf(sz_text, sizeof(sz_text), "%s:%s", addr, port);
860 retv_if(ret < 0, SETTING_DNET_RETURN_ERR);
861 connection_profile_set_proxy_address(con_info, CONNECTION_ADDRESS_FAMILY_IPV4, sz_text);
863 /* save home url(message connection only) */
864 if (!safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) { /* Message Connection */
865 home = elm_entry_markup_to_utf8(ad->data_hm_url->sub_desc);
866 if (home == (char *)NULL) {
867 connection_profile_set_cellular_home_url(con_info, URL_HEAD);
869 if (!safeStrCmp(home, "")) {
871 home = strdup(URL_HEAD);
872 ret = SETTING_DNET_RETURN_NULL_HOMEURL;
874 connection_profile_set_cellular_home_url(con_info, home);
876 } else if (!safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION")) {
879 //For internet, it needs call following api to set the default profile.
880 connection_set_default_cellular_service_profile(ad->connection, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, con_info);
889 //SETTING_TRACE("ad->con_type:%d", ad->con_type);
890 /* save connection */
892 //con_info->profile_type = NET_DEVICE_CELLULAR;
893 //con_info->ProfileState = NET_STATE_TYPE_UNKNOWN;
894 //con_info->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
895 err = connection_add_profile(ad->connection, con_info);
896 if (err != CONNECTION_ERROR_NONE) {
898 ("%s*** [ERR] connection_add_profile. err=%d ***%s",
899 SETTING_FONT_RED, err, SETTING_FONT_BLACK);
900 ret = SETTING_DNET_RETURN_ERR;
901 setting_create_simple_popup(ad, ad->win_get,
902 NULL, _("IDS_COM_POP_FAILED"));
905 connection_profile_destroy(con_info);
908 err = connection_update_profile(ad->connection, con_info);
909 if (err != CONNECTION_ERROR_NONE) {
911 ("%s*** [ERR] net_modify_profile. err=%d ***%s",
912 SETTING_FONT_RED, err, SETTING_FONT_BLACK);
913 ret = SETTING_DNET_RETURN_ERR;
914 setting_create_simple_popup(ad, ad->win_get,
915 NULL, _("IDS_COM_POP_FAILED"));
921 /* ***************************************************
925 ***************************************************/
927 setting_network_edit_connection_click_softkey_eidt_cb(void *data,
933 retm_if(data == NULL, "Data parameter is NULL");
935 SettingNetworkUG *ad = (SettingNetworkUG *) data;
936 //setting_enable_evas_object(ad->scl_edit);
937 __genlist_disable_set(ad->scl_edit, FALSE);
939 if (!ad->l_button) //go into first time
941 ad->l_button = setting_create_button(ad->navi_bar, _("IDS_COM_SK_DONE"),
942 "naviframe/title/icon/edit",
943 setting_network_edit_connection_click_softkey_save_cb,
947 if (!ad->r_button) //go into first time
949 ad->r_button = setting_create_button(ad->navi_bar, _("IDS_COM_SK_CANCEL"),
950 NAVI_BACK_BUTTON_STYLE,
951 setting_network_edit_connection_click_softkey_cancel_cb,
954 /*if (!ad->m_button) //go into first time
956 ad->m_button = setting_create_button(ad->navi_bar, NULL,
961 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_LEFT, ad->l_button);
962 evas_object_show(ad->l_button);
965 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_RIGHT, ad->r_button);
966 ad->has_form_changed = TRUE;//intialize
967 setting_network_connection_check_entry_empty(ad);
968 ad->has_form_changed = FALSE;//restore
970 /*if (ad->m_button) {
971 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_MORE, ad->m_button);
972 evas_object_show(ad->r_button);
976 ad->back_btn = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_PREV);
977 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_PREV, NULL);
978 evas_object_hide(ad->back_btn);
980 //remove other buttons
981 ad->bottom_btn = elm_object_item_part_content_unset(ad->navi_it, "toolbar_button1");
982 elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", NULL);
983 evas_object_hide(ad->bottom_btn);
988 setting_network_edit_connection_click_softkey_save_cb(void *data,
994 retm_if(data == NULL, "Data parameter is NULL");
996 SettingNetworkUG *ad = (SettingNetworkUG *) data;
997 /* elm_box_unpack_all(ad->bx_blk); */
998 /* elm_dialoguegroup_remove_all(ad->dg_blk); */
1000 int ret = __save_connection(ad);
1001 /* need special handle */
1002 if (SETTING_DNET_RETURN_NULL_ACCESS_NAME == ret
1003 || SETTING_DNET_RETURN_NULL_USER_NAME == ret
1004 || SETTING_DNET_RETURN_NULL_PASSWORD == ret
1005 || SETTING_DNET_RETURN_INVALID_PROXY_ADDR == ret
1006 || SETTING_DNET_RETURN_ERR == ret) {
1009 if (ret != SETTING_RETURN_SUCCESS) {
1011 ("%s*** [ERR] __save_connection ***%s",
1012 SETTING_FONT_RED, SETTING_FONT_BLACK);
1015 setting_create_popup_without_btn(ad, ad->win_get, NULL, _(KeyStr_Saved), NULL, POPUP_INTERVAL, FALSE, FALSE);
1016 //re-fetch connection info..
1017 __get_connection_info(ad);
1020 elm_object_item_text_set(ad->navi_it, _(ad->con_name));
1021 setting_network_edit_connection_click_softkey_cancel_cb(ad, ad->r_button, NULL);
1025 setting_network_edit_connection_click_softkey_back_cb(void *data,
1029 SETTING_TRACE_BEGIN;
1031 retm_if(data == NULL, "Data parameter is NULL");
1033 SettingNetworkUG *ad = (SettingNetworkUG *) data;
1034 /* elm_box_unpack_all(ad->bx_blk); */
1035 /* elm_dialoguegroup_remove_all(ad->dg_blk); */
1036 setting_view_change(&setting_view_network_connection_create,
1037 &setting_view_network_con, ad);
1040 setting_network_edit_connection_click_softkey_cancel_cb(void *data,
1044 SETTING_TRACE_BEGIN;
1046 retm_if(data == NULL, "Data parameter is NULL");
1048 SettingNetworkUG *ad = (SettingNetworkUG *) data;
1049 ad->l_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_LEFT);
1050 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_LEFT, NULL);
1051 evas_object_hide(ad->l_button);
1053 ad->m_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_MORE);
1054 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_MORE, NULL);
1055 evas_object_hide(ad->m_button);*/
1057 ad->r_button = elm_object_item_part_content_unset(ad->navi_it, NAVI_BTN_STYLE_RIGHT);
1058 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_RIGHT, NULL);
1059 evas_object_hide(ad->r_button);
1060 //setting_disable_evas_object(ad->r_button);
1061 setting_undo_dim_evas_object(ad->r_button, TRUE);
1063 elm_object_item_part_content_set(ad->navi_it, NAVI_BTN_STYLE_PREV, ad->back_btn);
1064 elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", ad->bottom_btn);
1065 evas_object_show(ad->back_btn);
1066 evas_object_show(ad->bottom_btn);
1068 __get_connection_info(ad);
1069 __update_genlist_info(ad);
1070 if(ad->data_auth_type) elm_genlist_item_expanded_set(ad->data_auth_type->item, FALSE);
1071 ecore_idler_add(__connection_idler, ad);
1073 static void _gl_Gendial_sel(void *data, Evas_Object *obj, void *event_info)
1075 /* SETTING_TRACE_BEGIN; */
1076 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1077 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1078 elm_genlist_item_selected_set(item, 0);
1082 static void setting_network_connection_check_entry_empty(SettingNetworkUG *ad)
1084 SETTING_TRACE_BEGIN;
1085 if (!ad->has_form_changed)
1087 SETTING_TRACE_DEBUG("ad->has_form_changed == FALSE!");
1090 bool isFoundEmptyEntry = FALSE;
1093 if (ad->data_acs_name && isEmptyStr(ad->data_acs_name->sub_desc)) {
1094 SETTING_TRACE("entry_str:%s", ad->data_acs_name->sub_desc);
1095 isFoundEmptyEntry = TRUE;
1098 if (ad->data_user_name && isEmptyStr(ad->data_user_name->sub_desc)) {
1099 SETTING_TRACE("entry_str:%s", ad->data_user_name->sub_desc);
1100 isFoundEmptyEntry = TRUE;
1103 if (ad->data_pwd && isEmptyStr(ad->data_pwd->sub_desc)) {
1104 SETTING_TRACE("entry_str:%s", ad->data_pwd->sub_desc);
1105 isFoundEmptyEntry = TRUE;
1108 if (ad->data_hm_url && isEmptyStr(ad->data_hm_url->sub_desc)) {
1109 SETTING_TRACE("entry_str:%s", ad->data_hm_url->sub_desc);
1110 isFoundEmptyEntry = TRUE;
1114 Evas_Object *done_btn = elm_object_item_part_content_get(ad->navi_it, NAVI_BTN_STYLE_LEFT);
1115 if (isFoundEmptyEntry) {
1116 if (!evas_object_pass_events_get(done_btn)) {//it had not yet been disabled
1117 setting_disable_evas_object(done_btn);
1118 setting_dim_evas_object(done_btn, TRUE);
1122 //do nothing..if invoke setting_dim_evas_object many times, the done button will be dimer until it cannot be see.
1123 //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.
1126 setting_enable_evas_object(done_btn);
1127 setting_undo_dim_evas_object(done_btn, TRUE);
1132 setting_network_edit_connection_display_auth_type(SettingNetworkUG *ad,
1135 SETTING_TRACE_BEGIN;
1136 retm_if(ad == NULL, "Data parameter is NULL");
1137 if (ad->chkType == auth_type) return;
1139 ad->chkType = auth_type; /* for update genlist */
1140 if (CONNECTION_CELLULAR_AUTH_TYPE_NONE != auth_type) { /* to show */
1141 SETTING_TRACE("ad->is_show_user:%d", ad->is_show_user);
1142 if (ad->is_show_user == 0) { /* do only when hiden */
1143 SETTING_TRACE("to create");
1145 ad->data_user_name =
1146 (Setting_GenGroupItem_Data *) calloc(1,
1148 (Setting_GenGroupItem_Data));
1149 setting_retm_if(ad->data_user_name == NULL, "calloc failed");
1150 ad->data_user_name->keyStr =
1151 (char *)g_strdup("IDS_COM_BODY_USER_NAME");
1152 ad->data_user_name->sub_desc =
1153 (char *)g_strdup(ad->ed_user_name_desc);
1154 ad->data_user_name->swallow_type =
1155 SWALLOW_Type_LAYOUT_ENTRY;
1156 ad->data_user_name->userdata = ad;
1157 ad->data_user_name->chk_change_cb =
1158 setting_network_connection_entry_changed_cb;
1159 ad->data_user_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
1160 if (ad->data_user_name->limit_filter_data) {
1161 ad->data_user_name->limit_filter_data->max_byte_count = MAX_PDP_AUTH_USERNAME_LEN_MAX - 1;
1162 ad->data_user_name->win_main = ad->win_get;
1164 ad->data_user_name->item =
1165 elm_genlist_item_insert_after(ad->scl_edit,
1169 ad->item_above_user_name,
1170 ELM_GENLIST_ITEM_NONE,
1171 _gl_Gendial_sel, ad);
1174 (Setting_GenGroupItem_Data *) calloc(1,
1176 (Setting_GenGroupItem_Data));
1178 setting_retm_if(ad->data_pwd == NULL, "calloc failed");
1179 ad->data_pwd->keyStr =
1180 (char *)g_strdup("IDS_COM_BODY_PASSWORD");
1181 ad->data_pwd->sub_desc =
1182 (char *)g_strdup(ad->ed_pwd_desc);
1183 ad->data_pwd->swallow_type = SWALLOW_Type_LAYOUT_ENTRY;
1184 ad->data_pwd->userdata = ad;
1185 ad->data_pwd->chk_change_cb =
1186 setting_network_connection_entry_changed_cb;
1187 ad->data_pwd->isPasswordFlag = TRUE;
1188 /* ad->data_pwd->chk_change_cb = chk_change_cb; */
1189 ad->data_pwd->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
1190 if (ad->data_pwd->limit_filter_data) {
1191 ad->data_pwd->limit_filter_data->max_byte_count = MAX_PDP_AUTH_PASSWORD_LEN_MAX - 1;
1192 ad->data_pwd->win_main = ad->win_get;
1194 ad->data_pwd->item =
1195 elm_genlist_item_insert_after(ad->scl_edit,
1199 data_user_name->item,
1200 ELM_GENLIST_ITEM_NONE,
1201 _gl_Gendial_sel, ad);
1203 ad->item_above_proxy_add =
1204 elm_genlist_item_insert_after(ad->scl_edit,
1208 ELM_GENLIST_ITEM_NONE,
1210 elm_genlist_item_select_mode_set
1211 (ad->item_above_proxy_add, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1213 ad->has_form_changed = TRUE;
1214 setting_network_connection_check_entry_empty(ad);
1215 /* ad->is_show_user = 1; */
1217 ad->is_show_user = 1;
1218 } else { /* to hide */
1220 SETTING_TRACE("ad->is_show_user:%d", ad->is_show_user);
1221 if (ad->is_show_user == 1) { /* do only when shown */
1222 SETTING_TRACE("to destroy");
1223 if (ad->data_user_name) {
1224 elm_object_item_del(ad->data_user_name->item);
1225 ad->data_user_name = NULL;
1228 elm_object_item_del(ad->data_pwd->item);
1229 ad->data_pwd = NULL;
1231 if (ad->item_above_proxy_add) {
1232 elm_object_item_del(ad->item_above_proxy_add);
1233 ad->item_above_proxy_add = NULL;
1237 ad->has_form_changed = TRUE;
1238 setting_network_connection_check_entry_empty(ad);
1239 ad->is_show_user = 0;
1245 setting_network_connection_entry_changed_cb(void *data, Evas_Object *obj,
1248 SETTING_TRACE_BEGIN;
1249 retm_if(data == NULL, "Data parameter is NULL");
1250 Setting_GenGroupItem_Data *list_item =
1251 (Setting_GenGroupItem_Data *) data;
1252 SettingNetworkUG *ad = list_item->userdata;
1253 const char *entry_str = elm_entry_entry_get(obj);
1254 list_item->sub_desc = (char *)g_strdup(entry_str);
1255 //SETTING_TRACE("list_item->sub_desc:%s", list_item->sub_desc);
1256 ad->has_form_changed = TRUE;
1257 setting_network_connection_check_entry_empty(ad);
1260 setting_network_connection_hide_input_pannel(void *data)
1262 SETTING_TRACE_BEGIN;
1263 retm_if(data == NULL, "Data parameter is NULL");
1264 SettingNetworkUG *ad = data;
1265 if (ad->data_acs_name) {
1266 setting_hide_input_pannel_cb(ad->data_acs_name->eo_check);
1268 if (ad->data_user_name) {
1269 setting_hide_input_pannel_cb(ad->data_user_name->eo_check);
1272 setting_hide_input_pannel_cb(ad->data_pwd->eo_check);
1274 if (ad->data_pxy_addr) {
1275 setting_hide_input_pannel_cb(ad->data_pxy_addr->eo_check);
1277 if (ad->data_pxy_port) {
1278 setting_hide_input_pannel_cb(ad->data_pxy_port->eo_check);
1280 if (ad->data_hm_url) {
1281 setting_hide_input_pannel_cb(ad->data_hm_url->eo_check);