Alarm / 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.  
  20. #include "$(appName).h"
  21. #include "view.h"
  22. #include "data.h"
  23.  
  24. static void _scheduled_alarm_callback(time_t t);
  25. static void _ontime_alarm_fired_callback(void);
  26. static void _recurring_alarm_fired_callback(void);
  27.  
  28. /**
  29. * @brief Hook to take necessary actions before main event loop starts.
  30. * Initialize UI resources and application's data.
  31. * If this function returns true, the main loop of application starts.
  32. * If this function returns false, the application is terminated.
  33. */
  34. static bool app_create(void *user_data)
  35. {
  36. if (!view_create()) {
  37. dlog_print(DLOG_ERROR, LOG_TAG, "Can't create view");
  38. return false;
  39. }
  40.  
  41. data_set_alarms_callbacks(_scheduled_alarm_callback, _ontime_alarm_fired_callback, _recurring_alarm_fired_callback);
  42. /* initialize alarm schedule */
  43. data_initialize();
  44.  
  45. return true;
  46. }
  47.  
  48. /**
  49. * @brief This callback function is called when another application
  50. * sends a launch request to the application.
  51. */
  52. static void app_control(app_control_h app_control, void *user_data)
  53. {
  54. data_handle_app_control(app_control);
  55. }
  56.  
  57. /**
  58. * @brief This callback function is called each time
  59. * the application is completely obscured by another application
  60. * and becomes invisible to the user.
  61. */
  62. static void app_pause(void *user_data)
  63. {
  64. /* Take necessary actions when application becomes invisible. */
  65. }
  66.  
  67. /**
  68. * @brief This callback function is called each time
  69. * the application becomes visible to the user.
  70. */
  71. static void app_resume(void *user_data)
  72. {
  73. /* Take necessary actions when application becomes visible. */
  74. }
  75.  
  76. /**
  77. * @brief This callback function is called once after the main loop of the application exits.
  78. */
  79. static void app_terminate(void *user_data)
  80. {
  81. /* Release all resources. */
  82. view_destroy();
  83. data_finalize();
  84. }
  85.  
  86. /**
  87. * @brief This function will be called when the language is changed.
  88. */
  89. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  90. {
  91. /* APP_EVENT_LANGUAGE_CHANGED */
  92. char *locale = NULL;
  93.  
  94. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  95.  
  96. if (locale != NULL) {
  97. elm_language_set(locale);
  98. free(locale);
  99. }
  100. return;
  101. }
  102.  
  103. int main(int argc, char *argv[])
  104. {
  105. int ret;
  106.  
  107. ui_app_lifecycle_callback_s event_callback = {0, };
  108. app_event_handler_h handlers[5] = {NULL, };
  109.  
  110. event_callback.create = app_create;
  111. event_callback.terminate = app_terminate;
  112. event_callback.pause = app_pause;
  113. event_callback.resume = app_resume;
  114. event_callback.app_control = app_control;
  115.  
  116. /*
  117. * If you want to handle more events,
  118. * please check the application life cycle guide.
  119. */
  120. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  121.  
  122. ret = ui_app_main(argc, argv, &event_callback, NULL);
  123. if (ret != APP_ERROR_NONE)
  124. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() failed. err = %d", ret);
  125.  
  126. return ret;
  127. }
  128.  
  129. /*
  130. * Function displays the alarm time information.
  131. */
  132. static void _scheduled_alarm_callback(time_t t)
  133. {
  134. struct tm *local_t;
  135. char buff[128] = {0,};
  136.  
  137. if (t != 0) {
  138. local_t = localtime(&t);
  139. strftime(buff, sizeof(buff), "Alarm will be fired about %T", local_t);
  140. view_display_alarm_info(buff);
  141. } else {
  142. view_display_alarm_info("");
  143. }
  144. }
  145.  
  146. /*
  147. * Function requests for text message and related image to show on alarm fire.
  148. */
  149. static void _ontime_alarm_fired_callback(void)
  150. {
  151. view_handle_ontime_alarm();
  152. }
  153. /*
  154. * Function requests for text message and related image to show on alarm fire.
  155. */
  156. static void _recurring_alarm_fired_callback(void)
  157. {
  158. view_handle_recurring_alarm();
  159. }