Mercurial > mplayer.hg
annotate libmenu/menu_param.c @ 22865:441582f3ed87
simplified function prototypes to avoid casts but keep external API compatibility
author | ben |
---|---|
date | Sun, 01 Apr 2007 12:39:06 +0000 |
parents | 83366c8e1928 |
children | a5e55cb59bbc |
rev | line source |
---|---|
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
1 |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
2 #include "config.h" |
8197 | 3 |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <dirent.h> | |
7 #include <errno.h> | |
8 #include <string.h> | |
9 #include <sys/types.h> | |
10 #include <sys/stat.h> | |
11 #include <ctype.h> | |
12 | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
13 #include "mp_msg.h" |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
14 #include "help_mp.h" |
8197 | 15 |
16862 | 16 #include "m_struct.h" |
17 #include "m_option.h" | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
18 #include "m_property.h" |
16862 | 19 #include "asxparser.h" |
8197 | 20 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
19059
diff
changeset
|
21 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
19059
diff
changeset
|
22 #include "libmpcodecs/mp_image.h" |
8197 | 23 |
24 #include "menu.h" | |
25 #include "menu_list.h" | |
16862 | 26 #include "input/input.h" |
27 #include "osdep/keycodes.h" | |
19532
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
28 #include "metadata.h" |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
29 |
8197 | 30 struct list_entry_s { |
31 struct list_entry p; | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
32 char* name; |
8197 | 33 m_option_t* opt; |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
34 char* menu; |
8197 | 35 }; |
36 | |
37 struct menu_priv_s { | |
38 menu_list_priv_t p; | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
39 char* ptr; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
40 int edit; |
8197 | 41 /// Cfg fields |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
42 char* na; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
43 int hide_na; |
8197 | 44 }; |
19532
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
45 |
8197 | 46 static struct menu_priv_s cfg_dflt = { |
47 MENU_LIST_PRIV_DFLT, | |
48 NULL, | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
49 0, |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
50 "N/A", |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
51 1 |
8197 | 52 }; |
53 | |
54 static m_option_t cfg_fields[] = { | |
55 MENU_LIST_PRIV_FIELDS, | |
56 { "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
|
57 { "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
|
58 { "hide-na", M_ST_OFF(struct menu_priv_s,hide_na), CONF_TYPE_FLAG, CONF_RANGE, 0, 1, NULL }, |
8197 | 59 { NULL, NULL, NULL, 0,0,0,NULL } |
60 }; | |
61 | |
62 #define mpriv (menu->priv) | |
63 | |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
64 #define OPT_NAME "name" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
65 #define OPT_VCODEC "vcodec" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
66 #define OPT_VBITRATE "vbitrate" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
67 #define OPT_RESOLUTION "resolution" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
68 #define OPT_ACODEC "acodec" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
69 #define OPT_ABITRATE "abitrate" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
70 #define OPT_SAMPLES "asamples" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
71 #define OPT_INFO_TITLE "title" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
72 #define OPT_INFO_ARTIST "artist" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
73 #define OPT_INFO_ALBUM "album" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
74 #define OPT_INFO_YEAR "year" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
75 #define OPT_INFO_COMMENT "comment" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
76 #define OPT_INFO_TRACK "track" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
77 #define OPT_INFO_GENRE "genre" |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
78 |
19059
231c0e700597
Compilation fix: Mark mp_property_find parameter as const.
diego
parents:
18006
diff
changeset
|
79 m_option_t* mp_property_find(const char* name); |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
80 |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
81 static void entry_set_text(menu_t* menu, list_entry_t* e) { |
22284 | 82 char* val = m_property_print(e->opt, menu->ctx); |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
83 int l,edit = (mpriv->edit && e == mpriv->p.current); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
84 if(!val) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
85 if(mpriv->hide_na) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
86 e->p.hide = 1; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
87 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
88 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
89 val = strdup(mpriv->na); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
90 } else if(mpriv->hide_na) |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
91 e->p.hide = 0; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
92 l = strlen(e->name) + 2 + strlen(val) + (edit ? 4 : 0) + 1; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
93 if(e->p.txt) free(e->p.txt); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
94 e->p.txt = malloc(l); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
95 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
|
96 free(val); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
97 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
98 |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
99 static void update_entries(menu_t* menu) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
100 list_entry_t* e; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
101 for(e = mpriv->p.menu ; e ; e = e->p.next) |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
102 if(e->opt) entry_set_text(menu,e); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
103 } |
8197 | 104 |
105 static int parse_args(menu_t* menu,char* args) { | |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
106 char *element,*body, **attribs, *name, *meta, *val; |
8197 | 107 list_entry_t* m = NULL; |
108 int r; | |
109 m_option_t* opt; | |
110 ASX_Parser_t* parser = asx_parser_new(); | |
111 | |
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:
17949
diff
changeset
|
116 mp_msg(MSGT_OSD_MENU,MSGL_ERR,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:
17949
diff
changeset
|
122 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
|
123 m = calloc(1,sizeof(struct list_entry_s)); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
124 m->p.txt = strdup("Back"); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
125 menu_list_add_entry(menu,m); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
126 return 1; |
8197 | 127 } |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
128 if(!strcmp(element,"menu")) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
129 name = asx_get_attrib("menu",attribs); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
130 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
|
131 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
|
132 goto next_element; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
133 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
134 m = calloc(1,sizeof(struct list_entry_s)); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
135 m->menu = name; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
136 name = NULL; // we want to keep it |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
137 m->p.txt = asx_get_attrib("name",attribs); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
138 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
|
139 menu_list_add_entry(menu,m); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
140 goto next_element; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
141 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
142 |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
143 meta = asx_get_attrib("meta",attribs); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
144 val = NULL; |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
145 if(meta) { |
19532
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
146 if (!strcmp (meta, OPT_NAME)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
147 val = get_metadata (META_NAME); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
148 else if (!strcmp (meta, OPT_VCODEC)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
149 val = get_metadata (META_VIDEO_CODEC); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
150 else if (!strcmp(meta, OPT_VBITRATE)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
151 val = get_metadata (META_VIDEO_BITRATE); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
152 else if(!strcmp(meta, OPT_RESOLUTION)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
153 val = get_metadata (META_VIDEO_RESOLUTION); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
154 else if (!strcmp(meta, OPT_ACODEC)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
155 val = get_metadata (META_AUDIO_CODEC); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
156 else if(!strcmp(meta, OPT_ABITRATE)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
157 val = get_metadata (META_AUDIO_BITRATE); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
158 else if(!strcmp(meta, OPT_SAMPLES)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
159 val = get_metadata (META_AUDIO_SAMPLES); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
160 else if (!strcmp (meta, OPT_INFO_TITLE)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
161 val = get_metadata (META_INFO_TITLE); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
162 else if (!strcmp (meta, OPT_INFO_ARTIST)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
163 val = get_metadata (META_INFO_ARTIST); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
164 else if (!strcmp (meta, OPT_INFO_ALBUM)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
165 val = get_metadata (META_INFO_ALBUM); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
166 else if (!strcmp (meta, OPT_INFO_YEAR)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
167 val = get_metadata (META_INFO_YEAR); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
168 else if (!strcmp (meta, OPT_INFO_COMMENT)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
169 val = get_metadata (META_INFO_COMMENT); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
170 else if (!strcmp (meta, OPT_INFO_TRACK)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
171 val = get_metadata (META_INFO_TRACK); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
172 else if (!strcmp (meta, OPT_INFO_GENRE)) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
173 val = get_metadata (META_INFO_GENRE); |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
174 if (val) { |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
175 char *item = asx_get_attrib("name",attribs); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
176 int l; |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
177 |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
178 if (!item) |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
179 item = strdup (meta); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
180 l = strlen(item) + 2 + strlen(val) + 1; |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
181 m = calloc(1,sizeof(struct list_entry_s)); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
182 m->p.txt = malloc(l); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
183 sprintf(m->p.txt,"%s: %s",item,val); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
184 free(val); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
185 free(item); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
186 menu_list_add_entry(menu,m); |
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
187 } |
19532
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
188 free (meta); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
189 if (element) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
190 free(element); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
191 if(body) |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
192 free(body); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
193 asx_free_attribs(attribs); |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
194 continue; |
13599373bb02
added new helpers to allow easy metadata retrieval and make libmenu use them
ben
parents:
19529
diff
changeset
|
195 } |
19529
9a59c33bee29
new option for libmenu that allow display of properties and metadata of currently played stream
ben
parents:
19431
diff
changeset
|
196 |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
197 name = asx_get_attrib("property",attribs); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
198 opt = name ? mp_property_find(name) : NULL; |
8197 | 199 if(!opt) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17949
diff
changeset
|
200 mp_msg(MSGT_OSD_MENU,MSGL_WARN,MSGTR_LIBMENU_PrefMenuEntryDefinitionsNeed,parser->line); |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
201 goto next_element; |
8197 | 202 } |
203 m = calloc(1,sizeof(struct list_entry_s)); | |
204 m->opt = opt; | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
205 m->name = asx_get_attrib("name",attribs); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
206 if(!m->name) m->name = strdup(opt->name); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
207 entry_set_text(menu,m); |
8197 | 208 menu_list_add_entry(menu,m); |
209 | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
210 next_element: |
8197 | 211 free(element); |
212 if(body) free(body); | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
213 if(name) free(name); |
8197 | 214 asx_free_attribs(attribs); |
215 } | |
216 } | |
217 | |
218 static void read_key(menu_t* menu,int c) { | |
219 menu_list_read_key(menu,c,0); | |
220 } | |
221 | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
222 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
|
223 list_entry_t* e = mpriv->p.current; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
224 |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
225 if(e->opt) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
226 switch(cmd) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
227 case MENU_CMD_UP: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
228 if(!mpriv->edit) break; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
229 case MENU_CMD_RIGHT: |
22284 | 230 if(m_property_do(e->opt,M_PROPERTY_STEP_UP,NULL,menu->ctx) > 0) |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
231 update_entries(menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
232 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
233 case MENU_CMD_DOWN: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
234 if(!mpriv->edit) break; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
235 case MENU_CMD_LEFT: |
22284 | 236 if(m_property_do(e->opt,M_PROPERTY_STEP_DOWN,NULL,menu->ctx) > 0) |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
237 update_entries(menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
238 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
239 |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
240 case MENU_CMD_OK: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
241 // check that the property is writable |
22284 | 242 if(m_property_do(e->opt,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
|
243 // shortcut for flags |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
244 if(e->opt->type == CONF_TYPE_FLAG) { |
22284 | 245 if(m_property_do(e->opt,M_PROPERTY_STEP_UP,NULL,menu->ctx) > 0) |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
246 update_entries(menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
247 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
248 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
249 // switch |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
250 mpriv->edit = !mpriv->edit; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
251 // update the menu |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
252 update_entries(menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
253 // switch the pointer |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
254 if(mpriv->edit) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
255 mpriv->ptr = mpriv->p.ptr; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
256 mpriv->p.ptr = NULL; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
257 } else |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
258 mpriv->p.ptr = mpriv->ptr; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
259 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
260 case MENU_CMD_CANCEL: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
261 if(!mpriv->edit) break; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
262 mpriv->edit = 0; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
263 update_entries(menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
264 mpriv->p.ptr = mpriv->ptr; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
265 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
266 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
267 } else if(e->menu) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
268 switch(cmd) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
269 case MENU_CMD_RIGHT: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
270 case MENU_CMD_OK: { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
271 mp_cmd_t* c; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
272 char* txt = malloc(10 + strlen(e->menu) + 1); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
273 sprintf(txt,"set_menu %s",e->menu); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
274 c = mp_input_parse_cmd(txt); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
275 if(c) mp_input_queue_cmd(c); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
276 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
277 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
278 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
279 } else { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
280 switch(cmd) { |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
281 case MENU_CMD_RIGHT: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
282 case MENU_CMD_OK: |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
283 menu->show = 0; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
284 menu->cl = 1; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
285 return; |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
286 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
287 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
288 menu_list_read_cmd(menu,cmd); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
289 } |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
290 |
8197 | 291 static void free_entry(list_entry_t* entry) { |
292 free(entry->p.txt); | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
293 if(entry->name) free(entry->name); |
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
294 if(entry->menu) free(entry->menu); |
8197 | 295 free(entry); |
296 } | |
297 | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
298 static void closeMenu(menu_t* menu) { |
8197 | 299 menu_list_uninit(menu,free_entry); |
300 } | |
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 static int openMenu(menu_t* menu, char* args) { |
8197 | 303 |
304 menu->draw = menu_list_draw; | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
305 menu->read_cmd = read_cmd; |
8197 | 306 menu->read_key = read_key; |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
307 menu->close = closeMenu; |
8197 | 308 |
309 | |
310 if(!args) { | |
18006
ce1a5b200c39
Minor spelling and grammar fixes for part 1 of Otvos Attila's
corey
parents:
17994
diff
changeset
|
311 mp_msg(MSGT_OSD_MENU,MSGL_ERR,MSGTR_LIBMENU_PrefMenuNeedsAnArgument); |
8197 | 312 return 0; |
313 } | |
314 | |
315 menu_list_init(menu); | |
17949
a6b11b35892a
Turn the preferences menu in something usefull using the new
albeu
parents:
16862
diff
changeset
|
316 return parse_args(menu,args); |
8197 | 317 } |
318 | |
319 const menu_info_t menu_info_pref = { | |
320 "Preferences menu", | |
321 "pref", | |
322 "Albeu", | |
323 "", | |
324 { | |
325 "pref_cfg", | |
326 sizeof(struct menu_priv_s), | |
327 &cfg_dflt, | |
328 cfg_fields | |
329 }, | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
330 openMenu |
8197 | 331 }; |