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);
27 setting_view setting_view_network_profile_delete = {
28 .create = setting_network_profile_delete_create,
29 .destroy = setting_network_profile_delete_destroy,
30 .update = setting_network_profile_delete_update,
31 .cleanup = setting_network_profile_delete_cleanup,
34 /* ***************************************************
38 ***************************************************/
39 static void __profile_delete_list_draw(SettingNetworkUG *ad)
42 if (ad->profile_del_list != NULL) {
43 eina_list_free(ad->profile_del_list);
44 ad->profile_del_list = NULL;
46 elm_genlist_clear(ad->gl_profile_del); /* first to clear list */
47 Elm_Object_Item *first_item;
48 /* item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); */
49 first_item = elm_genlist_item_append(ad->gl_profile_del, &itc_seperator, NULL, NULL,
50 ELM_GENLIST_ITEM_NONE, NULL, NULL);
51 elm_genlist_item_select_mode_set(first_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
53 Eina_List *elist = NULL;
54 connection_profile_h profile_h = NULL;
59 char *proxy_address = NULL;
60 connection_profile_type_e profile_type = CONNECTION_PROFILE_TYPE_CELLULAR;
61 Setting_GenGroupItem_Data *item_data = NULL;
63 setting_network_reget_profile_list(ad);
64 SETTING_TRACE("ad->profile_list:%p", ad->profile_list);
65 EINA_LIST_FOREACH(ad->profile_list, elist, profile_h) {
66 SETTING_TRACE("profile_h:%p", profile_h);
69 apn = name = proxy_address = id = NULL;
70 connection_profile_get_cellular_apn(profile_h, &apn);
73 connection_profile_get_name(profile_h, &name);
76 connection_profile_get_proxy_address(profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
77 connection_profile_get_id(profile_h, &id);
79 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
80 SETTING_TRACE_ERROR("Fail to get profile type");
84 SETTING_TRACE("Record[%s], profile_type:%d, service_type:%d, id:%s",
85 apn, profile_type, ad->profile_service_type, id);
87 item_data = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
89 SETTING_TRACE_ERROR("calloc failed");
93 item_data->keyStr = (char *)g_strdup(name);
94 item_data->swallow_type = SWALLOW_Type_1CHECK;
95 item_data->r_swallow_path = (char *)g_strdup("reveal/extended");
96 /*item_data->chk_status = 0; */
97 item_data->chk_change_cb = setting_network_profile_delete_check_cb;
98 item_data->userdata = ad;
99 item_data->sub_desc = (char *)g_strdup(apn);
100 item_data->belongs_to = (int) profile_h;
102 item_data->group_style = SETTING_GROUP_STYLE_TOP;
104 item_data->group_style = SETTING_GROUP_STYLE_CENTER;
107 elm_genlist_item_append(ad->gl_profile_del, &(itc_2text_1icon_2), item_data, NULL,
108 ELM_GENLIST_ITEM_NONE,
109 setting_network_profile_delete_mouse_up_cb, ad);
111 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_TOP);
113 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_CENTER);
114 ad->profile_del_list =
115 eina_list_append(ad->profile_del_list, item_data);
119 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
121 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
122 Evas_Object *allbtn = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "title_left_btn");
123 SETTING_TRACE("idx:%d", idx);
125 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_NONE);
126 /*if (button) elm_object_disabled_set(button, EINA_FALSE); */
127 if (allbtn) elm_object_disabled_set(allbtn, EINA_FALSE);
128 } else if (idx > 1) {
129 setting_genlist_item_groupstyle_set(item_data, SETTING_GROUP_STYLE_BOTTOM);
130 /*if (button) elm_object_disabled_set(button, EINA_FALSE); */
131 if (allbtn) elm_object_disabled_set(allbtn, EINA_FALSE);
133 /*all are invalid,to delete directly */
134 if (ad->profile_list != NULL) {
135 eina_list_free(ad->profile_list);
136 ad->profile_list = NULL;
138 SETTING_TRACE("To disable");
139 elm_object_item_disabled_set(elm_toolbar_last_item_get(toolbar), EINA_TRUE);
140 /*if (button) elm_object_disabled_set(button, EINA_TRUE); */
141 if (allbtn) elm_object_disabled_set(allbtn, EINA_TRUE);
142 SETTING_TRACE("To disable");
146 G_FREE(proxy_address);
151 static int setting_network_profile_delete_create(void *cb)
154 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
156 Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
157 retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
158 "Cannot set scroller object as contento of layout");
159 elm_genlist_realization_mode_set(scroller, EINA_TRUE);
160 elm_object_style_set(scroller, "dialogue");
161 elm_genlist_clear(scroller); /* first to clear list */
162 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
163 ad->gl_profile_del = scroller;
165 ad->navi_it_profile_del_list = setting_push_layout_navi_bar(_("IDS_COM_SK_DELETE"),
166 dgettext("sys_string", "IDS_COM_BODY_BACK"),
167 dgettext("sys_string", "IDS_COM_SK_DELETE"),
168 _("IDS_COM_SK_CANCEL"),
169 setting_network_profile_delete_click_softkey_cancel_cb,
170 setting_network_profile_delete_click_softkey_delete_cb,
171 setting_network_profile_delete_click_softkey_cancel_cb,
172 ad, scroller, ad->navi_bar, NULL);
173 /*disable Delete button */
174 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
175 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
176 elm_object_item_disabled_set(it, EINA_TRUE);
178 Evas_Object *allbtn = elm_button_add(ad->navi_bar);
180 elm_object_style_set(allbtn, "naviframe/title_icon");
181 Evas_Object *icon = elm_icon_add(allbtn);
182 elm_object_text_set(allbtn, _("IDS_ST_OPT_ALL"));
183 /*elm_image_file_set(icon, EDJ_NAME, "icon.select_all"); */
184 elm_image_file_set(icon, SETTING_ICON_PATH_CFG"select_all.png", NULL);
186 /*evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1 , 1); */
187 /*elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE); */
188 elm_object_content_set(allbtn, icon);
189 elm_object_focus_allow_set(allbtn, EINA_FALSE);
190 evas_object_propagate_events_set(allbtn, EINA_FALSE);
191 evas_object_smart_callback_add(allbtn, "clicked", setting_network_profile_delete_click_softkey_select_all_cb, ad);
192 evas_object_show(allbtn);
193 elm_object_item_part_content_set(ad->navi_it_profile_del_list, "title_left_btn", allbtn);
194 __profile_delete_list_draw(ad);
195 ADD_GL_SEPARATOR(scroller);
196 setting_view_network_profile_delete.is_create = 1;
198 return SETTING_RETURN_SUCCESS;
201 static int setting_network_profile_delete_destroy(void *cb)
204 SettingNetworkUG *ad = (SettingNetworkUG *) cb;
205 if (!setting_view_network_profile_delete.is_create)
206 return SETTING_RETURN_SUCCESS;
209 if (ad->profile_del_list != NULL) {
210 eina_list_free(ad->profile_del_list);
211 ad->profile_del_list = NULL;
213 ad->gl_profile_del = NULL;
214 ad->navi_it_profile_del_list = NULL;
215 setting_view_network_profile_delete.is_create = 0;
216 elm_naviframe_item_pop(ad->navi_bar);
218 return SETTING_RETURN_SUCCESS;
221 static int setting_network_profile_delete_update(void *cb)
225 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
226 __profile_delete_list_draw(cb);
227 return SETTING_RETURN_SUCCESS;
230 static int setting_network_profile_delete_cleanup(void *cb)
232 return setting_network_profile_delete_destroy(cb);
235 /* ***************************************************
239 ***************************************************/
240 void ___profile_selected(void *data)
242 SettingNetworkUG *ad = data;
243 retm_if(ad == NULL, "Invalid argument: ad is NULL");
244 Eina_List *check_list = ad->profile_del_list;
245 Setting_GenGroupItem_Data *item_data = NULL;
248 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
249 if (NULL == item_data)
252 SETTING_TRACE("%s :%d", _(item_data->keyStr), item_data->chk_status);
253 if (item_data->chk_status) {
256 check_list = eina_list_next(check_list);
258 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
260 Evas_Object *toolbar = elm_object_item_part_content_get(navi_it, "toolbar");
261 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
263 char title[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0, };
264 snprintf(title, MAX_DISPLAY_NAME_LEN_ON_UI, _("IDS_ST_HEADER_PD_SELECTED"), selnum);
265 elm_object_item_text_set(navi_it, _(title));
266 elm_object_item_disabled_set(it, EINA_FALSE);
268 elm_object_item_text_set(navi_it, _("IDS_COM_SK_DELETE"));
269 elm_object_item_disabled_set(it, EINA_TRUE);
275 setting_network_profile_delete_check_cb(void *data, Evas_Object *obj,
278 retm_if(data == NULL, "Data parameter is NULL");
279 Setting_GenGroupItem_Data *list_item =
280 (Setting_GenGroupItem_Data *) data;
281 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
282 ___profile_selected(list_item->userdata);
286 setting_network_profile_delete_mouse_up_cb(void *data,
292 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
294 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
295 elm_genlist_item_selected_set(item, 0);
296 Setting_GenGroupItem_Data *list_item =
297 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
298 SETTING_TRACE("list_item->keyStr:%s", list_item->keyStr);
300 setting_update_gl_item_chk_status(list_item, !(list_item->chk_status));
301 ___profile_selected(list_item->userdata);
304 /* ***************************************************
308 ***************************************************/
310 setting_network_profile_delete_click_softkey_cancel_cb(void *data,
317 retm_if(data == NULL, "Data parameter is NULL");
318 SettingNetworkUG *ad = (SettingNetworkUG *) data;
319 setting_view_change(&setting_view_network_profile_delete,
320 &setting_view_network_con_list, ad);
323 static void __popup_deleted_response_cb(void *data, Evas_Object *obj,
326 retm_if(data == NULL, "Data parameter is NULL");
328 SettingNetworkUG *ad = (SettingNetworkUG *) data;
330 setting_view_change(&setting_view_network_profile_delete, &setting_view_network_con_list, ad);
334 setting_network_profile_delete_click_softkey_delete_cb(void *data,
341 retm_if(data == NULL, "Data parameter is NULL");
343 SettingNetworkUG *ad = (SettingNetworkUG *) data;
344 Eina_List *check_list = ad->profile_del_list;
345 Setting_GenGroupItem_Data *item_data = NULL;
347 connection_profile_h profile_h;
351 char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
352 char *def_apn = NULL;
353 char *def_name = NULL;
355 connection_profile_h def_profile = NULL;
356 (void) connection_get_default_cellular_service_profile(ad->connection, ad->profile_service_type, &def_profile);
357 if (def_profile) connection_profile_get_cellular_apn(def_profile, &def_apn);
358 if (def_profile) connection_profile_get_name(def_profile, &def_name);
359 if (def_profile) connection_profile_get_id(def_profile, &def_id);
360 SETTING_TRACE("Default profile:%p, def_apn[%s], def_name[%s]", def_profile, def_apn, def_name);
363 Setting_GenGroupItem_Data *first_valid_item = NULL;
367 item_data = (Setting_GenGroupItem_Data *) eina_list_data_get(check_list);
368 if (NULL == item_data) {
369 check_list = eina_list_next(check_list);
372 SETTING_TRACE("item_data->chk_status:%d", item_data->chk_status);
373 if (!item_data->chk_status) {
374 if (!first_valid_item) first_valid_item = item_data;/*intilize at the first time */
375 check_list = eina_list_next(check_list);
378 profile_h = (connection_profile_h)(item_data->belongs_to);
379 connection_profile_get_name(profile_h, &name);
380 connection_profile_get_cellular_apn(profile_h, &apn);
381 connection_profile_get_id(profile_h, &id);
382 if (!safeStrCmp(def_apn, apn) && !safeStrCmp(def_name, name) && !safeStrCmp(def_id, id)) {
385 if ((err = connection_remove_profile(ad->connection, profile_h)) != CONNECTION_ERROR_NONE) {
386 SETTING_TRACE_ERROR("*** [ERR] connection_add_profile. err=%d ***", err);
387 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_COM_POP_FAILED")); */
389 connection_profile_get_name(profile_h, &name);
390 SETTING_TRACE("name:%s", name);
391 if (!result) { /*already false */
392 g_strlcat(speciliztion, ", ", MAX_SPECIALIZITION_LEN);
393 g_strlcat(speciliztion, _(name), MAX_SPECIALIZITION_LEN);
395 g_strlcat(speciliztion, _(name), MAX_SPECIALIZITION_LEN);
401 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("Deleting default profile")); */
403 if (first_valid_item) {
404 connection_profile_h first_profile_h = (connection_profile_h)(first_valid_item->belongs_to);
405 (void)connection_set_default_cellular_service_profile(ad->connection,
406 ad->profile_service_type,
410 /*eina_list_remove(ad->profile_list, profile_h); */
417 check_list = eina_list_next(check_list);
421 g_strlcat(speciliztion, _(": "), MAX_SPECIALIZITION_LEN);
422 g_strlcat(speciliztion, _("IDS_COM_POP_DELETE_FAILED"), MAX_SPECIALIZITION_LEN);
423 setting_create_simple_popup(ad, ad->win_get, NULL, _(speciliztion));
425 if (ad->navi_it_profile_del_list)
426 elm_object_item_text_set(ad->navi_it_profile_del_list, _("IDS_COM_SK_DELETE"));
428 if (ok_cnt) __profile_delete_list_draw(ad);
430 /*disable Delete button */
431 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
432 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
433 elm_object_item_disabled_set(it, EINA_TRUE);
437 /*setting_create_simple_popup(ad, ad->win_get, NULL, _("IDS_COM_POP_SUCCESS")); */
438 setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_COM_POP_DELETED"), __popup_deleted_response_cb, 1, FALSE, FALSE);
439 /*setting_create_popup_without_btn(ad, ad->win_get, NULL, _("IDS_COM_POP_DELETED"), __popup_deleted_response_cb, 0.5, FALSE, FALSE); */
450 setting_network_profile_delete_click_softkey_select_all_cb(void *data,
455 retm_if(data == NULL, "Data parameter is NULL");
456 SettingNetworkUG *ad = data;
457 Eina_List *check_list = ad->profile_del_list;
458 Setting_GenGroupItem_Data *item_data = NULL;
462 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
463 if (NULL == item_data)
466 SETTING_TRACE("%s :%d", _(item_data->keyStr), item_data->chk_status);
467 if (item_data->chk_status) {
472 check_list = eina_list_next(check_list);
474 SETTING_TRACE("selnum:%d, un_selnum:%d", selnum, un_selnum);
475 if (un_selnum == 0 && selnum != 0) {
476 /*current all are selected,so it need to unselect all after click the button */
477 SETTING_TRACE("to unselect all");
478 check_list = ad->profile_del_list;
481 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
482 if (NULL == item_data)
484 setting_update_gl_item_chk_status(item_data, 0);
486 check_list = eina_list_next(check_list);
490 /*or else, to select all */
491 SETTING_TRACE("to select all");
492 check_list = ad->profile_del_list;
495 item_data = (Setting_GenGroupItem_Data *)eina_list_data_get(check_list);
496 if (NULL == item_data)
499 setting_update_gl_item_chk_status(item_data, 1);
501 check_list = eina_list_next(check_list);
506 if (ad->navi_it_profile_del_list) {
507 Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it_profile_del_list, "toolbar");
508 Elm_Object_Item *it = elm_toolbar_last_item_get(toolbar);
510 char title[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0, };
511 snprintf(title, MAX_DISPLAY_NAME_LEN_ON_UI, _("IDS_ST_HEADER_PD_SELECTED"), selnum);
512 elm_object_item_text_set(ad->navi_it_profile_del_list, _(title));
513 elm_object_item_disabled_set(it, EINA_FALSE);
515 elm_object_item_text_set(ad->navi_it_profile_del_list, _("IDS_COM_SK_DELETE"));
516 elm_object_item_disabled_set(it, EINA_TRUE);