tizen 2.4 release
[apps/home/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
43 static void __setting_fileview_policy_navigation_decide(void *data, Evas_Object *webview, void *event_info)
44 {
45         SETTING_TRACE_BEGIN;
46         setting_retm_if(data == NULL, "data is NULL");
47         setting_retm_if(event_info == NULL, "event_info is NULL");
48
49         /*SettingFileviewUG *ad = (SettingFileviewUG *)data; */
50
51         /* open url in local window */
52         Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
53
54         char *url = (char *)ewk_policy_decision_url_get(policy_decision);
55         char *scheme = (char *)ewk_policy_decision_scheme_get(policy_decision);
56         SETTING_TRACE("url : %s", url);
57         SETTING_TRACE("scheme : %s", scheme);
58
59         /* if not launch broswer, do not call ewk_policy_decision_ignore */
60         /*ewk_policy_decision_ignore(policy_decision); */
61 }
62
63 static int setting_fileview_create(void *cb)
64 {
65         SETTING_TRACE_BEGIN;
66         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
67
68         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
69
70         Evas_Object *scroller = NULL;
71
72         ad->ly_main = setting_create_layout_navi_bar_scroller(ad->win_main_layout,
73                                                               ad->win_get,
74                                                               _(ad->input_title),/*_("IDS_ST_BODY_OPEN_SOURCE_LICENCES"), */
75                                                               _("IDS_ST_BUTTON_BACK"),
76                                                               NULL,
77                                                               setting_fileview_click_back_cb,
78                                                               NULL, ad, &scroller,
79                                                               &(ad->navi_bar));
80
81
82
83         Evas *evas = evas_object_evas_get(ad->win_get);
84         Evas_Object *webview = ewk_view_add(evas);
85
86         ad->webkit = webview;
87
88         SETTING_TRACE("ad->input_file:%s", ad->input_file);
89         ewk_view_url_set(ad->webkit, ad->input_file);
90
91         elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE);
92         elm_object_content_set(scroller, ad->webkit);
93
94         elm_access_object_register(ad->webkit, ad->win_get);
95         evas_object_show(ad->webkit);
96         ad->scroller = scroller;
97
98         evas_object_smart_callback_add(ad->webkit, "policy,navigation,decide", __setting_fileview_policy_navigation_decide, ad);
99
100         app_control_h svc;
101         if (app_control_create(&svc)) {
102                 return SETTING_RETURN_FAIL;
103         }
104
105         setting_view_fileview_main.is_create = 1;
106         app_control_destroy(svc);
107
108         return SETTING_RETURN_SUCCESS;
109 }
110
111 static int setting_fileview_destroy(void *cb)
112 {
113         /* error check */
114         SETTING_TRACE_BEGIN;
115         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
116         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
117         evas_object_smart_callback_del(ad->webkit, "policy,navigation,decide", __setting_fileview_policy_navigation_decide);
118
119         if (ad->webkit) {
120
121                 elm_object_content_unset(ad->webkit);
122                 evas_object_del(ad->webkit);
123                 ad->webkit = NULL;
124         }
125
126         if (ad->scroller) {
127                 evas_object_del(ad->scroller);
128                 ad->scroller = NULL;
129         }
130
131         if (ad->ly_main != NULL) {
132                 evas_object_del(ad->ly_main);
133                 ad->ly_main = NULL;
134                 setting_view_fileview_main.is_create = 0;
135         }
136
137         return SETTING_RETURN_SUCCESS;
138 }
139
140 static int setting_fileview_update(void *cb)
141 {
142         SETTING_TRACE_BEGIN;
143         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
144
145         if (ad->ly_main != NULL) {
146                 evas_object_show(ad->ly_main);
147         }
148         return SETTING_RETURN_SUCCESS;
149
150 }
151
152 static int setting_fileview_cleanup(void *cb)
153 {
154         SETTING_TRACE_BEGIN;
155         SettingFileviewUG *ad = (SettingFileviewUG *) cb;
156
157         if (ad->ly_main != NULL) {
158                 evas_object_hide(ad->ly_main);
159         }
160         return SETTING_RETURN_SUCCESS;
161 }
162
163 /* ***************************************************
164  *
165  *call back func
166  *
167  ***************************************************/
168
169 static void
170 setting_fileview_click_back_cb(void *data, Evas_Object *obj,
171                                void *event_info)
172 {
173         /* error check */
174         setting_retm_if(data == NULL, " Data parameter is NULL");
175
176         SettingFileviewUG *ad = (SettingFileviewUG *) data;
177         /* Send destroy request */
178         ug_destroy_me(ad->ug);
179         return;
180 }