Merge "packaging: spec cleanup" into tizen
[apps/core/preloaded/settings.git] / src / setting.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://floralicense.org/license/
10  *
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.
16  */
17 #include <setting.h>
18 #include <app.h>
19
20 #include <appcore-common.h>
21 #include <Ecore_X.h>
22 #include <sensor.h>
23 #include <aul.h>
24 #include "setting-common-plugin.h"
25 #include "setting-main.h"
26 #include <elm_object.h>
27 #include <appsvc.h>
28 #include <EWebKit2.h>
29 #include <nfc.h>
30 #include <signal.h>
31
32 extern void setting_update_gl_item(void* data);
33
34 #define KEY_END "XF86Stop"
35 #define SUPPORT_UG_MESSAGE
36
37 int g_geometry_x, g_geometry_y, g_geometry_w, g_geometry_h;
38
39 void termination_handler(int signum)
40 {
41         SETTING_TRACE_BEGIN;
42         SETTING_TRACE(">>>>>>>>>>> SIGTERM >>>>>>>>>>>>>>> SETTING");
43
44         elm_exit();
45 }
46
47 static void __main_motion_sensor_cb( unsigned long long timestamp, void *data)
48 {
49         /* The code 'return ;' will be deleted after the defect of elm_genlist_item_top_show() is fixed */
50
51         setting_retm_if(NULL == data, "NULL == data");
52         setting_main_appdata *ad = (setting_main_appdata *) data;
53
54         SETTING_TRACE(">>>>>>>Double tap event detected");
55         //If it is in UG mode, Setting just send the event to the loaded UG
56
57         if (ad->isInUGMode && ad->ug) {
58         #ifdef SUPPORT_UG_MESSAGE
59                 SETTING_TRACE(">>>>>>>Send event to UG");
60
61                 service_h svc;
62                 if(service_create(&svc))
63                         return;
64
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");
68                 }
69
70                 service_destroy(svc);
71         #else
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.
81                 //That's all
82                 Evas_Object *layout = (Evas_Object *)ug_get_layout(ad->ug);
83                 if (layout) {
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);
89
90                         const char *type = elm_object_widget_type_get(content);
91                         //SETTING_TRACE("content type:%s", type);
92                         if (0 == safeStrCmp(type, "genlist")) {
93                                 genlist = content;
94                         } else if (NULL != type) {//type="layout","conformant" etc..
95                                 //layout
96                                 //genlist = elm_object_part_content_get(content, "elm.swallow.contents");
97                                 const Eina_List *subobjs = elm_widget_sub_object_list_get(content);
98                                 ret_if(!subobjs);
99                                 Evas_Object *subobj;
100                                 const Eina_List *l;
101
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")) {
107                                                 genlist = subobj;
108                                                 Elm_Object_Item *first_item = elm_genlist_first_item_get(genlist);
109                                                 if (first_item) {
110                                                         elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
111                                                 }
112                                         }
113                                 }
114                                 return;//to return,because for this case,we need special process.
115                         } else {
116                                 //keep genlist to be NULL.
117                         }
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);
121                                 if (first_item) {
122                                         elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
123                                 }
124                         }
125                 }
126         #endif
127         } else {
128                 setting_go_to_navibar_list_top(ad->navibar_main);
129         }
130 }
131
132 /**
133 * The event process when hard key is pressed.
134 */
135 #if DISABLED_CODE
136 static int setting_main_keydown_cb(void *data, int type, void *event)
137 {
138         SETTING_TRACE_BEGIN;
139
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);
145                 if (popup) {
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);
151                         } else {
152                                 evas_object_smart_callback_call(popup, "timeout", NULL);
153                         }
154                 }
155                 return;
156         }
157
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);
161         } else {
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");
165                         elm_exit();
166                 } else {
167                         SETTING_TRACE("To pre-view of Setting App");
168                         elm_naviframe_item_pop(ad->navibar_main);
169                 }
170         }
171 }
172 #else
173         if (ev && !safeStrCmp(ev->keyname, KEY_END)) {
174                 /* do nothing except exit */
175                 SETTING_TRACE("before --- elm_exit ");
176
177                 elm_exit();
178                 s_count = s_count + 1;
179                 SETTING_TRACE("after --- elm_exit = %d ", s_count);
180         }
181 #endif
182         SETTING_TRACE_END;
183         return 1;
184 }
185 #endif
186
187 #if LOW_BATTERY_DO_NOTHING
188
189 /*  in case of low battery, don't terminate itself.*/
190
191 /**
192 * The event process when battery becomes low.
193 */
194 static void setting_main_low_battery_cb(void *data)
195 {
196         SETTING_TRACE_BEGIN;
197         setting_main_appdata *ad = data;
198
199         if (ad->ug)
200                 ug_send_event(UG_EVENT_LOW_BATTERY);
201 }
202 #endif
203
204 #if SUPPORT_APP_ROATION
205
206 /**
207 * To active rotation effect in Setting App
208 */
209 static void setting_main_rotate(app_device_orientation_e m, void *data)
210 {
211         SETTING_TRACE_BEGIN;
212         setting_main_appdata *ad = data;
213
214         if (ad == NULL || ad->win_main == NULL)
215                 return;
216
217 #if 0
218                                 int value = 0;
219                                 vconf_get_bool
220                                     (VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &value);
221                                 // true  : aoto rotation OFF
222                                 // false : auto rotation ON
223                                 value = !value;
224 #else
225         //int hold_flag = 0;
226         //vconf_get_bool (VCONFKEY_SETAPPL_ROTATE_HOLD_BOOL, &hold_flag);
227         //SETTING_TRACE("hold_flag:%d", hold_flag);
228         //if (hold_flag)
229         //{
230                 //do nothing..
231         //      return;
232         //}
233
234         int value = 0;
235         vconf_get_bool (VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &value);
236
237         if (value == 0)
238                 m = 0;
239
240         elm_win_rotation_with_resize_set(ad->win_main, m);
241
242         /////Send the rotation event to UGs..
243         enum ug_event event = UG_EVENT_ROTATE_PORTRAIT;
244         switch (m) {
245         case APP_DEVICE_ORIENTATION_0:
246                 event = UG_EVENT_ROTATE_PORTRAIT;
247                 break;
248         case APP_DEVICE_ORIENTATION_180:
249                 event = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
250                 break;
251         case APP_DEVICE_ORIENTATION_90:
252                 event = UG_EVENT_ROTATE_LANDSCAPE;
253                 break;
254         case APP_DEVICE_ORIENTATION_270:
255                 event = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
256                 break;
257         default:
258                 return;
259         }
260         ug_send_event(event);
261         //elm_win_rotation_get
262 #endif
263
264 }
265 static void _rot_changed_cb(void *data, Evas_Object *obj, void *event_info)
266 {
267         SETTING_TRACE_BEGIN;
268         setting_main_appdata *ad = (setting_main_appdata *)data;
269         if (ad == NULL || ad->win_main == NULL )
270                 return;
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;
279                 break;
280         case APP_DEVICE_ORIENTATION_180:
281                 event = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
282                 break;
283         case APP_DEVICE_ORIENTATION_270:
284                 event = UG_EVENT_ROTATE_LANDSCAPE;
285                 break;
286         case APP_DEVICE_ORIENTATION_90:
287                 event = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
288                 break;
289         default:
290                 return;
291         }
292         SETTING_TRACE("diff:%d",elm_win_rotation_get(ad->win_main) - ad->current_rotation);
293
294         if (change_ang != ad->current_rotation)
295         {
296                 ug_send_event(event);
297                 ad->current_rotation = change_ang;
298         }
299 }
300 #endif
301
302 /**
303 * The event process when region is changes.
304 */
305 static void setting_main_region_changed_cb(void *data)
306 {
307         setting_main_appdata *ad = data;
308
309         if (ad->ug)
310                 ug_send_event(UG_EVENT_REGION_CHANGE);
311 }
312
313 /**
314 * The event process when win object is destroyed
315 */
316 static void setting_main_del_win(void *data, Evas_Object *obj, void *event)
317 {
318         elm_exit();
319 }
320
321 void profile_changed_cb(void *data, Evas_Object * obj, void *event)
322 {
323         const char *profile = elm_config_profile_get();
324
325         if (strcmp(profile, "desktop") == 0)
326                 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_HIDE);
327         else
328                 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_SHOW);
329 }
330
331 /**
332 * To create a win object, the win is shared between the App and all its UGs
333 */
334 static Evas_Object *setting_main_create_win(const char *name)
335 {
336         SETTING_TRACE_BEGIN;
337         Evas_Object *eo;
338         int w, h;
339
340         //eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
341         eo = elm_win_util_standard_add(name, name);
342         if (eo) {
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(),
348                                         &w, &h);
349                 evas_object_resize(eo, w, h);
350         }
351
352         return eo;
353 }
354
355 /**
356 * exceptional process, reset the env vars by Setting vconf VCONFKEY_LANGSET
357 */
358 static void setting_main_lang_changed_cb(void *data)
359 {
360         SETTING_TRACE_BEGIN;
361         setting_main_appdata *ad = data;
362
363         char* str = NULL;
364         if (ad->data_wifi) {
365             str = (char *)get_pa_Wi_Fi_on_off_str();
366                 if ( ! str) str = g_strdup("err");
367             ad->data_wifi->sub_desc = str;
368         }
369         if (ad->data_bt) {
370             str = (char *)g_strdup(get_BT_on_off_str());
371                 if ( ! str) str = g_strdup("err");
372             ad->data_bt->sub_desc = str;
373         }
374         if (ad->data_nfc) {
375             str = (char *)g_strdup(get_NFC_on_off_str());
376                 if ( ! str) str = g_strdup("err");
377             ad->data_nfc->sub_desc = str;
378         }
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;
383         }
384
385         if (ad->data_moreConnect) {
386                 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
387                 int idx = 0;
388                 while (idx < MAX_MORE_MENU_NUM && ad->more_connective_menus[idx])
389                 {
390                         if (idx != 0)
391                         {
392                                 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
393                         }
394                         safeStrNCat(sub_text, _(ad->more_connective_menus[idx]), MAX_COMMON_BUFFER_LEN);
395                         idx++;
396                 }
397                 ad->data_moreConnect->sub_desc = g_strdup(sub_text);
398         }
399
400         if (ad->data_moreSystem) {
401                 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
402                 int idx = 0;
403                 while (idx < MAX_MORE_MENU_NUM && ad->more_system_menus[idx])
404                 {
405                         if (idx != 0)
406                         {
407                                 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
408                         }
409                         safeStrNCat(sub_text, _(ad->more_system_menus[idx]), MAX_COMMON_BUFFER_LEN);
410                         idx++;
411                 }
412                 ad->data_moreSystem->sub_desc = g_strdup(sub_text);
413         }
414
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);
417
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));
422 #endif
423
424         navi_it = elm_naviframe_bottom_item_get(ad->navibar_main);
425         if (navi_it)
426                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_SETTINGS"));
427
428         if (ad->edit_item)
429         {
430 #if SUPPORT_BOTTOM_BTNS
431                 elm_object_item_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
432 #else
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));
436 #endif
437         }
438
439         if (ad->segment_all)
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));
443
444         // set toolbar text
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));
450         } else {
451                 /* do nothing */
452         }
453         Evas_Object *btn = elm_object_item_part_content_get(navi_it, "toolbar_button1");
454         elm_object_text_set(btn, tmp_text);
455
456
457         if (ad->ug)
458                 ug_send_event(UG_EVENT_LANG_CHANGE);
459 }
460
461 /**
462 * the event process when other VCONFS changes
463 */
464 static void setting_other_vconf_change_cb(keynode_t *key, void *data)
465 {
466         setting_main_appdata *ad = data;
467         retm_if(!data, "Invalid argument: data is NULL");
468
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);
472
473         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_WIDGET_THEME_STR)) {
474                 return;
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");
478
479                 int status = 0;
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);
484
485                 //Flight mode is ON : Network menu dimmed
486                 if (ad->data_network)
487                 {
488                         if (status)
489                         {
490                                 setting_disable_genlist_item(ad->data_network->item);
491                         }
492                         else
493                         {
494                                 setting_enable_genlist_item(ad->data_network->item);
495                         }
496                 }
497                 return;
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");
501
502                 int status = 0;
503                 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &status);
504
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
510                 {
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);
515                 }
516
517                 return;
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");
522
523                 int status = 0;
524                 vconf_get_bool(VCONFKEY_NFC_STATE, &status);
525
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);
531
532                 //item_to_update->sub_desc = (char *)g_strdup(get_NFC_on_off_str());
533                 //SETTING_TRACE_DEBUG("%s", item_to_update->sub_desc);
534
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);
540                 }
541         }
542 }
543
544 /**
545 * the event process when int VCONFS changes
546 * @todo code clean - it has big if-else structure
547 */
548 static void setting_int_vconf_change_cb(keynode_t *key, void *data)
549 {
550         setting_main_appdata *ad = data;
551         retm_if(!data, "Invalid argument: data is NULL");
552
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);
556
557         Setting_GenGroupItem_Data* item_to_update = NULL;
558
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");
563
564                 switch (status) {
565                 case VCONFKEY_WIFI_OFF:
566                         //item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
567
568                         item_to_update->chk_status = EINA_FALSE;
569                         break;
570
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);
577                         //} else {
578                         //      item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
579                         //}
580                         //FREE(pa_wifi_device);
581
582                         item_to_update->chk_status = EINA_TRUE;
583                         break;
584                 default:
585                         SETTING_TRACE_ERROR("Invalid wifi status!");
586                         return;
587                 }
588
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);
591
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);
597                 }
598         }
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)
604                 {
605                         if (ad->data_network)
606                                 setting_disable_genlist_item(ad->data_network->item);
607                 }
608                 else
609                 {
610                         if (ad->data_network)
611                                 setting_enable_genlist_item(ad->data_network->item);
612                 }
613
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");
618 /*
619                 if (FALSE == status) {
620                 //      item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
621
622                         item_to_update->chk_status = EINA_FALSE;
623                 } else {
624                         //item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
625
626                         item_to_update->chk_status = EINA_TRUE;
627                 }
628 */
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);
632
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);
638                 }
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);
643                         }
644                 } else {
645                         if (ad->data_bright) {
646                                 setting_enable_genlist_item(ad->data_bright->item);
647                         }
648
649                 }
650         }else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT)) {
651                 //update directly
652                 if (ad->data_bright)
653                 {
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);
657                 }
658         } else {
659                 SETTING_TRACE_ERROR("vconf_name is bad[%s]", vconf_name);
660         }
661
662         return;
663 }
664
665 /**
666 * the event process when string VCONFS changes
667 */
668 static void setting_string_vconf_change_cb(keynode_t *key, void *data)
669 {
670         SETTING_TRACE_BEGIN;
671         setting_main_appdata *ad = data;
672         retm_if(!data, "Invalid argument: data is NULL");
673
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;
677
678         if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_CONNECTED_AP_NAME)) {
679                 int status;
680                 item_to_update = ad->data_wifi;
681                 retm_if(!item_to_update, "ad->data_wifi is NULL");
682
683                 if (0 != vconf_get_int(VCONFKEY_WIFI_STATE, &status)) {
684                         SETTING_TRACE_ERROR("vconf_get err: %s", VCONFKEY_WIFI_STATE);
685                         return;
686                 }
687                 SETTING_TRACE("status:%d", status);
688                 switch (status) {
689                 case VCONFKEY_WIFI_OFF:
690                         //item_to_update->sub_desc =
691                         //      (char *)g_strdup(setting_gettext ("IDS_COM_BODY_OFF_M_STATUS"));
692
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);
696                         break;
697
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);
704                         } else {
705                                 //item_to_update->sub_desc =
706                                 //      (char *) g_strdup(setting_gettext ("IDS_COM_BODY_ON_M_STATUS"));
707                         }
708
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);
712                         break;
713                 default:
714                         SETTING_TRACE_ERROR("Invalid wifi status!");
715                         return;
716                 }
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);
722                 }
723         } // vconf_name == VCONFKEY_WIFI_CONNECTED_AP_NAME
724 }
725
726
727 /**
728 * Do the process which cost much time
729 */
730 static Eina_Bool setting_on_idle_lazy(void *data)
731 {
732         SETTING_TRACE_BEGIN;
733         setting_main_appdata *ad = data;
734
735         /* A. add system event callback */
736         if (sensor_create(&ad->sf_handle) != SENSOR_ERROR_NONE) {
737                 SETTING_TRACE_ERROR("sensor attach fail");
738         }
739
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");
742         }
743
744         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
745                 SETTING_TRACE_ERROR("sensor_start fail");
746         }
747
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);
750 #endif
751
752         return FALSE;
753 }
754
755 /**
756 * The function is called to create Setting view widgets
757 */
758 static bool setting_main_app_create(void *data)
759 {
760         SETTING_TRACE_BEGIN;
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;
765
766         // registering sigterm
767         if (signal(SIGTERM, termination_handler) == SIG_IGN)
768         {
769                 signal(SIGTERM, SIG_IGN);
770         }
771
772         ad->data_roaming_popup = NULL;
773
774         /* create window */
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))
783         {
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);
786         }
787         evas_object_smart_callback_add(ad->win_main, "wm,rotation,changed", _rot_changed_cb, ad);
788
789         /* load config file */
790         int cfg_operation_ret = setting_cfg_init();
791         //PLUGIN_INIT(ad);
792
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;
797         if (0 !=
798             vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
799                           &origin_backlight_value)) {
800                 /* error handle.. */
801                 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 30);
802                 origin_backlight_value = 30;
803         }
804         /* to set intial value */
805         vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP,
806                       origin_backlight_value);
807
808         /* Firstly, Setting is running in foreground, LCD_TIMEOUT must be 600s(/10m) */
809         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
810 #endif
811
812         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
813
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);
817
818         /* error handling */
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) {
823
824                 case Cfg_Error_Type_CreateCfg_Failed:
825                         {
826                                 notifyStr = _("failed to create config file, <br>re-install org.tizen.setting please");
827                                 break;
828                         }
829                 case Cfg_Error_Type_Mkdir_Failed:
830                         {
831                                 notifyStr = _("file system missed<br>/opt/data/setting, <br>re-install org.tizen.setting please");
832                                 break;
833                         }
834                 case Cfg_Error_Type_RemoveCfg_Failed:
835                         {
836                                 notifyStr = _("config file size 0 byte<br>and failed to re-create it.<br>try to startup the app again");
837                                 break;
838                         }
839                 case Cfg_Error_Type_ReadCfg_Failed:
840                         {
841                                 notifyStr = _("failed to read config file, <br>try to startup the app again");
842                                 break;
843                         }
844                 case Cfg_Error_Type_DirPermissionDenied:
845                         {
846                                 notifyStr =
847                                     _("the dir of config file permission denied");
848                                 break;
849                         }
850                 case Cfg_Error_Type_FilePermissionDenied:
851                         {
852                                 notifyStr = _("config file permission denied");
853                                 break;
854                         }
855                 default:
856                         {
857                                 notifyStr = _("Invalid Result, try to startup the app again");
858                                 break;
859                         }
860                 }
861                 setting_create_popup_without_btn(ad, ad->win_main, NULL, (char *)notifyStr, NULL, 10, FALSE, FALSE);
862                 return SETTING_RETURN_FAIL;
863         }
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();
867
868         // set default local automatically
869         set_defaultLangICU();
870         return true;
871 }
872
873 /**
874 * The function is called when Setting is terminated
875 */
876 static int setting_main_app_terminate(void *data)
877 {
878         SETTING_TRACE_BEGIN;
879         setting_main_appdata *ad = data;
880         //vconf_set_bool (VCONFKEY_SETAPPL_ROTATE_HOLD_BOOL, FALSE);
881
882         setting_cfg_exit();
883         clear_system_service_data();
884
885         ug_destroy_all();
886         ad->ug = NULL;
887
888         SETTING_TRACE("%s*** SETTING APPLICATION CLOSED ***%s",
889                       SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
890
891         DEREGISTER_VCONFS(ad->listened_list);
892
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");
895         }
896         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
897         sensor_destroy(ad->sf_handle);
898
899 #if SUPPORT_LCD_TIMEOUT_KEEPING
900         /* once Setting is not running, LCD_TIMEOUT must be backuped */
901         int back_value = 0;
902         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
903         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
904 #endif
905         setting_view_destroy(&setting_view_more_menu, ad);
906         setting_view_destroy(&setting_view_main, ad);
907         SETTING_TRACE("!!! After setting_view_destroy");
908         if (ad->win_main) {
909                 evas_object_del(ad->win_main);
910                 ad->win_main = NULL;
911         }
912
913         SETTING_TRACE_END;
914         return 0;
915 }
916
917 /**
918 * The function is called when Setting begins run in background from forground
919 */
920 static void setting_main_app_pause(void *data)
921 {
922         SETTING_TRACE_BEGIN;
923         setting_main_appdata *ad = data;
924
925         ad->bAppPause = EINA_TRUE;
926         if (ad->ug)
927                 ug_pause();
928
929 #if SUPPORT_LCD_TIMEOUT_KEEPING
930         /* once Setting is running in background, LCD_TIMEOUT must be backuped */
931         int back_value = 0;
932         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
933         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
934 #endif
935
936         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
937
938 }
939
940 /**
941 * The function is called when Setting begins run in forground from background
942 */
943 static void setting_main_app_resume(void *data)
944 {
945         SETTING_TRACE_BEGIN;
946         setting_main_appdata *ad = data;
947
948         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
949                 SETTING_TRACE_ERROR("sf_start fail");
950         }
951
952         if (ad->ug)
953                 ug_resume();
954
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);
958 #endif
959
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
965         }
966 }
967
968 /**
969  * The function is called by app-fwk after app_create. It always do the process which cost much time.
970  */
971 static void setting_main_app_reset(service_h service, void *data)
972 {
973         SETTING_TRACE_BEGIN;
974         setting_main_appdata *ad = data;
975
976         int value = 0;
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
980         {
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);
985         }
986
987         vconf_callback_fn cb = NULL;
988
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);
993
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);
997
998         cb = setting_string_vconf_change_cb;
999         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_CONNECTED_AP_NAME, cb, ad);
1000
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);
1004
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);
1008
1009         if (ad->win_main)
1010                 elm_win_activate(ad->win_main);
1011
1012         ecore_idler_add(setting_on_idle_lazy, ad);
1013
1014         int flight_mode = 0;
1015         vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
1016         if (flight_mode)
1017         {
1018                 if (ad->data_network) setting_disable_genlist_item(ad->data_network->item);
1019         }
1020
1021         int call_status = VCONFKEY_CALL_OFF;
1022         vconf_get_int(VCONFKEY_CALL_STATE, &call_status);
1023         if (VCONFKEY_CALL_OFF != call_status)
1024         {
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);
1028         }
1029
1030         /* for jumping view */
1031         service_get_extra_data(service, "view_to_jump", &(ad->view_to_jump));
1032         if(ad->view_to_jump)
1033         {
1034                 SETTING_TRACE_DEBUG("view to jump is %s", ad->view_to_jump);
1035                 /* Jumping */
1036                 if(!safeStrCmp(ad->view_to_jump, KeyStr_Sounds))
1037                 {
1038
1039                         SETTING_TRACE_DEBUG("Kill launched ug.");
1040                         if(ad->isInUGMode == TRUE && (safeStrCmp(ad->cur_loaded_ug, "setting-profile-efl") != 0))
1041                         {
1042                                 ug_destroy_all();
1043                                 ad->ug = NULL;
1044                         }
1045                         if(ad->isInUGMode == TRUE && (safeStrCmp(ad->cur_loaded_ug, "setting-profile-efl") == 0))
1046                         {
1047                                 return;
1048                         }
1049
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;
1056
1057                         SETTING_TRACE_DEBUG("call setting-profile-efl ug");
1058                         ad->ug = ug_create(NULL, "setting-profile-efl", UG_MODE_FULLVIEW, 0, cbs);
1059                         if (ad->ug) {
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);
1063                         } else {
1064                                 evas_object_show(ad->ly_main);
1065
1066                                 SETTING_TRACE_ERROR("errno:%d", errno);
1067                                 setting_create_simple_popup(ad, ad->win_main, NULL, NO_UG_FOUND_MSG);
1068                         }
1069                         if (cbs)
1070                                 FREE(cbs);
1071                         cbs = NULL;
1072                         ad->view_to_jump = NULL;
1073                 }
1074         }
1075         else
1076         {
1077                 SETTING_TRACE_DEBUG("No need to jump view. Draw main.");
1078         }
1079 }
1080
1081 int main(int argc, char *argv[])
1082 {
1083         int r = 0;
1084         setting_main_appdata ad;
1085
1086         elm_init(argc, argv);
1087 #if SUPPORT_GL_ENGINE
1088         // opengl_x11 or software_x11
1089         elm_config_preferred_engine_set("software_x11");
1090 #endif
1091
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();
1095
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,
1106         };
1107
1108
1109         memset(&ad, 0x00, sizeof(setting_main_appdata));
1110
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);
1116
1117         return 0;
1118 }