tizen 2.3 release
[apps/home/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 <setting-cfg.h>
23 #include <ITapiModem.h>
24 #include <TapiUtility.h>
25 #include <tapi_common.h>
26 #include <setting-cfg.h>
27
28 #ifndef UG_MODULE_API
29 #define UG_MODULE_API __attribute__ ((visibility("default")))
30 #endif
31
32 static void setting_reset_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
33                                        void *event_info)
34 {
35         SettingResetUG *ad = (SettingResetUG *) data;
36         setting_view_update(&setting_view_reset_main, ad);
37 }
38
39 static void *setting_reset_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
40                                         app_control_h service, void *priv)
41 {
42         setting_retvm_if((!priv), NULL, "!priv");
43
44         SettingResetUG *resetUG = priv;
45         resetUG->ug = ug;
46
47         resetUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
48         resetUG->win_get = (Evas_Object *) ug_get_window();
49
50         evas_object_show(resetUG->win_main_layout);
51         resetUG->evas = evas_object_evas_get(resetUG->win_main_layout);
52
53         setting_retvm_if(resetUG->win_main_layout == NULL, NULL,
54                          "cannot get main window ");
55
56         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
57
58         setting_create_Gendial_itc("multiline_sub", &(resetUG->itc_1text));
59         setting_create_Gendial_itc("1icon", &(resetUG->itc_1icon));
60
61         /*  creating a view. */
62         setting_view_node_table_register(&setting_view_reset_main, NULL);
63         setting_view_node_table_register(&setting_view_reset_settings, &setting_view_reset_main);
64         setting_view_node_set_cur_view(&setting_view_reset_main);
65
66         setting_view_create(&setting_view_reset_main, (void *)resetUG);
67         evas_object_event_callback_add(resetUG->win_main_layout,
68                                        EVAS_CALLBACK_RESIZE,
69                                        setting_reset_ug_cb_resize, resetUG);
70         return resetUG->ly_main;
71 }
72
73 static void setting_reset_ug_on_start(ui_gadget_h ug, app_control_h service,
74                                       void *priv)
75 {
76 }
77
78 static void setting_reset_ug_on_pause(ui_gadget_h ug, app_control_h service,
79                                       void *priv)
80 {
81 }
82
83 static void setting_reset_ug_on_resume(ui_gadget_h ug, app_control_h service,
84                                        void *priv)
85 {
86 }
87
88 static void setting_reset_ug_on_destroy(ui_gadget_h ug, app_control_h service,
89                                         void *priv)
90 {
91         SETTING_TRACE_BEGIN;
92         setting_retm_if((!priv), "!priv");
93         SettingResetUG *resetUG = priv;
94
95         evas_object_event_callback_del(resetUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_reset_ug_cb_resize);     /* fix flash issue for gallery */
96         resetUG->ug = ug;
97         /*  delete the allocated objects. */
98         setting_view_destroy(&setting_view_reset_settings, resetUG);
99         setting_view_destroy(&setting_view_reset_main, resetUG);
100
101         if (NULL != ug_get_layout(resetUG->ug)) {
102                 evas_object_hide((Evas_Object *) ug_get_layout(resetUG->ug));
103                 evas_object_del((Evas_Object *) ug_get_layout(resetUG->ug));
104         }
105
106         SETTING_TRACE_END;
107 }
108
109 static void setting_reset_ug_on_message(ui_gadget_h ug, app_control_h msg,
110                                         app_control_h service, void *priv)
111 {
112         SETTING_TRACE_BEGIN;
113 }
114
115 static void setting_reset_ug_on_event(ui_gadget_h ug, enum ug_event event,
116                                       app_control_h service, void *priv)
117 {
118         SETTING_TRACE_BEGIN;
119         setting_retm_if(!priv, "!priv");
120         SettingResetUG *ad = (SettingResetUG *) priv;
121         switch (event) {
122         case UG_EVENT_LOW_MEMORY:
123                 break;
124         case UG_EVENT_LOW_BATTERY:
125                 break;
126         case UG_EVENT_LANG_CHANGE:
127         {
128                 /* navigation item in reset setting view */
129                 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
130                 ret_if(!navi_it);
131                 elm_object_item_text_set(navi_it, _(RESET_SETTINGS_STR));
132
133                 /* navigation item in reset main view */
134                 navi_it = elm_naviframe_bottom_item_get(ad->navi_bar);
135                 ret_if(!navi_it);
136                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_RESET"));
137
138                 if (ad->main_scroller)
139                 {
140                         elm_genlist_realized_items_update(ad->main_scroller);
141                 }
142                 SETTING_TRACE("ad->main_scroller:%p", ad->main_scroller);
143
144                 if (ad->controllbar)
145                 {
146                         Elm_Object_Item *item = NULL;
147                         item = elm_toolbar_first_item_get(ad->controllbar);
148                         if (item)
149                         {
150 #if SUPPORT_BOTTOM_BTNS
151                                 elm_object_item_text_set(item, _("IDS_COM_BODY_RESET"));
152 #else
153                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
154                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
155                                 elm_object_text_set(eo_btn, _("IDS_COM_SK_CANCEL"));
156 #endif
157                         }
158
159                         item = elm_toolbar_last_item_get(ad->controllbar);
160                         if (item)
161                         {
162 #if SUPPORT_BOTTOM_BTNS
163                                 elm_object_item_text_set(item, _("IDS_COM_SK_CANCEL"));
164 #else
165                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
166                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
167                                 elm_object_text_set(eo_btn, _("IDS_COM_BODY_RESET"));
168 #endif
169                         }
170                 }
171                 Evas_Object *sub_layout = elm_object_part_content_get(ad->view_layout, "elm.swallow.contents");
172                 if (sub_layout)
173                 {
174                         Evas_Object *select_all_layout = elm_object_part_content_get(sub_layout, "search_bar");
175                         if (select_all_layout) {
176                                 elm_object_part_text_set(select_all_layout, "elm.text", _(KeyStr_Select_All));
177                         }
178                 }
179
180                 if (ad->reset_list){
181                         elm_genlist_realized_items_update(ad->reset_list);
182                 }
183                 setting_reset_result_popup_update(ad);
184
185                 break;
186         }
187
188         case UG_EVENT_ROTATE_PORTRAIT:
189                 break;
190         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
191                 break;
192         case UG_EVENT_ROTATE_LANDSCAPE:
193                 break;
194         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
195                 break;
196         case UG_EVENT_REGION_CHANGE:
197                 break;
198         default:
199                 break;
200         }
201 }
202
203 static void setting_reset_ug_on_key_event(ui_gadget_h ug,
204                                           enum ug_key_event event,
205                                           app_control_h service, void *priv)
206 {
207         SETTING_TRACE_BEGIN;
208
209         switch (event) {
210         case UG_KEY_EVENT_END:
211                 ug_destroy_me(ug);
212                 break;
213         default:
214                 break;
215         }
216 }
217
218 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
219 {
220         SETTING_TRACE_BEGIN;
221         SettingResetUG *resetUG = calloc(1, sizeof(SettingResetUG));
222         setting_retvm_if(!resetUG, -1, "Create SettingResetUG obj failed");
223
224         ops->create = setting_reset_ug_on_create;
225         ops->start = setting_reset_ug_on_start;
226         ops->pause = setting_reset_ug_on_pause;
227         ops->resume = setting_reset_ug_on_resume;
228         ops->destroy = setting_reset_ug_on_destroy;
229         ops->message = setting_reset_ug_on_message;
230         ops->event = setting_reset_ug_on_event;
231         ops->key_event = setting_reset_ug_on_key_event;
232         ops->priv = resetUG;
233         ops->opt = UG_OPT_INDICATOR_ENABLE;
234
235         return 0;
236 }
237
238 /**
239  *@brief callback function for reset UG.the exit the reset mode, it will be called to destory the resource.
240 */
241 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
242 {
243         SETTING_TRACE_BEGIN;
244         struct SettingResetUG *resetUG;
245         setting_retm_if(!ops, "ops == NULL");
246
247         resetUG = ops->priv;
248         if (resetUG) {
249                 FREE(resetUG);
250         }
251 }
252
253 /* ***************************************************
254  *
255  *general func
256  *
257  ***************************************************/
258 /**
259  *@brief callback function for reset result.when you press the button in the popup, it will be called.
260 */
261 void setting_reset_result_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
262 {
263         SETTING_TRACE_BEGIN;
264         ret_if(!data);
265         SettingResetUG *ad = data;
266         if (btn_type(obj) == POPUP_RESPONSE_OK) {
267         }
268
269         if(ad->reset_process) {
270                 evas_object_del(ad->reset_process);
271                 ad->reset_process = NULL;
272         }
273         if (ad->notify) {
274                 evas_object_del(ad->notify);
275                 ad->notify = NULL;
276         }
277 #if 0
278         if (ad->old_notify) {
279                 evas_object_del(ad->old_notify);
280                 ad->old_notify = NULL;
281         }
282 #endif
283 }
284
285 void setting_reset_result_popup_update(void *data)
286 {
287         SETTING_TRACE_BEGIN;
288         ret_if(!data);
289         SettingResetUG *ad = data;
290         if (ad->notify) {
291                 elm_object_part_text_set(ad->notify, "title,text", _(RESET_SETTINGS_STR));
292                 Evas_Object *btn = elm_object_part_content_get(ad->notify, "button1");
293                 elm_object_style_set(btn, "popup");
294                 if (btn)
295                 {
296                         elm_object_text_set(btn, _("IDS_COM_SK_OK"));
297                 }
298                 /*
299                 Evas_Object *genlist = elm_object_content_get(ad->notify);
300                 if(genlist)
301                 {
302                         elm_genlist_realized_items_update(genlist);
303                         elm_object_content_set(ad->notify, genlist);
304                 }
305                 */
306                 //evas_object_show(ad->notify);
307         }
308 }
309
310 /**
311  *@brief callback function for reset flight mode.when reset the flight mode,it will be called.
312 */
313 static void __tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
314 {
315         SETTING_TRACE_BEGIN;
316         SETTING_TRACE("result:%d", result);
317 }
318
319 /**
320  *@brief reset function for reset flight mode.
321 */
322 int setting_reset_flight_mode()
323 {
324         int ret = -1;
325         TapiHandle *handle = tel_init(NULL);
326         if (!handle) {
327                 SETTING_TRACE_ERROR("tel_init error");
328         }
329
330         //if callback is NULL,it will return failed directly.
331         if (tel_set_flight_mode(handle, TAPI_POWER_FLIGHT_MODE_LEAVE, __tapi_flight_mode_cb, NULL) == 0) {
332 #if SUPPORT_RUN_SYSTEM_COMMAND
333                 ret = excuteCmd(SETTING_POSTINST_FILE, 1, "flightmode");
334 #else
335                 ret = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, FALSE);
336 #endif
337         }
338         else {
339                 SETTING_TRACE_ERROR("tel_set_flight_mode error");
340         }
341
342
343         if (tel_deinit(handle) != 0) {
344                 SETTING_TRACE_ERROR("tel_deinit error");
345         }
346         return ret;
347 }
348
349 /*
350  * @brief lock the screen,make it does not support rotation.
351  */
352 int setting_reset_rotation_lock(void)
353 {
354 #if SUPPORT_RUN_SYSTEM_COMMAND
355         return excuteCmd(SETTING_POSTINST_FILE, 1, "rotationLock");
356 #else
357         return vconf_set_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, TRUE);
358 #endif
359 }
360
361 static Setting_Cfg_Node_T reset_node_array[] = {
362         {"IDS_ST_MBODY_FACTORY_RESET", NULL, "search_key:IDS_ST_MBODY_FACTORY_RESET", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
363 };
364
365 /**
366  *@brief init function for setting module search,it will add the module name into the search database.
367 */
368 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char** applocale)
369 {
370         SETTING_TRACE_BEGIN;
371         SETTING_TRACE(">> setting-reset-efl DB search code");
372
373         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
374
375         Eina_List **pplist = (Eina_List**)priv;
376         int i;
377         int size = sizeof(reset_node_array)/sizeof(reset_node_array[0]);
378         for(i=0;i<size;i++) {
379                 Setting_Cfg_Node_T * node = setting_plugin_search_item_subindex_add(reset_node_array[i].key_name, reset_node_array[i].ug_args, IMG_Reset,reset_node_array[i].item_type,  reset_node_array[i].data, "Reset");
380                 *pplist = eina_list_append(*pplist, node);
381         }
382         return 0;
383 }
384