3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <appcore-common.h>
24 #include "setting-common-plugin.h"
25 #include "setting-main.h"
26 #include <elm_object.h>
32 extern void setting_update_gl_item(void* data);
34 #define KEY_END "XF86Stop"
35 #define SUPPORT_UG_MESSAGE
37 int g_geometry_x, g_geometry_y, g_geometry_w, g_geometry_h;
39 void termination_handler(int signum)
42 SETTING_TRACE(">>>>>>>>>>> SIGTERM >>>>>>>>>>>>>>> SETTING");
47 static void __main_motion_sensor_cb( unsigned long long timestamp, void *data)
49 /* The code 'return ;' will be deleted after the defect of elm_genlist_item_top_show() is fixed */
51 setting_retm_if(NULL == data, "NULL == data");
52 setting_main_appdata *ad = (setting_main_appdata *) data;
54 SETTING_TRACE(">>>>>>>Double tap event detected");
55 //If it is in UG mode, Setting just send the event to the loaded UG
57 if (ad->isInUGMode && ad->ug) {
58 #ifdef SUPPORT_UG_MESSAGE
59 SETTING_TRACE(">>>>>>>Send event to UG");
62 if(service_create(&svc))
65 service_add_extra_data(svc, "Detected", "Double_tap_event");
66 if (ug_send_message(ad->ug, svc) != 0) {
67 SETTING_TRACE_ERROR("call ug_send_message fail");
72 //Methord: instead of send message to UG and its sub-UGs,
73 //1.To get the layout of UG ,and then
74 //2.To get the naviframe of the layout, and then,
75 //3.To get the toppest item of naviframe, and then
76 //4.To get the content of naviframe toppest item,that is content
77 //5.content ia mainly a genlist,but it is not fixed,it maybe a conformant or another layout
78 // if it is a genlist,directly show its top item
79 // if it is a conformant or another layout,to get all of its sub-objects,then ask turnly
80 // whether it is a genlist,if it is(some sub-object), topply show it.
82 Evas_Object *layout = (Evas_Object *)ug_get_layout(ad->ug);
84 Evas_Object *genlist = NULL;
85 Evas_Object *navi_bar = elm_object_part_content_get(layout, "elm.swallow.content");
86 Elm_Object_Item *item = elm_naviframe_top_item_get(navi_bar);
87 Evas_Object *content = elm_object_item_content_get(item);
88 //SETTING_TRACE("content:%p", content);
90 const char *type = elm_object_widget_type_get(content);
91 //SETTING_TRACE("content type:%s", type);
92 if (0 == safeStrCmp(type, "genlist")) {
94 } else if (NULL != type) {//type="layout","conformant" etc..
96 //genlist = elm_object_part_content_get(content, "elm.swallow.contents");
97 const Eina_List *subobjs = elm_widget_sub_object_list_get(content);
102 //just only search the first objects level
103 EINA_LIST_FOREACH(subobjs, l, subobj) {
104 if (!subobj) continue;
105 type = elm_object_widget_type_get(subobj);
106 if (0 == safeStrCmp(type, "genlist")) {
108 Elm_Object_Item *first_item = elm_genlist_first_item_get(genlist);
110 elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
114 return;//to return,because for this case,we need special process.
116 //keep genlist to be NULL.
118 if (genlist && 0 == safeStrCmp(elm_object_widget_type_get(genlist), "genlist")) {
119 SETTING_TRACE("Get the genlist:%p", genlist);
120 Elm_Object_Item *first_item = elm_genlist_first_item_get(genlist);
122 elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
128 setting_go_to_navibar_list_top(ad->navibar_main);
133 * The event process when hard key is pressed.
136 static int setting_main_keydown_cb(void *data, int type, void *event)
140 static int s_count = 0;
141 Ecore_Event_Key *ev = event;
142 #if APPLIED_BACK_KEY_UG
143 if (!safeStrCmp(ev->keyname, KEY_END)) {
144 Evas_Object *popup = get_toppest_popup_window(ad->evas);
146 /* "progressbar"ÀàÐ͵Äpopup, ²»×÷´¦Àí */
147 Evas_Object *content = elm_object_content_get(popup);
148 const char *type = elm_widget_type_get(content);
149 if (type && !safeStrCmp(type, "progressbar")) {
150 SETTING_TRACE_DEBUG ("Found popup[%p], but it respresent a progress bar, so skip it.", popup);
152 evas_object_smart_callback_call(popup, "timeout", NULL);
158 if (ad->isInUGMode) { /* have some ug being loaded, it was reset to be FALSE in setting_main_destroy_ug_cb() */
159 SETTING_TRACE("Send UG_KEY_EVENT_END to ug");
160 ug_send_key_event(UG_KEY_EVENT_END);
162 if (elm_naviframe_top_item_get(ad->navibar_main)
163 == elm_naviframe_bottom_item_get(ad->navibar_main)) {
164 SETTING_TRACE("To exit Setting App");
167 SETTING_TRACE("To pre-view of Setting App");
168 elm_naviframe_item_pop(ad->navibar_main);
173 if (ev && !safeStrCmp(ev->keyname, KEY_END)) {
174 /* do nothing except exit */
175 SETTING_TRACE("before --- elm_exit ");
178 s_count = s_count + 1;
179 SETTING_TRACE("after --- elm_exit = %d ", s_count);
187 #if LOW_BATTERY_DO_NOTHING
189 /* in case of low battery, don't terminate itself.*/
192 * The event process when battery becomes low.
194 static void setting_main_low_battery_cb(void *data)
197 setting_main_appdata *ad = data;
200 ug_send_event(UG_EVENT_LOW_BATTERY);
204 #if SUPPORT_APP_ROATION
207 * To active rotation effect in Setting App
209 static void setting_main_rotate(app_device_orientation_e m, void *data)
212 setting_main_appdata *ad = data;
214 if (ad == NULL || ad->win_main == NULL)
220 (VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &value);
221 // true : aoto rotation OFF
222 // false : auto rotation ON
226 //vconf_get_bool (VCONFKEY_SETAPPL_ROTATE_HOLD_BOOL, &hold_flag);
227 //SETTING_TRACE("hold_flag:%d", hold_flag);
235 vconf_get_bool (VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &value);
240 elm_win_rotation_with_resize_set(ad->win_main, m);
242 /////Send the rotation event to UGs..
243 enum ug_event event = UG_EVENT_ROTATE_PORTRAIT;
245 case APP_DEVICE_ORIENTATION_0:
246 event = UG_EVENT_ROTATE_PORTRAIT;
248 case APP_DEVICE_ORIENTATION_180:
249 event = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
251 case APP_DEVICE_ORIENTATION_90:
252 event = UG_EVENT_ROTATE_LANDSCAPE;
254 case APP_DEVICE_ORIENTATION_270:
255 event = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
260 ug_send_event(event);
261 //elm_win_rotation_get
265 static void _rot_changed_cb(void *data, Evas_Object *obj, void *event_info)
268 setting_main_appdata *ad = (setting_main_appdata *)data;
269 if (ad == NULL || ad->win_main == NULL )
271 int change_ang = elm_win_rotation_get(ad->win_main);
272 SETTING_TRACE("....change_ang:%d",change_ang);
273 SETTING_TRACE("current_rotation:%d",ad->current_rotation);
274 //Send the rotation event to UGs..
275 enum ug_event event = UG_EVENT_ROTATE_PORTRAIT;
276 switch (change_ang) {
277 case APP_DEVICE_ORIENTATION_0:
278 event = UG_EVENT_ROTATE_PORTRAIT;
280 case APP_DEVICE_ORIENTATION_180:
281 event = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
283 case APP_DEVICE_ORIENTATION_270:
284 event = UG_EVENT_ROTATE_LANDSCAPE;
286 case APP_DEVICE_ORIENTATION_90:
287 event = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
292 SETTING_TRACE("diff:%d",elm_win_rotation_get(ad->win_main) - ad->current_rotation);
294 if (change_ang != ad->current_rotation)
296 ug_send_event(event);
297 ad->current_rotation = change_ang;
303 * The event process when region is changes.
305 static void setting_main_region_changed_cb(void *data)
307 setting_main_appdata *ad = data;
310 ug_send_event(UG_EVENT_REGION_CHANGE);
314 * The event process when win object is destroyed
316 static void setting_main_del_win(void *data, Evas_Object *obj, void *event)
321 void profile_changed_cb(void *data, Evas_Object * obj, void *event)
323 const char *profile = elm_config_profile_get();
325 if (strcmp(profile, "desktop") == 0)
326 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_HIDE);
328 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_SHOW);
332 * To create a win object, the win is shared between the App and all its UGs
334 static Evas_Object *setting_main_create_win(const char *name)
340 //eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
341 eo = elm_win_util_standard_add(name, name);
343 elm_win_title_set(eo, name);
344 evas_object_smart_callback_add(eo, "delete,request", setting_main_del_win, NULL);
345 evas_object_smart_callback_add(eo, "profile,changed", profile_changed_cb, NULL);
346 //elm_win_conformant_set(eo, EINA_TRUE);
347 ecore_x_window_size_get(ecore_x_window_root_first_get(),
349 evas_object_resize(eo, w, h);
356 * exceptional process, reset the env vars by Setting vconf VCONFKEY_LANGSET
358 static void setting_main_lang_changed_cb(void *data)
361 setting_main_appdata *ad = data;
365 str = (char *)get_pa_Wi_Fi_on_off_str();
366 if ( ! str) str = g_strdup("err");
367 ad->data_wifi->sub_desc = str;
370 str = (char *)g_strdup(get_BT_on_off_str());
371 if ( ! str) str = g_strdup("err");
372 ad->data_bt->sub_desc = str;
375 str = (char *)g_strdup(get_NFC_on_off_str());
376 if ( ! str) str = g_strdup("err");
377 ad->data_nfc->sub_desc = str;
379 if (ad->data_bright) {
380 str = (char*)g_strdup(get_brightness_mode_str());
381 if ( ! str) str = g_strdup("err");
382 ad->data_bright->sub_desc = str;
385 if (ad->data_moreConnect) {
386 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
388 while (idx < MAX_MORE_MENU_NUM && ad->more_connective_menus[idx])
392 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
394 safeStrNCat(sub_text, _(ad->more_connective_menus[idx]), MAX_COMMON_BUFFER_LEN);
397 ad->data_moreConnect->sub_desc = g_strdup(sub_text);
400 if (ad->data_moreSystem) {
401 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
403 while (idx < MAX_MORE_MENU_NUM && ad->more_system_menus[idx])
407 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
409 safeStrNCat(sub_text, _(ad->more_system_menus[idx]), MAX_COMMON_BUFFER_LEN);
412 ad->data_moreSystem->sub_desc = g_strdup(sub_text);
415 if (ad->main_genlist) elm_genlist_realized_items_update(ad->main_genlist);
416 if (ad->genlist_load) elm_genlist_realized_items_update(ad->genlist_load);
418 Elm_Object_Item *navi_it = NULL;
419 #if SUPPORT_MORE_ITEM_FUNCTION
420 navi_it = elm_naviframe_top_item_get(ad->navibar_main);
421 if (navi_it) elm_object_item_text_set(navi_it, _(KeyStr_MoreSystem));
424 navi_it = elm_naviframe_bottom_item_get(ad->navibar_main);
426 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_SETTINGS"));
430 #if SUPPORT_BOTTOM_BTNS
431 elm_object_item_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
433 Evas_Object *eo_btn = elm_object_item_part_content_get(ad->edit_item, "object");
434 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
435 elm_object_text_set(eo_btn, _(EDIT_PREFERRED_STR));
440 elm_object_item_text_set(ad->segment_all, _(ALL_STR));
441 if (ad->segment_preferred)
442 elm_object_item_text_set(ad->segment_preferred, _(PREFERRED_STR));
445 char tmp_text[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0,};
446 if (MAIN_PROFILE_ALL == ad->profile_type) {
447 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(PREFERRED_STR));
448 } else if (MAIN_PROFILE_PREFERRED == ad->profile_type) {
449 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(ALL_STR));
453 Evas_Object *btn = elm_object_item_part_content_get(navi_it, "toolbar_button1");
454 elm_object_text_set(btn, tmp_text);
458 ug_send_event(UG_EVENT_LANG_CHANGE);
462 * the event process when other VCONFS changes
464 static void setting_other_vconf_change_cb(keynode_t *key, void *data)
466 setting_main_appdata *ad = data;
467 retm_if(!data, "Invalid argument: data is NULL");
469 Setting_GenGroupItem_Data* item_to_update = NULL;
470 char *vconf_name = vconf_keynode_get_name(key);
471 //SETTING_TRACE("the value of [ %s ] just changed", vconf_name);
473 if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_WIDGET_THEME_STR)) {
475 } else if (!safeStrCmp(vconf_name, VCONFKEY_TELEPHONY_FLIGHT_MODE)) {
476 item_to_update = ad->data_flight;
477 retm_if(!item_to_update, "ad->data_flight is NULL");
480 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &status);
481 item_to_update->chk_status = status;
482 //do not need delay for checks
483 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
485 //Flight mode is ON : Network menu dimmed
486 if (ad->data_network)
490 setting_disable_genlist_item(ad->data_network->item);
494 setting_enable_genlist_item(ad->data_network->item);
498 } else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL)) {
499 item_to_update = ad->data_rotationMode;
500 retm_if(!item_to_update, "ad->data_rotationMode is NULL");
503 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &status);
505 item_to_update->chk_status = status;
506 //do not need delay for checks
507 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
508 SETTING_TRACE("item_to_update->chk_status:%d", item_to_update->chk_status);
509 if (item_to_update->chk_status) //rotation function is not blocked
511 SETTING_TRACE("Rotation function is on, it is necessary to adjust the device orientation");
512 //int mode = APP_DEVICE_ORIENTATION_0;
513 //mode = app_get_device_orientation();
514 //elm_win_rotation_with_resize_set(ad->win_main, mode);
518 } else if (!safeStrCmp(vconf_name, VCONFKEY_NFC_STATE)) {
519 SETTING_TRACE_DEBUG("%s updated", vconf_name);
520 item_to_update = ad->data_nfc;
521 retm_if(!item_to_update, "ad->data_nfc is NULL");
524 vconf_get_bool(VCONFKEY_NFC_STATE, &status);
526 item_to_update->swallow_type = SWALLOW_Type_1ICON_1RADIO;
527 item_to_update->chk_status = status;
528 //do not need delay for checks
529 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
530 SETTING_TRACE("item_to_update->chk_status:%d", item_to_update->chk_status);
532 //item_to_update->sub_desc = (char *)g_strdup(get_NFC_on_off_str());
533 //SETTING_TRACE_DEBUG("%s", item_to_update->sub_desc);
535 if (ad->bAppPause || ad->ug) {
536 ad->updateItems[GL_ITEM_NFC] = EINA_TRUE;
537 } else { // app is not in pause without ug
538 elm_object_item_data_set(item_to_update->item, item_to_update);
539 elm_genlist_item_update(item_to_update->item);
545 * the event process when int VCONFS changes
546 * @todo code clean - it has big if-else structure
548 static void setting_int_vconf_change_cb(keynode_t *key, void *data)
550 setting_main_appdata *ad = data;
551 retm_if(!data, "Invalid argument: data is NULL");
553 int status = vconf_keynode_get_int(key);
554 char *vconf_name = vconf_keynode_get_name(key);
555 SETTING_TRACE("Enter %s(%s=%d)", __FUNCTION__, vconf_name, status);
557 Setting_GenGroupItem_Data* item_to_update = NULL;
559 if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_STATE)) {
560 // do handling in case of VCONFKEY_WIFI_STATE
561 item_to_update = ad->data_wifi;
562 retm_if(!item_to_update, "ad->data_wifi is NULL");
565 case VCONFKEY_WIFI_OFF:
566 //item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
568 item_to_update->chk_status = EINA_FALSE;
571 case VCONFKEY_WIFI_UNCONNECTED:
572 case VCONFKEY_WIFI_CONNECTED:
573 case VCONFKEY_WIFI_TRANSFER:
574 //pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
575 //if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
576 // item_to_update->sub_desc = (char *)g_strdup(pa_wifi_device);
578 // item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
580 //FREE(pa_wifi_device);
582 item_to_update->chk_status = EINA_TRUE;
585 SETTING_TRACE_ERROR("Invalid wifi status!");
589 item_to_update->swallow_type = SWALLOW_Type_1ICON_1RADIO;
590 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
592 if (ad->bAppPause || ad->ug) {
593 ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
594 } else { // app is not in pause without ug
595 elm_object_item_data_set(item_to_update->item, item_to_update);
596 elm_genlist_item_update(item_to_update->item);
599 else if (!safeStrCmp(vconf_name, VCONFKEY_CALL_STATE)) {
600 // do handling in case of VCONFKEY_CALL_STATE
601 // In call situation : Wi-fi / Tethering / Network menu dimmed
602 // -- Only Wi-fi should be dimmed (2013.04.04) --
603 if (VCONFKEY_CALL_OFF != status)
605 if (ad->data_network)
606 setting_disable_genlist_item(ad->data_network->item);
610 if (ad->data_network)
611 setting_enable_genlist_item(ad->data_network->item);
614 } else if (!safeStrCmp(vconf_name, VCONFKEY_BT_STATUS)) {
615 // do handling in case of VCONFKEY_BT_STATUS
616 item_to_update = ad->data_bt;
617 retm_if(!item_to_update, "ad->data_bt is NULL");
619 if (FALSE == status) {
620 // item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
622 item_to_update->chk_status = EINA_FALSE;
624 //item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
626 item_to_update->chk_status = EINA_TRUE;
629 item_to_update->swallow_type = SWALLOW_Type_1ICON_1RADIO;
630 item_to_update->chk_status = status;
631 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
633 if (ad->bAppPause || ad->ug) {
634 ad->updateItems[GL_ITEM_BT] = EINA_TRUE;
635 } else { // app is not in pause without ug
636 elm_object_item_data_set(item_to_update->item, item_to_update);
637 elm_genlist_item_update(item_to_update->item);
639 } else if (!safeStrCmp(vconf_name, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW)) {
640 if (status <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
641 if (ad->data_bright) {
642 setting_disable_genlist_item(ad->data_bright->item);
645 if (ad->data_bright) {
646 setting_enable_genlist_item(ad->data_bright->item);
650 }else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT)) {
654 ad->data_bright->sub_desc = (char *)g_strdup(get_brightness_mode_str());
655 elm_object_item_data_set(ad->data_bright->item, ad->data_bright);
656 elm_genlist_item_update(ad->data_bright->item);
659 SETTING_TRACE_ERROR("vconf_name is bad[%s]", vconf_name);
666 * the event process when string VCONFS changes
668 static void setting_string_vconf_change_cb(keynode_t *key, void *data)
671 setting_main_appdata *ad = data;
672 retm_if(!data, "Invalid argument: data is NULL");
674 char *value = vconf_keynode_get_str(key);
675 char *vconf_name = vconf_keynode_get_name(key);
676 Setting_GenGroupItem_Data* item_to_update = NULL;
678 if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_CONNECTED_AP_NAME)) {
680 item_to_update = ad->data_wifi;
681 retm_if(!item_to_update, "ad->data_wifi is NULL");
683 if (0 != vconf_get_int(VCONFKEY_WIFI_STATE, &status)) {
684 SETTING_TRACE_ERROR("vconf_get err: %s", VCONFKEY_WIFI_STATE);
687 SETTING_TRACE("status:%d", status);
689 case VCONFKEY_WIFI_OFF:
690 //item_to_update->sub_desc =
691 // (char *)g_strdup(setting_gettext ("IDS_COM_BODY_OFF_M_STATUS"));
693 item_to_update->chk_status = EINA_FALSE;
694 item_to_update->swallow_type = SWALLOW_Type_1ICON_1RADIO;
695 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
698 case VCONFKEY_WIFI_UNCONNECTED:
699 case VCONFKEY_WIFI_CONNECTED:
700 case VCONFKEY_WIFI_TRANSFER:
701 if (NULL != value && '\0' != value[0]) {
702 SETTING_TRACE("wifi_device:%s", value);
703 //item_to_update->sub_desc = (char *)g_strdup(value);
705 //item_to_update->sub_desc =
706 // (char *) g_strdup(setting_gettext ("IDS_COM_BODY_ON_M_STATUS"));
709 item_to_update->chk_status = EINA_TRUE;
710 item_to_update->swallow_type = SWALLOW_Type_1ICON_1RADIO;
711 elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
714 SETTING_TRACE_ERROR("Invalid wifi status!");
717 if (ad->bAppPause || ad->ug) {
718 ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
719 } else { // app is not in pause without ug
720 elm_object_item_data_set(item_to_update->item, item_to_update);
721 elm_genlist_item_update(item_to_update->item);
723 } // vconf_name == VCONFKEY_WIFI_CONNECTED_AP_NAME
728 * Do the process which cost much time
730 static Eina_Bool setting_on_idle_lazy(void *data)
733 setting_main_appdata *ad = data;
735 /* A. add system event callback */
736 if (sensor_create(&ad->sf_handle) != SENSOR_ERROR_NONE) {
737 SETTING_TRACE_ERROR("sensor attach fail");
740 if (sensor_motion_doubletap_set_cb(ad->sf_handle, __main_motion_sensor_cb, ad) != SENSOR_ERROR_NONE) {
741 SETTING_TRACE("sensor_motion_doubletap_set_cb fail to gather data");
744 if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
745 SETTING_TRACE_ERROR("sensor_start fail");
748 #if SUPPORT_APP_ROATION
749 evas_object_geometry_get(ad->win_main, &g_geometry_x, &g_geometry_y, &g_geometry_w, &g_geometry_h);
756 * The function is called to create Setting view widgets
758 static bool setting_main_app_create(void *data)
761 //fprintf(stderr, "[TIME] 3. it taked %d msec from main to setting_main_app_create \n", appcore_measure_time());
762 //SETTING_TRACE("[TIME] 3. it taked %d msec from main to setting_main_app_create ", appcore_measure_time());
763 //appcore_measure_start();
764 setting_main_appdata *ad = data;
766 // registering sigterm
767 if (signal(SIGTERM, termination_handler) == SIG_IGN)
769 signal(SIGTERM, SIG_IGN);
772 ad->data_roaming_popup = NULL;
775 ad->win_main = setting_main_create_win(SETTING_PACKAGE);
776 setting_retvm_if(ad->win_main == NULL, SETTING_RETURN_FAIL, "window is null");
777 evas_object_show(ad->win_main);
778 UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
779 ad->evas = evas_object_evas_get(ad->win_main);
780 ad->current_rotation = elm_win_rotation_get(ad->win_main);
781 SETTING_TRACE("ad->current_rotation:%d",ad->current_rotation);
782 if (elm_win_wm_rotation_supported_get(ad->win_main))
784 int rots[4] = { 0, 90, 180, 270 }; // rotation value that app may want
785 elm_win_wm_rotation_available_rotations_set(ad->win_main, &rots, 4);
787 evas_object_smart_callback_add(ad->win_main, "wm,rotation,changed", _rot_changed_cb, ad);
789 /* load config file */
790 int cfg_operation_ret = setting_cfg_init();
793 elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME);
794 #if SUPPORT_LCD_TIMEOUT_KEEPING
795 /* to keep according with each other */
796 int origin_backlight_value;
798 vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
799 &origin_backlight_value)) {
801 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 30);
802 origin_backlight_value = 30;
804 /* to set intial value */
805 vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP,
806 origin_backlight_value);
808 /* Firstly, Setting is running in foreground, LCD_TIMEOUT must be 600s(/10m) */
809 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
812 elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
814 setting_view_create(&setting_view_main, ad);
815 setting_view_node_table_register(&setting_view_main, NULL);
816 setting_view_node_table_register(&setting_view_more_menu, &setting_view_main);
819 if (Cfg_Error_Type_Sucess != cfg_operation_ret) {
820 SETTING_TRACE_ERROR("cfg_operation_ret: %d", cfg_operation_ret);
821 const char *notifyStr = NULL;
822 switch (cfg_operation_ret) {
824 case Cfg_Error_Type_CreateCfg_Failed:
826 notifyStr = _("failed to create config file, <br>re-install org.tizen.setting please");
829 case Cfg_Error_Type_Mkdir_Failed:
831 notifyStr = _("file system missed<br>/opt/data/setting, <br>re-install org.tizen.setting please");
834 case Cfg_Error_Type_RemoveCfg_Failed:
836 notifyStr = _("config file size 0 byte<br>and failed to re-create it.<br>try to startup the app again");
839 case Cfg_Error_Type_ReadCfg_Failed:
841 notifyStr = _("failed to read config file, <br>try to startup the app again");
844 case Cfg_Error_Type_DirPermissionDenied:
847 _("the dir of config file permission denied");
850 case Cfg_Error_Type_FilePermissionDenied:
852 notifyStr = _("config file permission denied");
857 notifyStr = _("Invalid Result, try to startup the app again");
861 setting_create_popup_without_btn(ad, ad->win_main, NULL, (char *)notifyStr, NULL, 10, FALSE, FALSE);
862 return SETTING_RETURN_FAIL;
864 //fprintf(stderr, "[TIME] 4. setting_main_app_create taked %d msec \n", appcore_measure_time());
865 //SETTING_TRACE("[TIME] 4. setting_main_app_create taked %d msec ", appcore_measure_time());
866 //appcore_measure_start();
868 // set default local automatically
869 set_defaultLangICU();
874 * The function is called when Setting is terminated
876 static int setting_main_app_terminate(void *data)
879 setting_main_appdata *ad = data;
880 //vconf_set_bool (VCONFKEY_SETAPPL_ROTATE_HOLD_BOOL, FALSE);
883 clear_system_service_data();
888 SETTING_TRACE("%s*** SETTING APPLICATION CLOSED ***%s",
889 SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
891 DEREGISTER_VCONFS(ad->listened_list);
893 if (sensor_motion_doubletap_unset_cb(ad->sf_handle) != SENSOR_ERROR_NONE) {
894 SETTING_TRACE("sensor_motion_doubletap_unset_cb fail to gather data");
896 sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
897 sensor_destroy(ad->sf_handle);
899 #if SUPPORT_LCD_TIMEOUT_KEEPING
900 /* once Setting is not running, LCD_TIMEOUT must be backuped */
902 vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
903 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
905 setting_view_destroy(&setting_view_more_menu, ad);
906 setting_view_destroy(&setting_view_main, ad);
907 SETTING_TRACE("!!! After setting_view_destroy");
909 evas_object_del(ad->win_main);
918 * The function is called when Setting begins run in background from forground
920 static void setting_main_app_pause(void *data)
923 setting_main_appdata *ad = data;
925 ad->bAppPause = EINA_TRUE;
929 #if SUPPORT_LCD_TIMEOUT_KEEPING
930 /* once Setting is running in background, LCD_TIMEOUT must be backuped */
932 vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
933 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
936 sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
941 * The function is called when Setting begins run in forground from background
943 static void setting_main_app_resume(void *data)
946 setting_main_appdata *ad = data;
948 if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
949 SETTING_TRACE_ERROR("sf_start fail");
955 #if SUPPORT_LCD_TIMEOUT_KEEPING
956 /* once Setting is running in foreground, LCD_TIMEOUT must be reset to 600 */
957 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
960 // update main genlist in resuming app.
961 ad->bAppPause = EINA_FALSE;
962 if(!ad->ug) { // top-level view is not on UG
963 SETTING_TRACE("update main genlist in resuming app without UG");
964 setting_update_gl_item(ad); // update genlist sub-texts
969 * The function is called by app-fwk after app_create. It always do the process which cost much time.
971 static void setting_main_app_reset(service_h service, void *data)
974 setting_main_appdata *ad = data;
977 vconf_get_bool (VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &value);
978 SETTING_TRACE("value:%d", value);
979 if (value) //rotation function is not blocked
981 SETTING_TRACE("Rotation function is on, it is necessary to adjust the device orientation");
982 //int mode = APP_DEVICE_ORIENTATION_0;
983 //mode = app_get_device_orientation();
984 //elm_win_rotation_with_resize_set(ad->win_main, mode);
987 vconf_callback_fn cb = NULL;
989 cb = setting_int_vconf_change_cb;
990 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_BT_STATUS, cb, data);
991 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_STATE, cb, ad);
992 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_CALL_STATE, cb, ad);
994 //do need to disable 'Brightness' menu,just disable sub-items in 'Brightness' menu
995 //REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, cb, ad);
996 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, cb, data);
998 cb = setting_string_vconf_change_cb;
999 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_CONNECTED_AP_NAME, cb, ad);
1001 cb = setting_other_vconf_change_cb;
1002 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_USB_MODE_INT, cb, ad);
1003 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_WIDGET_THEME_STR, cb, ad);
1005 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_TELEPHONY_FLIGHT_MODE, cb, ad);
1006 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, cb, ad);
1007 REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_NFC_STATE, cb, ad);
1010 elm_win_activate(ad->win_main);
1012 ecore_idler_add(setting_on_idle_lazy, ad);
1014 int flight_mode = 0;
1015 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
1018 if (ad->data_network) setting_disable_genlist_item(ad->data_network->item);
1021 int call_status = VCONFKEY_CALL_OFF;
1022 vconf_get_int(VCONFKEY_CALL_STATE, &call_status);
1023 if (VCONFKEY_CALL_OFF != call_status)
1025 if (ad->data_network) setting_disable_genlist_item(ad->data_network->item);
1026 if (ad->data_wifi) setting_disable_genlist_item(ad->data_wifi->item);
1027 //if (ad->data_mobileApp) setting_disable_genlist_item(ad->data_mobileApp->item);
1030 /* for jumping view */
1031 service_get_extra_data(service, "view_to_jump", &(ad->view_to_jump));
1032 if(ad->view_to_jump)
1034 SETTING_TRACE_DEBUG("view to jump is %s", ad->view_to_jump);
1036 if(!safeStrCmp(ad->view_to_jump, KeyStr_Sounds))
1039 SETTING_TRACE_DEBUG("Kill launched ug.");
1040 if(ad->isInUGMode == TRUE && (safeStrCmp(ad->cur_loaded_ug, "setting-profile-efl") != 0))
1045 if(ad->isInUGMode == TRUE && (safeStrCmp(ad->cur_loaded_ug, "setting-profile-efl") == 0))
1050 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1051 setting_retm_if(!cbs, "calloc failed");
1052 cbs->layout_cb = setting_main_layout_ug_cb;
1053 cbs->result_cb = setting_main_result_ug_cb;
1054 cbs->destroy_cb = setting_main_destroy_ug_cb;
1055 cbs->priv = (void *)ad;
1057 SETTING_TRACE_DEBUG("call setting-profile-efl ug");
1058 ad->ug = ug_create(NULL, "setting-profile-efl", UG_MODE_FULLVIEW, 0, cbs);
1060 ad->isInUGMode = TRUE;
1061 memset(ad->cur_loaded_ug, 0x00, MAX_DISPLAY_NAME_LEN_ON_UI);
1062 safeCopyStr(ad->cur_loaded_ug, "setting-profile-efl", MAX_DISPLAY_NAME_LEN_ON_UI);
1064 evas_object_show(ad->ly_main);
1066 SETTING_TRACE_ERROR("errno:%d", errno);
1067 setting_create_simple_popup(ad, ad->win_main, NULL, NO_UG_FOUND_MSG);
1072 ad->view_to_jump = NULL;
1077 SETTING_TRACE_DEBUG("No need to jump view. Draw main.");
1081 int main(int argc, char *argv[])
1084 setting_main_appdata ad;
1086 elm_init(argc, argv);
1087 #if SUPPORT_GL_ENGINE
1088 // opengl_x11 or software_x11
1089 elm_config_preferred_engine_set("software_x11");
1092 //fprintf(stderr, "[TIME] 1. aul_launch -> main :: Setting main : %d msec \n", appcore_measure_time_from("APP_START_TIME"));
1093 //SETTING_TRACE("[TIME] 1. aul_launch -> main :: Setting main : %d msec ", appcore_measure_time_from("APP_START_TIME"));
1094 //appcore_measure_start();
1096 app_event_callback_s ops = {
1097 .create = setting_main_app_create,
1098 .terminate = setting_main_app_terminate,
1099 .pause = setting_main_app_pause,
1100 .resume = setting_main_app_resume,
1101 .service = setting_main_app_reset,
1102 .low_battery = setting_main_low_battery_cb,
1103 .language_changed = setting_main_lang_changed_cb,
1104 .region_format_changed = setting_main_region_changed_cb,
1105 .device_orientation = NULL,
1109 memset(&ad, 0x00, sizeof(setting_main_appdata));
1111 //fprintf(stderr, "[TIME] 2. main : %d msec \n", appcore_measure_time());
1112 //SETTING_TRACE("[TIME] 2. main : %d msec ", appcore_measure_time());
1113 //appcore_measure_start();
1114 r = app_efl_main(&argc, &argv, &ops, &ad);
1115 retv_if(r == -1, -1);