Merge "[Bug] Fix N_SE-11764 : get size of all music files from db using APIs of capi...
[apps/core/preloaded/settings.git] / setting-about / src / setting-about.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
22 /**
23  *@defgroup setting-about
24  *UG creation code for setting-about
25  *
26  * - Device Info
27  *  - Name
28  *  - My number
29  *  - Model
30  *  - Version
31  *  - Bluetooth
32  *  - Wi-Fi
33  *  - Battery
34  *  - CPU usage
35  *  - Diagnostics and Usage
36  *  - Software update
37  *  - Certificates
38  */
39 #include <setting-about.h>
40 #include <setting-about-main.h>
41
42 #ifndef UG_MODULE_API
43 #define UG_MODULE_API __attribute__ ((visibility("default")))
44 #endif
45
46 /**
47 * Event process when the sizeof UG view changes
48 *
49 * @param data
50 * @param e
51 * @param obj
52 * @param event_info
53 */
54 static void setting_about_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
55                                        void *event_info)
56 {
57         SettingAboutUG *ad = (SettingAboutUG *) data;
58         setting_view_update(&setting_view_about_main, ad);
59 }
60
61 /**
62 * on_create function of the UG
63 *
64 * @param ug
65 * @param mode
66 * @param data
67 * @param priv
68 *
69 * @return
70 */
71 static void *setting_about_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
72                                         service_h service, void *priv)
73 {
74         SETTING_TRACE_BEGIN;
75         setting_retvm_if((NULL == priv), NULL, "NULL == priv");
76         SettingAboutUG *aboutUG = priv;
77         aboutUG->ug = ug;
78
79         aboutUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
80         aboutUG->win_get = (Evas_Object *) ug_get_window();
81         evas_object_show(aboutUG->win_main_layout);
82         aboutUG->evas = evas_object_evas_get(aboutUG->win_main_layout);
83
84         setting_retvm_if(aboutUG->win_main_layout == NULL, NULL,
85                          "cannot get main window ");
86
87         /* register view node table */
88         setting_view_node_table_intialize();
89         setting_view_node_table_register(&setting_view_about_main, NULL);
90
91         /* setting_view_node_table_register(&setting_view_about_about_view, &setting_view_about_main); */
92
93         /*  creating a view. */
94         setting_create_Gendial_itc("dialogue/1text", &(aboutUG->itc_1text));
95         setting_create_Gendial_itc("dialogue/2text.3", &(aboutUG->itc_2text_2));
96         setting_create_Gendial_itc("dialogue/title",
97                                    &(aboutUG->itc_group_item));
98         setting_create_Gendial_itc("dialogue/1icon", &(aboutUG->itc_1icon));
99         setting_create_Gendial_itc("dialogue/2text.3/expandable",
100                                    &(aboutUG->itc_2text_3_parent));
101         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2",
102                                    &(aboutUG->itc_1icon_1text_sub));
103         setting_create_Gendial_itc("multiline/1text",
104                                    &(aboutUG->itc_help_style));
105
106         aboutUG->itc_seperator.item_style = "dialogue/separator/21/with_line";
107         aboutUG->itc_seperator.func.text_get = NULL;
108         aboutUG->itc_seperator.func.content_get = NULL;
109         aboutUG->itc_seperator.func.state_get = NULL;
110         aboutUG->itc_seperator.func.del = NULL;
111         setting_view_node_set_cur_view(&setting_view_about_main);
112         setting_view_create(&setting_view_about_main, (void *)aboutUG);
113         evas_object_event_callback_add(aboutUG->win_main_layout,
114                                        EVAS_CALLBACK_RESIZE,
115                                        setting_about_ug_cb_resize, aboutUG);
116
117         aboutUG->popup_showed_flag = FALSE;
118         return aboutUG->ly_main;
119 }
120
121 static void setting_about_ug_on_start(ui_gadget_h ug, service_h service,
122                                       void *priv)
123 {
124 }
125
126 static void setting_about_ug_on_pause(ui_gadget_h ug, service_h service,
127                                       void *priv)
128 {
129         SETTING_TRACE_BEGIN;
130         SettingAboutUG *SettingAboutUG = priv;
131         SettingAboutUG->pause_flag = TRUE;
132 }
133
134 static void setting_about_ug_on_resume(ui_gadget_h ug, service_h service,
135                                        void *priv)
136 {
137         SETTING_TRACE_BEGIN;
138         setting_retm_if((!priv), "!priv");
139         SettingAboutUG *aboutUG = priv;
140         aboutUG->pause_flag = FALSE;
141
142         char str[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
143
144         memset(str, 0x00, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
145         if(aboutUG->item_data_wifi)
146         {
147                 setting_about_main_get_wifi_mac_address_string(str, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
148                 aboutUG->item_data_wifi->sub_desc = (char*)g_strdup(str);
149                 elm_object_item_data_set(aboutUG->item_data_wifi->item, aboutUG->item_data_wifi);
150                 elm_genlist_item_update(aboutUG->item_data_wifi->item);
151         }
152         memset(str, 0x00, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
153         if(aboutUG->item_data_bt)
154         {
155                 setting_about_main_get_bluetooth_address_string(str, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
156                 aboutUG->item_data_bt->sub_desc = (char*)g_strdup(str);
157                 elm_object_item_data_set(aboutUG->item_data_bt->item, aboutUG->item_data_bt);
158                 elm_genlist_item_update(aboutUG->item_data_bt->item);
159         }
160 }
161
162 /**
163 * on_destroy function of the UG
164 *
165 * @param ug
166 * @param data
167 * @param priv
168 */
169 static void setting_about_ug_on_destroy(ui_gadget_h ug, service_h service,
170                                         void *priv)
171 {
172         SETTING_TRACE_BEGIN;
173         setting_retm_if((!priv), "!priv");
174         SettingAboutUG *aboutUG = priv;
175
176         evas_object_event_callback_del(aboutUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_about_ug_cb_resize);     /* fix flash issue for gallery */
177         aboutUG->ug = ug;
178
179         /*  delete the allocated objects. */
180         setting_view_destroy(&setting_view_about_main, aboutUG);
181         if (NULL != ug_get_layout(aboutUG->ug)) {
182                 evas_object_hide((Evas_Object *) ug_get_layout(aboutUG->ug));
183                 evas_object_del((Evas_Object *) ug_get_layout(aboutUG->ug));
184         }
185
186         SETTING_TRACE_END;
187 }
188
189 static void setting_about_ug_on_message(ui_gadget_h ug, service_h msg,
190                                         service_h service, void *priv)
191 {
192         SETTING_TRACE_BEGIN;
193 }
194
195 static void setting_about_ug_on_event(ui_gadget_h ug, enum ug_event event,
196                                       service_h service, void *priv)
197 {
198         SETTING_TRACE_BEGIN;
199         switch (event) {
200         case UG_EVENT_LOW_MEMORY:
201                 break;
202         case UG_EVENT_LOW_BATTERY:
203                 break;
204         case UG_EVENT_LANG_CHANGE:
205                 break;
206         case UG_EVENT_ROTATE_PORTRAIT:
207                 break;
208         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
209                 break;
210         case UG_EVENT_ROTATE_LANDSCAPE:
211                 break;
212         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
213                 break;
214         case UG_EVENT_REGION_CHANGE:
215                 break;
216         default:
217                 break;
218         }
219 }
220
221 static void setting_about_ug_on_key_event(ui_gadget_h ug,
222                                           enum ug_key_event event,
223                                           service_h service, void *priv)
224 {
225         SETTING_TRACE_BEGIN;
226         SettingAboutUG *ad = (SettingAboutUG *) priv;
227         if (!ug)
228                 return;
229
230         switch (event) {
231         case UG_KEY_EVENT_END:
232                 {
233                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
234                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
235                                 ug_destroy_me(ug);
236                         } else {
237                                 /* elm_naviframe_item_pop(ad->navi_bar); */
238                                 setting_view_cb_at_endKey(ad);
239                         }
240                 }
241                 break;
242         default:
243                 break;
244         }
245 }
246
247 static void __about_gl_sel_expand(void *data, Evas_Object *obj,
248                                    void *event_info)
249 {
250         /* SETTING_TRACE_BEGIN; */
251         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
252         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
253         elm_genlist_item_selected_set(item, 0);
254         bool status = !elm_genlist_item_expanded_get(item);
255         elm_genlist_item_expanded_set(item, status);
256 }
257
258 /**
259  * @see __on_sim_get_msisdn (caller)
260  */
261 Eina_Bool __insert_item_idler(void *data)
262 {
263         SETTING_TRACE_BEGIN;
264         retv_if(!data, FALSE);
265         SettingAboutUG *ad = data;
266         if (ad->item_dev_name) //the genlist exists already.
267         {
268                 SETTING_TRACE("Beging to insert items...");
269                 // [UI] My number
270                 int err;
271                 char sel_num[TAPI_SIM_XDN_DIALING_NUMBER_LEN + 1] = { 0, };
272                 setting_get_string_slp_key(STR_SLP_SETTING_SELECT_NUM, sel_num, &err);
273
274                 Setting_GenGroupItem_Data *item_data = NULL;
275                 if (ad->my_numbers.count == 1) {
276                         item_data = calloc(1, sizeof(Setting_GenGroupItem_Data));
277                         setting_retvm_if(!item_data, FALSE, "calloc item_data failed");
278                         item_data->keyStr = (char *)g_strdup("IDS_ST_BODY_MY_NUMBER");
279                         item_data->sub_desc = (char *)g_strdup(sel_num);
280                         item_data->swallow_type = SWALLOW_Type_INVALID;
281
282                         item_data->item = elm_genlist_item_insert_after(ad->genlsit, &(ad->itc_2text_2),
283                                                               item_data, NULL,
284                                                               ad->item_dev_name->item,
285                                                               ELM_GENLIST_ITEM_NONE,
286                                                               NULL, NULL);
287                         elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
288
289                 } else if (ad->my_numbers.count > 1) {
290                         setting_enable_expandable_genlist(ad->genlsit, ad,
291                                                   setting_about_main_exp_cb, NULL);
292                         item_data = calloc(1, sizeof(Setting_GenGroupItem_Data));
293                         setting_retvm_if(!item_data, FALSE, "calloc item_data failed");
294                         item_data->keyStr = (char *)g_strdup("IDS_ST_BODY_MY_NUMBER");
295                         item_data->sub_desc = (char *)g_strdup(sel_num);
296                         item_data->swallow_type = SWALLOW_Type_INVALID;
297
298                         item_data->int_slp_setting_binded = STR_SLP_SETTING_SELECT_NUM;
299                         item_data->item = elm_genlist_item_insert_after(ad->genlsit, &(ad->itc_2text_3_parent),
300                                                               item_data, NULL,
301                                                               ad->item_dev_name->item,
302                                                               ELM_GENLIST_ITEM_TREE,
303                                                               __about_gl_sel_expand, NULL);
304                 }
305         }
306
307         return FALSE;
308 }
309
310 /**
311  * called at initialization of About UG
312  * @see tel_get_sim_msisnd
313  */
314 static void __on_sim_get_msisdn(TapiHandle *handle, int result, void *data, void *user_data)
315 {
316         SETTING_TRACE_BEGIN;
317         ret_if(!user_data || !data);
318         SettingAboutUG *ad = user_data;
319         TelSimAccessResult_t access_rt = result;
320         //TelSimMsisdnList_t *list = data;
321         int i =0;
322
323         SETTING_TRACE("access_rt[%d]", access_rt);
324
325         //#define TEST
326         #ifndef TEST
327         memcpy(&(ad->my_numbers), data, sizeof(TelSimMsisdnList_t));
328         #else
329         TelSimMsisdnList_t r_numbers;
330         /////////r_numbers.count = 3;
331         r_numbers.count = 3;
332         safeCopyStr(r_numbers.list[0].name, "n1", 30);
333         safeCopyStr(r_numbers.list[1].name, "n2", 30);
334         safeCopyStr(r_numbers.list[2].name, "n3", 30);
335         safeCopyStr(r_numbers.list[0].num, "1111111111", 30);
336         safeCopyStr(r_numbers.list[1].num, "2222222222", 30);
337         safeCopyStr(r_numbers.list[2].num, "3333333333", 30);
338         memcpy(&(ad->my_numbers), &r_numbers, sizeof(TelSimMsisdnList_t));
339         #endif
340
341         int err;
342         char sel_num[TAPI_SIM_XDN_DIALING_NUMBER_LEN + 1] = { 0, };
343         setting_get_string_slp_key(STR_SLP_SETTING_SELECT_NUM, sel_num, &err);
344
345         bool isFound = FALSE;
346         SETTING_TRACE("ad->my_numbers.count[%d]", ad->my_numbers.count);
347
348         for (i = 0; i < ad->my_numbers.count && i < SETTING_ABOUT_MY_NUMBERS_LEN; i++) {
349                 SETTING_TRACE("index[%d] - name[%s], num[%s]", i, ad->my_numbers.list[i].name, ad->my_numbers.list[i].num);
350                 if (0 == safeStrCmp(sel_num, ad->my_numbers.list[i].num)) {
351                         isFound = TRUE;
352                 }
353         }
354         if (!isFound && ad->my_numbers.count > 0) {//if not found, set as the first num of returned-list
355                 SETTING_TRACE("Selected-num hasn't been found, to let the first one as defalut one");
356                 setting_set_string_slp_key(STR_SLP_SETTING_SELECT_NUM, ad->my_numbers.list[0].num, &err);
357         }
358
359         ad->tapi_responsed = TRUE;
360         if (ad->popup) {
361                 evas_object_del(ad->popup);
362                 ad->popup = NULL;
363         }
364         setting_about_generate_genlist((void *)ad);
365 }
366
367 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
368 {
369         SETTING_TRACE_BEGIN;
370         SettingAboutUG *aboutUG = calloc(1, sizeof(SettingAboutUG));
371         setting_retvm_if(!aboutUG, -1, "Create SettingAboutUG obj failed");
372
373         ops->create = setting_about_ug_on_create;
374         ops->start = setting_about_ug_on_start;
375         ops->pause = setting_about_ug_on_pause;
376         ops->resume = setting_about_ug_on_resume;
377         ops->destroy = setting_about_ug_on_destroy;
378         ops->message = setting_about_ug_on_message;
379         ops->event = setting_about_ug_on_event;
380         ops->key_event = setting_about_ug_on_key_event;
381         ops->priv = aboutUG;
382         ops->opt = UG_OPT_INDICATOR_ENABLE;
383
384         // init aboutUG
385
386         int err = 0;
387         int value;
388         setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
389         if (VCONFKEY_TELEPHONY_SIM_INSERTED == value)//There is a sim card, so do display to user
390         {
391                 aboutUG->handle = tel_init(NULL);
392
393
394                 SETTING_TRACE("aboutUG->handle:%p", aboutUG->handle);
395                 if (aboutUG->handle) {
396                         SETTING_TRACE("tel_init sucessed, and there is at least one sim card, now trying to get misidns");
397                         if (tel_get_sim_msisdn(aboutUG->handle, __on_sim_get_msisdn, aboutUG) == TAPI_API_SUCCESS) {
398                                 SETTING_TRACE("tel_get_sim_msisdn sent");
399                         }
400
401                 }
402         }
403         else
404         {
405                 SETTING_TRACE_DEBUG("There is no sim card, so skip getting misidns");
406         }
407         return 0;
408 }
409
410 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
411 {
412         SETTING_TRACE_BEGIN;
413         SettingAboutUG *aboutUG;
414         setting_retm_if(!ops, "ops == NULL");
415
416         aboutUG = ops->priv;
417         if (aboutUG) {
418                 if (aboutUG->handle
419                     && tel_deinit(aboutUG->handle) == TAPI_API_SUCCESS) {
420                         SETTING_TRACE("tel_deinit sucessed");
421                 }
422                 FREE(aboutUG);
423         }
424 }
425
426 /* ***************************************************
427  **
428  **general func
429  **
430  ****************************************************/
431 void setting_about_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
432                                   void *priv)
433 {
434         SettingAboutUG *ad = (SettingAboutUG *) priv;
435         Evas_Object *base;
436
437         if (!priv)
438                 return;
439         SETTING_TRACE_BEGIN;
440
441         base = (Evas_Object *) ug_get_layout(ug);
442         if (!base)
443                 return;
444
445         switch (mode) {
446         case UG_MODE_FULLVIEW:
447                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
448                                                  EVAS_HINT_EXPAND);
449                 elm_win_resize_object_add(ad->win_get, base);
450                 evas_object_show(base);
451                 break;
452         default:
453                 break;
454         }
455
456         SETTING_TRACE_END;
457 }
458
459 static void __setting_about_sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
460 {
461         SETTING_TRACE_BEGIN;
462         /* error check */
463         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
464         Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
465         Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
466         elm_genlist_item_selected_set(subitem, 0);
467         Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
468         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
469         ret_if(NULL == data_subItem || NULL == data_parentItem);
470
471
472         int err;
473         setting_set_string_slp_key(data_parentItem->int_slp_setting_binded, data_subItem->keyStr, &err);
474         setting_retm_if(0 != err, "Set vconf error[%d]",data_parentItem->int_slp_setting_binded);
475
476         data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
477         elm_object_item_data_set(data_parentItem->item, data_parentItem);
478         elm_genlist_item_update(data_parentItem->item);
479         elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
480 }
481
482 static void __setting_about_sub_list_rd_change(void *data, Evas_Object *obj, void *event_info)
483
484 {
485         SETTING_TRACE_BEGIN;
486         retm_if(data == NULL, "Data parameter is NULL");
487         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
488
489         Elm_Object_Item *subItem = list_item->item;
490         Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subItem);
491
492         Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subItem);    /* subItem data */
493         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
494         ret_if(NULL == data_subItem || NULL == data_parentItem);
495
496         int err;
497         setting_set_string_slp_key(data_parentItem->int_slp_setting_binded, data_subItem->keyStr, &err);
498
499         ret_if(0 != err);
500         data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
501         elm_object_item_data_set(data_parentItem->item, data_parentItem);
502         elm_genlist_item_update(data_parentItem->item);
503         elm_radio_value_set(obj, data_subItem->chk_status);
504 }
505
506 void setting_about_main_exp_cb(void *data, Evas_Object *obj, void *event_info)
507 {
508         SETTING_TRACE_BEGIN;
509         setting_retm_if(data == NULL, "Data parameter is NULL");
510         setting_retm_if(event_info == NULL, "event_info parameter is NULL");
511
512         SettingAboutUG *ad = (SettingAboutUG *) data;
513         Elm_Object_Item *parentItem = event_info;       /* parent item */
514         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);
515         Evas_Object *scroller = elm_object_item_widget_get(parentItem);
516
517         Evas_Object *rgd = elm_radio_add(scroller);
518         elm_radio_value_set(rgd, -1);
519
520         int err;
521         char sel_num[TAPI_SIM_XDN_DIALING_NUMBER_LEN + 1] = { 0, };
522         setting_get_string_slp_key(data_parentItem->int_slp_setting_binded, sel_num, &err);
523         SETTING_TRACE("binded: %d, checked: %s, err: %d", data_parentItem->int_slp_setting_binded, sel_num, err);
524
525         int i = 0;
526         int sel_idx = -1;
527         Setting_GenGroupItem_Data *item_data = NULL;
528
529         for(; i < ad->my_numbers.count; i++) {
530                 if (ad->my_numbers.list[i].num == NULL) {
531                         break;
532                 }
533
534                 if (sel_idx == -1 && 0 == safeStrCmp(sel_num, ad->my_numbers.list[i].num)) {
535                         sel_idx = i;
536                 }
537                 item_data = setting_create_Gendial_exp_sub_field(scroller,
538                                         &(ad->itc_1icon_1text_sub),
539                                         __setting_about_sub_list_sel_cb, ad, parentItem,
540                                         SWALLOW_Type_1RADIO, rgd,
541                                         i,
542                                         ad->my_numbers.list[i].num, __setting_about_sub_list_rd_change);
543                 if (item_data) {
544                         item_data->userdata = ad;
545                 } else {
546                         SETTING_TRACE_ERROR("item_data is NULL");
547                 }
548         }
549
550         elm_radio_value_set(rgd, sel_idx);
551 }
552
553
554 /**
555 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
556 *
557 * @param[in] data
558 * @param[in] priv
559 */
560 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
561 {
562         SETTING_TRACE_BEGIN;
563 #if SUPPORT_RUN_SYSTEM_COMMAND
564         return excuteCmd(SETTING_POSTINST_FILE, 1, "about");
565 #else
566         return vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SETTING_ABOUT_DEFAULT_DEVICE_NAME);
567 #endif
568 }
569
570