From c7e08d26c033ffc555cbd6fe2da98115eef93cdf Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Fri, 3 Aug 2012 15:52:13 +0100 Subject: [PATCH] Updated to include support for mux configuration setting in UI, I have added a general config section (though currently it only contains this one value). --- Makefile | 1 + docs/html/config_misc.html | 15 +++++ src/config2.c | 60 ++++++++++++++++++++ src/config2.h | 35 ++++++++++++ src/main.c | 11 ++-- src/muxes.c | 14 ++--- src/muxes.h | 2 +- src/webui/extjs.c | 56 +++++++++++++++++++ src/webui/static/app/config.js | 91 +++++++++++++++++++++++++++++++ src/webui/static/app/tvheadend.js | 4 +- 10 files changed, 272 insertions(+), 17 deletions(-) create mode 100644 docs/html/config_misc.html create mode 100644 src/config2.c create mode 100644 src/config2.h create mode 100644 src/webui/static/app/config.js diff --git a/Makefile b/Makefile index 6c725f09..0edf1d44 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,7 @@ SRCS = src/main.c \ src/huffman.c \ src/filebundle.c \ src/muxes.c \ + src/config2.c \ SRCS += src/epggrab/module.c\ src/epggrab/channel.c\ diff --git a/docs/html/config_misc.html b/docs/html/config_misc.html new file mode 100644 index 00000000..d712d399 --- /dev/null +++ b/docs/html/config_misc.html @@ -0,0 +1,15 @@ +
+ +

+ This tabs allow configuration of several general parameters that affect the + core TVH functionality. +

