aspect.c: use fallback if screen dimensions are not known
[mplayer/glamo.git] / libmenu / menu_pt.c
blob7008db28961329c2ce767a2e54b162fc7136d8d8
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"
27 #include "libmpcodecs/img_format.h"
28 #include "libmpcodecs/mp_image.h"
30 #include "m_struct.h"
31 #include "m_option.h"
32 #include "menu.h"
33 #include "menu_list.h"
36 #include "playtree.h"
37 #include "input/input.h"
38 #include "access_mpcontext.h"
40 #define mp_basename(s) (strrchr((s),'/')==NULL?(char*)(s):(strrchr((s),'/')+1))
42 struct list_entry_s {
43 struct list_entry p;
44 play_tree_t* pt;
48 struct menu_priv_s {
49 menu_list_priv_t p;
50 char* title;
51 int auto_close;
54 static struct menu_priv_s cfg_dflt = {
55 MENU_LIST_PRIV_DFLT,
56 "Jump to",
60 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
62 static const m_option_t cfg_fields[] = {
63 MENU_LIST_PRIV_FIELDS,
64 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
65 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
66 { NULL, NULL, NULL, 0,0,0,NULL }
69 #define mpriv (menu->priv)
71 static void read_cmd(menu_t* menu,int cmd) {
72 switch(cmd) {
73 case MENU_CMD_RIGHT:
74 case MENU_CMD_OK: {
75 int d = 1;
76 char str[15];
77 play_tree_t* i;
78 mp_cmd_t* c;
79 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
81 if(playtree_iter->tree == mpriv->p.current->pt)
82 break;
84 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
85 snprintf(str,15,"pt_up_step 1");
86 else {
87 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
88 if(i == mpriv->p.current->pt)
89 break;
90 d++;
92 if(i == NULL) {
93 d = -1;
94 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
95 if(i == mpriv->p.current->pt)
96 break;
97 d--;
99 if(i == NULL) {
100 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Can't find the target item ????\n");
101 break;
104 snprintf(str,15,"pt_step %d",d);
106 c = mp_input_parse_cmd(str);
107 if(c) {
108 if(mpriv->auto_close)
109 mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd("menu hide"));
110 mp_input_queue_cmd(menu->input_ctx, c);
112 else
113 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Failed to build command: %s.\n",str);
114 } break;
115 default:
116 menu_list_read_cmd(menu,cmd);
120 static int read_key(menu_t* menu,int c){
121 if (menu_dflt_read_key(menu, c))
122 return 1;
123 return menu_list_jump_to_key(menu, c);
126 static void close_menu(menu_t* menu) {
127 menu_list_uninit(menu,NULL);
130 static int op(menu_t* menu, char* args) {
131 play_tree_t* i;
132 list_entry_t* e;
133 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
135 args = NULL; // Warning kill
137 menu->draw = menu_list_draw;
138 menu->read_cmd = read_cmd;
139 menu->read_key = read_key;
140 menu->close = close_menu;
142 menu_list_init(menu);
144 mpriv->p.title = mpriv->title;
146 if(playtree_iter->tree->parent != playtree_iter->root) {
147 e = calloc(1,sizeof(list_entry_t));
148 e->p.txt = "..";
149 e->pt = playtree_iter->tree->parent;
150 menu_list_add_entry(menu,e);
153 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
154 /* NOP */;
155 for( ; i != NULL ; i = i->next ) {
156 e = calloc(1,sizeof(list_entry_t));
157 if(i->files)
158 e->p.txt = mp_basename(i->files[0]);
159 else
160 e->p.txt = "Group ...";
161 e->pt = i;
162 menu_list_add_entry(menu,e);
165 return 1;
168 const menu_info_t menu_info_pt = {
169 "Playtree menu",
170 "pt",
171 "Albeu",
174 "pt_cfg",
175 sizeof(struct menu_priv_s),
176 &cfg_dflt,
177 cfg_fields