annotate libmenu/menu_pt.c @ 36237:dc06b09d02a4

vo_aa: Specifying a single option should only change the value of that option. Previous code mean that specifying anything at all would disable all aalib options.
author reimar
date Tue, 11 Jun 2013 19:23:12 +0000
parents 18338ee51c9d
children b28f3ff37ae7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28113
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
1 /*
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
2 * This file is part of MPlayer.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
3 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
5 * it under the terms of the GNU General Public License as published by
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
7 * (at your option) any later version.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
8 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
12 * GNU General Public License for more details.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
13 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
14 * You should have received a copy of the GNU General Public License along
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 27072
diff changeset
17 */
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20 #include <stdio.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8197
diff changeset
21 #include <string.h>
9102
048d0a158714 don't depend on libgen/basename()
arpi
parents: 8623
diff changeset
22 //#include <libgen.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9102
diff changeset
24 #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
25 #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
26 #include "help_mp.h"
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30957
diff changeset
27 #include "path.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18817
diff changeset
29 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18817
diff changeset
30 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9102
diff changeset
32 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9102
diff changeset
33 #include "m_option.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
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9102
diff changeset
38 #include "playtree.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9102
diff changeset
39 #include "input/input.h"
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 19431
diff changeset
40 #include "access_mpcontext.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 play_tree_t* pt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 };
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
46
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 char* title;
27072
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
51 int auto_close;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 MENU_LIST_PRIV_DFLT,
27072
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
56 "Jump to",
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
57 0
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61
30957
45b93bea8082 Mark cfg_fields m_option_t array as const.
diego
parents: 29263
diff changeset
62 static const m_option_t cfg_fields[] = {
8197
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", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
27072
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
65 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 switch(cmd) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
73 case MENU_CMD_RIGHT:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 int d = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 char str[15];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 play_tree_t* i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 mp_cmd_t* c;
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 19431
diff changeset
79 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 if(playtree_iter->tree == mpriv->p.current->pt)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 snprintf(str,15,"pt_up_step 1");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 if(i == mpriv->p.current->pt)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 d++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 if(i == NULL) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 d = -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 if(i == mpriv->p.current->pt)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 d--;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 if(i == NULL) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
100 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantfindTheTargetItem);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 snprintf(str,15,"pt_step %d",d);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 c = mp_input_parse_cmd(str);
27072
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
107 if(c) {
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
108 if(mpriv->auto_close)
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
109 mp_input_queue_cmd(mp_input_parse_cmd("menu hide"));
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 mp_input_queue_cmd(c);
27072
15b870cf3592 Add auto-close option to libmenu playlist handling part.
ben
parents: 25502
diff changeset
111 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 else
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
113 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToBuildCommand,str);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 } break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119
25502
605d4e3e403f From now on, libmenu does not steal all input keys from input modules.
ulion
parents: 25263
diff changeset
120 static int read_key(menu_t* menu,int c){
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 22284
diff changeset
121 if (menu_dflt_read_key(menu, c))
25502
605d4e3e403f From now on, libmenu does not steal all input keys from input modules.
ulion
parents: 25263
diff changeset
122 return 1;
605d4e3e403f From now on, libmenu does not steal all input keys from input modules.
ulion
parents: 25263
diff changeset
123 return menu_list_jump_to_key(menu, c);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125
18817
a2b064a48775 declaring static functions with the same name than libc ones was not the best idea ever
ben
parents: 17994
diff changeset
126 static void close_menu(menu_t* menu) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 menu_list_uninit(menu,NULL);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 static int op(menu_t* menu, char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131 play_tree_t* i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 list_entry_t* e;
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 19431
diff changeset
133 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
134
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 args = NULL; // Warning kill
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 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: 17994
diff changeset
140 menu->close = close_menu;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 mpriv->p.title = mpriv->title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 if(playtree_iter->tree->parent != playtree_iter->root) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 e = calloc(1,sizeof(list_entry_t));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 e->p.txt = "..";
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 e->pt = playtree_iter->tree->parent;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 menu_list_add_entry(menu,e);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
152
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 /* NOP */;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 for( ; i != NULL ; i = i->next ) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 e = calloc(1,sizeof(list_entry_t));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157 if(i->files)
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30957
diff changeset
158 e->p.txt = (char *)mp_basename(i->files[0]);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 e->p.txt = "Group ...";
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 e->pt = i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 menu_list_add_entry(menu,e);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 const menu_info_t menu_info_pt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169 "Playtree menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 "pt",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 "pt_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179 op
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
180 };