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