-/*
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include "ode.h"
-
-int launchpad_main(int argc, char *argv[]);
-int standalone_main(int argc, char *argv[]);
-
-struct submain {
- const char* name;
- int (*main)(int argc, char* argv[]);
-} submains[] = {
- {
- .name = PACKAGE,
- .main = launchpad_main
- },
- {
- .name = "ode-gui",
- .main = standalone_main
- },
-};
-
-static bool app_create(void *data)
-{
- return true;
-}
-
-static void app_pause(void *data)
-{
-}
-
-static void app_resume(void *data)
-{
-}
-
-static void app_terminate(void *data)
-{
-}
-
-static void app_control(app_control_h app_control, void *data)
-{
- char *mode;
- int ret = 0;
-
- ret = app_control_get_extra_data(app_control, "mode", &mode);
- if (ret != APP_CONTROL_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get mode");
- ui_app_exit();
- return;
- }
-
- create_base_window();
-
- if (!strncmp(mode, "progress", sizeof("progress"))) {
- char *type, *target;
-
- ret = app_control_get_extra_data(app_control, "type", &type);
- if (ret != APP_CONTROL_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get type");
- ui_app_exit();
- return;
- }
- ret = app_control_get_extra_data(app_control, "target", &target);
- if (ret != APP_CONTROL_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get target");
- ui_app_exit();
- return;
- }
- create_progress_view(type, target);
- }
-}
-
-static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
-{
- int ret = 0;
- char *locale = NULL;
-
- ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
- if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "failed to get language");
- return;
- }
-
- elm_language_set(locale);
- free(locale);
- return;
-}
-
-int launchpad_main(int argc, char *argv[])
-{
- int ret = 0;
- app_event_handler_h handlers[5] = {NULL, };
- ui_app_lifecycle_callback_s event_callback = {0, };
-
- event_callback.create = app_create;
- event_callback.terminate = app_terminate;
- event_callback.pause = app_pause;
- event_callback.resume = app_resume;
- event_callback.app_control = app_control;
-
- ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
-
- ret = ui_app_main(argc, argv, &event_callback, NULL);
- if (ret != APP_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);
-
- return ret;
-}
-
-int standalone_main(int argc, char *argv[])
-{
- setenv("HOME", "/root", 1);
-
- if (argc <2) {
- fprintf(stderr, "Other arguments is needed\n");
- return EXIT_FAILURE;
- }
-
- elm_init(argc, argv);
- ui_app_lang_changed(NULL, NULL);
- create_base_window();
-
- if (!strncmp(argv[1], "progress", sizeof("progress"))) {
- if (argc < 4) {
- fprintf(stderr, "Other arguments is needed\n");
- return EXIT_FAILURE;
- }
- create_progress_view(argv[2], argv[3]);
- }
-
- elm_run();
-
- return EXIT_SUCCESS;
-}
-
-int main(int argc, char* argv[])
-{
- char *name = strrchr(argv[0], '/');
- int i;
-
- name = name ? name + 1 : argv[0];
-
- for (i = 0; i < sizeof(submains) / sizeof(struct submain); i++) {
- if (strcmp(name, submains[i].name) == 0) {
- return submains[i].main(argc, argv);
- }
- }
-
- return EXIT_FAILURE;
-}