From ae9190d057d897e4298fd373aa90e4d9577b2232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sun, 4 May 2008 20:03:42 +0000 Subject: [PATCH] Refactor service<>channel mapping UI code slightly --- ajaxui/ajaxui.h | 3 ++ ajaxui/ajaxui_config_transport.c | 62 +++++++++++++++++--------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/ajaxui/ajaxui.h b/ajaxui/ajaxui.h index 274870ca..0b2aa302 100644 --- a/ajaxui/ajaxui.h +++ b/ajaxui/ajaxui.h @@ -116,4 +116,7 @@ void ajax_a_jsfuncf(tcp_queue_t *tq, const char *innerhtml, void ajax_button(tcp_queue_t *tq, const char *caption, const char *code, ...); +void ajax_transport_build_mapper_state(char *buf, size_t siz, + th_transport_t *t, int mapped); + #endif /* AJAXUI_H_ */ diff --git a/ajaxui/ajaxui_config_transport.c b/ajaxui/ajaxui_config_transport.c index 1950d778..e28e388a 100644 --- a/ajaxui/ajaxui_config_transport.c +++ b/ajaxui/ajaxui_config_transport.c @@ -25,8 +25,6 @@ #include #include -#include - #include "tvhead.h" #include "http.h" #include "ajaxui.h" @@ -254,19 +252,31 @@ ajax_transport_rename_channel(http_connection_t *hc, http_reply_t *hr, return 0; } + /** * */ -static void -dvb_map_channel(th_transport_t *t, tcp_queue_t *tq) +void +ajax_transport_build_mapper_state(char *buf, size_t siz, th_transport_t *t, + int mapped) { - transport_map_channel(t, NULL); - - tcp_qprintf(tq, - "$('chname_%s').innerHTML='%s';\n\r" - "$('map_%s').src='/gfx/mapped.png';\n\r", - t->tht_identifier, t->tht_ch->ch_name, - t->tht_identifier); + if(mapped) { + snprintf(buf, siz, + "$('chname_%s').innerHTML='%s';\n\r" + "$('map_%s').src='/gfx/mapped.png';\n\r", + t->tht_identifier, t->tht_ch->ch_name, + t->tht_identifier); + } else { + snprintf(buf, siz, + "$('chname_%s').innerHTML='" + "%s" + "';\n\r" + "$('map_%s').src='/gfx/unmapped.png';\n\r", + t->tht_identifier, t->tht_identifier, t->tht_identifier, + t->tht_chname, t->tht_chname, t->tht_identifier); + } } @@ -274,23 +284,20 @@ dvb_map_channel(th_transport_t *t, tcp_queue_t *tq) * */ static void -dvb_unmap_channel(th_transport_t *t, tcp_queue_t *tq) +ajax_map_unmap_channel(th_transport_t *t, tcp_queue_t *tq, int map) { - transport_unmap_channel(t); + char buf[1000]; - tcp_qprintf(tq, - "$('chname_%s').innerHTML='" - "%s" - "';\n\r" - "$('map_%s').src='/gfx/unmapped.png';\n\r", - t->tht_identifier, t->tht_identifier, t->tht_identifier, - t->tht_chname, t->tht_chname, t->tht_identifier); + if(map) + transport_map_channel(t, NULL); + else + transport_unmap_channel(t); + + ajax_transport_build_mapper_state(buf, sizeof(buf), t, map); + tcp_qprintf(tq, "%s", buf); } - /** * */ @@ -314,14 +321,11 @@ ajax_transport_op(http_connection_t *hc, http_reply_t *hr, continue; if(!strcmp(op, "toggle")) { - if(t->tht_ch) - dvb_unmap_channel(t, tq); - else - dvb_map_channel(t, tq); + ajax_map_unmap_channel(t, tq, t->tht_ch ? 0 : 1); } else if(!strcmp(op, "map") && t->tht_ch == NULL) { - dvb_map_channel(t, tq); + ajax_map_unmap_channel(t, tq, 1); } else if(!strcmp(op, "unmap") && t->tht_ch != NULL) { - dvb_unmap_channel(t, tq); + ajax_map_unmap_channel(t, tq, 0); } else if(!strcmp(op, "probe")) { serviceprobe_add(t); continue;