annotate libmenu/menu_cmdlist.c @ 24533:43ff93c329d7

r24550: msglevel 5 is the default. r24551: Clarify description of MPLAYER_VERBOSE.
author voroshil
date Mon, 17 Sep 2007 10:22:53 +0000
parents b344b6520518
children 96d0992c7920
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
2 #include "config.h"
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
3 #include "mp_msg.h"
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
4 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include <ctype.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8197
diff changeset
9 #include <string.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
10
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18819
diff changeset
11 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18819
diff changeset
12 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
13
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
14 #include "m_option.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
15 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
16 #include "asxparser.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
20 #include "libvo/font_load.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
22 #include "input/input.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
23 #include "version.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30 char* ok;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31 char* cancel;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
32 char* left;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
33 char* right;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 menu_list_priv_t p;
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
38 int auto_close;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
41 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
42
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 static struct menu_priv_s cfg_dflt = {
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
44 MENU_LIST_PRIV_DFLT,
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
45 0,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
51 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 switch(cmd) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
59 case MENU_CMD_RIGHT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
60 if(mpriv->p.current->right) {
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
61 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->right);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
62 if(c) mp_input_queue_cmd(c);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
63 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
64 } // fallback on ok if right is not defined
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 if(mpriv->p.current->ok) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 if(c)
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
69 {
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
70 if (mpriv->auto_close)
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
71 mp_input_queue_cmd (mp_input_parse_cmd ("menu hide"));
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 mp_input_queue_cmd(c);
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
73 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 } break;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
76 case MENU_CMD_LEFT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
77 if(mpriv->p.current->left) {
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
78 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->left);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
79 if(c) mp_input_queue_cmd(c);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
80 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
81 } // fallback on cancel if left is not defined
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 if(mpriv->p.current->cancel) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 if(c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 static void read_key(menu_t* menu,int c){
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 menu_list_read_key(menu,c,0);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 if(entry->ok)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 free(entry->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 if(entry->cancel)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 free(entry->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106
18817
a2b064a48775 declaring static functions with the same name than libc ones was not the best idea ever
ben
parents: 18006
diff changeset
107 static void close_menu(menu_t* menu) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 static int parse_args(menu_t* menu,char* args) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
112 char *element,*body, **attribs, *name;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 list_entry_t* m = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 ASX_Parser_t* parser = asx_parser_new();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 r = asx_get_element(parser,&args,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 if(r < 0) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
120 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 return -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 } else if(r == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 if(!m)
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
126 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 return m ? 1 : 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129 // Has it a name ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 name = asx_get_attrib("name",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131 if(!name) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
132 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
134 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 m = calloc(1,sizeof(struct list_entry_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 m->p.txt = name;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
140 m->ok = asx_get_attrib("ok",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
141 m->cancel = asx_get_attrib("cancel",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
142 m->left = asx_get_attrib("left",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
143 m->right = asx_get_attrib("right",attribs);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 menu_list_add_entry(menu,m);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
152 static int open_cmdlist(menu_t* menu, char* args) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 menu->read_key = read_key;
18817
a2b064a48775 declaring static functions with the same name than libc ones was not the best idea ever
ben
parents: 18006
diff changeset
156 menu->close = close_menu;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158 if(!args) {
18006
ce1a5b200c39 Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents: 17994
diff changeset
159 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164 if(!parse_args(menu,args))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169 const menu_info_t menu_info_cmdlist = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 "Command list menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 "cmdlist",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 "cmdlist_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179 },
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
180 open_cmdlist
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 };