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