Bundles / 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 <app.h>
  18. #include <Elementary.h>
  19. #include <system_settings.h>
  20. #include <message_port.h>
  21. #include "$(appName).h"
  22. #include "data.h"
  23. #include "view.h"
  24. #include "view/view_sink.h"
  25.  
  26. bool string_equal(const char *str1, const char *str2)
  27. {
  28. size_t len = strlen(str1);
  29.  
  30. return len == strlen(str2) && !strncmp(str1, str2, len);
  31. }
  32.  
  33. /**
  34. * @brief Hook to take necessary actions before main event loop starts.
  35. * Initialize UI resources and application's data.
  36. * If this function returns true, the main loop of application starts.
  37. * If this function returns false, the application is terminated.
  38. */
  39. static bool app_create(void *user_data)
  40. {
  41. data_initialize(view_sink_new_message_cb);
  42. return (bool)view_create(user_data);
  43. }
  44.  
  45. /**
  46. * @brief This callback function is called when another application
  47. * sends a launch request to the application.
  48. */
  49. static void app_control(app_control_h app_control, void *user_data)
  50. {
  51. /* Handle the launch request. */
  52. }
  53.  
  54. /**
  55. * @brief This callback function is called each time
  56. * the application is completely obscured by another application
  57. * and becomes invisible to the user.
  58. */
  59. static void app_pause(void *user_data)
  60. {
  61. /* Take necessary actions when application becomes invisible. */
  62. }
  63.  
  64. /**
  65. * @brief This callback function is called each time
  66. * the application becomes visible to the user.
  67. */
  68. static void app_resume(void *user_data)
  69. {
  70. /* Take necessary actions when application becomes visible. */
  71. }
  72.  
  73. /**
  74. * @brief This callback function is called once after the main loop of the application exits.
  75. */
  76. static void app_terminate(void *user_data)
  77. {
  78. /* Release all resources. */
  79. view_destroy();
  80. data_finalize();
  81. }
  82.  
  83. /**
  84. * @brief This function will be called when the language is changed.
  85. */
  86. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  87. {
  88. /* APP_EVENT_LANGUAGE_CHANGED */
  89. char *locale = NULL;
  90.  
  91. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  92.  
  93. if (locale != NULL) {
  94. elm_language_set(locale);
  95. free(locale);
  96. }
  97.  
  98. return;
  99. }
  100.  
  101. /**
  102. * @brief Main function of the application.
  103. */
  104. int main(int argc, char *argv[])
  105. {
  106. int ret;
  107.  
  108. ui_app_lifecycle_callback_s event_callback = {0, };
  109. app_event_handler_h handlers[5] = {NULL, };
  110.  
  111. event_callback.create = app_create;
  112. event_callback.terminate = app_terminate;
  113. event_callback.pause = app_pause;
  114. event_callback.resume = app_resume;
  115. event_callback.app_control = app_control;
  116.  
  117. /*
  118. * If you want to handle more events,
  119. * please check the application life cycle guide.
  120. */
  121. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  122.  
  123. ret = ui_app_main(argc, argv, &event_callback, NULL);
  124. if (ret != APP_ERROR_NONE)
  125. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() failed. err = %d", ret);
  126.  
  127. return ret;
  128. }