diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-download.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-download.c | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c index 61b34419..05a5ae95 100644 --- a/src/fs/gnunet-fs-gtk-download.c +++ b/src/fs/gnunet-fs-gtk-download.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -27,7 +27,7 @@ | |||
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 | ||
30 | struct dialog_context | 30 | struct DownloadAsDialogContext |
31 | { | 31 | { |
32 | GtkBuilder *builder; | 32 | GtkBuilder *builder; |
33 | GtkWidget *dialog; | 33 | GtkWidget *dialog; |
@@ -36,12 +36,27 @@ struct dialog_context | |||
36 | }; | 36 | }; |
37 | 37 | ||
38 | 38 | ||
39 | static void | ||
40 | free_download_context (struct DownloadContext *dc) | ||
41 | { | ||
42 | if (NULL != dc->rr) | ||
43 | gtk_tree_row_reference_free (dc->rr); | ||
44 | GNUNET_free_non_null (dc->mime); | ||
45 | GNUNET_free_non_null (dc->filename); | ||
46 | if (NULL != dc->meta) | ||
47 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | ||
48 | if (NULL != dc->uri) | ||
49 | GNUNET_FS_uri_destroy (dc->uri); | ||
50 | GNUNET_free (dc); | ||
51 | } | ||
52 | |||
53 | |||
39 | gboolean | 54 | gboolean |
40 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | 55 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, |
41 | gpointer user_data) | 56 | gpointer user_data) |
42 | { | 57 | { |
58 | struct DownloadAsDialogContext *dlc = user_data; | ||
43 | GtkBuilder *builder; | 59 | GtkBuilder *builder; |
44 | struct dialog_context *dlc; | ||
45 | struct DownloadContext *dc; | 60 | struct DownloadContext *dc; |
46 | enum GNUNET_FS_DownloadOptions opt; | 61 | enum GNUNET_FS_DownloadOptions opt; |
47 | struct GNUNET_FS_Handle *fs; | 62 | struct GNUNET_FS_Handle *fs; |
@@ -50,26 +65,20 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
50 | uint32_t anonymity; | 65 | uint32_t anonymity; |
51 | uint64_t len; | 66 | uint64_t len; |
52 | 67 | ||
53 | builder = GTK_BUILDER (user_data); | ||
54 | dlc = g_object_get_data (G_OBJECT (widget), "dialog-context"); | ||
55 | if (dlc == NULL) | 68 | if (dlc == NULL) |
56 | { | 69 | { |
57 | g_object_unref (G_OBJECT (builder)); | 70 | GNUNET_break (0); |
58 | return FALSE; | 71 | return FALSE; |
59 | } | 72 | } |
73 | builder = dlc->builder; | ||
60 | dc = dlc->dc; | 74 | dc = dlc->dc; |
61 | cb = GTK_WIDGET (gtk_builder_get_object | 75 | cb = GTK_WIDGET (gtk_builder_get_object |
62 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); | 76 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); |
63 | if (GTK_RESPONSE_OK != dlc->response) | 77 | if (GTK_RESPONSE_OK != dlc->response) |
64 | { | 78 | { |
79 | free_download_context (dc); | ||
65 | g_object_unref (G_OBJECT (dlc->builder)); | 80 | g_object_unref (G_OBJECT (dlc->builder)); |
66 | if (dc->rr != NULL) | 81 | GNUNET_free (dlc); |
67 | gtk_tree_row_reference_free (dc->rr); | ||
68 | GNUNET_free_non_null (dc->mime); | ||
69 | GNUNET_free_non_null (dc->filename); | ||
70 | GNUNET_FS_uri_destroy (dc->uri); | ||
71 | GNUNET_free (dc); | ||
72 | g_free (dlc); | ||
73 | return FALSE; | 82 | return FALSE; |
74 | } | 83 | } |
75 | GNUNET_free_non_null (dc->filename); | 84 | GNUNET_free_non_null (dc->filename); |
@@ -90,9 +99,12 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
90 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); | 99 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); |
91 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); | 100 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); |
92 | g_object_unref (G_OBJECT (builder)); | 101 | g_object_unref (G_OBJECT (builder)); |
102 | |||
93 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | 103 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); |
94 | de->uri = dc->uri; | 104 | de->uri = dc->uri; |
105 | dc->uri = NULL; | ||
95 | de->meta = dc->meta; | 106 | de->meta = dc->meta; |
107 | dc->meta = NULL; | ||
96 | if (dc->rr != NULL) | 108 | if (dc->rr != NULL) |
97 | { | 109 | { |
98 | de->rr = dc->rr; | 110 | de->rr = dc->rr; |
@@ -117,18 +129,18 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
117 | len, anonymity, opt, de, | 129 | len, anonymity, opt, de, |
118 | NULL /* parent download ctx */ )); | 130 | NULL /* parent download ctx */ )); |
119 | } | 131 | } |
120 | GNUNET_free (dc); | 132 | free_download_context (dc); |
121 | GNUNET_free (dlc); | 133 | GNUNET_free (dlc); |
122 | return FALSE; | 134 | return FALSE; |
123 | } | 135 | } |
124 | 136 | ||
137 | |||
125 | void | 138 | void |
126 | GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, | 139 | GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, |
127 | gpointer user_data) | 140 | gpointer user_data) |
128 | { | 141 | { |
129 | struct dialog_context *dlc; | 142 | struct DownloadAsDialogContext *dlc = user_data; |
130 | 143 | ||
131 | dlc = g_object_get_data (G_OBJECT (dialog), "dialog-context"); | ||
132 | if (dlc != NULL) | 144 | if (dlc != NULL) |
133 | dlc->response = response_id; | 145 | dlc->response = response_id; |
134 | /* dialogs don't get delete-event the way normal windows do, | 146 | /* dialogs don't get delete-event the way normal windows do, |
@@ -139,24 +151,24 @@ GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, | |||
139 | gtk_widget_destroy (GTK_WIDGET (dialog)); | 151 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
140 | } | 152 | } |
141 | 153 | ||
154 | |||
142 | void | 155 | void |
143 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | 156 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) |
144 | { | 157 | { |
145 | GtkWidget *ad; | 158 | GtkWidget *ad; |
146 | GtkBuilder *builder; | 159 | GtkBuilder *builder; |
147 | GtkWidget *cb; | 160 | GtkWidget *cb; |
148 | struct dialog_context *dlc; | 161 | struct DownloadAsDialogContext *dlc; |
149 | 162 | ||
163 | dlc = GNUNET_malloc (sizeof (struct DownloadAsDialogContext)); | ||
150 | builder = | 164 | builder = |
151 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade"); | 165 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade", |
166 | dlc); | ||
152 | if (builder == NULL) | 167 | if (builder == NULL) |
153 | { | 168 | { |
154 | if (dc->rr != NULL) | 169 | GNUNET_break (0); |
155 | gtk_tree_row_reference_free (dc->rr); | 170 | free_download_context (dc); |
156 | GNUNET_free_non_null (dc->mime); | 171 | GNUNET_free (dlc); |
157 | GNUNET_free_non_null (dc->filename); | ||
158 | GNUNET_FS_uri_destroy (dc->uri); | ||
159 | GNUNET_free (dc); | ||
160 | return; | 172 | return; |
161 | } | 173 | } |
162 | cb = GTK_WIDGET (gtk_builder_get_object | 174 | cb = GTK_WIDGET (gtk_builder_get_object |
@@ -166,26 +178,11 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
166 | ad = GTK_WIDGET (gtk_builder_get_object | 178 | ad = GTK_WIDGET (gtk_builder_get_object |
167 | (builder, "GNUNET_GTK_save_as_dialog")); | 179 | (builder, "GNUNET_GTK_save_as_dialog")); |
168 | if (dc->filename != NULL) | 180 | if (dc->filename != NULL) |
169 | { | 181 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), dc->filename); |
170 | char buf[FILENAME_MAX]; | ||
171 | |||
172 | if (NULL != getcwd (buf, sizeof (buf))) | ||
173 | { | ||
174 | if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf)) | ||
175 | { | ||
176 | strcat (buf, DIR_SEPARATOR_STR); | ||
177 | strcat (buf, dc->filename); | ||
178 | } | ||
179 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf); | ||
180 | } | ||
181 | } | ||
182 | dlc = g_new0 (struct dialog_context, 1); | ||
183 | |||
184 | dlc->builder = builder; | 182 | dlc->builder = builder; |
185 | dlc->dialog = ad; | 183 | dlc->dialog = ad; |
186 | dlc->response = 0; | 184 | dlc->response = 0; |
187 | dlc->dc = dc; | 185 | dlc->dc = dc; |
188 | g_object_set_data (G_OBJECT (ad), "dialog-context", dlc); | ||
189 | gtk_window_present (GTK_WINDOW (ad)); | 186 | gtk_window_present (GTK_WINDOW (ad)); |
190 | } | 187 | } |
191 | 188 | ||