Fix the issue in 'Setting->About phone->My number list' .
[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 }
130
131 static void setting_about_ug_on_resume(ui_gadget_h ug, service_h service,
132                                        void *priv)
133 {
134         SETTING_TRACE_BEGIN;
135         setting_retm_if((!priv), "!priv");
136         SettingAboutUG *aboutUG = priv;
137
138         char str[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
139
140         memset(str, 0x00, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
141         if(aboutUG->item_data_wifi)
142         {
143                 setting_about_main_get_wifi_mac_address_string(str, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
144                 aboutUG->item_data_wifi->sub_desc = (char*)g_strdup(str);
145                 elm_object_item_data_set(aboutUG->item_data_wifi->item, aboutUG->item_data_wifi);
146                 elm_genlist_item_update(aboutUG->item_data_wifi->item);
147         }
148         memset(str, 0x00, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
149         if(aboutUG->item_data_bt)
150         {
151                 setting_about_main_get_bluetooth_address_string(str, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
152                 aboutUG->item_data_bt->sub_desc = (char*)g_strdup(str);
153                 elm_object_item_data_set(aboutUG->item_data_bt->item, aboutUG->item_data_bt);
154                 elm_genlist_item_update(aboutUG->item_data_bt->item);
155         }
156 }
157
158 /**
159 * on_destroy function of the UG
160 *
161 * @param ug
162 * @param data
163 * @param priv
164 */
165 static void setting_about_ug_on_destroy(ui_gadget_h ug, service_h service,
166                                         void *priv)
167 {
168         SETTING_TRACE_BEGIN;
169         setting_retm_if((!priv), "!priv");
170         SettingAboutUG *aboutUG = priv;
171
172         evas_object_event_callback_del(aboutUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_about_ug_cb_resize);     /* fix flash issue for gallery */
173         aboutUG->ug = ug;
174
175         /*  delete the allocated objects. */
176         setting_view_destroy(&setting_view_about_main, aboutUG);
177         if (NULL != ug_get_layout(aboutUG->ug)) {
178                 evas_object_hide((Evas_Object *) ug_get_layout(aboutUG->ug));
179                 evas_object_del((Evas_Object *) ug_get_layout(aboutUG->ug));
180         }
181
182         SETTING_TRACE_END;
183 }
184
185 static void setting_about_ug_on_message(ui_gadget_h ug, service_h msg,
186                                         service_h service, void *priv)
187 {
188         SETTING_TRACE_BEGIN;
189 }
190
191 static void setting_about_ug_on_event(ui_gadget_h ug, enum ug_event event,
192                                       service_h service, void *priv)
193 {
194         SETTING_TRACE_BEGIN;
195         switch (event) {
196         case UG_EVENT_LOW_MEMORY:
197                 break;
198         case UG_EVENT_LOW_BATTERY:
199                 break;
200         case UG_EVENT_LANG_CHANGE:
201                 break;
202         case UG_EVENT_ROTATE_PORTRAIT:
203                 break;
204         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
205                 break;
206         case UG_EVENT_ROTATE_LANDSCAPE:
207                 break;
208         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
209                 break;
210         case UG_EVENT_REGION_CHANGE:
211                 break;
212         default:
213                 break;
214         }
215 }
216
217 static void setting_about_ug_on_key_event(ui_gadget_h ug,
218                                           enum ug_key_event event,
219                                           service_h service, void *priv)
220 {
221         SETTING_TRACE_BEGIN;
222         SettingAboutUG *ad = (SettingAboutUG *) priv;
223         if (!ug)
224                 return;
225
226         switch (event) {
227         case UG_KEY_EVENT_END:
228                 {
229                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
230                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
231                                 ug_destroy_me(ug);
232                         } else {
233                                 /* elm_naviframe_item_pop(ad->navi_bar); */
234                                 setting_view_cb_at_endKey(ad);
235                         }
236                 }
237                 break;
238         default:
239                 break;
240         }
241 }
242
243 static void __on_sim_get_msisdn(TapiHandle *handle, int result, void *data, void *user_data)
244 {
245         SETTING_TRACE_BEGIN;
246         ret_if(!user_data || !data);
247         SettingAboutUG *ad = user_data;
248         TelSimAccessResult_t access_rt = result;
249         //TelSimMsisdnList_t *list = data;
250         int i =0;
251
252         SETTING_TRACE("access_rt[%d]", access_rt);
253
254         //#define TEST
255         #ifndef TEST
256         memcpy(&(ad->my_numbers), data, sizeof(TelSimMsisdnList_t));
257         #else
258         TelSimMsisdnList_t r_numbers;
259         /////////r_numbers.count = 3;
260         r_numbers.count = 3;
261         safeCopyStr(r_numbers.list[0].name, "n1", 30);
262         safeCopyStr(r_numbers.list[1].name, "n2", 30);
263         safeCopyStr(r_numbers.list[2].name, "n3", 30);
264         safeCopyStr(r_numbers.list[0].num, "1111111111", 30);
265         safeCopyStr(r_numbers.list[1].num, "2222222222", 30);
266         safeCopyStr(r_numbers.list[2].num, "3333333333", 30);
267         memcpy(&(ad->my_numbers), &r_numbers, sizeof(TelSimMsisdnList_t));
268         #endif
269
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         bool isFound = FALSE;
275         SETTING_TRACE("ad->my_numbers.count[%d]", ad->my_numbers.count);
276
277         for (i = 0; i < ad->my_numbers.count && i < SETTING_ABOUT_MY_NUMBERS_LEN; i++) {
278                 SETTING_TRACE("index[%d] - name[%s], num[%s]", i, ad->my_numbers.list[i].name, ad->my_numbers.list[i].num);
279                 if (0 == safeStrCmp(sel_num, ad->my_numbers.list[i].num)) {
280                         isFound = TRUE;
281                 }
282         }
283         if (!isFound && ad->my_numbers.count > 0) {//if not found, set as the first num of returned-list
284                 SETTING_TRACE("Selected-num hasn't been found, to let the first one as defalut one");
285                 setting_set_string_slp_key(STR_SLP_SETTING_SELECT_NUM, ad->my_numbers.list[0].num, &err);
286         }
287
288         ad->tapi_responsed = TRUE;
289         if (ad->popup) {
290                 evas_object_del(ad->popup);
291                 ad->popup = NULL;
292         }
293         setting_about_generate_genlist((void *)ad);
294 }
295
296 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
297 {
298         SETTING_TRACE_BEGIN;
299         SettingAboutUG *aboutUG = calloc(1, sizeof(SettingAboutUG));
300         setting_retvm_if(!aboutUG, -1, "Create SettingAboutUG obj failed");
301
302         ops->create = setting_about_ug_on_create;
303         ops->start = setting_about_ug_on_start;
304         ops->pause = setting_about_ug_on_pause;
305         ops->resume = setting_about_ug_on_resume;
306         ops->destroy = setting_about_ug_on_destroy;
307         ops->message = setting_about_ug_on_message;
308         ops->event = setting_about_ug_on_event;
309         ops->key_event = setting_about_ug_on_key_event;
310         ops->priv = aboutUG;
311         ops->opt = UG_OPT_INDICATOR_ENABLE;
312
313         int err = 0;
314         int value;
315         setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
316         if (VCONFKEY_TELEPHONY_SIM_INSERTED == value)//There is a sim card, so do display to user
317         {
318                 aboutUG->handle = tel_init(NULL);
319                 if (aboutUG->handle) {
320                         SETTING_TRACE("tel_init sucessed, and there is at least one sim card, now trying to get misidns");
321                         if (tel_get_sim_msisdn(aboutUG->handle, __on_sim_get_msisdn, aboutUG) == TAPI_API_SUCCESS) {
322                                 SETTING_TRACE("tel_get_sim_msisdn sent");
323                         }
324
325                 }
326         }
327         else
328         {
329                 SETTING_TRACE_DEBUG("There is no sim card, so skip getting misidns");
330         }
331         return 0;
332 }
333
334 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
335 {
336         SETTING_TRACE_BEGIN;
337         SettingAboutUG *aboutUG;
338         setting_retm_if(!ops, "ops == NULL");
339
340         aboutUG = ops->priv;
341         if (aboutUG) {
342                 if (aboutUG->handle
343                     && tel_deinit(aboutUG->handle) == TAPI_API_SUCCESS) {
344                         SETTING_TRACE("tel_deinit sucessed");
345                 }
346                 FREE(aboutUG);
347         }
348 }
349
350 /* ***************************************************
351  **
352  **general func
353  **
354  ****************************************************/
355 void setting_about_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
356                                   void *priv)
357 {
358         SettingAboutUG *ad = (SettingAboutUG *) priv;
359         Evas_Object *base;
360
361         if (!priv)
362                 return;
363         SETTING_TRACE_BEGIN;
364
365         base = (Evas_Object *) ug_get_layout(ug);
366         if (!base)
367                 return;
368
369         switch (mode) {
370         case UG_MODE_FULLVIEW:
371                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
372                                                  EVAS_HINT_EXPAND);
373                 elm_win_resize_object_add(ad->win_get, base);
374                 evas_object_show(base);
375                 break;
376         default:
377                 break;
378         }
379
380         SETTING_TRACE_END;
381 }
382
383 /**
384 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
385 *
386 * @param[in] data
387 * @param[in] priv
388 */
389 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
390 {
391         SETTING_TRACE_BEGIN;
392 #if SUPPORT_RUN_SYSTEM_COMMAND
393         return excuteCmd(SETTING_POSTINST_FILE, 1, "about");
394 #else
395         return vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SETTING_ABOUT_DEFAULT_DEVICE_NAME);
396 #endif
397 }
398
399