[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19697 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19697 - gnunet-gtk/src/fs |
Date: |
Sun, 5 Feb 2012 14:29:08 +0100 |
Author: grothoff
Date: 2012-02-05 14:29:08 +0100 (Sun, 05 Feb 2012)
New Revision: 19697
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
Log:
-trying to fix #2137 and #2080, testing needed
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-02-05 11:55:46 UTC
(rev 19696)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-02-05 13:29:08 UTC
(rev 19697)
@@ -829,6 +829,266 @@
/**
+ * Copy all of the children of 'src_iter' from the 'src_model' to
+ * become children of 'dst_iter' in the 'dst_model'. The models are
+ * both 'GNUNET_GTK_file_sharing_result_tree_store' models.
+ *
+ * Note that we also need to update the 'struct SearchResult'
+ * and (if it exists) the respective 'struct DownloadEntry'
+ * to refer to the new model.
+ *
+ * @param src_model source model
+ * @param src_iter parent of the nodes to move
+ * @param dst_tab destination tab
+ * @param dst_iter new parent of the entries we are moving
+ */
+static void
+copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
+ struct SearchTab *dst_tab,
+ GtkTreeIter * dst_iter)
+{
+ GtkTreeIter src_child;
+ GtkTreeIter dst_child;
+ GtkTreePath *path;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *uri;
+ guint64 filesize, completed;
+ GdkPixbuf *preview;
+ guint percent_progress;
+ guint percent_availability;
+ gchar *filename;
+ gchar *uri_as_string;
+ gchar *status_colour;
+ struct SearchResult *search_result_old;
+ struct SearchResult *search_result_new;
+ gchar *mimetype;
+ guint applicability_rank;
+ guint availability_certainty;
+ gint availability_rank;
+ gchar *downloaded_filename;
+ gint downloaded_anonymity;
+
+ if (! gtk_tree_model_iter_children (src_model, &src_child, src_iter))
+ return;
+ do
+ {
+ gtk_tree_model_get (src_model, &src_child,
+ 0, &meta,
+ 1, &uri,
+ 2, &filesize,
+ 3, &preview,
+ 4, &percent_progress,
+ 5, &percent_availability,
+ 6, &filename,
+ 7, &uri_as_string,
+ 8, &status_colour,
+ 9, &search_result_old,
+ 10, &mimetype,
+ 11, &applicability_rank,
+ 12, &availability_certainty,
+ 13, &availability_rank,
+ 14, &completed,
+ 15, &downloaded_filename,
+ 16, &downloaded_anonymity,
+ -1);
+ search_result_new = GNUNET_malloc (sizeof (struct SearchResult));
+ search_result_new->tab = dst_tab;
+ search_result_new->download = search_result_old->download;
+ if (NULL != search_result_old->download)
+ {
+ search_result_old->download = NULL;
+ search_result_new->download->sr = search_result_new;
+ }
+ gtk_tree_store_insert_with_values (dst_tab->ts, &dst_child,
+ dst_iter, G_MAXINT,
+ 0, GNUNET_CONTAINER_meta_data_duplicate
(meta),
+ 1, GNUNET_FS_uri_dup (uri),
+ 2, filesize,
+ 3, preview,
+ 4, percent_progress,
+ 5, percent_availability,
+ 6, filename,
+ 7, uri_as_string,
+ 8, status_colour,
+ 9, search_result_new,
+ 10, mimetype,
+ 11, applicability_rank,
+ 12, availability_certainty,
+ 13, availability_rank,
+ 14, completed,
+ 15, downloaded_filename,
+ 16, downloaded_anonymity,
+ -1);
+ g_free (filename);
+ g_free (downloaded_filename);
+ g_free (uri_as_string);
+ g_free (status_colour);
+ g_free (mimetype);
+ if (preview != NULL)
+ g_object_unref (preview);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (dst_tab->ts), &dst_child);
+ search_result_new->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL
(dst_tab->ts), path);
+ gtk_tree_path_free (path);
+
+ copy_children (src_model, &src_child, dst_tab, &dst_child);
+ }
+ while (gtk_tree_model_iter_next (src_model, &src_child));
+}
+
+
+/**
+ * Handle the case where an active download lost its
+ * search parent by moving it to the URI tab.
+ *
+ * @param de download where the parent (i.e. search) was lost
+ */
+static void
+download_lost_parent (struct DownloadEntry *de)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeModel *tm_old;
+ GtkTreeIter iter_old;
+ GtkTreeModel *model;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *uri;
+ guint64 completed;
+ guint percent_progress;
+ guint percent_availability;
+ gchar *filename;
+ gchar *status_colour;
+ guint applicability_rank;
+ guint availability_certainty;
+ gint availability_rank;
+ gchar *downloaded_filename;
+ gint downloaded_anonymity;
+
+ /* find the 'old' root */
+ tm_old = GTK_TREE_MODEL (de->sr->tab->ts);
+ path = gtk_tree_row_reference_get_path (de->sr->rr);
+ if (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
+ {
+ GNUNET_break (0);
+ gtk_tree_path_free (path);
+ return;
+ }
+ gtk_tree_path_free (path);
+ gtk_tree_model_get (tm_old, &iter_old,
+ 0, &meta,
+ 1, &uri,
+ 4, &percent_progress,
+ 5, &percent_availability,
+ 6, &filename,
+ 8, &status_colour,
+ 11, &applicability_rank,
+ 12, &availability_certainty,
+ 13, &availability_rank,
+ 14, &completed,
+ 15, &downloaded_filename,
+ 16, &downloaded_anonymity,
+ -1);
+ GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (uri, de->uri));
+ GNUNET_assert (de->sr->download == de);
+ de->sr->download = NULL;
+
+ /* create the target root */
+ de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri);
+ de->sr->download = de;
+
+ /* get positions of the 'new' root */
+ model = GTK_TREE_MODEL (de->sr->tab->ts);
+ path = gtk_tree_row_reference_get_path (de->sr->rr);
+ if (! gtk_tree_model_get_iter (model, &iter, path))
+ {
+ GNUNET_break (0);
+ gtk_tree_path_free (path);
+ return;
+ }
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_set (de->sr->tab->ts, &iter,
+ 4, percent_progress,
+ 5, percent_availability,
+ 6, filename,
+ 8, status_colour,
+ 11, applicability_rank,
+ 12, availability_certainty,
+ 13, availability_rank,
+ 14, completed,
+ 15, downloaded_filename,
+ 16, downloaded_anonymity,
+ -1);
+ g_free (filename);
+ g_free (downloaded_filename);
+ g_free (status_colour);
+
+ /* finally, move all children over as well */
+ copy_children (tm_old, &iter_old, de->sr->tab, &iter);
+}
+
+
+/**
+ * Moves all of the downloads in the given subtree to the URI tab
+ * and cleans up the state of the other entries from the view.
+ * The subtree itself will be removed from the tree view later.
+ *
+ * @param tm tree model
+ * @param iter parent of the subtree to check
+ */
+static void
+move_downloads_in_subtree (GtkTreeModel *tm,
+ GtkTreeIter *iter)
+{
+ GtkTreeIter child;
+ struct SearchResult *sr;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *uri;
+
+ if (gtk_tree_model_iter_children (tm,
+ iter,
+ &child))
+ {
+ do
+ {
+ gtk_tree_model_get (tm, &child,
+ 0, &meta,
+ 1, &uri,
+ 9, &sr,
+ -1);
+ if (NULL != sr->download)
+ {
+ if (sr->download->is_done == GNUNET_YES)
+ {
+ /* got a finished download, stop it */
+ GNUNET_FS_download_stop (sr->download->dc, GNUNET_YES);
+ }
+ else
+ {
+ /* got an active download, move to URI tab! */
+ download_lost_parent (sr->download);
+ }
+ }
+ GNUNET_assert (NULL == sr->download);
+ move_downloads_in_subtree (tm, &child);
+ GNUNET_FS_uri_destroy (uri);
+ if (NULL != meta)
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ gtk_tree_row_reference_free (sr->rr);
+ GNUNET_free (sr);
+ /* get ready for removal of the tree */
+ gtk_tree_store_set (GTK_TREE_STORE (tm), &child,
+ 0, NULL,
+ 1, NULL,
+ 9, NULL,
+ -1);
+ }
+ while (TRUE == gtk_tree_model_iter_next (tm, &child));
+ }
+}
+
+
+/**
* Free a particular search result and remove the respective
* entries from the respective tree store. This function
* is called when a search is stopped to clean up the state
@@ -869,8 +1129,9 @@
if (meta != NULL)
GNUNET_CONTAINER_meta_data_destroy (meta);
gtk_tree_row_reference_free (sr->rr);
- (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
GNUNET_free (sr);
+ move_downloads_in_subtree (tm, &iter);
+ GNUNET_FS_GTK_remove_treestore_subtree (GTK_TREE_STORE (tm), &iter);
}
@@ -1036,6 +1297,47 @@
/**
+ * Stops all of the downloads in the given subtree.
+ *
+ * @param tm tree model
+ * @param iter parent of the subtree to check
+ * @return GNUNET_YES if there are no active downloads left in the subtree
+ */
+static int
+stop_downloads_in_subtree (GtkTreeModel *tm,
+ GtkTreeIter *iter)
+{
+ GtkTreeIter child;
+ struct SearchResult *sr;
+ int ret;
+
+ ret = GNUNET_YES;
+ if (gtk_tree_model_iter_children (tm,
+ iter,
+ &child))
+ {
+ do
+ {
+ gtk_tree_model_get (tm, &child, 9, &sr, -1);
+ if ( (NULL != sr->download) &&
+ (sr->download->is_done == GNUNET_YES) )
+ {
+ /* got a finished download, stop it */
+ GNUNET_FS_download_stop (sr->download->dc, GNUNET_YES);
+ }
+ if ( (NULL != sr->download) ||
+ (NULL != sr->result) )
+ ret = GNUNET_NO;
+ if (GNUNET_YES != stop_downloads_in_subtree (tm, &child))
+ ret = GNUNET_NO;
+ }
+ while (TRUE == gtk_tree_model_iter_next (tm, &child));
+ }
+ return ret;
+}
+
+
+/**
* User clicked on the 'clean' button of a search tab.
* Stop completed downloads (or those that failed). Should
* iterate over the underlying tree store and stop all
@@ -1057,10 +1359,8 @@
tm = GTK_TREE_MODEL (tab->ts);
if (TRUE != gtk_tree_model_get_iter_first (tm, &iter))
return;
- /* FIXME-BUG: this is a tree, what about cleaning up
- of the children? */
do
- {
+ {
gtk_tree_model_get (tm, &iter, 9, &sr, -1);
if ( (sr->download != NULL) &&
(sr->download->is_done == GNUNET_YES) )
@@ -1069,12 +1369,16 @@
GNUNET_FS_download_stop (sr->download->dc, GNUNET_YES);
}
if ( (NULL == sr->download) &&
- (NULL == sr->result) )
+ (NULL == sr->result) &&
+ (GNUNET_YES == stop_downloads_in_subtree (tm, &iter)) )
{
/* no active download and no associated FS-API search result;
so this must be some left-over entry from an opened
directory; clean it up */
free_search_result (sr);
+ /* the above call clobbered our 'iter', restart from the beginning... */
+ if (TRUE != gtk_tree_model_get_iter_first (tm, &iter))
+ return;
}
}
while (TRUE == gtk_tree_model_iter_next (tm, &iter));
@@ -1822,206 +2126,6 @@
/**
- * Copy all of the children of 'src_iter' from the 'src_model' to
- * become children of 'dst_iter' in the 'dst_model'. The models are
- * both 'GNUNET_GTK_file_sharing_result_tree_store' models.
- *
- * Note that we also need to update the 'struct SearchResult'
- * and (if it exists) the respective 'struct DownloadEntry'
- * to refer to the new model.
- *
- * @param src_model source model
- * @param src_iter parent of the nodes to move
- * @param dst_tab destination tab
- * @param dst_iter new parent of the entries we are moving
- */
-static void
-copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
- struct SearchTab *dst_tab,
- GtkTreeIter * dst_iter)
-{
- GtkTreeIter src_child;
- GtkTreeIter dst_child;
- GtkTreePath *path;
- struct GNUNET_CONTAINER_MetaData *meta;
- struct GNUNET_FS_Uri *uri;
- guint64 filesize, completed;
- GdkPixbuf *preview;
- guint percent_progress;
- guint percent_availability;
- gchar *filename;
- gchar *uri_as_string;
- gchar *status_colour;
- struct SearchResult *search_result_old;
- struct SearchResult *search_result_new;
- gchar *mimetype;
- guint applicability_rank;
- guint availability_certainty;
- gint availability_rank;
- gchar *downloaded_filename;
- gint downloaded_anonymity;
-
- if (! gtk_tree_model_iter_children (src_model, &src_child, src_iter))
- return;
- do
- {
- gtk_tree_model_get (src_model, &src_child,
- 0, &meta,
- 1, &uri,
- 2, &filesize,
- 3, &preview,
- 4, &percent_progress,
- 5, &percent_availability,
- 6, &filename,
- 7, &uri_as_string,
- 8, &status_colour,
- 9, &search_result_old,
- 10, &mimetype,
- 11, &applicability_rank,
- 12, &availability_certainty,
- 13, &availability_rank,
- 14, &completed,
- 15, &downloaded_filename,
- 16, &downloaded_anonymity,
- -1);
- search_result_new = GNUNET_malloc (sizeof (struct SearchResult));
- search_result_new->tab = dst_tab;
- search_result_new->download = search_result_old->download;
- if (NULL != search_result_old->download)
- {
- search_result_old->download = NULL;
- search_result_new->download->sr = search_result_new;
- }
- gtk_tree_store_insert_with_values (dst_tab->ts, &dst_child,
- dst_iter, G_MAXINT,
- 0, GNUNET_CONTAINER_meta_data_duplicate
(meta),
- 1, GNUNET_FS_uri_dup (uri),
- 2, filesize,
- 3, preview,
- 4, percent_progress,
- 5, percent_availability,
- 6, filename,
- 7, uri_as_string,
- 8, status_colour,
- 9, search_result_new,
- 10, mimetype,
- 11, applicability_rank,
- 12, availability_certainty,
- 13, availability_rank,
- 14, completed,
- 15, downloaded_filename,
- 16, downloaded_anonymity,
- -1);
- g_free (filename);
- g_free (downloaded_filename);
- g_free (uri_as_string);
- g_free (status_colour);
- g_free (mimetype);
- if (preview != NULL)
- g_object_unref (preview);
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (dst_tab->ts), &dst_child);
- search_result_new->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL
(dst_tab->ts), path);
- gtk_tree_path_free (path);
-
- copy_children (src_model, &src_child, dst_tab, &dst_child);
- }
- while (gtk_tree_model_iter_next (src_model, &src_child));
-}
-
-
-/**
- * Handle the case where an active download lost its
- * search parent by moving it to the URI tab.
- *
- * @param de download where the parent (i.e. search) was lost
- */
-static void
-download_lost_parent (struct DownloadEntry *de)
-{
- GtkTreeIter iter;
- GtkTreePath *path;
- GtkTreeModel *tm_old;
- GtkTreeIter iter_old;
- GtkTreeModel *model;
- struct GNUNET_CONTAINER_MetaData *meta;
- struct GNUNET_FS_Uri *uri;
- guint64 completed;
- guint percent_progress;
- guint percent_availability;
- gchar *filename;
- gchar *status_colour;
- guint applicability_rank;
- guint availability_certainty;
- gint availability_rank;
- gchar *downloaded_filename;
- gint downloaded_anonymity;
-
- /* find the 'old' root */
- tm_old = GTK_TREE_MODEL (de->sr->tab->ts);
- path = gtk_tree_row_reference_get_path (de->sr->rr);
- if (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
- {
- GNUNET_break (0);
- gtk_tree_path_free (path);
- return;
- }
- gtk_tree_path_free (path);
- gtk_tree_model_get (tm_old, &iter_old,
- 0, &meta,
- 1, &uri,
- 4, &percent_progress,
- 5, &percent_availability,
- 6, &filename,
- 8, &status_colour,
- 11, &applicability_rank,
- 12, &availability_certainty,
- 13, &availability_rank,
- 14, &completed,
- 15, &downloaded_filename,
- 16, &downloaded_anonymity,
- -1);
- GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (uri, de->uri));
- GNUNET_assert (de->sr->download == de);
- de->sr->download = NULL;
-
- /* create the target root */
- de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri);
- de->sr->download = de;
-
- /* get positions of the 'new' root */
- model = GTK_TREE_MODEL (de->sr->tab->ts);
- path = gtk_tree_row_reference_get_path (de->sr->rr);
- if (! gtk_tree_model_get_iter (model, &iter, path))
- {
- GNUNET_break (0);
- gtk_tree_path_free (path);
- return;
- }
- gtk_tree_path_free (path);
-
- gtk_tree_store_set (de->sr->tab->ts, &iter,
- 4, percent_progress,
- 5, percent_availability,
- 6, filename,
- 8, status_colour,
- 11, applicability_rank,
- 12, availability_certainty,
- 13, availability_rank,
- 14, completed,
- 15, downloaded_filename,
- 16, downloaded_anonymity,
- -1);
- g_free (filename);
- g_free (downloaded_filename);
- g_free (status_colour);
-
- /* finally, move all children over as well */
- copy_children (tm_old, &iter_old, de->sr->tab, &iter);
-}
-
-
-/**
* Setup a new download entry.
*
* @param de existing download entry for the download, or NULL (in which case
we create a fresh one)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19697 - gnunet-gtk/src/fs,
gnunet <=