Puzzle / 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 (bool)view_create(NULL);
  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. /* Take necessary actions when application becomes invisible. */
  50. }
  51.  
  52. /**
  53. * @brief This callback function is called each time
  54. * the application becomes visible to the user.
  55. */
  56. static void app_resume(void *user_data)
  57. {
  58. /* Take necessary actions when application becomes visible. */
  59. }
  60.  
  61. /**
  62. * @brief This callback function is called once after the main loop of the application exits.
  63. */
  64. static void app_terminate(void *user_data)
  65. {
  66. /* Release all resources. */
  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. return;
  85. }
  86.  
  87. /**
  88. * @brief Main function of the application.
  89. */
  90. int main(int argc, char *argv[])
  91. {
  92. int ret;
  93.  
  94. ui_app_lifecycle_callback_s event_callback = {0, };
  95. app_event_handler_h handlers[5] = {NULL, };
  96.  
  97. event_callback.create = app_create;
  98. event_callback.terminate = app_terminate;
  99. event_callback.pause = app_pause;
  100. event_callback.resume = app_resume;
  101. event_callback.app_control = app_control;
  102.  
  103. /*
  104. * If you want to handle more events,
  105. * please check the application lifecycle guide.
  106. */
  107. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  108.  
  109. ret = ui_app_main(argc, argv, &event_callback, NULL);
  110. if (ret != APP_ERROR_NONE)
  111. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() failed. err = %d", ret);
  112.  
  113. return ret;
  114. }