From baf30dae96284e7e41082704ac638da8ecf08012 Mon Sep 17 00:00:00 2001 From: Soohye Shin Date: Tue, 16 Jun 2015 16:16:32 +0900 Subject: [PATCH] add datamgr - add data_home - modify home.json for adding focus icon item Change-Id: If34e9381ec259f1394f91fd370ef4c78710cd797 Signed-off-by: Soohye Shin --- CMakeLists.txt | 2 + config/home.json.in | 18 ++-- include/data_home.h | 24 ++++++ include/datamgr.h | 52 ++++++++++++ src/data/data_home.c | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/data/datamgr.c | 87 +++++++++++++++++++ src/view/view_home.c | 16 ++++ 7 files changed, 425 insertions(+), 6 deletions(-) create mode 100644 include/data_home.h create mode 100644 include/datamgr.h create mode 100644 src/data/data_home.c create mode 100644 src/data/datamgr.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5697dff..2fe857a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ SET(DEFCONFIG "${PROJECT_NAME}.json") SET(THEME_EDJ "${PROJECT_NAME}-theme.edj") SET(SRCS src/main.c + src/data/datamgr.c + src/data/data_home.c src/view/view_recent.c src/view/view_home.c) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/config/home.json.in b/config/home.json.in index 0c48276..da33bc7 100644 --- a/config/home.json.in +++ b/config/home.json.in @@ -2,37 +2,43 @@ "item": [ { "name": "Owner", - "icon": "@IMAGEDIR@/ico_man.png", + "icon": "@IMAGEDIR@/ic_user_08_nor.png", + "focus_icon": "@IMAGEDIR@/ic_user_08_foc.png", "package": "", "notification": false }, { "name": "Favorites", - "icon": "@IMAGEDIR@/icn_app_foc.png", + "icon": "@IMAGEDIR@/btn_menu_favorite_nor.png", + "focus_icon": "@IMAGEDIR@/btn_menu_favorite_foc.png", "package": "org.tizen.app-launcher-tv-ref", "notification": false }, { "name": "Media Hub", - "icon": "@IMAGEDIR@/icn_movie_foc.png", + "icon": "@IMAGEDIR@/btn_menu_media_nor.png", + "focus_icon": "@IMAGEDIR@/btn_menu_media_foc.png", "package": "org.tizen.gallery-tv-ref", "notification": false }, { "name": "APP", - "icon": "@IMAGEDIR@/icn_app_foc.png", + "icon": "@IMAGEDIR@/btn_menu_app_nor.png", + "focus_icon": "@IMAGEDIR@/btn_menu_app_foc.png", "package": "org.tizen.app-launcher-tv-ref", "notification": false }, { "name": "Notification", - "icon": "@IMAGEDIR@/icn_noti_foc.png", + "icon": "@IMAGEDIR@/btn_menu_notification_nor.png", + "focus_icon": "@IMAGEDIR@/btn_menu_notification_foc.png", "package": "org.tizen.music-player-tv-ref", "notification": true }, { "name": "Settings", - "icon": "@IMAGEDIR@/icn_history_foc.png", + "icon": "@IMAGEDIR@/btn_menu_setting_nor.png", + "focus_icon": "@IMAGEDIR@/btn_menu_setting_foc.png", "package": "org.tizen.file-broswer-tv-ref", "notification": false } diff --git a/include/data_home.h b/include/data_home.h new file mode 100644 index 0000000..9697a86 --- /dev/null +++ b/include/data_home.h @@ -0,0 +1,24 @@ +/* + * 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_HOME_DATA_HOME_H__ +#define __AIR_HOME_DATA_HOME_H__ + +#include + +struct data_class *datamgr_home_get_dclass(void); + +#endif /* __AIR_HOME_DATA_HOME_H__ */ diff --git a/include/datamgr.h b/include/datamgr.h new file mode 100644 index 0000000..3d8c38e --- /dev/null +++ b/include/datamgr.h @@ -0,0 +1,52 @@ +/* + * 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_HOME_DATAMGR_H__ +#define __AIR_HOME_DATAMGR_H__ + +#include +#include + +struct datamgr { + Eina_List *list; + const char *view_id; + struct data_class *dclass; +}; + +struct datamgr_item { + char *title; + char *subtitle; + char *icon; + char *focus_icon; + char *thumbnail; + char *package; + bool noti; +}; + +struct data_class { + bool (*init)(struct datamgr *dm); + void (*fini)(struct datamgr *dm); + void (*launch)(struct datamgr *dm); + Eina_List *(*get_items)(struct datamgr *dm); + /* It should be added later */ +}; + +struct datamgr *datamgr_init(struct data_class *dclass, const char *view_id); +void datamgr_fini(struct datamgr *dm); +Eina_List *datamgr_get_items(struct datamgr *dm); +void datamgr_launch(struct datamgr *dm); + +#endif /* __AIR_HOME_DATAMGR_H__ */ diff --git a/src/data/data_home.c b/src/data/data_home.c new file mode 100644 index 0000000..a81135a --- /dev/null +++ b/src/data/data_home.c @@ -0,0 +1,232 @@ +/* + * 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 +#include +#include +#include + +#include "data_home.h" +#include "datamgr.h" + +#define OBJECT_MEMBERS "item" +#define MEMBER_STR_NAME "name" +#define MEMBER_STR_ICON "icon" +#define MEMBER_STR_FOCUS_ICON "focus_icon" +#define MEMBER_STR_PACKAGE "package" +#define MEMBER_INT_NOTIFICATION "notification" + +static inline char *_read_string(JsonReader *reader, char *member) +{ + char *val; + + if (!reader || !member) { + _ERR("Invalid argument"); + return NULL; + } + + json_reader_read_member(reader, member); + val = (char *)json_reader_get_string_value(reader); + json_reader_end_member(reader); + + return val; +} + +static inline gboolean _read_boolean(JsonReader *reader, char *member) +{ + gboolean val; + + if (!reader || !member) { + _ERR("Invalid argument"); + return false; + } + + json_reader_read_member(reader, member); + val = json_reader_get_boolean_value(reader); + json_reader_end_member(reader); + + return val; +} + +static struct datamgr_item *_pack_home_item(JsonReader *reader, int i) +{ + struct datamgr_item *di; + char *name, *icon, *package, *focus_icon; + gboolean noti; + + if (!reader) { + _ERR("Invalid argument"); + return NULL; + } + + if (!json_reader_read_element(reader, i)) { + _ERR("failed to reader %dth element", i); + return NULL; + } + + name = _read_string(reader, MEMBER_STR_NAME); + if (!name) + goto err; + + icon = _read_string(reader, MEMBER_STR_ICON); + if (!icon) + goto err; + + focus_icon = _read_string(reader, MEMBER_STR_FOCUS_ICON); + if (!focus_icon) + goto err; + + package = _read_string(reader, MEMBER_STR_PACKAGE); + noti = _read_boolean(reader, MEMBER_INT_NOTIFICATION); + + json_reader_end_element(reader); + + di = calloc(1, sizeof(*di)); + if (!di) { + _ERR("failed to calloc home item"); + return NULL; + } + + di->title = strdup(name); + di->icon = strdup(icon); + di->focus_icon = strdup(focus_icon); + di->package = strdup(package); + di->noti = noti; + + return di; +err: + json_reader_end_element(reader); + return NULL; +} + +static Eina_List *_load_home_data(JsonReader *reader) +{ + struct datamgr_item *di; + int cnt, i; + Eina_List *list; + + if (!reader) { + _ERR("Invalid argument"); + return NULL; + } + + json_reader_read_member(reader, OBJECT_MEMBERS); + if (!json_reader_is_array(reader)) { + _ERR(OBJECT_MEMBERS" is not array"); + json_reader_end_member(reader); + return NULL; + } + + list = NULL; + cnt = json_reader_count_elements(reader); + for (i = 0; i < cnt; i++) { + di = _pack_home_item(reader, i); + if (!di) + continue; + + list = eina_list_append(list, di); + } + + json_reader_end_member(reader); + + return list; +} + +static Eina_List *_get_items(struct datamgr *dm) +{ + if (!dm) { + _ERR("Invalid argument"); + return NULL; + } + + return dm->list; +} + +static void _fini(struct datamgr *dm) +{ + struct datamgr_item *di; + + if (!dm) { + _ERR("Invalid argument"); + return; + } + + EINA_LIST_FREE(dm->list, di) { + free(di->title); + free(di->icon); + free(di->focus_icon); + free(di->package); + + free(di); + } + + dm->list = NULL; +} + +static bool _init(struct datamgr *dm) +{ + JsonParser *parser; + JsonReader *reader; + + if (!dm) { + _ERR("Invalid argument"); + return false; + } + + parser = json_parser_new(); + if (!parser) { + _ERR("failed to new parser"); + return false; + } + + if (!json_parser_load_from_file(parser, DEFCONFIG, NULL)) { + _ERR("failed to load from file"); + g_object_unref(parser); + return false; + } + + reader = json_reader_new(json_parser_get_root(parser)); + if (!reader) { + _ERR("failed to new reader"); + g_object_unref(parser); + return false; + } + + dm->list = _load_home_data(reader); + if (!dm->list) { + _ERR("failed to load home data"); + g_object_unref(reader); + g_object_unref(parser); + return false; + } + + g_object_unref(reader); + g_object_unref(parser); + + return true; +} + +static struct data_class dclass = { + .init = _init, + .fini = _fini, + .get_items = _get_items +}; + +struct data_class *datamgr_home_get_dclass(void) +{ + return &dclass; +} + diff --git a/src/data/datamgr.c b/src/data/datamgr.c new file mode 100644 index 0000000..30579e1 --- /dev/null +++ b/src/data/datamgr.c @@ -0,0 +1,87 @@ +/* + + * 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 +#include + +#include "datamgr.h" +#include "defs.h" + +struct datamgr *datamgr_init(struct data_class *dclass, const char *view_id) +{ + struct datamgr *dm; + + if (!view_id || !dclass) { + _ERR("Invalid argument"); + return NULL; + } + + dm = calloc(1, sizeof(*dm)); + if (!dm) { + _ERR("failed to calloc dm"); + return NULL; + } + + dm->view_id = view_id; + dm->dclass = dclass; + + if (!dm->dclass->init(dm)) { + _ERR("failed to initialize dclass"); + free(dm); + return NULL; + } + + return dm; +} + +void datamgr_fini(struct datamgr *dm) +{ + if (!dm) { + _ERR("Invalid argument"); + return; + } + + dm->dclass->fini(dm); + + free(dm); +} + +Eina_List *datamgr_get_items(struct datamgr *dm) +{ + if (!dm || !dm->dclass) { + _ERR("Invalid argument"); + return NULL; + } + + if (!dm->dclass->get_items) + return NULL; + + return dm->dclass->get_items(dm); +} + +void datamgr_launch(struct datamgr *dm) +{ + if (!dm || !dm->dclass) { + _ERR("Invalid argument"); + return; + } + + if (!dm->dclass->launch) + return; + + dm->dclass->launch(dm); +} diff --git a/src/view/view_home.c b/src/view/view_home.c index 48fccc2..db4e0f7 100644 --- a/src/view/view_home.c +++ b/src/view/view_home.c @@ -22,10 +22,14 @@ #include "defs.h" #include "view_home.h" +#include "data_home.h" +#include "datamgr.h" struct _priv { Evas_Object *win; Evas_Object *base; + + struct datamgr *dm; }; static inline Evas_Object *_add_layout(Evas_Object *base, const char *group, @@ -180,6 +184,7 @@ static bool _add_home(struct _priv *priv, Evas_Object *base) static Evas_Object *_create(Evas_Object *win, void *data) { struct _priv *priv; + struct datamgr *dm; Evas_Object *base; if (!win) { @@ -193,9 +198,17 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } + dm = datamgr_init(datamgr_home_get_dclass(), VIEW_HOME); + if (!dm) { + _ERR("failed to initialize datamgr"); + free(priv); + return NULL; + } + base =_add_layout(win, GRP_HOME, false); if (!base) { _ERR("failed to create base"); + datamgr_fini(dm); free(priv); return NULL; } @@ -204,9 +217,11 @@ static Evas_Object *_create(Evas_Object *win, void *data) priv->win = win; priv->base = base; + priv->dm = dm; if (!_add_home(priv, base)) { _ERR("failed to load home"); + datamgr_fini(dm); evas_object_del(base); free(priv); return NULL; @@ -257,6 +272,7 @@ static void _destroy(void *data) priv = data; + datamgr_fini(priv->dm); evas_object_del(priv->base); free(priv); } -- 2.7.4