3 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <Elementary.h>
19 #include <app_debug.h>
24 #include "view_photo.h"
25 #include "data_photo.h"
28 #define GENGRID_ITEM_SIZE 200
36 Elm_Gengrid_Item_Class *grid_ic;
43 static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj,
44 Evas_Event_Key_Down *ev);
46 static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj,
47 Evas_Event_Key_Down *ev);
49 static Evas_Object *_create(Evas_Object *win, void *data)
56 _ERR("Invalid argument");
60 priv = calloc(1, sizeof(*priv));
62 _ERR("failed to calloc priv");
66 dm = datamgr_init(datamgr_photo_get_dclass(), VIEW_PHOTO);
68 _ERR("failed to initialize datamgr");
73 base = utils_add_layout(win, GRP_PHOTO, false, NULL);
75 _ERR("failed to create base");
80 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
82 elm_win_resize_object_add(win, base);
88 viewmgr_set_view_data(VIEW_PHOTO, priv);
93 static void _ly_key_down(int id, void *data, Evas *e, Evas_Object *obj,
94 Evas_Event_Key_Down *ev)
96 if (!strcmp(ev->keyname, KEY_BACK)) {
101 static input_handler ly_handler = {
102 .key_down = _ly_key_down
105 static void _load_no_content(struct _priv *priv)
109 ly = utils_add_layout(priv->base, GRP_PHOTO_NO_CONTENT, true,
112 _ERR("failed to create layout");
115 evas_object_show(ly);
116 inputmgr_add_callback(ly, 0, &ly_handler, NULL);
120 static void _grid_key_down(int id, void *data, Evas *e, Evas_Object *obj,
121 Evas_Event_Key_Down *ev)
123 if (!strcmp(ev->keyname, KEY_BACK)) {
128 static input_handler grid_handler = {
129 .key_down = _grid_key_down
132 static Evas_Object *_add_photo_grid(struct _priv *priv)
136 grid = elm_gengrid_add(priv->base);
138 _ERR("failed to add gend grid");
141 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
143 elm_object_part_content_set(priv->base, PART_PHOTO_LIST, grid);
144 elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
145 elm_gengrid_multi_select_set(grid, EINA_FALSE);
146 elm_gengrid_item_size_set(grid,
147 GENGRID_ITEM_SIZE * elm_config_scale_get(),
148 GENGRID_ITEM_SIZE * elm_config_scale_get());
149 elm_gengrid_horizontal_set(grid, EINA_TRUE);
150 elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF,
151 ELM_SCROLLER_POLICY_OFF);
152 elm_gengrid_align_set(grid, 0.0, 0.5);
153 evas_object_show(grid);
155 inputmgr_add_callback(grid, 0, &grid_handler, priv);
160 static Evas_Object *_get_grid_content(void *data, Evas_Object *obj,
163 Evas_Object *img = NULL;
165 if (!strcmp(part, PART_SWALLOW_ICON)) {
166 img = utils_add_icon(obj, data, NULL);
168 _ERR("failed to add image");
171 elm_image_fill_outside_set(img, EINA_TRUE);
177 static void _delete_popup(struct _priv *priv, input_handler *handler,
180 inputmgr_remove_callback(obj, handler);
181 evas_object_del(priv->popup);
185 static input_handler cancel_handler = {
186 .key_down = _cancel_key_down
189 static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj,
190 Evas_Event_Key_Down *ev)
192 struct _priv *priv = data;
194 if (!strcmp(ev->keyname, KEY_ENTER) ||
195 !strcmp(ev->keyname, KEY_ENTER_REMOTE) ||
196 !strcmp(ev->keyname, KEY_BACK) ||
197 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
198 _delete_popup(priv, &cancel_handler, obj);
199 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
200 elm_object_focus_set(priv->grid, EINA_TRUE);
204 static input_handler done_handler = {
205 .key_down = _done_key_down
208 static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj,
209 Evas_Event_Key_Down *ev)
211 struct _priv *priv = data;
213 if (!strcmp(ev->keyname, KEY_ENTER) ||
214 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
215 _delete_popup(priv, &done_handler, obj);
216 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
217 elm_object_focus_set(priv->grid, EINA_TRUE);
218 } else if (!strcmp(ev->keyname, KEY_BACK) ||
219 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
220 _delete_popup(priv, &done_handler, obj);
221 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
222 elm_object_focus_set(priv->grid, EINA_TRUE);
226 static void _add_viewer_popup(struct _priv *priv, char *file)
228 Evas_Object *popup, *ly, *cancel_btn, *done_btn, *img;
230 popup = utils_add_popup(priv->base, NULL, NULL);
232 _ERR("failed to add popup");
236 ly = utils_add_layout(popup, GRP_PHOTO_VIEWER, false,
237 PART_SWALLOW_CONTENT);
239 _ERR("failed to add layout");
240 evas_object_del(popup);
244 cancel_btn = utils_add_button(ly, MESSAGE_CANCEL,
245 PART_PHOTO_VIEWER_CANCEL);
247 _ERR("failed to add cancel button");
248 evas_object_del(popup);
251 inputmgr_add_callback(cancel_btn, 0, &cancel_handler, priv);
253 done_btn = utils_add_button(ly, MESSAGE_DONE, PART_PHOTO_VIEWER_DONE);
255 _ERR("failed to add done button");
256 evas_object_del(popup);
259 inputmgr_add_callback(done_btn, 0, &done_handler, priv);
261 elm_object_focus_set(cancel_btn, EINA_TRUE);
263 img = utils_add_icon(ly, file, PART_PHOTO_VIEWER);
265 _ERR("failed to add icon");
266 evas_object_del(popup);
269 elm_image_fill_outside_set(img, EINA_TRUE);
271 elm_object_focus_set(cancel_btn, EINA_TRUE);
275 static void _select_item(void *data, Evas_Object *obj, void *ei)
277 struct _priv *priv = data;
280 thumb = elm_object_item_data_get(ei);
282 _ERR("failed to get data");
286 elm_object_focus_allow_set(priv->grid, EINA_FALSE);
287 _add_viewer_popup(priv, thumb);
292 static bool _add_photo_item(struct _priv *priv, Evas_Object *grid,
295 Elm_Gengrid_Item_Class *ic;
296 Elm_Object_Item *item;
300 elm_gengrid_clear(grid);
302 ic = elm_gengrid_item_class_new();
304 _ERR("failed to add gengrid item class");
308 ic->item_style = STYLE_GENGRID_ITEM;
309 ic->func.text_get = NULL;
310 ic->func.content_get = _get_grid_content;
311 ic->func.state_get = NULL;
314 EINA_LIST_FOREACH(dlist, l, thumb) {
315 item = elm_gengrid_item_append(grid, ic, thumb,
320 elm_object_item_data_set(item, thumb);
321 priv->plist = eina_list_append(priv->plist, item);
324 priv->cur = elm_gengrid_first_item_get(grid);
330 static void _load_photo(struct _priv *priv)
335 dlist = datamgr_get_items(priv->dm);
337 _load_no_content(priv);
341 grid = _add_photo_grid(priv);
343 _ERR("failed to add grid");
347 if (!_add_photo_item(priv, grid, dlist)) {
348 _ERR("failed to add photo item");
349 evas_object_del(grid);
350 _load_no_content(priv);
354 elm_win_focus_highlight_enabled_set(priv->win, EINA_TRUE);
358 static void _show(void *data)
363 _ERR("Invalid argument");
369 evas_object_show(priv->base);
374 elm_object_focus_set(priv->ly, EINA_TRUE);
376 elm_object_focus_set(priv->grid, EINA_TRUE);
379 static void _hide(void *data)
384 _ERR("Invalid argument");
390 inputmgr_remove_callback(priv->ly, &ly_handler);
391 evas_object_del(priv->ly);
394 elm_gengrid_item_class_free(priv->grid_ic);
395 inputmgr_remove_callback(priv->grid, &grid_handler);
396 evas_object_del(priv->grid);
400 evas_object_hide(priv->base);
401 elm_win_focus_highlight_enabled_set(priv->win, EINA_FALSE);
404 static void _destroy(void *data)
409 _ERR("Invalid argument");
415 evas_object_del(priv->base);
419 static view_class vclass = {
420 .view_id = VIEW_PHOTO,
427 view_class *view_photo_get_vclass(void)