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-profile-delete.h>
23 static int setting_network_profile_delete_create(void *cb);
24 static int setting_network_profile_delete_destroy(void *cb);
25 static int setting_network_profile_delete_update(void *cb);
26 static int setting_network_profile_delete_cleanup(void *cb);
28 setting_view setting_view_network_profile_delete = {
29 .create = setting_network_profile_delete_create,
30 .destroy = setting_network_profile_delete_destroy,
31 //.update = setting_network_profile_delete_update,
33 .cleanup = setting_network_profile_delete_cleanup,
36 /* ***************************************************
40 ***************************************************/
41 static void __profile_delete_list_draw(SettingNetworkUG *ad)
44 if (ad->profile_del_list != NULL) {
45 eina_list_free(ad->profile_del_list);
46 ad->profile_del_list = NULL;
48 elm_genlist_clear(ad->gl_profile_del); /* first to clear list */
49 Elm_Object_Item *first_item;
50 /* item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
51 first_item = elm_genlist_item_append(ad->gl_profile_del, &itc_seperator, NULL, NULL,
52 ELM_GENLIST_ITEM_NONE, NULL, NULL);
53 elm_genlist_item_select_mode_set(first_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
55 Eina_List *elist = NULL;
56 connection_profile_h profile_h = NULL;
61 char *proxy_address = NULL;
62 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
63 Setting_GenGroupItem_Data *item_data = NULL;
65 setting_network_reget_profile_list(ad);
67 // CREATE GENLIST 'Select All'
70 SETTING_TRACE("ad->profile_list:%p", ad->profile_list);
71 EINA_LIST_FOREACH(ad->profile_list, elist, profile_h) {
72 SETTING_TRACE("profile_h:%p", profile_h);
75 apn = name = proxy_address = id = NULL;
76 connection_profile_get_cellular_apn(profile_h, &apn);
79 connection_profile_get_name(profile_h, &name);
82 connection_profile_get_proxy_address(profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
83 connection_profile_get_id(profile_h, &id);
85 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
86 SETTING_TRACE_ERROR("Fail to get profile type");
90 SETTING_TRACE("Record[%s], profile_type:%d, service_type:%d, id:%s",
91 apn, profile_type, ad->profile_service_type, id);
93 item_data = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
95 SETTING_TRACE_ERROR("calloc failed");
99 item_data->keyStr = (char *)g_strdup(name);
100 item_data->swallow_type = SWALLOW_Type_1CHECK_RIGHT;
101 item_data->r_swallow_path = (char *)g_strdup("reveal/extended");
102 item_data->chk_change_cb = setting_network_profile_delete_check_cb;
103 item_data->userdata = ad;
104 item_data->sub_desc = (char *)g_strdup(apn);
105 item_data->belongs_to = (int) profile_h;
108 elm_genlist_item_append(ad->gl_profile_del, &(itc_2text_1icon_2), item_data, NULL,
109 ELM_GENLIST_ITEM_NONE,
110 setting_network_profile_delete_mouse_up_cb, ad);
111 ad->profile_del_list =
112 eina_list_append(ad->profile_del_list, item_data);
117 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
118 Evas_Object *allbtn = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "title_left_btn");
119 SETTING_TRACE("idx:%d", idx);
121 if (allbtn) elm_object_disabled_set(allbtn, EINA_FALSE);
122 } else if (idx > 1) {
123 if (allbtn) elm_object_disabled_set(allbtn, EINA_FALSE);
125 if (ad->profile_list != NULL) {
126 eina_list_free(ad->profile_list);
127 ad->profile_list = NULL;
129 SETTING_TRACE("To disable");
130 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_TRUE);
131 if (allbtn) elm_object_disabled_set(allbtn, EINA_TRUE);
132 SETTING_TRACE("To disable");
136 G_FREE(proxy_address);
141 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
142 static Evas_Object* ctxpopup;
145 ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
148 evas_object_del(ctxpopup);
153 move_more_ctxpopup(Evas_Object *ctxpopup)
160 /* We convince the top widget is a window */
161 win = elm_object_top_widget_get(ctxpopup);
162 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
163 pos = elm_win_rotation_get(win);
168 evas_object_move(ctxpopup, (w / 2), h);
171 evas_object_move(ctxpopup, (h / 2), w);
174 evas_object_move(ctxpopup, (h / 2), w);
180 naviframe_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
183 Evas_Object *ctxpopup = data;
184 move_more_ctxpopup(ctxpopup);
188 more_ctxpopup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
191 Evas_Object *nf = data;
192 evas_object_event_callback_del_full(nf, EVAS_CALLBACK_RESIZE, naviframe_resize_cb, ctxpopup);
196 win_rotation_changed_cb(void *data, Evas_Object *obj, void *event_info)
199 Evas_Object *ctxpopup = data;
200 move_more_ctxpopup(ctxpopup);
203 /* Icon + Text (More button style : Naviframe Toolbar) */
204 static void create_ctxpopup_more_button_cb(void *data, Evas_Object *obj, void *event_info)
207 SettingNetworkUG *ad = (SettingNetworkUG *) data;
209 Evas_Object *nf = ad->navi_bar;
213 if (ctxpopup != NULL) {
214 evas_object_del(ctxpopup);
217 ctxpopup = elm_ctxpopup_add(nf);
218 elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
219 elm_object_style_set(ctxpopup, "more/default");
220 eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK, eext_ctxpopup_back_cb, NULL);
221 eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_MORE, eext_ctxpopup_back_cb, NULL);
222 evas_object_smart_callback_add(ctxpopup, "dismissed", ctxpopup_dismissed_cb, NULL);
223 evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL, more_ctxpopup_del_cb, nf);
224 evas_object_event_callback_add(nf, EVAS_CALLBACK_RESIZE, naviframe_resize_cb, ctxpopup);
226 /* We convince the top widget is a window */
227 win = elm_object_top_widget_get(nf);
228 evas_object_smart_callback_add(win, "rotation,changed", win_rotation_changed_cb, ctxpopup);
230 //---------------------------------------------------------------------------------------------
231 elm_ctxpopup_item_append(ctxpopup, _("IDS_ST_BUTTON_CANCEL_ABB"), NULL, setting_network_profile_delete_click_softkey_cancel_cb, ad);
232 elm_ctxpopup_item_append(ctxpopup, _("IDS_ST_BODY_DELETE"), NULL, setting_network_profile_delete_click_softkey_delete_cb, ad);
233 //---------------------------------------------------------------------------------------------
235 elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN);
236 move_more_ctxpopup(ctxpopup);
237 evas_object_show(ctxpopup);
239 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
243 static int setting_network_profile_delete_create(void *cb)
246 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
248 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
249 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
250 "Cannot set scroller object as contento of layout");
251 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
252 elm_object_style_set(scroller, "dialogue");
253 elm_genlist_clear(scroller); /* first to clear list */
254 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
255 ad->gl_profile_del = scroller;
257 ad->navi_it_profile_del_list = setting_push_layout_navi_bar(_(IDS_ST_BODY_DELETE),
259 _(IDS_ST_BODY_DELETE),
260 _(IDS_ST_BUTTON_CANCEL_ABB),
261 setting_network_profile_delete_click_softkey_cancel_cb,
262 setting_network_profile_delete_click_softkey_delete_cb,
263 setting_network_profile_delete_click_softkey_cancel_cb,
264 ad, scroller, ad->navi_bar, NULL);
265 /*disable Delete button */
266 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
267 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
268 elm_object_item_disabled_set(it, EINA_TRUE);
270 Evas_Object *allbtn = elm_button_add(ad->navi_bar);
271 evas_object_size_hint_weight_set(allbtn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
272 evas_object_size_hint_align_set(allbtn, EVAS_HINT_FILL, 0.5);
274 elm_object_text_set(allbtn, _("IDS_ST_OPT_ALL"));
275 evas_object_smart_callback_add(allbtn, "clicked", setting_network_profile_delete_click_softkey_select_all_cb, ad);
276 evas_object_show(allbtn);
277 elm_object_item_part_content_set(ad->navi_it_profile_del_list, "title_right_btn", allbtn);
279 if (ad->navi_it_profile_del_list) {
280 elm_object_item_domain_text_translatable_set(ad->navi_it_profile_del_list, SETTING_PACKAGE, EINA_TRUE);
281 elm_naviframe_item_pop_cb_set(ad->navi_it_profile_del_list, setting_network_profile_delete_click_softkey_cancel_cb, ad);
284 // Add ctx popup handler
285 Evas_Object* morebtn = elm_button_add(ad->navi_bar);
286 elm_object_style_set(morebtn, "naviframe/more/default");
287 evas_object_smart_callback_add(morebtn, "clicked", create_ctxpopup_more_button_cb, ad);
288 elm_object_item_part_content_set(ad->navi_it_profile_del_list, "toolbar_more_btn", morebtn);
292 ad->data_delete_all = setting_create_Gendial_field_1radio(ad->gl_profile_del, &(ad->itc_1icon_1text_sub),
293 __screen_timeout_cb, ad,
294 SWALLOW_Type_1RADIO_RIGHT,
295 rdg, 4, KeyStr_Backlight_5_MIN_STR,
297 if (ad->data_delete_all) {
298 ad->data_delete_all->userdata = ad;
299 __BACK_POINTER_SET(ad->data_delete_all);
301 SETTING_TRACE_ERROR("ad->data_delete_all is NULL");
305 __profile_delete_list_draw(ad);
306 ADD_GL_SEPARATOR(scroller);
307 setting_view_network_profile_delete.is_create = 1;
309 return SETTING_RETURN_SUCCESS;
312 static int setting_network_profile_delete_destroy(void *cb)
315 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
316 if (!setting_view_network_profile_delete.is_create) {
317 return SETTING_RETURN_SUCCESS;
321 if (ad->profile_del_list != NULL) {
322 eina_list_free(ad->profile_del_list);
323 ad->profile_del_list = NULL;
325 ad->gl_profile_del = NULL;
326 ad->navi_it_profile_del_list = NULL;
327 elm_naviframe_item_pop(ad->navi_bar);
328 setting_view_network_profile_delete.is_create = 0;
330 return SETTING_RETURN_SUCCESS;
333 static int setting_network_profile_delete_update(void *cb)
337 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
338 __profile_delete_list_draw(cb);
339 return SETTING_RETURN_SUCCESS;
342 static int setting_network_profile_delete_cleanup(void *cb)
345 setting_network_profile_delete_destroy(cb);
346 return SETTING_RETURN_SUCCESS;
349 /* ***************************************************
353 ***************************************************/
354 void ___profile_selected(void *data)
356 SettingNetworkUG *ad = data;
357 retm_if(ad == NULL, "Invalid argument: ad is NULL");
358 Eina_List *check_list = ad->profile_del_list;
359 Setting_GenGroupItem_Data *item_data = NULL;
362 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
363 if (NULL == item_data)
366 SETTING_TRACE("%s :%d", _(item_data->keyStr), item_data->chk_status);
367 if (item_data->chk_status) {
370 check_list = eina_list_next(check_list);
372 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
374 Evas_Object *toolbar = elm_object_item_part_content_get(navi_it, "toolbar");
375 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
377 char title[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0, };
378 snprintf(title, MAX_DISPLAY_NAME_LEN_ON_UI, _("IDS_ST_HEADER_PD_SELECTED"), selnum);
379 elm_object_item_text_set(navi_it, _(title));
380 elm_object_item_disabled_set(it, EINA_FALSE);
382 elm_object_item_text_set(navi_it, _("IDS_ST_BODY_DELETE"));
383 elm_object_item_disabled_set(it, EINA_TRUE);
389 setting_network_profile_delete_check_cb(void *data, Evas_Object *obj,
392 retm_if(data == NULL, "Data parameter is NULL");
393 Setting_GenGroupItem_Data *list_item =
394 (Setting_GenGroupItem_Data *) data;
395 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
396 ___profile_selected(list_item->userdata);
400 setting_network_profile_delete_mouse_up_cb(void *data,
406 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
408 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
409 elm_genlist_item_selected_set(item, 0);
410 Setting_GenGroupItem_Data *list_item =
411 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
412 setting_retm_if(NULL == list_item, "list_item is NULL");
413 SETTING_TRACE("list_item->keyStr:%s", list_item->keyStr);
415 setting_update_gl_item_chk_status(list_item, !(list_item->chk_status));
416 ___profile_selected(list_item->userdata);
419 /* ***************************************************
423 ***************************************************/
424 static Eina_Bool setting_network_profile_delete_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
428 retvm_if(data == NULL, FALSE, "Data parameter is NULL");
429 SettingNetworkUG *ad = (SettingNetworkUG *) data;
430 setting_view_change(&setting_view_network_profile_delete,
431 &setting_view_network_con_list, ad);
433 if (ctxpopup != NULL) {
434 evas_object_del(ctxpopup);
440 static void __popup_deleted_response_cb(void *data, Evas_Object *obj,
443 retm_if(data == NULL, "Data parameter is NULL");
445 SettingNetworkUG *ad = (SettingNetworkUG *) data;
447 setting_view_change(&setting_view_network_profile_delete, &setting_view_network_con_list, ad);
451 setting_network_profile_delete_click_softkey_delete_cb(void *data,
458 retm_if(data == NULL, "Data parameter is NULL");
460 SettingNetworkUG *ad = (SettingNetworkUG *) data;
461 Eina_List *check_list = ad->profile_del_list;
462 Setting_GenGroupItem_Data *item_data = NULL;
464 connection_profile_h profile_h;
468 char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
469 char *def_apn = NULL;
470 char *def_name = NULL;
472 connection_profile_h def_profile = NULL;
473 (void) connection_get_default_cellular_service_profile(ad->connection, ad->profile_service_type, &def_profile);
474 if (def_profile) connection_profile_get_cellular_apn(def_profile, &def_apn);
475 if (def_profile) connection_profile_get_name(def_profile, &def_name);
476 if (def_profile) connection_profile_get_id(def_profile, &def_id);
477 SETTING_TRACE("Default profile:%p, def_apn[%s], def_name[%s]", def_profile, def_apn, def_name);
480 Setting_GenGroupItem_Data *first_valid_item = NULL;
484 item_data = (Setting_GenGroupItem_Data *) eina_list_data_get(check_list);
485 if (NULL == item_data) {
486 check_list = eina_list_next(check_list);
489 SETTING_TRACE("item_data->chk_status:%d", item_data->chk_status);
490 if (!item_data->chk_status) {
491 if (!first_valid_item) first_valid_item = item_data;/*intilize at the first time */
492 check_list = eina_list_next(check_list);
495 profile_h = (connection_profile_h)(item_data->belongs_to);
496 connection_profile_get_name(profile_h, &name);
497 connection_profile_get_cellular_apn(profile_h, &apn);
498 connection_profile_get_id(profile_h, &id);
499 if (!safeStrCmp(def_apn, apn) && !safeStrCmp(def_name, name) && !safeStrCmp(def_id, id)) {
502 if ((err = connection_remove_profile(ad->connection, profile_h)) != CONNECTION_ERROR_NONE) {
503 SETTING_TRACE_ERROR("*** [ERR] connection_add_profile. err=%d ***", err);
505 connection_profile_get_name(profile_h, &name);
506 SETTING_TRACE("name:%s", name);
507 if (!result) { /*already false */
508 g_strlcat(speciliztion, ", ", MAX_SPECIALIZITION_LEN);
509 g_strlcat(speciliztion, _(name), MAX_SPECIALIZITION_LEN);
511 g_strlcat(speciliztion, _(name), MAX_SPECIALIZITION_LEN);
517 if (first_valid_item) {
518 connection_profile_h first_profile_h = (connection_profile_h)(first_valid_item->belongs_to);
519 (void)connection_set_default_cellular_service_profile(ad->connection,
520 ad->profile_service_type,
524 /*eina_list_remove(ad->profile_list, profile_h); */
531 check_list = eina_list_next(check_list);
535 g_strlcat(speciliztion, _(": "), MAX_SPECIALIZITION_LEN);
536 g_strlcat(speciliztion, _("IDS_COM_POP_DELETE_FAILED"), MAX_SPECIALIZITION_LEN);
537 setting_create_popup(ad, ad->win_get, NULL, _(speciliztion), NULL, 0, false, false, 0);
539 if (ad->navi_it_profile_del_list)
540 elm_object_item_text_set(ad->navi_it_profile_del_list, _("IDS_ST_BODY_DELETE"));
542 if (ok_cnt) __profile_delete_list_draw(ad);
544 /*disable Delete button */
545 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
546 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
547 elm_object_item_disabled_set(it, EINA_TRUE);
551 setting_create_popup(ad, ad->win_get, NULL, "IDS_ST_BODY_DELETED", __popup_deleted_response_cb, 1, FALSE, FALSE, 0);
560 if (ctxpopup != NULL) {
561 evas_object_del(ctxpopup);
567 setting_network_profile_delete_click_softkey_select_all_cb(void *data,
572 retm_if(data == NULL, "Data parameter is NULL");
573 SettingNetworkUG *ad = data;
574 Eina_List *check_list = ad->profile_del_list;
575 Setting_GenGroupItem_Data *item_data = NULL;
579 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
580 if (NULL == item_data)
583 SETTING_TRACE("%s :%d", _(item_data->keyStr), item_data->chk_status);
584 if (item_data->chk_status) {
589 check_list = eina_list_next(check_list);
591 SETTING_TRACE("selnum:%d, un_selnum:%d", selnum, un_selnum);
592 if (un_selnum == 0 && selnum != 0) {
593 /*current all are selected,so it need to unselect all after click the button */
594 SETTING_TRACE("to unselect all");
595 check_list = ad->profile_del_list;
598 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
599 if (NULL == item_data)
601 setting_update_gl_item_chk_status(item_data, 0);
603 check_list = eina_list_next(check_list);
607 /*or else, to select all */
608 SETTING_TRACE("to select all");
609 check_list = ad->profile_del_list;
612 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
613 if (NULL == item_data)
616 setting_update_gl_item_chk_status(item_data, 1);
618 check_list = eina_list_next(check_list);
623 if (ad->navi_it_profile_del_list) {
624 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
625 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
627 char title[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0, };
628 snprintf(title, MAX_DISPLAY_NAME_LEN_ON_UI, _("IDS_ST_HEADER_PD_SELECTED"), selnum);
629 elm_object_item_text_set(ad->navi_it_profile_del_list, _(title));
630 elm_object_item_disabled_set(it, EINA_FALSE);
632 elm_object_item_text_set(ad->navi_it_profile_del_list, _("IDS_ST_BODY_DELETE"));
633 elm_object_item_disabled_set(it, EINA_TRUE);