2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
36 #include "libmpcodecs/img_format.h"
37 #include "libmpcodecs/mp_image.h"
40 #include "menu_list.h"
41 #include "input/input.h"
42 #include "osdep/keycodes.h"
44 #include "stream/dvbin.h"
50 int num
; //the position of the chosen channel in the list
64 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
65 #define mpriv (menu->priv)
67 static const m_option_t cfg_fields
[] = {
68 MENU_LIST_PRIV_FIELDS
,
69 { "title", ST_OFF(title
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
70 { "auto-close", ST_OFF(auto_close
), CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
71 { NULL
, NULL
, NULL
, 0,0,0,NULL
},
75 static struct menu_priv_s cfg_dflt
= {
88 static void free_entry(list_entry_t
* entry
)
95 static int fill_channels_menu(menu_t
*menu
, dvb_channels_list
*dvb_list_ptr
)
98 dvb_channel_t
*channel
;
102 if(dvb_list_ptr
== NULL
)
104 mp_msg(MSGT_DEMUX
, MSGL_ERR
, "dvb_set_channel: LIST NULL PTR, quit\n");
106 if((elem
= calloc(1, sizeof(list_entry_t
))) != NULL
)
109 elem
->p
.txt
= strdup("There are no channels for this DVB card!");
111 menu_list_add_entry(menu
, elem
);
115 for(n
= 0; n
< dvb_list_ptr
->NUM_CHANNELS
; n
++)
117 channel
= &(dvb_list_ptr
->channels
[n
]);
118 if((elem
= calloc(1, sizeof(list_entry_t
))) != NULL
)
121 elem
->p
.txt
= strdup(channel
->name
);
124 menu_list_add_entry(menu
, elem
);
128 mp_msg(MSGT_DEMUX
, MSGL_ERR
, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
129 sizeof(list_entry_t
), strerror(errno
));
138 static int fill_cards_menu(menu_t
*menu
, dvb_config_t
*conf
)
143 for(n
= 0; n
< conf
->count
; n
++)
145 if((elem
= calloc(1, sizeof(list_entry_t
))) != NULL
)
148 elem
->p
.txt
= strdup(conf
->cards
[n
].name
);
154 menu_list_add_entry(menu
, elem
);
158 fprintf(stderr
, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
159 sizeof(list_entry_t
), strerror(errno
));
171 static int fill_menu(menu_t
* menu
)
174 dvb_channels_list
*dvb_list_ptr
;
176 menu_list_init(menu
);
178 if(mpriv
->config
== NULL
)
180 if((elem
= calloc(1, sizeof(list_entry_t
))) != NULL
)
182 elem
->p
.prev
= elem
->p
.next
= NULL
;
183 elem
->p
.txt
= strdup("NO DVB configuration present!");
185 menu_list_add_entry(menu
, elem
);
191 mpriv
->p
.title
= mpriv
->title
;
192 if(mpriv
->level
== 1 && mpriv
->config
->count
> 1)
193 return fill_cards_menu(menu
, mpriv
->config
);
196 dvb_list_ptr
= mpriv
->config
->cards
[mpriv
->card
].list
;
197 return fill_channels_menu(menu
, dvb_list_ptr
);
202 static void read_cmd(menu_t
* menu
, int cmd
)
212 elem
= mpriv
->p
.current
;
214 if(mpriv
->level
== 1)
216 mpriv
->card
= mpriv
->p
.current
->num
;
218 menu_list_uninit(menu
, free_entry
);
223 dvb_priv_t
*dvbp
= (dvb_priv_t
*) mpriv
->config
->priv
;
224 cmd_name
= malloc(25 + strlen(elem
->p
.txt
));
226 sprintf(cmd_name
, "dvb_set_channel %d %d", elem
->num
, mpriv
->card
);
228 sprintf(cmd_name
, "loadfile 'dvb://%d@%s'", mpriv
->card
+1, elem
->p
.txt
);
230 c
= mp_input_parse_cmd(cmd_name
);
234 if(mpriv
->auto_close
)
235 mp_input_queue_cmd(menu
->input_ctx
, mp_input_parse_cmd ("menu hide"));
236 mp_input_queue_cmd(menu
->input_ctx
, c
);
243 case MENU_CMD_CANCEL
:
245 elem
= mpriv
->p
.current
;
247 menu_list_uninit(menu
, free_entry
);
248 if(mpriv
->config
->count
> 1)
261 menu_list_read_cmd(menu
, cmd
);
266 static void close_menu(menu_t
* menu
)
268 dvb_free_config(mpriv
->config
);
269 menu_list_uninit(menu
, free_entry
);
273 static int open_dvb_sel(menu_t
* menu
, char* args
)
275 mpriv
->config
= dvb_get_config();
276 if(mpriv
->config
== NULL
)
279 menu
->draw
= menu_list_draw
;
280 menu
->read_cmd
= read_cmd
;
281 menu
->close
= close_menu
;
285 return fill_menu(menu
);
288 const menu_info_t menu_info_dvbsel
=
290 "DVB channels menu", //descr
294 { //m_struct_t priv_st=
296 sizeof(struct menu_priv_s
), //size
297 &cfg_dflt
, //defaults
298 cfg_fields
//settable fields
300 open_dvb_sel
//open function