2008-04-03 19:15:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* tvheadend, AJAX / HTML user interface
|
|
|
|
|
* Copyright (C) 2008 Andreas <EFBFBD>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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-05-02 05:46:12 +00:00
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
2008-04-03 19:15:00 +00:00
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2008-05-02 05:46:12 +00:00
|
|
|
|
|
2008-04-03 19:15:00 +00:00
|
|
|
|
#include "tvhead.h"
|
|
|
|
|
#include "http.h"
|
|
|
|
|
#include "ajaxui.h"
|
|
|
|
|
#include "channels.h"
|
2008-04-24 05:38:33 +00:00
|
|
|
|
#include "epg.h"
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2008-07-21 08:40:12 +00:00
|
|
|
|
ajax_channelgroupmenu_content(htsbuf_queue_t *tq, int current)
|
2008-04-03 19:15:00 +00:00
|
|
|
|
{
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_group_t *tcg;
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<ul class=\"menubar\">");
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
|
|
|
|
|
if(tcg->tcg_hidden)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(current < 1)
|
|
|
|
|
current = tcg->tcg_tag;
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-03 19:15:00 +00:00
|
|
|
|
"<li%s>"
|
|
|
|
|
"<a href=\"javascript:switchtab('channelgroup', '%d')\">%s</a>"
|
|
|
|
|
"</li>",
|
|
|
|
|
current == tcg->tcg_tag ? " style=\"font-weight:bold;\"" : "",
|
|
|
|
|
tcg->tcg_tag, tcg->tcg_name);
|
|
|
|
|
}
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</ul>");
|
2008-04-03 19:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Channelgroup menu bar
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2008-04-14 18:59:31 +00:00
|
|
|
|
ajax_channelgroup_menu(http_connection_t *hc, http_reply_t *hr,
|
|
|
|
|
const char *remain, void *opaque)
|
2008-04-03 19:15:00 +00:00
|
|
|
|
{
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_queue_t *tq = &hr->hr_q;
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
|
|
|
|
if(remain == NULL)
|
|
|
|
|
return HTTP_STATUS_NOT_FOUND;
|
|
|
|
|
|
2008-04-14 18:59:31 +00:00
|
|
|
|
ajax_channelgroupmenu_content(tq, atoi(remain));
|
|
|
|
|
http_output_html(hc, hr);
|
2008-04-03 19:15:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 05:38:33 +00:00
|
|
|
|
static void
|
2008-07-21 08:40:12 +00:00
|
|
|
|
ajax_output_event(htsbuf_queue_t *tq, event_t *e, int flags, int color)
|
2008-04-24 05:38:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct tm a, b;
|
|
|
|
|
time_t stop;
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div class=\"fullrow\"%s>",
|
2008-04-24 05:38:33 +00:00
|
|
|
|
color ? "style=\"background: #fff\" " : "");
|
|
|
|
|
|
|
|
|
|
localtime_r(&e->e_start, &a);
|
|
|
|
|
stop = e->e_start + e->e_duration;
|
|
|
|
|
localtime_r(&stop, &b);
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-24 05:38:33 +00:00
|
|
|
|
"<div class=\"compact\" style=\"width: 35%%\">"
|
|
|
|
|
"%02d:%02d-%02d:%02d"
|
|
|
|
|
"</div>",
|
|
|
|
|
a.tm_hour, a.tm_min, b.tm_hour, b.tm_min);
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-24 05:38:33 +00:00
|
|
|
|
"<div class=\"compact\" style=\"width: 65%%\">"
|
|
|
|
|
"%s"
|
|
|
|
|
"</div>",
|
|
|
|
|
e->e_title);
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
2008-04-24 05:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-04-24 05:38:33 +00:00
|
|
|
|
static void
|
2008-07-21 08:40:12 +00:00
|
|
|
|
ajax_list_events(htsbuf_queue_t *tq, channel_t *ch, int lines)
|
2008-04-24 05:38:33 +00:00
|
|
|
|
{
|
|
|
|
|
event_t *e;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
e = epg_event_find_current_or_upcoming(ch);
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 3 && e != NULL; i++) {
|
|
|
|
|
ajax_output_event(tq, e, 0, !(i & 1));
|
2008-05-03 06:00:07 +00:00
|
|
|
|
e = TAILQ_NEXT(e, e_channel_link);
|
2008-04-24 05:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Display a list of all channels within the given group
|
|
|
|
|
*
|
|
|
|
|
* Group is given by 'tag' as an ASCII string in remain
|
|
|
|
|
*/
|
2008-05-02 19:37:23 +00:00
|
|
|
|
static int
|
2008-04-14 18:59:31 +00:00
|
|
|
|
ajax_channel_tab(http_connection_t *hc, http_reply_t *hr,
|
|
|
|
|
const char *remain, void *opaque)
|
2008-04-03 19:15:00 +00:00
|
|
|
|
{
|
2008-04-24 05:38:33 +00:00
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_queue_t *tq = &hr->hr_q;
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_t *ch;
|
|
|
|
|
channel_group_t *tcg;
|
2008-04-24 05:38:33 +00:00
|
|
|
|
char dispname[20];
|
2008-05-02 05:46:12 +00:00
|
|
|
|
struct sockaddr_in *si;
|
2008-05-04 15:12:05 +00:00
|
|
|
|
int nchs = 0;
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-04-24 05:38:33 +00:00
|
|
|
|
if(remain == NULL || (tcg = channel_group_by_tag(atoi(remain))) == NULL)
|
2008-04-03 19:15:00 +00:00
|
|
|
|
return HTTP_STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
|
|
|
|
|
if(LIST_FIRST(&ch->ch_transports) == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
2008-05-04 15:12:05 +00:00
|
|
|
|
nchs++;
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div style=\"float:left; width: 25%%\">");
|
2008-04-24 05:38:33 +00:00
|
|
|
|
|
|
|
|
|
snprintf(dispname, sizeof(dispname), "%s", ch->ch_name);
|
|
|
|
|
strcpy(dispname + sizeof(dispname) - 4, "...");
|
|
|
|
|
|
|
|
|
|
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, dispname);
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-05-02 05:46:12 +00:00
|
|
|
|
/* inner */
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-24 05:38:33 +00:00
|
|
|
|
"<div style=\"width: 100%%; overflow: hidden; height:36px\">");
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-24 05:38:33 +00:00
|
|
|
|
"<div style=\"float: left; height:32px; width:32px; "
|
|
|
|
|
"margin: 2px\">");
|
|
|
|
|
|
|
|
|
|
if(ch->ch_icon != NULL) {
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<img src=\"%s\" style=\"width:32px\">",
|
2008-04-24 05:38:33 +00:00
|
|
|
|
ch->ch_icon);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
2008-05-02 05:46:12 +00:00
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div style=\"float:left; text-align: right\">");
|
2008-05-02 05:46:12 +00:00
|
|
|
|
|
|
|
|
|
si = (struct sockaddr_in *)&hc->hc_tcp_session.tcp_self_addr;
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-05-02 05:46:12 +00:00
|
|
|
|
"<a href=\"rtsp://%s:%d/%s\">Stream</a>",
|
|
|
|
|
inet_ntoa(si->sin_addr), ntohs(si->sin_port),
|
|
|
|
|
ch->ch_sname);
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
2008-04-24 05:38:33 +00:00
|
|
|
|
|
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div id=\"events%d\" style=\"height:42px\">", ch->ch_tag);
|
2008-04-24 05:38:33 +00:00
|
|
|
|
ajax_list_events(tq, ch, 3);
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
2008-04-24 05:38:33 +00:00
|
|
|
|
|
|
|
|
|
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "</div>");
|
2008-04-03 19:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-04 15:12:05 +00:00
|
|
|
|
if(nchs == 0)
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div style=\"text-align: center; font-weight: bold\">"
|
2008-05-04 15:12:05 +00:00
|
|
|
|
"No channels in this group</div>");
|
|
|
|
|
|
2008-04-14 18:59:31 +00:00
|
|
|
|
http_output_html(hc, hr);
|
2008-04-03 19:15:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 05:38:33 +00:00
|
|
|
|
|
2008-04-03 19:15:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Channel (group)s AJAX page
|
|
|
|
|
*
|
|
|
|
|
* This is the top level menu for this c-file
|
|
|
|
|
*/
|
|
|
|
|
int
|
2008-04-14 18:59:31 +00:00
|
|
|
|
ajax_channelgroup_tab(http_connection_t *hc, http_reply_t *hr)
|
2008-04-03 19:15:00 +00:00
|
|
|
|
{
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_queue_t *tq = &hr->hr_q;
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-04-14 18:59:31 +00:00
|
|
|
|
ajax_box_begin(tq, AJAX_BOX_FILLED, "channelgroupmenu", NULL, NULL);
|
|
|
|
|
ajax_box_end(tq, AJAX_BOX_FILLED);
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq, "<div id=\"channelgroupdeck\"></div>");
|
2008-04-03 19:15:00 +00:00
|
|
|
|
|
2008-07-21 08:40:12 +00:00
|
|
|
|
htsbuf_qprintf(tq,
|
2008-04-03 19:15:00 +00:00
|
|
|
|
"<script type=\"text/javascript\">"
|
|
|
|
|
"switchtab('channelgroup', '0')"
|
|
|
|
|
"</script>");
|
|
|
|
|
|
2008-04-14 18:59:31 +00:00
|
|
|
|
http_output_html(hc, hr);
|
2008-04-03 19:15:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
ajax_channels_init(void)
|
|
|
|
|
{
|
2008-04-29 06:53:21 +00:00
|
|
|
|
http_path_add("/ajax/channelgroupmenu", NULL, ajax_channelgroup_menu,
|
|
|
|
|
ACCESS_WEB_INTERFACE);
|
|
|
|
|
http_path_add("/ajax/channelgrouptab", NULL, ajax_channel_tab,
|
|
|
|
|
ACCESS_WEB_INTERFACE);
|
|
|
|
|
|
2008-04-03 19:15:00 +00:00
|
|
|
|
}
|