diff options
author | Christian Grothoff <christian@grothoff.org> | 2006-10-23 00:32:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2006-10-23 00:32:41 +0000 |
commit | a453403315966056aa40945a81e4c3ed677fc71e (patch) | |
tree | 05252b75fa2c671d165ccc1cdaff3a1e64a10035 /src/plugins/fs/download.c | |
parent | a8c2614e103da41188fcc9e9b225cefe788ec0b5 (diff) | |
download | gnunet-gtk-a453403315966056aa40945a81e4c3ed677fc71e.tar.gz gnunet-gtk-a453403315966056aa40945a81e4c3ed677fc71e.zip |
making gnunet-gtk compile
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r-- | src/plugins/fs/download.c | 144 |
1 files changed, 77 insertions, 67 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index cc287093..2e645738 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -44,6 +44,10 @@ static DownloadList * head; | |||
44 | 44 | ||
45 | static GtkTreeStore * summary; | 45 | static GtkTreeStore * summary; |
46 | 46 | ||
47 | static struct GE_Context * ectx; | ||
48 | |||
49 | static struct GC_Configuration * cfg; | ||
50 | |||
47 | static int addFilesToDirectory | 51 | static int addFilesToDirectory |
48 | (const ECRS_FileInfo * fi, | 52 | (const ECRS_FileInfo * fi, |
49 | const HashCode512 * key, | 53 | const HashCode512 * key, |
@@ -59,7 +63,6 @@ static int addFilesToDirectory | |||
59 | if (isRoot == YES) | 63 | if (isRoot == YES) |
60 | return OK; | 64 | return OK; |
61 | DEBUG_BEGIN(); | 65 | DEBUG_BEGIN(); |
62 | FSUI_trackURI(fi); | ||
63 | pos = head; | 66 | pos = head; |
64 | while (pos != NULL) { | 67 | while (pos != NULL) { |
65 | if (ECRS_equalsUri(uri, | 68 | if (ECRS_equalsUri(uri, |
@@ -112,7 +115,7 @@ typedef struct { | |||
112 | const char * mime; | 115 | const char * mime; |
113 | char * final_download_destination; | 116 | char * final_download_destination; |
114 | unsigned int anon; | 117 | unsigned int anon; |
115 | int ret; | 118 | struct FSUI_SearchList * ret; |
116 | } InitiateDownloadCls; | 119 | } InitiateDownloadCls; |
117 | 120 | ||
118 | static void * startSearch(void * cls) { | 121 | static void * startSearch(void * cls) { |
@@ -120,6 +123,8 @@ static void * startSearch(void * cls) { | |||
120 | 123 | ||
121 | idc->ret = FSUI_startSearch(ctx, | 124 | idc->ret = FSUI_startSearch(ctx, |
122 | idc->anon, | 125 | idc->anon, |
126 | 1000, /* FIXME: max results */ | ||
127 | 99 * cronYEARS, /* fixme: timeout */ | ||
123 | idc->uri); | 128 | idc->uri); |
124 | return NULL; | 129 | return NULL; |
125 | } | 130 | } |
@@ -129,6 +134,7 @@ static void * startDownload(void * cls) { | |||
129 | 134 | ||
130 | FSUI_startDownload(ctx, | 135 | FSUI_startDownload(ctx, |
131 | idc->anon, | 136 | idc->anon, |
137 | NO, /* FIXME: isRecursive */ | ||
132 | idc->uri, | 138 | idc->uri, |
133 | idc->final_download_destination); | 139 | idc->final_download_destination); |
134 | return NULL; | 140 | return NULL; |
@@ -189,8 +195,8 @@ static void initiateDownload(GtkTreeModel * model, | |||
189 | we'll just add it as a new tab for now */ | 195 | we'll just add it as a new tab for now */ |
190 | run_with_save_calls(&startSearch, | 196 | run_with_save_calls(&startSearch, |
191 | &idc); | 197 | &idc); |
192 | if (idc.ret == OK) | 198 | if (idc.ret != NULL) |
193 | openTabForSearch(NULL, | 199 | openTabForSearch(idc.ret, |
194 | idc.uri, | 200 | idc.uri, |
195 | idc.anon, | 201 | idc.anon, |
196 | 0, | 202 | 0, |
@@ -238,11 +244,11 @@ static void initiateDownload(GtkTreeModel * model, | |||
238 | if (*cname == '\0') /* name ended in '/' - likely directory */ | 244 | if (*cname == '\0') /* name ended in '/' - likely directory */ |
239 | cname = oname; | 245 | cname = oname; |
240 | idc.name = cname; | 246 | idc.name = cname; |
241 | 247 | GC_get_configuration_value_filename(cfg, | |
242 | final_download_dir = getFileName("FS", | 248 | "FS", |
243 | "INCOMINGDIR", | 249 | "INCOMINGDIR", |
244 | _("You must specify a directory in the configuration" | 250 | "$HOME/gnunet-downloads/", |
245 | " in section `%s' under `%s'.")); | 251 | &final_download_dir); |
246 | if (strlen(dname) > 0) { | 252 | if (strlen(dname) > 0) { |
247 | char * tmp; | 253 | char * tmp; |
248 | tmp = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | 254 | tmp = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); |
@@ -301,7 +307,8 @@ static void initiateDownload(GtkTreeModel * model, | |||
301 | strcat(idc.final_download_destination, | 307 | strcat(idc.final_download_destination, |
302 | DIR_SEPARATOR_STR); | 308 | DIR_SEPARATOR_STR); |
303 | strcat(idc.final_download_destination, dirPath); | 309 | strcat(idc.final_download_destination, dirPath); |
304 | mkdirp(idc.final_download_destination); | 310 | disk_directory_create(ectx, |
311 | idc.final_download_destination); | ||
305 | strcat(idc.final_download_destination, idc.name); | 312 | strcat(idc.final_download_destination, idc.name); |
306 | if ( (idc.final_download_destination[strlen(idc.final_download_destination) - 1] == '/') || | 313 | if ( (idc.final_download_destination[strlen(idc.final_download_destination) - 1] == '/') || |
307 | (idc.final_download_destination[strlen(idc.final_download_destination) - 1] == '\\') ) | 314 | (idc.final_download_destination[strlen(idc.final_download_destination) - 1] == '\\') ) |
@@ -331,11 +338,11 @@ static void initiateDownload(GtkTreeModel * model, | |||
331 | if (final_download_dir[strlen(final_download_dir)-1] != DIR_SEPARATOR) | 338 | if (final_download_dir[strlen(final_download_dir)-1] != DIR_SEPARATOR) |
332 | strcat(list->finalName, DIR_SEPARATOR_STR); | 339 | strcat(list->finalName, DIR_SEPARATOR_STR); |
333 | strcat(list->finalName, dirPath); | 340 | strcat(list->finalName, dirPath); |
334 | mkdirp(list->finalName); | 341 | disk_directory_create(ectx, list->finalName); |
335 | strcat(list->finalName, idc.name); | 342 | strcat(list->finalName, idc.name); |
336 | head = list; | 343 | head = list; |
337 | size = ECRS_fileSize(idc.uri); | 344 | size = ECRS_fileSize(idc.uri); |
338 | size_h = getHumanSize(size); | 345 | size_h = string_get_fancy_byte_size(size); |
339 | gtk_tree_store_insert(summary, | 346 | gtk_tree_store_insert(summary, |
340 | &iiter, | 347 | &iiter, |
341 | NULL, | 348 | NULL, |
@@ -395,7 +402,7 @@ void on_statusDownloadURIEntry_editing_done(GtkWidget * entry, | |||
395 | urid = STRDUP(uris); | 402 | urid = STRDUP(uris); |
396 | gtk_entry_set_text(GTK_ENTRY(entry), | 403 | gtk_entry_set_text(GTK_ENTRY(entry), |
397 | ECRS_URI_PREFIX); | 404 | ECRS_URI_PREFIX); |
398 | idc.uri = ECRS_stringToUri(urid); | 405 | idc.uri = ECRS_stringToUri(ectx, urid); |
399 | if (idc.uri == NULL) { | 406 | if (idc.uri == NULL) { |
400 | addLogEntry(_("Invalid URI `%s'"), urid); | 407 | addLogEntry(_("Invalid URI `%s'"), urid); |
401 | FREE(urid); | 408 | FREE(urid); |
@@ -412,11 +419,12 @@ void on_statusDownloadURIEntry_editing_done(GtkWidget * entry, | |||
412 | ECRS_freeUri(idc.uri); | 419 | ECRS_freeUri(idc.uri); |
413 | return; | 420 | return; |
414 | } | 421 | } |
415 | final_download_dir = getFileName("FS", | 422 | GC_get_configuration_value_filename(cfg, |
416 | "INCOMINGDIR", | 423 | "FS", |
417 | _("You must specify a directory in the configuration" | 424 | "INCOMINGDIR", |
418 | " in section `%s' under `%s'.")); | 425 | "$HOME/gnunet-downloads/", |
419 | mkdirp(final_download_dir); | 426 | &final_download_dir); |
427 | disk_directory_create(ectx, final_download_dir); | ||
420 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; | 428 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; |
421 | idc.final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | 429 | idc.final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); |
422 | strcpy(idc.final_download_destination, final_download_dir); | 430 | strcpy(idc.final_download_destination, final_download_dir); |
@@ -434,7 +442,7 @@ void on_statusDownloadURIEntry_editing_done(GtkWidget * entry, | |||
434 | list->filename = idc.final_download_destination; | 442 | list->filename = idc.final_download_destination; |
435 | list->finalName = STRDUP(idc.final_download_destination); | 443 | list->finalName = STRDUP(idc.final_download_destination); |
436 | head = list; | 444 | head = list; |
437 | size_h = getHumanSize(ECRS_fileSize(idc.uri)); | 445 | size_h = string_get_fancy_byte_size(ECRS_fileSize(idc.uri)); |
438 | gtk_tree_store_insert(summary, | 446 | gtk_tree_store_insert(summary, |
439 | &iiter, | 447 | &iiter, |
440 | NULL, | 448 | NULL, |
@@ -507,7 +515,8 @@ void displayDownloadUpdate(const struct ECRS_URI * uri, | |||
507 | &iter)); | 515 | &iter)); |
508 | } | 516 | } |
509 | meta = NULL; | 517 | meta = NULL; |
510 | ECRS_listDirectory(data, | 518 | ECRS_listDirectory(ectx, |
519 | data, | ||
511 | size, | 520 | size, |
512 | &meta, | 521 | &meta, |
513 | &addFilesToDirectory, | 522 | &addFilesToDirectory, |
@@ -528,9 +537,10 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
528 | DownloadList * pos; | 537 | DownloadList * pos; |
529 | 538 | ||
530 | DEBUG_BEGIN(); | 539 | DEBUG_BEGIN(); |
531 | LOG(LOG_DEBUG, | 540 | GE_LOG(ectx, |
532 | "Download '%s' complete\n", | 541 | GE_STATUS | GE_USER | GE_BULK, |
533 | filename); | 542 | _("Download '%s' complete.\n"), |
543 | filename); | ||
534 | pos = head; | 544 | pos = head; |
535 | while (pos != NULL) { | 545 | while (pos != NULL) { |
536 | if (ECRS_equalsUri(uri, | 546 | if (ECRS_equalsUri(uri, |
@@ -544,16 +554,20 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
544 | if ( (pos->rr != NULL) && | 554 | if ( (pos->rr != NULL) && |
545 | (gtk_tree_row_reference_valid(pos->rr)) ) { | 555 | (gtk_tree_row_reference_valid(pos->rr)) ) { |
546 | /* update directory view (if applicable!) */ | 556 | /* update directory view (if applicable!) */ |
547 | if (OK == getFileSize(filename, &size)) { | 557 | if (OK == disk_file_size(ectx, |
548 | LOG(LOG_DEBUG, | 558 | filename, |
549 | "Updating directory view of '%s'\n", | 559 | &size, |
550 | filename); | 560 | YES)) { |
561 | GE_LOG(ectx, | ||
562 | GE_DEBUG, | ||
563 | "Updating directory view of '%s'\n", | ||
564 | filename); | ||
551 | 565 | ||
552 | meta = NULL; | 566 | meta = NULL; |
553 | fd = fileopen(filename, O_RDONLY); | 567 | fd = disk_file_open(ectx, |
554 | if (fd == -1) { | 568 | filename, |
555 | LOG_FILE_STRERROR(LOG_ERROR, "open", filename); | 569 | O_RDONLY); |
556 | } else { | 570 | if (fd != -1) { |
557 | data = MMAP(NULL, | 571 | data = MMAP(NULL, |
558 | size, | 572 | size, |
559 | PROT_READ, | 573 | PROT_READ, |
@@ -561,10 +575,14 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
561 | fd, | 575 | fd, |
562 | 0); | 576 | 0); |
563 | if (data == MAP_FAILED) { | 577 | if (data == MAP_FAILED) { |
564 | LOG_FILE_STRERROR(LOG_ERROR, "mmap", filename); | 578 | GE_LOG_STRERROR_FILE(ectx, |
579 | GE_ERROR | GE_ADMIN | GE_BULK, | ||
580 | "mmap", | ||
581 | filename); | ||
565 | } else { | 582 | } else { |
566 | if (data != NULL) { | 583 | if (data != NULL) { |
567 | ECRS_listDirectory(data, | 584 | ECRS_listDirectory(ectx, |
585 | data, | ||
568 | size, | 586 | size, |
569 | &meta, | 587 | &meta, |
570 | &addFilesToDirectory, | 588 | &addFilesToDirectory, |
@@ -622,28 +640,20 @@ static int delDownloadView(void * cls, | |||
622 | } | 640 | } |
623 | 641 | ||
624 | static void * clearCompletedDownloads(void * unused) { | 642 | static void * clearCompletedDownloads(void * unused) { |
625 | FSUI_clearCompletedDownloads(ctx, | 643 | /* FIXME */ |
626 | &delDownloadView, | ||
627 | NULL); | ||
628 | return NULL; | 644 | return NULL; |
629 | } | 645 | } |
630 | 646 | ||
631 | void on_clearCompletedDownloadsButton_clicked(void * unused, | 647 | void on_clearCompletedDownloadsButton_clicked_fs(void * unused, |
632 | GtkWidget * clearButton) { | 648 | GtkWidget * clearButton) { |
633 | run_with_save_calls(&clearCompletedDownloads, | 649 | run_with_save_calls(&clearCompletedDownloads, |
634 | NULL); | 650 | NULL); |
635 | } | 651 | } |
636 | 652 | ||
637 | struct aDC_closure { | ||
638 | struct ECRS_URI * u; | ||
639 | char * fn; | ||
640 | }; | ||
641 | |||
642 | static void * shutdownCode(void * c) { | 653 | static void * shutdownCode(void * c) { |
643 | struct aDC_closure * cls = c; | 654 | struct FSUI_DownloadList * pos = c; |
644 | FSUI_stopDownload(ctx, | 655 | FSUI_stopDownload(ctx, |
645 | cls->u, | 656 | pos); |
646 | cls->fn); | ||
647 | return NULL; | 657 | return NULL; |
648 | } | 658 | } |
649 | 659 | ||
@@ -651,20 +661,21 @@ static void abortDownloadCallback(GtkTreeModel * model, | |||
651 | GtkTreePath * path, | 661 | GtkTreePath * path, |
652 | GtkTreeIter * iter, | 662 | GtkTreeIter * iter, |
653 | GtkTreeStore * tree) { | 663 | GtkTreeStore * tree) { |
654 | struct aDC_closure cls; | 664 | void * c; |
665 | struct ECRS_URI * u; | ||
655 | 666 | ||
656 | GNUNET_ASSERT(model == GTK_TREE_MODEL(summary)); | 667 | GE_ASSERT(ectx, model == GTK_TREE_MODEL(summary)); |
657 | gtk_tree_model_get(model, | 668 | gtk_tree_model_get(model, |
658 | iter, | 669 | iter, |
659 | DOWNLOAD_URI, &cls.u, | 670 | DOWNLOAD_POS, &c, |
660 | DOWNLOAD_FILENAME, &cls.fn, | 671 | DOWNLOAD_URI, &u, |
661 | -1); | 672 | -1); |
662 | run_with_save_calls(&shutdownCode, | 673 | run_with_save_calls(&shutdownCode, |
663 | &cls); | 674 | c); |
664 | gtk_tree_store_remove(summary, | 675 | gtk_tree_store_remove(summary, |
665 | iter); | 676 | iter); |
666 | if (cls.u != NULL) | 677 | if (u != NULL) |
667 | ECRS_freeUri(cls.u); | 678 | ECRS_freeUri(u); |
668 | } | 679 | } |
669 | 680 | ||
670 | void on_abortDownloadButton_clicked(void * unused, | 681 | void on_abortDownloadButton_clicked(void * unused, |
@@ -683,14 +694,14 @@ void on_abortDownloadButton_clicked(void * unused, | |||
683 | DEBUG_END(); | 694 | DEBUG_END(); |
684 | } | 695 | } |
685 | 696 | ||
686 | static int addDownloadView(void * cls, | 697 | int addDownloadView(struct FSUI_DownloadList * pos, |
687 | const struct FSUI_DownloadList * pos, | 698 | struct FSUI_DownloadList * ppos, |
688 | const char * filename, | 699 | const char * filename, |
689 | const struct ECRS_URI * uri, | 700 | const struct ECRS_URI * uri, |
690 | unsigned long long filesize, | 701 | unsigned long long filesize, |
691 | unsigned long long bytesCompleted, | 702 | unsigned long long bytesCompleted, |
692 | int isRecursive, | 703 | int isRecursive, |
693 | unsigned int anonymityLevel) { | 704 | unsigned int anonymityLevel) { |
694 | GtkTreeIter iiter; | 705 | GtkTreeIter iiter; |
695 | int progress; | 706 | int progress; |
696 | char * uriname; | 707 | char * uriname; |
@@ -712,7 +723,7 @@ static int addDownloadView(void * cls, | |||
712 | (sname[-1] != '/') && | 723 | (sname[-1] != '/') && |
713 | (sname[-1] != '\\') ) | 724 | (sname[-1] != '\\') ) |
714 | sname--; | 725 | sname--; |
715 | size_h = getHumanSize(filesize); | 726 | size_h = string_get_fancy_byte_size(filesize); |
716 | gtk_tree_store_set(summary, | 727 | gtk_tree_store_set(summary, |
717 | &iiter, | 728 | &iiter, |
718 | DOWNLOAD_FILENAME, filename, | 729 | DOWNLOAD_FILENAME, filename, |
@@ -731,12 +742,15 @@ static int addDownloadView(void * cls, | |||
731 | } | 742 | } |
732 | 743 | ||
733 | 744 | ||
734 | void fs_download_start() { | 745 | void fs_download_start(struct GE_Context * e, |
746 | struct GC_Configuration * c) { | ||
735 | GtkWidget * downloadList; | 747 | GtkWidget * downloadList; |
736 | GtkCellRenderer * renderer; | 748 | GtkCellRenderer * renderer; |
737 | GtkTreeViewColumn * column; | 749 | GtkTreeViewColumn * column; |
738 | int col; | 750 | int col; |
739 | 751 | ||
752 | ectx = e; | ||
753 | cfg = c; | ||
740 | DEBUG_BEGIN(); | 754 | DEBUG_BEGIN(); |
741 | downloadList = glade_xml_get_widget(getMainXML(), | 755 | downloadList = glade_xml_get_widget(getMainXML(), |
742 | "activeDownloadsList"); | 756 | "activeDownloadsList"); |
@@ -805,10 +819,6 @@ void fs_download_start() { | |||
805 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(downloadList), | 819 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(downloadList), |
806 | col - 1), | 820 | col - 1), |
807 | TRUE); | 821 | TRUE); |
808 | FSUI_listDownloads(ctx, | ||
809 | NULL, | ||
810 | &addDownloadView, | ||
811 | NULL); | ||
812 | DEBUG_END(); | 822 | DEBUG_END(); |
813 | } | 823 | } |
814 | 824 | ||