Mercurial > gftp.yaz
annotate src/gtk/misc-gtk.c @ 42:cd169e4789df
2002-10-29 Brian Masney <masneyb@gftp.org>
* src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/gftp-gtk.c
src/gtk/gftp-gtk.h src/gtk/menu-items.c src/gtk/misc-gtk.c
src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c -
improved and simplified signal handling code
author | masneyb |
---|---|
date | Wed, 30 Oct 2002 03:34:37 +0000 |
parents | 4bcfaf6307b5 |
children | 36e2868ce8b7 |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* misc-gtk.c - misc stuff for the gtk+ 1.2 port of gftp */ | |
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */ | |
4 /* */ | |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
18 /*****************************************************************************/ | |
19 | |
20 #include <gftp-gtk.h> | |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
23 static void set_menu_sensitive ( gftp_window_data * wdata, | |
24 char *path, | |
25 int sensitive ); | |
26 static gint delete_event ( GtkWidget * widget, | |
27 GdkEvent * event, | |
28 gpointer data ); | |
29 static void trans_stop_button ( GtkWidget * widget, | |
30 gpointer data ); | |
31 | |
32 static GtkWidget * statuswid; | |
33 | |
34 | |
35 void | |
36 fix_display (void) | |
37 { | |
31 | 38 int ret; |
39 | |
33 | 40 if (!gftp_is_started) |
41 return; | |
42 | |
31 | 43 ret = 1; |
44 while (ret) | |
45 { | |
33 | 46 GDK_THREADS_LEAVE (); |
41 | 47 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
31 | 48 ret = g_main_iteration (FALSE); |
41 | 49 #else |
50 ret = g_main_context_iteration (NULL, FALSE); | |
51 #endif | |
52 | |
31 | 53 } |
1 | 54 } |
55 | |
56 | |
57 void | |
58 remove_files_window (gftp_window_data * wdata) | |
59 { | |
60 wdata->show_selected = 0; | |
61 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
62 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
63 free_file_list (wdata->files); | |
64 wdata->files = NULL; | |
65 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
66 } | |
67 | |
68 | |
69 void | |
70 ftp_log (gftp_logging_level level, void *ptr, const char *string, ...) | |
71 { | |
72 char tempstr[512]; | |
73 gftp_log * newlog; | |
74 gint delsize; | |
75 va_list argp; | |
76 guint len; | |
77 int upd; | |
78 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 | |
79 gftp_color * color; | |
80 GdkColor fore; | |
81 #else | |
82 GtkTextBuffer * textbuf; | |
83 GtkTextIter iter, iter2; | |
84 const char *descr; | |
85 guint inslen; | |
86 #endif | |
87 | |
88 if (ptr == (void *) 0x1) | |
89 { | |
90 newlog = g_malloc0 (sizeof (*newlog)); | |
91 newlog->type = level; | |
92 va_start (argp, string); | |
93 newlog->msg = g_strdup_vprintf (string, argp); | |
94 va_end (argp); | |
95 | |
96 pthread_mutex_lock (&log_mutex); | |
97 file_transfer_logs = g_list_append (file_transfer_logs, newlog); | |
98 pthread_mutex_unlock (&log_mutex); | |
99 return; | |
100 } | |
101 | |
102 va_start (argp, string); | |
103 g_vsnprintf (tempstr, sizeof (tempstr), string, argp); | |
104 va_end (argp); | |
105 | |
106 if (logfd != NULL) | |
107 { | |
108 if (fwrite (tempstr, strlen (tempstr), 1, logfd) != 1) | |
109 { | |
110 fclose (logfd); | |
111 logfd = NULL; | |
112 } | |
113 else | |
114 fflush (logfd); | |
115 } | |
116 | |
117 upd = logwdw_vadj->upper - logwdw_vadj->page_size == logwdw_vadj->value; | |
118 | |
119 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 | |
120 switch (level) | |
121 { | |
122 case gftp_logging_send: | |
123 color = &send_color; | |
124 break; | |
125 case gftp_logging_recv: | |
126 color = &recv_color; | |
127 break; | |
128 case gftp_logging_error: | |
129 color = &error_color; | |
130 break; | |
131 default: | |
132 color = &misc_color; | |
133 break; | |
134 } | |
135 | |
136 memset (&fore, 0, sizeof (fore)); | |
137 fore.red = color->red; | |
138 fore.green = color->green; | |
139 fore.blue = color->blue; | |
140 | |
141 gtk_text_freeze (GTK_TEXT (logwdw)); | |
142 gtk_text_insert (GTK_TEXT (logwdw), NULL, &fore, NULL, tempstr, -1); | |
143 | |
144 len = gtk_text_get_length (GTK_TEXT (logwdw)); | |
145 if (max_log_window_size > 0 && len > max_log_window_size) | |
146 { | |
147 delsize = len - max_log_window_size; | |
148 gtk_text_set_point (GTK_TEXT (logwdw), delsize); | |
149 gtk_text_backward_delete (GTK_TEXT (logwdw), delsize); | |
150 len = max_log_window_size; | |
151 } | |
152 gtk_text_set_point (GTK_TEXT (logwdw), len); | |
153 | |
154 gtk_text_thaw (GTK_TEXT (logwdw)); | |
155 | |
156 if (upd) | |
157 gtk_adjustment_set_value (logwdw_vadj, logwdw_vadj->upper); | |
158 #else | |
159 switch (level) | |
160 { | |
161 case gftp_logging_send: | |
162 descr = "send"; | |
163 break; | |
164 case gftp_logging_recv: | |
165 descr = "recv"; | |
166 break; | |
167 case gftp_logging_error: | |
168 descr = "error"; | |
169 break; | |
170 default: | |
171 descr = "misc"; | |
172 break; | |
173 } | |
174 | |
175 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
176 len = gtk_text_buffer_get_char_count (textbuf); | |
177 inslen = strlen (tempstr); | |
178 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, len); | |
179 gtk_text_buffer_insert_with_tags_by_name (textbuf, &iter, tempstr, inslen, | |
180 descr, NULL); | |
181 | |
182 if (upd) | |
183 { | |
184 gtk_text_buffer_move_mark (textbuf, logwdw_textmark, &iter); | |
185 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (logwdw), logwdw_textmark, | |
186 0, 1, 1, 1); | |
187 } | |
188 | |
189 delsize = len + inslen - max_log_window_size; | |
190 if (max_log_window_size > 0 && delsize > 0) | |
191 { | |
192 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
193 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, delsize); | |
194 gtk_text_buffer_delete (textbuf, &iter, &iter2); | |
195 } | |
196 #endif | |
197 | |
33 | 198 if (ptr == NULL) |
1 | 199 fix_display (); |
200 } | |
201 | |
202 | |
203 void | |
204 refresh (gftp_window_data * wdata) | |
205 { | |
206 if (!check_status (_("Refresh"), wdata, 0, 0, 0, 1)) | |
207 return; | |
208 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
209 remove_files_window (wdata); | |
210 gftp_delete_cache_entry (wdata->request); | |
211 ftp_list_files (wdata, 0); | |
212 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
213 fix_display (); | |
214 } | |
215 | |
216 | |
217 void | |
218 update_window_info (void) | |
219 { | |
220 char *tempstr, empty[] = ""; | |
221 GtkWidget * tempwid; | |
222 int i; | |
223 | |
224 if (current_wdata->request != NULL) | |
225 { | |
226 if ((tempstr = GFTP_GET_HOSTNAME (current_wdata->request)) == NULL) | |
227 tempstr = empty; | |
228 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry), tempstr); | |
229 | |
230 if ((tempstr = GFTP_GET_USERNAME (current_wdata->request)) == NULL) | |
231 tempstr = empty; | |
232 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (useredit)->entry), tempstr); | |
233 | |
234 if ((tempstr = GFTP_GET_PASSWORD (current_wdata->request)) == NULL) | |
235 tempstr = empty; | |
236 gtk_entry_set_text (GTK_ENTRY (passedit), tempstr); | |
237 | |
238 if (GFTP_GET_PORT (current_wdata->request) != 0) | |
239 { | |
240 tempstr = g_strdup_printf ("%d", GFTP_GET_PORT (current_wdata->request)); | |
241 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (portedit)->entry), tempstr); | |
242 g_free (tempstr); | |
243 } | |
244 | |
245 for (i=0; gftp_protocols[i].init != NULL; i++) | |
246 { | |
247 if (current_wdata->request->init == gftp_protocols[i].init) | |
248 { | |
249 gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), i); | |
250 break; | |
251 } | |
252 } | |
253 } | |
254 | |
255 update_window (&window1); | |
256 update_window (&window2); | |
257 | |
7 | 258 tempwid = gtk_item_factory_get_widget (factory, menus[tools_start+2].path); |
1 | 259 gtk_widget_set_sensitive (tempwid, GFTP_IS_CONNECTED (window1.request) |
260 && GFTP_IS_CONNECTED (window2.request)); | |
261 } | |
262 | |
263 | |
264 void | |
265 update_window (gftp_window_data * wdata) | |
266 { | |
267 char *dir, *tempstr, *temp1str, *fspec; | |
268 int connected, start; | |
269 | |
270 connected = GFTP_IS_CONNECTED (wdata->request); | |
271 if (connected) | |
272 { | |
273 fspec = wdata->show_selected ? "Selected" : strcmp (wdata->filespec, "*") == 0 ? _("All Files") : wdata->filespec; | |
274 | |
275 if ((temp1str = GFTP_GET_HOSTNAME (wdata->request)) == NULL) | |
276 temp1str = ""; | |
277 tempstr = g_strconcat (temp1str, *temp1str == '\0' ? "[" : " [", | |
278 GFTP_GET_PROTOCOL_NAME (wdata->request), | |
279 wdata->request->cached ? _("] (Cached) [") : "] [", | |
280 fspec, "]", current_wdata == wdata ? "*" : "", NULL); | |
281 gtk_label_set (GTK_LABEL (wdata->hoststxt), tempstr); | |
282 g_free (tempstr); | |
283 | |
284 if ((dir = GFTP_GET_DIRECTORY (wdata->request)) == NULL) | |
285 temp1str = ""; | |
286 else | |
287 temp1str = dir; | |
288 | |
289 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry),temp1str); | |
290 } | |
291 else if (wdata->hoststxt != NULL) | |
292 { | |
293 tempstr = g_strconcat (_("Not connected"), | |
294 current_wdata == wdata ? "*" : "", NULL); | |
295 gtk_label_set (GTK_LABEL (wdata->hoststxt), tempstr); | |
296 g_free (tempstr); | |
297 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry), ""); | |
298 } | |
299 | |
300 if (wdata == &window1) | |
301 start = local_start; | |
302 else | |
303 start = remote_start; | |
304 | |
305 set_menu_sensitive (wdata, menus[start + 3].path, connected && | |
306 strcmp (wdata->request->url_prefix, "file") != 0); | |
307 set_menu_sensitive (wdata, menus[start + 5].path, connected); | |
308 set_menu_sensitive (wdata, menus[start + 6].path, connected); | |
309 set_menu_sensitive (wdata, menus[start + 7].path, connected); | |
310 set_menu_sensitive (wdata, menus[start + 8].path, connected); | |
311 set_menu_sensitive (wdata, menus[start + 9].path, connected); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
312 set_menu_sensitive (wdata, menus[start + 11].path, connected); |
1 | 313 set_menu_sensitive (wdata, menus[start + 12].path, connected && |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
314 wdata->request->site != NULL); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
315 set_menu_sensitive (wdata, menus[start + 13].path, connected && |
1 | 316 wdata->request->chdir!= NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
317 set_menu_sensitive (wdata, menus[start + 14].path, connected && |
1 | 318 wdata->request->chmod != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
319 set_menu_sensitive (wdata, menus[start + 15].path, connected && |
1 | 320 wdata->request->mkdir != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
321 set_menu_sensitive (wdata, menus[start + 16].path, connected && |
1 | 322 wdata->request->rename != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
323 set_menu_sensitive (wdata, menus[start + 17].path, connected && |
1 | 324 wdata->request->rmdir != NULL && |
325 wdata->request->rmfile != NULL); | |
326 set_menu_sensitive (wdata, menus[start + 18].path, connected && | |
327 wdata->request->get_file != NULL); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
328 set_menu_sensitive (wdata, menus[start + 19].path, connected && |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
329 wdata->request->get_file != NULL); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
330 set_menu_sensitive (wdata, menus[start + 20].path, connected); |
1 | 331 fix_display (); |
332 } | |
333 | |
334 | |
335 static void | |
336 set_menu_sensitive (gftp_window_data * wdata, char *path, int sensitive) | |
337 { | |
338 GtkWidget * tempwid; | |
339 char * pos; | |
340 | |
341 tempwid = NULL; | |
342 | |
343 if (factory != NULL) | |
7 | 344 tempwid = gtk_item_factory_get_widget (factory, path); |
1 | 345 if (tempwid) |
346 gtk_widget_set_sensitive (tempwid, sensitive); | |
347 | |
348 if ((pos = strchr (path + 1, '/')) == NULL) | |
349 pos = path; | |
350 | |
351 if (wdata->ifactory) | |
7 | 352 tempwid = gtk_item_factory_get_widget (wdata->ifactory, pos); |
1 | 353 if (tempwid) |
354 gtk_widget_set_sensitive (tempwid, sensitive); | |
355 } | |
356 | |
357 | |
358 GtkWidget * | |
359 toolbar_pixmap (GtkWidget * widget, char *filename) | |
360 { | |
361 gftp_graphic * graphic; | |
362 GtkWidget *pix; | |
363 | |
364 if (filename == NULL || *filename == '\0') | |
365 return (NULL); | |
366 | |
367 graphic = open_xpm (widget, filename); | |
368 | |
369 if (graphic == NULL) | |
370 return (NULL); | |
371 | |
372 if ((pix = gtk_pixmap_new (graphic->pixmap, graphic->bitmap)) == NULL) | |
373 return (NULL); | |
374 | |
375 gtk_widget_show (pix); | |
376 return (pix); | |
377 } | |
378 | |
379 | |
380 gftp_graphic * | |
381 open_xpm (GtkWidget * widget, char *filename) | |
382 { | |
383 gftp_graphic * graphic; | |
384 GtkStyle *style; | |
385 char *exfile; | |
386 | |
387 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) != NULL) | |
388 return (graphic); | |
389 | |
390 style = gtk_widget_get_style (widget); | |
391 | |
392 if ((exfile = get_xpm_path (filename, 0)) == NULL) | |
393 return (NULL); | |
394 | |
395 graphic = g_malloc0 (sizeof (*graphic)); | |
396 graphic->pixmap = gdk_pixmap_create_from_xpm (widget->window, | |
397 &graphic->bitmap, &style->bg[GTK_STATE_NORMAL], exfile); | |
398 g_free (exfile); | |
399 | |
400 if (graphic->pixmap == NULL) | |
401 { | |
402 g_free (graphic); | |
403 ftp_log (gftp_logging_error, NULL, _("Error opening file %s: %s\n"), | |
404 exfile, g_strerror (errno)); | |
405 return (NULL); | |
406 } | |
407 | |
408 graphic->filename = g_malloc (strlen (filename) + 1); | |
409 strcpy (graphic->filename, filename); | |
410 g_hash_table_insert (graphic_hash_table, graphic->filename, graphic); | |
411 | |
412 return (graphic); | |
413 } | |
414 | |
415 | |
416 void | |
417 gftp_free_pixmap (char *filename) | |
418 { | |
419 gftp_graphic * graphic; | |
420 | |
421 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) == NULL) | |
422 return; | |
423 | |
424 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 | |
425 gdk_pixmap_unref (graphic->pixmap); | |
426 gdk_bitmap_unref (graphic->bitmap); | |
427 #else | |
41 | 428 g_object_unref (graphic->pixmap); |
429 g_object_unref (graphic->bitmap); | |
1 | 430 #endif |
431 | |
432 g_hash_table_remove (graphic_hash_table, filename); | |
433 g_free (graphic->filename); | |
434 g_free (graphic); | |
435 } | |
436 | |
437 | |
438 void | |
439 gftp_get_pixmap (GtkWidget * widget, char *filename, GdkPixmap ** pix, | |
440 GdkBitmap ** bitmap) | |
441 { | |
442 gftp_graphic * graphic; | |
443 | |
444 if (filename == NULL || *filename == '\0') | |
445 { | |
446 *pix = NULL; | |
447 *bitmap = NULL; | |
448 return; | |
449 } | |
450 | |
451 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) == NULL) | |
452 graphic = open_xpm (widget, filename); | |
453 | |
454 if (graphic == NULL) | |
455 { | |
456 *pix = NULL; | |
457 *bitmap = NULL; | |
458 return; | |
459 } | |
460 | |
461 *pix = graphic->pixmap; | |
462 *bitmap = graphic->bitmap; | |
463 } | |
464 | |
465 | |
466 int | |
467 check_status (char *name, gftp_window_data *wdata, int check_other_stop, | |
468 int only_one, int at_least_one, int func) | |
469 { | |
470 gftp_window_data * owdata; | |
471 | |
472 owdata = wdata == &window1 ? &window2 : &window1; | |
473 | |
474 if (wdata->request->stopable) | |
475 { | |
476 ftp_log (gftp_logging_misc, NULL, | |
477 _("%s: Please hit the stop button first to do anything else\n"), | |
478 name); | |
479 return (0); | |
480 } | |
481 | |
482 if (check_other_stop && owdata->request->stopable) | |
483 { | |
484 ftp_log (gftp_logging_misc, NULL, | |
485 _("%s: Please hit the stop button first to do anything else\n"), | |
486 name); | |
487 return (0); | |
488 } | |
489 | |
490 if (!GFTP_IS_CONNECTED (wdata->request)) | |
491 { | |
492 ftp_log (gftp_logging_misc, NULL, | |
493 _("%s: Not connected to a remote site\n"), name); | |
494 return (0); | |
495 } | |
496 | |
497 if (!func) | |
498 { | |
499 ftp_log (gftp_logging_misc, NULL, | |
500 _("%s: This feature is not available using this protocol\n"), | |
501 name); | |
502 return (0); | |
503 } | |
504 | |
505 if (only_one && !IS_ONE_SELECTED (wdata)) | |
506 { | |
507 ftp_log (gftp_logging_misc, NULL, | |
508 _("%s: You must only have one item selected\n"), name); | |
509 return (0); | |
510 } | |
511 | |
512 if (at_least_one && !only_one && IS_NONE_SELECTED (wdata)) | |
513 { | |
514 ftp_log (gftp_logging_misc, NULL, | |
515 _("%s: You must have at least one item selected\n"), name); | |
516 return (0); | |
517 } | |
518 return (1); | |
519 } | |
520 | |
19 | 521 |
7 | 522 static gchar * |
523 gftp_item_factory_translate (const char *path, | |
524 gpointer func_data) | |
525 { | |
526 const gchar *strip_prefix = func_data; | |
527 const char *result; | |
528 | |
529 if (strip_prefix) | |
530 { | |
531 char *tmp_path = g_strconcat (strip_prefix, path, NULL); | |
532 result = gettext (tmp_path); | |
533 if (result == tmp_path) | |
534 result = path; | |
535 g_free (tmp_path); | |
536 } | |
537 else | |
538 result = gettext (path); | |
539 | |
540 return (char *)result; | |
541 } | |
542 | |
19 | 543 |
7 | 544 GtkItemFactory * |
19 | 545 item_factory_new (GtkType container_type, const char *path, |
546 GtkAccelGroup *accel_group, const char *strip_prefix) | |
7 | 547 { |
548 GtkItemFactory *result = gtk_item_factory_new (container_type, path, accel_group); | |
549 gchar *strip_prefix_dup = g_strdup (g_strdup (strip_prefix)); | |
550 | |
551 gtk_item_factory_set_translate_func (result, gftp_item_factory_translate, | |
552 strip_prefix_dup, NULL); | |
553 | |
554 if (strip_prefix_dup) | |
555 gtk_object_set_data_full (GTK_OBJECT (result), "gftp-strip-prefix", | |
556 strip_prefix_dup, (GDestroyNotify)g_free); | |
557 | |
558 return result; | |
559 } | |
1 | 560 |
19 | 561 |
1 | 562 void |
563 create_item_factory (GtkItemFactory * ifactory, guint n_entries, | |
564 GtkItemFactoryEntry * entries, gpointer callback_data) | |
565 { | |
566 int i; | |
7 | 567 const char *strip_prefix = gtk_object_get_data (GTK_OBJECT (ifactory), "gftp-strip-prefix"); |
568 int strip_prefix_len = 0; | |
569 | |
570 if (strip_prefix) | |
571 strip_prefix_len = strlen (strip_prefix); | |
1 | 572 |
573 for (i = 0; i < n_entries; i++) | |
574 { | |
7 | 575 GtkItemFactoryEntry dummy_item = entries[i]; |
576 if (strip_prefix && strncmp (entries[i].path, strip_prefix, strip_prefix_len) == 0) | |
577 dummy_item.path += strip_prefix_len; | |
578 | |
1 | 579 gtk_item_factory_create_item (ifactory, &dummy_item, callback_data, 1); |
580 } | |
581 } | |
582 | |
583 GList * | |
584 get_next_selection (GList * selection, GList ** list, int *curnum) | |
585 { | |
586 gftp_file * tempfle; | |
587 int i, newpos; | |
588 | |
589 newpos = (int) selection->data; | |
590 i = *curnum - newpos; | |
591 | |
592 if (i < 0) | |
593 { | |
594 while (i != 0) | |
595 { | |
596 tempfle = (*list)->data; | |
597 if (tempfle->shown) | |
598 { | |
599 ++*curnum; | |
600 i++; | |
601 } | |
602 *list = (*list)->next; | |
603 } | |
604 } | |
605 else if (i > 0) | |
606 { | |
607 while (i != 0) | |
608 { | |
609 tempfle = (*list)->data; | |
610 if (tempfle->shown) | |
611 { | |
612 --*curnum; | |
613 i--; | |
614 } | |
615 *list = (*list)->prev; | |
616 } | |
617 } | |
618 | |
619 tempfle = (*list)->data; | |
620 while ((*list)->next && !tempfle->shown) | |
621 { | |
622 *list = (*list)->next; | |
623 tempfle = (*list)->data; | |
624 } | |
625 return (selection->next); | |
626 } | |
627 | |
628 | |
629 void | |
630 add_history (GtkWidget * widget, GList ** history, unsigned int *histlen, | |
631 const char *str) | |
632 { | |
633 GList *node, *delnode; | |
634 char *tempstr; | |
635 int i; | |
636 | |
637 if (str == NULL || *str == '\0') | |
638 return; | |
639 | |
640 for (node = *history; node != NULL; node = node->next) | |
641 { | |
642 if (strcmp ((char *) node->data, str) == 0) | |
643 break; | |
644 } | |
645 | |
646 if (node == NULL) | |
647 { | |
648 if (*histlen >= MAX_HIST_LEN) | |
649 { | |
650 node = *history; | |
651 for (i = 1; i < MAX_HIST_LEN; i++) | |
652 node = node->next; | |
653 node->prev->next = NULL; | |
654 node->prev = NULL; | |
655 delnode = node; | |
656 while (delnode != NULL) | |
657 { | |
658 if (delnode->data) | |
659 g_free (delnode->data); | |
660 delnode = delnode->next; | |
661 } | |
662 g_list_free (node); | |
663 } | |
664 tempstr = g_malloc (strlen (str) + 1); | |
665 strcpy (tempstr, str); | |
666 *history = g_list_prepend (*history, tempstr); | |
667 ++*histlen; | |
668 } | |
669 else if (node->prev != NULL) | |
670 { | |
671 node->prev->next = node->next; | |
672 if (node->next != NULL) | |
673 node->next->prev = node->prev; | |
674 node->prev = NULL; | |
675 node->next = *history; | |
676 if (node->next != NULL) | |
677 node->next->prev = node; | |
678 *history = node; | |
679 } | |
680 gtk_combo_set_popdown_strings (GTK_COMBO (widget), *history); | |
681 } | |
682 | |
683 | |
684 int | |
685 check_reconnect (gftp_window_data *wdata) | |
686 { | |
687 return (wdata->request->cached && wdata->request->sockfd == NULL && | |
688 !ftp_connect (wdata, wdata->request, 0) ? -1 : 0); | |
689 } | |
690 | |
691 | |
692 void | |
693 add_file_listbox (gftp_window_data * wdata, gftp_file * fle) | |
694 { | |
695 char *add_data[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, *pos; | |
696 gftp_file_extensions * tempext; | |
697 char *tempstr, *str; | |
698 GdkBitmap * bitmap; | |
699 GList * templist; | |
700 GdkPixmap * pix; | |
701 int clist_num; | |
702 size_t stlen; | |
703 | |
704 if (wdata->show_selected) | |
705 { | |
706 fle->shown = fle->was_sel; | |
707 if (!fle->shown) | |
708 return; | |
709 } | |
710 else if ((!show_hidden_files && *fle->file == '.' && | |
711 strcmp (fle->file, "..") != 0) || | |
712 !gftp_match_filespec (fle->file, wdata->filespec)) | |
713 { | |
714 fle->shown = 0; | |
715 fle->was_sel = 0; | |
716 return; | |
717 } | |
718 else | |
719 fle->shown = 1; | |
720 | |
721 clist_num = gtk_clist_append (GTK_CLIST (wdata->listbox), add_data); | |
722 | |
723 if (fle->was_sel) | |
724 { | |
725 fle->was_sel = 0; | |
726 gtk_clist_select_row (GTK_CLIST (wdata->listbox), clist_num, 0); | |
727 } | |
728 | |
729 pix = NULL; | |
730 bitmap = NULL; | |
731 if (strcmp (fle->file, "..") == 0) | |
732 gftp_get_pixmap (wdata->listbox, "dotdot.xpm", &pix, &bitmap); | |
733 else if (fle->islink && fle->isdir) | |
734 gftp_get_pixmap (wdata->listbox, "linkdir.xpm", &pix, &bitmap); | |
735 else if (fle->islink) | |
736 gftp_get_pixmap (wdata->listbox, "linkfile.xpm", &pix, &bitmap); | |
737 else if (fle->isdir) | |
738 gftp_get_pixmap (wdata->listbox, "dir.xpm", &pix, &bitmap); | |
739 else if (fle->isexe) | |
740 gftp_get_pixmap (wdata->listbox, "exe.xpm", &pix, &bitmap); | |
741 else | |
742 { | |
743 stlen = strlen (fle->file); | |
744 templist = registered_exts; | |
745 while (templist != NULL) | |
746 { | |
747 tempext = templist->data; | |
748 if (stlen >= tempext->stlen && | |
749 strcmp (&fle->file[stlen - tempext->stlen], tempext->ext) == 0) | |
750 { | |
751 if (toupper (*tempext->ascii_binary) == 'A') | |
752 fle->ascii = 1; | |
753 | |
754 gftp_get_pixmap (wdata->listbox, tempext->filename, &pix, | |
755 &bitmap); | |
756 break; | |
757 } | |
758 templist = templist->next; | |
759 } | |
760 } | |
761 | |
762 if (pix == NULL && bitmap == NULL) | |
763 gftp_get_pixmap (wdata->listbox, "doc.xpm", &pix, &bitmap); | |
764 | |
765 gtk_clist_set_pixmap (GTK_CLIST (wdata->listbox), clist_num, 0, pix, bitmap); | |
766 | |
767 if (fle->file) | |
768 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 1, fle->file); | |
769 | |
770 if (fle->attribs && (*fle->attribs == 'b' || *fle->attribs == 'c')) | |
771 tempstr = g_strdup_printf ("%d, %d", (int) fle->size >> 16, | |
772 (int) fle->size & 0xFF); | |
773 else | |
774 tempstr = insert_commas (fle->size, NULL, 0); | |
775 | |
776 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 2, tempstr); | |
777 g_free (tempstr); | |
778 | |
779 if (fle->user) | |
780 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 3, fle->user); | |
781 if (fle->group) | |
782 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 4, fle->group); | |
783 if ((str = ctime (&fle->datetime))) | |
784 { | |
785 if ((pos = strchr (str, '\n')) != NULL) | |
786 *pos = '\0'; | |
787 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 5, str); | |
788 } | |
789 if (fle->attribs) | |
790 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 6, fle->attribs); | |
791 | |
792 } | |
793 | |
794 | |
21 | 795 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
796 static void | |
797 ok_dialog_response (GtkWidget * widget, gftp_dialog_data * ddata) | |
798 { | |
799 if (ddata->edit == NULL) | |
800 gtk_widget_destroy (ddata->dialog); | |
801 | |
802 if (ddata->yesfunc != NULL) | |
803 ddata->yesfunc (ddata->yespointer, ddata); | |
804 | |
805 if (ddata->edit != NULL) | |
806 gtk_widget_destroy (ddata->dialog); | |
807 | |
808 g_free (ddata); | |
809 } | |
810 | |
811 | |
812 static void | |
813 cancel_dialog_response (GtkWidget * widget, gftp_dialog_data * ddata) | |
814 { | |
815 if (ddata->edit == NULL) | |
816 gtk_widget_destroy (ddata->dialog); | |
817 | |
818 if (ddata->nofunc != NULL) | |
819 ddata->nofunc (ddata->nopointer, ddata); | |
820 | |
821 if (ddata->edit != NULL) | |
822 gtk_widget_destroy (ddata->dialog); | |
823 | |
824 g_free (ddata); | |
825 } | |
826 #else | |
19 | 827 static void |
828 dialog_response (GtkWidget * widget, gint response, gftp_dialog_data * ddata) | |
829 { | |
830 if (ddata->edit == NULL) | |
831 gtk_widget_destroy (widget); | |
832 | |
833 switch (response) | |
834 { | |
835 case GTK_RESPONSE_YES: | |
836 if (ddata->yesfunc != NULL) | |
837 ddata->yesfunc (ddata->yespointer, ddata); | |
838 break; | |
839 default: | |
840 if (ddata->nofunc != NULL) | |
841 ddata->nofunc (ddata->nopointer, ddata); | |
842 break; | |
843 } | |
844 | |
845 if (ddata->edit != NULL) | |
846 gtk_widget_destroy (widget); | |
847 | |
848 g_free (ddata); | |
849 } | |
850 #endif | |
851 | |
852 | |
1 | 853 void |
19 | 854 MakeEditDialog (char *diagtxt, char *infotxt, char *deftext, int passwd_item, |
855 char *checktext, | |
856 gftp_dialog_button okbutton, void (*okfunc) (), void *okptr, | |
857 void (*cancelfunc) (), void *cancelptr) | |
1 | 858 { |
19 | 859 GtkWidget * tempwid, * dialog; |
860 gftp_dialog_data * ddata; | |
861 const gchar * yes_text; | |
862 | |
863 ddata = g_malloc (sizeof (*ddata)); | |
864 ddata->yesfunc = okfunc; | |
865 ddata->yespointer = okptr; | |
866 ddata->nofunc = cancelfunc; | |
867 ddata->nopointer = cancelptr; | |
1 | 868 |
19 | 869 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
870 dialog = gtk_dialog_new (); | |
871 gtk_window_set_title (GTK_WINDOW (dialog), diagtxt); | |
872 gtk_grab_add (dialog); | |
1 | 873 gtk_container_border_width (GTK_CONTAINER |
19 | 874 (GTK_DIALOG (dialog)->action_area), 5); |
875 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15); | |
876 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
877 #else | |
878 switch (okbutton) | |
879 { | |
880 case gftp_dialog_button_create: | |
881 yes_text = GTK_STOCK_ADD; | |
882 break; | |
883 case gftp_dialog_button_change: | |
884 yes_text = _("Change"); | |
885 break; | |
886 case gftp_dialog_button_connect: | |
887 yes_text = _("Connect"); | |
888 break; | |
889 case gftp_dialog_button_rename: | |
890 yes_text = _("Rename"); | |
891 break; | |
892 default: | |
893 yes_text = GTK_STOCK_MISSING_IMAGE; | |
894 break; | |
895 } | |
1 | 896 |
19 | 897 dialog = gtk_dialog_new_with_buttons (_(diagtxt), NULL, 0, |
898 yes_text, | |
899 GTK_RESPONSE_YES, | |
900 GTK_STOCK_CANCEL, | |
901 GTK_RESPONSE_NO, | |
902 NULL); | |
903 #endif | |
904 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
905 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
906 gtk_window_set_wmclass (GTK_WINDOW(dialog), "edit", "gFTP"); | |
907 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
908 gtk_widget_realize (dialog); | |
1 | 909 |
19 | 910 if (gftp_icon != NULL) |
911 { | |
912 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
913 gftp_icon->bitmap); | |
914 gdk_window_set_icon_name (dialog->window, _("gFTP Icon")); | |
915 } | |
916 | |
917 ddata->dialog = dialog; | |
918 | |
1 | 919 tempwid = gtk_label_new (infotxt); |
19 | 920 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, TRUE, |
1 | 921 TRUE, 0); |
922 gtk_widget_show (tempwid); | |
923 | |
19 | 924 ddata->edit = gtk_entry_new (); |
925 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), ddata->edit, TRUE, | |
1 | 926 TRUE, 0); |
19 | 927 gtk_widget_grab_focus (ddata->edit); |
928 gtk_entry_set_visibility (GTK_ENTRY (ddata->edit), passwd_item); | |
1 | 929 |
930 if (deftext != NULL) | |
931 { | |
19 | 932 gtk_entry_set_text (GTK_ENTRY (ddata->edit), deftext); |
933 gtk_entry_select_region (GTK_ENTRY (ddata->edit), 0, strlen (deftext)); | |
1 | 934 } |
19 | 935 gtk_widget_show (ddata->edit); |
1 | 936 |
19 | 937 if (checktext != NULL) |
1 | 938 { |
19 | 939 ddata->checkbox = gtk_check_button_new_with_label (checktext); |
940 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), | |
941 ddata->checkbox, TRUE, TRUE, 0); | |
942 gtk_widget_show (ddata->checkbox); | |
1 | 943 } |
944 | |
19 | 945 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
21 | 946 switch (okbutton) |
947 { | |
948 case gftp_dialog_button_create: | |
949 yes_text = _("Add"); | |
950 break; | |
951 case gftp_dialog_button_change: | |
952 yes_text = _("Change"); | |
953 break; | |
954 case gftp_dialog_button_connect: | |
955 yes_text = _("Connect"); | |
956 break; | |
957 case gftp_dialog_button_rename: | |
958 yes_text = _("Rename"); | |
959 break; | |
960 default: | |
961 yes_text = ""; | |
962 break; | |
963 } | |
964 | |
965 tempwid = gtk_button_new_with_label (yes_text); | |
1 | 966 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
19 | 967 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, |
1 | 968 TRUE, TRUE, 0); |
21 | 969 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
970 GTK_SIGNAL_FUNC (ok_dialog_response), | |
971 ddata); | |
1 | 972 gtk_widget_grab_default (tempwid); |
973 gtk_widget_show (tempwid); | |
974 | |
21 | 975 tempwid = gtk_button_new_with_label (_("Cancel")); |
1 | 976 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
19 | 977 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, |
1 | 978 TRUE, TRUE, 0); |
21 | 979 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
980 GTK_SIGNAL_FUNC (cancel_dialog_response), | |
981 ddata); | |
1 | 982 gtk_widget_show (tempwid); |
19 | 983 #else |
984 g_signal_connect (GTK_OBJECT (dialog), "response", | |
985 G_CALLBACK (dialog_response), ddata); | |
986 #endif | |
1 | 987 |
19 | 988 gtk_widget_show (dialog); |
1 | 989 } |
990 | |
991 | |
992 void | |
19 | 993 MakeYesNoDialog (char *diagtxt, char *infotxt, |
994 void (*yesfunc) (), gpointer yespointer, | |
995 void (*nofunc) (), gpointer nopointer) | |
1 | 996 { |
19 | 997 GtkWidget * text, * dialog; |
998 gftp_dialog_data * ddata; | |
21 | 999 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
1000 GtkWidget * tempwid; | |
19 | 1001 #endif |
1 | 1002 |
21 | 1003 ddata = g_malloc (sizeof (*ddata)); |
1004 ddata->yesfunc = yesfunc; | |
1005 ddata->yespointer = yespointer; | |
1006 ddata->nofunc = nofunc; | |
1007 ddata->nopointer = nopointer; | |
1008 | |
19 | 1009 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
1 | 1010 dialog = gtk_dialog_new (); |
1011 gtk_grab_add (dialog); | |
1012 gtk_window_set_title (GTK_WINDOW (dialog), diagtxt); | |
1013 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), | |
1014 5); | |
1015 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15); | |
1016 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
19 | 1017 #else |
1018 dialog = gtk_dialog_new_with_buttons (_(diagtxt), NULL, 0, | |
1019 GTK_STOCK_YES, | |
1020 GTK_RESPONSE_YES, | |
1021 GTK_STOCK_NO, | |
1022 GTK_RESPONSE_NO, | |
1023 NULL); | |
1024 #endif | |
1025 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
1026 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 1027 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); |
19 | 1028 gtk_window_set_wmclass (GTK_WINDOW(dialog), "yndiag", "gFTP"); |
1029 gtk_widget_realize (dialog); | |
1030 | |
1031 if (gftp_icon != NULL) | |
1032 { | |
1033 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
1034 gftp_icon->bitmap); | |
1035 gdk_window_set_icon_name (dialog->window, _("gFTP Icon")); | |
1036 } | |
1 | 1037 |
21 | 1038 ddata->dialog = dialog; |
1039 | |
1 | 1040 text = gtk_label_new (infotxt); |
1041 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), text, TRUE, TRUE, 0); | |
1042 gtk_widget_show (text); | |
1043 | |
19 | 1044 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
1045 tempwid = gtk_button_new_with_label (_(" Yes ")); | |
1046 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1047 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1048 FALSE, FALSE, 0); | |
21 | 1049 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
1050 GTK_SIGNAL_FUNC (ok_dialog_response), | |
1051 ddata); | |
19 | 1052 gtk_widget_grab_default (tempwid); |
1053 gtk_widget_show (tempwid); | |
1 | 1054 |
19 | 1055 tempwid = gtk_button_new_with_label (_(" No ")); |
1056 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1057 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1058 FALSE, FALSE, 0); | |
21 | 1059 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
1060 GTK_SIGNAL_FUNC (cancel_dialog_response), | |
1061 ddata); | |
19 | 1062 gtk_widget_show (tempwid); |
1063 | |
1064 #else | |
1065 g_signal_connect (GTK_OBJECT (dialog), "response", | |
1066 G_CALLBACK (dialog_response), ddata); | |
1067 #endif | |
1 | 1068 |
1069 gtk_widget_show (dialog); | |
1070 } | |
1071 | |
1072 | |
1073 void | |
1074 update_directory_download_progress (gftp_transfer * transfer) | |
1075 { | |
1076 static GtkWidget * dialog = NULL, * textwid, * stopwid; | |
1077 char tempstr[255]; | |
1078 GtkWidget * vbox; | |
1079 | |
1080 if (transfer->numfiles < 0 || transfer->numdirs < 0) | |
1081 { | |
1082 if (dialog != NULL) | |
1083 gtk_widget_destroy (dialog); | |
1084 dialog = NULL; | |
1085 return; | |
1086 } | |
1087 | |
1088 if (dialog == NULL) | |
1089 { | |
1090 dialog = gtk_window_new (GTK_WINDOW_POPUP); | |
1091 gtk_grab_add (dialog); | |
1092 gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", | |
1093 GTK_SIGNAL_FUNC (delete_event), NULL); | |
1094 gtk_window_set_title (GTK_WINDOW (dialog), | |
1095 _("Getting directory listings")); | |
1096 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
1097 gtk_window_set_wmclass (GTK_WINDOW(dialog), "dirlist", "gFTP"); | |
1098 | |
1099 vbox = gtk_vbox_new (FALSE, 5); | |
1100 gtk_container_border_width (GTK_CONTAINER (vbox), 10); | |
1101 gtk_container_add (GTK_CONTAINER (dialog), vbox); | |
1102 gtk_widget_show (vbox); | |
1103 | |
1104 textwid = gtk_label_new (NULL); | |
1105 gtk_box_pack_start (GTK_BOX (vbox), textwid, TRUE, TRUE, 0); | |
1106 gtk_widget_show (textwid); | |
1107 | |
1108 statuswid = gtk_progress_bar_new (); | |
1109 gtk_progress_set_activity_mode (GTK_PROGRESS (statuswid), 1); | |
1110 gtk_progress_bar_set_activity_step (GTK_PROGRESS_BAR (statuswid), 3); | |
1111 gtk_progress_bar_set_activity_blocks (GTK_PROGRESS_BAR (statuswid), 5); | |
1112 gtk_box_pack_start (GTK_BOX (vbox), statuswid, TRUE, TRUE, 0); | |
1113 gtk_widget_show (statuswid); | |
1114 | |
1115 stopwid = gtk_button_new_with_label (_(" Stop ")); | |
1116 gtk_signal_connect (GTK_OBJECT (stopwid), "clicked", | |
1117 GTK_SIGNAL_FUNC (trans_stop_button), transfer); | |
1118 gtk_box_pack_start (GTK_BOX (vbox), stopwid, TRUE, TRUE, 0); | |
1119 gtk_widget_show (stopwid); | |
1120 | |
1121 gtk_widget_show (dialog); | |
1122 } | |
1123 | |
1124 g_snprintf (tempstr, sizeof (tempstr), | |
1125 _("Received %ld directories\nand %ld files"), | |
1126 transfer->numdirs, transfer->numfiles); | |
1127 gtk_label_set_text (GTK_LABEL (textwid), tempstr); | |
1128 } | |
1129 | |
1130 | |
1131 void * | |
1132 generic_thread (void * (*func) (void *), gftp_window_data * wdata) | |
1133 { | |
1134 void * ret; | |
1135 | |
1136 if (wdata->request->use_threads) | |
1137 { | |
1138 wdata->request->stopable = 1; | |
1139 gtk_widget_set_sensitive (stop_btn, 1); | |
1140 pthread_create (&wdata->tid, NULL, func, wdata); | |
1141 | |
1142 while (wdata->request->stopable) | |
31 | 1143 { |
33 | 1144 GDK_THREADS_LEAVE (); |
41 | 1145 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 |
31 | 1146 g_main_iteration (TRUE); |
41 | 1147 #else |
1148 g_main_context_iteration (NULL, TRUE); | |
1149 #endif | |
31 | 1150 } |
1 | 1151 |
1152 pthread_join (wdata->tid, &ret); | |
1153 gtk_widget_set_sensitive (stop_btn, 0); | |
1154 } | |
1155 else | |
1156 ret = func (wdata); | |
1157 | |
1158 if (!GFTP_IS_CONNECTED (wdata->request)) | |
1159 disconnect (wdata); | |
1160 | |
1161 return (ret); | |
1162 } | |
1163 | |
1164 | |
1165 int | |
1166 progress_timeout (gpointer data) | |
1167 { | |
1168 gftp_transfer * tdata; | |
1169 double val; | |
1170 | |
1171 tdata = data; | |
1172 | |
1173 update_directory_download_progress (tdata); | |
1174 | |
1175 val = gtk_progress_get_value (GTK_PROGRESS (statuswid)); | |
1176 if (val >= 1.0) | |
1177 val = 0; | |
1178 else | |
1179 val += 0.10; | |
1180 gtk_progress_bar_update (GTK_PROGRESS_BAR (statuswid), val); | |
1181 | |
1182 return (1); | |
1183 } | |
1184 | |
1185 | |
1186 static gint | |
1187 delete_event (GtkWidget * widget, GdkEvent * event, gpointer data) | |
1188 { | |
1189 return (TRUE); | |
1190 } | |
1191 | |
1192 | |
1193 static void | |
1194 trans_stop_button (GtkWidget * widget, gpointer data) | |
1195 { | |
1196 gftp_transfer * transfer; | |
1197 | |
1198 transfer = data; | |
1199 pthread_kill (((gftp_window_data *) transfer->fromwdata)->tid, SIGINT); | |
1200 } | |
1201 | |
1202 void | |
1203 display_cached_logs (void) | |
1204 { | |
1205 gftp_log * templog; | |
1206 GList * templist; | |
1207 | |
1208 pthread_mutex_lock (&log_mutex); | |
1209 templist = file_transfer_logs; | |
1210 while (templist != NULL) | |
1211 { | |
1212 templog = (gftp_log *) templist->data; | |
1213 ftp_log (templog->type, (void *) 0x2, "%s", templog->msg); | |
1214 g_free (templog->msg); | |
1215 g_free (templog); | |
1216 templist->data = NULL; | |
1217 templist = templist->next; | |
1218 } | |
1219 g_list_free (file_transfer_logs); | |
1220 file_transfer_logs = NULL; | |
1221 pthread_mutex_unlock (&log_mutex); | |
1222 } | |
1223 | |
42 | 1224 |
1225 RETSIGTYPE | |
1226 signal_handler (int signo) | |
1227 { | |
1228 signal (signo, signal_handler); | |
1229 | |
1230 if (use_jmp_environment) | |
1231 siglongjmp (jmp_environment, signo == SIGINT ? 1 : 2); | |
1232 } | |
1233 | |
1234 | |
1 | 1235 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR) |
1236 | |
1237 static pthread_mutex_t netfunclock = PTHREAD_MUTEX_INITIALIZER; | |
1238 | |
1239 struct hostent * | |
1240 r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop) | |
1241 { | |
1242 struct hostent *hent; | |
1243 | |
1244 pthread_mutex_lock (&netfunclock); | |
1245 if ((hent = gethostbyname (name)) == NULL) | |
1246 { | |
1247 if (h_errnop) | |
1248 *h_errnop = h_errno; | |
1249 } | |
1250 else | |
1251 { | |
1252 *result_buf = *hent; | |
1253 hent = result_buf; | |
1254 } | |
1255 pthread_mutex_unlock (&netfunclock); | |
1256 return (hent); | |
1257 } | |
1258 | |
1259 | |
1260 struct servent * | |
1261 r_getservbyname (const char *name, const char *proto, | |
1262 struct servent *result_buf, int *h_errnop) | |
1263 { | |
1264 struct servent *sent; | |
1265 | |
1266 pthread_mutex_lock (&netfunclock); | |
1267 if ((sent = getservbyname (name, proto)) == NULL) | |
1268 { | |
1269 if (h_errnop) | |
1270 *h_errnop = h_errno; | |
1271 } | |
1272 else | |
1273 { | |
1274 *result_buf = *sent; | |
1275 sent = result_buf; | |
1276 } | |
1277 pthread_mutex_unlock (&netfunclock); | |
1278 return (sent); | |
1279 } | |
1280 | |
1281 #endif /* !HAVE_GETADDRINFO */ | |
1282 |