From 9e30fe0be68b1c0d446fee8860e4773bf836d372 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 4 Feb 2012 20:26:25 +0000 Subject: -fixes --- src/fs/gnunet-fs-gtk_download-save-as.c | 3 +- src/fs/gnunet-fs-gtk_event-handler.c | 96 +++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/fs/gnunet-fs-gtk_download-save-as.c b/src/fs/gnunet-fs-gtk_download-save-as.c index 8e3cbc5f..41b00216 100644 --- a/src/fs/gnunet-fs-gtk_download-save-as.c +++ b/src/fs/gnunet-fs-gtk_download-save-as.c @@ -160,6 +160,7 @@ GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, (dlc->builder, "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); gtk_widget_destroy (GTK_WIDGET (dialog)); + /* we were successful, do not remove the directory (if we created one) */ GNUNET_free_non_null (dlc->dirname); dlc->dirname = NULL; clean_up_download_as_context (dlc); @@ -259,7 +260,7 @@ GNUNET_FS_GTK_download_context_start_download (struct DownloadEntry *de) if (de->is_recursive) opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; len = GNUNET_FS_uri_chk_get_file_size (de->uri); - if (NULL != de->sr) + if (NULL != de->sr->result) { GNUNET_break (NULL != GNUNET_FS_download_start_from_search (fs, diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index 43ff0844..ab1fea71 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c @@ -206,13 +206,17 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, gtk_tree_model_get (tm, iter, 0, &meta, 15, &local_filename, 16, &downloaded_anonymity, - -1); - if ( (NULL != local_filename) && (GNUNET_YES == top) ) - *local_parents = GNUNET_YES; - if ( (NULL == local_filename) && (GNUNET_NO == top) ) - *local_parents = GNUNET_NO; - if ( (downloaded_anonymity != -1) && (*anonymity == -1) && (GNUNET_NO == top) ) - *anonymity = downloaded_anonymity; + -1); + if (GNUNET_NO == top) + { + if (NULL != local_filename) + *local_parents = GNUNET_YES; + else + *local_parents = GNUNET_NO; + if ( (downloaded_anonymity != -1) && + (*anonymity == -1) ) + *anonymity = downloaded_anonymity; + } if (gtk_tree_model_iter_parent (tm, &parent, iter)) { have_a_parent = GNUNET_YES; @@ -224,8 +228,6 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, { have_a_parent = GNUNET_NO; dirname = NULL; - if (GNUNET_NO == top) - *local_parents = GNUNET_NO; } if (local_filename == NULL) { @@ -242,7 +244,7 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, */ if ( (NULL == dirname) && (GNUNET_NO == have_a_parent)) { - /* This is the ealderlest parent directory. Use absolute path. */ + /* This is the root. Use absolute path. */ basename = (const char *) local_filename; *filename_is_absolute = GNUNET_YES; } @@ -284,12 +286,14 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, * @param path path selecting which entry we want to download * @param tab the search tab where the user triggered the download request * @param is_recursive was the request for a recursive download? + * @param save_as force opening the 'save as' dialog? */ static void start_download (GtkTreeView *tree_view, GtkTreePath *path, struct SearchTab *tab, - int is_recursive) + int is_recursive, + int save_as) { GtkTreeModel *tm; GtkTreeIter iter; @@ -396,10 +400,13 @@ start_download (GtkTreeView *tree_view, de->anonymity = anonymity; de->is_recursive = is_recursive; de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta); + if (save_as) + have_a_suggestion = GNUNET_NO; fprintf (stderr, "lp %d, have-sug: %d\n", local_parents, have_a_suggestion); + if ( (GNUNET_YES == local_parents) && (GNUNET_YES == have_a_suggestion) ) /* Skip the dialog, call directly */ @@ -444,18 +451,19 @@ GNUNET_FS_GTK_search_treeview_row_activated (GtkTreeView * tree_view, { struct SearchTab *tab = user_data; - start_download (tree_view, path, tab, GNUNET_NO); + start_download (tree_view, path, tab, GNUNET_NO, GNUNET_NO); } /** * "Download" was selected in the current search context menu. * - * @param item the 'download' menu item - * @parma user_data the 'struct DownloadEntry' to download. + * @param is_recursive was this the 'recursive' option? + * @parma save_as was this the 'save as' option? */ static void -start_download_ctx_menu (GtkMenuItem *item, gpointer user_data) +start_download_ctx_menu_helper (int is_recursive, + int save_as) { GtkTreePath *path; GtkTreeView *tv; @@ -471,38 +479,50 @@ start_download_ctx_menu (GtkMenuItem *item, gpointer user_data) tv = GTK_TREE_VIEW (gtk_builder_get_object (current_context_search_tab->builder, "_search_result_frame")); - start_download (tv, path, current_context_search_tab, GNUNET_NO); + start_download (tv, path, current_context_search_tab, + is_recursive, + save_as); gtk_tree_path_free (path); current_context_search_tab = NULL; } +/** + * "Download" was selected in the current search context menu. + * + * @param item the 'download' menu item + * @parma user_data FIXME + */ +static void +start_download_ctx_menu (GtkMenuItem *item, gpointer user_data) +{ + start_download_ctx_menu_helper (GNUNET_NO, GNUNET_NO); +} + + /** * "Download recursively" was selected in the current search context menu. * * @param item the 'download recursively' menu item - * @parma user_data the 'struct DownloadEntry' to download. + * @parma user_data FIXME */ static void start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data) { - GtkTreePath *path; - GtkTreeView *tv; + start_download_ctx_menu_helper (GNUNET_YES, GNUNET_NO); +} - if (current_context_row_reference == NULL) - { - GNUNET_break (0); - return; - } - path = gtk_tree_row_reference_get_path (current_context_row_reference); - gtk_tree_row_reference_free (current_context_row_reference); - current_context_row_reference = NULL; - tv = GTK_TREE_VIEW (gtk_builder_get_object - (current_context_search_tab->builder, - "_search_result_frame")); - start_download (tv, path, current_context_search_tab, GNUNET_YES); - gtk_tree_path_free (path); - current_context_search_tab = NULL; + +/** + * "Download as..." was selected in the current search context menu. + * + * @param item the 'download as...' menu item + * @parma user_data FIXME + */ +static void +start_download_as_ctx_menu (GtkMenuItem *item, gpointer user_data) +{ + start_download_ctx_menu_helper (GNUNET_NO, GNUNET_YES); } @@ -643,6 +663,16 @@ search_list_popup (GtkTreeModel *tm, TRUE); gtk_widget_show (child); gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); + + + child = gtk_menu_item_new_with_label (_("Download _as...")); + g_signal_connect (child, "activate", + G_CALLBACK (start_download_as_ctx_menu), NULL); + gtk_label_set_use_underline (GTK_LABEL + (gtk_bin_get_child (GTK_BIN (child))), + TRUE); + gtk_widget_show (child); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); } if ( (NULL != sr->download) && (GNUNET_YES != sr->download->is_done) ) -- cgit v1.2.3