Mercurial > mplayer.hg
annotate gui/ui/gtk/fileselect.c @ 34481:887c198b5b78
Add size to ICONERROR warning message.
author | ib |
---|---|
date | Sat, 14 Jan 2012 16:30:03 +0000 |
parents | a650895d50a5 |
children | d476fbab0a28 |
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 ); |
34364 | 364 ((GtkCList *)fsFNameList)->focus_row = fsLastFNameListSelected; |
365 gtk_clist_select_row( GTK_CLIST( fsFNameList ),fsLastFNameListSelected,1 ); | |
366 fsLastFNameListSelected = 0; | |
34346 | 367 |
33572 | 368 gtk_window_set_modal( GTK_WINDOW( fsFileSelect ),modal ); |
369 | |
370 gtk_widget_show( fsFileSelect ); | |
371 } | |
372 | |
373 void HideFileSelect( void ) | |
374 { | |
375 if ( !fsFileSelect ) return; | |
376 gtk_widget_hide( fsFileSelect ); | |
377 gtk_widget_destroy( fsFileSelect ); | |
378 fsFileSelect=NULL; | |
34364 | 379 fsLastFNameListSelected = fsCurrFNameListSelected; |
33572 | 380 } |
381 | |
382 static void fs_PersistantHistory( char * subject ) | |
383 { | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
384 unsigned int i; |
33572 | 385 |
386 if ( fsType != fsVideoSelector ) return; | |
387 | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
388 for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ ) |
33572 | 389 if ( fsHistory[i] && !strcmp( fsHistory[i],subject ) ) |
390 { | |
391 char * tmp = fsHistory[i]; fsHistory[i]=fsHistory[0]; fsHistory[0]=tmp; | |
392 return; | |
393 } | |
33751
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
394 nfree( fsHistory[FF_ARRAY_ELEMS(fsHistory) - 1] ); |
c28c967e40e9
Replace numeric constant fsPersistant_MaxPos for fsHistory array size.
ib
parents:
33740
diff
changeset
|
395 for ( i=FF_ARRAY_ELEMS(fsHistory) - 1;i;i-- ) fsHistory[i]=fsHistory[i - 1]; |
33572 | 396 fsHistory[0]=gstrdup( subject ); |
397 } | |
398 //----------------------------------------------- | |
399 | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
400 static void fs_fsFilterCombo_activate( GtkEntry * entry, |
33572 | 401 gpointer user_data ) |
402 { | |
403 fsFilter=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
404 CheckDir( fsFNameList ); | |
405 } | |
406 | |
407 static void fs_fsFilterCombo_changed( GtkEditable * editable, | |
408 gpointer user_data ) | |
409 { | |
410 const char * str; | |
411 int i; | |
412 | |
413 str=gtk_entry_get_text( GTK_ENTRY(user_data ) ); | |
414 | |
415 switch ( fsType ) | |
416 { | |
417 case fsVideoSelector: | |
418 for( i=0;fsVideoFilterNames[i][0];i++ ) | |
419 if( !strcmp( str,fsVideoFilterNames[i][0] ) ) | |
420 { fsFilter=fsVideoFilterNames[i][1]; fsLastVideoFilterSelected = i; break; } | |
421 break; | |
422 case fsSubtitleSelector: | |
423 for( i=0;fsSubtitleFilterNames[i][0];i++ ) | |
424 if( !strcmp( str,fsSubtitleFilterNames[i][0] ) ) | |
425 { fsFilter=fsSubtitleFilterNames[i][1]; fsLastSubtitleFilterSelected = i; break; } | |
426 break; | |
33776 | 427 /* case fsOtherSelector: |
33572 | 428 for( i=0;fsOtherFilterNames[i][0];i++ ) |
429 if( !strcmp( str,fsOtherFilterNames[i][0] ) ) | |
430 { fsFilter=fsOtherFilterNames[i][1]; break; } | |
33776 | 431 break;*/ |
33572 | 432 case fsAudioSelector: |
433 for( i=0;fsAudioFileNames[i][0];i++ ) | |
434 if( !strcmp( str,fsAudioFileNames[i][0] ) ) | |
435 { fsFilter=fsAudioFileNames[i][1]; fsLastAudioFilterSelected = i; break; } | |
436 break; | |
437 case fsFontSelector: | |
438 for( i=0;fsFontFileNames[i][0];i++ ) | |
439 if( !strcmp( str,fsFontFileNames[i][0] ) ) | |
440 { fsFilter=fsFontFileNames[i][1]; fsLastFontFilterSelected = i; break; } | |
441 break; | |
442 default: return; | |
443 } | |
444 CheckDir( fsFNameList ); | |
445 } | |
446 | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
447 static void fs_fsPathCombo_activate( GtkEntry * entry, |
33572 | 448 gpointer user_data ) |
449 { | |
450 const unsigned char * str; | |
451 gchar * dirname; | |
452 | |
453 str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
454 dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); | |
455 if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); | |
456 g_free( dirname ); | |
457 } | |
458 | |
459 static void fs_fsPathCombo_changed( GtkEditable * editable, | |
460 gpointer user_data ) | |
461 { | |
462 const unsigned char * str; | |
463 gchar * dirname; | |
464 | |
465 str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); | |
466 dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); | |
467 if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); | |
468 g_free( dirname ); | |
469 } | |
470 | |
471 static void fs_Up_released( GtkButton * button, gpointer user_data ) | |
472 { | |
473 chdir( ".." ); | |
474 fsSelectedFile=fsThatDir; | |
475 CheckDir( fsFNameList ); | |
476 gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name_utf8() ); | |
477 return; | |
478 } | |
479 | |
480 static void fs_Ok_released( GtkButton * button, gpointer user_data ) | |
481 { | |
482 GList * item; | |
483 int i = 1; | |
484 struct stat fs; | |
485 | |
486 stat( fsSelectedFile,&fs ); | |
487 if( S_ISDIR(fs.st_mode ) ) | |
488 { | |
489 chdir( fsSelectedFile ); | |
490 fsSelectedFile=fsThatDir; | |
491 CheckDir( fsFNameList ); | |
492 gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name_utf8() ); | |
34364 | 493 gtk_widget_grab_focus( fsFNameList ); |
33572 | 494 return; |
495 } | |
496 | |
497 fsSelectedDirectory=(unsigned char *)get_current_dir_name(); | |
498 switch ( fsType ) | |
499 { | |
500 case fsVideoSelector: | |
34065
8a7056729022
Change guiInfo.Filename by using uiSetFileName() only.
ib
parents:
33897
diff
changeset
|
501 uiSetFileName( fsSelectedDirectory,fsSelectedFile,STREAMTYPE_FILE ); |
33894 | 502 guiInfo.NewPlay=GUI_FILE_NEW; sub_fps=0; |
33572 | 503 fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history |
504 break; | |
505 case fsSubtitleSelector: | |
33897 | 506 setddup( &guiInfo.SubtitleFilename,fsSelectedDirectory,fsSelectedFile ); |
507 mplayerLoadSubtitle( guiInfo.SubtitleFilename ); | |
33572 | 508 break; |
33776 | 509 /* case fsOtherSelector: |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
510 setddup( &guiInfo.Othername,fsSelectedDirectory,fsSelectedFile ); |
33776 | 511 break;*/ |
33572 | 512 case fsAudioSelector: |
33897 | 513 setddup( &guiInfo.AudioFilename,fsSelectedDirectory,fsSelectedFile ); |
33572 | 514 break; |
515 case fsFontSelector: | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
516 setddup( &font_name,fsSelectedDirectory,fsSelectedFile ); |
33763 | 517 mplayerLoadFont(); |
33572 | 518 if ( Preferences ) gtk_entry_set_text( GTK_ENTRY( prEFontName ),font_name ); |
519 break; | |
520 } | |
521 | |
522 HideFileSelect(); | |
523 | |
524 item=fsTopList_items; | |
525 while( item ) | |
526 { | |
527 if ( !strcmp( item->data,fsSelectedDirectory ) ) i=0; | |
528 item=item->next; | |
529 } | |
530 if ( i ) fsTopList_items=g_list_prepend( fsTopList_items,(gchar *)get_current_dir_name_utf8() ); | |
531 if ( uiMainAutoPlay ) { uiMainAutoPlay=0; uiEventHandling( evPlay,0 ); } | |
33731
81f71d910333
Cosmetic: Change prefix for symbolic constants from GMP to GUI.
ib
parents:
33725
diff
changeset
|
532 else gui( GUI_SET_STATE,(void *) GUI_STOP ); |
33572 | 533 } |
534 | |
535 static void fs_Cancel_released( GtkButton * button,gpointer user_data ) | |
536 { | |
537 HideFileSelect(); | |
538 fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history file | |
539 } | |
540 | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
541 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
|
542 GdkEvent * event, gpointer user_data) |
33572 | 543 { |
34364 | 544 fsCurrFNameListSelected = row; |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
545 gtk_clist_get_text( clist,row,1,&fsSelectedFile ); |
33572 | 546 g_free( fsSelectedFileUtf8 ); |
547 fsSelectedFileUtf8 = g_filename_from_utf8( fsSelectedFile, -1, NULL, NULL, NULL ); | |
548 if ( fsSelectedFileUtf8 ) fsSelectedFile = fsSelectedFileUtf8; | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
549 if( event && event->type == GDK_BUTTON_PRESS ) gtk_button_released( GTK_BUTTON( fsOk ) ); |
33572 | 550 } |
551 | |
552 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
|
553 GdkEvent * event, |
33572 | 554 gpointer user_data ) |
555 { | |
34344 | 556 if ( GTK_WIDGET_TYPE( widget ) == GTK_TYPE_BUTTON ) |
557 { | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
558 if (event->key.keyval == GDK_Return) gtk_button_released( GTK_BUTTON( widget ) ); |
34344 | 559 } |
560 else | |
561 { | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
34368
diff
changeset
|
562 switch ( event->key.keyval ) |
34345 | 563 { |
564 case GDK_Escape: | |
565 gtk_button_released( GTK_BUTTON( fsCancel ) ); | |
566 break; | |
567 case GDK_Return: | |
568 gtk_button_released( GTK_BUTTON( fsOk ) ); | |
569 break; | |
570 case GDK_BackSpace: | |
571 gtk_button_released( GTK_BUTTON( fsUp ) ); | |
34351
52a18f850c28
Leave the focus in fsFNameList after key event in file selector.
ib
parents:
34346
diff
changeset
|
572 gtk_widget_grab_focus( fsFNameList ); |
34345 | 573 break; |
574 } | |
34344 | 575 } |
33572 | 576 return FALSE; |
577 } | |
578 | |
579 static gboolean fs_fsFNameList_event( GtkWidget * widget, | |
580 GdkEvent * event, | |
581 gpointer user_data ) | |
582 { | |
583 GdkEventButton *bevent; | |
584 gint row, col; | |
585 | |
586 bevent = (GdkEventButton *) event; | |
587 | |
588 if ( event->type == GDK_BUTTON_RELEASE && bevent->button == 2 ) | |
589 { | |
590 if ( gtk_clist_get_selection_info( GTK_CLIST( widget ), bevent->x, bevent->y, &row, &col ) ) | |
591 { | |
592 gtk_clist_get_text( GTK_CLIST( widget ), row, 1, &fsSelectedFile ); | |
593 g_free( fsSelectedFileUtf8 ); | |
594 fsSelectedFileUtf8 = g_filename_from_utf8( fsSelectedFile, -1, NULL, NULL, NULL ); | |
595 if ( fsSelectedFileUtf8 ) fsSelectedFile = fsSelectedFileUtf8; | |
596 gtk_button_released( GTK_BUTTON( fsOk ) ); | |
597 return TRUE; | |
598 } | |
599 } | |
600 | |
601 return FALSE; | |
602 } | |
603 | |
604 static void fs_Destroy( void ) | |
605 { | |
606 g_free( fsSelectedFileUtf8 ); | |
607 fsSelectedFileUtf8 = NULL; | |
33787
42feff0f8a7b
Start all file dialogs always in last active directory.
ib
parents:
33776
diff
changeset
|
608 g_free( fsSelectedDirectoryUtf8 ); |
42feff0f8a7b
Start all file dialogs always in last active directory.
ib
parents:
33776
diff
changeset
|
609 fsSelectedDirectoryUtf8 = NULL; |
33572 | 610 WidgetDestroy( fsFileSelect, &fsFileSelect ); |
611 } | |
612 | |
613 GtkWidget * create_FileSelect( void ) | |
614 { | |
615 GtkWidget * vbox4; | |
616 GtkWidget * hbox4; | |
617 GtkWidget * vseparator1; | |
618 GtkWidget * hbox6; | |
619 GtkWidget * fsFNameListWindow; | |
620 GtkWidget * hbuttonbox3; | |
621 | |
622 GtkWidget * uppixmapwid; | |
623 GdkPixmap * uppixmap; | |
624 GdkBitmap * upmask; | |
625 GtkStyle * upstyle; | |
626 | |
627 | |
628 fsFileSelect=gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
629 gtk_widget_set_name( fsFileSelect,"fsFileSelect" ); | |
630 gtk_object_set_data( GTK_OBJECT( fsFileSelect ),"fsFileSelect",fsFileSelect ); | |
631 gtk_widget_set_usize( fsFileSelect,512,300 ); | |
632 GTK_WIDGET_SET_FLAGS( fsFileSelect,GTK_CAN_DEFAULT ); | |
633 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 ); | |
634 gtk_window_set_title( GTK_WINDOW( fsFileSelect ),MSGTR_FileSelect ); | |
635 gtk_window_set_position( GTK_WINDOW( fsFileSelect ),GTK_WIN_POS_CENTER ); | |
636 gtk_window_set_policy( GTK_WINDOW( fsFileSelect ),TRUE,TRUE,TRUE ); | |
637 gtk_window_set_wmclass( GTK_WINDOW( fsFileSelect ),"FileSelect","MPlayer" ); | |
638 fsColorMap=gdk_colormap_get_system(); | |
639 | |
640 gtk_widget_realize( fsFileSelect ); | |
641 gtkAddIcon( fsFileSelect ); | |
642 | |
643 style=gtk_widget_get_style( fsFileSelect ); | |
644 dpixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&dmask,&style->bg[GTK_STATE_NORMAL],(gchar **)dir_xpm ); | |
645 fpixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&fmask,&style->bg[GTK_STATE_NORMAL],(gchar **)file_xpm ); | |
646 | |
647 vbox4=AddVBox( AddDialogFrame( fsFileSelect ),0 ); | |
648 hbox4=AddHBox( vbox4,1 ); | |
649 | |
650 fsCombo4=gtk_combo_new(); | |
651 gtk_widget_set_name( fsCombo4,"fsCombo4" ); | |
652 gtk_widget_show( fsCombo4 ); | |
653 gtk_box_pack_start( GTK_BOX( hbox4 ),fsCombo4,TRUE,TRUE,0 ); | |
654 gtk_widget_set_usize( fsCombo4,-2,20 ); | |
655 | |
656 fsPathCombo=GTK_COMBO( fsCombo4 )->entry; | |
657 gtk_widget_set_name( fsPathCombo,"fsPathCombo" ); | |
658 gtk_widget_show( fsPathCombo ); | |
659 gtk_widget_set_usize( fsPathCombo,-2,20 ); | |
660 | |
661 vseparator1=gtk_vseparator_new(); | |
662 gtk_widget_set_name( vseparator1,"vseparator1" ); | |
663 gtk_widget_show( vseparator1 ); | |
664 gtk_box_pack_start( GTK_BOX( hbox4 ),vseparator1,FALSE,TRUE,0 ); | |
665 gtk_widget_set_usize( vseparator1,7,20 ); | |
666 | |
667 upstyle=gtk_widget_get_style( fsFileSelect ); | |
668 uppixmap=gdk_pixmap_colormap_create_from_xpm_d( fsFileSelect->window,fsColorMap,&upmask,&upstyle->bg[GTK_STATE_NORMAL],(gchar **)up_xpm ); | |
669 uppixmapwid=gtk_pixmap_new( uppixmap,upmask ); | |
670 gtk_widget_show( uppixmapwid ); | |
671 | |
672 fsUp=gtk_button_new(); | |
673 gtk_container_add( GTK_CONTAINER(fsUp ),uppixmapwid ); | |
674 gtk_widget_show( fsUp ); | |
675 gtk_box_pack_start( GTK_BOX( hbox4 ),fsUp,FALSE,FALSE,0 ); | |
676 gtk_widget_set_usize( fsUp,65,15 ); | |
677 | |
678 AddHSeparator( vbox4 ); | |
679 | |
680 hbox6=AddHBox( NULL,0 ); | |
681 gtk_box_pack_start( GTK_BOX( vbox4 ),hbox6,TRUE,TRUE,0 ); | |
682 | |
683 fsFNameListWindow=gtk_scrolled_window_new( NULL,NULL ); | |
684 gtk_widget_set_name( fsFNameListWindow,"fsFNameListWindow" ); | |
685 gtk_widget_show( fsFNameListWindow ); | |
686 gtk_box_pack_start( GTK_BOX( hbox6 ),fsFNameListWindow,TRUE,TRUE,0 ); | |
687 gtk_widget_set_usize( fsFNameListWindow,-2,145 ); | |
688 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( fsFNameListWindow ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC ); | |
689 | |
690 fsFNameList=gtk_clist_new( 2 ); | |
691 gtk_widget_set_name( fsFNameList,"fsFNameList" ); | |
692 gtk_container_add( GTK_CONTAINER( fsFNameListWindow ),fsFNameList ); | |
693 gtk_clist_set_column_width( GTK_CLIST( fsFNameList ),0,80 ); | |
694 gtk_clist_set_selection_mode( GTK_CLIST( fsFNameList ),GTK_SELECTION_BROWSE ); | |
695 gtk_clist_column_titles_hide( GTK_CLIST( fsFNameList ) ); | |
696 gtk_clist_set_shadow_type( GTK_CLIST( fsFNameList ),GTK_SHADOW_ETCHED_OUT ); | |
697 | |
698 AddHSeparator( vbox4 ); | |
699 | |
700 List=gtk_combo_new(); | |
701 gtk_widget_set_name( List,"List" ); | |
702 gtk_widget_ref( List ); | |
703 gtk_object_set_data_full( GTK_OBJECT( fsFileSelect ),"List",List,(GtkDestroyNotify)gtk_widget_unref ); | |
704 gtk_widget_show( List ); | |
705 gtk_box_pack_start( GTK_BOX( vbox4 ),List,FALSE,FALSE,0 ); | |
706 gtk_widget_set_usize( List,-2,20 ); | |
707 | |
708 fsFilterCombo=GTK_COMBO( List )->entry; | |
709 gtk_widget_set_name( fsFilterCombo,"fsFilterCombo" ); | |
710 gtk_widget_show( fsFilterCombo ); | |
711 gtk_entry_set_editable (GTK_ENTRY( fsFilterCombo ),FALSE ); | |
712 | |
713 AddHSeparator( vbox4 ); | |
714 | |
715 hbuttonbox3=AddHButtonBox( vbox4 ); | |
716 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox3 ),GTK_BUTTONBOX_END ); | |
717 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox3 ),10 ); | |
718 | |
719 fsOk=AddButton( MSGTR_Ok,hbuttonbox3 ); | |
720 fsCancel=AddButton( MSGTR_Cancel,hbuttonbox3 ); | |
721 | |
722 gtk_signal_connect( GTK_OBJECT( fsFileSelect ),"destroy",GTK_SIGNAL_FUNC( fs_Destroy ), NULL ); | |
723 gtk_signal_connect( GTK_OBJECT( fsFileSelect ),"key_release_event",GTK_SIGNAL_FUNC( on_FileSelect_key_release_event ),NULL ); | |
724 | |
725 gtk_signal_connect( GTK_OBJECT( fsFilterCombo ),"changed",GTK_SIGNAL_FUNC( fs_fsFilterCombo_changed ),fsFilterCombo ); | |
726 gtk_signal_connect( GTK_OBJECT( fsFilterCombo ),"activate",GTK_SIGNAL_FUNC( fs_fsFilterCombo_activate ),fsFilterCombo ); | |
727 gtk_signal_connect( GTK_OBJECT( fsPathCombo ),"changed",GTK_SIGNAL_FUNC( fs_fsPathCombo_changed ),fsPathCombo ); | |
728 gtk_signal_connect( GTK_OBJECT( fsPathCombo ),"activate",GTK_SIGNAL_FUNC( fs_fsPathCombo_activate ),fsPathCombo ); | |
729 gtk_signal_connect( GTK_OBJECT( fsUp ),"released",GTK_SIGNAL_FUNC( fs_Up_released ),fsFNameList ); | |
34344 | 730 gtk_signal_connect( GTK_OBJECT( fsUp ),"key_release_event",GTK_SIGNAL_FUNC( on_FileSelect_key_release_event ),NULL ); |
33572 | 731 gtk_signal_connect( GTK_OBJECT( fsOk ),"released",GTK_SIGNAL_FUNC( fs_Ok_released ),fsCombo4 ); |
34344 | 732 gtk_signal_connect( GTK_OBJECT( fsOk ),"key_release_event",GTK_SIGNAL_FUNC( on_FileSelect_key_release_event ),NULL ); |
33572 | 733 gtk_signal_connect( GTK_OBJECT( fsCancel ),"released",GTK_SIGNAL_FUNC( fs_Cancel_released ),NULL ); |
34344 | 734 gtk_signal_connect( GTK_OBJECT( fsCancel ),"key_release_event",GTK_SIGNAL_FUNC( on_FileSelect_key_release_event ),NULL ); |
33572 | 735 gtk_signal_connect( GTK_OBJECT( fsFNameList ),"select_row",(GtkSignalFunc)fs_fsFNameList_select_row,NULL ); |
736 gtk_signal_connect( GTK_OBJECT( fsFNameList ),"event", (GtkSignalFunc)fs_fsFNameList_event,NULL ); | |
737 | |
738 return fsFileSelect; | |
739 } |