Mercurial > mplayer.hg
annotate libmenu/menu_cmdlist.c @ 25299:0335de28ee01
Use recorded last path only when stat it ok.
author | ulion |
---|---|
date | Sun, 09 Dec 2007 07:50:37 +0000 |
parents | 96d0992c7920 |
children | 4fbf536cc033 |
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 |
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 | 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; | |
18819
cd0491dc2afa
support for auto_close parameter in menu command list (geexbox patch)
ben
parents:
18817
diff
changeset
|
38 int auto_close; |
8197 | 39 }; |
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 | 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 | 46 }; |
47 | |
48 static m_option_t cfg_fields[] = { | |
49 MENU_LIST_PRIV_FIELDS, | |
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 | 52 { NULL, NULL, NULL, 0,0,0,NULL } |
53 }; | |
54 | |
55 #define mpriv (menu->priv) | |
56 | |
57 static void read_cmd(menu_t* menu,int cmd) { | |
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 | 65 case MENU_CMD_OK: { |
66 if(mpriv->p.current->ok) { | |
67 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok); | |
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 | 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 | 74 } |
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 | 82 case MENU_CMD_CANCEL: |
83 if(mpriv->p.current->cancel) { | |
84 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel); | |
85 if(c) | |
86 mp_input_queue_cmd(c); | |
87 break; | |
88 } | |
89 default: | |
90 menu_list_read_cmd(menu,cmd); | |
91 } | |
92 } | |
93 | |
94 static void free_entry(list_entry_t* entry) { | |
95 if(entry->ok) | |
96 free(entry->ok); | |
97 if(entry->cancel) | |
98 free(entry->cancel); | |
99 free(entry->p.txt); | |
100 free(entry); | |
101 } | |
102 | |
18817
a2b064a48775
declaring static functions with the same name than libc ones was not the best idea ever
ben
parents:
18006
diff
changeset
|
103 static void close_menu(menu_t* menu) { |
8197 | 104 menu_list_uninit(menu,free_entry); |
105 } | |
106 | |
107 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
|
108 char *element,*body, **attribs, *name; |
8197 | 109 list_entry_t* m = NULL; |
110 int r; | |
111 ASX_Parser_t* parser = asx_parser_new(); | |
112 | |
113 while(1) { | |
114 r = asx_get_element(parser,&args,&element,&body,&attribs); | |
115 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
|
116 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line); |
8197 | 117 asx_parser_free(parser); |
118 return -1; | |
119 } else if(r == 0) { | |
120 asx_parser_free(parser); | |
121 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
|
122 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition); |
8197 | 123 return m ? 1 : 0; |
124 } | |
125 // Has it a name ? | |
126 name = asx_get_attrib("name",attribs); | |
127 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
|
128 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line); |
8197 | 129 free(element); |
130 if(body) free(body); | |
131 asx_free_attribs(attribs); | |
132 continue; | |
133 } | |
134 m = calloc(1,sizeof(struct list_entry_s)); | |
135 m->p.txt = name; | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
136 m->ok = asx_get_attrib("ok",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
137 m->cancel = asx_get_attrib("cancel",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
138 m->left = asx_get_attrib("left",attribs); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
139 m->right = asx_get_attrib("right",attribs); |
8197 | 140 menu_list_add_entry(menu,m); |
141 | |
142 free(element); | |
143 if(body) free(body); | |
144 asx_free_attribs(attribs); | |
145 } | |
146 } | |
147 | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
148 static int open_cmdlist(menu_t* menu, char* args) { |
8197 | 149 menu->draw = menu_list_draw; |
150 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
|
151 menu->close = close_menu; |
8197 | 152 |
153 if(!args) { | |
18006
ce1a5b200c39
Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents:
17994
diff
changeset
|
154 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument); |
8197 | 155 return 0; |
156 } | |
157 | |
158 menu_list_init(menu); | |
159 if(!parse_args(menu,args)) | |
160 return 0; | |
161 return 1; | |
162 } | |
163 | |
164 const menu_info_t menu_info_cmdlist = { | |
165 "Command list menu", | |
166 "cmdlist", | |
167 "Albeu", | |
168 "", | |
169 { | |
170 "cmdlist_cfg", | |
171 sizeof(struct menu_priv_s), | |
172 &cfg_dflt, | |
173 cfg_fields | |
174 }, | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
175 open_cmdlist |
8197 | 176 }; |