/* * tvheadend, AJAX / HTML user interface * Copyright (C) 2008 Andreas Öman * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include "tvhead.h" #include "http.h" #include "ajaxui.h" #include "obj/ajaxui.cssh" #include "obj/prototype.jsh" #include "obj/builder.jsh" #include "obj/controls.jsh" #include "obj/dragdrop.jsh" #include "obj/effects.jsh" #include "obj/scriptaculous.jsh" #include "obj/slider.jsh" #include "obj/tvheadend.jsh" #include "obj/sbbody_l.gifh" #include "obj/sbbody_r.gifh" #include "obj/sbhead_l.gifh" #include "obj/sbhead_r.gifh" #include "obj/mapped.pngh" #include "obj/unmapped.pngh" const char *ajax_tabnames[] = { [AJAX_TAB_CHANNELS] = "Channels", [AJAX_TAB_RECORDER] = "Recorder", [AJAX_TAB_CONFIGURATION] = "Configuration", [AJAX_TAB_ABOUT] = "About", }; /** * AJAX box start */ void ajax_box_begin(tcp_queue_t *tq, ajax_box_t type, const char *id, const char *style, const char *title) { char id0[100], style0[100]; if(id != NULL) snprintf(id0, sizeof(id0), "id=\"%s\" ", id); else id0[0] = 0; if(style != NULL) snprintf(style0, sizeof(style0), "style=\"%s\" ", style); else style0[0] = 0; switch(type) { case AJAX_BOX_SIDEBOX: tcp_qprintf(tq, "
" "

%s

\r\n" "
", title, id0, style0); break; case AJAX_BOX_FILLED: tcp_qprintf(tq, "
" "" "" "" "" "" "" "
\r\n", id0, style0); break; case AJAX_BOX_BORDER: tcp_qprintf(tq, "
" "" "" "" "" "
\r\n", id0, style0); break; } } /** * AJAX box end */ void ajax_box_end(tcp_queue_t *tq, ajax_box_t type) { switch(type) { case AJAX_BOX_SIDEBOX: tcp_qprintf(tq,"
"); break; case AJAX_BOX_FILLED: tcp_qprintf(tq, "
" "" "" "" "" "" "" "
\r\n"); break; case AJAX_BOX_BORDER: tcp_qprintf(tq, "
" "" "" "" "" "
\r\n"); break; } } /** * */ void ajax_js(tcp_queue_t *tq, const char *fmt, ...) { va_list ap; tcp_qprintf(tq, "\r\n"); } /** * Based on the given char[] array, generate a menu bar */ void ajax_menu_bar_from_array(tcp_queue_t *tq, const char *name, const char **vec, int num, int cur) { int i; tcp_qprintf(tq, "
    "); for(i = 0; i < num; i++) { tcp_qprintf(tq, "" "%s" "", cur == i ? " style=\"font-weight:bold;\"" : "", name, i, vec[i]); } tcp_qprintf(tq, "
"); } /** * */ void ajax_a_jsfunc(tcp_queue_t *tq, const char *innerhtml, const char *func, const char *trailer) { tcp_qprintf(tq, "%s%s\r\n", func, innerhtml, trailer); } /* * Titlebar AJAX page */ static int ajax_page_titlebar(http_connection_t *hc, const char *remain, void *opaque) { tcp_queue_t tq; if(remain == NULL) return HTTP_STATUS_NOT_FOUND; tcp_init_queue(&tq, -1); ajax_menu_bar_from_array(&tq, "top", ajax_tabnames, AJAX_TABS, atoi(remain)); http_output_queue(hc, &tq, "text/html; charset=UTF-8", 0); return 0; } /** * About */ static int ajax_about_tab(http_connection_t *hc) { tcp_queue_t tq; tcp_init_queue(&tq, -1); tcp_qprintf(&tq, "
"); tcp_qprintf(&tq, "
"); ajax_box_begin(&tq, AJAX_BOX_SIDEBOX, NULL, NULL, "About"); tcp_qprintf(&tq, "
"); tcp_qprintf(&tq, "

HTS / Tvheadend

" "

(c) 2006-2008 Andreas \303\226man

" "

Latest release and information is available at:

" "

" "http://www.lonelycoder.com/hts/

" "

 

" "

This webinterface is powered by

" "

Prototype" " and " "script.aculo.us" "

" "

 

" "

Media formats and codecs by

" "

FFmpeg

" ); tcp_qprintf(&tq, "
"); ajax_box_end(&tq, AJAX_BOX_SIDEBOX); tcp_qprintf(&tq, "
"); tcp_qprintf(&tq, "
"); http_output_queue(hc, &tq, "text/html; charset=UTF-8", 0); return 0; } /* * Tab AJAX page * * Find the 'tab' id and continue with tab specific code */ static int ajax_page_tab(http_connection_t *hc, const char *remain, void *opaque) { int tab; if(remain == NULL) return HTTP_STATUS_NOT_FOUND; tab = atoi(remain); switch(tab) { case AJAX_TAB_CHANNELS: return ajax_channelgroup_tab(hc); case AJAX_TAB_CONFIGURATION: return ajax_config_tab(hc); case AJAX_TAB_ABOUT: return ajax_about_tab(hc); default: return HTTP_STATUS_NOT_FOUND; } return 0; } /* * Root page */ static int ajax_page_root(http_connection_t *hc, const char *remain, void *opaque) { tcp_queue_t tq; tcp_init_queue(&tq, -1); tcp_qprintf(&tq, "" /* "" */ "\r\n" "" "" "HTS/Tvheadend" "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, ""); tcp_qprintf(&tq, ""); ajax_box_begin(&tq, AJAX_BOX_FILLED, "topmenu", NULL, NULL); ajax_box_end(&tq, AJAX_BOX_FILLED); tcp_qprintf(&tq, "
"); ajax_js(&tq, "switchtab('top', '0')"); tcp_qprintf(&tq, ""); http_output_queue(hc, &tq, "text/html; charset=UTF-8", 0); return 0; } #if 0 void blah(void) { tcp_qprintf(&tq, "
    " "
  • I'm number 1 a link
  • " "
  • "); ajax_box_top(&tq, NULL, NULL); tcp_qprintf(&tq, "I'm number 2"); ajax_box_bottom(&tq); tcp_qprintf(&tq, "
  • " "
  • I'm number 3
  • " "
  • I'm number 4
  • " "
" "\r\n" "

\r\n"); tcp_qprintf(&tq, "\r\n"); tcp_qprintf(&tq, "
\r\n" "
\n" "
\r\n" "
\r\n" "\r\n" "
\r\n"); for(i = 0; i < 40; i++) { tcp_qprintf(&tq, "
\r\n" "

Discovery

\r\n" "
" "

Idag e det bra saker pa TV

" "

Imorgon vet vi inte

" "
"); } tcp_qprintf(&tq, ""); http_output_queue(hc, &tq, "text/html; charset=UTF-8", 0); return 0; } #endif /** * AJAX user interface */ void ajaxui_start(void) { http_path_add("/ajax/index.html", NULL, ajax_page_root); http_path_add("/ajax/topmenu", NULL, ajax_page_titlebar); http_path_add("/ajax/toptab", NULL, ajax_page_tab); /* Stylesheet */ http_resource_add("/ajax/ajaxui.css", embedded_ajaxui, sizeof(embedded_ajaxui), "text/css", "gzip"); #define ADD_JS_RESOURCE(path, name) \ http_resource_add(path, name, sizeof(name), "text/javascript", "gzip") /* Prototype */ ADD_JS_RESOURCE("/ajax/prototype.js", embedded_prototype); /* Scriptaculous */ ADD_JS_RESOURCE("/ajax/builder.js", embedded_builder); ADD_JS_RESOURCE("/ajax/controls.js", embedded_controls); ADD_JS_RESOURCE("/ajax/dragdrop.js", embedded_dragdrop); ADD_JS_RESOURCE("/ajax/effects.js", embedded_effects); ADD_JS_RESOURCE("/ajax/scriptaculous.js", embedded_scriptaculous); ADD_JS_RESOURCE("/ajax/slider.js", embedded_slider); /* Tvheadend */ ADD_JS_RESOURCE("/ajax/tvheadend.js", embedded_tvheadend); /* Embedded images */ http_resource_add("/sidebox/sbbody-l.gif", embedded_sbbody_l, sizeof(embedded_sbbody_l), "image/gif", NULL); http_resource_add("/sidebox/sbbody-r.gif", embedded_sbbody_r, sizeof(embedded_sbbody_r), "image/gif", NULL); http_resource_add("/sidebox/sbhead-l.gif", embedded_sbhead_l, sizeof(embedded_sbhead_l), "image/gif", NULL); http_resource_add("/sidebox/sbhead-r.gif", embedded_sbhead_r, sizeof(embedded_sbhead_r), "image/gif", NULL); http_resource_add("/gfx/unmapped.png", embedded_unmapped, sizeof(embedded_unmapped), "image/png", NULL); http_resource_add("/gfx/mapped.png", embedded_mapped, sizeof(embedded_mapped), "image/png", NULL); ajax_channels_init(); ajax_config_init(); ajax_config_transport_init(); }