diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/view/channelinfo.edc | 56 | ||||
-rw-r--r-- | include/define.h | 12 | ||||
-rw-r--r-- | include/layout_channelinfo.h | 22 | ||||
-rw-r--r-- | src/layout_channelinfo.c | 359 | ||||
-rw-r--r-- | src/view_channelinfo.c | 254 |
6 files changed, 465 insertions, 239 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ca1a401..566aebf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ ENDIF(NOT DEFINED MANIFESTDIR) SET(SRCS src/main.c src/tv.c src/view_channelinfo.c + src/layout_channelinfo.c src/tv_service.c) SET(TARGET_EDJ "${PROJECT_NAME}.edj") diff --git a/data/view/channelinfo.edc b/data/view/channelinfo.edc index c0e95ad..b30785c 100644 --- a/data/view/channelinfo.edc +++ b/data/view/channelinfo.edc @@ -20,6 +20,25 @@ group { name, GRP_VIEW_CHANNELINFO; parts { part { + name, PART_CONTENT; + type, SWALLOW; + scale, 1; + description { + state, "default" 0.0; + rel1.relative, 1.0 0.5; + rel2.relative, 1.0 0.5; + min, 536 0; + align, 1.0 0.5; + fixed, 1 0; + } + } + } +} + +group { + name, GRP_CHANNELINFO; + parts { + part { name, "bg"; type, RECT; scale, 1; @@ -80,6 +99,11 @@ group { align, 0.0 0.0; fixed, 1 1; } + description { + state, "focused" 0.0; + inherit, "default" 0.0; + color, COLOR_TEXT_FOCUSED; + } } part { name, "padding.title"; @@ -124,6 +148,11 @@ group { align, 0.0 0.0; fixed, 1 1; } + description { + state, "focused" 0.0; + inherit, "default" 0.0; + color, COLOR_TEXT_FOCUSED; + } } part { name, "padding.time"; @@ -168,6 +197,11 @@ group { align, 0.0 0.0; fixed, 1 1; } + description { + state, "focused" 0.0; + inherit, "default" 0.0; + color, COLOR_TEXT_FOCUSED; + } } part { name, "padding.right_top"; @@ -208,4 +242,26 @@ group { } } } + programs { + program { + name, "focused"; + signal, SIGNAL_FOCUSED; + source, SOURCE_ELM; + action, STATE_SET "focused" 0.0; + target, "bg"; + target, PART_CHANNELINFO_CHANNEL; + target, PART_CHANNELINFO_TITLE; + target, PART_CHANNELINFO_TIME; + } + program { + name, "unfocused"; + signal, SIGNAL_UNFOCUSED; + source, SOURCE_ELM; + action, STATE_SET "default" 0.0; + target, "bg"; + target, PART_CHANNELINFO_CHANNEL; + target, PART_CHANNELINFO_TITLE; + target, PART_CHANNELINFO_TIME; + } + } } diff --git a/include/define.h b/include/define.h index e11b3f4..e544292 100644 --- a/include/define.h +++ b/include/define.h @@ -21,8 +21,13 @@ #define KEY_SVCID "svcid" -#define VIEW_CHANNELINFO "VIEW_CHANNELINFO" -#define PART_CONTENT "part.content" +#define PART_CONTENT "elm.swallow.content" + +#define SOURCE_PROGRAM "program" +#define SOURCE_ELM "elm" + +#define SIGNAL_FOCUSED "elm,action,focus" +#define SIGNAL_UNFOCUSED "elm,action,unfocus" #define FONT_REGULAR "TizenSans" #define FONT_LIGHT "TizenSans:style=Light" @@ -38,7 +43,10 @@ #define IMG_FAVORITE_NOR IMAGEDIR"ic_thumbnail_favorite_01.png" #define IMG_FAVORITE_FOC IMG_FAVORITE_NOR +#define VIEW_CHANNELINFO "VIEW_CHANNELINFO" +#define LAYOUT_CHANNELINFO "LAYOUT_CHANNELINFO" #define GRP_VIEW_CHANNELINFO "grp.view.channelinfo" +#define GRP_CHANNELINFO "grp.channelinfo" #define PART_CHANNELINFO_CHANNEL "part.channelinfo.channel" #define PART_CHANNELINFO_TITLE "part.channelinfo.title" #define PART_CHANNELINFO_TIME "part.channelinfo.time" diff --git a/include/layout_channelinfo.h b/include/layout_channelinfo.h new file mode 100644 index 0000000..5ae049a --- /dev/null +++ b/include/layout_channelinfo.h @@ -0,0 +1,22 @@ +/* + * 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 __LAYOUT_CHANNELINFO_H__ +#define __LAYOUT_CHANNELINFO_H__ + +layout_class *layout_channelinfo_get_lclass(void); + +#endif /* __LAYOUT_CHANNELINFO_H__*/ diff --git a/src/layout_channelinfo.c b/src/layout_channelinfo.c new file mode 100644 index 0000000..0a5af8a --- /dev/null +++ b/src/layout_channelinfo.c @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2014 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 <layoutmgr.h> +#include <inputmgr.h> +#include <viewmgr.h> +#include <app_debug.h> + +#include "define.h" +#include "tv.h" + +#define HIDE_DUR 10.0 +#define BUF_MAX 128 +#define STATUS_BOX_PADDING 10 + +struct _priv { + Evas_Object *base; + Evas_Object *layout; + + Ecore_Timer *hide_timer; + layoutmgr *lmgr; + const struct tv_channel_info *channel_info; +}; + +static int _get_program_time(char *buf, int buf_len, time_t start_time, + time_t end_time) +{ + struct tm tm; + int r; + + if (start_time >= end_time) { + _ERR("invalid time"); + return -1; + } + + localtime_r(&start_time, &tm); + r = strftime(buf, buf_len, "%I:%M %P -", &tm); + if (r <= 0) + return -1; + + localtime_r(&end_time, &tm); + r = strftime(buf + r, buf_len - r, " %I:%M %P", &tm); + if (r <= 0) + return -1; + + return 0; +} + +static Eina_Bool _hide_timer(void *data) +{ + struct _priv *priv; + + if (!data) + return ECORE_CALLBACK_CANCEL; + + priv = data; + + priv->hide_timer = NULL; + + viewmgr_hide_view(VIEW_CHANNELINFO); + + return ECORE_CALLBACK_CANCEL; +} + +static void _start_hide_timer(struct _priv *priv) +{ + if (priv->hide_timer) + ecore_timer_reset(priv->hide_timer); + else + priv->hide_timer = ecore_timer_add(HIDE_DUR, _hide_timer, priv); +} + +static void _stop_hide_timer(struct _priv *priv) +{ + if (priv->hide_timer) { + ecore_timer_del(priv->hide_timer); + priv->hide_timer = NULL; + } +} + +static void _add_icon(Evas_Object *box, const char *file) +{ + Evas_Object *ic; + + ic = elm_icon_add(box); + if (!ic) { + _ERR("failed to create icon"); + return; + } + + elm_image_file_set(ic, file, NULL); + elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE); + elm_image_no_scale_set(ic, EINA_TRUE); + evas_object_show(ic); + + elm_box_pack_end(box, ic); +} + +static void _pack_icon_box(struct _priv *priv, + const struct tv_channel_info *channel_info) +{ + Evas_Object *box; + + if (!priv) { + _ERR("failed to get priv"); + return; + } + + box = elm_box_add(priv->layout); + if (!box) { + _ERR("failed to create box"); + return; + } + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_box_horizontal_set(box, EINA_TRUE); + elm_box_padding_set(box, STATUS_BOX_PADDING, 0); + elm_box_align_set(box, 1.0, 0.5); + elm_object_part_content_set(priv->layout, PART_CHANNELINFO_STATUS, box); + + if (channel_info->locked) + _add_icon(box, IMG_LOCKED_NOR); + if (channel_info->favorite) + _add_icon(box, IMG_FAVORITE_NOR); +} + +static void _load_channel_text(struct _priv *priv, + const struct tv_channel_info *channel_info) +{ + char buf[BUF_MAX]; + + if (!priv || !channel_info) { + _ERR("failed to get priv and channel info"); + return; + } + + if (channel_info->channel_minor > 0 && + channel_info->channel_minor < MINOR_MAX) + snprintf(buf, sizeof(buf), "%lu-%lu %s", + channel_info->channel_major, + channel_info->channel_minor, + channel_info->channel_name); + else + snprintf(buf, sizeof(buf), "%lu %s", + channel_info->channel_major, + channel_info->channel_name); + + elm_object_part_text_set(priv->layout, + PART_CHANNELINFO_CHANNEL, buf); + + elm_object_part_text_set(priv->layout, + PART_CHANNELINFO_TITLE, + STR_NOTITLE); + elm_object_part_text_set(priv->layout, + PART_CHANNELINFO_TIME, + STR_NOTIME); +} + +static void _load_program_info(struct _priv *priv, + const struct tv_program_info *prog) +{ + char buf[BUF_MAX]; + int r; + + if (!priv || !prog) { + _ERR("failed to get priv and program data"); + return; + } + + if (prog->start_time && prog->end_time) { + r = _get_program_time(buf, sizeof(buf), + prog->start_time, + prog->end_time); + if (!r) + elm_object_part_text_set(priv->layout, + PART_CHANNELINFO_TIME, buf); + } + + if (strlen(prog->prog_title) > 0) + elm_object_part_text_set(priv->layout, + PART_CHANNELINFO_TITLE, prog->prog_title); +} + +static void _tv_program_cb(Eina_List *prog_list, void *data) +{ + struct _priv *priv; + struct tv_program_info *prog = NULL; + + if (!data) { + _ERR("failed to get data"); + return; + } + + priv = data; + + prog = (struct tv_program_info *) eina_list_nth(prog_list, 0); + if (prog) { + if (priv->channel_info && + prog->service_id != priv->channel_info->service_id) + return; + else + _load_program_info(priv, prog); + } else { + _ERR("failed to get tv_program_info"); + } + + _start_hide_timer(priv); +} + +static void _update_channel_info(struct _priv *priv) +{ + struct tv_program_request *prog_req; + int r; + + if (priv->channel_info) { + tv_channel_del_info(priv->channel_info); + priv->channel_info = NULL; + } + + priv->channel_info = tv_channel_get_info(); + if (!priv->channel_info) { + _ERR("failed to get channel info"); + + return; + } + + _stop_hide_timer(priv); + + _load_channel_text(priv, priv->channel_info); + _pack_icon_box(priv, priv->channel_info); + + prog_req = calloc(1, sizeof(*prog_req)); + prog_req->tv_program_cb = _tv_program_cb; + prog_req->user_data = priv; + r = tv_epg_get_program(priv->channel_info->service_id, + prog_req); + if (r < 0) + _start_hide_timer(priv); +} + +bool _create(layoutmgr *lmgr, void *data) +{ + struct _priv *priv; + Evas_Object *base, *layout; + + priv = calloc(1, sizeof(*priv)); + if (!priv) { + _ERR("failed to allocate priv"); + return false; + } + + base = layoutmgr_get_base(lmgr); + + layout = elm_layout_add(base); + if (!layout) { + _ERR("failed to create layout"); + return false; + } + + if (!elm_layout_file_set(layout, EDJEFILE, GRP_CHANNELINFO)) + goto error; + + elm_object_content_set(base, layout); + + priv->base = base; + priv->layout = layout; + priv->lmgr = lmgr; + + layoutmgr_set_layout_data(lmgr, LAYOUT_CHANNELINFO, priv); + + return true; + +error: + _ERR("failed to create layout"); + evas_object_del(layout); + free(priv); + + return false; +} + +void _destroy(void *layout_data) +{ + struct _priv *priv; + + if (!layout_data) + return; + + priv = layout_data; + + if (priv->channel_info) { + tv_channel_del_info(priv->channel_info); + priv->channel_info = NULL; + } + + _stop_hide_timer(priv); + + evas_object_del(priv->layout); + free(priv); +} + +void _show(void *layout_data) +{ + struct _priv *priv; + + if (!layout_data) + return; + + priv = layout_data; + + _update_channel_info(priv); + + evas_object_show(priv->layout); +} + +void _hide(void *layout_data) +{ + struct _priv *priv; + + if (!layout_data) + return; + + priv = layout_data; + + _stop_hide_timer(priv); + + evas_object_hide(priv->layout); +} + +void _update(void *layout_data, int update_type, int *data) +{ +} + +static layout_class lclass = { + .layout_id = LAYOUT_CHANNELINFO, + .create = _create, + .show = _show, + .hide = _hide, + .destroy = _destroy, + .update = _update, +}; + +layout_class *layout_channelinfo_get_lclass(void) +{ + return &lclass; +} diff --git a/src/view_channelinfo.c b/src/view_channelinfo.c index 365a0f8..7c9a593 100644 --- a/src/view_channelinfo.c +++ b/src/view_channelinfo.c @@ -16,248 +16,23 @@ #include <Elementary.h> #include <viewmgr.h> +#include <layoutmgr.h> #include <inputmgr.h> #include <app_debug.h> #include "define.h" #include "tv.h" -#include "view_channelinfo.h" - -#define HIDE_DUR 10.0 -#define BUF_MAX 128 -#define STATUS_BOX_PADDING 10 +#include "layout_channelinfo.h" struct _priv { Evas_Object *base; - Ecore_Timer *hide_timer; - const struct tv_channel_info *channel_info; -}; - -static int _get_program_time(char *buf, int buf_len, time_t start_time, - time_t end_time) -{ - struct tm tm; - int r; - - if (start_time >= end_time) { - _ERR("invalid time"); - return -1; - } - - localtime_r(&start_time, &tm); - r = strftime(buf, buf_len, "%I:%M %P -", &tm); - if (r <= 0) - return -1; - - localtime_r(&end_time, &tm); - r = strftime(buf + r, buf_len - r, " %I:%M %P", &tm); - if (r <= 0) - return -1; - - return 0; -} - -static Eina_Bool _hide_timer(void *data) -{ - struct _priv *priv; - - if (!data) - return ECORE_CALLBACK_CANCEL; - - priv = data; - - priv->hide_timer = NULL; - - viewmgr_hide_view(VIEW_CHANNELINFO); - - return ECORE_CALLBACK_CANCEL; -} - -static void _start_hide_timer(struct _priv *priv) -{ - if (!priv) { - _ERR("failed to get priv"); - return; - } - - if (priv->hide_timer) - ecore_timer_reset(priv->hide_timer); - else - priv->hide_timer = ecore_timer_add(HIDE_DUR, _hide_timer, priv); -} - -static void _add_icon(Evas_Object *box, const char *file) -{ - Evas_Object *ic; - - ic = elm_icon_add(box); - if (!ic) { - _ERR("failed to create icon"); - return; - } - - elm_image_file_set(ic, file, NULL); - elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE); - elm_image_no_scale_set(ic, EINA_TRUE); - evas_object_show(ic); - - elm_box_pack_end(box, ic); -} - -static void _pack_icon_box(struct _priv *priv, - const struct tv_channel_info *channel_info) -{ - Evas_Object *box; - - if (!priv) { - _ERR("failed to get priv"); - return; - } - - box = elm_box_add(priv->base); - if (!box) { - _ERR("failed to create box"); - return; - } - evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - elm_box_horizontal_set(box, EINA_TRUE); - elm_box_padding_set(box, STATUS_BOX_PADDING, 0); - elm_box_align_set(box, 1.0, 0.5); - elm_object_part_content_set(priv->base, PART_CHANNELINFO_STATUS, box); - - if (channel_info->locked) - _add_icon(box, IMG_LOCKED_NOR); - if (channel_info->favorite) - _add_icon(box, IMG_FAVORITE_NOR); -} - -static void _load_channel_text(struct _priv *priv, - const struct tv_channel_info *channel_info) -{ - char buf[BUF_MAX]; - if (!priv || !channel_info) { - _ERR("failed to get priv and channel info"); - return; - } - - if (channel_info->channel_minor > 0 && - channel_info->channel_minor < MINOR_MAX) - snprintf(buf, sizeof(buf), "%lu-%lu %s", - channel_info->channel_major, - channel_info->channel_minor, - channel_info->channel_name); - else - snprintf(buf, sizeof(buf), "%lu %s", - channel_info->channel_major, - channel_info->channel_name); - - elm_object_part_text_set(priv->base, - PART_CHANNELINFO_CHANNEL, buf); - - elm_object_part_text_set(priv->base, - PART_CHANNELINFO_TITLE, - STR_NOTITLE); - elm_object_part_text_set(priv->base, - PART_CHANNELINFO_TIME, - STR_NOTIME); -} - -static void _load_program_info(struct _priv *priv, - const struct tv_program_info *prog) -{ - char buf[BUF_MAX]; - int r; - - if (!priv || !prog) { - _ERR("failed to get priv and program data"); - return; - } - - if (prog->start_time && prog->end_time) { - r = _get_program_time(buf, sizeof(buf), - prog->start_time, - prog->end_time); - if (!r) - elm_object_part_text_set(priv->base, - PART_CHANNELINFO_TIME, buf); - } - - if (strlen(prog->prog_title) > 0) - elm_object_part_text_set(priv->base, - PART_CHANNELINFO_TITLE, prog->prog_title); -} - -static void _tv_program_cb(Eina_List *prog_list, void *data) -{ - struct _priv *priv; - struct tv_program_info *prog = NULL; - - if (!data) { - _ERR("failed to get data"); - return; - } - - priv = data; - - prog = (struct tv_program_info *) eina_list_nth(prog_list, 0); - if (prog) { - if (priv->channel_info && - prog->service_id != priv->channel_info->service_id) - return; - else - _load_program_info(priv, prog); - } else { - _ERR("failed to get tv_program_info"); - } - - _start_hide_timer(priv); -} - -static void _update_channel_info(struct _priv *priv) -{ - struct tv_program_request *prog_req; - int r; - - if (!priv) { - _ERR("failed to get priv"); - return; - } - - if (priv->channel_info) { - tv_channel_del_info(priv->channel_info); - priv->channel_info = NULL; - } - - priv->channel_info = tv_channel_get_info(); - if (!priv->channel_info) { - _ERR("failed to get channel info"); - - return; - } - - if (priv->hide_timer) { - ecore_timer_del(priv->hide_timer); - priv->hide_timer = NULL; - } - - _load_channel_text(priv, priv->channel_info); - _pack_icon_box(priv, priv->channel_info); - - prog_req = calloc(1, sizeof(*prog_req)); - prog_req->tv_program_cb = _tv_program_cb; - prog_req->user_data = priv; - r = tv_epg_get_program(priv->channel_info->service_id, - prog_req); - if (r < 0) - _start_hide_timer(priv); -} + layoutmgr *lmgr; +}; static Evas_Object *_create(Evas_Object *win, void *data) { struct _priv *priv; - Evas_Object *base; if (!win) { _ERR("failed to get win object"); @@ -270,22 +45,24 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } - base = elm_layout_add(win); - if (!base) { + priv->base = elm_layout_add(win); + if (!priv->base) { _ERR("failed to create base object"); free(priv); return NULL; } - elm_layout_file_set(base, EDJEFILE, GRP_VIEW_CHANNELINFO); + elm_layout_file_set(priv->base, EDJEFILE, GRP_VIEW_CHANNELINFO); - evas_object_size_hint_weight_set(base, + evas_object_size_hint_weight_set(priv->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, base); + elm_win_resize_object_add(win, priv->base); + + priv->lmgr = layoutmgr_create(priv->base); + layoutmgr_add_layout(priv->lmgr, layout_channelinfo_get_lclass(), NULL); - priv->base = base; viewmgr_set_view_data(VIEW_CHANNELINFO, priv); - return base; + return priv->base; } static void _show(void *view_data) @@ -299,7 +76,7 @@ static void _show(void *view_data) priv = view_data; - _update_channel_info(priv); + layoutmgr_show_layout(priv->lmgr, LAYOUT_CHANNELINFO); evas_object_show(priv->base); } @@ -329,6 +106,9 @@ static void _destroy(void *view_data) priv = view_data; + layoutmgr_remove_layout(priv->lmgr, LAYOUT_CHANNELINFO); + layoutmgr_destroy(priv->lmgr); + evas_object_del(priv->base); free(priv); |