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