Apply GUI resource and layout to progressbar
[platform/core/security/ode.git] / tools / apps / ode-gui / src / ui.c
1 /*
2  *
3  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  */
18
19 #include <limits.h>
20 #include <vconf.h>
21
22 #include "ode.h"
23 #include "widget.h"
24
25 #define EDJ_PATH "/usr/apps/" PACKAGE "/res/" PACKAGE ".edj"
26 #define IMAGE_PATH "/usr/apps/" PACKAGE "/res/images/HD/"
27
28 static Evas_Object *win, *conform, *layout, *progress_layout;
29 static char key[PATH_MAX] = "";
30 static int done = 0;
31
32 static void set_progress_percentage(int value)
33 {
34         Evas_Object *text_block = NULL;
35         char percentage[PATH_MAX] = "";
36
37         snprintf(percentage, sizeof(percentage), "%d%%", value);
38         text_block = _create_textblock(progress_layout, percentage, SUB_CONTENT_STYLE_W);
39         elm_object_part_content_set(progress_layout, "progress_percentage", text_block);
40         return;
41 }
42
43 static Eina_Bool progressbar_timer_cb(void *data)
44 {
45         Evas_Object *progressbar = (Evas_Object *)data;
46         char *progress = NULL;
47         int percentage = 0;
48
49         if (done) {
50                 ui_app_exit();
51                 return ECORE_CALLBACK_DONE;
52         }
53
54         progress = vconf_get_str(key);
55         if (progress)
56                 percentage = atoi(progress);
57
58         elm_progressbar_value_set(progressbar, (double)(percentage / 100.0));
59         set_progress_percentage(percentage);
60
61         if (percentage == 100) {
62                 done = 1;
63                 return ECORE_CALLBACK_PASS_ON;
64         }
65
66         return ECORE_CALLBACK_PASS_ON;
67 }
68
69 void create_base_window()
70 {
71         /* Create main UI widget */
72         win = _create_win(PACKAGE);
73         conform = _create_conformant(win);
74         layout = _create_layout(conform, NULL, NULL);
75         elm_object_content_set(conform, layout);
76
77         evas_object_show(win);
78         return;
79 }
80
81 static void set_internal_progress_layout(int state)
82 {
83         Evas_Object *text_block = NULL, *image = NULL;
84         char string[PATH_MAX] = "";
85         char image_path[PATH_MAX] = "";
86         char *internal_text[2][3] = {
87                 {
88                         "IDS_ST_NPBODY_ENCRYPTING_DEVICE_ING",
89                         "IDS_ST_BODY_PLEASE_WAIT",
90                         "IDS_ST_BODY_ONCE_THE_DEVICE_IS_ENCRYPTED_IT_WILL_RESTART"
91                 },
92                 {
93                         "IDS_ST_BODY_DECRYPTING_DEVICE_ING",
94                         "",
95                         "IDS_ST_BODY_PLEASE_WAIT_NONCE_THE_DEVICE_IS_DECRYPTED_IT_WILL_RESTART"
96                 }
97         };
98         char *icon_path[2] = {
99                 "icon_security.png",
100                 "icon_security_off.png"
101         };
102         char **text = NULL;
103
104         text = internal_text[state];
105         snprintf(image_path, sizeof(image_path), IMAGE_PATH"%s", icon_path[state]);
106
107         image = elm_image_add(progress_layout);
108         elm_image_file_set(image, image_path, NULL);
109         elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
110         elm_object_part_content_set(progress_layout, "icon", image);
111
112         snprintf(string, sizeof(string), "%s", __(text[0]));
113         text_block = _create_textblock(progress_layout, string, SUB_TITLE_STYLE_W);
114         elm_object_part_content_set(progress_layout, "message_title", text_block);
115
116         set_progress_percentage(0);
117
118         if (strcmp(text[1], ""))
119                 snprintf(string, sizeof(string), "%s<br>%s", __(text[1]), __(text[2]));
120         else
121                 snprintf(string, sizeof(string), "%s", __(text[2]));
122         text_block = _create_textblock(progress_layout, string, SUB_CONTENT_STYLE_W);
123         elm_object_part_content_set(progress_layout, "message_content", text_block);
124 }
125
126 static void set_external_progress_layout(int state)
127 {
128         Evas_Object *text_block = NULL, *image = NULL;
129         char string[PATH_MAX] = "";
130         char image_path[PATH_MAX] = "";
131         char *external_text[2][4] = {
132                 {
133                         "IDS_ST_BODY_ENCRYPTING_SD_CARD_ING",
134                         "IDS_ST_BODY_PLEASE_WAIT",
135                         "IDS_ST_BODY_ENCRYPT_ALL_NEW_FILES_SAVED_ON_THIS_SD_CARD_EXISTING_FILES_WILL_NOT_BE_ENCRYPTED",
136                         "IDS_ST_BODY_THE_SD_CARD_CANT_BE_USED_UNTIL_IT_HAS_BEEN_ENCRYPTED"
137                 },
138                 {
139                         "IDS_ST_BODY_DECRYPTING_SD_CARD_ING",
140                         "IDS_ST_BODY_PLEASE_WAIT",
141                         "",
142                         "IDS_ST_BODY_THE_SD_CARD_CANT_BE_USED_UNTIL_IT_HAS_BEEN_DECRYPTED"
143                 }
144         };
145         char *icon_path[2] = {
146                 "icon_security_sdcard.png",
147                 "icon_security_off_sdcard.png"
148         };
149         char **text = NULL;
150
151         text = external_text[state];
152         snprintf(image_path, sizeof(image_path), IMAGE_PATH"%s", icon_path[state]);
153
154         image = elm_image_add(progress_layout);
155         elm_image_file_set(image, image_path, NULL);
156         elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
157         elm_object_part_content_set(progress_layout, "icon", image);
158
159         snprintf(string, sizeof(string), "%s", __(text[0]));
160         text_block = _create_textblock(progress_layout, string, SUB_TITLE_STYLE_W);
161         elm_object_part_content_set(progress_layout, "message_title", text_block);
162
163         set_progress_percentage(0);
164
165         snprintf(string, sizeof(string), "%s<br>%s", __(text[1]), __(text[2]));
166         text_block = _create_textblock(progress_layout, string, SUB_CONTENT_STYLE_W);
167         elm_object_part_content_set(progress_layout, "message_content", text_block);
168
169         snprintf(string, sizeof(string), "%s", __(text[3]));
170         text_block = _create_textblock(progress_layout, string, SUB_CONTENT_STYLE_W);
171         elm_object_part_content_set(progress_layout, "message_bottom", text_block);
172 }
173
174 void create_progress_view(const char *type, const char *target)
175 {
176         Evas_Object *progressbar = NULL;
177         int state = 0;
178
179         done = 0;
180
181         if (!strcmp(type, "Encrypting")) {
182                 state = 0;
183         } else {
184                 state = 1;
185         }
186
187         progress_layout = _create_layout(layout, EDJ_PATH, "progress_layout");
188
189         if (!strcmp(target, "Internal")) {
190                 snprintf(key, PATH_MAX, "%s", VCONFKEY_ODE_ENCRYPT_PROGRESS);
191                 set_internal_progress_layout(state);
192         } else if (!strcmp(target, "External")) {
193                 snprintf(key, PATH_MAX, "%s", VCONFKEY_SDE_ENCRYPT_PROGRESS);
194                 set_external_progress_layout(state);
195         }
196
197         progressbar = _create_progressbar(progress_layout, "default");
198         elm_object_part_content_set(progress_layout, "progress_indicator", progressbar);
199
200         elm_object_part_content_set(layout, "elm.swallow.content", progress_layout);
201
202         elm_progressbar_value_set(progressbar, 0.0);
203         ecore_timer_add(1, progressbar_timer_cb, progressbar);
204         return;
205 }