EOM / src /

main.c

  1. /*
  2. * Samsung API
  3. * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the License);
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/license/
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an AS IS BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17.  
  18.  
  19.  
  20. #include <tizen.h>
  21. #include <time.h>
  22.  
  23. #include "log.h"
  24. #include "main.h"
  25. #include "eom_sample.h"
  26. #include "view.h"
  27.  
  28. static void win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
  29. {
  30. appdata_s *ad = NULL;
  31.  
  32. ret_if(!data);
  33.  
  34. ad = data;
  35.  
  36. if (ad->vd) free(ad->vd);
  37.  
  38. ui_app_exit();
  39. }
  40.  
  41. static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
  42. {
  43. appdata_s *ad = NULL;
  44.  
  45. ret_if(!data);
  46.  
  47. _D("hide EOM");
  48.  
  49. ad = data;
  50.  
  51. /* Let window go to hide state. */
  52. elm_win_lower(ad->win);
  53. }
  54.  
  55. static Evas_Object *_create_win(appdata_s *ad)
  56. {
  57. Evas_Object *win = NULL;
  58.  
  59. retv_if(!ad, NULL);
  60.  
  61. win = elm_win_util_standard_add(PACKAGE, PACKAGE);
  62. retv_if(!win, NULL);
  63.  
  64. elm_win_conformant_set(win, EINA_TRUE);
  65. elm_win_autodel_set(win, EINA_TRUE);
  66.  
  67. if (elm_win_wm_rotation_supported_get(win)) {
  68. int rots[4] = { 0, 90, 180, 270 };
  69. elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
  70. }
  71.  
  72. evas_object_smart_callback_add(win, "delete,request", win_delete_request_cb, ad);
  73. eext_object_event_callback_add(win, EEXT_CALLBACK_BACK, win_back_cb, ad);
  74.  
  75. return win;
  76. }
  77.  
  78. static void _destroy_window(Evas_Object *win)
  79. {
  80. ret_if(!win);
  81.  
  82. evas_object_del(win);
  83. }
  84.  
  85. static Evas_Object *_create_conform(appdata_s *ad)
  86. {
  87. Evas_Object *conform = NULL;
  88.  
  89. retv_if(!ad, NULL);
  90.  
  91. conform = elm_conformant_add(ad->win);
  92. retv_if(!conform, NULL);
  93.  
  94. elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
  95. elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
  96. evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  97. elm_win_resize_object_add(ad->win, conform);
  98. evas_object_show(conform);
  99.  
  100. return conform;
  101. }
  102.  
  103. static void _destroy_conform(Evas_Object *conform)
  104. {
  105. ret_if(!conform);
  106.  
  107. evas_object_del(conform);
  108. }
  109.  
  110. static void _set_indicator_bg(appdata_s *ad)
  111. {
  112. Evas_Object *bg = NULL;
  113.  
  114. ret_if(!ad);
  115.  
  116. bg = elm_bg_add(ad->conform);
  117. ret_if(!bg);
  118.  
  119. elm_object_style_set(bg, "indicator/headerbg");
  120. elm_object_part_content_set(ad->conform, "elm.swallow.indicator_bg", bg);
  121. evas_object_show(bg);
  122. }
  123.  
  124. static Evas_Object *_create_navi(appdata_s *ad)
  125. {
  126. Evas_Object *nf = NULL;
  127.  
  128. retv_if(!ad, NULL);
  129.  
  130. nf = elm_naviframe_add(ad->conform);
  131. retv_if(!nf, NULL);
  132.  
  133. elm_object_content_set(ad->conform, nf);
  134. evas_object_show(nf);
  135.  
  136. return nf;
  137. }
  138.  
  139. static void _destroy_navi(Evas_Object *nf)
  140. {
  141. ret_if(!nf);
  142.  
  143. evas_object_del(nf);
  144. }
  145.  
  146. static Evas_Object *_create_layout(appdata_s *ad)
  147. {
  148. Evas_Object *layout = NULL;
  149.  
  150. retv_if(!ad, NULL);
  151.  
  152. layout = elm_layout_add(ad->nf);
  153. retv_if(!layout, NULL);
  154.  
  155. elm_layout_file_set(layout, LAYOUTEDJ, "main");
  156. evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  157. eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, win_back_cb, ad);
  158.  
  159. return layout;
  160. }
  161.  
  162. static void _destroy_layout(Evas_Object *layout)
  163. {
  164. ret_if(!layout);
  165.  
  166. evas_object_del(layout);
  167. }
  168.  
  169. static int _sample_get_output_id (const char *output_name)
  170. {
  171. eom_output_id *output_ids = NULL;
  172. eom_output_id output_id = 0;
  173. eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
  174. int id_cnt = 0;
  175. int i;
  176.  
  177. /* get output_ids */
  178. output_ids = eom_get_eom_output_ids(&id_cnt);
  179. if (id_cnt == 0)
  180. {
  181. _D("no external outuputs supported\n");
  182. return 0;
  183. }
  184.  
  185. /* find output ids interested */
  186. for (i = 0; i < id_cnt; i++)
  187. {
  188. eom_get_output_type(output_ids[i], &output_type);
  189. if (!strncmp(output_name, "HDMI", 4))
  190. {
  191. if (output_type == EOM_OUTPUT_TYPE_HDMIA || output_type == EOM_OUTPUT_TYPE_HDMIB)
  192. {
  193. output_id = output_ids[i];
  194. break;
  195. }
  196. }
  197. }
  198.  
  199. if (output_ids)
  200. free (output_ids);
  201.  
  202. return output_id;
  203. }
  204.  
  205. static void eom_setup(appdata_s *ad)
  206. {
  207. /* Get output ID */
  208. if (eom_init())
  209. _E("eom_init fail");
  210. else
  211. ad->output_id = _sample_get_output_id("HDMI");
  212.  
  213. /* not support eom if output_id is 0 */
  214. if (ad->output_id == 0)
  215. {
  216. ad->support_external_display = EINA_FALSE;
  217. ad->connected = EINA_FALSE;
  218. }
  219. else
  220. {
  221. /* connnection check */
  222. eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
  223. eom_get_output_mode(ad->output_id, &output_mode);
  224. if (output_mode != EOM_OUTPUT_MODE_NONE)
  225. ad->connected = EINA_TRUE;
  226. else
  227. ad->connected = EINA_FALSE;
  228. ad->support_external_display = EINA_TRUE;
  229. ad->mode = EOM_OUTPUT_MODE_MIRROR;
  230. }
  231.  
  232. if (ad->support_external_display == EINA_TRUE)
  233. {
  234. /* attribute set for presentation mode */
  235. if (eom_set_output_attribute(ad->output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL))
  236. {
  237. _D("eom_set_output_attribute EOM_OUTPUT_ATTRIBUTE_NORMAL fail");
  238. ad->attribute_set = EINA_FALSE;
  239. }
  240. else
  241. {
  242. _D("eom_set_output_attribute EOM_OUTPUT_ATTRIBUTE_NORMAL success");
  243. ad->attribute_set = EINA_TRUE;
  244. }
  245.  
  246. /* set eom callback */
  247. eom_set_unset_cb(ad, EINA_TRUE);
  248. }
  249. }
  250.  
  251. static void _create_eom_sample(appdata_s *ad)
  252. {
  253. Elm_Object_Item *nf_it = NULL;
  254. Evas_Object *box1 = NULL;
  255. Evas_Object *box2 = NULL;
  256.  
  257. ret_if(!ad);
  258.  
  259. _D("Create EOM sample app");
  260. eom_setup(ad);
  261.  
  262. /* Window */
  263. ad->win = _create_win(ad);
  264. ret_if(!ad->win);
  265.  
  266. /* Conformant */
  267. ad->conform = _create_conform(ad);
  268. goto_if(!ad->conform, ERROR);
  269.  
  270. /* Indicator BG */
  271. _set_indicator_bg(ad);
  272.  
  273. /* Naviframe */
  274. ad->nf = _create_navi(ad);
  275. goto_if(!ad->nf, ERROR);
  276.  
  277. /* Layout */
  278. ad->layout = _create_layout(ad);
  279. goto_if(!ad->layout, ERROR);
  280.  
  281. /* two part in layout */
  282. box1 = view_create_eom_display(ad);
  283. goto_if(!box1, ERROR);
  284. elm_object_part_content_set(ad->layout, "main_display", box1);
  285. evas_object_data_set(ad->layout, "b_1", box1);
  286.  
  287. box2 = view_create_eom_button(ad);
  288. goto_if(!box2, ERROR);
  289. elm_object_part_content_set(ad->layout, "button", box2);
  290. evas_object_data_set(ad->layout, "b_2", box2);
  291.  
  292. evas_object_show(ad->layout);
  293.  
  294. /* insert layout to naviframe */
  295. nf_it = elm_naviframe_item_push(ad->nf, "External Output Manager", NULL, NULL, ad->layout, NULL);
  296. goto_if(!nf_it, ERROR);
  297.  
  298. /* Show window after base gui is set up */
  299. evas_object_show(ad->win);
  300.  
  301. return;
  302.  
  303. ERROR:
  304. if (box2) {
  305. box2 = elm_object_part_content_unset(ad->layout, "button");
  306. evas_object_del(box2);
  307. }
  308. if (box1) {
  309. box1 = elm_object_part_content_unset(ad->layout, "main_display");
  310. evas_object_del(box1);
  311. }
  312. if (ad->layout) _destroy_layout(ad->layout);
  313. if (ad->nf) _destroy_navi(ad->nf);
  314. if (ad->conform) _destroy_conform(ad->conform);
  315. if (ad->win) _destroy_window(ad->win);
  316. if (ad->support_external_display)
  317. {
  318. eom_set_unset_cb(ad, EINA_FALSE);
  319. eom_deinit();
  320. }
  321.  
  322. return;
  323. }
  324.  
  325. static void _destroy_btn(Evas_Object *btn)
  326. {
  327. ret_if(!btn);
  328.  
  329. evas_object_del(btn);
  330. }
  331.  
  332. static void _destroy_eom_sample(appdata_s *ad)
  333. {
  334. Evas_Object *box1 = NULL;
  335. Evas_Object *box2 = NULL;
  336.  
  337. ret_if(!ad);
  338.  
  339. _D("Destroy stopwatch");
  340.  
  341. if (ad->vd) {
  342. if (ad->vd->text1) evas_object_del(ad->vd->text1);
  343. if (ad->vd->text2) evas_object_del(ad->vd->text2);
  344. if (ad->vd->text3) evas_object_del(ad->vd->text3);
  345. if (ad->vd->bg) evas_object_del(ad->vd->bg);
  346. if (ad->vd->box_external) evas_object_del(ad->vd->box_external);
  347.  
  348. free(ad->vd);
  349. }
  350.  
  351. if (ad->btn_presentation) _destroy_btn(ad->btn_presentation);
  352. if (ad->btn_mirror) _destroy_btn(ad->btn_mirror);
  353.  
  354. if (ad->nf) {
  355. ad->layout = elm_naviframe_item_pop(ad->nf);
  356. if (ad->layout) {
  357. box2 = evas_object_data_del(ad->layout, "b_2");
  358. if (box2) {
  359. box2 = elm_object_part_content_unset(ad->layout, "button");
  360. evas_object_del(box2);
  361. }
  362.  
  363. box1 = evas_object_data_del(ad->layout, "b_1");
  364. if (box1) {
  365. box1 = elm_object_part_content_unset(ad->layout, "main_display");
  366. evas_object_del(box1);
  367. }
  368.  
  369. if (ad->layout) _destroy_layout(ad->layout);
  370. }
  371. }
  372.  
  373. if (ad->nf) _destroy_navi(ad->nf);
  374. if (ad->conform) _destroy_conform(ad->conform);
  375. if (ad->win) _destroy_window(ad->win);
  376. if (ad->support_external_display)
  377. {
  378. if (ad->external_win)
  379. _destroy_window(ad->external_win);
  380. eom_set_unset_cb(ad, EINA_FALSE);
  381. eom_deinit();
  382. }
  383. }
  384.  
  385. static bool app_create(void *data)
  386. {
  387. /* Hook to take necessary actions before main event loop starts
  388. Initialize UI resources and application's data
  389. If this function returns true, the main loop of application starts
  390. If this function returns false, the application is terminated */
  391. appdata_s *ad = data;
  392.  
  393. _create_eom_sample(ad);
  394.  
  395. return true;
  396. }
  397.  
  398. static void app_control(app_control_h app_control, void *data)
  399. {
  400. /* Handle the launch request. */
  401. }
  402.  
  403. static void app_pause(void *data)
  404. {
  405. /* Take necessary actions when application becomes invisible. */
  406. }
  407.  
  408. static void app_resume(void *data)
  409. {
  410. /* Take necessary actions when application becomes visible. */
  411. }
  412.  
  413. static void app_terminate(void *data)
  414. {
  415. /* Release all resources. */
  416. appdata_s *ad = NULL;
  417.  
  418. ret_if(!data);
  419.  
  420. ad = data;
  421.  
  422. _destroy_eom_sample(ad);
  423. }
  424.  
  425. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  426. {
  427. /*APP_EVENT_LANGUAGE_CHANGED*/
  428. char *locale = NULL;
  429.  
  430. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  431. ret_if(!locale);
  432.  
  433. elm_language_set(locale);
  434. free(locale);
  435.  
  436. return;
  437. }
  438.  
  439. static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
  440. {
  441. /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
  442. return;
  443. }
  444.  
  445. static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
  446. {
  447. /*APP_EVENT_REGION_FORMAT_CHANGED*/
  448. }
  449.  
  450. static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
  451. {
  452. /*APP_EVENT_LOW_BATTERY*/
  453. }
  454.  
  455. static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
  456. {
  457. /*APP_EVENT_LOW_MEMORY*/
  458. }
  459.  
  460. int main(int argc, char *argv[])
  461. {
  462. appdata_s ad = {0,};
  463. int ret = 0;
  464.  
  465. ui_app_lifecycle_callback_s event_callback = {0,};
  466. app_event_handler_h handlers[5] = {NULL, };
  467.  
  468. event_callback.create = app_create;
  469. event_callback.terminate = app_terminate;
  470. event_callback.pause = app_pause;
  471. event_callback.resume = app_resume;
  472. event_callback.app_control = app_control;
  473.  
  474. ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
  475. ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
  476. ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
  477. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
  478. ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
  479. ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
  480.  
  481. ret = ui_app_main(argc, argv, &event_callback, &ad);
  482. if (ret != APP_ERROR_NONE) {
  483. _E("ui_app_main() is failed. err = %d", ret);
  484. }
  485.  
  486. return ret;
  487. }
  488. /* End of file */