+ +
+
DVB scan files path: +
Select the path to use for DVB scan configuration files. Typically + dvb-apps stores these in /usr/share/dvb/. Leave blank to use TVH's internal + file set (probably stored at /usr/share/tvheadend/data/dvb-scan/)
+
+ +
diff --git a/src/config2.c b/src/config2.c new file mode 100644 index 00000000..2b635c44 --- /dev/null +++ b/src/config2.c @@ -0,0 +1,60 @@ +/* + * TV headend - General configuration settings + * Copyright (C) 2012 Adam Sutton + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "tvheadend.h" +#include "settings.h" +#include "config2.h" + +#include + +static htsmsg_t *config; + +void config_init ( void ) +{ + config = hts_settings_load("config"); + if (!config) { + tvhlog(LOG_WARNING, "config", "no configuration, loading defaults"); + config = htsmsg_create_map(); + } +} + +void config_save ( void ) +{ + hts_settings_save(config, "config"); +} + +htsmsg_t *config_get_all ( void ) +{ + return htsmsg_copy(config); +} + +const char *config_get_muxconfpath ( void ) +{ + return htsmsg_get_str(config, "muxconfpath"); +} + +int config_set_muxconfpath ( const char *path ) +{ + const char *c = config_get_muxconfpath(); + if (!c || strcmp(c, path)) { + if (c) htsmsg_delete_field(config, "muxconfpath"); + htsmsg_add_str(config, "muxconfpath", path); + return 1; + } + return 0; +} diff --git a/src/config2.h b/src/config2.h new file mode 100644 index 00000000..b9d7d9a2 --- /dev/null +++ b/src/config2.h @@ -0,0 +1,35 @@ +/* + * TV headend - General configuration settings + * Copyright (C) 2012 Adam Sutton + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// TODO: expand this, possibly integrate command line + +#ifndef __TVH_CONFIG__H__ +#define __TVH_CONFIG__H__ + +#include "htsmsg.h" + +void config_init ( void ); +void config_save ( void ); + +htsmsg_t *config_get_all ( void ); + +const char *config_get_muxconfpath ( void ); +int config_set_muxconfpath ( const char *str ) + __attribute__((warn_unused_result)); + +#endif /* __TVH_CONFIG__H__ */ diff --git a/src/main.c b/src/main.c index c689abe8..c15f0912 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ #include "settings.h" #include "ffdecsa/FFdecsa.h" #include "muxes.h" +#include "config2.h" int running; time_t dispatch_clock; @@ -259,12 +260,11 @@ main(int argc, char **argv) char *p, *endp; uint32_t adapter_mask = 0xffffffff; int crash = 0; - const char *muxpath = NULL; // make sure the timezone is set tzset(); - while((c = getopt(argc, argv, "Aa:fp:u:g:c:m:Chdr:j:s")) != -1) { + while((c = getopt(argc, argv, "Aa:fp:u:g:c:Chdr:j:s")) != -1) { switch(c) { case 'a': adapter_mask = 0x0; @@ -304,9 +304,6 @@ main(int argc, char **argv) case 'c': confpath = optarg; break; - case 'm': - muxpath = optarg; - break; case 'd': log_debug_to_console = 1; break; @@ -386,7 +383,9 @@ main(int argc, char **argv) * Initialize subsystems */ - muxes_init(muxpath); + config_init(); + + muxes_init(); service_init(); diff --git a/src/muxes.c b/src/muxes.c index 318663b5..5e13f21e 100644 --- a/src/muxes.c +++ b/src/muxes.c @@ -32,6 +32,7 @@ #include "dvb/dvb.h" #include "muxes.h" #include "filebundle.h" +#include "config2.h" region_list_t regions_DVBC; region_list_t regions_DVBT; @@ -95,7 +96,6 @@ tldcode2longname(const char *tld) for(i = 0; i < sizeof(tldlist) / sizeof(tldlist[0]); i++) if(!strcmp(tld, tldlist[i].code)) return tldlist[i].name; - tvhlog(LOG_WARNING, "muxes", "unknown tld code %s", tld); return tld; } @@ -197,7 +197,6 @@ static int _reg_cmp ( void *a, void *b ) static region_t *_muxes_region_create ( const char *type, const char *id, const char *desc ) { - printf("_muxes_region_create(%s, %s, %s)\n", type, id, desc); region_t *reg; region_list_t *list = NULL; if (!strcmp(type, "dvb-s")) list = ®ions_DVBS; @@ -344,7 +343,7 @@ static void _muxes_load_dir ( const char *path, const char *type ) if (de->type == FB_DIR) { snprintf(p, sizeof(p), "%s/%s", path, de->name); _muxes_load_dir(p, de->name); - } else { + } else if (type) { _muxes_load_file(type, dir, de->name); } } @@ -355,12 +354,9 @@ static void _muxes_load_dir ( const char *path, const char *type ) /* * Initialise the mux list */ -void muxes_init ( const char *path ) +void muxes_init ( void ) { - /* Default */ - if (!path) - path = "data/dvb-scan"; - - /* Process */ + const char *path = config_get_muxconfpath(); + if (!path || !*path) path = "data/dvb-scan"; _muxes_load_dir(path, NULL); } diff --git a/src/muxes.h b/src/muxes.h index 1cf51896..43511a83 100644 --- a/src/muxes.h +++ b/src/muxes.h @@ -54,6 +54,6 @@ extern region_list_t regions_DVBT; extern region_list_t regions_DVBS; extern region_list_t regions_ATSC; -void muxes_init ( const char *path ); +void muxes_init ( void ); #endif /* __TVH_MUXES_H__ */ diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 6134839d..4b992951 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -43,6 +43,8 @@ #include "epg.h" #include "iptv_input.h" +#include "config2.h" + static void extjs_load(htsbuf_queue_t *hq, const char *script) { @@ -131,6 +133,7 @@ extjs_root(http_connection_t *hc, const char *remain, void *opaque) extjs_load(hq, "static/app/epg.js"); extjs_load(hq, "static/app/dvr.js"); extjs_load(hq, "static/app/epggrab.js"); + extjs_load(hq, "static/app/config.js"); /** * Finally, the app itself @@ -1697,6 +1700,58 @@ extjs_tvadapter(http_connection_t *hc, const char *remain, void *opaque) return 0; } +/** + * + */ +static int +extjs_config(http_connection_t *hc, const char *remain, void *opaque) +{ + htsbuf_queue_t *hq = &hc->hc_reply; + const char *op = http_arg_get(&hc->hc_req_args, "op"); + htsmsg_t *out, *m; + const char *str; + + if(op == NULL) + return 400; + + pthread_mutex_lock(&global_lock); + + if(http_access_verify(hc, ACCESS_ADMIN)) { + pthread_mutex_unlock(&global_lock); + return HTTP_STATUS_UNAUTHORIZED; + } + + pthread_mutex_unlock(&global_lock); + + /* Basic settings (not the advanced schedule) */ + if(!strcmp(op, "loadSettings")) { + pthread_mutex_lock(&global_lock); + out = htsmsg_create_map(); + if ((m = config_get_all())) + htsmsg_add_msg(out, "config", m); + pthread_mutex_unlock(&global_lock); + + /* Save settings */ + } else if (!strcmp(op, "saveSettings") ) { + int save = 0; + pthread_mutex_lock(&global_lock); + if ((str = http_arg_get(&hc->hc_req_args, "muxconfpath"))) + save |= config_set_muxconfpath(str); + if (save) config_save(); + pthread_mutex_unlock(&global_lock); + out = htsmsg_create_map(); + htsmsg_add_u32(out, "success", 1); + + } else { + return HTTP_STATUS_BAD_REQUEST; + } + + htsmsg_json_serialize(out, hq, 0); + htsmsg_destroy(out); + http_output_content(hc, "text/x-json; charset=UTF-8"); + + return 0; +} /** * WEB user interface @@ -1717,6 +1772,7 @@ extjs_start(void) http_path_add("/dvr", NULL, extjs_dvr, ACCESS_WEB_INTERFACE); http_path_add("/dvrlist", NULL, extjs_dvrlist, ACCESS_WEB_INTERFACE); http_path_add("/ecglist", NULL, extjs_ecglist, ACCESS_WEB_INTERFACE); + http_path_add("/config", NULL, extjs_config, ACCESS_WEB_INTERFACE); http_path_add("/mergechannel", NULL, extjs_mergechannel, ACCESS_ADMIN); diff --git a/src/webui/static/app/config.js b/src/webui/static/app/config.js new file mode 100644 index 00000000..947f8f2d --- /dev/null +++ b/src/webui/static/app/config.js @@ -0,0 +1,91 @@ +tvheadend.miscconf = function() { + + /* + * Basic Config + */ + + var confreader = new Ext.data.JsonReader( + { root: 'config' }, + [ + 'muxconfpath', + ] + ); + + /* **************************************************************** + * Form Fields + * ***************************************************************/ + + var dvbscanPath = new Ext.form.TextField({ + fieldLabel : 'DVB scan files path', + name : 'muxconfpath', + allowBlank : true, + }); + + /* **************************************************************** + * Form + * ***************************************************************/ + + var saveButton = new Ext.Button({ + text : "Save configuration", + tooltip : 'Save changes made to configuration below', + iconCls :'save', + handler : saveChanges, + }); + + var helpButton = new Ext.Button({ + text : 'Help', + handler : function() { + new tvheadend.help('General Configuration', + 'config_misc.html'); + } + }); + + var confpanel = new Ext.FormPanel({ + title : 'General', + iconCls : 'wrench', + border : false, + bodyStyle : 'padding:15px', + labelAlign : 'left', + labelWidth : 150, + waitMsgTarget : true, + reader : confreader, + layout : 'form', + defaultType : 'textfield', + autoHeight : true, + items : [ + dvbscanPath + ], + tbar: [ + saveButton, + '->', + helpButton + ] + }); + + /* **************************************************************** + * Load/Save + * ***************************************************************/ + + confpanel.on('render', function() { + confpanel.getForm().load({ + url : 'config', + params : { op : 'loadSettings' }, + success : function ( form, action ) { + confpanel.enable(); + } + }); + }); + + function saveChanges() { + confpanel.getForm().submit({ + url : 'config', + params : { op : 'saveSettings' }, + waitMsg : 'Saving Data...', + failure : function (form, action) { + Ext.Msg.alert('Save failed', action.result.errormsg); + } + }); + } + + return confpanel; +} diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index 1b70dcb5..a5a98a10 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -233,7 +233,9 @@ function accessUpdate(o) { autoScroll:true, title: 'Configuration', iconCls: 'wrench', - items: [new tvheadend.chconf, + items: [ + new tvheadend.miscconf, + new tvheadend.chconf, new tvheadend.epggrab, new tvheadend.cteditor, new tvheadend.dvrsettings,