4 * Copyright (c) 2009-2014 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.
25 #include <appcore-efl.h>
27 //#include <Ecore_X.h>
28 #include <Elementary.h>
30 #include <system_info.h>
32 #include <app_preference.h>
33 //#include <system_info_internal.h>
34 #include <system_settings.h>
41 #include "menu_screen.h"
44 #include "page_scroller.h"
48 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
50 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
51 #define LAYOUT_GROUP_NAME "layout"
55 // Define prototype of the "hidden API of AUL"
56 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
68 } menu_screen_info = {
69 .state = APP_STATE_PAUSE,
81 HAPI Evas *menu_screen_get_evas(void)
83 return menu_screen_info.evas;
88 HAPI int menu_screen_get_root_width(void)
90 return menu_screen_info.root_width;
95 HAPI int menu_screen_get_root_height(void)
97 return menu_screen_info.root_height;
102 HAPI Evas_Object *menu_screen_get_win(void)
104 return menu_screen_info.win;
109 HAPI Elm_Theme *menu_screen_get_theme(void)
111 return menu_screen_info.theme;
116 HAPI bool menu_screen_get_done(void)
118 return menu_screen_info.is_done;
123 HAPI void menu_screen_set_done(bool is_done)
125 menu_screen_info.is_done = is_done;
130 HAPI int menu_screen_get_state(void)
132 return menu_screen_info.state;
137 HAPI int menu_screen_is_tts(void)
139 return menu_screen_info.is_tts;
143 static Eina_Bool _appcore_flush_cb(void *data)
145 if (APP_STATE_PAUSE != menu_screen_info.state) return ECORE_CALLBACK_CANCEL;
146 if (0 != appcore_flush_memory()) _E("Cannot flush memory");
147 return ECORE_CALLBACK_CANCEL;
152 HAPI void menu_screen_inc_booting_state(void)
154 menu_screen_info.booting_state++;
155 if (BOOTING_STATE_DONE > menu_screen_info.booting_state) return;
157 menu_screen_error_e ret = MENU_SCREEN_ERROR_OK;
159 ret = pkgmgr_reserve_list_pop_request();
160 } while (MENU_SCREEN_ERROR_OK == ret);
162 /* Cache memory is cleared when the application paused (every time, after 5 seconds (in appcore)),
163 * but after running in a minimized mode (HIDE_LAUNCH) application have status AS_RUNNING.
164 * Application have status AS_PAUSED only after change of visibility to hidden condition by user (on hiding window)
165 * Cleaning must be performed only once after application loading in hidden condition
166 * (and stay in a hidden condition at time of cleaning).
168 if (APP_STATE_PAUSE == menu_screen_info.state)
169 ecore_timer_add(5, _appcore_flush_cb, NULL);
174 HAPI void menu_screen_dec_booting_state(void)
176 menu_screen_info.booting_state --;
181 HAPI int menu_screen_get_booting_state(void)
183 return menu_screen_info.booting_state;
188 static bool _is_emulator_on(void)
193 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
194 if (SYSTEM_INFO_ERROR_NONE != ret) {
201 if (!strncmp(model, "Emulator", strlen(model))) {
202 _D("This model is on Emulator");
207 _D("This model is NOT on Emulator");
214 static menu_screen_error_e _create_canvas(char *name, char *title)
216 //Ecore_X_Atom ATOM_WM_WINDOW_ROLE;
219 if (_is_emulator_on()) {
220 _D("ELM_ENGINE is set as [software_x11]");
221 elm_config_accel_preference_set("opengl");
223 buf = vconf_get_str(MENU_SCREEN_ENGINE);
225 _D("ELM_ENGINE is set as [%s]", buf);
226 elm_config_accel_preference_set(buf);
229 _D("ELM_ENGINE is set as [gl]");
230 elm_config_accel_preference_set("gl");
235 menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
236 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
239 elm_win_title_set(menu_screen_info.win, title);
241 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
242 elm_win_screen_size_get(menu_screen_info.win, NULL, NULL, &menu_screen_info.root_width, &menu_screen_info.root_height);
244 //ecore_x_icccm_name_class_set(elm_win_xwindow_get(menu_screen_info.win), "MENU_SCREEN", "MENU_SCREEN");
245 //ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
246 //if (ATOM_WM_WINDOW_ROLE) {
247 // ecore_x_window_prop_string_set(elm_win_xwindow_get(menu_screen_info.win), ATOM_WM_WINDOW_ROLE, "MENU_SCREEN");
249 // _D("Failed to set the window role as MENU_SCREEN");
252 //elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
253 //evas_object_resize(menu_screen_info.win, menu_screen_get_root_width(), menu_screen_get_root_height());
255 menu_screen_info.evas = evas_object_evas_get(menu_screen_info.win);
256 if (!menu_screen_info.evas) {
257 _E("[%s] Failed to get the evas object", __func__);
260 menu_screen_info.ee = ecore_evas_ecore_evas_get(menu_screen_info.evas);
261 if (!menu_screen_info.ee) {
262 _E("[%s] Failed to get ecore_evas object", __func__);
265 evas_object_size_hint_min_set(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
266 evas_object_size_hint_max_set(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
267 evas_object_resize(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
268 evas_object_show(menu_screen_info.win);
270 return MENU_SCREEN_ERROR_OK;
275 static void _destroy_canvas(void)
277 evas_object_del(menu_screen_info.win);
282 static int _dead_cb(int pid, void *data)
289 static void _create_bg(void)
296 static int trigger = 0;
301 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf);
304 width = menu_screen_get_root_width();
305 height = menu_screen_get_root_height();
307 bg = evas_object_data_get(menu_screen_get_win(), "bg");
311 rect = evas_object_rectangle_add(menu_screen_get_evas());
312 ret_if(NULL == rect);
313 evas_object_data_set(menu_screen_get_win(), "rect", rect);
314 evas_object_color_set(rect, 0, 0, 0, 255);
315 evas_object_size_hint_min_set(rect, width, height);
316 evas_object_size_hint_max_set(rect, width, height);
317 elm_win_resize_object_add(menu_screen_get_win(), rect);
318 evas_object_show(rect);
320 bg = evas_object_image_add(menu_screen_get_evas());
325 evas_object_image_load_orientation_set(bg, EINA_TRUE);
326 evas_object_data_set(menu_screen_get_win(), "bg", bg);
337 evas_object_image_file_set(bg, buf, key);
338 evas_object_image_size_get(bg, &w, &h);
339 evas_object_image_filled_set(bg, 1);
341 wf = (double) width / (double) w;
342 hf = (double) height / (double) h;
344 f = wf < hf ? hf : wf;
346 w = (int) ((double) f * (double) w);
347 h = (int) ((double) f * (double) h);
349 evas_object_image_load_size_set(bg, w, h);
350 evas_object_image_fill_set(bg, 0, 0, w, h);
351 elm_win_resize_object_add(menu_screen_get_win(), bg);
352 evas_object_show(bg);
360 static void _destroy_bg()
365 rect = evas_object_data_del(menu_screen_get_win(), "rect");
366 evas_object_del(rect);
368 bg = evas_object_data_del(menu_screen_get_win(), "bg");
374 static void _change_bg_cb(keynode_t *node, void *data)
376 _D("Background image is changed.");
382 static void _init_theme(void)
384 menu_screen_info.theme = elm_theme_new();
385 elm_theme_ref_set(menu_screen_info.theme, NULL);
386 elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
391 static void _fini_theme(void)
393 elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
394 elm_theme_free(menu_screen_info.theme);
395 menu_screen_info.theme = NULL;
401 static Evas_Object *_create_conformant(Evas_Object *win)
403 Evas_Object *conformant;
405 conformant = elm_conformant_add(win);
406 retv_if(NULL == conformant, NULL);
408 elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSLUCENT);
409 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
410 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
411 evas_object_data_set(conformant, "win", win);
412 evas_object_show(conformant);
414 elm_win_resize_object_add(win, conformant);
415 elm_win_conformant_set(win, EINA_TRUE);
422 static void _destroy_conformant(Evas_Object *conformant)
424 evas_object_data_del(conformant, "win");
425 evas_object_del(conformant);
429 static char *_replace_str(char *str, const char *before, const char *after)
431 retv_if(NULL == str, NULL);
432 retv_if(NULL == before, NULL);
433 retv_if(NULL == after, NULL);
435 size_t before_len = strlen(before);
436 retv_if(before_len < 1, str);
438 size_t after_len = strlen(after);
440 if (after_len != before_len) {
441 for (i = 0; str[i] != '\0';) {
442 if (0 == memcmp(&str[i], before, before_len)) {
454 result = malloc(i + 1 + count * (after_len - before_len));
455 retv_if(result == NULL, NULL);
460 if (0 == memcmp(str, before, before_len)) {
461 memcpy(sr, after, after_len);
475 static bool _create_cb(void *data)
477 Evas_Object *conformant;
480 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas(PACKAGE, PACKAGE), false);
482 //if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, _change_bg_cb, NULL) < 0) {
483 // _E("Failed to register a settings change cb for %s\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
487 conformant = _create_conformant(menu_screen_info.win);
488 retv_if(NULL == conformant, false);
489 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
492 layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
493 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
494 if (NULL == layout) {
495 _E("Failed to load an edje object");
496 evas_object_del(menu_screen_info.win);
499 evas_object_data_set(menu_screen_info.win, "layout", layout);
501 elm_object_content_set(conformant, layout);
504 aul_listen_app_dead_signal(_dead_cb, NULL);
507 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
515 static void _terminate_cb(void *data)
517 Evas_Object *conformant;
520 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
523 if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN) < 0) {
524 _E("Failed to remove bgset [%s]\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
527 evas_object_hide(menu_screen_info.win);
532 layout = evas_object_data_del(menu_screen_info.win, "layout");
533 if (layout) layout_destroy(layout);
535 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
536 if (conformant) _destroy_conformant(conformant);
541 evas_object_del(menu_screen_info.win);
546 static void _pause_cb(void *data)
550 menu_screen_info.state = APP_STATE_PAUSE;
555 static void _resume_cb(void *data)
560 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
561 break_if(NULL == layout);
563 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
564 break_if(NULL == all_apps);
566 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
567 break_if(NULL == scroller);
569 page_scroller_focus(scroller);
572 menu_screen_info.state = APP_STATE_RESUME;
577 static void _app_control_cb(app_control_h service, void *data)
579 _D("START RESET : %d", menu_screen_info.state);
582 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
583 break_if(NULL == layout);
585 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
586 break_if(NULL == all_apps);
588 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
589 break_if(NULL == scroller);
591 page_scroller_focus(scroller);
597 static void _language_changed_cb(app_event_info_h event_info, void *data)
599 register unsigned int i;
600 register unsigned int j;
603 Evas_Object *all_apps;
604 Evas_Object *scroller;
607 unsigned int page_max_app;
609 _D("Language is changed");
611 if (false == menu_screen_info.is_done) {
615 layout = evas_object_data_get(menu_screen_info.win, "layout");
616 ret_if(NULL == layout);
617 all_apps = evas_object_data_get(layout, "all_apps");
618 ret_if(NULL == all_apps);
619 scroller = elm_object_part_content_get(all_apps, "content");
620 ret_if(NULL == scroller);
622 count = page_scroller_count_page(scroller);
623 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
624 for (i = 0; i < count; i ++) {
625 page = page_scroller_get_page_at(scroller, i);
627 if (mapbuf_is_enabled(page)) {
628 mapbuf_disable(page, 1);
631 for (j = 0; j < page_max_app; j ++) {
635 item = page_get_item_at(page, j);
638 if (ail_get_appinfo(item_get_package(item), &ai) < 0) {
639 ail_destroy_appinfo(ai);
642 if (ail_appinfo_get_str(ai, AIL_PROP_NAME_STR, &name) < 0) {
643 ail_destroy_appinfo(ai);
648 _D("Failed to get name for %s", item_get_package(item));
649 ail_destroy_appinfo(ai);
653 item_set_name(item, name, 0);
654 ail_destroy_appinfo(ai);
657 mapbuf_enable(page, 1);
663 static void _init(ui_app_lifecycle_callback_s *lifecycle_callback, app_event_handler_h *event_handlers)
665 lifecycle_callback->create = _create_cb;
666 lifecycle_callback->terminate = _terminate_cb;
667 lifecycle_callback->pause = _pause_cb;
668 lifecycle_callback->resume = _resume_cb;
669 lifecycle_callback->app_control = _app_control_cb;
671 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
672 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
673 ui_app_add_event_handler(&event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
674 ui_app_add_event_handler(&event_handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _language_changed_cb, NULL);
675 ui_app_add_event_handler(&event_handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
681 static void _fini(app_event_handler_h *event_handlers)
683 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_BATTERY]);
684 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_MEMORY]);
685 ui_app_remove_event_handler(event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED]);
686 ui_app_remove_event_handler(event_handlers[APP_EVENT_LANGUAGE_CHANGED]);
687 ui_app_remove_event_handler(event_handlers[APP_EVENT_REGION_FORMAT_CHANGED]);
693 static void _init_reference_value(void)
695 preference_set_string(MENU_SCREEN_ENGINE, "gl");
699 int main(int argc, char *argv[])
702 ui_app_lifecycle_callback_s lifecycle_callback = {0, };
703 app_event_handler_h event_handlers[5] = {NULL, };
705 _init(&lifecycle_callback, event_handlers);
706 ui_app_main(argc, argv, &lifecycle_callback, NULL);
707 _fini(event_handlers);