2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <setting-reset-main.h>
18 #include <setting-cfg.h>
22 #define RESULT_FONT_SIZE 28 /* 18->28 */
23 #define ITEM_NAME_FONT_SIZE 35 /* 22->35 */
25 static int setting_reset_main_create(void *cb);
26 static int setting_reset_main_destroy(void *cb);
27 static int setting_reset_main_update(void *cb);
28 static int setting_reset_main_cleanup(void *cb);
30 setting_view setting_view_reset_main = {
31 .create = setting_reset_main_create,
32 .destroy = setting_reset_main_destroy,
33 .update = setting_reset_main_update,
34 .cleanup = setting_reset_main_cleanup,
37 static void setting_reset_main_click_softkey_reset_cb(void *data,
40 static void setting_reset_main_click_softkey_cancel_cb(void *data,
44 static gboolean setting_reset_main_create_password_sg(void *data);
45 static void setting_reset_check_state(Setting_Done_List_Data *list_data);
46 static void setting_reset_main_result_password_ug_cb(struct ui_gadget *ug,
50 /* ***************************************************
54 ***************************************************/
55 #if SUPPORT_DYNAMIC_THEME_CHANGING
56 static void setting_reset_vconf_change_cb(keynode_t *key, void *data)
61 SettingResetUG *ad = data;
62 char *vconf_name = vconf_keynode_get_name(key);
63 SETTING_TRACE("the value of [ %s ] just changed", vconf_name);
64 if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_WIDGET_THEME_STR)) {
65 //elm_theme_all_set(vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR));
66 elm_theme_set(NULL, vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR));
67 elm_config_all_flush();
69 int is_them_changed = FALSE;
70 vconf_get_bool(VCONFKEY_SETAPPL_THEM_CHANGED, &is_them_changed);
72 if (is_them_changed && ad->notify) {
73 setting_reset_result_popup_update(ad);
76 evas_object_del(ad->pop_progress);
77 ad->pop_progress = NULL;
80 ad->pop_progress = setting_create_popup_with_progressbar(ad, ad->win_get,
83 evas_object_show(ad->pop_progress);
90 static char *__result_gl_text_get(void *data, Evas_Object *obj,
94 Setting_GenGroupItem_Data *item_data =
95 (Setting_GenGroupItem_Data *) data;
97 if (!safeStrCmp(part, "elm.text.1")) { /* title */
98 char label[HELP_MSG_BUFF_SIZE + 1] = { 0, };
99 if (item_data->keyStr)
101 const char *key = setting_customize_text(_(item_data->keyStr), ITEM_NAME_FONT_SIZE, NULL, NULL);
102 safeStrNCat(label, key,HELP_MSG_BUFF_SIZE);
105 if (item_data->sub_desc)
107 safeStrNCat(label, ": ",HELP_MSG_BUFF_SIZE);
108 const char *sub_desc = setting_customize_text(_(item_data->sub_desc), RESULT_FONT_SIZE, NULL, NULL);
109 safeStrNCat(label, sub_desc,HELP_MSG_BUFF_SIZE);
112 return (char *)g_strdup(label);
117 static void __processing_popup_response_cb(void *data, Evas_Object *obj,
121 SettingResetUG *ad = data;
122 setting_reset_special_process(ad);
124 evas_object_del(ad->notify);
128 // key ungrab: after showing the result popup
129 Ecore_X_Display *disp = ecore_x_display_get();
130 Ecore_X_Window xwin = elm_win_xwindow_get((Evas_Object*)ug_get_window());
131 int ret = utilx_ungrab_key(disp, xwin, KEY_HOME);
133 SETTING_TRACE_ERROR("KEY_HOME ungrab error ret[%d]", ret);
137 bool __reset_all_idler(void *data)
140 retv_if(!data, FALSE);
141 SettingResetUG *ad = data;
146 const char *result_str = RESET_SUCESS_STR;
147 char ug_file[PATH_MAX + 1];
152 char *item_name = NULL;
154 for (; i < setting_cfg_get_category_length(); i++) {
155 SETTING_TRACE("group is:%s", _(setting_cfg_get_category_name(i)));
158 result_str = RESET_SUCESS_STR;
160 for (j = 0; j < setting_cfg_get_menu_length(i); j++) {
161 SETTING_TRACE("i:%d\tj:%d", i, j);
162 if (Cfg_Item_unResetable ==
163 setting_cfg_get_resetable_flag_idx(i, j))
165 // SETTING_TRACE("process %s:%s skipped",_(item_name), ug_args);
168 ug_args = setting_cfg_get_ug_args_idx(i, j);
169 item_name = setting_cfg_get_keyname_idx(i, j);
170 SETTING_TRACE(">>> process %s:%s",_(item_name), ug_args);
173 if (NULL == ug_args) /*special process*/
175 if (!safeStrCmp(KeyStr_DataRoaming, item_name)) {
176 ret = setting_reset_data_roaming();
177 } else if (!safeStrCmp(KeyStr_Landscape, item_name)) {
178 ret = setting_reset_rotation_lock();
183 result_str = RESET_FAILED_STR;
188 path = get_ug_path_from_ug_args((void *)ug_args);
189 b = get_bundle_from_ug_args((void *)ug_args);
191 if (snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, path) < 0) {
192 ad->reset_all_idler = NULL;
196 ret = setting_invoke_reset_function(ug_file, b, NULL);
197 //SETTING_TRACE("load %s[plugin_ret:%d]", ug_file, ret);
199 if (OPERATE_LIB_SUCESS > ret)
201 result_str = RESET_FAILED_STR;
210 memset(ug_file, 0, PATH_MAX);
212 SETTING_TRACE("process %s:%s %s",_(item_name), ug_args, _(result_str));
216 SETTING_TRACE_DEBUG("Reset totally %d items. result_str:%s", idx, result_str);
217 elm_object_text_set(ad->notify, _(result_str));
218 elm_popup_timeout_set(ad->notify, 2);
219 ad->reset_all_idler = NULL;
223 static void __reset_all_button_cb(void *data, Evas_Object *obj, void *event_info)
227 Setting_GenGroupItem_Data *item_Data = data;
228 ret_if(!item_Data->userdata);
229 SettingResetUG *ad = item_Data->userdata;
232 char pw_pass[SETTING_STR_SLP_LEN] = { 0, };
235 /* Check Password Setting status */
237 setting_get_string_slp_key(STR_SLP_LIST_PHONE_PASSWORD,
239 SETTING_TRACE("pw_pass:%s", pw_pass);
240 if (SETTING_RETURN_SUCCESS == ret && '\0' != pw_pass[0]) {
241 setting_reset_main_create_password_sg(ad);
245 // key grab: before showing processing popup
246 Ecore_X_Display *disp = ecore_x_display_get();
247 Ecore_X_Window xwin = elm_win_xwindow_get((Evas_Object*)ug_get_window());
248 ret = utilx_grab_key(disp, xwin, KEY_HOME, TOP_POSITION_GRAB);
250 SETTING_TRACE_ERROR("KEY_HOME grab error ret[%d]", ret);
254 setting_create_popup_without_btn(ad, ad->win_get, _("IDS_COM_POP_PROCESSING"), NULL, __processing_popup_response_cb, 0);
255 if (ad->reset_all_idler) {
256 ecore_idler_del(ad->reset_all_idler);
257 ad->reset_all_idler = NULL;
259 ad->reset_all_idler =
260 ecore_idler_add((Ecore_Task_Cb) __reset_all_idler, ad);
263 static int setting_reset_main_create(void *cb)
267 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
269 SettingResetUG *ad = (SettingResetUG *) cb;
270 Evas_Object *scroller = NULL;
271 #if SIMPLY_SUPPORT_ALL_RESET
273 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
275 _("IDS_COM_BODY_RESET"),
276 _("IDS_COM_BODY_BACK"), NULL,
277 setting_reset_main_click_softkey_cancel_cb,
281 setting_create_Gendial_field_def(scroller, &(ad->itc_1text), NULL,
282 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
283 NULL, NULL, 0, RESET_ALL_DESC,
286 Setting_GenGroupItem_Data *item_data =
287 (Setting_GenGroupItem_Data *) calloc(1,
289 (Setting_GenGroupItem_Data));
290 setting_retvm_if(!item_data, SETTING_RETURN_FAIL, "calloc failed");
291 item_data->userdata = ad;
292 item_data->keyStr = (char *)g_strdup(RESET_ALL);
293 item_data->swallow_type = SWALLOW_Type_1BUTTON;
295 if (Theme_Tizen_Black == setting_get_theme())
296 item_data->r_swallow_path = (char *)g_strdup("sweep");//pass button style
298 item_data->chk_change_cb = __reset_all_button_cb;
299 item_data->item = elm_genlist_item_append(scroller, &(ad->itc_1icon), item_data, NULL,
300 ELM_GENLIST_ITEM_NONE,
302 setting_view_reset_main.is_create = 1;
303 ad->main_scroller = scroller;
304 return SETTING_RETURN_SUCCESS;
308 Evas_Object *navi_bar = NULL;
310 Evas_Object *controllbar = NULL;
312 Evas_Object *view_layout = elm_layout_add(ad->win_main_layout);
313 elm_layout_file_set(view_layout, SETTING_THEME_EDJ_NAME,
315 evas_object_size_hint_weight_set(view_layout, EVAS_HINT_EXPAND, 0.0);
318 setting_create_layout_navi_bar(ad->win_main_layout, ad->win_get,
319 S_("IDS_COM_BODY_RESET"),
320 _("IDS_COM_SK_CANCEL"),
321 _("IDS_COM_BODY_RESET"), NULL,
322 setting_reset_main_click_softkey_cancel_cb,
323 setting_reset_main_click_softkey_reset_cb,
324 NULL, ad, view_layout, &navi_bar,
326 elm_object_item_disabled_set(elm_toolbar_last_item_get
327 (controllbar), EINA_TRUE);
329 /* ******************************************create frame */
330 Setting_Done_List_Data *list_data = &(ad->list_data); /* define a handle */
332 list_data->win_main = ad->ly_main;
333 list_data->UG_data = ad;
334 list_data->ly_parent = view_layout;
335 list_data->controllbar = controllbar;
338 list_data->chk_items[idx++].item_name = KeyStr_Select_All;
345 for (; i < setting_cfg_get_category_length(); i++) {
346 SETTING_TRACE("group is:%s", _(setting_cfg_get_category_name(i)));
348 for (j = 0; j < setting_cfg_get_menu_length(i); j++) {
349 if (Cfg_Item_unResetable ==
350 setting_cfg_get_resetable_flag_idx(i, j))
354 list_data->chk_items[idx].ug_args = ug_args =
355 setting_cfg_get_ug_args_idx(i, j);
356 list_data->chk_items[idx].item_name = item_name =
357 setting_cfg_get_keyname_idx(i, j);
359 SETTING_TRACE("process %s:\t%s",_(item_name), ug_args);
364 list_data->cur_item_num = idx;
365 SETTING_TRACE("list_data->cur_item_num:%d", list_data->cur_item_num);
366 scroller = setting_create_done_list(list_data);
367 elm_object_part_content_set(view_layout, "elm.swallow.contents", scroller);
369 ad->view_layout = view_layout;
370 ad->navi_bar = navi_bar;
371 ad->controllbar = controllbar;
372 /* *******************************************update info */
374 setting_view_reset_main.is_create = 1;
375 ad->itc_1text.func.text_get = __result_gl_text_get;
376 #if SUPPORT_DYNAMIC_THEME_CHANGING
377 (void) vconf_notify_key_changed(VCONFKEY_SETAPPL_WIDGET_THEME_STR,
378 setting_reset_vconf_change_cb, ad);
380 return SETTING_RETURN_SUCCESS;
383 static int setting_reset_main_destroy(void *cb)
387 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
389 SettingResetUG *ad = (SettingResetUG *) cb;
390 #if SUPPORT_DYNAMIC_THEME_CHANGING
391 (void)vconf_ignore_key_changed(VCONFKEY_SETAPPL_WIDGET_THEME_STR,
392 setting_reset_vconf_change_cb);
395 evas_object_del(ad->notify);
398 if (ad->old_notify) {
399 evas_object_del(ad->old_notify);
400 ad->old_notify = NULL;
402 if (ad->pop_progress)
404 evas_object_del(ad->pop_progress);
405 ad->pop_progress = NULL;
410 evas_object_del(ad->ask_popup);
411 ad->ask_popup = NULL;
415 ecore_animator_del(ad->animator);
419 if (ad->ly_main != NULL) {
420 evas_object_del(ad->ly_main);
421 setting_view_reset_main.is_create = 0;
424 return SETTING_RETURN_SUCCESS;
427 static int setting_reset_main_update(void *cb)
431 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
433 SettingResetUG *ad = (SettingResetUG *) cb;
435 if (ad->ly_main != NULL) {
436 evas_object_show(ad->ly_main);
439 return SETTING_RETURN_SUCCESS;
442 static int setting_reset_main_cleanup(void *cb)
446 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
448 SettingResetUG *ad = (SettingResetUG *) cb;
450 if (ad->ly_main != NULL) {
451 evas_object_hide(ad->ly_main);
454 return SETTING_RETURN_SUCCESS;
457 /* ***************************************************
461 ***************************************************/
463 static void __reset_an_item(Setting_Done_List_Data *list_data,
464 const char *item_name,
467 SettingResetUG *ad = (SettingResetUG *) list_data->UG_data;
468 Evas_Object *genlist = elm_object_content_get(ad->notify);
469 Setting_GenGroupItem_Data *item_data = NULL;
470 const char *result_str = RESET_SUCESS_STR;
471 if (NULL == ug_args) /*special process*/
474 if (!safeStrCmp(KeyStr_DataRoaming, item_name)) {
475 ret = setting_reset_data_roaming();
476 } else if (!safeStrCmp(KeyStr_Landscape, item_name)) {
477 ret = setting_reset_rotation_lock();
482 result_str = VCONF_RESET_FAILED_STR;
485 item_data = setting_create_Gendial_field_def(genlist, &(ad->itc_1text),
487 SWALLOW_Type_LAYOUT_SPECIALIZTION,
490 (char *)result_str, NULL);
494 char *path = get_ug_path_from_ug_args((void *)ug_args);
495 bundle *b = get_bundle_from_ug_args((void *)ug_args);
496 char ug_file[PATH_MAX];
497 if (snprintf(ug_file, PATH_MAX,
498 "%s/libug-%s.so", SETTING_UG_PATH, path) < 0) return;
500 int plugin_ret = setting_invoke_reset_function(ug_file, b, NULL);
501 SETTING_TRACE("load %s[plugin_ret:%d]", ug_file, plugin_ret);
503 if (LOAD_LIB_FAILED == plugin_ret) // -1
505 result_str = LOAD_LIB_FAILED_STR;
507 } else if (UNDEFINED_LIB_SYMBOL == plugin_ret) // -2
509 result_str = UNDEFINE_STR;
510 } else if (OPERATE_LIB_SUCESS <= plugin_ret){ // 0
511 result_str = RESET_SUCESS_STR;
514 result_str = RESET_FAILED_STR;
526 item_data = setting_create_Gendial_field_def(genlist, &(ad->itc_1text),
528 SWALLOW_Type_LAYOUT_SPECIALIZTION,
531 (char *)result_str, NULL);
535 elm_genlist_item_show(item_data->item, ELM_GENLIST_ITEM_SCROLLTO_IN);//show the last item
537 SETTING_TRACE_ERROR("error : item_data is NULL");
540 static Eina_Bool __reset_animator_cb(void *data)
542 SettingResetUG *ad = (SettingResetUG *) data;
544 SETTING_TRACE("Processing the %dth of %d",
545 ad->gl_index, ad->list_data.cur_item_num);
546 if (ad->gl_index >= ad->list_data.cur_item_num) {
547 ecore_animator_del(ad->animator);
549 if (ad->pop_progress) {
550 evas_object_del(ad->pop_progress);
551 ad->pop_progress = NULL;
554 return ECORE_CALLBACK_CANCEL;
556 if (ad->list_data.chk_items[ad->gl_index].data_GenItem->chk_status) {
557 __reset_an_item(&(ad->list_data),
558 ad->list_data.chk_items[ad->gl_index].item_name,
559 ad->list_data.chk_items[ad->gl_index].ug_args);
562 elm_check_state_set(ad->list_data.chk_items[ad->gl_index].data_GenItem->eo_check, 0);
563 ad->list_data.chk_items[ad->gl_index].data_GenItem->chk_status = 0;
567 return ECORE_CALLBACK_RENEW;
571 static void setting_reset_check_state(Setting_Done_List_Data *list_data)
574 SETTING_TRACE_DEBUG("********resetting*******");
576 SettingResetUG *ad = (SettingResetUG *) list_data->UG_data;
578 //some item must have been selected, or else cannot go into setting_reset_check_state()
579 ad->notify = elm_popup_add(ad->win_get);
580 elm_object_style_set(ad->notify,"menustyle");
581 elm_object_part_text_set(ad->notify, "title,text", RESET_RESULT_STR);
582 evas_object_size_hint_weight_set(ad->notify,
586 Evas_Object *btn = setting_create_button(ad->notify, _("IDS_COM_SK_OK"), NULL, setting_reset_result_popup_resp_cb, ad);
587 elm_object_part_content_set(ad->notify, "button1", btn);
590 Evas_Object *genlist = elm_genlist_add(ad->notify);
591 evas_object_size_hint_weight_set(genlist,
594 evas_object_size_hint_align_set(genlist,
598 elm_object_content_set(ad->notify, genlist);
600 evas_object_show(ad->notify);
601 ad->pop_progress = setting_create_popup_with_progressbar(ad, ad->win_get,
603 NULL, NULL, NULL, 0);
606 ad->animator = ecore_animator_add(__reset_animator_cb, ad);
608 /* reset sel_all item */
609 elm_check_state_set(list_data->chk_items[0].data_GenItem->eo_check, 0);
610 list_data->chk_items[0].data_GenItem->chk_status = 0;
616 setting_reset_main_result_password_ug_cb(struct ui_gadget *ug, bundle *result,
621 retm_if(priv == NULL, "Data parameter is NULL");
623 SettingResetUG *ad = (SettingResetUG *) priv;
625 const char *ret_str = bundle_get_val(result, "result");
626 SETTING_TRACE("result:%s", ret_str);
628 retm_if(ret_str == NULL, "result paremeter is NULL");
631 if (0 == safeStrCmp("SETTING_PW_TYPE_RESET", ret_str)) {
633 #if SIMPLY_SUPPORT_ALL_RESET
635 setting_create_popup_without_btn(ad, ad->win_get, _("IDS_COM_POP_PROCESSING"), NULL, __processing_popup_response_cb, 0);
636 if (ad->reset_all_idler) {
637 ecore_idler_del(ad->reset_all_idler);
638 ad->reset_all_idler = NULL;
640 ad->reset_all_idler =
641 ecore_idler_add((Ecore_Task_Cb) __reset_all_idler, ad);
643 setting_reset_check_state(&(ad->list_data));
650 setting_reset_main_layout_ug_cb(struct ui_gadget *ug, enum ug_mode mode,
653 SettingResetUG *ad = (SettingResetUG *) priv;
660 base = (Evas_Object *) ug_get_layout(ug);
665 case UG_MODE_FULLVIEW:
666 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
668 elm_win_resize_object_add(ad->win_get, base);
669 evas_object_show(base);
675 /* TODO animation effect here */
679 static void setting_reset_main_destroy_password_ug_cb(struct ui_gadget *ug,
685 SettingResetUG *ad = (SettingResetUG *) priv;
688 ad->ug_loading = NULL;
693 static gboolean setting_reset_main_create_password_sg(void *data)
697 retv_if(data == NULL, FALSE);
699 SettingResetUG *ad = (SettingResetUG *) data;
701 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
704 cbs->layout_cb = setting_reset_main_layout_ug_cb;
705 cbs->result_cb = setting_reset_main_result_password_ug_cb;
706 cbs->destroy_cb = setting_reset_main_destroy_password_ug_cb;
707 cbs->priv = (void *)ad;
708 bundle *b = bundle_create();
713 bundle_add(b, "viewtype", "SETTING_PW_TYPE_RESET");
716 ug_create(ad->ug, "setting-password-efl", UG_MODE_FULLVIEW, b, cbs);
717 if (NULL == ad->ug_loading) { /* error handling */
726 /* ***************************************************
730 ***************************************************/
733 setting_reset_main_click_softkey_cancel_cb(void *data, Evas_Object *obj,
738 retm_if(data == NULL, "Data parameter is NULL");
740 SettingResetUG *ad = (SettingResetUG *) data;
741 if (ad->list_data.selInfoPop) {
742 evas_object_del(ad->list_data.selInfoPop);
743 ad->list_data.selInfoPop = NULL;
745 /* Send destroy request */
746 ug_destroy_me(ad->ug);
750 setting_reset_main_click_softkey_reset_cb(void *data, Evas_Object *obj,
755 retm_if(data == NULL, "Data parameter is NULL");
757 SettingResetUG *ad = (SettingResetUG *) data;
759 //every time clicking 'Reset' button, restore following VCONFs
760 vconf_set_bool(VCONFKEY_SETAPPL_FONT_CHANGED, FALSE);
761 vconf_set_bool(VCONFKEY_SETAPPL_THEM_CHANGED, FALSE);
763 if (ad->list_data.selInfoPop) {
764 evas_object_del(ad->list_data.selInfoPop);
765 ad->list_data.selInfoPop = NULL;
768 if (!setting_done_list_is_some_item_selected(&(ad->list_data))) {
769 setting_create_popup_without_title(NULL, ad->win_get,
772 char pw_pass[SETTING_STR_SLP_LEN] = { 0, };
775 /* Check Password Setting status */
777 setting_get_string_slp_key(STR_SLP_LIST_PHONE_PASSWORD,
779 SETTING_TRACE("pw_pass:%s", pw_pass);
780 if (SETTING_RETURN_SUCCESS == ret && '\0' != pw_pass[0]) {
781 setting_reset_main_create_password_sg(ad);
783 setting_reset_check_state(&(ad->list_data));