change deprecated API to new
[apps/core/preloaded/settings.git] / setting-fileview / src / setting-fileview-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 #include <setting-fileview-main.h>
22
23 #define SETTING_FILEVIEW_LEN 20
24
25 static int setting_fileview_create(void *cb);
26 static int setting_fileview_destroy(void *cb);
27 static int setting_fileview_update(void *cb);
28 static int setting_fileview_cleanup(void *cb);
29
30 setting_view setting_view_fileview_main = {
31         .create = setting_fileview_create,
32         .destroy = setting_fileview_destroy,
33         .update = setting_fileview_update,
34         .cleanup = setting_fileview_cleanup,
35 };
36
37 /* ***************************************************
38  *
39  *basic func
40  *
41  ***************************************************/
42 #if DISABLED_CODE
43 static Eina_Bool __web_on_idle(void *data)
44 {
45         SETTING_TRACE_BEGIN;
46         SettingFileviewUG *ad = (SettingFileviewUG *) data;
47         if (ad->progress_bar) {
48                 evas_object_del(ad->progress_bar);
49                 ad->progress_bar = NULL;
50         }
51         return FALSE;
52 }
53 #endif
54 static void __setting_fileview_policy_navigation_decide(void *data, Evas_Object *webview, void *event_info)
55 {
56         SETTING_TRACE_BEGIN;
57         setting_retm_if(data == NULL, "data is NULL");
58         setting_retm_if(event_info == NULL, "event_info is NULL");
59
60         //SettingFileviewUG *ad = (SettingFileviewUG *)data;
61
62         // open url in local window
63         Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
64
65         char *url = (char *)ewk_policy_decision_url_get(policy_decision);
66         char *scheme = (char *)ewk_policy_decision_scheme_get(policy_decision);
67         SETTING_TRACE("url : %s", url);
68         SETTING_TRACE("scheme : %s", scheme);
69
70         /* if not launch broswer, do not call ewk_policy_decision_ignore */
71         //ewk_policy_decision_ignore(policy_decision);
72 }
73
74 static int setting_fileview_create(void *cb)
75 {
76         SETTING_TRACE_BEGIN;
77         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
78
79         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
80
81         Evas_Object *scroller;
82         //ad->progress_bar = setting_create_popup_with_progressbar(ad, ad->win_get, "pending_list", NULL, NULL, NULL, 0, TRUE, TRUE);
83
84         ad->ly_main = setting_create_layout_navi_bar_scroller(ad->win_main_layout,
85                                         ad->win_get,
86                                         _(ad->input_title),//_("IDS_ST_BODY_OPEN_SOURCE_LICENCES"),
87                                         _("IDS_COM_BODY_BACK"),
88                                         NULL,
89                                         setting_fileview_click_back_cb,
90                                         NULL, ad, &scroller,
91                                         &(ad->navi_bar));
92
93         Evas *evas = evas_object_evas_get(ad->win_get);
94         Evas_Object *webview = ewk_view_add(evas);
95         ad->webkit = webview;
96
97         SETTING_TRACE("ad->input_file:%s", ad->input_file);
98         ewk_view_url_set(webview, ad->input_file);
99
100         elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE);
101
102         elm_object_content_set(scroller, webview);
103         evas_object_show(webview);
104         //ecore_idler_add(__web_on_idle, ad);
105
106         evas_object_smart_callback_add(webview, "policy,navigation,decide", __setting_fileview_policy_navigation_decide, ad);
107
108         service_h svc;
109         if (service_create(&svc)) {
110                 return SETTING_RETURN_FAIL;
111         }
112
113         setting_view_fileview_main.is_create = 1;
114
115         return SETTING_RETURN_SUCCESS;
116 }
117
118 static int setting_fileview_destroy(void *cb)
119 {
120         /* error check */
121         SETTING_TRACE_BEGIN;
122         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
123         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
124         evas_object_smart_callback_del(ad->webkit, "policy,navigation,decide", __setting_fileview_policy_navigation_decide);
125
126         if (ad->webkit) {
127                 evas_object_del(ad->webkit);
128                 ad->webkit = NULL;
129         }
130
131         if (ad->progress_bar) {
132                 evas_object_del(ad->progress_bar);
133                 ad->progress_bar = NULL;
134         }
135
136         if (ad->ly_main != NULL) {
137                 evas_object_del(ad->ly_main);
138                 ad->ly_main = NULL;
139                 setting_view_fileview_main.is_create = 0;
140         }
141
142         return SETTING_RETURN_SUCCESS;
143 }
144
145 static int setting_fileview_update(void *cb)
146 {
147         SETTING_TRACE_BEGIN;
148         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
149
150         if (ad->ly_main != NULL) {
151                 evas_object_show(ad->ly_main);
152         }
153         return SETTING_RETURN_SUCCESS;
154
155 }
156
157 static int setting_fileview_cleanup(void *cb)
158 {
159         SETTING_TRACE_BEGIN;
160         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
161
162         if (ad->ly_main != NULL) {
163                 evas_object_hide(ad->ly_main);
164         }
165         return SETTING_RETURN_SUCCESS;
166 }
167
168 /* ***************************************************
169  *
170  *call back func
171  *
172  ***************************************************/
173
174 static void
175 setting_fileview_click_back_cb(void *data, Evas_Object *obj,
176                                             void *event_info)
177 {
178         /* error check */
179         setting_retm_if(data == NULL, " Data parameter is NULL");
180
181         SettingFileviewUG *ad = (SettingFileviewUG *) data;
182         /* Send destroy request */
183         ug_destroy_me(ad->ug);
184         return;
185 }