Mercurial > mplayer.hg
annotate gui/dialog/fileselect.c @ 36442:ee46a4670903
Query codec support first.
The filter chain query is more complex.
In addition this for the moment avoids a vo_vdpau bug
where the query function destroys the old decoder.
author | reimar |
---|---|
date | Sun, 08 Dec 2013 17:52:23 +0000 |
parents | 236d31040749 |
children | e5ce1d3bd82c |
rev | line source |
---|---|
33572 | 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 */ | |
18 | |
36014 | 19 #include <glob.h> |
33572 | 20 #include <stdlib.h> |
21 #include <string.h> | |
35903 | 22 #include <strings.h> |
36032 | 23 #include <unistd.h> |
33572 | 24 #include <sys/stat.h> |
25 | |
36014 | 26 #include "fileselect.h" |
27 #include "dialog.h" | |
28 #include "preferences.h" | |
29 #include "tools.h" | |
35526 | 30 #include "pixmaps/dir.xpm" |
31 #include "pixmaps/file.xpm" | |
36014 | 32 #include "pixmaps/up.xpm" |
36032 | 33 #include "gui/interface.h" |
35525 | 34 #include "gui/app/app.h" |
36014 | 35 #include "gui/app/cfg.h" |
35525 | 36 #include "gui/app/gui.h" |
36014 | 37 #include "gui/ui/actions.h" |
35350 | 38 #include "gui/util/list.h" |
33739 | 39 #include "gui/util/mem.h" |
33737 | 40 #include "gui/util/string.h" |
33572 | 41 |
36011 | 42 #define CFG_OLD_FILESELECT |
35926 | 43 #include "gui/app/cfg-old.c" |
44 | |
36014 | 45 #include "config.h" |
46 #include "help_mp.h" | |
36032 | 47 #include "mpcommon.h" |
36014 | 48 #include "libavutil/common.h" |
49 #include "stream/stream.h" | |
50 | |
36015 | 51 #ifdef __linux__ |
52 char *get_current_dir_name(void); | |
33572 | 53 #else |
36015 | 54 #include <limits.h> |
55 #define get_current_dir_name() getcwd(NULL, PATH_MAX) | |
33572 | 56 #endif |
57 | |
36045 | 58 const char *fsSelectedFile; |
36046 | 59 const char *fsThisDir = "."; |
60 const gchar *fsFilter = "*"; | |
33572 | 61 |
36045 | 62 int fsType; |
33572 | 63 |
36012 | 64 static gint fsCurrFNameListSelected, fsLastFNameListSelected; |
34364 | 65 |
36012 | 66 char *fsVideoAudioFilterNames[][2] = { |
67 { MSGTR_Filter_AVIFiles, "*.avi" }, | |
68 { MSGTR_Filter_DivXFiles, "*.divx" }, | |
69 { MSGTR_Filter_FlashVideo, "*.flv" }, | |
70 { MSGTR_Filter_MP3Files, "*.mp3" }, | |
71 { MSGTR_Filter_MP4Files, "*.aac,*.f4a,*.f4b,*.f4v,*.m4a,*.m4b,*.m4v,*.mp4" }, | |
72 { MSGTR_Filter_MPEGFiles, "*.m1v,*.m2v,*.mp2,*.mpe,*.mpeg,*.mpg,*.mpga,*.vdr,*.vob" }, | |
73 { MSGTR_Filter_MP2TS, "*.bdm,*.bdmv,*.clpi,*.cpi,*.m2t,*.m2ts,*.mpl,*.mpls,*.mts,*.rec,*.trp,*.ts,*.ty" }, | |
74 { MSGTR_Filter_MatroskaMedia, "*.mka,*.mkv" }, | |
75 { MSGTR_Filter_OGGMedia, "*.oga,*.ogg,*.ogm,*.ogv,*.ogx,*.spx" }, | |
76 { MSGTR_Filter_QTMedia, "*.moov,*.mov,*.qt,*.qtvr" }, | |
77 { MSGTR_Filter_RNMedia, "*.ra,*.rm,*.rmvb,*.rv" }, | |
78 { MSGTR_Filter_VideoCDImages, "*.bin" }, | |
79 { MSGTR_Filter_WAVFiles, "*.wav" }, | |
80 { MSGTR_Filter_WindowsMedia, "*.asf,*.wma,*.wmv" }, | |
81 { MSGTR_Filter_Playlists, "*.asx,*.m3u,*.m3u8,*.nsc,*.pls,*.ram,*.smi,*.smil,*.sml,*.vlc,*.wax,*.wmx,*.wvx" }, | |
82 { MSGTR_Filter_AllAudioFiles, "*.aac,*.ac3,*.aif,*.aifc,*.aiff,*.amr,*.ape,*.au,*.awb,*.cdg,*.f4a,*.f4b,*.flac,*.m4a,*.m4b,*.mka,*.mp+,*.mp2,*.mp3,*.mpc,*.mpga,*.mpp,*.nsa,*.oga,*.ogg,*.pcm,*.qcp,*.ra,*.snd,*.spx,*.tak,*.voc,*.vqf,*.w64,*.wav,*.wma,*.wv,*.wvp" }, | |
83 { MSGTR_Filter_AllVideoFiles, "*.264,*.3g2,*.3ga,*.3gp,*.3gp2,*.3gpp,*.3gpp2,*.asf,*.avi,*.bdm,*.bdmv,*.bin,*.clpi,*.cpi,*.cpk,*.divx,*.dv,*.f4v,*.flc,*.fli,*.flv,*.m1v,*.m2t,*.m2ts,*.m2v,*.m4v,*.mjpg,*.mkv,*.moov,*.mov,*.mp2,*.mp4,*.mpe,*.mpeg,*.mpg,*.mpl,*.mpls,*.mts,*.mxf,*.nsv,*.nuv,*.ogg,*.ogm,*.ogv,*.ogx,*.pva,*.qt,*.qtvr,*.rec,*.rm,*.rmvb,*.roq,*.rv,*.spl,*.str,*.swf,*.trp,*.ts,*.ty,*.vdr,*.viv,*.vivo,*.vob,*.webm,*.wmv,*.y4m" }, | |
84 { MSGTR_Filter_AllFiles, "*" }, | |
85 { NULL, NULL } | |
86 }; | |
35985 | 87 int fsLastVideoAudioFilterSelected = -1; |
33572 | 88 |
36012 | 89 char *fsSubtitleFilterNames[][2] = { |
90 { "AQTitle (*.aqt)", "*.aqt" }, | |
91 { "Advanced SubStation Alpha (*.ass)", "*.ass" }, | |
92 { "JACOSub (*.jss) ", "*.jss" }, | |
93 { "RealText (*.rt) ", "*.rt" }, | |
94 { "SAMI (*.smi)", "*.smi" }, | |
95 { "SubRip (*.srt)", "*.srt" }, | |
96 { "SubStation Alpha (*.ssa)", "*.ssa" }, | |
97 { "MicroDVD (*.sub)", "*.sub" }, | |
98 { "Text (*.txt)", "*.txt" }, | |
99 { MSGTR_Filter_UTF8Subtitles, "*.utf,*.utf-8,*.utf8" }, | |
100 { MSGTR_Filter_AllSubtitles, "*.aqt,*.ass,*.jss,*.rt,*.smi,*.srt,*.ssa,*.sub,*.txt,*.utf" }, | |
101 { MSGTR_Filter_AllFiles, "*" }, | |
102 { NULL, NULL } | |
103 }; | |
33572 | 104 int fsLastSubtitleFilterSelected = -1; |
105 | |
36012 | 106 char *fsOtherFilterNames[][2] = { |
107 { MSGTR_Filter_AllFiles, "*" }, | |
108 { NULL, NULL } | |
109 }; | |
33572 | 110 |
36012 | 111 char *fsAudioFileNames[][2] = { |
112 { MSGTR_Filter_DDRawAudio, "*.ac3,*.pcm" }, | |
113 { MSGTR_Filter_MPEGAudio, "*.aac,*.f4a,*.m4a,*.mp2,*.mp3,*.mpga" }, | |
114 { MSGTR_Filter_MatroskaAudio, "*.mka" }, | |
115 { MSGTR_Filter_OGGAudio, "*.oga,*.ogg,*.spx" }, | |
116 { MSGTR_Filter_WAVAudio, "*.wav" }, | |
117 { MSGTR_Filter_WMAAudio, "*.wma" }, | |
118 { MSGTR_Filter_AllAudioFiles, "*.aac,*.ac3,*.f4a,*.m4a,*.mka,*.mp2,*.mp3,*.mpga,*.oga,*.ogg,*.pcm,*.spx,*.wav,*.wma" }, | |
119 { MSGTR_Filter_AllFiles, "*" }, | |
120 { NULL, NULL } | |
121 }; | |
33572 | 122 int fsLastAudioFilterSelected = -1; |
123 | |
36012 | 124 char *fsFontFileNames[][2] = { |
33572 | 125 #ifdef CONFIG_FREETYPE |
36012 | 126 { MSGTR_Filter_TTF, "*.ttf" }, |
127 { MSGTR_Filter_Type1, "*.pfb" }, | |
128 { MSGTR_Filter_AllFonts, "*.pfb,*.ttf" }, | |
33572 | 129 #else |
36012 | 130 { MSGTR_Filter_FontFiles, "*.desc" }, |
33572 | 131 #endif |
36012 | 132 { MSGTR_Filter_AllFiles, "*" }, |
133 { NULL, NULL } | |
134 }; | |
33572 | 135 int fsLastFontFilterSelected = -1; |
136 | |
36012 | 137 GtkWidget *fsFileNamesList; |
138 GtkWidget *fsFNameList; | |
36045 | 139 GtkWidget *FileSelector; |
36012 | 140 GdkColormap *fsColorMap; |
141 GtkWidget *fsOk; | |
142 GtkWidget *fsUp; | |
143 GtkWidget *fsCancel; | |
144 GtkWidget *fsCombo4; | |
145 GtkWidget *fsPathCombo; | |
36045 | 146 GList *fsList_items; |
147 GList *fsTopList_items; | |
36012 | 148 GHashTable *fsPathTable; |
149 GtkWidget *List; | |
150 GtkWidget *fsFilterCombo; | |
151 | |
152 GtkStyle *style; | |
153 GdkPixmap *dpixmap; | |
154 GdkPixmap *fpixmap; | |
155 GdkBitmap *dmask; | |
156 GdkBitmap *fmask; | |
33572 | 157 |
36016 | 158 static void fs_PersistantHistory(char *subject) |
159 { | |
160 unsigned int i; | |
161 char *entry; | |
162 | |
163 if (!subject) | |
164 return; | |
165 | |
166 for (i = 0; i < FF_ARRAY_ELEMS(fsHistory); i++) | |
167 if (gstrcmp(fsHistory[i], subject) == 0) { | |
168 entry = fsHistory[i]; | |
169 break; | |
170 } | |
171 | |
172 if (i == FF_ARRAY_ELEMS(fsHistory)) { | |
173 entry = strdup(subject); | |
174 free(fsHistory[--i]); | |
175 } | |
176 | |
177 for (; i; i--) | |
178 fsHistory[i] = fsHistory[i - 1]; | |
179 | |
180 fsHistory[0] = entry; | |
181 } | |
182 | |
36012 | 183 static gchar *get_current_dir_name_utf8(void) |
184 { | |
185 char *dir; | |
186 gchar *utf8dir; | |
187 | |
188 dir = get_current_dir_name(); | |
189 utf8dir = g_filename_display_name(dir); | |
190 free(dir); | |
191 | |
192 return utf8dir; | |
193 } | |
33572 | 194 |
36016 | 195 static GList *fs_AddPath(GList *list, gpointer data, GtkPositionType pos) |
196 { | |
197 if (!g_list_find_custom(list, data, (GCompareFunc)strcmp)) { | |
198 if (pos == GTK_POS_TOP) | |
199 list = g_list_prepend(list, data); | |
200 else | |
201 list = g_list_append(list, data); | |
202 } | |
203 | |
204 return list; | |
205 } | |
206 | |
207 static void fs_AddPathUtf8(const char *name, GtkPositionType pos) | |
208 { | |
209 gchar *utf8name; | |
210 | |
211 utf8name = g_filename_display_name(name); | |
212 fsTopList_items = fs_AddPath(fsTopList_items, utf8name, pos); | |
213 g_hash_table_insert(fsPathTable, strdup(utf8name), strdup(name)); | |
214 } | |
215 | |
36012 | 216 static void clist_append_fname(GtkWidget *list, char *fname, |
217 GdkPixmap *pixmap, GdkPixmap *mask) | |
33572 | 218 { |
36012 | 219 gint pos; |
220 gchar *str[2]; | |
221 | |
222 str[0] = NULL; | |
223 str[1] = g_filename_display_name(fname); | |
224 pos = gtk_clist_append(GTK_CLIST(list), str); | |
225 gtk_clist_set_row_data_full(GTK_CLIST(list), pos, strdup(fname), free); | |
226 gtk_clist_set_pixmap(GTK_CLIST(list), pos, 0, pixmap, mask); | |
227 g_free(str[1]); | |
33572 | 228 } |
229 | |
36012 | 230 static void CheckDir(GtkWidget *list) |
231 { | |
232 struct stat fs; | |
233 unsigned int i, j, fn; | |
234 glob_t gg; | |
235 gchar *filter, **fext; | |
236 | |
237 if (!fsFilter[0]) | |
238 return; | |
239 | |
240 gtk_widget_hide(list); | |
241 gtk_clist_clear(GTK_CLIST(list)); | |
242 | |
243 clist_append_fname(list, ".", dpixmap, dmask); | |
244 clist_append_fname(list, "..", dpixmap, dmask); | |
245 | |
246 glob("*", 0, NULL, &gg); | |
247 | |
248 for (i = 0; i < gg.gl_pathc; i++) { | |
249 if ((stat(gg.gl_pathv[i], &fs) != 0) || !S_ISDIR(fs.st_mode)) | |
250 continue; | |
251 | |
252 clist_append_fname(list, gg.gl_pathv[i], dpixmap, dmask); | |
253 } | |
254 | |
255 for (fn = 1, i = 0; fsFilter[i]; i++) | |
256 if (fsFilter[i] == ',') | |
257 fn++; | |
258 | |
259 filter = g_strdup(fsFilter); | |
260 fext = calloc(fn, sizeof(gchar *)); | |
261 | |
262 if (filter && fext) { | |
263 for (j = 0, i = 0; filter[i]; i++) { | |
264 if (filter[i] == '.') | |
265 fext[j] = filter + i; | |
266 | |
267 if (filter[i] == ',') { | |
268 filter[i] = 0; | |
269 j++; | |
270 } | |
271 } | |
272 | |
273 for (i = 0; i < gg.gl_pathc; i++) { | |
274 char *ext; | |
275 | |
276 if ((stat(gg.gl_pathv[i], &fs) != 0) || S_ISDIR(fs.st_mode)) | |
277 continue; | |
278 | |
279 ext = strrchr(gg.gl_pathv[i], '.'); | |
280 | |
281 if (ext || !fext[0]) { | |
282 for (j = 0; j < fn; j++) { | |
283 if (fext[j] == NULL || strcasecmp(fext[j], ext) == 0) { | |
284 clist_append_fname(list, gg.gl_pathv[i], fpixmap, fmask); | |
285 break; | |
286 } | |
287 } | |
288 } | |
289 } | |
290 } | |
291 | |
292 free(fext); | |
293 g_free(filter); | |
294 globfree(&gg); | |
295 | |
296 gtk_clist_set_column_width(GTK_CLIST(list), 0, 17); | |
297 gtk_widget_show(list); | |
33572 | 298 } |
299 | |
34684 | 300 /* ----------------------------------------------- */ |
33572 | 301 |
36012 | 302 static void fs_fsFilterCombo_changed(GtkEditable *editable, |
303 gpointer user_data) | |
33572 | 304 { |
36012 | 305 const char *str; |
306 int i; | |
307 | |
308 (void)editable; | |
33572 | 309 |
36012 | 310 str = gtk_entry_get_text(GTK_ENTRY(user_data)); |
36010 | 311 |
36012 | 312 switch (fsType) { |
313 case FILESELECT_VIDEO_AUDIO: | |
33572 | 314 |
36012 | 315 for (i = 0; fsVideoAudioFilterNames[i][0]; i++) |
316 if (!strcmp(str, fsVideoAudioFilterNames[i][0])) { | |
317 fsFilter = fsVideoAudioFilterNames[i][1]; | |
318 fsLastVideoAudioFilterSelected = i; | |
319 break; | |
320 } | |
321 | |
322 break; | |
323 | |
324 case FILESELECT_SUBTITLE: | |
325 | |
326 for (i = 0; fsSubtitleFilterNames[i][0]; i++) | |
327 if (!strcmp(str, fsSubtitleFilterNames[i][0])) { | |
328 fsFilter = fsSubtitleFilterNames[i][1]; | |
329 fsLastSubtitleFilterSelected = i; | |
330 break; | |
331 } | |
332 | |
333 break; | |
334 | |
33776 | 335 /* case fsOtherSelector: |
36012 | 336 * for( i=0;fsOtherFilterNames[i][0];i++ ) |
337 * if( !strcmp( str,fsOtherFilterNames[i][0] ) ) | |
338 * { fsFilter=fsOtherFilterNames[i][1]; break; } | |
339 * break;*/ | |
340 case FILESELECT_AUDIO: | |
341 | |
342 for (i = 0; fsAudioFileNames[i][0]; i++) | |
343 if (!strcmp(str, fsAudioFileNames[i][0])) { | |
344 fsFilter = fsAudioFileNames[i][1]; | |
345 fsLastAudioFilterSelected = i; | |
346 break; | |
347 } | |
348 | |
349 break; | |
33572 | 350 |
36012 | 351 case FILESELECT_FONT: |
352 | |
353 for (i = 0; fsFontFileNames[i][0]; i++) | |
354 if (!strcmp(str, fsFontFileNames[i][0])) { | |
355 fsFilter = fsFontFileNames[i][1]; | |
356 fsLastFontFilterSelected = i; | |
357 break; | |
358 } | |
33572 | 359 |
36012 | 360 break; |
361 | |
362 default: | |
36010 | 363 |
36012 | 364 return; |
365 } | |
366 | |
367 CheckDir(fsFNameList); | |
33572 | 368 } |
369 | |
36016 | 370 static void fs_fsPathCombo_changed(GtkEditable *editable, |
371 gpointer user_data) | |
372 { | |
373 const unsigned char *str; | |
374 gchar *dirname; | |
375 | |
376 (void)editable; | |
377 | |
378 str = gtk_entry_get_text(GTK_ENTRY(user_data)); | |
379 dirname = g_hash_table_lookup(fsPathTable, str); | |
380 | |
381 if (chdir(dirname ? (const unsigned char *)dirname : str) != -1) | |
382 CheckDir(fsFNameList); | |
383 } | |
384 | |
385 static gboolean fs_fsFNameList_event(GtkWidget *widget, | |
386 GdkEvent *event, | |
387 gpointer user_data) | |
33572 | 388 { |
36016 | 389 GdkEventButton *bevent; |
390 gint row, col; | |
391 | |
392 (void)user_data; | |
393 | |
394 bevent = (GdkEventButton *)event; | |
395 | |
396 if (event->type == GDK_BUTTON_RELEASE && bevent->button == 2) { | |
397 if (gtk_clist_get_selection_info(GTK_CLIST(widget), bevent->x, bevent->y, &row, &col)) { | |
398 fsSelectedFile = gtk_clist_get_row_data(GTK_CLIST(widget), row); | |
399 gtk_button_released(GTK_BUTTON(fsOk)); | |
36012 | 400 |
36016 | 401 return TRUE; |
402 } | |
403 } | |
404 | |
405 return FALSE; | |
406 } | |
35934 | 407 |
36016 | 408 static void fs_fsFNameList_select_row(GtkCList *clist, gint row, gint column, |
409 GdkEvent *event, gpointer user_data) | |
410 { | |
411 (void)column; | |
412 (void)user_data; | |
36012 | 413 |
36016 | 414 fsCurrFNameListSelected = row; |
415 fsSelectedFile = gtk_clist_get_row_data(clist, row); | |
416 | |
417 if (event && event->type == GDK_BUTTON_PRESS) | |
418 gtk_button_released(GTK_BUTTON(fsOk)); | |
36012 | 419 } |
36010 | 420 |
36012 | 421 static void fs_Up_released(GtkButton *button, gpointer user_data) |
422 { | |
423 gchar *utf8dir; | |
424 | |
425 (void)button; | |
426 (void)user_data; | |
427 | |
428 chdir(".."); | |
429 CheckDir(fsFNameList); | |
430 utf8dir = get_current_dir_name_utf8(); | |
431 gtk_entry_set_text(GTK_ENTRY(fsPathCombo), utf8dir); | |
432 g_free(utf8dir); | |
433 fsSelectedFile = fsThisDir; | |
434 | |
435 return; | |
33572 | 436 } |
437 | |
36012 | 438 static void fs_Cancel_released(GtkButton *button, gpointer user_data) |
36001 | 439 { |
36012 | 440 (void)button; |
441 (void)user_data; | |
36010 | 442 |
36012 | 443 gtk_widget_destroy(FileSelector); |
444 fsLastFNameListSelected = fsCurrFNameListSelected; | |
36001 | 445 } |
446 | |
36012 | 447 static void fs_Ok_released(GtkButton *button, gpointer user_data) |
33572 | 448 { |
36012 | 449 char *fsSelectedDirectory; |
450 int l; | |
451 struct stat fs; | |
452 gchar *selected; | |
33572 | 453 |
36012 | 454 (void)button; |
455 (void)user_data; | |
456 | |
457 if ((stat(fsSelectedFile, &fs) == 0) && S_ISDIR(fs.st_mode)) { | |
458 gchar *utf8dir; | |
459 | |
460 if (chdir(fsSelectedFile) != 0) | |
461 return; | |
36010 | 462 |
36012 | 463 CheckDir(fsFNameList); |
464 utf8dir = get_current_dir_name_utf8(); | |
465 gtk_entry_set_text(GTK_ENTRY(fsPathCombo), utf8dir); | |
466 g_free(utf8dir); | |
467 gtk_widget_grab_focus(fsFNameList); | |
468 fsSelectedFile = fsThisDir; | |
469 | |
470 return; | |
471 } | |
472 | |
473 fsSelectedDirectory = get_current_dir_name(); | |
33572 | 474 |
36012 | 475 switch (fsType) { |
476 case FILESELECT_VIDEO_AUDIO: | |
477 | |
478 for (l = 0; fsVideoAudioFilterNames[l][0]; l++) | |
479 if (strcmp(fsVideoAudioFilterNames[l][0], MSGTR_Filter_Playlists) == 0) | |
480 break; | |
481 | |
482 uiSetFile(fsSelectedDirectory, fsSelectedFile, fsLastVideoAudioFilterSelected == l ? STREAMTYPE_PLAYLIST : STREAMTYPE_FILE); | |
483 selected = g_strconcat(fsSelectedDirectory, "/", fsSelectedFile, NULL); | |
484 | |
485 if (selected) { | |
35352 | 486 listMgr(PLAYLIST_DELETE, 0); |
35350 | 487 add_to_gui_playlist(selected, PLAYLIST_ITEM_APPEND); |
35348 | 488 g_free(selected); |
36012 | 489 } |
490 | |
491 guiInfo.NewPlay = GUI_FILE_NEW; | |
492 sub_fps = 0; | |
493 fs_PersistantHistory(fsSelectedDirectory); | |
494 break; | |
495 | |
496 case FILESELECT_SUBTITLE: | |
497 setddup(&guiInfo.SubtitleFilename, fsSelectedDirectory, fsSelectedFile); | |
498 mplayerLoadSubtitle(guiInfo.SubtitleFilename); | |
499 break; | |
500 | |
33776 | 501 /* case fsOtherSelector: |
36012 | 502 * setddup( &guiInfo.Othername,fsSelectedDirectory,fsSelectedFile ); |
503 * break;*/ | |
504 case FILESELECT_AUDIO: | |
505 setddup(&guiInfo.AudioFilename, fsSelectedDirectory, fsSelectedFile); | |
506 break; | |
507 | |
508 case FILESELECT_FONT: | |
509 setddup(&font_name, fsSelectedDirectory, fsSelectedFile); | |
510 mplayerLoadFont(); | |
511 | |
512 if (Preferences) | |
513 gtk_entry_set_text(GTK_ENTRY(prEFontName), font_name); | |
33572 | 514 |
36012 | 515 break; |
516 } | |
517 | |
518 free(fsSelectedDirectory); | |
33572 | 519 |
36012 | 520 fs_Cancel_released(NULL, NULL); |
35931 | 521 |
36012 | 522 if (uiLoadPlay) { |
523 uiLoadPlay = False; | |
524 uiEvent(evPlay, 0); | |
525 } else | |
526 gui(GUI_SET_STATE, (void *)GUI_STOP); | |
33572 | 527 } |
528 | |
36100
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
529 /** |
36103 | 530 * @brief Handle the escape, return and backspace key depending on the |
531 * @a widget it has been pressed on. | |
36100
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
532 * |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
533 * @param widget object which received the signal |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
534 * @param event GdkEventKey which triggered the signal |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
535 * @param user_data user data set when the signal handler was connected |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
536 * |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
537 * @return TRUE to stop other handlers from being invoked for the event or |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
538 * FALSE to propagate the event further |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
539 */ |
4a8ab984a69e
Rename on_FileSelect_key_release_event() fs_key_release_event().
ib
parents:
36099
diff
changeset
|
540 static gboolean fs_key_release_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
33572 | 541 { |
36012 | 542 (void)user_data; |
36010 | 543 |
36098 | 544 switch (event->key.keyval) { |
545 case GDK_Escape: | |
36097 | 546 |
547 if (GTK_IS_SCROLLED_WINDOW(widget)) | |
36012 | 548 gtk_button_released(GTK_BUTTON(fsCancel)); |
36097 | 549 |
36098 | 550 break; |
36012 | 551 |
36098 | 552 case GDK_Return: |
36097 | 553 |
554 if (GTK_IS_SCROLLED_WINDOW(widget)) | |
36012 | 555 gtk_button_released(GTK_BUTTON(fsOk)); |
36097 | 556 else if (GTK_IS_BUTTON(widget)) |
557 gtk_button_released(GTK_BUTTON(widget)); | |
36099 | 558 else if (GTK_IS_ENTRY(widget)) |
559 gtk_widget_grab_focus(fsFNameList); | |
36097 | 560 |
36098 | 561 break; |
36012 | 562 |
36098 | 563 case GDK_BackSpace: |
36097 | 564 |
565 if (GTK_IS_SCROLLED_WINDOW(widget)) { | |
36012 | 566 gtk_button_released(GTK_BUTTON(fsUp)); |
567 gtk_widget_grab_focus(fsFNameList); | |
36097 | 568 } |
569 | |
36098 | 570 break; |
36012 | 571 } |
572 | |
573 return FALSE; | |
33572 | 574 } |
575 | |
36012 | 576 static void fs_Destroy(void) |
33572 | 577 { |
36012 | 578 gtk_widget_destroyed(FileSelector, &FileSelector); |
35959 | 579 |
36012 | 580 g_hash_table_destroy(fsPathTable); |
35959 | 581 |
36012 | 582 g_list_foreach(fsTopList_items, (GFunc)g_free, NULL); |
583 g_list_free(fsTopList_items); | |
584 fsTopList_items = NULL; | |
33572 | 585 } |
586 | |
36012 | 587 static GtkWidget *CreateFileSelect(void) |
33572 | 588 { |
36012 | 589 GtkWidget *vbox4; |
590 GtkWidget *hbox4; | |
591 GtkWidget *vseparator1; | |
592 GtkWidget *hbox6; | |
593 GtkWidget *fsFNameListWindow; | |
594 GtkWidget *hbuttonbox3; | |
595 | |
596 GtkWidget *uppixmapwid; | |
597 GdkPixmap *uppixmap; | |
598 GdkBitmap *upmask; | |
599 GtkStyle *upstyle; | |
33572 | 600 |
36012 | 601 FileSelector = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
602 gtk_widget_set_usize(FileSelector, 512, 300); | |
603 gtk_widget_set_events(FileSelector, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK); | |
604 gtk_window_set_title(GTK_WINDOW(FileSelector), MSGTR_FileSelect); | |
605 gtk_window_set_position(GTK_WINDOW(FileSelector), GTK_WIN_POS_CENTER); | |
36055 | 606 gtk_window_set_wmclass(GTK_WINDOW(FileSelector), "FileSelector", MPlayer); |
36012 | 607 fsColorMap = gdk_colormap_get_system(); |
33572 | 608 |
36012 | 609 gtk_widget_realize(FileSelector); |
610 gtkAddIcon(FileSelector); | |
33572 | 611 |
36012 | 612 style = gtk_widget_get_style(FileSelector); |
613 dpixmap = gdk_pixmap_colormap_create_from_xpm_d(FileSelector->window, fsColorMap, &dmask, &style->bg[GTK_STATE_NORMAL], (gchar **)dir_xpm); | |
614 fpixmap = gdk_pixmap_colormap_create_from_xpm_d(FileSelector->window, fsColorMap, &fmask, &style->bg[GTK_STATE_NORMAL], (gchar **)file_xpm); | |
33572 | 615 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
616 vbox4 = gtkAddVBox(gtkAddDialogFrame(FileSelector), 0); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
617 hbox4 = gtkAddHBox(vbox4, 1); |
33572 | 618 |
36012 | 619 fsCombo4 = gtk_combo_new(); |
620 gtk_widget_show(fsCombo4); | |
621 gtk_box_pack_start(GTK_BOX(hbox4), fsCombo4, TRUE, TRUE, 0); | |
622 gtk_widget_set_usize(fsCombo4, -2, 20); | |
33572 | 623 |
36012 | 624 fsPathCombo = GTK_COMBO(fsCombo4)->entry; |
625 gtk_widget_show(fsPathCombo); | |
626 gtk_widget_set_usize(fsPathCombo, -2, 20); | |
33572 | 627 |
36012 | 628 vseparator1 = gtk_vseparator_new(); |
629 gtk_widget_show(vseparator1); | |
630 gtk_box_pack_start(GTK_BOX(hbox4), vseparator1, FALSE, TRUE, 0); | |
631 gtk_widget_set_usize(vseparator1, 7, 20); | |
33572 | 632 |
36012 | 633 upstyle = gtk_widget_get_style(FileSelector); |
634 uppixmap = gdk_pixmap_colormap_create_from_xpm_d(FileSelector->window, fsColorMap, &upmask, &upstyle->bg[GTK_STATE_NORMAL], (gchar **)up_xpm); | |
635 uppixmapwid = gtk_pixmap_new(uppixmap, upmask); | |
636 gtk_widget_show(uppixmapwid); | |
33572 | 637 |
36012 | 638 fsUp = gtk_button_new(); |
639 gtk_container_add(GTK_CONTAINER(fsUp), uppixmapwid); | |
640 gtk_widget_show(fsUp); | |
641 gtk_box_pack_start(GTK_BOX(hbox4), fsUp, FALSE, FALSE, 0); | |
642 gtk_widget_set_usize(fsUp, 65, 15); | |
33572 | 643 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
644 gtkAddHSeparator(vbox4); |
33572 | 645 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
646 hbox6 = gtkAddHBox(NULL, 0); |
36012 | 647 gtk_box_pack_start(GTK_BOX(vbox4), hbox6, TRUE, TRUE, 0); |
33572 | 648 |
36012 | 649 fsFNameListWindow = gtk_scrolled_window_new(NULL, NULL); |
650 gtk_widget_show(fsFNameListWindow); | |
651 gtk_box_pack_start(GTK_BOX(hbox6), fsFNameListWindow, TRUE, TRUE, 0); | |
652 gtk_widget_set_usize(fsFNameListWindow, -2, 145); | |
653 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(fsFNameListWindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
33572 | 654 |
36012 | 655 fsFNameList = gtk_clist_new(2); |
656 gtk_container_add(GTK_CONTAINER(fsFNameListWindow), fsFNameList); | |
657 gtk_clist_set_column_width(GTK_CLIST(fsFNameList), 0, 80); | |
658 gtk_clist_set_selection_mode(GTK_CLIST(fsFNameList), GTK_SELECTION_BROWSE); | |
659 gtk_clist_column_titles_hide(GTK_CLIST(fsFNameList)); | |
660 gtk_clist_set_shadow_type(GTK_CLIST(fsFNameList), GTK_SHADOW_ETCHED_OUT); | |
33572 | 661 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
662 gtkAddHSeparator(vbox4); |
33572 | 663 |
36012 | 664 List = gtk_combo_new(); |
665 gtk_widget_ref(List); | |
666 gtk_object_set_data_full(GTK_OBJECT(FileSelector), "List", List, (GtkDestroyNotify)gtk_widget_unref); | |
667 gtk_widget_show(List); | |
668 gtk_box_pack_start(GTK_BOX(vbox4), List, FALSE, FALSE, 0); | |
669 gtk_widget_set_usize(List, -2, 20); | |
33572 | 670 |
36012 | 671 fsFilterCombo = GTK_COMBO(List)->entry; |
672 gtk_widget_show(fsFilterCombo); | |
673 gtk_entry_set_editable(GTK_ENTRY(fsFilterCombo), FALSE); | |
674 gtk_widget_set_usize(fsFilterCombo, -2, 20); | |
33572 | 675 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
676 gtkAddHSeparator(vbox4); |
33572 | 677 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
678 hbuttonbox3 = gtkAddHButtonBox(vbox4); |
36012 | 679 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox3), GTK_BUTTONBOX_END); |
680 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox3), 10); | |
33572 | 681 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
682 fsOk = gtkAddButton(MSGTR_Ok, hbuttonbox3); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
683 fsCancel = gtkAddButton(MSGTR_Cancel, hbuttonbox3); |
33572 | 684 |
36012 | 685 gtk_signal_connect(GTK_OBJECT(FileSelector), "destroy", GTK_SIGNAL_FUNC(fs_Destroy), NULL); |
36101 | 686 gtk_signal_connect(GTK_OBJECT(fsFNameListWindow), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
33572 | 687 |
36012 | 688 gtk_signal_connect(GTK_OBJECT(fsFilterCombo), "changed", GTK_SIGNAL_FUNC(fs_fsFilterCombo_changed), fsFilterCombo); |
36101 | 689 gtk_signal_connect(GTK_OBJECT(fsFilterCombo), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
36012 | 690 gtk_signal_connect(GTK_OBJECT(fsPathCombo), "changed", GTK_SIGNAL_FUNC(fs_fsPathCombo_changed), fsPathCombo); |
36101 | 691 gtk_signal_connect(GTK_OBJECT(fsPathCombo), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
36012 | 692 gtk_signal_connect(GTK_OBJECT(fsUp), "released", GTK_SIGNAL_FUNC(fs_Up_released), fsFNameList); |
36101 | 693 gtk_signal_connect(GTK_OBJECT(fsUp), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
36012 | 694 gtk_signal_connect(GTK_OBJECT(fsOk), "released", GTK_SIGNAL_FUNC(fs_Ok_released), fsCombo4); |
36101 | 695 gtk_signal_connect(GTK_OBJECT(fsOk), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
36012 | 696 gtk_signal_connect(GTK_OBJECT(fsCancel), "released", GTK_SIGNAL_FUNC(fs_Cancel_released), NULL); |
36101 | 697 gtk_signal_connect(GTK_OBJECT(fsCancel), "key-release-event", GTK_SIGNAL_FUNC(fs_key_release_event), NULL); |
698 gtk_signal_connect(GTK_OBJECT(fsFNameList), "select-row", (GtkSignalFunc)fs_fsFNameList_select_row, NULL); | |
36012 | 699 gtk_signal_connect(GTK_OBJECT(fsFNameList), "event", (GtkSignalFunc)fs_fsFNameList_event, NULL); |
33572 | 700 |
36012 | 701 return FileSelector; |
33572 | 702 } |
35958 | 703 |
36012 | 704 void ShowFileSelector(int type) |
35958 | 705 { |
36012 | 706 int i, k, fsMedium; |
707 char *tmp = NULL, *dir = NULL; | |
708 const gchar *fname; | |
709 struct stat f; | |
710 | |
711 if (FileSelector) | |
36019 | 712 gtkRaise(FileSelector); |
36012 | 713 else |
714 FileSelector = CreateFileSelect(); | |
35958 | 715 |
36012 | 716 fsType = type; |
717 | |
718 switch (type) { | |
719 case FILESELECT_VIDEO_AUDIO: | |
720 gtk_window_set_title(GTK_WINDOW(FileSelector), MSGTR_FileSelect); | |
721 fsList_items = NULL; | |
722 | |
723 for (i = 0; fsVideoAudioFilterNames[i][0]; i++) | |
724 fsList_items = g_list_append(fsList_items, fsVideoAudioFilterNames[i][0]); | |
35958 | 725 |
36012 | 726 k = fsLastVideoAudioFilterSelected; |
727 gtk_combo_set_popdown_strings(GTK_COMBO(List), fsList_items); | |
728 g_list_free(fsList_items); | |
729 gtk_entry_set_text(GTK_ENTRY(fsFilterCombo), fsVideoAudioFilterNames[k >= 0 ? k : i - 2][0]); | |
730 //tmp=guiInfo.Filename; | |
35958 | 731 break; |
36012 | 732 |
733 case FILESELECT_SUBTITLE: | |
734 gtk_window_set_title(GTK_WINDOW(FileSelector), MSGTR_SubtitleSelect); | |
735 fsList_items = NULL; | |
736 | |
737 for (i = 0; fsSubtitleFilterNames[i][0]; i++) | |
738 fsList_items = g_list_append(fsList_items, fsSubtitleFilterNames[i][0]); | |
739 | |
740 k = fsLastSubtitleFilterSelected; | |
741 gtk_combo_set_popdown_strings(GTK_COMBO(List), fsList_items); | |
742 g_list_free(fsList_items); | |
743 gtk_entry_set_text(GTK_ENTRY(fsFilterCombo), fsSubtitleFilterNames[k >= 0 ? k : i - 2][0]); | |
744 tmp = guiInfo.SubtitleFilename; | |
35958 | 745 break; |
36012 | 746 |
35958 | 747 /* case fsOtherSelector: |
36012 | 748 * gtk_window_set_title( GTK_WINDOW( FileSelector ),MSGTR_OtherSelect ); |
749 * fsList_items=NULL; | |
750 * for( i=0;fsOtherFilterNames[i][0];i++ ) | |
751 * fsList_items=g_list_append( fsList_items,fsOtherFilterNames[i][0] ); | |
752 * gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
753 * g_list_free( fsList_items ); | |
754 * gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsOtherFilterNames[0][0] ); | |
755 * tmp=guiInfo.Othername; | |
756 * break;*/ | |
757 case FILESELECT_AUDIO: | |
758 gtk_window_set_title(GTK_WINDOW(FileSelector), MSGTR_AudioFileSelect); | |
759 fsList_items = NULL; | |
760 | |
761 for (i = 0; fsAudioFileNames[i][0]; i++) | |
762 fsList_items = g_list_append(fsList_items, fsAudioFileNames[i][0]); | |
763 | |
764 k = fsLastAudioFilterSelected; | |
765 gtk_combo_set_popdown_strings(GTK_COMBO(List), fsList_items); | |
766 g_list_free(fsList_items); | |
767 gtk_entry_set_text(GTK_ENTRY(fsFilterCombo), fsAudioFileNames[k >= 0 ? k : i - 2][0]); | |
768 tmp = guiInfo.AudioFilename; | |
769 break; | |
770 | |
771 case FILESELECT_FONT: | |
772 gtk_window_set_title(GTK_WINDOW(FileSelector), MSGTR_FontSelect); | |
773 fsList_items = NULL; | |
774 | |
775 for (i = 0; fsFontFileNames[i][0]; i++) | |
776 fsList_items = g_list_append(fsList_items, fsFontFileNames[i][0]); | |
35958 | 777 |
36012 | 778 k = fsLastFontFilterSelected; |
779 gtk_combo_set_popdown_strings(GTK_COMBO(List), fsList_items); | |
780 g_list_free(fsList_items); | |
781 gtk_entry_set_text(GTK_ENTRY(fsFilterCombo), fsFontFileNames[k >= 0 ? k : i - 2][0]); | |
782 tmp = font_name; | |
783 break; | |
784 } | |
785 | |
786 fsMedium = (fsType == FILESELECT_VIDEO_AUDIO || fsType == FILESELECT_SUBTITLE || fsType == FILESELECT_AUDIO); | |
787 | |
788 if (tmp && tmp[0] && !strstr(tmp, "://")) { | |
789 dir = strdup(tmp); | |
35958 | 790 |
36012 | 791 do { |
792 char *c = strrchr(dir, '/'); | |
793 | |
794 if ((stat(dir, &f) == 0) && S_ISDIR(f.st_mode)) | |
795 break; | |
35958 | 796 |
36012 | 797 if (c) |
798 *c = 0; | |
799 } while (strrchr(dir, '/')); | |
800 | |
801 if (!dir[0]) | |
802 nfree(dir); | |
803 } | |
804 | |
805 fsPathTable = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); | |
806 | |
35958 | 807 { |
36012 | 808 unsigned int i, c = 1; |
809 | |
810 if (fsMedium) { | |
811 for (i = 0; i < FF_ARRAY_ELEMS(fsHistory); i++) | |
812 if (fsHistory[i]) { | |
813 fname = cfg_old_filename_from_utf8(fsHistory[i]); | |
814 fs_AddPathUtf8(fname, GTK_POS_BOTTOM); | |
35958 | 815 |
36012 | 816 if (c) |
817 c = gstrcmp(dir, fname); | |
818 } | |
819 } | |
35958 | 820 |
36012 | 821 if (c && dir) |
822 fs_AddPathUtf8(dir, GTK_POS_TOP); | |
823 } | |
824 free(dir); | |
825 fname = getenv("HOME"); | |
35958 | 826 |
36012 | 827 if (fname) |
828 fs_AddPathUtf8(fname, GTK_POS_BOTTOM); | |
829 else | |
830 fsTopList_items = fs_AddPath(fsTopList_items, g_strdup("/home"), GTK_POS_BOTTOM); | |
831 | |
832 if (stat("/media", &f) == 0) | |
833 fsTopList_items = fs_AddPath(fsTopList_items, g_strdup("/media"), GTK_POS_BOTTOM); | |
834 | |
835 if (stat("/mnt", &f) == 0) | |
836 fsTopList_items = fs_AddPath(fsTopList_items, g_strdup("/mnt"), GTK_POS_BOTTOM); | |
35958 | 837 |
36012 | 838 fsTopList_items = fs_AddPath(fsTopList_items, g_strdup("/"), GTK_POS_BOTTOM); |
839 gtk_combo_set_popdown_strings(GTK_COMBO(fsCombo4), fsTopList_items); | |
840 | |
841 gtk_widget_grab_focus(fsFNameList); | |
35958 | 842 |
36012 | 843 if (fsLastFNameListSelected + 1 > ((GtkCList *)fsFNameList)->rows) |
844 fsLastFNameListSelected = 0; | |
845 | |
846 ((GtkCList *)fsFNameList)->focus_row = fsLastFNameListSelected; | |
847 gtk_clist_select_row(GTK_CLIST(fsFNameList), fsLastFNameListSelected, 1); | |
848 fsLastFNameListSelected = 0; | |
849 | |
850 gtk_widget_show(FileSelector); | |
35958 | 851 } |