rpm: Remove MEncoder from rpm packaging
[mplayer/glamo.git] / libmenu / menu_cmdlist.c
blob5b7812be5e3be764ac349fa7307827aef647de9f
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
20 #include "mp_msg.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <string.h>
27 #include "libmpcodecs/img_format.h"
28 #include "libmpcodecs/mp_image.h"
30 #include "m_option.h"
31 #include "m_struct.h"
32 #include "asxparser.h"
33 #include "menu.h"
34 #include "menu_list.h"
36 #include "libvo/font_load.h"
38 #include "input/input.h"
42 struct list_entry_s {
43 struct list_entry p;
45 char* ok;
46 char* cancel;
47 char* left;
48 char* right;
51 struct menu_priv_s {
52 menu_list_priv_t p;
55 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
57 static struct menu_priv_s cfg_dflt = {
58 MENU_LIST_PRIV_DFLT,
61 static const m_option_t cfg_fields[] = {
62 MENU_LIST_PRIV_FIELDS,
63 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
64 { NULL, NULL, NULL, 0,0,0,NULL }
67 #define mpriv (menu->priv)
69 static void read_cmd(menu_t* menu,int cmd) {
70 switch(cmd) {
71 case MENU_CMD_RIGHT:
72 if(mpriv->p.current->right) {
73 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->right);
74 break;
75 } // fallback on ok if right is not defined
76 case MENU_CMD_OK:
77 if (mpriv->p.current->ok)
78 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->ok);
79 break;
80 case MENU_CMD_LEFT:
81 if(mpriv->p.current->left) {
82 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->left);
83 break;
84 } // fallback on cancel if left is not defined
85 case MENU_CMD_CANCEL:
86 if(mpriv->p.current->cancel) {
87 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->cancel);
88 break;
90 default:
91 menu_list_read_cmd(menu,cmd);
95 static void free_entry(list_entry_t* entry) {
96 free(entry->ok);
97 free(entry->cancel);
98 free(entry->left);
99 free(entry->right);
100 free(entry->p.txt);
101 free(entry);
104 static void close_menu(menu_t* menu) {
105 menu_list_uninit(menu,free_entry);
108 static int parse_args(menu_t* menu,char* args) {
109 char *element,*body, **attribs, *name;
110 list_entry_t* m = NULL;
111 int r;
112 ASX_Parser_t* parser = asx_parser_new(menu->mconfig);
114 while(1) {
115 r = asx_get_element(parser,&args,&element,&body,&attribs);
116 if(r < 0) {
117 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] syntax error at line: %d\n",parser->line);
118 asx_parser_free(parser);
119 return -1;
120 } else if(r == 0) {
121 asx_parser_free(parser);
122 if(!m)
123 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] No entry found in the menu definition.\n");
124 return m ? 1 : 0;
126 // Has it a name ?
127 name = asx_get_attrib("name",attribs);
128 if(!name) {
129 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] List menu entry definitions need a name (line %d).\n",parser->line);
130 free(element);
131 free(body);
132 asx_free_attribs(attribs);
133 continue;
135 m = calloc(1,sizeof(struct list_entry_s));
136 m->p.txt = name;
137 m->ok = asx_get_attrib("ok",attribs);
138 m->cancel = asx_get_attrib("cancel",attribs);
139 m->left = asx_get_attrib("left",attribs);
140 m->right = asx_get_attrib("right",attribs);
141 menu_list_add_entry(menu,m);
143 free(element);
144 free(body);
145 asx_free_attribs(attribs);
149 static int open_cmdlist(menu_t* menu, char* args) {
150 menu->draw = menu_list_draw;
151 menu->read_cmd = read_cmd;
152 menu->close = close_menu;
154 if(!args) {
155 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] List menu needs an argument.\n");
156 return 0;
159 menu_list_init(menu);
160 if(!parse_args(menu,args))
161 return 0;
162 return 1;
165 const menu_info_t menu_info_cmdlist = {
166 "Command list menu",
167 "cmdlist",
168 "Albeu",
171 "cmdlist_cfg",
172 sizeof(struct menu_priv_s),
173 &cfg_dflt,
174 cfg_fields
176 open_cmdlist