… | |
… | |
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 |
|
|
22 | # define DEBUG(stmt) stmt; |
|
|
23 | #else |
|
|
24 | # define DEBUG(stmt) |
|
|
25 | #endif |
|
|
26 | |
21 | ///////////////////////////////////////////////////////////////////////////// |
27 | ///////////////////////////////////////////////////////////////////////////// |
22 | |
28 | |
23 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
29 | gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) |
24 | { |
30 | { |
|
|
31 | DEBUG ((printf ("gtk_file_chooser_get_filename<%s>\n", last_path))) |
25 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
32 | return g_strdup (last_path ? last_path : "/nonex1st4nt"); |
26 | } |
33 | } |
27 | |
34 | |
28 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
35 | gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) |
29 | { |
36 | { |
… | |
… | |
55 | return 1; |
62 | return 1; |
56 | } |
63 | } |
57 | |
64 | |
58 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
65 | gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) |
59 | { |
66 | { |
60 | return g_strdup ("/nonex1st4nt/"); |
67 | DEBUG ((printf ("gtk_file_chooser_get_current_folder\n"))) |
|
|
68 | return g_strdup ("/tmp/gtkbfc"); |
61 | } |
69 | } |
62 | |
70 | |
63 | ///////////////////////////////////////////////////////////////////////////// |
71 | ///////////////////////////////////////////////////////////////////////////// |
64 | |
72 | |
65 | static const gchar * |
73 | static const gchar * |
… | |
… | |
72 | |
80 | |
73 | return rv; |
81 | return rv; |
74 | } |
82 | } |
75 | |
83 | |
76 | static gchar * |
84 | static gchar * |
77 | to_uri (gchar * file) |
85 | to_uri (gchar *file) |
78 | { |
86 | { |
79 | gchar *rv = NULL; |
87 | gchar *rv = NULL; |
80 | |
88 | |
81 | if (file) |
89 | if (file) |
82 | { |
90 | { |
… | |
… | |
107 | } |
115 | } |
108 | |
116 | |
109 | return files; |
117 | return files; |
110 | } |
118 | } |
111 | |
119 | |
112 | gchar * gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
120 | gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) |
113 | { |
121 | { |
114 | 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; |
115 | } |
125 | } |
116 | |
126 | |
117 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
127 | gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) |
118 | { |
128 | { |
119 | return gtk_file_chooser_set_filename (chooser, from_uri (uri)); |
129 | return gtk_file_chooser_set_filename (chooser, from_uri (uri)); |
… | |
… | |
134 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
144 | return to_uri (gtk_file_chooser_get_current_folder (chooser)); |
135 | } |
145 | } |
136 | |
146 | |
137 | ///////////////////////////////////////////////////////////////////////////// |
147 | ///////////////////////////////////////////////////////////////////////////// |
138 | |
148 | |
139 | static gboolean activate_cb (gpointer data) |
149 | static gboolean disable_cb (gpointer data) |
140 | { |
150 | { |
141 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
151 | // set the path again to avoid a race condition |
142 | //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data))))); |
152 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (data), "/tmp/gtkbfc/empty"); |
143 | g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
153 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 0); |
|
|
154 | //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
144 | return FALSE; |
155 | return FALSE; |
145 | } |
156 | } |
146 | |
157 | |
147 | static gboolean unmap_cb (gpointer data) |
|
|
148 | { |
|
|
149 | gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); |
|
|
150 | return FALSE; |
|
|
151 | } |
|
|
152 | |
|
|
153 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
158 | static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) |
154 | { |
159 | { |
|
|
160 | if (last_path) |
|
|
161 | { |
|
|
162 | g_free (last_path); |
|
|
163 | last_path = 0; |
|
|
164 | } |
|
|
165 | |
155 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
166 | g_io_channel_read_to_end (source, &last_path, 0, 0); |
156 | g_io_channel_unref (source); |
167 | g_io_channel_unref (source); |
157 | activate_cb (data); |
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 | { |
|
|
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 | } |
|
|
183 | |
158 | return FALSE; |
184 | return FALSE; |
159 | } |
185 | } |
160 | |
186 | |
161 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
187 | static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
162 | { |
188 | { |
… | |
… | |
182 | argv [3] = 0; |
208 | argv [3] = 0; |
183 | |
209 | |
184 | mkdir ("/tmp/gtkbfc", 0777); |
210 | mkdir ("/tmp/gtkbfc", 0777); |
185 | 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)); |
186 | |
212 | |
187 | if (save) |
|
|
188 | ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_current_name"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); |
|
|
189 | else |
|
|
190 | ((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"); |
191 | |
|
|
192 | if (last_path) |
|
|
193 | { |
|
|
194 | g_free (last_path); |
|
|
195 | last_path = 0; |
|
|
196 | } |
|
|
197 | |
214 | |
198 | gint stdout_fd = -1; |
215 | gint stdout_fd = -1; |
199 | |
216 | |
200 | 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)) |
201 | { |
218 | { |
202 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
219 | GIOChannel *channel = g_io_channel_unix_new (stdout_fd); |
203 | gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); |
|
|
204 | 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); |
205 | g_idle_add (unmap_cb, widget); |
221 | g_idle_add (disable_cb, widget); |
206 | //g_timeout_add (1, unmap_cb, widget); |
|
|
207 | } |
222 | } |
208 | else |
223 | else |
209 | ;//gtk_widget_show (widget); |
224 | ;//gtk_widget_show (widget); |
210 | } |
225 | } |
211 | |
226 | |