diff options
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r-- | src/plugins/fs/download.c | 155 |
1 files changed, 85 insertions, 70 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index eab6ed20..1fd31bfb 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -388,7 +388,7 @@ void fs_download_completed(DownloadList * downloadContext) { | |||
388 | * possibly refresh directory listing. | 388 | * possibly refresh directory listing. |
389 | */ | 389 | */ |
390 | void fs_download_aborted(DownloadList * downloadContext) { | 390 | void fs_download_aborted(DownloadList * downloadContext) { |
391 | /* FIXME: update summary? / search list status entry (once added) */ | 391 | /* FIXME: update summary? / search list status entry! */ |
392 | downloadContext->has_terminated = YES; | 392 | downloadContext->has_terminated = YES; |
393 | refreshDirectoryViewFromDisk(downloadContext); | 393 | refreshDirectoryViewFromDisk(downloadContext); |
394 | } | 394 | } |
@@ -479,6 +479,31 @@ check_pending(const char * filename, | |||
479 | return OK; | 479 | return OK; |
480 | } | 480 | } |
481 | 481 | ||
482 | typedef struct { | ||
483 | char * uri_name; | ||
484 | struct ECRS_URI * idc_uri; | ||
485 | struct ECRS_MetaData * idc_meta; | ||
486 | char * idc_final_download_destination; | ||
487 | SearchList * searchContext; | ||
488 | DownloadList * parentContext; | ||
489 | unsigned int anonymity; | ||
490 | int recursive; | ||
491 | } SDC; | ||
492 | |||
493 | static void * init_download_helper(void * cls) { | ||
494 | SDC * sdc = cls; | ||
495 | |||
496 | FSUI_startDownload(ctx, | ||
497 | sdc->anonymity, | ||
498 | sdc->recursive, | ||
499 | sdc->idc_uri, | ||
500 | sdc->idc_meta, | ||
501 | sdc->idc_final_download_destination, | ||
502 | sdc->searchContext->fsui_list, | ||
503 | (sdc->parentContext != NULL) ? sdc->parentContext->fsui_list : NULL); | ||
504 | return NULL; | ||
505 | } | ||
506 | |||
482 | /** | 507 | /** |
483 | * The user clicked the download button. | 508 | * The user clicked the download button. |
484 | * Start the download of the selected entry. | 509 | * Start the download of the selected entry. |
@@ -488,7 +513,7 @@ initiateDownload(GtkTreeModel * model, | |||
488 | GtkTreePath * path, | 513 | GtkTreePath * path, |
489 | GtkTreeIter * iter, | 514 | GtkTreeIter * iter, |
490 | gpointer unused) { | 515 | gpointer unused) { |
491 | char * uri_name; | 516 | SDC sdc; |
492 | char * final_download_dir; | 517 | char * final_download_dir; |
493 | GtkTreeIter iiter; | 518 | GtkTreeIter iiter; |
494 | char * tmp; | 519 | char * tmp; |
@@ -497,43 +522,38 @@ initiateDownload(GtkTreeModel * model, | |||
497 | GtkTreePath *dirTreePath; | 522 | GtkTreePath *dirTreePath; |
498 | char *dirPath; | 523 | char *dirPath; |
499 | unsigned int dirPathLen; | 524 | unsigned int dirPathLen; |
500 | struct ECRS_URI * idc_uri; | ||
501 | struct ECRS_MetaData * idc_meta; | ||
502 | char * idc_name; | 525 | char * idc_name; |
503 | char * idc_mime; | 526 | char * idc_mime; |
504 | char * idc_final_download_destination; | ||
505 | SearchList * searchContext; | ||
506 | DownloadList * parentContext; | ||
507 | 527 | ||
508 | idc_uri = NULL; | 528 | sdc.idc_uri = NULL; |
509 | idc_meta = NULL; | 529 | sdc.idc_meta = NULL; |
510 | idc_name = NULL; | 530 | idc_name = NULL; |
511 | idc_mime = NULL; | 531 | idc_mime = NULL; |
512 | searchContext = NULL; | 532 | sdc.searchContext = NULL; |
513 | parentContext = NULL; | 533 | sdc.parentContext = NULL; |
514 | gtk_tree_model_get(model, | 534 | gtk_tree_model_get(model, |
515 | iter, | 535 | iter, |
516 | SEARCH_NAME, &idc_name, | 536 | SEARCH_NAME, &idc_name, |
517 | SEARCH_URI, &idc_uri, | 537 | SEARCH_URI, &sdc.idc_uri, |
518 | SEARCH_META, &idc_meta, | 538 | SEARCH_META, &sdc.idc_meta, |
519 | SEARCH_MIME, &idc_mime, | 539 | SEARCH_MIME, &idc_mime, |
520 | SEARCH_INTERNAL, &searchContext, | 540 | SEARCH_INTERNAL, &sdc.searchContext, |
521 | SEARCH_INTERNAL_PARENT, &parentContext, | 541 | SEARCH_INTERNAL_PARENT, &sdc.parentContext, |
522 | -1); | 542 | -1); |
523 | if ( (idc_uri == NULL) || | 543 | if ( (sdc.idc_uri == NULL) || |
524 | (! ECRS_isFileUri(idc_uri)) ) { | 544 | (! ECRS_isFileUri(sdc.idc_uri)) ) { |
525 | GE_BREAK(ectx, 0); | 545 | GE_BREAK(ectx, 0); |
526 | FREENONNULL(idc_name); | 546 | FREENONNULL(idc_name); |
527 | FREENONNULL(idc_mime); | 547 | FREENONNULL(idc_mime); |
528 | return; | 548 | return; |
529 | } | 549 | } |
530 | uri_name = ECRS_uriToString(idc_uri); | 550 | sdc.uri_name = ECRS_uriToString(sdc.idc_uri); |
531 | if ( (uri_name == NULL) || | 551 | if ( (sdc.uri_name == NULL) || |
532 | (strlen(uri_name) < | 552 | (strlen(sdc.uri_name) < |
533 | strlen(ECRS_URI_PREFIX) + | 553 | strlen(ECRS_URI_PREFIX) + |
534 | strlen(ECRS_FILE_INFIX)) ) { | 554 | strlen(ECRS_FILE_INFIX)) ) { |
535 | GE_BREAK(ectx, 0); | 555 | GE_BREAK(ectx, 0); |
536 | FREENONNULL(uri_name); | 556 | FREENONNULL(sdc.uri_name); |
537 | FREENONNULL(idc_name); | 557 | FREENONNULL(idc_name); |
538 | FREENONNULL(idc_mime); | 558 | FREENONNULL(idc_mime); |
539 | return; | 559 | return; |
@@ -542,12 +562,12 @@ initiateDownload(GtkTreeModel * model, | |||
542 | #ifdef WINDOWS | 562 | #ifdef WINDOWS |
543 | char * filehash; | 563 | char * filehash; |
544 | 564 | ||
545 | filehash = STRDUP(uri_name); | 565 | filehash = STRDUP(sdc.uri_name); |
546 | filehash[16] = 0; | 566 | filehash[16] = 0; |
547 | idc_name = STRDUP(filehash); | 567 | idc_name = STRDUP(filehash); |
548 | FREENONNULL(filehash); | 568 | FREENONNULL(filehash); |
549 | #else | 569 | #else |
550 | idc_name = STRDUP(uri_name); | 570 | idc_name = STRDUP(sdc.uri_name); |
551 | #endif | 571 | #endif |
552 | } | 572 | } |
553 | 573 | ||
@@ -620,41 +640,35 @@ initiateDownload(GtkTreeModel * model, | |||
620 | gtk_tree_path_free(dirTreePath); | 640 | gtk_tree_path_free(dirTreePath); |
621 | 641 | ||
622 | /* construct completed/directory/real-filename */ | 642 | /* construct completed/directory/real-filename */ |
623 | idc_final_download_destination = MALLOC(strlen(final_download_dir) + 2 + | 643 | sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + 2 + |
624 | strlen(idc_name) + strlen(GNUNET_DIRECTORY_EXT) + | 644 | strlen(idc_name) + strlen(GNUNET_DIRECTORY_EXT) + |
625 | strlen(dirPath)); | 645 | strlen(dirPath)); |
626 | strcpy(idc_final_download_destination, | 646 | strcpy(sdc.idc_final_download_destination, |
627 | final_download_dir); | 647 | final_download_dir); |
628 | if (idc_final_download_destination[strlen(idc_final_download_destination)-1] != DIR_SEPARATOR) | 648 | if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)-1] != DIR_SEPARATOR) |
629 | strcat(idc_final_download_destination, | 649 | strcat(sdc.idc_final_download_destination, |
630 | DIR_SEPARATOR_STR); | 650 | DIR_SEPARATOR_STR); |
631 | strcat(idc_final_download_destination, | 651 | strcat(sdc.idc_final_download_destination, |
632 | dirPath); | 652 | dirPath); |
633 | strcat(idc_final_download_destination, | 653 | strcat(sdc.idc_final_download_destination, |
634 | idc_name); | 654 | idc_name); |
635 | /* FIXME: check that there is no pending download for idc_name! */ | 655 | sdc.anonymity = getSpinButtonValue(sdc.searchContext->searchXML, |
656 | "downloadAnonymitySpinButton"); | ||
657 | sdc.recursive = getToggleButtonValue(sdc.searchContext->searchXML, | ||
658 | "downloadRecursiveCheckButton"); | ||
636 | if (OK == check_pending(idc_name, | 659 | if (OK == check_pending(idc_name, |
637 | NULL)) { | 660 | NULL)) { |
638 | addLogEntry(_("Downloading `%s'"), | 661 | addLogEntry(_("Downloading `%s'"), |
639 | idc_name); | 662 | idc_name); |
640 | /* FIXME! DEADLOCK! */ | 663 | run_with_save_calls(&init_download_helper, |
641 | FSUI_startDownload(ctx, | 664 | &sdc); |
642 | getSpinButtonValue(searchContext->searchXML, | ||
643 | "downloadAnonymitySpinButton"), | ||
644 | getToggleButtonValue(searchContext->searchXML, | ||
645 | "downloadRecursiveCheckButton"), | ||
646 | idc_uri, | ||
647 | idc_meta, | ||
648 | idc_final_download_destination, | ||
649 | searchContext->fsui_list, | ||
650 | (parentContext != NULL) ? parentContext->fsui_list : NULL); | ||
651 | } else { | 665 | } else { |
652 | addLogEntry(_("ERROR: already downloading `%s'"), | 666 | addLogEntry(_("ERROR: already downloading `%s'"), |
653 | idc_name); | 667 | idc_name); |
654 | } | 668 | } |
655 | FREE(uri_name); | 669 | FREE(sdc.uri_name); |
656 | FREE(dirPath); | 670 | FREE(dirPath); |
657 | FREE(idc_final_download_destination); | 671 | FREE(sdc.idc_final_download_destination); |
658 | FREENONNULL(final_download_dir); | 672 | FREENONNULL(final_download_dir); |
659 | FREENONNULL(idc_name); | 673 | FREENONNULL(idc_name); |
660 | FREENONNULL(idc_mime); | 674 | FREENONNULL(idc_mime); |
@@ -683,36 +697,35 @@ void on_downloadButton_clicked_fs(GtkWidget * treeview, | |||
683 | * TODO: | 697 | * TODO: |
684 | * - support for recursive downloads | 698 | * - support for recursive downloads |
685 | * - support for user-specified filename | 699 | * - support for user-specified filename |
700 | * - enable button only if valid URI is entered | ||
686 | */ | 701 | */ |
687 | void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, | 702 | void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, |
688 | GtkWidget * downloadButton) { | 703 | GtkWidget * downloadButton) { |
689 | struct ECRS_URI * idc_uri; | ||
690 | struct ECRS_MetaData * idc_meta; | ||
691 | char * idc_final_download_destination; | ||
692 | const char * uris; | 704 | const char * uris; |
693 | char * urid; | 705 | char * urid; |
694 | char * final_download_dir; | 706 | char * final_download_dir; |
695 | const char * dname; | 707 | const char * dname; |
708 | SDC sdc; | ||
696 | 709 | ||
697 | uris = gtk_entry_get_text(GTK_ENTRY(entry)); | 710 | uris = gtk_entry_get_text(GTK_ENTRY(entry)); |
698 | urid = STRDUP(uris); | 711 | urid = STRDUP(uris); |
699 | gtk_entry_set_text(GTK_ENTRY(entry), | 712 | gtk_entry_set_text(GTK_ENTRY(entry), |
700 | ECRS_URI_PREFIX); | 713 | ECRS_URI_PREFIX); |
701 | idc_uri = ECRS_stringToUri(ectx, urid); | 714 | sdc.idc_uri = ECRS_stringToUri(ectx, urid); |
702 | if (idc_uri == NULL) { | 715 | if (sdc.idc_uri == NULL) { |
703 | addLogEntry(_("Invalid URI `%s'"), urid); | 716 | addLogEntry(_("Invalid URI `%s'"), urid); |
704 | FREE(urid); | 717 | FREE(urid); |
705 | return; | 718 | return; |
706 | } | 719 | } |
707 | if (ECRS_isKeywordUri(idc_uri)) { | 720 | if (ECRS_isKeywordUri(sdc.idc_uri)) { |
708 | addLogEntry(_("Please use the search function for keyword (KSK) URIs!")); | 721 | addLogEntry(_("Please use the search function for keyword (KSK) URIs!")); |
709 | FREE(urid); | 722 | FREE(urid); |
710 | ECRS_freeUri(idc_uri); | 723 | ECRS_freeUri(sdc.idc_uri); |
711 | return; | 724 | return; |
712 | } else if (ECRS_isLocationUri(idc_uri)) { | 725 | } else if (ECRS_isLocationUri(sdc.idc_uri)) { |
713 | addLogEntry(_("Location URIs are not yet supported")); | 726 | addLogEntry(_("Location URIs are not yet supported")); |
714 | FREE(urid); | 727 | FREE(urid); |
715 | ECRS_freeUri(idc_uri); | 728 | ECRS_freeUri(sdc.idc_uri); |
716 | return; | 729 | return; |
717 | } | 730 | } |
718 | GC_get_configuration_value_filename(cfg, | 731 | GC_get_configuration_value_filename(cfg, |
@@ -722,26 +735,28 @@ void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, | |||
722 | &final_download_dir); | 735 | &final_download_dir); |
723 | disk_directory_create(ectx, final_download_dir); | 736 | disk_directory_create(ectx, final_download_dir); |
724 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; | 737 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; |
725 | idc_final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | 738 | sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); |
726 | strcpy(idc_final_download_destination, final_download_dir); | 739 | strcpy(sdc.idc_final_download_destination, |
740 | final_download_dir); | ||
727 | FREE(final_download_dir); | 741 | FREE(final_download_dir); |
728 | if (idc_final_download_destination[strlen(idc_final_download_destination)] != DIR_SEPARATOR) | 742 | if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)] != DIR_SEPARATOR) |
729 | strcat(idc_final_download_destination, DIR_SEPARATOR_STR); | 743 | strcat(sdc.idc_final_download_destination, |
730 | strcat(idc_final_download_destination, dname); | 744 | DIR_SEPARATOR_STR); |
745 | strcat(sdc.idc_final_download_destination, | ||
746 | dname); | ||
731 | 747 | ||
732 | addLogEntry(_("Downloading `%s'"), | 748 | addLogEntry(_("Downloading `%s'"), |
733 | uris); | 749 | uris); |
734 | idc_meta = ECRS_createMetaData(); | 750 | sdc.idc_meta = ECRS_createMetaData(); |
735 | FSUI_startDownload(ctx, | 751 | sdc.anonymity = getSpinButtonValue(getMainXML(), |
736 | getSpinButtonValue(getMainXML(), | 752 | "fsstatusAnonymitySpin"); |
737 | "fsstatusAnonymitySpin"), | 753 | sdc.recursive = NO; |
738 | NO, /* FIXME: isRecursive */ | 754 | sdc.searchContext = NULL; |
739 | idc_uri, | 755 | sdc.parentContext = NULL; |
740 | idc_meta, | 756 | run_with_save_calls(&init_download_helper, |
741 | idc_final_download_destination, | 757 | &sdc); |
742 | NULL, | 758 | ECRS_freeMetaData(sdc.idc_meta); |
743 | NULL); | 759 | FREE(sdc.idc_final_download_destination); |
744 | ECRS_freeMetaData(idc_meta); | ||
745 | FREE(urid); | 760 | FREE(urid); |
746 | } | 761 | } |
747 | 762 | ||