apply FSL license
[apps/home/settings.git] / setting-about / src / setting-about-main.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include <setting-about-main.h>
18 #include <aul.h>
19 #include <iniparser.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <bluetooth-api.h>
24
25 #define MAX_DEVICE_NAME_LEN                     24
26 #define EMPTY_LIMITATION_STR            "Name cannot be empty!"
27
28
29 static int setting_about_main_create(void *cb);
30 static int setting_about_main_destroy(void *cb);
31 static int setting_about_main_update(void *cb);
32 static int setting_about_main_cleanup(void *cb);
33
34 setting_view setting_view_about_main = {
35         .create = setting_about_main_create,
36         .destroy = setting_about_main_destroy,
37         .update = setting_about_main_update,
38         .cleanup = setting_about_main_cleanup,
39 };
40
41 static void __setting_about_main_mobile_ap_turn_off_ask_resp_cb(void *data,
42                                                     Evas_Object *obj,
43                                                     void *event_info);
44
45 static void __setting_about_main_certificates_clicked(void *data);
46 static void __setting_about_main_device_name_clicked(void *data, Evas_Object *obj);
47 static void __setting_about_main_exp_cb(void *data, Evas_Object *obj, void *event_info);
48 static void __setting_about_sub_list_rd_change(void *data, Evas_Object *obj, void *event_info);
49 /* ***************************************************
50  *
51  *basic func
52  *
53  ***************************************************/
54
55 static void
56 __setting_about_device_name_changed_cb(void *data, Evas_Object *obj,
57                                        void *event_info)
58 {
59         retm_if(!data || !obj, "Data parameter is NULL");
60         //return if entry is not focused too
61         retm_if(!elm_object_focus_get(obj), "Entry is not focused");
62
63         Setting_GenGroupItem_Data *list_item =
64             (Setting_GenGroupItem_Data *) data;
65         SettingAboutUG *ad = list_item->userdata;
66         retm_if(ad == NULL, "Data parameter is NULL");
67
68         const char *entry_str = elm_entry_entry_get(obj);
69         int entry_len = safeStrLen(entry_str);
70         SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
71
72         //for genlist update
73         G_FREE(list_item->sub_desc);//release first
74         list_item->sub_desc = (char *)g_strdup(entry_str);
75
76         if (NULL == entry_str || 0 == entry_len) {
77                 if (!ad->empty_flag)
78                 {
79                         ad->empty_flag = TRUE;
80                         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
81                         if (navi_it)
82                         {
83                                 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
84                                 setting_disable_evas_object(back_btn);
85                                 setting_dim_evas_object(back_btn, TRUE);
86                         }
87
88                 }
89         } else {
90                 if (ad->empty_flag)
91                 {
92                         ad->empty_flag = FALSE;
93                         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
94                         if (navi_it)
95                         {
96                                 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
97                                 setting_enable_evas_object(back_btn);
98                                 setting_undo_dim_evas_object(back_btn, TRUE);
99                         }
100                 }
101         }
102
103 }
104
105 void setting_about_main_get_phonenumber(char *my_numbers[], int *my_numbers_len, int *selected_index)
106 {
107         SETTING_TRACE_BEGIN;
108         /* Currently only have one SIM card */
109         TelSimSubscriberInfo_t subscriber;
110         TapiResult_t ret = 0;
111         ret = tel_get_sim_msisdn(&subscriber);
112         setting_retm_if(ret != TAPI_API_SUCCESS, "call tel_get_sim_msisdn failed");
113
114         SETTING_TRACE("num[%s]", subscriber.num);
115         *my_numbers_len = 0;
116         *selected_index = 0;
117         if(!isEmptyStr(subscriber.num)) {
118                 my_numbers[0] = (char *)g_strdup(subscriber.num);
119                 (*my_numbers_len)++;
120         } else {
121                 SETTING_TRACE("subscriber.num is empty string");
122                 my_numbers[0] = NULL;
123         }
124 }
125
126 /*
127         Model Name:
128                 - No ini: Unavailable
129                 - Tizen @ target: TIZEN
130                 - Tizen @ emul: SDK
131 */
132 void setting_about_main_get_phone_model_name(char* szStr, int nSize)
133 {
134         retm_if(szStr == NULL, "szStr parameter is NULL");
135
136         char szBin[50];
137         char szEmul[50];
138
139         const char* szBinVer = NULL;
140
141         dictionary* dic = iniparser_load(SETTING_ABOUT_INFO_PATH);
142         if (dic) {
143                 szBinVer = (char*)iniparser_getstr(dic, "Version:Build");
144                 if (szBinVer) {
145                         char* str = g_strdup(szBinVer);
146                         if (str) {
147                                 char* pPos = str;
148                                 while (*pPos++) {
149                                         if ('_' == *pPos)
150                                                 *pPos = ' ';
151                                 }
152                                 sscanf(str, "%s %s", szBin, szEmul);
153                         }
154                         G_FREE(str);
155                 }
156         }
157
158         if (!strncmp(szEmul, "emul", 4)) {
159                 snprintf(szStr, nSize, "%s", "SDK");
160         } else {
161                 if (!strncmp(szBin, "TIZEN", 5)) {
162                         snprintf(szStr, nSize, "TIZEN REFERENCE");
163                 } else {
164                         snprintf(szStr, nSize, "%s", _("IDS_ST_HEADER_UNAVAILABLE"));
165                 }
166         }
167
168         if (dic) {
169                 iniparser_freedict(dic);
170                 dic = NULL;
171         }
172 }
173
174 void setting_about_main_get_sw_version(char* szStr, int nSize)
175 {
176         retm_if(szStr == NULL, "szStr parameter is NULL");
177
178         dictionary* dic = iniparser_load(SETTING_ABOUT_INFO_PATH);
179         if (dic == NULL) {
180                 snprintf(szStr, nSize, "%s", _("IDS_ST_HEADER_UNAVAILABLE"));
181         } else {
182                 char* szBinVer =
183                         g_strdup((char*)iniparser_getstr(dic, "Version:Version"));
184                 if (szBinVer) {
185                         char* pPos = szBinVer;
186                         while(*pPos++) {
187                                 if ('.' == *pPos) *pPos = '\0';
188                         }
189                 } else {
190                         szBinVer = g_strdup(_("IDS_ST_HEADER_UNAVAILABLE"));
191                 }
192                 char* szBinVerMaj = g_strdup((char*)iniparser_getstr(dic, "Version:Major"));
193                 char* szBinVerMin = g_strdup((char*)iniparser_getstr(dic, "Version:Minor"));
194
195                 if (szBinVerMaj == NULL || szBinVerMaj == '\0'
196                                         || szBinVerMin == NULL || szBinVerMin == '\0') {
197                         snprintf(szStr, nSize, "TIZEN %s", szBinVer);
198                 } else {
199                         snprintf(szStr, nSize, "TIZEN%s.%s %s", szBinVerMaj, szBinVerMin, szBinVer);
200                 }
201
202                 if (szBinVer != NULL) G_FREE(szBinVer);
203                 if (szBinVerMaj != NULL) G_FREE(szBinVerMaj);
204                 if (szBinVerMin != NULL) G_FREE(szBinVerMin);
205         }
206
207         if (dic) {
208                 iniparser_freedict(dic);
209                 dic = NULL;
210         }
211 }
212
213 void setting_about_main_get_wifi_mac_address_string(char *str, int size)
214 {
215         setting_retm_if(str == NULL, "str parameter is NULL");
216         setting_retm_if(size < SETTING_ABOUT_WIFI_MAC_STR_LEN+1, "size parameter is wrong");
217
218         FILE *p = fopen(SETTING_ABOUT_MACINFO_PATH, "r");
219
220
221
222         if (p) {
223
224                 fread(str, sizeof(char), SETTING_ABOUT_WIFI_MAC_STR_LEN, p);
225                 fclose(p);
226                 p = NULL;
227         } else {
228                 perror("open failed!");
229         }
230
231
232         SETTING_TRACE_DEBUG("get_wifi_mac_address : %s", str);
233
234         if(safeStrLen(str) == 0)
235                 snprintf(str, size, "%s  (%s)", _("IDS_ST_HEADER_UNAVAILABLE"), _(SETTING_ABOUT_NEVER_TURN_WIFI_ON_STR));
236
237
238
239
240
241 }
242
243 void setting_about_main_get_battery_string(char *str, int size)
244 {
245         setting_retm_if(str == NULL, "str parameter is NULL");
246
247         int val = -1;
248         char file[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
249         snprintf(file, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO,
250                  "%s/%s/%s", SETTING_ABOUT_POWER_SUPPLY_PATH, "battery", "capacity");
251
252         char buf[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
253         int fd = 0;
254         int r = 0;
255
256         fd = open(file, O_RDONLY);
257         if (fd != -1) {
258                 r = read(fd, buf, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
259                 if ((r >= 0) && (r < MAX_DISPLAY_STR_LEN_ON_PHONE_INFO)) {
260                         buf[r] = '\0';
261                         val = atoi(buf);
262                         snprintf(str, size, "%d%s", val, "\%");
263                 } else {
264                         SETTING_TRACE_ERROR("read file fail");
265                         snprintf(str, size, _("IDS_ST_HEADER_UNAVAILABLE"));
266                 }
267
268                 close(fd);
269         } else {
270                 SETTING_TRACE_ERROR("open file fail");
271                 snprintf(str, size, _("IDS_ST_HEADER_UNAVAILABLE"));
272         }
273 }
274
275 void setting_about_main_get_bluetooth_address_string(char *str, int size)
276 {
277         setting_retm_if(str == NULL, "str parameter is NULL");
278
279         bluetooth_device_address_t local_address;
280         memset(&local_address, 0x0, sizeof(local_address));
281         int ret = 0;
282
283         /* for fixing BS of dbus signal */
284         bluetooth_register_callback(NULL, NULL);
285
286     ret = bluetooth_get_local_address(&local_address);
287
288         /* for fixing BS of dbus signal */
289         bluetooth_unregister_callback();
290
291     if (ret < 0)
292         {
293         snprintf(str, size, "%s", _("IDS_ST_HEADER_UNAVAILABLE"));
294     }
295         else
296     {
297                 snprintf(str, size, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
298                         local_address.addr[0], local_address.addr[1], local_address.addr[2],
299                         local_address.addr[3], local_address.addr[4], local_address.addr[5]);
300     }
301         SETTING_TRACE_DEBUG("bt address : %s", str);
302 }
303
304 int __stat_get_cpuinfo(float *usr_pct, float *sys_pct)
305 {
306         setting_retvm_if(usr_pct == NULL, -ENOENT, "param usr_pct is null");
307         setting_retvm_if(sys_pct == NULL, -ENOENT, "param sys_pct is null");
308
309         /*  default value */
310         *usr_pct = 0.0;
311         *sys_pct = 0.0;
312         static unsigned long long usr_time = 0, nice_time = 0, sys_time = 0;
313         static unsigned long long old_usr = 0, old_nice = 0, old_sys = 0;
314         static struct timeval old_tv, cur_tv;
315         unsigned long long elapsed_tick;
316         long tick_per_sec;
317         long cpu_num;
318         FILE *fp = NULL;
319         int ret = 0;
320
321         tick_per_sec = sysconf(_SC_CLK_TCK);
322         cpu_num = sysconf(_SC_NPROCESSORS_ONLN);
323
324         if (cpu_num < 1)
325                 cpu_num = 1;
326
327         gettimeofday(&cur_tv, NULL);
328         fp = fopen(SETTING_ABOUT_STAT_PATH, "r");
329         if (fp == NULL) {
330                 SETTING_TRACE_ERROR("fp == NULL");
331                 return -ENOENT;
332         }
333
334         char cpu_info[MAX_COMMON_BUFFER_LEN] = {0,};
335         char *cpu_info_p = fgets(cpu_info, MAX_COMMON_BUFFER_LEN, fp);
336
337                 if(cpu_info_p == NULL) {
338                         SETTING_TRACE_ERROR("fgets failed");
339                         fclose(fp);   // free - code
340                         return -ENOENT;
341                 }
342
343         char *substr = NULL;
344         unsigned long long tmp_long = 0;
345         int i = 0;
346         /* split cpu_info, get 3 numbers headmost*/
347         while ((substr = strsep(&cpu_info_p, " \t")) != NULL) {
348                 char* endptr = NULL;
349                 tmp_long = strtoull(substr, &endptr, 10);
350                 if (tmp_long != 0 && tmp_long != ULLONG_MAX) {
351                         switch (i) {
352                         case 0:
353                                 usr_time = tmp_long;
354                                 break;
355                         case 1:
356                                 nice_time = tmp_long;
357                                 break;
358                         case 2:
359                                 sys_time = tmp_long;
360                                 break;
361                         default:
362                                 break;
363                         }
364                         i++;
365                 }
366                 if (i >= 3) {
367                         break;
368                 }
369         }
370
371         fclose(fp);
372         fp = NULL;
373         if (old_usr == 0) {
374                 ret = -EAGAIN;
375                 SETTING_TRACE_ERROR("old_usr == 0");
376                 goto out;
377         }
378
379         elapsed_tick = (cur_tv.tv_sec - old_tv.tv_sec) * tick_per_sec +
380             ((cur_tv.tv_usec - old_tv.tv_usec) * tick_per_sec) / 1000000;
381
382         /* REMOVE BS */
383         if (elapsed_tick != 0)
384                 *usr_pct =
385                     ((float)(usr_time - old_usr) * 100 / elapsed_tick) /
386                     cpu_num;
387         else
388                 *usr_pct = 0;
389         /* REMOVE BS */
390         if (elapsed_tick != 0)
391                 *sys_pct =
392                     ((float)(sys_time - old_sys) * 100 / elapsed_tick) /
393                     cpu_num;
394         else
395                 *sys_pct = 0;
396
397  out:
398         old_usr = usr_time;
399         old_nice = nice_time;
400         old_sys = sys_time;
401         old_tv = cur_tv;
402
403         return ret;
404 }
405
406 static Eina_Bool __timer_update_cb(const void *data)
407 {
408         retv_if(data == NULL, TRUE);
409         SettingAboutUG *ad = (SettingAboutUG *) data;
410
411         char str[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
412         if (ad->item_data_cpu) {
413                 float usr, sys;
414                 int ret = __stat_get_cpuinfo(&usr, &sys);
415                 if (ret == -ENOENT) {
416                         SETTING_TRACE_ERROR("call __stat_get_cpuinfo fail");
417                         snprintf(str, sizeof(str),
418                                  _("IDS_ST_HEADER_UNAVAILABLE"));
419                 } else {
420                         snprintf(str, sizeof(str), "%.0f%s", usr + sys, "\%");
421                 }
422
423                 ad->item_data_cpu->sub_desc = (char *)g_strdup(str);
424                 elm_object_item_data_set(ad->item_data_cpu->item, ad->item_data_cpu);
425                 elm_genlist_item_update(ad->item_data_cpu->item);
426         }
427
428         if (ad->item_data_battery) {
429                 setting_about_main_get_battery_string(str, sizeof(str));
430                 ad->item_data_battery->sub_desc = (char *)g_strdup(str);
431                 elm_object_item_data_set(ad->item_data_battery->item, ad->item_data_battery);
432                 elm_genlist_item_update(ad->item_data_battery->item);
433         }
434         return TRUE;
435 }
436
437 static void
438 __about_main_gl_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event)
439 {
440         ret_if(!data);
441         SettingAboutUG *ad = (SettingAboutUG *) data;
442         retm_if(event == NULL, "Invalid argument: event info is NULL");
443         Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *)event;
444
445         if (ad->item_dev_name) {
446                 Elm_Object_Item *selected_item = elm_genlist_at_xy_item_get(ad->genlsit, ev->output.x, ev->output.y, NULL);
447                 if (ad->empty_flag && ad->item_dev_name->item != selected_item) {
448                         setting_create_popup_without_btn(ad, ad->win_get,_(EMPTY_LIMITATION_STR),
449                                              NULL, NULL, POPUP_INTERVAL);
450                         return;
451                 }
452                 else
453                 {
454                         //invoke elm_object_unfocus to trigger "unfocus" event.
455                         elm_object_focus_set(ad->item_dev_name->eo_check, EINA_FALSE);
456                         setting_hide_input_pannel_cb(ad->item_dev_name->eo_check);
457                 }
458         }
459
460 }
461
462 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
463 {
464         SETTING_TRACE_BEGIN;
465         retm_if(!data || !obj, "Data parameter is NULL");
466
467         Evas_Object *entry_container = elm_object_parent_widget_get(obj);
468         if(entry_container)
469         {
470                 elm_object_part_text_set(entry_container, "elm.guidetext", _("IDS_ST_BODY_TAP_TO_INSERT"));
471
472                 if(elm_entry_is_empty(obj))
473                         elm_object_signal_emit(entry_container, "elm,state,guidetext,show", "elm");
474                 elm_object_signal_emit(entry_container, "elm,state,eraser,hide", "elm");
475         }
476
477         //Setting_GenGroupItem_Data *list_item = data;
478         const char *entry_str = elm_entry_entry_get(obj);
479         char *entry_str_utf8 = NULL;
480         entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
481         //int len = safeStrLen(entry_str_utf8);
482         SETTING_TRACE("To store \"%s\" into vconf[%s]", entry_str_utf8, VCONFKEY_SETAPPL_DEVICE_NAME_STR);
483
484         if (0 != vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, entry_str_utf8)) {
485                 SETTING_TRACE_ERROR("Set vconf[%s] failed",
486                                     VCONFKEY_SETAPPL_DEVICE_NAME_STR);
487         }
488
489         FREE(entry_str_utf8);
490
491 }
492
493 static void __entry_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
494 {
495         ret_if(data == NULL);
496         SettingAboutUG *ad = (SettingAboutUG*)data;
497         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info;
498         SETTING_TRACE_DEBUG("ev->key : %s", ev->key);
499
500         if(safeStrCmp(ev->key, "Return") == 0)
501         {
502                 // if entry has 1 char at list, hide ime.
503                 if(safeStrLen(elm_entry_entry_get(obj)) > 0)
504                 {
505                         ecore_imf_context_input_panel_hide((Ecore_IMF_Context*)elm_entry_imf_context_get(obj));
506                 }
507                 else
508                 {
509                         setting_create_popup_without_btn(ad, ad->win_get,_(EMPTY_LIMITATION_STR),
510                                      NULL, NULL, POPUP_INTERVAL);
511                 }
512         }
513 }
514
515 static Eina_Bool __add_event_on_idler(void *data)
516 {
517         retv_if(data==NULL, FALSE);
518
519         SettingAboutUG *ad = (SettingAboutUG*)data;
520
521         if(ad->item_dev_name)
522         evas_object_event_callback_add(ad->item_dev_name->eo_check, EVAS_CALLBACK_KEY_DOWN, __entry_key_down_cb, ad);
523
524         return ECORE_CALLBACK_CANCEL;
525 }
526
527 static int setting_about_main_create(void *cb)
528 {
529         SETTING_TRACE_BEGIN;
530         /* error check */
531         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
532
533         SettingAboutUG *ad = (SettingAboutUG *) cb;
534
535         Evas_Object *scroller = elm_genlist_add(ad->win_main_layout);
536         retvm_if(scroller == NULL, SETTING_DRAW_ERR_FAIL_SCROLLER,
537                  "Cannot set scroller object  as contento of layout");
538         elm_genlist_clear(scroller);    /* first to clear list */
539
540         /*  Enabling illume notification property for window */
541         elm_win_conformant_set(ad->win_main_layout, 1);
542         Evas_Object *conformant = elm_conformant_add(ad->win_main_layout);
543         elm_object_style_set(conformant, "internal_layout");    /*  By Kollus. 2011-01-04 */
544         evas_object_show(conformant);
545         elm_object_content_set(conformant, scroller);
546         ad->genlsit = scroller;
547
548         ad->ly_main =
549             setting_create_layout_navi_bar(ad->win_main_layout, ad->win_get,
550                                            _(KeyStr_AboutPhone),
551                                            _("IDS_COM_BODY_BACK"), NULL, NULL,
552                                            setting_about_main_click_softkey_back_cb,
553                                            NULL, NULL, ad, conformant,
554                                            &ad->navi_bar, NULL);
555
556         evas_object_event_callback_add(scroller, EVAS_CALLBACK_MOUSE_UP,
557                                        __about_main_gl_mouse_up, ad);
558
559         Elm_Object_Item *item = NULL;
560         Setting_GenGroupItem_Data *item_data = NULL;
561         char str[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
562
563         (void)setting_create_Gendial_field_titleItem(scroller,
564                                                      &(ad->itc_group_item),
565                                                      SETTING_ABOUT_DEVICE_INFO_STR, NULL);
566
567         /* Device name */
568         char *name_value = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
569         char *pa_sub_desc = elm_entry_utf8_to_markup(name_value);
570         FREE(name_value);
571
572         ad->empty_flag = FALSE;
573         if (NULL == pa_sub_desc || '\0' == pa_sub_desc[0])
574         {
575                 ad->empty_flag = TRUE;
576                 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
577                 if (navi_it)
578                 {
579                         Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
580                         setting_disable_evas_object(back_btn);
581                         setting_dim_evas_object(back_btn, TRUE);
582                 }
583         }
584
585         // [UI] Device name
586         ad->item_dev_name =
587             setting_create_Gendial_field_def(scroller, &(ad->itc_1icon),
588                                              setting_about_main_mouse_up_Gendial_list_cb,
589                                              ad, SWALLOW_Type_LAYOUT_ENTRY,
590                                              NULL, NULL, 0, SETTING_ABOUT_DEVICE_NAME_STR, pa_sub_desc,
591                                              __setting_about_device_name_changed_cb);
592         if (ad->item_dev_name) {
593                 ad->item_dev_name->userdata = ad;
594                 ad->item_dev_name->isSinglelineFlag = 1;
595                 ad->item_dev_name->stop_change_cb = __entry_unfocus_cb;
596                 ad->item_dev_name->limit_filter_data = calloc(1, sizeof(Elm_Entry_Filter_Accept_Set));
597
598                 if (ad->item_dev_name->limit_filter_data) {
599                         //max byte len is 31 not 31+1
600                         ad->item_dev_name->limit_filter_data->max_byte_count = MAX_DEVICE_NAME_LEN;
601                         ad->item_dev_name->win_main = ad->win_get;
602                 }
603                 ad->item_dev_name->input_panel_disable_flag = EINA_TRUE;
604         } else {
605                 SETTING_TRACE_ERROR("ad->item_dev_name is NULL");
606         }
607         FREE(pa_sub_desc);
608
609         /* My number */
610         int my_numbers_len = 0;
611         setting_about_main_get_phonenumber(ad->my_numbers, &my_numbers_len, &ad->my_number_sel_idx);
612         if (my_numbers_len == 1) {
613                 item_data =
614                         setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
615                                              setting_about_main_mouse_up_Gendial_list_cb,
616                                              ad, SWALLOW_Type_INVALID, NULL,
617                                              NULL, 0, SETTING_ABOUT_MY_NUMBER_STR,
618                                              ad->my_numbers[0], NULL);
619                 if (item_data) {
620                         elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
621                 } else {
622                         SETTING_TRACE_ERROR("item_data is NULL");
623                 }
624         } else if (my_numbers_len > 1){
625                 setting_enable_expandable_genlist(scroller, ad,
626                                           __setting_about_main_exp_cb, NULL);
627                 item_data = setting_create_Gendial_exp_parent_field(scroller,
628                                                     &(ad->itc_2text_3_parent),
629                                                     NULL, NULL,
630                                                     SWALLOW_Type_INVALID,
631                                                     SETTING_ABOUT_MY_NUMBER_STR,
632                                                     ad->my_numbers[ad->my_number_sel_idx]);
633
634         } else {
635                 SETTING_TRACE_ERROR("don't have my number");
636         }
637
638         memset(str, 0x00, sizeof(str));
639         setting_about_main_get_phone_model_name(str, sizeof(str));
640         item_data =
641             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
642                                              NULL, SWALLOW_Type_INVALID, NULL,
643                                              NULL, 0, SETTING_ABOUT_MODEL_STR, str, NULL);
644         if (item_data) {
645                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
646         } else {
647                 SETTING_TRACE_ERROR("item_data is NULL");
648         }
649
650         memset(str, 0x00, sizeof(str));
651         setting_about_main_get_sw_version(str, sizeof(str));
652         item_data =
653             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
654                                              NULL, SWALLOW_Type_INVALID, NULL,
655                                              NULL, 0, SETTING_ABOUT_VERSION_STR, str, NULL);
656         if (item_data) {
657                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
658         } else {
659                 SETTING_TRACE_ERROR("item_data is NULL");
660         }
661
662         if ( ! isEmulBin()) { // requested by DI Kim due to BT BS on 11/26
663                 memset(str, 0x00, sizeof(str));
664                 setting_about_main_get_bluetooth_address_string(str, sizeof(str));
665                 item_data =
666                         setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
667                                                         NULL, SWALLOW_Type_INVALID, NULL,
668                                                         NULL, 0, SETTING_ABOUT_BLUETOOTH_STR, str, NULL);
669                 if (item_data) {
670                         elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
671                 } else {
672                                 SETTING_TRACE_ERROR("item_data is NULL");
673         }
674 }
675         memset(str, 0x00, sizeof(str));
676         setting_about_main_get_wifi_mac_address_string(str, sizeof(str));
677
678         item_data =
679             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
680                                              NULL, SWALLOW_Type_INVALID, NULL,
681                                              NULL, 0, SETTING_ABOUT_WIFI_STR, str, NULL);
682         if (item_data) {
683                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
684         } else {
685                 SETTING_TRACE_ERROR("item_data is NULL");
686         }
687
688         memset(str, 0x00, sizeof(str));
689         setting_about_main_get_battery_string(str, sizeof(str));
690         item_data =
691             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
692                                              NULL, SWALLOW_Type_INVALID, NULL,
693                                              NULL, 0, SETTING_ABOUT_BATTERY_STR, str, NULL);
694         if (item_data) {
695                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
696                 ad->item_data_battery = item_data;
697         } else {
698                 SETTING_TRACE_ERROR("item_data is NULL");
699         }
700
701         memset(str, 0x00, sizeof(str));
702         float usr, sys;
703         int ret = __stat_get_cpuinfo(&usr, &sys);
704         if (ret == -ENOENT) {
705                 SETTING_TRACE_ERROR("call __stat_get_cpuinfo fail");
706                 snprintf(str, sizeof(str), _("IDS_ST_HEADER_UNAVAILABLE"));
707         } else {
708                 snprintf(str, sizeof(str), "%.0f%s", usr + sys, "\%");
709         }
710
711         ad->item_data_cpu = item_data =
712             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2), NULL,
713                                              NULL, SWALLOW_Type_INVALID, NULL,
714                                              NULL, 0, SETTING_ABOUT_CPU_USAGE_STR, str, NULL);
715         if (item_data) {
716                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
717         } else {
718                 SETTING_TRACE_ERROR("item_data is NULL");
719         }
720
721         item =
722             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
723                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
724         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
725
726         setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
727                                          setting_about_main_mouse_up_Gendial_list_cb,
728                                          ad, SWALLOW_Type_INVALID, NULL, NULL,
729                                          0, "IDS_ST_BODY_OPEN_SOURCE_LICENCES",
730                                          NULL, NULL);
731         // implementation is in progress.
732         setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
733                                          setting_about_main_mouse_up_Gendial_list_cb,
734                                          ad, SWALLOW_Type_INVALID, NULL, NULL,
735                                          0, "IDS_COM_BODY_CERTIFICATES", NULL, NULL);
736
737         ad->update_timer =
738             ecore_timer_add(2, (Ecore_Task_Cb) __timer_update_cb, ad);
739
740         ecore_idler_add(__add_event_on_idler, ad);
741
742         setting_view_about_main.is_create = 1;
743
744         return SETTING_RETURN_SUCCESS;
745 }
746
747 static int setting_about_main_destroy(void *cb)
748 {
749         SETTING_TRACE_BEGIN;
750         /* error check */
751         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
752
753         SettingAboutUG *ad = (SettingAboutUG *) cb;
754
755         if (ad->update_timer) {
756                 ecore_timer_del(ad->update_timer);
757                 ad->update_timer = NULL;
758         }
759         if (ad->popup) {
760                 evas_object_del(ad->popup);
761                 ad->popup = NULL;
762         }
763         if (ad->progress_bar) {
764                 evas_object_del(ad->progress_bar);
765                 ad->progress_bar = NULL;
766         }
767
768         if (ad->ly_main != NULL) {
769                 evas_object_del(ad->ly_main);
770                 ad->ly_main = NULL;
771         }
772
773         setting_view_about_main.is_create = 0;
774         return SETTING_RETURN_SUCCESS;
775 }
776
777 static int setting_about_main_update(void *cb)
778 {
779         SETTING_TRACE_BEGIN;
780         /* error check */
781         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
782
783         SettingAboutUG *ad = (SettingAboutUG *) cb;
784
785         if (ad->ly_main != NULL) {
786                 evas_object_show(ad->ly_main);
787         }
788
789         return SETTING_RETURN_SUCCESS;
790 }
791
792 static int setting_about_main_cleanup(void *cb)
793 {
794         return SETTING_RETURN_SUCCESS;
795 }
796
797 /* ***************************************************
798  *
799  *general func
800  *
801  ***************************************************/
802
803 /* ***************************************************
804  *
805  *call back func
806  *
807  ***************************************************/
808
809 static void
810 setting_about_main_click_softkey_back_cb(void *data, Evas_Object *obj,
811                                          void *event_info)
812 {
813         SETTING_TRACE_BEGIN;
814         /* error check */
815         setting_retm_if(data == NULL, "Data parameter is NULL");
816
817         SettingAboutUG *ad = (SettingAboutUG *) data;
818         if (ad->empty_flag) {
819                 setting_create_popup_without_btn(ad, ad->win_get,_(EMPTY_LIMITATION_STR),
820                                      NULL, NULL, POPUP_INTERVAL);
821                 if (ad->item_dev_name) {
822                         elm_object_focus_set(ad->item_dev_name->eo_check, EINA_TRUE);
823                 }
824                 return;
825         }
826
827         /* Send destroy request */
828         ug_destroy_me(ad->ug);
829         //imf must be hided before view is destroyed.
830         //Following code is just to improve the hiding speed. If not add these code,
831         //the input pannel will also be hided with the view destroyed,but it works too slow.
832         if (ad->item_dev_name) {
833                 elm_object_focus_set(ad->item_dev_name->eo_check, EINA_FALSE);
834                 setting_hide_input_pannel_cb(ad->item_dev_name->eo_check);
835         }
836
837         SETTING_TRACE_END;
838 }
839
840 /**
841 * @brief
842 *
843 * @param data
844 * @param obj
845 * @param event_info
846 */
847 static void
848 setting_about_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
849                                             void *event_info)
850 {
851         SETTING_TRACE_BEGIN;
852         /* error check */
853         setting_retm_if(data == NULL, "Data parameter is NULL");
854
855         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
856         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
857         elm_genlist_item_selected_set(item, 0);
858         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
859
860         /* SettingAboutUG *ad = (SettingAboutUG *) data; */
861
862         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
863         if (!safeStrCmp("IDS_ST_BODY_OPEN_SOURCE_LICENCES", list_item->keyStr)) {
864
865                 setting_view_change(&setting_view_about_main, &setting_view_about_licences, data);
866
867         } else if (!safeStrCmp("IDS_COM_BODY_CERTIFICATES", list_item->keyStr)) {
868                 __setting_about_main_certificates_clicked(data);
869         } else if (!safeStrCmp(SETTING_ABOUT_DEVICE_NAME_STR, list_item->keyStr)) {
870                 __setting_about_main_device_name_clicked(data, list_item->eo_check);
871         }
872 }
873
874 static void __destroy_certificates_ug_cb(struct ui_gadget *ug, void *priv)
875 {
876         SETTING_TRACE_BEGIN;
877
878         /* restore the '<-' button on the navigate bar */
879         ret_if(!priv);
880         SettingAboutUG *ad = (SettingAboutUG *) priv;   /* ad is point to priv */
881
882         if (ug) {
883                 ug_destroy(ug);
884                 ad->ug_loading = NULL;
885         }
886
887 }
888
889 static void __setting_about_main_certificates_clicked(void *data)
890 {
891         SETTING_TRACE_BEGIN;
892         retm_if(data == NULL, "Data parameter is NULL");
893         SettingAboutUG *ad = (SettingAboutUG *)data;
894
895         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
896         if (!cbs) {
897                 return;
898         }
899
900         cbs->layout_cb = setting_about_layout_ug_cb;
901         cbs->result_cb = NULL;
902         cbs->destroy_cb = __destroy_certificates_ug_cb;
903         cbs->priv = (void *)ad;
904
905         ad->ug_loading =
906             ug_create(ad->ug, "setting-manage-applications-efl", UG_MODE_FULLVIEW, NULL, cbs);
907
908         if (NULL == ad->ug_loading) {   /* error handling */
909                 SETTING_TRACE_ERROR("NULL == ad->ug_loading");
910         }
911         FREE(cbs);
912 }
913
914
915 static void __setting_about_main_device_name_clicked(void *data, Evas_Object *obj)
916 {
917         SETTING_TRACE_BEGIN;
918         retm_if(data == NULL, "Data parameter is NULL");
919         retm_if(obj == NULL, "obj parameter is NULL");
920         SettingAboutUG *ad = (SettingAboutUG *)data;
921
922         int mobile_ap_status = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
923         int err = -1;
924         int ret = setting_get_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, &mobile_ap_status, &err);
925         //setting_retm_if(ret == SETTING_RETURN_FAIL, "Get vconf failed");
926
927         if (!elm_object_focus_get(obj)) {
928                 elm_object_focus_set(obj, EINA_TRUE);
929         }
930
931         if ((mobile_ap_status & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) && !ad->popup_showed_flag) {
932                 if (ad->popup) {
933                         evas_object_del(ad->popup);
934                         ad->popup = NULL;
935                 }
936                 ad->popup = setting_create_popup_with_btn(ad, ad->win_get,
937                                          _(SETTING_ABOUT_MOBILE_AP_TURNED_OFF),
938                                          NULL, __setting_about_main_mobile_ap_turn_off_ask_resp_cb, 0,
939                                          1, _("IDS_COM_SK_OK"));
940         } else {
941                 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(obj);
942                 setting_retm_if(imf_context == NULL, "imf_context is NULL");
943                 ecore_imf_context_input_panel_show(imf_context);
944         }
945 }
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002 static void __setting_about_main_mobile_ap_turn_off_ask_resp_cb(void *data,
1003                                                     Evas_Object *obj,
1004                                                     void *event_info)
1005 {
1006         SETTING_TRACE_BEGIN;
1007         setting_retm_if(data == NULL, "Data parameter is NULL");
1008         SettingAboutUG *ad = (SettingAboutUG *)data;
1009         int response_type = btn_type(obj);
1010
1011         if (POPUP_RESPONSE_OK == response_type) {
1012                 ad->popup_showed_flag = TRUE;
1013                 Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(ad->item_dev_name->eo_check);
1014                 setting_retm_if(imf_context == NULL, "imf_context is NULL");
1015                 ecore_imf_context_input_panel_show(imf_context);
1016         }
1017         
1018         if (ad->popup)
1019         {
1020                 evas_object_del(ad->popup);
1021                 ad->popup = NULL;
1022         }
1023 }
1024
1025 static void __setting_about_main_exp_cb(void *data, Evas_Object *obj, void *event_info)
1026 {
1027         SETTING_TRACE_BEGIN;
1028         setting_retm_if(data == NULL, "Data parameter is NULL");
1029         setting_retm_if(event_info == NULL, "event_info parameter is NULL");
1030
1031         SettingAboutUG *ad = (SettingAboutUG *) data;
1032         Elm_Object_Item *parentItem = event_info;       /* parent item */
1033         Evas_Object *scroller = elm_object_item_widget_get(parentItem);
1034
1035         Evas_Object *rgd = elm_radio_add(scroller);
1036         elm_radio_value_set(rgd, -1);
1037
1038         int i = 0;
1039         Setting_GenGroupItem_Data *item_data = NULL;
1040         for(; i < SETTING_ABOUT_MY_NUMBERS_LEN; i++) {
1041                 if (ad->my_numbers[i] == NULL) {
1042                         break;
1043                 }
1044
1045                 item_data = setting_create_Gendial_exp_sub_field(scroller,
1046                                         &(ad->itc_1icon_1text_sub),
1047                                         NULL, NULL, parentItem,
1048                                         SWALLOW_Type_1RADIO, rgd,
1049                                         i,
1050                                         ad->my_numbers[i], __setting_about_sub_list_rd_change);
1051                 if (item_data) {
1052                         item_data->userdata = ad;
1053                         elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1054                 } else {
1055                         SETTING_TRACE_ERROR("item_data is NULL");
1056                 }
1057         }
1058         elm_radio_value_set(rgd, ad->my_number_sel_idx);
1059 }
1060
1061 static void __setting_about_sub_list_rd_change(void *data, Evas_Object *obj, void *event_info) {
1062         SETTING_TRACE_BEGIN;
1063         retm_if(data == NULL, "Data parameter is NULL");
1064         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
1065         SettingAboutUG *ad = (SettingAboutUG *) list_item->userdata;
1066         SETTING_TRACE("my_number_sel_idx = %d", ad->my_number_sel_idx);
1067         elm_radio_value_set(obj, ad->my_number_sel_idx);
1068 }
1069