f9e69a1cf71768e758be77424ad180b0669d82cf
[apps/core/preloaded/settings.git] / src / setting.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting.h>
22 #include <appcore-common.h>
23 #include <heynoti.h>
24 #include <Ecore_X.h>
25 #include <sensor.h>
26 #include <aul.h>
27 #include "setting-plugin.h"
28 #include "setting-main.h"
29 #include <elm_object.h>
30 #include <appsvc.h>
31
32 extern void setting_update_gl_item(void* data);
33
34 #define KEY_END "XF86Stop"
35
36 int g_geometry_x, g_geometry_y, g_geometry_w, g_geometry_h;
37 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
38
39 static void __main_motion_sensor_cb( unsigned long long timestamp, void *data)
40 {
41         /* The code 'return ;' will be deleted after the defect of elm_genlist_item_top_show() is fixed */
42
43         setting_retm_if(NULL == data, "NULL == data");
44         SETTING_TRACE_BEGIN;
45         setting_main_appdata *ad = (setting_main_appdata *) data;
46
47         SETTING_TRACE(">>>>>>>Double tap event detected");
48         //If it is in UG mode, Setting just send the event to the loaded UG
49
50         if (ad->isInUGMode && ad->ug) {
51         #ifdef SUPPORT_UG_MESSAGE
52                 SETTING_TRACE(">>>>>>>Send event to UG");
53
54                 service_h svc;
55                 if(service_create(&svc))
56                         return;
57
58                 service_add_extra_data(svc, "Detected", "Double_tap_event");
59                 if (ug_send_message(ad->ug, svc) != 0) {
60                         SETTING_TRACE_ERROR("call ug_send_message fail");
61                 }
62
63                 service_destroy(svc);
64         #else
65                 //Methord: instead of send message to UG and its sub-UGs,
66                 //1.To get the layout of UG ,and then
67                 //2.To get the naviframe of the layout, and then,
68                 //3.To get the toppest item  of naviframe, and then
69                 //4.To get the content of naviframe toppest item,that is content
70                 //5.content ia mainly a genlist,but it is not fixed,it maybe a conformant or another layout
71                 //  if it is a genlist,directly show its top item
72                 //  if it is a conformant or another layout,to get all of its sub-objects,then ask turnly
73                 //     whether it is a genlist,if it is(some sub-object), topply show it.
74                 //That's all
75                 Evas_Object *layout = (Evas_Object *)ug_get_layout(ad->ug);
76                 if (layout) {
77                         Evas_Object *genlist = NULL;
78                         Evas_Object *navi_bar = elm_object_part_content_get(layout, "elm.swallow.content");
79                         Elm_Object_Item *item = elm_naviframe_top_item_get(navi_bar);
80                         Evas_Object *content = elm_object_item_content_get(item);
81                         //SETTING_TRACE("content:%p", content);
82
83                         const char *type = elm_object_widget_type_get(content);
84                         SETTING_TRACE("content type:%s", type);
85                         if (0 == safeStrCmp(type, "genlist")) {
86                                 genlist = content;
87                         //} else if (0 == safeStrCmp(type, "layout") || 0 == safeStrCmp(type, "conformant")) {
88                         } else if (NULL != type) {//type="layout","conformant" etc..
89                                 //layout
90                                 //genlist = elm_object_part_content_get(content, "elm.swallow.contents");
91                                 const Eina_List *subobjs = elm_widget_sub_object_list_get(content);
92                                 ret_if(!subobjs);
93                                 Evas_Object *subobj;
94                                 const Eina_List *l;
95
96                                 //just only search the first objects level
97                                 EINA_LIST_FOREACH(subobjs, l, subobj) {
98                                         if (!subobj) continue;
99                                         type = elm_object_widget_type_get(subobj);
100                                         if (0 == safeStrCmp(type, "genlist")) {
101                                                 genlist = subobj;
102                                                 SETTING_TRACE("Get the genlist:%p", genlist);
103                                                 Elm_Object_Item *first_item = elm_genlist_first_item_get(genlist);
104                                                 if (first_item) {
105                                                         elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
106                                                 }
107                                         }
108                                 }
109                                 return;//to return,because for this case,we need special process.
110                         } else {
111                                 //keep genlist to be NULL.
112                         }
113                         SETTING_TRACE("genlist(:%p) type:%s", genlist, elm_object_widget_type_get(genlist));
114                         if (genlist && 0 == safeStrCmp(elm_object_widget_type_get(genlist), "genlist")) {
115                                 SETTING_TRACE("Get the genlist:%p", genlist);
116                                 Elm_Object_Item *first_item = elm_genlist_first_item_get(genlist);
117                                 if (first_item) {
118                                         elm_genlist_item_show(first_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
119                                 }
120                         }
121                 }
122         #endif
123         } else {
124                 setting_go_to_navibar_list_top(ad->navibar_main);
125         }
126 }
127
128 /**
129 * The event process when hard key is pressed.
130 */
131 #if DISABLED_CODE
132 static int setting_main_keydown_cb(void *data, int type, void *event)
133 {
134         SETTING_TRACE_BEGIN;
135
136         static int s_count = 0;
137         Ecore_Event_Key *ev = event;
138 #if APPLIED_BACK_KEY_UG
139         if (!safeStrCmp(ev->keyname, KEY_END)) {
140                 Evas_Object *popup = get_toppest_popup_window(ad->evas);
141                 if (popup) {
142                         /* "progressbar"ÀàÐ͵Äpopup, ²»×÷´¦Àí */
143                         Evas_Object *content = elm_object_content_get(popup);
144                         const char *type = elm_widget_type_get(content);
145                         if (type && !safeStrCmp(type, "progressbar")) {
146                                 SETTING_TRACE_DEBUG
147                                     ("Found popup[%p], but it respresent a progress bar, so skip it.",
148                                      popup);
149                         } else {
150                                 evas_object_smart_callback_call(popup,
151                                                                 "timeout",
152                                                                 NULL);
153
154                                 /* error handling */
155                                 /*Evas_Object *popup2 = get_toppest_popup_window(ad->evas);
156                                    if (popup == popup2)
157                                    {
158                                    SETTING_TRACE_ERROR("error handling");
159                                    evas_object_del(popup);
160                                    } */
161                         }
162                 }
163                 return;
164         }
165
166         if (ad->isInUGMode) {   /* have some ug being loaded, it was reset to be FALSE in  setting_main_destroy_ug_cb() */
167                 SETTING_TRACE("Send UG_KEY_EVENT_END to ug");
168                 ug_send_key_event(UG_KEY_EVENT_END);
169         } else {
170                 if (elm_naviframe_top_item_get(ad->navibar_main)
171                     == elm_naviframe_bottom_item_get(ad->navibar_main)) {
172                         SETTING_TRACE("To exit Setting App");
173                         elm_exit();
174                 } else {
175                         SETTING_TRACE("To pre-view of Setting App");
176                         elm_naviframe_item_pop(ad->navibar_main);
177                 }
178         }
179 }
180 #else                           /* FOR MWC DEMO 2010.02.07 */
181         if (ev && !safeStrCmp(ev->keyname, KEY_END)) {
182                 /* do nothing except exit */
183                 SETTING_TRACE("before --- elm_exit ");
184
185                 elm_exit();
186                 s_count = s_count + 1;
187                 SETTING_TRACE("after --- elm_exit = %d ", s_count);
188         }
189 #endif
190         SETTING_TRACE_END;
191         return 1;
192 }
193 #endif
194
195 #if LOW_BATTERY_DO_NOTHING
196
197 /*  in case of low battery, don't terminate itself.*/
198
199 /**
200 * The event process when battery becomes low.
201 */
202 static int setting_main_low_battery_cb(void *data)
203 {
204         SETTING_TRACE_BEGIN;
205         setting_main_appdata *ad = data;
206
207         if (ad->ug)
208                 ug_send_event(UG_EVENT_LOW_BATTERY);
209
210         return 0;
211 }
212 #endif
213
214 #if SUPPORT_APP_ROATION
215
216 /**
217 * To active rotation effect in Setting App
218 */
219 static int setting_main_rotate(enum appcore_rm m, void *data)
220 {
221         SETTING_TRACE_BEGIN;
222         setting_main_appdata *ad = data;
223         int r;
224
225         if (ad == NULL || ad->win_main == NULL)
226                 return 0;
227
228         switch (m) {
229         case APPCORE_RM_PORTRAIT_NORMAL:
230                 r = 0;
231                 break;
232         case APPCORE_RM_PORTRAIT_REVERSE:
233                 r = 180;
234                 break;
235         case APPCORE_RM_LANDSCAPE_NORMAL:
236                 r = 270;
237                 break;
238         case APPCORE_RM_LANDSCAPE_REVERSE:
239                 r = 90;
240                 break;
241         default:
242                 r = -1;
243                 break;
244         }
245
246         if (r >= 0)
247                 elm_win_rotation_with_resize_set(ad->win_main, r);
248
249         return 0;
250 }
251 #endif
252
253 /**
254 * The event process when region is changes.
255 */
256 static int setting_main_region_changed_cb(void *data)
257 {
258         setting_main_appdata *ad = data;
259
260         if (ad->ug)
261                 ug_send_event(UG_EVENT_REGION_CHANGE);
262
263         return 0;
264 }
265
266 /**
267 * The event process when win object is destroyed
268 */
269 static void setting_main_del_win(void *data, Evas_Object *obj, void *event)
270 {
271         elm_exit();
272 }
273
274 /**
275 * To create a win object, the win is shared between the App and all its UGs
276 */
277 static Evas_Object *setting_main_create_win(const char *name)
278 {
279         SETTING_TRACE_BEGIN;
280         Evas_Object *eo;
281         int w, h;
282
283         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
284         if (eo) {
285                 elm_win_title_set(eo, name);
286                 elm_win_borderless_set(eo, EINA_TRUE);
287                 evas_object_smart_callback_add(eo, "delete,request",
288                                                setting_main_del_win, NULL);
289                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
290                                         &w, &h);
291                 evas_object_resize(eo, w, h);
292         }
293
294         return eo;
295 }
296
297 /**
298 * exceptional process, reset the env vars by Setting vconf VCONFKEY_LANGSET
299 */
300 static int setting_main_lang_changed_cb(void *data)
301 {
302         SETTING_TRACE_BEGIN;
303         setting_main_appdata *ad = data;
304
305         char* str = NULL;
306         if (ad->data_wifi) {
307             str = (char *)get_pa_Wi_Fi_on_off_str();
308                 if ( ! str) str = g_strdup("err");
309             ad->data_wifi->sub_desc = str;
310         }
311         if (ad->data_bt) {
312             str = (char *)g_strdup(get_BT_on_off_str());
313                 if ( ! str) str = g_strdup("err");
314             ad->data_bt->sub_desc = str;
315         }
316         if (ad->data_nfc) {
317             str = (char *)g_strdup(get_NFC_on_off_str());
318                 if ( ! str) str = g_strdup("err");
319             ad->data_nfc->sub_desc = str;
320         }
321         if (ad->data_mobileApp) {
322             str = (char *)g_strdup(get_Mobile_AP_on_off_str());
323                 if ( ! str) str = g_strdup("err");
324             ad->data_mobileApp->sub_desc = str;
325         }
326         if (ad->data_bright) {
327                 str = (char*)g_strdup(get_brightness_mode_str());
328                 if ( ! str) str = g_strdup("err");
329                 ad->data_bright->sub_desc = str;
330         }
331
332         if (ad->data_moreConnect) {
333                 str = (char*)g_strdup(_(MORE_CONNECT_STR));
334                 if ( ! str) str = g_strdup("err");
335                 ad->data_moreConnect->sub_desc = str;
336         }
337
338         if (ad->data_moreSystem) {
339                 str = (char*)g_strdup(_(MORE_SYSTEM_STR));
340                 if ( ! str) str = g_strdup("err");
341                 ad->data_moreSystem->sub_desc = str;
342         }
343
344         if (ad->main_genlist) elm_genlist_realized_items_update(ad->main_genlist);
345         if (ad->genlist_load) elm_genlist_realized_items_update(ad->genlist_load);
346
347         Elm_Object_Item *navi_it = NULL;
348 #if SUPPORT_MORE_ITEM_FUNCTION
349         navi_it = elm_naviframe_top_item_get(ad->navibar_main);
350         if (navi_it) elm_object_item_text_set(navi_it, _(KeyStr_MoreSystem));
351 #endif
352
353         navi_it = elm_naviframe_bottom_item_get(ad->navibar_main);
354         if (navi_it)
355                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_SETTINGS"));
356
357         if (ad->edit_item)
358         {
359 #if SUPPORT_BOTTOM_BTNS
360                 elm_object_item_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
361 #else
362                 //elm_object_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
363                 Evas_Object *eo_btn = elm_object_item_part_content_get(ad->edit_item, "object");
364                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
365                 elm_object_text_set(eo_btn, _(EDIT_PREFERRED_STR));
366 #endif
367         }
368
369         if (ad->segment_all) elm_object_item_text_set(ad->segment_all, _(ALL_STR));
370         if (ad->segment_preferred) elm_object_item_text_set(ad->segment_preferred,
371                                            _(PREFERRED_STR));
372
373         Elm_Object_Item *item = NULL;
374         item = elm_toolbar_first_item_get(ad->controlbar);
375         setting_retvm_if(!item, SETTING_RETURN_FAIL, "get toolbar first item failed");
376         char tmp_text[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0,};
377         if (MAIN_PROFILE_ALL == ad->profile_type) {
378                 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(PREFERRED_STR));
379         } else if (MAIN_PROFILE_PREFERRED == ad->profile_type) {
380                 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(ALL_STR));
381         } else {
382                 /* do nothing */
383         }
384         elm_object_item_text_set(item, tmp_text);
385
386         if (ad->ug)
387                 ug_send_event(UG_EVENT_LANG_CHANGE);
388
389         return SETTING_RETURN_SUCCESS;
390 }
391
392 /**
393 * the event process when other VCONFS changes
394 */
395 static void setting_other_vconf_change_cb(keynode_t *key, void *data)
396 {
397         setting_main_appdata *ad = data;
398         retm_if(!data, "Invalid argument: data is NULL");
399
400         Setting_GenGroupItem_Data* item_to_update = NULL;
401         char *vconf_name = vconf_keynode_get_name(key);
402         //SETTING_TRACE("the value of [ %s ] just changed", vconf_name);
403
404         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_WIDGET_THEME_STR)) {
405                 return;
406         } else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL)) {
407                 item_to_update = ad->data_flight;
408                 retm_if(!item_to_update, "ad->data_flight is NULL");
409
410                 int status = 0;
411                 vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, &status);
412                 item_to_update->chk_status = status;
413                 if (ad->bAppPause || ad->ug) {
414                         ad->updateItems[GL_ITEM_FLIGHT] = EINA_TRUE;
415                 } else { // app is not in pause without ug
416                         elm_check_state_set(item_to_update->eo_check, status);
417                 }
418                 return;
419         } else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL)) {
420                 item_to_update = ad->data_rotationMode;
421                 retm_if(!item_to_update, "ad->data_rotationMode is NULL");
422
423                 int status = 0;
424                 vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &status);
425
426                 item_to_update->chk_status = !status;
427
428                 if (ad->bAppPause || ad->ug) {
429                         ad->updateItems[GL_ITEM_ROTATION] = EINA_TRUE;
430                 } else { // app is not in pause without ug
431                         elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
432                 }
433                 return;
434         } else if (!safeStrCmp(vconf_name, VCONFKEY_NFC_STATE)) {
435                 SETTING_TRACE_DEBUG("%s updated", vconf_name);
436                 item_to_update = ad->data_nfc;
437                 retm_if(!item_to_update, "ad->data_nfc is NULL");
438
439                 item_to_update->sub_desc = (char *)g_strdup(get_NFC_on_off_str());
440
441                 SETTING_TRACE_DEBUG("%s", item_to_update->sub_desc);
442
443                 if (ad->bAppPause || ad->ug) {
444                         ad->updateItems[GL_ITEM_NFC] = EINA_TRUE;
445                 } else { // app is not in pause without ug
446                         elm_object_item_data_set(item_to_update->item, item_to_update);
447                         elm_genlist_item_update(item_to_update->item);
448                 }
449         }
450 }
451
452 /**
453 * the event process when int VCONFS changes
454 */
455 static void setting_int_vconf_change_cb(keynode_t *key, void *data)
456 {
457         setting_main_appdata *ad = data;
458         retm_if(!data, "Invalid argument: data is NULL");
459
460         int status = vconf_keynode_get_int(key);
461         char *vconf_name = vconf_keynode_get_name(key);
462         SETTING_TRACE("Enter %s(%s=%d)", __FUNCTION__, vconf_name, status);
463
464         char *pa_wifi_device = NULL;
465         Setting_GenGroupItem_Data* item_to_update = NULL;
466
467         if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_STATE)) {
468                 item_to_update = ad->data_wifi;
469                 retm_if(!item_to_update, "ad->data_wifi is NULL");
470
471                 switch (status) {
472                 case VCONFKEY_WIFI_OFF:
473                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
474                         break;
475
476                 case VCONFKEY_WIFI_UNCONNECTED:
477                 case VCONFKEY_WIFI_CONNECTED:
478                 case VCONFKEY_WIFI_TRANSFER:
479                         pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
480                         if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
481                                 item_to_update->sub_desc = (char *)g_strdup(pa_wifi_device);
482                         } else {
483                                 item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
484                         }
485                         FREE(pa_wifi_device);
486                         break;
487                 default:
488                         SETTING_TRACE_ERROR("Invalid wifi status!");
489                         return;
490                 }
491
492                 if (ad->bAppPause || ad->ug) {
493                         ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
494                 } else { // app is not in pause without ug
495                         elm_object_item_data_set(item_to_update->item, item_to_update);
496                         elm_genlist_item_update(item_to_update->item);
497                 }
498         } else if (!safeStrCmp(vconf_name, VCONFKEY_BT_STATUS)) {
499                 item_to_update = ad->data_bt;
500                 retm_if(!item_to_update, "ad->data_bt is NULL");
501
502                 if (FALSE == status) {
503                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
504                 } else {
505                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
506                 }
507
508                 if (ad->bAppPause || ad->ug) {
509                         ad->updateItems[GL_ITEM_BT] = EINA_TRUE;
510                 } else { // app is not in pause without ug
511                         elm_object_item_data_set(item_to_update->item, item_to_update);
512                         elm_genlist_item_update(item_to_update->item);
513                 }
514         } else if (!safeStrCmp(vconf_name, VCONFKEY_MOBILE_HOTSPOT_MODE)) {
515                 item_to_update = ad->data_mobileApp;
516                 retm_if(!item_to_update, "ad->data_mobileApp is NULL");
517
518                 /* For other vconfs */
519                 if (FALSE == status) {
520                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
521                 } else {
522                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
523                 }
524
525                 if (ad->bAppPause || ad->ug) {
526                         ad->updateItems[GL_ITEM_MAP] = EINA_TRUE;
527                 } else { // app is not in pause without ug
528                         elm_object_item_data_set(item_to_update->item, item_to_update);
529                         elm_genlist_item_update(item_to_update->item);
530                 }
531         } else if (!safeStrCmp(vconf_name, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW)) {
532                 if (status <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
533                         if (ad->data_bright) {
534                                 setting_disable_genlist_item(ad->data_bright->item);
535                         }
536                 } else {
537                         if (ad->data_bright) {
538                                 setting_enable_genlist_item(ad->data_bright->item);
539                         }
540
541                 }
542         }else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT)) {
543                 //update directly
544                 if (ad->data_bright)
545                 {
546                         ad->data_bright->sub_desc = (char *)g_strdup(get_brightness_mode_str());
547                         elm_object_item_data_set(ad->data_bright->item, ad->data_bright);
548                         elm_genlist_item_update(ad->data_bright->item);
549                 }
550         } else {
551                         SETTING_TRACE_ERROR("vconf_name is bad[%s]", vconf_name);
552         }
553
554         return;
555 }
556
557 /**
558 * the event process when string VCONFS changes
559 */
560 static void setting_string_vconf_change_cb(keynode_t *key, void *data)
561 {
562         SETTING_TRACE_BEGIN;
563         setting_main_appdata *ad = data;
564         retm_if(!data, "Invalid argument: data is NULL");
565
566         char *value = vconf_keynode_get_str(key);
567         char *vconf_name = vconf_keynode_get_name(key);
568         Setting_GenGroupItem_Data* item_to_update = NULL;
569
570         if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_CONNECTED_AP_NAME)) {
571                 int status;
572                 item_to_update = ad->data_wifi;
573                 retm_if(!item_to_update, "ad->data_wifi is NULL");
574
575                 if (0 != vconf_get_int(VCONFKEY_WIFI_STATE, &status)) {
576                         SETTING_TRACE_ERROR("vconf_get err: %s", VCONFKEY_WIFI_STATE);
577                         return;
578                 }
579                 SETTING_TRACE("status:%d", status);
580                 switch (status) {
581                 case VCONFKEY_WIFI_OFF:
582                         item_to_update->sub_desc =
583                                 (char *)g_strdup(setting_gettext ("IDS_COM_BODY_OFF_M_STATUS"));
584                         break;
585
586                 case VCONFKEY_WIFI_UNCONNECTED:
587                 case VCONFKEY_WIFI_CONNECTED:
588                 case VCONFKEY_WIFI_TRANSFER:
589                         if (NULL != value && '\0' != value[0]) {
590                                 SETTING_TRACE("wifi_device:%s", value);
591                                 item_to_update->sub_desc = (char *)g_strdup(value);
592                         } else {
593                                 item_to_update->sub_desc =
594                                         (char *) g_strdup(setting_gettext ("IDS_COM_BODY_ON_M_STATUS"));
595                         }
596                         break;
597                 default:
598                         SETTING_TRACE_ERROR("Invalid wifi status!");
599                         return;
600                 }
601                 if (ad->bAppPause || ad->ug) {
602                         ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
603                 } else { // app is not in pause without ug
604                         elm_object_item_data_set(item_to_update->item, item_to_update);
605                         elm_genlist_item_update(item_to_update->item);
606                 }
607         } // vconf_name == VCONFKEY_WIFI_CONNECTED_AP_NAME
608 }
609
610
611 /**
612 * Do the process which cost much time
613 */
614 static Eina_Bool setting_on_idle_lazy(void *data)
615 {
616         SETTING_TRACE_BEGIN;
617         setting_main_appdata *ad = data;
618
619         /* A. add system event callback */
620         if (sensor_create(&ad->sf_handle) != SENSOR_ERROR_NONE) {
621                 SETTING_TRACE_ERROR("sensor attach fail");
622         }
623
624
625         if (sensor_motion_doubletap_set_cb(ad->sf_handle, __main_motion_sensor_cb, ad) != SENSOR_ERROR_NONE) {
626                 SETTING_TRACE("sensor_motion_doubletap_set_cb fail to gather data");
627         }
628
629         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
630                 SETTING_TRACE_ERROR("sensor_start fail");
631         }
632
633         appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE,
634                                    setting_main_lang_changed_cb, ad);
635
636 #if LOW_BATTERY_DO_NOTHING
637         appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY,
638                                    setting_main_low_battery_cb, ad);
639 #endif
640
641         appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE,
642                                    setting_main_region_changed_cb, ad);
643
644 #if SUPPORT_APP_ROATION
645         appcore_set_rotation_cb(setting_main_rotate, ad);
646         evas_object_geometry_get(ad->win_main, &g_geometry_x, &g_geometry_y, &g_geometry_w, &g_geometry_h);
647 #endif
648
649         return FALSE;
650 }
651
652 /**
653 * The function is called to create Setting view widgets
654 */
655 static int setting_main_app_create(void *data)
656 {
657         SETTING_TRACE_BEGIN;
658         //fprintf(stderr, "[TIME] 3. it taked %d msec from main to setting_main_app_create \n", appcore_measure_time());
659         SETTING_TRACE("[TIME] 3. it taked %d msec from main to setting_main_app_create ", appcore_measure_time());
660         appcore_measure_start();
661         setting_main_appdata *ad = data;
662
663         ad->data_roaming_popup = NULL;
664
665         /* create window */
666         ad->win_main = setting_main_create_win(SETTING_PACKAGE);
667         setting_retvm_if(ad->win_main == NULL, SETTING_RETURN_FAIL, "window is null");
668         evas_object_show(ad->win_main);
669         UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
670         ad->evas = evas_object_evas_get(ad->win_main);
671
672         /* load config file */
673         int cfg_operation_ret = setting_cfg_init();
674         PLUGIN_INIT;
675
676         elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME);
677 #if SUPPORT_LCD_TIMEOUT_KEEPING
678         /* to keep according with each other */
679         int origin_backlight_value;
680         if (0 !=
681             vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
682                           &origin_backlight_value)) {
683                 /* error handle.. */
684                 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 30);
685                 origin_backlight_value = 30;
686         }
687         /* to set intial value */
688         vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP,
689                       origin_backlight_value);
690
691         /* Firstly, Setting is running in foreground, LCD_TIMEOUT must be 600s(/10m) */
692         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
693 #endif
694
695         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
696
697         setting_view_create(&setting_view_main, ad);
698         setting_view_node_table_register(&setting_view_main, NULL);
699         setting_view_node_table_register(&setting_view_more_menu, &setting_view_main);
700
701         /* error handling */
702         if (Cfg_Error_Type_Sucess != cfg_operation_ret) {
703                 SETTING_TRACE_ERROR("cfg_operation_ret: %d", cfg_operation_ret);
704                 const char *notifyStr = NULL;
705                 switch (cfg_operation_ret) {
706
707                 case Cfg_Error_Type_CreateCfg_Failed:
708                         {
709                                 notifyStr = _("failed to create config file, <br>re-install com.samsung.setting please");
710                                 break;
711                         }
712                 case Cfg_Error_Type_Mkdir_Failed:
713                         {
714                                 notifyStr = _("file system missed<br>/opt/data/setting, <br>re-install com.samsung.setting please");
715                                 break;
716                         }
717                 case Cfg_Error_Type_RemoveCfg_Failed:
718                         {
719                                 notifyStr = _("config file size 0 byte<br>and failed to re-create it.<br>try to startup the app again");
720                                 break;
721                         }
722                 case Cfg_Error_Type_ReadCfg_Failed:
723                         {
724                                 notifyStr = _("failed to read config file, <br>try to startup the app again");
725                                 break;
726                         }
727                 case Cfg_Error_Type_DirPermissionDenied:
728                         {
729                                 notifyStr =
730                                     _("the dir of config file permission denied");
731                                 break;
732                         }
733                 case Cfg_Error_Type_FilePermissionDenied:
734                         {
735                                 notifyStr = _("config file permission denied");
736                                 break;
737                         }
738                 default:
739                         {
740                                 notifyStr = _("Invalid Result, try to startup the app again");
741                                 break;
742                         }
743                 }
744                 setting_create_popup_without_btn(ad, ad->win_main, NULL, (char *)notifyStr, NULL, 10, FALSE, FALSE);
745                 return SETTING_RETURN_FAIL;
746         }
747         //fprintf(stderr, "[TIME] 4. setting_main_app_create taked %d msec \n", appcore_measure_time());
748         SETTING_TRACE("[TIME] 4. setting_main_app_create taked %d msec ", appcore_measure_time());
749         appcore_measure_start();
750
751         return 0;
752 }
753
754 /**
755 * The function is called when Setting is terminated
756 */
757 static int setting_main_app_terminate(void *data)
758 {
759         SETTING_TRACE_BEGIN;
760         setting_main_appdata *ad = data;
761         PLUGIN_FINI;
762         setting_cfg_exit();
763         clear_system_service_data();
764
765         ug_destroy_all();
766         ad->ug = NULL;
767
768         SETTING_TRACE("%s*** SETTING APPLICATION CLOSED ***%s",
769                       SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
770
771         DEREGISTER_VCONFS(ad->listened_list);
772
773         if (sensor_motion_doubletap_unset_cb(ad->sf_handle) != SENSOR_ERROR_NONE) {
774                 SETTING_TRACE("sensor_motion_doubletap_unset_cb fail to gather data");
775         }
776         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
777         sensor_destroy(ad->sf_handle);
778
779 #if SUPPORT_LCD_TIMEOUT_KEEPING
780         /* once Setting is not running, LCD_TIMEOUT must be backuped */
781         int back_value = 0;
782         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
783         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
784 #endif
785         setting_view_destroy(&setting_view_more_menu, ad);
786         setting_view_destroy(&setting_view_main, ad);
787         SETTING_TRACE("!!! After setting_view_destroy");
788         if (ad->win_main) {
789                 evas_object_del(ad->win_main);
790                 ad->win_main = NULL;
791         }
792
793         SETTING_TRACE_END;
794         return 0;
795 }
796
797 /**
798 * The function is called when Setting begins run in background from forground
799 */
800 static int setting_main_app_pause(void *data)
801 {
802         SETTING_TRACE_BEGIN;
803         setting_main_appdata *ad = data;
804
805         ad->bAppPause = EINA_TRUE;
806         if (ad->ug)
807                 ug_pause();
808
809 #if SUPPORT_LCD_TIMEOUT_KEEPING
810         /* once Setting is running in background, LCD_TIMEOUT must be backuped */
811         int back_value = 0;
812         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
813         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
814 #endif
815
816         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
817
818         return 0;
819 }
820
821 /**
822 * The function is called when Setting begins run in forground from background
823 */
824 static int setting_main_app_resume(void *data)
825 {
826         SETTING_TRACE_BEGIN;
827         setting_main_appdata *ad = data;
828
829         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
830                 SETTING_TRACE_ERROR("sf_start fail");
831         }
832
833         if (ad->ug)
834                 ug_resume();
835
836 #if SUPPORT_LCD_TIMEOUT_KEEPING
837         /* once Setting is running in foreground, LCD_TIMEOUT must be reset to 600 */
838         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
839 #endif
840
841         // update main genlist in resuming app.
842         ad->bAppPause = EINA_FALSE;
843         if(!ad->ug) {   // top-level view is not on UG
844                 SETTING_TRACE("update main genlist in resuming app without UG");
845                 setting_update_gl_item(ad);     // update genlist sub-texts
846         }
847
848         return 0;
849 }
850
851 /**
852 * The function is called by app-fwk after app_create. It always do the process which cost much time.
853 */
854 static int setting_main_app_reset(service_h service, void *data)
855 {
856         SETTING_TRACE_BEGIN;
857         setting_main_appdata *ad = data;
858
859 #if SUPPORT_LIVEBOX_DEMO
860         char *ug_name = NULL;
861         if(b != NULL)
862         {
863                 ug_name = (char*)appsvc_get_data(b, "ug");
864                 if(ug_name)
865                 {
866                         SETTING_TRACE_DEBUG("get ug_name : %s", ug_name);
867                         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
868                         setting_retm_if(!cbs, "calloc failed");
869                         cbs->layout_cb = setting_main_layout_ug_cb;
870                         cbs->result_cb = setting_main_result_ug_cb;
871                         cbs->destroy_cb = setting_main_destroy_ug_cb;
872                         cbs->priv = (void *)ad;
873
874                         char *path = get_ug_path_from_ug_args(data);
875                         service_h svc = get_bundle_from_ug_args(data);
876                         ad->ug = ug_create(NULL, ug_name, UG_MODE_FULLVIEW, svc, cbs);
877                         if (ad->ug) {
878                                 ad->isInUGMode = TRUE;
879                         } else {
880
881                                 evas_object_show(ad->ly_main);
882
883                                 SETTING_TRACE_ERROR("errno:%d", errno);
884                                 setting_create_simple_popup(ad, ad->win_main, NULL, NO_UG_FOUND_MSG);
885                         }
886                         if (path)
887                                 FREE(path);
888                         if (cbs)
889                                 FREE(cbs);
890                         path = NULL;
891                         cbs = NULL;
892                         service_destroy(svc);
893                 }
894                 else
895                 {
896                         SETTING_TRACE_DEBUG("ug_name is NULL");
897                 }
898         }
899         else
900         {
901                 SETTING_TRACE_DEBUG("bundle is NULL");
902         }
903 #endif
904         vconf_callback_fn cb = NULL;
905
906         cb = setting_int_vconf_change_cb;
907         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_BT_STATUS, cb, data);
908         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_STATE, cb, ad);
909         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_MOBILE_HOTSPOT_MODE, cb, ad);
910         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, cb, ad);
911         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, cb, data);
912
913         cb = setting_string_vconf_change_cb;
914         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_CONNECTED_AP_NAME, cb, ad);
915
916         cb = setting_other_vconf_change_cb;
917         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_USB_MODE_INT, cb, ad);
918         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_WIDGET_THEME_STR, cb, ad);
919
920         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, cb, ad);
921         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, cb, ad);
922         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_NFC_STATE, cb, ad);
923
924         if (ad->win_main)
925                 elm_win_activate(ad->win_main);
926
927         ecore_idler_add(setting_on_idle_lazy, ad);
928
929         //fprintf(stderr, "[TIME] 5. app_create -> app_resume (first display) : %d msec\n", appcore_measure_time());
930         SETTING_TRACE("[TIME] 5. app_create -> app_resume (first display) : %d msec", appcore_measure_time());
931         //fprintf(stderr, "[TIME] Total. aul_launch -> app_resume (first display) : %d msec\n", appcore_measure_time_from("APP_START_TIME"));
932         SETTING_TRACE("[TIME] Total. aul_launch -> app_resume (first display) : %d msec", appcore_measure_time_from("APP_START_TIME"));
933
934         return 0;
935 }
936
937 int main(int argc, char *argv[])
938 {
939         int r = 0;
940         setting_main_appdata ad;
941
942         elm_init(argc, argv);
943 #if SUPPORT_GL_ENGINE
944         // opengl_x11 or software_x11
945         elm_config_engine_set("software_x11");
946 #endif
947
948         //fprintf(stderr, "[TIME] 1. aul_launch -> main :: Setting main : %d msec \n", appcore_measure_time_from("APP_START_TIME"));
949         SETTING_TRACE("[TIME] 1. aul_launch -> main :: Setting main : %d msec ", appcore_measure_time_from("APP_START_TIME"));
950         appcore_measure_start();
951
952         struct appcore_ops ops = {
953                 .create = setting_main_app_create,
954                 .terminate = setting_main_app_terminate,
955                 .pause = setting_main_app_pause,
956                 .resume = setting_main_app_resume,
957                 .reset = setting_main_app_reset,
958         };
959
960         memset(&ad, 0x0, sizeof(setting_main_appdata));
961         ops.data = &ad;
962
963         //fprintf(stderr, "[TIME] 2. main : %d msec \n", appcore_measure_time());
964         SETTING_TRACE("[TIME] 2. main : %d msec ", appcore_measure_time());
965         appcore_measure_start();
966         r = appcore_efl_main(SETTING_PACKAGE, &argc, &argv, &ops);
967         retv_if(r == -1, -1);
968
969         return 0;
970 }