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")) {
71 response_type = POPUP_RESPONSE_OK;
73 evas_object_del(ad->popup_conlist);
74 ad->popup_conlist = NULL;
76 if (POPUP_RESPONSE_OK == response_type) {
77 setting_view_destroy(&setting_view_network_con_list, ad);
78 setting_view_destroy(&setting_view_network_con, ad);
85 static void __enabled_tethering(void *data)
87 SettingNetworkUG *ad = (SettingNetworkUG *) data;
88 SETTING_TRACE("Tethering is enabled -- callback\n");
90 int frames = __get_naviframe_depth_con_list(ad);
93 ad->popup_conlist = setting_create_popup_with_btn(ad, ad->win_get,
94 NULL, _(SETTING_NETWORK_NOT_ALLOWED_WITH_TETHERING),
95 __popup_cb, 0, 1, "OK");
99 static void __disabled_tethering(void *data)
101 SETTING_TRACE("Tethering is disabled -- callback\n");
102 /*setting_enable_genlist_item(ad->data_connection->item); */
105 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
108 SettingNetworkUG *ad = (SettingNetworkUG *) data;
109 SETTING_TRACE("Tethering is enabled -- callback\n");
110 __enabled_tethering(ad);
113 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
116 SettingNetworkUG *ad = (SettingNetworkUG *) data;
117 SETTING_TRACE("Tethering is disabled -- callback\n");
118 __disabled_tethering(ad);
123 * if tethering is ON, 'connection' should be inactivated.
125 static bool is_tethering_enabled(void *data)
127 SettingNetworkUG *ad = (SettingNetworkUG *) data;
130 tethering_h th = NULL;
131 (void) tethering_create(&th);
133 ad->th_conlists = th;
135 tethering_set_enabled_cb(th, TETHERING_TYPE_ALL, __enabled_cb, data);
136 tethering_set_disabled_cb(th, TETHERING_TYPE_ALL, __disabled_cb, data);
138 if (tethering_is_enabled(th, TETHERING_TYPE_WIFI) == true ||
139 tethering_is_enabled(th, TETHERING_TYPE_USB) == true ||
140 tethering_is_enabled(th, TETHERING_TYPE_BT) == true) {
142 SETTING_TRACE("Tethering is enabled\n");
143 __enabled_tethering(ad);
146 SETTING_TRACE("Tethering is not enabled\n");
147 __disabled_tethering(ad);
151 /*tethering_destroy(th); */
156 /* ***************************************************
160 ***************************************************/
161 static int __con_list_recreate(void *cb)
164 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
165 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
166 Evas_Object *scroller;
167 scroller = ad->con_list_gl;
168 elm_genlist_clear(scroller); /* first to clear list */
169 Elm_Object_Item *first_item;
170 /* item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
171 first_item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
172 ELM_GENLIST_ITEM_NONE, NULL, NULL);
173 elm_genlist_item_select_mode_set(first_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
176 Setting_GenGroupItem_Data *item_data = NULL;
178 radio = elm_radio_add(scroller);
179 elm_radio_state_value_set(radio, -1);
181 setting_disable_evas_object(radio);
183 int srvType = ad->profile_service_type;
185 char *def_apn = NULL;
186 char *def_name = NULL;
188 connection_profile_h def_profile = NULL;
189 (void) connection_get_default_cellular_service_profile(ad->connection, srvType, &def_profile);
190 if (def_profile) connection_profile_get_cellular_apn(def_profile, &def_apn);
191 if (def_profile) connection_profile_get_name(def_profile, &def_name);
192 if (def_profile) connection_profile_get_id(def_profile, &def_id);
193 SETTING_TRACE("Default profile:%p, def_apn[%s], def_name[%s], def_id[%s]", def_profile, def_apn, def_name, def_id);
195 setting_network_reget_profile_list(ad);
197 Eina_List *elist = NULL;
198 connection_profile_h profile_h = NULL;
201 ad->selected_profile = NULL;
205 EINA_LIST_FOREACH(ad->profile_list, elist, profile_h) {
207 connection_profile_get_cellular_apn(profile_h, &apn);
208 connection_profile_get_name(profile_h, &name);
209 connection_profile_get_proxy_address(profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
210 connection_profile_get_id(profile_h, &id);
213 item_data = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
214 setting_retvm_if(!item_data, SETTING_RETURN_FAIL, "calloc failed");
215 item_data->keyStr = (char *)g_strdup(name);
216 item_data->swallow_type = SWALLOW_Type_1RADIO_1BTN;
217 item_data->r_swallow_path = (char *)g_strdup("reveal/extended");
218 item_data->chk_status = idx;
219 item_data->chk_change_cb = setting_network_con_list_chk_changed;
220 item_data->stop_change_cb = setting_network_con_list_go_button_cb;
221 item_data->rgd = radio;
222 item_data->userdata = ad;
223 item_data->sub_desc = (char *)g_strdup(apn);
224 item_data->keyStr2 = (char *)g_strdup(id);
226 ad->selected_profile = item_data; /*defaulty,it the first item */
227 item_data->group_style = SETTING_GROUP_STYLE_TOP;
229 item_data->group_style = SETTING_GROUP_STYLE_CENTER;
232 elm_genlist_item_append(scroller, &(itc_2text_2icon_3), item_data, NULL,
233 ELM_GENLIST_ITEM_NONE,
234 setting_network_con_list_item_Gendial_mouse_up_cb, ad);
236 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_TOP);
238 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_CENTER);
240 SETTING_TRACE("profile_h:%p, apn:%s, id:%s", profile_h, apn, id);
241 if (!safeStrCmp(def_apn, apn) && !safeStrCmp(def_name, name) && !safeStrCmp(def_id, id)) {
242 SETTING_TRACE("Matched [idx:%d, apn:%s, id:%s]!", idx, apn, id);
243 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) {
244 ad->selected_profile = item_data; /*the selected item */
245 elm_radio_value_set(radio, idx);
246 if (ad->internet_conn) {
247 G_FREE(ad->internet_conn->sub_desc);
248 FREE(ad->apn_internet);
249 ad->apn_internet = strdup(name);
250 ad->internet_conn->sub_desc = strdup(name);
251 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
252 elm_genlist_item_update(ad->internet_conn->item);
259 G_FREE(proxy_address);
263 ADD_GL_SEPARATOR(scroller);
265 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
266 SETTING_TRACE("idx:%d", idx);
267 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_con_list, "toolbar");
268 SETTING_TRACE("elm_object_text_get(del_btn):%s", elm_object_item_text_get(elm_toolbar_last_item_get(toolbar)));
270 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_NONE);
271 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_FALSE);
272 } else if (idx > 1) {
273 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
274 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_FALSE);
276 FREE(ad->apn_internet);
277 SETTING_TRACE("To disable");
278 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_TRUE);
280 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) {
281 if (idx > 0) elm_radio_value_set(radio, 0);/*the first one */
282 if (ad->selected_profile && !isEmptyStr(ad->selected_profile->keyStr) && ad->mms_conn) {
283 SETTING_TRACE("ad->selected_profile->keyStr:%s", ad->selected_profile->keyStr);
284 G_FREE(ad->mms_conn->sub_desc);
286 ad->apn_MMS = strdup(ad->selected_profile->keyStr);
287 ad->mms_conn->sub_desc = strdup(ad->selected_profile->keyStr);
288 elm_genlist_item_fields_update(ad->mms_conn->item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
291 ad->cur_profile_num = idx;
293 /* setting_create_simple_popup(ad, ad->navi_bar,NULL, "There is no avaiable profile,you can create one."); */
299 return SETTING_RETURN_SUCCESS;
302 static int setting_network_con_list_create(void *cb)
305 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
307 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
309 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
310 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
311 "Cannot set scroller object as contento of layout");
312 //elm_genlist_realization_mode_set(scroller, EINA_TRUE);
313 elm_object_style_set(scroller, "dialogue");
315 const char *title = NULL;
316 switch (ad->profile_service_type) {
317 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
318 title = "IDS_ST_BODY_MMS_CONNECTIONS";
320 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
321 title = "IDS_ST_BODY_INTERNET_CONNECTION";
324 title = ad->con_name;
328 ad->navi_it_con_list =
329 setting_push_layout_navi_bar(_(title),
330 _("IDS_ST_BUTTON_BACK"),
331 _("IDS_ST_BODY_DELETE"),
332 _("IDS_ST_BODY_MYTHEME_CREATE"),
334 setting_network_con_list_click_softkey_delete_cb,
335 setting_network_con_list_click_softkey_create_cb,
336 ad, scroller, ad->navi_bar, NULL);
338 elm_naviframe_item_pop_cb_set(ad->navi_it_con_list,
339 setting_network_con_list_click_softkey_cancel_cb, ad);
340 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
341 ad->con_list_gl = scroller;
342 __con_list_recreate(ad);
344 #if SUPPORT_TETHERING
345 is_tethering_enabled(ad);
347 setting_view_network_con_list.is_create = 1;
349 return SETTING_RETURN_SUCCESS;
352 static int setting_network_con_list_destroy(void *cb)
356 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
358 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
359 if (setting_view_network_con_list.is_create) {
360 /*ad->connections_gl = NULL; */
361 #if SUPPORT_TETHERING
362 if (ad->th_conlists) {
363 SETTING_TRACE("tethering destruction ");
364 tethering_destroy(ad->th_conlists);
365 ad->th_conlists = NULL;
368 setting_view_network_con_list.is_create = 0;
369 ad->selected_profile = NULL;
370 ad->navi_it_con_list = NULL;
371 ad->con_list_gl = NULL;
372 elm_naviframe_item_pop(ad->navi_bar);
374 SETTING_TRACE("why is this is_create == 0 ?? !!!");
376 return SETTING_RETURN_SUCCESS;
379 static int setting_network_con_list_update(void *cb)
383 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
384 __con_list_recreate(cb);
385 return SETTING_RETURN_SUCCESS;
388 static int setting_network_con_list_cleanup(void *cb)
391 return setting_network_con_list_destroy(cb);
392 /*return SETTING_RETURN_SUCCESS; */
395 /* ***************************************************
399 ***************************************************/
401 /* ***************************************************
405 ***************************************************/
406 static void setting_network_con_list_go_button_cb(void *data, Evas_Object *obj, void *event_info)
409 retm_if(data == NULL, "Data parameter is NULL");
410 Setting_GenGroupItem_Data *item_data = data;
412 SettingNetworkUG *ad = item_data->userdata;
413 FREE(ad->access_name);
414 ad->access_name = strdup(item_data->keyStr2);
415 setting_view_change(&setting_view_network_con_list, &setting_view_network_connection_create, ad);
419 static void ___network_con_set_default_cb(connection_error_e result, void *data)
422 setting_retm_if(data == NULL, "Data parameter is NULL");
423 Setting_GenGroupItem_Data *list_item = data;
424 SettingNetworkUG *ad = list_item->userdata;
425 setting_retm_if(ad == NULL, "ad parameter is NULL");
426 if (ad->network_ug_pop) {
427 evas_object_del(ad->network_ug_pop);
428 ad->network_ug_pop = NULL;
431 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
432 if (0 == safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION")) {
433 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
434 } else if (0 == safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) {
435 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
437 SETTING_TRACE("The result is :%d,but it is meaningless for our Setting", result);
438 ad->selected_profile = list_item;
439 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET && ad->internet_conn) {
440 G_FREE(ad->internet_conn->sub_desc);
441 FREE(ad->apn_internet);
442 ad->apn_internet = strdup(list_item->keyStr);
443 ad->internet_conn->sub_desc = strdup(list_item->keyStr);
444 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
445 elm_genlist_item_update(ad->internet_conn->item);
447 elm_genlist_realized_items_update(ad->con_list_gl);
451 static void __set_default_response_cb(void *data, Evas_Object *obj,
454 setting_retm_if(data == NULL, "Data parameter is NULL");
455 Setting_GenGroupItem_Data *list_item = data;
456 SettingNetworkUG *ad = list_item->userdata;
458 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
459 if (0 == safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION")) {
460 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
461 } else if (0 == safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) {
462 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
464 /*SETTING_TRACE("The result is :%d,but it is meaningless for our Setting", result); */
465 ad->selected_profile = list_item;
466 if (srvType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET && ad->internet_conn) {
467 G_FREE(ad->internet_conn->sub_desc);
468 FREE(ad->apn_internet);
469 ad->apn_internet = strdup(list_item->keyStr);
470 ad->internet_conn->sub_desc = strdup(list_item->keyStr);
471 elm_object_item_data_set(ad->internet_conn->item, ad->internet_conn);
472 elm_genlist_item_update(ad->internet_conn->item);
474 elm_genlist_realized_items_update(ad->con_list_gl);
477 evas_object_del(obj);
483 void __set_default_profile(void *data)
485 setting_retm_if(data == NULL, "Data parameter is NULL");
486 Setting_GenGroupItem_Data *list_item = data;
487 SettingNetworkUG *ad = list_item->userdata;
488 setting_retm_if(ad == NULL, "ad parameter is NULL");
490 connection_profile_iterator_h profile_iter = NULL;
491 connection_profile_h profile_h = NULL;
492 int rv = connection_get_profile_iterator(ad->connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
493 if (rv != CONNECTION_ERROR_NONE) {
494 SETTING_TRACE_ERROR("Fail to get profile iterator [%d]", rv);
500 char *profile_id = NULL;
501 connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
503 int srvType = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
504 if (0 == safeStrCmp(ad->con_name, "IDS_ST_BODY_INTERNET_CONNECTION")) {
505 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
506 } else if (0 == safeStrCmp(ad->con_name, STR_SETTING_MMS_CONNECTIONS)) {
507 srvType = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
509 while (connection_profile_iterator_has_next(profile_iter)) {
510 if (cnt >= MAX_PROFILE_NUM) {
513 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
514 SETTING_TRACE_ERROR("Fail to get profile handle");
517 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
518 SETTING_TRACE_ERROR("Fail to get service type");
522 connection_profile_get_cellular_apn(profile_h, &apn);
523 connection_profile_get_id(profile_h, &profile_id);
524 if (srvType != service_type) {
529 SETTING_TRACE("Record[%d] profile is %s(%s)", cnt, apn, profile_id);
530 if (0 == safeStrCmp(profile_id, list_item->keyStr2)) {
532 if (CONNECTION_CELLULAR_SERVICE_TYPE_MMS == srvType) {
533 setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_MSGF_POP_UNSUPPORTED"));
534 /*elm_radio_value_set(list_item->eo_check, old_type); */
535 if (ad->selected_profile)
536 elm_radio_value_set(list_item->eo_check, ad->selected_profile->chk_status);
539 SETTING_TRACE("Set default[%d] as [%s], profile:%p, id:%s", srvType, apn, profile_h, profile_id);
540 int ret = connection_set_default_cellular_service_profile(ad->connection, srvType, profile_h);
541 SETTING_TRACE("The result is :%d", ret);
543 if (ad->network_ug_pop) {
544 evas_object_del(ad->network_ug_pop);
545 ad->network_ug_pop = NULL;
547 if (ret != CONNECTION_ERROR_NONE) {
548 if (ad->selected_profile)
549 elm_radio_value_set(list_item->eo_check, ad->selected_profile->chk_status);
551 setting_create_popup_without_btn(list_item, ad->win_get, NULL,
552 _("IDS_CST_POP_FAILED"), NULL,
557 setting_create_popup_without_btn(list_item, ad->win_get, NULL,
558 _("IDS_ST_BUTTON2_PROCESSING_ING"), __set_default_response_cb,
569 static void setting_network_con_list_item_Gendial_mouse_up_cb(void *data, Evas_Object *obj, void *event_info)
573 setting_retm_if(data == NULL, "Data parameter is NULL");
575 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
576 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
577 elm_genlist_item_selected_set(item, 0);
578 Setting_GenGroupItem_Data *list_item =
579 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
580 setting_retm_if(NULL == list_item, "list_item is NULL");
582 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
583 if (list_item->chk_status == elm_radio_value_get(list_item->eo_check)) {
584 SettingNetworkUG *ad = data;
585 elm_genlist_realized_items_update(ad->con_list_gl);
589 elm_radio_value_set(list_item->eo_check, list_item->chk_status);
590 __set_default_profile(list_item);
592 void setting_network_con_list_chk_changed(void *data, Evas_Object *obj, void *event_info)
595 retm_if(data == NULL || obj == NULL, "Parameter is NULL");
596 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
597 list_item->chk_status = elm_radio_value_get(obj);
598 __set_default_profile(list_item);
602 static void setting_network_con_list_click_softkey_delete_cb(void *data, Evas_Object *obj, void *event_info)
606 retm_if(data == NULL, "Data parameter is NULL");
608 SettingNetworkUG *ad = (SettingNetworkUG *) data;
609 setting_view_change(&setting_view_network_con_list, &setting_view_network_profile_delete, ad);
612 static void setting_network_con_list_click_softkey_create_cb(void *data, Evas_Object *obj, void *event_info)
616 retm_if(data == NULL, "Data parameter is NULL");
618 SettingNetworkUG *ad = (SettingNetworkUG *) data;
620 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("UX Undefined")); */
623 /*to add a new connection */
624 /*ad->con_type = -1; */
625 /*FREE(ad->con_name); */
626 /*ad->need_check_srvtype = FALSE; */
627 /*ad->con_name = strdup(STR_SETTING_NEW_CONNECTIONS); */
628 FREE(ad->access_name);
629 setting_view_change(&setting_view_network_con_list, &setting_view_network_connection_create, ad);
633 setting_network_con_list_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
636 SETTING_TRACE_ERROR("TTT");
638 retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
640 SettingNetworkUG *ad = (SettingNetworkUG *) data;
642 setting_view_change(&setting_view_network_con_list,
643 &setting_view_network_con, ad);