Mercurial > mplayer.hg
annotate gui/ui/gtk/fileselect.c @ 33768:cee9987bc81d
Remove guiExit().
Integrate it into mplayer().
author | ib |
---|---|
date | Sat, 09 Jul 2011 10:23:47 +0000 |
parents | 03824cf8728d |
children | 4fae8b19fbbd |
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 | |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
21 #include <string.h> | |
22 #include <sys/stat.h> | |
23 #include <glob.h> | |
24 #include <unistd.h> | |
25 | |
26 #include "config.h" | |
27 #include "gui/ui/gmplayer.h" | |
28 | |
29 #include "gui/ui/pixmaps/up.xpm" | |
30 #include "gui/ui/pixmaps/dir.xpm" | |
31 #include "gui/ui/pixmaps/file.xpm" | |
32 | |
33 #include "gui/app.h" | |
34 #include "gui/interface.h" | |
33739 | 35 #include "gui/util/mem.h" |
33737 | 36 #include "gui/util/string.h" |
33572 | 37 #include "help_mp.h" |
38 #include "mpcommon.h" | |
39 #include "stream/stream.h" | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
40 #include "libavutil/common.h" |
33572 | 41 |
42 #include "gui/ui/widgets.h" | |
43 #include "fileselect.h" | |
44 #include "preferences.h" | |
45 #include "tools.h" | |
46 | |
47 #ifndef __linux__ | |
48 #define get_current_dir_name() getcwd(NULL, PATH_MAX) | |
49 #else | |
50 char * get_current_dir_name( void ); | |
51 #endif | |
52 | |
53 gchar * fsSelectedFile = NULL; | |
54 gchar * fsSelectedFileUtf8 = NULL; | |
55 gchar * fsSelectedDirectory = NULL; | |
56 unsigned char * fsThatDir = "."; | |
57 const gchar * fsFilter = "*"; | |
58 | |
59 int fsType = 0; | |
60 | |
61 char * fsVideoFilterNames[][2] = | |
62 { | |
63 { "ASF files (*.asf)", "*.asf" }, | |
64 { "AVI files (*.avi)", "*.avi" }, | |
65 { "Autodesk animations (*.fli,*.flc)", "*.fli,*.flc" }, | |
66 { "DGStation Cuberevo recordings (*.trp)", "*.trp" }, | |
67 { "DiVX files (*.divx)", "*.divx" }, | |
68 { "MP3 files (*.mp3,*.mp2)", "*.mp3,*.mp2" }, | |
69 { "MPEG files (*.mpg,*.mpeg,*.m1v)", "*.mpg,*.mpeg,*.m1v" }, | |
70 { "Macromedia Flash Video (*.flv)", "*.flv" }, | |
71 { "Matroska Audio files (*.mka)", "*.mka" }, | |
72 { "Matroska Media files (*.mkv)", "*.mkv" }, | |
73 { "NuppelVideo files (*.nuv)", "*.nuv" }, | |
74 { "OGG Vorbis files (*.ogg)", "*.ogg" }, | |
75 { "OGG Media files (*.ogm)", "*.ogm" }, | |
76 { "QuickTime files (*.mov,*.qt,*.mp4)", "*.mov,*.qt,*.mp4" }, | |
77 { "RealVideo files (*.rm,*.rmvb)", "*.rm,*.rmvb" }, | |
78 { "Tivo files (*.ty)", "*.ty" }, | |
79 { "VCD/SVCD Images (*.bin)", "*.bin" }, | |
80 { "VIVO files (*.viv)", "*.viv" }, | |
81 { "VOB files (*.vob)", "*.vob" }, | |
82 { "Wave files (*.wav)", "*.wav" }, | |
83 { "Windows Media Audio (*.wma)", "*.wma" }, | |
84 { "Windows Media Video (*.wmv)", "*.wmv" }, | |
85 { "Audio files", "*.mp2,*.mp3,*.mka,*.ogg,*.wav,*.wma" }, | |
86 { "Video files", "*.asf,*.avi,*.fli,*.flc,*.trp,*.divx,*.mpg,*.mpeg,*.m1v,*.flv,*.mkv,*.nuv,*.ogm,*.mov,*.qt,*.mp4,*.rm,*.rmvb,*.ty,*.bin,*.viv,*.vob,*.wmv" }, | |
87 { "All files", "*" }, | |
88 { NULL,NULL } | |
89 }; | |
90 int fsLastVideoFilterSelected = -1; | |
91 | |
92 char * fsSubtitleFilterNames[][2] = | |
93 { | |
94 { "AQT (*.aqt)", "*.aqt" }, | |
95 { "ASS (*.ass)", "*.ass" }, | |
96 { "RT (*.rt) ", "*.rt" }, | |
97 { "SMI (*.smi)", "*.smi" }, | |
98 { "SRT (*.srt)", "*.srt" }, | |
99 { "SSA (*.ssa)", "*.ssa" }, | |
100 { "SUB (*.sub)", "*.sub" }, | |
101 { "TXT (*.txt)", "*.txt" }, | |
102 { "UTF (*.utf)", "*.utf" }, | |
103 { "Subtitles", "*.aqt,*.ass,*.rt,*.smi,*.srt,*.ssa,*.sub,*.txt,*.utf" }, | |
104 { "All files", "*" }, | |
105 { NULL,NULL } | |
106 }; | |
107 int fsLastSubtitleFilterSelected = -1; | |
108 | |
109 char * fsOtherFilterNames[][2] = | |
110 { | |
111 { "All files", "*" }, | |
112 { NULL,NULL } | |
113 }; | |
114 | |
115 char * fsAudioFileNames[][2] = | |
116 { | |
117 { "MP3 files (*.mp2, *.mp3)", "*.mp2,*.mp3" }, | |
118 { "Matroska Audio files (*.mka)", "*.mka" }, | |
119 { "OGG Vorbis files (*.ogg)", "*.ogg" }, | |
120 { "WAV files (*.wav)", "*.wav" }, | |
121 { "WMA files (*.wma)", "*.wma" }, | |
122 { "Audio files", "*.mp2,*.mp3,*.mka,*.ogg,*.wav,*.wma" }, | |
123 { "All files", "*" }, | |
124 { NULL, NULL } | |
125 }; | |
126 int fsLastAudioFilterSelected = -1; | |
127 | |
128 char * fsFontFileNames[][2] = | |
129 { | |
130 #ifdef CONFIG_FREETYPE | |
131 { "True Type fonts (*.ttf)", "*.ttf" }, | |
132 { "Type1 fonts (*.pfb)", "*.pfb" }, | |
133 { "All fonts", "*.ttf,*.pfb" }, | |
134 #else | |
135 { "Font files (*.desc)", "*.desc" }, | |
136 #endif | |
137 { "All files", "*" }, | |
138 { NULL,NULL } | |
139 }; | |
140 int fsLastFontFilterSelected = -1; | |
141 | |
142 GtkWidget * fsFileNamesList; | |
143 GtkWidget * fsFNameList; | |
144 GtkWidget * fsFileSelect = NULL; | |
145 GdkColormap * fsColorMap; | |
146 GtkWidget * fsOk; | |
147 GtkWidget * fsUp; | |
148 GtkWidget * fsCancel; | |
149 GtkWidget * fsCombo4; | |
150 GtkWidget * fsPathCombo; | |
151 GList * fsList_items = NULL; | |
152 GList * fsTopList_items = NULL; | |
153 GtkWidget * List; | |
154 GtkWidget * fsFilterCombo; | |
155 | |
156 GtkStyle * style; | |
157 GdkPixmap * dpixmap; | |
158 GdkPixmap * fpixmap; | |
159 GdkBitmap * dmask; | |
160 GdkBitmap * fmask; | |
161 | |
162 static char * get_current_dir_name_utf8( void ) | |
163 { | |
164 char * dir, * utf8dir; | |
165 dir = get_current_dir_name(); | |
166 utf8dir = g_filename_to_utf8( dir, -1, NULL, NULL, NULL ); | |
167 if ( !utf8dir ) utf8dir = g_strdup( dir ); | |
168 free( dir ); | |
169 return utf8dir; | |
170 } | |
171 | |
172 static char * Filter( const char * name ) | |
173 { | |
174 static char tmp[32]; | |
33755
90a5fdb500db
Use unsigned index variable for comparison with string length.
ib
parents:
33751
diff
changeset
|
175 unsigned int i,c; |
33572 | 176 for ( i=0,c=0;i < strlen( name );i++ ) |
177 { | |
178 if ( ( name[i] >='a' )&&( name[i] <= 'z' ) ) { tmp[c++]='['; tmp[c++]=name[i]; tmp[c++]=name[i] - 32; tmp[c++]=']'; } | |
179 else tmp[c++]=name[i]; | |
180 } | |
181 tmp[c]=0; | |
182 return tmp; | |
183 } | |
184 | |
185 static void clist_append_fname(GtkWidget * list, char *fname, | |
186 GdkPixmap *pixmap, GdkPixmap *mask) { | |
187 gint pos; | |
188 gchar *filename, *str[2]; | |
189 filename = g_filename_to_utf8(fname, -1, NULL, NULL, NULL); | |
190 str[0] = NULL; | |
191 str[1] = filename ? filename : fname; | |
192 pos = gtk_clist_append(GTK_CLIST(list), str); | |
193 gtk_clist_set_pixmap(GTK_CLIST(list), pos, 0, pixmap, mask); | |
194 g_free(filename); | |
195 } | |
196 | |
197 static void CheckDir( GtkWidget * list ) | |
198 { | |
199 struct stat fs; | |
200 int i; | |
201 glob_t gg; | |
202 | |
203 if ( !fsFilter[0] ) return; | |
204 | |
205 gtk_widget_hide( list ); | |
206 gtk_clist_clear( GTK_CLIST( list ) ); | |
207 | |
208 clist_append_fname(list, ".", dpixmap, dmask); | |
209 clist_append_fname(list, "..", dpixmap, dmask); | |
210 | |
211 glob( "*",0,NULL,&gg ); | |
212 for( i=0;(unsigned)i<gg.gl_pathc;i++ ) | |
213 { | |
214 stat( gg.gl_pathv[i],&fs ); | |
215 if( !S_ISDIR( fs.st_mode ) ) continue; | |
216 clist_append_fname(list, gg.gl_pathv[i], dpixmap, dmask); | |
217 } | |
218 globfree( &gg ); | |
219 | |
220 if ( strchr( fsFilter,',' ) ) | |
221 { | |
222 char tmp[8]; | |
223 int i,c,glob_param = 0; | |
224 for ( i=0,c=0;i<(int)strlen( fsFilter ) + 1;i++,c++ ) | |
225 { | |
226 tmp[c]=fsFilter[i]; | |
227 if ( ( tmp[c] == ',' )||( tmp[c] == '\0' ) ) | |
228 { | |
229 tmp[c]=0; c=-1; | |
230 glob( Filter( tmp ),glob_param,NULL,&gg ); | |
231 glob_param=GLOB_APPEND; | |
232 } | |
233 } | |
234 } else glob( Filter( fsFilter ),0,NULL,&gg ); | |
235 | |
236 for( i=0;(unsigned)i<gg.gl_pathc;i++ ) | |
237 { | |
238 stat( gg.gl_pathv[i],&fs ); | |
239 if( S_ISDIR( fs.st_mode ) ) continue; | |
240 clist_append_fname(list, gg.gl_pathv[i], fpixmap, fmask); | |
241 } | |
242 globfree( &gg ); | |
243 | |
244 gtk_clist_set_column_width( GTK_CLIST( list ),0,17 ); | |
245 gtk_clist_select_row( GTK_CLIST( list ),0,1 ); | |
246 gtk_widget_show( list ); | |
247 } | |
248 | |
249 void ShowFileSelect( int type,int modal ) | |
250 { | |
251 int i, k; | |
252 char * tmp = NULL; | |
253 | |
254 if ( fsFileSelect ) gtkActive( fsFileSelect ); | |
255 else fsFileSelect=create_FileSelect(); | |
256 | |
257 fsType=type; | |
258 switch ( type ) | |
259 { | |
260 case fsVideoSelector: | |
261 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_FileSelect ); | |
262 fsList_items=NULL; | |
263 for( i=0;fsVideoFilterNames[i][0];i++ ) | |
264 fsList_items=g_list_append( fsList_items,fsVideoFilterNames[i][0] ); | |
265 k = fsLastVideoFilterSelected; | |
266 gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
267 g_list_free( fsList_items ); | |
268 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsVideoFilterNames[k >= 0 ? k : i-2][0] ); | |
269 tmp=guiInfo.Filename; | |
270 break; | |
271 case fsSubtitleSelector: | |
272 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_SubtitleSelect ); | |
273 fsList_items=NULL; | |
274 for( i=0;fsSubtitleFilterNames[i][0];i++ ) | |
275 fsList_items=g_list_append( fsList_items,fsSubtitleFilterNames[i][0] ); | |
276 k = fsLastSubtitleFilterSelected; | |
277 gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
278 g_list_free( fsList_items ); | |
279 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsSubtitleFilterNames[k >= 0 ? k : i-2][0] ); | |
280 tmp=guiInfo.Subtitlename; | |
281 break; | |
282 case fsOtherSelector: | |
283 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_OtherSelect ); | |
284 fsList_items=NULL; | |
285 for( i=0;fsOtherFilterNames[i][0];i++ ) | |
286 fsList_items=g_list_append( fsList_items,fsOtherFilterNames[i][0] ); | |
287 gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
288 g_list_free( fsList_items ); | |
289 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsOtherFilterNames[0][0] ); | |
290 tmp=guiInfo.Othername; | |
291 break; | |
292 case fsAudioSelector: | |
293 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_AudioFileSelect ); | |
294 fsList_items=NULL; | |
295 for( i=0;fsAudioFileNames[i][0];i++ ) | |
296 fsList_items=g_list_append( fsList_items,fsAudioFileNames[i][0] ); | |
297 k = fsLastAudioFilterSelected; | |
298 gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
299 g_list_free( fsList_items ); | |
300 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsAudioFileNames[k >= 0 ? k : i-2][0] ); | |
301 tmp=guiInfo.AudioFile; | |
302 break; | |
303 case fsFontSelector: | |
304 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_FontSelect ); | |
305 fsList_items=NULL; | |
306 for( i=0;fsFontFileNames[i][0];i++ ) | |
307 fsList_items=g_list_append( fsList_items,fsFontFileNames[i][0] ); | |
308 k = fsLastFontFilterSelected; | |
309 gtk_combo_set_popdown_strings( GTK_COMBO( List ),fsList_items ); | |
310 g_list_free( fsList_items ); | |
311 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsFontFileNames[k >= 0 ? k : i-2][0] ); | |
312 tmp=font_name; | |
313 break; | |
314 } | |
315 | |
316 if ( tmp && tmp[0] ) | |
317 { | |
318 struct stat f; | |
319 char * dir = strdup( tmp ); | |
320 | |
321 do | |
322 { | |
323 char * c = strrchr( dir,'/' ); | |
324 stat( dir,&f ); | |
325 if ( S_ISDIR( f.st_mode ) ) break; | |
326 if ( c ) *c=0; | |
327 } while ( strrchr( dir,'/' ) ); | |
328 | |
329 if ( dir[0] ) chdir( dir ); | |
330 | |
331 free( dir ); | |
332 } | |
333 | |
334 if ( fsTopList_items ) g_list_free( fsTopList_items ); fsTopList_items=NULL; | |
335 { | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
336 unsigned int i, c = 1; |
33572 | 337 |
338 if ( fsType == fsVideoSelector ) | |
339 { | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
340 for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ ) |
33572 | 341 if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,fsHistory[i] ); c=0; } |
342 } | |
343 if ( c ) fsTopList_items=g_list_append( fsTopList_items,(gchar *)get_current_dir_name_utf8() ); | |
344 } | |
345 if ( getenv( "HOME" ) ) fsTopList_items=g_list_append( fsTopList_items,getenv( "HOME" ) ); | |
346 fsTopList_items=g_list_append( fsTopList_items,"/home" ); | |
347 fsTopList_items=g_list_append( fsTopList_items,"/mnt" ); | |
348 fsTopList_items=g_list_append( fsTopList_items,"/" ); | |
349 gtk_combo_set_popdown_strings( GTK_COMBO( fsCombo4 ),fsTopList_items ); | |
350 | |
351 gtk_window_set_modal( GTK_WINDOW( fsFileSelect ),modal ); | |
352 | |
353 gtk_widget_show( fsFileSelect ); | |
354 } | |
355 | |
356 void HideFileSelect( void ) | |
357 { | |
358 if ( !fsFileSelect ) return; | |
359 gtk_widget_hide( fsFileSelect ); | |
360 gtk_widget_destroy( fsFileSelect ); | |
361 fsFileSelect=NULL; | |
362 } | |
363 | |
364 static void fs_PersistantHistory( char * subject ) | |
365 { | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
366 unsigned int i; |
33572 | 367 |
368 if ( fsType != fsVideoSelector ) return; | |
369 | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
370 for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ ) |
33572 | 371 if ( fsHistory[i] && !strcmp( fsHistory[i],subject ) ) |
372 { | |
373 char * tmp = fsHistory[i]; fsHistory[i]=fsHistory[0]; fsHistory[0]=tmp; | |
374 return; | |
375 } | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
376 nfree( fsHistory[FF_ARRAY_ELEMS(fsHistory) - 1] ); |
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
377 for ( i=FF_ARRAY_ELEMS(fsHistory) - 1;i;i-- ) fsHistory[i]=fsHistory[i - 1]; |
33572 | 378 fsHistory[0]=gstrdup( subject ); |
379 } | |
380 //----------------------------------------------- | |
381 | |
382 static void fs_fsFilterCombo_activate( GtkEditable * editable, | |
383 gpointer user_data ) | |
384 { | |
385 fsFilter=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
386 CheckDir( fsFNameList ); | |
387 } | |
388 | |
389 static void fs_fsFilterCombo_changed( GtkEditable * editable, | |
390 gpointer user_data ) | |
391 { | |
392 const char * str; | |
393 int i; | |
394 | |
395 str=gtk_entry_get_text( GTK_ENTRY(user_data ) ); | |
396 | |
397 switch ( fsType ) | |
398 { | |
399 case fsVideoSelector: | |
400 for( i=0;fsVideoFilterNames[i][0];i++ ) | |
401 if( !strcmp( str,fsVideoFilterNames[i][0] ) ) | |
402 { fsFilter=fsVideoFilterNames[i][1]; fsLastVideoFilterSelected = i; break; } | |
403 break; | |
404 case fsSubtitleSelector: | |
405 for( i=0;fsSubtitleFilterNames[i][0];i++ ) | |
406 if( !strcmp( str,fsSubtitleFilterNames[i][0] ) ) | |
407 { fsFilter=fsSubtitleFilterNames[i][1]; fsLastSubtitleFilterSelected = i; break; } | |
408 break; | |
409 case fsOtherSelector: | |
410 for( i=0;fsOtherFilterNames[i][0];i++ ) | |
411 if( !strcmp( str,fsOtherFilterNames[i][0] ) ) | |
412 { fsFilter=fsOtherFilterNames[i][1]; break; } | |
413 break; | |
414 case fsAudioSelector: | |
415 for( i=0;fsAudioFileNames[i][0];i++ ) | |
416 if( !strcmp( str,fsAudioFileNames[i][0] ) ) | |
417 { fsFilter=fsAudioFileNames[i][1]; fsLastAudioFilterSelected = i; break; } | |
418 break; | |
419 case fsFontSelector: | |
420 for( i=0;fsFontFileNames[i][0];i++ ) | |
421 if( !strcmp( str,fsFontFileNames[i][0] ) ) | |
422 { fsFilter=fsFontFileNames[i][1]; fsLastFontFilterSelected = i; break; } | |
423 break; | |
424 default: return; | |
425 } | |
426 CheckDir( fsFNameList ); | |
427 } | |
428 | |
429 static void fs_fsPathCombo_activate( GtkEditable * editable, | |
430 gpointer user_data ) | |
431 { | |
432 const unsigned char * str; | |
433 gchar * dirname; | |
434 | |
435 str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
436 dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); | |
437 if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); | |
438 g_free( dirname ); | |
439 } | |
440 | |
441 static void fs_fsPathCombo_changed( GtkEditable * editable, | |
442 gpointer user_data ) | |
443 { | |
444 const unsigned char * str; | |
445 gchar * dirname; | |
446 | |
447 str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
448 dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); | |
449 if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); | |
450 g_free( dirname ); | |
451 } | |
452 | |
453 static void fs_Up_released( GtkButton * button, gpointer user_data ) | |
454 { | |
455 chdir( ".." ); | |
456 fsSelectedFile=fsThatDir; | |
457 CheckDir( fsFNameList ); | |
458 gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name_utf8() ); | |
459 return; | |
460 } | |
461 | |
462 static void fs_Ok_released( GtkButton * button, gpointer user_data ) | |
463 { | |
464 GList * item; | |
465 int i = 1; | |
466 struct stat fs; | |
467 | |
468 stat( fsSelectedFile,&fs ); | |
469 if( S_ISDIR(fs.st_mode ) ) | |
470 { | |
471 chdir( fsSelectedFile ); | |
472 fsSelectedFile=fsThatDir; | |
473 CheckDir( fsFNameList ); | |
474 gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name_utf8() ); | |
475 return; | |
476 } | |
477 | |
478 fsSelectedDirectory=(unsigned char *)get_current_dir_name(); | |
479 switch ( fsType ) | |
480 { | |
481 case fsVideoSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
482 setddup( &guiInfo.Filename,fsSelectedDirectory,fsSelectedFile ); |
33572 | 483 guiInfo.StreamType=STREAMTYPE_FILE; |
484 guiInfo.FilenameChanged=1; sub_fps=0; | |
33739 | 485 nfree( guiInfo.AudioFile ); |
486 nfree( guiInfo.Subtitlename ); | |
33572 | 487 fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history |
488 break; | |
489 case fsSubtitleSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
490 setddup( &guiInfo.Subtitlename,fsSelectedDirectory,fsSelectedFile ); |
33763 | 491 mplayerLoadSubtitle( guiInfo.Subtitlename ); |
33572 | 492 break; |
493 case fsOtherSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
494 setddup( &guiInfo.Othername,fsSelectedDirectory,fsSelectedFile ); |
33572 | 495 break; |
496 case fsAudioSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
497 setddup( &guiInfo.AudioFile,fsSelectedDirectory,fsSelectedFile ); |
33572 | 498 break; |
499 case fsFontSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
500 setddup( &font_name,fsSelectedDirectory,fsSelectedFile ); |
33763 | 501 mplayerLoadFont(); |
33572 | 502 if ( Preferences ) gtk_entry_set_text( GTK_ENTRY( prEFontName ),font_name ); |
503 break; | |
504 } | |
505 | |
506 HideFileSelect(); | |
507 | |
508 item=fsTopList_items; | |
509 while( item ) | |
510 { | |
511 if ( !strcmp( item->data,fsSelectedDirectory ) ) i=0; | |
512 item=item->next; | |
513 } | |
514 if ( i ) fsTopList_items=g_list_prepend( fsTopList_items,(gchar *)get_current_dir_name_utf8() ); | |
515 if ( uiMainAutoPlay ) { uiMainAutoPlay=0; uiEventHandling( evPlay,0 ); } | |
33731
81f71d910333
Cosmetic: Change prefix for symbolic constants from GMP to GUI.
ib
parents:
33725
diff
changeset
|
516 else gui( GUI_SET_STATE,(void *) GUI_STOP ); |
33572 | 517 } |
518 | |
519 static void fs_Cancel_released( GtkButton * button,gpointer user_data ) | |
520 { | |
521 HideFileSelect(); | |
522 fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history file | |
523 } | |
524 | |
525 static void fs_fsFNameList_select_row( GtkWidget * widget, gint row, gint column, | |
526 GdkEventButton *bevent, gpointer user_data) | |
527 { | |
528 gtk_clist_get_text( GTK_CLIST(widget ),row,1,&fsSelectedFile ); | |
529 g_free( fsSelectedFileUtf8 ); | |
530 fsSelectedFileUtf8 = g_filename_from_utf8( fsSelectedFile, -1, NULL, NULL, NULL ); | |
531 if ( fsSelectedFileUtf8 ) fsSelectedFile = fsSelectedFileUtf8; | |
532 if( bevent && bevent->type == GDK_BUTTON_PRESS ) gtk_button_released( GTK_BUTTON( fsOk ) ); | |
533 } | |
534 | |
535 static gboolean on_FileSelect_key_release_event( GtkWidget * widget, | |
536 GdkEventKey * event, | |
537 gpointer user_data ) | |
538 { | |
539 switch ( event->keyval ) | |
540 { | |
541 case GDK_Escape: | |
542 gtk_button_released( GTK_BUTTON( fsCancel ) ); | |
543 break; | |
544 case GDK_Return: | |
545 gtk_button_released( GTK_BUTTON( fsOk ) ); | |
546 break; | |
547 case GDK_BackSpace: | |
548 gtk_button_released( GTK_BUTTON( fsUp ) ); | |
549 break; | |
550 } | |
551 return FALSE; | |
552 } | |
553 | |
554 static gboolean fs_fsFNameList_event( GtkWidget * widget, | |
555 GdkEvent * event, | |
556 gpointer user_data ) | |
557 { | |
558 GdkEventButton *bevent; | |
559 gint row, col; | |
560 | |
561 (void) user_data; | |
562 | |
563 bevent = (GdkEventButton *) event; | |
564 | |
565 if ( event->type == GDK_BUTTON_RELEASE && bevent->button == 2 ) | |
566 { | |
567 if ( gtk_clist_get_selection_info( GTK_CLIST( widget ), bevent->x, bevent->y, &row, &col ) ) | |
568 { | |
569 gtk_clist_get_text( GTK_CLIST( widget ), row, 1, &fsSelectedFile ); | |
570 g_free( fsSelectedFileUtf8 ); | |
571 fsSelectedFileUtf8 = g_filename_from_utf8( fsSelectedFile, -1, NULL, NULL, NULL ); | |
572 if ( fsSelectedFileUtf8 ) fsSelectedFile = fsSelectedFileUtf8; | |
573 gtk_button_released( GTK_BUTTON( fsOk ) ); | |
574 return TRUE; | |
575 } | |
576 } | |
577 | |
578 return FALSE; | |
579 } | |
580 | |
581 static void fs_Destroy( void ) | |
582 { | |
583 g_free( fsSelectedFileUtf8 ); | |
584 fsSelectedFileUtf8 = NULL; | |
585 WidgetDestroy( fsFileSelect, &fsFileSelect ); | |
586 } | |
587 | |
588 GtkWidget * create_FileSelect( void ) | |
589 { | |
590 GtkWidget * vbox4; | |
591 GtkWidget * hbox4; | |
592 GtkWidget * vseparator1; | |
593 GtkWidget * hbox6; | |
594 GtkWidget * fsFNameListWindow; | |
595 GtkWidget * hbuttonbox3; | |
596 | |
597 GtkWidget * uppixmapwid; | |
598 GdkPixmap * uppixmap; | |
599 GdkBitmap * upmask; | |
600 GtkStyle * upstyle; | |
601 | |
602 | |
603 fsFileSelect=gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
604 gtk_widget_set_name( fsFileSelect,"fsFileSelect" ); | |
605 gtk_object_set_data( GTK_OBJECT( fsFileSelect ),"fsFileSelect",fsFileSelect ); | |
606 gtk_widget_set_usize( fsFileSelect,512,300 ); | |
607 GTK_WIDGET_SET_FLAGS( fsFileSelect,GTK_CAN_DEFAULT ); | |
608 gtk_widget_set_events( fsFileSelect,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 ); | |
609 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_FileSelect ); | |
610 gtk_window_set_position( GTK_WINDOW( fsFileSelect ),GTK_WIN_POS_CENTER ); | |
611 gtk_window_set_policy( GTK_WINDOW( fsFileSelect ),TRUE,TRUE,TRUE ); | |
612 gtk_window_set_wmclass( GTK_WINDOW( fsFileSelect ),"FileSelect","MPlayer" ); | |
613 fsColorMap=gdk_colormap_get_system(); | |
614 | |
615 gtk_widget_realize( fsFileSelect ); | |
616 gtkAddIcon( fsFileSelect ); | |
617 | |
618 style=gtk_widget_get_style( fsFileSelect ); | |
619 dpixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&dmask,&style->bg[GTK_STATE_NORMAL],(gchar **)dir_xpm ); | |
620 fpixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&fmask,&style->bg[GTK_STATE_NORMAL],(gchar **)file_xpm ); | |
621 | |
622 vbox4=AddVBox( AddDialogFrame( fsFileSelect ),0 ); | |
623 hbox4=AddHBox( vbox4,1 ); | |
624 | |
625 fsCombo4=gtk_combo_new(); | |
626 gtk_widget_set_name( fsCombo4,"fsCombo4" ); | |
627 gtk_widget_show( fsCombo4 ); | |
628 gtk_box_pack_start( GTK_BOX( hbox4 ),fsCombo4,TRUE,TRUE,0 ); | |
629 gtk_widget_set_usize( fsCombo4,-2,20 ); | |
630 | |
631 fsPathCombo=GTK_COMBO( fsCombo4 )->entry; | |
632 gtk_widget_set_name( fsPathCombo,"fsPathCombo" ); | |
633 gtk_widget_show( fsPathCombo ); | |
634 gtk_widget_set_usize( fsPathCombo,-2,20 ); | |
635 | |
636 vseparator1=gtk_vseparator_new(); | |
637 gtk_widget_set_name( vseparator1,"vseparator1" ); | |
638 gtk_widget_show( vseparator1 ); | |
639 gtk_box_pack_start( GTK_BOX( hbox4 ),vseparator1,FALSE,TRUE,0 ); | |
640 gtk_widget_set_usize( vseparator1,7,20 ); | |
641 | |
642 upstyle=gtk_widget_get_style( fsFileSelect ); | |
643 uppixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&upmask,&upstyle->bg[GTK_STATE_NORMAL],(gchar **)up_xpm ); | |
644 uppixmapwid=gtk_pixmap_new( uppixmap,upmask ); | |
645 gtk_widget_show( uppixmapwid ); | |
646 | |
647 fsUp=gtk_button_new(); | |
648 gtk_container_add( GTK_CONTAINER(fsUp ),uppixmapwid ); | |
649 gtk_widget_show( fsUp ); | |
650 gtk_box_pack_start( GTK_BOX( hbox4 ),fsUp,FALSE,FALSE,0 ); | |
651 gtk_widget_set_usize( fsUp,65,15 ); | |
652 | |
653 AddHSeparator( vbox4 ); | |
654 | |
655 hbox6=AddHBox( NULL,0 ); | |
656 gtk_box_pack_start( GTK_BOX( vbox4 ),hbox6,TRUE,TRUE,0 ); | |
657 | |
658 fsFNameListWindow=gtk_scrolled_window_new( NULL,NULL ); | |
659 gtk_widget_set_name( fsFNameListWindow,"fsFNameListWindow" ); | |
660 gtk_widget_show( fsFNameListWindow ); | |
661 gtk_box_pack_start( GTK_BOX( hbox6 ),fsFNameListWindow,TRUE,TRUE,0 ); | |
662 gtk_widget_set_usize( fsFNameListWindow,-2,145 ); | |
663 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( fsFNameListWindow ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC ); | |
664 | |
665 fsFNameList=gtk_clist_new( 2 ); | |
666 gtk_widget_set_name( fsFNameList,"fsFNameList" ); | |
667 gtk_container_add( GTK_CONTAINER( fsFNameListWindow ),fsFNameList ); | |
668 gtk_clist_set_column_width( GTK_CLIST( fsFNameList ),0,80 ); | |
669 gtk_clist_set_selection_mode( GTK_CLIST( fsFNameList ),GTK_SELECTION_BROWSE ); | |
670 gtk_clist_column_titles_hide( GTK_CLIST( fsFNameList ) ); | |
671 gtk_clist_set_shadow_type( GTK_CLIST( fsFNameList ),GTK_SHADOW_ETCHED_OUT ); | |
672 | |
673 AddHSeparator( vbox4 ); | |
674 | |
675 List=gtk_combo_new(); | |
676 gtk_widget_set_name( List,"List" ); | |
677 gtk_widget_ref( List ); | |
678 gtk_object_set_data_full( GTK_OBJECT( fsFileSelect ),"List",List,(GtkDestroyNotify)gtk_widget_unref ); | |
679 gtk_widget_show( List ); | |
680 gtk_box_pack_start( GTK_BOX( vbox4 ),List,FALSE,FALSE,0 ); | |
681 gtk_widget_set_usize( List,-2,20 ); | |
682 | |
683 fsFilterCombo=GTK_COMBO( List )->entry; | |
684 gtk_widget_set_name( fsFilterCombo,"fsFilterCombo" ); | |
685 gtk_widget_show( fsFilterCombo ); | |
686 gtk_entry_set_editable (GTK_ENTRY( fsFilterCombo ),FALSE ); | |
687 | |
688 AddHSeparator( vbox4 ); | |
689 | |
690 hbuttonbox3=AddHButtonBox( vbox4 ); | |
691 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox3 ),GTK_BUTTONBOX_END ); | |
692 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox3 ),10 ); | |
693 | |
694 fsOk=AddButton( MSGTR_Ok,hbuttonbox3 ); | |
695 fsCancel=AddButton( MSGTR_Cancel,hbuttonbox3 ); | |
696 | |
697 gtk_signal_connect( GTK_OBJECT( fsFileSelect ),"destroy",GTK_SIGNAL_FUNC( fs_Destroy ), NULL ); | |
698 gtk_signal_connect( GTK_OBJECT( fsFileSelect ),"key_release_event",GTK_SIGNAL_FUNC( on_FileSelect_key_release_event ),NULL ); | |
699 | |
700 gtk_signal_connect( GTK_OBJECT( fsFilterCombo ),"changed",GTK_SIGNAL_FUNC( fs_fsFilterCombo_changed ),fsFilterCombo ); | |
701 gtk_signal_connect( GTK_OBJECT( fsFilterCombo ),"activate",GTK_SIGNAL_FUNC( fs_fsFilterCombo_activate ),fsFilterCombo ); | |
702 gtk_signal_connect( GTK_OBJECT( fsPathCombo ),"changed",GTK_SIGNAL_FUNC( fs_fsPathCombo_changed ),fsPathCombo ); | |
703 gtk_signal_connect( GTK_OBJECT( fsPathCombo ),"activate",GTK_SIGNAL_FUNC( fs_fsPathCombo_activate ),fsPathCombo ); | |
704 gtk_signal_connect( GTK_OBJECT( fsUp ),"released",GTK_SIGNAL_FUNC( fs_Up_released ),fsFNameList ); | |
705 gtk_signal_connect( GTK_OBJECT( fsOk ),"released",GTK_SIGNAL_FUNC( fs_Ok_released ),fsCombo4 ); | |
706 gtk_signal_connect( GTK_OBJECT( fsCancel ),"released",GTK_SIGNAL_FUNC( fs_Cancel_released ),NULL ); | |
707 gtk_signal_connect( GTK_OBJECT( fsFNameList ),"select_row",(GtkSignalFunc)fs_fsFNameList_select_row,NULL ); | |
708 gtk_signal_connect( GTK_OBJECT( fsFNameList ),"event", (GtkSignalFunc)fs_fsFNameList_event,NULL ); | |
709 | |
710 gtk_widget_grab_focus( fsFNameList ); | |
711 | |
712 return fsFileSelect; | |
713 } |