The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / src / all_apps.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include "homescreen-efl.h"
18 #include "all_apps.h"
19 #include "page_scroller.h"
20 #include "app_grid.h"
21 #include "dynamic_index.h"
22
23 static struct {
24         Evas_Object *all_apps;
25         Evas_Object *parent;
26         Evas_Coord w;
27         Evas_Coord h;
28
29         dynamic_index_t *index;
30
31         bool anim_base_positions_actual;
32         int anim_base_pos_x;
33         int anim_base_pos_y;
34
35 } s_info = {
36         .all_apps = NULL,
37         .parent = NULL,
38         .w = -1,
39         .h = -1,
40
41         .index = NULL,
42
43         /*these variables are used during animation transitions:*/
44         .anim_base_positions_actual = false,
45         .anim_base_pos_x = -1,
46         .anim_base_pos_y = -1
47 };
48
49
50 static bool __all_apps_fill(void);
51
52 HAPI void all_apps_detach_from_grid(Elm_Object_Item *grid_item)
53 {
54         LOGI("");
55         if (!grid_item) {
56                 LOGE("[INVALID_ARG][grid_item='%p']" , grid_item);
57                 return;
58         }
59
60         app_grid_unpack_item(grid_item);
61         elm_object_item_del(grid_item);
62 }
63
64 HAPI Elm_Object_Item *all_apps_attach_to_grid(Evas_Object *icon, int grid_num)
65 {
66         Evas_Object *grid = NULL;
67
68         if (!icon) {
69                 LOGE("icon == NULL");
70                 return NULL;
71         }
72
73         grid = page_scroller_get_page(s_info.all_apps, grid_num);
74
75         if (home_screen_get_view_type() == HOMESCREEN_VIEW_ALL_APPS_CHOOSE)
76                 elm_object_signal_emit(icon, SIGNAL_EDIT_MODE_OFF, SIGNAL_SOURCE);
77
78         return app_grid_append_item(grid, icon);
79 }
80
81 HAPI Evas_Object *all_apps_create(Evas_Object *parent, void *data)
82 {
83         Evas_Object *p_edje = NULL;
84
85         /*Created before!*/
86         if (!parent) {
87                 LOGE("[INVALID_ARG][parent='%p'][data='%p']" , parent, data);
88                 return NULL;
89         }
90         s_info.parent = parent;
91
92         p_edje = elm_layout_edje_get(parent);
93         edje_object_part_geometry_get(p_edje, PART_CONTENT , NULL , NULL, &s_info.w, &s_info.h);
94
95         if (s_info.w < 0 || s_info.h < 0) {
96                 LOGE("[FAILED][edje_object_part_geometry_get][w='%d'][h='%d']", s_info.w, s_info.h);
97                 return NULL;
98         }
99
100         s_info.all_apps = page_scroller_create(s_info.w, s_info.h);
101         if (!s_info.all_apps) {
102                 LOGE("[FAILED][page_scroller_create]");
103                 return NULL;
104         }
105
106         if (!__all_apps_fill()) {
107                 LOGE("[FAILED][__all_apps_fill]");
108                 page_scroller_destroy(s_info.all_apps);
109                 s_info.all_apps = NULL;
110                 return NULL;
111         }
112
113         s_info.index = dynamic_index_new(s_info.all_apps);
114         if (!s_info.index) {
115                 LOGE("[FAILED][dynamic_index_new]");
116                 page_scroller_destroy(s_info.all_apps);
117                 s_info.all_apps = NULL;
118                 return NULL;
119         }
120
121         evas_object_size_hint_min_set(s_info.all_apps, home_screen_get_root_width(), home_screen_get_root_height());
122         evas_object_resize(s_info.all_apps, home_screen_get_root_width(), home_screen_get_root_height());
123         evas_object_move(s_info.all_apps, 0, home_screen_get_root_height());
124
125         return s_info.all_apps;
126 }
127
128 HAPI void all_apps_show(void)
129 {
130         if (s_info.index) {
131                 elm_object_part_content_set(s_info.parent, PART_INDEX, s_info.index->box);
132                 evas_object_show(s_info.index->box);
133         }
134 }
135
136 HAPI void all_apps_hide(void)
137 {
138         elm_object_part_content_unset(s_info.parent, PART_INDEX);
139         if (s_info.index)
140                 evas_object_hide(s_info.index->box);
141
142 }
143
144 HAPI void all_apps_del(void)
145 {
146         /*app_grids was added into all_apps so it should be removed
147         when this object will be deleted.*/
148         dynamic_index_del(s_info.index);
149         s_info.index = NULL;
150
151         evas_object_del(s_info.all_apps);
152         s_info.all_apps = NULL;
153 }
154
155 HAPI void all_apps_set_view_mode(homescreen_view_t view)
156 {
157         data_model_set_view_mode(view);
158 }
159
160 HAPI void all_apps_set_scrolling_blocked_state(bool is_blocked)
161 {
162         if (is_blocked) page_scroller_freeze(s_info.all_apps);
163         else page_scroller_unfreeze(s_info.all_apps);
164 }
165
166 HAPI bool all_apps_append_page(Tree_node_t *page_item)
167 {
168         Evas_Object *app_grid = app_grid_create(s_info.all_apps, page_item, s_info.w, s_info.h, APP_GRID_TYPE_ALL_APPS);
169
170         if (!app_grid) {
171                 LOGE("[FAILED][app_grid_create]");
172                 return false;
173         }
174
175         if (!page_scroller_add_page(s_info.all_apps, app_grid)) {
176                 LOGE("[FAILED][page_scroller_page_add]");
177                 evas_object_del(app_grid);
178                 return false;
179         }
180
181         return true;
182 }
183
184 HAPI void all_apps_remove_empty_pages(void)
185 {
186         Evas_Object *empty_page_layout = NULL, *page_layout = NULL, *gengrid_inside_layout = NULL;
187         int i = 0;
188
189         do {
190                 i = 0;
191                 empty_page_layout = NULL;
192
193                 while ((page_layout = page_scroller_get_page(s_info.all_apps, i++))) {
194                         gengrid_inside_layout = elm_object_part_content_get(page_layout, PART_APP_GRID_CONTENT);
195
196                         if (elm_gengrid_items_count(gengrid_inside_layout) == 0) {
197                                 empty_page_layout = page_layout;
198                                 break;
199                         }
200                 }
201                 page_scroller_remove_page(s_info.all_apps, empty_page_layout);
202         } while (empty_page_layout);
203 }
204
205 HAPI void all_apps_update_dynamic_index_count(void)
206 {
207         elm_object_signal_emit(s_info.all_apps, "scroller,count,changed", "layout");
208 }
209
210 static bool __all_apps_fill(void)
211 {
212         Tree_node_t *it = NULL;
213         Tree_node_t *data_model = (Tree_node_t *)data_model_get_all_apps();
214
215         if (!data_model) {
216                 LOGE("[FAILED][data_model_tree_get");
217                 return false;
218         }
219
220         TREE_NODE_FOREACH(data_model, it)
221                 if (!all_apps_append_page(it))
222                         return false;
223
224         return true;
225 }