aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-04 21:09:11 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-04 21:09:11 +0000
commit40bf5d27b21fedc867bd9f6bd001697bd1077ba1 (patch)
tree3f407b16348c1b3b4893691b444d22c88ac6e358
parent9e30fe0be68b1c0d446fee8860e4773bf836d372 (diff)
downloadgnunet-gtk-40bf5d27b21fedc867bd9f6bd001697bd1077ba1.tar.gz
gnunet-gtk-40bf5d27b21fedc867bd9f6bd001697bd1077ba1.zip
-fix crash after lost parent event
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c161
1 files changed, 99 insertions, 62 deletions
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index ab1fea71..1535f18d 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -402,11 +402,6 @@ start_download (GtkTreeView *tree_view,
402 de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta); 402 de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
403 if (save_as) 403 if (save_as)
404 have_a_suggestion = GNUNET_NO; 404 have_a_suggestion = GNUNET_NO;
405 fprintf (stderr,
406 "lp %d, have-sug: %d\n",
407 local_parents,
408 have_a_suggestion);
409
410 if ( (GNUNET_YES == local_parents) && 405 if ( (GNUNET_YES == local_parents) &&
411 (GNUNET_YES == have_a_suggestion) ) 406 (GNUNET_YES == have_a_suggestion) )
412 /* Skip the dialog, call directly */ 407 /* Skip the dialog, call directly */
@@ -1838,12 +1833,13 @@ mark_download_completed (struct DownloadEntry *de, uint64_t size,
1838 * 1833 *
1839 * @param src_model source model 1834 * @param src_model source model
1840 * @param src_iter parent of the nodes to move 1835 * @param src_iter parent of the nodes to move
1841 * @param dst_model destination model 1836 * @param dst_tab destination tab
1842 * @param dst_iter new parent of the entries we are moving 1837 * @param dst_iter new parent of the entries we are moving
1843 */ 1838 */
1844static void 1839static void
1845copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter, 1840copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1846 GtkTreeModel * dst_model, GtkTreeIter * dst_iter) 1841 struct SearchTab *dst_tab,
1842 GtkTreeIter * dst_iter)
1847{ 1843{
1848 GtkTreeIter src_child; 1844 GtkTreeIter src_child;
1849 GtkTreeIter dst_child; 1845 GtkTreeIter dst_child;
@@ -1857,7 +1853,8 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1857 gchar *filename; 1853 gchar *filename;
1858 gchar *uri_as_string; 1854 gchar *uri_as_string;
1859 gchar *status_colour; 1855 gchar *status_colour;
1860 struct SearchResult *search_result; 1856 struct SearchResult *search_result_old;
1857 struct SearchResult *search_result_new;
1861 gchar *mimetype; 1858 gchar *mimetype;
1862 guint applicability_rank; 1859 guint applicability_rank;
1863 guint availability_certainty; 1860 guint availability_certainty;
@@ -1869,26 +1866,53 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1869 return; 1866 return;
1870 do 1867 do
1871 { 1868 {
1872 gtk_tree_model_get (src_model, &src_child, 0, &meta, 1, &uri, 2, 1869 gtk_tree_model_get (src_model, &src_child,
1873 &filesize, 3, &preview, 4, &percent_progress, 5, 1870 0, &meta,
1874 &percent_availability, 6, &filename, 7, 1871 1, &uri,
1875 &uri_as_string, 8, &status_colour, 9, &search_result, 1872 2, &filesize,
1876 10, &mimetype, 11, &applicability_rank, 12, 1873 3, &preview,
1877 &availability_certainty, 13, &availability_rank, 14, 1874 4, &percent_progress,
1878 &completed, 15, &downloaded_filename, 16, 1875 5, &percent_availability,
1879 &downloaded_anonymity, -1); 1876 6, &filename,
1880 gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model), &dst_child, 1877 7, &uri_as_string,
1881 dst_iter, G_MAXINT, 0, meta, 1, uri, 2, 1878 8, &status_colour,
1882 filesize, 3, preview, 4, 1879 9, &search_result_old,
1883 percent_progress, 5, 1880 10, &mimetype,
1884 percent_availability, 6, filename, 7, 1881 11, &applicability_rank,
1885 uri_as_string, 8, status_colour, 9, 1882 12, &availability_certainty,
1886 search_result, 10, mimetype, 11, 1883 13, &availability_rank,
1887 applicability_rank, 12, 1884 14, &completed,
1888 availability_certainty, 13, 1885 15, &downloaded_filename,
1889 availability_rank, 14, completed, 15, 1886 16, &downloaded_anonymity,
1890 downloaded_filename, 16, 1887 -1);
1891 downloaded_anonymity, -1); 1888 search_result_new = GNUNET_malloc (sizeof (struct SearchResult));
1889 search_result_new->tab = dst_tab;
1890 search_result_new->download = search_result_old->download;
1891 if (NULL != search_result_old->download)
1892 {
1893 search_result_old->download = NULL;
1894 search_result_new->download->sr = search_result_new;
1895 }
1896 gtk_tree_store_insert_with_values (dst_tab->ts, &dst_child,
1897 dst_iter, G_MAXINT,
1898 0, GNUNET_CONTAINER_meta_data_duplicate (meta),
1899 1, GNUNET_FS_uri_dup (uri),
1900 2, filesize,
1901 3, preview,
1902 4, percent_progress,
1903 5, percent_availability,
1904 6, filename,
1905 7, uri_as_string,
1906 8, status_colour,
1907 9, search_result_new,
1908 10, mimetype,
1909 11, applicability_rank,
1910 12, availability_certainty,
1911 13, availability_rank,
1912 14, completed,
1913 15, downloaded_filename,
1914 16, downloaded_anonymity,
1915 -1);
1892 g_free (filename); 1916 g_free (filename);
1893 g_free (downloaded_filename); 1917 g_free (downloaded_filename);
1894 g_free (uri_as_string); 1918 g_free (uri_as_string);
@@ -1896,37 +1920,18 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1896 g_free (mimetype); 1920 g_free (mimetype);
1897 if (preview != NULL) 1921 if (preview != NULL)
1898 g_object_unref (preview); 1922 g_object_unref (preview);
1899 gtk_tree_row_reference_free (search_result->rr); 1923
1900 path = gtk_tree_model_get_path (dst_model, &dst_child); 1924 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dst_tab->ts), &dst_child);
1901 search_result->rr = gtk_tree_row_reference_new (dst_model, path); 1925 search_result_new->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (dst_tab->ts), path);
1902 search_result->result = NULL;
1903 gtk_tree_path_free (path); 1926 gtk_tree_path_free (path);
1904 copy_children (src_model, &src_child, dst_model, &dst_child); 1927
1928 copy_children (src_model, &src_child, dst_tab, &dst_child);
1905 } 1929 }
1906 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child)); 1930 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child));
1907} 1931}
1908 1932
1909 1933
1910/** 1934/**
1911 * Delete the entire given subtree from the model. Does not free
1912 * anything inside of the respective model's fields (since they have
1913 * been moved).
1914 *
1915 * @param model model that contains the subtree to remove
1916 * @param iter root of the subtree to remove
1917 */
1918static void
1919delete_stale_subtree (GtkTreeModel * model, GtkTreeIter * iter)
1920{
1921 GtkTreeIter child;
1922
1923 while (TRUE == gtk_tree_model_iter_children (model, &child, iter))
1924 delete_stale_subtree (model, &child);
1925 gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
1926}
1927
1928
1929/**
1930 * Handle the case where an active download lost its 1935 * Handle the case where an active download lost its
1931 * search parent by moving it to the URI tab. 1936 * search parent by moving it to the URI tab.
1932 * 1937 *
@@ -1937,19 +1942,25 @@ download_lost_parent (struct DownloadEntry *de)
1937{ 1942{
1938 GtkTreeIter iter; 1943 GtkTreeIter iter;
1939 GtkTreePath *path; 1944 GtkTreePath *path;
1940 GtkTreeRowReference *rr_old;
1941 GtkTreeModel *tm_old; 1945 GtkTreeModel *tm_old;
1942 GtkTreeIter iter_old; 1946 GtkTreeIter iter_old;
1943 GtkTreeIter child;
1944 GtkTreeModel *model; 1947 GtkTreeModel *model;
1945 struct GNUNET_CONTAINER_MetaData *meta; 1948 struct GNUNET_CONTAINER_MetaData *meta;
1946 struct GNUNET_FS_Uri *uri; 1949 struct GNUNET_FS_Uri *uri;
1950 guint64 completed;
1951 guint percent_progress;
1952 guint percent_availability;
1953 gchar *filename;
1954 gchar *status_colour;
1955 guint applicability_rank;
1956 guint availability_certainty;
1957 gint availability_rank;
1958 gchar *downloaded_filename;
1959 gint downloaded_anonymity;
1947 1960
1948 /* find the 'old' root */ 1961 /* find the 'old' root */
1949 rr_old = de->sr->rr; 1962 tm_old = GTK_TREE_MODEL (de->sr->tab->ts);
1950 tm_old = gtk_tree_row_reference_get_model (rr_old); 1963 path = gtk_tree_row_reference_get_path (de->sr->rr);
1951 path = gtk_tree_row_reference_get_path (rr_old);
1952 gtk_tree_row_reference_free (rr_old);
1953 if (! gtk_tree_model_get_iter (tm_old, &iter_old, path)) 1964 if (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
1954 { 1965 {
1955 GNUNET_break (0); 1966 GNUNET_break (0);
@@ -1960,9 +1971,21 @@ download_lost_parent (struct DownloadEntry *de)
1960 gtk_tree_model_get (tm_old, &iter_old, 1971 gtk_tree_model_get (tm_old, &iter_old,
1961 0, &meta, 1972 0, &meta,
1962 1, &uri, 1973 1, &uri,
1974 4, &percent_progress,
1975 5, &percent_availability,
1976 6, &filename,
1977 8, &status_colour,
1978 11, &applicability_rank,
1979 12, &availability_certainty,
1980 13, &availability_rank,
1981 14, &completed,
1982 15, &downloaded_filename,
1983 16, &downloaded_anonymity,
1963 -1); 1984 -1);
1964 GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (uri, de->uri)); 1985 GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (uri, de->uri));
1965 1986 GNUNET_assert (de->sr->download == de);
1987 de->sr->download = NULL;
1988
1966 /* create the target root */ 1989 /* create the target root */
1967 de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri); 1990 de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri);
1968 de->sr->download = de; 1991 de->sr->download = de;
@@ -1978,10 +2001,24 @@ download_lost_parent (struct DownloadEntry *de)
1978 } 2001 }
1979 gtk_tree_path_free (path); 2002 gtk_tree_path_free (path);
1980 2003
2004 gtk_tree_store_set (de->sr->tab->ts, &iter,
2005 4, percent_progress,
2006 5, percent_availability,
2007 6, filename,
2008 8, status_colour,
2009 11, applicability_rank,
2010 12, availability_certainty,
2011 13, availability_rank,
2012 14, completed,
2013 15, downloaded_filename,
2014 16, downloaded_anonymity,
2015 -1);
2016 g_free (filename);
2017 g_free (downloaded_filename);
2018 g_free (status_colour);
2019
1981 /* finally, move all children over as well */ 2020 /* finally, move all children over as well */
1982 copy_children (tm_old, &iter_old, model, &iter); 2021 copy_children (tm_old, &iter_old, de->sr->tab, &iter);
1983 while (gtk_tree_model_iter_children (model, &child, &iter))
1984 delete_stale_subtree (model, &child);
1985} 2022}
1986 2023
1987 2024