Merge "put a note of the Flora license description"
[apps/core/preloaded/settings.git] / setting-storage / src / setting-storage.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <setting-storage.h>
18 #ifndef UG_MODULE_API
19 #define UG_MODULE_API __attribute__ ((visibility("default")))
20 #endif
21
22 static void setting_storage_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
23                                       void *event_info)
24 {
25         SettingStorageUG *ad = (SettingStorageUG *) data;
26         setting_view_update(&setting_view_storage_main, ad);
27 }
28
29 static void *setting_storage_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
30                                        service_h service, void *priv)
31 {
32         setting_retvm_if((!ug || !priv), NULL, "!ug || !priv");
33
34         int ret = media_content_connect();
35         if(ret == MEDIA_CONTENT_ERROR_NONE) {
36                 SETTING_TRACE("media_content_connect is success");
37         } else {
38                 SETTING_TRACE_ERROR("media_content_connect is failed");
39                 return NULL;
40         }
41
42         SettingStorageUG *storageUG = priv;
43         storageUG->ug = ug;
44         storageUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
45         storageUG->win_get = (Evas_Object *) ug_get_window();
46         evas_object_show(storageUG->win_main_layout);
47         storageUG->evas = evas_object_evas_get(storageUG->win_main_layout);
48
49         setting_retvm_if(storageUG->win_main_layout == NULL, NULL, "cannot get main window ");
50
51         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
52
53         /* register view node table */
54         setting_view_node_table_intialize();
55         setting_view_node_table_register(&setting_view_storage_main, NULL);
56         setting_view_node_table_register(&setting_view_storage_default_storage,
57                                          &setting_view_storage_main);
58         setting_view_node_table_register(&setting_view_storage_miscellaneous_files,
59                                          &setting_view_storage_main);
60
61         storageUG->itc_seperator.item_style = "dialogue/separator";
62         storageUG->itc_seperator.func.text_get = NULL;
63         storageUG->itc_seperator.func.content_get = NULL;
64         storageUG->itc_seperator.func.state_get = NULL;
65         storageUG->itc_seperator.func.del = NULL;
66
67         setting_create_Gendial_itc("dialogue/2text.3/expandable", &(storageUG->itc_2text_3_parent));
68         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2", &(storageUG->itc_1icon_1text_sub));
69         setting_create_Gendial_itc("dialogue/2text.3", &(storageUG->itc_2text_2));
70         setting_create_Gendial_itc("dialogue/1text.1icon.2", &(storageUG->itc_1text_1icon_2));
71         setting_create_Gendial_itc("dialogue/title", &(storageUG->itc_group_item));
72         setting_create_Gendial_itc("multiline/1text", &(storageUG->itc_bg_1icon));
73         setting_create_Gendial_itc("dialogue/2text.1icon.3", &(storageUG->itc_2text_1icon_3));
74         setting_create_Gendial_itc("dialogue/1text", &(storageUG->itc_1text));
75         setting_create_Gendial_itc("1text.1icon.3", &(storageUG->itc_1text_1icon));
76
77         /*  creating a view. */
78         setting_view_node_set_cur_view(&setting_view_storage_main);
79         setting_view_create(&setting_view_storage_main, (void *)storageUG);
80         evas_object_event_callback_add(storageUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_storage_ug_cb_resize, storageUG);
81         return storageUG->ly_main;
82 }
83
84 static void setting_storage_ug_on_start(ui_gadget_h ug, service_h service,
85                                      void *priv)
86 {
87 }
88
89 static void setting_storage_ug_on_pause(ui_gadget_h ug, service_h service,
90                                      void *priv)
91 {
92 }
93
94 static void setting_storage_ug_on_resume(ui_gadget_h ug, service_h service,
95                                       void *priv)
96 {
97         SETTING_TRACE_BEGIN;
98         setting_retm_if((!ug || !priv), "!ug || !priv");
99         SettingStorageUG *storageUG = priv;
100
101         setting_view_update(&setting_view_storage_main, storageUG);
102 }
103
104 static void setting_storage_ug_on_destroy(ui_gadget_h ug, service_h service,
105                                        void *priv)
106 {
107         SETTING_TRACE_BEGIN;
108         setting_retm_if((!ug || !priv), "!ug || !priv");
109         SettingStorageUG *storageUG = priv;
110
111         int ret = media_content_disconnect();
112         if (ret == MEDIA_CONTENT_ERROR_NONE) {
113                 SETTING_TRACE("media_content_disconnect is success");
114         } else {
115                 SETTING_TRACE_ERROR("media_content_disconnect is failed");
116         }
117
118         evas_object_event_callback_del(storageUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_storage_ug_cb_resize); /* fix flash issue for gallery */
119         storageUG->ug = ug;
120
121         /*  delete the allocated objects. */
122         setting_view_destroy(&setting_view_storage_miscellaneous_files, storageUG);
123         setting_view_destroy(&setting_view_storage_default_storage, storageUG);
124         setting_view_destroy(&setting_view_storage_main, storageUG);
125
126         if (NULL != ug_get_layout(storageUG->ug)) {
127                 evas_object_hide((Evas_Object *) ug_get_layout(storageUG->ug));
128                 evas_object_del((Evas_Object *) ug_get_layout(storageUG->ug));
129         }
130
131         SETTING_TRACE_END;
132 }
133
134 static void setting_storage_ug_on_message(ui_gadget_h ug, service_h msg,
135                                        service_h service, void *priv)
136 {
137         SETTING_TRACE_BEGIN;
138 }
139
140 static void setting_storage_ug_on_event(ui_gadget_h ug, enum ug_event event,
141                                      service_h service, void *priv)
142 {
143         SETTING_TRACE_BEGIN;
144         setting_retm_if(priv == NULL, "priv is NULL");
145         SettingStorageUG *ad = (SettingStorageUG *)priv;
146
147         switch (event) {
148         case UG_EVENT_LOW_MEMORY:
149                 break;
150         case UG_EVENT_LOW_BATTERY:
151                 break;
152         case UG_EVENT_LANG_CHANGE:
153                 break;
154         case UG_EVENT_ROTATE_PORTRAIT:
155         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
156                 {
157                         SETTING_TRACE("UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN");
158                         if (ad->internal) {
159                                 if (ad->internal->eo_check) {
160                                         evas_object_del(ad->internal->eo_check);
161                                         ad->internal->eo_check = NULL;
162                                 }
163                                 elm_object_item_data_set(ad->internal->item, ad->internal);
164                                 elm_genlist_item_update(ad->internal->item);
165                         }
166                 }
167                 break;
168         case UG_EVENT_ROTATE_LANDSCAPE:
169         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
170                 {
171                         SETTING_TRACE("UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN");
172                         if (ad->internal) {
173                                 if (ad->internal->eo_check) {
174                                         evas_object_del(ad->internal->eo_check);
175                                         ad->internal->eo_check = NULL;
176                                 }
177                                 elm_object_item_data_set(ad->internal->item, ad->internal);
178                                 elm_genlist_item_update(ad->internal->item);
179                         }
180                 }
181                 break;
182         case UG_EVENT_REGION_CHANGE:
183                 break;
184         default:
185                 break;
186         }
187 }
188
189 static void setting_storage_ug_on_key_event(ui_gadget_h ug,
190                                          enum ug_key_event event, service_h service,
191                                          void *priv)
192 {
193         SETTING_TRACE_BEGIN;
194         if (!ug)
195                 return;
196
197         switch (event) {
198         case UG_KEY_EVENT_END:
199                 ug_destroy_me(ug);
200                 break;
201         default:
202                 break;
203         }
204 }
205
206 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
207 {
208         SETTING_TRACE_BEGIN;
209         SettingStorageUG *storageUG = calloc(1, sizeof(SettingStorageUG));
210         setting_retvm_if(!storageUG, -1, "Create SettingStorageUG obj failed");
211
212         ops->create = setting_storage_ug_on_create;
213         ops->start = setting_storage_ug_on_start;
214         ops->pause = setting_storage_ug_on_pause;
215         ops->resume = setting_storage_ug_on_resume;
216         ops->destroy = setting_storage_ug_on_destroy;
217         ops->message = setting_storage_ug_on_message;
218         ops->event = setting_storage_ug_on_event;
219         ops->key_event = setting_storage_ug_on_key_event;
220         ops->priv = storageUG;
221         ops->opt = UG_OPT_INDICATOR_ENABLE;
222
223         return 0;
224 }
225
226 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
227 {
228         SETTING_TRACE_BEGIN;
229         struct SettingStorageUG *storageUG;
230         setting_retm_if(!ops, "ops == NULL");
231
232         storageUG = ops->priv;
233         if (storageUG) {
234                 FREE(storageUG);
235         }
236 }
237
238 /* ***************************************************
239  *
240  *general func
241  *
242  ***************************************************/
243
244 /**
245 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
246 */
247 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
248 {
249         SETTING_TRACE_BEGIN;
250         int ret = 0;
251         int value = SETTING_DEF_MEMORY_PHONE;
252         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, value);
253         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, value);
254         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, value);
255
256         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_VOICE_RECORDER_INT, value);
257         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_FM_RADIO_INT, value);
258         ret += vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_DVB_H_INT, value);
259         return ret;
260 }