28113
|
1 /*
|
|
2 * This file is part of MPlayer.
|
|
3 *
|
|
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.
|
|
8 *
|
|
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.
|
|
13 *
|
|
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.
|
|
17 */
|
8197
|
18
|
|
19 #include <stdlib.h>
|
|
20 #include <stdio.h>
|
8623
|
21 #include <string.h>
|
9102
|
22 //#include <libgen.h>
|
8197
|
23
|
16862
|
24 #include "config.h"
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
diff
changeset
|
25 #include "mp_msg.h"
|
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
diff
changeset
|
26 #include "help_mp.h"
|
8197
|
27
|
19431
|
28 #include "libmpcodecs/img_format.h"
|
|
29 #include "libmpcodecs/mp_image.h"
|
8197
|
30
|
16862
|
31 #include "m_struct.h"
|
|
32 #include "m_option.h"
|
8197
|
33 #include "menu.h"
|
|
34 #include "menu_list.h"
|
|
35
|
|
36
|
16862
|
37 #include "playtree.h"
|
|
38 #include "input/input.h"
|
22284
|
39 #include "access_mpcontext.h"
|
8197
|
40
|
9102
|
41 #define mp_basename(s) (strrchr((s),'/')==NULL?(char*)(s):(strrchr((s),'/')+1))
|
8197
|
42
|
|
43 struct list_entry_s {
|
|
44 struct list_entry p;
|
|
45 play_tree_t* pt;
|
|
46 };
|
29263
|
47
|
8197
|
48
|
|
49 struct menu_priv_s {
|
|
50 menu_list_priv_t p;
|
|
51 char* title;
|
27072
|
52 int auto_close;
|
8197
|
53 };
|
|
54
|
|
55 static struct menu_priv_s cfg_dflt = {
|
|
56 MENU_LIST_PRIV_DFLT,
|
27072
|
57 "Jump to",
|
|
58 0
|
8197
|
59 };
|
|
60
|
|
61 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
|
|
62
|
|
63 static m_option_t cfg_fields[] = {
|
|
64 MENU_LIST_PRIV_FIELDS,
|
|
65 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
27072
|
66 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
|
8197
|
67 { NULL, NULL, NULL, 0,0,0,NULL }
|
|
68 };
|
|
69
|
|
70 #define mpriv (menu->priv)
|
|
71
|
|
72 static void read_cmd(menu_t* menu,int cmd) {
|
|
73 switch(cmd) {
|
17945
|
74 case MENU_CMD_RIGHT:
|
8197
|
75 case MENU_CMD_OK: {
|
|
76 int d = 1;
|
|
77 char str[15];
|
|
78 play_tree_t* i;
|
|
79 mp_cmd_t* c;
|
22284
|
80 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
|
8197
|
81
|
|
82 if(playtree_iter->tree == mpriv->p.current->pt)
|
|
83 break;
|
|
84
|
|
85 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
|
|
86 snprintf(str,15,"pt_up_step 1");
|
|
87 else {
|
|
88 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
|
|
89 if(i == mpriv->p.current->pt)
|
|
90 break;
|
|
91 d++;
|
|
92 }
|
|
93 if(i == NULL) {
|
|
94 d = -1;
|
|
95 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
|
|
96 if(i == mpriv->p.current->pt)
|
|
97 break;
|
|
98 d--;
|
|
99 }
|
|
100 if(i == NULL) {
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
diff
changeset
|
101 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantfindTheTargetItem);
|
8197
|
102 break;
|
|
103 }
|
|
104 }
|
|
105 snprintf(str,15,"pt_step %d",d);
|
|
106 }
|
|
107 c = mp_input_parse_cmd(str);
|
27072
|
108 if(c) {
|
|
109 if(mpriv->auto_close)
|
|
110 mp_input_queue_cmd(mp_input_parse_cmd("menu hide"));
|
8197
|
111 mp_input_queue_cmd(c);
|
27072
|
112 }
|
8197
|
113 else
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
diff
changeset
|
114 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToBuildCommand,str);
|
8197
|
115 } break;
|
|
116 default:
|
|
117 menu_list_read_cmd(menu,cmd);
|
|
118 }
|
|
119 }
|
|
120
|
25502
|
121 static int read_key(menu_t* menu,int c){
|
25263
|
122 if (menu_dflt_read_key(menu, c))
|
25502
|
123 return 1;
|
|
124 return menu_list_jump_to_key(menu, c);
|
8197
|
125 }
|
|
126
|
18817
|
127 static void close_menu(menu_t* menu) {
|
8197
|
128 menu_list_uninit(menu,NULL);
|
|
129 }
|
|
130
|
|
131 static int op(menu_t* menu, char* args) {
|
|
132 play_tree_t* i;
|
|
133 list_entry_t* e;
|
22284
|
134 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
|
29263
|
135
|
8197
|
136 args = NULL; // Warning kill
|
|
137
|
|
138 menu->draw = menu_list_draw;
|
|
139 menu->read_cmd = read_cmd;
|
|
140 menu->read_key = read_key;
|
18817
|
141 menu->close = close_menu;
|
8197
|
142
|
|
143 menu_list_init(menu);
|
|
144
|
|
145 mpriv->p.title = mpriv->title;
|
|
146
|
|
147 if(playtree_iter->tree->parent != playtree_iter->root) {
|
|
148 e = calloc(1,sizeof(list_entry_t));
|
|
149 e->p.txt = "..";
|
|
150 e->pt = playtree_iter->tree->parent;
|
|
151 menu_list_add_entry(menu,e);
|
|
152 }
|
29263
|
153
|
8197
|
154 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
|
|
155 /* NOP */;
|
|
156 for( ; i != NULL ; i = i->next ) {
|
|
157 e = calloc(1,sizeof(list_entry_t));
|
|
158 if(i->files)
|
9102
|
159 e->p.txt = mp_basename(i->files[0]);
|
8197
|
160 else
|
|
161 e->p.txt = "Group ...";
|
|
162 e->pt = i;
|
|
163 menu_list_add_entry(menu,e);
|
|
164 }
|
|
165
|
|
166 return 1;
|
|
167 }
|
|
168
|
|
169 const menu_info_t menu_info_pt = {
|
|
170 "Playtree menu",
|
|
171 "pt",
|
|
172 "Albeu",
|
|
173 "",
|
|
174 {
|
|
175 "pt_cfg",
|
|
176 sizeof(struct menu_priv_s),
|
|
177 &cfg_dflt,
|
|
178 cfg_fields
|
|
179 },
|
|
180 op
|
|
181 };
|