]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Updated to include support for mux configuration setting in UI, I have added a genera...
authorAdam Sutton <dev@adamsutton.me.uk>
Fri, 3 Aug 2012 14:52:13 +0000 (15:52 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Tue, 14 Aug 2012 19:02:38 +0000 (20:02 +0100)
Makefile
docs/html/config_misc.html [new file with mode: 0644]
src/config2.c [new file with mode: 0644]
src/config2.h [new file with mode: 0644]
src/main.c
src/muxes.c
src/muxes.h
src/webui/extjs.c
src/webui/static/app/config.js [new file with mode: 0644]
src/webui/static/app/tvheadend.js

index 6c725f095e15b717c0b728ee9502a4d15d3515a0..0edf1d44f23227031ae41027c1a6afa0fb665937 100644 (file)
--- 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 (file)
index 0000000..d712d39
--- /dev/null
@@ -0,0 +1,15 @@
+<div class="hts-doc-text">
+
+ <p>
+ This tabs allow configuration of several general parameters that affect the
+ core TVH functionality.
+ </p>
+
+ <dl>
+  <dt>DVB scan files path:
+  <dd>Select the path to use for DVB scan configuration files. Typically</dt>
+  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/)</dd>
+ </dl>  
+
+</div>
diff --git a/src/config2.c b/src/config2.c
new file mode 100644 (file)
index 0000000..2b635c4
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "tvheadend.h"
+#include "settings.h"
+#include "config2.h"
+
+#include <string.h>
+
+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 (file)
index 0000000..b9d7d9a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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__ */
index c689abe8afb2cfe7ba348ab574f5c6ee10bb972d..c15f0912709e09afe553de870fdc20ba6ee6788e 100644 (file)
@@ -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();
 
index 318663b571434e7434e82b4488916b0ff5c8ce5b..5e13f21ec68f59d9aeadb65a5cbbb39059e670e1 100644 (file)
@@ -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 = &regions_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);
 } 
index 1cf51896462900174ba78d942bee5956cfcf1bac..43511a832952f2f214c8e984a749fa99d099659e 100644 (file)
@@ -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__ */
index 6134839d072f46775f0f4899e03d1ca13bc0fa7a..4b992951edd82db02a1ffa96b46aca4ddfa42d56 100644 (file)
@@ -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 (file)
index 0000000..947f8f2
--- /dev/null
@@ -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;
+}
index 1b70dcb569766c9356a54465d6448d36eee8ec18..a5a98a10d36fbad5e114e2cdd930c99694ff9081 100644 (file)
@@ -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,