diff --git a/ajaxui/ajaxui_config_channels.c b/ajaxui/ajaxui_config_channels.c
index 97779bef..b4cbbace 100644
--- a/ajaxui/ajaxui_config_channels.c
+++ b/ajaxui/ajaxui_config_channels.c
@@ -443,6 +443,21 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr,
tcp_qprintf(tq, "
\r\n");
+ tcp_qprintf(tq, "");
+ ajax_a_jsfuncf(tq, "Rename channel...",
+ "channel_rename('%d', '%s');",
+ ch->ch_tag, ch->ch_name);
+
+ tcp_qprintf(tq, " / ");
+
+ ajax_a_jsfuncf(tq, "Delete channel...",
+ "channel_delete('%d', '%s');",
+ ch->ch_tag, ch->ch_name);
+
+ tcp_qprintf(tq, "
");
+
+ tcp_qprintf(tq, "
\r\n");
+
tcp_qprintf(tq,
""
"Commercial detection:
"
@@ -533,6 +548,75 @@ ajax_chsetcomdetect(http_connection_t *hc, http_reply_t *hr,
}
+/**
+ * Rename a channel
+ */
+static int
+ajax_chrename(http_connection_t *hc, http_reply_t *hr,
+ const char *remain, void *opaque)
+{
+ tcp_queue_t *tq = &hr->hr_tq;
+ th_channel_t *ch;
+ const char *s;
+
+ if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
+ return HTTP_STATUS_BAD_REQUEST;
+
+ if((s = http_arg_get(&hc->hc_req_args, "newname")) == NULL)
+ return HTTP_STATUS_BAD_REQUEST;
+
+ if(channel_rename(ch, s)) {
+ tcp_qprintf(tq, "alert('Channel already exist');");
+ } else {
+ tcp_qprintf(tq,
+ "new Ajax.Updater('groupeditortab', "
+ "'/ajax/chgroup_editor/%d', "
+ "{method: 'get', evalScripts: true});\r\n",
+ ch->ch_group->tcg_tag);
+
+ tcp_qprintf(tq,
+ "new Ajax.Updater('cheditortab', "
+ "'/ajax/cheditor/%d', "
+ "{method: 'get', evalScripts: true});\r\n",
+ ch->ch_tag);
+ }
+
+ http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
+ return 0;
+}
+
+
+/**
+ * Delete channel
+ */
+static int
+ajax_chdelete(http_connection_t *hc, http_reply_t *hr,
+ const char *remain, void *opaque)
+{
+ tcp_queue_t *tq = &hr->hr_tq;
+ th_channel_t *ch;
+ th_channel_group_t *tcg;
+
+ if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
+ return HTTP_STATUS_BAD_REQUEST;
+
+ tcg = ch->ch_group;
+
+ channel_delete(ch);
+
+ 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;
+}
+
+
/**
*
*/
@@ -553,5 +637,9 @@ ajax_config_channels_init(void)
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chsetcomdetect", NULL, ajax_chsetcomdetect,
AJAX_ACCESS_CONFIG);
+ http_path_add("/ajax/chrename", NULL, ajax_chrename,
+ AJAX_ACCESS_CONFIG);
+ http_path_add("/ajax/chdelete", NULL, ajax_chdelete,
+ AJAX_ACCESS_CONFIG);
}
diff --git a/ajaxui/tvheadend.js b/ajaxui/tvheadend.js
index 6485e4b5..e385f106 100644
--- a/ajaxui/tvheadend.js
+++ b/ajaxui/tvheadend.js
@@ -103,4 +103,20 @@ function makedivinput(id, url)
'onClick="new Ajax.Request(\'' + url + '\', ' +
'{parameters: {value: $F(\'val' + id + '\')}})">' +
'';
-}
\ No newline at end of file
+}
+
+function channel_rename(tag, oldname)
+{
+ newname = prompt("Enter new name", oldname);
+ if(newname != null && newname != oldname) {
+ a = new Ajax.Request('/ajax/chrename/' + tag,
+ { parameters: { 'newname': newname}});
+ }
+}
+
+function channel_delete(tag, name)
+{
+ if(confirm("Are you sure you want to delete '" + name + "'") == true) {
+ a = new Ajax.Request('/ajax/chdelete/' + tag);
+ }
+}
diff --git a/channels.c b/channels.c
index ccdbf503..47df3803 100644
--- a/channels.c
+++ b/channels.c
@@ -159,22 +159,16 @@ channel_group_destroy(th_channel_group_t *tcg)
/**
*
*/
-th_channel_t *
-channel_find(const char *name, int create, th_channel_group_t *tcg)
+static void
+channel_set_name(th_channel_t *ch, const char *name)
{
const char *n2;
- th_channel_t *ch;
int l, i;
char *cp, c;
- LIST_FOREACH(ch, &channels, ch_global_link)
- if(!strcasecmp(name, ch->ch_name))
- return ch;
+ free((void *)ch->ch_name);
+ free((void *)ch->ch_sname);
- if(create == 0)
- return NULL;
-
- ch = calloc(1, sizeof(th_channel_t));
ch->ch_name = strdup(name);
l = strlen(name);
@@ -193,10 +187,29 @@ channel_find(const char *name, int create, th_channel_group_t *tcg)
free((void *)n2);
+ LIST_INSERT_SORTED(&channels, ch, ch_global_link, channelcmp);
+}
+
+/**
+ *
+ */
+th_channel_t *
+channel_find(const char *name, int create, th_channel_group_t *tcg)
+{
+ th_channel_t *ch;
+
+ LIST_FOREACH(ch, &channels, ch_global_link)
+ if(!strcasecmp(name, ch->ch_name))
+ return ch;
+
+ if(create == 0)
+ return NULL;
+
+ ch = calloc(1, sizeof(th_channel_t));
ch->ch_index = nchannels;
TAILQ_INIT(&ch->ch_epg_events);
- LIST_INSERT_SORTED(&channels, ch, ch_global_link, channelcmp);
+ channel_set_name(ch, name);
channel_set_group(ch, tcg ?: defgroup);
@@ -431,3 +444,40 @@ channel_settings_write(th_channel_t *ch)
fclose(fp);
}
+/**
+ * Rename a channel and all tied transports
+ */
+int
+channel_rename(th_channel_t *ch, const char *newname)
+{
+ th_transport_t *t;
+
+ if(channel_find(newname, 0, NULL))
+ return -1;
+
+ LIST_REMOVE(ch, ch_global_link);
+ channel_set_name(ch, newname);
+
+ LIST_FOREACH(t, &ch->ch_transports, tht_channel_link) {
+ free(t->tht_servicename);
+ t->tht_servicename = strdup(newname);
+ t->tht_config_change(t);
+ }
+
+ channel_settings_write(ch);
+ return 0;
+}
+
+/**
+ * Delete channel
+ */
+void
+channel_delete(th_channel_t *ch)
+{
+ th_transport_t *t;
+
+ while((t = LIST_FIRST(&ch->ch_transports)) != NULL)
+ transport_unmap_channel(t);
+
+ printf("Deleted channel %s\n", ch->ch_name);
+}
diff --git a/channels.h b/channels.h
index fbc2bc73..ca5d2fc3 100644
--- a/channels.h
+++ b/channels.h
@@ -48,4 +48,8 @@ void channel_group_settings_write(void);
void channel_settings_write(th_channel_t *ch);
+int channel_rename(th_channel_t *ch, const char *newname);
+
+void channel_delete(th_channel_t *ch);
+
#endif /* CHANNELS_H */