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