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