Mercurial > mplayer.hg
comparison libmenu/menu_cmdlist.c @ 8197:b31caec933e9
OSD menus initial version
author | albeu |
---|---|
date | Thu, 14 Nov 2002 23:47:11 +0000 |
parents | |
children | 440301fef3fe |
comparison
equal
deleted
inserted
replaced
8196:419bdbfdb660 | 8197:b31caec933e9 |
---|---|
1 | |
2 #include "../config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <ctype.h> | |
7 | |
8 #include "img_format.h" | |
9 #include "mp_image.h" | |
10 | |
11 #include "../m_option.h" | |
12 #include "../m_struct.h" | |
13 #include "../asxparser.h" | |
14 #include "menu.h" | |
15 #include "menu_list.h" | |
16 | |
17 #include "../libvo/font_load.h" | |
18 | |
19 #include "../input/input.h" | |
20 #include "../version.h" | |
21 | |
22 | |
23 | |
24 struct list_entry_s { | |
25 struct list_entry p; | |
26 | |
27 char* ok; | |
28 char* cancel; | |
29 }; | |
30 | |
31 struct menu_priv_s { | |
32 menu_list_priv_t p; | |
33 }; | |
34 | |
35 static struct menu_priv_s cfg_dflt = { | |
36 MENU_LIST_PRIV_DFLT | |
37 }; | |
38 | |
39 static m_option_t cfg_fields[] = { | |
40 MENU_LIST_PRIV_FIELDS, | |
41 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
42 { NULL, NULL, NULL, 0,0,0,NULL } | |
43 }; | |
44 | |
45 #define mpriv (menu->priv) | |
46 | |
47 static void read_cmd(menu_t* menu,int cmd) { | |
48 switch(cmd) { | |
49 case MENU_CMD_OK: { | |
50 if(mpriv->p.current->ok) { | |
51 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok); | |
52 if(c) | |
53 mp_input_queue_cmd(c); | |
54 } | |
55 } break; | |
56 case MENU_CMD_CANCEL: | |
57 if(mpriv->p.current->cancel) { | |
58 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel); | |
59 if(c) | |
60 mp_input_queue_cmd(c); | |
61 break; | |
62 } | |
63 default: | |
64 menu_list_read_cmd(menu,cmd); | |
65 } | |
66 } | |
67 | |
68 static void read_key(menu_t* menu,int c){ | |
69 menu_list_read_key(menu,c,0); | |
70 } | |
71 | |
72 static void free_entry(list_entry_t* entry) { | |
73 if(entry->ok) | |
74 free(entry->ok); | |
75 if(entry->cancel) | |
76 free(entry->cancel); | |
77 free(entry->p.txt); | |
78 free(entry); | |
79 } | |
80 | |
81 static void close(menu_t* menu) { | |
82 menu_list_uninit(menu,free_entry); | |
83 } | |
84 | |
85 static int parse_args(menu_t* menu,char* args) { | |
86 char *element,*body, **attribs, *name, *ok, *cancel; | |
87 list_entry_t* m = NULL; | |
88 int r; | |
89 ASX_Parser_t* parser = asx_parser_new(); | |
90 | |
91 while(1) { | |
92 r = asx_get_element(parser,&args,&element,&body,&attribs); | |
93 if(r < 0) { | |
94 printf("Syntax error at line %d\n",parser->line); | |
95 asx_parser_free(parser); | |
96 return -1; | |
97 } else if(r == 0) { | |
98 asx_parser_free(parser); | |
99 if(!m) | |
100 printf("No entry found in the menu definition\n"); | |
101 return m ? 1 : 0; | |
102 } | |
103 // Has it a name ? | |
104 name = asx_get_attrib("name",attribs); | |
105 if(!name) { | |
106 printf("List menu entry definitions need a name (line %d)\n",parser->line); | |
107 free(element); | |
108 if(body) free(body); | |
109 asx_free_attribs(attribs); | |
110 continue; | |
111 } | |
112 ok = asx_get_attrib("ok",attribs); | |
113 cancel = asx_get_attrib("cancel",attribs); | |
114 m = calloc(1,sizeof(struct list_entry_s)); | |
115 m->p.txt = name; | |
116 m->ok = ok; | |
117 m->cancel = cancel; | |
118 menu_list_add_entry(menu,m); | |
119 | |
120 free(element); | |
121 if(body) free(body); | |
122 asx_free_attribs(attribs); | |
123 } | |
124 } | |
125 | |
126 static int open(menu_t* menu, char* args) { | |
127 menu->draw = menu_list_draw; | |
128 menu->read_cmd = read_cmd; | |
129 menu->read_key = read_key; | |
130 menu->close = close; | |
131 | |
132 if(!args) { | |
133 printf("List menu need an argument\n"); | |
134 return 0; | |
135 } | |
136 | |
137 menu_list_init(menu); | |
138 if(!parse_args(menu,args)) | |
139 return 0; | |
140 return 1; | |
141 } | |
142 | |
143 const menu_info_t menu_info_cmdlist = { | |
144 "Command list menu", | |
145 "cmdlist", | |
146 "Albeu", | |
147 "", | |
148 { | |
149 "cmdlist_cfg", | |
150 sizeof(struct menu_priv_s), | |
151 &cfg_dflt, | |
152 cfg_fields | |
153 }, | |
154 open | |
155 }; |