From fef3bb3b03d2efba0e93eaee2c16ea32379cddab Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 27 Jun 2010 11:14:37 +0000 Subject: handling lost parent --- contrib/open_url_dialog.glade | 24 ++-- contrib/search_tab.glade | 240 +++++++++++++++++++++------------------ src/fs_event_handler.c | 158 ++++++++++++++++++++------ src/fs_event_handler.h | 16 +++ src/main_window_open_directory.c | 11 ++ 5 files changed, 296 insertions(+), 153 deletions(-) diff --git a/contrib/open_url_dialog.glade b/contrib/open_url_dialog.glade index 64cecacb..4717ef9e 100644 --- a/contrib/open_url_dialog.glade +++ b/contrib/open_url_dialog.glade @@ -2,9 +2,19 @@ + + True + gtk-execute + + + 100000 + 1 + 1 + 10 + 500 - 350 + 100 5 Download from URI True @@ -77,6 +87,8 @@ + False + False 3 @@ -138,14 +150,4 @@ GNUNET_GTK_open_url_dialog_execute_button - - 100000 - 1 - 1 - 10 - - - True - gtk-execute - diff --git a/contrib/search_tab.glade b/contrib/search_tab.glade index 18497adb..00423c5f 100644 --- a/contrib/search_tab.glade +++ b/contrib/search_tab.glade @@ -2,37 +2,105 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + True + 5 + + + 30 + True + query + + + False + 5 + 0 + + + + + True + True + False + + + True + gtk-media-play + 2 + + + + + False + False + 1 + + + + + True + True + True + False + + + True + gtk-media-pause + 2 + + + + + False + False + 2 + + + + + False + True + True + False + + + True + gtk-clear + + + + + False + False + 5 + 3 + + + + + True + True + True + False + half + + + True + gtk-close + 2 + + + + + False + False + 4 + + + + You should never see this @@ -132,84 +200,36 @@ - - - - True - 5 - - - 30 - True - query - - - False - 5 - 0 - - - - - True - True - True - False - half - - - True - gtk-close - 2 - - - - - False - False - 1 - - - - - True - True - False - - - True - gtk-media-play - 2 - - - - - False - False - 2 - - - - - True - True - True - False - - - True - gtk-media-pause - 2 - - - - - False - False - 3 - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fs_event_handler.c b/src/fs_event_handler.c index b4cc9d13..f37d575e 100644 --- a/src/fs_event_handler.c +++ b/src/fs_event_handler.c @@ -25,6 +25,7 @@ */ #include "common.h" #include "download.h" +#include "fs_event_handler.h" #include @@ -214,6 +215,39 @@ mark_publish_progress (struct PublishEntry *pe, } +/** + * Handle the case where an active download lost its + * search parent by moving it to the URI tab. + */ +static struct DownloadEntry * +download_lost_parent (struct DownloadEntry *de, + uint64_t size, + uint64_t completed, + int is_active) +{ + GtkTreeIter iter; + + gtk_tree_row_reference_free (de->rr); + de->sr = NULL; + de->ts = GNUNET_GTK_add_to_uri_tab (&iter, + de->meta, + de->uri); + mark_download_progress (de, size, completed); + if (size > completed) + { + if (is_active) + change_download_colour (de, "yellow"); + else + change_download_colour (de, "blue"); + } + else + { + change_download_colour (de, "green"); + } + return de; +} + + /** * Setup a new download entry. * @@ -259,10 +293,14 @@ setup_download (struct DownloadEntry *pde, } else { - /* FIXME: find or create tab with just download results and - create new entry! */ - GNUNET_break (0); - return de; + de->ts = GNUNET_GTK_add_to_uri_tab (&iter, + meta, + uri); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), + &iter); + de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts), + path); + gtk_tree_path_free (path); } path = gtk_tree_row_reference_get_path (de->rr); if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), @@ -627,8 +665,7 @@ continue_search (GtkButton *button, */ static struct SearchTab * setup_search (struct GNUNET_FS_SearchContext *sc, - const struct GNUNET_FS_Uri *query, - uint32_t anonymity) + const struct GNUNET_FS_Uri *query) { struct SearchTab *tab; GtkTreeView *tv; @@ -641,10 +678,17 @@ setup_search (struct GNUNET_FS_SearchContext *sc, search_tab_tail, tab); tab->sc = sc; - if (GNUNET_FS_uri_test_ksk (query)) - tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query); + if (query == NULL) + { + tab->query_txt = GNUNET_strdup ("*"); + } else - tab->query_txt = GNUNET_FS_uri_to_string (query); + { + if (GNUNET_FS_uri_test_ksk (query)) + tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query); + else + tab->query_txt = GNUNET_FS_uri_to_string (query); + } tab->builder = GNUNET_GTK_get_new_builder ("search_tab.glade"); /* load frame */ @@ -709,18 +753,16 @@ setup_search (struct GNUNET_FS_SearchContext *sc, } - static struct SearchResult * -process_search_result (void *cls, - void *parent, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_SearchResult *result, - uint32_t applicability_rank) +add_search_result (struct SearchTab *tab, + GtkTreeIter *iter, + void *parent, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_SearchResult *result, + uint32_t applicability_rank) { - struct SearchTab *tab = cls; struct SearchResult *sr; - GtkTreeIter iter; GtkTreePath *tp; GtkTreeStore *ts; char *desc; @@ -761,7 +803,7 @@ process_search_result (void *cls, ts = GTK_TREE_STORE (gtk_builder_get_object (tab->builder, "GNUNET_GTK_file_sharing_result_tree_store")); gtk_tree_store_insert_with_values (ts, - &iter, + iter, NULL, G_MAXINT, 0, GNUNET_CONTAINER_meta_data_duplicate (meta), @@ -780,14 +822,13 @@ process_search_result (void *cls, 13, 0 /* avail-rank */, -1); tab->num_results++; - update_search_label (tab); if (pixbuf != NULL) g_object_unref (pixbuf); GNUNET_free (uris); GNUNET_free (desc); GNUNET_free_non_null (mime); tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), - &iter); + iter); sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp); gtk_tree_path_free (tp); @@ -795,6 +836,65 @@ process_search_result (void *cls, } +static struct SearchResult * +process_search_result (void *cls, + void *parent, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_SearchResult *result, + uint32_t applicability_rank) +{ + struct SearchTab *tab = cls; + struct SearchResult *sr; + GtkTreeIter iter; + + sr = add_search_result (tab, &iter, parent, uri, + meta, result, applicability_rank); + update_search_label (tab); + return sr; +} + + +/** + * Setup a new top-level entry in the URI tab. If necessary, create + * the URI tab first. + * + * @param iter set to the new entry + * @param meta metadata for the new entry + * @param uri URI for the new entry + * @return NULL on error, otherwise tree store matching iter + */ +GtkTreeStore * +GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri) +{ + struct SearchTab *utab; + struct SearchResult *sr; + + utab = search_tab_head; + while (utab != NULL) + { + if (utab->sc != NULL) + utab = utab->next; + } + if (utab == NULL) + { + utab = setup_search (NULL, NULL); + } + else + { + /* FIXME: make 'utab' the current page */ + GNUNET_break (0); + } + sr = add_search_result (utab, iter, + NULL, uri, meta, + NULL, 0); + return GTK_TREE_STORE (gtk_builder_get_object (utab->builder, + "GNUNET_GTK_file_sharing_result_tree_store")); +} + + static struct SearchResult * update_search_result (struct SearchResult *sr, const struct GNUNET_CONTAINER_MetaData *meta, @@ -1107,15 +1207,10 @@ GNUNET_GTK_fs_event_handler (void *cls, return change_download_colour (info->value.download.cctx, "blue"); case GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT: - /* FIXME: keep entry (especially if download is not - done!?) ? */ - /* FIXME: if we do not stop here, we currently crash on exit; - I think this is because somehow fs-lib fails to handle - LOST_PARENT correctly and does not generate the necessary - suspend event in this case */ - stop_download (info->value.download.cctx, - GNUNET_YES); - break; + return download_lost_parent (info->value.download.cctx, + info->value.download.size, + info->value.download.completed, + info->value.download.is_active); case GNUNET_FS_STATUS_SEARCH_START: fprintf (stderr, "Search started!\n"); @@ -1125,8 +1220,7 @@ GNUNET_GTK_fs_event_handler (void *cls, break; } return setup_search (info->value.search.sc, - info->value.search.query, - info->value.search.anonymity); + info->value.search.query); case GNUNET_FS_STATUS_SEARCH_RESUME: GNUNET_break (0); break; diff --git a/src/fs_event_handler.h b/src/fs_event_handler.h index 2643994e..d883545f 100644 --- a/src/fs_event_handler.h +++ b/src/fs_event_handler.h @@ -25,6 +25,22 @@ */ #include "common.h" + +/** + * Setup a new top-level entry in the URI tab. If necessary, create + * the URI tab first. + * + * @param iter set to the new entry + * @param meta metadata for the new entry + * @param uri URI for the new entry + * @return NULL on error, otherwise tree store matching iter + */ +GtkTreeStore * +GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri); + + /** * Notification of FS to a client about the progress of an * operation. Callbacks of this type will be used for uploads, diff --git a/src/main_window_open_directory.c b/src/main_window_open_directory.c index cd67adba..5384222d 100644 --- a/src/main_window_open_directory.c +++ b/src/main_window_open_directory.c @@ -53,8 +53,19 @@ GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy, filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad)); gtk_widget_destroy (ad); g_object_unref (G_OBJECT (builder)); +#if 0 + open_directory; + uri = compute_uri_from_file (filename); + meta = new; + meta_make_directory (); + meta_add (filename); + ts = setup_entry_in_uri_tab (&iter, + meta, + uri); + directory_iterate (add_child, ts, &iter); GNUNET_break (0); +#endif g_free (filename); } -- cgit v1.2.3