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