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