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