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