aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk_event-handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk_event-handler.c')
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c155
1 files 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,
1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1650 "Adding directory entry `%s'\n", 1650 "Adding directory entry `%s'\n",
1651 filename); 1651 filename);
1652
1653 if (NULL == uri) 1652 if (NULL == uri)
1654 { 1653 {
1655 /* directory meta data itself */ 1654 /* directory meta data itself */
@@ -1690,6 +1689,7 @@ add_directory_entry (void *cls, const char *filename,
1690 * the contents. 1689 * the contents.
1691 * 1690 *
1692 * @param de download entry that is progressing 1691 * @param de download entry that is progressing
1692 * @param filename name of the downloaded file on disk (possibly a temporary file)
1693 * @param size overall size of the download 1693 * @param size overall size of the download
1694 * @param completed number of bytes we have completed 1694 * @param completed number of bytes we have completed
1695 * @param block_data current block we've downloaded 1695 * @param block_data current block we've downloaded
@@ -1698,7 +1698,9 @@ add_directory_entry (void *cls, const char *filename,
1698 * @param depth depth of the block in the ECRS tree 1698 * @param depth depth of the block in the ECRS tree
1699 */ 1699 */
1700static void 1700static void
1701mark_download_progress (struct DownloadEntry *de, uint64_t size, 1701mark_download_progress (struct DownloadEntry *de,
1702 const char *filename,
1703 uint64_t size,
1702 uint64_t completed, const void *block_data, 1704 uint64_t completed, const void *block_data,
1703 uint64_t offset, uint64_t block_size, 1705 uint64_t offset, uint64_t block_size,
1704 unsigned int depth) 1706 unsigned int depth)
@@ -1731,24 +1733,46 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size,
1731 size) : 100) /* availability == progress */, 1733 size) : 100) /* availability == progress */,
1732 14, completed, 1734 14, completed,
1733 -1); 1735 -1);
1734 if ( (depth == 0) && 1736 if (completed < size)
1735 (block_size > 0) && 1737 {
1736 (GNUNET_YES == de->is_directory) ) 1738 /* partial completion, consider looking at the block */
1737 { 1739 if ( (depth == 0) &&
1738 /* got a data block of a directory, list its contents */ 1740 (block_size > 0) &&
1739 struct AddDirectoryEntryContext ade; 1741 (GNUNET_YES == de->is_directory) )
1740
1741 ade.tab = de->sr->tab;
1742 ade.prr = de->sr->rr;
1743 ade.check_duplicates = GNUNET_NO;
1744 if (GNUNET_SYSERR ==
1745 GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
1746 offset, &add_directory_entry, &ade))
1747 { 1742 {
1748 /* Mime type was wrong, this is not a directory, update model! */ 1743 /* got a data block of a directory, list its contents */
1749 de->is_directory = GNUNET_SYSERR; 1744 struct AddDirectoryEntryContext ade;
1750 gtk_tree_store_set (de->sr->tab->ts, &iter, 1745
1751 10, "" /* unknown mime type */, -1); 1746 ade.tab = de->sr->tab;
1747 ade.prr = de->sr->rr;
1748 ade.check_duplicates = GNUNET_NO;
1749 if (GNUNET_SYSERR ==
1750 GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
1751 offset, &add_directory_entry, &ade))
1752 {
1753 /* Mime type was wrong, this is not a directory, update model! */
1754 de->is_directory = GNUNET_SYSERR;
1755 gtk_tree_store_set (de->sr->tab->ts, &iter,
1756 10, "" /* unknown mime type */, -1);
1757 }
1758 }
1759 }
1760 else
1761 {
1762 /* full completion, look at the entire file */
1763 if ( (GNUNET_NO != de->is_directory) &&
1764 (filename != NULL) )
1765 {
1766 struct AddDirectoryEntryContext ade;
1767
1768 /* download was for a directory (and we have a temp file for scanning);
1769 add contents of the directory to the view */
1770 ade.tab = de->sr->tab;
1771 ade.prr = de->sr->rr;
1772 ade.check_duplicates = GNUNET_YES;
1773 if (GNUNET_OK !=
1774 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade))
1775 de->is_directory = GNUNET_NO;
1752 } 1776 }
1753 } 1777 }
1754} 1778}
@@ -1784,37 +1808,15 @@ mark_download_error (struct DownloadEntry *de,
1784 1808
1785/** 1809/**
1786 * FS-API notified us that we're done with a download. Update the 1810 * FS-API notified us that we're done with a download. Update the
1787 * view accordingly. If the download is a directory, try to display 1811 * view accordingly.
1788 * the contents.
1789 * 1812 *
1790 * @param de download that has finished 1813 * @param de download that has finished
1791 * @param size overall size of the file 1814 * @param size overall size of the file
1792 * @param filename name of the downloaded file on disk (possibly a temporary file)
1793 */ 1815 */
1794static void 1816static void
1795mark_download_completed (struct DownloadEntry *de, uint64_t size, 1817mark_download_completed (struct DownloadEntry *de, uint64_t size)
1796 const char *filename)
1797{ 1818{
1798 struct AddDirectoryEntryContext ade;
1799
1800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1801 "Marking download completed for DE=%p, %llu-byte `%s'\n",
1802 de, size, filename);
1803
1804 de->is_done = GNUNET_YES; 1819 de->is_done = GNUNET_YES;
1805 mark_download_progress (de, size, size, NULL, 0, 0, 0);
1806 if ( (GNUNET_NO != de->is_directory) &&
1807 (filename != NULL) )
1808 {
1809 /* download was for a directory (and we have a temp file for scanning);
1810 add contents of the directory to the view */
1811 ade.tab = de->sr->tab;
1812 ade.prr = de->sr->rr;
1813 ade.check_duplicates = GNUNET_YES;
1814 if (GNUNET_OK !=
1815 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade))
1816 de->is_directory = GNUNET_NO;
1817 }
1818 change_download_color (de, "green"); 1820 change_download_color (de, "green");
1819} 1821}
1820 1822
@@ -1924,7 +1926,7 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1924 1926
1925 copy_children (src_model, &src_child, dst_tab, &dst_child); 1927 copy_children (src_model, &src_child, dst_tab, &dst_child);
1926 } 1928 }
1927 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child)); 1929 while (gtk_tree_model_iter_next (src_model, &src_child));
1928} 1930}
1929 1931
1930 1932
@@ -2073,6 +2075,40 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2073 GNUNET_assert (sr == de->sr); 2075 GNUNET_assert (sr == de->sr);
2074 } 2076 }
2075 } 2077 }
2078 if ( (NULL == de->sr) &&
2079 (NULL != pde) )
2080 {
2081 /* child download, find appropriate search result from parent! */
2082 GtkTreePath *path;
2083 GtkTreeModel *tm;
2084 GtkTreeIter iter;
2085 GtkTreeIter child;
2086 struct GNUNET_FS_Uri *uri;
2087
2088 tm = GTK_TREE_MODEL (pde->sr->tab->ts);
2089 path = gtk_tree_row_reference_get_path (pde->sr->rr);
2090 if ( (! gtk_tree_model_get_iter (tm, &iter, path)) ||
2091 (! gtk_tree_model_iter_children (tm, &child, &iter)) )
2092 {
2093 GNUNET_break (0);
2094 }
2095 else
2096 {
2097 do
2098 {
2099 gtk_tree_model_get (tm, &child, 1, &uri,
2100 9, &de->sr,
2101 -1);
2102 if (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri,
2103 uri))
2104 break;
2105 de->sr = NULL;
2106 }
2107 while (gtk_tree_model_iter_next (tm, &child));
2108 GNUNET_break (NULL != de->sr);
2109 }
2110 gtk_tree_path_free (path);
2111 }
2076 if (NULL == de->sr) 2112 if (NULL == de->sr)
2077 { 2113 {
2078 /* Stand-alone download with no 'row'/search result affiliated 2114 /* Stand-alone download with no 'row'/search result affiliated
@@ -2080,13 +2116,30 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2080 download in the URI tab */ 2116 download in the URI tab */
2081 de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri); 2117 de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri);
2082 de->sr->download = de; 2118 de->sr->download = de;
2119 path = gtk_tree_row_reference_get_path (de->sr->rr);
2120 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
2121 {
2122 GNUNET_break (0);
2123 gtk_tree_path_free (path);
2124 return de;
2125 }
2083 } 2126 }
2084 path = gtk_tree_row_reference_get_path (de->sr->rr); 2127 else
2085 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
2086 { 2128 {
2087 GNUNET_break (0); 2129 struct GNUNET_CONTAINER_MetaData *meta;
2088 gtk_tree_path_free (path); 2130
2089 return de; 2131 /* get metadata from existing tab, might have a mime type */
2132 path = gtk_tree_row_reference_get_path (de->sr->rr);
2133 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
2134 {
2135 GNUNET_break (0);
2136 gtk_tree_path_free (path);
2137 return de;
2138 }
2139 gtk_tree_model_get (GTK_TREE_MODEL (de->sr->tab->ts), &iter,
2140 0, &meta,
2141 -1);
2142 de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
2090 } 2143 }
2091 gtk_tree_path_free (path); 2144 gtk_tree_path_free (path);
2092 gtk_tree_store_set (de->sr->tab->ts, &iter, 2145 gtk_tree_store_set (de->sr->tab->ts, &iter,
@@ -2500,6 +2553,7 @@ GNUNET_GTK_fs_event_handler (void *cls,
2500 return NULL; 2553 return NULL;
2501 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 2554 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
2502 mark_download_progress (info->value.download.cctx, 2555 mark_download_progress (info->value.download.cctx,
2556 info->value.download.filename,
2503 info->value.download.size, 2557 info->value.download.size,
2504 info->value.download.completed, 2558 info->value.download.completed,
2505 info->value.download.specifics.progress.data, 2559 info->value.download.specifics.progress.data,
@@ -2516,8 +2570,7 @@ GNUNET_GTK_fs_event_handler (void *cls,
2516 return info->value.download.cctx; 2570 return info->value.download.cctx;
2517 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 2571 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
2518 mark_download_completed (info->value.download.cctx, 2572 mark_download_completed (info->value.download.cctx,
2519 info->value.download.size, 2573 info->value.download.size);
2520 info->value.download.filename);
2521 return info->value.download.cctx; 2574 return info->value.download.cctx;
2522 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 2575 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
2523 stop_download (info->value.download.cctx); 2576 stop_download (info->value.download.cctx);