annotate libmenu/menu_cmdlist.c @ 29271:82b6fbc72099

When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
author adrian
date Mon, 18 May 2009 21:00:35 +0000
parents 0f1b5b68af32
children 45b93bea8082
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28113
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
1 /*
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
2 * This file is part of MPlayer.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
3 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
5 * it under the terms of the GNU General Public License as published by
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
7 * (at your option) any later version.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
8 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
12 * GNU General Public License for more details.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
13 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
14 * You should have received a copy of the GNU General Public License along
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 26570
diff changeset
17 */
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
19 #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
20 #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
21 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 #include <ctype.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8197
diff changeset
26 #include <string.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18819
diff changeset
28 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18819
diff changeset
29 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
31 #include "m_option.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
32 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
33 #include "asxparser.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
37 #include "libvo/font_load.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
39 #include "input/input.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 char* ok;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 char* cancel;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
48 char* left;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
49 char* right;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55
18819
cd0491dc2afa support for auto_close parameter in menu command list (geexbox patch)
ben
parents: 18817
diff changeset
56 #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
57
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 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
59 MENU_LIST_PRIV_DFLT,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 switch(cmd) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
72 case MENU_CMD_RIGHT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
73 if(mpriv->p.current->right) {
25320
4fbf536cc033 Support to run multiple mplayer commands set in menu.conf
ulion
parents: 25263
diff changeset
74 mp_input_parse_and_queue_cmds(mpriv->p.current->right);
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
75 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
76 } // fallback on ok if right is not defined
25498
4852e5553d4e Remove useless scope.
ulion
parents: 25401
diff changeset
77 case MENU_CMD_OK:
25505
8d329f7bbc3c Remove redundant option 'auto-close' from cmdlist and filesel.
ulion
parents: 25498
diff changeset
78 if (mpriv->p.current->ok)
8d329f7bbc3c Remove redundant option 'auto-close' from cmdlist and filesel.
ulion
parents: 25498
diff changeset
79 mp_input_parse_and_queue_cmds(mpriv->p.current->ok);
25498
4852e5553d4e Remove useless scope.
ulion
parents: 25401
diff changeset
80 break;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
81 case MENU_CMD_LEFT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
82 if(mpriv->p.current->left) {
25320
4fbf536cc033 Support to run multiple mplayer commands set in menu.conf
ulion
parents: 25263
diff changeset
83 mp_input_parse_and_queue_cmds(mpriv->p.current->left);
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
84 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
85 } // fallback on cancel if left is not defined
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 if(mpriv->p.current->cancel) {
25320
4fbf536cc033 Support to run multiple mplayer commands set in menu.conf
ulion
parents: 25263
diff changeset
88 mp_input_parse_and_queue_cmds(mpriv->p.current->cancel);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 if(entry->ok)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 free(entry->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 if(entry->cancel)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 free(entry->cancel);
25401
f3acd58a3eff Fix memory leak.
ulion
parents: 25320
diff changeset
101 if(entry->left)
f3acd58a3eff Fix memory leak.
ulion
parents: 25320
diff changeset
102 free(entry->left);
f3acd58a3eff Fix memory leak.
ulion
parents: 25320
diff changeset
103 if(entry->right)
f3acd58a3eff Fix memory leak.
ulion
parents: 25320
diff changeset
104 free(entry->right);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108
18817
a2b064a48775 declaring static functions with the same name than libc ones was not the best idea ever
ben
parents: 18006
diff changeset
109 static void close_menu(menu_t* menu) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 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
114 char *element,*body, **attribs, *name;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 list_entry_t* m = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 ASX_Parser_t* parser = asx_parser_new();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 r = asx_get_element(parser,&args,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 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
122 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
125 } else if(r == 0) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 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
128 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129 return m ? 1 : 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131 // Has it a name ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 name = asx_get_attrib("name",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 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
134 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140 m = calloc(1,sizeof(struct list_entry_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141 m->p.txt = name;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
142 m->ok = asx_get_attrib("ok",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
143 m->cancel = asx_get_attrib("cancel",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
144 m->left = asx_get_attrib("left",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
145 m->right = asx_get_attrib("right",attribs);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 menu_list_add_entry(menu,m);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
154 static int open_cmdlist(menu_t* menu, char* args) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 menu->read_cmd = read_cmd;
18817
a2b064a48775 declaring static functions with the same name than libc ones was not the best idea ever
ben
parents: 18006
diff changeset
157 menu->close = close_menu;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 if(!args) {
18006
ce1a5b200c39 Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents: 17994
diff changeset
160 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
163
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 if(!parse_args(menu,args))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 const menu_info_t menu_info_cmdlist = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 "Command list menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 "cmdlist",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 "cmdlist_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
180 },
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
181 open_cmdlist
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 };