[Mplayer-cvslog] CVS: main/libmenu menu_dvbin.c,1.2,1.3
Nico Sabbi CVS
syncmail at mplayerhq.hu
Mon Apr 26 23:20:39 CEST 2004
CVS change done by Nico Sabbi CVS
Update of /cvsroot/mplayer/main/libmenu
In directory mail:/var2/tmp/cvs-serv16754
Modified Files:
menu_dvbin.c
Log Message:
new configuration structure, multi-card support
Index: menu_dvbin.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmenu/menu_dvbin.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- menu_dvbin.c 1 Nov 2003 15:16:51 -0000 1.2
+++ menu_dvbin.c 26 Apr 2004 21:20:37 -0000 1.3
@@ -38,6 +38,8 @@
char* title;
char* file;
int card;
+ int level;
+ dvb_config_t *config;
};
@@ -47,17 +49,16 @@
static m_option_t cfg_fields[] = {
MENU_LIST_PRIV_FIELDS,
{ "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
- { "file", ST_OFF(file), CONF_TYPE_STRING, 0, 0, 0, NULL },
- { "card", ST_OFF(card), CONF_TYPE_INT, 0, 0, 0, NULL },
- { NULL, NULL, NULL, 0,0,0,NULL }
+ { NULL, NULL, NULL, 0,0,0,NULL },
};
static struct menu_priv_s cfg_dflt = {
MENU_LIST_PRIV_DFLT,
- "Select a channel: %p",
+ "Select a channel: ",
"channels.conf",
- 1,
+ 0,
+ 0,
NULL,
};
@@ -71,45 +72,61 @@
}
-static int fill_menu(menu_t* menu)
+static int fill_channels_menu(menu_t *menu, dvb_channels_list *dvb_list_ptr)
{
int n;
- list_entry_t* elem;
- char *name;
- extern dvb_channels_list *dvb_list_ptr;
dvb_channel_t *channel;
+ list_entry_t* elem;
- menu_list_init(menu);
-
- mpriv->p.title = mpriv->title;
-
+ mpriv->level = 2;
if(dvb_list_ptr == NULL)
{
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
n = 1;
- if((elem = malloc(sizeof(list_entry_t))) != NULL)
+ if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
{
- name = malloc(80);
- sprintf(name, "Empty channel list from file %s; \nrun mplayer dvb:// to load the list", mpriv->file);
elem->p.next = NULL;
- elem->p.txt = name;
+ elem->p.txt = strdup("There are no channels for this DVB card!");
menu_list_add_entry(menu, elem);
}
+ return 1;
}
- else
- {
- n = dvb_list_ptr->NUM_CHANNELS;
for(n = 0; n < dvb_list_ptr->NUM_CHANNELS; n++)
{
channel = &(dvb_list_ptr->channels[n]);
- if((elem = malloc(sizeof(list_entry_t))) != NULL)
+ if((elem = calloc(1, sizeof(list_entry_t))) != NULL)
+ {
+ elem->p.next = NULL;
+ elem->p.txt = strdup(channel->name);
+ elem->num = n;
+
+ menu_list_add_entry(menu, elem);
+ }
+ else
+ {
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
+ sizeof(list_entry_t), strerror(errno));
+
+ break;
+ }
+ }
+
+ 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)
{
- name = malloc(80);
- strncpy(name, channel->name, 79);
- name[79] = 0;
elem->p.next = NULL;
- elem->p.txt = name;
+ elem->p.txt = strdup(conf->cards[n].name);
elem->num = n;
if(n == 0)
@@ -119,7 +136,7 @@
}
else
{
- mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
+ fprintf(stderr, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
sizeof(list_entry_t), strerror(errno));
if(n)
@@ -128,32 +145,93 @@
return 0;
}
}
- }
+ return n;
+}
+
+
+static int fill_menu(menu_t* menu)
+{
+ list_entry_t* elem;
+ dvb_channels_list *dvb_list_ptr;
+
+ menu_list_init(menu);
+
+ 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);
return 1;
+ }
+ return 0;
+ }
+
+ 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);
+ }
}
static void read_cmd(menu_t* menu, int cmd)
{
- list_entry_t *p;
+ list_entry_t *elem;
mp_cmd_t* c;
char *cmd_name;
switch(cmd)
{
case MENU_CMD_OK:
{
- p = mpriv->p.current;
- mp_msg(MSGT_DEMUX, MSGL_V, "CHOSEN DVB CHANNEL %d\n\n", p->num);
+ elem = mpriv->p.current;
+
+ if(mpriv->level == 1)
+ {
+ mpriv->card = mpriv->p.current->num;
+ mpriv->level = 2;
+ menu_list_uninit(menu, free_entry);
+ fill_menu(menu);
+ }
+ else
+ {
+ dvb_priv_t *dvbp = (dvb_priv_t*) mpriv->config->priv;
+ cmd_name = malloc(25 + strlen(elem->p.txt));
+ if(dvbp != NULL)
+ sprintf(cmd_name, "dvb_set_channel %d %d", elem->num, mpriv->card);
+ else
+ sprintf(cmd_name, "loadfile 'dvb://%d@%s'", mpriv->card+1, elem->p.txt);
- cmd_name = malloc(30);
- sprintf(cmd_name, "dvb_set_channel %d", p->num);
c = mp_input_parse_cmd(cmd_name);
if(c)
mp_input_queue_cmd(c);
}
+ }
break;
+ case MENU_CMD_CANCEL:
+ {
+ elem = mpriv->p.current;
+
+ 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;
+ }
+ }
+
default:
menu_list_read_cmd(menu, cmd);
}
@@ -163,17 +241,21 @@
static void close_menu(menu_t* menu)
{
menu_list_uninit(menu, free_entry);
- //free(mpriv->dir);
}
static int open_dvb_sel(menu_t* menu, char* args)
{
+ mpriv->config = dvb_get_config();
+ if(mpriv->config == NULL)
+ return 0;
+
menu->draw = menu_list_draw;
menu->read_cmd = read_cmd;
- //menu->read_key = read_key;
menu->close = close_menu;
+ mpriv->card = 0;
+ mpriv->level = 1;
return fill_menu(menu);
}
@@ -185,7 +267,7 @@
"dvb_sel",
{ //m_struct_t priv_st=
"dvb_cfg", //name
- sizeof(dvb_channels_list), //size
+ sizeof(struct menu_priv_s), //size
&cfg_dflt, //defaults
cfg_fields //settable fields
},
More information about the MPlayer-cvslog
mailing list