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.
18 #include <Elementary.h>
20 #include <app_preference.h>
21 #include <system_settings.h>
23 #include "homescreen-efl.h"
25 #include "option_menu.h"
26 #include "livebox/livebox_panel.h"
27 #include "livebox/livebox_utils.h"
32 #include "data_model.h"
34 #include "folder_panel.h"
35 #include "livebox_all_pages.h"
42 Evas_Object *gradient_bg;
43 Evas_Object *conformant;
45 Evas_Object *all_apps;
49 homescreen_view_t view_type;
61 .view_type = HOMESCREEN_VIEW_HOME,
62 .is_bg_blurred = false
65 static bool mvc_badge_refresh_enable = true;
67 /*======================================UI HELPER FUNCTIONS========================*/
68 static void __homescreen_efl_create_base_gui(void);
69 static void __homescreen_efl_win_delete_request_cb(void *data, Evas_Object *obj, void *event_info);
70 static void __homescreen_efl_get_window_size(Evas_Object *win);
71 static void __homescreen_efl_home_btn_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
72 static void __homescreen_efl_menu_btn_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
73 static void __homescreen_efl_attach_badge_callback(void);
74 static void __homescreen_efl_detach_badge_callback(void);
75 static bool __homescreen_efl_update_icon_label(Tree_node_t *parent, Tree_node_t *node, void *data);
76 static void __homescreen_efl_make_gradient_bg(void);
77 static void __homescreen_efl_show_gradient_bg(void);
78 static void __homescreen_efl_show_normal_bg(void);
80 /*======================================APP CONTROL CALLBACKS=======================*/
81 static bool __homescreen_efl_app_create_cb(void *data);
82 static void __homescreen_efl_app_control_cb(app_control_h app_control, void *data);
83 static void __homescreen_efl_app_pause_cb(void *data);
84 static void __homescreen_efl_app_resume_cb(void *data);
85 static void __homescreen_efl_app_terminate_cb(void *data);
88 /*============================UI CALLBACKS==========================================*/
89 static void __homescreen_efl_lang_changed_cb(app_event_info_h event_info, void *user_data);
90 static void __homescreen_efl_orient_changed_cb(app_event_info_h event_info, void *user_data);
91 static void __homescreen_efl_region_changed_cb(app_event_info_h event_info, void *user_data);
92 static void __homescreen_efl_low_battery_cb(app_event_info_h event_info, void *user_data);
93 static void __homescreen_efl_low_memory_cb(app_event_info_h event_info, void *user_data);
95 /*==================== MVC Controller functions implementation: ===================*/
96 static bool __update_all_badges_count(Tree_node_t *parent, Tree_node_t *node, void *data);
97 static void __badge_change_cb(unsigned int action, const char *app_id, unsigned int count, void *user_data);
98 static bool __homescreen_efl_update_icon_badge(Tree_node_t *parent, Tree_node_t *node, void *data);
99 static void __homescreen_efl_badge_count_update_cb(void *app_item);
100 static void __homescreen_efl_activate_chooser_caption(void);
101 static void __homescreen_efl_deactivate_chooser_caption(void);
102 static void __homescreen_efl_chooser_caption_done_button_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
103 static void __homescreen_efl_chooser_caption_cancel_button_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
104 static bool __homescreen_efl_free_grid_item(Tree_node_t *page, Tree_node_t *item, void *data);
105 static bool __homescreen_efl_increment_page(Tree_node_t *parent, Tree_node_t *item, void *data);
106 static bool __homescreen_efl_attach_all_apps_grid_item(Tree_node_t *page, Tree_node_t *item, void *data);
107 static void __homescreen_efl_apply_data_model_to_view(void);
108 static void __homescreen_efl_show_all_apps(void);
109 static void __homescreen_efl_show_home_view(void);
110 static void __homescreen_efl_home_bg_changed_cb(system_settings_key_e key, void *data);
111 static void __homescreen_efl_apply_home_bg_effect(bool is_on);
112 static Eina_Bool __homescreen_efl_show_all_apps_anim(void *data, double pos);
113 static Eina_Bool __homescreen_efl_show_home_anim(void *data, double pos);
114 /*====================PUBLIC FUNCTIONS IMPLEMENTATION===============================*/
116 /*used to iterate over data model:*/
117 static bool folder_count_pending = false;
118 static unsigned int folder_badge_counter = 0;
120 int main(int argc, char *argv[])
122 dlog_print(DLOG_DEBUG, LOG_TAG, "Starting homescreen-efl");
125 ui_app_lifecycle_callback_s event_callback = {0,};
126 app_event_handler_h handlers[5] = {NULL, };
128 event_callback.create = __homescreen_efl_app_create_cb;
129 event_callback.terminate = __homescreen_efl_app_terminate_cb;
130 event_callback.pause = __homescreen_efl_app_pause_cb;
131 event_callback.resume = __homescreen_efl_app_resume_cb;
132 event_callback.app_control = __homescreen_efl_app_control_cb;
134 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, __homescreen_efl_low_battery_cb, NULL);
135 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, __homescreen_efl_low_memory_cb, NULL);
136 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, __homescreen_efl_orient_changed_cb, NULL);
137 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, __homescreen_efl_lang_changed_cb, NULL);
138 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, __homescreen_efl_region_changed_cb, NULL);
139 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
141 ret = ui_app_main(argc, argv, &event_callback, NULL);
142 if (ret != APP_ERROR_NONE)
143 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
145 s_info.view_type = HOMESCREEN_VIEW_HOME;
150 HAPI int home_screen_get_root_width(void)
152 return s_info.root_width;
155 HAPI int home_screen_get_root_height(void)
157 return s_info.root_height;
160 HAPI Evas_Object *home_screen_get_win(void)
165 HAPI Evas_Object *home_screen_get_layout(void)
167 return s_info.layout;
170 HAPI homescreen_view_t home_screen_get_view_type(void)
172 return s_info.view_type;
175 HAPI void home_screen_set_view_type(homescreen_view_t view)
178 case HOMESCREEN_VIEW_HOME:
179 __homescreen_efl_apply_home_bg_effect(false);
180 __homescreen_efl_show_normal_bg();
181 if (s_info.view_type == HOMESCREEN_VIEW_ALL_APPS) {
182 all_apps_set_view_mode(view);
183 __homescreen_efl_show_home_view();
186 case HOMESCREEN_VIEW_HOME_EDIT:
187 LOGI("HOMESCREEN_VIEW_HOME_EDIT");
190 case HOMESCREEN_VIEW_HOME_ALL_PAGES:
191 LOGI("HOMESCREEN_VIEW_HOME_ALL_PAGES");
192 livebox_all_pages_show();
194 case HOMESCREEN_VIEW_ALL_APPS:
195 __homescreen_efl_apply_home_bg_effect(true);
196 __homescreen_efl_show_gradient_bg();
197 if (s_info.view_type == HOMESCREEN_VIEW_HOME)
198 __homescreen_efl_show_all_apps();
200 if (s_info.view_type == HOMESCREEN_VIEW_ALL_APPS_CHOOSE)
201 __homescreen_efl_deactivate_chooser_caption();
202 all_apps_set_view_mode(view);
203 elm_object_signal_emit(s_info.layout, SIGNAL_BOTTOM_BUTTONS_ALL_APPS_STATE_SET, SIGNAL_SOURCE);
204 __badge_change_cb(0, NULL, 0, NULL);
206 case HOMESCREEN_VIEW_ALL_APPS_EDIT:
207 LOGI("HOMESCREEN_VIEW_ALL_APPS_EDIT");
208 if (s_info.view_type == HOMESCREEN_VIEW_ALL_APPS_CHOOSE)
209 __homescreen_efl_deactivate_chooser_caption();
210 all_apps_set_view_mode(view);
211 elm_object_signal_emit(s_info.layout, SIGNAL_BOTTOM_BUTTONS_ALL_APPS_EDIT_STATE_SET, SIGNAL_SOURCE);
213 case HOMESCREEN_VIEW_ALL_APPS_CHOOSE:
214 LOGI("HOMESCREEN_VIEW_ALL_APPS_CHOOSE");
215 __homescreen_efl_activate_chooser_caption();
216 all_apps_set_view_mode(view);
218 case HOMESCREEN_VIEW_UNKNOWN:
219 LOGI("HOMESCREEN_VIEW_UNKNOWN");
222 LOGE("UKNOWN VIEW TYPE");
226 s_info.view_type = view;
229 HAPI void home_screen_set_indice_state(indice_type_t indice)
232 case INDICE_NEXT_PAGE_ON:
233 elm_object_signal_emit(s_info.layout, SIGNAL_NEXT_PAGE_INDICE_SHOW, SIGNAL_SOURCE);
235 case INDICE_PREV_PAGE_ON:
236 elm_object_signal_emit(s_info.layout, SIGNAL_PREV_PAGE_INDICE_SHOW, SIGNAL_SOURCE);
239 elm_object_signal_emit(s_info.layout, SIGNAL_INDICE_HIDE, SIGNAL_SOURCE);
246 HAPI void home_screen_mvc_set_ly_scale(Evas_Object *layout)
248 Evas_Object *edje = NULL;
253 LOGE("[FAILED][invalid parameter]");
257 edje = elm_layout_edje_get(layout);
259 width = s_info.root_width;
260 height = s_info.root_height;
262 if (width == HD_WIDTH && height == HD_HEIGHT) {
264 edje_object_scale_set(edje, HD_SCALE_FACTOR);
265 } else if(width == QHD_WIDTH && height == QHD_HEIGHT) {
267 edje_object_scale_set(edje, QHD_SCALE_FACTOR);
268 } else if(width == WVGA_WIDTH && height == WVGA_HEIGHT) {
270 edje_object_scale_set(edje, WVGA_SCALE_FACTOR);
275 /*====================END OF PUBLIC FUNCTIONS IMPLEMENTATION=========================*/
277 static void __homescreen_efl_win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
282 static Evas_Object *_create_conformant(void)
284 Evas_Object *conformant = NULL;
287 LOGE("Window is not created");
291 conformant = elm_conformant_add(s_info.win);
293 LOGE("Failed to create conformant");
296 elm_win_conformant_set(s_info.win, EINA_TRUE);
298 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
299 elm_win_resize_object_add(s_info.win, conformant);
301 elm_win_indicator_mode_set(s_info.win, ELM_WIN_INDICATOR_SHOW);
302 elm_win_indicator_opacity_set(s_info.win, ELM_WIN_INDICATOR_TRANSLUCENT);
303 elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
305 evas_object_show(conformant);
310 static void __homescreen_efl_create_base_gui(void)
312 char edj_path[PATH_MAX] = {0, };
313 const char *bg_path = IMAGE_DIR"/default_bg.png";
314 char trbuf[PATH_MAX] = {0, };
319 s_info.win = elm_win_util_standard_add(PACKAGE, PACKAGE);
320 elm_win_autodel_set(s_info.win, EINA_TRUE);
322 evas_object_smart_callback_add(s_info.win, "delete,request", __homescreen_efl_win_delete_request_cb, NULL);
325 s_info.bg = evas_object_image_filled_add(evas_object_evas_get(s_info.win));
327 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf);
328 if (!buf || ret != SYSTEM_SETTINGS_ERROR_NONE) {
329 evas_object_image_file_set(s_info.bg, bg_path, "bg");
331 evas_object_image_file_set(s_info.bg, buf, "bg");
335 system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, __homescreen_efl_home_bg_changed_cb, NULL);
337 elm_win_resize_object_add(s_info.win, s_info.bg);
338 evas_object_show(s_info.bg);
340 __homescreen_efl_get_window_size(s_info.win);
341 __homescreen_efl_make_gradient_bg();
344 s_info.conformant = _create_conformant();
347 snprintf(edj_path, sizeof(edj_path), EDJE_DIR"/home.edj");
348 s_info.layout = elm_layout_add(s_info.win);
349 elm_layout_file_set(s_info.layout, edj_path, GROUP_HOME_LY);
350 evas_object_size_hint_weight_set(s_info.layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351 elm_win_resize_object_add(s_info.win, s_info.layout);
352 evas_object_show(s_info.layout);
354 home_screen_mvc_set_ly_scale(s_info.layout);
356 s_info.home = livebox_panel_create(s_info.layout);
358 evas_object_del(s_info.win);
359 evas_object_del(s_info.bg);
360 evas_object_del(s_info.conformant);
361 evas_object_del(s_info.layout);
363 LOGE("s_info.home == NULL");
367 elm_object_part_content_set(s_info.layout, PART_CONTENT, s_info.home);
369 /* Show window after base gui is set up */
370 evas_object_show(s_info.win);
371 elm_object_signal_callback_add(s_info.layout, SIGNAL_HOME_BTN_CLICKED, SIGNAL_SOURCE, __homescreen_efl_home_btn_clicked, NULL);
372 elm_object_signal_callback_add(s_info.layout, SIGNAL_MENU_BTN_CLICKED, SIGNAL_SOURCE, __homescreen_efl_menu_btn_clicked, NULL);
374 /*Chooser caption setup:*/
375 elm_layout_signal_callback_add(s_info.layout, "mouse,clicked,*",
376 "chooser_caption_left_clickable_space",
377 __homescreen_efl_chooser_caption_cancel_button_cb, NULL);
378 elm_layout_signal_callback_add(s_info.layout, "mouse,clicked,*",
379 "chooser_caption_right_clickable_space",
380 __homescreen_efl_chooser_caption_done_button_cb, NULL);
382 snprintf(trbuf, sizeof(trbuf), _("IDS_MEMO_HEADER_PD_SELECTED_ABB2"), 0);
383 layout_main_caption_set_menu_texts(trbuf,
384 _("IDS_TPLATFORM_ACBUTTON_CANCEL_ABB"),
385 _("IDS_TPLATFORM_ACBUTTON_DONE_ABB"));
388 /*TODO: coding convention!*/
389 bool tree_print_cb(Tree_node_t *parent_node, Tree_node_t *tn, void *data)
391 app_item_t *item = tn->data;
392 app_item_t *parent = NULL;
395 parent = tn->parent->data;
397 LOGD("TYPE: %2d; PARENT name: %12.12s; id: %2d | ITEM appid: %28.28s; id: %2d; [%d, %d; %d, %d]; %s",
399 parent ? parent->appid : "NULL",
400 parent ? parent->unique_id : -1,
412 /*TODO: coding convention!*/
413 void home_screen_print_tree(void)
415 LOGD("TREE TEST START");
416 data_model_iterate(data_model_get_data(), tree_print_cb, NULL);
419 static void __homescreen_efl_attach_badge_callback(void)
421 app_mgr_register_badge_callback(__badge_change_cb);
424 static void __homescreen_efl_detach_badge_callback(void)
426 app_mgr_unregister_badge_callback(__badge_change_cb);
429 static bool __homescreen_efl_app_create_cb(void *data)
431 elm_config_accel_preference_set("3d");
432 ecore_animator_frametime_set(FRAMES_PER_SECOND);
437 __homescreen_efl_create_base_gui();
438 folder_panel_init_module();
441 if(!data_model_load_db()) {
442 data_model_load_app_mgr();
445 livebox_panel_fill();
446 livebox_panel_set_content(s_info.layout);
447 __homescreen_efl_attach_badge_callback();
449 home_screen_mvc_update_view();
453 static void __homescreen_efl_app_control_cb(app_control_h app_control, void *data)
455 elm_win_activate(s_info.win);
458 static void __homescreen_efl_app_pause_cb(void *data)
460 /* Take necessary actions when application becomes invisible. */
461 livebox_panel_paused();
464 static void __homescreen_efl_app_resume_cb(void *data)
466 /* Take necessary actions when application becomes visible. */
467 livebox_panel_resumed();
470 static void __homescreen_efl_app_terminate_cb(void *data)
472 /* Release all resources. */
473 __homescreen_efl_detach_badge_callback();
479 folder_panel_deinit_module();
481 livebox_panel_destroy();
484 static bool __homescreen_efl_update_icon_label(Tree_node_t *parent, Tree_node_t *node, void *data)
486 if(!node || !node->data)
490 if (node->data->label && node->data->type == APP_ITEM_ICON) {
491 free(node->data->label);
492 node->data->label = app_mgr_get_app_label(node->data->appid);
496 elm_object_part_text_set(node->data->layout, PART_ICON_NAME, node->data->label);
501 static void __homescreen_efl_make_gradient_bg(void)
503 #ifdef HOME_HOME_SCREEN_GRADIENT_ENABLED
505 Evas_Colorspace ec = EVAS_COLORSPACE_ARGB8888;
506 char *image_raw_data = NULL;
508 int image_height = 0;
517 ec = evas_object_image_colorspace_get(s_info.bg);
519 if(ec != EVAS_COLORSPACE_ARGB8888)
522 image_raw_data = evas_object_image_data_get(s_info.bg, EINA_FALSE);
526 evas_object_image_size_get(s_info.bg, &image_width, &image_height);
527 if(image_width == 0 || image_height == 0)
530 if(!s_info.gradient_bg)
531 s_info.gradient_bg = evas_object_rectangle_add(evas_object_evas_get(s_info.win));
533 if(!s_info.gradient_bg)
536 evas_object_resize(s_info.gradient_bg, s_info.root_width, s_info.root_height);
542 evas_map_util_points_populate_from_object(m, s_info.gradient_bg);
544 r = image_raw_data[2] & 0xff;
545 g = image_raw_data[1] & 0xff;
546 b = image_raw_data[0] & 0xff;
547 a = image_raw_data[3] & 0xff;
548 evas_map_point_color_set(m, 0, r, g, b, a);
550 r = image_raw_data[4*image_width -4 + 2] & 0xff;
551 g = image_raw_data[4*image_width -4 + 1] & 0xff;
552 b = image_raw_data[4*image_width -4 + 0] & 0xff;
553 a = image_raw_data[4*image_width -4 + 3] & 0xff;
554 evas_map_point_color_set(m, 1, r, g, b, a);
556 r = image_raw_data[4*image_width -4 + (image_height-1)*4*image_width + 2] & 0xff;
557 g = image_raw_data[4*image_width -4 + (image_height-1)*4*image_width + 1] & 0xff;
558 b = image_raw_data[4*image_width -4 + (image_height-1)*4*image_width + 0] & 0xff;
559 a = image_raw_data[4*image_width -4 + (image_height-1)*4*image_width + 3] & 0xff;
560 evas_map_point_color_set(m, 2, r, g, b, a);
562 r = image_raw_data[(image_height-1)*4*image_width + 2] & 0xff;
563 g = image_raw_data[(image_height-1)*4*image_width + 1] & 0xff;
564 b = image_raw_data[(image_height-1)*4*image_width + 0] & 0xff;
565 a = image_raw_data[(image_height-1)*4*image_width + 3] & 0xff;
566 evas_map_point_color_set(m, 3, r, g, b, a);
568 evas_object_map_set(s_info.gradient_bg, m);
569 evas_object_map_enable_set(s_info.gradient_bg, EINA_TRUE);
574 static void __homescreen_efl_show_gradient_bg(void)
576 #ifdef HOME_HOME_SCREEN_GRADIENT_ENABLED
577 if(s_info.gradient_bg) {
578 evas_object_hide(s_info.bg);
579 elm_win_resize_object_del(s_info.win, s_info.bg);
580 elm_win_resize_object_add(s_info.win, s_info.gradient_bg);
581 evas_object_show(s_info.gradient_bg);
582 evas_object_raise(s_info.layout);
587 static void __homescreen_efl_show_normal_bg(void)
589 #ifdef HOME_HOME_SCREEN_GRADIENT_ENABLED
590 evas_object_hide(s_info.gradient_bg);
591 elm_win_resize_object_del(s_info.win, s_info.gradient_bg);
592 elm_win_resize_object_add(s_info.win, s_info.bg);
593 evas_object_show(s_info.bg);
594 evas_object_raise(s_info.layout);
598 static void __homescreen_efl_lang_changed_cb(app_event_info_h event_info, void *user_data)
600 data_model_iterate(NULL, __homescreen_efl_update_icon_label, NULL);
603 static void __homescreen_efl_orient_changed_cb(app_event_info_h event_info, void *user_data)
605 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
608 static void __homescreen_efl_region_changed_cb(app_event_info_h event_info, void *user_data)
610 /*APP_EVENT_REGION_FORMAT_CHANGED*/
613 static void __homescreen_efl_low_battery_cb(app_event_info_h event_info, void *user_data)
615 /*APP_EVENT_LOW_BATTERY*/
618 static void __homescreen_efl_low_memory_cb(app_event_info_h event_info, void *user_data)
620 /*APP_EVENT_LOW_MEMORY*/
623 static void __homescreen_efl_get_window_size(Evas_Object *win)
625 elm_win_screen_size_get(win, NULL, NULL, &s_info.root_width, &s_info.root_height);
626 dlog_print(DLOG_DEBUG, LOG_TAG, "Width: [%d], Height: [%d]", s_info.root_width, s_info.root_height);
629 static void __homescreen_efl_home_btn_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
631 homescreen_view_t view_t = home_screen_get_view_type();
633 if (view_t == HOMESCREEN_VIEW_HOME) {
634 home_screen_set_view_type(HOMESCREEN_VIEW_ALL_APPS);
635 } else if (view_t == HOMESCREEN_VIEW_ALL_APPS) {
636 home_screen_set_view_type(HOMESCREEN_VIEW_HOME);
640 static void __homescreen_efl_menu_btn_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
642 homescreen_view_t view = home_screen_get_view_type();
645 case HOMESCREEN_VIEW_HOME:
646 case HOMESCREEN_VIEW_ALL_APPS:
654 /*==================== MVC Controller functions implementation: ===================*/
656 /*TODO: code convention!*/
657 void home_screen_mvc_item_uninstall_cb(Tree_node_t *item)
659 if (!item || !item->data)
662 if (item->data->type == APP_ITEM_ICON) {
663 app_mgr_uninstall_app(item->data->appid);
664 data_model_uninstall_application(item);
665 } else {/*folder item type:*/
666 data_model_delete_folder(item);
669 /*by default model is being sorted:*/
670 data_model_sort(NULL);
671 data_model_free_empty_pages(NULL);
672 __homescreen_efl_apply_data_model_to_view();
673 all_apps_remove_empty_pages();
676 void home_screen_mvc_update_view(void)
678 data_model_sort(NULL);
679 __homescreen_efl_apply_data_model_to_view();
682 void home_screen_mvc_drag_item_to_folder_cb(Tree_node_t *dragged_item, Tree_node_t *folder)
684 if (dragged_item && folder) {
686 data_model_append_node_to_folder(folder, dragged_item); /*there were no pages in folder*/
688 data_model_reposition_item(dragged_item, folder->last, folder->last->last, REPOSITION_SIDE_TO_RIGHT, FOLDER_APPS_PAGE);
690 /*for now model is always sorted:*/
691 data_model_sort(NULL);
692 data_model_free_empty_pages(NULL);
693 __homescreen_efl_apply_data_model_to_view();
694 all_apps_remove_empty_pages();
698 /*TODO:All mvc funcitons will be moved to separeted file.*/
699 void home_screen_mvc_drag_item_from_folder_cb(void)
701 __homescreen_efl_apply_data_model_to_view();
704 static void __homescreen_efl_activate_chooser_caption(void)
706 data_model_check_all_apps(data_model_get_all_apps(), false);
707 elm_layout_signal_emit(s_info.layout, SIGNAL_CHOOSER_CAPTION_ACTIVATE, SIGNAL_SOURCE);
708 elm_win_indicator_mode_set(s_info.win, ELM_WIN_INDICATOR_HIDE);
711 static void __homescreen_efl_deactivate_chooser_caption(void)
713 elm_layout_signal_emit(s_info.layout, SIGNAL_CHOOSER_CAPTION_DEACTIVATE, SIGNAL_SOURCE);
714 elm_win_indicator_mode_set(s_info.win, ELM_WIN_INDICATOR_SHOW);
717 static bool __homescreen_efl_free_grid_item(Tree_node_t *page, Tree_node_t *item, void *data)
719 if (!item->data || !item->data->grid_item) {
720 LOGE("__homescreen_efl_free_grid_item, skipping: %d %d", item->data, item->data ? item->data->type : -1);
724 if (!item->data->layout)
725 LOGD("__homescreen_efl_free_grid_item, %s item->data->layout == NULL", item->data->label);
727 all_apps_detach_from_grid(item->data->grid_item);
728 item->data->grid_item = NULL;
729 evas_object_hide(item->data->layout);
734 static bool __homescreen_efl_increment_page(Tree_node_t *parent, Tree_node_t *item, void *data)
741 static bool __homescreen_efl_attach_all_apps_grid_item(Tree_node_t *page, Tree_node_t *item, void *data)
744 LOGE("__homescreen_efl_attach_all_apps_grid_item, skipping: %d", item->data);
748 item->data->grid_item = all_apps_attach_to_grid(item->data->layout, *(int *)data);
750 if (!item->data->grid_item) {
751 /*failed to attach item - there is no room in page scroller
752 so we have to add another page. This problem does not concern folders.*/
754 if (!all_apps_append_page(page))
755 LOGE("Could not create page for item: %s", item->data->label);
758 app_icon_set_view_mode(item->data->layout, home_screen_get_view_type(), false);
763 static bool _folder_grid_item_att(Tree_node_t *page, Tree_node_t *item, void *data)
765 if (!item->data || !page->parent || !page->parent->data ||
766 page->parent->data->type != APP_ITEM_FOLDER ||
767 folder_panel_get_opened_folder_item() != page->parent->data) {
768 LOGE("_folder_grid_item_att, skipping: %s dest_folder: %d", item->data ? item->data->appid : NULL);
772 item->data->grid_item = folder_panel_attach_to_grid(item->data->layout, ((app_item_t *)page->parent->data)->data);
777 static bool _folder_data_model_to_view_apply_cb(Tree_node_t *page, Tree_node_t *item, void *data)
779 if (!item->data || item->data->type != APP_ITEM_FOLDER)
782 data_model_iterate_pages(item, NULL, __homescreen_efl_free_grid_item, NULL);
783 data_model_iterate_pages(item, NULL, _folder_grid_item_att, NULL);
784 app_icon_update_folder_icon(item);
788 static void __homescreen_efl_apply_data_model_to_view(void)
790 int page_counter = -1;
791 Tree_node_t *apps_root = data_model_get_all_apps();
793 if (!apps_root || !apps_root->data || apps_root->data->type != APP_ITEM_ALL_APPS_ROOT) {
794 LOGE("Can't apply view [apps root]: %d %d", apps_root, apps_root ? apps_root->data : NULL);
798 mvc_badge_refresh_enable = false;
800 data_model_iterate_pages(NULL, NULL, __homescreen_efl_free_grid_item, NULL);
801 data_model_iterate_pages(NULL, NULL, _folder_data_model_to_view_apply_cb, NULL);
802 data_model_iterate_pages(NULL, __homescreen_efl_increment_page, __homescreen_efl_attach_all_apps_grid_item, &page_counter);
803 all_apps_update_dynamic_index_count();
805 mvc_badge_refresh_enable = true;
807 __badge_change_cb(0, NULL, 0, NULL);
810 static bool _checked_items_get(Tree_node_t *root, Tree_node_t *item, void *list)
812 Eina_List **checked_items_list = (Eina_List **)list;
814 if (item->data && item->data->is_checked) {
815 *checked_items_list = eina_list_append(*checked_items_list, item);
816 item->data->is_checked = false;
822 static void __homescreen_efl_chooser_caption_done_button_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
824 /*Folder creation/modification:*/
825 app_item_t *destination_folder_data = NULL;
826 Eina_List *iterator = NULL, *checked_items_list = NULL;
827 Tree_node_t *item = NULL;
828 Tree_node_t *destination_folder = folder_panel_get_opened_folder_node();
830 if (!destination_folder) {
831 destination_folder_data = app_item_create(APP_ITEM_FOLDER, -1, "", NULL, NULL, NULL, NULL, true, 0, 0, 0, 0, NULL);
833 if (!destination_folder_data) {
834 LOGE("caption_done_button_cb: failed to create destination_folder_data");
838 destination_folder = data_model_create_folder(destination_folder_data);
840 if (!destination_folder) {
841 LOGE("caption_done_button_cb: failed to create destination_folder");
842 folder_panel_cancel_add_icon();
843 folder_panel_set_click_ignore_state(false);
844 app_item_free(destination_folder_data);
847 folder_panel_create(destination_folder);
850 /*all checked items should be added to the folder:*/
851 data_model_iterate(NULL, _checked_items_get, &checked_items_list);
853 EINA_LIST_FOREACH(checked_items_list, iterator, item)
854 data_model_append_node_to_folder(destination_folder, item);
856 eina_list_free(checked_items_list);
857 /*for now they are always sorted:*/
858 data_model_sort(NULL);
860 folder_panel_cancel_add_icon();
861 folder_panel_set_click_ignore_state(false);
863 data_model_free_empty_pages(NULL);
864 home_screen_set_view_type(HOMESCREEN_VIEW_ALL_APPS);
865 __homescreen_efl_apply_data_model_to_view();
866 all_apps_remove_empty_pages();
869 static void __homescreen_efl_chooser_caption_cancel_button_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
871 folder_panel_cancel_add_icon();
872 folder_panel_set_click_ignore_state(false);
873 data_model_check_all_apps(data_model_get_all_apps(), false);
874 home_screen_set_view_type(HOMESCREEN_VIEW_ALL_APPS);
877 static void __homescreen_efl_show_all_apps(void)
879 livebox_panel_unset_content(s_info.layout);
882 if (!s_info.all_apps)
883 s_info.all_apps = all_apps_create(s_info.layout, NULL);
885 elm_object_part_content_unset(s_info.layout, PART_CONTENT);
887 evas_object_hide(s_info.all_apps);
888 evas_object_move(s_info.all_apps, 0, s_info.root_height);
890 elm_object_signal_emit(s_info.layout, SIGNAL_BLOCK_EVENTS, SIGNAL_SOURCE);
891 app_icon_set_click_ignore(true);
893 ecore_animator_timeline_add(APPS_SHOW_HIDE_ANIMATION_TIME, __homescreen_efl_show_all_apps_anim, NULL);
896 static void __homescreen_efl_show_home_view(void)
898 elm_object_part_content_unset(s_info.layout, PART_CONTENT);
900 elm_object_signal_emit(s_info.layout, SIGNAL_BOTTOM_BUTTONS_HOME_STATE_SET, SIGNAL_SOURCE);
902 elm_object_signal_emit(s_info.layout, SIGNAL_BLOCK_EVENTS, SIGNAL_SOURCE);
903 app_icon_set_click_ignore(true);
905 ecore_animator_timeline_add(APPS_SHOW_HIDE_ANIMATION_TIME, __homescreen_efl_show_home_anim, NULL);
908 static bool __update_all_badges_count(Tree_node_t *parent, Tree_node_t *node, void *data)
910 app_item_t *item = NULL;
914 __homescreen_efl_badge_count_update_cb(item);
920 static void __badge_change_cb(unsigned int action, const char *app_id, unsigned int count, void *user_data)
922 data_model_iterate(NULL, __update_all_badges_count, NULL);
925 static bool __homescreen_efl_update_icon_badge(Tree_node_t *parent, Tree_node_t *node, void *data)
927 app_item_t *app = (app_item_t *)data;
929 if (!folder_count_pending && app != node->data)
932 if (!folder_count_pending && app == node->data) {
933 folder_count_pending = true;
934 data_model_iterate(node, __homescreen_efl_update_icon_badge, app);
935 folder_count_pending = false;
938 if (folder_count_pending && node->data->type == APP_ITEM_ICON)
939 folder_badge_counter += node->data->badge_count;
941 if (!folder_count_pending && app == node->data)
947 static void __homescreen_efl_badge_count_update_cb(void *app_item)
949 app_item_t *app = (app_item_t *)app_item;
951 if (!mvc_badge_refresh_enable)
955 LOGE("badge_count_update_cb: app_item is NULL");
959 if (app->type == APP_ITEM_ICON && !app_mgr_app_get_badge_count(app->appid, &app->badge_count)) {
960 LOGE("badge_count_update_cb: get_badge_count returned error");
964 if (app->type == APP_ITEM_FOLDER) {
965 folder_count_pending = false;
966 folder_badge_counter = 0;
967 data_model_iterate(NULL, __homescreen_efl_update_icon_badge, app);
968 app->badge_count = folder_badge_counter;
971 app_icon_show_badge(app->layout, app->badge_count);
974 static void __homescreen_efl_home_bg_changed_cb(system_settings_key_e key, void *data)
980 LOGE("[FAILED][bg=NULL]");
984 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf);
985 if (!buf || ret != SYSTEM_SETTINGS_ERROR_NONE) {
986 LOGE("[FAILED][failed to get bg path]");
990 evas_object_image_file_set(s_info.bg, buf, "bg");
993 __homescreen_efl_make_gradient_bg();
996 static void __homescreen_efl_apply_home_bg_effect(bool is_on)
998 #ifndef HOME_HOME_SCREEN_BLUR_ENABLED
1003 /*source data and destination data (pixel values)*/
1004 uint32_t *src = NULL, *dst = NULL;
1006 /*values of channels in each pixel*/
1007 uint32_t A = 0, R = 0, G = 0, B = 0;
1009 /*helper variables*/
1010 uint32_t *s = NULL, *d = NULL, w = 0, p = 0;
1012 int width = -1, height = -1;
1015 int i = 0, j = 0, k = 0;
1017 /*kernel used for transform the image*/
1019 const int size = COUNT_OF(kernel);
1020 const int half = size / 2;
1023 LOGE("[FAILED][bg=NULL]");
1027 /*if is_on == false, then restore original image data*/
1029 /*restore original data and return;*/
1030 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &buf);
1032 LOGE("[FAILED][failed to get bg path]");
1036 evas_object_image_file_set(s_info.bg, buf, "bg");
1038 s_info.is_bg_blurred = false;
1042 evas_object_image_size_get(s_info.bg, &width, &height);
1043 src = evas_object_image_data_get(s_info.bg, EINA_TRUE);
1045 /*if image is already blurred then we should not perform once again*/
1046 if (s_info.is_bg_blurred)
1049 dst = (uint32_t *) alloca(sizeof(uint32_t) * width * height);
1051 LOGE("[FAILED][dst=NULL]");
1057 for (i = 0; i < size; i++) {
1058 double f = i - half;
1059 w += kernel[i] = exp(-f * f / 60.0) * 40;
1062 /*Apply modifications from src - > dst*/
1063 for (i = 0; i < height; i++) {
1064 s = (uint32_t *) (src + i * width);
1065 d = (uint32_t *) (dst + i * width);
1067 for (j = 0; j < width; j++) {
1069 for (k = 0; k < size; k++) {
1070 if (j - half + k < 0 || j - half + k >= width) {
1075 p = s[j - half + k];
1077 A = (p & 0xff000000);
1078 R += ((p >> 16) & 0xff) * kernel[k];
1079 G += ((p >> 8) & 0xff) * kernel[k];
1080 B += ((p >> 0) & 0xff) * kernel[k];
1082 d[j] = A | (((uint32_t)(R / w)) << 16) | (((uint32_t)(G / w)) << 8) | ((uint32_t)(B / w));
1086 /*Apply modification from dst -> srcs*/
1087 for (i = 0; i < height; i++) {
1088 s = (uint32_t *) (dst + i * width);
1089 d = (uint32_t *) (src + i * width);
1090 for (j = 0; j < width; j++) {
1092 for (k = 0; k < size; k++) {
1093 if (i - half + k < 0 || i - half + k >= height) {
1098 s = (uint32_t *) (dst + (i - half + k) * width);
1101 A = (p & 0xff000000);
1102 R += ((p >> 16) & 0xff) * kernel[k];
1103 G += ((p >> 8) & 0xff) * kernel[k];
1104 B += ((p >> 0) & 0xff) * kernel[k];
1106 d[j] = A | (((uint32_t)(R / w)) << 16) | (((uint32_t)(G / w)) << 8) | ((uint32_t)(B / w));
1110 s_info.is_bg_blurred = true;
1111 evas_object_image_data_update_add(s_info.bg, 0, 0, width, height);
1114 static Eina_Bool __homescreen_efl_show_all_apps_anim(void *data, double pos)
1116 Evas_Object *box = elm_object_content_get(s_info.all_apps);
1118 evas_object_show(s_info.all_apps);
1119 evas_object_move(s_info.all_apps, 0, (1.0 - pos) * ALL_APPS_ANIMATION_DELTA_Y);
1120 evas_object_move(s_info.home, 0, -pos * ALL_APPS_ANIMATION_HOME_DELTA_Y);
1122 evas_object_color_set(box, 255, 255, 255, pos*(double)255);
1125 elm_object_part_content_set(s_info.layout, PART_CONTENT, s_info.all_apps);
1127 elm_object_signal_emit(s_info.layout, SIGNAL_UNBLOCK_EVENTS, SIGNAL_SOURCE);
1128 return ECORE_CALLBACK_DONE;
1131 return ECORE_CALLBACK_RENEW;
1134 static Eina_Bool __homescreen_efl_show_home_anim(void *data, double pos)
1136 Evas_Object *box = elm_object_content_get(s_info.all_apps);
1138 evas_object_move(s_info.all_apps, 0, pos * ALL_APPS_ANIMATION_DELTA_Y);
1139 evas_object_move(s_info.home, 0, -(1.0 - pos ) * ALL_APPS_ANIMATION_HOME_DELTA_Y);
1141 evas_object_color_set(box, 255, 255, 255, (1.0 - pos * 2.0)*(double)255);
1144 if (s_info.layout && elm_object_part_content_get(s_info.layout, PART_CONTENT) == NULL && s_info.home) {
1145 elm_object_part_content_set(s_info.layout, PART_CONTENT, s_info.home);
1146 livebox_panel_set_content(s_info.layout);
1149 elm_object_signal_emit(s_info.layout, SIGNAL_UNBLOCK_EVENTS, SIGNAL_SOURCE);
1150 return ECORE_CALLBACK_DONE;
1153 return ECORE_CALLBACK_RENEW;