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