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>
35 #include <pkgmgr-info.h>
42 #include "menu_screen.h"
45 #include "page_scroller.h"
49 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
51 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
52 #define LAYOUT_GROUP_NAME "layout"
56 // Define prototype of the "hidden API of AUL"
57 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
69 } menu_screen_info = {
70 .state = APP_STATE_PAUSE,
82 HAPI Evas *menu_screen_get_evas(void)
84 return menu_screen_info.evas;
89 HAPI int menu_screen_get_root_width(void)
91 return menu_screen_info.root_width;
96 HAPI int menu_screen_get_root_height(void)
98 return menu_screen_info.root_height;
103 HAPI Evas_Object *menu_screen_get_win(void)
105 return menu_screen_info.win;
110 HAPI Elm_Theme *menu_screen_get_theme(void)
112 return menu_screen_info.theme;
117 HAPI bool menu_screen_get_done(void)
119 return menu_screen_info.is_done;
124 HAPI void menu_screen_set_done(bool is_done)
126 menu_screen_info.is_done = is_done;
131 HAPI int menu_screen_get_state(void)
133 return menu_screen_info.state;
138 HAPI int menu_screen_is_tts(void)
140 return menu_screen_info.is_tts;
144 static Eina_Bool _appcore_flush_cb(void *data)
146 if (APP_STATE_PAUSE != menu_screen_info.state) return ECORE_CALLBACK_CANCEL;
147 if (0 != appcore_flush_memory()) _E("Cannot flush memory");
148 return ECORE_CALLBACK_CANCEL;
153 HAPI void menu_screen_inc_booting_state(void)
155 menu_screen_info.booting_state++;
156 if (BOOTING_STATE_DONE > menu_screen_info.booting_state) return;
158 menu_screen_error_e ret = MENU_SCREEN_ERROR_OK;
160 ret = pkgmgr_reserve_list_pop_request();
161 } while (MENU_SCREEN_ERROR_OK == ret);
163 /* Cache memory is cleared when the application paused (every time, after 5 seconds (in appcore)),
164 * but after running in a minimized mode (HIDE_LAUNCH) application have status AS_RUNNING.
165 * Application have status AS_PAUSED only after change of visibility to hidden condition by user (on hiding window)
166 * Cleaning must be performed only once after application loading in hidden condition
167 * (and stay in a hidden condition at time of cleaning).
169 if (APP_STATE_PAUSE == menu_screen_info.state)
170 ecore_timer_add(5, _appcore_flush_cb, NULL);
175 HAPI void menu_screen_dec_booting_state(void)
177 menu_screen_info.booting_state --;
182 HAPI int menu_screen_get_booting_state(void)
184 return menu_screen_info.booting_state;
189 static bool _is_emulator_on(void)
194 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
195 if (SYSTEM_INFO_ERROR_NONE != ret) {
202 if (!strncmp(model, "Emulator", strlen(model))) {
203 _D("This model is on Emulator");
208 _D("This model is NOT on Emulator");
215 static menu_screen_error_e _create_canvas(char *name, char *title)
217 //Ecore_X_Atom ATOM_WM_WINDOW_ROLE;
220 if (_is_emulator_on()) {
221 _D("ELM_ENGINE is set as [software_x11]");
222 elm_config_accel_preference_set("opengl");
224 buf = vconf_get_str(MENU_SCREEN_ENGINE);
226 _D("ELM_ENGINE is set as [%s]", buf);
227 elm_config_accel_preference_set(buf);
230 _D("ELM_ENGINE is set as [gl]");
231 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)
297 static int trigger = 0;
301 int ret = SYSTEM_SETTINGS_ERROR_NONE;
303 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf);
304 _D("result: %d, value: %s", ret, buf);
307 width = menu_screen_get_root_width();
308 height = menu_screen_get_root_height();
310 bg = evas_object_data_get(menu_screen_get_win(), "bg");
314 rect = evas_object_rectangle_add(menu_screen_get_evas());
315 ret_if(NULL == rect);
316 evas_object_data_set(menu_screen_get_win(), "rect", rect);
317 evas_object_color_set(rect, 0, 0, 0, 255);
318 evas_object_size_hint_min_set(rect, width, height);
319 evas_object_size_hint_max_set(rect, width, height);
320 elm_win_resize_object_add(menu_screen_get_win(), rect);
321 evas_object_show(rect);
323 bg = evas_object_image_add(menu_screen_get_evas());
328 evas_object_image_load_orientation_set(bg, EINA_TRUE);
329 evas_object_data_set(menu_screen_get_win(), "bg", bg);
340 evas_object_image_file_set(bg, buf, key);
341 evas_object_image_size_get(bg, &w, &h);
342 evas_object_image_filled_set(bg, 1);
344 wf = (double) width / (double) w;
345 hf = (double) height / (double) h;
347 f = wf < hf ? hf : wf;
349 w = (int) ((double) f * (double) w);
350 h = (int) ((double) f * (double) h);
352 evas_object_image_load_size_set(bg, w, h);
353 evas_object_image_fill_set(bg, 0, 0, w, h);
354 elm_win_resize_object_add(menu_screen_get_win(), bg);
355 evas_object_show(bg);
363 static void _destroy_bg()
368 rect = evas_object_data_del(menu_screen_get_win(), "rect");
369 evas_object_del(rect);
371 bg = evas_object_data_del(menu_screen_get_win(), "bg");
377 static void _change_bg_cb(system_settings_key_e key, void *data)
379 _D("Background image is changed.");
385 static void _init_theme(void)
387 menu_screen_info.theme = elm_theme_new();
388 elm_theme_ref_set(menu_screen_info.theme, NULL);
389 elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
394 static void _fini_theme(void)
396 elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
397 elm_theme_free(menu_screen_info.theme);
398 menu_screen_info.theme = NULL;
404 static Evas_Object *_create_conformant(Evas_Object *win)
406 Evas_Object *conformant;
408 conformant = elm_conformant_add(win);
409 retv_if(NULL == conformant, NULL);
411 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
412 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
413 elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
414 evas_object_data_set(conformant, "win", win);
415 evas_object_show(conformant);
417 elm_win_resize_object_add(win, conformant);
418 elm_win_conformant_set(win, EINA_TRUE);
425 static void _destroy_conformant(Evas_Object *conformant)
427 evas_object_data_del(conformant, "win");
428 evas_object_del(conformant);
432 static char *_replace_str(char *str, const char *before, const char *after)
434 retv_if(NULL == str, NULL);
435 retv_if(NULL == before, NULL);
436 retv_if(NULL == after, NULL);
438 size_t before_len = strlen(before);
439 retv_if(before_len < 1, str);
441 size_t after_len = strlen(after);
443 if (after_len != before_len) {
444 for (i = 0; str[i] != '\0';) {
445 if (0 == memcmp(&str[i], before, before_len)) {
457 result = malloc(i + 1 + count * (after_len - before_len));
458 retv_if(result == NULL, NULL);
463 if (0 == memcmp(str, before, before_len)) {
464 memcpy(sr, after, after_len);
478 static bool _create_cb(void *data)
480 Evas_Object *conformant;
483 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas(PACKAGE, PACKAGE), false);
485 //if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, _change_bg_cb, NULL) < 0) {
486 // _E("Failed to register a settings change cb for %s\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
490 conformant = _create_conformant(menu_screen_info.win);
491 retv_if(NULL == conformant, false);
492 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
495 layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
496 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
497 if (NULL == layout) {
498 _E("Failed to load an edje object");
499 evas_object_del(menu_screen_info.win);
502 evas_object_data_set(menu_screen_info.win, "layout", layout);
504 elm_object_content_set(conformant, layout);
507 aul_listen_app_dead_signal(_dead_cb, NULL);
510 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
518 static void _terminate_cb(void *data)
520 Evas_Object *conformant;
523 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
526 if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN) < 0) {
527 _E("Failed to remove bgset [%s]\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
530 evas_object_hide(menu_screen_info.win);
535 layout = evas_object_data_del(menu_screen_info.win, "layout");
536 if (layout) layout_destroy(layout);
538 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
539 if (conformant) _destroy_conformant(conformant);
544 evas_object_del(menu_screen_info.win);
549 static void _pause_cb(void *data)
553 menu_screen_info.state = APP_STATE_PAUSE;
558 static void _resume_cb(void *data)
563 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
564 break_if(NULL == layout);
566 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
567 break_if(NULL == all_apps);
569 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
570 break_if(NULL == scroller);
572 page_scroller_focus(scroller);
575 menu_screen_info.state = APP_STATE_RESUME;
580 static void _app_control_cb(app_control_h service, void *data)
582 _D("START RESET : %d", menu_screen_info.state);
585 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
586 break_if(NULL == layout);
588 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
589 break_if(NULL == all_apps);
591 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
592 break_if(NULL == scroller);
594 page_scroller_focus(scroller);
600 static void _language_changed_cb(app_event_info_h event_info, void *data)
602 register unsigned int i;
603 register unsigned int j;
606 Evas_Object *all_apps;
607 Evas_Object *scroller;
610 unsigned int page_max_app;
612 _D("Language is changed");
614 if (false == menu_screen_info.is_done) {
618 layout = evas_object_data_get(menu_screen_info.win, "layout");
619 ret_if(NULL == layout);
620 all_apps = evas_object_data_get(layout, "all_apps");
621 ret_if(NULL == all_apps);
622 scroller = elm_object_part_content_get(all_apps, "content");
623 ret_if(NULL == scroller);
625 count = page_scroller_count_page(scroller);
626 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
627 for (i = 0; i < count; i ++) {
628 page = page_scroller_get_page_at(scroller, i);
630 if (mapbuf_is_enabled(page)) {
631 mapbuf_disable(page, 1);
634 for (j = 0; j < page_max_app; j ++) {
635 pkgmgrinfo_appinfo_h appinfo_h = NULL;
638 item = page_get_item_at(page, j);
641 if (pkgmgrinfo_appinfo_get_appinfo(item_get_package(item), &appinfo_h) < 0) {
642 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
645 if (pkgmgrinfo_appinfo_get_label(appinfo_h, &name) < 0) {
646 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
651 _D("Failed to get name for %s", item_get_package(item));
652 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
656 item_set_name(item, name, 0);
657 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
660 mapbuf_enable(page, 1);
666 static void _init(ui_app_lifecycle_callback_s *lifecycle_callback, app_event_handler_h *event_handlers)
668 lifecycle_callback->create = _create_cb;
669 lifecycle_callback->terminate = _terminate_cb;
670 lifecycle_callback->pause = _pause_cb;
671 lifecycle_callback->resume = _resume_cb;
672 lifecycle_callback->app_control = _app_control_cb;
674 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
675 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
676 ui_app_add_event_handler(&event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
677 ui_app_add_event_handler(&event_handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _language_changed_cb, NULL);
678 ui_app_add_event_handler(&event_handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
684 static void _fini(app_event_handler_h *event_handlers)
686 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_BATTERY]);
687 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_MEMORY]);
688 ui_app_remove_event_handler(event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED]);
689 ui_app_remove_event_handler(event_handlers[APP_EVENT_LANGUAGE_CHANGED]);
690 ui_app_remove_event_handler(event_handlers[APP_EVENT_REGION_FORMAT_CHANGED]);
696 static void _init_reference_value(void)
698 preference_set_string(MENU_SCREEN_ENGINE, "gl");
702 int main(int argc, char *argv[])
705 ui_app_lifecycle_callback_s lifecycle_callback = {0, };
706 app_event_handler_h event_handlers[5] = {NULL, };
708 _init(&lifecycle_callback, event_handlers);
709 ui_app_main(argc, argv, &lifecycle_callback, NULL);
710 _fini(event_handlers);