World Clock Widget / src /

main.c

  1. /*
  2. * Copyright (c) 2015 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 <tizen.h>
  18. #include <widget_app.h>
  19. #include <dlog.h>
  20. #include "log.h"
  21. #include "view.h"
  22. #include "data.h"
  23.  
  24. static void clicked_cb(void *user_data);
  25.  
  26.  
  27. static int widget_instance_create(widget_context_h context, bundle *content, int w, int h, void *user_data)
  28. {
  29. void *wid = NULL;
  30. char *region_text = NULL;
  31. char *time_text = NULL;
  32. char *date_text = NULL;
  33.  
  34. if (content != NULL) {
  35. /* Recover the previous status with the bundle object. */
  36. }
  37.  
  38. /*
  39. * @note
  40. * view_create() function makes empty view frame.
  41. */
  42. wid = view_create(context, w, h);
  43. if (wid == NULL) {
  44. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a view.");
  45. return WIDGET_ERROR_FAULT;
  46. }
  47.  
  48. /*
  49. * @note
  50. * view_set_image() function put a image to the part.
  51. * Pass the part name which you want to put in as a second parameter,
  52. * and name of image file including its directory path as a third parameter.
  53. */
  54. view_set_image(wid, "widget.bg", "images/bg.png");
  55.  
  56. /*
  57. * @note
  58. * data_get_text() function get the text you want to use.
  59. * Pass the part name which you want to fill out as parameter.
  60. */
  61. region_text = data_get_text("widget.region");
  62. /*
  63. * @note
  64. * view_set_text() function fill out the part with the text.
  65. * Pass the part name as a first parameter and the text as a second parameter.
  66. */
  67. view_set_text(wid, "widget.region", region_text);
  68. free(region_text);
  69.  
  70. /*
  71. * @note
  72. * This function set will be called several times as much as you want to use.
  73. */
  74. time_text = data_get_text("widget.time");
  75. view_set_text(wid, "widget.time", time_text);
  76. free(time_text);
  77.  
  78. date_text = data_get_text("widget.date");
  79. view_set_text(wid, "widget.date", date_text);
  80. free(date_text);
  81.  
  82. /*
  83. * @note
  84. * view_set_event_callback() function launch widget's application.
  85. * Decide a third parameter of the function to designate the moment that application be launched.
  86. * There are three choices, WIDGET_EVENT_PRESSED, WIDGET_EVENT_RELEASED, WIDGET_EVENT_CLICKED.
  87. */
  88. view_set_event_callback(wid, "widget.event", WIDGET_EVENT_CLICKED, (void *) clicked_cb);
  89.  
  90. widget_app_context_set_tag(context, wid);
  91.  
  92. return WIDGET_ERROR_NONE;
  93. }
  94.  
  95. static int widget_instance_destroy(widget_context_h context, widget_app_destroy_type_e reason, bundle *content_info, void *user_data)
  96. {
  97. void *wid = NULL;
  98. widget_app_context_get_tag(context, (void**) &wid);
  99.  
  100. view_destroy(wid);
  101.  
  102. return WIDGET_ERROR_NONE;
  103. }
  104.  
  105. static int widget_instance_pause(widget_context_h context, void *user_data)
  106. {
  107. /* Take necessary actions when widget instance becomes invisible. */
  108. return WIDGET_ERROR_NONE;
  109. }
  110.  
  111. static int widget_instance_resume(widget_context_h context, void *user_data)
  112. {
  113. /* Take necessary actions when widget instance becomes visible. */
  114. return WIDGET_ERROR_NONE;
  115. }
  116.  
  117. static int widget_instance_update(widget_context_h context, bundle *content, int force, void *user_data)
  118. {
  119. /* Take necessary actions when widget instance should be updated. */
  120. return WIDGET_ERROR_NONE;
  121. }
  122.  
  123. static int widget_instance_resize(widget_context_h context, int w, int h, void *user_data)
  124. {
  125. void *wid = NULL;
  126.  
  127. widget_app_context_get_tag(context, (void**) &wid);
  128. view_resize(wid, w, h);
  129.  
  130. return WIDGET_ERROR_NONE;
  131. }
  132.  
  133. static void widget_app_lang_changed(app_event_info_h event_info, void *user_data)
  134. {
  135. /* APP_EVENT_LANGUAGE_CHANGED */
  136. char *locale = NULL;
  137. app_event_get_language(event_info, &locale);
  138. elm_language_set(locale);
  139. free(locale);
  140. }
  141.  
  142. static void widget_app_region_changed(app_event_info_h event_info, void *user_data)
  143. {
  144. /* APP_EVENT_REGION_FORMAT_CHANGED */
  145. }
  146.  
  147. static widget_class_h widget_app_create(void *user_data)
  148. {
  149. app_event_handler_h handlers[5] = {NULL, };
  150.  
  151. widget_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
  152. APP_EVENT_LANGUAGE_CHANGED, widget_app_lang_changed, user_data);
  153. widget_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
  154. APP_EVENT_REGION_FORMAT_CHANGED, widget_app_region_changed,
  155. user_data);
  156.  
  157. widget_instance_lifecycle_callback_s ops = {
  158. .create = widget_instance_create,
  159. .destroy = widget_instance_destroy,
  160. .pause = widget_instance_pause,
  161. .resume = widget_instance_resume,
  162. .update = widget_instance_update,
  163. .resize = widget_instance_resize,
  164. };
  165.  
  166. return widget_app_class_create(ops, user_data);
  167. }
  168.  
  169. static void widget_app_terminate(void *user_data)
  170. {
  171. /* Release all resources. */
  172. }
  173.  
  174. int main(int argc, char *argv[])
  175. {
  176. widget_app_lifecycle_callback_s ops = {0, };
  177. int ret;
  178.  
  179. ops.create = widget_app_create;
  180. ops.terminate = widget_app_terminate;
  181.  
  182. ret = widget_app_main(argc, argv, &ops, NULL);
  183. if (ret != WIDGET_ERROR_NONE) {
  184. dlog_print(DLOG_ERROR, LOG_TAG, "widget_app_main() is failed. err = %d", ret);
  185. }
  186.  
  187. return ret;
  188. }
  189.  
  190.  
  191. /*
  192. * @note
  193. * Below functions are static functions.
  194. */
  195.  
  196. /*
  197. * @brief: This function will be operated when the specific Evas object is clicked
  198. * @param[user_data]: data needed in this function
  199. */
  200. static void clicked_cb(void *user_data)
  201. {
  202. /*
  203. * @note
  204. * In this function, you launch the application.
  205. */
  206. dlog_print(DLOG_DEBUG, LOG_TAG, "clicked a widget.");
  207. }
  208.  
  209. /* End of file */