]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
store configuration
authorAndreas Öman <andreas@lonelycoder.com>
Fri, 7 Dec 2007 10:37:17 +0000 (10:37 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Fri, 7 Dec 2007 10:37:17 +0000 (10:37 +0000)
channels.c
htmlui.c
main.c
transports.c

index 628d12d395c5d9b83d78d3eff0be11f210fe39b1..8d16bef6a12819d05e94bf07142bd75853a2052c 100644 (file)
@@ -112,8 +112,7 @@ channel_group_find(const char *name, int create)
 
   TAILQ_INSERT_TAIL(&all_channel_groups, tcg, tcg_global_link);
 
-  if(!dontwritesettings)
-    channel_settings_write();
+  channel_settings_write();
 
   return tcg;
 }
@@ -132,8 +131,7 @@ channel_set_group(th_channel_t *ch, th_channel_group_t *tcg)
 
   ch->ch_group = tcg;
   TAILQ_INSERT_SORTED(&tcg->tcg_channels, ch, ch_group_link, channelcmp);
-  if(!dontwritesettings)
-    channel_settings_write();
+  channel_settings_write();
 }
 
 /**
@@ -392,8 +390,9 @@ channel_settings_write(void)
   FILE *fp;
   th_channel_group_t *tcg;
   th_channel_t *ch;
+  th_transport_t *t;
 
-  if(settingsfile == NULL)
+  if(dontwritesettings || startupcounter > 0 || settingsfile == NULL)
     return;
 
   fp = fopen(settingsfile, "w+");
@@ -404,6 +403,9 @@ channel_settings_write(void)
     fprintf(fp, "channel-group {\n"
            "\tname = %s\n", tcg->tcg_name);
     TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
+      if(LIST_FIRST(&ch->ch_transports) == NULL)
+       continue;
+
       fprintf(fp, "\tchannel {\n"
              "\t\tname = %s\n", ch->ch_name);
       if(ch->ch_teletext_rundown)
@@ -412,5 +414,19 @@ channel_settings_write(void)
     }
     fprintf(fp, "}\n");
   }
+
+  LIST_FOREACH(t, &all_transports, tht_global_link) {
+    if(t->tht_channel == NULL)
+      continue;
+
+    fprintf(fp, "transport {\n"
+           "\tuniquename = %s\n"
+           "\tchannel = %s\n"
+           "\tprio = %d\n"
+           "}\n",
+           t->tht_uniquename,
+           t->tht_channel->ch_name,
+           t->tht_prio);
+  }
   fclose(fp);
 }
index fa6dbce767e6dee0bc80389d858b41771c7bd183..835fe7ee96779f1b8176844bbd90a354288631b5 100644 (file)
--- a/htmlui.c
+++ b/htmlui.c
@@ -460,6 +460,9 @@ page_root(http_connection_t *hc, const char *remain, void *opaque)
     tcp_qprintf(&tq, "<br>");
 
     TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
+      if(LIST_FIRST(&ch->ch_transports) == NULL)
+       continue;
+
       box_top(&tq, "box");
       tcp_qprintf(&tq, "<div class=\"content3\">");
 
@@ -1550,11 +1553,11 @@ static int
 page_updatechannel(http_connection_t *hc, const char *remain, void *opaque)
 {
   th_channel_t *ch, *ch2;
-  th_transport_t *t;
+  th_transport_t *t, **tv;
   th_channel_group_t *tcg;
   const char *grp, *s;
   char buf[100];
-  int pri;
+  int pri, i, n;
 
   if(!html_verify_access(hc, "admin"))
     return HTTP_STATUS_UNAUTHORIZED;
@@ -1587,7 +1590,20 @@ page_updatechannel(http_connection_t *hc, const char *remain, void *opaque)
     channel_set_group(ch, tcg);
   }
 
-  LIST_FOREACH(t, &ch->ch_transports, tht_channel_link) {
+  /* We are going to rearrange listorder by changing priority, so we
+     cannot just loop the list */
+
+  n = 0;
+  LIST_FOREACH(t, &ch->ch_transports, tht_channel_link)
+    n++;
+
+  tv = alloca(n * sizeof(th_transport_t *));
+  n = 0;
+  LIST_FOREACH(t, &ch->ch_transports, tht_channel_link)
+    tv[n++] = t;
+  
+  for(i = 0; i < n; i++) {
+    t = tv[i];
     s = http_arg_get(&hc->hc_url_args, t->tht_uniquename);
     if(s != NULL) {
       pri = atoi(s);
@@ -1597,8 +1613,6 @@ page_updatechannel(http_connection_t *hc, const char *remain, void *opaque)
     }
   }
   
-  channel_settings_write();
-
   snprintf(buf, sizeof(buf), "/editchannel/%d", ch->ch_tag);
   http_redirect(hc, buf);
   return 0;
diff --git a/main.c b/main.c
index a29f2069c2ef1bc64e12d3f9b6176a74e9f0254f..7ecda1f11483caf92550454329d57c2b081ee43d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -203,6 +203,8 @@ main(int argc, char **argv)
   while(running) {
 
     if(startupcounter == 0) {
+      channel_settings_write();
+
       startupcounter = -1;
       syslog(LOG_NOTICE, 
             "Initial input setup completed, starting output modules");
index 48da64717ee3780adeff467af969874f84565e97..a726273921c3ec5394ab960d59ed572585fc9a3a 100644 (file)
@@ -53,6 +53,7 @@
 #include "pes.h"
 #include "buffer.h"
 #include "plugin.h"
+#include "channels.h"
 
 static dtimer_t transport_monitor_timer;
 
@@ -387,11 +388,28 @@ transport_set_channel(th_transport_t *t, th_channel_t *ch)
   th_stream_t *st;
   char *chname;
   const char *n;
-
+  config_entry_t *ce;
   char pid[30];
   char lang[30];
 
   assert(t->tht_uniquename != NULL);
+
+  TAILQ_FOREACH(ce, &settings_list, ce_link) {
+    if(ce->ce_type != CFG_SUB || strcasecmp("transport", ce->ce_key))
+      continue;
+
+    n = config_get_str_sub(&ce->ce_sub, "uniquename", NULL);
+    if(n != NULL && !strcmp(n, t->tht_uniquename))
+      break;
+  }
+
+  if(ce != NULL) {
+    t->tht_prio = atoi(config_get_str_sub(&ce->ce_sub, "prio", "0"));
+    n = config_get_str_sub(&ce->ce_sub, "channel", NULL);
+    if(n != NULL)
+      ch = channel_find(n, 1, NULL); 
+  }
+
   t->tht_channel = ch;
   LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp);
 
@@ -437,6 +455,7 @@ transport_set_priority(th_transport_t *t, int prio)
   LIST_REMOVE(t, tht_channel_link);
   t->tht_prio = prio;
   LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp);
+  channel_settings_write();
 }
 
 
@@ -449,4 +468,5 @@ transport_move(th_transport_t *t, th_channel_t *ch)
   LIST_REMOVE(t, tht_channel_link);
   t->tht_channel = ch;
   LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp);
+  channel_settings_write();
 }