tizen 2.4 release
[apps/home/settings.git] / setting-phone / src / setting-phone-license-main.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 #include <setting-phone-license-main.h>
23 #define TEXT_CLEAR_LICENSE   "IDS_ST_BODY_REMOVE_LICENCE"
24
25 static int setting_phone_license_main_create(void *cb);
26 static int setting_phone_license_main_destroy(void *cb);
27 static int setting_phone_license_main_update(void *cb);
28 static int setting_phone_license_main_cleanup(void *cb);
29
30 setting_view setting_view_phone_license_main = {
31         .create = setting_phone_license_main_create,
32         .destroy = setting_phone_license_main_destroy,
33         .update = setting_phone_license_main_update,
34         .cleanup = setting_phone_license_main_cleanup,
35 };
36
37 /* ***************************************************
38  *
39  *basic func
40  *
41  ***************************************************/
42 static int setting_phone_license_main_create(void *cb)
43 {
44         SETTING_TRACE_BEGIN;
45         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
46
47         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
48
49         Evas_Object *scroller;
50
51         /* add basic layout */
52         char setBtnStr[MAX_DISPLAY_NAME_LEN_ON_UI];
53         snprintf(setBtnStr, sizeof(setBtnStr), "%s",
54                  (char *)dgettext("sys_string", "IDS_ST_BUTTON_BACK"));
55         /* scroller is a genlist */
56         ad->ly_license = setting_create_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get, "IDS_ST_MBODY_LEGAL_INFORMATION_ABB", setBtnStr, NULL,        /* dgettext("sys_string", "IDS_ST_SK_SET_LITE"), */
57                                                                 setting_phone_license_main_click_softkey_cancel, NULL,  /* setting_phone_license_main_click_softkey_set, */
58                                                                 ad, &scroller,
59                                                                 &
60                                                                 (ad->navi_bar));
61         Elm_Object_Item *item = NULL;
62         Setting_GenGroupItem_Data *itme_data = NULL;
63
64
65         /*int value; */
66         /*int err; */
67         item =
68             elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
69                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
70         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
71
72         /* Clear license */
73         item =
74             elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
75                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
76         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
77
78         /* [UI] open source license */
79         itme_data = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
80                                                      setting_phone_license_main_mouse_up_Gendial_list_cb,
81                                                      ad, SWALLOW_Type_INVALID, NULL, NULL,
82                                                      0, "IDS_ST_BODY_OPEN_SOURCE_LICENCES",
83                                                      NULL, NULL);
84
85         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
86
87         setting_view_phone_license_main.is_create = 1;
88
89         return SETTING_RETURN_SUCCESS;
90 }
91
92 static int setting_phone_license_main_destroy(void *cb)
93 {
94         SETTING_TRACE_BEGIN;
95         /* error check */
96         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
97
98         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
99
100         if (ad->ly_license != NULL) {
101                 SETTING_TRACE("ad->ly_license:%p", ad->ly_license);
102                 /* SETTING_TRACE("ad->roaming_nw_dialData:%p", ad->roaming_nw_dialData); */
103                 if (ad->popup_clear_license) {
104                         evas_object_del(ad->popup_clear_license);
105                         ad->popup_clear_license = NULL;
106                 }
107
108                 evas_object_del(ad->ly_license);
109                 /* if(ad->roaming_nw_dialData) FREE(ad->roaming_nw_dialData); */
110                 setting_view_phone_license_main.is_create = 0;
111         }
112         return SETTING_RETURN_SUCCESS;
113 }
114
115 static int setting_phone_license_main_update(void *cb)
116 {
117         /* error check */
118         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
119
120         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
121
122         if (ad->ly_license != NULL) {
123                 evas_object_show(ad->ly_license);
124                 /* setting_check_onoff_status(ad->chk_expiry, BOOL_SLP_SETTING_EXPIRY_REMINDER); */
125
126                 /* setting_update_chk_status(ad->chk_roaming_nw, INT_SLP_SETTING_ROAMING_NETWORK); */
127                 /* edje_object_part_text_set(_EDJ(ad->li_roaming_nw), "bottom.text", get_pa_roaming_network_str()); */
128         }
129
130         return SETTING_RETURN_SUCCESS;
131 }
132
133 static int setting_phone_license_main_cleanup(void *cb)
134 {
135         /* error check */
136         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
137
138         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
139
140         if (ad->ly_license != NULL) {
141                 /*  evas_object_hide(ad->ly_license); */
142         }
143
144         return SETTING_RETURN_SUCCESS;
145 }
146
147 static void __ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
148 {
149
150         Evas_Object *base;
151
152         if (!priv) {
153                 return;
154         }
155         SETTING_TRACE_BEGIN;
156
157         base = (Evas_Object *) ug_get_layout(ug);
158         if (!base) {
159                 return;
160         }
161
162         switch (mode) {
163                 case UG_MODE_FULLVIEW:
164                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
165                                                          EVAS_HINT_EXPAND);
166                         /*elm_win_resize_object_add(ad->win_get, base); */
167                         evas_object_show(base);
168                         break;
169                 default:
170                         break;
171         }
172
173         SETTING_TRACE_END;
174 }
175
176 static void __ug_destroy_cb(ui_gadget_h ug, void *priv)
177 {
178         SETTING_TRACE_BEGIN;
179
180         /* restore the '<-' button on the navigate bar */
181         ret_if(!priv);
182         SettingPhoneUG *ad = (SettingPhoneUG *) priv;   /* ad is point to priv */
183
184         if (ug) {
185                 setting_ug_destroy(ug);
186                 ad->ug_loading = NULL;
187         }
188
189 }
190
191 static void __ug_result_cb(ui_gadget_h ug, app_control_h result, void *priv)
192 {
193         SETTING_TRACE_BEGIN;
194         /* error check */
195         retm_if(priv == NULL, "Data parameter is NULL");
196
197         SettingPhoneUG *ad = (SettingPhoneUG *) priv;
198
199         if (result) {
200                 char *webkit_address = NULL;
201                 app_control_get_extra_data(result, "webkit_address", &webkit_address);
202                 SETTING_TRACE("webkit_address = %s", webkit_address);
203
204                 app_control_h svc;
205                 if (app_control_create(&svc)) {
206                         FREE(webkit_address);
207                         return;
208                 }
209
210                 app_control_add_extra_data(svc, "webkit_address", webkit_address);
211
212                 ug_send_result(ad->ug, svc);
213                 app_control_destroy(svc);
214                 FREE(webkit_address);
215         }
216 }
217
218 static void __main_license_clicked(void *data)
219 {
220         SETTING_TRACE_BEGIN;
221         retm_if(data == NULL, "Data parameter is NULL");
222         SettingPhoneUG *ad = (SettingPhoneUG *)data;
223         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
224         setting_retm_if(cbs == NULL, "calloc failed");
225         cbs->layout_cb = __ug_layout_cb;
226         cbs->result_cb = __ug_result_cb;
227         cbs->destroy_cb = __ug_destroy_cb;
228         cbs->priv = (void *)ad;
229
230         /*bundle *b = bundle_create(); */
231         app_control_h svc;
232         if (app_control_create(&svc)) {
233                 FREE(cbs);
234                 return;
235         }
236         app_control_add_extra_data(svc, "file", SETTING_OPEN_SOURCE_LICENSE_PATH);
237         app_control_add_extra_data(svc, "title", "IDS_ST_BODY_OPEN_SOURCE_LICENCES");
238
239         if (ad->ly_language) {
240                 elm_object_tree_focus_allow_set(ad->ly_language, EINA_FALSE);
241         }
242
243         ad->ug_loading = setting_ug_create(ad->ug, "setting-fileview-efl", UG_MODE_FULLVIEW, svc, cbs);
244         if (NULL == ad->ug_loading) {   /* error handling */
245                 setting_create_popup(ad, ad->win_get, NULL, _(UNSUPPORTED_FUNCTION), NULL, 0, false, false, 0);
246         }
247
248         app_control_destroy(svc);
249         FREE(cbs);
250 }
251
252 void
253 setting_phone_license_main_mouse_up_Gendial_list_cb(void *data,
254                                                     Evas_Object *obj,
255                                                     void *event_info)
256 {
257         /* error check */
258         setting_retm_if(data == NULL, "Data parameter is NULL");
259
260         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
261         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
262         elm_genlist_item_selected_set(item, 0);
263         Setting_GenGroupItem_Data *list_item =
264             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
265         setting_retm_if(NULL == list_item, "list_item is NULL");
266
267         /*SettingPhoneUG *ad = (SettingPhoneUG *) data; */
268
269         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
270
271         if (!safeStrCmp("IDS_ST_BODY_OPEN_SOURCE_LICENCES", list_item->keyStr)) {
272                 __main_license_clicked(data);
273         }
274 }
275
276 void setting_phone_license_main_popup_resp_cb(void *data, Evas_Object *obj,
277                                               void *event_info)
278 {
279         int response_type = btn_type(obj);
280         if (POPUP_RESPONSE_OK == response_type) {
281         }
282
283         setting_retm_if(data == NULL, "Data parameter is NULL");
284         SettingPhoneUG *ad = (SettingPhoneUG *) data;
285         if (ad->popup) {
286                 evas_object_del(ad->popup);
287                 ad->popup = NULL;
288         }
289
290 }
291
292 void
293 setting_phone_license_main_click_softkey_cancel(void *data, Evas_Object *obj,
294                                                 void *event_info)
295 {
296         /* error check */
297         retm_if(data == NULL, "Data parameter is NULL");
298
299         SettingPhoneUG *ad = (SettingPhoneUG *) data;
300
301         /* modify by kairong78.yin */
302         /* Send destroy request */
303         ug_destroy_me(ad->ug);
304 }