4 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Jin Yoon <jinny.yoon@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include <appcore-efl.h>
26 #include <Elementary.h>
28 #include <system_info.h>
30 #include <app_preference.h>
31 #include <system_settings.h>
32 #include <pkgmgr-info.h>
39 #include "menu_screen.h"
42 #include "page_scroller.h"
46 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
48 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
49 #define LAYOUT_GROUP_NAME "layout"
53 // Define prototype of the "hidden API of AUL"
54 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
66 } menu_screen_info = {
67 .state = APP_STATE_PAUSE,
79 HAPI Evas *menu_screen_get_evas(void)
81 return menu_screen_info.evas;
86 HAPI int menu_screen_get_root_width(void)
88 return menu_screen_info.root_width;
93 HAPI int menu_screen_get_root_height(void)
95 return menu_screen_info.root_height;
100 HAPI Evas_Object *menu_screen_get_win(void)
102 return menu_screen_info.win;
107 HAPI Elm_Theme *menu_screen_get_theme(void)
109 return menu_screen_info.theme;
114 HAPI bool menu_screen_get_done(void)
116 return menu_screen_info.is_done;
121 HAPI void menu_screen_set_done(bool is_done)
123 menu_screen_info.is_done = is_done;
128 HAPI int menu_screen_get_state(void)
130 return menu_screen_info.state;
135 HAPI int menu_screen_is_tts(void)
137 return menu_screen_info.is_tts;
141 static Eina_Bool _appcore_flush_cb(void *data)
143 if (APP_STATE_PAUSE != menu_screen_info.state) return ECORE_CALLBACK_CANCEL;
144 if (0 != appcore_flush_memory()) _E("Cannot flush memory");
145 return ECORE_CALLBACK_CANCEL;
150 HAPI void menu_screen_inc_booting_state(void)
152 menu_screen_info.booting_state++;
153 if (BOOTING_STATE_DONE > menu_screen_info.booting_state) return;
155 menu_screen_error_e ret = MENU_SCREEN_ERROR_OK;
157 ret = pkgmgr_reserve_list_pop_request();
158 } while (MENU_SCREEN_ERROR_OK == ret);
160 /* Cache memory is cleared when the application paused (every time, after 5 seconds (in appcore)),
161 * but after running in a minimized mode (HIDE_LAUNCH) application have status AS_RUNNING.
162 * Application have status AS_PAUSED only after change of visibility to hidden condition by user (on hiding window)
163 * Cleaning must be performed only once after application loading in hidden condition
164 * (and stay in a hidden condition at time of cleaning).
166 if (APP_STATE_PAUSE == menu_screen_info.state)
167 ecore_timer_add(5, _appcore_flush_cb, NULL);
172 HAPI void menu_screen_dec_booting_state(void)
174 menu_screen_info.booting_state --;
179 HAPI int menu_screen_get_booting_state(void)
181 return menu_screen_info.booting_state;
186 static bool _is_emulator_on(void)
191 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
192 if (SYSTEM_INFO_ERROR_NONE != ret) {
199 if (!strncmp(model, "Emulator", strlen(model))) {
200 _D("This model is on Emulator");
205 _D("This model is NOT on Emulator");
212 static menu_screen_error_e _create_canvas(char *name, char *title)
216 if (_is_emulator_on()) {
217 _D("ELM_ENGINE is set as [software_x11]");
218 elm_config_accel_preference_set("opengl");
220 buf = vconf_get_str(MENU_SCREEN_ENGINE);
222 _D("ELM_ENGINE is set as [%s]", buf);
223 elm_config_accel_preference_set(buf);
226 _D("ELM_ENGINE is set as [gl]");
227 elm_config_accel_preference_set("gl");
231 menu_screen_info.win = elm_win_util_standard_add(name, name);
232 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
235 elm_win_title_set(menu_screen_info.win, title);
237 _D("elm_scale: %f", elm_app_base_scale_get());
238 _D("config_scale: %f", elm_config_scale_get());
240 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
241 elm_win_screen_size_get(menu_screen_info.win, NULL, NULL, &menu_screen_info.root_width, &menu_screen_info.root_height);
242 _D("menu-screen window size:: width: %d, height: %d", menu_screen_info.root_width, menu_screen_info.root_height);
245 ecore_x_icccm_name_class_set(elm_win_xwindow_get(menu_screen_info.win), "MENU_SCREEN", "MENU_SCREEN");
246 ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
247 if (ATOM_WM_WINDOW_ROLE) {
248 ecore_x_window_prop_string_set(elm_win_xwindow_get(menu_screen_info.win), ATOM_WM_WINDOW_ROLE, "MENU_SCREEN");
250 _D("Failed to set the window role as MENU_SCREEN");
254 elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
256 menu_screen_info.evas = evas_object_evas_get(menu_screen_info.win);
257 if (!menu_screen_info.evas) {
258 _E("[%s] Failed to get the evas object", __func__);
261 menu_screen_info.ee = ecore_evas_ecore_evas_get(menu_screen_info.evas);
262 if (!menu_screen_info.ee) {
263 _E("[%s] Failed to get ecore_evas object", __func__);
266 evas_object_show(menu_screen_info.win);
268 return MENU_SCREEN_ERROR_OK;
273 static void _destroy_canvas(void)
275 evas_object_del(menu_screen_info.win);
280 static int _dead_cb(int pid, void *data)
287 static void _create_bg(void)
295 if (system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf) < 0) {
296 _E("Failed to get a wallpaper: %d\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
298 _D("Menu-screen bg's image : %s", buf);
300 width = menu_screen_get_root_width();
301 height = menu_screen_get_root_height();
302 _D("width : %d, height : %d FOR BG", width, height);
304 bg = evas_object_data_get(menu_screen_get_win(), "bg");
306 _D("BG is NULL, Create!!");
309 rect = evas_object_rectangle_add(menu_screen_get_evas());
311 evas_object_data_set(menu_screen_get_win(), "rect", rect);
312 evas_object_color_set(rect, 0, 0, 0, 255);
313 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
314 evas_object_size_hint_min_set(rect, width, height);
315 evas_object_size_hint_max_set(rect, width, height);
316 elm_win_resize_object_add(menu_screen_get_win(), rect);
317 evas_object_show(rect);
319 bg = elm_image_add(menu_screen_get_win());
324 evas_object_data_set(menu_screen_get_win(), "bg", bg);
327 elm_image_aspect_fixed_set(bg, EINA_TRUE);
328 elm_image_fill_outside_set(bg, EINA_TRUE);
329 elm_image_preload_disabled_set(bg, EINA_FALSE);
331 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332 evas_object_size_hint_min_set(bg, width, height);
333 evas_object_size_hint_max_set(bg, width, height);
334 if (!elm_image_file_set(bg, buf, NULL)) {
335 _E("Failed to set image file : %s", buf);
338 elm_win_resize_object_add(menu_screen_get_win(), bg);
339 evas_object_show(bg);
347 static void _destroy_bg()
352 rect = evas_object_data_del(menu_screen_get_win(), "rect");
353 evas_object_del(rect);
355 bg = evas_object_data_del(menu_screen_get_win(), "bg");
361 static void _change_bg_cb(system_settings_key_e key, void *data)
363 _D("Background image is changed.");
369 static void _init_theme(void)
371 menu_screen_info.theme = elm_theme_new();
372 elm_theme_ref_set(menu_screen_info.theme, NULL);
373 elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
378 static void _fini_theme(void)
380 elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
381 elm_theme_free(menu_screen_info.theme);
382 menu_screen_info.theme = NULL;
388 static Evas_Object *_create_conformant(Evas_Object *win)
390 Evas_Object *conformant;
392 conformant = elm_conformant_add(win);
393 retv_if(NULL == conformant, NULL);
395 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
396 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
397 elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
398 evas_object_data_set(conformant, "win", win);
399 evas_object_show(conformant);
401 elm_win_resize_object_add(win, conformant);
402 elm_win_conformant_set(win, EINA_TRUE);
409 static void _destroy_conformant(Evas_Object *conformant)
411 evas_object_data_del(conformant, "win");
412 evas_object_del(conformant);
417 static bool _create_cb(void *data)
419 Evas_Object *conformant;
422 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas(PACKAGE, PACKAGE), false);
424 if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, _change_bg_cb, NULL) < 0) {
425 _E("Failed to register a settings change cb for %d\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
429 conformant = _create_conformant(menu_screen_info.win);
430 retv_if(NULL == conformant, false);
431 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
434 layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
435 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
436 if (NULL == layout) {
437 _E("Failed to load an edje object");
438 evas_object_del(menu_screen_info.win);
441 evas_object_data_set(menu_screen_info.win, "layout", layout);
443 elm_object_content_set(conformant, layout);
446 aul_listen_app_dead_signal(_dead_cb, NULL);
449 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
457 static void _terminate_cb(void *data)
459 Evas_Object *conformant;
462 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
465 if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN) < 0) {
466 _E("Failed to remove bgset [%s]\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
469 evas_object_hide(menu_screen_info.win);
474 layout = evas_object_data_del(menu_screen_info.win, "layout");
475 if (layout) layout_destroy(layout);
477 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
478 if (conformant) _destroy_conformant(conformant);
483 evas_object_del(menu_screen_info.win);
488 static void _pause_cb(void *data)
492 menu_screen_info.state = APP_STATE_PAUSE;
497 static void _resume_cb(void *data)
502 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
503 break_if(NULL == layout);
505 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
506 break_if(NULL == all_apps);
508 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
509 break_if(NULL == scroller);
511 page_scroller_focus(scroller);
514 menu_screen_info.state = APP_STATE_RESUME;
519 static void _app_control_cb(app_control_h service, void *data)
521 _D("START RESET : %d", menu_screen_info.state);
524 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
525 break_if(NULL == layout);
527 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
528 break_if(NULL == all_apps);
530 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
531 break_if(NULL == scroller);
533 page_scroller_focus(scroller);
539 static void _language_changed_cb(app_event_info_h event_info, void *data)
541 register unsigned int i;
542 register unsigned int j;
545 Evas_Object *all_apps;
546 Evas_Object *scroller;
549 unsigned int page_max_app;
551 _D("Language is changed");
553 if (false == menu_screen_info.is_done) {
557 layout = evas_object_data_get(menu_screen_info.win, "layout");
558 ret_if(NULL == layout);
559 all_apps = evas_object_data_get(layout, "all_apps");
560 ret_if(NULL == all_apps);
561 scroller = elm_object_part_content_get(all_apps, "content");
562 ret_if(NULL == scroller);
564 count = page_scroller_count_page(scroller);
565 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
566 for (i = 0; i < count; i ++) {
567 page = page_scroller_get_page_at(scroller, i);
569 if (mapbuf_is_enabled(page)) {
570 mapbuf_disable(page, 1);
573 for (j = 0; j < page_max_app; j ++) {
574 pkgmgrinfo_appinfo_h appinfo_h = NULL;
577 item = page_get_item_at(page, j);
580 if (pkgmgrinfo_appinfo_get_usr_appinfo(item_get_package(item), getuid(), &appinfo_h) < 0) {
581 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
584 if (pkgmgrinfo_appinfo_get_label(appinfo_h, &name) < 0) {
585 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
590 _D("Failed to get name for %s", item_get_package(item));
591 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
595 item_set_name(item, name, 0);
596 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
599 mapbuf_enable(page, 1);
605 static void _init(ui_app_lifecycle_callback_s *lifecycle_callback, app_event_handler_h *event_handlers)
607 lifecycle_callback->create = _create_cb;
608 lifecycle_callback->terminate = _terminate_cb;
609 lifecycle_callback->pause = _pause_cb;
610 lifecycle_callback->resume = _resume_cb;
611 lifecycle_callback->app_control = _app_control_cb;
613 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
614 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
615 ui_app_add_event_handler(&event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
616 ui_app_add_event_handler(&event_handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _language_changed_cb, NULL);
617 ui_app_add_event_handler(&event_handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
623 static void _fini(app_event_handler_h *event_handlers)
625 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_BATTERY]);
626 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_MEMORY]);
627 ui_app_remove_event_handler(event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED]);
628 ui_app_remove_event_handler(event_handlers[APP_EVENT_LANGUAGE_CHANGED]);
629 ui_app_remove_event_handler(event_handlers[APP_EVENT_REGION_FORMAT_CHANGED]);
635 int main(int argc, char *argv[])
637 ui_app_lifecycle_callback_s lifecycle_callback = {0, };
638 app_event_handler_h event_handlers[5] = {NULL, };
640 _init(&lifecycle_callback, event_handlers);
641 ui_app_main(argc, argv, &lifecycle_callback, NULL);
642 _fini(event_handlers);