annotate libmenu/menu_filesel.c @ 24290:ca7ee5c1b88d

Support for selecting language via packet 28. Also allows to select default teletext language. It will be used if language is not specified by network provider via packet 28.
author voroshil
date Fri, 31 Aug 2007 16:53:27 +0000
parents 9bf57f60bf0a
children dcf1bfb29dc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
2 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
4 #include <dirent.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5 #include <errno.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <string.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <sys/types.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include <sys/stat.h>
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
9 #include <fcntl.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
10 #include <ctype.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
11 #include <unistd.h>
8291
abe95dde3223 limits.h required to get a PATH_MAX definition (on solaris)
jkeil
parents: 8226
diff changeset
12 #include <limits.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
13
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
14
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 16061
diff changeset
15 #include "config.h"
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
16 #include "mp_msg.h"
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
17 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 16061
diff changeset
19 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 16061
diff changeset
20 #include "m_option.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 17994
diff changeset
22 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 17994
diff changeset
23 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26 #include "menu_list.h"
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 16061
diff changeset
27 #include "input/input.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 16061
diff changeset
28 #include "osdep/keycodes.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
30 #define MENU_KEEP_PATH "/tmp/mp_current_path"
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
31
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
32 int menu_keepdir = 0;
23391
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
33 char *menu_chroot = NULL;
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
34
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 int d;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 char* dir; // current dir
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 /// Cfg fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 char* path;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 char* title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 char* file_action;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 char* dir_action;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 int auto_close;
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
49 char** actions;
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
50 char* filter;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 MENU_LIST_PRIV_DFLT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 "Select a file: %p",
8226
4b8fcc2af8f1 quote the filenames
albeu
parents: 8197
diff changeset
59 "loadfile '%p'",
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 NULL,
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
61 0,
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
62 NULL,
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
63 NULL
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 { "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 { "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 { "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
75 { "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
76 { "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL},
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 static char* replace_path(char* title , char* dir) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 char *p = strstr(title,"%p");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 if(p) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 int tl = strlen(title);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 int dl = strlen(dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 int t1l = p-title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 int l = tl - 2 + dl;
10624
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
94 char *r, *n, *d = dir;
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
95 char term = *(p-1);
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
96
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
97 do {
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
98 if (*d == '\\' || *d == term)
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
99 l++;
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
100 } while (*d++);
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
101 r = malloc(l + 1);
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
102 n = r + t1l;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 memcpy(r,title,t1l);
10624
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
104 do {
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
105 if (*dir == '\\' || *dir == term)
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
106 *n++ = '\\';
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
107 } while ((*n++ = *dir++));
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 if(tl - t1l - 2 > 0)
10624
cdfd4a43c406 I've juste found a bug which prevent to load a file whose name contain
albeu
parents: 9380
diff changeset
109 strcpy(n-1,p+2);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 return r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 return title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 typedef int (*kill_warn)(const void*, const void*);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
117 static int mylstat(char *dir, char *file,struct stat* st) {
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
118 int l = strlen(dir) + strlen(file);
8613
f88ba181ecf2 some 10l bugfixes
arpi
parents: 8358
diff changeset
119 char s[l+2];
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
120 sprintf(s,"%s/%s",dir,file);
9249
8546faeb0112 lstat->stat
arpi
parents: 9104
diff changeset
121 return stat(s,st);
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
122 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
123
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
124 static int compare(char **a, char **b){
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
125 if((*a)[strlen(*a) - 1] == '/') {
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
126 if((*b)[strlen(*b) - 1] == '/')
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
127 return strcmp(*b, *a) ;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
128 else
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
129 return 1;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
130 } else {
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
131 if((*b)[strlen(*b) - 1] == '/')
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
132 return -1;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
133 else
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
134 return strcmp(*b, *a);
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
135 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
136 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
137
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
138 static char **get_extensions(menu_t *menu){
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
139 char **extensions, ext[32];
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
140 FILE *fp;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
141 int n = 1;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
142
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
143 if (!mpriv->filter)
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
144 return NULL;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
145
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
146 fp = fopen(mpriv->filter, "r");
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
147 if(!fp)
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
148 return NULL;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
149
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
150 extensions = (char **) malloc(sizeof(*extensions));
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
151 *extensions = NULL;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
152
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
153 while(fgets(ext,sizeof(ext),fp)) {
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
154 char **l, *e;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
155 int s = strlen (ext);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
156
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
157 if(ext[s-1] == '\n') {
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
158 ext[s-1] = '\0';
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
159 s--;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
160 }
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
161 e = (char *) malloc(s+1);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
162 extensions = (char **) realloc(extensions, ++n * sizeof(*extensions));
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
163 extensions = (char **) realloc(extensions, ++n * sizeof(*extensions));
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
164 strcpy (e, ext);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
165 for (l=extensions; *l; l++);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
166 *l++ = e;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
167 *l = NULL;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
168 }
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
169
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
170 fclose (fp);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
171 return extensions;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
172 }
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
173
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
174 static void free_extensions(char **extensions){
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
175 if (extensions) {
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
176 char **l = extensions;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
177 while (*l)
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
178 free (*l++);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
179 free (extensions);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
180 }
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
181 }
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
182
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 static int open_dir(menu_t* menu,char* args) {
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
184 char **namelist, **tp;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
185 struct dirent *dp;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 struct stat st;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187 int n;
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
188 int path_fp;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
189 char* p = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 list_entry_t* e;
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
191 DIR* dirp;
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
192 extern int file_filter;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
193 char **extensions, **elem, *ext;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
194
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
195 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
196
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
197 if(mpriv->dir)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
198 free(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
199 mpriv->dir = strdup(args);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
200 if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
201 free(mpriv->p.title);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
202 p = strstr(mpriv->title,"%p");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
203
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
204 mpriv->p.title = replace_path(mpriv->title,mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
206 if ((dirp = opendir (mpriv->dir)) == NULL){
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
207 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno));
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
208 return 0;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
209 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
210
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
211 if (menu_keepdir) {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
212 path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
213 if (path_fp >= 0) {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
214 write (path_fp, mpriv->dir, strlen (mpriv->dir));
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
215 close (path_fp);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
216 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
217 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
218
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
219 namelist = (char **) malloc(sizeof(char *));
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
220 extensions = get_extensions(menu);
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
221
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
222 n=0;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
223 while ((dp = readdir(dirp)) != NULL) {
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
224 if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0)
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
225 continue;
23391
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
226 if (menu_chroot && !strcmp (dp->d_name,"..")) {
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
227 int len = strlen (menu_chroot);
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
228 if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1)
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
229 && !strncmp (mpriv->dir, menu_chroot, len))
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
230 continue;
9bf57f60bf0a new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents: 23229
diff changeset
231 }
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
232 mylstat(args,dp->d_name,&st);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
233 if (file_filter && extensions && !S_ISDIR(st.st_mode)) {
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
234 if((ext = strrchr(dp->d_name,'.')) == NULL)
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
235 continue;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
236 ext++;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
237 elem = extensions;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
238 do {
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
239 if (!strcasecmp(ext, *elem))
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
240 break;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
241 } while (*++elem);
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
242 if (*elem == NULL)
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
243 continue;
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
244 }
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
245 if(n%20 == 0){ // Get some more mem
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
246 if((tp = (char **) realloc(namelist, (n+20) * sizeof (char *)))
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
247 == NULL) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
248 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReallocError, strerror(errno));
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
249 n--;
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
250 goto bailout;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
251 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
252 namelist=tp;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
253 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
254
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
255 namelist[n] = (char *) malloc(strlen(dp->d_name) + 2);
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
256 if(namelist[n] == NULL){
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
257 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno));
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
258 n--;
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
259 goto bailout;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
260 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
261
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
262 strcpy(namelist[n], dp->d_name);
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
263 if(S_ISDIR(st.st_mode))
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
264 strcat(namelist[n], "/");
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
265 n++;
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
266 }
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
267
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
268 bailout:
19491
10d8f2cae948 added new filter option to menu file browser to only display some files according to extension
ben
parents: 19490
diff changeset
269 free_extensions (extensions);
16061
261022c048cd add some closedir() to fix some opendir() leaks
aurel
parents: 10624
diff changeset
270 closedir(dirp);
261022c048cd add some closedir() to fix some opendir() leaks
aurel
parents: 10624
diff changeset
271
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
272 qsort(namelist, n, sizeof(char *), (kill_warn)compare);
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
273
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
274 if (n < 0) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
275 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno));
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
276 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
277 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
278 while(n--) {
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
279 if((e = calloc(1,sizeof(list_entry_t))) != NULL){
8613
f88ba181ecf2 some 10l bugfixes
arpi
parents: 8358
diff changeset
280 e->p.next = NULL;
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
281 e->p.txt = strdup(namelist[n]);
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
282 if(strchr(namelist[n], '/') != NULL)
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
283 e->d = 1;
8358
ecf6a4cf3272 No scandir() an no functions defined within other functions.
arpi
parents: 8291
diff changeset
284 menu_list_add_entry(menu,e);
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
285 }else{
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
286 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno));
9104
a0aacfb492a5 Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents: 8853
diff changeset
287 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
288 free(namelist[n]);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
289 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
290 free(namelist);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
291
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
292 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
293 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
294
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
295
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
296 static char *action;
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
297
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
298 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
299 mp_cmd_t* c = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
300 switch(cmd) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
301 case MENU_CMD_LEFT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
302 mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
303 case MENU_CMD_RIGHT:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
304 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
305 // Directory
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
306 if(mpriv->p.current->d) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
307 if(mpriv->dir_action) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
308 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
309 char filename[fname_len];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
310 char* str;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
311 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
312 str = replace_path(mpriv->dir_action,filename);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
313 c = mp_input_parse_cmd(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
314 if(str != mpriv->dir_action)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
315 free(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
316 } else { // Default action : open this dirctory ourself
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
317 int l = strlen(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
318 char *slash = NULL, *p = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
319 if(strcmp(mpriv->p.current->p.txt,"../") == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
320 if(l <= 1) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
321 mpriv->dir[l-1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
322 slash = strrchr(mpriv->dir,'/');
20505
543f6e8deeb6 Handle windows path separator in filesel menu.
reimar
parents: 19491
diff changeset
323 #if defined(__MINGW32__) || defined(__CYGWIN__)
543f6e8deeb6 Handle windows path separator in filesel menu.
reimar
parents: 19491
diff changeset
324 if (!slash)
543f6e8deeb6 Handle windows path separator in filesel menu.
reimar
parents: 19491
diff changeset
325 slash = strrchr(mpriv->dir,'\\');
543f6e8deeb6 Handle windows path separator in filesel menu.
reimar
parents: 19491
diff changeset
326 #endif
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
327 if(!slash) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
328 slash[1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
329 p = strdup(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
330 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
331 p = malloc(l + strlen(mpriv->p.current->p.txt) + 1);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
332 sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
333 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
334 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
335 if(!open_dir(menu,p)) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17945
diff changeset
336 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_CantOpenDirectory,p);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
337 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
338 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
339 free(p);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
340 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
341 } else { // Files
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
342 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
343 char filename[fname_len];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
344 char *str;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
345 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
346 str = replace_path(mpriv->file_action,filename);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
347 c = mp_input_parse_cmd(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
348 if(str != mpriv->file_action)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
349 free(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
350 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
351 if(c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
352 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
353 if(mpriv->auto_close)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
354 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
355 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
356 } break;
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
357 case MENU_CMD_ACTION: {
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
358 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
359 char filename[fname_len];
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
360 char *str;
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
361 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
362 str = replace_path(action, filename);
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
363 mp_input_queue_cmd(mp_input_parse_cmd(str));
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
364 if(str != action)
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
365 free(str);
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
366 } break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
367 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
368 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
369 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
370 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
371
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
372 static void read_key(menu_t* menu,int c){
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
373 if(c == KEY_BS)
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
374 read_cmd(menu,MENU_CMD_LEFT);
19490
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
375 else {
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
376 char **str;
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
377 for (str=mpriv->actions; str && *str; str++)
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
378 if (c == (*str)[0]) {
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
379 action = &(*str)[2];
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
380 read_cmd(menu,MENU_CMD_ACTION);
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
381 break;
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
382 }
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
383 if (!str || !*str)
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
384 menu_list_read_key(menu,c,1);
f57977ac0394 support multiple actions in menu's file browser using key bindings
ben
parents: 19431
diff changeset
385 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
386 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
387
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
388 static void clos(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
389 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
390 free(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
391 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
392
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
393 static int open_fs(menu_t* menu, char* args) {
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
394 char *path = mpriv->path, *freepath = NULL;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
395 int r = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
396 char wd[PATH_MAX+1];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
397 args = NULL; // Warning kill
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
398
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
399 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
400 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
401 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
402 menu->close = clos;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
403
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
404 if (menu_keepdir) {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
405 if (!path || path[0] == '\0') {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
406 struct stat st;
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
407 int path_fp;
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
408
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
409 path_fp = open (MENU_KEEP_PATH, O_RDONLY);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
410 if (path_fp >= 0) {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
411 if (!fstat (path_fp, &st) && (st.st_size > 0)) {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
412 path = malloc(st.st_size+1);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
413 if ((read(path_fp, path, st.st_size) == st.st_size) && path[0] != '\0'){
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
414 freepath = path;
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
415 path[st.st_size] = '\0';
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
416 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
417 else {
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
418 free(path);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
419 path = NULL;
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
420 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
421 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
422 close (path_fp);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
423 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
424 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
425 }
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
426
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
427 getcwd(wd,PATH_MAX);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
428 if(!path || path[0] == '\0') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
429 int l = strlen(wd) + 2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
430 char b[l];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
431 sprintf(b,"%s/",wd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
432 r = open_dir(menu,b);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
433 } else if(path[0] != '/') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
434 int al = strlen(path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
435 int l = strlen(wd) + al + 3;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
436 char b[l];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
437 if(b[al-1] != '/')
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
438 sprintf(b,"%s/%s/",wd,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
439 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
440 sprintf(b,"%s/%s",wd,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
441 r = open_dir(menu,b);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
442 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
443 r = open_dir(menu,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
444
23229
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
445 if (freepath)
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
446 free(freepath);
ae2a2d5ca64b new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents: 20505
diff changeset
447
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
448 return r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
449 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
450
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
451 const menu_info_t menu_info_filesel = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
452 "File seletor menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
453 "filesel",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
454 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
455 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
456 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
457 "fs_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
458 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
459 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
460 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
461 },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
462 open_fs
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
463 };