ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gtkbfc/gtkbfc.c
(Generate patch)

Comparing gtkbfc/gtkbfc.c (file contents):
Revision 1.11 by root, Sat Aug 18 11:08:01 2007 UTC vs.
Revision 1.16 by root, Sat Aug 18 14:26:44 2007 UTC

10#include <unistd.h> 10#include <unistd.h>
11#include <sys/types.h> 11#include <sys/types.h>
12#include <sys/stat.h> 12#include <sys/stat.h>
13#include <fcntl.h> 13#include <fcntl.h>
14 14
15static const char version[] = "gtkbfc version 0.0";
16
15static char *helper = "/etc/gtkbfc-helper"; 17static char *helper = "/etc/gtkbfc-helper";
16 18
17static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); 19static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties);
18 20
19static gchar *last_path; 21static gchar *last_path;
26 28
27///////////////////////////////////////////////////////////////////////////// 29/////////////////////////////////////////////////////////////////////////////
28 30
29gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) 31gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser)
30{ 32{
31 DEBUG ((printf ("gtk_file_chooser_get_filename %s\n", last_path))) 33 DEBUG ((printf ("gtk_file_chooser_get_filename<%s>\n", last_path)))
32 return g_strdup (last_path ? last_path : "/nonex1st4nt"); 34 return g_strdup (last_path ? last_path : "/nonex1st4nt");
33} 35}
34 36
35gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) 37gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename)
36{ 38{
118} 120}
119 121
120gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser) 122gchar *gtk_file_chooser_get_uri (GtkFileChooser *chooser)
121{ 123{
122 gchar *uri = to_uri(gtk_file_chooser_get_filename (chooser)); 124 gchar *uri = to_uri(gtk_file_chooser_get_filename (chooser));
123 DEBUG ((printf ("gtk_file_chooser_get_uri %s\n", uri))); 125 DEBUG ((printf ("gtk_file_chooser_get_uri<%s>\n", uri)));
124 return uri; 126 return uri;
125} 127}
126 128
127gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) 129gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri)
128{ 130{
144 return to_uri (gtk_file_chooser_get_current_folder (chooser)); 146 return to_uri (gtk_file_chooser_get_current_folder (chooser));
145} 147}
146 148
147///////////////////////////////////////////////////////////////////////////// 149/////////////////////////////////////////////////////////////////////////////
148 150
149static gboolean activate_cb (gpointer data)
150{
151 gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 1);
152 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE);
153 //fprintf (stderr, "ad %d\n", gtk_window_activate_default (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data)))));
154 g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated");
155 return FALSE;
156}
157
158static gboolean unmap_cb (gpointer data) 151static gboolean disable_cb (gpointer data)
159{ 152{
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"); 153 ((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); 154
163 //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); 155 GtkWidget *toplevel = gtk_widget_get_toplevel (data);
156 if (toplevel) gtk_widget_set_sensitive (toplevel, 0);
157
158 gtk_widget_unref (data);
159
164 return FALSE; 160 return FALSE;
165} 161}
166 162
167static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) 163static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data)
168{ 164{
172 last_path = 0; 168 last_path = 0;
173 } 169 }
174 170
175 g_io_channel_read_to_end (source, &last_path, 0, 0); 171 g_io_channel_read_to_end (source, &last_path, 0, 0);
176 g_io_channel_unref (source); 172 g_io_channel_unref (source);
177 activate_cb (data);
178 173
174 GtkWidget *toplevel = gtk_widget_get_toplevel (data);
175 if (toplevel) gtk_widget_set_sensitive (toplevel, 1);
176
177 if (!last_path || *last_path != '/')
178 {
179 DEBUG ((printf ("read_result cancel\n")))
180 g_free (last_path);
181 last_path = 0;
182
183 if (toplevel)
184 {
185 GdkEvent ev = { GDK_DELETE };
186 g_signal_emit_by_name (toplevel, "delete-event", &ev);
187 }
188 }
189 else
190 {
179 DEBUG ((printf ("read_result<%s>\n", last_path))); 191 DEBUG ((printf ("read_result<%s>\n", last_path)))
192 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE);
193 g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated");
194 }
195
196 gtk_widget_unref (data);
180 197
181 return FALSE; 198 return FALSE;
182} 199}
183 200
184static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) 201static gboolean map_cb (GtkWidget *widget, gpointer user_data)
185{ 202{
186 gchar *argv[10]; 203 gchar *argv[10];
187 gboolean save = 0; 204 gboolean save = 0;
188 char xid [40]; 205 char xid [40];
189 206
193 { 210 {
194 case GTK_FILE_CHOOSER_ACTION_SAVE: argv [1] = "save "; save = 1;break; 211 case GTK_FILE_CHOOSER_ACTION_SAVE: argv [1] = "save "; save = 1;break;
195 case GTK_FILE_CHOOSER_ACTION_OPEN: argv [1] = "load "; break; 212 case GTK_FILE_CHOOSER_ACTION_OPEN: argv [1] = "load "; break;
196 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: argv [1] = "mkdir "; save = 1; break; 213 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: argv [1] = "mkdir "; save = 1; break;
197 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: argv [1] = "cd "; break; 214 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: argv [1] = "cd "; break;
198 default: argv [1] = "<filechooser> "; break; 215 default: argv [1] = "<unknown action> "; break;
199 } 216 }
200 217
201 GdkWindow *w = gtk_widget_get_parent_window (GTK_WIDGET (widget)); 218 GdkWindow *w = gtk_widget_get_parent_window (GTK_WIDGET (widget));
202 219
203 snprintf (xid, 80, "%lu", (unsigned long)(w ? gdk_x11_drawable_get_xid (w) : 0)); 220 snprintf (xid, 80, "%lu", (unsigned long)(w ? gdk_x11_drawable_get_xid (w) : 0));
209 226
210 ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty"); 227 ((void (*)(void *, const char *)) dlsym (RTLD_NEXT, "gtk_file_chooser_set_filename"))(GTK_FILE_CHOOSER (widget), "/tmp/gtkbfc/empty");
211 228
212 gint stdout_fd = -1; 229 gint stdout_fd = -1;
213 230
231 gtk_widget_ref (widget); disable_cb (widget);
232
214 if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0)) 233 if (g_spawn_async_with_pipes (0, argv, 0, 0, 0, 0, 0, 0, &stdout_fd, 0, 0))
215 { 234 {
216 GIOChannel *channel = g_io_channel_unix_new (stdout_fd); 235 GIOChannel *channel = g_io_channel_unix_new (stdout_fd);
217 //gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); 236
218 g_io_add_watch (channel, G_IO_IN, read_result, widget); 237 gtk_widget_ref (widget); g_io_add_watch (channel, G_IO_IN | G_IO_ERR | G_IO_HUP, read_result, widget);
219 g_idle_add (unmap_cb, widget); 238
220 //g_timeout_add (1, unmap_cb, widget); 239 // disable again in an idle handler, to get around race conditions
240 gtk_widget_ref (widget); g_idle_add (disable_cb, widget);
221 } 241 }
222 else
223 ;//gtk_widget_show (widget);
224} 242}
225 243
226static GObject *new_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) 244static GObject *new_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
227{ 245{
228 GObject *ob = old_constructor (type, n_construct_properties, construct_properties); 246 GObject *ob = old_constructor (type, n_construct_properties, construct_properties);
229 g_signal_connect_after (ob, "map", G_CALLBACK (show_cb), 0); 247 g_signal_connect_after (ob, "map", G_CALLBACK (map_cb), 0);
230 return ob; 248 return ob;
231} 249}
232 250
233__attribute__ ((constructor)) 251__attribute__ ((constructor))
234static void init () 252static void init ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines