From 8c743ba44b2a23556f8486ed2aa18f8a8fdc5e00 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sun, 30 Nov 2014 18:39:01 +0100 Subject: [PATCH] HTSP: add comment to DVR entry and all related APIs --- src/api/api_dvr.c | 10 +++++++--- src/dvr/dvr.h | 11 +++++++---- src/dvr/dvr_db.c | 35 ++++++++++++++++++++++++----------- src/dvr/dvr_timerec.c | 3 ++- src/htsp_server.c | 15 ++++++++------- src/webui/simpleui.c | 4 ++-- src/webui/static/app/dvr.js | 13 ++++++++----- 7 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/api/api_dvr.c b/src/api/api_dvr.c index 257bbd20..42685c81 100644 --- a/src/api/api_dvr.c +++ b/src/api/api_dvr.c @@ -160,16 +160,19 @@ static htsmsg_t * api_dvr_entry_create_from_single(htsmsg_t *args) { htsmsg_t *entries, *m; - const char *s1, *s2; + const char *s1, *s2, *s3; if (!(s1 = htsmsg_get_str(args, "config_uuid"))) return NULL; if (!(s2 = htsmsg_get_str(args, "event_id"))) return NULL; + s3 = htsmsg_get_str(args, "comment"); entries = htsmsg_create_list(); m = htsmsg_create_map(); htsmsg_add_str(m, "config_uuid", s1); htsmsg_add_str(m, "event_id", s2); + if (s3) + htsmsg_add_str(m, "comment", s3); htsmsg_add_msg(entries, NULL, m); return entries; } @@ -179,7 +182,7 @@ api_dvr_entry_create_by_event ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { dvr_entry_t *de; - const char *config_uuid; + const char *config_uuid, *comment; epg_broadcast_t *e; htsmsg_t *entries, *entries2 = NULL, *m; htsmsg_field_t *f; @@ -199,6 +202,7 @@ api_dvr_entry_create_by_event continue; config_uuid = htsmsg_get_str(m, "config_uuid"); + comment = htsmsg_get_str(m, "comment"); pthread_mutex_lock(&global_lock); if ((e = epg_broadcast_find_by_id(strtoll(s, NULL, 10)))) { @@ -206,7 +210,7 @@ api_dvr_entry_create_by_event if (cfg) { de = dvr_entry_create_by_event(idnode_uuid_as_str(&cfg->dvr_id), e, 0, 0, perm->aa_representative, - NULL, DVR_PRIO_NORMAL, 0); + NULL, DVR_PRIO_NORMAL, 0, comment); if (de) dvr_entry_save(de); } diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h index e7551039..e6bf12bb 100644 --- a/src/dvr/dvr.h +++ b/src/dvr/dvr.h @@ -155,6 +155,7 @@ typedef struct dvr_entry { time_t de_stop_extra; char *de_creator; + char *de_comment; char *de_filename; /* Initially null if no filename has been generated yet */ lang_str_t *de_title; /* Title in UTF-8 (from EPG) */ @@ -404,7 +405,8 @@ dvr_entry_create_by_event( const char *dvr_config_uuid, time_t start_extra, time_t stop_extra, const char *creator, dvr_autorec_entry_t *dae, - dvr_prio_t pri, int retention ); + dvr_prio_t pri, int retention, + const char *comment ); dvr_entry_t * dvr_entry_create_htsp( const char *dvr_config_uuid, @@ -413,7 +415,8 @@ dvr_entry_create_htsp( const char *dvr_config_uuid, const char *title, const char *description, const char *lang, epg_genre_t *content_type, const char *creator, dvr_autorec_entry_t *dae, - dvr_prio_t pri, int retention ); + dvr_prio_t pri, int retention, + const char *comment ); dvr_entry_t * dvr_entry_update( dvr_entry_t *de, @@ -473,9 +476,9 @@ dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e, const char *lang, epg_genre_t *content_type, const char *creator, dvr_autorec_entry_t *dae, dvr_timerec_entry_t *tae, - dvr_prio_t pri, int retention); + dvr_prio_t pri, int retention, const char *comment); -dvr_autorec_entry_t* +dvr_autorec_entry_t * dvr_autorec_create_htsp(const char *dvr_config_name, const char *title, channel_t *ch, uint32_t aroundTime, uint32_t days, time_t start_extra, time_t stop_extra, diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index 8cee0adf..ce066fd4 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -451,7 +451,8 @@ dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e, const char *lang, epg_genre_t *content_type, const char *creator, dvr_autorec_entry_t *dae, dvr_timerec_entry_t *dte, - dvr_prio_t pri, int retention) + dvr_prio_t pri, int retention, + const char *comment) { dvr_entry_t *de; char tbuf[64], *s; @@ -470,6 +471,7 @@ dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e, htsmsg_add_s64(conf, "start_extra", start_extra); htsmsg_add_s64(conf, "stop_extra", stop_extra); htsmsg_add_str(conf, "creator", creator ?: ""); + htsmsg_add_str(conf, "comment", comment ?: ""); if (e) { htsmsg_add_u32(conf, "dvb_eid", e->dvb_eid); if (e->episode && e->episode->title) @@ -537,7 +539,8 @@ dvr_entry_create_htsp(const char *config_uuid, const char *description, const char *lang, epg_genre_t *content_type, const char *creator, dvr_autorec_entry_t *dae, - dvr_prio_t pri, int retention) + dvr_prio_t pri, int retention, + const char *comment) { dvr_config_t *cfg = dvr_config_find_by_uuid(config_uuid); if (!cfg) @@ -546,7 +549,8 @@ dvr_entry_create_htsp(const char *config_uuid, NULL, ch, start, stop, start_extra, stop_extra, title, description, lang, content_type, - creator, dae, NULL, pri, retention); + creator, dae, NULL, pri, retention, + comment); } /** @@ -557,7 +561,8 @@ dvr_entry_create_by_event(const char *config_uuid, epg_broadcast_t *e, time_t start_extra, time_t stop_extra, const char *creator, dvr_autorec_entry_t *dae, - dvr_prio_t pri, int retention) + dvr_prio_t pri, int retention, + const char *comment) { if(!e->channel || !e->episode || !e->episode->title) return NULL; @@ -567,7 +572,8 @@ dvr_entry_create_by_event(const char *config_uuid, start_extra, stop_extra, NULL, NULL, NULL, LIST_FIRST(&e->episode->genre), - creator, dae, NULL, pri, retention); + creator, dae, NULL, pri, retention, + comment); } /** @@ -618,14 +624,14 @@ dvr_entry_create_by_autorec(epg_broadcast_t *e, dvr_autorec_entry_t *dae) /* Dup detection */ if (_dvr_duplicate_event(e)) return; - if(dae->dae_creator) { - snprintf(buf, sizeof(buf), "Auto recording by: %s", dae->dae_creator); - } else { - snprintf(buf, sizeof(buf), "Auto recording"); - } + snprintf(buf, sizeof(buf), "Auto recording%s%s", + dae->dae_creator ? " by: " : "", + dae->dae_creator ?: ""); + dvr_entry_create_by_event(idnode_uuid_as_str(&dae->dae_config->dvr_id), e, dae->dae_start_extra, dae->dae_stop_extra, - buf, dae, dae->dae_pri, dae->dae_retention); + buf, dae, dae->dae_pri, dae->dae_retention, + dae->dae_comment); } /** @@ -656,6 +662,7 @@ dvr_entry_dec_ref(dvr_entry_t *de) free(de->de_filename); free(de->de_creator); + free(de->de_comment); if (de->de_title) lang_str_destroy(de->de_title); if (de->de_desc) lang_str_destroy(de->de_desc); if (de->de_bcast) de->de_bcast->putref((epg_object_t*)de->de_bcast); @@ -1912,6 +1919,12 @@ const idclass_t dvr_entry_class = { .get = dvr_entry_class_sched_status_get, .opts = PO_RDONLY | PO_NOSAVE | PO_HIDDEN, }, + { + .type = PT_STR, + .id = "comment", + .name = "Comment", + .off = offsetof(dvr_entry_t, de_comment), + }, {} } }; diff --git a/src/dvr/dvr_timerec.c b/src/dvr/dvr_timerec.c index 4812b9cf..ca0b1323 100644 --- a/src/dvr/dvr_timerec.c +++ b/src/dvr/dvr_timerec.c @@ -156,7 +156,8 @@ dvr_timerec_check(dvr_timerec_entry_t *dte) NULL, dte->dte_channel, start, stop, 0, 0, title, NULL, NULL, NULL, buf, - NULL, dte, dte->dte_pri, dte->dte_retention); + NULL, dte, dte->dte_pri, dte->dte_retention, + dte->dte_comment); return; diff --git a/src/htsp_server.c b/src/htsp_server.c index 358fec8d..2e3b99a0 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -1332,7 +1332,7 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in) epg_broadcast_t *e = NULL; dvr_entry_t *de; dvr_entry_sched_state_t dvr_status; - const char *dvr_config_name, *title, *desc, *creator, *lang; + const char *dvr_config_name, *title, *desc, *creator, *lang, *comment; int64_t start, stop, start_extra, stop_extra; uint32_t u32, priority, retention; channel_t *ch = NULL; @@ -1353,8 +1353,8 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in) priority = DVR_PRIO_NORMAL; if(htsmsg_get_u32(in, "retention", &retention)) retention = 0; - if (!(creator = htsmsg_get_str(in, "creator")) || !*creator) - creator = htsp->htsp_username ?: "anonymous"; + comment = htsmsg_get_str(in, "comment"); + creator = htsp->htsp_username; if (!(lang = htsmsg_get_str(in, "language"))) lang = htsp->htsp_language; @@ -1380,13 +1380,15 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in) // create the dvr entry de = dvr_entry_create_htsp(dvr_config_name, ch, start, stop, start_extra, stop_extra, - title, desc, lang, 0, creator, NULL, priority, retention); + title, desc, lang, 0, creator, NULL, + priority, retention, comment); /* Event timer */ } else { de = dvr_entry_create_by_event(dvr_config_name, e, start_extra, stop_extra, - creator, NULL, priority, retention); + creator, NULL, + priority, retention, comment); } dvr_status = de != NULL ? de->de_sched_state : DVR_NOSTATE; @@ -1549,8 +1551,7 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in) start_extra = 0; // 0 = dvr config if(htsmsg_get_s64(in, "stopExtra", &stop_extra)) stop_extra = 0; // 0 = dvr config - if (!(creator = htsmsg_get_str(in, "creator")) || !*creator) - creator = htsp->htsp_username ?: "anonymous"; + creator = htsp->htsp_username; if (!(comment = htsmsg_get_str(in, "comment"))) comment = ""; diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index 18191e06..50665e50 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -315,8 +315,8 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque) de = dvr_entry_find_by_event(e); if((http_arg_get(&hc->hc_req_args, "rec")) != NULL) { - de = dvr_entry_create_by_event(NULL, e, 0, 0, hc->hc_username ?: "anonymous", NULL, - DVR_PRIO_NORMAL, 0); + de = dvr_entry_create_by_event(NULL, e, 0, 0, hc->hc_username ?: NULL, NULL, + DVR_PRIO_NORMAL, 0, "simpleui"); } else if(de != NULL && (http_arg_get(&hc->hc_req_args, "cancel")) != NULL) { de = dvr_entry_cancel(de); } diff --git a/src/webui/static/app/dvr.js b/src/webui/static/app/dvr.js index c00065dc..d95d3893 100644 --- a/src/webui/static/app/dvr.js +++ b/src/webui/static/app/dvr.js @@ -18,6 +18,7 @@ tvheadend.dvrDetails = function(uuid) { var desc = params[6].value; var status = params[7].value; var filesize = params[8].value; + var comment = params[9].value; var content = ''; var but; @@ -33,6 +34,8 @@ tvheadend.dvrDetails = function(uuid) { content += '
'; content += '
Status:
' + status + '
'; content += '
File size:
' + parseInt(filesize / 1000000) + ' MB
'; + if (comment) + content += '
Comment:
' + comment + '
'; var win = new Ext.Window({ title: title, @@ -54,7 +57,7 @@ tvheadend.dvrDetails = function(uuid) { params: { uuid: uuid, list: 'channel_icon,disp_title,episode,start_real,stop_real,' + - 'duration,disp_description,status,filesize' + 'duration,disp_description,status,filesize,comment' }, success: function(d) { d = json_decode(d); @@ -137,7 +140,7 @@ tvheadend.dvr_upcoming = function(panel, index) { var actions = tvheadend.dvrRowActions(); var list = 'disp_title,start,start_extra,stop,stop_extra,' + - 'channel,config_name'; + 'channel,config_name,comment'; var abortButton = { name: 'abort', @@ -205,7 +208,7 @@ tvheadend.dvr_upcoming = function(panel, index) { del: true, list: 'disp_title,episode,pri,start_real,stop_real,' + 'duration,channelname,creator,config_name,' + - 'sched_status', + 'sched_status,comment', sort: { field: 'start_real', direction: 'ASC' @@ -266,7 +269,7 @@ tvheadend.dvr_finished = function(panel, index) { del: true, list: 'disp_title,episode,start_real,stop_real,' + 'duration,filesize,channelname,creator,' + - 'sched_status,url', + 'sched_status,url,comment', columns: { filesize: { renderer: tvheadend.filesizeRenderer() @@ -344,7 +347,7 @@ tvheadend.dvr_failed = function(panel, index) { del: true, list: 'disp_title,episode,start_real,stop_real,' + 'duration,filesize,channelname,creator,' + - 'status,sched_status,url', + 'status,sched_status,url,comment', columns: { filesize: { renderer: tvheadend.filesizeRenderer()