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>
25 #include "data_photo.h"
28 #define GENGRID_ITEM_SIZE 200
30 enum input_handler_type {
31 INPUT_HANDLER_TYPE_GRID,
32 INPUT_HANDLER_TYPE_NO_CONTENTS,
33 INPUT_HANDLER_TYPE_DONE,
34 INPUT_HANDLER_TYPE_CANCEL
43 Elm_Gengrid_Item_Class *grid_ic;
50 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
51 Evas_Event_Key_Down *ev);
53 static void _mouse_up(int id, void *data, Evas *e, Evas_Object *obj,
54 Evas_Event_Mouse_Up *ev);
56 static input_handler handler = {
57 .key_down = _key_down,
61 static void _delete_popup(struct _priv *priv, Evas_Object *obj)
63 inputmgr_remove_callback(obj, &handler);
64 evas_object_del(priv->popup);
68 static void _select_done(struct _priv *priv, Evas_Object *obj)
72 _delete_popup(priv, obj);
73 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
74 thumb = elm_object_item_data_get(priv->cur);
76 viewmgr_update_view(VIEW_USER_EDIT,
77 UPDATE_TYPE_PHOTO, thumb);
82 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
83 Evas_Event_Key_Down *ev)
85 struct _priv *priv = data;
88 case INPUT_HANDLER_TYPE_GRID:
90 case INPUT_HANDLER_TYPE_NO_CONTENTS:
91 if (!strcmp(ev->keyname, KEY_BACK) ||
92 !strcmp(ev->keyname, KEY_BACK_REMOTE))
95 case INPUT_HANDLER_TYPE_DONE:
100 if (!strcmp(ev->keyname, KEY_ENTER) ||
101 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
102 _select_done(priv, obj);
103 } else if (!strcmp(ev->keyname, KEY_BACK) ||
104 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
105 _delete_popup(priv, obj);
106 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
107 elm_object_focus_set(priv->grid, EINA_TRUE);
110 case INPUT_HANDLER_TYPE_CANCEL:
115 if (!strcmp(ev->keyname, KEY_ENTER) ||
116 !strcmp(ev->keyname, KEY_ENTER_REMOTE) ||
117 !strcmp(ev->keyname, KEY_BACK) ||
118 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
119 _delete_popup(priv, obj);
120 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
121 elm_object_focus_set(priv->grid, EINA_TRUE);
129 static void _mouse_up(int id, void *data, Evas *e, Evas_Object *obj,
130 Evas_Event_Mouse_Up *ev)
135 case INPUT_HANDLER_TYPE_DONE:
140 _select_done(priv, obj);
142 case INPUT_HANDLER_TYPE_CANCEL:
147 _delete_popup(priv, obj);
148 elm_object_focus_allow_set(priv->grid, EINA_TRUE);
149 elm_object_focus_set(priv->grid, EINA_TRUE);
156 static Evas_Object *_create(Evas_Object *win, void *data)
163 _ERR("Invalid argument");
167 priv = calloc(1, sizeof(*priv));
169 _ERR("failed to calloc priv");
173 dm = datamgr_init(datamgr_photo_get_dclass(), VIEW_PHOTO);
175 _ERR("failed to initialize datamgr");
180 base = utils_add_layout(win, GRP_PHOTO, false, NULL);
182 _ERR("failed to create base");
187 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
189 elm_win_resize_object_add(win, base);
195 viewmgr_set_view_data(VIEW_PHOTO, priv);
200 static void _load_no_content(struct _priv *priv)
204 ly = utils_add_layout(priv->base, GRP_PHOTO_NO_CONTENT, true,
207 _ERR("failed to create layout");
210 evas_object_show(ly);
211 inputmgr_add_callback(ly, INPUT_HANDLER_TYPE_NO_CONTENTS, &handler,
217 static Evas_Object *_add_photo_grid(struct _priv *priv)
221 grid = elm_gengrid_add(priv->base);
223 _ERR("failed to add gend grid");
226 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
228 elm_object_part_content_set(priv->base, PART_PHOTO_LIST, grid);
229 elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
230 elm_gengrid_multi_select_set(grid, EINA_FALSE);
231 elm_gengrid_item_size_set(grid,
232 GENGRID_ITEM_SIZE * elm_config_scale_get(),
233 GENGRID_ITEM_SIZE * elm_config_scale_get());
234 elm_gengrid_horizontal_set(grid, EINA_TRUE);
235 elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF,
236 ELM_SCROLLER_POLICY_OFF);
237 elm_gengrid_align_set(grid, 0.0, 0.5);
238 evas_object_show(grid);
240 inputmgr_add_callback(grid, INPUT_HANDLER_TYPE_GRID, &handler, priv);
245 static Evas_Object *_get_grid_content(void *data, Evas_Object *obj,
248 Evas_Object *img = NULL;
250 if (!strcmp(part, PART_SWALLOW_ICON)) {
251 img = utils_add_icon(obj, data, NULL);
253 _ERR("failed to add image");
261 static void _add_viewer_popup(struct _priv *priv, char *file)
263 Evas_Object *popup, *ly, *cancel_btn, *done_btn, *img;
265 popup = utils_add_popup(priv->base, NULL, NULL);
267 _ERR("failed to add popup");
271 ly = utils_add_layout(popup, GRP_PHOTO_VIEWER, false,
272 PART_SWALLOW_CONTENT);
274 _ERR("failed to add layout");
275 evas_object_del(popup);
279 cancel_btn = utils_add_button(ly, MESSAGE_CANCEL,
280 PART_PHOTO_VIEWER_CANCEL);
282 _ERR("failed to add cancel button");
283 evas_object_del(popup);
286 inputmgr_add_callback(cancel_btn, INPUT_HANDLER_TYPE_CANCEL, &handler,
289 done_btn = utils_add_button(ly, MESSAGE_DONE, PART_PHOTO_VIEWER_DONE);
291 _ERR("failed to add done button");
292 evas_object_del(popup);
295 inputmgr_add_callback(done_btn, INPUT_HANDLER_TYPE_DONE, &handler,
298 elm_object_focus_set(cancel_btn, EINA_TRUE);
300 img = utils_add_icon(ly, file, PART_PHOTO_VIEWER);
302 _ERR("failed to add icon");
303 evas_object_del(popup);
307 elm_object_focus_set(cancel_btn, EINA_TRUE);
311 static void _select_item(void *data, Evas_Object *obj, void *ei)
313 struct _priv *priv = data;
316 thumb = elm_object_item_data_get(ei);
318 _ERR("failed to get data");
322 elm_object_focus_allow_set(priv->grid, EINA_FALSE);
323 _add_viewer_popup(priv, thumb);
328 static bool _add_photo_item(struct _priv *priv, Evas_Object *grid,
331 Elm_Gengrid_Item_Class *ic;
332 Elm_Object_Item *item;
336 elm_gengrid_clear(grid);
338 ic = elm_gengrid_item_class_new();
340 _ERR("failed to add gengrid item class");
344 ic->item_style = STYLE_GENGRID_ITEM;
345 ic->func.text_get = NULL;
346 ic->func.content_get = _get_grid_content;
347 ic->func.state_get = NULL;
350 EINA_LIST_FOREACH(dlist, l, thumb) {
351 item = elm_gengrid_item_append(grid, ic, thumb,
356 elm_object_item_data_set(item, thumb);
357 priv->plist = eina_list_append(priv->plist, item);
360 priv->cur = elm_gengrid_first_item_get(grid);
366 static void _load_photo(struct _priv *priv)
371 dlist = datamgr_get_items(priv->dm);
373 _load_no_content(priv);
377 grid = _add_photo_grid(priv);
379 _ERR("failed to add grid");
383 if (!_add_photo_item(priv, grid, dlist)) {
384 _ERR("failed to add photo item");
385 evas_object_del(grid);
386 _load_no_content(priv);
390 elm_win_focus_highlight_enabled_set(priv->win, EINA_TRUE);
394 static void _show(void *data)
399 _ERR("Invalid argument");
405 evas_object_show(priv->base);
410 elm_object_focus_set(priv->ly, EINA_TRUE);
412 elm_object_focus_set(priv->grid, EINA_TRUE);
415 static void _hide(void *data)
420 _ERR("Invalid argument");
426 inputmgr_remove_callback(priv->ly, &handler);
427 evas_object_del(priv->ly);
430 elm_gengrid_item_class_free(priv->grid_ic);
431 inputmgr_remove_callback(priv->grid, &handler);
432 evas_object_del(priv->grid);
436 evas_object_hide(priv->base);
437 elm_win_focus_highlight_enabled_set(priv->win, EINA_FALSE);
440 static void _destroy(void *data)
445 _ERR("Invalid argument");
451 evas_object_del(priv->base);
455 static view_class vclass = {
456 .view_id = VIEW_PHOTO,
463 view_class *view_photo_get_vclass(void)