comparison libmenu/menu_dvbin.c @ 10626:fd97f3727f15

Finnaly commit Nico's dvb menu. Sorry for committing this months later :(
author albeu
date Sat, 16 Aug 2003 09:51:05 +0000
parents
children d8b1f7509df2
comparison
equal deleted inserted replaced
10625:620cc649f519 10626:fd97f3727f15
1
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dirent.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <ctype.h>
10 #include <unistd.h>
11 #include <limits.h>
12
13
14 #include "../config.h"
15
16 #include "../m_struct.h"
17 #include "../m_option.h"
18
19 #include "img_format.h"
20 #include "mp_image.h"
21
22 #include "menu.h"
23 #include "menu_list.h"
24 #include "../input/input.h"
25 #include "../osdep/keycodes.h"
26
27 #include "../libmpdemux/dvbin.h"
28
29
30
31 struct list_entry_s {
32 struct list_entry p;
33 int num; //the position of the chosen channel in the list
34 };
35
36 struct menu_priv_s {
37 menu_list_priv_t p;
38 char* title;
39 char* file;
40 int card;
41 };
42
43
44 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
45 #define mpriv (menu->priv)
46
47 static m_option_t cfg_fields[] = {
48 MENU_LIST_PRIV_FIELDS,
49 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
50 { "file", ST_OFF(file), CONF_TYPE_STRING, 0, 0, 0, NULL },
51 { "card", ST_OFF(card), CONF_TYPE_INT, 0, 0, 0, NULL },
52 { NULL, NULL, NULL, 0,0,0,NULL }
53 };
54
55
56 static struct menu_priv_s cfg_dflt = {
57 MENU_LIST_PRIV_DFLT,
58 "Select a channel: %p",
59 "channels.conf",
60 1,
61 NULL,
62 };
63
64
65
66
67 static void free_entry(list_entry_t* entry)
68 {
69 free(entry->p.txt);
70 free(entry);
71 }
72
73
74 static int fill_menu(menu_t* menu)
75 {
76 int n;
77 list_entry_t* elem;
78 char *name;
79 extern dvb_channels_list *dvb_list_ptr;
80 dvb_channel_t *channel;
81
82 menu_list_init(menu);
83
84 mpriv->p.title = mpriv->title;
85
86 if(dvb_list_ptr == NULL)
87 {
88 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
89 n = 1;
90 if((elem = malloc(sizeof(list_entry_t))) != NULL)
91 {
92 name = malloc(80);
93 sprintf(name, "Empty channel list from file %s; \nrun mplayer dvb:// to load the list", mpriv->file);
94 elem->p.next = NULL;
95 elem->p.txt = name;
96
97 menu_list_add_entry(menu, elem);
98 }
99 }
100 else
101 {
102 n = dvb_list_ptr->NUM_CHANNELS;
103 for(n = 0; n < dvb_list_ptr->NUM_CHANNELS; n++)
104 {
105 channel = &(dvb_list_ptr->channels[n]);
106 if((elem = malloc(sizeof(list_entry_t))) != NULL)
107 {
108 name = malloc(80);
109 strncpy(name, channel->name, 79);
110 name[79] = 0;
111 elem->p.next = NULL;
112 elem->p.txt = name;
113 elem->num = n;
114
115
116 menu_list_add_entry(menu, elem);
117 }
118 else
119 {
120 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n",
121 sizeof(list_entry_t), strerror(errno));
122
123 if(n)
124 return 1;
125
126 return 0;
127 }
128 }
129 }
130
131 return 1;
132 }
133
134
135 static void read_cmd(menu_t* menu, int cmd)
136 {
137 list_entry_t *p;
138 mp_cmd_t* c;
139 char *cmd_name;
140 switch(cmd)
141 {
142 case MENU_CMD_OK:
143 {
144 p = mpriv->p.current;
145 mp_msg(MSGT_DEMUX, MSGL_V, "CHOSEN DVB CHANNEL %d\n\n", p->num);
146
147 cmd_name = malloc(30);
148 sprintf(cmd_name, "dvb_set_channel %d", p->num);
149 c = mp_input_parse_cmd(cmd_name);
150 if(c)
151 mp_input_queue_cmd(c);
152 }
153 break;
154
155 default:
156 menu_list_read_cmd(menu, cmd);
157 }
158 }
159
160
161 static void close_menu(menu_t* menu)
162 {
163 menu_list_uninit(menu, free_entry);
164 //free(mpriv->dir);
165 }
166
167
168 static int open_dvb_sel(menu_t* menu, char* args)
169 {
170 menu->draw = menu_list_draw;
171 menu->read_cmd = read_cmd;
172 //menu->read_key = read_key;
173 menu->close = close_menu;
174
175 return fill_menu(menu);
176 }
177
178 const menu_info_t menu_info_dvbsel =
179 {
180 "DVB channels menu", //descr
181 "dvbsel", //name
182 "Nico", //author
183 "dvb_sel",
184 { //m_struct_t priv_st=
185 "dvb_cfg", //name
186 sizeof(dvb_channels_list), //size
187 &cfg_dflt, //defaults
188 cfg_fields //settable fields
189 },
190 open_dvb_sel //open function
191 };