0189711736799dfa8b04bc327cb2b712b6cabb0f
[platform/core/security/krate.git] / tools / apps / setup-wizard / src / ui.c
1 /*
2  * Tizen Zone Setup-Wizard application
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include "krate-setup.h"
20 #include "widget.h"
21
22 static void __create_welcome_view(appdata_s *ad);
23
24 uidata_s ud = {0, };
25
26 static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it)
27 {
28         app_control_h svc = (app_control_h) data;
29
30         _create_notification(svc);
31         ui_app_exit();
32
33         return EINA_FALSE;
34 }
35
36 static void __welcome_cancel_cb(void *data, Evas_Object *obj, void *event_info)
37 {
38         appdata_s *ad = (appdata_s *)data;
39
40         _create_notification(ad->app_control);
41         ui_app_exit();
42
43         return;
44 }
45
46 static void __welcome_next_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48         appdata_s *ad = (appdata_s *)data;
49
50         if (!strcmp(ad->mode, "create")) {
51                 _create_security_view(ad);
52         } else {
53                 if (_send_zone_remove_request(ad) != 0)
54                         ui_app_exit();
55                 _create_setup_view(ad);
56         }
57
58         return;
59 }
60
61 static Eina_Bool __home_key_cb(void *data, int type, void *event)
62 {
63         app_control_h app_control = (app_control_h) data;
64         Evas_Event_Key_Down *ev = event;
65
66         if (!strcmp(ev->keyname, "XF86Home")) {
67                 _create_notification(app_control);
68                 ui_app_exit();
69         }
70
71         return EINA_TRUE;
72 }
73
74 void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Evas_Object *right_button)
75 {
76         Evas_Object *layout;
77
78         layout = _create_layout(parent, ud.edj_path, "two_button_layout");
79
80         elm_object_part_content_set(layout, "prev_button", left_button);
81         elm_object_part_content_set(layout, "next_button", right_button);
82         elm_object_part_content_set(parent, "bottom_layout", layout);
83         return;
84 }
85
86 static Eina_Bool __progressbar_timer_cb(void *data)
87 {
88         appdata_s *ad = (appdata_s *)data;
89         if (ad->request_done) {
90                 ui_app_exit();
91                 return ECORE_CALLBACK_CANCEL;
92         }
93
94         return ECORE_CALLBACK_RENEW;
95 }
96
97 void _create_base_window(appdata_s *ad)
98 {
99         Evas_Object *win;
100         Evas_Object *layout;
101
102         char edj_path[PATH_MAX] = "\0";
103         char *res_path = NULL;
104
105         /* Initialize data */
106         ad->request_done = false;
107
108         /* Get EDJ path */
109         res_path = app_get_resource_path();
110         if (res_path == NULL) {
111                 dlog_print(DLOG_ERROR, LOG_TAG, "failed get resource path");
112                 ui_app_exit();
113         }
114         snprintf(edj_path, PATH_MAX, "%s%s", res_path, "org.tizen.krate-setup-wizard.edj");
115
116         ud.edj_path = strdup(edj_path);
117         free(res_path);
118
119         /* Create main UI widget */
120         win = _create_win(PACKAGE);
121         ud.conform = _create_conformant(win);
122         layout = _create_layout(ud.conform, NULL, NULL);
123         elm_object_content_set(ud.conform, layout);
124         ud.nf = elm_naviframe_add(layout);
125
126         ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __home_key_cb, ad->app_control);
127
128         __create_welcome_view(ad);
129
130         elm_object_part_content_set(layout, "elm.swallow.content", ud.nf);
131         eext_object_event_callback_add(ud.nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
132
133         evas_object_show(win);
134         return;
135 }
136
137 static void __create_welcome_view(appdata_s *ad)
138 {
139         Elm_Object_Item *nf_it;
140         Evas_Object *layout, *welcome_layout;
141         Evas_Object *title, *content;
142         Evas_Object *left_button, *right_button;
143
144         char *welcome_text[2][4] = {
145                 {WELCOME_MESSAGE_TITLE, WELCOME_MESSAGE_CONTENT, CANCEL_BUTTON, NEXT_BUTTON},
146                 {DELETE_MESSAGE_TITLE, DELETE_MESSAGE_CONTENT, CANCEL_BUTTON, REMOVE_BUTTON}
147         };
148         char **text = NULL;
149
150         if (!strcmp(ad->mode, "create"))
151                 text = welcome_text[0];
152         else
153                 text = welcome_text[1];
154
155         elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
156
157         layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
158         welcome_layout = _create_layout(layout, ud.edj_path, "welcome_layout");
159
160         title = _create_textblock(welcome_layout, text[0], SUB_TITLE_STYLE_B);
161         content = _create_textblock(welcome_layout, text[1], SUB_CONTENT_STYLE_B);
162
163         elm_object_part_content_set(welcome_layout, "message_title", title);
164         elm_object_part_content_set(welcome_layout, "message_content", content);
165
166         elm_object_part_content_set(layout, "content_layout", welcome_layout);
167
168         left_button = _create_button(layout, text[2], __welcome_cancel_cb, ad);
169         right_button = _create_button(layout, text[3], __welcome_next_cb, ad);
170
171         _create_two_button_layout(layout, left_button, right_button);
172
173         nf_it = elm_naviframe_item_push(ud.nf, NULL, NULL, NULL, layout, NULL);
174         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_TRUE);
175         elm_naviframe_item_pop_cb_set(nf_it, __naviframe_pop_cb, ad->app_control);
176
177         return;
178 }
179
180 void _create_setup_view(appdata_s *ad)
181 {
182         Elm_Object_Item *nf_it;
183         Evas_Object *setup_layout;
184         Evas_Object *progressbar;
185         Evas_Object *title, *content;
186
187         char *setup_text[2][2] = {
188                 {SETUP_MESSAGE_TITLE, SETUP_MESSAGE_CONTENT},
189                 {DELETE_ONGOING_TITLE, DELETE_ONGOING_CONTENT}
190         };
191         char **text = NULL;
192
193         if (!strcmp(ad->mode, "create"))
194                 text = setup_text[0];
195         else
196                 text = setup_text[1];
197
198         eext_object_event_callback_del(ud.nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb);
199
200         setup_layout = _create_layout(ud.nf, ud.edj_path, "setup_layout");
201
202         title = _create_textblock(setup_layout, text[0], SUB_TITLE_STYLE_W);
203         content = _create_textblock(setup_layout, text[1], SUB_CONTENT_STYLE_W);
204
205         elm_object_part_content_set(setup_layout, "progressbar_msg", title);
206
207         progressbar = _create_progressbar(setup_layout, "pending");
208         elm_object_part_content_set(setup_layout, "progressbar", progressbar);
209
210         elm_object_part_content_set(setup_layout, "content_text", content);
211
212         nf_it = elm_naviframe_item_push(ud.nf, NULL, NULL, NULL, setup_layout, NULL);
213         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_TRUE);
214
215         /* set progressbar timer callback */
216         ecore_timer_add(0.1, __progressbar_timer_cb, ad);
217
218         return;
219 }