2008-12-13 18:40:19 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2003-08-16 09:51:05 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "config.h"
|
2003-08-16 09:51:05 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "m_struct.h"
|
|
|
|
#include "m_option.h"
|
2003-08-16 09:51:05 +00:00
|
|
|
|
2006-08-18 13:58:03 +00:00
|
|
|
#include "libmpcodecs/img_format.h"
|
|
|
|
#include "libmpcodecs/mp_image.h"
|
2003-08-16 09:51:05 +00:00
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_list.h"
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "input/input.h"
|
|
|
|
#include "osdep/keycodes.h"
|
2003-08-16 09:51:05 +00:00
|
|
|
|
2006-07-31 17:39:17 +00:00
|
|
|
#include "stream/dvbin.h"
|
2003-08-16 09:51:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct list_entry_s {
|
|
|
|
struct list_entry p;
|
|
|
|
int num; //the position of the chosen channel in the list
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_priv_s {
|
|
|
|
menu_list_priv_t p;
|
|
|
|
char* title;
|
|
|
|
char* file;
|
|
|
|
int card;
|
2004-04-26 21:20:37 +00:00
|
|
|
int level;
|
2006-02-24 23:01:40 +00:00
|
|
|
int auto_close;
|
2004-04-26 21:20:37 +00:00
|
|
|
dvb_config_t *config;
|
2003-08-16 09:51:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
|
|
|
|
#define mpriv (menu->priv)
|
|
|
|
|
|
|
|
static m_option_t cfg_fields[] = {
|
|
|
|
MENU_LIST_PRIV_FIELDS,
|
|
|
|
{ "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
2006-02-24 23:01:40 +00:00
|
|
|
{ "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
|
2004-04-26 21:20:37 +00:00
|
|
|
{ NULL, NULL, NULL, 0,0,0,NULL },
|
2003-08-16 09:51:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct menu_priv_s cfg_dflt = {
|
|
|
|
MENU_LIST_PRIV_DFLT,
|
2004-04-26 21:20:37 +00:00
|
|
|
"Select a channel: ",
|
2003-08-16 09:51:05 +00:00
|
|
|
"channels.conf",
|
2004-04-26 21:20:37 +00:00
|
|
|
0,
|
|
|
|
0,
|
2006-02-24 23:01:40 +00:00
|
|
|
1,
|
2003-08-16 09:51:05 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void free_entry(list_entry_t* entry)
|
|
|
|
{
|
|
|
|
free(entry->p.txt);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
static int fill_channels_menu(menu_t *menu, dvb_channels_list *dvb_list_ptr)
|
2003-08-16 09:51:05 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
dvb_channel_t *channel;
|
2004-04-26 21:20:37 +00:00
|
|
|
list_entry_t* elem;
|
2003-08-16 09:51:05 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
mpriv->level = 2;
|
2003-08-16 09:51:05 +00:00
|
|
|
if(dvb_list_ptr == NULL)
|
2007-12-12 23:01:49 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
|
2003-08-16 09:51:05 +00:00
|
|
|
n = 1;
|
2004-04-26 21:20:37 +00:00
|
|
|
if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
|
2003-08-16 09:51:05 +00:00
|
|
|
{
|
|
|
|
elem->p.next = NULL;
|
2004-04-26 21:20:37 +00:00
|
|
|
elem->p.txt = strdup("There are no channels for this DVB card!");
|
2003-08-16 09:51:05 +00:00
|
|
|
|
|
|
|
menu_list_add_entry(menu, elem);
|
|
|
|
}
|
2004-04-26 21:20:37 +00:00
|
|
|
return 1;
|
2007-12-12 23:01:49 +00:00
|
|
|
}
|
|
|
|
for(n = 0; n < dvb_list_ptr->NUM_CHANNELS; n++)
|
|
|
|
{
|
|
|
|
channel = &(dvb_list_ptr->channels[n]);
|
2004-04-26 21:20:37 +00:00
|
|
|
if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
|
|
|
|
{
|
|
|
|
elem->p.next = NULL;
|
|
|
|
elem->p.txt = strdup(channel->name);
|
|
|
|
elem->num = n;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
menu_list_add_entry(menu, elem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-13 02:58:57 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
|
2004-04-26 21:20:37 +00:00
|
|
|
sizeof(list_entry_t), strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int fill_cards_menu(menu_t *menu, dvb_config_t *conf)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
list_entry_t* elem;
|
|
|
|
|
|
|
|
for(n = 0; n < conf->count; n++)
|
|
|
|
{
|
|
|
|
if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
|
2007-12-12 23:01:49 +00:00
|
|
|
{
|
|
|
|
elem->p.next = NULL;
|
2004-04-26 21:20:37 +00:00
|
|
|
elem->p.txt = strdup(conf->cards[n].name);
|
2007-12-12 23:01:49 +00:00
|
|
|
elem->num = n;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2007-12-12 23:01:49 +00:00
|
|
|
if(n == 0)
|
|
|
|
elem->p.prev = NULL;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2007-12-12 23:01:49 +00:00
|
|
|
menu_list_add_entry(menu, elem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-13 02:58:57 +00:00
|
|
|
fprintf(stderr, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
|
2007-12-12 23:01:49 +00:00
|
|
|
sizeof(list_entry_t), strerror(errno));
|
|
|
|
if(n)
|
2003-08-16 09:51:05 +00:00
|
|
|
return 1;
|
2007-12-12 23:01:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int fill_menu(menu_t* menu)
|
|
|
|
{
|
|
|
|
list_entry_t* elem;
|
|
|
|
dvb_channels_list *dvb_list_ptr;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
menu_list_init(menu);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
if(mpriv->config == NULL)
|
|
|
|
{
|
|
|
|
if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
|
|
|
|
{
|
|
|
|
elem->p.prev = elem->p.next = NULL;
|
|
|
|
elem->p.txt = strdup("NO DVB configuration present!");
|
|
|
|
|
|
|
|
menu_list_add_entry(menu, elem);
|
2007-12-12 23:01:49 +00:00
|
|
|
return 1;
|
2004-04-26 21:20:37 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
mpriv->p.title = mpriv->title;
|
|
|
|
if(mpriv->level == 1 && mpriv->config->count > 1)
|
|
|
|
return fill_cards_menu(menu, mpriv->config);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dvb_list_ptr = mpriv->config->cards[mpriv->card].list;
|
|
|
|
return fill_channels_menu(menu, dvb_list_ptr);
|
|
|
|
}
|
2003-08-16 09:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void read_cmd(menu_t* menu, int cmd)
|
|
|
|
{
|
2004-04-26 21:20:37 +00:00
|
|
|
list_entry_t *elem;
|
2003-08-16 09:51:05 +00:00
|
|
|
mp_cmd_t* c;
|
|
|
|
char *cmd_name;
|
|
|
|
switch(cmd)
|
|
|
|
{
|
2006-03-25 17:32:10 +00:00
|
|
|
case MENU_CMD_RIGHT:
|
2003-08-16 09:51:05 +00:00
|
|
|
case MENU_CMD_OK:
|
|
|
|
{
|
2004-04-26 21:20:37 +00:00
|
|
|
elem = mpriv->p.current;
|
|
|
|
|
|
|
|
if(mpriv->level == 1)
|
|
|
|
{
|
|
|
|
mpriv->card = mpriv->p.current->num;
|
|
|
|
mpriv->level = 2;
|
|
|
|
menu_list_uninit(menu, free_entry);
|
2009-05-13 02:58:57 +00:00
|
|
|
fill_menu(menu);
|
2004-04-26 21:20:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dvb_priv_t *dvbp = (dvb_priv_t*) mpriv->config->priv;
|
|
|
|
cmd_name = malloc(25 + strlen(elem->p.txt));
|
|
|
|
if(dvbp != NULL)
|
2009-05-13 02:58:57 +00:00
|
|
|
sprintf(cmd_name, "dvb_set_channel %d %d", elem->num, mpriv->card);
|
2004-04-26 21:20:37 +00:00
|
|
|
else
|
|
|
|
sprintf(cmd_name, "loadfile 'dvb://%d@%s'", mpriv->card+1, elem->p.txt);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2007-12-12 23:01:49 +00:00
|
|
|
c = mp_input_parse_cmd(cmd_name);
|
|
|
|
free(cmd_name);
|
|
|
|
if(c)
|
|
|
|
{
|
|
|
|
if(mpriv->auto_close)
|
|
|
|
mp_input_queue_cmd (mp_input_parse_cmd ("menu hide"));
|
|
|
|
mp_input_queue_cmd(c);
|
|
|
|
}
|
|
|
|
}
|
2004-04-26 21:20:37 +00:00
|
|
|
}
|
2003-08-16 09:51:05 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-25 17:32:10 +00:00
|
|
|
case MENU_CMD_LEFT:
|
2004-04-26 21:20:37 +00:00
|
|
|
case MENU_CMD_CANCEL:
|
|
|
|
{
|
|
|
|
elem = mpriv->p.current;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
menu_list_uninit(menu, free_entry);
|
|
|
|
if(mpriv->config->count > 1)
|
|
|
|
mpriv->level--;
|
|
|
|
else
|
|
|
|
mpriv->level = 0;
|
|
|
|
|
|
|
|
if(mpriv->level > 0)
|
|
|
|
{
|
|
|
|
fill_menu(menu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-16 09:51:05 +00:00
|
|
|
default:
|
|
|
|
menu_list_read_cmd(menu, cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void close_menu(menu_t* menu)
|
|
|
|
{
|
2007-12-15 13:30:44 +00:00
|
|
|
dvb_free_config(mpriv->config);
|
2003-08-16 09:51:05 +00:00
|
|
|
menu_list_uninit(menu, free_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int open_dvb_sel(menu_t* menu, char* args)
|
|
|
|
{
|
2004-04-26 21:20:37 +00:00
|
|
|
mpriv->config = dvb_get_config();
|
|
|
|
if(mpriv->config == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2003-08-16 09:51:05 +00:00
|
|
|
menu->draw = menu_list_draw;
|
|
|
|
menu->read_cmd = read_cmd;
|
|
|
|
menu->close = close_menu;
|
|
|
|
|
2004-04-26 21:20:37 +00:00
|
|
|
mpriv->card = 0;
|
|
|
|
mpriv->level = 1;
|
2003-08-16 09:51:05 +00:00
|
|
|
return fill_menu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu_info_t menu_info_dvbsel =
|
|
|
|
{
|
|
|
|
"DVB channels menu", //descr
|
|
|
|
"dvbsel", //name
|
|
|
|
"Nico", //author
|
|
|
|
"dvb_sel",
|
|
|
|
{ //m_struct_t priv_st=
|
|
|
|
"dvb_cfg", //name
|
2004-04-26 21:20:37 +00:00
|
|
|
sizeof(struct menu_priv_s), //size
|
2003-08-16 09:51:05 +00:00
|
|
|
&cfg_dflt, //defaults
|
|
|
|
cfg_fields //settable fields
|
|
|
|
},
|
|
|
|
open_dvb_sel //open function
|
|
|
|
};
|