2 * Tizen ODE application
4 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include "ode-password.h"
24 int launchpad_main(int argc, char *argv[]);
25 int standalone_main(int argc, char *argv[]);
29 int (*main)(int argc, char *argv[]);
33 .main = launchpad_main
37 .main = standalone_main
41 static Evas_Object *create_mainview(appdata_s *ad)
43 Evas_Object *base_layout = NULL;
44 Evas_Object *navi_bar = NULL;
46 base_layout = ode_create_layout(ad->conform, NULL, NULL);
47 if (ad->view_type == SD_CARD_PASSWORD) {
48 on_insert_sdcard_popup(base_layout);
52 navi_bar = ode_create_navigation(base_layout);
53 elm_naviframe_prev_btn_auto_pushed_set(navi_bar, EINA_TRUE);
54 ad->navi_bar = navi_bar;
56 switch (ad->view_type) {
58 ode_encrypt_device_create_view(ad);
61 ode_check_encrypt_device_create_view(ad);
64 ode_encrypt_sd_card_create_view(ad);
67 ode_decrypt_sd_card_create_view(ad);
73 static int create_base_gui(appdata_s *ad)
75 dlog_print(DLOG_DEBUG, LOG_TAG, "### create base gui start ###");
76 char *res_path = NULL;
77 char edj_path[PATH_MAX], icon_check_path[PATH_MAX], icon_bar_path[PATH_MAX] = "\0";
79 /* get EDJ & icon path */
80 res_path = app_get_resource_path();
81 if (res_path == NULL) {
82 dlog_print(DLOG_ERROR, LOG_TAG, "failed get resource path");
86 snprintf(edj_path, PATH_MAX, "%s%s", res_path, "org.tizen.ode.edj");
87 ad->edj_path = strdup(edj_path);
88 snprintf(icon_check_path, PATH_MAX, "%s%s", res_path, "images/icon_encrypt_check.png");
89 ad->icon_check_path = strdup(icon_check_path);
90 snprintf(icon_bar_path, PATH_MAX, "%s%s", res_path, "images/icon_encrypt_bar.png");
91 ad->icon_bar_path = strdup(icon_bar_path);
95 ad->win = ode_create_win(PACKAGE);
96 elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_TRANSPARENT);
99 ad->conform = ode_create_conformant(ad->win);
101 ad->base = create_mainview(ad);
102 elm_object_content_set(ad->conform, ad->base);
103 evas_object_show(ad->win);
108 static bool app_create(void *data)
113 static void app_control(app_control_h app_control, void *data)
115 /* Handle the launch request. */
116 appdata_s *ad = (appdata_s *)data;
118 char *viewtype = NULL;
120 ret = app_control_get_extra_data(app_control, "viewtype", &viewtype);
121 if (ret != APP_CONTROL_ERROR_NONE) {
122 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get viewtype");
126 dlog_print(DLOG_DEBUG, LOG_TAG, "viewtype is %s", viewtype);
127 if (!strcmp(viewtype, "ENCRYPT_DEVICE"))
128 ad->view_type = ENCRYPT_DEVICE;
129 else if (!strcmp(viewtype, "DECRYPT_DEVICE"))
130 ad->view_type = DECRYPT_DEVICE;
131 else if (!strcmp(viewtype, "ENCRYPT_SD_CARD"))
132 ad->view_type = ENCRYPT_SD_CARD;
133 else if (!strcmp(viewtype, "DECRYPT_SD_CARD"))
134 ad->view_type = DECRYPT_SD_CARD;
135 else if (!strcmp(viewtype, "SD_CARD_PASSWORD"))
136 ad->view_type = SD_CARD_PASSWORD;
142 elm_app_base_scale_set(1.8);
144 if (create_base_gui(ad) != 0) {
145 dlog_print(DLOG_ERROR, LOG_TAG, "### create base gui fail ###");
150 static void app_pause(void *data)
152 /* Take necessary actions when application becomes invisible. */
155 static void app_resume(void *data)
157 /* Take necessary actions when application becomes visible. */
158 dlog_print(DLOG_DEBUG, LOG_TAG, "### app_resume ###");
161 static void app_terminate(void *data)
163 /* unregister vconf notify callback */
165 appdata_s *ad = (appdata_s *)data;
167 switch (ad->view_type) {
169 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, locktype_status_changed_cb);
171 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister lockscreen type callback");
172 /* unregister runtime info callback */
173 ret = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_CHARGER_CONNECTED);
175 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister runtime info callback");
176 /* unregister battery percent callback */
177 ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_CAPACITY, battery_changed_cb);
179 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister battery capacity callback");
182 /* unregister runtime info callback */
183 ret = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_CHARGER_CONNECTED);
185 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister runtime info callback");
186 /* unregister battery percent callback */
187 ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_CAPACITY, battery_changed_cb);
189 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister battery capacity callback");
191 case ENCRYPT_SD_CARD:
192 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, sdcard_status_changed_cb);
194 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to unregister sdcard callback");
199 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
201 /* APP_EVENT_LANGUAGE_CHANGED */
205 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
206 if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
207 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get language");
209 elm_language_set(locale);
215 static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
217 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED */
221 static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
223 /*APP_EVENT_REGION_FORMAT_CHANGED */
226 static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
228 /*APP_EVENT_LOW_BATTERY */
231 static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
233 /*APP_EVENT_LOW_MEMORY */
236 int launchpad_main(int argc, char *argv[])
238 appdata_s ad = {0, };
241 ui_app_lifecycle_callback_s event_callback = { 0, };
242 app_event_handler_h handlers[5] = { NULL, };
244 event_callback.create = app_create;
245 event_callback.terminate = app_terminate;
246 event_callback.pause = app_pause;
247 event_callback.resume = app_resume;
248 event_callback.app_control = app_control;
250 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
251 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
252 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
253 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
254 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
255 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
257 ret = ui_app_main(argc, argv, &event_callback, &ad);
258 if (ret != APP_ERROR_NONE)
259 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);
264 int standalone_main(int argc, char *argv[])
266 setenv("HOME", "/opt/home/root", 1);
269 fprintf(stderr, "Other arguments is needed\n");
273 char *lang = vconf_get_str(VCONFKEY_LANGSET);
274 setlocale(LC_ALL, lang);
278 bindtextdomain("ode", "/usr/apps/org.tizen.ode/res/locale");
280 elm_init(argc, argv);
281 create_base_window();
283 if (!strncmp(argv[1], "progress", sizeof("progress"))) {
285 fprintf(stderr, "Other arguments is needed\n");
288 create_progress_view(argv[2], argv[3]);
296 int main(int argc, char *argv[])
298 char *name = strrchr(argv[0], '/');
301 name = name ? name + 1 : argv[0];
303 for (i = 0; i < sizeof(submains) / sizeof(struct submain); i++) {
304 if (strcmp(name, submains[i].name) == 0) {
305 return submains[i].main(argc, argv);