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.
25 #include <Elementary.h>
27 #include <system_info.h>
29 #include <app_preference.h>
30 #include <system_settings.h>
31 #include <app_manager.h>
38 #include "menu_screen.h"
41 #include "page_scroller.h"
45 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
46 #define LAYOUT_GROUP_NAME "layout"
49 // Define prototype of the "hidden API of AUL"
50 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
60 } menu_screen_info = {
61 .state = APP_STATE_PAUSE,
71 HAPI Evas *menu_screen_get_evas(void)
73 return menu_screen_info.evas;
78 HAPI int menu_screen_get_root_width(void)
80 return menu_screen_info.root_width;
85 HAPI int menu_screen_get_root_height(void)
87 return menu_screen_info.root_height;
92 HAPI Evas_Object *menu_screen_get_win(void)
94 return menu_screen_info.win;
99 HAPI Elm_Theme *menu_screen_get_theme(void)
101 return menu_screen_info.theme;
106 HAPI bool menu_screen_get_done(void)
108 return menu_screen_info.is_done;
113 HAPI void menu_screen_set_done(bool is_done)
115 menu_screen_info.is_done = is_done;
120 HAPI int menu_screen_get_state(void)
122 return menu_screen_info.state;
127 static bool _is_emulator_on(void)
132 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
133 if (SYSTEM_INFO_ERROR_NONE != ret) {
140 if (!strncmp(model, "Emulator", strlen(model))) {
141 _D("This model is on Emulator");
146 _D("This model is NOT on Emulator");
153 static menu_screen_error_e _create_canvas(char *name, char *title)
157 if (_is_emulator_on()) {
158 _D("ELM_ENGINE is set as [software_x11]");
159 elm_config_accel_preference_set("opengl");
161 buf = vconf_get_str(MENU_SCREEN_ENGINE);
163 _D("ELM_ENGINE is set as [%s]", buf);
164 elm_config_accel_preference_set(buf);
167 _D("ELM_ENGINE is set as [gl]");
168 elm_config_accel_preference_set("gl");
172 menu_screen_info.win = elm_win_util_standard_add(name, name);
173 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
176 elm_win_title_set(menu_screen_info.win, title);
178 _D("elm_scale: %f", elm_app_base_scale_get());
179 _D("config_scale: %f", elm_config_scale_get());
181 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
182 elm_win_screen_size_get(menu_screen_info.win, NULL, NULL, &menu_screen_info.root_width, &menu_screen_info.root_height);
183 _D("menu-screen window size:: width: %d, height: %d", menu_screen_info.root_width, menu_screen_info.root_height);
185 elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
187 menu_screen_info.evas = evas_object_evas_get(menu_screen_info.win);
188 if (!menu_screen_info.evas) {
189 _E("[%s] Failed to get the evas object", __func__);
192 menu_screen_info.ee = ecore_evas_ecore_evas_get(menu_screen_info.evas);
193 if (!menu_screen_info.ee) {
194 _E("[%s] Failed to get ecore_evas object", __func__);
197 evas_object_show(menu_screen_info.win);
199 return MENU_SCREEN_ERROR_OK;
204 static void _destroy_canvas(void)
206 evas_object_del(menu_screen_info.win);
211 static int _dead_cb(int pid, void *data)
218 static void _create_bg(void)
226 if (system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf) < 0) {
227 _E("Failed to get a wallpaper: %d\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
229 _D("Menu-screen bg's image : %s", buf);
231 width = menu_screen_get_root_width();
232 height = menu_screen_get_root_height();
233 _D("width : %d, height : %d FOR BG", width, height);
235 bg = evas_object_data_get(menu_screen_get_win(), "bg");
237 _D("BG is NULL, Create!!");
240 rect = evas_object_rectangle_add(menu_screen_get_evas());
245 evas_object_data_set(menu_screen_get_win(), "rect", rect);
246 evas_object_color_set(rect, 0, 0, 0, 255);
247 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
248 evas_object_size_hint_min_set(rect, width, height);
249 evas_object_size_hint_max_set(rect, width, height);
250 elm_win_resize_object_add(menu_screen_get_win(), rect);
251 evas_object_show(rect);
253 bg = elm_image_add(menu_screen_get_win());
258 evas_object_data_set(menu_screen_get_win(), "bg", bg);
261 elm_image_aspect_fixed_set(bg, EINA_TRUE);
262 elm_image_fill_outside_set(bg, EINA_TRUE);
263 elm_image_preload_disabled_set(bg, EINA_FALSE);
265 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
266 evas_object_size_hint_min_set(bg, width, height);
267 evas_object_size_hint_max_set(bg, width, height);
268 if (!elm_image_file_set(bg, buf, NULL)) {
269 _E("Failed to set image file : %s", buf);
270 if (!elm_image_file_set(bg, util_get_file_path(IMAGE_DIR"/home_001.png"), NULL)) {
271 _E("Failed to set default image file: %s", util_get_file_path(IMAGE_DIR"/home_001.png"));
276 elm_win_resize_object_add(menu_screen_get_win(), bg);
277 evas_object_show(bg);
285 static void _destroy_bg()
290 rect = evas_object_data_del(menu_screen_get_win(), "rect");
291 evas_object_del(rect);
293 bg = evas_object_data_del(menu_screen_get_win(), "bg");
299 static void _change_bg_cb(system_settings_key_e key, void *data)
301 _D("Background image is changed.");
307 static void _init_theme(void)
309 menu_screen_info.theme = elm_theme_new();
310 elm_theme_ref_set(menu_screen_info.theme, NULL);
311 elm_theme_extension_add(menu_screen_info.theme, util_get_file_path(EDJE_DIR"/index.edj"));
316 static void _fini_theme(void)
318 elm_theme_extension_del(menu_screen_info.theme, util_get_file_path(EDJE_DIR"/index.edj"));
319 elm_theme_free(menu_screen_info.theme);
320 menu_screen_info.theme = NULL;
326 static Evas_Object *_create_conformant(Evas_Object *win)
328 Evas_Object *conformant;
330 conformant = elm_conformant_add(win);
331 retv_if(NULL == conformant, NULL);
333 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
334 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
335 elm_win_indicator_opacity_set(menu_screen_info.win, ELM_WIN_INDICATOR_TRANSLUCENT);
336 elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
337 evas_object_data_set(conformant, "win", win);
338 evas_object_show(conformant);
340 elm_win_resize_object_add(win, conformant);
341 elm_win_conformant_set(win, EINA_TRUE);
348 static void _destroy_conformant(Evas_Object *conformant)
350 evas_object_data_del(conformant, "win");
351 evas_object_del(conformant);
356 static bool _create_cb(void *data)
358 Evas_Object *conformant;
361 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas(PACKAGE, PACKAGE), false);
363 if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, _change_bg_cb, NULL) < 0) {
364 _E("Failed to register a settings change cb for %d\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
368 conformant = _create_conformant(menu_screen_info.win);
369 retv_if(NULL == conformant, false);
370 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
373 layout = layout_create(conformant, util_get_file_path(EDJE_DIR"/layout_portrait.edj"), LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
374 if (NULL == layout) {
375 _E("Failed to load an edje object");
376 evas_object_del(menu_screen_info.win);
379 evas_object_data_set(menu_screen_info.win, "layout", layout);
381 elm_object_content_set(conformant, layout);
384 aul_listen_app_dead_signal(_dead_cb, NULL);
387 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
395 static void _terminate_cb(void *data)
397 Evas_Object *conformant;
400 // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
402 if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN) < 0) {
403 _E("Failed to remove bgset [%s]\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
406 evas_object_hide(menu_screen_info.win);
411 layout = evas_object_data_del(menu_screen_info.win, "layout");
412 if (layout) layout_destroy(layout);
414 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
415 if (conformant) _destroy_conformant(conformant);
420 evas_object_del(menu_screen_info.win);
425 static void _pause_cb(void *data)
429 menu_screen_info.state = APP_STATE_PAUSE;
434 static void _resume_cb(void *data)
439 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
440 break_if(NULL == layout);
442 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
443 break_if(NULL == all_apps);
445 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
446 break_if(NULL == scroller);
448 page_scroller_focus(scroller);
451 menu_screen_info.state = APP_STATE_RESUME;
456 static void _app_control_cb(app_control_h service, void *data)
458 _D("START RESET : %d", menu_screen_info.state);
461 Evas_Object *layout = evas_object_data_get(menu_screen_info.win, "layout");
462 break_if(NULL == layout);
464 Evas_Object *all_apps = evas_object_data_get(layout, "all_apps");
465 break_if(NULL == all_apps);
467 Evas_Object *scroller = elm_object_part_content_get(all_apps, "content");
468 break_if(NULL == scroller);
470 page_scroller_focus(scroller);
476 static void _language_changed_cb(app_event_info_h event_info, void *data)
478 register unsigned int i;
479 register unsigned int j;
482 Evas_Object *all_apps;
483 Evas_Object *scroller;
486 unsigned int page_max_app;
488 _D("Language is changed");
490 if (false == menu_screen_info.is_done) {
494 layout = evas_object_data_get(menu_screen_info.win, "layout");
495 ret_if(NULL == layout);
496 all_apps = evas_object_data_get(layout, "all_apps");
497 ret_if(NULL == all_apps);
498 scroller = elm_object_part_content_get(all_apps, "content");
499 ret_if(NULL == scroller);
501 count = page_scroller_count_page(scroller);
502 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
503 for (i = 0; i < count; i++) {
504 page = page_scroller_get_page_at(scroller, i);
506 if (mapbuf_is_enabled(page)) {
507 mapbuf_disable(page, 1);
510 for (j = 0; j < page_max_app; j++) {
511 app_info_h app_info = NULL;
516 item = page_get_item_at(page, j);
519 package = item_get_package(item);
520 if (!package) continue;
522 ret = app_manager_get_app_info(package, &app_info);
523 if (ret != APP_MANAGER_ERROR_NONE || !app_info) {
524 _E("Failed to get app info");
527 ret = app_info_get_label(app_info, &name);
528 if (APP_MANAGER_ERROR_NONE != ret) {
529 _E("Failed to get label from : %s", item_get_package(item));
532 _D("Changed Language name: %s", name);
535 item_set_name(item, name, 0);
538 mapbuf_enable(page, 1);
544 static void _init(ui_app_lifecycle_callback_s *lifecycle_callback, app_event_handler_h *event_handlers)
546 lifecycle_callback->create = _create_cb;
547 lifecycle_callback->terminate = _terminate_cb;
548 lifecycle_callback->pause = _pause_cb;
549 lifecycle_callback->resume = _resume_cb;
550 lifecycle_callback->app_control = _app_control_cb;
552 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
553 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
554 ui_app_add_event_handler(&event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
555 ui_app_add_event_handler(&event_handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _language_changed_cb, NULL);
556 ui_app_add_event_handler(&event_handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
562 static void _fini(app_event_handler_h *event_handlers)
564 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_BATTERY]);
565 ui_app_remove_event_handler(event_handlers[APP_EVENT_LOW_MEMORY]);
566 ui_app_remove_event_handler(event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED]);
567 ui_app_remove_event_handler(event_handlers[APP_EVENT_LANGUAGE_CHANGED]);
568 ui_app_remove_event_handler(event_handlers[APP_EVENT_REGION_FORMAT_CHANGED]);
574 int main(int argc, char *argv[])
576 ui_app_lifecycle_callback_s lifecycle_callback = {0, };
577 app_event_handler_h event_handlers[5] = {NULL, };
579 _init(&lifecycle_callback, event_handlers);
580 ui_app_main(argc, argv, &lifecycle_callback, NULL);
581 _fini(event_handlers);