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-list.h>
23 static int setting_network_con_list_create(void *cb);
24 static int setting_network_con_list_destroy(void *cb);
25 static int setting_network_con_list_update(void *cb);
26 static int setting_network_con_list_cleanup(void *cb);
27 void setting_network_con_list_chk_changed(void *data, Evas_Object *obj, void *event_info);
29 setting_view setting_view_network_con_list = {
30 .create = setting_network_con_list_create,
31 .destroy = setting_network_con_list_destroy,
32 .update = setting_network_con_list_update,
33 .cleanup = setting_network_con_list_cleanup,
41 static int __get_naviframe_depth_con_list(void* data)
43 SettingNetworkUG *ad = (SettingNetworkUG *) data;
45 Eina_List * list = elm_naviframe_items_get(ad->navi_bar);
46 //Object_Drawer *list_item = NULL;
50 Elm_Object_Item *item = (Elm_Object_Item *) eina_list_data_get(list);
54 SETTING_TRACE("ad->navi_bar : %x --- %d --- address of the item = %x",ad->navi_bar, index, item);
57 //if not matched,to check next node.
58 list = eina_list_next(list);
64 static void __popup_cb(void *data, Evas_Object *obj, void *event_info)
67 setting_retm_if(NULL == data, "NULL == data");
68 SettingNetworkUG *ad = (SettingNetworkUG *) data;
69 int response_type = POPUP_RESPONSE_CANCEL;
70 if (0 == safeStrCmp(elm_object_text_get(obj), "OK"))
72 response_type = POPUP_RESPONSE_OK;
74 evas_object_del(ad->popup_conlist);
75 ad->popup_conlist = NULL;
77 if (POPUP_RESPONSE_OK == response_type)
79 setting_view_destroy(&setting_view_network_con_list, ad);
80 setting_view_destroy(&setting_view_network_con, ad);
87 static void __enabled_tethering(void *data)
89 SettingNetworkUG *ad = (SettingNetworkUG *) data;
90 SETTING_TRACE("Tethering is enabled -- callback\n");
92 int frames = __get_naviframe_depth_con_list(ad);
96 ad->popup_conlist = setting_create_popup_with_btn(ad, ad->win_get,
97 NULL, _(SETTING_NETWORK_NOT_ALLOWED_WITH_TETHERING),
98 __popup_cb, 0, 1, "OK");
102 static void __disabled_tethering(void *data)
104 SETTING_TRACE("Tethering is disabled -- callback\n");
105 //setting_enable_genlist_item(ad->data_connection->item);
108 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
111 SettingNetworkUG *ad = (SettingNetworkUG *) data;
112 SETTING_TRACE("Tethering is enabled -- callback\n");
113 __enabled_tethering(ad);
116 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
119 SettingNetworkUG *ad = (SettingNetworkUG *) data;
120 SETTING_TRACE("Tethering is disabled -- callback\n");
121 __disabled_tethering(ad);
126 * if tethering is ON, 'connection' should be inactivated.
128 static bool is_tethering_enabled(void* data)
130 SettingNetworkUG *ad = (SettingNetworkUG *) data;
133 tethering_h th = NULL;
134 (void) tethering_create(&th);
136 ad->th_conlists = th;
138 tethering_set_enabled_cb(th, TETHERING_TYPE_ALL, __enabled_cb, data);
139 tethering_set_disabled_cb(th, TETHERING_TYPE_ALL, __disabled_cb, data);
141 if (tethering_is_enabled(th, TETHERING_TYPE_WIFI) == true ||
142 tethering_is_enabled(th, TETHERING_TYPE_USB) == true ||
143 tethering_is_enabled(th, TETHERING_TYPE_BT) == true) {
145 SETTING_TRACE("Tethering is enabled\n");
146 __enabled_tethering(ad);
149 SETTING_TRACE("Tethering is not enabled\n");
150 __disabled_tethering(ad);
154 //tethering_destroy(th);
159 /* ***************************************************
163 ***************************************************/
164 static int __con_list_recreate(void *cb)
167 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
168 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
169 Evas_Object *scroller;
170 scroller = ad->con_list_gl;
171 elm_genlist_clear(scroller); /* first to clear list */
172 Elm_Object_Item *first_item;
173 /* item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
174 first_item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
175 ELM_GENLIST_ITEM_NONE, NULL, NULL);
176 elm_genlist_item_select_mode_set(first_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
179 Setting_GenGroupItem_Data *item_data = NULL;
181 radio = elm_radio_add(scroller);
182 elm_radio_state_value_set(radio, -1);
184 setting_disable_evas_object(radio);
186 int srvType = ad->profile_service_type;
188 char *def_apn = NULL;
189 char *def_name = NULL;
191 connection_profile_h def_profile = NULL;
192 (void) connection_get_default_cellular_service_profile(ad->connection, srvType, &def_profile);
193 if (def_profile) connection_profile_get_cellular_apn(def_profile, &def_apn);
194 if (def_profile) connection_profile_get_name(def_profile, &def_name);
195 if (def_profile) connection_profile_get_id(def_profile, &def_id);
196 SETTING_TRACE("Default profile:%p, def_apn[%s], def_name[%s], def_id[%s]", def_profile, def_apn, def_name, def_id);
198 setting_network_reget_profile_list(ad);
200 Eina_List* elist = NULL;
201 connection_profile_h profile_h = NULL;
204 ad->selected_profile = NULL;
208 EINA_LIST_FOREACH(ad->profile_list, elist, profile_h)
211 connection_profile_get_cellular_apn(profile_h, &apn);
212 connection_profile_get_name(profile_h, &name);
213 connection_profile_get_proxy_address(profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
214 connection_profile_get_id(profile_h, &id);
217 item_data = (Setting_GenGroupItem_Data *) calloc(1,sizeof(Setting_GenGroupItem_Data));
218 setting_retvm_if(!item_data, SETTING_RETURN_FAIL, "calloc failed");
219 item_data->keyStr = (char *)g_strdup(name);
220 item_data->swallow_type = SWALLOW_Type_1RADIO_1BTN;
221 item_data->r_swallow_path = (char *)g_strdup("reveal/extended");
222 item_data->chk_status = idx;
223 item_data->chk_change_cb = setting_network_con_list_chk_changed;
224 item_data->stop_change_cb = setting_network_con_list_go_button_cb;
225 item_data->rgd = radio;
226 item_data->userdata = ad;
227 item_data->sub_desc = (char *)g_strdup(apn);
228 item_data->keyStr2 = (char *)g_strdup(id);
231 ad->selected_profile = item_data; //defaulty,it the first item
232 item_data->group_style = SETTING_GROUP_STYLE_TOP;
235 item_data->group_style = SETTING_GROUP_STYLE_CENTER;
238 elm_genlist_item_append(scroller, &(itc_2text_2icon_3), item_data, NULL,
239 ELM_GENLIST_ITEM_NONE,
240 setting_network_con_list_item_Gendial_mouse_up_cb, ad);
242 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_TOP);
244 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_CENTER);
246 SETTING_TRACE("profile_h:%p, apn:%s, id:%s", profile_h, apn, id);
247 if (!safeStrCmp(def_apn, apn) && !safeStrCmp(def_name, name) && !safeStrCmp(def_id, id))
249 SETTING_TRACE("Matched [idx:%d, apn:%s, id:%s]!", idx, apn, id);
250 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET)
252 ad->selected_profile = item_data; //the selected item
253 elm_radio_value_set(radio, idx);
254 if(ad->internet_conn) {
255 G_FREE(ad->internet_conn->sub_desc);
256 FREE(ad->apn_internet);
257 ad->apn_internet = strdup(name);
258 ad->internet_conn->sub_desc = strdup(name);
259 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
260 elm_genlist_item_update( ad->internet_conn->item);
267 G_FREE(proxy_address);
271 ADD_GL_SEPARATOR(scroller);
273 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
274 SETTING_TRACE("idx:%d", idx);
275 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_con_list, "toolbar");
276 SETTING_TRACE("elm_object_text_get(del_btn):%s", elm_object_item_text_get(elm_toolbar_last_item_get(toolbar)));
279 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_NONE);
280 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_FALSE);
284 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
285 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_FALSE);
289 FREE(ad->apn_internet);
290 SETTING_TRACE("To disable");
291 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_TRUE);
293 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS)
295 if (idx > 0) elm_radio_value_set(radio, 0);//the first one
296 if (ad->selected_profile && !isEmptyStr(ad->selected_profile->keyStr) && ad->mms_conn)
298 SETTING_TRACE("ad->selected_profile->keyStr:%s", ad->selected_profile->keyStr);
299 G_FREE(ad->mms_conn->sub_desc);
301 ad->apn_MMS = strdup(ad->selected_profile->keyStr);
302 ad->mms_conn->sub_desc = strdup(ad->selected_profile->keyStr);
303 elm_genlist_item_fields_update(ad->mms_conn->item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
306 ad->cur_profile_num = idx;
308 // setting_create_simple_popup(ad, ad->navi_bar,NULL, "There is no avaiable profile,you can create one.");
314 return SETTING_RETURN_SUCCESS;
317 static int setting_network_con_list_create(void *cb)
320 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
322 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
324 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
325 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
326 "Cannot set scroller object as contento of layout");
327 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
328 elm_object_style_set(scroller, "dialogue");
330 const char *title = NULL;
331 switch (ad->profile_service_type)
333 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
334 title = "IDS_ST_BODY_MMS_CONNECTIONS";
336 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
337 title = "IDS_ST_BODY_INTERNET_CONNECTION";
340 title = ad->con_name;
344 ad->navi_it_con_list =
345 setting_push_layout_navi_bar(_(title),
346 _("IDS_COM_BODY_BACK"),
347 _("IDS_COM_SK_DELETE"),
348 _("IDS_COM_BODY_CREATE"),
350 setting_network_con_list_click_softkey_delete_cb,
351 setting_network_con_list_click_softkey_create_cb,
352 ad, scroller, ad->navi_bar, NULL);
354 elm_naviframe_item_pop_cb_set(ad->navi_it_con_list,
355 setting_network_con_list_click_softkey_cancel_cb, ad);
356 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
357 ad->con_list_gl = scroller;
358 __con_list_recreate(ad);
360 #if SUPPORT_TETHERING
361 is_tethering_enabled(ad);
363 setting_view_network_con_list.is_create = 1;
365 return SETTING_RETURN_SUCCESS;
368 static int setting_network_con_list_destroy(void *cb)
372 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
374 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
375 if (setting_view_network_con_list.is_create) {
376 //ad->connections_gl = NULL;
377 #if SUPPORT_TETHERING
378 if (ad->th_conlists) {
379 SETTING_TRACE("tethering destruction ");
380 tethering_destroy(ad->th_conlists);
381 ad->th_conlists = NULL;
384 setting_view_network_con_list.is_create = 0;
385 ad->selected_profile = NULL;
386 ad->navi_it_con_list = NULL;
387 ad->con_list_gl = NULL;
388 elm_naviframe_item_pop(ad->navi_bar);
390 SETTING_TRACE("why is this is_create == 0 ?? !!!");
392 return SETTING_RETURN_SUCCESS;
395 static int setting_network_con_list_update(void *cb)
399 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
400 __con_list_recreate(cb);
401 return SETTING_RETURN_SUCCESS;
404 static int setting_network_con_list_cleanup(void *cb)
407 return setting_network_con_list_destroy(cb);
408 //return SETTING_RETURN_SUCCESS;
411 /* ***************************************************
415 ***************************************************/
417 /* ***************************************************
421 ***************************************************/
422 static void setting_network_con_list_go_button_cb(void *data, Evas_Object * obj, void *event_info)
425 retm_if(data == NULL, "Data parameter is NULL");
426 Setting_GenGroupItem_Data *item_data = data;
428 SettingNetworkUG *ad = item_data->userdata;
429 FREE(ad->access_name);
430 ad->access_name = strdup(item_data->keyStr2);
431 setting_view_change(&setting_view_network_con_list, &setting_view_network_connection_create, ad);
435 static void ___network_con_set_default_cb(connection_error_e result, void* data)
438 setting_retm_if(data == NULL, "Data parameter is NULL");
439 Setting_GenGroupItem_Data *list_item = data;
440 SettingNetworkUG *ad = list_item->userdata;
441 setting_retm_if(ad == NULL, "ad parameter is NULL");
442 if(ad->network_ug_pop) {
443 evas_object_del(ad->network_ug_pop);
444 ad->network_ug_pop = NULL;
447 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
448 if (0 == safeStrCmp(ad->con_name,"IDS_ST_BODY_INTERNET_CONNECTION"))
450 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
452 else if (0 == safeStrCmp(ad->con_name,STR_SETTING_MMS_CONNECTIONS))
454 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
456 SETTING_TRACE("The result is :%d,but it is meaningless for our Setting", result);
457 ad->selected_profile = list_item;
458 if(srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET && ad->internet_conn) {
459 G_FREE(ad->internet_conn->sub_desc);
460 FREE(ad->apn_internet);
461 ad->apn_internet = strdup(list_item->keyStr);
462 ad->internet_conn->sub_desc = strdup(list_item->keyStr);
463 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
464 elm_genlist_item_update( ad->internet_conn->item);
466 elm_genlist_realized_items_update(ad->con_list_gl);
470 static void __set_default_response_cb(void *data, Evas_Object *obj,
473 setting_retm_if(data == NULL, "Data parameter is NULL");
474 Setting_GenGroupItem_Data *list_item = data;
475 SettingNetworkUG *ad = list_item->userdata;
477 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
478 if (0 == safeStrCmp(ad->con_name,"IDS_ST_BODY_INTERNET_CONNECTION"))
480 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
482 else if (0 == safeStrCmp(ad->con_name,STR_SETTING_MMS_CONNECTIONS))
484 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
486 //SETTING_TRACE("The result is :%d,but it is meaningless for our Setting", result);
487 ad->selected_profile = list_item;
488 if(srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET && ad->internet_conn) {
489 G_FREE(ad->internet_conn->sub_desc);
490 FREE(ad->apn_internet);
491 ad->apn_internet = strdup(list_item->keyStr);
492 ad->internet_conn->sub_desc = strdup(list_item->keyStr);
493 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
494 elm_genlist_item_update( ad->internet_conn->item);
496 elm_genlist_realized_items_update(ad->con_list_gl);
499 evas_object_del(obj);
505 void __set_default_profile(void *data)
507 setting_retm_if(data == NULL, "Data parameter is NULL");
508 Setting_GenGroupItem_Data *list_item = data;
509 SettingNetworkUG *ad = list_item->userdata;
510 setting_retm_if(ad == NULL, "ad parameter is NULL");
512 connection_profile_iterator_h profile_iter = NULL;
513 connection_profile_h profile_h = NULL;
514 int rv = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
515 if (rv != CONNECTION_ERROR_NONE) {
516 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", rv);
522 char *profile_id = NULL;
523 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
525 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
526 if (0 == safeStrCmp(ad->con_name,"IDS_ST_BODY_INTERNET_CONNECTION"))
528 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
530 else if (0 == safeStrCmp(ad->con_name,STR_SETTING_MMS_CONNECTIONS))
532 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
534 while (connection_profile_iterator_has_next(profile_iter)) {
535 if (cnt >= MAX_PROFILE_NUM)
539 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
540 SETTING_TRACE_ERROR("Fail to get profile handle");
543 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
544 SETTING_TRACE_ERROR("Fail to get service type");
548 connection_profile_get_cellular_apn(profile_h, &apn);
549 connection_profile_get_id(profile_h, &profile_id);
550 if(srvType != service_type)
556 SETTING_TRACE("Record[%d] profile is %s(%s)", cnt, apn, profile_id);
557 if (0 == safeStrCmp(profile_id, list_item->keyStr2))
560 if (CONNECTION_CELLULAR_SERVICE_TYPE_MMS == srvType)
562 setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_MSGF_POP_UNSUPPORTED"));
563 //elm_radio_value_set(list_item->eo_check, old_type);
564 if (ad->selected_profile)
565 elm_radio_value_set(list_item->eo_check, ad->selected_profile->chk_status);
570 SETTING_TRACE("Set default[%d] as [%s], profile:%p, id:%s", srvType, apn, profile_h, profile_id);
571 int ret = connection_set_default_cellular_service_profile(ad->connection, srvType, profile_h);
572 SETTING_TRACE("The result is :%d", ret);
574 if(ad->network_ug_pop) {
575 evas_object_del(ad->network_ug_pop);
576 ad->network_ug_pop = NULL;
578 if(ret != CONNECTION_ERROR_NONE){
579 if (ad->selected_profile)
580 elm_radio_value_set(list_item->eo_check, ad->selected_profile->chk_status);
582 setting_create_popup_without_btn(list_item, ad->win_get, NULL,
583 _("IDS_COM_POP_FAILED"), NULL,
588 setting_create_popup_without_btn(list_item, ad->win_get, NULL,
589 _("IDS_COM_POP_PROCESSING"), __set_default_response_cb,
600 static void setting_network_con_list_item_Gendial_mouse_up_cb(void *data, Evas_Object *obj, void *event_info)
604 setting_retm_if(data == NULL, "Data parameter is NULL");
606 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
607 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
608 elm_genlist_item_selected_set(item, 0);
609 Setting_GenGroupItem_Data *list_item =
610 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
612 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
613 if(list_item->chk_status == elm_radio_value_get(list_item->eo_check))
615 SettingNetworkUG *ad = data;
616 elm_genlist_realized_items_update(ad->con_list_gl);
620 elm_radio_value_set(list_item->eo_check, list_item->chk_status);
621 __set_default_profile(list_item);
623 void setting_network_con_list_chk_changed(void *data, Evas_Object *obj, void *event_info)
626 retm_if(data == NULL || obj == NULL, "Parameter is NULL");
627 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
628 list_item->chk_status = elm_radio_value_get(obj);
629 __set_default_profile(list_item);
633 static void setting_network_con_list_click_softkey_delete_cb(void *data, Evas_Object *obj,void *event_info)
637 retm_if(data == NULL, "Data parameter is NULL");
639 SettingNetworkUG *ad = (SettingNetworkUG *) data;
640 setting_view_change(&setting_view_network_con_list, &setting_view_network_profile_delete, ad);
643 static void setting_network_con_list_click_softkey_create_cb(void *data, Evas_Object *obj,void *event_info)
647 retm_if(data == NULL, "Data parameter is NULL");
649 SettingNetworkUG *ad = (SettingNetworkUG *) data;
651 //setting_create_simple_popup(ad, ad->win_get, NULL, _("UX Undefined"));
654 //to add a new connection
656 //FREE(ad->con_name);
657 //ad->need_check_srvtype = FALSE;
658 //ad->con_name = strdup(STR_SETTING_NEW_CONNECTIONS);
659 FREE(ad->access_name);
660 setting_view_change(&setting_view_network_con_list, &setting_view_network_connection_create, ad);
664 setting_network_con_list_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
667 SETTING_TRACE_ERROR("TTT");
669 retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
671 SettingNetworkUG *ad = (SettingNetworkUG *) data;
673 setting_view_change(&setting_view_network_con_list,
674 &setting_view_network_con, ad);