aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-04 19:30:06 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-04 19:30:06 +0000
commit283a796b4c7f91e46360ae2984d4bf556ec9111b (patch)
tree262dae8005eb0f1797de9e19a364df6c531c7435
parenta4bea383983ee8bb0bc37a676e215e0ad09df84b (diff)
downloadgnunet-gtk-283a796b4c7f91e46360ae2984d4bf556ec9111b.tar.gz
gnunet-gtk-283a796b4c7f91e46360ae2984d4bf556ec9111b.zip
-simplify data structures by eliminating the DownloadContext -- virtually a full duplicate of the DownloadEntry
-rw-r--r--src/fs/gnunet-fs-gtk_download-save-as.c139
-rw-r--r--src/fs/gnunet-fs-gtk_download-save-as.h73
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c175
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.h65
-rw-r--r--src/fs/gnunet-fs-gtk_open-directory.c2
-rw-r--r--src/fs/gnunet-fs-gtk_open-uri.c10
6 files changed, 193 insertions, 271 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 */
60static void 60void
61save_as_dialog_free_download_context (struct DownloadContext *dc) 61GNUNET_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 */
152void 154void
153GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) 155GNUNET_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 */
219void 221void
220GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc) 222GNUNET_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
diff --git a/src/fs/gnunet-fs-gtk_download-save-as.h b/src/fs/gnunet-fs-gtk_download-save-as.h
index 37a6e3a9..db0f8018 100644
--- a/src/fs/gnunet-fs-gtk_download-save-as.h
+++ b/src/fs/gnunet-fs-gtk_download-save-as.h
@@ -27,62 +27,7 @@
27#define GNUNET_FS_GTK_DOWNLOAD_SAVE_AS_H 27#define GNUNET_FS_GTK_DOWNLOAD_SAVE_AS_H
28 28
29#include "gnunet-fs-gtk_common.h" 29#include "gnunet-fs-gtk_common.h"
30 30#include "gnunet-fs-gtk_event-handler.h"
31
32/**
33 * Information we keep for a download.
34 */
35struct DownloadContext;
36
37
38/**
39 * Information we keep for a download.
40 */
41struct DownloadContext
42{
43 /**
44 * URI for the download.
45 */
46 struct GNUNET_FS_Uri *uri;
47
48 /**
49 * Meta data.
50 */
51 struct GNUNET_CONTAINER_MetaData *meta;
52
53 /**
54 * Suggested filename, or NULL.
55 */
56 char *filename;
57
58 /**
59 * Row reference (if URI was found by search, or
60 * part of directory, etc.); otherwise NULL (download by URI).
61 */
62 GtkTreeRowReference *rr;
63
64 /**
65 * Associated search result, or NULL.
66 */
67 struct GNUNET_FS_SearchResult *sr;
68
69 /**
70 * Is this a recursive download?
71 */
72 int is_recursive;
73
74 /**
75 * Desired (default) anonymity level.
76 */
77 int anonymity;
78
79 /**
80 * Tab where this download is currently on display.
81 * (this is the same as sr->tab, but sr is opaque here).
82 */
83 struct SearchTab *tab;
84
85};
86 31
87 32
88/** 33/**
@@ -91,10 +36,10 @@ struct DownloadContext
91 * respective tree model and trigger a start of the download using the 36 * respective tree model and trigger a start of the download using the
92 * FS-API. 37 * FS-API.
93 * 38 *
94 * @param dc download context of the download to execute 39 * @param de download entry of the download to execute
95 */ 40 */
96void 41void
97GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc); 42GNUNET_FS_GTK_download_context_start_download (struct DownloadEntry *de);
98 43
99 44
100/** 45/**
@@ -106,7 +51,17 @@ GNUNET_FS_GTK_download_context_start_download (struct DownloadContext *dc);
106 * @param dc download context for the file/directory 51 * @param dc download context for the file/directory
107 */ 52 */
108void 53void
109GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc); 54GNUNET_FS_GTK_open_download_as_dialog (struct DownloadEntry *de);
55
56
57/**
58 * Free resources associated with the given download entry.
59 *
60 * @param de context to free
61 */
62void
63GNUNET_FS_GTK_free_download_entry (struct DownloadEntry *de);
64
110 65
111 66
112#endif 67#endif
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index 5c0a5710..ae0ab3db 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -88,37 +88,6 @@ struct PublishEntry
88}; 88};
89 89
90 90
91/**
92 * Information we keep for each search result entry in any search tab.
93 * An entry like this is also generated for downloads by-URI. Used to
94 * quickly identify the tab and row of the result; stored in the
95 * user-context of the FS library for the search result.
96 */
97struct SearchResult
98{
99 /**
100 * Where in the tab is this result?
101 */
102 GtkTreeRowReference *rr;
103
104 /**
105 * Tab storing this result.
106 */
107 struct SearchTab *tab;
108
109 /**
110 * Search result for top-level results and
111 * namespace-update results.
112 */
113 struct GNUNET_FS_SearchResult *result;
114
115 /**
116 * Associated download, or NULL for none.
117 */
118 struct DownloadEntry *download;
119};
120
121
122 91
123/** 92/**
124 * Head of linked list of tabs for searches. 93 * Head of linked list of tabs for searches.
@@ -327,7 +296,7 @@ start_download (GtkTreeView *tree_view,
327 struct GNUNET_FS_Uri *uri; 296 struct GNUNET_FS_Uri *uri;
328 struct GNUNET_CONTAINER_MetaData *meta; 297 struct GNUNET_CONTAINER_MetaData *meta;
329 struct SearchResult *sr; 298 struct SearchResult *sr;
330 struct DownloadContext *dc; 299 struct DownloadEntry *de;
331 char *buf = NULL; 300 char *buf = NULL;
332 char *tmp; 301 char *tmp;
333 size_t tmplen; 302 size_t tmplen;
@@ -357,6 +326,11 @@ start_download (GtkTreeView *tree_view,
357 have no URI and downloading makes no sense. Ignore! */ 326 have no URI and downloading makes no sense. Ignore! */
358 return; 327 return;
359 } 328 }
329 if (NULL != sr->download)
330 {
331 /* download already active! */
332 return;
333 }
360 if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))) 334 if (!(GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))
361 { 335 {
362 /* can only download chk/loc URIs, ignore */ 336 /* can only download chk/loc URIs, ignore */
@@ -414,16 +388,14 @@ start_download (GtkTreeView *tree_view,
414 GNUNET_free_non_null (filename); 388 GNUNET_free_non_null (filename);
415 389
416 /* now setup everything for the save-as dialog */ 390 /* now setup everything for the save-as dialog */
417 dc = GNUNET_malloc (sizeof (struct DownloadContext)); 391 de = GNUNET_malloc (sizeof (struct DownloadEntry));
418 dc->uri = GNUNET_FS_uri_dup (uri); 392 de->uri = GNUNET_FS_uri_dup (uri);
419 393 de->filename = buf;
420 dc->filename = buf; 394 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
421 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 395 de->sr = sr;
422 dc->rr = gtk_tree_row_reference_new (tm, path); 396 sr->download = de;
423 dc->sr = sr->result; 397 de->anonymity = anonymity;
424 dc->anonymity = anonymity; 398 de->is_recursive = is_recursive;
425 dc->is_recursive = is_recursive;
426 dc->tab = tab;
427 fprintf (stderr, 399 fprintf (stderr,
428 "lp %d, have-sug: %d\n", 400 "lp %d, have-sug: %d\n",
429 local_parents, 401 local_parents,
@@ -431,9 +403,9 @@ start_download (GtkTreeView *tree_view,
431 if ( (GNUNET_YES == local_parents) && 403 if ( (GNUNET_YES == local_parents) &&
432 (GNUNET_YES == have_a_suggestion) ) 404 (GNUNET_YES == have_a_suggestion) )
433 /* Skip the dialog, call directly */ 405 /* Skip the dialog, call directly */
434 GNUNET_FS_GTK_download_context_start_download (dc); 406 GNUNET_FS_GTK_download_context_start_download (de);
435 else 407 else
436 GNUNET_FS_GTK_open_download_as_dialog (dc); 408 GNUNET_FS_GTK_open_download_as_dialog (de);
437} 409}
438 410
439 411
@@ -1511,18 +1483,16 @@ setup_inner_search (struct GNUNET_FS_SearchContext *sc,
1511 * Setup a new top-level entry in the URI/orphan tab. If necessary, create 1483 * Setup a new top-level entry in the URI/orphan tab. If necessary, create
1512 * the URI tab first. 1484 * the URI tab first.
1513 * 1485 *
1514 * @param iter set to the new entry (OUT only) 1486 * @param iter set to the new entry (OUT only) -- FIXME: remove, obtainable as 'RETVAL->rr'
1515 * @param srp set to search result (can be NULL)
1516 * @param meta metadata for the new entry 1487 * @param meta metadata for the new entry
1517 * @param uri URI for the new entry 1488 * @param uri URI for the new entry
1518 * @return the 'uri_tab' the result was added to 1489 * @return the search result that was set up
1519 */ 1490 */
1520struct SearchTab * 1491struct SearchResult *
1521GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, struct SearchResult **srp, 1492GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter,
1522 const struct GNUNET_CONTAINER_MetaData *meta, 1493 const struct GNUNET_CONTAINER_MetaData *meta,
1523 const struct GNUNET_FS_Uri *uri) 1494 const struct GNUNET_FS_Uri *uri)
1524{ 1495{
1525 struct SearchResult *sr;
1526 GtkNotebook *notebook; 1496 GtkNotebook *notebook;
1527 gint page; 1497 gint page;
1528 1498
@@ -1542,10 +1512,7 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, struct SearchResult **srp,
1542 gtk_notebook_set_current_page (notebook, page); 1512 gtk_notebook_set_current_page (notebook, page);
1543 break; 1513 break;
1544 } 1514 }
1545 sr = GNUNET_GTK_add_search_result (uri_tab, iter, NULL, uri, meta, NULL, 0); 1515 return GNUNET_GTK_add_search_result (uri_tab, iter, NULL, uri, meta, NULL, 0);
1546 if (NULL != srp)
1547 *srp = sr;
1548 return uri_tab;
1549} 1516}
1550 1517
1551 1518
@@ -1570,15 +1537,15 @@ change_download_color (struct DownloadEntry *de,
1570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1571 "Changing download DE=%p color to %s\n", 1538 "Changing download DE=%p color to %s\n",
1572 de, color); 1539 de, color);
1573 path = gtk_tree_row_reference_get_path (de->rr); 1540 path = gtk_tree_row_reference_get_path (de->sr->rr);
1574 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path)) 1541 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
1575 { 1542 {
1576 GNUNET_break (0); 1543 GNUNET_break (0);
1577 gtk_tree_path_free (path); 1544 gtk_tree_path_free (path);
1578 return; 1545 return;
1579 } 1546 }
1580 gtk_tree_path_free (path); 1547 gtk_tree_path_free (path);
1581 gtk_tree_store_set (de->tab->ts, &iter, 8, color, -1); 1548 gtk_tree_store_set (de->sr->tab->ts, &iter, 8, color, -1);
1582} 1549}
1583 1550
1584 1551
@@ -1591,16 +1558,8 @@ change_download_color (struct DownloadEntry *de,
1591static void 1558static void
1592stop_download (struct DownloadEntry *de) 1559stop_download (struct DownloadEntry *de)
1593{ 1560{
1594 if (NULL != de->sr)
1595 {
1596 GNUNET_assert (de->sr->download == de);
1597 de->sr->download = NULL;
1598 }
1599 change_download_color (de, "white"); 1561 change_download_color (de, "white");
1600 gtk_tree_row_reference_free (de->rr); 1562 GNUNET_FS_GTK_free_download_entry (de);
1601 GNUNET_FS_uri_destroy (de->uri);
1602 GNUNET_CONTAINER_meta_data_destroy (de->meta);
1603 GNUNET_free (de);
1604} 1563}
1605 1564
1606 1565
@@ -1732,8 +1691,8 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size,
1732 "Marking download progress for DE=%p, %llu/%llu, %llu@%llu depth=%u\n", 1691 "Marking download progress for DE=%p, %llu/%llu, %llu@%llu depth=%u\n",
1733 de, completed, size, block_size, offset, depth); 1692 de, completed, size, block_size, offset, depth);
1734 1693
1735 path = gtk_tree_row_reference_get_path (de->rr); 1694 path = gtk_tree_row_reference_get_path (de->sr->rr);
1736 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path)) 1695 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
1737 { 1696 {
1738 GNUNET_break (0); 1697 GNUNET_break (0);
1739 gtk_tree_path_free (path); 1698 gtk_tree_path_free (path);
@@ -1744,7 +1703,7 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size,
1744 'progress' once the download has started and re-use the 1703 'progress' once the download has started and re-use the
1745 space in the display? Probably yes, at least once we have 1704 space in the display? Probably yes, at least once we have
1746 a custom CellRenderer... */ 1705 a custom CellRenderer... */
1747 gtk_tree_store_set (de->tab->ts, &iter, 1706 gtk_tree_store_set (de->sr->tab->ts, &iter,
1748 4, (guint) ((size > 1707 4, (guint) ((size >
1749 0) ? (100 * completed / 1708 0) ? (100 * completed /
1750 size) : 100) /* progress */, 1709 size) : 100) /* progress */,
@@ -1760,8 +1719,8 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size,
1760 /* got a data block of a directory, list its contents */ 1719 /* got a data block of a directory, list its contents */
1761 struct AddDirectoryEntryContext ade; 1720 struct AddDirectoryEntryContext ade;
1762 1721
1763 ade.tab = de->tab; 1722 ade.tab = de->sr->tab;
1764 ade.prr = de->rr; 1723 ade.prr = de->sr->rr;
1765 ade.check_duplicates = GNUNET_NO; 1724 ade.check_duplicates = GNUNET_NO;
1766 if (GNUNET_SYSERR == 1725 if (GNUNET_SYSERR ==
1767 GNUNET_FS_directory_list_contents ((size_t) block_size, block_data, 1726 GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
@@ -1771,7 +1730,7 @@ mark_download_progress (struct DownloadEntry *de, uint64_t size,
1771 GNUNET_break (GNUNET_OK == 1730 GNUNET_break (GNUNET_OK ==
1772 GNUNET_CONTAINER_meta_data_delete (de->meta, 1731 GNUNET_CONTAINER_meta_data_delete (de->meta,
1773 EXTRACTOR_METATYPE_MIMETYPE, NULL, 0)); 1732 EXTRACTOR_METATYPE_MIMETYPE, NULL, 0));
1774 gtk_tree_store_set (de->tab->ts, &iter, 1733 gtk_tree_store_set (de->sr->tab->ts, &iter,
1775 10, "" /* unknown mime type */, -1); 1734 10, "" /* unknown mime type */, -1);
1776 } 1735 }
1777 } 1736 }
@@ -1794,15 +1753,15 @@ mark_download_error (struct DownloadEntry *de,
1794 1753
1795 change_download_color (de, "red"); 1754 change_download_color (de, "red");
1796 de->is_done = GNUNET_YES; 1755 de->is_done = GNUNET_YES;
1797 path = gtk_tree_row_reference_get_path (de->rr); 1756 path = gtk_tree_row_reference_get_path (de->sr->rr);
1798 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path)) 1757 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
1799 { 1758 {
1800 GNUNET_break (0); 1759 GNUNET_break (0);
1801 gtk_tree_path_free (path); 1760 gtk_tree_path_free (path);
1802 return; 1761 return;
1803 } 1762 }
1804 gtk_tree_path_free (path); 1763 gtk_tree_path_free (path);
1805 gtk_tree_store_set (de->tab->ts, &iter, 4, 0, 7, emsg, -1); 1764 gtk_tree_store_set (de->sr->tab->ts, &iter, 4, 0, 7, emsg, -1);
1806} 1765}
1807 1766
1808 1767
@@ -1832,8 +1791,8 @@ mark_download_completed (struct DownloadEntry *de, uint64_t size,
1832 { 1791 {
1833 /* download was for a directory (and we have a temp file for scanning); 1792 /* download was for a directory (and we have a temp file for scanning);
1834 add contents of the directory to the view */ 1793 add contents of the directory to the view */
1835 ade.tab = de->tab; 1794 ade.tab = de->sr->tab;
1836 ade.prr = de->rr; 1795 ade.prr = de->sr->rr;
1837 ade.check_duplicates = GNUNET_YES; 1796 ade.check_duplicates = GNUNET_YES;
1838 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade); 1797 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade);
1839 } 1798 }
@@ -1915,12 +1874,6 @@ copy_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
1915 search_result->rr = gtk_tree_row_reference_new (dst_model, path); 1874 search_result->rr = gtk_tree_row_reference_new (dst_model, path);
1916 search_result->result = NULL; 1875 search_result->result = NULL;
1917 gtk_tree_path_free (path); 1876 gtk_tree_path_free (path);
1918 if (search_result->download != NULL)
1919 {
1920 gtk_tree_row_reference_free (search_result->download->rr);
1921 search_result->download->rr =
1922 gtk_tree_row_reference_copy (search_result->rr);
1923 }
1924 copy_children (src_model, &src_child, dst_model, &dst_child); 1877 copy_children (src_model, &src_child, dst_model, &dst_child);
1925 } 1878 }
1926 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child)); 1879 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child));
@@ -1957,7 +1910,6 @@ download_lost_parent (struct DownloadEntry *de)
1957{ 1910{
1958 GtkTreeIter iter; 1911 GtkTreeIter iter;
1959 GtkTreePath *path; 1912 GtkTreePath *path;
1960 struct SearchTab *tab;
1961 GtkTreeRowReference *rr_old; 1913 GtkTreeRowReference *rr_old;
1962 GtkTreeModel *tm_old; 1914 GtkTreeModel *tm_old;
1963 GtkTreeIter iter_old; 1915 GtkTreeIter iter_old;
@@ -1965,17 +1917,16 @@ download_lost_parent (struct DownloadEntry *de)
1965 GtkTreeModel *model; 1917 GtkTreeModel *model;
1966 1918
1967 /* first, move the root of the respective 'de'-tree */ 1919 /* first, move the root of the respective 'de'-tree */
1968 rr_old = de->rr; 1920 rr_old = de->sr->rr;
1969 tab = GNUNET_GTK_add_to_uri_tab (&iter, &de->sr, de->meta, de->uri); 1921 de->sr = GNUNET_GTK_add_to_uri_tab (&iter, de->meta, de->uri);
1970 de->tab = tab;
1971 de->sr->download = de; 1922 de->sr->download = de;
1972 model = GTK_TREE_MODEL (de->tab->ts); 1923
1973 path = gtk_tree_model_get_path (model, &iter); 1924 model = GTK_TREE_MODEL (de->sr->tab->ts);
1974 de->rr = gtk_tree_row_reference_new (model, path); 1925
1975 gtk_tree_path_free (path);
1976 tm_old = gtk_tree_row_reference_get_model (rr_old); 1926 tm_old = gtk_tree_row_reference_get_model (rr_old);
1977 path = gtk_tree_row_reference_get_path (rr_old); 1927 path = gtk_tree_row_reference_get_path (rr_old);
1978 gtk_tree_row_reference_free (rr_old); 1928 gtk_tree_row_reference_free (rr_old);
1929
1979 if (! gtk_tree_model_get_iter (tm_old, &iter_old, path)) 1930 if (! gtk_tree_model_get_iter (tm_old, &iter_old, path))
1980 { 1931 {
1981 GNUNET_break (0); 1932 GNUNET_break (0);
@@ -2014,13 +1965,11 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2014{ 1965{
2015 GtkTreeIter iter; 1966 GtkTreeIter iter;
2016 GtkTreePath *path; 1967 GtkTreePath *path;
2017 struct SearchResult *srp;
2018 1968
2019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2020 "Setting up download, initially DE=%p, PDE=%p for %p & %p into %llu/%llu `%s'\n", 1970 "Setting up download, initially DE=%p, PDE=%p for %p & %p into %llu/%llu `%s'\n",
2021 de, pde, sr, dc, completed, size, filename); 1971 de, pde, sr, dc, completed, size, filename);
2022 GNUNET_assert (NULL != uri); 1972 GNUNET_assert (NULL != uri);
2023 srp = NULL;
2024 if (NULL == de) 1973 if (NULL == de)
2025 { 1974 {
2026 /* no existing download entry to build on, create a fresh one */ 1975 /* no existing download entry to build on, create a fresh one */
@@ -2032,47 +1981,49 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2032 GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri, uri)); 1981 GNUNET_assert (GNUNET_YES == GNUNET_FS_uri_test_equal (de->uri, uri));
2033 } 1982 }
2034 de->dc = dc; 1983 de->dc = dc;
2035 de->sr = sr;
2036 de->pde = pde; 1984 de->pde = pde;
2037 if ( (meta != NULL) && (de->meta == NULL) ) 1985 if ( (meta != NULL) && (de->meta == NULL) )
2038 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 1986 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
2039 if (NULL != sr) 1987 if (NULL != sr)
2040 { 1988 {
2041 /* got a search result; display the download in the same location as the search result */ 1989 /* have a search result, establish mapping de <--> sr */
2042 GNUNET_assert (sr->download == NULL); 1990 if (NULL == de->sr)
2043 sr->download = de; 1991 {
2044 de->rr = gtk_tree_row_reference_copy (sr->rr); 1992 GNUNET_assert (sr->download == NULL);
2045 de->tab = sr->tab; 1993 de->sr = sr;
2046 srp = sr; 1994 sr->download = de;
1995 }
1996 else
1997 {
1998 GNUNET_assert (sr == de->sr);
1999 }
2047 } 2000 }
2048 if (NULL == de->rr) 2001 if (NULL == de->sr)
2049 { 2002 {
2050 /* Stand-alone download with no 'row'/search result affiliated 2003 /* Stand-alone download with no 'row'/search result affiliated
2051 with the download so far; create a fresh entry for this 2004 with the download so far; create a fresh entry for this
2052 download in the URI tab */ 2005 download in the URI tab */
2053 de->tab = GNUNET_GTK_add_to_uri_tab (&iter, &srp, meta, uri); 2006 de->sr = GNUNET_GTK_add_to_uri_tab (&iter, meta, uri);
2054 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->tab->ts), &iter); 2007 de->sr->download = de;
2055 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->tab->ts), path);
2056 gtk_tree_path_free (path);
2057 srp->download = de;
2058 } 2008 }
2059 GNUNET_assert (NULL != de->tab); 2009 path = gtk_tree_row_reference_get_path (de->sr->rr);
2060 path = gtk_tree_row_reference_get_path (de->rr); 2010 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->sr->tab->ts), &iter, path))
2061 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
2062 { 2011 {
2063 GNUNET_break (0); 2012 GNUNET_break (0);
2064 gtk_tree_path_free (path); 2013 gtk_tree_path_free (path);
2065 return de; 2014 return de;
2066 } 2015 }
2067 gtk_tree_path_free (path); 2016 gtk_tree_path_free (path);
2068 gtk_tree_store_set (de->tab->ts, &iter, 2017 gtk_tree_store_set (de->sr->tab->ts, &iter,
2069 4, (guint) ((size > 2018 4, (guint) ((size >
2070 0) ? (100 * completed / 2019 0) ? (100 * completed /
2071 size) : 100) /* progress */ , 2020 size) : 100) /* progress */ ,
2072 6, filename /* filename/description */ , 2021 6, filename /* filename/description */ ,
2073 8, "blue" /* status colour: pending */ , 2022 8, "blue" /* status colour: pending */ ,
2074 9, srp, 2023 9, de->sr,
2075 14, completed, 2024 14, completed,
2025 15, de->filename,
2026 16, de->anonymity,
2076 -1); 2027 -1);
2077 return de; 2028 return de;
2078} 2029}
diff --git a/src/fs/gnunet-fs-gtk_event-handler.h b/src/fs/gnunet-fs-gtk_event-handler.h
index a36ec604..bfd667de 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.h
+++ b/src/fs/gnunet-fs-gtk_event-handler.h
@@ -23,6 +23,9 @@
23 * @brief Main event handler for file-sharing 23 * @brief Main event handler for file-sharing
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#ifndef GNUNET_FS_GTK_EVENT_HANDLER_H
27#define GNUNET_FS_GTK_EVENT_HANDLER_H
28
26#include "gnunet-fs-gtk_common.h" 29#include "gnunet-fs-gtk_common.h"
27 30
28 31
@@ -133,35 +136,75 @@ struct DownloadEntry
133 struct SearchResult *sr; 136 struct SearchResult *sr;
134 137
135 /** 138 /**
136 * FS handle to control the download. 139 * FS handle to control the download, NULL if the download
140 * has not yet started.
137 */ 141 */
138 struct GNUNET_FS_DownloadContext *dc; 142 struct GNUNET_FS_DownloadContext *dc;
139 143
140 /** 144 /**
141 * URI for the download. 145 * URI for the download, never NULL.
142 */ 146 */
143 struct GNUNET_FS_Uri *uri; 147 struct GNUNET_FS_Uri *uri;
144 148
145 /** 149 /**
146 * Meta data for the download. 150 * Meta data for the download, can be NULL (i.e. for download
151 * by URI). In that case, we'll need to figure out if the
152 * result is a directory later!
147 */ 153 */
148 struct GNUNET_CONTAINER_MetaData *meta; 154 struct GNUNET_CONTAINER_MetaData *meta;
149 155
150 /** 156 /**
151 * Where in the tree view is this download being displayed. 157 * Suggested (or selected) filename for the download on the
158 * local disk, or NULL for on suggestion.
159 */
160 char *filename;
161
162 /**
163 * Is this a recursive download?
164 */
165 int is_recursive;
166
167 /**
168 * Desired (default) anonymity level.
169 */
170 uint32_t anonymity;
171
172 /**
173 * Has the download completed (or failed)?
174 */
175 int is_done;
176
177};
178
179
180/**
181 * Information we keep for each search result entry in any search tab.
182 * An entry like this is also generated for downloads by-URI. Used to
183 * quickly identify the tab and row of the result; stored in the
184 * user-context of the FS library for the search result.
185 */
186struct SearchResult
187{
188 /**
189 * Where in the tab is this result?
152 */ 190 */
153 GtkTreeRowReference *rr; 191 GtkTreeRowReference *rr;
154 192
155 /** 193 /**
156 * Tab where this download is currently on display. 194 * Tab storing this result.
157 */ 195 */
158 struct SearchTab *tab; 196 struct SearchTab *tab;
159 197
160 /** 198 /**
161 * Has the download completed (or errored)? 199 * Search result for top-level results and
200 * namespace-update results.
162 */ 201 */
163 int is_done; 202 struct GNUNET_FS_SearchResult *result;
164 203
204 /**
205 * Associated download, or NULL for none.
206 */
207 struct DownloadEntry *download;
165}; 208};
166 209
167 210
@@ -170,13 +213,12 @@ struct DownloadEntry
170 * the URI tab first. 213 * the URI tab first.
171 * 214 *
172 * @param iter set to the new entry (OUT only) 215 * @param iter set to the new entry (OUT only)
173 * @param srp set to search result (can be NULL)
174 * @param meta metadata for the new entry 216 * @param meta metadata for the new entry
175 * @param uri URI for the new entry 217 * @param uri URI for the new entry
176 * @return the 'uri_tab' the result was added to 218 * @return the search result that was set up
177 */ 219 */
178struct SearchTab * 220struct SearchResult *
179GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, struct SearchResult **sr, 221GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter,
180 const struct GNUNET_CONTAINER_MetaData *meta, 222 const struct GNUNET_CONTAINER_MetaData *meta,
181 const struct GNUNET_FS_Uri *uri); 223 const struct GNUNET_FS_Uri *uri);
182 224
@@ -228,4 +270,5 @@ GNUNET_GTK_fs_event_handler (void *cls,
228 const struct GNUNET_FS_ProgressInfo *info); 270 const struct GNUNET_FS_ProgressInfo *info);
229 271
230 272
273#endif
231/* end of gnunet-fs-gtk-event_handler.h */ 274/* end of gnunet-fs-gtk-event_handler.h */
diff --git a/src/fs/gnunet-fs-gtk_open-directory.c b/src/fs/gnunet-fs-gtk_open-directory.c
index 21247d2b..0c13f7f3 100644
--- a/src/fs/gnunet-fs-gtk_open-directory.c
+++ b/src/fs/gnunet-fs-gtk_open-directory.c
@@ -90,7 +90,7 @@ add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
90 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 90 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
91 acc->filename, 91 acc->filename,
92 strlen (acc->filename) + 1); 92 strlen (acc->filename) + 1);
93 acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, NULL, dmeta, NULL); 93 acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, dmeta, NULL)->tab;
94 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &iter); 94 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &iter);
95 acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp); 95 acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp);
96 gtk_tree_path_free (tp); 96 gtk_tree_path_free (tp);
diff --git a/src/fs/gnunet-fs-gtk_open-uri.c b/src/fs/gnunet-fs-gtk_open-uri.c
index 90235c76..be0e0f86 100644
--- a/src/fs/gnunet-fs-gtk_open-uri.c
+++ b/src/fs/gnunet-fs-gtk_open-uri.c
@@ -94,12 +94,12 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button,
94 } 94 }
95 if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)) 95 if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))
96 { 96 {
97 struct DownloadContext *dc; 97 struct DownloadEntry *de;
98 98
99 dc = GNUNET_malloc (sizeof (struct DownloadContext)); 99 de = GNUNET_malloc (sizeof (struct DownloadEntry));
100 dc->uri = uri; 100 de->uri = uri;
101 dc->anonymity = anonymity_level; 101 de->anonymity = anonymity_level;
102 GNUNET_FS_GTK_open_download_as_dialog (dc); 102 GNUNET_FS_GTK_open_download_as_dialog (de);
103 gtk_widget_destroy (dialog); 103 gtk_widget_destroy (dialog);
104 g_object_unref (G_OBJECT (builder)); 104 g_object_unref (G_OBJECT (builder));
105 return; 105 return;