rpm: Remove MEncoder from rpm packaging
[mplayer/glamo.git] / libmenu / menu_pt.c
blob985066ba7c33c3f96e989004f9d3811a6e006253
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 <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 //#include <libgen.h>
24 #include "config.h"
25 #include "mp_msg.h"
26 #include "path.h"
28 #include "libmpcodecs/img_format.h"
29 #include "libmpcodecs/mp_image.h"
31 #include "m_struct.h"
32 #include "m_option.h"
33 #include "menu.h"
34 #include "menu_list.h"
37 #include "playtree.h"
38 #include "input/input.h"
39 #include "access_mpcontext.h"
41 struct list_entry_s {
42 struct list_entry p;
43 play_tree_t* pt;
47 struct menu_priv_s {
48 menu_list_priv_t p;
49 char* title;
50 int auto_close;
53 static struct menu_priv_s cfg_dflt = {
54 MENU_LIST_PRIV_DFLT,
55 "Jump to",
59 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
61 static const m_option_t cfg_fields[] = {
62 MENU_LIST_PRIV_FIELDS,
63 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
64 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
65 { NULL, NULL, NULL, 0,0,0,NULL }
68 #define mpriv (menu->priv)
70 static void read_cmd(menu_t* menu,int cmd) {
71 switch(cmd) {
72 case MENU_CMD_RIGHT:
73 case MENU_CMD_OK: {
74 int d = 1;
75 char str[15];
76 play_tree_t* i;
77 mp_cmd_t* c;
78 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
80 if(playtree_iter->tree == mpriv->p.current->pt)
81 break;
83 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
84 snprintf(str,15,"pt_up_step 1");
85 else {
86 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
87 if(i == mpriv->p.current->pt)
88 break;
89 d++;
91 if(i == NULL) {
92 d = -1;
93 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
94 if(i == mpriv->p.current->pt)
95 break;
96 d--;
98 if(i == NULL) {
99 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Can't find the target item ????\n");
100 break;
103 snprintf(str,15,"pt_step %d",d);
105 c = mp_input_parse_cmd(str);
106 if(c) {
107 if(mpriv->auto_close)
108 mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd("menu hide"));
109 mp_input_queue_cmd(menu->input_ctx, c);
111 else
112 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Failed to build command: %s.\n",str);
113 } break;
114 default:
115 menu_list_read_cmd(menu,cmd);
119 static int read_key(menu_t* menu,int c){
120 if (menu_dflt_read_key(menu, c))
121 return 1;
122 return menu_list_jump_to_key(menu, c);
125 static void close_menu(menu_t* menu) {
126 menu_list_uninit(menu,NULL);
129 static int op(menu_t* menu, char* args) {
130 play_tree_t* i;
131 list_entry_t* e;
132 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
134 args = NULL; // Warning kill
136 menu->draw = menu_list_draw;
137 menu->read_cmd = read_cmd;
138 menu->read_key = read_key;
139 menu->close = close_menu;
141 menu_list_init(menu);
143 mpriv->p.title = mpriv->title;
145 if(playtree_iter->tree->parent != playtree_iter->root) {
146 e = calloc(1,sizeof(list_entry_t));
147 e->p.txt = "..";
148 e->pt = playtree_iter->tree->parent;
149 menu_list_add_entry(menu,e);
152 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
153 /* NOP */;
154 for( ; i != NULL ; i = i->next ) {
155 e = calloc(1,sizeof(list_entry_t));
156 if(i->files)
157 e->p.txt = (char *)mp_basename(i->files[0]);
158 else
159 e->p.txt = "Group ...";
160 e->pt = i;
161 menu_list_add_entry(menu,e);
164 return 1;
167 const menu_info_t menu_info_pt = {
168 "Playtree menu",
169 "pt",
170 "Albeu",
173 "pt_cfg",
174 sizeof(struct menu_priv_s),
175 &cfg_dflt,
176 cfg_fields