… | |
… | |
26 | |
26 | |
27 | ///////////////////////////////////////////////////////////////////////////// |
27 | ///////////////////////////////////////////////////////////////////////////// |
28 | |
28 | |
29 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
29 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
30 | { |
30 | { |
31 | DEBUG ((printf ("gtk_file_chooser_get_filename %s\n", last_path))) |
31 | DEBUG ((printf ("gtk_file_chooser_get_filename<%s>\n", last_path))) |
32 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
32 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
33 | } |
33 | } |
34 | |
34 | |
35 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
35 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
36 | { |
36 | { |
… | |
… | |
63 | } |
63 | } |
64 | |
64 | |
65 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
65 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
66 | { |
66 | { |
67 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
67 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
68 | return g_strdup ("/nonex1st4nt/"); |
68 | return g_strdup ("/tmp/gtkbfc"); |
69 | } |
69 | } |
70 | |
70 | |
71 | ///////////////////////////////////////////////////////////////////////////// |
71 | ///////////////////////////////////////////////////////////////////////////// |
72 | |
72 | |
73 | static const gchar * |
73 | static const gchar * |
… | |
… | |
118 | } |
118 | } |
119 | |
119 | |
120 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
120 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
121 | { |
121 | { |
122 | gchar *uri = 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))); |
123 | DEBUG ((printf ("gtk_file_chooser_get_uri<%s>\n", uri))); |
124 | return uri; |
124 | return uri; |
125 | } |
125 | } |
126 | |
126 | |
127 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
127 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
128 | { |
128 | { |
… | |
… | |
144 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
144 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
145 | } |
145 | } |
146 | |
146 | |
147 | ///////////////////////////////////////////////////////////////////////////// |
147 | ///////////////////////////////////////////////////////////////////////////// |
148 | |
148 | |
149 | static gboolean activate_cb (gpointer data) |
|
|
150 | { |
|
|
151 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
|
|
152 | //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data))))); |
|
|
153 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
|
|
154 | return FALSE; |
|
|
155 | } |
|
|
156 | |
|
|
157 | static gboolean unmap_cb (gpointer data) |
149 | static gboolean disable_cb (gpointer data) |
158 | { |
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); |
159 | gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
154 | //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
160 | return FALSE; |
155 | return FALSE; |
161 | } |
156 | } |
162 | |
157 | |
163 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
158 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
164 | { |
159 | { |
… | |
… | |
168 | last_path = 0; |
163 | last_path = 0; |
169 | } |
164 | } |
170 | |
165 | |
171 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
166 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
172 | g_io_channel_unref (source); |
167 | g_io_channel_unref (source); |
173 | activate_cb (data); |
|
|
174 | |
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 | { |
175 | 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 | } |
176 | |
183 | |
177 | return FALSE; |
184 | return FALSE; |
178 | } |
185 | } |
179 | |
186 | |
180 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
187 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
… | |
… | |
201 | argv [3] = 0; |
208 | argv [3] = 0; |
202 | |
209 | |
203 | mkdir ("/tmp/gtkbfc", 0777); |
210 | mkdir ("/tmp/gtkbfc", 0777); |
204 | 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)); |
205 | |
212 | |
206 | if (save) |
|
|
207 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_current_name"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
|
|
208 | else |
|
|
209 | ((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"); |
210 | |
214 | |
211 | gint stdout_fd = -1; |
215 | gint stdout_fd = -1; |
212 | |
216 | |
213 | 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)) |
214 | { |
218 | { |
215 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
219 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
216 | gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); |
|
|
217 | 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); |
218 | g_idle_add (unmap_cb, widget); |
221 | g_idle_add (disable_cb, widget); |
219 | //g_timeout_add (1, unmap_cb, widget); |
|
|
220 | } |
222 | } |
221 | else |
223 | else |
222 | ;//gtk_widget_show (widget); |
224 | ;//gtk_widget_show (widget); |
223 | } |
225 | } |
224 | |
226 | |