8197
|
1
|
|
2 #include <stdlib.h>
|
|
3 #include <stdio.h>
|
|
4 #include <libgen.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7
|
|
8 #include "img_format.h"
|
|
9 #include "mp_image.h"
|
|
10
|
|
11 #include "../m_struct.h"
|
|
12 #include "../m_option.h"
|
|
13 #include "menu.h"
|
|
14 #include "menu_list.h"
|
|
15
|
|
16
|
|
17 #include "../playtree.h"
|
|
18 #include "../input/input.h"
|
|
19
|
|
20
|
|
21
|
|
22 extern play_tree_iter_t* playtree_iter;
|
|
23
|
|
24 struct list_entry_s {
|
|
25 struct list_entry p;
|
|
26 play_tree_t* pt;
|
|
27 };
|
|
28
|
|
29
|
|
30 struct menu_priv_s {
|
|
31 menu_list_priv_t p;
|
|
32 char* title;
|
|
33 };
|
|
34
|
|
35 static struct menu_priv_s cfg_dflt = {
|
|
36 MENU_LIST_PRIV_DFLT,
|
|
37 "Jump to"
|
|
38 };
|
|
39
|
|
40 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
|
|
41
|
|
42 static m_option_t cfg_fields[] = {
|
|
43 MENU_LIST_PRIV_FIELDS,
|
|
44 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
45 { NULL, NULL, NULL, 0,0,0,NULL }
|
|
46 };
|
|
47
|
|
48 #define mpriv (menu->priv)
|
|
49
|
|
50 static void read_cmd(menu_t* menu,int cmd) {
|
|
51 switch(cmd) {
|
|
52 case MENU_CMD_OK: {
|
|
53 int d = 1;
|
|
54 char str[15];
|
|
55 play_tree_t* i;
|
|
56 mp_cmd_t* c;
|
|
57
|
|
58
|
|
59 if(playtree_iter->tree == mpriv->p.current->pt)
|
|
60 break;
|
|
61
|
|
62 if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent)
|
|
63 snprintf(str,15,"pt_up_step 1");
|
|
64 else {
|
|
65 for(i = playtree_iter->tree->next; i != NULL ; i = i->next) {
|
|
66 if(i == mpriv->p.current->pt)
|
|
67 break;
|
|
68 d++;
|
|
69 }
|
|
70 if(i == NULL) {
|
|
71 d = -1;
|
|
72 for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) {
|
|
73 if(i == mpriv->p.current->pt)
|
|
74 break;
|
|
75 d--;
|
|
76 }
|
|
77 if(i == NULL) {
|
|
78 printf("Can't find the target item ????\n");
|
|
79 break;
|
|
80 }
|
|
81 }
|
|
82 snprintf(str,15,"pt_step %d",d);
|
|
83 }
|
|
84 c = mp_input_parse_cmd(str);
|
|
85 if(c)
|
|
86 mp_input_queue_cmd(c);
|
|
87 else
|
|
88 printf("Failed to build command %s\n",str);
|
|
89 } break;
|
|
90 default:
|
|
91 menu_list_read_cmd(menu,cmd);
|
|
92 }
|
|
93 }
|
|
94
|
|
95 static void read_key(menu_t* menu,int c){
|
|
96 menu_list_read_key(menu,c,1);
|
|
97 }
|
|
98
|
|
99 static void close(menu_t* menu) {
|
|
100 menu_list_uninit(menu,NULL);
|
|
101 }
|
|
102
|
|
103 static int op(menu_t* menu, char* args) {
|
|
104 play_tree_t* i;
|
|
105 list_entry_t* e;
|
|
106 args = NULL; // Warning kill
|
|
107
|
|
108 menu->draw = menu_list_draw;
|
|
109 menu->read_cmd = read_cmd;
|
|
110 menu->read_key = read_key;
|
|
111 menu->close = close;
|
|
112
|
|
113 menu_list_init(menu);
|
|
114
|
|
115 mpriv->p.title = mpriv->title;
|
|
116
|
|
117 if(playtree_iter->tree->parent != playtree_iter->root) {
|
|
118 e = calloc(1,sizeof(list_entry_t));
|
|
119 e->p.txt = "..";
|
|
120 e->pt = playtree_iter->tree->parent;
|
|
121 menu_list_add_entry(menu,e);
|
|
122 }
|
|
123
|
|
124 for(i = playtree_iter->tree ; i->prev != NULL ; i = i->prev)
|
|
125 /* NOP */;
|
|
126 for( ; i != NULL ; i = i->next ) {
|
|
127 e = calloc(1,sizeof(list_entry_t));
|
|
128 if(i->files)
|
|
129 e->p.txt = basename(i->files[0]);
|
|
130 else
|
|
131 e->p.txt = "Group ...";
|
|
132 e->pt = i;
|
|
133 menu_list_add_entry(menu,e);
|
|
134 }
|
|
135
|
|
136 return 1;
|
|
137 }
|
|
138
|
|
139 const menu_info_t menu_info_pt = {
|
|
140 "Playtree menu",
|
|
141 "pt",
|
|
142 "Albeu",
|
|
143 "",
|
|
144 {
|
|
145 "pt_cfg",
|
|
146 sizeof(struct menu_priv_s),
|
|
147 &cfg_dflt,
|
|
148 cfg_fields
|
|
149 },
|
|
150 op
|
|
151 };
|