diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk_download-save-as.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk_download-save-as.c | 139 |
1 files changed, 56 insertions, 83 deletions
diff --git a/src/fs/gnunet-fs-gtk_download-save-as.c b/src/fs/gnunet-fs-gtk_download-save-as.c index 8cf3b1de..63b711cd 100644 --- a/src/fs/gnunet-fs-gtk_download-save-as.c +++ b/src/fs/gnunet-fs-gtk_download-save-as.c | |||
@@ -34,10 +34,10 @@ struct DownloadAsDialogContext | |||
34 | { | 34 | { |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Download context for which this dialog determines the | 37 | * Download entry for which this dialog determines the |
38 | * filename (and other options). | 38 | * filename (and other options). |
39 | */ | 39 | */ |
40 | struct DownloadContext *dc; | 40 | struct DownloadEntry *de; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Builder for the dialog. | 43 | * Builder for the dialog. |
@@ -53,21 +53,24 @@ struct DownloadAsDialogContext | |||
53 | 53 | ||
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Free resources associated with the given download context. | 56 | * Free resources associated with the given download entry. |
57 | * | 57 | * |
58 | * @param dc context to free | 58 | * @param de context to free |
59 | */ | 59 | */ |
60 | static void | 60 | void |
61 | save_as_dialog_free_download_context (struct DownloadContext *dc) | 61 | GNUNET_FS_GTK_free_download_entry (struct DownloadEntry *de) |
62 | { | 62 | { |
63 | if (NULL != dc->rr) | 63 | GNUNET_assert (NULL == de->dc); |
64 | gtk_tree_row_reference_free (dc->rr); | 64 | if (NULL != de->sr) |
65 | GNUNET_free_non_null (dc->filename); | 65 | { |
66 | if (NULL != dc->meta) | 66 | GNUNET_assert (de->sr->download == de); |
67 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | 67 | de->sr->download = NULL; |
68 | if (NULL != dc->uri) | 68 | } |
69 | GNUNET_FS_uri_destroy (dc->uri); | 69 | GNUNET_free_non_null (de->filename); |
70 | GNUNET_free (dc); | 70 | if (NULL != de->meta) |
71 | GNUNET_CONTAINER_meta_data_destroy (de->meta); | ||
72 | GNUNET_FS_uri_destroy (de->uri); | ||
73 | GNUNET_free (de); | ||
71 | } | 74 | } |
72 | 75 | ||
73 | 76 | ||
@@ -87,7 +90,7 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
87 | { | 90 | { |
88 | struct DownloadAsDialogContext *dlc = user_data; | 91 | struct DownloadAsDialogContext *dlc = user_data; |
89 | 92 | ||
90 | save_as_dialog_free_download_context (dlc->dc); | 93 | GNUNET_FS_GTK_free_download_entry (dlc->de); |
91 | g_object_unref (G_OBJECT (dlc->builder)); | 94 | g_object_unref (G_OBJECT (dlc->builder)); |
92 | GNUNET_free (dlc); | 95 | GNUNET_free (dlc); |
93 | return FALSE; | 96 | return FALSE; |
@@ -108,37 +111,36 @@ GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, | |||
108 | gpointer user_data) | 111 | gpointer user_data) |
109 | { | 112 | { |
110 | struct DownloadAsDialogContext *dlc = user_data; | 113 | struct DownloadAsDialogContext *dlc = user_data; |
111 | struct DownloadContext *dc; | 114 | struct DownloadEntry *de; |
112 | GtkToggleButton *cb; | 115 | GtkToggleButton *cb; |
113 | 116 | ||
114 | dc = dlc->dc; | 117 | de = dlc->de; |
115 | |||
116 | if (GTK_RESPONSE_OK != response_id) | 118 | if (GTK_RESPONSE_OK != response_id) |
117 | { | 119 | { |
118 | save_as_dialog_free_download_context (dc); | 120 | GNUNET_FS_GTK_free_download_entry (de); |
119 | gtk_widget_destroy (GTK_WIDGET (dialog)); | 121 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
120 | g_object_unref (G_OBJECT (dlc->builder)); | 122 | g_object_unref (G_OBJECT (dlc->builder)); |
121 | GNUNET_free (dlc); | 123 | GNUNET_free (dlc); |
122 | return; | 124 | return; |
123 | } | 125 | } |
124 | GNUNET_free_non_null (dc->filename); | 126 | GNUNET_free_non_null (de->filename); |
125 | dc->filename = | 127 | de->filename = |
126 | GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dlc->dialog)); | 128 | GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dlc->dialog)); |
127 | cb = GTK_TOGGLE_BUTTON (gtk_builder_get_object | 129 | cb = GTK_TOGGLE_BUTTON (gtk_builder_get_object |
128 | (dlc->builder, "GNUNET_GTK_save_as_recursive_check_button")); | 130 | (dlc->builder, "GNUNET_GTK_save_as_recursive_check_button")); |
129 | dc->is_recursive = | 131 | de->is_recursive = |
130 | (TRUE == | 132 | (TRUE == |
131 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : | 133 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : |
132 | GNUNET_NO; | 134 | GNUNET_NO; |
133 | dc->anonymity = | 135 | de->anonymity = |
134 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | 136 | (uint32_t) gtk_spin_button_get_value (GTK_SPIN_BUTTON |
135 | (gtk_builder_get_object | 137 | (gtk_builder_get_object |
136 | (dlc->builder, | 138 | (dlc->builder, |
137 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); | 139 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); |
138 | gtk_widget_destroy (GTK_WIDGET (dialog)); | 140 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
139 | g_object_unref (G_OBJECT (dlc->builder)); | 141 | g_object_unref (G_OBJECT (dlc->builder)); |
140 | GNUNET_free (dlc); | 142 | GNUNET_free (dlc); |
141 | GNUNET_FS_GTK_download_context_start_download (dc); | 143 | GNUNET_FS_GTK_download_context_start_download (de); |
142 | } | 144 | } |
143 | 145 | ||
144 | 146 | ||
@@ -147,23 +149,23 @@ GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, | |||
147 | * continutation when the dialog is complete. Will release the 'dc' | 149 | * continutation when the dialog is complete. Will release the 'dc' |
148 | * resources if the dialog is cancelled. | 150 | * resources if the dialog is cancelled. |
149 | * | 151 | * |
150 | * @param dc download context for the file/directory | 152 | * @param de download context for the file/directory |
151 | */ | 153 | */ |
152 | void | 154 | void |
153 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | 155 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadEntry *de) |
154 | { | 156 | { |
155 | struct DownloadAsDialogContext *dlc; | 157 | struct DownloadAsDialogContext *dlc; |
156 | GtkWidget *cb; | 158 | GtkWidget *cb; |
157 | 159 | ||
158 | dlc = GNUNET_malloc (sizeof (struct DownloadAsDialogContext)); | 160 | dlc = GNUNET_malloc (sizeof (struct DownloadAsDialogContext)); |
159 | dlc->dc = dc; | 161 | dlc->de = de; |
160 | dlc->builder = | 162 | dlc->builder = |
161 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade", | 163 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade", |
162 | dlc); | 164 | dlc); |
163 | if (NULL == dlc->builder) | 165 | if (NULL == dlc->builder) |
164 | { | 166 | { |
165 | GNUNET_break (0); | 167 | GNUNET_break (0); |
166 | save_as_dialog_free_download_context (dc); | 168 | GNUNET_FS_GTK_free_download_entry (de); |
167 | GNUNET_free (dlc); | 169 | GNUNET_free (dlc); |
168 | return; | 170 | return; |
169 | } | 171 | } |
@@ -174,18 +176,18 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
174 | set recursive 'default' value based on what the 'dc' tells us */ | 176 | set recursive 'default' value based on what the 'dc' tells us */ |
175 | cb = GTK_WIDGET (gtk_builder_get_object | 177 | cb = GTK_WIDGET (gtk_builder_get_object |
176 | (dlc->builder, "GNUNET_GTK_save_as_recursive_check_button")); | 178 | (dlc->builder, "GNUNET_GTK_save_as_recursive_check_button")); |
177 | if (GNUNET_FS_meta_data_test_for_directory (dc->meta)) | 179 | if (GNUNET_FS_meta_data_test_for_directory (de->meta)) |
178 | gtk_widget_set_sensitive (cb, TRUE); | 180 | gtk_widget_set_sensitive (cb, TRUE); |
179 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), | 181 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), |
180 | dc->is_recursive); | 182 | de->is_recursive); |
181 | 183 | ||
182 | /* initialize filename based on filename from 'dc' */ | 184 | /* initialize filename based on filename from 'dc' */ |
183 | if (NULL != dc->filename) | 185 | if (NULL != de->filename) |
184 | { | 186 | { |
185 | char *dirname; | 187 | char *dirname; |
186 | char *basename; | 188 | char *basename; |
187 | 189 | ||
188 | dirname = GNUNET_strdup (dc->filename); | 190 | dirname = GNUNET_strdup (de->filename); |
189 | basename = (char *) GNUNET_STRINGS_get_short_name (dirname); | 191 | basename = (char *) GNUNET_STRINGS_get_short_name (dirname); |
190 | /* basename now points into 'dirname'; cut 'dirname' off at the '/' before basename */ | 192 | /* basename now points into 'dirname'; cut 'dirname' off at the '/' before basename */ |
191 | if (basename > dirname) | 193 | if (basename > dirname) |
@@ -194,7 +196,7 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
194 | /* FIXME: remove following lines after testing... */ | 196 | /* FIXME: remove following lines after testing... */ |
195 | fprintf (stderr, | 197 | fprintf (stderr, |
196 | "Splitting `%s' into `%s' + `%s' for file chooser dialog.\n", | 198 | "Splitting `%s' into `%s' + `%s' for file chooser dialog.\n", |
197 | dc->filename, | 199 | de->filename, |
198 | dirname, | 200 | dirname, |
199 | basename); | 201 | basename); |
200 | 202 | ||
@@ -214,74 +216,45 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
214 | * respective tree model and trigger a start of the download using the | 216 | * respective tree model and trigger a start of the download using the |
215 | * FS-API. | 217 | * FS-API. |
216 | * | 218 | * |
217 | * @param dc download context of the download to execute | 219 | * @param de download context of the download to execute |
218 | */ | 220 | */ |
219 | void | 221 | void |
220 | GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc) | 222 | GNUNET_FS_GTK_download_context_start_download (struct DownloadEntry *de) |
221 | { | 223 | { |
222 | enum GNUNET_FS_DownloadOptions opt; | 224 | enum GNUNET_FS_DownloadOptions opt; |
223 | struct GNUNET_FS_Handle *fs; | 225 | struct GNUNET_FS_Handle *fs; |
224 | struct DownloadEntry *de; | ||
225 | uint64_t len; | 226 | uint64_t len; |
226 | GtkTreeIter iter; | ||
227 | GtkTreePath *path; | ||
228 | 227 | ||
229 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | ||
230 | de->uri = dc->uri; | ||
231 | dc->uri = NULL; | ||
232 | de->meta = dc->meta; | ||
233 | de->tab = dc->tab; | ||
234 | dc->meta = NULL; | ||
235 | if (NULL != dc->rr) | ||
236 | { | ||
237 | de->rr = gtk_tree_row_reference_copy (dc->rr); | ||
238 | path = gtk_tree_row_reference_get_path (de->rr); | ||
239 | if ( (NULL != path) && | ||
240 | (gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path)) ) | ||
241 | { | ||
242 | /* Store filename and anonymity as specified by the user. | ||
243 | * These will be re-used when this is a directory, and the user | ||
244 | * downloads its children. | ||
245 | */ | ||
246 | gtk_tree_store_set (de->tab->ts, &iter, 15, dc->filename, 16, dc->anonymity, -1); | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | /* We could not find the referenced row in the search tab; this is | ||
251 | conceivable as the search tab might have been closed by the | ||
252 | user while the 'save as' dialog was open. In this case, this | ||
253 | is equivalent to having no search, so we drop the (now invalid) | ||
254 | 'sr' reference */ | ||
255 | dc->sr = NULL; | ||
256 | } | ||
257 | if (NULL != path) | ||
258 | gtk_tree_path_free (path); | ||
259 | } | ||
260 | fs = GNUNET_FS_GTK_get_fs_handle (); | 228 | fs = GNUNET_FS_GTK_get_fs_handle (); |
261 | opt = GNUNET_FS_DOWNLOAD_OPTION_NONE; | 229 | opt = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
262 | if (dc->is_recursive) | 230 | if (de->is_recursive) |
263 | opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | 231 | opt |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; |
264 | len = GNUNET_FS_uri_chk_get_file_size (de->uri); | 232 | len = GNUNET_FS_uri_chk_get_file_size (de->uri); |
265 | if (NULL != dc->sr) | 233 | if (NULL != de->sr) |
266 | { | 234 | { |
267 | GNUNET_break (NULL != | 235 | GNUNET_break (NULL != |
268 | GNUNET_FS_download_start_from_search (fs, dc->sr, | 236 | GNUNET_FS_download_start_from_search (fs, |
269 | dc->filename, | 237 | de->sr->result, |
238 | de->filename, | ||
270 | NULL /* tempname */ , | 239 | NULL /* tempname */ , |
271 | 0 /* offset */ , | 240 | 0 /* offset */ , |
272 | len, dc->anonymity, opt, | 241 | len, |
242 | de->anonymity, opt, | ||
273 | de)); | 243 | de)); |
274 | } | 244 | } |
275 | else | 245 | else |
276 | { | 246 | { |
277 | GNUNET_break (NULL != | 247 | GNUNET_break (NULL != |
278 | GNUNET_FS_download_start (fs, de->uri, NULL /* meta */ , | 248 | GNUNET_FS_download_start (fs, |
279 | dc->filename, NULL /* tempname */ , | 249 | de->uri, |
250 | de->meta, | ||
251 | de->filename, NULL /* tempname */ , | ||
280 | 0 /* offset */ , | 252 | 0 /* offset */ , |
281 | len, dc->anonymity, opt, de, | 253 | len, |
282 | NULL /* parent download ctx */ )); | 254 | de->anonymity, opt, |
255 | de, | ||
256 | (NULL != de->pde) ? de->pde->dc : NULL)); | ||
283 | } | 257 | } |
284 | save_as_dialog_free_download_context (dc); | ||
285 | } | 258 | } |
286 | 259 | ||
287 | 260 | ||