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