Mercurial > mplayer.hg
annotate libmenu/menu_cmdlist.c @ 18426:2306dcaa256f
grammar fix
author | kraymer |
---|---|
date | Wed, 10 May 2006 18:31:53 +0000 |
parents | ce1a5b200c39 |
children | a2b064a48775 |
rev | line source |
---|---|
8197 | 1 |
16862 | 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 | 5 |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
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 | 10 |
11 #include "img_format.h" | |
12 #include "mp_image.h" | |
13 | |
16862 | 14 #include "m_option.h" |
15 #include "m_struct.h" | |
16 #include "asxparser.h" | |
8197 | 17 #include "menu.h" |
18 #include "menu_list.h" | |
19 | |
16862 | 20 #include "libvo/font_load.h" |
8197 | 21 |
16862 | 22 #include "input/input.h" |
23 #include "version.h" | |
8197 | 24 |
25 | |
26 | |
27 struct list_entry_s { | |
28 struct list_entry p; | |
29 | |
30 char* ok; | |
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 | 34 }; |
35 | |
36 struct menu_priv_s { | |
37 menu_list_priv_t p; | |
38 }; | |
39 | |
40 static struct menu_priv_s cfg_dflt = { | |
41 MENU_LIST_PRIV_DFLT | |
42 }; | |
43 | |
44 static m_option_t cfg_fields[] = { | |
45 MENU_LIST_PRIV_FIELDS, | |
46 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
47 { NULL, NULL, NULL, 0,0,0,NULL } | |
48 }; | |
49 | |
50 #define mpriv (menu->priv) | |
51 | |
52 static void read_cmd(menu_t* menu,int cmd) { | |
53 switch(cmd) { | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
54 case MENU_CMD_RIGHT: |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
55 if(mpriv->p.current->right) { |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
56 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
|
57 if(c) mp_input_queue_cmd(c); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
58 break; |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
59 } // fallback on ok if right is not defined |
8197 | 60 case MENU_CMD_OK: { |
61 if(mpriv->p.current->ok) { | |
62 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok); | |
63 if(c) | |
64 mp_input_queue_cmd(c); | |
65 } | |
66 } break; | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
67 case MENU_CMD_LEFT: |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
68 if(mpriv->p.current->left) { |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
69 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
|
70 if(c) mp_input_queue_cmd(c); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
71 break; |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
72 } // fallback on cancel if left is not defined |
8197 | 73 case MENU_CMD_CANCEL: |
74 if(mpriv->p.current->cancel) { | |
75 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel); | |
76 if(c) | |
77 mp_input_queue_cmd(c); | |
78 break; | |
79 } | |
80 default: | |
81 menu_list_read_cmd(menu,cmd); | |
82 } | |
83 } | |
84 | |
85 static void read_key(menu_t* menu,int c){ | |
86 menu_list_read_key(menu,c,0); | |
87 } | |
88 | |
89 static void free_entry(list_entry_t* entry) { | |
90 if(entry->ok) | |
91 free(entry->ok); | |
92 if(entry->cancel) | |
93 free(entry->cancel); | |
94 free(entry->p.txt); | |
95 free(entry); | |
96 } | |
97 | |
98 static void close(menu_t* menu) { | |
99 menu_list_uninit(menu,free_entry); | |
100 } | |
101 | |
102 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
|
103 char *element,*body, **attribs, *name; |
8197 | 104 list_entry_t* m = NULL; |
105 int r; | |
106 ASX_Parser_t* parser = asx_parser_new(); | |
107 | |
108 while(1) { | |
109 r = asx_get_element(parser,&args,&element,&body,&attribs); | |
110 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
|
111 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line); |
8197 | 112 asx_parser_free(parser); |
113 return -1; | |
114 } else if(r == 0) { | |
115 asx_parser_free(parser); | |
116 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
|
117 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition); |
8197 | 118 return m ? 1 : 0; |
119 } | |
120 // Has it a name ? | |
121 name = asx_get_attrib("name",attribs); | |
122 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
|
123 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line); |
8197 | 124 free(element); |
125 if(body) free(body); | |
126 asx_free_attribs(attribs); | |
127 continue; | |
128 } | |
129 m = calloc(1,sizeof(struct list_entry_s)); | |
130 m->p.txt = name; | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
131 m->ok = asx_get_attrib("ok",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
132 m->cancel = asx_get_attrib("cancel",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
133 m->left = asx_get_attrib("left",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
134 m->right = asx_get_attrib("right",attribs); |
8197 | 135 menu_list_add_entry(menu,m); |
136 | |
137 free(element); | |
138 if(body) free(body); | |
139 asx_free_attribs(attribs); | |
140 } | |
141 } | |
142 | |
143 static int open(menu_t* menu, char* args) { | |
144 menu->draw = menu_list_draw; | |
145 menu->read_cmd = read_cmd; | |
146 menu->read_key = read_key; | |
147 menu->close = close; | |
148 | |
149 if(!args) { | |
18006
ce1a5b200c39
Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents:
17994
diff
changeset
|
150 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument); |
8197 | 151 return 0; |
152 } | |
153 | |
154 menu_list_init(menu); | |
155 if(!parse_args(menu,args)) | |
156 return 0; | |
157 return 1; | |
158 } | |
159 | |
160 const menu_info_t menu_info_cmdlist = { | |
161 "Command list menu", | |
162 "cmdlist", | |
163 "Albeu", | |
164 "", | |
165 { | |
166 "cmdlist_cfg", | |
167 sizeof(struct menu_priv_s), | |
168 &cfg_dflt, | |
169 cfg_fields | |
170 }, | |
171 open | |
172 }; |