fixed N_SE-12894
[apps/core/preloaded/settings.git] / setting-reset / src / setting-reset.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-reset.h>
22 #include <ITapiModem.h>
23 #include <TapiUtility.h>
24 #include <tapi_common.h>
25
26 #ifndef UG_MODULE_API
27 #define UG_MODULE_API __attribute__ ((visibility("default")))
28 #endif
29
30 static void setting_reset_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
31                                        void *event_info)
32 {
33         SettingResetUG *ad = (SettingResetUG *) data;
34         setting_view_update(&setting_view_reset_main, ad);
35 }
36
37 static void *setting_reset_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
38                                         service_h service, void *priv)
39 {
40         setting_retvm_if((!priv), NULL, "!priv");
41
42         SettingResetUG *resetUG = priv;
43         resetUG->ug = ug;
44
45         resetUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
46         resetUG->win_get = (Evas_Object *) ug_get_window();
47
48         evas_object_show(resetUG->win_main_layout);
49         resetUG->evas = evas_object_evas_get(resetUG->win_main_layout);
50
51         setting_retvm_if(resetUG->win_main_layout == NULL, NULL,
52                          "cannot get main window ");
53
54         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
55
56         setting_create_Gendial_itc("multiline/1text", &(resetUG->itc_1text));
57         setting_create_Gendial_itc("dialogue/bg/1icon", &(resetUG->itc_1icon));
58
59         /*  creating a view. */
60         setting_view_node_table_register(&setting_view_reset_main, NULL);
61         setting_view_node_table_register(&setting_view_reset_settings, &setting_view_reset_main);
62         setting_view_node_set_cur_view(&setting_view_reset_main);
63
64         setting_view_create(&setting_view_reset_main, (void *)resetUG);
65         evas_object_event_callback_add(resetUG->win_main_layout,
66                                        EVAS_CALLBACK_RESIZE,
67                                        setting_reset_ug_cb_resize, resetUG);
68         return resetUG->ly_main;
69 }
70
71 static void setting_reset_ug_on_start(ui_gadget_h ug, service_h service,
72                                       void *priv)
73 {
74 }
75
76 static void setting_reset_ug_on_pause(ui_gadget_h ug, service_h service,
77                                       void *priv)
78 {
79 }
80
81 static void setting_reset_ug_on_resume(ui_gadget_h ug, service_h service,
82                                        void *priv)
83 {
84 }
85
86 static void setting_reset_ug_on_destroy(ui_gadget_h ug, service_h service,
87                                         void *priv)
88 {
89         SETTING_TRACE_BEGIN;
90         setting_retm_if((!priv), "!priv");
91         SettingResetUG *resetUG = priv;
92
93         evas_object_event_callback_del(resetUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_reset_ug_cb_resize);     /* fix flash issue for gallery */
94         resetUG->ug = ug;
95         /*  delete the allocated objects. */
96         setting_view_destroy(&setting_view_reset_settings, resetUG);
97         setting_view_destroy(&setting_view_reset_main, resetUG);
98
99         if (NULL != ug_get_layout(resetUG->ug)) {
100                 evas_object_hide((Evas_Object *) ug_get_layout(resetUG->ug));
101                 evas_object_del((Evas_Object *) ug_get_layout(resetUG->ug));
102         }
103
104         SETTING_TRACE_END;
105 }
106
107 static void setting_reset_ug_on_message(ui_gadget_h ug, service_h msg,
108                                         service_h service, void *priv)
109 {
110         SETTING_TRACE_BEGIN;
111 }
112
113 static void setting_reset_ug_on_event(ui_gadget_h ug, enum ug_event event,
114                                       service_h service, void *priv)
115 {
116         SETTING_TRACE_BEGIN;
117         setting_retm_if(!priv, "!priv");
118         SettingResetUG *ad = (SettingResetUG *) priv;
119         switch (event) {
120         case UG_EVENT_LOW_MEMORY:
121                 break;
122         case UG_EVENT_LOW_BATTERY:
123                 break;
124         case UG_EVENT_LANG_CHANGE:
125         {
126                 /* navigation item in reset setting view */
127                 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
128                 ret_if(!navi_it);
129                 elm_object_item_text_set(navi_it, _(RESET_SETTINGS_STR));
130
131                 /* navigation item in reset main view */
132                 navi_it = elm_naviframe_bottom_item_get(ad->navi_bar);
133                 ret_if(!navi_it);
134                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_RESET"));
135
136                 if (ad->main_scroller)
137                 {
138                         elm_genlist_realized_items_update(ad->main_scroller);
139                 }
140                 SETTING_TRACE("ad->main_scroller:%p", ad->main_scroller);
141
142                 if (ad->controllbar)
143                 {
144                         Elm_Object_Item *item = NULL;
145                         item = elm_toolbar_first_item_get(ad->controllbar);
146                         if (item)
147                         {
148 #if SUPPORT_BOTTOM_BTNS
149                                 elm_object_item_text_set(item, _("IDS_COM_BODY_RESET"));
150 #else
151                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
152                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
153                                 elm_object_text_set(eo_btn, _("IDS_COM_SK_CANCEL"));
154 #endif
155                         }
156
157                         item = elm_toolbar_last_item_get(ad->controllbar);
158                         if (item)
159                         {
160 #if SUPPORT_BOTTOM_BTNS
161                                 elm_object_item_text_set(item, _("IDS_COM_SK_CANCEL"));
162 #else
163                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
164                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
165                                 elm_object_text_set(eo_btn, _("IDS_COM_BODY_RESET"));
166 #endif
167                         }
168                 }
169                 Evas_Object *sub_layout = elm_object_part_content_get(ad->view_layout, "elm.swallow.contents");
170                 if (sub_layout)
171                 {
172                         Evas_Object *select_all_layout = elm_object_part_content_get(sub_layout, "search_bar");
173                         if (select_all_layout) {
174                                 elm_object_part_text_set(select_all_layout, "elm.text", _(KeyStr_Select_All));
175                         }
176                 }
177
178                 if (ad->reset_list)
179                         elm_genlist_realized_items_update(ad->reset_list);
180
181                 // setting_reset_result_popup_update(ad);
182
183                 break;
184         }
185
186         case UG_EVENT_ROTATE_PORTRAIT:
187                 break;
188         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
189                 break;
190         case UG_EVENT_ROTATE_LANDSCAPE:
191                 break;
192         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
193                 break;
194         case UG_EVENT_REGION_CHANGE:
195                 break;
196         default:
197                 break;
198         }
199 }
200
201 static void setting_reset_ug_on_key_event(ui_gadget_h ug,
202                                           enum ug_key_event event,
203                                           service_h service, void *priv)
204 {
205         SETTING_TRACE_BEGIN;
206
207         switch (event) {
208         case UG_KEY_EVENT_END:
209                 ug_destroy_me(ug);
210                 break;
211         default:
212                 break;
213         }
214 }
215
216 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
217 {
218         SETTING_TRACE_BEGIN;
219         SettingResetUG *resetUG = calloc(1, sizeof(SettingResetUG));
220         setting_retvm_if(!resetUG, -1, "Create SettingResetUG obj failed");
221
222         ops->create = setting_reset_ug_on_create;
223         ops->start = setting_reset_ug_on_start;
224         ops->pause = setting_reset_ug_on_pause;
225         ops->resume = setting_reset_ug_on_resume;
226         ops->destroy = setting_reset_ug_on_destroy;
227         ops->message = setting_reset_ug_on_message;
228         ops->event = setting_reset_ug_on_event;
229         ops->key_event = setting_reset_ug_on_key_event;
230         ops->priv = resetUG;
231         ops->opt = UG_OPT_INDICATOR_ENABLE;
232
233         return 0;
234 }
235
236 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
237 {
238         SETTING_TRACE_BEGIN;
239         struct SettingResetUG *resetUG;
240         setting_retm_if(!ops, "ops == NULL");
241
242         resetUG = ops->priv;
243         if (resetUG)
244                 FREE(resetUG);
245 }
246
247 /* ***************************************************
248  *
249  *general func
250  *
251  ***************************************************/
252 #if DISABLED_CODE
253 static void __ask_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
254 {
255         if (btn_type(obj) == POPUP_RESPONSE_OK) {
256                 elm_exit();//exit the Setting app
257         }
258
259         ret_if(!data);
260         SettingResetUG *ad = data;
261         if (ad->ask_popup) {
262                 evas_object_del(ad->ask_popup);
263                 ad->ask_popup = NULL;
264         }
265 }
266 #endif
267
268 void setting_reset_result_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
269 {
270         SETTING_TRACE_BEGIN;
271         ret_if(!data);
272         SettingResetUG *ad = data;
273         if (btn_type(obj) == POPUP_RESPONSE_OK) {
274         }
275         if (ad->notify) {
276                 evas_object_del(ad->notify);
277                 ad->notify = NULL;
278         }
279
280         if (ad->old_notify) {
281                 evas_object_del(ad->old_notify);
282                 ad->old_notify = NULL;
283         }
284         ad->pop_btn = NULL;
285 }
286
287 /**
288  * language change makes B/S on resetting "Language&Region UG"
289  */
290 void setting_reset_result_popup_update(void *data)
291 {
292 #if 1
293         SETTING_TRACE_BEGIN;
294         ret_if(!data);
295         SettingResetUG *ad = data;
296         if (ad->notify) {
297                 elm_object_part_text_set(ad->notify, "title,text", _(RESET_RESULT_STR));
298                 Evas_Object *btn = elm_object_part_content_get(ad->notify, "button1");
299                 elm_object_style_set(btn, "popup_button/default");
300                 if (btn)
301                 {
302                         elm_object_text_set(btn, _("IDS_COM_SK_OK"));
303                 }
304                 Evas_Object *genlist = elm_object_content_get(ad->notify);
305                 if(genlist)
306                 {
307                         elm_genlist_realized_items_update(genlist);
308                         elm_object_content_set(ad->notify, genlist);
309                 }
310                 //evas_object_show(ad->notify);
311         }
312 #endif
313 }
314
315
316 static void __tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
317 {
318         SETTING_TRACE_BEGIN;
319         SETTING_TRACE("result:%d", result);
320 }
321 int setting_reset_flight_mode()
322 {
323         int ret = -1;
324         TapiHandle *handle = tel_init(NULL);
325         if (!handle) {
326                 SETTING_TRACE_ERROR("tel_init error");
327         }
328
329         //if callback is NULL,it will return failed directly.
330         if (tel_set_flight_mode(handle, TAPI_POWER_FLIGHT_MODE_LEAVE, __tapi_flight_mode_cb, NULL) == 0) {
331 #if SUPPORT_RUN_SYSTEM_COMMAND
332                 ret = excuteCmd(SETTING_POSTINST_FILE, 1, "flightmode");
333 #else
334                 ret = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, FALSE);
335 #endif
336         } else {
337                 SETTING_TRACE_ERROR("tel_set_flight_mode error");
338         }
339
340
341         if (tel_deinit(handle) != 0) {
342                 SETTING_TRACE_ERROR("tel_deinit error");
343         }
344         return ret;
345 }
346
347 int setting_reset_rotation_lock(void)
348 {
349 #if SUPPORT_RUN_SYSTEM_COMMAND
350         return excuteCmd(SETTING_POSTINST_FILE, 1, "rotationLock");
351 #else
352         return vconf_set_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, TRUE);
353 #endif
354 }
355