comparison src/ft.c @ 4675:3145c5c45877

[gaim-migrate @ 4986] Okay, redid the cancel stuff. It may not work too well yet, as it's largely untested, and will need some testing and bug reporting. The protocols may not work too well (namely, Oscar), but this will be fixed soon. Note that that's only for canceling. Any receiving that currently works will continue to work. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 08 Mar 2003 08:27:02 +0000
parents e557a10a9541
children ac9ca88d4b25
comparison
equal deleted inserted replaced
4674:7ffe2b64de2d 4675:3145c5c45877
62 62
63 if (xfer == NULL) 63 if (xfer == NULL)
64 return; 64 return;
65 65
66 if (!xfer->completed) { 66 if (!xfer->completed) {
67 gaim_xfer_cancel(xfer); 67 gaim_xfer_cancel_local(xfer);
68 return; 68 return;
69 } 69 }
70 70
71 ui_ops = gaim_xfer_get_ui_ops(xfer); 71 ui_ops = gaim_xfer_get_ui_ops(xfer);
72 72
414 414
415 xfer->ops.end = fnc; 415 xfer->ops.end = fnc;
416 } 416 }
417 417
418 void 418 void
419 gaim_xfer_set_cancel_fnc(struct gaim_xfer *xfer, 419 gaim_xfer_set_cancel_send_fnc(struct gaim_xfer *xfer,
420 void (*fnc)(struct gaim_xfer *)) 420 void (*fnc)(struct gaim_xfer *))
421 { 421 {
422 if (xfer == NULL) 422 if (xfer == NULL)
423 return; 423 return;
424 424
425 xfer->ops.cancel = fnc; 425 xfer->ops.cancel_send = fnc;
426 }
427
428 void
429 gaim_xfer_set_cancel_recv_fnc(struct gaim_xfer *xfer,
430 void (*fnc)(struct gaim_xfer *))
431 {
432 if (xfer == NULL)
433 return;
434
435 xfer->ops.cancel_recv = fnc;
426 } 436 }
427 437
428 size_t 438 size_t
429 gaim_xfer_read(struct gaim_xfer *xfer, char **buffer) 439 gaim_xfer_read(struct gaim_xfer *xfer, char **buffer)
430 { 440 {
535 xfer->dest_fp = fopen(gaim_xfer_get_local_filename(xfer), 545 xfer->dest_fp = fopen(gaim_xfer_get_local_filename(xfer),
536 type == GAIM_XFER_RECEIVE ? "wb" : "rb"); 546 type == GAIM_XFER_RECEIVE ? "wb" : "rb");
537 547
538 /* Just in case, though. */ 548 /* Just in case, though. */
539 if (xfer->dest_fp == NULL) { 549 if (xfer->dest_fp == NULL) {
540 gaim_xfer_cancel(xfer); /* ? */ 550 gaim_xfer_cancel_local(xfer); /* ? */
541 return; 551 return;
542 } 552 }
543 553
544 xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer); 554 xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer);
545 555
607 if (xfer == NULL) 617 if (xfer == NULL)
608 return; 618 return;
609 619
610 /* See if we are actually trying to cancel this. */ 620 /* See if we are actually trying to cancel this. */
611 if (!xfer->completed) { 621 if (!xfer->completed) {
612 gaim_xfer_cancel(xfer); 622 gaim_xfer_cancel_local(xfer);
613 return; 623 return;
614 } 624 }
615 625
616 if (xfer->ops.end != NULL) 626 if (xfer->ops.end != NULL)
617 xfer->ops.end(xfer); 627 xfer->ops.end(xfer);
629 xfer->dest_fp = NULL; 639 xfer->dest_fp = NULL;
630 } 640 }
631 } 641 }
632 642
633 void 643 void
634 gaim_xfer_cancel(struct gaim_xfer *xfer) 644 gaim_xfer_cancel_local(struct gaim_xfer *xfer)
635 { 645 {
636 struct gaim_xfer_ui_ops *ui_ops; 646 struct gaim_xfer_ui_ops *ui_ops;
637 647
638 if (xfer == NULL) 648 if (xfer == NULL)
639 return; 649 return;
640 650
641 if (xfer->ops.cancel != NULL) 651 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND)
642 xfer->ops.cancel(xfer); 652 {
653 if (xfer->ops.cancel_send != NULL)
654 xfer->ops.cancel_send(xfer);
655 }
656 else
657 {
658 if (xfer->ops.cancel_recv != NULL)
659 xfer->ops.cancel_recv(xfer);
660 }
643 661
644 if (xfer->watcher != 0) { 662 if (xfer->watcher != 0) {
645 gaim_input_remove(xfer->watcher); 663 gaim_input_remove(xfer->watcher);
646 xfer->watcher = 0; 664 xfer->watcher = 0;
647 } 665 }
654 xfer->dest_fp = NULL; 672 xfer->dest_fp = NULL;
655 } 673 }
656 674
657 ui_ops = gaim_xfer_get_ui_ops(xfer); 675 ui_ops = gaim_xfer_get_ui_ops(xfer);
658 676
659 if (ui_ops != NULL && ui_ops->cancel != NULL) 677 if (ui_ops != NULL && ui_ops->cancel_local != NULL)
660 ui_ops->cancel(xfer); 678 ui_ops->cancel_local(xfer);
661 679
662 xfer->bytes_remaining = 0; 680 xfer->bytes_remaining = 0;
663 } 681 }
664 682
665 void 683 void
684 gaim_xfer_cancel_remote(struct gaim_xfer *xfer)
685 {
686 struct gaim_xfer_ui_ops *ui_ops;
687
688 if (xfer == NULL)
689 return;
690
691 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND)
692 {
693 if (xfer->ops.cancel_send != NULL)
694 xfer->ops.cancel_send(xfer);
695 }
696 else
697 {
698 if (xfer->ops.cancel_recv != NULL)
699 xfer->ops.cancel_recv(xfer);
700 }
701
702 if (xfer->watcher != 0) {
703 gaim_input_remove(xfer->watcher);
704 xfer->watcher = 0;
705 }
706
707 if (xfer->fd != 0)
708 close(xfer->fd);
709
710 if (xfer->dest_fp != NULL) {
711 fclose(xfer->dest_fp);
712 xfer->dest_fp = NULL;
713 }
714
715 ui_ops = gaim_xfer_get_ui_ops(xfer);
716
717 if (ui_ops != NULL && ui_ops->cancel_remote != NULL)
718 ui_ops->cancel_remote(xfer);
719
720 xfer->bytes_remaining = 0;
721 }
722
723 void
666 gaim_xfer_error(GaimXferType type, const char *who, const char *msg) 724 gaim_xfer_error(GaimXferType type, const char *who, const char *msg)
667 { 725 {
668 char *title; 726 char *title;
669 727
670 if (xfer == NULL || msg == NULL || type == GAIM_XFER_UNKNOWN) 728 if (msg == NULL || type == GAIM_XFER_UNKNOWN)
671 return; 729 return;
672 730
673 if (type == GAIM_XFER_SEND) 731 if (type == GAIM_XFER_SEND)
674 title = g_strdup_printf(_("File transfer to %s aborted.\n"), who); 732 title = g_strdup_printf(_("File transfer to %s aborted.\n"), who);
675 else 733 else