(Circle) System Settings / 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 <Elementary.h>
  18. #include <app.h>
  19. #include <dlog.h>
  20. #include <system_settings.h>
  21. #include <efl_extension.h>
  22.  
  23. #include "$(appName).h"
  24. #include "view.h"
  25. #include "data.h"
  26.  
  27. #define MENU_ITEMS 9
  28. #define DISPLAY_ITEMS 6
  29.  
  30. static Eina_Bool _naviframe_pop_cb(void *data, Elm_Object_Item *it);
  31. static void _gl_display(void);
  32. static void _create_sub_list(void *data, Evas_Object *obj, void *event_info);
  33. static void _gl_clicked_cb(void *data, Evas_Object *obj, void *event_info);
  34.  
  35. /*
  36. * @brief: Hook to take necessary actions before main event loop starts
  37. * Initialize UI resources and application's data
  38. * If this function returns true, the main loop of application starts
  39. * If this function returns false, the application is terminated
  40. */
  41. static bool app_create(void *user_data)
  42. {
  43. /* Hook to take necessary actions before main event loop starts
  44. Initialize UI resources and application's data
  45. If this function returns true, the main loop of application starts
  46. If this function returns false, the application is terminated */
  47.  
  48. Evas_Object *nf = NULL;
  49. Evas_Object *genlist = NULL;
  50. int i = 0;
  51.  
  52. /*
  53. * Create essential objects.
  54. */
  55. view_create();
  56.  
  57. /*
  58. * Create a genlist.
  59. */
  60. nf = view_get_naviframe();
  61. genlist = view_create_circle_genlist(nf);
  62.  
  63. /*
  64. * Append a genlist's item as a title.
  65. */
  66. view_append_item_to_genlist(genlist, "menu.title", NULL, NULL, NULL);
  67.  
  68. /*
  69. * Append menu items to genlist.
  70. */
  71. for (i = 0; i < MENU_ITEMS; i++) {
  72. view_append_item_to_genlist(genlist, "1text.1icon", (void *)i, _create_sub_list, (void *)i);
  73. }
  74.  
  75. /*
  76. * Create a genlist's item as a padding item.
  77. * Padding item makes genlist's items is located at the middle of the screen.
  78. */
  79. view_append_item_to_genlist(genlist, "padding", NULL, NULL, NULL);
  80.  
  81. /*
  82. * Push the genlist at naviframe.
  83. */
  84. view_push_item_to_naviframe(nf, genlist, _naviframe_pop_cb, NULL);
  85.  
  86. view_set_genlist(genlist);
  87.  
  88. return true;
  89. }
  90.  
  91. /*
  92. * @brief: This callback function is called when another application
  93. * sends the launch request to the application
  94. */
  95. static void app_control(app_control_h app_control, void *user_data)
  96. {
  97. /* Handle the launch request. */
  98. }
  99.  
  100. /*
  101. * @brief: This callback function is called each time
  102. * the application is completely obscured by another application
  103. * and becomes invisible to the user
  104. */
  105. static void app_pause(void *user_data)
  106. {
  107. /* Take necessary actions when application becomes invisible. */
  108. }
  109.  
  110. /*
  111. * @brief: This callback function is called each time
  112. * the application becomes visible to the user
  113. */
  114. static void app_resume(void *user_data)
  115. {
  116. /* Take necessary actions when application becomes visible. */
  117. }
  118.  
  119. /*
  120. * @brief: This callback function is called once after the main loop of the application exits
  121. */
  122. static void app_terminate(void *user_data)
  123. {
  124. /* Release all resources. */
  125.  
  126. view_destroy();
  127. }
  128.  
  129. /*
  130. * @brief: This function will be called when the language is changed
  131. */
  132. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  133. {
  134. /*APP_EVENT_LANGUAGE_CHANGED*/
  135. char *locale = NULL;
  136.  
  137. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  138.  
  139. if (locale != NULL) {
  140. elm_language_set(locale);
  141. free(locale);
  142. }
  143. return;
  144. }
  145.  
  146. /*
  147. * @brief: main function of the application
  148. */
  149. int main(int argc, char *argv[])
  150. {
  151. int ret;
  152.  
  153. ui_app_lifecycle_callback_s event_callback = {0, };
  154. app_event_handler_h handlers[5] = {NULL, };
  155.  
  156. event_callback.create = app_create;
  157. event_callback.terminate = app_terminate;
  158. event_callback.pause = app_pause;
  159. event_callback.resume = app_resume;
  160. event_callback.app_control = app_control;
  161.  
  162. /*
  163. * If you want to handling more events,
  164. * Please check the application lifecycle guide
  165. */
  166. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  167.  
  168. ret = ui_app_main(argc, argv, &event_callback, NULL);
  169. if (ret != APP_ERROR_NONE) {
  170. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
  171. }
  172.  
  173. return ret;
  174. }
  175.  
  176. /*
  177. * @note
  178. * Below functions are static functions.
  179. */
  180.  
  181. /*
  182. * @brief: This function will be operated when the first item of the naviframe is going to popped.
  183. * @param[data]: Data needed in this function
  184. * @param[it]: Item of naviframe
  185. */
  186. static Eina_Bool _naviframe_pop_cb(void *data, Elm_Object_Item *it)
  187. {
  188. ui_app_exit();
  189.  
  190. return EINA_FALSE;
  191. }
  192.  
  193. /*
  194. * @brief: This function will be operated when the first genlist's item is clicked
  195. */
  196. static void _gl_display(void)
  197. {
  198. Evas_Object *nf = NULL;
  199. Evas_Object *display_genlist = NULL;
  200. int i = 0;
  201.  
  202. /*
  203. * Create a genlist of display menu.
  204. */
  205. nf = view_get_naviframe();
  206. display_genlist = view_create_circle_genlist(nf);
  207.  
  208. view_append_item_to_genlist(display_genlist, "display.title", NULL, NULL, NULL);
  209.  
  210. for (i = 0; i < DISPLAY_ITEMS; i++) {
  211. if (i == 0 || i == 3 || i == 5) {
  212. view_append_item_to_genlist(display_genlist, "1text", (void *)i, NULL, NULL);
  213. } else if (i == 1 || i == 2) {
  214. view_append_item_to_genlist(display_genlist, "1text.1icon.1", (void *)i, _gl_clicked_cb, (void *)i);
  215. } else {
  216. view_append_item_to_genlist(display_genlist, "2text", (void *)i, NULL, NULL);
  217. }
  218. }
  219.  
  220. view_append_item_to_genlist(display_genlist, "padding", NULL, NULL, NULL);
  221.  
  222. view_push_item_to_naviframe(nf, display_genlist, NULL, NULL);
  223. }
  224.  
  225. /*
  226. * @brief: This function will be operated when one of genlist's items is clicked
  227. * @param[data]: Data passed from 'elm_genlist_item_append' as seventh parameter
  228. * @param[obj]: Genlist
  229. * @param[event_info]: A pointer to data which is totally dependent on the smart object's implementation and semantic for the given event
  230. */
  231. static void _create_sub_list(void *data, Evas_Object *obj, void *event_info)
  232. {
  233. int index = (int)data;
  234.  
  235. switch (index) {
  236. case 0:
  237. /*
  238. * You can do as you want by adding code here
  239. * when you select the item of list.
  240. */
  241. _gl_display();
  242. break;
  243. case 1:
  244. /*
  245. * You can do as you want by adding code here
  246. * when you select the item of list.
  247. */
  248. break;
  249. case 2:
  250. /*
  251. * You can do as you want by adding code here
  252. * when you select the item of list.
  253. */
  254. break;
  255. case 3:
  256. /*
  257. * You can do as you want by adding code here
  258. * when you select the item of list.
  259. */
  260. break;
  261. case 4:
  262. /*
  263. * You can do as you want by adding code here
  264. * when you select the item of list.
  265. */
  266. break;
  267. case 5:
  268. /*
  269. * You can do as you want by adding code here
  270. * when you select the item of list.
  271. */
  272. break;
  273. case 6:
  274. /*
  275. * You can do as you want by adding code here
  276. * when you select the item of list.
  277. */
  278. break;
  279. case 7:
  280. /*
  281. * You can do as you want by adding code here
  282. * when you select the item of list.
  283. */
  284. break;
  285. case 8:
  286. /*
  287. * You can do as you want by adding code here
  288. * when you select the item of list.
  289. */
  290. break;
  291. default:
  292. dlog_print(DLOG_ERROR, LOG_TAG, "wrong approach");
  293. break;
  294. }
  295. }
  296.  
  297. /*
  298. * @brief: This function will be operated when one of genlist's items is clicked
  299. * @param[data]: Data passed from 'elm_genlist_item_append' as seventh parameter
  300. * @param[obj]: Genlist
  301. * @param[event_info]: A pointer to data which is totally dependent on the smart object's implementation and semantic for the given event
  302. */
  303. static void _gl_clicked_cb(void *data, Evas_Object *obj, void *event_info)
  304. {
  305. Elm_Object_Item *it = (Elm_Object_Item *)event_info;
  306. Evas_Object *content = NULL;
  307. const char *w_type;
  308.  
  309. /*
  310. * Get content of genlist's item.
  311. */
  312. content = elm_object_item_part_content_get(it, "elm.icon");
  313.  
  314. /*
  315. * Check whether type of content is elm_check or not.
  316. */
  317. w_type = elm_object_widget_type_get(content);
  318. if (w_type == NULL) {
  319. return;
  320. }
  321.  
  322. if (strcmp(w_type, "elm_check")) return;
  323.  
  324. /*
  325. * Control check state.
  326. */
  327. if (content) {
  328. int index;
  329. Eina_Bool state;
  330.  
  331. index = (int)data;
  332. state = elm_check_state_get(content);
  333.  
  334. if (state == EINA_TRUE) {
  335. elm_check_state_set(content, EINA_FALSE);
  336. data_set_display_int_value(index, EINA_FALSE);
  337. dlog_print(DLOG_INFO, LOG_TAG, "selected check [%p] state [%d]", content, EINA_FALSE);
  338. } else {
  339. elm_check_state_set(content, EINA_TRUE);
  340. data_set_display_int_value(index, EINA_TRUE);
  341. dlog_print(DLOG_INFO, LOG_TAG, "selected check [%p] state [%d]", content, EINA_TRUE);
  342. }
  343. }
  344. }
  345.  
  346. /* End of file */