diff --git a/src/epg.c b/src/epg.c index 6fec7883..d2864325 100644 --- a/src/epg.c +++ b/src/epg.c @@ -73,6 +73,11 @@ static int ebc_win_cmp ( const epg_broadcast_t *a, const epg_broadcast_t *b ) return 0; } +static int ptr_cmp ( void *a, void *b ) +{ + return a - b; +} + /* ************************************************************************** * Testing/Debug * *************************************************************************/ @@ -512,6 +517,35 @@ int epg_episode_set_season ( epg_episode_t *episode, epg_season_t *season, int u return save; } +int epg_episode_add_broadcast + ( epg_episode_t *episode, epg_broadcast_t *broadcast, int u ) +{ + int save = 0; + epg_broadcast_t *eb; + if ( !episode || !broadcast ) return 0; + eb = RB_INSERT_SORTED(&episode->ee_broadcasts, broadcast, eb_elink, ptr_cmp); + if ( eb == NULL ) { + if ( u ) save |= epg_broadcast_set_episode(broadcast, episode, 0); + save = 1; + } + return save; +} + +int epg_episode_rem_broadcast + ( epg_episode_t *episode, epg_broadcast_t *broadcast, int u ) +{ + int save = 0; + epg_broadcast_t *eb; + if ( !episode || !broadcast ) return 0; + eb = RB_FIND(&episode->ee_broadcasts, broadcast, eb_elink, ptr_cmp); + if ( eb != NULL ) { + if ( u ) save |= epg_broadcast_set_episode(broadcast, episode, 0); + RB_REMOVE(&episode->ee_broadcasts, broadcast, eb_elink); + save = 1; + } + return save; +} + /* ************************************************************************** * Broadcast * *************************************************************************/ @@ -607,3 +641,35 @@ epg_channel_t* epg_channel_find return channel; } + +/* ************************************************************************** + * Querying + * *************************************************************************/ + +void epg_query(epg_query_result_t *eqr, const char *channel, const char *tag, + const char *contentgroup, const char *title) +{ + epg_channel_t *ec; + epg_broadcast_t *ebc; + eqr->eqr_array = calloc(2, sizeof(epg_broadcast_t*)); + RB_FOREACH(ec, &epg_channels, ec_link) { + RB_FOREACH(ebc, &ec->ec_schedule, eb_slink) { + if ( ebc->eb_episode ) { + eqr->eqr_array[0] = ebc; + eqr->eqr_entries = 1; + eqr->eqr_alloced = 2; + return; + } + } + } + return; +} + +void epg_query_free(epg_query_result_t *eqr) +{ + free(eqr->eqr_array); +} + +void epg_query_sort(epg_query_result_t *eqr) +{ +} diff --git a/src/epg.h b/src/epg.h index 2fdaf905..f779dbbc 100644 --- a/src/epg.h +++ b/src/epg.h @@ -243,6 +243,11 @@ int epg_episode_set_brand ( epg_episode_t *e, epg_brand_t *b, int u ) __attribute__((warn_unused_result)); int epg_episode_set_season ( epg_episode_t *e, epg_season_t *s, int u ) __attribute__((warn_unused_result)); +int epg_episode_add_broadcast ( epg_episode_t *e, epg_broadcast_t *b, int u ) + __attribute__((warn_unused_result)); +int epg_episode_rem_broadcast ( epg_episode_t *e, epg_broadcast_t *b, int u ) + __attribute__((warn_unused_result)); + /* Broadcast set() calls */ int epg_broadcast_set_episode ( epg_broadcast_t *b, epg_episode_t *e, int u ) diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 38e60e31..03a30b02 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -667,11 +667,13 @@ skip: static int extjs_epg(http_connection_t *hc, const char *remain, void *opaque) { -#if TODO htsbuf_queue_t *hq = &hc->hc_reply; htsmsg_t *out, *array, *m; epg_query_result_t eqr; - event_t *e; + epg_broadcast_t *e; + epg_episode_t *ee = NULL; + //epg_season_t *es = NULL; + //epg_brand_t *eb = NULL; int start = 0, end, limit, i; const char *s; const char *channel = http_arg_get(&hc->hc_req_args, "channel"); @@ -706,28 +708,39 @@ extjs_epg(http_connection_t *hc, const char *remain, void *opaque) end = MIN(start + limit, eqr.eqr_entries); for(i = start; i < end; i++) { - const char *s; + //const char *s; + //eb = NULL; es = NULL; ee = NULL; - e = eqr.eqr_array[i]; + e = eqr.eqr_array[i]; + ee = e->eb_episode; + //if (ee) es = ee->ee_season; + //if (ee) eb = ee->ee_brand; m = htsmsg_create_map(); +#if TODO if(e->e_channel != NULL) { htsmsg_add_str(m, "channel", e->e_channel->ch_name); htsmsg_add_u32(m, "channelid", e->e_channel->ch_id); if(e->e_channel->ch_icon != NULL) htsmsg_add_str(m, "chicon", e->e_channel->ch_icon); } +#endif - if(e->e_title != NULL) - htsmsg_add_str(m, "title", e->e_title); + if(ee->ee_title != NULL) + htsmsg_add_str(m, "title", ee->ee_title); - if(e->e_desc != NULL) - htsmsg_add_str(m, "description", e->e_desc); + if(ee->ee_description != NULL) + htsmsg_add_str(m, "description", ee->ee_description); + else if(ee->ee_summary != NULL) + htsmsg_add_str(m, "description", ee->ee_summary); +#if TODO if(e->e_episode.ee_onscreen != NULL) htsmsg_add_str(m, "episode", e->e_episode.ee_onscreen); +#endif +#if TODO if(e->e_ext_desc != NULL) htsmsg_add_str(m, "ext_desc", e->e_ext_desc); @@ -736,18 +749,21 @@ extjs_epg(http_connection_t *hc, const char *remain, void *opaque) if(e->e_ext_text != NULL) htsmsg_add_str(m, "ext_text", e->e_ext_text); +#endif - htsmsg_add_u32(m, "id", e->e_id); - htsmsg_add_u32(m, "start", e->e_start); - htsmsg_add_u32(m, "end", e->e_stop); - htsmsg_add_u32(m, "duration", e->e_stop - e->e_start); + //htsmsg_add_u32(m, "id", e->e_id); + htsmsg_add_u32(m, "start", e->eb_start); + htsmsg_add_u32(m, "end", e->eb_stop); + htsmsg_add_u32(m, "duration", e->eb_stop - e->eb_start); +#if TODO if((s = epg_content_group_get_name(e->e_content_type)) != NULL) htsmsg_add_str(m, "contentgrp", s); dvr_entry_t *de; if((de = dvr_entry_find_by_event(e)) != NULL) htsmsg_add_str(m, "schedstate", dvr_entry_schedstatus(de)); +#endif htsmsg_add_msg(array, NULL, m); } @@ -761,7 +777,6 @@ extjs_epg(http_connection_t *hc, const char *remain, void *opaque) htsmsg_json_serialize(out, hq, 0); htsmsg_destroy(out); http_output_content(hc, "text/x-json; charset=UTF-8"); -#endif return 0; }