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.c236
1 files changed, 113 insertions, 123 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 52f89dd8..23681bdd 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -1848,47 +1848,57 @@ mark_download_error (struct DownloadEntry *de,
1848} 1848}
1849 1849
1850 1850
1851static struct DownloadEntry * 1851/**
1852 * FS-API notified us that we're done with a download. Update the
1853 * view accordingly. If the download is a directory, try to display
1854 * the contents.
1855 *
1856 * @param de download that has finished
1857 * @param size overall size of the file
1858 * @param filename name of the downloaded file on disk (possibly a temporary file)
1859 */
1860static void
1852mark_download_completed (struct DownloadEntry *de, uint64_t size, 1861mark_download_completed (struct DownloadEntry *de, uint64_t size,
1853 const char *filename) 1862 const char *filename)
1854{ 1863{
1855 struct AddDirectoryEntryContext ade; 1864 struct AddDirectoryEntryContext ade;
1856 1865
1857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1858 "Marking download completed for DE=%p, %llu-byte `%s'\n", 1867 "Marking download completed for DE=%p, %llu-byte `%s'\n",
1859 de, size, filename); 1868 de, size, filename);
1860 1869
1861 de->is_done = GNUNET_YES; 1870 de->is_done = GNUNET_YES;
1862 mark_download_progress (de, size, size, NULL, 0, 0, 0); 1871 mark_download_progress (de, size, size, NULL, 0, 0, 0);
1863 if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) && 1872 if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) &&
1864 (filename != NULL)) 1873 (filename != NULL) )
1865 { 1874 {
1875 /* download was for a directory (and we have a temp file for scanning);
1876 add contents of the directory to the view */
1866 ade.tab = de->tab; 1877 ade.tab = de->tab;
1867 ade.prr = de->rr; 1878 ade.prr = de->rr;
1868 ade.check_duplicates = GNUNET_YES; 1879 ade.check_duplicates = GNUNET_YES;
1869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, scan its contents\n");
1870 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade); 1880 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade);
1871 } 1881 }
1872 change_download_color (de, "green"); 1882 change_download_color (de, "green");
1873 return de;
1874} 1883}
1875 1884
1876 1885
1877
1878
1879
1880/** 1886/**
1881 * Move (aka copy) all of the children of 'src_iter' from the 'src_model' 1887 * Copy all of the children of 'src_iter' from the 'src_model' to
1882 * to become children of 'dst_iter' in the 'dst_model'. 1888 * become children of 'dst_iter' in the 'dst_model'. The models are
1883 * 1889 * both 'GNUNET_GTK_file_sharing_result_tree_store' models.
1884 * The models are both 'GNUNET_GTK_file_sharing_result_tree_store' models.
1885 * 1890 *
1886 * Note that we also need to update the 'struct SearchResult' 1891 * Note that we also need to update the 'struct SearchResult'
1887 * and (if it exists) the respective 'struct DownloadEntry' 1892 * and (if it exists) the respective 'struct DownloadEntry'
1888 * to refer to the new model. 1893 * to refer to the new model.
1894 *
1895 * @param src_model source model
1896 * @param src_iter parent of the nodes to move
1897 * @param dst_model destination model
1898 * @param dst_iter new parent of the entries we are moving
1889 */ 1899 */
1890static void 1900static void
1891move_children (GtkTreeModel * src_model, GtkTreeIter * src_iter, 1901copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1892 GtkTreeModel * dst_model, GtkTreeIter * dst_iter) 1902 GtkTreeModel * dst_model, GtkTreeIter * dst_iter)
1893{ 1903{
1894 GtkTreeIter src_child; 1904 GtkTreeIter src_child;
@@ -1911,60 +1921,62 @@ move_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1911 gchar *downloaded_filename; 1921 gchar *downloaded_filename;
1912 gint downloaded_anonymity; 1922 gint downloaded_anonymity;
1913 1923
1914 if (TRUE == gtk_tree_model_iter_children (src_model, &src_child, src_iter)) 1924 if (! gtk_tree_model_iter_children (src_model, &src_child, src_iter))
1925 return;
1926 do
1915 { 1927 {
1916 do 1928 gtk_tree_model_get (src_model, &src_child, 0, &meta, 1, &uri, 2,
1929 &filesize, 3, &preview, 4, &percent_progress, 5,
1930 &percent_availability, 6, &filename, 7,
1931 &uri_as_string, 8, &status_colour, 9, &search_result,
1932 10, &mimetype, 11, &applicability_rank, 12,
1933 &availability_certainty, 13, &availability_rank, 14,
1934 &completed, 15, &downloaded_filename, 16,
1935 &downloaded_anonymity, -1);
1936 gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model), &dst_child,
1937 dst_iter, G_MAXINT, 0, meta, 1, uri, 2,
1938 filesize, 3, preview, 4,
1939 percent_progress, 5,
1940 percent_availability, 6, filename, 7,
1941 uri_as_string, 8, status_colour, 9,
1942 search_result, 10, mimetype, 11,
1943 applicability_rank, 12,
1944 availability_certainty, 13,
1945 availability_rank, 14, completed, 15,
1946 downloaded_filename, 16,
1947 downloaded_anonymity, -1);
1948 g_free (filename);
1949 g_free (downloaded_filename);
1950 g_free (uri_as_string);
1951 g_free (status_colour);
1952 g_free (mimetype);
1953 if (preview != NULL)
1954 g_object_unref (preview);
1955 gtk_tree_row_reference_free (search_result->rr);
1956 path = gtk_tree_model_get_path (dst_model, &dst_child);
1957 search_result->rr = gtk_tree_row_reference_new (dst_model, path);
1958 search_result->result = NULL;
1959 gtk_tree_path_free (path);
1960 if (search_result->download != NULL)
1917 { 1961 {
1918 gtk_tree_model_get (src_model, &src_child, 0, &meta, 1, &uri, 2, 1962 search_result->download->ts = GTK_TREE_STORE (dst_model);
1919 &filesize, 3, &preview, 4, &percent_progress, 5, 1963 gtk_tree_row_reference_free (search_result->download->rr);
1920 &percent_availability, 6, &filename, 7, 1964 search_result->download->rr =
1921 &uri_as_string, 8, &status_colour, 9, &search_result, 1965 gtk_tree_row_reference_copy (search_result->rr);
1922 10, &mimetype, 11, &applicability_rank, 12,
1923 &availability_certainty, 13, &availability_rank, 14,
1924 &completed, 15, &downloaded_filename, 16,
1925 &downloaded_anonymity, -1);
1926 gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model), &dst_child,
1927 dst_iter, G_MAXINT, 0, meta, 1, uri, 2,
1928 filesize, 3, preview, 4,
1929 percent_progress, 5,
1930 percent_availability, 6, filename, 7,
1931 uri_as_string, 8, status_colour, 9,
1932 search_result, 10, mimetype, 11,
1933 applicability_rank, 12,
1934 availability_certainty, 13,
1935 availability_rank, 14, completed, 15,
1936 downloaded_filename, 16,
1937 downloaded_anonymity, -1);
1938 g_free (filename);
1939 g_free (downloaded_filename);
1940 g_free (uri_as_string);
1941 g_free (status_colour);
1942 g_free (mimetype);
1943 if (preview != NULL)
1944 g_object_unref (preview);
1945 gtk_tree_row_reference_free (search_result->rr);
1946 path = gtk_tree_model_get_path (dst_model, &dst_child);
1947 search_result->rr = gtk_tree_row_reference_new (dst_model, path);
1948 search_result->result = NULL;
1949 gtk_tree_path_free (path);
1950 if (search_result->download != NULL)
1951 {
1952 search_result->download->ts = GTK_TREE_STORE (dst_model);
1953 gtk_tree_row_reference_free (search_result->download->rr);
1954 search_result->download->rr =
1955 gtk_tree_row_reference_copy (search_result->rr);
1956 }
1957 move_children (src_model, &src_child, dst_model, &dst_child);
1958 } 1966 }
1959 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child)); 1967 copy_children (src_model, &src_child, dst_model, &dst_child);
1960 } 1968 }
1969 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child));
1961} 1970}
1962 1971
1963 1972
1964/** 1973/**
1965 * Delete the entire given subtree from the model. 1974 * Delete the entire given subtree from the model. Does not free
1966 * Does not free anything inside of the respective 1975 * anything inside of the respective model's fields (since they have
1967 * model's fields (since they have been moved). 1976 * been moved).
1977 *
1978 * @param model model that contains the subtree to remove
1979 * @param iter root of the subtree to remove
1968 */ 1980 */
1969static void 1981static void
1970delete_stale_subtree (GtkTreeModel * model, GtkTreeIter * iter) 1982delete_stale_subtree (GtkTreeModel * model, GtkTreeIter * iter)
@@ -1980,10 +1992,11 @@ delete_stale_subtree (GtkTreeModel * model, GtkTreeIter * iter)
1980/** 1992/**
1981 * Handle the case where an active download lost its 1993 * Handle the case where an active download lost its
1982 * search parent by moving it to the URI tab. 1994 * search parent by moving it to the URI tab.
1995 *
1996 * @param de download where the parent (i.e. search) was lost
1983 */ 1997 */
1984static struct DownloadEntry * 1998static void
1985download_lost_parent (struct DownloadEntry *de, uint64_t size, 1999download_lost_parent (struct DownloadEntry *de)
1986 uint64_t completed, int is_active)
1987{ 2000{
1988 GtkTreeIter iter; 2001 GtkTreeIter iter;
1989 GtkTreePath *path; 2002 GtkTreePath *path;
@@ -1994,6 +2007,7 @@ download_lost_parent (struct DownloadEntry *de, uint64_t size,
1994 GtkTreeIter child; 2007 GtkTreeIter child;
1995 GtkTreeModel *model; 2008 GtkTreeModel *model;
1996 2009
2010 /* first, move the root of the respective 'de'-tree */
1997 rr_old = de->rr; 2011 rr_old = de->rr;
1998 tab = GNUNET_GTK_add_to_uri_tab (&iter, &de->sr, de->meta, de->uri); 2012 tab = GNUNET_GTK_add_to_uri_tab (&iter, &de->sr, de->meta, de->uri);
1999 de->sr->download = de; 2013 de->sr->download = de;
@@ -2002,46 +2016,37 @@ download_lost_parent (struct DownloadEntry *de, uint64_t size,
2002 path = gtk_tree_model_get_path (model, &iter); 2016 path = gtk_tree_model_get_path (model, &iter);
2003 de->rr = gtk_tree_row_reference_new (model, path); 2017 de->rr = gtk_tree_row_reference_new (model, path);
2004 gtk_tree_path_free (path); 2018 gtk_tree_path_free (path);
2005 mark_download_progress (de, size, completed, NULL, 0, 0, 0);
2006 tm_old = gtk_tree_row_reference_get_model (rr_old); 2019 tm_old = gtk_tree_row_reference_get_model (rr_old);
2007 path = gtk_tree_row_reference_get_path (rr_old); 2020 path = gtk_tree_row_reference_get_path (rr_old);
2008 gtk_tree_row_reference_free (rr_old); 2021 gtk_tree_row_reference_free (rr_old);
2009 if (TRUE != gtk_tree_model_get_iter (tm_old, &iter_old, path)) 2022 if (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
2010 { 2023 {
2011 GNUNET_break (0); 2024 GNUNET_break (0);
2012 gtk_tree_path_free (path); 2025 gtk_tree_path_free (path);
2013 return NULL; 2026 return;
2014 } 2027 }
2015 gtk_tree_path_free (path); 2028 gtk_tree_path_free (path);
2016 move_children (tm_old, &iter_old, model, &iter); 2029
2017 while (TRUE == gtk_tree_model_iter_children (model, &child, &iter)) 2030 /* finally, move all children over as well */
2031 copy_children (tm_old, &iter_old, model, &iter);
2032 while (gtk_tree_model_iter_children (model, &child, &iter))
2018 delete_stale_subtree (model, &child); 2033 delete_stale_subtree (model, &child);
2019 if (size > completed)
2020 {
2021 if (is_active)
2022 change_download_color (de, "yellow");
2023 else
2024 change_download_color (de, "blue");
2025 }
2026 else
2027 {
2028 change_download_color (de, "green");
2029 }
2030 return de;
2031} 2034}
2032 2035
2033 2036
2034/** 2037/**
2035 * Setup a new download entry. 2038 * Setup a new download entry.
2036 * 2039 *
2037 * @param de existing download entry for the download, or NULL 2040 * @param de existing download entry for the download, or NULL (in which case we create a fresh one)
2038 * @param pde parent download entry, or NULL 2041 * @param pde parent download entry, or NULL
2039 * @param sr search result, or NULL 2042 * @param sr search result, or NULL
2040 * @param dc download context (for stopping) 2043 * @param dc download context (for stopping)
2041 * @param uri the URI 2044 * @param uri the URI, must not be NULL
2045 * @param filename filename on disk
2042 * @param meta metadata 2046 * @param meta metadata
2043 * @param size total size 2047 * @param size total size
2044 * @param completed current progress 2048 * @param completed current progress
2049 * @return download entry struct for the download (equal to 'de' if 'de' was not NULL)
2045 */ 2050 */
2046static struct DownloadEntry * 2051static struct DownloadEntry *
2047setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, 2052setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
@@ -2055,55 +2060,49 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2055 struct SearchResult *srp; 2060 struct SearchResult *srp;
2056 2061
2057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2058 "Setting up download, initially DE=%p, PDE=%p for %p & %p into %llu/%llu `%s'\n", 2063 "Setting up download, initially DE=%p, PDE=%p for %p & %p into %llu/%llu `%s'\n",
2059 de, pde, sr, dc, completed, size, filename); 2064 de, pde, sr, dc, completed, size, filename);
2060 GNUNET_assert (NULL != uri); 2065 GNUNET_assert (NULL != uri);
2061 srp = NULL; 2066 srp = NULL;
2062 if (de == NULL) 2067 if (NULL == de)
2063 { 2068 {
2069 /* no existing download entry to build on, create a fresh one */
2064 de = GNUNET_malloc (sizeof (struct DownloadEntry)); 2070 de = GNUNET_malloc (sizeof (struct DownloadEntry));
2065 de->uri = GNUNET_FS_uri_dup (uri); 2071 de->uri = GNUNET_FS_uri_dup (uri);
2066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Allocated DE=%p\n", de); 2072 }
2073 else
2074 {
2075 GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri, uri));
2067 } 2076 }
2068 de->dc = dc; 2077 de->dc = dc;
2069 de->sr = sr; 2078 de->sr = sr;
2079 de->pde = pde;
2080 if ( (meta != NULL) && (de->meta == NULL) )
2081 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
2070 if (NULL != sr) 2082 if (NULL != sr)
2071 { 2083 {
2084 /* got a search result; display the download in the same location as the search result */
2072 GNUNET_assert (sr->download == NULL); 2085 GNUNET_assert (sr->download == NULL);
2073 sr->download = de; 2086 sr->download = de;
2074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SR=%p now refers to DE=%p\n", sr, de);
2075 }
2076 de->pde = pde;
2077 if ((meta != NULL) && (de->meta == NULL))
2078 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
2079 if (sr != NULL)
2080 {
2081 de->rr = gtk_tree_row_reference_copy (sr->rr); 2087 de->rr = gtk_tree_row_reference_copy (sr->rr);
2082 de->ts = sr->tab->ts; 2088 de->ts = sr->tab->ts;
2083 de->tab = sr->tab; 2089 de->tab = sr->tab;
2084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2090 srp = sr;
2085 "It's started from a search result, store a copy of a reference to rr=%p (%p), ts=%p and tab=%p\n",
2086 sr->rr, de->rr, de->ts, de->tab);
2087 } 2091 }
2088 else if (de->rr == NULL) 2092 if (NULL == de->rr)
2089 { 2093 {
2094 /* Stand-alone download with no 'row'/search result affiliated
2095 with the download so far; create a fresh entry for this
2096 download in the URI tab */
2090 de->tab = GNUNET_GTK_add_to_uri_tab (&iter, &srp, meta, uri); 2097 de->tab = GNUNET_GTK_add_to_uri_tab (&iter, &srp, meta, uri);
2091 de->ts = de->tab->ts; 2098 de->ts = de->tab->ts;
2092 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), &iter); 2099 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), &iter);
2093 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts), path); 2100 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts), path);
2094 gtk_tree_path_free (path); 2101 gtk_tree_path_free (path);
2095 srp->download = de; 2102 srp->download = de;
2096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2097 "It's a standalone download, added it to uri tab=%p, ts=%p and rr=%p\n",
2098 de->tab, de->ts, de->rr);
2099 }
2100 else
2101 {
2102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2103 "It's a child download, leaving its rr, ts and tab unset\n");
2104 } 2103 }
2105 path = gtk_tree_row_reference_get_path (de->rr); 2104 path = gtk_tree_row_reference_get_path (de->rr);
2106 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path)) 2105 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
2107 { 2106 {
2108 GNUNET_break (0); 2107 GNUNET_break (0);
2109 gtk_tree_path_free (path); 2108 gtk_tree_path_free (path);
@@ -2116,25 +2115,18 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2116 size) : 100) /* progress */ , 2115 size) : 100) /* progress */ ,
2117 6, filename /* filename/description */ , 2116 6, filename /* filename/description */ ,
2118 8, "blue" /* status colour: pending */ , 2117 8, "blue" /* status colour: pending */ ,
2118 9, srp,
2119 14, completed, 2119 14, completed,
2120 -1); 2120 -1);
2121 if (NULL != srp)
2122 gtk_tree_store_set (de->ts, &iter,
2123 9, srp,
2124 -1);
2125 return de; 2121 return de;
2126} 2122}
2127 2123
2128 2124
2129 2125
2130
2131
2132
2133/* ***************** Publish event handling ****************** */ 2126/* ***************** Publish event handling ****************** */
2134 2127
2135 2128
2136 2129
2137
2138/** 2130/**
2139 * Change the (background) color of the given publish entry. 2131 * Change the (background) color of the given publish entry.
2140 * 2132 *
@@ -2160,7 +2152,6 @@ change_publish_color (struct PublishEntry *pe,
2160 } 2152 }
2161 gtk_tree_path_free (path); 2153 gtk_tree_path_free (path);
2162 gtk_tree_store_set (pe->tab->ts, &iter, 2, color, -1); 2154 gtk_tree_store_set (pe->tab->ts, &iter, 2, color, -1);
2163 return;
2164} 2155}
2165 2156
2166 2157
@@ -2518,9 +2509,10 @@ GNUNET_GTK_fs_event_handler (void *cls,
2518 info->value.download.specifics.error.message); 2509 info->value.download.specifics.error.message);
2519 return info->value.download.cctx; 2510 return info->value.download.cctx;
2520 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 2511 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
2521 return mark_download_completed (info->value.download.cctx, 2512 mark_download_completed (info->value.download.cctx,
2522 info->value.download.size, 2513 info->value.download.size,
2523 info->value.download.filename); 2514 info->value.download.filename);
2515 return info->value.download.cctx;
2524 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 2516 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
2525 stop_download (info->value.download.cctx); 2517 stop_download (info->value.download.cctx);
2526 return NULL; 2518 return NULL;
@@ -2531,10 +2523,8 @@ GNUNET_GTK_fs_event_handler (void *cls,
2531 change_download_color (info->value.download.cctx, "blue"); 2523 change_download_color (info->value.download.cctx, "blue");
2532 return info->value.download.cctx; 2524 return info->value.download.cctx;
2533 case GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT: 2525 case GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT:
2534 return download_lost_parent (info->value.download.cctx, 2526 download_lost_parent (info->value.download.cctx);
2535 info->value.download.size, 2527 return info->value.download.cctx;
2536 info->value.download.completed,
2537 info->value.download.is_active);
2538 case GNUNET_FS_STATUS_SEARCH_START: 2528 case GNUNET_FS_STATUS_SEARCH_START:
2539 if (info->value.search.pctx != NULL) 2529 if (info->value.search.pctx != NULL)
2540 return setup_inner_search (info->value.search.sc, 2530 return setup_inner_search (info->value.search.sc,