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

Comparing gtkbfc/gtkbfc.c (file contents):
Revision 1.6 by root, Wed Aug 15 15:46:10 2007 UTC vs.
Revision 1.11 by root, Sat Aug 18 11:08:01 2007 UTC

16 16
17static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); 17static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties);
18 18
19static gchar *last_path; 19static 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
23gchar *gtk_file_chooser_get_filename (GtkFileChooser *chooser) 29gchar *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
28gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename) 35gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser, const char *filename)
29{ 36{
55 return 1; 62 return 1;
56} 63}
57 64
58gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser) 65gchar * 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
65static const gchar * 73static const gchar *
72 80
73 return rv; 81 return rv;
74} 82}
75 83
76static gchar * 84static gchar *
77to_uri (gchar * file) 85to_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
112gchar * gtk_file_chooser_get_uri (GtkFileChooser *chooser) 120gchar *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
117gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser, const char *uri) 127gboolean 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));
136 146
137///////////////////////////////////////////////////////////////////////////// 147/////////////////////////////////////////////////////////////////////////////
138 148
139static gboolean activate_cb (gpointer data) 149static gboolean activate_cb (gpointer data)
140{ 150{
151 gtk_widget_set_sensitive (GTK_WIDGET (gtk_widget_get_toplevel (data)), 1);
141 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);
142 //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)))));
143 g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); 154 g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated");
144 return FALSE; 155 return FALSE;
145} 156}
146 157
147static gboolean unmap_cb (gpointer data) 158static gboolean unmap_cb (gpointer data)
148{ 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);
149 gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data))); 163 //gtk_widget_unmap (GTK_WIDGET (gtk_widget_get_toplevel (data)));
150 return FALSE; 164 return FALSE;
151} 165}
152 166
153static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data) 167static gboolean read_result (GIOChannel *source, GIOCondition condition, gpointer data)
154{ 168{
169 if (last_path)
170 {
171 g_free (last_path);
172 last_path = 0;
173 }
174
155 g_io_channel_read_to_end (source, &last_path, 0, 0); 175 g_io_channel_read_to_end (source, &last_path, 0, 0);
156 g_io_channel_unref (source); 176 g_io_channel_unref (source);
157 activate_cb (data); 177 activate_cb (data);
178
179 DEBUG ((printf ("read_result<%s>\n", last_path)));
180
158 return FALSE; 181 return FALSE;
159} 182}
160 183
161static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) 184static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
162{ 185{
182 argv [3] = 0; 205 argv [3] = 0;
183 206
184 mkdir ("/tmp/gtkbfc", 0777); 207 mkdir ("/tmp/gtkbfc", 0777);
185 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));
186 209
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"); 210 ((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 211
198 gint stdout_fd = -1; 212 gint stdout_fd = -1;
199 213
200 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))
201 { 215 {
202 GIOChannel *channel = g_io_channel_unix_new (stdout_fd); 216 GIOChannel *channel = g_io_channel_unix_new (stdout_fd);
203 gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget))); 217 //gtk_widget_hide (GTK_WIDGET (gtk_widget_get_toplevel (widget)));
204 g_io_add_watch (channel, G_IO_IN, read_result, widget); 218 g_io_add_watch (channel, G_IO_IN, read_result, widget);
205 g_idle_add (unmap_cb, widget); 219 g_idle_add (unmap_cb, widget);
206 //g_timeout_add (1, unmap_cb, widget); 220 //g_timeout_add (1, unmap_cb, widget);
207 } 221 }
208 else 222 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines