--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_MEDIAHUB_LISTMGR_H__
+#define __AIR_MEDIAHUB_LISTMGR_H__
+
+struct listmgr;
+
+struct listmgr_data {
+ int grid_item_x;
+ int grid_item_y;
+ int grid_num_item;
+
+ int box_padding;
+
+ struct grid_class *gclass;
+};
+
+struct listmgr *listmgr_create(Evas_Object *base, void *data);
+void listmgr_destroy(struct listmgr *listmgr);
+
+bool listmgr_draw_list_area(struct listmgr *lmgr);
+bool listmgr_update_list_area(struct listmgr *lmgr, Eina_List *list);
+
+#endif /* __AIR_MEDIAHUB_LISTMGR_H__ */
#include <media_content.h>
#include <app_debug.h>
#include <app_media.h>
-#include <layoutmgr.h>
#include <gridmgr.h>
+#include <layoutmgr.h>
#include "define.h"
#include "data/mediadata.h"
-#include "util/util.h"
+#include "util/listmgr.h"
#define LIST_MEDIA_COND "media_type=1 AND copyright NOT LIKE \"Unknown\""
-#define TEXT_NOCONTENT "No Movie Content"
+#define TEXT_NOCONTENT "No Movies"
-#define NUM_CONTENT 2
-#define SIZE_GRID_ITEM_X 404
-#define SIZE_GRID_ITEM_Y 320
+#define GRID_ITEM_X 404
+#define GRID_ITEM_Y 320
+#define GRID_NUM_ITEM 2
-#define PADDING_BOX_ITEM 62
+#define BOX_PADDING 62
struct _priv {
Evas_Object *base;
layoutmgr *lmgr;
- struct gridmgr *gmgr;
+ struct listmgr *listmgr;
struct mediadata *md;
return NULL;
}
-static struct grid_class gclass = {
+static struct grid_class _gclass = {
.item_style = STYLE_GRID_MOVIE_ITEM,
.text_get = _grid_text_get,
.content_get = _grid_content_get
};
-static int _get_grid_size(int count)
-{
- int size;
-
- size = count / NUM_CONTENT;
- if (count % NUM_CONTENT > 0)
- size++;
-
- return size;
-}
-
-static Evas_Object *_draw_list_item(struct _priv *priv, struct group_info *gi)
+static struct listmgr_data *_create_listmgr_data(void)
{
- Evas_Object *ly, *btn, *grid;
- int size;
-
- ly = elm_layout_add(priv->box);
- if (!ly) {
- _ERR("failed to create layout object");
- return NULL;
- }
-
- elm_layout_file_set(ly, EDJEFILE, GRP_LIST_ITEM);
-
- btn = elm_button_add(ly);
- if (!btn) {
- _ERR("failed to create button object");
- evas_object_del(ly);
- return NULL;
- }
-
- elm_object_style_set(btn, STYLE_BTN_INDEX);
- elm_object_text_set(btn, gi->name);
-
- grid = util_add_gengrid(ly, SIZE_GRID_ITEM_X, SIZE_GRID_ITEM_Y);
- if (!grid) {
- _ERR("failed to create gengrid object");
- evas_object_del(ly);
- return NULL;
- }
+ struct listmgr_data *data;
- if (!gridmgr_add_grid(priv->gmgr, gi->name, grid, &gclass)) {
- _ERR("failed to add grid");
- evas_object_del(ly);
+ data = calloc(1, sizeof(*data));
+ if (!data) {
+ _ERR("failed to allocate listmgr data");
return NULL;
}
- size = _get_grid_size(eina_list_count(gi->list));
+ data->grid_item_x = GRID_ITEM_X;
+ data->grid_item_y = GRID_ITEM_Y;
+ data->grid_num_item = GRID_NUM_ITEM;
+ data->box_padding = BOX_PADDING;
+ data->gclass = &_gclass;
- evas_object_size_hint_min_set(grid, size * SIZE_GRID_ITEM_X,
- NUM_CONTENT * SIZE_GRID_ITEM_Y);
-
- elm_object_part_content_set(ly, PART_ITEM_TITLE, btn);
- elm_object_part_content_set(ly, PART_ITEM_CONTENT, grid);
-
- return ly;
+ return data;
}
static void _update_list_area(struct _priv *priv)
{
- Eina_List *list, *l;
- Evas_Object *ly;
- struct group_info *gi;
+ Eina_List *list;
if (priv->media_list)
return;
return;
}
- EINA_LIST_FOREACH(list, l, gi) {
- ly = _draw_list_item(priv, gi);
- if (!ly) {
- _ERR("failed to draw list item");
- return;
- }
-
- if (!gridmgr_append_list(priv->gmgr, gi->name, gi->list)) {
- _ERR("failed to append list in grid");
- return;
- }
-
- evas_object_show(ly);
-
- elm_box_pack_end(priv->box, ly);
- }
+ if (!listmgr_update_list_area(priv->listmgr, list))
+ _ERR("failed to update list area");
priv->media_list = list;
}
-static bool _draw_list_area(struct _priv *priv)
-{
- Evas_Object *scr, *box;
-
- scr = util_add_scroller(priv->layout);
- if (!scr) {
- _ERR("failed to create scroller object");
- return false;
- }
-
- box = util_add_box(scr);
- if (!box) {
- _ERR("failed to create box object");
- evas_object_del(scr);
- return false;
- }
-
- elm_box_padding_set(box, PADDING_BOX_ITEM, 0);
-
- evas_object_show(box);
- elm_object_content_set(scr, box);
-
- elm_object_part_content_set(priv->layout, PART_CONTENT, scr);
-
- priv->box = box;
-
- return true;
-}
-
static bool _create(layoutmgr *lmgr, void *data)
{
- struct gridmgr *gmgr;
+ struct listmgr *listmgr;
+ struct listmgr_data *ldata;
struct mediadata *md;
struct _priv *priv;
Evas_Object *base, *layout;
goto err2;
}
- gmgr = gridmgr_create();
- if (!gmgr) {
- _ERR("failed to create gridmgr");
+ ldata = _create_listmgr_data();
+ if (!ldata) {
+ _ERR("failed to create listmgr data");
goto err2;
}
+ listmgr = listmgr_create(layout, (void *)ldata);
+ if (!listmgr) {
+ _ERR("failed to create listmgr");
+ goto err3;
+ }
+
md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_NAME);
if (!md) {
_ERR("failed to create mediadata");
- gridmgr_destroy(gmgr);
- goto err2;
+ listmgr_destroy(listmgr);
+ goto err3;
}
priv->base = base;
priv->layout = layout;
priv->lmgr = lmgr;
- priv->gmgr = gmgr;
+ priv->listmgr = listmgr;
priv->md = md;
layoutmgr_set_layout_data(lmgr, LAYOUT_MOVIE, priv);
- if (!_draw_list_area(priv)) {
+ if (!listmgr_draw_list_area(priv->listmgr)) {
_ERR("failed to draw list area");
mediadata_destroy(md);
- gridmgr_destroy(gmgr);
- goto err2;
+ listmgr_destroy(listmgr);
+ goto err3;
}
return true;
+err3:
+ free(ldata);
err2:
evas_object_del(layout);
err:
priv = layout_data;
- gridmgr_destroy(priv->gmgr);
-
mediadata_free_list(priv->media_list);
mediadata_destroy(priv->md);
+ listmgr_destroy(priv->listmgr);
+
evas_object_del(priv->layout);
free(priv);
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Elementary.h>
+#include <app_debug.h>
+#include <gridmgr.h>
+
+#include "define.h"
+#include "data/mediadata.h"
+#include "util/listmgr.h"
+#include "util/util.h"
+
+struct listmgr {
+ Evas_Object *base;
+ Evas_Object *box;
+
+ struct gridmgr *gmgr;
+ struct listmgr_data *data;
+};
+
+static int _get_grid_size(int count, int num_item)
+{
+ int size;
+
+ size = count / num_item;
+ if (count % num_item > 0)
+ size++;
+
+ return size;
+}
+
+static Evas_Object *_draw_list_item(struct listmgr *lmgr, struct group_info *gi)
+{
+ Evas_Object *ly, *btn, *grid;
+ struct listmgr_data *data;
+ int size;
+
+ data = lmgr->data;
+
+ ly = elm_layout_add(lmgr->box);
+ if (!ly) {
+ _ERR("failed to create layout object");
+ return NULL;
+ }
+
+ elm_layout_file_set(ly, EDJEFILE, GRP_LIST_ITEM);
+
+ btn = elm_button_add(ly);
+ if (!btn) {
+ _ERR("failed to create button object");
+ evas_object_del(ly);
+ return NULL;
+ }
+
+ elm_object_style_set(btn, STYLE_BTN_INDEX);
+ elm_object_text_set(btn, gi->name);
+
+ grid = util_add_gengrid(ly, data->grid_item_x, data->grid_item_y);
+ if (!grid) {
+ _ERR("failed to create gengrid object");
+ evas_object_del(ly);
+ return NULL;
+ }
+
+ if (!gridmgr_add_grid(lmgr->gmgr, gi->name, grid, data->gclass)) {
+ _ERR("failed to add grid");
+ evas_object_del(ly);
+ return NULL;
+ }
+
+ size = _get_grid_size(eina_list_count(gi->list), data->grid_num_item);
+
+ evas_object_size_hint_min_set(grid, size * data->grid_item_x,
+ data->grid_num_item * data->grid_item_y);
+
+ elm_object_part_content_set(ly, PART_ITEM_TITLE, btn);
+ elm_object_part_content_set(ly, PART_ITEM_CONTENT, grid);
+
+ return ly;
+}
+
+bool listmgr_update_list_area(struct listmgr *lmgr, Eina_List *list)
+{
+ Evas_Object *ly;
+ Eina_List *l;
+ struct group_info *gi;
+
+ if (!lmgr) {
+ _ERR("invalid argument");
+ return false;
+ }
+
+ EINA_LIST_FOREACH(list, l, gi) {
+ ly = _draw_list_item(lmgr, gi);
+ if (!ly) {
+ _ERR("failed to draw list item");
+ return false;
+ }
+
+ if (!gridmgr_append_list(lmgr->gmgr, gi->name, gi->list)) {
+ _ERR("failed to append list in grid");
+ return false;
+ }
+
+ evas_object_show(ly);
+
+ elm_box_pack_end(lmgr->box, ly);
+ }
+
+ return true;
+}
+
+bool listmgr_draw_list_area(struct listmgr *lmgr)
+{
+ Evas_Object *scr, *box;
+
+ if (!lmgr) {
+ _ERR("invalid argument");
+ return false;
+ }
+
+ scr = util_add_scroller(lmgr->base);
+ if (!scr) {
+ _ERR("failed to create scroller object");
+ return false;
+ }
+
+ box = util_add_box(scr);
+ if (!box) {
+ _ERR("failed to create box object");
+ evas_object_del(scr);
+ return false;
+ }
+
+ elm_box_padding_set(box, lmgr->data->box_padding, 0);
+
+ evas_object_show(box);
+ elm_object_content_set(scr, box);
+
+ elm_object_part_content_set(lmgr->base, PART_CONTENT, scr);
+
+ lmgr->box = box;
+
+ return true;
+}
+
+struct listmgr *listmgr_create(Evas_Object *base, void *data)
+{
+ struct gridmgr *gmgr;
+ struct listmgr *lmgr;
+
+ if (!base || !data) {
+ _ERR("invalid argument");
+ return NULL;
+ }
+
+ lmgr = calloc(1, sizeof(*lmgr));
+ if (!lmgr) {
+ _ERR("failed to allocate listmgr");
+ return NULL;
+ }
+
+ gmgr = gridmgr_create();
+ if (!gmgr) {
+ _ERR("failed to create gridmgr");
+ free(lmgr);
+ return false;
+ }
+
+ lmgr->base = base;
+ lmgr->gmgr = gmgr;
+ lmgr->data = (struct listmgr_data *)data;
+
+ return lmgr;
+}
+
+void listmgr_destroy(struct listmgr *lmgr)
+{
+ if (!lmgr) {
+ _ERR("invalid argument");
+ return;
+ }
+
+ gridmgr_destroy(lmgr->gmgr);
+ free(lmgr->data);
+
+ free(lmgr);
+}