Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libmenu / menu_pt.c
blob27ce5ae0e37f677ec4930aaa246847b4686761e1
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 //#include <libgen.h>
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
11 #include "libmpcodecs/img_format.h"
12 #include "libmpcodecs/mp_image.h"
14 #include "m_struct.h"
15 #include "m_option.h"
16 #include "menu.h"
17 #include "menu_list.h"
20 #include "playtree.h"
21 #include "input/input.h"
22 #include "access_mpcontext.h"
24 #define mp_basename(s) (strrchr((s),'/')==NULL?(char*)(s):(strrchr((s),'/')+1))
26 struct list_entry_s {
27 struct list_entry p;
28 play_tree_t* pt;
32 struct menu_priv_s {
33 menu_list_priv_t p;
34 char* title;
37 static struct menu_priv_s cfg_dflt = {
38 MENU_LIST_PRIV_DFLT,
39 "Jump to"
42 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
44 static m_option_t cfg_fields[] = {
45 MENU_LIST_PRIV_FIELDS,
46 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
47 { NULL, NULL, NULL, 0,0,0,NULL }
50 #define mpriv (menu->priv)
52 static void read_cmd(menu_t* menu,int cmd) {
53 switch(cmd) {
54 case MENU_CMD_RIGHT:
55 case MENU_CMD_OK: {
56 int d = 1;
57 char str[15];
58 play_tree_t* i;
59 mp_cmd_t* c;
60 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
62 if(playtree_iter->tree == mpriv->p.current->pt)
63 break;
65 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
66 snprintf(str,15,"pt_up_step 1");
67 else {
68 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
69 if(i == mpriv->p.current->pt)
70 break;
71 d++;
73 if(i == NULL) {
74 d = -1;
75 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
76 if(i == mpriv->p.current->pt)
77 break;
78 d--;
80 if(i == NULL) {
81 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantfindTheTargetItem);
82 break;
85 snprintf(str,15,"pt_step %d",d);
87 c = mp_input_parse_cmd(str);
88 if(c)
89 mp_input_queue_cmd(c);
90 else
91 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToBuildCommand,str);
92 } break;
93 default:
94 menu_list_read_cmd(menu,cmd);
98 static int read_key(menu_t* menu,int c){
99 if (menu_dflt_read_key(menu, c))
100 return 1;
101 return menu_list_jump_to_key(menu, c);
104 static void close_menu(menu_t* menu) {
105 menu_list_uninit(menu,NULL);
108 static int op(menu_t* menu, char* args) {
109 play_tree_t* i;
110 list_entry_t* e;
111 play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx);
113 args = NULL; // Warning kill
115 menu->draw = menu_list_draw;
116 menu->read_cmd = read_cmd;
117 menu->read_key = read_key;
118 menu->close = close_menu;
120 menu_list_init(menu);
122 mpriv->p.title = mpriv->title;
124 if(playtree_iter->tree->parent != playtree_iter->root) {
125 e = calloc(1,sizeof(list_entry_t));
126 e->p.txt = "..";
127 e->pt = playtree_iter->tree->parent;
128 menu_list_add_entry(menu,e);
131 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
132 /* NOP */;
133 for( ; i != NULL ; i = i->next ) {
134 e = calloc(1,sizeof(list_entry_t));
135 if(i->files)
136 e->p.txt = mp_basename(i->files[0]);
137 else
138 e->p.txt = "Group ...";
139 e->pt = i;
140 menu_list_add_entry(menu,e);
143 return 1;
146 const menu_info_t menu_info_pt = {
147 "Playtree menu",
148 "pt",
149 "Albeu",
152 "pt_cfg",
153 sizeof(struct menu_priv_s),
154 &cfg_dflt,
155 cfg_fields