diff --git a/ajaxui/ajaxui_config_channels.c b/ajaxui/ajaxui_config_channels.c index d6dc01cd..9cc73af9 100644 --- a/ajaxui/ajaxui_config_channels.c +++ b/ajaxui/ajaxui_config_channels.c @@ -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, ""); + tcp_qprintf(tq, + ""); + tcp_qprintf(tq, ""); tcp_qprintf(tq, "
\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); } diff --git a/ajaxui/tvheadend.js b/ajaxui/tvheadend.js index 66a34084..53be59cd 100644 --- a/ajaxui/tvheadend.js +++ b/ajaxui/tvheadend.js @@ -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}}); + } +} diff --git a/channels.c b/channels.c index c16aa4f4..0fcd0c54 100644 --- a/channels.c +++ b/channels.c @@ -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); +} diff --git a/channels.h b/channels.h index 83a206e0..7f5a9e1d 100644 --- a/channels.h +++ b/channels.h @@ -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 */