2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <Elementary.h>
24 #include <system_info.h>
31 #include "menu_screen.h"
34 #include "page_scroller.h"
37 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
39 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
40 #define LAYOUT_GROUP_NAME "layout"
44 // Define prototype of the "hidden API of AUL"
45 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
51 } menu_screen_info = {
52 .state = APP_STATE_PAUSE,
60 HAPI Evas *menu_screen_get_evas(void)
62 return evas_object_evas_get(menu_screen_info.win);
66 HAPI int menu_screen_get_root_width(void)
69 elm_win_screen_size_get(menu_screen_get_win(), NULL, NULL, &width, NULL);
75 HAPI int menu_screen_get_root_height(void)
78 elm_win_screen_size_get(menu_screen_get_win(), NULL, NULL, NULL, &height);
84 HAPI Evas_Object *menu_screen_get_win(void)
86 return menu_screen_info.win;
91 HAPI Elm_Theme *menu_screen_get_theme(void)
93 return menu_screen_info.theme;
98 HAPI bool menu_screen_get_done(void)
100 return menu_screen_info.is_done;
105 HAPI void menu_screen_set_done(bool is_done)
107 menu_screen_info.is_done = is_done;
112 static menu_screen_error_e _create_canvas(char *name, char *title)
115 menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
116 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
119 elm_win_title_set(menu_screen_info.win, title);
121 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
123 elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
125 evas_object_show(menu_screen_info.win);
127 return MENU_SCREEN_ERROR_OK;
132 static void _destroy_canvas(void)
134 evas_object_del(menu_screen_info.win);
139 static int _dead_cb(int pid, void *data)
141 evas_object_show(menu_screen_get_win());
147 static void _create_bg(void)
154 static int trigger = 0;
159 buf = vconf_get_str(VCONFKEY_BGSET);
162 width = menu_screen_get_root_width();
163 height = menu_screen_get_root_height();
165 bg = evas_object_data_get(menu_screen_get_win(), "bg");
169 rect = evas_object_rectangle_add(menu_screen_get_evas());
170 ret_if(NULL == rect);
171 evas_object_data_set(menu_screen_get_win(), "rect", rect);
172 evas_object_color_set(rect, 0, 0, 0, 255);
173 evas_object_size_hint_min_set(rect, width, height);
174 evas_object_size_hint_max_set(rect, width, height);
175 evas_object_resize(rect, width, height);
176 evas_object_show(rect);
178 bg = evas_object_image_add(menu_screen_get_evas());
183 evas_object_image_load_orientation_set(bg, EINA_TRUE);
184 evas_object_data_set(menu_screen_get_win(), "bg", bg);
195 evas_object_image_file_set(bg, buf, key);
196 evas_object_image_size_get(bg, &w, &h);
197 evas_object_image_filled_set(bg, 1);
199 wf = (double) width / (double) w;
200 hf = (double) height / (double) h;
202 f = wf < hf ? hf : wf;
204 w = (int) ((double) f * (double) w);
205 h = (int) ((double) f * (double) h);
207 evas_object_image_load_size_set(bg, w, h);
208 evas_object_image_fill_set(bg, 0, 0, w, h);
209 evas_object_move(bg, (width - w) / 2, (height - h) / 2);
210 evas_object_resize(bg, w, h);
211 evas_object_show(bg);
219 static void _destroy_bg()
224 rect = evas_object_data_del(menu_screen_get_win(), "rect");
225 evas_object_del(rect);
227 bg = evas_object_data_del(menu_screen_get_win(), "bg");
233 static void _change_bg_cb(keynode_t *node, void *data)
235 _D("Background image is changed.");
241 static void _init_theme(void)
243 menu_screen_info.theme = elm_theme_new();
244 elm_theme_ref_set(menu_screen_info.theme, NULL);
245 elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
250 static void _fini_theme(void)
252 elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
253 elm_theme_free(menu_screen_info.theme);
254 menu_screen_info.theme = NULL;
260 static Evas_Object *_create_conformant(Evas_Object *win)
262 Evas_Object *conformant;
264 conformant = elm_conformant_add(win);
265 retv_if(NULL == conformant, NULL);
267 elm_object_style_set(conformant, "nokeypad");
268 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
269 evas_object_data_set(conformant, "win", win);
270 evas_object_show(conformant);
272 elm_win_resize_object_add(win, conformant);
273 elm_win_conformant_set(win, EINA_TRUE);
280 static void _destroy_conformant(Evas_Object *conformant)
282 evas_object_data_del(conformant, "win");
283 evas_object_del(conformant);
288 static bool _create_cb(void *data)
290 Evas_Object *conformant;
293 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas("MENU_SCREEN", PACKAGE), false);
294 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
296 if (vconf_notify_key_changed(VCONFKEY_BGSET, _change_bg_cb, NULL) < 0) {
297 _E("Failed to register a vconf cb for %s\n", VCONFKEY_BGSET);
301 conformant = _create_conformant(menu_screen_info.win);
302 retv_if(NULL == conformant, false);
303 evas_object_data_set(menu_screen_info.win, "conformant", conformant);
306 layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
307 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
308 if (NULL == layout) {
309 _E("Failed to load an edje object");
310 evas_object_del(menu_screen_info.win);
313 evas_object_data_set(menu_screen_info.win, "layout", layout);
315 elm_object_content_set(conformant, layout);
317 aul_listen_app_dead_signal(_dead_cb, NULL);
324 static void _terminate_cb(void *data)
326 Evas_Object *conformant;
329 if (vconf_ignore_key_changed(VCONFKEY_BGSET, _change_bg_cb) < 0) {
330 _E("Failed to remove bgset [%s]\n", VCONFKEY_BGSET);
333 evas_object_hide(menu_screen_info.win);
337 layout = evas_object_data_del(menu_screen_info.win, "layout");
338 if (layout) layout_destroy(layout);
340 conformant = evas_object_data_del(menu_screen_info.win, "conformant");
341 if (conformant) _destroy_conformant(conformant);
346 evas_object_del(menu_screen_info.win);
351 static void _pause_cb(void *data)
355 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_FALSE) < 0) {
356 _E("Failed to set %s to 0", VCONFKEY_IDLE_SCREEN_TOP);
359 menu_screen_info.state = APP_STATE_PAUSE;
364 static void _resume_cb(void *data)
368 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
369 _E("Failed to set %s to 1", VCONFKEY_IDLE_SCREEN_TOP);
372 evas_object_show(menu_screen_get_win());
374 menu_screen_info.state = APP_STATE_RESUME;
379 static void _service_cb(service_h service, void *data)
381 _D("START RESET : %d", menu_screen_info.state);
383 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
384 _E("Failed to set %s to 1", VCONFKEY_IDLE_SCREEN_TOP);
387 evas_object_show(menu_screen_get_win());
392 static void _language_changed_cb(void *data)
394 register unsigned int i;
395 register unsigned int j;
398 Evas_Object *all_apps;
399 Evas_Object *scroller;
402 unsigned int page_max_app;
404 _D("Language is changed");
406 if (false == menu_screen_info.is_done) {
410 layout = evas_object_data_get(menu_screen_info.win, "layout");
411 ret_if(NULL == layout);
412 all_apps = evas_object_data_get(layout, "all_apps");
413 ret_if(NULL == all_apps);
414 scroller = elm_object_part_content_get(all_apps, "content");
415 ret_if(NULL == scroller);
417 count = page_scroller_count_page(scroller);
418 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
419 for (i = 0; i < count; i ++) {
420 page = page_scroller_get_page_at(scroller, i);
422 if (mapbuf_is_enabled(page)) {
423 mapbuf_disable(page, 1);
426 for (j = 0; j < page_max_app; j ++) {
430 item = page_get_item_at(page, j);
433 if (ail_get_appinfo(item_get_package(item), &ai) < 0) continue;
434 if (ail_appinfo_get_str(ai, AIL_PROP_NAME_STR, &name) < 0) {
435 ail_destroy_appinfo(ai);
440 _D("Failed to get name for %s", item_get_package(item));
441 ail_destroy_appinfo(ai);
445 item_set_name(item, name, 0);
446 ail_destroy_appinfo(ai);
449 mapbuf_enable(page, 1);
455 static void _init(app_event_callback_s *event_callback)
457 event_callback->create = _create_cb;
458 event_callback->terminate = _terminate_cb;
459 event_callback->pause = _pause_cb;
460 event_callback->resume = _resume_cb;
461 event_callback->service = _service_cb;
462 event_callback->low_memory = NULL;
463 event_callback->low_battery = NULL;
464 event_callback->device_orientation = NULL;
465 event_callback->language_changed = _language_changed_cb;
466 event_callback->region_format_changed = NULL;
471 static void _fini(void)
477 #define QP_EMUL_STR "Emulator"
478 static bool _is_emulator_on(void)
482 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
483 if (info == NULL) return false;
484 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
494 int main(int argc, char *argv[])
497 app_event_callback_s event_callback;
499 if (_is_emulator_on()) {
500 _D("ELM_ENGINE is set as [software_x11]");
501 setenv("ELM_ENGINE", "software_x11", 1);
503 buf = vconf_get_str(MENU_SCREEN_ENGINE);
505 _D("ELM_ENGINE is set as [%s]", buf);
506 setenv("ELM_ENGINE", buf, 1);
509 _D("ELM_ENGINE is set as [gl]");
510 setenv("ELM_ENGINE", "gl", 1);
514 _init(&event_callback);
515 app_efl_main(&argc, &argv, &event_callback, NULL);