summaryrefslogtreecommitdiffstats
path: root/libmenu/menu_dvbin.c
blob: 1e48508db30dc6565cb28e05f3bc10b229df7f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

#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>


#include "../config.h"

#include "../m_struct.h"
#include "../m_option.h"

#include "img_format.h"
#include "mp_image.h"

#include "menu.h"
#include "menu_list.h"
#include "../input/input.h"
#include "../osdep/keycodes.h"

#include "../libmpdemux/dvbin.h"



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;
};


#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 },
  { "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 }
};


static struct menu_priv_s cfg_dflt = {
  MENU_LIST_PRIV_DFLT,
  "Select a channel: %p",
  "channels.conf",
  1,
  NULL,
};




static void free_entry(list_entry_t* entry)
{
  free(entry->p.txt);
  free(entry);
}


static int fill_menu(menu_t* menu)
{
	int n;
	list_entry_t* elem;
	char *name;
	extern dvb_channels_list  *dvb_list_ptr;
	dvb_channel_t *channel;

	menu_list_init(menu);
	
	mpriv->p.title = mpriv->title;
	
	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)
		{
			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;

			menu_list_add_entry(menu, elem);
		}
    }
	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)
			{
		  		name = malloc(80);
				strncpy(name, channel->name, 79);
				name[79] = 0;
				elem->p.next 	= NULL;
				elem->p.txt 	= name;
				elem->num 	= n;
				
				if(n == 0)
				    elem->p.prev = NULL;
				
				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));
			
			  if(n)
				return 1;
			
			  return 0;
			}
		}  
	}
	
	return 1;
}


static void read_cmd(menu_t* menu, int cmd)
{
  list_entry_t *p;
  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);
		
		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;

  	default:
    	menu_list_read_cmd(menu, cmd);
  }
}


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)
{
	menu->draw 		= menu_list_draw;
	menu->read_cmd 	= read_cmd;
	//menu->read_key 	= read_key;
	menu->close 	= close_menu;

	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
    sizeof(dvb_channels_list),	//size
    &cfg_dflt,					//defaults
    cfg_fields					//settable fields
  },
  open_dvb_sel					//open function
};