annotate libmenu/menu_param.c @ 35904:cef5275fc11f

Avoid usage of obsolete and BSD-specific "struct timezone".
author diego
date Sun, 17 Mar 2013 22:47:31 +0000
parents 389d43c448b3
children 7bfdbba6f2f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28113
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
1 /*
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
2 * This file is part of MPlayer.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
3 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
5 * it under the terms of the GNU General Public License as published by
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
7 * (at your option) any later version.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
8 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
12 * GNU General Public License for more details.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
13 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
14 * You should have received a copy of the GNU General Public License along
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25381
diff changeset
17 */
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
18
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
19 #include "config.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23 #include <dirent.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 #include <errno.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 #include <string.h>
35903
389d43c448b3 Add missing strings.h #includes for strcasecmp().
diego
parents: 32537
diff changeset
26 #include <strings.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 #include <sys/types.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 #include <sys/stat.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 #include <ctype.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
31 #include "mp_msg.h"
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
32 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
33
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10864
diff changeset
34 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10864
diff changeset
35 #include "m_option.h"
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
36 #include "m_property.h"
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10864
diff changeset
37 #include "asxparser.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 19059
diff changeset
39 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 #include "menu_list.h"
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10864
diff changeset
43 #include "input/input.h"
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
44 #include "command.h"
19529
9a59c33bee29 new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents: 19431
diff changeset
45
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 struct list_entry p;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
48 char* name;
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
49 char* txt;
23393
a5e55cb59bbc Rework the property API to allow sub properties such as
albeu
parents: 22284
diff changeset
50 char* prop;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 m_option_t* opt;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
52 char* menu;
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
53 int auto_update;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 menu_list_priv_t p;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
58 char* ptr;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
59 int edit;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 /// Cfg fields
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
61 char* na;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
62 int hide_na;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 };
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
64
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 MENU_LIST_PRIV_DFLT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 NULL,
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
68 0,
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
69 "N/A",
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
70 1
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72
30957
45b93bea8082 Mark cfg_fields m_option_t array as const.
diego
parents: 29263
diff changeset
73 static const m_option_t cfg_fields[] = {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 { "title", M_ST_OFF(menu_list_priv_t,title), CONF_TYPE_STRING, 0, 0, 0, NULL },
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
76 { "na", M_ST_OFF(struct menu_priv_s,na), CONF_TYPE_STRING, 0, 0, 0, NULL },
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
77 { "hide-na", M_ST_OFF(struct menu_priv_s,hide_na), CONF_TYPE_FLAG, CONF_RANGE, 0, 1, NULL },
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
83 static void entry_set_text(menu_t* menu, list_entry_t* e) {
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
84 char* val = e->txt ? property_expand_string(menu->ctx, e->txt) :
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
85 mp_property_print(e->prop, menu->ctx);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
86 int l,edit = (mpriv->edit && e == mpriv->p.current);
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
87 if(!val || !val[0]) {
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
88 free(val);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
89 if(mpriv->hide_na) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
90 e->p.hide = 1;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
91 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
92 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
93 val = strdup(mpriv->na);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
94 } else if(mpriv->hide_na)
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
95 e->p.hide = 0;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
96 l = strlen(e->name) + 2 + strlen(val) + (edit ? 4 : 0) + 1;
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
97 free(e->p.txt);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
98 e->p.txt = malloc(l);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
99 sprintf(e->p.txt,"%s: %s%s%s",e->name,edit ? "> " : "",val,edit ? " <" : "");
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
100 free(val);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
101 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
102
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
103 static void update_entries(menu_t* menu, int auto_update) {
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
104 list_entry_t* e;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
105 for(e = mpriv->p.menu ; e ; e = e->p.next)
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
106 if ((e->txt || e->prop) && (!auto_update || e->auto_update))
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
107 entry_set_text(menu, e);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
108 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 static int parse_args(menu_t* menu,char* args) {
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
111 char *element,*body, **attribs, *name, *txt, *auto_update;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 list_entry_t* m = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 m_option_t* opt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 ASX_Parser_t* parser = asx_parser_new();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
116
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 r = asx_get_element(parser,&args,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 if(r < 0) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17949
diff changeset
121 mp_msg(MSGT_OSD_MENU,MSGL_ERR,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
124 } else if(r == 0) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 if(!m)
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17949
diff changeset
127 mp_msg(MSGT_OSD_MENU,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
128 m = calloc(1,sizeof(struct list_entry_s));
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
129 m->p.txt = strdup("Back");
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
130 menu_list_add_entry(menu,m);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
131 return 1;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 }
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
133 if(!strcmp(element,"menu")) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
134 name = asx_get_attrib("menu",attribs);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
135 if(!name) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17949
diff changeset
136 mp_msg(MSGT_OSD_MENU,MSGL_WARN,MSGTR_LIBMENU_SubmenuDefinitionNeedAMenuAttribut);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
137 goto next_element;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
138 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
139 m = calloc(1,sizeof(struct list_entry_s));
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
140 m->menu = name;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
141 name = NULL; // we want to keep it
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
142 m->p.txt = asx_get_attrib("name",attribs);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
143 if(!m->p.txt) m->p.txt = strdup(m->menu);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
144 menu_list_add_entry(menu,m);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
145 goto next_element;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
146 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
147
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
148 name = asx_get_attrib("property",attribs);
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
149 opt = NULL;
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
150 if(name && mp_property_do(name,M_PROPERTY_GET_TYPE,&opt,menu->ctx) <= 0) {
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
151 mp_msg(MSGT_OSD_MENU,MSGL_WARN,MSGTR_LIBMENU_InvalidProperty,
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
152 name,parser->line);
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
153 goto next_element;
19529
9a59c33bee29 new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents: 19431
diff changeset
154 }
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
155 txt = asx_get_attrib("txt",attribs);
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
156 if(!(name || txt)) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17949
diff changeset
157 mp_msg(MSGT_OSD_MENU,MSGL_WARN,MSGTR_LIBMENU_PrefMenuEntryDefinitionsNeed,parser->line);
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
158 free(txt);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
159 txt = NULL;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
160 goto next_element;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 m = calloc(1,sizeof(struct list_entry_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 m->opt = opt;
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
164 m->txt = txt; txt = NULL;
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
165 m->prop = name; name = NULL;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
166 m->name = asx_get_attrib("name",attribs);
23398
69bf352bcef8 Drop the metadata stuff and replace it with generic property string expansion.
albeu
parents: 23393
diff changeset
167 if(!m->name) m->name = strdup(opt ? opt->name : "-");
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
168 auto_update = asx_get_attrib("auto-update", attribs);
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
169 if (auto_update) {
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
170 if (!strcmp(auto_update, "1") ||
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
171 !strcasecmp(auto_update, "on") ||
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
172 !strcasecmp(auto_update, "yes") ||
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
173 !strcasecmp(auto_update, "true"))
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
174 m->auto_update = 1;
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
175 free(auto_update);
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
176 }
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
177 entry_set_text(menu,m);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 menu_list_add_entry(menu,m);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
180 next_element:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 free(element);
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
182 free(body);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
183 free(name);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
188 static void read_cmd(menu_t* menu,int cmd) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
189 list_entry_t* e = mpriv->p.current;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
190
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
191 if(e->opt) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
192 switch(cmd) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
193 case MENU_CMD_UP:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
194 if(!mpriv->edit) break;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
195 case MENU_CMD_RIGHT:
23393
a5e55cb59bbc Rework the property API to allow sub properties such as
albeu
parents: 22284
diff changeset
196 if(mp_property_do(e->prop,M_PROPERTY_STEP_UP,NULL,menu->ctx) > 0)
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
197 update_entries(menu, 0);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
198 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
199 case MENU_CMD_DOWN:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
200 if(!mpriv->edit) break;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
201 case MENU_CMD_LEFT:
23393
a5e55cb59bbc Rework the property API to allow sub properties such as
albeu
parents: 22284
diff changeset
202 if(mp_property_do(e->prop,M_PROPERTY_STEP_DOWN,NULL,menu->ctx) > 0)
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
203 update_entries(menu, 0);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
204 return;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
205
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
206 case MENU_CMD_OK:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
207 // check that the property is writable
23393
a5e55cb59bbc Rework the property API to allow sub properties such as
albeu
parents: 22284
diff changeset
208 if(mp_property_do(e->prop,M_PROPERTY_SET,NULL,menu->ctx) < 0) return;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
209 // shortcut for flags
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
210 if(e->opt->type == CONF_TYPE_FLAG) {
23393
a5e55cb59bbc Rework the property API to allow sub properties such as
albeu
parents: 22284
diff changeset
211 if(mp_property_do(e->prop,M_PROPERTY_STEP_UP,NULL,menu->ctx) > 0)
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
212 update_entries(menu, 0);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
213 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
214 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
215 // switch
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
216 mpriv->edit = !mpriv->edit;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
217 // update the menu
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
218 update_entries(menu, 0);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
219 // switch the pointer
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
220 if(mpriv->edit) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
221 mpriv->ptr = mpriv->p.ptr;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
222 mpriv->p.ptr = NULL;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
223 } else
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
224 mpriv->p.ptr = mpriv->ptr;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
225 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
226 case MENU_CMD_CANCEL:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
227 if(!mpriv->edit) break;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
228 mpriv->edit = 0;
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
229 update_entries(menu, 0);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
230 mpriv->p.ptr = mpriv->ptr;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
231 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
232 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
233 } else if(e->menu) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
234 switch(cmd) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
235 case MENU_CMD_RIGHT:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
236 case MENU_CMD_OK: {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
237 mp_cmd_t* c;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
238 char* txt = malloc(10 + strlen(e->menu) + 1);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
239 sprintf(txt,"set_menu %s",e->menu);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
240 c = mp_input_parse_cmd(txt);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
241 if(c) mp_input_queue_cmd(c);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
242 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
243 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
244 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
245 } else {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
246 switch(cmd) {
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
247 case MENU_CMD_RIGHT:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
248 case MENU_CMD_OK:
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
249 menu->show = 0;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
250 menu->cl = 1;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
251 return;
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
252 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
253 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
254 menu_list_read_cmd(menu,cmd);
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
255 }
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
256
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
257 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
258 free(entry->p.txt);
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
259 free(entry->name);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
260 free(entry->txt);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
261 free(entry->prop);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30957
diff changeset
262 free(entry->menu);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
263 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
264 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
265
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 9380
diff changeset
266 static void closeMenu(menu_t* menu) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
267 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
268 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
269
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
270 static void menu_pref_draw(menu_t* menu, mp_image_t* mpi) {
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
271 update_entries(menu, 1);
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
272 menu_list_draw(menu, mpi);
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
273 }
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
274
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 9380
diff changeset
275 static int openMenu(menu_t* menu, char* args) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
276
25381
beda94ca3895 Add auto-update property for property menu item.
ulion
parents: 25345
diff changeset
277 menu->draw = menu_pref_draw;
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
278 menu->read_cmd = read_cmd;
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 9380
diff changeset
279 menu->close = closeMenu;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
280
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
281
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
282 if(!args) {
18006
ce1a5b200c39 Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents: 17994
diff changeset
283 mp_msg(MSGT_OSD_MENU,MSGL_ERR,MSGTR_LIBMENU_PrefMenuNeedsAnArgument);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
284 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
285 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
286
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
287 menu_list_init(menu);
17949
a6b11b35892a Turn the preferences menu in something usefull using the new
albeu
parents: 16862
diff changeset
288 return parse_args(menu,args);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
289 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
290
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
291 const menu_info_t menu_info_pref = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
292 "Preferences menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
293 "pref",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
294 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
295 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
296 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
297 "pref_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
298 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
299 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
300 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
301 },
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 9380
diff changeset
302 openMenu
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
303 };