Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 559:b497d05cb591
2004-9-22 Brian Masney <masneyb@gftp.org>
* src/gtk/transfer.c (check_done_process) - if the process returned an
error code, then remove the file and don't prompt the user to upload the
file if it was changed
author | masneyb |
---|---|
date | Wed, 22 Sep 2004 23:38:53 +0000 |
parents | 017b1108305b |
children | 89216879202f |
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 | |
724 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
725 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 726 pcent, hours, mins, secs, tdata->current_file_number, |
727 tdata->numdirs + tdata->numfiles); | |
728 | |
729 *dlstr = '\0'; | |
730 if (!tdata->stalled) | |
731 { | |
732 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
733 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
734 st = 1; | |
735 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
736 { | |
737 if (tdata->curfle->next != NULL) | |
738 { | |
220 | 739 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 740 |
741 lkbs = (unsigned long) tdata->kbs; | |
742 if (lkbs > 0) | |
743 remaining_secs /= lkbs; | |
220 | 744 |
745 hours = remaining_secs / 3600; | |
746 remaining_secs -= hours * 3600; | |
747 mins = remaining_secs / 60; | |
748 remaining_secs -= mins * 60; | |
749 secs = remaining_secs; | |
1 | 750 } |
751 | |
752 if (!(hours < 0 || mins < 0 || secs < 0)) | |
753 { | |
754 g_snprintf (dlstr, sizeof (dlstr), | |
755 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
756 st = 0; | |
757 } | |
758 } | |
759 | |
760 if (st) | |
761 { | |
762 tdata->stalled = 1; | |
763 g_snprintf (dlstr, sizeof (dlstr), | |
764 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
765 gotstr, ofstr); | |
766 } | |
767 } | |
768 | |
129 | 769 g_static_mutex_unlock (&tdata->statmutex); |
1 | 770 |
129 | 771 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 772 |
773 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
774 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
775 { | |
776 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
777 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
778 winstr); | |
779 } | |
1 | 780 |
781 if (*dlstr != '\0') | |
129 | 782 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 783 } |
784 | |
377 | 785 |
56 | 786 static void |
787 update_window_transfer_bytes (gftp_window_data * wdata) | |
788 { | |
789 char *tempstr, *temp1str; | |
790 | |
791 if (wdata->request->gotbytes == -1) | |
792 { | |
793 update_window_info (); | |
794 wdata->request->gotbytes = 0; | |
795 } | |
796 else | |
797 { | |
798 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
799 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
800 tempstr); | |
801 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
802 g_free (tempstr); | |
803 g_free (temp1str); | |
804 } | |
805 } | |
806 | |
1 | 807 |
48 | 808 gint |
809 update_downloads (gpointer data) | |
810 { | |
433 | 811 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 812 GList * templist, * next; |
813 gftp_transfer * tdata; | |
814 | |
129 | 815 if (gftp_file_transfer_logs != NULL) |
48 | 816 display_cached_logs (); |
817 | |
56 | 818 if (window1.request->gotbytes != 0) |
819 update_window_transfer_bytes (&window1); | |
48 | 820 if (window2.request->gotbytes != 0) |
56 | 821 update_window_transfer_bytes (&window2); |
48 | 822 |
470 | 823 if (gftpui_common_child_process_done) |
48 | 824 check_done_process (); |
825 | |
129 | 826 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 827 { |
828 tdata = templist->data; | |
829 if (tdata->ready) | |
830 { | |
129 | 831 g_static_mutex_lock (&tdata->structmutex); |
48 | 832 |
833 if (tdata->next_file) | |
834 on_next_transfer (tdata); | |
835 else if (tdata->show) | |
836 show_transfer (tdata); | |
837 else if (tdata->done) | |
838 { | |
839 next = templist->next; | |
129 | 840 g_static_mutex_unlock (&tdata->structmutex); |
48 | 841 transfer_done (templist); |
842 templist = next; | |
843 continue; | |
844 } | |
845 | |
846 if (tdata->curfle != NULL) | |
847 { | |
151 | 848 gftp_lookup_global_option ("one_transfer", |
129 | 849 &do_one_transfer_at_a_time); |
433 | 850 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 851 |
433 | 852 if (!tdata->started && start_transfers && |
129 | 853 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 854 create_transfer (tdata); |
855 | |
856 if (tdata->started) | |
857 update_file_status (tdata); | |
858 } | |
129 | 859 g_static_mutex_unlock (&tdata->structmutex); |
48 | 860 } |
861 templist = templist->next; | |
862 } | |
863 | |
864 gtk_timeout_add (500, update_downloads, NULL); | |
865 return (0); | |
866 } | |
867 | |
868 | |
1 | 869 void |
870 start_transfer (gpointer data) | |
871 { | |
367 | 872 gftpui_common_curtrans_data * transdata; |
1 | 873 GtkCTreeNode * node; |
874 | |
875 if (GTK_CLIST (dlwdw)->selection == NULL) | |
876 { | |
877 ftp_log (gftp_logging_misc, NULL, | |
878 _("There are no file transfers selected\n")); | |
879 return; | |
880 } | |
881 node = GTK_CLIST (dlwdw)->selection->data; | |
882 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
883 | |
129 | 884 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 885 if (!transdata->transfer->started) |
886 create_transfer (transdata->transfer); | |
129 | 887 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 888 } |
889 | |
890 | |
891 void | |
892 stop_transfer (gpointer data) | |
893 { | |
367 | 894 gftpui_common_curtrans_data * transdata; |
1 | 895 GtkCTreeNode * node; |
896 | |
897 if (GTK_CLIST (dlwdw)->selection == NULL) | |
898 { | |
899 ftp_log (gftp_logging_misc, NULL, | |
900 _("There are no file transfers selected\n")); | |
901 return; | |
902 } | |
903 node = GTK_CLIST (dlwdw)->selection->data; | |
904 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
905 | |
129 | 906 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 907 if (transdata->transfer->started) |
908 { | |
909 transdata->transfer->cancel = 1; | |
42 | 910 transdata->transfer->fromreq->cancel = 1; |
911 transdata->transfer->toreq->cancel = 1; | |
1 | 912 transdata->transfer->skip_file = 0; |
913 } | |
914 else | |
915 transdata->transfer->done = 1; | |
129 | 916 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 917 |
1 | 918 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
919 transdata->transfer->fromreq->hostname); | |
920 } | |
921 | |
922 | |
923 void | |
924 skip_transfer (gpointer data) | |
925 { | |
367 | 926 gftpui_common_curtrans_data * transdata; |
1 | 927 GtkCTreeNode * node; |
928 gftp_file * curfle; | |
40 | 929 char *file; |
1 | 930 |
931 if (GTK_CLIST (dlwdw)->selection == NULL) | |
932 { | |
933 ftp_log (gftp_logging_misc, NULL, | |
934 _("There are no file transfers selected\n")); | |
935 return; | |
936 } | |
937 node = GTK_CLIST (dlwdw)->selection->data; | |
938 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
939 | |
129 | 940 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 941 if (transdata->transfer->curfle != NULL) |
942 { | |
943 curfle = transdata->transfer->curfle->data; | |
944 if (transdata->transfer->started) | |
945 { | |
946 transdata->transfer->cancel = 1; | |
42 | 947 transdata->transfer->fromreq->cancel = 1; |
948 transdata->transfer->toreq->cancel = 1; | |
1 | 949 transdata->transfer->skip_file = 1; |
950 } | |
951 | |
952 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 953 file = curfle->file; |
1 | 954 } |
40 | 955 else |
956 file = NULL; | |
129 | 957 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 958 |
959 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
960 file, transdata->transfer->fromreq->hostname); | |
1 | 961 } |
962 | |
963 | |
964 void | |
965 remove_file_transfer (gpointer data) | |
966 { | |
367 | 967 gftpui_common_curtrans_data * transdata; |
1 | 968 GtkCTreeNode * node; |
969 gftp_file * curfle; | |
970 | |
971 if (GTK_CLIST (dlwdw)->selection == NULL) | |
972 { | |
973 ftp_log (gftp_logging_misc, NULL, | |
974 _("There are no file transfers selected\n")); | |
975 return; | |
976 } | |
977 | |
978 node = GTK_CLIST (dlwdw)->selection->data; | |
979 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
980 | |
981 | |
982 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
983 return; | |
984 | |
985 curfle = transdata->curfle->data; | |
986 | |
987 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
988 return; | |
989 | |
129 | 990 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 991 |
992 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
993 | |
994 if (transdata->transfer->started && | |
995 transdata->curfle == transdata->transfer->curfle) | |
996 { | |
997 transdata->transfer->cancel = 1; | |
42 | 998 transdata->transfer->fromreq->cancel = 1; |
999 transdata->transfer->toreq->cancel = 1; | |
1 | 1000 transdata->transfer->skip_file = 1; |
1001 } | |
1002 else if (transdata->curfle != transdata->transfer->curfle && | |
1003 !curfle->transfer_done) | |
1004 { | |
129 | 1005 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 1006 _("Skipped")); |
1007 transdata->transfer->total_bytes -= curfle->size; | |
1008 } | |
1009 | |
129 | 1010 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 1011 |
1 | 1012 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
1013 curfle->file, transdata->transfer->fromreq->hostname); | |
1014 } | |
1015 | |
1016 | |
1017 void | |
1018 move_transfer_up (gpointer data) | |
1019 { | |
1020 GList * firstentry, * secentry, * lastentry; | |
367 | 1021 gftpui_common_curtrans_data * transdata; |
1 | 1022 GtkCTreeNode * node; |
1023 | |
1024 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1025 { | |
1026 ftp_log (gftp_logging_misc, NULL, | |
1027 _("There are no file transfers selected\n")); | |
1028 return; | |
1029 } | |
1030 node = GTK_CLIST (dlwdw)->selection->data; | |
1031 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1032 | |
1033 if (transdata->curfle == NULL) | |
1034 return; | |
1035 | |
129 | 1036 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1037 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1038 (transdata->transfer->curfle != transdata->curfle && | |
1039 transdata->transfer->curfle != transdata->curfle->prev))) | |
1040 { | |
1041 if (transdata->curfle->prev->prev == NULL) | |
1042 { | |
1043 firstentry = transdata->curfle->prev; | |
1044 lastentry = transdata->curfle->next; | |
1045 transdata->transfer->files = transdata->curfle; | |
1046 transdata->curfle->next = firstentry; | |
1047 transdata->transfer->files->prev = NULL; | |
1048 firstentry->prev = transdata->curfle; | |
1049 firstentry->next = lastentry; | |
1050 if (lastentry != NULL) | |
1051 lastentry->prev = firstentry; | |
1052 } | |
1053 else | |
1054 { | |
1055 firstentry = transdata->curfle->prev->prev; | |
1056 secentry = transdata->curfle->prev; | |
1057 lastentry = transdata->curfle->next; | |
1058 firstentry->next = transdata->curfle; | |
1059 transdata->curfle->prev = firstentry; | |
1060 transdata->curfle->next = secentry; | |
1061 secentry->prev = transdata->curfle; | |
1062 secentry->next = lastentry; | |
1063 if (lastentry != NULL) | |
1064 lastentry->prev = secentry; | |
1065 } | |
1066 | |
1067 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1068 ((gftp_file *) transdata->curfle->data)->user_data, |
1069 transdata->transfer->user_data, | |
1 | 1070 transdata->curfle->next != NULL ? |
129 | 1071 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1072 } |
129 | 1073 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1074 } |
1075 | |
367 | 1076 |
1 | 1077 void |
1078 move_transfer_down (gpointer data) | |
1079 { | |
1080 GList * firstentry, * secentry, * lastentry; | |
367 | 1081 gftpui_common_curtrans_data * transdata; |
1 | 1082 GtkCTreeNode * node; |
1083 | |
1084 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1085 { | |
1086 ftp_log (gftp_logging_misc, NULL, | |
1087 _("There are no file transfers selected\n")); | |
1088 return; | |
1089 } | |
1090 node = GTK_CLIST (dlwdw)->selection->data; | |
1091 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1092 | |
1093 if (transdata->curfle == NULL) | |
1094 return; | |
1095 | |
129 | 1096 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1097 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1098 (transdata->transfer->curfle != transdata->curfle && | |
1099 transdata->transfer->curfle != transdata->curfle->next))) | |
1100 { | |
1101 if (transdata->curfle->prev == NULL) | |
1102 { | |
1103 firstentry = transdata->curfle->next; | |
1104 lastentry = transdata->curfle->next->next; | |
1105 transdata->transfer->files = firstentry; | |
1106 transdata->transfer->files->prev = NULL; | |
1107 transdata->transfer->files->next = transdata->curfle; | |
1108 transdata->curfle->prev = transdata->transfer->files; | |
1109 transdata->curfle->next = lastentry; | |
1110 if (lastentry != NULL) | |
1111 lastentry->prev = transdata->curfle; | |
1112 } | |
1113 else | |
1114 { | |
1115 firstentry = transdata->curfle->prev; | |
1116 secentry = transdata->curfle->next; | |
1117 lastentry = transdata->curfle->next->next; | |
1118 firstentry->next = secentry; | |
1119 secentry->prev = firstentry; | |
1120 secentry->next = transdata->curfle; | |
1121 transdata->curfle->prev = secentry; | |
1122 transdata->curfle->next = lastentry; | |
1123 if (lastentry != NULL) | |
1124 lastentry->prev = transdata->curfle; | |
1125 } | |
1126 | |
1127 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1128 ((gftp_file *) transdata->curfle->data)->user_data, |
1129 transdata->transfer->user_data, | |
1 | 1130 transdata->curfle->next != NULL ? |
129 | 1131 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1132 } |
129 | 1133 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1134 } |
1135 |