cf70ecd39a5ac642d23c7134570693370bd6758a
[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         int r;
223
224         if (ad == NULL || ad->win_main == NULL)
225                 return 0;
226
227 #if 0
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 #endif
246         if (r >= 0)
247                 elm_win_rotation_with_resize_set(ad->win_main, r);
248 }
249 #endif
250
251 /**
252 * The event process when region is changes.
253 */
254 static void setting_main_region_changed_cb(void *data)
255 {
256         setting_main_appdata *ad = data;
257
258         if (ad->ug)
259                 ug_send_event(UG_EVENT_REGION_CHANGE);
260 }
261
262 /**
263 * The event process when win object is destroyed
264 */
265 static void setting_main_del_win(void *data, Evas_Object *obj, void *event)
266 {
267         elm_exit();
268 }
269
270 /**
271 * To create a win object, the win is shared between the App and all its UGs
272 */
273 static Evas_Object *setting_main_create_win(const char *name)
274 {
275         SETTING_TRACE_BEGIN;
276         Evas_Object *eo;
277         int w, h;
278
279         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
280         if (eo) {
281                 elm_win_title_set(eo, name);
282                 elm_win_borderless_set(eo, EINA_TRUE);
283                 evas_object_smart_callback_add(eo, "delete,request",
284                                                setting_main_del_win, NULL);
285                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
286                                         &w, &h);
287                 evas_object_resize(eo, w, h);
288         }
289
290         return eo;
291 }
292
293 /**
294 * exceptional process, reset the env vars by Setting vconf VCONFKEY_LANGSET
295 */
296 static void setting_main_lang_changed_cb(void *data)
297 {
298         SETTING_TRACE_BEGIN;
299         setting_main_appdata *ad = data;
300
301         char* str = NULL;
302         if (ad->data_wifi) {
303             str = (char *)get_pa_Wi_Fi_on_off_str();
304                 if ( ! str) str = g_strdup("err");
305             ad->data_wifi->sub_desc = str;
306         }
307         if (ad->data_bt) {
308             str = (char *)g_strdup(get_BT_on_off_str());
309                 if ( ! str) str = g_strdup("err");
310             ad->data_bt->sub_desc = str;
311         }
312         if (ad->data_nfc) {
313             str = (char *)g_strdup(get_NFC_on_off_str());
314                 if ( ! str) str = g_strdup("err");
315             ad->data_nfc->sub_desc = str;
316         }
317         if (ad->data_bright) {
318                 str = (char*)g_strdup(get_brightness_mode_str());
319                 if ( ! str) str = g_strdup("err");
320                 ad->data_bright->sub_desc = str;
321         }
322
323         if (ad->data_moreConnect) {
324                 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
325                 int idx = 0;
326                 while (idx < MAX_MORE_MENU_NUM && ad->more_connective_menus[idx])
327                 {
328                         if (idx != 0)
329                         {
330                                 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
331                         }
332                         safeStrNCat(sub_text, _(ad->more_connective_menus[idx]), MAX_COMMON_BUFFER_LEN);
333                         idx++;
334                 }
335                 ad->data_moreConnect->sub_desc = g_strdup(sub_text);
336         }
337
338         if (ad->data_moreSystem) {
339                 char sub_text[MAX_COMMON_BUFFER_LEN] = {0, };
340                 int idx = 0;
341                 while (idx < MAX_MORE_MENU_NUM && ad->more_system_menus[idx])
342                 {
343                         if (idx != 0)
344                         {
345                                 safeStrNCat(sub_text, ", ", MAX_COMMON_BUFFER_LEN);
346                         }
347                         safeStrNCat(sub_text, _(ad->more_system_menus[idx]), MAX_COMMON_BUFFER_LEN);
348                         idx++;
349                 }
350                 ad->data_moreSystem->sub_desc = g_strdup(sub_text);
351         }
352
353         if (ad->main_genlist) elm_genlist_realized_items_update(ad->main_genlist);
354         if (ad->genlist_load) elm_genlist_realized_items_update(ad->genlist_load);
355
356         Elm_Object_Item *navi_it = NULL;
357 #if SUPPORT_MORE_ITEM_FUNCTION
358         navi_it = elm_naviframe_top_item_get(ad->navibar_main);
359         if (navi_it) elm_object_item_text_set(navi_it, _(KeyStr_MoreSystem));
360 #endif
361
362         navi_it = elm_naviframe_bottom_item_get(ad->navibar_main);
363         if (navi_it)
364                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_SETTINGS"));
365
366         if (ad->edit_item)
367         {
368 #if SUPPORT_BOTTOM_BTNS
369                 elm_object_item_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
370 #else
371                 //elm_object_text_set(ad->edit_item, _(EDIT_PREFERRED_STR));
372                 Evas_Object *eo_btn = elm_object_item_part_content_get(ad->edit_item, "object");
373                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
374                 elm_object_text_set(eo_btn, _(EDIT_PREFERRED_STR));
375 #endif
376         }
377
378         if (ad->segment_all) elm_object_item_text_set(ad->segment_all, _(ALL_STR));
379         if (ad->segment_preferred) elm_object_item_text_set(ad->segment_preferred,
380                                            _(PREFERRED_STR));
381
382         Elm_Object_Item *item = NULL;
383         item = elm_toolbar_first_item_get(ad->controlbar);
384         setting_retvm_if(!item, SETTING_RETURN_FAIL, "get toolbar first item failed");
385         char tmp_text[MAX_DISPLAY_NAME_LEN_ON_UI + 1] = {0,};
386         if (MAIN_PROFILE_ALL == ad->profile_type) {
387                 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(PREFERRED_STR));
388         } else if (MAIN_PROFILE_PREFERRED == ad->profile_type) {
389                 snprintf(tmp_text, MAX_DISPLAY_NAME_LEN_ON_UI, "%s", _(ALL_STR));
390         } else {
391                 /* do nothing */
392         }
393         elm_object_item_text_set(item, tmp_text);
394
395         if (ad->ug)
396                 ug_send_event(UG_EVENT_LANG_CHANGE);
397 }
398
399 /**
400 * the event process when other VCONFS changes
401 */
402 static void setting_other_vconf_change_cb(keynode_t *key, void *data)
403 {
404         setting_main_appdata *ad = data;
405         retm_if(!data, "Invalid argument: data is NULL");
406
407         Setting_GenGroupItem_Data* item_to_update = NULL;
408         char *vconf_name = vconf_keynode_get_name(key);
409         //SETTING_TRACE("the value of [ %s ] just changed", vconf_name);
410
411         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_WIDGET_THEME_STR)) {
412                 return;
413         } else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL)) {
414                 item_to_update = ad->data_flight;
415                 retm_if(!item_to_update, "ad->data_flight is NULL");
416
417                 int status = 0;
418                 vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, &status);
419                 item_to_update->chk_status = status;
420                 if (ad->bAppPause || ad->ug) {
421                         ad->updateItems[GL_ITEM_FLIGHT] = EINA_TRUE;
422                 } else { // app is not in pause without ug
423                         elm_check_state_set(item_to_update->eo_check, status);
424                 }
425                 return;
426         } else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL)) {
427                 item_to_update = ad->data_rotationMode;
428                 retm_if(!item_to_update, "ad->data_rotationMode is NULL");
429
430                 int status = 0;
431                 vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &status);
432
433                 item_to_update->chk_status = !status;
434
435                 if (ad->bAppPause || ad->ug) {
436                         ad->updateItems[GL_ITEM_ROTATION] = EINA_TRUE;
437                 } else { // app is not in pause without ug
438                         elm_check_state_set(item_to_update->eo_check, item_to_update->chk_status);
439                 }
440                 return;
441         } else if (!safeStrCmp(vconf_name, VCONFKEY_NFC_STATE)) {
442                 SETTING_TRACE_DEBUG("%s updated", vconf_name);
443                 item_to_update = ad->data_nfc;
444                 retm_if(!item_to_update, "ad->data_nfc is NULL");
445
446                 item_to_update->sub_desc = (char *)g_strdup(get_NFC_on_off_str());
447
448                 SETTING_TRACE_DEBUG("%s", item_to_update->sub_desc);
449
450                 if (ad->bAppPause || ad->ug) {
451                         ad->updateItems[GL_ITEM_NFC] = EINA_TRUE;
452                 } else { // app is not in pause without ug
453                         elm_object_item_data_set(item_to_update->item, item_to_update);
454                         elm_genlist_item_update(item_to_update->item);
455                 }
456         }
457 }
458
459 /**
460 * the event process when int VCONFS changes
461 */
462 static void setting_int_vconf_change_cb(keynode_t *key, void *data)
463 {
464         setting_main_appdata *ad = data;
465         retm_if(!data, "Invalid argument: data is NULL");
466
467         int status = vconf_keynode_get_int(key);
468         char *vconf_name = vconf_keynode_get_name(key);
469         SETTING_TRACE("Enter %s(%s=%d)", __FUNCTION__, vconf_name, status);
470
471         char *pa_wifi_device = NULL;
472         Setting_GenGroupItem_Data* item_to_update = NULL;
473
474         if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_STATE)) {
475                 item_to_update = ad->data_wifi;
476                 retm_if(!item_to_update, "ad->data_wifi is NULL");
477
478                 switch (status) {
479                 case VCONFKEY_WIFI_OFF:
480                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
481                         break;
482
483                 case VCONFKEY_WIFI_UNCONNECTED:
484                 case VCONFKEY_WIFI_CONNECTED:
485                 case VCONFKEY_WIFI_TRANSFER:
486                         pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
487                         if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
488                                 item_to_update->sub_desc = (char *)g_strdup(pa_wifi_device);
489                         } else {
490                                 item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
491                         }
492                         FREE(pa_wifi_device);
493                         break;
494                 default:
495                         SETTING_TRACE_ERROR("Invalid wifi status!");
496                         return;
497                 }
498
499                 if (ad->bAppPause || ad->ug) {
500                         ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
501                 } else { // app is not in pause without ug
502                         elm_object_item_data_set(item_to_update->item, item_to_update);
503                         elm_genlist_item_update(item_to_update->item);
504                 }
505         } else if (!safeStrCmp(vconf_name, VCONFKEY_BT_STATUS)) {
506                 item_to_update = ad->data_bt;
507                 retm_if(!item_to_update, "ad->data_bt is NULL");
508
509                 if (FALSE == status) {
510                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_OFF_M_STATUS"));
511                 } else {
512                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_COM_BODY_ON_M_STATUS"));
513                 }
514
515                 if (ad->bAppPause || ad->ug) {
516                         ad->updateItems[GL_ITEM_BT] = EINA_TRUE;
517                 } else { // app is not in pause without ug
518                         elm_object_item_data_set(item_to_update->item, item_to_update);
519                         elm_genlist_item_update(item_to_update->item);
520                 }
521         } else if (!safeStrCmp(vconf_name, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW)) {
522                 if (status <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
523                         if (ad->data_bright) {
524                                 setting_disable_genlist_item(ad->data_bright->item);
525                         }
526                 } else {
527                         if (ad->data_bright) {
528                                 setting_enable_genlist_item(ad->data_bright->item);
529                         }
530
531                 }
532         }else if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT)) {
533                 //update directly
534                 if (ad->data_bright)
535                 {
536                         ad->data_bright->sub_desc = (char *)g_strdup(get_brightness_mode_str());
537                         elm_object_item_data_set(ad->data_bright->item, ad->data_bright);
538                         elm_genlist_item_update(ad->data_bright->item);
539                 }
540         } else {
541                         SETTING_TRACE_ERROR("vconf_name is bad[%s]", vconf_name);
542         }
543
544         return;
545 }
546
547 /**
548 * the event process when string VCONFS changes
549 */
550 static void setting_string_vconf_change_cb(keynode_t *key, void *data)
551 {
552         SETTING_TRACE_BEGIN;
553         setting_main_appdata *ad = data;
554         retm_if(!data, "Invalid argument: data is NULL");
555
556         char *value = vconf_keynode_get_str(key);
557         char *vconf_name = vconf_keynode_get_name(key);
558         Setting_GenGroupItem_Data* item_to_update = NULL;
559
560         if (!safeStrCmp(vconf_name, VCONFKEY_WIFI_CONNECTED_AP_NAME)) {
561                 int status;
562                 item_to_update = ad->data_wifi;
563                 retm_if(!item_to_update, "ad->data_wifi is NULL");
564
565                 if (0 != vconf_get_int(VCONFKEY_WIFI_STATE, &status)) {
566                         SETTING_TRACE_ERROR("vconf_get err: %s", VCONFKEY_WIFI_STATE);
567                         return;
568                 }
569                 SETTING_TRACE("status:%d", status);
570                 switch (status) {
571                 case VCONFKEY_WIFI_OFF:
572                         item_to_update->sub_desc =
573                                 (char *)g_strdup(setting_gettext ("IDS_COM_BODY_OFF_M_STATUS"));
574                         break;
575
576                 case VCONFKEY_WIFI_UNCONNECTED:
577                 case VCONFKEY_WIFI_CONNECTED:
578                 case VCONFKEY_WIFI_TRANSFER:
579                         if (NULL != value && '\0' != value[0]) {
580                                 SETTING_TRACE("wifi_device:%s", value);
581                                 item_to_update->sub_desc = (char *)g_strdup(value);
582                         } else {
583                                 item_to_update->sub_desc =
584                                         (char *) g_strdup(setting_gettext ("IDS_COM_BODY_ON_M_STATUS"));
585                         }
586                         break;
587                 default:
588                         SETTING_TRACE_ERROR("Invalid wifi status!");
589                         return;
590                 }
591                 if (ad->bAppPause || ad->ug) {
592                         ad->updateItems[GL_ITEM_WIFI] = EINA_TRUE;
593                 } else { // app is not in pause without ug
594                         elm_object_item_data_set(item_to_update->item, item_to_update);
595                         elm_genlist_item_update(item_to_update->item);
596                 }
597         } // vconf_name == VCONFKEY_WIFI_CONNECTED_AP_NAME
598 }
599
600
601 /**
602 * Do the process which cost much time
603 */
604 static Eina_Bool setting_on_idle_lazy(void *data)
605 {
606         SETTING_TRACE_BEGIN;
607         setting_main_appdata *ad = data;
608
609         /* A. add system event callback */
610         if (sensor_create(&ad->sf_handle) != SENSOR_ERROR_NONE) {
611                 SETTING_TRACE_ERROR("sensor attach fail");
612         }
613
614
615         if (sensor_motion_doubletap_set_cb(ad->sf_handle, __main_motion_sensor_cb, ad) != SENSOR_ERROR_NONE) {
616                 SETTING_TRACE("sensor_motion_doubletap_set_cb fail to gather data");
617         }
618
619         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
620                 SETTING_TRACE_ERROR("sensor_start fail");
621         }
622
623 //      appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, setting_main_lang_changed_cb, ad);
624
625 #if LOW_BATTERY_DO_NOTHING
626 //      appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, setting_main_low_battery_cb, ad);
627 #endif
628
629 //      appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, setting_main_region_changed_cb, ad);
630
631 #if SUPPORT_APP_ROATION
632 //      appcore_set_rotation_cb(setting_main_rotate, ad);
633         evas_object_geometry_get(ad->win_main, &g_geometry_x, &g_geometry_y, &g_geometry_w, &g_geometry_h);
634 #endif
635
636         return FALSE;
637 }
638
639 /**
640 * The function is called to create Setting view widgets
641 */
642 static int setting_main_app_create(void *data)
643 {
644         SETTING_TRACE_BEGIN;
645         //fprintf(stderr, "[TIME] 3. it taked %d msec from main to setting_main_app_create \n", appcore_measure_time());
646         //SETTING_TRACE("[TIME] 3. it taked %d msec from main to setting_main_app_create ", appcore_measure_time());
647         //appcore_measure_start();
648         setting_main_appdata *ad = data;
649
650         ad->data_roaming_popup = NULL;
651
652         /* create window */
653         ad->win_main = setting_main_create_win(SETTING_PACKAGE);
654         setting_retvm_if(ad->win_main == NULL, SETTING_RETURN_FAIL, "window is null");
655         evas_object_show(ad->win_main);
656         UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
657         ad->evas = evas_object_evas_get(ad->win_main);
658
659         /* load config file */
660         int cfg_operation_ret = setting_cfg_init();
661         PLUGIN_INIT;
662
663         elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME);
664 #if SUPPORT_LCD_TIMEOUT_KEEPING
665         /* to keep according with each other */
666         int origin_backlight_value;
667         if (0 !=
668             vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
669                           &origin_backlight_value)) {
670                 /* error handle.. */
671                 vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 30);
672                 origin_backlight_value = 30;
673         }
674         /* to set intial value */
675         vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP,
676                       origin_backlight_value);
677
678         /* Firstly, Setting is running in foreground, LCD_TIMEOUT must be 600s(/10m) */
679         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
680 #endif
681
682         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
683
684         setting_view_create(&setting_view_main, ad);
685         setting_view_node_table_register(&setting_view_main, NULL);
686         setting_view_node_table_register(&setting_view_more_menu, &setting_view_main);
687
688         /* error handling */
689         if (Cfg_Error_Type_Sucess != cfg_operation_ret) {
690                 SETTING_TRACE_ERROR("cfg_operation_ret: %d", cfg_operation_ret);
691                 const char *notifyStr = NULL;
692                 switch (cfg_operation_ret) {
693
694                 case Cfg_Error_Type_CreateCfg_Failed:
695                         {
696                                 notifyStr = _("failed to create config file, <br>re-install org.tizen.setting please");
697                                 break;
698                         }
699                 case Cfg_Error_Type_Mkdir_Failed:
700                         {
701                                 notifyStr = _("file system missed<br>/opt/data/setting, <br>re-install org.tizen.setting please");
702                                 break;
703                         }
704                 case Cfg_Error_Type_RemoveCfg_Failed:
705                         {
706                                 notifyStr = _("config file size 0 byte<br>and failed to re-create it.<br>try to startup the app again");
707                                 break;
708                         }
709                 case Cfg_Error_Type_ReadCfg_Failed:
710                         {
711                                 notifyStr = _("failed to read config file, <br>try to startup the app again");
712                                 break;
713                         }
714                 case Cfg_Error_Type_DirPermissionDenied:
715                         {
716                                 notifyStr =
717                                     _("the dir of config file permission denied");
718                                 break;
719                         }
720                 case Cfg_Error_Type_FilePermissionDenied:
721                         {
722                                 notifyStr = _("config file permission denied");
723                                 break;
724                         }
725                 default:
726                         {
727                                 notifyStr = _("Invalid Result, try to startup the app again");
728                                 break;
729                         }
730                 }
731                 setting_create_popup_without_btn(ad, ad->win_main, NULL, (char *)notifyStr, NULL, 10, FALSE, FALSE);
732                 return SETTING_RETURN_FAIL;
733         }
734         //fprintf(stderr, "[TIME] 4. setting_main_app_create taked %d msec \n", appcore_measure_time());
735         //SETTING_TRACE("[TIME] 4. setting_main_app_create taked %d msec ", appcore_measure_time());
736         //appcore_measure_start();
737
738         return true;
739 }
740
741 /**
742 * The function is called when Setting is terminated
743 */
744 static void setting_main_app_terminate(void *data)
745 {
746         SETTING_TRACE_BEGIN;
747         setting_main_appdata *ad = data;
748         PLUGIN_FINI;
749         setting_cfg_exit();
750         clear_system_service_data();
751
752         ug_destroy_all();
753         ad->ug = NULL;
754
755         SETTING_TRACE("%s*** SETTING APPLICATION CLOSED ***%s",
756                       SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
757
758         DEREGISTER_VCONFS(ad->listened_list);
759
760         if (sensor_motion_doubletap_unset_cb(ad->sf_handle) != SENSOR_ERROR_NONE) {
761                 SETTING_TRACE("sensor_motion_doubletap_unset_cb fail to gather data");
762         }
763         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
764         sensor_destroy(ad->sf_handle);
765
766 #if SUPPORT_LCD_TIMEOUT_KEEPING
767         /* once Setting is not running, LCD_TIMEOUT must be backuped */
768         int back_value = 0;
769         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
770         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
771 #endif
772         setting_view_destroy(&setting_view_more_menu, ad);
773         setting_view_destroy(&setting_view_main, ad);
774         SETTING_TRACE("!!! After setting_view_destroy");
775         if (ad->win_main) {
776                 evas_object_del(ad->win_main);
777                 ad->win_main = NULL;
778         }
779
780         SETTING_TRACE_END;
781         return 0;
782 }
783
784 /**
785 * The function is called when Setting begins run in background from forground
786 */
787 static void setting_main_app_pause(void *data)
788 {
789         SETTING_TRACE_BEGIN;
790         setting_main_appdata *ad = data;
791
792         ad->bAppPause = EINA_TRUE;
793         if (ad->ug)
794                 ug_pause();
795
796 #if SUPPORT_LCD_TIMEOUT_KEEPING
797         /* once Setting is running in background, LCD_TIMEOUT must be backuped */
798         int back_value = 0;
799         vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &back_value);
800         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, back_value);
801 #endif
802
803         sensor_stop(ad->sf_handle, SENSOR_MOTION_DOUBLETAP);
804 }
805
806 /**
807 * The function is called when Setting begins run in forground from background
808 */
809 static void setting_main_app_resume(void *data)
810 {
811         SETTING_TRACE_BEGIN;
812         setting_main_appdata *ad = data;
813
814         if (sensor_start(ad->sf_handle, SENSOR_MOTION_DOUBLETAP) != SENSOR_ERROR_NONE) {
815                 SETTING_TRACE_ERROR("sf_start fail");
816         }
817
818         if (ad->ug)
819                 ug_resume();
820
821 #if SUPPORT_LCD_TIMEOUT_KEEPING
822         /* once Setting is running in foreground, LCD_TIMEOUT must be reset to 600 */
823         vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 600);
824 #endif
825
826         // update main genlist in resuming app.
827         ad->bAppPause = EINA_FALSE;
828         if(!ad->ug) {   // top-level view is not on UG
829                 SETTING_TRACE("update main genlist in resuming app without UG");
830                 setting_update_gl_item(ad);     // update genlist sub-texts
831         }
832 }
833
834 /**
835 * The function is called by app-fwk after app_create. It always do the process which cost much time.
836 */
837 static int setting_main_app_reset(service_h service, void *data)
838 {
839         SETTING_TRACE_BEGIN;
840         setting_main_appdata *ad = data;
841
842 #if SUPPORT_LIVEBOX_DEMO
843         char *ug_name = NULL;
844         if(b != NULL)
845         {
846                 ug_name = (char*)appsvc_get_data(b, "ug");
847                 if(ug_name)
848                 {
849                         SETTING_TRACE_DEBUG("get ug_name : %s", ug_name);
850                         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
851                         setting_retm_if(!cbs, "calloc failed");
852                         cbs->layout_cb = setting_main_layout_ug_cb;
853                         cbs->result_cb = setting_main_result_ug_cb;
854                         cbs->destroy_cb = setting_main_destroy_ug_cb;
855                         cbs->priv = (void *)ad;
856
857                         char *path = get_ug_path_from_ug_args(data);
858                         service_h svc = get_bundle_from_ug_args(data);
859                         ad->ug = ug_create(NULL, ug_name, UG_MODE_FULLVIEW, svc, cbs);
860                         if (ad->ug) {
861                                 ad->isInUGMode = TRUE;
862                         } else {
863
864                                 evas_object_show(ad->ly_main);
865
866                                 SETTING_TRACE_ERROR("errno:%d", errno);
867                                 setting_create_simple_popup(ad, ad->win_main, NULL, NO_UG_FOUND_MSG);
868                         }
869                         if (path)
870                                 FREE(path);
871                         if (cbs)
872                                 FREE(cbs);
873                         path = NULL;
874                         cbs = NULL;
875                         service_destroy(svc);
876                 }
877                 else
878                 {
879                         SETTING_TRACE_DEBUG("ug_name is NULL");
880                 }
881         }
882         else
883         {
884                 SETTING_TRACE_DEBUG("bundle is NULL");
885         }
886 #endif
887         vconf_callback_fn cb = NULL;
888
889         cb = setting_int_vconf_change_cb;
890         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_BT_STATUS, cb, data);
891         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_STATE, cb, ad);
892         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, cb, ad);
893         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, cb, data);
894
895         cb = setting_string_vconf_change_cb;
896         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_WIFI_CONNECTED_AP_NAME, cb, ad);
897
898         cb = setting_other_vconf_change_cb;
899         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_USB_MODE_INT, cb, ad);
900         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_WIDGET_THEME_STR, cb, ad);
901
902         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, cb, ad);
903         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, cb, ad);
904         REGISTER_VCONF_NODE(ad->listened_list, VCONFKEY_NFC_STATE, cb, ad);
905
906         if (ad->win_main)
907                 elm_win_activate(ad->win_main);
908
909         ecore_idler_add(setting_on_idle_lazy, ad);
910
911         //fprintf(stderr, "[TIME] 5. app_create -> app_resume (first display) : %d msec\n", appcore_measure_time());
912         //SETTING_TRACE("[TIME] 5. app_create -> app_resume (first display) : %d msec", appcore_measure_time());
913         //fprintf(stderr, "[TIME] Total. aul_launch -> app_resume (first display) : %d msec\n", appcore_measure_time_from("APP_START_TIME"));
914         //SETTING_TRACE("[TIME] Total. aul_launch -> app_resume (first display) : %d msec", appcore_measure_time_from("APP_START_TIME"));
915
916         //return 0;
917 }
918
919 int main(int argc, char *argv[])
920 {
921         int r = 0;
922         setting_main_appdata ad;
923
924         elm_init(argc, argv);
925 #if SUPPORT_GL_ENGINE
926         // opengl_x11 or software_x11
927         elm_config_preferred_engine_set("software_x11");
928 #endif
929
930         //fprintf(stderr, "[TIME] 1. aul_launch -> main :: Setting main : %d msec \n", appcore_measure_time_from("APP_START_TIME"));
931         //SETTING_TRACE("[TIME] 1. aul_launch -> main :: Setting main : %d msec ", appcore_measure_time_from("APP_START_TIME"));
932         //appcore_measure_start();
933
934         app_event_callback_s ops = {
935                 .create = setting_main_app_create,
936                 .terminate = setting_main_app_terminate,
937                 .pause = setting_main_app_pause,
938                 .resume = setting_main_app_resume,
939                 .service = setting_main_app_reset,
940                 .low_battery = setting_main_low_battery_cb,
941                 .language_changed = setting_main_lang_changed_cb,
942                 .region_format_changed = setting_main_region_changed_cb,
943                 .device_orientation = setting_main_rotate,
944         };
945
946         memset(&ad, 0x0, sizeof(setting_main_appdata));
947         //ops.data = &ad;
948
949         //fprintf(stderr, "[TIME] 2. main : %d msec \n", appcore_measure_time());
950         //SETTING_TRACE("[TIME] 2. main : %d msec ", appcore_measure_time());
951         //appcore_measure_start();
952         r = app_efl_main(&argc, &argv, &ops, &ad);
953         retv_if(r == -1, -1);
954
955         return 0;
956 }