]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add support for rename and delete of channel.
authorAndreas Öman <andreas@lonelycoder.com>
Sat, 3 May 2008 05:13:31 +0000 (05:13 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Sat, 3 May 2008 05:13:31 +0000 (05:13 +0000)
Channel destroy still needs to be fixed though.

ajaxui/ajaxui_config_channels.c
ajaxui/tvheadend.js
channels.c
channels.h

index 97779bef8c8059016d3216d0bfa54cda343ae7ac..b4cbbace8d3555621f4863c2e6853961d4152059 100644 (file)
@@ -443,6 +443,21 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr,
 
   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>"
@@ -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);
 
 }
index 6485e4b52ac9257f01fff98c85fe298e5efb82a7..e385f10683c3a45cd54ef65bb4cf755b1ce57e87 100644 (file)
@@ -103,4 +103,20 @@ function makedivinput(id, url)
        '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);
+       }
+}
index ccdbf5035fb4310ebf911842ff525662a7e30c01..47df38032bbd8aebca3ac6c7902dee3057df89f7 100644 (file)
@@ -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);
+}
index fbc2bc73ccbe6491e6ac35b67bd940fc6ab83e1b..ca5d2fc3651209f473af55d29bc60dfe495f83f8 100644 (file)
@@ -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 */