… | |
… | |
16 | |
16 | |
17 | 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); |
18 | |
18 | |
19 | static gchar *last_path; |
19 | static gchar *last_path; |
20 | |
20 | |
|
|
21 | #if 0 |
21 | #define DEBUG(stmt) stmt; |
22 | # define DEBUG(stmt) stmt; |
|
|
23 | #else |
|
|
24 | # define DEBUG(stmt) |
|
|
25 | #endif |
22 | |
26 | |
23 | ///////////////////////////////////////////////////////////////////////////// |
27 | ///////////////////////////////////////////////////////////////////////////// |
24 | |
28 | |
25 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
29 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
26 | { |
30 | { |
27 | DEBUG ((printf ("gtk_file_chooser_get_filename %s\n", last_path))) |
31 | DEBUG ((printf ("gtk_file_chooser_get_filename<%s>\n", last_path))) |
28 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
32 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
29 | } |
33 | } |
30 | |
34 | |
31 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
35 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
32 | { |
36 | { |
… | |
… | |
59 | } |
63 | } |
60 | |
64 | |
61 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
65 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
62 | { |
66 | { |
63 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
67 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
64 | return g_strdup ("/nonex1st4nt/"); |
68 | return g_strdup ("/tmp/gtkbfc"); |
65 | } |
69 | } |
66 | |
70 | |
67 | ///////////////////////////////////////////////////////////////////////////// |
71 | ///////////////////////////////////////////////////////////////////////////// |
68 | |
72 | |
69 | static const gchar * |
73 | static const gchar * |
… | |
… | |
114 | } |
118 | } |
115 | |
119 | |
116 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
120 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
117 | { |
121 | { |
118 | gchar *uri = to_uri(gtk_file_chooser_get_filename (chooser)); |
122 | gchar *uri = to_uri(gtk_file_chooser_get_filename (chooser)); |
119 | DEBUG ((printf ("gtk_file_chooser_get_uri %s\n", uri))); |
123 | DEBUG ((printf ("gtk_file_chooser_get_uri<%s>\n", uri))); |
120 | return uri; |
124 | return uri; |
121 | } |
125 | } |
122 | |
126 | |
123 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
127 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
124 | { |
128 | { |
… | |
… | |
140 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
144 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
141 | } |
145 | } |
142 | |
146 | |
143 | ///////////////////////////////////////////////////////////////////////////// |
147 | ///////////////////////////////////////////////////////////////////////////// |
144 | |
148 | |
145 | static gboolean activate_cb (gpointer data) |
|
|
146 | { |
|
|
147 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
|
|
148 | //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data))))); |
|
|
149 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
|
|
150 | return FALSE; |
|
|
151 | } |
|
|
152 | |
|
|
153 | static gboolean unmap_cb (gpointer data) |
149 | static gboolean disable_cb (gpointer data) |
154 | { |
150 | { |
|
|
151 | // set the path again to avoid a race condition |
|
|
152 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (data), "/tmp/gtkbfc/empty"); |
|
|
153 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 0); |
155 | gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
154 | //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
156 | return FALSE; |
155 | return FALSE; |
157 | } |
156 | } |
158 | |
157 | |
159 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
158 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
160 | { |
159 | { |
… | |
… | |
164 | last_path = 0; |
163 | last_path = 0; |
165 | } |
164 | } |
166 | |
165 | |
167 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
166 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
168 | g_io_channel_unref (source); |
167 | g_io_channel_unref (source); |
169 | activate_cb (data); |
|
|
170 | |
168 | |
|
|
169 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 1); |
|
|
170 | |
|
|
171 | if (!last_path || *last_path != '/') |
|
|
172 | { |
|
|
173 | DEBUG ((printf ("read_result cancel\n"))) |
|
|
174 | g_free (last_path); |
|
|
175 | last_path = 0; |
|
|
176 | } |
|
|
177 | else |
|
|
178 | { |
171 | DEBUG ((printf ("read_result<%s>\n", last_path))); |
179 | DEBUG ((printf ("read_result<%s>\n", last_path))) |
|
|
180 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
|
|
181 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
|
|
182 | } |
172 | |
183 | |
173 | return FALSE; |
184 | return FALSE; |
174 | } |
185 | } |
175 | |
186 | |
176 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
187 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
… | |
… | |
197 | argv [3] = 0; |
208 | argv [3] = 0; |
198 | |
209 | |
199 | mkdir ("/tmp/gtkbfc", 0777); |
210 | mkdir ("/tmp/gtkbfc", 0777); |
200 | close (open ("/tmp/gtkbfc/empty", O_WRONLY|O_CREAT|O_TRUNC, 0666)); |
211 | close (open ("/tmp/gtkbfc/empty", O_WRONLY|O_CREAT|O_TRUNC, 0666)); |
201 | |
212 | |
202 | if (save) |
|
|
203 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_current_name"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
|
|
204 | else |
|
|
205 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
213 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
206 | |
214 | |
207 | gint stdout_fd = -1; |
215 | gint stdout_fd = -1; |
208 | |
216 | |
209 | if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0)) |
217 | if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0)) |
210 | { |
218 | { |
211 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
219 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
212 | gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); |
|
|
213 | g_io_add_watch (channel, G_IO_IN, read_result, widget); |
220 | g_io_add_watch (channel, G_IO_IN | G_IO_ERR | G_IO_HUP, read_result, widget); |
214 | g_idle_add (unmap_cb, widget); |
221 | g_idle_add (disable_cb, widget); |
215 | //g_timeout_add (1, unmap_cb, widget); |
|
|
216 | } |
222 | } |
217 | else |
223 | else |
218 | ;//gtk_widget_show (widget); |
224 | ;//gtk_widget_show (widget); |
219 | } |
225 | } |
220 | |
226 | |