Copy and paste / src /

main.c

  1. /*
  2. * Copyright (c) 2016 Samsung Electronics Co., Ltd
  3. *
  4. * Licensed under the Flora License, Version 1.1 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://floralicense.org/license/
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. #include <Elementary.h>
  18. #include <system_settings.h>
  19. #include "$(appName).h"
  20. #include "view.h"
  21.  
  22. /**
  23. * @brief Hook to take necessary actions before main event loop starts.
  24. * Initialize UI resources and application's data.
  25. * If this function returns true, the main loop of application starts.
  26. * If this function returns false, the application is terminated.
  27. */
  28. static bool app_create(void *user_data)
  29. {
  30. return view_create();
  31. }
  32.  
  33. /**
  34. * @brief This callback function is called when another application
  35. * sends a launch request to the application.
  36. */
  37. static void app_control(app_control_h app_control, void *user_data)
  38. {
  39. /* Handle the launch request. */
  40. }
  41.  
  42. /**
  43. * @brief This callback function is called each time
  44. * the application is completely obscured by another application
  45. * and becomes invisible to the user.
  46. */
  47. static void app_pause(void *user_data)
  48. {
  49. view_set_normal_state();
  50. }
  51.  
  52.  
  53. /**
  54. * @brief This callback function is called each time
  55. * the application becomes visible to the user.
  56. */
  57. static void app_resume(void *user_data)
  58. {
  59. /* Take necessary actions when application becomes visible. */
  60. }
  61.  
  62. /**
  63. * @brief This callback function is called once after the main loop of the application exits.
  64. */
  65. static void app_terminate(void *user_data)
  66. {
  67. view_destroy();
  68. }
  69.  
  70. /**
  71. * @brief This function will be called when the language is changed.
  72. */
  73. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  74. {
  75. /* APP_EVENT_LANGUAGE_CHANGED */
  76. char *locale = NULL;
  77.  
  78. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  79.  
  80. if (locale != NULL) {
  81. elm_language_set(locale);
  82. free(locale);
  83. }
  84.  
  85. return;
  86. }
  87.  
  88. /**
  89. * @brief Main function of the application.
  90. */
  91. int main(int argc, char *argv[])
  92. {
  93. int ret;
  94.  
  95. ui_app_lifecycle_callback_s event_callback = {0, };
  96. app_event_handler_h handlers[5] = {NULL, };
  97.  
  98. event_callback.create = app_create;
  99. event_callback.terminate = app_terminate;
  100. event_callback.pause = app_pause;
  101. event_callback.resume = app_resume;
  102. event_callback.app_control = app_control;
  103.  
  104. /*
  105. * If you want to handle more events,
  106. * please check the application lifecycle guide.
  107. */
  108. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  109.  
  110. ret = ui_app_main(argc, argv, &event_callback, NULL);
  111. if (ret != APP_ERROR_NONE)
  112. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() failed. err = %d", ret);
  113.  
  114. return ret;
  115. }