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