Mercurial > mplayer.hg
annotate libmenu/menu_filesel.c @ 28506:fe72d4f7ac25
Only set VO_EVENT_RESIZE if size actually changed, not if e.g. the window was
only moved to the foreground.
author | reimar |
---|---|
date | Thu, 12 Feb 2009 12:43:14 +0000 |
parents | f8b6c7045cf8 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
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> | |
21 #include <dirent.h> | |
22 #include <errno.h> | |
23 #include <string.h> | |
24 #include <sys/types.h> | |
25 #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
|
26 #include <fcntl.h> |
8197 | 27 #include <ctype.h> |
28 #include <unistd.h> | |
8291
abe95dde3223
limits.h required to get a PATH_MAX definition (on solaris)
jkeil
parents:
8226
diff
changeset
|
29 #include <limits.h> |
8197 | 30 |
31 | |
16862 | 32 #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
|
33 #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
|
34 #include "help_mp.h" |
8197 | 35 |
16862 | 36 #include "m_struct.h" |
37 #include "m_option.h" | |
8197 | 38 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
39 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
40 #include "libmpcodecs/mp_image.h" |
8197 | 41 |
42 #include "menu.h" | |
43 #include "menu_list.h" | |
16862 | 44 #include "input/input.h" |
45 #include "osdep/keycodes.h" | |
8197 | 46 |
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
|
47 #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
|
48 |
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
|
49 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
|
50 char *menu_chroot = NULL; |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
51 extern char *filename; |
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
|
52 |
8197 | 53 struct list_entry_s { |
54 struct list_entry p; | |
55 int d; | |
56 }; | |
57 | |
58 struct menu_priv_s { | |
59 menu_list_priv_t p; | |
60 char* dir; // current dir | |
61 /// Cfg fields | |
62 char* path; | |
63 char* title; | |
64 char* file_action; | |
65 char* dir_action; | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
66 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
|
67 char* filter; |
8197 | 68 }; |
69 | |
70 static struct menu_priv_s cfg_dflt = { | |
71 MENU_LIST_PRIV_DFLT, | |
72 NULL, | |
73 | |
74 NULL, | |
75 "Select a file: %p", | |
8226 | 76 "loadfile '%p'", |
8197 | 77 NULL, |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
78 NULL, |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
79 NULL |
8197 | 80 }; |
81 | |
82 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
83 | |
84 static m_option_t cfg_fields[] = { | |
85 MENU_LIST_PRIV_FIELDS, | |
86 { "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
87 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
88 { "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
89 { "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
90 { "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
|
91 { "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL}, |
8197 | 92 { NULL, NULL, NULL, 0,0,0,NULL } |
93 }; | |
94 | |
95 #define mpriv (menu->priv) | |
96 | |
97 static void free_entry(list_entry_t* entry) { | |
98 free(entry->p.txt); | |
99 free(entry); | |
100 } | |
101 | |
27086 | 102 static char* replace_path(char* title , char* dir , int escape) { |
8197 | 103 char *p = strstr(title,"%p"); |
104 if(p) { | |
105 int tl = strlen(title); | |
106 int dl = strlen(dir); | |
107 int t1l = p-title; | |
108 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
|
109 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
|
110 |
27086 | 111 if (escape) { |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
112 do { |
27086 | 113 if (*d == '\\') |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
114 l++; |
27086 | 115 else if (*d == '\'') /* ' -> \'\\\'\' */ |
116 l+=7; | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
117 } while (*d++); |
27086 | 118 } |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
119 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
|
120 n = r + t1l; |
8197 | 121 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
|
122 do { |
27086 | 123 if (escape) { |
124 if (*dir == '\\') | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
125 *n++ = '\\'; |
27086 | 126 else if (*dir == '\'') { /* ' -> \'\\\'\' */ |
127 *n++ = '\\'; *n++ = '\''; | |
128 *n++ = '\\'; *n++ = '\\'; | |
129 *n++ = '\\'; *n++ = '\''; | |
130 *n++ = '\\'; | |
131 } | |
132 } | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
133 } while ((*n++ = *dir++)); |
8197 | 134 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
|
135 strcpy(n-1,p+2); |
8197 | 136 return r; |
137 } else | |
138 return title; | |
139 } | |
140 | |
141 typedef int (*kill_warn)(const void*, const void*); | |
142 | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
143 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
|
144 int l = strlen(dir) + strlen(file); |
8613 | 145 char s[l+2]; |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
146 if (!strcmp("..", file)) { |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
147 char *slash; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
148 l -= 3; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
149 strcpy(s, dir); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
150 #if defined(__MINGW32__) || defined(__CYGWIN__) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
151 if (s[l] == '/' || s[l] == '\\') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
152 #else |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
153 if (s[l] == '/') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
154 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
155 s[l] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
156 slash = strrchr(s, '/'); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
157 #if defined(__MINGW32__) || defined(__CYGWIN__) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
158 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
159 slash = strrchr(s,'\\'); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
160 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
161 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
162 return stat(dir,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
163 slash[1] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
164 return stat(s,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
165 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
166 sprintf(s,"%s/%s",dir,file); |
9249 | 167 return stat(s,st); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
168 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
169 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
170 static int compare(char **a, char **b){ |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
171 if((*a)[strlen(*a) - 1] == '/') { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
172 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
173 return strcmp(*b, *a) ; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
174 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
175 return 1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
176 } else { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
177 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
178 return -1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
179 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
180 return strcmp(*b, *a); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
181 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
182 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
183 |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
184 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
|
185 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
|
186 FILE *fp; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
187 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
|
188 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
189 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
|
190 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
191 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
192 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
|
193 if(!fp) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
194 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
195 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
196 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
|
197 *extensions = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
198 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
203 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
|
204 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
|
205 s--; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
206 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 *l++ = e; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
213 *l = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
214 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
215 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
216 fclose (fp); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
217 return extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
218 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
219 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
220 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
|
221 if (extensions) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
222 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
|
223 while (*l) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
224 free (*l++); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
225 free (extensions); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
226 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
227 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
228 |
25354
a4c4b56e933d
reverted r25323: deprecated by ulion's recent patches
ben
parents:
25320
diff
changeset
|
229 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
|
230 char **namelist, **tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
231 struct dirent *dp; |
8197 | 232 struct stat st; |
233 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
|
234 int path_fp; |
8197 | 235 char* p = NULL; |
236 list_entry_t* e; | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
237 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
|
238 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
|
239 char **extensions, **elem, *ext; |
8197 | 240 |
241 menu_list_init(menu); | |
242 | |
243 if(mpriv->dir) | |
244 free(mpriv->dir); | |
245 mpriv->dir = strdup(args); | |
246 if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title) | |
247 free(mpriv->p.title); | |
248 p = strstr(mpriv->title,"%p"); | |
249 | |
27086 | 250 mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0); |
8197 | 251 |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
252 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
|
253 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
|
254 return 0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
255 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
256 |
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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 } |
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
|
263 } |
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
|
264 |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
265 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
|
266 extensions = get_extensions(menu); |
8358
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 n=0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
269 while ((dp = readdir(dirp)) != NULL) { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
270 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
|
271 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
|
272 if (menu_chroot && !strcmp (dp->d_name,"..")) { |
26945
b105b2c1f8ae
Use size_t instead of int for a variable that is compared to the result
diego
parents:
25632
diff
changeset
|
273 size_t len = strlen (menu_chroot); |
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
|
274 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
|
275 && !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
|
276 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
|
277 } |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
278 if (mylstat(args,dp->d_name,&st)) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
279 continue; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
280 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
|
281 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
|
282 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
283 ext++; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
284 elem = extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
285 do { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
286 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
|
287 break; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
288 } while (*++elem); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
289 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
|
290 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
291 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
292 if(n%20 == 0){ // Get some more mem |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
293 if((tp = (char **) realloc(namelist, (n+20) * sizeof (char *))) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
294 == NULL) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
295 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
|
296 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
297 goto bailout; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
298 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
299 namelist=tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
300 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
301 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
302 namelist[n] = (char *) malloc(strlen(dp->d_name) + 2); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
303 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
|
304 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
|
305 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
306 goto bailout; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
307 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
308 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
309 strcpy(namelist[n], dp->d_name); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
310 if(S_ISDIR(st.st_mode)) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
311 strcat(namelist[n], "/"); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
312 n++; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
313 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
314 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
315 bailout: |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
316 free_extensions (extensions); |
16061 | 317 closedir(dirp); |
318 | |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
319 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
|
320 |
8197 | 321 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
|
322 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno)); |
8197 | 323 return 0; |
324 } | |
325 while(n--) { | |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
326 if((e = calloc(1,sizeof(list_entry_t))) != NULL){ |
8613 | 327 e->p.next = NULL; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
328 e->p.txt = strdup(namelist[n]); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
329 if(strchr(namelist[n], '/') != NULL) |
8197 | 330 e->d = 1; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
331 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
|
332 }else{ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
333 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
|
334 } |
8197 | 335 free(namelist[n]); |
336 } | |
337 free(namelist); | |
338 | |
339 return 1; | |
340 } | |
341 | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
342 static char *action; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
343 |
8197 | 344 static void read_cmd(menu_t* menu,int cmd) { |
345 switch(cmd) { | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
346 case MENU_CMD_LEFT: |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
347 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
|
348 case MENU_CMD_RIGHT: |
8197 | 349 case MENU_CMD_OK: { |
350 // Directory | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
351 if(mpriv->p.current->d && !mpriv->dir_action) { |
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
352 // Default action : open this dirctory ourself |
8197 | 353 int l = strlen(mpriv->dir); |
354 char *slash = NULL, *p = NULL; | |
355 if(strcmp(mpriv->p.current->p.txt,"../") == 0) { | |
356 if(l <= 1) break; | |
357 mpriv->dir[l-1] = '\0'; | |
358 slash = strrchr(mpriv->dir,'/'); | |
20505 | 359 #if defined(__MINGW32__) || defined(__CYGWIN__) |
360 if (!slash) | |
361 slash = strrchr(mpriv->dir,'\\'); | |
362 #endif | |
8197 | 363 if(!slash) break; |
364 slash[1] = '\0'; | |
365 p = strdup(mpriv->dir); | |
366 } else { | |
367 p = malloc(l + strlen(mpriv->p.current->p.txt) + 1); | |
368 sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt); | |
369 } | |
370 menu_list_uninit(menu,free_entry); | |
371 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
|
372 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_CantOpenDirectory,p); |
8197 | 373 menu->cl = 1; |
374 } | |
375 free(p); | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
376 } else { // File and directory dealt with action string. |
8197 | 377 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; |
378 char filename[fname_len]; | |
379 char *str; | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
380 char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; |
8197 | 381 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
27086 | 382 str = replace_path(action, filename,1); |
25505
8d329f7bbc3c
Remove redundant option 'auto-close' from cmdlist and filesel.
ulion
parents:
25502
diff
changeset
|
383 mp_input_parse_and_queue_cmds(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
384 if (str != action) |
8197 | 385 free(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
386 } |
8197 | 387 } break; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
388 case MENU_CMD_ACTION: { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
389 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
|
390 char filename[fname_len]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
391 char *str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
392 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
27086 | 393 str = replace_path(action, filename,1); |
25320
4fbf536cc033
Support to run multiple mplayer commands set in menu.conf
ulion
parents:
25311
diff
changeset
|
394 mp_input_parse_and_queue_cmds(str); |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
395 if(str != action) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
396 free(str); |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
397 } break; |
8197 | 398 default: |
399 menu_list_read_cmd(menu,cmd); | |
400 } | |
401 } | |
402 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
403 static int read_key(menu_t* menu,int c){ |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
404 char **str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
405 for (str=mpriv->actions; str && *str; str++) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
406 if (c == (*str)[0]) { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
407 action = &(*str)[2]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
408 read_cmd(menu,MENU_CMD_ACTION); |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
409 return 1; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
410 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25134
diff
changeset
|
411 if (menu_dflt_read_key(menu, c)) |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
412 return 1; |
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
413 return menu_list_jump_to_key(menu, c); |
8197 | 414 } |
415 | |
416 static void clos(menu_t* menu) { | |
417 menu_list_uninit(menu,free_entry); | |
418 free(mpriv->dir); | |
419 } | |
420 | |
421 static int open_fs(menu_t* menu, char* args) { | |
26970 | 422 char *path = mpriv->path; |
8197 | 423 int r = 0; |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
424 char wd[PATH_MAX+1], b[PATH_MAX+1]; |
8197 | 425 args = NULL; // Warning kill |
426 | |
427 menu->draw = menu_list_draw; | |
428 menu->read_cmd = read_cmd; | |
429 menu->read_key = read_key; | |
430 menu->close = clos; | |
431 | |
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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 |
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
|
437 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
|
438 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
|
439 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
|
440 path = malloc(st.st_size+1); |
26960 | 441 path[st.st_size] = '\0'; |
26970 | 442 if (!((read(path_fp, path, st.st_size) == st.st_size) && path[0] == '/' |
443 && !stat(path, &st) && S_ISDIR(st.st_mode))) { | |
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
|
444 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
|
445 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
|
446 } |
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 } |
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
|
448 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
|
449 } |
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
|
450 } |
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
|
451 } |
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
|
452 |
8197 | 453 getcwd(wd,PATH_MAX); |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
454 if (!path || path[0] == '\0') { |
25632 | 455 #if 0 |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
456 char *slash = NULL; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
457 if (filename && !strstr(filename, "://") && (path=realpath(filename, b))) { |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
458 slash = strrchr(path, '/'); |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
459 #if defined(__MINGW32__) || defined(__CYGWIN__) |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
460 // FIXME: Do we need and can convert all '\\' in path to '/' on win32? |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
461 if (!slash) |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
462 slash = strrchr(path, '\\'); |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
463 #endif |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
464 } |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
465 if (slash) |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
466 slash[1] = '\0'; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
467 else |
25632 | 468 #endif |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
469 path = wd; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
470 } |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
471 if (path[0] != '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
472 if(path[strlen(path)-1] != '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
473 snprintf(b,sizeof(b),"%s/%s/",wd,path); |
8197 | 474 else |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
475 snprintf(b,sizeof(b),"%s/%s",wd,path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
476 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
477 } else if (path[strlen(path)-1]!='/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
478 sprintf(b,"%s/",path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
479 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
480 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
481 if (menu_chroot && menu_chroot[0] == '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
482 int l = strlen(menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
483 if (l > 0 && menu_chroot[l-1] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
484 --l; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
485 if (strncmp(menu_chroot, path, l) || (path[l] != '\0' && path[l] != '/')) { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
486 if (menu_chroot[l] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
487 path = menu_chroot; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
488 else { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
489 sprintf(b,"%s/",menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
490 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
491 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
492 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
493 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
494 r = open_dir(menu,path); |
8197 | 495 |
496 return r; | |
497 } | |
498 | |
499 const menu_info_t menu_info_filesel = { | |
500 "File seletor menu", | |
501 "filesel", | |
502 "Albeu", | |
503 "", | |
504 { | |
505 "fs_cfg", | |
506 sizeof(struct menu_priv_s), | |
507 &cfg_dflt, | |
508 cfg_fields | |
509 }, | |
510 open_fs | |
511 }; |