From 3460b6532f47251a561087017f78db1750476c88 Mon Sep 17 00:00:00 2001 From: Hyojung Jo Date: Wed, 1 Jul 2015 16:58:58 +0900 Subject: [PATCH] Applied the changed gridmgr API Change-Id: I5883a20091328ccd7a03027a8c45681112ac78ea Signed-off-by: Hyojung Jo --- include/define.h | 8 -- src/grid/grid_apps.c | 1 - src/grid/grid_gallery.c | 1 - src/grid/grid_movie.c | 1 - src/grid/grid_music.c | 1 - src/grid/grid_tv.c | 1 - src/grid/grid_webs.c | 1 - src/view/view_base.c | 215 ++++++++++++++++++++++++++++++------------------ 8 files changed, 133 insertions(+), 96 deletions(-) diff --git a/include/define.h b/include/define.h index af49e5b..41713ba 100644 --- a/include/define.h +++ b/include/define.h @@ -20,14 +20,6 @@ /* View ID */ #define VIEW_ID_BASE "VIEW_ID_BASE" -/* Grid ID */ -#define GRID_ID_TV "GRID_TV" -#define GRID_ID_MOVIE "GRID_MOVIE" -#define GRID_ID_GALLERY "GRID_GALLERY" -#define GRID_ID_MUSIC "GRID_MUSIC" -#define GRID_ID_APPS "GRID_APPS" -#define GRID_ID_WEBS "GRID_WEBS" - /* Group */ #define GRP_VIEW_BASE "grp.view.base" diff --git a/src/grid/grid_apps.c b/src/grid/grid_apps.c index fb1c8f0..6b56143 100644 --- a/src/grid/grid_apps.c +++ b/src/grid/grid_apps.c @@ -66,7 +66,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_APPS, .item_style = STYLE_APPS, .text_get = _text_get, .content_get = _content_get, diff --git a/src/grid/grid_gallery.c b/src/grid/grid_gallery.c index 39b999f..1de2232 100644 --- a/src/grid/grid_gallery.c +++ b/src/grid/grid_gallery.c @@ -49,7 +49,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_GALLERY, .item_style = STYLE_GALLERY, .text_get = _text_get, .content_get = _content_get, diff --git a/src/grid/grid_movie.c b/src/grid/grid_movie.c index ea4bd56..d6f4dc5 100644 --- a/src/grid/grid_movie.c +++ b/src/grid/grid_movie.c @@ -35,7 +35,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_MOVIE, .item_style = STYLE_MOVIE, .text_get = _text_get, .content_get = _content_get, diff --git a/src/grid/grid_music.c b/src/grid/grid_music.c index 9a0ed4b..0e782fd 100644 --- a/src/grid/grid_music.c +++ b/src/grid/grid_music.c @@ -38,7 +38,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_MUSIC, .item_style = STYLE_MUSIC, .text_get = _text_get, .content_get = _content_get, diff --git a/src/grid/grid_tv.c b/src/grid/grid_tv.c index a8a5124..5c5a0e6 100644 --- a/src/grid/grid_tv.c +++ b/src/grid/grid_tv.c @@ -35,7 +35,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_TV, .item_style = STYLE_TV, .text_get = _text_get, .content_get = _content_get, diff --git a/src/grid/grid_webs.c b/src/grid/grid_webs.c index b117b4e..fa0d813 100644 --- a/src/grid/grid_webs.c +++ b/src/grid/grid_webs.c @@ -35,7 +35,6 @@ static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *part) } static struct grid_class _gclass = { - .grid_id = GRID_ID_WEBS, .item_style = STYLE_WEBS, .text_get = _text_get, .content_get = _content_get, diff --git a/src/view/view_base.c b/src/view/view_base.c index a5eaf84..d432300 100644 --- a/src/view/view_base.c +++ b/src/view/view_base.c @@ -31,15 +31,21 @@ #include "grid/grid_apps.h" #include "grid/grid_webs.h" -enum grid_type { - GRID_INVALID = -1, - GRID_TV = 0, - GRID_MOVIE, - GRID_GALLERY, - GRID_MUSIC, - GRID_APPS, - GRID_WEBS, - GRID_MAX +enum menu_type { + MENU_INVALID = -1, + MENU_TV = 0, + MENU_MOVIE, + MENU_GALLERY, + MENU_MUSIC, + MENU_APPS, + MENU_WEBS, + MENU_MAX +}; + +struct _menu_data { + Evas_Object *btn; + Evas_Object *grid; + Eina_List *list; }; struct _priv { @@ -47,10 +53,8 @@ struct _priv { Evas_Object *win; Evas_Object *base; Evas_Object *box; - Evas_Object *menu_btn[GRID_MAX]; - Evas_Object *grid; - Eina_List *list[GRID_MAX]; - enum grid_type cur_grid; + struct _menu_data *mdata[MENU_MAX]; + enum menu_type cur_menu; }; const char *str_menu[] = { @@ -64,12 +68,12 @@ const char *str_menu[] = { }; static struct grid_class *(*_get_grid_class[])(void) = { - [GRID_TV] = get_tv_grid_class, - [GRID_MOVIE] = get_movie_grid_class, - [GRID_GALLERY] = get_gallery_grid_class, - [GRID_MUSIC] = get_music_grid_class, - [GRID_APPS] = get_apps_grid_class, - [GRID_WEBS] = get_webs_grid_class + [MENU_TV] = get_tv_grid_class, + [MENU_MOVIE] = get_movie_grid_class, + [MENU_GALLERY] = get_gallery_grid_class, + [MENU_MUSIC] = get_music_grid_class, + [MENU_APPS] = get_apps_grid_class, + [MENU_WEBS] = get_webs_grid_class }; static void _clicked_cb(int id, void *data, Evas_Object *obj); @@ -81,76 +85,69 @@ static input_handler _input_handler = { /* It will be implemented later. */ }; -static Eina_List *_get_contents_list(enum grid_type type) +static Eina_List *_get_contents_list(enum menu_type type) { switch (type) { - case GRID_TV: + case MENU_TV: /* It will be implemented later. */ return NULL; - case GRID_MOVIE: + case MENU_MOVIE: /* It will be implemented later. */ return NULL; - case GRID_GALLERY: + case MENU_GALLERY: return get_media_favorite_list(CONTENTS_GALLERY); - case GRID_MUSIC: + case MENU_MUSIC: return get_media_favorite_list(CONTENTS_MUSIC); - case GRID_APPS: + case MENU_APPS: return get_app_favorite_list(); - case GRID_WEBS: + case MENU_WEBS: /* It will be implemented later. */ return NULL; default: - _ERR("Invalid data type."); + _ERR("Invalid menu type."); return NULL; } } static bool _load_current_contents(struct _priv *priv) { + struct _menu_data *mdata; Eina_List *list = NULL; - struct grid_class *gclass; + enum menu_type type; - if (!priv || !priv->gmgr || !priv->grid) { + if (!priv || !priv->gmgr || priv->cur_menu <= MENU_INVALID + || priv->cur_menu >= MENU_MAX) { _ERR("Invalid argument."); return false; } + type = priv->cur_menu; - if (!priv->list[priv->cur_grid]) { - list = _get_contents_list(priv->cur_grid); + mdata = priv->mdata[type]; + if (!mdata || !mdata->grid) + return false; + + if (!mdata->list) { + list = _get_contents_list(type); if (!list) { /* 'No contents' should be displayed. */ return true; } - priv->list[priv->cur_grid] = list; + mdata->list = list; } - gclass = _get_grid_class[priv->cur_grid](); - if (!gclass) { - _ERR("Get gclass failed."); + if (!gridmgr_append_list(priv->gmgr, str_menu[type], mdata->list)) { + _ERR("Gridmgr append list failed."); return false; } - elm_object_part_content_set(priv->base, PART_GENGRID, priv->grid); - - if (!gridmgr_add_grid(priv->gmgr, gclass)) { - _ERR("Gridmgr add grid failed."); - gridmgr_destroy(priv->gmgr); - return false; - } - - if (!gridmgr_append_all(priv->gmgr, gclass->grid_id, priv->grid, - priv->list[priv->cur_grid])) { - _ERR("Gridmgr update grid failed."); - gridmgr_destroy(priv->gmgr); - return false; - } + elm_object_part_content_set(priv->base, PART_GENGRID, mdata->grid); return true; } @@ -171,10 +168,10 @@ static void _focused_cb(int id, void *data, Evas_Object *obj, } priv = data; - if (priv->cur_grid == id) + if (priv->cur_menu == id) return; - priv->cur_grid = id; + priv->cur_menu = id; if (!_load_current_contents(priv)) _ERR("Load current grid view failed."); @@ -182,6 +179,7 @@ static void _focused_cb(int id, void *data, Evas_Object *obj, static bool _draw_top_area(struct _priv *priv) { + Evas_Object *btn; int i; if (!priv || !priv->base) { @@ -197,18 +195,18 @@ static bool _draw_top_area(struct _priv *priv) return false; } - for (i = GRID_INVALID + 1; i < GRID_MAX; i++) { - priv->menu_btn[i] = add_button(priv->box, NULL); - if (!priv->menu_btn[i]) { + for (i = MENU_INVALID + 1; i < MENU_MAX; i++) { + btn = add_button(priv->box, NULL); + if (!btn) { _ERR("Add button failed."); evas_object_del(priv->box); return false; } - elm_box_pack_end(priv->box, priv->menu_btn[i]); + elm_box_pack_end(priv->box, btn); + inputmgr_add_callback(btn, i, &_input_handler, priv); - inputmgr_add_callback(priv->menu_btn[i], - i, &_input_handler, priv); + priv->mdata[i]->btn = btn; } /* It will be implemented more later. */ @@ -216,11 +214,50 @@ static bool _draw_top_area(struct _priv *priv) return true; } +static Evas_Object *_add_grid(struct _priv *priv, enum menu_type type) +{ + struct grid_class *gclass; + Evas_Object *grid; + + if (!priv || !priv->base || !priv->gmgr + || type <= MENU_INVALID || type >= MENU_MAX) { + _ERR("Invalid argument."); + return NULL; + } + + grid = elm_gengrid_add(priv->base); + if (!grid) { + _ERR("elm_gengrid_add failed."); + return NULL; + } + + evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); + + gclass = _get_grid_class[type](); + if (!gclass) { + _ERR("Get gclass failed."); + evas_object_del(grid); + return NULL; + } + + if (!gridmgr_add_grid(priv->gmgr, str_menu[type], grid, gclass)) { + _ERR("Gridmgr add grid failed."); + evas_object_del(grid); + return NULL; + } + + return grid; +} + static Evas_Object *_create(Evas_Object *win, void *data) { struct _priv *priv; + struct _menu_data *mdata; struct gridmgr *gmgr; Evas_Object *base, *grid; + int i; if (!win) { _ERR("Invalid argument."); @@ -242,37 +279,49 @@ static Evas_Object *_create(Evas_Object *win, void *data) elm_win_resize_object_add(win, base); - grid = elm_gengrid_add(base); - if (!grid) { - _ERR("elm_gengrid_add failed."); - goto end; - } - - evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); - gmgr = gridmgr_create(); if (!gmgr) { _ERR("Grid manager initialized failed."); - goto end; + evas_object_del(base); + free(priv); + return NULL; } priv->win = win; priv->base = base; - priv->grid = grid; priv->gmgr = gmgr; + for (i = MENU_INVALID + 1; i < MENU_MAX; i++) { + grid = _add_grid(priv, i); + if (!grid) { + _ERR("Add grid failed."); + goto err; + } + + mdata = calloc(1, sizeof(*mdata)); + if (!mdata) { + _ERR("Calloc failed."); + goto err; + } + + mdata->grid = grid; + priv->mdata[i] = mdata; + } + if (!viewmgr_set_view_data(VIEW_ID_BASE, priv)) { _ERR("Set view data failed."); - gridmgr_destroy(gmgr); - goto end; + goto err; } return base; -end: +err: + gridmgr_destroy(gmgr); evas_object_del(base); + + for (i = MENU_INVALID + 1; i < MENU_MAX; i++) + free(priv->mdata[i]); + free(priv); return NULL; @@ -309,32 +358,32 @@ static void _hide(void *data) evas_object_hide(priv->base); } -static void _destroy_data_list(Eina_List *list, enum grid_type type) +static void _destroy_data_list(Eina_List *list, enum menu_type type) { if (!list) return; switch (type) { - case GRID_TV: + case MENU_TV: /* It will be implemented later. */ break; - case GRID_MOVIE: - case GRID_GALLERY: - case GRID_MUSIC: + case MENU_MOVIE: + case MENU_GALLERY: + case MENU_MUSIC: free_media_favorite_list(list); break; - case GRID_APPS: + case MENU_APPS: free_app_favorite_list(list); break; - case GRID_WEBS: + case MENU_WEBS: /* It will be implemented later. */ break; default: - _ERR("Invalid grid type."); + _ERR("Invalid menu type."); return; } } @@ -350,8 +399,10 @@ static void _destroy(void *data) } priv = data; - for (i = GRID_INVALID + 1; i < GRID_MAX; i++) - _destroy_data_list(priv->list[i], i); + for (i = MENU_INVALID + 1; i < MENU_MAX; i++) { + _destroy_data_list(priv->mdata[i]->list, i); + free(priv->mdata[i]); + } if (priv->base) evas_object_del(priv->base); -- 2.7.4