annotate nuklear_ui/filechooser_gtk.c @ 2496:187bc857a76a default tip

Fix bug in MED mapper protection bit implementation
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 Apr 2024 23:33:11 -0700
parents 12d594e69e04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stddef.h>
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdint.h>
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stdio.h>
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <gtk/gtk.h>
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include <dlfcn.h>
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 typedef GtkWidget* (*gtk_file_chooser_dialog_new_t)(const gchar *title, GtkWindow *parent, GtkFileChooserAction action, const gchar *first_button_text, ...);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 typedef gint (*gtk_dialog_run_t)(GtkDialog *dialog);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 typedef void (*gtk_widget_destroy_t)(GtkWidget *widget);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 typedef gchar* (*gtk_file_chooser_get_filename_t)(GtkFileChooser *chooser);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 typedef gboolean (*gtk_init_check_t)(int *argc, char **argv);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 typedef gboolean (*gtk_file_chooser_set_current_folder_t)(GtkFileChooser *chooser, const gchar *filename);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 typedef void (*gtk_file_chooser_setadd_filter_t)(GtkFileChooser *chooser, GtkFileFilter *filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 typedef gboolean (*gtk_events_pending_t)(void);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 typedef gboolean (*gtk_main_iteration_t)(void);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 typedef GtkFileFilter* (*gtk_file_filter_new_t)(void);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 typedef void (*gtk_file_filter_set_name_t)(GtkFileFilter *filter, const gchar *name);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 typedef void (*gtk_file_filter_add_pattern_t)(GtkFileFilter *filter, const gchar *pattern);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 typedef struct {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 gtk_file_chooser_dialog_new_t gtk_file_chooser_dialog_new;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 gtk_dialog_run_t gtk_dialog_run;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 gtk_widget_destroy_t gtk_widget_destroy;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 gtk_file_chooser_get_filename_t gtk_file_chooser_get_filename;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 gtk_file_chooser_set_current_folder_t gtk_file_chooser_set_current_folder;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 gtk_file_chooser_setadd_filter_t gtk_file_chooser_add_filter;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 gtk_file_chooser_setadd_filter_t gtk_file_chooser_set_filter;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 gtk_file_filter_new_t gtk_file_filter_new;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 gtk_file_filter_set_name_t gtk_file_filter_set_name;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 gtk_file_filter_add_pattern_t gtk_file_filter_add_pattern;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 gtk_init_check_t gtk_init_check;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 gtk_events_pending_t gtk_events_pending;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 gtk_main_iteration_t gtk_main_iteration;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 } gtk;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 #define LOAD_SYM(s, t, name) t->name = dlsym(s, #name); if (!t->name) { fputs("filechooser_gtk: Failed to load " #name "\n", stderr); goto error_cleanup; }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 static gtk* check_init_gtk(void)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 static const char *so_paths[] = {
2356
12d594e69e04 Don't use absolute paths for GTK so things work across distros without extra work
Michael Pavone <pavone@retrodev.com>
parents: 2355
diff changeset
41 "libgtk-3.so.0",
12d594e69e04 Don't use absolute paths for GTK so things work across distros without extra work
Michael Pavone <pavone@retrodev.com>
parents: 2355
diff changeset
42 "libgtk-x11-2.0.so.0",
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 };
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 static gtk *funcs;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 static uint8_t already_init;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 if (!already_init) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 void *so = NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 for (int i = 0; !so && i < sizeof(so_paths)/sizeof(*so_paths); i++)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 so = dlopen(so_paths[i], RTLD_NOW | RTLD_LOCAL);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 if (so) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 funcs = calloc(1, sizeof(gtk));
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 LOAD_SYM(so, funcs, gtk_file_chooser_dialog_new)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 LOAD_SYM(so, funcs, gtk_dialog_run)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 LOAD_SYM(so, funcs, gtk_widget_destroy)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 LOAD_SYM(so, funcs, gtk_file_chooser_get_filename)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 LOAD_SYM(so, funcs, gtk_file_chooser_set_current_folder)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 LOAD_SYM(so, funcs, gtk_file_chooser_add_filter)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 LOAD_SYM(so, funcs, gtk_file_chooser_set_filter)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 LOAD_SYM(so, funcs, gtk_file_filter_new)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 LOAD_SYM(so, funcs, gtk_file_filter_set_name)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 LOAD_SYM(so, funcs, gtk_file_filter_add_pattern)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 LOAD_SYM(so, funcs, gtk_init_check)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 LOAD_SYM(so, funcs, gtk_events_pending)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 LOAD_SYM(so, funcs, gtk_main_iteration)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 if (funcs->gtk_init_check(NULL, NULL)) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 return funcs;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 error_cleanup:
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 free(funcs);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 dlclose(so);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 return funcs;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 uint8_t native_filechooser_available(void)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 return !!check_init_gtk();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 char* native_filechooser_pick(const char *title, const char *start_directory)
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 gtk *g = check_init_gtk();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 if (!g) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 return NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 GtkFileChooser *chooser = (GtkFileChooser *)g->gtk_file_chooser_dialog_new(
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 "Cancel", GTK_RESPONSE_CANCEL,
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 "Open", GTK_RESPONSE_ACCEPT,
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 NULL
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 );
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 if (!chooser) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 return NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 if (start_directory) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 g->gtk_file_chooser_set_current_folder(chooser, start_directory);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 GtkFileFilter *filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 g->gtk_file_filter_set_name(filter, "All Files");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 g->gtk_file_filter_add_pattern(filter, "*");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 g->gtk_file_filter_set_name(filter, "All Supported Types");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 g->gtk_file_filter_add_pattern(filter, "*.zip");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 g->gtk_file_filter_add_pattern(filter, "*.bin");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 g->gtk_file_filter_add_pattern(filter, "*.bin.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 g->gtk_file_filter_add_pattern(filter, "*.gen");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 g->gtk_file_filter_add_pattern(filter, "*.gen.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 g->gtk_file_filter_add_pattern(filter, "*.md");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 g->gtk_file_filter_add_pattern(filter, "*.md.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 g->gtk_file_filter_add_pattern(filter, "*.sms");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 g->gtk_file_filter_add_pattern(filter, "*.sms.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 g->gtk_file_filter_add_pattern(filter, "*.gg");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 g->gtk_file_filter_add_pattern(filter, "*.gg.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 g->gtk_file_filter_add_pattern(filter, "*.sg");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 g->gtk_file_filter_add_pattern(filter, "*.sg.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 g->gtk_file_filter_add_pattern(filter, "*.cue");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 g->gtk_file_filter_add_pattern(filter, "*.toc");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 g->gtk_file_filter_add_pattern(filter, "*.flac");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 g->gtk_file_filter_add_pattern(filter, "*.vgm");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 g->gtk_file_filter_add_pattern(filter, "*.vgz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 g->gtk_file_filter_add_pattern(filter, "*.vgm.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 g->gtk_file_chooser_set_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 g->gtk_file_filter_set_name(filter, "Genesis/MD");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 g->gtk_file_filter_add_pattern(filter, "*.zip");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 g->gtk_file_filter_add_pattern(filter, "*.bin");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 g->gtk_file_filter_add_pattern(filter, "*.bin.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 g->gtk_file_filter_add_pattern(filter, "*.gen");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 g->gtk_file_filter_add_pattern(filter, "*.gen.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 g->gtk_file_filter_add_pattern(filter, "*.md");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 g->gtk_file_filter_add_pattern(filter, "*.md.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 g->gtk_file_filter_set_name(filter, "Sega/Mega CD");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 g->gtk_file_filter_add_pattern(filter, "*.cue");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 g->gtk_file_filter_add_pattern(filter, "*.toc");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 g->gtk_file_filter_set_name(filter, "Sega 8-bit");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 g->gtk_file_filter_add_pattern(filter, "*.sms");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 g->gtk_file_filter_add_pattern(filter, "*.sms.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 g->gtk_file_filter_add_pattern(filter, "*.gg");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 g->gtk_file_filter_add_pattern(filter, "*.gg.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 g->gtk_file_filter_add_pattern(filter, "*.sg");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 g->gtk_file_filter_add_pattern(filter, "*.sg.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 filter = g->gtk_file_filter_new();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 g->gtk_file_filter_set_name(filter, "Audio/VGM");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 g->gtk_file_filter_add_pattern(filter, "*.flac");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 g->gtk_file_filter_add_pattern(filter, "*.vgm");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 g->gtk_file_filter_add_pattern(filter, "*.vgz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 g->gtk_file_filter_add_pattern(filter, "*.vgm.gz");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 g->gtk_file_chooser_add_filter(chooser, filter);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 char *ret = NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 if (GTK_RESPONSE_ACCEPT == g->gtk_dialog_run((GtkDialog*)chooser)) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 ret = g->gtk_file_chooser_get_filename(chooser);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 g->gtk_widget_destroy((GtkWidget *)chooser);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 while (g->gtk_events_pending())
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 g->gtk_main_iteration();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 return ret;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 }