tcp_qprintf(tq, "<hr>\r\n");
+ tcp_qprintf(tq, "<div style=\"overflow: auto; width:100%%\">");
+ 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, "</div>");
+
+ tcp_qprintf(tq, "<hr>\r\n");
+
tcp_qprintf(tq,
"<div class=\"infoprefixwidewidefat\">"
"Commercial detection:</div>"
}
+/**
+ * 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;
+}
+
+
/**
*
*/
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);
}
'onClick="new Ajax.Request(\'' + url + '\', ' +
'{parameters: {value: $F(\'val' + id + '\')}})">' +
'</div></div>';
-}
\ 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);
+ }
+}
/**
*
*/
-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);
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);
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);
+}