|
|
1 | /* this file is publiched under the gnu gpl license, version 3 or any later */ |
|
|
2 | |
1 | #define _GNU_SOURCE |
3 | #define _GNU_SOURCE |
2 | |
4 | |
3 | #include <dlfcn.h> |
5 | #include <dlfcn.h> |
4 | #include <glib.h> |
6 | #include <glib.h> |
5 | #include <gtk/gtk.h> |
7 | #include <gtk/gtk.h> |
… | |
… | |
14 | |
16 | |
15 | static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); |
17 | static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); |
16 | |
18 | |
17 | static gchar *last_path; |
19 | static gchar *last_path; |
18 | |
20 | |
|
|
21 | #if 0 |
|
|
22 | # define DEBUG(stmt) stmt; |
|
|
23 | #else |
|
|
24 | # define DEBUG(stmt) |
|
|
25 | #endif |
|
|
26 | |
19 | ///////////////////////////////////////////////////////////////////////////// |
27 | ///////////////////////////////////////////////////////////////////////////// |
20 | |
28 | |
21 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
29 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
22 | { |
30 | { |
|
|
31 | DEBUG ((printf ("gtk_file_chooser_get_filename %s\n", last_path))) |
23 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
32 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
24 | } |
33 | } |
25 | |
34 | |
26 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
35 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
27 | { |
36 | { |
… | |
… | |
53 | return 1; |
62 | return 1; |
54 | } |
63 | } |
55 | |
64 | |
56 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
65 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
57 | { |
66 | { |
58 | return g_strdup ("/nonex1st4nt/"); |
67 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
|
|
68 | return g_strdup ("/tmp/gtkbfc"); |
59 | } |
69 | } |
60 | |
70 | |
61 | ///////////////////////////////////////////////////////////////////////////// |
71 | ///////////////////////////////////////////////////////////////////////////// |
62 | |
72 | |
63 | static const gchar * |
73 | static const gchar * |
… | |
… | |
70 | |
80 | |
71 | return rv; |
81 | return rv; |
72 | } |
82 | } |
73 | |
83 | |
74 | static gchar * |
84 | static gchar * |
75 | to_uri (gchar * file) |
85 | to_uri (gchar *file) |
76 | { |
86 | { |
77 | gchar *rv = NULL; |
87 | gchar *rv = NULL; |
78 | |
88 | |
79 | if (file) |
89 | if (file) |
80 | { |
90 | { |
… | |
… | |
105 | } |
115 | } |
106 | |
116 | |
107 | return files; |
117 | return files; |
108 | } |
118 | } |
109 | |
119 | |
110 | gchar * gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
120 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
111 | { |
121 | { |
112 | return to_uri(gtk_file_chooser_get_filename (chooser)); |
122 | gchar *uri = to_uri(gtk_file_chooser_get_filename (chooser)); |
|
|
123 | DEBUG ((printf ("gtk_file_chooser_get_uri %s\n", uri))); |
|
|
124 | return uri; |
113 | } |
125 | } |
114 | |
126 | |
115 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
127 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
116 | { |
128 | { |
117 | return gtk_file_chooser_set_filename (chooser, from_uri (uri)); |
129 | return gtk_file_chooser_set_filename (chooser, from_uri (uri)); |
… | |
… | |
134 | |
146 | |
135 | ///////////////////////////////////////////////////////////////////////////// |
147 | ///////////////////////////////////////////////////////////////////////////// |
136 | |
148 | |
137 | static gboolean activate_cb (gpointer data) |
149 | static gboolean activate_cb (gpointer data) |
138 | { |
150 | { |
|
|
151 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 1); |
139 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
152 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
140 | //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data))))); |
153 | //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data))))); |
141 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
154 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
142 | return FALSE; |
155 | return FALSE; |
143 | } |
156 | } |
144 | |
157 | |
145 | static gboolean unmap_cb (gpointer data) |
158 | static gboolean unmap_cb (gpointer data) |
146 | { |
159 | { |
|
|
160 | // set the path again to avoid a race condition |
|
|
161 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (data), "/tmp/gtkbfc/empty"); |
|
|
162 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 0); |
147 | gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
163 | //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
148 | return FALSE; |
164 | return FALSE; |
149 | } |
165 | } |
150 | |
166 | |
151 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
167 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
152 | { |
168 | { |
|
|
169 | if (last_path) |
|
|
170 | { |
|
|
171 | g_free (last_path); |
|
|
172 | last_path = 0; |
|
|
173 | } |
|
|
174 | |
153 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
175 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
154 | g_io_channel_unref (source); |
176 | g_io_channel_unref (source); |
155 | activate_cb (data); |
177 | activate_cb (data); |
|
|
178 | |
|
|
179 | DEBUG ((printf ("read_result<%s>\n", last_path))); |
|
|
180 | |
156 | return FALSE; |
181 | return FALSE; |
157 | } |
182 | } |
158 | |
183 | |
159 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
184 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
160 | { |
185 | { |
… | |
… | |
180 | argv [3] = 0; |
205 | argv [3] = 0; |
181 | |
206 | |
182 | mkdir ("/tmp/gtkbfc", 0777); |
207 | mkdir ("/tmp/gtkbfc", 0777); |
183 | close (open ("/tmp/gtkbfc/empty", O_WRONLY|O_CREAT|O_TRUNC, 0666)); |
208 | close (open ("/tmp/gtkbfc/empty", O_WRONLY|O_CREAT|O_TRUNC, 0666)); |
184 | |
209 | |
185 | if (save) |
|
|
186 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_current_name"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
|
|
187 | else |
|
|
188 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
210 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
189 | |
|
|
190 | if (last_path) |
|
|
191 | { |
|
|
192 | g_free (last_path); |
|
|
193 | last_path = 0; |
|
|
194 | } |
|
|
195 | |
211 | |
196 | gint stdout_fd = -1; |
212 | gint stdout_fd = -1; |
197 | |
213 | |
198 | if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0)) |
214 | if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0)) |
199 | { |
215 | { |
200 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
216 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
201 | gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); |
217 | //gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); |
202 | g_io_add_watch (channel, G_IO_IN, read_result, widget); |
218 | g_io_add_watch (channel, G_IO_IN, read_result, widget); |
203 | g_idle_add (unmap_cb, widget); |
219 | g_idle_add (unmap_cb, widget); |
204 | //g_timeout_add (1, unmap_cb, widget); |
220 | //g_timeout_add (1, unmap_cb, widget); |
205 | } |
221 | } |
206 | else |
222 | else |