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