Improve the response speed of 'Reset'
[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         setting_create_Gendial_itc("multiline/1text", &(resetUG->itc_1text));
54         setting_create_Gendial_itc("dialogue/bg/1icon", &(resetUG->itc_1icon));
55
56         /*  creating a view. */
57         setting_view_node_table_register(&setting_view_reset_main, NULL);
58         setting_view_node_table_register(&setting_view_reset_settings, &setting_view_reset_main);
59         setting_view_node_set_cur_view(&setting_view_reset_main);
60
61         setting_view_create(&setting_view_reset_main, (void *)resetUG);
62         evas_object_event_callback_add(resetUG->win_main_layout,
63                                        EVAS_CALLBACK_RESIZE,
64                                        setting_reset_ug_cb_resize, resetUG);
65         return resetUG->ly_main;
66 }
67
68 static void setting_reset_ug_on_start(ui_gadget_h ug, service_h service,
69                                       void *priv)
70 {
71 }
72
73 static void setting_reset_ug_on_pause(ui_gadget_h ug, service_h service,
74                                       void *priv)
75 {
76 }
77
78 static void setting_reset_ug_on_resume(ui_gadget_h ug, service_h service,
79                                        void *priv)
80 {
81 }
82
83 static void setting_reset_ug_on_destroy(ui_gadget_h ug, service_h service,
84                                         void *priv)
85 {
86         SETTING_TRACE_BEGIN;
87         setting_retm_if((!priv), "!priv");
88         SettingResetUG *resetUG = priv;
89
90         evas_object_event_callback_del(resetUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_reset_ug_cb_resize);     /* fix flash issue for gallery */
91         resetUG->ug = ug;
92         /*  delete the allocated objects. */
93         setting_view_destroy(&setting_view_reset_settings, resetUG);
94         setting_view_destroy(&setting_view_reset_main, resetUG);
95
96         if (NULL != ug_get_layout(resetUG->ug)) {
97                 evas_object_hide((Evas_Object *) ug_get_layout(resetUG->ug));
98                 evas_object_del((Evas_Object *) ug_get_layout(resetUG->ug));
99         }
100
101         SETTING_TRACE_END;
102 }
103
104 static void setting_reset_ug_on_message(ui_gadget_h ug, service_h msg,
105                                         service_h service, void *priv)
106 {
107         SETTING_TRACE_BEGIN;
108 }
109
110 static void setting_reset_ug_on_event(ui_gadget_h ug, enum ug_event event,
111                                       service_h service, void *priv)
112 {
113         SETTING_TRACE_BEGIN;
114         setting_retm_if(!priv, "!priv");
115         SettingResetUG *ad = (SettingResetUG *) priv;
116         switch (event) {
117         case UG_EVENT_LOW_MEMORY:
118                 break;
119         case UG_EVENT_LOW_BATTERY:
120                 break;
121         case UG_EVENT_LANG_CHANGE:
122         {
123                 /* navigation item in reset setting view */
124                 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
125                 ret_if(!navi_it);
126                 elm_object_item_text_set(navi_it, _(RESET_SETTINGS_STR));
127
128                 /* navigation item in reset main view */
129                 navi_it = elm_naviframe_bottom_item_get(ad->navi_bar);
130                 ret_if(!navi_it);
131                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_RESET"));
132
133                 if (ad->main_scroller)
134                 {
135                         elm_genlist_realized_items_update(ad->main_scroller);
136                 }
137                 SETTING_TRACE("ad->main_scroller:%p", ad->main_scroller);
138
139                 if (ad->controllbar)
140                 {
141                         Elm_Object_Item *item = NULL;
142                         item = elm_toolbar_first_item_get(ad->controllbar);
143                         if (item)
144                         {
145 #if SUPPORT_BOTTOM_BTNS
146                                 elm_object_item_text_set(item, _("IDS_COM_BODY_RESET"));
147 #else
148                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
149                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
150                                 elm_object_text_set(eo_btn, _("IDS_COM_SK_CANCEL"));
151 #endif
152                         }
153
154                         item = elm_toolbar_last_item_get(ad->controllbar);
155                         if (item)
156                         {
157 #if SUPPORT_BOTTOM_BTNS
158                                 elm_object_item_text_set(item, _("IDS_COM_SK_CANCEL"));
159 #else
160                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
161                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
162                                 elm_object_text_set(eo_btn, _("IDS_COM_BODY_RESET"));
163 #endif
164                         }
165                 }
166                 Evas_Object *sub_layout = elm_object_part_content_get(ad->view_layout, "elm.swallow.contents");
167                 if (sub_layout)
168                 {
169                         Evas_Object *select_all_layout = elm_object_part_content_get(sub_layout, "search_bar");
170                         if (select_all_layout) {
171                                 elm_object_part_text_set(select_all_layout, "elm.text", _(KeyStr_Select_All));
172                         }
173                 }
174
175                 if (ad->reset_list)
176                         elm_genlist_realized_items_update(ad->reset_list);
177
178                 setting_reset_result_popup_update(ad);
179
180                 break;
181         }
182
183         case UG_EVENT_ROTATE_PORTRAIT:
184                 break;
185         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
186                 break;
187         case UG_EVENT_ROTATE_LANDSCAPE:
188                 break;
189         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
190                 break;
191         case UG_EVENT_REGION_CHANGE:
192                 break;
193         default:
194                 break;
195         }
196 }
197
198 static void setting_reset_ug_on_key_event(ui_gadget_h ug,
199                                           enum ug_key_event event,
200                                           service_h service, void *priv)
201 {
202         SETTING_TRACE_BEGIN;
203
204         switch (event) {
205         case UG_KEY_EVENT_END:
206                 ug_destroy_me(ug);
207                 break;
208         default:
209                 break;
210         }
211 }
212
213 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
214 {
215         SETTING_TRACE_BEGIN;
216         SettingResetUG *resetUG = calloc(1, sizeof(SettingResetUG));
217         setting_retvm_if(!resetUG, -1, "Create SettingResetUG obj failed");
218
219         ops->create = setting_reset_ug_on_create;
220         ops->start = setting_reset_ug_on_start;
221         ops->pause = setting_reset_ug_on_pause;
222         ops->resume = setting_reset_ug_on_resume;
223         ops->destroy = setting_reset_ug_on_destroy;
224         ops->message = setting_reset_ug_on_message;
225         ops->event = setting_reset_ug_on_event;
226         ops->key_event = setting_reset_ug_on_key_event;
227         ops->priv = resetUG;
228         ops->opt = UG_OPT_INDICATOR_ENABLE;
229
230         return 0;
231 }
232
233 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
234 {
235         SETTING_TRACE_BEGIN;
236         struct SettingResetUG *resetUG;
237         setting_retm_if(!ops, "ops == NULL");
238
239         resetUG = ops->priv;
240         if (resetUG)
241                 FREE(resetUG);
242 }
243
244 /* ***************************************************
245  *
246  *general func
247  *
248  ***************************************************/
249 static void __ask_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
250 {
251         if (btn_type(obj) == POPUP_RESPONSE_OK) {
252                 elm_exit();//exit the Setting app
253         }
254
255         ret_if(!data);
256         SettingResetUG *ad = data;
257         if (ad->ask_popup) {
258                 evas_object_del(ad->ask_popup);
259                 ad->ask_popup = NULL;
260         }
261 }
262
263 void setting_reset_result_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
264 {
265         SETTING_TRACE_BEGIN;
266         ret_if(!data);
267         SettingResetUG *ad = data;
268         if (btn_type(obj) == POPUP_RESPONSE_OK) {
269         }
270         if (ad->notify) {
271                 evas_object_del(ad->notify);
272                 ad->notify = NULL;
273         }
274
275         if (ad->old_notify) {
276                 evas_object_del(ad->old_notify);
277                 ad->old_notify = NULL;
278         }
279 }
280
281 void setting_reset_result_popup_update(void *data)
282 {
283         SETTING_TRACE_BEGIN;
284         ret_if(!data);
285         SettingResetUG *ad = data;
286         if (ad->notify) {
287                 elm_object_part_text_set(ad->notify, "title,text", _(RESET_RESULT_STR));
288                 Evas_Object *btn = elm_object_part_content_get(ad->notify, "button1");
289                 if (btn)
290                 {
291                         elm_object_text_set(btn, _("IDS_COM_SK_OK"));
292                 }
293                 Evas_Object *genlist = elm_object_content_get(ad->notify);
294                 if(genlist)
295                 {
296                         elm_genlist_realized_items_update(genlist);
297                         elm_object_content_set(ad->notify, genlist);
298                 }
299                 //evas_object_show(ad->notify);
300         }
301 }
302
303
304 static void __tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
305 {
306         SETTING_TRACE_BEGIN;
307         SETTING_TRACE("result:%d", result);
308 }
309 int setting_reset_flight_mode()
310 {
311         int ret = -1;
312         TapiHandle *handle = tel_init(NULL);
313         if (!handle) {
314                 SETTING_TRACE_ERROR("tel_init error");
315         }
316
317         //if callback is NULL,it will return failed directly.
318         if (tel_set_flight_mode(handle, TAPI_POWER_FLIGHT_MODE_LEAVE, __tapi_flight_mode_cb, NULL) == 0) {
319 #if SUPPORT_RUN_SYSTEM_COMMAND
320                 ret = excuteCmd(SETTING_POSTINST_FILE, 1, "flightmode");
321 #else
322                 ret = vconf_set_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, FALSE);
323 #endif
324         } else {
325                 SETTING_TRACE_ERROR("tel_set_flight_mode error");
326         }
327
328
329         if (tel_deinit(handle) != 0) {
330                 SETTING_TRACE_ERROR("tel_deinit error");
331         }
332         return ret;
333 }
334
335 int setting_reset_rotation_lock(void)
336 {
337 #if SUPPORT_RUN_SYSTEM_COMMAND
338         return excuteCmd(SETTING_POSTINST_FILE, 1, "rotationLock");
339 #else
340         return vconf_set_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, TRUE);
341 #endif
342 }
343