Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 867:b1cfb42c5be4
2006-11-30 Brian Masney <masneyb@gftp.org>
* src/gtk/bookmarks.c (do_make_new) - don't allow creating
bookmarks that have an empty description. (closes #367933)
author | masneyb |
---|---|
date | Sat, 23 Dec 2006 20:10:06 +0000 |
parents | 1fae947d4418 |
children | 2d4e6fca8e7c |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* transfer.c - functions to handle transfering files */ | |
255 | 3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */ |
1 | 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 | |
518 | 20 #include "gftp-gtk.h" |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
129 | 23 static int num_transfers_in_progress = 0; |
1 | 24 |
48 | 25 int |
496 | 26 ftp_list_files (gftp_window_data * wdata) |
48 | 27 { |
355 | 28 gftpui_callback_data * cdata; |
48 | 29 |
30 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); | |
31 | |
355 | 32 cdata = g_malloc0 (sizeof (*cdata)); |
33 cdata->request = wdata->request; | |
34 cdata->uidata = wdata; | |
35 cdata->run_function = gftpui_common_run_ls; | |
511 | 36 cdata->dont_refresh = 1; |
48 | 37 |
355 | 38 gftpui_common_run_callback_function (cdata); |
48 | 39 |
355 | 40 wdata->files = cdata->files; |
41 g_free (cdata); | |
48 | 42 |
43 if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) | |
44 { | |
380 | 45 gftpui_disconnect (wdata); |
48 | 46 return (0); |
47 } | |
48 | |
49 wdata->sorted = 0; | |
129 | 50 sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); |
355 | 51 |
48 | 52 if (IS_NONE_SELECTED (wdata)) |
53 gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); | |
355 | 54 |
48 | 55 return (1); |
56 } | |
57 | |
58 | |
1 | 59 int |
767 | 60 ftp_connect (gftp_window_data * wdata, gftp_request * request) |
1 | 61 { |
62 if (wdata->request == request) | |
367 | 63 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); |
1 | 64 |
377 | 65 return (gftpui_common_cmd_open (wdata, request, NULL, NULL, NULL)); |
1 | 66 } |
67 | |
68 | |
69 void | |
70 get_files (gpointer data) | |
71 { | |
72 transfer_window_files (&window2, &window1); | |
73 } | |
74 | |
75 | |
76 void | |
77 put_files (gpointer data) | |
78 { | |
79 transfer_window_files (&window1, &window2); | |
80 } | |
81 | |
82 | |
83 void | |
84 transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) | |
85 { | |
86 gftp_file * tempfle, * newfle; | |
87 GList * templist, * filelist; | |
88 gftp_transfer * transfer; | |
506 | 89 int num, ret, disconnect; |
1 | 90 |
91 if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, | |
92 towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) | |
93 return; | |
94 | |
95 if (!GFTP_IS_CONNECTED (fromwdata->request) || | |
96 !GFTP_IS_CONNECTED (towdata->request)) | |
97 { | |
677 | 98 ftp_log (gftp_logging_error, NULL, |
1 | 99 _("Retrieve Files: Not connected to a remote site\n")); |
100 return; | |
101 } | |
102 | |
103 if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) | |
104 return; | |
105 | |
106 transfer = g_malloc0 (sizeof (*transfer)); | |
368 | 107 transfer->fromreq = gftp_copy_request (fromwdata->request); |
108 transfer->toreq = gftp_copy_request (towdata->request); | |
1 | 109 transfer->fromwdata = fromwdata; |
110 transfer->towdata = towdata; | |
111 | |
112 num = 0; | |
525 | 113 templist = gftp_gtk_get_list_selection (fromwdata); |
1 | 114 filelist = fromwdata->files; |
115 while (templist != NULL) | |
116 { | |
117 templist = get_next_selection (templist, &filelist, &num); | |
118 tempfle = filelist->data; | |
119 if (strcmp (tempfle->file, "..") != 0) | |
120 { | |
121 newfle = copy_fdata (tempfle); | |
122 transfer->files = g_list_append (transfer->files, newfle); | |
123 } | |
124 } | |
125 | |
126 if (transfer->files != NULL) | |
127 { | |
63 | 128 gftp_swap_socks (transfer->fromreq, fromwdata->request); |
129 gftp_swap_socks (transfer->toreq, towdata->request); | |
1 | 130 |
767 | 131 ret = gftp_gtk_get_subdirs (transfer); |
506 | 132 if (ret < 0) |
133 disconnect = 1; | |
1 | 134 else |
506 | 135 disconnect = 0; |
1 | 136 |
137 if (!GFTP_IS_CONNECTED (transfer->fromreq)) | |
138 { | |
380 | 139 gftpui_disconnect (fromwdata); |
506 | 140 disconnect = 1; |
1 | 141 } |
142 | |
143 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
144 { | |
380 | 145 gftpui_disconnect (towdata); |
506 | 146 disconnect = 1; |
147 } | |
148 | |
149 if (disconnect) | |
150 { | |
151 free_tdata (transfer); | |
1 | 152 return; |
506 | 153 } |
1 | 154 |
63 | 155 gftp_swap_socks (fromwdata->request, transfer->fromreq); |
156 gftp_swap_socks (towdata->request, transfer->toreq); | |
1 | 157 } |
158 | |
159 if (transfer->files != NULL) | |
160 { | |
367 | 161 gftpui_common_add_file_transfer (transfer->fromreq, transfer->toreq, |
162 transfer->fromwdata, transfer->towdata, | |
163 transfer->files); | |
1 | 164 g_free (transfer); |
165 } | |
166 else | |
129 | 167 free_tdata (transfer); |
1 | 168 } |
169 | |
506 | 170 |
508 | 171 static int |
511 | 172 gftpui_gtk_tdata_connect (gftpui_callback_data * cdata) |
173 { | |
174 gftp_transfer * tdata; | |
175 int ret; | |
176 | |
177 tdata = cdata->user_data; | |
178 | |
179 if (tdata->fromreq != NULL) | |
180 { | |
181 ret = gftp_connect (tdata->fromreq); | |
182 if (ret < 0) | |
183 return (ret); | |
184 } | |
185 | |
186 if (tdata->toreq != NULL) | |
187 { | |
188 ret = gftp_connect (tdata->toreq); | |
189 if (ret < 0) | |
190 return (ret); | |
191 } | |
192 | |
193 return (0); | |
194 } | |
195 | |
196 | |
197 static void | |
198 gftpui_gtk_tdata_disconnect (gftpui_callback_data * cdata) | |
199 { | |
200 gftp_transfer * tdata; | |
201 | |
202 tdata = cdata->user_data; | |
203 | |
204 if (tdata->fromreq != NULL) | |
205 gftp_disconnect (tdata->fromreq); | |
206 | |
207 if (tdata->toreq != NULL) | |
208 gftp_disconnect (tdata->toreq); | |
209 | |
210 cdata->request->datafd = -1; | |
211 } | |
212 | |
213 | |
214 static int | |
508 | 215 _gftp_getdir_thread (gftpui_callback_data * cdata) |
1 | 216 { |
508 | 217 return (gftp_get_all_subdirs (cdata->user_data, NULL)); |
1 | 218 } |
219 | |
220 | |
506 | 221 int |
767 | 222 gftp_gtk_get_subdirs (gftp_transfer * transfer) |
506 | 223 { |
508 | 224 gftpui_callback_data * cdata; |
506 | 225 long numfiles, numdirs; |
226 guint timeout_num; | |
508 | 227 int ret; |
506 | 228 |
508 | 229 cdata = g_malloc0 (sizeof (*cdata)); |
230 cdata->user_data = transfer; | |
231 cdata->uidata = transfer->fromwdata; | |
232 cdata->request = ((gftp_window_data *) transfer->fromwdata)->request; | |
233 cdata->run_function = _gftp_getdir_thread; | |
511 | 234 cdata->connect_function = gftpui_gtk_tdata_connect; |
235 cdata->disconnect_function = gftpui_gtk_tdata_disconnect; | |
236 cdata->dont_check_connection = 1; | |
237 cdata->dont_refresh = 1; | |
506 | 238 |
508 | 239 timeout_num = gtk_timeout_add (100, progress_timeout, transfer); |
240 ret = gftpui_common_run_callback_function (cdata); | |
241 gtk_timeout_remove (timeout_num); | |
506 | 242 |
508 | 243 numfiles = transfer->numfiles; |
244 numdirs = transfer->numdirs; | |
245 transfer->numfiles = transfer->numdirs = -1; | |
246 update_directory_download_progress (transfer); | |
247 transfer->numfiles = numfiles; | |
248 transfer->numdirs = numdirs; | |
506 | 249 |
508 | 250 g_free (cdata); |
506 | 251 |
508 | 252 return (ret); |
506 | 253 } |
254 | |
255 | |
305 | 256 static void |
770 | 257 remove_file (gftp_viewedit_data * ve_proc) |
48 | 258 { |
770 | 259 if (ve_proc->remote_filename == NULL) |
260 return; | |
261 | |
262 if (unlink (ve_proc->filename) == 0) | |
48 | 263 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), |
770 | 264 ve_proc->filename); |
48 | 265 else |
266 ftp_log (gftp_logging_error, NULL, | |
770 | 267 _("Error: Could not remove file %s: %s\n"), ve_proc->filename, |
48 | 268 g_strerror (errno)); |
269 } | |
270 | |
271 | |
272 static void | |
273 free_edit_data (gftp_viewedit_data * ve_proc) | |
274 { | |
275 int i; | |
276 | |
294 | 277 if (ve_proc->torequest) |
278 gftp_request_destroy (ve_proc->torequest, 1); | |
48 | 279 if (ve_proc->filename) |
280 g_free (ve_proc->filename); | |
281 if (ve_proc->remote_filename) | |
282 g_free (ve_proc->remote_filename); | |
283 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
284 g_free (ve_proc->argv[i]); | |
285 g_free (ve_proc->argv); | |
286 g_free (ve_proc); | |
287 } | |
288 | |
289 | |
290 static void | |
291 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
1 | 292 { |
770 | 293 remove_file (ve_proc); |
48 | 294 free_edit_data (ve_proc); |
295 } | |
296 | |
297 | |
298 static void | |
299 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
300 { | |
303 | 301 gftp_transfer * tdata; |
48 | 302 gftp_file * tempfle; |
303 GList * newfile; | |
1 | 304 |
48 | 305 tempfle = g_malloc0 (sizeof (*tempfle)); |
555 | 306 tempfle->destfile = gftp_build_path (ve_proc->torequest, |
307 ve_proc->torequest->directory, | |
294 | 308 ve_proc->remote_filename, NULL); |
48 | 309 ve_proc->remote_filename = NULL; |
310 tempfle->file = ve_proc->filename; | |
311 ve_proc->filename = NULL; | |
312 tempfle->done_rm = 1; | |
313 newfile = g_list_append (NULL, tempfle); | |
367 | 314 tdata = gftpui_common_add_file_transfer (ve_proc->fromwdata->request, |
315 ve_proc->torequest, | |
316 ve_proc->fromwdata, | |
317 ve_proc->towdata, newfile); | |
48 | 318 free_edit_data (ve_proc); |
303 | 319 |
320 if (tdata != NULL) | |
321 tdata->conn_error_no_timeout = 1; | |
48 | 322 } |
323 | |
1 | 324 |
829 | 325 static int |
326 _check_viewedit_process_status (gftp_viewedit_data * ve_proc, int ret) | |
327 { | |
328 int procret; | |
329 | |
330 if (WIFEXITED (ret)) | |
331 { | |
332 procret = WEXITSTATUS (ret); | |
333 if (procret != 0) | |
334 { | |
335 ftp_log (gftp_logging_error, NULL, | |
336 _("Error: Child %d returned %d\n"), ve_proc->pid, procret); | |
337 if (ve_proc->view) | |
338 remove_file (ve_proc); | |
339 | |
340 return (0); | |
341 } | |
342 else | |
343 { | |
344 ftp_log (gftp_logging_misc, NULL, | |
345 _("Child %d returned successfully\n"), ve_proc->pid); | |
346 return (1); | |
347 } | |
348 } | |
349 else | |
350 { | |
351 ftp_log (gftp_logging_error, NULL, | |
352 _("Error: Child %d did not terminate properly\n"), | |
353 ve_proc->pid); | |
354 return (0); | |
355 } | |
356 } | |
357 | |
358 | |
359 static int | |
360 _prompt_to_upload_edited_file (gftp_viewedit_data * ve_proc) | |
361 { | |
362 struct stat st; | |
363 char *str; | |
364 | |
365 if (stat (ve_proc->filename, &st) == -1) | |
366 { | |
367 ftp_log (gftp_logging_error, NULL, | |
368 _("Error: Cannot get information about file %s: %s\n"), | |
369 ve_proc->filename, g_strerror (errno)); | |
370 return (0); | |
371 } | |
372 else if (st.st_mtime == ve_proc->st.st_mtime) | |
373 { | |
374 ftp_log (gftp_logging_misc, NULL, _("File %s was not changed\n"), | |
375 ve_proc->filename); | |
376 remove_file (ve_proc); | |
377 return (0); | |
378 } | |
379 else | |
380 { | |
381 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
382 str = g_strdup_printf (_("File %s has changed.\nWould you like to upload it?"), | |
383 ve_proc->remote_filename); | |
384 | |
385 MakeYesNoDialog (_("Edit File"), str, do_upload, ve_proc, dont_upload, | |
386 ve_proc); | |
387 g_free (str); | |
388 return (1); | |
389 } | |
390 } | |
391 | |
392 | |
48 | 393 static void |
829 | 394 do_check_done_process (pid_t pid, int ret) |
48 | 395 { |
396 gftp_viewedit_data * ve_proc; | |
397 GList * curdata, *deldata; | |
829 | 398 int ok; |
399 | |
400 curdata = viewedit_processes; | |
401 while (curdata != NULL) | |
402 { | |
403 ve_proc = curdata->data; | |
404 if (ve_proc->pid != pid) | |
405 continue; | |
406 | |
407 printf ("Found pid %d in the linked list\n", pid); | |
408 deldata = curdata; | |
409 curdata = curdata->next; | |
410 | |
411 viewedit_processes = g_list_remove_link (viewedit_processes, | |
412 deldata); | |
413 | |
414 ok = _check_viewedit_process_status (ve_proc, ret); | |
415 if (!ve_proc->view && ve_proc->dontupload) | |
416 gftpui_refresh (ve_proc->fromwdata, 1); | |
417 | |
418 if (ok && !ve_proc->view && !ve_proc->dontupload) | |
419 { | |
420 /* We were editing the file. Upload it */ | |
421 if (_prompt_to_upload_edited_file (ve_proc)) | |
422 break; /* Don't free the ve_proc structure */ | |
423 } | |
424 else if (ve_proc->view && ve_proc->rm) | |
425 { | |
426 /* After viewing the file delete the tmp file */ | |
427 remove_file (ve_proc); | |
428 } | |
429 | |
430 free_edit_data (ve_proc); | |
431 break; | |
432 } | |
433 } | |
434 | |
435 | |
436 static void | |
437 check_done_process (void) | |
438 { | |
48 | 439 pid_t pid; |
829 | 440 int ret; |
48 | 441 |
470 | 442 gftpui_common_child_process_done = 0; |
48 | 443 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) |
1 | 444 { |
829 | 445 do_check_done_process (pid, ret); |
1 | 446 } |
447 } | |
448 | |
449 | |
450 static void | |
451 on_next_transfer (gftp_transfer * tdata) | |
452 { | |
326 | 453 int fd; |
454 intptr_t refresh_files; | |
1 | 455 gftp_file * tempfle; |
456 | |
457 tdata->next_file = 0; | |
458 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
459 { | |
460 tempfle = tdata->updfle->data; | |
461 | |
462 if (tempfle->is_fd) | |
58 | 463 fd = tempfle->fd; |
1 | 464 else |
465 fd = 0; | |
466 | |
467 if (tempfle->done_view) | |
468 { | |
469 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
470 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
471 tempfle->file, NULL); | |
472 | |
473 if (tempfle->is_fd) | |
474 { | |
58 | 475 close (tempfle->fd); |
476 tempfle->fd = -1; | |
1 | 477 } |
478 } | |
479 else if (tempfle->done_edit) | |
480 { | |
481 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
482 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
483 tempfle->file, NULL); | |
484 | |
485 if (tempfle->is_fd) | |
486 { | |
58 | 487 close (tempfle->fd); |
488 tempfle->fd = -1; | |
1 | 489 } |
490 } | |
491 else if (tempfle->done_rm) | |
492 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
493 | |
494 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
129 | 495 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 496 _("Skipped")); |
497 else | |
129 | 498 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 499 _("Finished")); |
500 } | |
501 | |
129 | 502 gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); |
503 | |
1 | 504 if (refresh_files && tdata->curfle && tdata->curfle->next && |
505 compare_request (tdata->toreq, | |
506 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 507 gftpui_refresh (tdata->towdata, 1); |
1 | 508 } |
509 | |
510 | |
511 static void | |
19 | 512 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
513 { | |
514 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
515 request->stopable = 0; | |
516 } | |
517 | |
518 | |
519 static void | |
520 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
521 { | |
522 if (tdata->fromreq->stopable == 0) | |
523 return; | |
524 | |
819 | 525 gftpui_common_cancel_file_transfer (tdata); |
19 | 526 } |
527 | |
528 | |
529 static void | |
1 | 530 show_transfer (gftp_transfer * tdata) |
531 { | |
532 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
533 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
367 | 534 gftpui_common_curtrans_data * transdata; |
1 | 535 gftp_file * tempfle; |
536 GList * templist; | |
397 | 537 char *text[2]; |
1 | 538 |
539 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
540 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
541 | |
129 | 542 text[0] = tdata->fromreq->hostname; |
1 | 543 text[1] = _("Waiting..."); |
129 | 544 tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, |
545 text, 5, | |
1 | 546 closedir_pixmap, closedir_bitmap, |
547 opendir_pixmap, opendir_bitmap, | |
548 FALSE, | |
549 tdata->numdirs + tdata->numfiles < 50); | |
550 transdata = g_malloc (sizeof (*transdata)); | |
551 transdata->transfer = tdata; | |
552 transdata->curfle = NULL; | |
129 | 553 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); |
1 | 554 tdata->show = 0; |
555 tdata->curfle = tdata->updfle = tdata->files; | |
556 | |
557 tdata->total_bytes = 0; | |
558 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
559 { | |
560 tempfle = templist->data; | |
397 | 561 |
562 text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); | |
1 | 563 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) |
564 text[1] = _("Skipped"); | |
565 else | |
566 { | |
567 tdata->total_bytes += tempfle->size; | |
568 text[1] = _("Waiting..."); | |
569 } | |
570 | |
129 | 571 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
572 tdata->user_data, | |
1 | 573 NULL, text, 5, NULL, NULL, NULL, |
574 NULL, FALSE, FALSE); | |
575 transdata = g_malloc (sizeof (*transdata)); | |
576 transdata->transfer = tdata; | |
577 transdata->curfle = templist; | |
129 | 578 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
579 transdata); | |
1 | 580 } |
581 | |
553 | 582 if (!tdata->toreq->stopable && gftp_need_password (tdata->toreq)) |
1 | 583 { |
584 tdata->toreq->stopable = 1; | |
585 MakeEditDialog (_("Enter Password"), | |
586 _("Please enter your password for this site"), NULL, 0, | |
19 | 587 NULL, gftp_dialog_button_connect, |
588 get_trans_password, tdata->toreq, | |
589 cancel_get_trans_password, tdata); | |
1 | 590 } |
591 | |
553 | 592 if (!tdata->fromreq->stopable && gftp_need_password (tdata->fromreq)) |
1 | 593 { |
594 tdata->fromreq->stopable = 1; | |
595 MakeEditDialog (_("Enter Password"), | |
596 _("Please enter your password for this site"), NULL, 0, | |
19 | 597 NULL, gftp_dialog_button_connect, |
598 get_trans_password, tdata->fromreq, | |
599 cancel_get_trans_password, tdata); | |
1 | 600 } |
601 } | |
602 | |
603 | |
604 static void | |
605 transfer_done (GList * node) | |
606 { | |
367 | 607 gftpui_common_curtrans_data * transdata; |
1 | 608 gftp_transfer * tdata; |
609 gftp_file * tempfle; | |
610 GList * templist; | |
611 | |
612 tdata = node->data; | |
613 if (tdata->started) | |
614 { | |
297 | 615 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, |
616 tdata->fromreq)) | |
309 | 617 { |
618 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
619 | |
620 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
621 tdata->fromreq); | |
622 } | |
1 | 623 else |
297 | 624 gftp_disconnect (tdata->fromreq); |
625 | |
626 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
627 tdata->toreq)) | |
309 | 628 { |
629 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
630 | |
631 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
632 tdata->toreq); | |
633 } | |
297 | 634 else |
635 gftp_disconnect (tdata->toreq); | |
1 | 636 |
305 | 637 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
638 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 639 gftpui_refresh (tdata->towdata, 1); |
305 | 640 |
129 | 641 num_transfers_in_progress--; |
1 | 642 } |
643 | |
785 | 644 if ((!tdata->show && tdata->started) || |
645 (tdata->done && !tdata->started)) | |
1 | 646 { |
129 | 647 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
648 tdata->user_data); | |
1 | 649 if (transdata != NULL) |
650 g_free (transdata); | |
651 | |
652 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
653 { | |
654 tempfle = templist->data; | |
129 | 655 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
656 tempfle->user_data); | |
1 | 657 if (transdata != NULL) |
658 g_free (transdata); | |
659 } | |
660 | |
129 | 661 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 662 } |
129 | 663 |
367 | 664 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 665 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 666 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
667 | |
320 | 668 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
669 gftp_version); | |
129 | 670 |
1 | 671 free_tdata (tdata); |
672 } | |
673 | |
674 | |
367 | 675 static void * |
676 _gftpui_transfer_files (void *data) | |
677 { | |
678 int ret; | |
679 | |
680 pthread_detach (pthread_self ()); | |
681 ret = gftpui_common_transfer_files (data); | |
682 return (GINT_TO_POINTER(ret)); | |
683 } | |
684 | |
685 | |
1 | 686 static void |
687 create_transfer (gftp_transfer * tdata) | |
688 { | |
689 pthread_t tid; | |
690 | |
691 if (!tdata->fromreq->stopable) | |
692 { | |
297 | 693 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
694 tdata->fromreq)) | |
695 { | |
696 gftp_swap_socks (tdata->fromreq, | |
697 ((gftp_window_data *) tdata->fromwdata)->request); | |
698 update_window (tdata->fromwdata); | |
699 } | |
700 | |
701 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
702 tdata->toreq)) | |
703 { | |
63 | 704 gftp_swap_socks (tdata->toreq, |
705 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 706 update_window (tdata->towdata); |
1 | 707 } |
297 | 708 |
129 | 709 num_transfers_in_progress++; |
1 | 710 tdata->started = 1; |
711 tdata->stalled = 1; | |
129 | 712 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 713 _("Connecting...")); |
367 | 714 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 715 } |
716 } | |
717 | |
718 | |
719 static void | |
753 | 720 _setup_dlstr (gftp_transfer * tdata, gftp_file * fle, char *dlstr, |
721 size_t dlstr_len) | |
722 { | |
767 | 723 int hours, mins, secs, stalled, usesentdescr; |
753 | 724 unsigned long remaining_secs, lkbs; |
725 char gotstr[50], ofstr[50]; | |
726 struct timeval tv; | |
727 | |
767 | 728 stalled = 1; |
753 | 729 gettimeofday (&tv, NULL); |
730 usesentdescr = (tdata->fromreq->protonum == GFTP_LOCAL_NUM); | |
731 | |
732 insert_commas (fle->size, ofstr, sizeof (ofstr)); | |
733 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
734 | |
735 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
736 { | |
767 | 737 remaining_secs = (fle->size - tdata->curtrans - tdata->curresumed) / 1024; |
738 | |
739 lkbs = (unsigned long) tdata->kbs; | |
740 if (lkbs > 0) | |
741 remaining_secs /= lkbs; | |
753 | 742 |
767 | 743 hours = remaining_secs / 3600; |
744 remaining_secs -= hours * 3600; | |
745 mins = remaining_secs / 60; | |
746 remaining_secs -= mins * 60; | |
747 secs = remaining_secs; | |
753 | 748 |
749 if (!(hours < 0 || mins < 0 || secs < 0)) | |
750 { | |
767 | 751 stalled = 0; |
753 | 752 if (usesentdescr) |
753 { | |
754 g_snprintf (dlstr, dlstr_len, | |
755 _("Sent %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
756 } | |
757 else | |
758 { | |
759 g_snprintf (dlstr, dlstr_len, | |
760 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
761 } | |
762 } | |
763 } | |
764 | |
767 | 765 if (stalled) |
753 | 766 { |
767 tdata->stalled = 1; | |
768 if (usesentdescr) | |
769 { | |
770 g_snprintf (dlstr, dlstr_len, | |
771 _("Sent %s of %s, transfer stalled, unknown time remaining"), | |
772 gotstr, ofstr); | |
773 } | |
774 else | |
775 { | |
776 g_snprintf (dlstr, dlstr_len, | |
777 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
778 gotstr, ofstr); | |
779 } | |
780 } | |
781 } | |
782 | |
783 | |
784 static void | |
1 | 785 update_file_status (gftp_transfer * tdata) |
786 { | |
753 | 787 char totstr[150], winstr[150], dlstr[150]; |
246 | 788 unsigned long remaining_secs, lkbs; |
767 | 789 int hours, mins, secs, pcent; |
463 | 790 intptr_t show_trans_in_title; |
1 | 791 gftp_file * tempfle; |
320 | 792 |
129 | 793 g_static_mutex_lock (&tdata->statmutex); |
1 | 794 tempfle = tdata->curfle->data; |
795 | |
220 | 796 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; |
246 | 797 |
798 lkbs = (unsigned long) tdata->kbs; | |
799 if (lkbs > 0) | |
800 remaining_secs /= lkbs; | |
1 | 801 |
220 | 802 hours = remaining_secs / 3600; |
803 remaining_secs -= hours * 3600; | |
804 mins = remaining_secs / 60; | |
805 remaining_secs -= mins * 60; | |
806 secs = remaining_secs; | |
1 | 807 |
808 if (hours < 0 || mins < 0 || secs < 0) | |
809 { | |
129 | 810 g_static_mutex_unlock (&tdata->statmutex); |
1 | 811 return; |
812 } | |
813 | |
246 | 814 if ((double) tdata->total_bytes > 0) |
815 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
816 else | |
1 | 817 pcent = 0; |
818 | |
602 | 819 if (pcent > 100) |
820 g_snprintf (totstr, sizeof (totstr), | |
821 _("Unknown percentage complete. (File %ld of %ld)"), | |
822 tdata->current_file_number, tdata->numdirs + tdata->numfiles); | |
823 else | |
824 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
825 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 826 pcent, hours, mins, secs, tdata->current_file_number, |
827 tdata->numdirs + tdata->numfiles); | |
828 | |
829 *dlstr = '\0'; | |
830 if (!tdata->stalled) | |
753 | 831 _setup_dlstr (tdata, tempfle, dlstr, sizeof (dlstr)); |
1 | 832 |
129 | 833 g_static_mutex_unlock (&tdata->statmutex); |
1 | 834 |
129 | 835 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 836 |
837 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
838 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
839 { | |
840 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
841 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
842 winstr); | |
843 } | |
1 | 844 |
845 if (*dlstr != '\0') | |
129 | 846 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 847 } |
848 | |
377 | 849 |
56 | 850 static void |
851 update_window_transfer_bytes (gftp_window_data * wdata) | |
852 { | |
853 char *tempstr, *temp1str; | |
854 | |
855 if (wdata->request->gotbytes == -1) | |
856 { | |
793 | 857 update_window (wdata); |
56 | 858 wdata->request->gotbytes = 0; |
859 } | |
860 else | |
861 { | |
862 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
863 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
864 tempstr); | |
865 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
866 g_free (tempstr); | |
867 g_free (temp1str); | |
868 } | |
869 } | |
870 | |
1 | 871 |
48 | 872 gint |
873 update_downloads (gpointer data) | |
874 { | |
433 | 875 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 876 GList * templist, * next; |
877 gftp_transfer * tdata; | |
878 | |
129 | 879 if (gftp_file_transfer_logs != NULL) |
48 | 880 display_cached_logs (); |
881 | |
56 | 882 if (window1.request->gotbytes != 0) |
883 update_window_transfer_bytes (&window1); | |
48 | 884 if (window2.request->gotbytes != 0) |
56 | 885 update_window_transfer_bytes (&window2); |
48 | 886 |
470 | 887 if (gftpui_common_child_process_done) |
48 | 888 check_done_process (); |
889 | |
129 | 890 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 891 { |
892 tdata = templist->data; | |
893 if (tdata->ready) | |
894 { | |
129 | 895 g_static_mutex_lock (&tdata->structmutex); |
48 | 896 |
897 if (tdata->next_file) | |
898 on_next_transfer (tdata); | |
899 else if (tdata->show) | |
900 show_transfer (tdata); | |
901 else if (tdata->done) | |
902 { | |
903 next = templist->next; | |
129 | 904 g_static_mutex_unlock (&tdata->structmutex); |
48 | 905 transfer_done (templist); |
906 templist = next; | |
907 continue; | |
908 } | |
909 | |
910 if (tdata->curfle != NULL) | |
911 { | |
151 | 912 gftp_lookup_global_option ("one_transfer", |
129 | 913 &do_one_transfer_at_a_time); |
433 | 914 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 915 |
433 | 916 if (!tdata->started && start_transfers && |
129 | 917 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 918 create_transfer (tdata); |
919 | |
920 if (tdata->started) | |
921 update_file_status (tdata); | |
922 } | |
129 | 923 g_static_mutex_unlock (&tdata->structmutex); |
48 | 924 } |
925 templist = templist->next; | |
926 } | |
927 | |
928 gtk_timeout_add (500, update_downloads, NULL); | |
929 return (0); | |
930 } | |
931 | |
932 | |
1 | 933 void |
934 start_transfer (gpointer data) | |
935 { | |
367 | 936 gftpui_common_curtrans_data * transdata; |
1 | 937 GtkCTreeNode * node; |
938 | |
939 if (GTK_CLIST (dlwdw)->selection == NULL) | |
940 { | |
677 | 941 ftp_log (gftp_logging_error, NULL, |
1 | 942 _("There are no file transfers selected\n")); |
943 return; | |
944 } | |
945 node = GTK_CLIST (dlwdw)->selection->data; | |
946 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
947 | |
129 | 948 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 949 if (!transdata->transfer->started) |
950 create_transfer (transdata->transfer); | |
129 | 951 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 952 } |
953 | |
954 | |
955 void | |
956 stop_transfer (gpointer data) | |
957 { | |
367 | 958 gftpui_common_curtrans_data * transdata; |
1 | 959 GtkCTreeNode * node; |
960 | |
961 if (GTK_CLIST (dlwdw)->selection == NULL) | |
962 { | |
677 | 963 ftp_log (gftp_logging_error, NULL, |
1 | 964 _("There are no file transfers selected\n")); |
965 return; | |
966 } | |
819 | 967 |
1 | 968 node = GTK_CLIST (dlwdw)->selection->data; |
969 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
819 | 970 gftpui_common_cancel_file_transfer (transdata->transfer); |
1 | 971 } |
972 | |
973 | |
974 void | |
975 skip_transfer (gpointer data) | |
976 { | |
367 | 977 gftpui_common_curtrans_data * transdata; |
1 | 978 GtkCTreeNode * node; |
979 | |
980 if (GTK_CLIST (dlwdw)->selection == NULL) | |
981 { | |
677 | 982 ftp_log (gftp_logging_error, NULL, |
1 | 983 _("There are no file transfers selected\n")); |
984 return; | |
985 } | |
819 | 986 |
1 | 987 node = GTK_CLIST (dlwdw)->selection->data; |
988 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
989 | |
819 | 990 gftpui_common_skip_file_transfer (transdata->transfer, |
991 transdata->transfer->curfle->data); | |
1 | 992 } |
993 | |
994 | |
995 void | |
996 remove_file_transfer (gpointer data) | |
997 { | |
367 | 998 gftpui_common_curtrans_data * transdata; |
1 | 999 GtkCTreeNode * node; |
1000 gftp_file * curfle; | |
1001 | |
1002 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1003 { | |
677 | 1004 ftp_log (gftp_logging_error, NULL, |
1 | 1005 _("There are no file transfers selected\n")); |
1006 return; | |
1007 } | |
1008 | |
1009 node = GTK_CLIST (dlwdw)->selection->data; | |
1010 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1011 | |
1012 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1013 return; | |
1014 | |
1015 curfle = transdata->curfle->data; | |
819 | 1016 gftpui_common_skip_file_transfer (transdata->transfer, curfle); |
1 | 1017 |
819 | 1018 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1019 _("Skipped")); | |
1 | 1020 } |
1021 | |
1022 | |
1023 void | |
1024 move_transfer_up (gpointer data) | |
1025 { | |
1026 GList * firstentry, * secentry, * lastentry; | |
367 | 1027 gftpui_common_curtrans_data * transdata; |
1 | 1028 GtkCTreeNode * node; |
1029 | |
1030 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1031 { | |
677 | 1032 ftp_log (gftp_logging_error, NULL, |
1 | 1033 _("There are no file transfers selected\n")); |
1034 return; | |
1035 } | |
1036 node = GTK_CLIST (dlwdw)->selection->data; | |
1037 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1038 | |
1039 if (transdata->curfle == NULL) | |
1040 return; | |
1041 | |
129 | 1042 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1043 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1044 (transdata->transfer->curfle != transdata->curfle && | |
1045 transdata->transfer->curfle != transdata->curfle->prev))) | |
1046 { | |
1047 if (transdata->curfle->prev->prev == NULL) | |
1048 { | |
1049 firstentry = transdata->curfle->prev; | |
1050 lastentry = transdata->curfle->next; | |
1051 transdata->transfer->files = transdata->curfle; | |
1052 transdata->curfle->next = firstentry; | |
1053 transdata->transfer->files->prev = NULL; | |
1054 firstentry->prev = transdata->curfle; | |
1055 firstentry->next = lastentry; | |
1056 if (lastentry != NULL) | |
1057 lastentry->prev = firstentry; | |
1058 } | |
1059 else | |
1060 { | |
1061 firstentry = transdata->curfle->prev->prev; | |
1062 secentry = transdata->curfle->prev; | |
1063 lastentry = transdata->curfle->next; | |
1064 firstentry->next = transdata->curfle; | |
1065 transdata->curfle->prev = firstentry; | |
1066 transdata->curfle->next = secentry; | |
1067 secentry->prev = transdata->curfle; | |
1068 secentry->next = lastentry; | |
1069 if (lastentry != NULL) | |
1070 lastentry->prev = secentry; | |
1071 } | |
1072 | |
1073 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1074 ((gftp_file *) transdata->curfle->data)->user_data, |
1075 transdata->transfer->user_data, | |
1 | 1076 transdata->curfle->next != NULL ? |
129 | 1077 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1078 } |
129 | 1079 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1080 } |
1081 | |
367 | 1082 |
1 | 1083 void |
1084 move_transfer_down (gpointer data) | |
1085 { | |
1086 GList * firstentry, * secentry, * lastentry; | |
367 | 1087 gftpui_common_curtrans_data * transdata; |
1 | 1088 GtkCTreeNode * node; |
1089 | |
1090 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1091 { | |
677 | 1092 ftp_log (gftp_logging_error, NULL, |
1 | 1093 _("There are no file transfers selected\n")); |
1094 return; | |
1095 } | |
1096 node = GTK_CLIST (dlwdw)->selection->data; | |
1097 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1098 | |
1099 if (transdata->curfle == NULL) | |
1100 return; | |
1101 | |
129 | 1102 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1103 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1104 (transdata->transfer->curfle != transdata->curfle && | |
1105 transdata->transfer->curfle != transdata->curfle->next))) | |
1106 { | |
1107 if (transdata->curfle->prev == NULL) | |
1108 { | |
1109 firstentry = transdata->curfle->next; | |
1110 lastentry = transdata->curfle->next->next; | |
1111 transdata->transfer->files = firstentry; | |
1112 transdata->transfer->files->prev = NULL; | |
1113 transdata->transfer->files->next = transdata->curfle; | |
1114 transdata->curfle->prev = transdata->transfer->files; | |
1115 transdata->curfle->next = lastentry; | |
1116 if (lastentry != NULL) | |
1117 lastentry->prev = transdata->curfle; | |
1118 } | |
1119 else | |
1120 { | |
1121 firstentry = transdata->curfle->prev; | |
1122 secentry = transdata->curfle->next; | |
1123 lastentry = transdata->curfle->next->next; | |
1124 firstentry->next = secentry; | |
1125 secentry->prev = firstentry; | |
1126 secentry->next = transdata->curfle; | |
1127 transdata->curfle->prev = secentry; | |
1128 transdata->curfle->next = lastentry; | |
1129 if (lastentry != NULL) | |
1130 lastentry->prev = transdata->curfle; | |
1131 } | |
1132 | |
1133 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1134 ((gftp_file *) transdata->curfle->data)->user_data, |
1135 transdata->transfer->user_data, | |
1 | 1136 transdata->curfle->next != NULL ? |
129 | 1137 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1138 } |
129 | 1139 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1140 } |
1141 |