Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 828:db4b34e3f83f
2006-10-15 Brian Masney <masneyb@gftp.org>
* lib/fsplib/lock.c (client_init_key) - renamed the sun local variable
to su. This was causing compile problems under Solaris.
* lib/fsplib/lock.h - include ../../config.h
author | masneyb |
---|---|
date | Sun, 15 Oct 2006 17:36:29 +0000 |
parents | d6fdfcbdb056 |
children | 74f49d528c68 |
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 |
48 | 325 static void |
326 check_done_process (void) | |
327 { | |
328 gftp_viewedit_data * ve_proc; | |
329 GList * curdata, *deldata; | |
556 | 330 int ret, procret; |
48 | 331 struct stat st; |
332 char *str; | |
333 pid_t pid; | |
334 | |
470 | 335 gftpui_common_child_process_done = 0; |
48 | 336 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) |
1 | 337 { |
48 | 338 curdata = viewedit_processes; |
339 while (curdata != NULL) | |
340 { | |
341 ve_proc = curdata->data; | |
342 deldata = curdata; | |
343 curdata = curdata->next; | |
344 if (ve_proc->pid == pid) | |
345 { | |
346 viewedit_processes = g_list_remove_link (viewedit_processes, | |
347 deldata); | |
556 | 348 if (WIFEXITED (ret)) |
349 { | |
350 procret = WEXITSTATUS (ret); | |
351 if (procret != 0) | |
559 | 352 { |
353 ftp_log (gftp_logging_error, NULL, | |
354 _("Error: Child %d returned %d\n"), pid, procret); | |
703 | 355 if (ve_proc->view) |
770 | 356 remove_file (ve_proc); |
559 | 357 continue; |
358 } | |
556 | 359 else |
360 ftp_log (gftp_logging_misc, NULL, | |
361 _("Child %d returned successfully\n"), pid); | |
362 } | |
363 else | |
364 ftp_log (gftp_logging_error, NULL, | |
365 _("Error: Child %d did not terminate properly\n"), | |
366 pid); | |
48 | 367 |
368 if (!ve_proc->view && !ve_proc->dontupload) | |
369 { | |
370 /* We was editing the file. Upload it */ | |
556 | 371 ret = stat (ve_proc->filename, &st); |
372 | |
373 if (ret == -1) | |
48 | 374 ftp_log (gftp_logging_error, NULL, |
375 _("Error: Cannot get information about file %s: %s\n"), | |
376 ve_proc->filename, g_strerror (errno)); | |
377 else if (st.st_mtime == ve_proc->st.st_mtime) | |
378 { | |
379 ftp_log (gftp_logging_misc, NULL, | |
380 _("File %s was not changed\n"), | |
381 ve_proc->filename); | |
770 | 382 remove_file (ve_proc); |
48 | 383 } |
384 else | |
385 { | |
386 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
387 str = g_strdup_printf ( | |
388 _("File %s has changed.\nWould you like to upload it?"), | |
389 ve_proc->remote_filename); | |
390 | |
391 MakeYesNoDialog (_("Edit File"), str, | |
392 do_upload, ve_proc, | |
393 dont_upload, ve_proc); | |
394 g_free (str); | |
395 continue; | |
396 } | |
397 } | |
778 | 398 else if (ve_proc->view && ve_proc->rm) |
399 { | |
400 /* After viewing the file delete the tmp file */ | |
401 remove_file (ve_proc); | |
402 } | |
48 | 403 |
404 free_edit_data (ve_proc); | |
405 continue; | |
406 } | |
1 | 407 } |
408 } | |
409 } | |
410 | |
411 | |
412 static void | |
413 on_next_transfer (gftp_transfer * tdata) | |
414 { | |
326 | 415 int fd; |
416 intptr_t refresh_files; | |
1 | 417 gftp_file * tempfle; |
418 | |
419 tdata->next_file = 0; | |
420 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
421 { | |
422 tempfle = tdata->updfle->data; | |
423 | |
424 if (tempfle->is_fd) | |
58 | 425 fd = tempfle->fd; |
1 | 426 else |
427 fd = 0; | |
428 | |
429 if (tempfle->done_view) | |
430 { | |
431 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
432 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
433 tempfle->file, NULL); | |
434 | |
435 if (tempfle->is_fd) | |
436 { | |
58 | 437 close (tempfle->fd); |
438 tempfle->fd = -1; | |
1 | 439 } |
440 } | |
441 else if (tempfle->done_edit) | |
442 { | |
443 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
444 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
445 tempfle->file, NULL); | |
446 | |
447 if (tempfle->is_fd) | |
448 { | |
58 | 449 close (tempfle->fd); |
450 tempfle->fd = -1; | |
1 | 451 } |
452 } | |
453 else if (tempfle->done_rm) | |
454 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
455 | |
456 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
129 | 457 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 458 _("Skipped")); |
459 else | |
129 | 460 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 461 _("Finished")); |
462 } | |
463 | |
129 | 464 gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); |
465 | |
1 | 466 if (refresh_files && tdata->curfle && tdata->curfle->next && |
467 compare_request (tdata->toreq, | |
468 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 469 gftpui_refresh (tdata->towdata, 1); |
1 | 470 } |
471 | |
472 | |
473 static void | |
19 | 474 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
475 { | |
476 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
477 request->stopable = 0; | |
478 } | |
479 | |
480 | |
481 static void | |
482 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
483 { | |
484 if (tdata->fromreq->stopable == 0) | |
485 return; | |
486 | |
819 | 487 gftpui_common_cancel_file_transfer (tdata); |
19 | 488 } |
489 | |
490 | |
491 static void | |
1 | 492 show_transfer (gftp_transfer * tdata) |
493 { | |
494 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
495 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
367 | 496 gftpui_common_curtrans_data * transdata; |
1 | 497 gftp_file * tempfle; |
498 GList * templist; | |
397 | 499 char *text[2]; |
1 | 500 |
501 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
502 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
503 | |
129 | 504 text[0] = tdata->fromreq->hostname; |
1 | 505 text[1] = _("Waiting..."); |
129 | 506 tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, |
507 text, 5, | |
1 | 508 closedir_pixmap, closedir_bitmap, |
509 opendir_pixmap, opendir_bitmap, | |
510 FALSE, | |
511 tdata->numdirs + tdata->numfiles < 50); | |
512 transdata = g_malloc (sizeof (*transdata)); | |
513 transdata->transfer = tdata; | |
514 transdata->curfle = NULL; | |
129 | 515 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); |
1 | 516 tdata->show = 0; |
517 tdata->curfle = tdata->updfle = tdata->files; | |
518 | |
519 tdata->total_bytes = 0; | |
520 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
521 { | |
522 tempfle = templist->data; | |
397 | 523 |
524 text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); | |
1 | 525 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) |
526 text[1] = _("Skipped"); | |
527 else | |
528 { | |
529 tdata->total_bytes += tempfle->size; | |
530 text[1] = _("Waiting..."); | |
531 } | |
532 | |
129 | 533 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
534 tdata->user_data, | |
1 | 535 NULL, text, 5, NULL, NULL, NULL, |
536 NULL, FALSE, FALSE); | |
537 transdata = g_malloc (sizeof (*transdata)); | |
538 transdata->transfer = tdata; | |
539 transdata->curfle = templist; | |
129 | 540 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
541 transdata); | |
1 | 542 } |
543 | |
553 | 544 if (!tdata->toreq->stopable && gftp_need_password (tdata->toreq)) |
1 | 545 { |
546 tdata->toreq->stopable = 1; | |
547 MakeEditDialog (_("Enter Password"), | |
548 _("Please enter your password for this site"), NULL, 0, | |
19 | 549 NULL, gftp_dialog_button_connect, |
550 get_trans_password, tdata->toreq, | |
551 cancel_get_trans_password, tdata); | |
1 | 552 } |
553 | |
553 | 554 if (!tdata->fromreq->stopable && gftp_need_password (tdata->fromreq)) |
1 | 555 { |
556 tdata->fromreq->stopable = 1; | |
557 MakeEditDialog (_("Enter Password"), | |
558 _("Please enter your password for this site"), NULL, 0, | |
19 | 559 NULL, gftp_dialog_button_connect, |
560 get_trans_password, tdata->fromreq, | |
561 cancel_get_trans_password, tdata); | |
1 | 562 } |
563 } | |
564 | |
565 | |
566 static void | |
567 transfer_done (GList * node) | |
568 { | |
367 | 569 gftpui_common_curtrans_data * transdata; |
1 | 570 gftp_transfer * tdata; |
571 gftp_file * tempfle; | |
572 GList * templist; | |
573 | |
574 tdata = node->data; | |
575 if (tdata->started) | |
576 { | |
297 | 577 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, |
578 tdata->fromreq)) | |
309 | 579 { |
580 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
581 | |
582 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
583 tdata->fromreq); | |
584 } | |
1 | 585 else |
297 | 586 gftp_disconnect (tdata->fromreq); |
587 | |
588 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
589 tdata->toreq)) | |
309 | 590 { |
591 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
592 | |
593 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
594 tdata->toreq); | |
595 } | |
297 | 596 else |
597 gftp_disconnect (tdata->toreq); | |
1 | 598 |
305 | 599 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
600 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 601 gftpui_refresh (tdata->towdata, 1); |
305 | 602 |
129 | 603 num_transfers_in_progress--; |
1 | 604 } |
605 | |
785 | 606 if ((!tdata->show && tdata->started) || |
607 (tdata->done && !tdata->started)) | |
1 | 608 { |
129 | 609 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
610 tdata->user_data); | |
1 | 611 if (transdata != NULL) |
612 g_free (transdata); | |
613 | |
614 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
615 { | |
616 tempfle = templist->data; | |
129 | 617 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
618 tempfle->user_data); | |
1 | 619 if (transdata != NULL) |
620 g_free (transdata); | |
621 } | |
622 | |
129 | 623 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 624 } |
129 | 625 |
367 | 626 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 627 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 628 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
629 | |
320 | 630 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
631 gftp_version); | |
129 | 632 |
1 | 633 free_tdata (tdata); |
634 } | |
635 | |
636 | |
367 | 637 static void * |
638 _gftpui_transfer_files (void *data) | |
639 { | |
640 int ret; | |
641 | |
642 pthread_detach (pthread_self ()); | |
643 ret = gftpui_common_transfer_files (data); | |
644 return (GINT_TO_POINTER(ret)); | |
645 } | |
646 | |
647 | |
1 | 648 static void |
649 create_transfer (gftp_transfer * tdata) | |
650 { | |
651 pthread_t tid; | |
652 | |
653 if (!tdata->fromreq->stopable) | |
654 { | |
297 | 655 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
656 tdata->fromreq)) | |
657 { | |
658 gftp_swap_socks (tdata->fromreq, | |
659 ((gftp_window_data *) tdata->fromwdata)->request); | |
660 update_window (tdata->fromwdata); | |
661 } | |
662 | |
663 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
664 tdata->toreq)) | |
665 { | |
63 | 666 gftp_swap_socks (tdata->toreq, |
667 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 668 update_window (tdata->towdata); |
1 | 669 } |
297 | 670 |
129 | 671 num_transfers_in_progress++; |
1 | 672 tdata->started = 1; |
673 tdata->stalled = 1; | |
129 | 674 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 675 _("Connecting...")); |
367 | 676 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 677 } |
678 } | |
679 | |
680 | |
681 static void | |
753 | 682 _setup_dlstr (gftp_transfer * tdata, gftp_file * fle, char *dlstr, |
683 size_t dlstr_len) | |
684 { | |
767 | 685 int hours, mins, secs, stalled, usesentdescr; |
753 | 686 unsigned long remaining_secs, lkbs; |
687 char gotstr[50], ofstr[50]; | |
688 struct timeval tv; | |
689 | |
767 | 690 stalled = 1; |
753 | 691 gettimeofday (&tv, NULL); |
692 usesentdescr = (tdata->fromreq->protonum == GFTP_LOCAL_NUM); | |
693 | |
694 insert_commas (fle->size, ofstr, sizeof (ofstr)); | |
695 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
696 | |
697 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
698 { | |
767 | 699 remaining_secs = (fle->size - tdata->curtrans - tdata->curresumed) / 1024; |
700 | |
701 lkbs = (unsigned long) tdata->kbs; | |
702 if (lkbs > 0) | |
703 remaining_secs /= lkbs; | |
753 | 704 |
767 | 705 hours = remaining_secs / 3600; |
706 remaining_secs -= hours * 3600; | |
707 mins = remaining_secs / 60; | |
708 remaining_secs -= mins * 60; | |
709 secs = remaining_secs; | |
753 | 710 |
711 if (!(hours < 0 || mins < 0 || secs < 0)) | |
712 { | |
767 | 713 stalled = 0; |
753 | 714 if (usesentdescr) |
715 { | |
716 g_snprintf (dlstr, dlstr_len, | |
717 _("Sent %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
718 } | |
719 else | |
720 { | |
721 g_snprintf (dlstr, dlstr_len, | |
722 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
723 } | |
724 } | |
725 } | |
726 | |
767 | 727 if (stalled) |
753 | 728 { |
729 tdata->stalled = 1; | |
730 if (usesentdescr) | |
731 { | |
732 g_snprintf (dlstr, dlstr_len, | |
733 _("Sent %s of %s, transfer stalled, unknown time remaining"), | |
734 gotstr, ofstr); | |
735 } | |
736 else | |
737 { | |
738 g_snprintf (dlstr, dlstr_len, | |
739 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
740 gotstr, ofstr); | |
741 } | |
742 } | |
743 } | |
744 | |
745 | |
746 static void | |
1 | 747 update_file_status (gftp_transfer * tdata) |
748 { | |
753 | 749 char totstr[150], winstr[150], dlstr[150]; |
246 | 750 unsigned long remaining_secs, lkbs; |
767 | 751 int hours, mins, secs, pcent; |
463 | 752 intptr_t show_trans_in_title; |
1 | 753 gftp_file * tempfle; |
320 | 754 |
129 | 755 g_static_mutex_lock (&tdata->statmutex); |
1 | 756 tempfle = tdata->curfle->data; |
757 | |
220 | 758 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; |
246 | 759 |
760 lkbs = (unsigned long) tdata->kbs; | |
761 if (lkbs > 0) | |
762 remaining_secs /= lkbs; | |
1 | 763 |
220 | 764 hours = remaining_secs / 3600; |
765 remaining_secs -= hours * 3600; | |
766 mins = remaining_secs / 60; | |
767 remaining_secs -= mins * 60; | |
768 secs = remaining_secs; | |
1 | 769 |
770 if (hours < 0 || mins < 0 || secs < 0) | |
771 { | |
129 | 772 g_static_mutex_unlock (&tdata->statmutex); |
1 | 773 return; |
774 } | |
775 | |
246 | 776 if ((double) tdata->total_bytes > 0) |
777 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
778 else | |
1 | 779 pcent = 0; |
780 | |
602 | 781 if (pcent > 100) |
782 g_snprintf (totstr, sizeof (totstr), | |
783 _("Unknown percentage complete. (File %ld of %ld)"), | |
784 tdata->current_file_number, tdata->numdirs + tdata->numfiles); | |
785 else | |
786 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
787 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 788 pcent, hours, mins, secs, tdata->current_file_number, |
789 tdata->numdirs + tdata->numfiles); | |
790 | |
791 *dlstr = '\0'; | |
792 if (!tdata->stalled) | |
753 | 793 _setup_dlstr (tdata, tempfle, dlstr, sizeof (dlstr)); |
1 | 794 |
129 | 795 g_static_mutex_unlock (&tdata->statmutex); |
1 | 796 |
129 | 797 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 798 |
799 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
800 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
801 { | |
802 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
803 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
804 winstr); | |
805 } | |
1 | 806 |
807 if (*dlstr != '\0') | |
129 | 808 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 809 } |
810 | |
377 | 811 |
56 | 812 static void |
813 update_window_transfer_bytes (gftp_window_data * wdata) | |
814 { | |
815 char *tempstr, *temp1str; | |
816 | |
817 if (wdata->request->gotbytes == -1) | |
818 { | |
793 | 819 update_window (wdata); |
56 | 820 wdata->request->gotbytes = 0; |
821 } | |
822 else | |
823 { | |
824 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
825 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
826 tempstr); | |
827 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
828 g_free (tempstr); | |
829 g_free (temp1str); | |
830 } | |
831 } | |
832 | |
1 | 833 |
48 | 834 gint |
835 update_downloads (gpointer data) | |
836 { | |
433 | 837 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 838 GList * templist, * next; |
839 gftp_transfer * tdata; | |
840 | |
129 | 841 if (gftp_file_transfer_logs != NULL) |
48 | 842 display_cached_logs (); |
843 | |
56 | 844 if (window1.request->gotbytes != 0) |
845 update_window_transfer_bytes (&window1); | |
48 | 846 if (window2.request->gotbytes != 0) |
56 | 847 update_window_transfer_bytes (&window2); |
48 | 848 |
470 | 849 if (gftpui_common_child_process_done) |
48 | 850 check_done_process (); |
851 | |
129 | 852 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 853 { |
854 tdata = templist->data; | |
855 if (tdata->ready) | |
856 { | |
129 | 857 g_static_mutex_lock (&tdata->structmutex); |
48 | 858 |
859 if (tdata->next_file) | |
860 on_next_transfer (tdata); | |
861 else if (tdata->show) | |
862 show_transfer (tdata); | |
863 else if (tdata->done) | |
864 { | |
865 next = templist->next; | |
129 | 866 g_static_mutex_unlock (&tdata->structmutex); |
48 | 867 transfer_done (templist); |
868 templist = next; | |
869 continue; | |
870 } | |
871 | |
872 if (tdata->curfle != NULL) | |
873 { | |
151 | 874 gftp_lookup_global_option ("one_transfer", |
129 | 875 &do_one_transfer_at_a_time); |
433 | 876 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 877 |
433 | 878 if (!tdata->started && start_transfers && |
129 | 879 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 880 create_transfer (tdata); |
881 | |
882 if (tdata->started) | |
883 update_file_status (tdata); | |
884 } | |
129 | 885 g_static_mutex_unlock (&tdata->structmutex); |
48 | 886 } |
887 templist = templist->next; | |
888 } | |
889 | |
890 gtk_timeout_add (500, update_downloads, NULL); | |
891 return (0); | |
892 } | |
893 | |
894 | |
1 | 895 void |
896 start_transfer (gpointer data) | |
897 { | |
367 | 898 gftpui_common_curtrans_data * transdata; |
1 | 899 GtkCTreeNode * node; |
900 | |
901 if (GTK_CLIST (dlwdw)->selection == NULL) | |
902 { | |
677 | 903 ftp_log (gftp_logging_error, NULL, |
1 | 904 _("There are no file transfers selected\n")); |
905 return; | |
906 } | |
907 node = GTK_CLIST (dlwdw)->selection->data; | |
908 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
909 | |
129 | 910 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 911 if (!transdata->transfer->started) |
912 create_transfer (transdata->transfer); | |
129 | 913 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 914 } |
915 | |
916 | |
917 void | |
918 stop_transfer (gpointer data) | |
919 { | |
367 | 920 gftpui_common_curtrans_data * transdata; |
1 | 921 GtkCTreeNode * node; |
922 | |
923 if (GTK_CLIST (dlwdw)->selection == NULL) | |
924 { | |
677 | 925 ftp_log (gftp_logging_error, NULL, |
1 | 926 _("There are no file transfers selected\n")); |
927 return; | |
928 } | |
819 | 929 |
1 | 930 node = GTK_CLIST (dlwdw)->selection->data; |
931 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
819 | 932 gftpui_common_cancel_file_transfer (transdata->transfer); |
1 | 933 } |
934 | |
935 | |
936 void | |
937 skip_transfer (gpointer data) | |
938 { | |
367 | 939 gftpui_common_curtrans_data * transdata; |
1 | 940 GtkCTreeNode * node; |
941 gftp_file * curfle; | |
40 | 942 char *file; |
1 | 943 |
944 if (GTK_CLIST (dlwdw)->selection == NULL) | |
945 { | |
677 | 946 ftp_log (gftp_logging_error, NULL, |
1 | 947 _("There are no file transfers selected\n")); |
948 return; | |
949 } | |
819 | 950 |
1 | 951 node = GTK_CLIST (dlwdw)->selection->data; |
952 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
953 | |
819 | 954 gftpui_common_skip_file_transfer (transdata->transfer, |
955 transdata->transfer->curfle->data); | |
1 | 956 } |
957 | |
958 | |
959 void | |
960 remove_file_transfer (gpointer data) | |
961 { | |
367 | 962 gftpui_common_curtrans_data * transdata; |
1 | 963 GtkCTreeNode * node; |
964 gftp_file * curfle; | |
965 | |
966 if (GTK_CLIST (dlwdw)->selection == NULL) | |
967 { | |
677 | 968 ftp_log (gftp_logging_error, NULL, |
1 | 969 _("There are no file transfers selected\n")); |
970 return; | |
971 } | |
972 | |
973 node = GTK_CLIST (dlwdw)->selection->data; | |
974 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
975 | |
976 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
977 return; | |
978 | |
979 curfle = transdata->curfle->data; | |
819 | 980 gftpui_common_skip_file_transfer (transdata->transfer, curfle); |
1 | 981 |
819 | 982 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
983 _("Skipped")); | |
1 | 984 } |
985 | |
986 | |
987 void | |
988 move_transfer_up (gpointer data) | |
989 { | |
990 GList * firstentry, * secentry, * lastentry; | |
367 | 991 gftpui_common_curtrans_data * transdata; |
1 | 992 GtkCTreeNode * node; |
993 | |
994 if (GTK_CLIST (dlwdw)->selection == NULL) | |
995 { | |
677 | 996 ftp_log (gftp_logging_error, NULL, |
1 | 997 _("There are no file transfers selected\n")); |
998 return; | |
999 } | |
1000 node = GTK_CLIST (dlwdw)->selection->data; | |
1001 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1002 | |
1003 if (transdata->curfle == NULL) | |
1004 return; | |
1005 | |
129 | 1006 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1007 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1008 (transdata->transfer->curfle != transdata->curfle && | |
1009 transdata->transfer->curfle != transdata->curfle->prev))) | |
1010 { | |
1011 if (transdata->curfle->prev->prev == NULL) | |
1012 { | |
1013 firstentry = transdata->curfle->prev; | |
1014 lastentry = transdata->curfle->next; | |
1015 transdata->transfer->files = transdata->curfle; | |
1016 transdata->curfle->next = firstentry; | |
1017 transdata->transfer->files->prev = NULL; | |
1018 firstentry->prev = transdata->curfle; | |
1019 firstentry->next = lastentry; | |
1020 if (lastentry != NULL) | |
1021 lastentry->prev = firstentry; | |
1022 } | |
1023 else | |
1024 { | |
1025 firstentry = transdata->curfle->prev->prev; | |
1026 secentry = transdata->curfle->prev; | |
1027 lastentry = transdata->curfle->next; | |
1028 firstentry->next = transdata->curfle; | |
1029 transdata->curfle->prev = firstentry; | |
1030 transdata->curfle->next = secentry; | |
1031 secentry->prev = transdata->curfle; | |
1032 secentry->next = lastentry; | |
1033 if (lastentry != NULL) | |
1034 lastentry->prev = secentry; | |
1035 } | |
1036 | |
1037 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1038 ((gftp_file *) transdata->curfle->data)->user_data, |
1039 transdata->transfer->user_data, | |
1 | 1040 transdata->curfle->next != NULL ? |
129 | 1041 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1042 } |
129 | 1043 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1044 } |
1045 | |
367 | 1046 |
1 | 1047 void |
1048 move_transfer_down (gpointer data) | |
1049 { | |
1050 GList * firstentry, * secentry, * lastentry; | |
367 | 1051 gftpui_common_curtrans_data * transdata; |
1 | 1052 GtkCTreeNode * node; |
1053 | |
1054 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1055 { | |
677 | 1056 ftp_log (gftp_logging_error, NULL, |
1 | 1057 _("There are no file transfers selected\n")); |
1058 return; | |
1059 } | |
1060 node = GTK_CLIST (dlwdw)->selection->data; | |
1061 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1062 | |
1063 if (transdata->curfle == NULL) | |
1064 return; | |
1065 | |
129 | 1066 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1067 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1068 (transdata->transfer->curfle != transdata->curfle && | |
1069 transdata->transfer->curfle != transdata->curfle->next))) | |
1070 { | |
1071 if (transdata->curfle->prev == NULL) | |
1072 { | |
1073 firstentry = transdata->curfle->next; | |
1074 lastentry = transdata->curfle->next->next; | |
1075 transdata->transfer->files = firstentry; | |
1076 transdata->transfer->files->prev = NULL; | |
1077 transdata->transfer->files->next = transdata->curfle; | |
1078 transdata->curfle->prev = transdata->transfer->files; | |
1079 transdata->curfle->next = lastentry; | |
1080 if (lastentry != NULL) | |
1081 lastentry->prev = transdata->curfle; | |
1082 } | |
1083 else | |
1084 { | |
1085 firstentry = transdata->curfle->prev; | |
1086 secentry = transdata->curfle->next; | |
1087 lastentry = transdata->curfle->next->next; | |
1088 firstentry->next = secentry; | |
1089 secentry->prev = firstentry; | |
1090 secentry->next = transdata->curfle; | |
1091 transdata->curfle->prev = secentry; | |
1092 transdata->curfle->next = lastentry; | |
1093 if (lastentry != NULL) | |
1094 lastentry->prev = transdata->curfle; | |
1095 } | |
1096 | |
1097 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1098 ((gftp_file *) transdata->curfle->data)->user_data, |
1099 transdata->transfer->user_data, | |
1 | 1100 transdata->curfle->next != NULL ? |
129 | 1101 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1102 } |
129 | 1103 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1104 } |
1105 |