4 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <Elementary.h>
25 #include <system_info.h>
32 #include "menu_screen.h"
35 #include "page_scroller.h"
38 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
40 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
41 #define LAYOUT_GROUP_NAME "layout"
45 // Define prototype of the "hidden API of AUL"
46 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
52 } menu_screen_info = {
53 .state = APP_STATE_PAUSE,
61 HAPI Evas *menu_screen_get_evas(void)
63 return evas_object_evas_get(menu_screen_info.win);
67 HAPI int menu_screen_get_root_width(void)
70 elm_win_screen_size_get(menu_screen_get_win(), NULL, NULL, &width, NULL);
76 HAPI int menu_screen_get_root_height(void)
79 elm_win_screen_size_get(menu_screen_get_win(), NULL, NULL, NULL, &height);
85 HAPI Evas_Object *menu_screen_get_win(void)
87 return menu_screen_info.win;
92 HAPI Elm_Theme *menu_screen_get_theme(void)
94 return menu_screen_info.theme;
99 HAPI bool menu_screen_get_done(void)
101 return menu_screen_info.is_done;
106 HAPI void menu_screen_set_done(bool is_done)
108 menu_screen_info.is_done = is_done;
113 static menu_screen_error_e _create_canvas(char *name, char *title)
116 menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
117 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
120 elm_win_title_set(menu_screen_info.win, title);
122 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
124 elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
125 evas_object_resize(menu_screen_info.win, menu_screen_get_root_width(), menu_screen_get_root_height());
127 evas_object_show(menu_screen_info.win);
129 return MENU_SCREEN_ERROR_OK;
134 static void _destroy_canvas(void)
136 evas_object_del(menu_screen_info.win);
141 static int _dead_cb(int pid, void *data)
143 evas_object_show(menu_screen_get_win());
149 static void _create_bg(void)
156 static int trigger = 0;
161 buf = vconf_get_str(VCONFKEY_BGSET);
164 width = menu_screen_get_root_width();
165 height = menu_screen_get_root_height();
167 bg = evas_object_data_get(menu_screen_get_win(), "bg");
171 rect = evas_object_rectangle_add(menu_screen_get_evas());
172 ret_if(NULL == rect);
173 evas_object_data_set(menu_screen_get_win(), "rect", rect);
174 evas_object_color_set(rect, 0, 0, 0, 255);
175 evas_object_size_hint_min_set(rect, width, height);
176 evas_object_size_hint_max_set(rect, width, height);
177 evas_object_resize(rect, width, height);
178 evas_object_show(rect);
180 bg = evas_object_image_add(menu_screen_get_evas());
185 evas_object_image_load_orientation_set(bg, EINA_TRUE);
186 evas_object_data_set(menu_screen_get_win(), "bg", bg);
197 evas_object_image_file_set(bg, buf, key);
198 evas_object_image_size_get(bg, &w, &h);
199 evas_object_image_filled_set(bg, 1);
201 wf = (double) width / (double) w;
202 hf = (double) height / (double) h;
204 f = wf < hf ? hf : wf;
206 w = (int) ((double) f * (double) w);
207 h = (int) ((double) f * (double) h);
209 evas_object_image_load_size_set(bg, w, h);
210 evas_object_image_fill_set(bg, 0, 0, w, h);
211 evas_object_move(bg, (width - w) / 2, (height - h) / 2);
212 evas_object_resize(bg, w, h);
213 evas_object_show(bg);
221 static void _destroy_bg()
226 rect = evas_object_data_del(menu_screen_get_win(), "rect");
227 evas_object_del(rect);
229 bg = evas_object_data_del(menu_screen_get_win(), "bg");
235 static void _change_bg_cb(keynode_t *node, void *data)
237 _D("Background image is changed.");
243 static void _init_theme(void)
245 menu_screen_info.theme = elm_theme_new();
246 elm_theme_ref_set(menu_screen_info.theme, NULL);
247 elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
252 static void _fini_theme(void)
254 elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
255 elm_theme_free(menu_screen_info.theme);
256 menu_screen_info.theme = NULL;
262 static Evas_Object *_create_conformant(Evas_Object *win)
264 Evas_Object *conformant;
266 conformant = elm_conformant_add(win);
267 retv_if(NULL == conformant, NULL);
269 elm_object_style_set(conformant, "nokeypad");
270 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
271 evas_object_data_set(conformant, "win", win);
272 evas_object_show(conformant);
274 elm_win_resize_object_add(win, conformant);
275 elm_win_conformant_set(win, EINA_TRUE);
282 static void _destroy_conformant(Evas_Object *conformant)
284 evas_object_data_del(conformant, "win");
285 evas_object_del(conformant);
290 static bool _create_cb(void *data)
292 Evas_Object *conformant;
295 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas("MENU_SCREEN", PACKAGE), false);
296 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
298 if (vconf_notify_key_changed(VCONFKEY_BGSET, _change_bg_cb, NULL) < 0) {
299 _E("Failed to register a vconf cb for %s\n", VCONFKEY_BGSET);
303 conformant = _create_conformant(menu_screen_info.win);
304 retv_if(NULL == conformant, false);
305 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
308 layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
309 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
310 if (NULL == layout) {
311 _E("Failed to load an edje object");
312 evas_object_del(menu_screen_info.win);
315 evas_object_data_set(menu_screen_info.win, "layout", layout);
317 elm_object_content_set(conformant, layout);
319 aul_listen_app_dead_signal(_dead_cb, NULL);
326 static void _terminate_cb(void *data)
328 Evas_Object *conformant;
331 if (vconf_ignore_key_changed(VCONFKEY_BGSET, _change_bg_cb) < 0) {
332 _E("Failed to remove bgset [%s]\n", VCONFKEY_BGSET);
335 evas_object_hide(menu_screen_info.win);
339 layout = evas_object_data_del(menu_screen_info.win, "layout");
340 if (layout) layout_destroy(layout);
342 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
343 if (conformant) _destroy_conformant(conformant);
348 evas_object_del(menu_screen_info.win);
353 static void _pause_cb(void *data)
357 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_FALSE) < 0) {
358 _E("Failed to set %s to 0", VCONFKEY_IDLE_SCREEN_TOP);
361 menu_screen_info.state = APP_STATE_PAUSE;
366 static void _resume_cb(void *data)
370 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
371 _E("Failed to set %s to 1", VCONFKEY_IDLE_SCREEN_TOP);
374 evas_object_show(menu_screen_get_win());
376 menu_screen_info.state = APP_STATE_RESUME;
381 static void _service_cb(service_h service, void *data)
383 _D("START RESET : %d", menu_screen_info.state);
385 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
386 _E("Failed to set %s to 1", VCONFKEY_IDLE_SCREEN_TOP);
389 evas_object_show(menu_screen_get_win());
394 static void _language_changed_cb(void *data)
396 register unsigned int i;
397 register unsigned int j;
400 Evas_Object *all_apps;
401 Evas_Object *scroller;
404 unsigned int page_max_app;
406 _D("Language is changed");
408 if (false == menu_screen_info.is_done) {
412 layout = evas_object_data_get(menu_screen_info.win, "layout");
413 ret_if(NULL == layout);
414 all_apps = evas_object_data_get(layout, "all_apps");
415 ret_if(NULL == all_apps);
416 scroller = elm_object_part_content_get(all_apps, "content");
417 ret_if(NULL == scroller);
419 count = page_scroller_count_page(scroller);
420 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
421 for (i = 0; i < count; i ++) {
422 page = page_scroller_get_page_at(scroller, i);
424 if (mapbuf_is_enabled(page)) {
425 mapbuf_disable(page, 1);
428 for (j = 0; j < page_max_app; j ++) {
432 item = page_get_item_at(page, j);
435 if (ail_get_appinfo(item_get_package(item), &ai) < 0) continue;
436 if (ail_appinfo_get_str(ai, AIL_PROP_NAME_STR, &name) < 0) {
437 ail_destroy_appinfo(ai);
442 _D("Failed to get name for %s", item_get_package(item));
443 ail_destroy_appinfo(ai);
447 item_set_name(item, name, 0);
448 ail_destroy_appinfo(ai);
451 mapbuf_enable(page, 1);
457 static void _init(app_event_callback_s *event_callback)
459 event_callback->create = _create_cb;
460 event_callback->terminate = _terminate_cb;
461 event_callback->pause = _pause_cb;
462 event_callback->resume = _resume_cb;
463 event_callback->service = _service_cb;
464 event_callback->low_memory = NULL;
465 event_callback->low_battery = NULL;
466 event_callback->device_orientation = NULL;
467 event_callback->language_changed = _language_changed_cb;
468 event_callback->region_format_changed = NULL;
473 static void _fini(void)
479 #define QP_EMUL_STR "Emulator"
480 static bool _is_emulator_on(void)
485 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
486 if (SYSTEM_INFO_ERROR_NONE != ret) {
493 if (!strncmp(model, QP_EMUL_STR, strlen(model))) {
494 _D("This model is on Emulator");
499 _D("This model is NOT on Emulator");
506 int main(int argc, char *argv[])
509 app_event_callback_s event_callback;
511 if (_is_emulator_on()) {
512 _D("ELM_ENGINE is set as [software_x11]");
513 setenv("ELM_ENGINE", "software_x11", 1);
515 buf = vconf_get_str(MENU_SCREEN_ENGINE);
517 _D("ELM_ENGINE is set as [%s]", buf);
518 setenv("ELM_ENGINE", buf, 1);
521 _D("ELM_ENGINE is set as [gl]");
522 setenv("ELM_ENGINE", "gl", 1);
526 _init(&event_callback);
527 app_efl_main(&argc, &argv, &event_callback, NULL);