From 425b352bcbba53bded68c10d1f07c12c7f8e68c5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 4 Feb 2012 22:27:13 +0000 Subject: -partial fix for #2080 --- src/fs/gnunet-fs-gtk_event-handler.c | 155 +++++++++++++++++++++++------------ 1 file changed, 104 insertions(+), 51 deletions(-) diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index 61373011..ced65438 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c @@ -1649,7 +1649,6 @@ add_directory_entry (void *cls, const char *filename, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding directory entry `%s'\n", filename); - if (NULL == uri) { /* directory meta data itself */ @@ -1690,6 +1689,7 @@ add_directory_entry (void *cls, const char *filename, * the contents. * * @param de download entry that is progressing + * @param filename name of the downloaded file on disk (possibly a temporary file) * @param size overall size of the download * @param completed number of bytes we have completed * @param block_data current block we've downloaded @@ -1698,7 +1698,9 @@ add_directory_entry (void *cls, const char *filename, * @param depth depth of the block in the ECRS tree */ static void -mark_download_progress (struct DownloadEntry *de, uint64_t size, +mark_download_progress (struct DownloadEntry *de, + const char *filename, + uint64_t size, uint64_t completed, const void *block_data, uint64_t offset, uint64_t block_size, unsigned int depth) @@ -1731,24 +1733,46 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size, size) : 100) /* availability == progress */, 14, completed, -1); - if ( (depth == 0) && - (block_size > 0) && - (GNUNET_YES == de->is_directory) ) - { - /* got a data block of a directory, list its contents */ - struct AddDirectoryEntryContext ade; - - ade.tab = de->sr->tab; - ade.prr = de->sr->rr; - ade.check_duplicates = GNUNET_NO; - if (GNUNET_SYSERR == - GNUNET_FS_directory_list_contents ((size_t) block_size, block_data, - offset, &add_directory_entry, &ade)) + if (completed < size) + { + /* partial completion, consider looking at the block */ + if ( (depth == 0) && + (block_size > 0) && + (GNUNET_YES == de->is_directory) ) { - /* Mime type was wrong, this is not a directory, update model! */ - de->is_directory = GNUNET_SYSERR; - gtk_tree_store_set (de->sr->tab->ts, &iter, - 10, "" /* unknown mime type */, -1); + /* got a data block of a directory, list its contents */ + struct AddDirectoryEntryContext ade; + + ade.tab = de->sr->tab; + ade.prr = de->sr->rr; + ade.check_duplicates = GNUNET_NO; + if (GNUNET_SYSERR == + GNUNET_FS_directory_list_contents ((size_t) block_size, block_data, + offset, &add_directory_entry, &ade)) + { + /* Mime type was wrong, this is not a directory, update model! */ + de->is_directory = GNUNET_SYSERR; + gtk_tree_store_set (de->sr->tab->ts, &iter, + 10, "" /* unknown mime type */, -1); + } + } + } + else + { + /* full completion, look at the entire file */ + if ( (GNUNET_NO != de->is_directory) && + (filename != NULL) ) + { + struct AddDirectoryEntryContext ade; + + /* download was for a directory (and we have a temp file for scanning); + add contents of the directory to the view */ + ade.tab = de->sr->tab; + ade.prr = de->sr->rr; + ade.check_duplicates = GNUNET_YES; + if (GNUNET_OK != + GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade)) + de->is_directory = GNUNET_NO; } } } @@ -1784,37 +1808,15 @@ mark_download_error (struct DownloadEntry *de, /** * FS-API notified us that we're done with a download. Update the - * view accordingly. If the download is a directory, try to display - * the contents. + * view accordingly. * * @param de download that has finished * @param size overall size of the file - * @param filename name of the downloaded file on disk (possibly a temporary file) */ static void -mark_download_completed (struct DownloadEntry *de, uint64_t size, - const char *filename) +mark_download_completed (struct DownloadEntry *de, uint64_t size) { - struct AddDirectoryEntryContext ade; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Marking download completed for DE=%p, %llu-byte `%s'\n", - de, size, filename); - de->is_done = GNUNET_YES; - mark_download_progress (de, size, size, NULL, 0, 0, 0); - if ( (GNUNET_NO != de->is_directory) && - (filename != NULL) ) - { - /* download was for a directory (and we have a temp file for scanning); - add contents of the directory to the view */ - ade.tab = de->sr->tab; - ade.prr = de->sr->rr; - ade.check_duplicates = GNUNET_YES; - if (GNUNET_OK != - GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade)) - de->is_directory = GNUNET_NO; - } change_download_color (de, "green"); } @@ -1924,7 +1926,7 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter, copy_children (src_model, &src_child, dst_tab, &dst_child); } - while (TRUE == gtk_tree_model_iter_next (src_model, &src_child)); + while (gtk_tree_model_iter_next (src_model, &src_child)); } @@ -2073,6 +2075,40 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, GNUNET_assert (sr == de->sr); } } + if ( (NULL == de->sr) && + (NULL != pde) ) + { + /* child download, find appropriate search result from parent! */ + GtkTreePath *path; + GtkTreeModel *tm; + GtkTreeIter iter; + GtkTreeIter child; + struct GNUNET_FS_Uri *uri; + + tm = GTK_TREE_MODEL (pde->sr->tab->ts); + path = gtk_tree_row_reference_get_path (pde->sr->rr); + if ( (! gtk_tree_model_get_iter (tm, &iter, path)) || + (! gtk_tree_model_iter_children (tm, &child, &iter)) ) + { + GNUNET_break (0); + } + else + { + do + { + gtk_tree_model_get (tm, &child, 1, &uri, + 9, &de->sr, + -1); + if (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri, + uri)) + break; + de->sr = NULL; + } + while (gtk_tree_model_iter_next (tm, &child)); + GNUNET_break (NULL != de->sr); + } + gtk_tree_path_free (path); + } if (NULL == de->sr) { /* Stand-alone download with no 'row'/search result affiliated @@ -2080,13 +2116,30 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, download in the URI tab */ de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri); de->sr->download = de; + path = gtk_tree_row_reference_get_path (de->sr->rr); + if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path)) + { + GNUNET_break (0); + gtk_tree_path_free (path); + return de; + } } - path = gtk_tree_row_reference_get_path (de->sr->rr); - if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path)) + else { - GNUNET_break (0); - gtk_tree_path_free (path); - return de; + struct GNUNET_CONTAINER_MetaData *meta; + + /* get metadata from existing tab, might have a mime type */ + path = gtk_tree_row_reference_get_path (de->sr->rr); + if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path)) + { + GNUNET_break (0); + gtk_tree_path_free (path); + return de; + } + gtk_tree_model_get (GTK_TREE_MODEL (de->sr->tab->ts), &iter, + 0, &meta, + -1); + de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta); } gtk_tree_path_free (path); gtk_tree_store_set (de->sr->tab->ts, &iter, @@ -2500,6 +2553,7 @@ GNUNET_GTK_fs_event_handler (void *cls, return NULL; case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: mark_download_progress (info->value.download.cctx, + info->value.download.filename, info->value.download.size, info->value.download.completed, info->value.download.specifics.progress.data, @@ -2516,8 +2570,7 @@ GNUNET_GTK_fs_event_handler (void *cls, return info->value.download.cctx; case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: mark_download_completed (info->value.download.cctx, - info->value.download.size, - info->value.download.filename); + info->value.download.size); return info->value.download.cctx; case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: stop_download (info->value.download.cctx); -- cgit v1.2.3