Merge "Fix prevent issues"
[apps/core/preloaded/settings.git] / setting-memory / src / setting-memory.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-memory
24  *UG creation code for setting-memory
25  */
26
27 #include <setting-memory.h>
28
29 #ifndef UG_MODULE_API
30 #define UG_MODULE_API __attribute__ ((visibility("default")))
31 #endif
32
33 static void setting_memory_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
34                                         void *event_info)
35 {
36         SettingMemoryUG *ad = (SettingMemoryUG *) data;
37         setting_view_update(&setting_view_memory_default_memory, ad);
38 }
39
40 static void *setting_memory_ug_on_create(ui_gadget_h ug,
41                                          enum ug_mode mode, service_h service,
42                                          void *priv)
43 {
44         SETTING_TRACE_BEGIN;
45         setting_retvm_if((!priv), NULL, "!priv");
46
47         SettingMemoryUG *memoryUG = priv;
48         memoryUG->ug = ug;
49
50         memoryUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
51         memoryUG->win_get = (Evas_Object *) ug_get_window();
52         evas_object_show(memoryUG->win_main_layout);
53         memoryUG->evas = evas_object_evas_get(memoryUG->win_main_layout);
54
55         setting_retvm_if(memoryUG->win_main_layout == NULL, NULL,
56                          "cannot get main window ");
57
58         /* register view node table */
59         setting_view_node_table_intialize();
60
61         setting_view_node_table_register(&setting_view_memory_default_memory, NULL);
62
63         setting_create_Gendial_itc("dialogue/1text.1icon.2",
64                                    &(memoryUG->itc_1text_1icon_2));
65         setting_create_Gendial_itc("dialogue/title",
66                                    &(memoryUG->itc_group_item));
67         setting_create_Gendial_itc("dialogue/1text", &(memoryUG->itc_1text));
68         setting_create_Gendial_itc("1text.1icon.2",
69                                    &(memoryUG->itc_1text_1icon));
70         setting_create_Gendial_itc("select_all", &(memoryUG->itc_sel_all));
71
72         setting_create_Gendial_itc("dialogue/2text.3/expandable",
73                                    &(memoryUG->itc_2text_3_parent));
74         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2",
75                                    &(memoryUG->itc_1icon_1text_sub));
76         setting_create_Gendial_itc("dialogue/2text.2",
77                                    &(memoryUG->itc_2text_2));
78
79         memoryUG->itc_seperator.item_style = "dialogue/separator";
80         memoryUG->itc_seperator.func.text_get = NULL;
81         memoryUG->itc_seperator.func.content_get = NULL;
82         memoryUG->itc_seperator.func.state_get = NULL;
83         memoryUG->itc_seperator.func.del = NULL;
84
85         SETTING_TRACE_DEBUG("[DBG] set current view");
86
87         /*  creating a view. */
88         setting_view_node_set_cur_view(&setting_view_memory_default_memory);
89         setting_view_create(&setting_view_memory_default_memory, (void *)memoryUG);
90         evas_object_event_callback_add(memoryUG->win_main_layout,
91                                        EVAS_CALLBACK_RESIZE,
92                                        setting_memory_ug_cb_resize, memoryUG);
93         return memoryUG->ly_main;
94 }
95
96 static void setting_memory_ug_on_start(ui_gadget_h ug, service_h service,
97                                        void *priv)
98 {
99 }
100
101 static void setting_memory_ug_on_pause(ui_gadget_h ug, service_h service,
102                                        void *priv)
103 {
104 }
105
106 static void setting_memory_ug_on_resume(ui_gadget_h ug, service_h service,
107                                         void *priv)
108 {
109         SETTING_TRACE_BEGIN;
110         setting_retm_if((!ug || !priv), "!ug || !priv");
111         //SettingMemoryUG *ad = priv;
112
113         // Need to update the mem. status view in resuming the view
114
115         SETTING_TRACE_END;
116 }
117
118 static void setting_memory_ug_on_destroy(ui_gadget_h ug, service_h service,
119                                          void *priv)
120 {
121         SETTING_TRACE_BEGIN;
122         setting_retm_if((!priv), "!priv");
123         SettingMemoryUG *memoryUG = priv;
124
125         evas_object_event_callback_del(memoryUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_memory_ug_cb_resize);   /* fix flash issue for gallery */
126         memoryUG->ug = ug;
127
128         /*  delete the allocated objects. */
129
130         if (TRUE == setting_view_memory_default_memory.is_create) {
131                 setting_view_destroy(&setting_view_memory_default_memory, memoryUG);
132         }
133
134         if (NULL != ug_get_layout(memoryUG->ug)) {
135                 evas_object_hide((Evas_Object *) ug_get_layout(memoryUG->ug));
136                 evas_object_del((Evas_Object *) ug_get_layout(memoryUG->ug));
137         }
138
139         SETTING_TRACE_END;
140 }
141
142 static void setting_memory_ug_on_message(ui_gadget_h ug, service_h msg,
143                                          service_h service, void *priv)
144 {
145         SETTING_TRACE_BEGIN;
146 }
147
148 static void setting_memory_ug_on_event(ui_gadget_h ug,
149                                        enum ug_event event, service_h service,
150                                        void *priv)
151 {
152         SETTING_TRACE_BEGIN;
153         switch (event) {
154         case UG_EVENT_LOW_MEMORY:
155                 break;
156         case UG_EVENT_LOW_BATTERY:
157                 break;
158         case UG_EVENT_LANG_CHANGE:
159                 break;
160         case UG_EVENT_ROTATE_PORTRAIT:
161                 break;
162         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
163                 break;
164         case UG_EVENT_ROTATE_LANDSCAPE:
165                 break;
166         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
167                 break;
168         case UG_EVENT_REGION_CHANGE:
169                 break;
170         default:
171                 break;
172         }
173 }
174
175 static void setting_memory_ug_on_key_event(ui_gadget_h ug,
176                                            enum ug_key_event event,
177                                            service_h service, void *priv)
178 {
179         SETTING_TRACE_BEGIN;
180         if (!ug)
181                 return;
182         SettingMemoryUG *ad = (SettingMemoryUG *) priv;
183
184         switch (event) {
185         case UG_KEY_EVENT_END:
186                 {
187                         if (ad->wait_timer) {
188                                 ecore_timer_del(ad->wait_timer);
189                                 ad->wait_timer = NULL;
190                         }
191
192                         if (ad->progress_bar_timer) {
193                                 ecore_timer_del(ad->progress_bar_timer);
194                                 ad->progress_bar_timer = NULL;
195                         }
196                         if (ad->popup_timer) {
197                                 ecore_timer_del(ad->popup_timer);
198                                 ad->popup_timer = NULL;
199                         }
200
201                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
202                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
203                                 ug_destroy_me(ug);
204                         } else {
205                                 /* elm_naviframe_item_pop(ad->navi_bar); */
206                                 setting_view_cb_at_endKey(ad);
207                         }
208                 }
209                 break;
210
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         SettingMemoryUG *memoryUG = calloc(1, sizeof(SettingMemoryUG));
220         setting_retvm_if(!memoryUG, -1, "Create SettingMemoryUG obj failed");
221
222         ops->create = setting_memory_ug_on_create;
223         ops->start = setting_memory_ug_on_start;
224         ops->pause = setting_memory_ug_on_pause;
225         ops->resume = setting_memory_ug_on_resume;
226         ops->destroy = setting_memory_ug_on_destroy;
227         ops->message = setting_memory_ug_on_message;
228         ops->event = setting_memory_ug_on_event;
229         ops->key_event = setting_memory_ug_on_key_event;
230         ops->priv = memoryUG;
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 SettingMemoryUG *memoryUG;
240         setting_retm_if(!ops, "ops == NULL");
241
242         memoryUG = ops->priv;
243         if (memoryUG)
244                 FREE(memoryUG);
245 }
246
247 /**
248 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
249 *
250 * @param[in] data
251 * @param[in] priv
252 */
253 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
254 {
255         SETTING_TRACE_BEGIN;
256         int ret = 0;
257 #if SUPPORT_RUN_SYSTEM_COMMAND
258         ret += excuteCmd(SETTING_POSTINST_FILE, 1, "memory");
259 #else
260         int value = SETTING_DEF_MEMORY_PHONE;
261         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, value);
262         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, value);
263         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, value);
264
265         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_VOICE_RECORDER_INT, value);
266         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_FM_RADIO_INT, value);
267         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_ALL_SHARE_INT, value);
268         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_ADOBE_AIR_INT, value);
269         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_DVB_H_INT, value);
270 #endif
271         return ret;
272 }
273
274