annotate nuklear_ui/filechooser_gtk.c @ 2355:94cf5cc89227

Add an option to use the system file picker on Linux and Windows
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Oct 2023 19:22:01 -0700
parents
children 12d594e69e04
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[] = {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 #ifdef X86_64
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 "/usr/lib/x86_64-linux-gnu/libgtk-3.so.0",
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 "/usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0",
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 #elif X86_32
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 "/usr/lib/i386-linux-gnu/libgtk-3.so.0",
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 "/usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0",
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 #else
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 //TODO: what are these paths on ARM?
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 #endif
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 };
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 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
52 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
53 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
54 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
55 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
56 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 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
58 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 if (so) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 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
61
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_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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 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
77 return funcs;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 }
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 error_cleanup:
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 free(funcs);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 dlclose(so);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
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 return funcs;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 }
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 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
89 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 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
91 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 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
94 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 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
96 if (!g) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 return NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 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
100 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
101 "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
102 "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
103 NULL
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 );
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 if (!chooser) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 return NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 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
109 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
110 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 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
112 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
113 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
114 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
115
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 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
152 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
153 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
154 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
155 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
156
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 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
176 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
177 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
178 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 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
180 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
181 {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 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
183 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 return ret;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 }