Merge "packaging: spec cleanup" into tizen
[apps/core/preloaded/settings.git] / setting-privacy / src / setting-privacy.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-privacy.h>
22
23 #ifndef UG_MODULE_API
24 #define UG_MODULE_API __attribute__ ((visibility("default")))
25 #endif
26
27 static void setting_privacy_ug_cb_resize(void *data, Evas *e,
28                                          Evas_Object *obj, void *event_info)
29 {
30         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
31         setting_view_update(&setting_view_privacy_service, ad);
32 }
33
34 setting_view *__get_privacy_view_to_load(void *data, service_h service)
35 {
36         SETTING_TRACE_BEGIN;
37         setting_retvm_if((!data), NULL, "data is NULL");
38         SettingPrivacyUG *privacyUG = (SettingPrivacyUG *)data;
39
40         setting_view_node_table_intialize();
41
42         // if argument is there, process it first
43 /*
44         char *output_url = NULL;
45         int ret = service_get_operation(service, &output_url);
46
47         if(ret == SERVICE_ERROR_NONE
48                 && 0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/privacy/service")
49                 || 0 == safeStrCmp(output_url, "http://samsung.com/appcontrol/operation/configure/privacy/service"))
50         {
51                 setting_view_node_table_register(&setting_view_privacy_service, NULL);
52                 return &setting_view_privacy_service;
53
54         } else {
55                 SETTING_TRACE("output url : [%s]", output_url);
56                 // default action
57                 //setting_view_node_table_register(&setting_view_privacy_service, setting_view_privacy_main);
58                 //setting_view_node_table_register(&setting_view_privacy_main, NULL);
59                 //return &setting_view_privacy_main;
60         }
61 */
62         // service OK, but there's no argument
63         char *category = NULL;
64         service_get_extra_data(service, "privacy_category", &category);
65
66         if(0 == safeStrCmp(category, "service"))
67         {
68                 setting_view_node_table_register(&setting_view_privacy_service, NULL);
69                 return &setting_view_privacy_service;
70
71         } else {
72                 SETTING_TRACE("category : [%s]", category);
73                 // default action
74                 //setting_view_node_table_register(&setting_view_privacy_service, setting_view_privacy_main);
75                 //setting_view_node_table_register(&setting_view_privacy_main, NULL);
76                 //return &setting_view_privacy_main;
77         }
78
79 }
80
81 static void *setting_privacy_ug_on_create(ui_gadget_h ug,
82                                           enum ug_mode mode, service_h service,
83                                           void *priv)
84 {
85         SETTING_TRACE_BEGIN;
86         setting_retvm_if((!priv), NULL, "!priv");
87         SettingPrivacyUG *privacyUG = priv;
88         privacyUG->ug = ug;
89         privacyUG->bundle_data = service;
90         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
91
92         /* register view node table */
93         //setting_view_node_table_intialize();
94         //setting_view_node_table_register(&setting_view_privacy_main, NULL);
95
96         privacyUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
97         privacyUG->win_get = (Evas_Object *) ug_get_window();
98
99         evas_object_show(privacyUG->win_main_layout);
100         privacyUG->evas = evas_object_evas_get(privacyUG->win_main_layout);
101
102         setting_retvm_if(privacyUG->win_main_layout == NULL, NULL,
103                          "cannot get main window ");
104
105         // create bg
106         privacyUG->bg = elm_bg_add(privacyUG->win_get);
107         elm_object_style_set(privacyUG->bg, "dialogue_field");
108         evas_object_size_hint_weight_set(privacyUG->bg, EVAS_HINT_EXPAND,
109                                          EVAS_HINT_EXPAND);
110
111         privacyUG->view_to_load = __get_privacy_view_to_load(privacyUG, service);
112         setting_retvm_if(NULL == privacyUG->view_to_load, NULL, "NULL == fontUG->view_to_load");
113
114         // creating a view.
115         setting_view_node_set_cur_view(privacyUG->view_to_load);
116         setting_view_create(privacyUG->view_to_load, (void *)privacyUG);
117         evas_object_event_callback_add(privacyUG->win_main_layout,
118                                        EVAS_CALLBACK_RESIZE,
119                                        setting_privacy_ug_cb_resize, privacyUG);
120
121         //----------------------------------------------------------------
122         // dialogue/2text.3
123         // add genlist
124         //----------------------------------------------------------------
125         setting_create_Gendial_itc("dialogue/2text.3", &(privacyUG->itc_2text_2));
126
127         return privacyUG->ly_main;
128 }
129
130 static void setting_privacy_ug_on_start(ui_gadget_h ug, service_h service,
131                                         void *priv)
132 {
133 }
134
135 static void setting_privacy_ug_on_pause(ui_gadget_h ug, service_h service,
136                                         void *priv)
137 {
138 }
139
140 static void setting_privacy_ug_on_resume(ui_gadget_h ug, service_h service,
141                                          void *priv)
142 {
143 }
144
145 static void setting_privacy_ug_on_destroy(ui_gadget_h ug, service_h service,
146                                           void *priv)
147 {
148         SETTING_TRACE_BEGIN;
149         setting_retm_if((!priv), "!priv");
150         SettingPrivacyUG *privacyUG = priv;
151         evas_object_event_callback_del(privacyUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_privacy_ug_cb_resize); //fix flash issue for gallery
152         privacyUG->ug = ug;
153         if (privacyUG->bg) {
154                 evas_object_del(privacyUG->bg);
155         }
156         privacyUG->bg = NULL;
157
158         // called when this shared gadget is terminated. similar with app_exit
159         setting_view_destroy(&setting_view_privacy_service, privacyUG);
160
161         if (NULL != ug_get_layout(privacyUG->ug)) {
162                 evas_object_hide((Evas_Object *) ug_get_layout(privacyUG->ug));
163                 evas_object_del((Evas_Object *) ug_get_layout(privacyUG->ug));
164         }
165 }
166
167 static void setting_privacy_ug_on_message(ui_gadget_h ug, service_h msg,
168                                           service_h service, void *priv)
169 {
170         SETTING_TRACE_BEGIN;
171 }
172
173 static void setting_privacy_ug_on_event(ui_gadget_h ug,
174                                         enum ug_event event, service_h service,
175                                         void *priv)
176 {
177         SETTING_TRACE_BEGIN;
178         switch (event) {
179         case UG_EVENT_LOW_MEMORY:
180                 break;
181         case UG_EVENT_LOW_BATTERY:
182                 break;
183         case UG_EVENT_LANG_CHANGE:
184                 break;
185         case UG_EVENT_ROTATE_PORTRAIT:
186                 break;
187         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
188                 break;
189         case UG_EVENT_ROTATE_LANDSCAPE:
190                 break;
191         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
192                 break;
193         case UG_EVENT_REGION_CHANGE:
194                 break;
195         default:
196                 break;
197         }
198 }
199
200 static void setting_privacy_ug_on_key_event(ui_gadget_h ug,
201                                             enum ug_key_event event,
202                                             service_h service, void *priv)
203 {
204         SETTING_TRACE_BEGIN;
205         SettingPrivacyUG *ad = (SettingPrivacyUG *) priv;
206
207         switch (event) {
208         case UG_KEY_EVENT_END:
209                 {
210                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
211                             elm_naviframe_bottom_item_get(ad->
212                                                                  navi_bar)) {
213                                 ug_destroy_me(ug);
214                         } else {
215
216                                 setting_view_cb_at_endKey(ad);
217                         }
218                 }
219                 break;
220         default:
221                 break;
222         }
223 }
224
225 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
226 {
227         SETTING_TRACE_BEGIN;
228         SettingPrivacyUG *privacyUG = calloc(1, sizeof(SettingPrivacyUG));
229         setting_retvm_if(!privacyUG, -1, "Create SettingPrivacyUG obj failed");
230
231         ops->create = setting_privacy_ug_on_create;
232         ops->start = setting_privacy_ug_on_start;
233         ops->pause = setting_privacy_ug_on_pause;
234         ops->resume = setting_privacy_ug_on_resume;
235         ops->destroy = setting_privacy_ug_on_destroy;
236         ops->message = setting_privacy_ug_on_message;
237         ops->event = setting_privacy_ug_on_event;
238         ops->key_event = setting_privacy_ug_on_key_event;
239         ops->priv = privacyUG;
240         ops->opt = UG_OPT_INDICATOR_ENABLE;
241         return 0;
242 }
243
244 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
245 {
246         SETTING_TRACE_BEGIN;
247         struct SettingPrivacyUG *privacyUG;
248         setting_retm_if(!ops, "ops == NULL");
249
250         privacyUG = ops->priv;
251         if (privacyUG) {
252                 FREE(privacyUG);
253         }
254 }
255
256 /* ***************************************************
257 **
258 ** general func
259 **
260 ** **************************************************/
261
262 /**
263 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
264 *
265 * @param[in] data
266 * @param[in] priv
267 */
268