tizen 2.3.1 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                                 /* navigation item in reset setting view */
128                                 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
129                                 ret_if(!navi_it);
130                                 elm_object_item_text_set(navi_it, _(RESET_SETTINGS_STR));
131
132                                 /* navigation item in reset main view */
133                                 navi_it = elm_naviframe_bottom_item_get(ad->navi_bar);
134                                 ret_if(!navi_it);
135                                 elm_object_item_text_set(navi_it, _("IDS_COM_BODY_RESET"));
136
137                                 if (ad->main_scroller) {
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                                         Elm_Object_Item *item = NULL;
144                                         item = elm_toolbar_first_item_get(ad->controllbar);
145                                         if (item) {
146 #if SUPPORT_BOTTOM_BTNS
147                                                 elm_object_item_text_set(item, _("IDS_COM_BODY_RESET"));
148 #else
149                                                 Evas_Object *eo_btn = elm_object_item_part_content_get(item, "object");
150                                                 setting_retm_if(eo_btn == NULL, "get eo_lbtn failed");
151                                                 elm_object_text_set(eo_btn, _("IDS_COM_SK_CANCEL"));
152 #endif
153                                         }
154
155                                         item = elm_toolbar_last_item_get(ad->controllbar);
156                                         if (item) {
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                                         Evas_Object *select_all_layout = elm_object_part_content_get(sub_layout, "search_bar");
169                                         if (select_all_layout) {
170                                                 elm_object_part_text_set(select_all_layout, "elm.text", _(KeyStr_Select_All));
171                                         }
172                                 }
173
174                                 if (ad->reset_list) {
175                                         elm_genlist_realized_items_update(ad->reset_list);
176                                 }
177                                 setting_reset_result_popup_update(ad);
178
179                                 break;
180                         }
181
182                 case UG_EVENT_ROTATE_PORTRAIT:
183                         break;
184                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
185                         break;
186                 case UG_EVENT_ROTATE_LANDSCAPE:
187                         break;
188                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
189                         break;
190                 case UG_EVENT_REGION_CHANGE:
191                         break;
192                 default:
193                         break;
194         }
195 }
196
197 static void setting_reset_ug_on_key_event(ui_gadget_h ug,
198                                           enum ug_key_event event,
199                                           app_control_h service, void *priv)
200 {
201         SETTING_TRACE_BEGIN;
202
203         switch (event) {
204                 case UG_KEY_EVENT_END:
205                         ug_destroy_me(ug);
206                         break;
207                 default:
208                         break;
209         }
210 }
211
212 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
213 {
214         SETTING_TRACE_BEGIN;
215         SettingResetUG *resetUG = calloc(1, sizeof(SettingResetUG));
216         setting_retvm_if(!resetUG, -1, "Create SettingResetUG obj failed");
217
218         ops->create = setting_reset_ug_on_create;
219         ops->start = setting_reset_ug_on_start;
220         ops->pause = setting_reset_ug_on_pause;
221         ops->resume = setting_reset_ug_on_resume;
222         ops->destroy = setting_reset_ug_on_destroy;
223         ops->message = setting_reset_ug_on_message;
224         ops->event = setting_reset_ug_on_event;
225         ops->key_event = setting_reset_ug_on_key_event;
226         ops->priv = resetUG;
227         ops->opt = UG_OPT_INDICATOR_ENABLE;
228
229         return 0;
230 }
231
232 /**
233  *@brief callback function for reset UG.the exit the reset mode, it will be called to destory the resource.
234 */
235 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
236 {
237         SETTING_TRACE_BEGIN;
238         struct SettingResetUG *resetUG;
239         setting_retm_if(!ops, "ops == NULL");
240
241         resetUG = ops->priv;
242         if (resetUG) {
243                 FREE(resetUG);
244         }
245 }
246
247 /* ***************************************************
248  *
249  *general func
250  *
251  ***************************************************/
252 /**
253  *@brief callback function for reset result.when you press the button in the popup, it will be called.
254 */
255 void setting_reset_result_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
256 {
257         SETTING_TRACE_BEGIN;
258         ret_if(!data);
259         SettingResetUG *ad = data;
260         if (btn_type(obj) == POPUP_RESPONSE_OK) {
261         }
262
263         if (ad->reset_process) {
264                 evas_object_del(ad->reset_process);
265                 ad->reset_process = NULL;
266         }
267         if (ad->notify) {
268                 evas_object_del(ad->notify);
269                 ad->notify = NULL;
270         }
271 #if 0
272         if (ad->old_notify) {
273                 evas_object_del(ad->old_notify);
274                 ad->old_notify = NULL;
275         }
276 #endif
277 }
278
279 void setting_reset_result_popup_update(void *data)
280 {
281         SETTING_TRACE_BEGIN;
282         ret_if(!data);
283         SettingResetUG *ad = data;
284         if (ad->notify) {
285                 elm_object_part_text_set(ad->notify, "title,text", _(RESET_SETTINGS_STR));
286                 Evas_Object *btn = elm_object_part_content_get(ad->notify, "button1");
287                 elm_object_style_set(btn, "popup");
288                 if (btn) {
289                         elm_object_text_set(btn, _("IDS_COM_SK_OK"));
290                 }
291                 /*
292                 Evas_Object *genlist = elm_object_content_get(ad->notify);
293                 if(genlist)
294                 {
295                         elm_genlist_realized_items_update(genlist);
296                         elm_object_content_set(ad->notify, genlist);
297                 }
298                 */
299                 /*evas_object_show(ad->notify); */
300         }
301 }
302
303 /**
304  *@brief callback function for reset flight mode.when reset the flight mode,it will be called.
305 */
306 static void __tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
307 {
308         SETTING_TRACE_BEGIN;
309         SETTING_TRACE("result:%d", result);
310 }
311
312 /**
313  *@brief reset function for reset flight mode.
314 */
315 int setting_reset_flight_mode()
316 {
317         int ret = -1;
318         TapiHandle *handle = tel_init(NULL);
319         if (!handle) {
320                 SETTING_TRACE_ERROR("tel_init error");
321         }
322
323         /*if callback is NULL,it will return failed directly. */
324         if (tel_set_flight_mode(handle, TAPI_POWER_FLIGHT_MODE_LEAVE, __tapi_flight_mode_cb, NULL) == 0) {
325 #if SUPPORT_RUN_SYSTEM_COMMAND
326                 ret = excuteCmd(SETTING_POSTINST_FILE, 1, "flightmode");
327 #else
328                 ret = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, FALSE);
329 #endif
330         } else {
331                 SETTING_TRACE_ERROR("tel_set_flight_mode error");
332         }
333
334
335         if (tel_deinit(handle) != 0) {
336                 SETTING_TRACE_ERROR("tel_deinit error");
337         }
338         return ret;
339 }
340
341 /*
342  * @brief lock the screen,make it does not support rotation.
343  */
344 int setting_reset_rotation_lock(void)
345 {
346 #if SUPPORT_RUN_SYSTEM_COMMAND
347         return excuteCmd(SETTING_POSTINST_FILE, 1, "rotationLock");
348 #else
349         return vconf_set_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, TRUE);
350 #endif
351 }
352
353 static Setting_Cfg_Node_T reset_node_array[] = {
354         {"IDS_ST_MBODY_FACTORY_RESET", NULL, "search_key:IDS_ST_MBODY_FACTORY_RESET", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
355 };
356
357 /**
358  *@brief init function for setting module search,it will add the module name into the search database.
359 */
360 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char **applocale)
361 {
362         SETTING_TRACE_BEGIN;
363         SETTING_TRACE(">> setting-reset-efl DB search code");
364
365         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
366
367         Eina_List **pplist = (Eina_List **)priv;
368         int i;
369         int size = sizeof(reset_node_array) / sizeof(reset_node_array[0]);
370         for (i = 0; i < size; i++) {
371                 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");
372                 *pplist = eina_list_append(*pplist, node);
373         }
374         return 0;
375 }
376