diff options
author | Christian Grothoff <christian@grothoff.org> | 2006-12-02 05:22:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2006-12-02 05:22:45 +0000 |
commit | 31224e4c7a54f1bf2a03de0bcc9da093a601a5ff (patch) | |
tree | 54069d4826234e08056a0c789a8e595a11fb0543 | |
parent | 72f6c1fd08280851feb85aaf4c1066a1ee6eaeb6 (diff) | |
download | gnunet-gtk-31224e4c7a54f1bf2a03de0bcc9da093a601a5ff.tar.gz gnunet-gtk-31224e4c7a54f1bf2a03de0bcc9da093a601a5ff.zip |
mantis #1134
-rw-r--r-- | src/plugins/fs/download.c | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index 9d8d446f..a853eb57 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -56,6 +56,10 @@ addFilesToDirectory(const ECRS_FileInfo * fi, | |||
56 | return SYSERR; | 56 | return SYSERR; |
57 | model = GTK_TREE_MODEL(list->searchList->tree); | 57 | model = GTK_TREE_MODEL(list->searchList->tree); |
58 | path = gtk_tree_row_reference_get_path(list->searchViewRowReference); | 58 | path = gtk_tree_row_reference_get_path(list->searchViewRowReference); |
59 | if (path == NULL) { | ||
60 | GE_BREAK(ectx, 0); | ||
61 | return SYSERR; | ||
62 | } | ||
59 | gtk_tree_model_get_iter(model, | 63 | gtk_tree_model_get_iter(model, |
60 | &iter, | 64 | &iter, |
61 | path); | 65 | path); |
@@ -221,13 +225,18 @@ fs_download_started(struct FSUI_DownloadList * fsui_dl, | |||
221 | /* have parent, must be download from | 225 | /* have parent, must be download from |
222 | directory inside of search */ | 226 | directory inside of search */ |
223 | path = gtk_tree_row_reference_get_path(dl_parent->searchViewRowReference); | 227 | path = gtk_tree_row_reference_get_path(dl_parent->searchViewRowReference); |
224 | valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(sl_parent->tree), | 228 | if (path != NULL) { |
225 | &piter, | 229 | valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(sl_parent->tree), |
226 | path); | 230 | &piter, |
227 | if (valid == TRUE) | 231 | path); |
228 | valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(sl_parent->tree), | 232 | if (valid == TRUE) |
229 | &iter, | 233 | valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(sl_parent->tree), |
230 | &piter); | 234 | &iter, |
235 | &piter); | ||
236 | } else { | ||
237 | GE_BREAK(ectx, 0); | ||
238 | valid = FALSE; | ||
239 | } | ||
231 | } else { | 240 | } else { |
232 | /* must be top-level entry in search */ | 241 | /* must be top-level entry in search */ |
233 | valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sl_parent->tree), | 242 | valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sl_parent->tree), |
@@ -294,6 +303,10 @@ void fs_download_update(DownloadList * list, | |||
294 | struct ECRS_MetaData * meta; | 303 | struct ECRS_MetaData * meta; |
295 | 304 | ||
296 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 305 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); |
306 | if (path == NULL) { | ||
307 | GE_BREAK(ectx, 0); | ||
308 | return; | ||
309 | } | ||
297 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), | 310 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), |
298 | &iter, | 311 | &iter, |
299 | path); | 312 | path); |
@@ -351,14 +364,18 @@ void fs_download_stopped(DownloadList * list) { | |||
351 | DownloadList * prev; | 364 | DownloadList * prev; |
352 | 365 | ||
353 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 366 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); |
354 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), | 367 | if (path == NULL) { |
355 | &iter, | 368 | GE_BREAK(ectx, 0); |
356 | path); | 369 | } else { |
357 | gtk_tree_path_free(path); | 370 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), |
358 | gtk_tree_row_reference_free(list->summaryViewRowReference); | 371 | &iter, |
359 | list->summaryViewRowReference = NULL; | 372 | path); |
360 | gtk_tree_store_remove(download_summary, | 373 | gtk_tree_path_free(path); |
361 | &iter); | 374 | gtk_tree_row_reference_free(list->summaryViewRowReference); |
375 | list->summaryViewRowReference = NULL; | ||
376 | gtk_tree_store_remove(download_summary, | ||
377 | &iter); | ||
378 | } | ||
362 | if (list->searchViewRowReference != NULL) { | 379 | if (list->searchViewRowReference != NULL) { |
363 | gtk_tree_row_reference_free(list->searchViewRowReference); | 380 | gtk_tree_row_reference_free(list->searchViewRowReference); |
364 | list->searchViewRowReference = NULL; | 381 | list->searchViewRowReference = NULL; |
@@ -449,7 +466,6 @@ initiateDownload(GtkTreeModel * model, | |||
449 | SearchList * searchContext; | 466 | SearchList * searchContext; |
450 | DownloadList * parentContext; | 467 | DownloadList * parentContext; |
451 | 468 | ||
452 | DEBUG_BEGIN(); | ||
453 | idc_uri = NULL; | 469 | idc_uri = NULL; |
454 | idc_meta = NULL; | 470 | idc_meta = NULL; |
455 | idc_name = NULL; | 471 | idc_name = NULL; |
@@ -500,10 +516,18 @@ initiateDownload(GtkTreeModel * model, | |||
500 | cname = idc_name; | 516 | cname = idc_name; |
501 | dname = STRDUP(idc_name); | 517 | dname = STRDUP(idc_name); |
502 | cname = &dname[strlen(dname)-1]; | 518 | cname = &dname[strlen(dname)-1]; |
519 | if (cname != dname) | ||
520 | cname--; /* ignore tailing '/' */ | ||
503 | while ( (cname != dname) && | 521 | while ( (cname != dname) && |
504 | (*cname != DIR_SEPARATOR) ) | 522 | (*cname != DIR_SEPARATOR) ) |
505 | cname--; | 523 | cname--; |
506 | *cname = '\0'; | 524 | if (*cname == DIR_SEPARATOR) { |
525 | *cname = '\0'; | ||
526 | FREE(idc_name); | ||
527 | idc_name = STRDUP(cname + 1); | ||
528 | } else { | ||
529 | *cname = '\0'; | ||
530 | } | ||
507 | cname = NULL; | 531 | cname = NULL; |
508 | 532 | ||
509 | GC_get_configuration_value_filename(cfg, | 533 | GC_get_configuration_value_filename(cfg, |
@@ -525,9 +549,6 @@ initiateDownload(GtkTreeModel * model, | |||
525 | } | 549 | } |
526 | FREE(dname); | 550 | FREE(dname); |
527 | dname = NULL; | 551 | dname = NULL; |
528 | disk_directory_create(ectx, final_download_dir); | ||
529 | |||
530 | |||
531 | /* If file is inside a directory, get the full path */ | 552 | /* If file is inside a directory, get the full path */ |
532 | dirTreePath = gtk_tree_path_copy(path); | 553 | dirTreePath = gtk_tree_path_copy(path); |
533 | dirPath = MALLOC(1); | 554 | dirPath = MALLOC(1); |
@@ -535,27 +556,26 @@ initiateDownload(GtkTreeModel * model, | |||
535 | dirPathLen = 0; | 556 | dirPathLen = 0; |
536 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { | 557 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { |
537 | char * dirname; | 558 | char * dirname; |
538 | char * new; | 559 | char * newPath; |
539 | 560 | ||
540 | if (! gtk_tree_path_up(dirTreePath)) | 561 | if (! gtk_tree_path_up(dirTreePath)) |
541 | break; | 562 | break; |
542 | 563 | if (! gtk_tree_model_get_iter(model, | |
543 | if (!gtk_tree_model_get_iter(model, | 564 | &iiter, |
544 | &iiter, | 565 | dirTreePath)) |
545 | dirTreePath)) | ||
546 | break; | 566 | break; |
547 | gtk_tree_model_get(model, | 567 | gtk_tree_model_get(model, |
548 | &iiter, | 568 | &iiter, |
549 | SEARCH_NAME, &dirname, | 569 | SEARCH_NAME, &dirname, |
550 | -1); | 570 | -1); |
551 | dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; | 571 | dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; |
552 | new = MALLOC(dirPathLen + 1); | 572 | newPath = MALLOC(dirPathLen + 1); |
553 | strcpy(new, dirname); | 573 | strcpy(newPath, dirname); |
554 | if (new[strlen(new)-1] != DIR_SEPARATOR) | 574 | if (newPath[strlen(newPath)-1] != DIR_SEPARATOR) |
555 | strcat(new, DIR_SEPARATOR_STR); | 575 | strcat(newPath, DIR_SEPARATOR_STR); |
556 | strcat(new, dirPath); | 576 | strcat(newPath, dirPath); |
557 | FREE(dirPath); | 577 | FREE(dirPath); |
558 | dirPath = new; | 578 | dirPath = newPath; |
559 | free(dirname); | 579 | free(dirname); |
560 | } | 580 | } |
561 | gtk_tree_path_free(dirTreePath); | 581 | gtk_tree_path_free(dirTreePath); |
@@ -571,23 +591,8 @@ initiateDownload(GtkTreeModel * model, | |||
571 | DIR_SEPARATOR_STR); | 591 | DIR_SEPARATOR_STR); |
572 | strcat(idc_final_download_destination, | 592 | strcat(idc_final_download_destination, |
573 | dirPath); | 593 | dirPath); |
574 | disk_directory_create(ectx, | ||
575 | idc_final_download_destination); | ||
576 | strcat(idc_final_download_destination, | 594 | strcat(idc_final_download_destination, |
577 | idc_name); | 595 | idc_name); |
578 | if ( (idc_final_download_destination[strlen(idc_final_download_destination) - 1] == '/') || | ||
579 | (idc_final_download_destination[strlen(idc_final_download_destination) - 1] == '\\') ) | ||
580 | idc_final_download_destination[strlen(idc_final_download_destination) - 1] = '\0'; | ||
581 | /* append ".gnd" if needed (== directory and .gnd not present) */ | ||
582 | if ( (idc_mime != NULL) && | ||
583 | (0 == strcmp(idc_mime, GNUNET_DIRECTORY_MIME)) && | ||
584 | ( (strlen(idc_final_download_destination) < strlen(GNUNET_DIRECTORY_EXT)) || | ||
585 | (0 != strcmp(&idc_final_download_destination[strlen(idc_final_download_destination) | ||
586 | - strlen(GNUNET_DIRECTORY_EXT)], | ||
587 | GNUNET_DIRECTORY_EXT)) ) ) | ||
588 | strcat(idc_final_download_destination, | ||
589 | GNUNET_DIRECTORY_EXT); | ||
590 | |||
591 | /* FIXME: check that there is no pending download for idc_name! */ | 596 | /* FIXME: check that there is no pending download for idc_name! */ |
592 | if (OK == check_pending(idc_name, | 597 | if (OK == check_pending(idc_name, |
593 | NULL)) { | 598 | NULL)) { |