comparison src/gtk/transfer.c @ 305:6d180e6a8ba5

2003-11-3 Brian Masney <masneyb@gftp.org> * lib/gftp.h src/gtk/transfer.c src/gtk/delete_dialog.c - removed transfer_direction variable from gftp_transfer structure. Cleaned up the code that did checks based on the value of this variable. * lib/rfc959.c (rfc959_syst) - added a check for Novell FTP servers * src/gtk/transfer.c (add_file_transfer) - check the value of the option one_transfer and if that is disabled, do not append the file transfers. (transfer_done) - refresh the destination window correctly after a transfer is completed.
author masneyb
date Tue, 04 Nov 2003 02:53:17 +0000
parents 3b9d5797050f
children cc2eeb30b793
comparison
equal deleted inserted replaced
304:95bcb77d62c1 305:6d180e6a8ba5
430 return; 430 return;
431 431
432 transfer = g_malloc0 (sizeof (*transfer)); 432 transfer = g_malloc0 (sizeof (*transfer));
433 transfer->fromreq = copy_request (fromwdata->request, 0); 433 transfer->fromreq = copy_request (fromwdata->request, 0);
434 transfer->toreq = copy_request (towdata->request, 0); 434 transfer->toreq = copy_request (towdata->request, 0);
435 transfer->transfer_direction = fromwdata == &window2 ?
436 GFTP_DIRECTION_DOWNLOAD : GFTP_DIRECTION_UPLOAD;
437 transfer->fromwdata = fromwdata; 435 transfer->fromwdata = fromwdata;
438 transfer->towdata = towdata; 436 transfer->towdata = towdata;
439 437
440 num = 0; 438 num = 0;
441 templist = GTK_CLIST (fromwdata->listbox)->selection; 439 templist = GTK_CLIST (fromwdata->listbox)->selection;
547 transfer->fromreq->stopable = 0; 545 transfer->fromreq->stopable = 0;
548 return (GINT_TO_POINTER (success)); 546 return (GINT_TO_POINTER (success));
549 } 547 }
550 548
551 549
550 static void
551 _gftp_setup_fds (gftp_transfer * tdata, gftp_file * curfle,
552 int *fromfd, int *tofd)
553 {
554 *tofd = -1;
555 *fromfd = -1;
556
557 if (curfle->is_fd)
558 {
559 if (tdata->toreq->protonum == GFTP_LOCAL_NUM)
560 *tofd = curfle->fd;
561 else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM)
562 *fromfd = curfle->fd;
563 }
564 }
565
566
567 static void
568 _gftp_done_with_fds (gftp_transfer * tdata, gftp_file * curfle)
569 {
570 if (curfle->is_fd)
571 {
572 if (tdata->toreq->protonum == GFTP_LOCAL_NUM)
573 tdata->toreq->datafd = -1;
574 else
575 tdata->fromreq->datafd = -1;
576 }
577 }
578
579
552 void * 580 void *
553 gftp_gtk_transfer_files (void *data) 581 gftp_gtk_transfer_files (void *data)
554 { 582 {
555 int i, mode, tofd, fromfd, preserve_permissions; 583 int i, mode, tofd, fromfd, preserve_permissions;
556 gftp_transfer * transfer; 584 gftp_transfer * transfer;
604 transfer->curfle = transfer->curfle->next; 632 transfer->curfle = transfer->curfle->next;
605 g_static_mutex_unlock (&transfer->structmutex); 633 g_static_mutex_unlock (&transfer->structmutex);
606 continue; 634 continue;
607 } 635 }
608 636
609 if (curfle->is_fd) 637 _gftp_setup_fds (transfer, curfle, &fromfd, &tofd);
610 {
611 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD)
612 {
613 tofd = curfle->fd;
614 fromfd = -1;
615 }
616 else
617 {
618 tofd = -1;
619 fromfd = curfle->fd;
620 }
621 }
622 else
623 {
624 tofd = -1;
625 fromfd = -1;
626 }
627 638
628 if (curfle->size == 0) 639 if (curfle->size == 0)
629 { 640 {
630 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); 641 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file);
631 transfer->total_bytes += curfle->size; 642 transfer->total_bytes += curfle->size;
651 transfer->fromreq, 662 transfer->fromreq,
652 _("Error: Remote site disconnected after trying to transfer file\n")); 663 _("Error: Remote site disconnected after trying to transfer file\n"));
653 } 664 }
654 else if (fromsize < 0) 665 else if (fromsize < 0)
655 { 666 {
656 if (curfle->is_fd)
657 {
658 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD)
659 transfer->toreq->datafd = -1;
660 else
661 transfer->fromreq->datafd = -1;
662 }
663
664 g_static_mutex_lock (&transfer->structmutex); 667 g_static_mutex_lock (&transfer->structmutex);
665 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; 668 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP;
666 transfer->next_file = 1; 669 transfer->next_file = 1;
667 transfer->curfle = transfer->curfle->next; 670 transfer->curfle = transfer->curfle->next;
668 g_static_mutex_unlock (&transfer->structmutex); 671 g_static_mutex_unlock (&transfer->structmutex);
715 718
716 break; 719 break;
717 } 720 }
718 else 721 else
719 { 722 {
720 if (curfle->is_fd) 723 _gftp_done_with_fds (transfer, curfle);
721 {
722 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD)
723 transfer->toreq->datafd = -1;
724 else
725 transfer->fromreq->datafd = -1;
726 }
727
728 if (gftp_end_transfer (transfer->fromreq) != 0) 724 if (gftp_end_transfer (transfer->fromreq) != 0)
729 { 725 {
730 if (gftp_get_transfer_status (transfer, -1) == GFTP_ERETRYABLE) 726 if (gftp_get_transfer_status (transfer, -1) == GFTP_ERETRYABLE)
731 continue; 727 continue;
732 728
775 gftp_transfer * 771 gftp_transfer *
776 add_file_transfer (gftp_request * fromreq, gftp_request * toreq, 772 add_file_transfer (gftp_request * fromreq, gftp_request * toreq,
777 gftp_window_data * fromwdata, gftp_window_data * towdata, 773 gftp_window_data * fromwdata, gftp_window_data * towdata,
778 GList * files, int copy_req) 774 GList * files, int copy_req)
779 { 775 {
780 int dialog, append_transfers; 776 int dialog, append_transfers, one_transfer;
781 gftp_curtrans_data * transdata; 777 gftp_curtrans_data * transdata;
782 GList * templist, *curfle; 778 GList * templist, *curfle;
783 gftp_transfer * tdata; 779 gftp_transfer * tdata;
784 gftp_file * tempfle; 780 gftp_file * tempfle;
785 char *pos, *text[2]; 781 char *pos, *text[2];
792 } 788 }
793 dialog = templist != NULL; 789 dialog = templist != NULL;
794 790
795 gftp_lookup_request_option (fromreq, "append_transfers", 791 gftp_lookup_request_option (fromreq, "append_transfers",
796 &append_transfers); 792 &append_transfers);
793 gftp_lookup_request_option (fromreq, "one_transfer",
794 &one_transfer);
797 795
798 tdata = NULL; 796 tdata = NULL;
799 if (append_transfers) 797 if (append_transfers && one_transfer)
800 { 798 {
801 pthread_mutex_lock (&transfer_mutex); 799 pthread_mutex_lock (&transfer_mutex);
802 for (templist = gftp_file_transfers; templist != NULL; templist = templist->next) 800 for (templist = gftp_file_transfers; templist != NULL; templist = templist->next)
803 { 801 {
804 tdata = templist->data; 802 tdata = templist->data;
881 else 879 else
882 { 880 {
883 tdata->fromreq = fromreq; 881 tdata->fromreq = fromreq;
884 tdata->toreq = toreq; 882 tdata->toreq = toreq;
885 } 883 }
886 tdata->transfer_direction = fromwdata && fromwdata == &window1 ? 884
887 GFTP_DIRECTION_UPLOAD : GFTP_DIRECTION_DOWNLOAD;
888 tdata->fromwdata = fromwdata; 885 tdata->fromwdata = fromwdata;
889 tdata->towdata = towdata; 886 tdata->towdata = towdata;
890 if (!dialog) 887 if (!dialog)
891 tdata->show = tdata->ready = 1; 888 tdata->show = tdata->ready = 1;
892 tdata->files = files; 889 tdata->files = files;
1228 { 1225 {
1229 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; 1226 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL;
1230 1227
1231 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, 1228 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata,
1232 tdata->fromreq)) 1229 tdata->fromreq))
1233 { 1230 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request,
1234 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, 1231 tdata->fromreq);
1235 tdata->fromreq);
1236 refresh (tdata->fromwdata);
1237 }
1238 else 1232 else
1239 gftp_disconnect (tdata->fromreq); 1233 gftp_disconnect (tdata->fromreq);
1240 1234
1241 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, 1235 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata,
1242 tdata->toreq)) 1236 tdata->toreq))
1243 { 1237 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request,
1244 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, 1238 tdata->toreq);
1245 tdata->toreq);
1246 refresh (tdata->towdata);
1247 }
1248 else 1239 else
1249 gftp_disconnect (tdata->toreq); 1240 gftp_disconnect (tdata->toreq);
1241
1242 if (tdata->towdata != NULL && compare_request (tdata->toreq,
1243 ((gftp_window_data *) tdata->towdata)->request, 1))
1244 refresh (tdata->towdata);
1250 1245
1251 num_transfers_in_progress--; 1246 num_transfers_in_progress--;
1252 } 1247 }
1253 1248
1254 if (!tdata->show && tdata->started) 1249 if (!tdata->show && tdata->started)
1898 1893
1899 void 1894 void
1900 gftp_gtk_ask_transfer (gftp_transfer * tdata) 1895 gftp_gtk_ask_transfer (gftp_transfer * tdata)
1901 { 1896 {
1902 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, 1897 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL },
1903 tempstr[50], temp1str[50], *pos, *title; 1898 tempstr[50], temp1str[50], *pos;
1904 GtkWidget * tempwid, * scroll, * hbox; 1899 GtkWidget * tempwid, * scroll, * hbox;
1905 int i, overwrite_default; 1900 int i, overwrite_default;
1906 gftp_file * tempfle; 1901 gftp_file * tempfle;
1907 GList * templist; 1902 GList * templist;
1908 size_t len; 1903 size_t len;
1909 1904
1910 dltitles[0] = _("Filename"); 1905 dltitles[0] = _("Filename");
1911 dltitles[1] = _("Local Size"); 1906 dltitles[1] = tdata->fromreq->hostname;
1912 dltitles[2] = _("Remote Size"); 1907 dltitles[2] = tdata->toreq->hostname;
1913 dltitles[3] = _("Action"); 1908 dltitles[3] = _("Action");
1914 title = tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD ?
1915 _("Download Files") : _("Upload Files");
1916 1909
1917 #if GTK_MAJOR_VERSION == 1 1910 #if GTK_MAJOR_VERSION == 1
1918 dialog = gtk_dialog_new (); 1911 dialog = gtk_dialog_new ();
1919 gtk_grab_add (dialog); 1912 gtk_grab_add (dialog);
1920 gtk_window_set_title (GTK_WINDOW (dialog), title); 1913 gtk_window_set_title (GTK_WINDOW (dialog), _("Transfer Files"));
1921 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); 1914 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
1922 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); 1915 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35);
1923 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); 1916 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
1924 1917
1925 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", 1918 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event",
1926 GTK_SIGNAL_FUNC (gtk_widget_destroy), 1919 GTK_SIGNAL_FUNC (gtk_widget_destroy),
1927 GTK_OBJECT (dialog)); 1920 GTK_OBJECT (dialog));
1928 #else 1921 #else
1929 dialog = gtk_dialog_new_with_buttons (title, NULL, 0, 1922 dialog = gtk_dialog_new_with_buttons (_("Transfer Files"), NULL, 0,
1930 GTK_STOCK_OK, 1923 GTK_STOCK_OK,
1931 GTK_RESPONSE_OK, 1924 GTK_RESPONSE_OK,
1932 GTK_STOCK_CANCEL, 1925 GTK_STOCK_CANCEL,
1933 GTK_RESPONSE_CANCEL, 1926 GTK_RESPONSE_CANCEL,
1934 NULL); 1927 NULL);
2005 add_data[3] = _("Resume"); 1998 add_data[3] = _("Resume");
2006 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; 1999 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME;
2007 } 2000 }
2008 } 2001 }
2009 2002
2010 if (tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD) 2003 add_data[1] = insert_commas (tempfle->size, tempstr, sizeof (tempstr));
2011 { 2004 add_data[2] = insert_commas (tempfle->startsize, temp1str,
2012 add_data[2] = insert_commas (tempfle->size, tempstr, 2005 sizeof (temp1str));
2013 sizeof (tempstr)); 2006
2014 add_data[1] = insert_commas (tempfle->startsize, temp1str,
2015 sizeof (temp1str));
2016 }
2017 else
2018 {
2019 add_data[1] = insert_commas (tempfle->size, tempstr,
2020 sizeof (tempstr));
2021 add_data[2] = insert_commas (tempfle->startsize, temp1str,
2022 sizeof (temp1str));
2023 }
2024 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); 2007 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data);
2025 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); 2008 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle);
2026 } 2009 }
2027 2010
2028 gtk_clist_select_all (GTK_CLIST (tdata->clist)); 2011 gtk_clist_select_all (GTK_CLIST (tdata->clist));