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