From b9995d7f7363fcf22ec3f1240105d99bef581e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1=D1?= =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Tue, 13 Dec 2011 16:02:39 +0400 Subject: [PATCH 2/3] Various changes * Make preview sensitive (prevent graying-out) * Enable fs persistence and probes (crashes, but who said it was going to be easy? * Make Save File dialog non-blocking --- contrib/gnunet_fs_gtk_download_as_dialog.glade | 106 +++++++++------- contrib/gnunet_fs_gtk_main_window.glade | 17 ++-- src/fs/gnunet-fs-gtk-download.c | 154 +++++++++++++++++------ src/fs/gnunet-fs-gtk.c | 5 +- 4 files changed, 184 insertions(+), 98 deletions(-) diff --git a/contrib/gnunet_fs_gtk_download_as_dialog.glade b/contrib/gnunet_fs_gtk_download_as_dialog.glade index 74aa83f..d15ca72 100644 --- a/contrib/gnunet_fs_gtk_download_as_dialog.glade +++ b/contrib/gnunet_fs_gtk_download_as_dialog.glade @@ -9,6 +9,7 @@ 10 + False True True 5 @@ -17,26 +18,78 @@ True document-save-as dialog - False - False save False + False + True + False 2 + + + True + False + end + + + gtk-cancel + False + True + True + False + True + + + + False + False + 0 + + + + + gtk-save + False + True + True + True + True + True + True + + + + False + False + 1 + + + + + False + True + end + 0 + + True + False True + False _Anonymity: True True GNUNET_GTK_save_as_dialog_anonymity_spin_button + True + True 0 @@ -46,6 +99,10 @@ True False + False + False + True + True GNUNET_GTK_anonymity_adjustment True @@ -59,11 +116,11 @@ _recursive + False True False True False - False True True @@ -81,49 +138,6 @@ 2 - - - True - end - - - gtk-cancel - True - True - False - False - True - - - False - False - 0 - - - - - gtk-save - True - True - True - True - True - False - True - - - False - False - 1 - - - - - False - end - 0 - - diff --git a/contrib/gnunet_fs_gtk_main_window.glade b/contrib/gnunet_fs_gtk_main_window.glade index 5183ba9..37dab80 100644 --- a/contrib/gnunet_fs_gtk_main_window.glade +++ b/contrib/gnunet_fs_gtk_main_window.glade @@ -575,7 +575,6 @@ 128 128 True - False False True Thumbnail associated with the currently selected content @@ -759,6 +758,14 @@ False gtk-index + + vertical + + + + + + @@ -786,14 +793,6 @@ - - vertical - - - - - - diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c index fe239e5..d9451e1 100644 --- a/src/fs/gnunet-fs-gtk-download.c +++ b/src/fs/gnunet-fs-gtk-download.c @@ -27,65 +27,74 @@ #include "gnunet-fs-gtk.h" #include "gnunet-fs-gtk-event_handler.h" +struct dialog_context +{ + GtkBuilder *builder; + GtkWidget *dialog; + gint response; + struct DownloadContext *dc; +}; void -GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) +GNUNET_GTK_save_as_dialog_ok_button_clicked_cb (GtkButton *button, + gpointer user_data) { - GtkWidget *ad; - GtkBuilder *builder; - struct GNUNET_FS_Handle *fs; - uint64_t len; + return; + struct dialog_context *dlc = NULL; + dlc = g_object_get_data (G_OBJECT (button), "dialog-context"); + if (dlc != NULL) + dlc->response = 1; +} + +void +GNUNET_GTK_save_as_dialog_cancel_button_clicked_cb (GtkButton *button, + gpointer user_data) +{ + return; + struct dialog_context *dlc = NULL; + dlc = g_object_get_data (G_OBJECT (button), "dialog-context"); + if (dlc != NULL) + dlc->response = 2; +} + +gboolean +GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget *widget, GdkEvent *event, + gpointer user_data) +{ + GtkBuilder *builder = NULL; + struct dialog_context *dlc = NULL; + struct DownloadContext *dc = NULL; enum GNUNET_FS_DownloadOptions opt; - uint32_t anonymity; + struct GNUNET_FS_Handle *fs; struct DownloadEntry *de; GtkWidget *cb; + uint32_t anonymity; + uint64_t len; - builder = - GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade"); - if (builder == NULL) + builder = GTK_BUILDER (user_data); + dlc = g_object_get_data (G_OBJECT (widget), "dialog-context"); + if (dlc == NULL) { - if (dc->rr != NULL) - gtk_tree_row_reference_free (dc->rr); - GNUNET_free_non_null (dc->mime); - GNUNET_free_non_null (dc->filename); - GNUNET_FS_uri_destroy (dc->uri); - GNUNET_free (dc); - return; + g_object_unref (G_OBJECT (builder)); + return FALSE; } + dc = dlc->dc; cb = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_save_as_recursive_check_button")); - if (GNUNET_FS_meta_data_test_for_directory (dc->meta)) - gtk_widget_set_sensitive (cb, TRUE); - ad = GTK_WIDGET (gtk_builder_get_object - (builder, "GNUNET_GTK_save_as_dialog")); - if (dc->filename != NULL) - { - char buf[1024]; - - if (NULL != getcwd (buf, sizeof (buf))) - { - if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf)) - { - strcat (buf, DIR_SEPARATOR_STR); - strcat (buf, dc->filename); - } - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf); - } - } - if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) + if (GTK_RESPONSE_OK != dlc->response) { - gtk_widget_destroy (ad); - g_object_unref (G_OBJECT (builder)); + g_object_unref (G_OBJECT (dlc->builder)); if (dc->rr != NULL) gtk_tree_row_reference_free (dc->rr); GNUNET_free_non_null (dc->mime); GNUNET_free_non_null (dc->filename); GNUNET_FS_uri_destroy (dc->uri); GNUNET_free (dc); - return; + g_free (dlc); + return FALSE; } GNUNET_free_non_null (dc->filename); - dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad)); + dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlc->dialog)); dc->is_recursive = (TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : @@ -100,7 +109,6 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) (builder, "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); len = GNUNET_FS_uri_chk_get_file_size (dc->uri); - gtk_widget_destroy (ad); g_object_unref (G_OBJECT (builder)); de = GNUNET_malloc (sizeof (struct DownloadEntry)); de->uri = dc->uri; @@ -130,6 +138,72 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) NULL /* parent download ctx */ )); } GNUNET_free (dc); + GNUNET_free (dlc); + return FALSE; +} + +void +GNUNET_GTK_save_as_dialog_response_cb (GtkDialog *dialog, + gint response_id, gpointer user_data) +{ + struct dialog_context *dlc = NULL; + dlc = g_object_get_data (G_OBJECT (dialog), "dialog-context"); + if (dlc != NULL) + dlc->response = response_id; + /* dialogs don't get delete-event the way normal windows do, + * call the handler manually + */ + GNUNET_GTK_save_as_dialog_delete_event_cb (GTK_WIDGET (dialog), NULL, user_data); + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + +void +GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) +{ + GtkWidget *ad; + GtkBuilder *builder; + GtkWidget *cb; + struct dialog_context *dlc; + + builder = + GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade"); + if (builder == NULL) + { + if (dc->rr != NULL) + gtk_tree_row_reference_free (dc->rr); + GNUNET_free_non_null (dc->mime); + GNUNET_free_non_null (dc->filename); + GNUNET_FS_uri_destroy (dc->uri); + GNUNET_free (dc); + return; + } + cb = GTK_WIDGET (gtk_builder_get_object + (builder, "GNUNET_GTK_save_as_recursive_check_button")); + if (GNUNET_FS_meta_data_test_for_directory (dc->meta)) + gtk_widget_set_sensitive (cb, TRUE); + ad = GTK_WIDGET (gtk_builder_get_object + (builder, "GNUNET_GTK_save_as_dialog")); + if (dc->filename != NULL) + { + char buf[1024]; + + if (NULL != getcwd (buf, sizeof (buf))) + { + if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf)) + { + strcat (buf, DIR_SEPARATOR_STR); + strcat (buf, dc->filename); + } + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf); + } + } + dlc = g_new0 (struct dialog_context, 1); + dlc->builder = builder; + dlc->dialog = ad; + dlc->response = 0; + dlc->dc = dc; + g_object_set_data (G_OBJECT (ad), "dialog-context", dlc); + gtk_widget_show_all (ad); } /* end of gnunet-fs-gtk-download.c */ diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c index d5a6cb5..aa8d97b 100644 --- a/src/fs/gnunet-fs-gtk.c +++ b/src/fs/gnunet-fs-gtk.c @@ -648,9 +648,8 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml), "gnunet-gtk", &GNUNET_GTK_fs_event_handler, NULL, - GNUNET_FS_FLAGS_NONE - /* fixme later for persistence/probes */ , - /* set other options here later! */ + GNUNET_FS_FLAGS_PERSISTENCE | + GNUNET_FS_FLAGS_DO_PROBES, GNUNET_FS_OPTIONS_END); if (fs != NULL) { -- 1.7.4