aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-download.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-download.c')
-rw-r--r--src/fs/gnunet-fs-gtk-download.c154
1 files changed, 114 insertions, 40 deletions
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c
index fe239e5a..d9451e1c 100644
--- a/src/fs/gnunet-fs-gtk-download.c
+++ b/src/fs/gnunet-fs-gtk-download.c
@@ -27,65 +27,74 @@
27#include "gnunet-fs-gtk.h" 27#include "gnunet-fs-gtk.h"
28#include "gnunet-fs-gtk-event_handler.h" 28#include "gnunet-fs-gtk-event_handler.h"
29 29
30struct dialog_context
31{
32 GtkBuilder *builder;
33 GtkWidget *dialog;
34 gint response;
35 struct DownloadContext *dc;
36};
30 37
31void 38void
32GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) 39GNUNET_GTK_save_as_dialog_ok_button_clicked_cb (GtkButton *button,
40 gpointer user_data)
33{ 41{
34 GtkWidget *ad; 42 return;
35 GtkBuilder *builder; 43 struct dialog_context *dlc = NULL;
36 struct GNUNET_FS_Handle *fs; 44 dlc = g_object_get_data (G_OBJECT (button), "dialog-context");
37 uint64_t len; 45 if (dlc != NULL)
46 dlc->response = 1;
47}
48
49void
50GNUNET_GTK_save_as_dialog_cancel_button_clicked_cb (GtkButton *button,
51 gpointer user_data)
52{
53 return;
54 struct dialog_context *dlc = NULL;
55 dlc = g_object_get_data (G_OBJECT (button), "dialog-context");
56 if (dlc != NULL)
57 dlc->response = 2;
58}
59
60gboolean
61GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget *widget, GdkEvent *event,
62 gpointer user_data)
63{
64 GtkBuilder *builder = NULL;
65 struct dialog_context *dlc = NULL;
66 struct DownloadContext *dc = NULL;
38 enum GNUNET_FS_DownloadOptions opt; 67 enum GNUNET_FS_DownloadOptions opt;
39 uint32_t anonymity; 68 struct GNUNET_FS_Handle *fs;
40 struct DownloadEntry *de; 69 struct DownloadEntry *de;
41 GtkWidget *cb; 70 GtkWidget *cb;
71 uint32_t anonymity;
72 uint64_t len;
42 73
43 builder = 74 builder = GTK_BUILDER (user_data);
44 GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade"); 75 dlc = g_object_get_data (G_OBJECT (widget), "dialog-context");
45 if (builder == NULL) 76 if (dlc == NULL)
46 { 77 {
47 if (dc->rr != NULL) 78 g_object_unref (G_OBJECT (builder));
48 gtk_tree_row_reference_free (dc->rr); 79 return FALSE;
49 GNUNET_free_non_null (dc->mime);
50 GNUNET_free_non_null (dc->filename);
51 GNUNET_FS_uri_destroy (dc->uri);
52 GNUNET_free (dc);
53 return;
54 } 80 }
81 dc = dlc->dc;
55 cb = GTK_WIDGET (gtk_builder_get_object 82 cb = GTK_WIDGET (gtk_builder_get_object
56 (builder, "GNUNET_GTK_save_as_recursive_check_button")); 83 (builder, "GNUNET_GTK_save_as_recursive_check_button"));
57 if (GNUNET_FS_meta_data_test_for_directory (dc->meta)) 84 if (GTK_RESPONSE_OK != dlc->response)
58 gtk_widget_set_sensitive (cb, TRUE);
59 ad = GTK_WIDGET (gtk_builder_get_object
60 (builder, "GNUNET_GTK_save_as_dialog"));
61 if (dc->filename != NULL)
62 {
63 char buf[1024];
64
65 if (NULL != getcwd (buf, sizeof (buf)))
66 {
67 if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf))
68 {
69 strcat (buf, DIR_SEPARATOR_STR);
70 strcat (buf, dc->filename);
71 }
72 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf);
73 }
74 }
75 if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad)))
76 { 85 {
77 gtk_widget_destroy (ad); 86 g_object_unref (G_OBJECT (dlc->builder));
78 g_object_unref (G_OBJECT (builder));
79 if (dc->rr != NULL) 87 if (dc->rr != NULL)
80 gtk_tree_row_reference_free (dc->rr); 88 gtk_tree_row_reference_free (dc->rr);
81 GNUNET_free_non_null (dc->mime); 89 GNUNET_free_non_null (dc->mime);
82 GNUNET_free_non_null (dc->filename); 90 GNUNET_free_non_null (dc->filename);
83 GNUNET_FS_uri_destroy (dc->uri); 91 GNUNET_FS_uri_destroy (dc->uri);
84 GNUNET_free (dc); 92 GNUNET_free (dc);
85 return; 93 g_free (dlc);
94 return FALSE;
86 } 95 }
87 GNUNET_free_non_null (dc->filename); 96 GNUNET_free_non_null (dc->filename);
88 dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad)); 97 dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlc->dialog));
89 dc->is_recursive = 98 dc->is_recursive =
90 (TRUE == 99 (TRUE ==
91 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : 100 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)
100 (builder, 109 (builder,
101 "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); 110 "GNUNET_GTK_save_as_dialog_anonymity_spin_button")));
102 len = GNUNET_FS_uri_chk_get_file_size (dc->uri); 111 len = GNUNET_FS_uri_chk_get_file_size (dc->uri);
103 gtk_widget_destroy (ad);
104 g_object_unref (G_OBJECT (builder)); 112 g_object_unref (G_OBJECT (builder));
105 de = GNUNET_malloc (sizeof (struct DownloadEntry)); 113 de = GNUNET_malloc (sizeof (struct DownloadEntry));
106 de->uri = dc->uri; 114 de->uri = dc->uri;
@@ -130,6 +138,72 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
130 NULL /* parent download ctx */ )); 138 NULL /* parent download ctx */ ));
131 } 139 }
132 GNUNET_free (dc); 140 GNUNET_free (dc);
141 GNUNET_free (dlc);
142 return FALSE;
143}
144
145void
146GNUNET_GTK_save_as_dialog_response_cb (GtkDialog *dialog,
147 gint response_id, gpointer user_data)
148{
149 struct dialog_context *dlc = NULL;
150 dlc = g_object_get_data (G_OBJECT (dialog), "dialog-context");
151 if (dlc != NULL)
152 dlc->response = response_id;
153 /* dialogs don't get delete-event the way normal windows do,
154 * call the handler manually
155 */
156 GNUNET_GTK_save_as_dialog_delete_event_cb (GTK_WIDGET (dialog), NULL, user_data);
157 gtk_widget_destroy (GTK_WIDGET (dialog));
158}
159
160void
161GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
162{
163 GtkWidget *ad;
164 GtkBuilder *builder;
165 GtkWidget *cb;
166 struct dialog_context *dlc;
167
168 builder =
169 GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade");
170 if (builder == NULL)
171 {
172 if (dc->rr != NULL)
173 gtk_tree_row_reference_free (dc->rr);
174 GNUNET_free_non_null (dc->mime);
175 GNUNET_free_non_null (dc->filename);
176 GNUNET_FS_uri_destroy (dc->uri);
177 GNUNET_free (dc);
178 return;
179 }
180 cb = GTK_WIDGET (gtk_builder_get_object
181 (builder, "GNUNET_GTK_save_as_recursive_check_button"));
182 if (GNUNET_FS_meta_data_test_for_directory (dc->meta))
183 gtk_widget_set_sensitive (cb, TRUE);
184 ad = GTK_WIDGET (gtk_builder_get_object
185 (builder, "GNUNET_GTK_save_as_dialog"));
186 if (dc->filename != NULL)
187 {
188 char buf[1024];
189
190 if (NULL != getcwd (buf, sizeof (buf)))
191 {
192 if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf))
193 {
194 strcat (buf, DIR_SEPARATOR_STR);
195 strcat (buf, dc->filename);
196 }
197 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf);
198 }
199 }
200 dlc = g_new0 (struct dialog_context, 1);
201 dlc->builder = builder;
202 dlc->dialog = ad;
203 dlc->response = 0;
204 dlc->dc = dc;
205 g_object_set_data (G_OBJECT (ad), "dialog-context", dlc);
206 gtk_widget_show_all (ad);
133} 207}
134 208
135/* end of gnunet-fs-gtk-download.c */ 209/* end of gnunet-fs-gtk-download.c */