diff options
-rw-r--r-- | include/tv.h | 3 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/tv.c | 161 | ||||
-rw-r--r-- | src/view_channelinfo.c | 31 |
4 files changed, 91 insertions, 114 deletions
diff --git a/include/tv.h b/include/tv.h index 129b18b..1794033 100644 --- a/include/tv.h +++ b/include/tv.h @@ -74,11 +74,10 @@ Eina_List *tv_channel_search_by_number(long major, long minor); void tv_channel_del_list(Eina_List *channel_list); int tv_get_current_service_id(int *service_id); int tv_channel_tune(void); +int tv_channel_tune_prev_channel(void); int tv_channel_direct_tune(long major, long minor); int tv_channel_tune_with_service_id(int service_id); int tv_channel_tune_locked_channel(int service_id, char *password); -int tv_channel_next(void); -int tv_channel_prev(void); int tv_channel_set_favorite(int service_id, Eina_Bool flag); int tv_channel_add_channel(int service_id); int tv_channel_del_channel(int service_id); @@ -45,6 +45,7 @@ struct _appdata { int is_signal; int is_channel; + int is_tuned; }; struct key_map { @@ -58,7 +59,8 @@ static struct key_map g_kmap[] = { { KEY_ENTER, KEY_CHANNELUP, - KEY_CHANNELDOWN + KEY_CHANNELDOWN, + KEY_PREVIOUS, } }, { @@ -176,6 +178,7 @@ static void _tv_signal_cb(void *data, int is_signal) ad = data; ad->is_signal = is_signal; + ad->is_tuned = true; if (is_signal) { viewmgr_hide_view(VIEW_ERROR); @@ -243,6 +246,8 @@ static void _resume(void *data) ui_app_exit(); return; + } else if (r > 0) { + ad->is_tuned = false; } /* Try to tune with service id if supplied from app control */ @@ -256,6 +261,9 @@ static void _resume(void *data) } } + if (ad->is_tuned) + return; + r = tv_channel_tune(); if (r < 0) { ad->is_channel = false; @@ -32,6 +32,11 @@ #define DEFAULT_SERVICE 1 +struct _channel_history { + int service_id[2]; + unsigned int idx; +}; + /** * The Storage structure to used by tv related functions and events. */ @@ -43,6 +48,8 @@ struct _tv_info { /**< Stores service id if tune to locked channel was succeeded. */ int viewing_locked_channel; + /**< Stores previous service id. */ + struct _channel_history history; /**< The function pointer to pass tv signal event */ void (*signal_cb)(void *data, int is_signal); @@ -651,14 +658,26 @@ void tv_channel_del_list(Eina_List *channel_list) free(data); } -void _tv_channel_add_history(int service_id) +static void _tv_channel_add_history(int service_id) { char buf[128]; + g_tv_info.history.service_id[g_tv_info.history.idx++ % 2] + = service_id; + snprintf(buf, sizeof(buf), "%d", service_id); app_contents_recent_add(CONTENTS_CHANNEL, buf); } +static int _tv_channel_get_history(void) +{ + int service_id; + + service_id = g_tv_info.history.service_id[g_tv_info.history.idx % 2]; + + return service_id; +} + /** * Tunes to specific channel with service id. * @@ -714,6 +733,42 @@ int tv_channel_tune(void) return -1; } + _tv_channel_add_history(service_id); + + g_tv_info.viewing_locked_channel = -1; + + return 0; +} + +/** + * Tunes to previously viewed channel. + * + * @return If the operation was sucessful 0 is returned; otherwise negative value is returned + */ +int tv_channel_tune_prev_channel(void) +{ + int service_id; + int r; + + if (!g_tv_info.live_svc) { + _ERR("failed to get live service"); + return -1; + } + + service_id = _tv_channel_get_history(); + if (service_id < 1) { + _ERR("no previous channel"); + return -1; + } + + r = tv_service_live_tune(g_tv_info.live_svc, service_id); + if (r != TVS_ERROR_OK) { + _ERR("failed to set service"); + return -1; + } + + _tv_channel_add_history(service_id); + g_tv_info.viewing_locked_channel = -1; return 0; @@ -732,6 +787,11 @@ int tv_channel_direct_tune(long major, long minor) TvServiceChannel *tvs_data; int r; + if (!g_tv_info.live_svc) { + _ERR("failed to get live service"); + return -1; + } + if (major > 0 && major < MAJOR_MAX) { filter_node = _tv_channel_get_filter( TV_SERVICE_CHANNEL_DATA_MAJOR_NUMBER, @@ -811,92 +871,6 @@ int tv_channel_tune_locked_channel(int service_id, char *password) } /** - * Tunes to next channel. - * - * Note that deleted channels and service channels will skipped. - * - * @return If the operation was sucessful 0 is returned; otherwise negative value is returned - */ -int tv_channel_next(void) -{ - TvServiceAntenna antenna_type; - int service_id, r; - - if (!g_tv_info.live_svc) { - _ERR("failed to get live service"); - return -1; - } - - r = tv_service_live_get_antenna_type(g_tv_info.live_svc, &antenna_type); - if (r < 0) { - _ERR("failed to get antenna type"); - return -1; - } - - r = tv_service_live_tune_up(g_tv_info.live_svc, - TV_SERVICE_CHANNEL_MODE_DIGITAL_ANALOG, antenna_type); - if (r < 0) { - _ERR("failed to tune up"); - return -1; - } - - g_tv_info.viewing_locked_channel = -1; - - r = tv_service_live_get_service_id(g_tv_info.live_svc, &service_id); - if (r < 0) { - _ERR("failed to get service id"); - return -1; - } - - _tv_channel_add_history(service_id); - - return 0; -} - -/** - * Tunes to previous channel. - * - * Note that deleted channels and service channels will skipped. - * - * @return If the operation was sucessful 0 is returned; otherwise negative value is returned - */ -int tv_channel_prev(void) -{ - TvServiceAntenna antenna_type; - int service_id, r; - - if (!g_tv_info.live_svc) { - _ERR("failed to get live service"); - return -1; - } - - r = tv_service_live_get_antenna_type(g_tv_info.live_svc, &antenna_type); - if (r < 0) { - _ERR("failed to get antenna type"); - return -1; - } - - r = tv_service_live_tune_down(g_tv_info.live_svc, - TV_SERVICE_CHANNEL_MODE_DIGITAL_ANALOG, antenna_type); - if (r < 0) { - _ERR("failed to tune down"); - return -1; - } - - g_tv_info.viewing_locked_channel = -1; - - r = tv_service_live_get_service_id(g_tv_info.live_svc, &service_id); - if (r < 0) { - _ERR("failed to get service id"); - return -1; - } - - _tv_channel_add_history(service_id); - - return 0; -} - -/** * Sets the channel's favorite status. * * @param service_id The channel id @@ -1115,6 +1089,8 @@ int tv_create(void) goto err; } + memset(&g_tv_info.history, 0, sizeof(g_tv_info.history)); + return 0; err: tv_destroy(); @@ -1160,9 +1136,16 @@ int tv_resume(void) if (r != TVS_ERROR_OK) { _ERR("failed to create live service"); goto err; - } else { - return 1; } + + r = tv_service_live_register_callback(g_tv_info.live_svc, + _tv_service_event_cb, NULL); + if (r != TVS_ERROR_OK) { + _ERR("failed to register live callback"); + goto err; + } + + return 1; } r = tv_service_live_tune_resume(g_tv_info.live_svc); diff --git a/src/view_channelinfo.c b/src/view_channelinfo.c index 610e5a3..08191e3 100644 --- a/src/view_channelinfo.c +++ b/src/view_channelinfo.c @@ -49,11 +49,10 @@ static void _hide_current_layout(struct _priv *priv) static void _set_current_layout(struct _priv *priv, const char *layout_id) { - if (priv->current_layout && layout_id && - !strcmp(priv->current_layout, layout_id)) + if (!layout_id) return; - if (priv->current_layout) + if (priv->current_layout && strcmp(priv->current_layout, layout_id)) layoutmgr_hide_layout(priv->lmgr, priv->current_layout); layoutmgr_show_layout(priv->lmgr, layout_id); @@ -170,6 +169,7 @@ static void _destroy(void *view_data) static void _update(void *view_data, int type, void *data) { struct _priv *priv; + int r; if (!view_data) { _ERR("failed to get view data"); @@ -211,28 +211,15 @@ static void _update(void *view_data, int type, void *data) _set_current_layout(priv, LAYOUT_CHANNELINFO_LIST); layoutmgr_update_layout(priv->lmgr, LAYOUT_CHANNELINFO_LIST, type, ev); - } - - viewmgr_show_view(VIEW_CHANNELINFO); - } else if (type == UPDATE_TYPE_INPUT_KEY_UP) { - Evas_Event_Key_Up *ev = data; + } else if (!strcmp(ev->keyname, KEY_PREVIOUS)) { + r = tv_channel_tune_prev_channel(); + if (r < 0) + _ERR("failed to tune prev channel"); - if (!ev) { - _ERR("failed to get ev"); - return; + _set_current_layout(priv, LAYOUT_CHANNELINFO); } - if (!strcmp(ev->keyname, KEY_CHANNELUP) || - !strcmp(ev->keyname, KEY_CHANNELDOWN)) { - if (priv->current_layout && - !strcmp(priv->current_layout, - LAYOUT_CHANNELINFO_SEARCH)) - return; - - _set_current_layout(priv, LAYOUT_CHANNELINFO_LIST); - layoutmgr_update_layout(priv->lmgr, - LAYOUT_CHANNELINFO_LIST, type, ev); - } + viewmgr_show_view(VIEW_CHANNELINFO); } } |