]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add support for mergin channels
authorAndreas Öman <andreas@lonelycoder.com>
Sat, 3 May 2008 06:38:42 +0000 (06:38 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Sat, 3 May 2008 06:38:42 +0000 (06:38 +0000)
ajaxui/ajaxui_config_channels.c
ajaxui/tvheadend.js
channels.c
channels.h

index d6dc01cdce0d5edb157b72c14b76f70e201fff98..9cc73af91e0bd3a64daf9a15528c41e1f7724f01 100644 (file)
@@ -400,7 +400,8 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr,
              const char *remain, void *opaque)
 {
   tcp_queue_t *tq = &hr->hr_tq;
-  channel_t *ch;
+  channel_t *ch, *ch2;
+  channel_group_t *chg;
   th_transport_t *t;
   const char *s;
   int i;
@@ -454,8 +455,24 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr,
              "onClick=\"channel_delete('%d', '%s')\">",
              ch->ch_tag, ch->ch_name);
 
-  tcp_qprintf(tq, "</div>");
+  tcp_qprintf(tq,
+             "<select "
+             "onChange=\"channel_merge('%d', this.value);\">",
+             ch->ch_tag);
+  
+  tcp_qprintf(tq, "<option value=\"n\">Merge to channel:</option>");
 
+  
+  TAILQ_FOREACH(chg, &all_channel_groups, tcg_global_link) {
+    TAILQ_FOREACH(ch2, &chg->tcg_channels, ch_group_link) {
+      if(ch2 != ch)
+       tcp_qprintf(tq, "<option value=\"%d\">%s</option>",
+                   ch2->ch_tag, ch2->ch_name);
+    }
+  }
+  
+  tcp_qprintf(tq, "</select>");
+  tcp_qprintf(tq, "</div>");
   tcp_qprintf(tq, "<hr>\r\n");
 
   tcp_qprintf(tq,
@@ -616,6 +633,42 @@ ajax_chdelete(http_connection_t *hc, http_reply_t *hr,
   return 0;
 }
 
+/**
+ * Merge channel
+ */
+static int
+ajax_chmerge(http_connection_t *hc, http_reply_t *hr,
+            const char *remain, void *opaque)
+{
+  tcp_queue_t *tq = &hr->hr_tq;
+  channel_t *src, *dst;
+  channel_group_t *tcg;
+  const char *s;
+
+  if(remain == NULL || (src = channel_by_tag(atoi(remain))) == NULL)
+    return HTTP_STATUS_NOT_FOUND;
+  
+  if((s = http_arg_get(&hc->hc_req_args, "dst")) == NULL)
+    return HTTP_STATUS_BAD_REQUEST;
+  
+  if((dst = channel_by_tag(atoi(s))) == NULL)
+    return HTTP_STATUS_BAD_REQUEST;
+
+  tcg = src->ch_group;
+  channel_merge(dst, src);
+
+  tcp_qprintf(tq, 
+             "new Ajax.Updater('groupeditortab', "
+             "'/ajax/chgroup_editor/%d', "
+             "{method: 'get', evalScripts: true});\r\n",
+             tcg->tcg_tag);
+  tcp_qprintf(tq, "$('cheditortab').innerHTML='';\r\n");
+
+  http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
+  return 0;
+}
+
 
 /**
  *
@@ -641,5 +694,7 @@ ajax_config_channels_init(void)
                AJAX_ACCESS_CONFIG);
   http_path_add("/ajax/chdelete",            NULL, ajax_chdelete,
                AJAX_ACCESS_CONFIG);
+  http_path_add("/ajax/chmerge",             NULL, ajax_chmerge,
+               AJAX_ACCESS_CONFIG);
 
 }
index 66a340846b9555a15c9787994ba012bda948ac7a..53be59cdb22726a06034357f77101e1e2ad73a5d 100644 (file)
@@ -116,7 +116,15 @@ function channel_rename(tag, oldname)
 
 function channel_delete(tag, name)
 {
-       if(confirm("Are you sure you want to delete '" + name + "'") == true) {
+       if(confirm("Are you sure you want to delete '" + name + "'") == true){
                a = new Ajax.Request('/ajax/chdelete/' + tag);
        }
 }
+
+function channel_merge(srctag, dsttag)
+{
+       if(confirm("Are you sure") == true){
+               a = new Ajax.Request('/ajax/chmerge/' + srctag,
+                                       {parameters: {dst: dsttag}});
+       }
+}
index c16aa4f4d2c44bf0807c18eed41701e4f2ebaeff..0fcd0c549ff71bec54b4969af4d5fc93be710012 100644 (file)
@@ -508,3 +508,28 @@ channel_delete(channel_t *ch)
   snprintf(buf, sizeof(buf), "%s/channels/%s", settings_dir, ch->ch_sname);
   unlink(buf);
 }
+
+
+
+/**
+ * Merge transports from channel 'src' to channel 'dst'
+ *
+ * Then, destroy the 'src' channel
+ */
+void
+channel_merge(channel_t *dst, channel_t *src)
+{
+  th_transport_t *t;
+
+  while((t = LIST_FIRST(&src->ch_transports)) != NULL) {
+    transport_unmap_channel(t);
+
+    free(t->tht_servicename);
+    t->tht_servicename = strdup(dst->ch_name);
+
+    transport_map_channel(t);
+    t->tht_config_change(t);
+  }
+
+  channel_delete(src);
+}
index 83a206e0ba925da8932e3341aff26428c55abb9b..7f5a9e1df2c4c85f336249fdef9428bd06a4e668 100644 (file)
@@ -51,4 +51,6 @@ int channel_rename(channel_t *ch, const char *newname);
 
 void channel_delete(channel_t *ch);
 
+void channel_merge(channel_t *dst, channel_t *src);
+
 #endif /* CHANNELS_H */