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