aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-event_handler.c')
-rw-r--r--src/fs/gnunet-fs-gtk-event_handler.c1988
1 files changed, 918 insertions, 1070 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 3b53fca5..569462ed 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -66,19 +66,19 @@ struct PublishEntry
66 66
67 /** 67 /**
68 * Tab storing this entry. 68 * Tab storing this entry.
69 */ 69 */
70 struct PublishTab *tab; 70 struct PublishTab *tab;
71 71
72 /** 72 /**
73 * Where in the tab is this entry? 73 * Where in the tab is this entry?
74 */ 74 */
75 GtkTreeRowReference *rr; 75 GtkTreeRowReference *rr;
76 76
77 /** 77 /**
78 * URI of the file (set after completion). 78 * URI of the file (set after completion).
79 */ 79 */
80 struct GNUNET_FS_Uri *uri; 80 struct GNUNET_FS_Uri *uri;
81 81
82 int is_top; 82 int is_top;
83}; 83};
84 84
@@ -87,12 +87,12 @@ struct SearchResult
87{ 87{
88 /** 88 /**
89 * Where in the tab is this result? 89 * Where in the tab is this result?
90 */ 90 */
91 GtkTreeRowReference *rr; 91 GtkTreeRowReference *rr;
92 92
93 /** 93 /**
94 * Tab storing this result. 94 * Tab storing this result.
95 */ 95 */
96 struct SearchTab *tab; 96 struct SearchTab *tab;
97 97
98 /** 98 /**
@@ -115,59 +115,51 @@ static struct PublishTab *publish_tab_tail;
115 115
116 116
117static struct DownloadEntry * 117static struct DownloadEntry *
118change_download_colour (struct DownloadEntry *de, 118change_download_colour (struct DownloadEntry *de, const char *colour)
119 const char *colour)
120{ 119{
121 GtkTreeIter iter; 120 GtkTreeIter iter;
122 GtkTreePath *path; 121 GtkTreePath *path;
123 122
124 path = gtk_tree_row_reference_get_path (de->rr); 123 path = gtk_tree_row_reference_get_path (de->rr);
125 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), 124 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
126 &iter, path)) 125 {
127 { 126 GNUNET_break (0);
128 GNUNET_break (0); 127 gtk_tree_path_free (path);
129 gtk_tree_path_free (path); 128 return de;
130 return de; 129 }
131 }
132 gtk_tree_path_free (path); 130 gtk_tree_path_free (path);
133 gtk_tree_store_set (de->ts, &iter, 131 gtk_tree_store_set (de->ts, &iter, 8, colour, -1);
134 8, colour,
135 -1);
136 return de; 132 return de;
137} 133}
138 134
139 135
140static struct PublishEntry * 136static struct PublishEntry *
141change_publish_colour (struct PublishEntry *pe, 137change_publish_colour (struct PublishEntry *pe, const char *colour)
142 const char *colour)
143{ 138{
144 GtkTreeIter iter; 139 GtkTreeIter iter;
145 GtkTreePath *path; 140 GtkTreePath *path;
146 141
147 if (pe == NULL) 142 if (pe == NULL)
148 { 143 {
149 GNUNET_break (0); 144 GNUNET_break (0);
150 return NULL; 145 return NULL;
151 } 146 }
152 path = gtk_tree_row_reference_get_path (pe->rr); 147 path = gtk_tree_row_reference_get_path (pe->rr);
153 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), 148 if (TRUE !=
154 &iter, path)) 149 gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
155 { 150 {
156 GNUNET_break (0); 151 GNUNET_break (0);
157 gtk_tree_path_free (path); 152 gtk_tree_path_free (path);
158 return pe; 153 return pe;
159 } 154 }
160 gtk_tree_path_free (path); 155 gtk_tree_path_free (path);
161 gtk_tree_store_set (pe->tab->ts, &iter, 156 gtk_tree_store_set (pe->tab->ts, &iter, 2, colour, -1);
162 2, colour,
163 -1);
164 return pe; 157 return pe;
165} 158}
166 159
167 160
168static void 161static void
169stop_download (struct DownloadEntry *de, 162stop_download (struct DownloadEntry *de, int is_suspend)
170 int is_suspend)
171{ 163{
172 change_download_colour (de, "white"); 164 change_download_colour (de, "white");
173 gtk_tree_row_reference_free (de->rr); 165 gtk_tree_row_reference_free (de->rr);
@@ -187,7 +179,7 @@ struct AddDirectoryEntryContext
187 179
188 /** 180 /**
189 * Row reference of parent (the directory). 181 * Row reference of parent (the directory).
190 */ 182 */
191 GtkTreeRowReference *prr; 183 GtkTreeRowReference *prr;
192 184
193 int check_duplicates; 185 int check_duplicates;
@@ -210,13 +202,11 @@ struct AddDirectoryEntryContext
210 * embedded with the directory itself). 202 * embedded with the directory itself).
211 * @param data data available for the file (length bytes) 203 * @param data data available for the file (length bytes)
212 */ 204 */
213static void 205static void
214add_directory_entry (void *cls, 206add_directory_entry (void *cls, const char *filename,
215 const char *filename, 207 const struct GNUNET_FS_Uri *uri,
216 const struct GNUNET_FS_Uri *uri, 208 const struct GNUNET_CONTAINER_MetaData *meta,
217 const struct GNUNET_CONTAINER_MetaData *meta, 209 size_t length, const void *data)
218 size_t length,
219 const void *data)
220{ 210{
221 struct AddDirectoryEntryContext *ade = cls; 211 struct AddDirectoryEntryContext *ade = cls;
222 GtkTreeIter iter; 212 GtkTreeIter iter;
@@ -226,168 +216,144 @@ add_directory_entry (void *cls,
226 struct GNUNET_FS_Uri *xuri; 216 struct GNUNET_FS_Uri *xuri;
227 217
228 if (uri == NULL) 218 if (uri == NULL)
219 {
220 /* directory meta data itself */
221 /* FIXME: consider merging it in... */
222 return;
223 }
224 if (ade->check_duplicates == GNUNET_YES)
225 {
226 path = gtk_tree_row_reference_get_path (ade->prr);
227 tm = gtk_tree_row_reference_get_model (ade->prr);
228 if (TRUE != gtk_tree_model_get_iter (tm, &piter, path))
229 { 229 {
230 /* directory meta data itself */ 230 GNUNET_break (0);
231 /* FIXME: consider merging it in... */ 231 gtk_tree_path_free (path);
232 return; 232 return;
233 } 233 }
234 if (ade->check_duplicates == GNUNET_YES) 234 gtk_tree_path_free (path);
235 if (TRUE == gtk_tree_model_iter_children (tm, &iter, &piter))
235 { 236 {
236 path = gtk_tree_row_reference_get_path (ade->prr); 237 do
237 tm = gtk_tree_row_reference_get_model (ade->prr); 238 {
238 if (TRUE != gtk_tree_model_get_iter (tm, 239 gtk_tree_model_get (tm, &iter, 1, &xuri, -1);
239 &piter, path)) 240 if (GNUNET_YES == GNUNET_FS_uri_test_equal (xuri, uri))
240 { 241 return; /* already present */
241 GNUNET_break (0); 242 }
242 gtk_tree_path_free (path); 243 while (TRUE == gtk_tree_model_iter_next (tm, &iter));
243 return;
244 }
245 gtk_tree_path_free (path);
246 if (TRUE == gtk_tree_model_iter_children (tm,
247 &iter,
248 &piter))
249 {
250 do
251 {
252 gtk_tree_model_get (tm,
253 &iter,
254 1, &xuri,
255 -1);
256 if (GNUNET_YES ==
257 GNUNET_FS_uri_test_equal (xuri, uri))
258 return; /* already present */
259 }
260 while (TRUE == gtk_tree_model_iter_next (tm, &iter));
261 }
262 } 244 }
263 GNUNET_GTK_add_search_result (ade->de->tab, 245 }
264 &iter, 246 GNUNET_GTK_add_search_result (ade->de->tab, &iter, ade->prr, uri, meta, NULL,
265 ade->prr, 247 0);
266 uri,
267 meta,
268 NULL,
269 0);
270} 248}
271 249
272 250
273static struct DownloadEntry * 251static struct DownloadEntry *
274mark_download_progress (struct DownloadEntry *de, 252mark_download_progress (struct DownloadEntry *de, uint64_t size,
275 uint64_t size, 253 uint64_t completed, const void *block_data,
276 uint64_t completed, 254 uint64_t offset, uint64_t block_size,
277 const void *block_data, 255 unsigned int depth)
278 uint64_t offset,
279 uint64_t block_size,
280 unsigned int depth)
281{ 256{
282 struct AddDirectoryEntryContext ade; 257 struct AddDirectoryEntryContext ade;
283 GtkTreeIter iter; 258 GtkTreeIter iter;
284 GtkTreePath *path; 259 GtkTreePath *path;
285 260
286 path = gtk_tree_row_reference_get_path (de->rr); 261 path = gtk_tree_row_reference_get_path (de->rr);
287 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), 262 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
288 &iter, path)) 263 {
289 { 264 GNUNET_break (0);
290 GNUNET_break (0); 265 gtk_tree_path_free (path);
291 gtk_tree_path_free (path); 266 return de;
292 return de; 267 }
293 }
294 gtk_tree_path_free (path); 268 gtk_tree_path_free (path);
295 gtk_tree_store_set (de->ts, &iter, 269 gtk_tree_store_set (de->ts, &iter, 4,
296 4, (guint) ((size > 0) ? (100 * completed / size) : 100) /* progress */, 270 (guint) ((size >
297 -1); 271 0) ? (100 * completed /
298 if ( (depth == 0) && 272 size) : 100) /* progress */ ,
299 (block_size > 0) && 273 -1);
300 (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) ) 274 if ((depth == 0) && (block_size > 0) &&
275 (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)))
276 {
277 ade.de = de;
278 ade.prr = de->rr;
279 ade.check_duplicates = GNUNET_NO;
280 if (GNUNET_SYSERR ==
281 GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
282 offset, &add_directory_entry, &ade))
301 { 283 {
302 ade.de = de; 284 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
303 ade.prr = de->rr; 285 _
304 ade.check_duplicates = GNUNET_NO; 286 ("Metadata wrongly claims that this is a GNUnet directory!\n"));
305 if (GNUNET_SYSERR ==
306 GNUNET_FS_directory_list_contents ((size_t) block_size,
307 block_data,
308 offset,
309 &add_directory_entry,
310 &ade))
311 {
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 _("Metadata wrongly claims that this is a GNUnet directory!\n"));
314 }
315 } 287 }
288 }
316 return de; 289 return de;
317} 290}
318 291
319 292
320static struct DownloadEntry * 293static struct DownloadEntry *
321mark_download_error (struct DownloadEntry *de, 294mark_download_error (struct DownloadEntry *de, const char *emsg)
322 const char *emsg)
323{ 295{
324 GtkTreeIter iter; 296 GtkTreeIter iter;
325 GtkTreePath *path; 297 GtkTreePath *path;
326 298
327 de = change_download_colour (de, 299 de = change_download_colour (de, "red");
328 "red"); 300 de->is_done = GNUNET_YES;
329 de->is_done = GNUNET_YES;
330 path = gtk_tree_row_reference_get_path (de->rr); 301 path = gtk_tree_row_reference_get_path (de->rr);
331 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), 302 if (TRUE !=
332 &iter, path)) 303 gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), &iter, path))
333 { 304 {
334 GNUNET_break (0); 305 GNUNET_break (0);
335 gtk_tree_path_free (path); 306 gtk_tree_path_free (path);
336 return de; 307 return de;
337 } 308 }
338 gtk_tree_path_free (path); 309 gtk_tree_path_free (path);
339 gtk_tree_store_set (de->tab->ts, &iter, 310 gtk_tree_store_set (de->tab->ts, &iter, 4, 0, 7, emsg, -1);
340 4, 0,
341 7, emsg,
342 -1);
343 return de; 311 return de;
344} 312}
345 313
346 314
347static struct DownloadEntry * 315static struct DownloadEntry *
348mark_download_completed (struct DownloadEntry *de, 316mark_download_completed (struct DownloadEntry *de, uint64_t size,
349 uint64_t size, 317 const char *filename)
350 const char *filename)
351{ 318{
352 struct AddDirectoryEntryContext ade; 319 struct AddDirectoryEntryContext ade;
353 320
354 de->is_done = GNUNET_YES; 321 de->is_done = GNUNET_YES;
355 (void) mark_download_progress (de, size, size, NULL, 0, 0, 0); 322 (void) mark_download_progress (de, size, size, NULL, 0, 0, 0);
356 if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) && 323 if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) &&
357 (filename != NULL) ) 324 (filename != NULL))
358 { 325 {
359 ade.de = de; 326 ade.de = de;
360 ade.prr = de->rr; 327 ade.prr = de->rr;
361 ade.check_duplicates = GNUNET_NO; 328 ade.check_duplicates = GNUNET_NO;
362 GNUNET_FS_GTK_mmap_and_scan (filename, 329 GNUNET_FS_GTK_mmap_and_scan (filename, &add_directory_entry, &ade);
363 &add_directory_entry, 330 }
364 &ade);
365 }
366 (void) change_download_colour (de, "green"); 331 (void) change_download_colour (de, "green");
367 return de; 332 return de;
368} 333}
369 334
370 335
371static struct PublishEntry * 336static struct PublishEntry *
372mark_publish_progress (struct PublishEntry *pe, 337mark_publish_progress (struct PublishEntry *pe, uint64_t size,
373 uint64_t size, 338 uint64_t completed)
374 uint64_t completed)
375{ 339{
376 GtkTreeIter iter; 340 GtkTreeIter iter;
377 GtkTreePath *path; 341 GtkTreePath *path;
378 342
379 path = gtk_tree_row_reference_get_path (pe->rr); 343 path = gtk_tree_row_reference_get_path (pe->rr);
380 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), 344 if (TRUE !=
381 &iter, path)) 345 gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
382 { 346 {
383 GNUNET_break (0); 347 GNUNET_break (0);
384 gtk_tree_path_free (path); 348 gtk_tree_path_free (path);
385 return pe; 349 return pe;
386 } 350 }
387 gtk_tree_path_free (path); 351 gtk_tree_path_free (path);
388 gtk_tree_store_set (pe->tab->ts, &iter, 352 gtk_tree_store_set (pe->tab->ts, &iter, 3,
389 3, (guint) ((size > 0) ? (100 * completed / size) : 100) /* progress */, 353 (guint) ((size >
390 -1); 354 0) ? (100 * completed /
355 size) : 100) /* progress */ ,
356 -1);
391 return pe; 357 return pe;
392} 358}
393 359
@@ -403,10 +369,8 @@ mark_publish_progress (struct PublishEntry *pe,
403 * to refer to the new model. 369 * to refer to the new model.
404 */ 370 */
405static void 371static void
406move_children (GtkTreeModel *src_model, 372move_children (GtkTreeModel * src_model, GtkTreeIter * src_iter,
407 GtkTreeIter *src_iter, 373 GtkTreeModel * dst_model, GtkTreeIter * dst_iter)
408 GtkTreeModel *dst_model,
409 GtkTreeIter *dst_iter)
410{ 374{
411 GtkTreeIter src_child; 375 GtkTreeIter src_child;
412 GtkTreeIter dst_child; 376 GtkTreeIter dst_child;
@@ -424,76 +388,49 @@ move_children (GtkTreeModel *src_model,
424 gchar *mimetype; 388 gchar *mimetype;
425 guint applicability_rank; 389 guint applicability_rank;
426 guint availability_certainty; 390 guint availability_certainty;
427 gint availability_rank; 391 gint availability_rank;
428 392
429 if (TRUE == gtk_tree_model_iter_children (src_model, 393 if (TRUE == gtk_tree_model_iter_children (src_model, &src_child, src_iter))
430 &src_child, 394 {
431 src_iter)) 395 do
432 { 396 {
433 do 397 gtk_tree_model_get (src_model, &src_child, 0, &meta, 1, &uri, 2,
434 { 398 &filesize, 3, &preview, 4, &percent_progress, 5,
435 gtk_tree_model_get (src_model, 399 &percent_availability, 6, &filename, 7,
436 &src_child, 400 &uri_as_string, 8, &status_colour, 9, &search_result,
437 0, &meta, 401 10, &mimetype, 11, &applicability_rank, 12,
438 1, &uri, 402 &availability_certainty, 13, &availability_rank, -1);
439 2, &filesize, 403 gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model), &dst_child,
440 3, &preview, 404 dst_iter, G_MAXINT, 0, meta, 1, uri, 2,
441 4, &percent_progress, 405 filesize, 3, preview, 4,
442 5, &percent_availability, 406 percent_progress, 5,
443 6, &filename, 407 percent_availability, 6, filename, 7,
444 7, &uri_as_string, 408 uri_as_string, 8, status_colour, 9,
445 8, &status_colour, 409 search_result, 10, mimetype, 11,
446 9, &search_result, 410 applicability_rank, 12,
447 10, &mimetype, 411 availability_certainty, 13,
448 11, &applicability_rank, 412 availability_rank, -1);
449 12, &availability_certainty, 413 g_free (filename);
450 13, &availability_rank, 414 g_free (uri_as_string);
451 -1); 415 g_free (status_colour);
452 gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model), 416 g_free (mimetype);
453 &dst_child, 417 if (preview != NULL)
454 dst_iter, 418 g_object_unref (preview);
455 G_MAXINT, 419 gtk_tree_row_reference_free (search_result->rr);
456 0, meta, 420 path = gtk_tree_model_get_path (dst_model, &dst_child);
457 1, uri, 421 search_result->rr = gtk_tree_row_reference_new (dst_model, path);
458 2, filesize, 422 gtk_tree_path_free (path);
459 3, preview, 423 if (search_result->download != NULL)
460 4, percent_progress, 424 {
461 5, percent_availability, 425 search_result->download->ts = GTK_TREE_STORE (dst_model);
462 6, filename, 426 gtk_tree_row_reference_free (search_result->download->rr);
463 7, uri_as_string, 427 search_result->download->rr =
464 8, status_colour, 428 gtk_tree_row_reference_copy (search_result->rr);
465 9, search_result, 429 }
466 10, mimetype, 430 move_children (src_model, &src_child, dst_model, &dst_child);
467 11, applicability_rank,
468 12, availability_certainty,
469 13, availability_rank,
470 -1);
471 g_free (filename);
472 g_free (uri_as_string);
473 g_free (status_colour);
474 g_free (mimetype);
475 if (preview != NULL)
476 g_object_unref (preview);
477 gtk_tree_row_reference_free (search_result->rr);
478 path = gtk_tree_model_get_path (dst_model,
479 &dst_child);
480 search_result->rr = gtk_tree_row_reference_new (dst_model,
481 path);
482 gtk_tree_path_free (path);
483 if (search_result->download != NULL)
484 {
485 search_result->download->ts = GTK_TREE_STORE (dst_model);
486 gtk_tree_row_reference_free (search_result->download->rr);
487 search_result->download->rr = gtk_tree_row_reference_copy (search_result->rr);
488 }
489 move_children (src_model,
490 &src_child,
491 dst_model,
492 &dst_child);
493 }
494 while (TRUE == gtk_tree_model_iter_next (src_model,
495 &src_child));
496 } 431 }
432 while (TRUE == gtk_tree_model_iter_next (src_model, &src_child));
433 }
497} 434}
498 435
499 436
@@ -503,17 +440,13 @@ move_children (GtkTreeModel *src_model,
503 * model's fields (since they have been moved). 440 * model's fields (since they have been moved).
504 */ 441 */
505static void 442static void
506delete_stale_subtree (GtkTreeModel *model, 443delete_stale_subtree (GtkTreeModel * model, GtkTreeIter * iter)
507 GtkTreeIter *iter)
508{ 444{
509 GtkTreeIter child; 445 GtkTreeIter child;
510 446
511 while (TRUE == gtk_tree_model_iter_children (model, 447 while (TRUE == gtk_tree_model_iter_children (model, &child, iter))
512 &child,
513 iter))
514 delete_stale_subtree (model, &child); 448 delete_stale_subtree (model, &child);
515 gtk_tree_store_remove (GTK_TREE_STORE (model), 449 gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
516 iter);
517} 450}
518 451
519 452
@@ -522,10 +455,8 @@ delete_stale_subtree (GtkTreeModel *model,
522 * search parent by moving it to the URI tab. 455 * search parent by moving it to the URI tab.
523 */ 456 */
524static struct DownloadEntry * 457static struct DownloadEntry *
525download_lost_parent (struct DownloadEntry *de, 458download_lost_parent (struct DownloadEntry *de, uint64_t size,
526 uint64_t size, 459 uint64_t completed, int is_active)
527 uint64_t completed,
528 int is_active)
529{ 460{
530 GtkTreeIter iter; 461 GtkTreeIter iter;
531 GtkTreePath *path; 462 GtkTreePath *path;
@@ -536,42 +467,30 @@ download_lost_parent (struct DownloadEntry *de,
536 467
537 rr_old = de->rr; 468 rr_old = de->rr;
538 de->sr = NULL; 469 de->sr = NULL;
539 tab = GNUNET_GTK_add_to_uri_tab (&iter, 470 tab = GNUNET_GTK_add_to_uri_tab (&iter, NULL, de->meta, de->uri);
540 NULL,
541 de->meta,
542 de->uri);
543 de->ts = tab->ts; 471 de->ts = tab->ts;
544 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), 472 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), &iter);
545 &iter); 473 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts), path);
546 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts),
547 path);
548 gtk_tree_path_free (path); 474 gtk_tree_path_free (path);
549 mark_download_progress (de, size, completed, 475 mark_download_progress (de, size, completed, NULL, 0, 0, 0);
550 NULL, 0, 0, 0);
551 tm_old = gtk_tree_row_reference_get_model (rr_old); 476 tm_old = gtk_tree_row_reference_get_model (rr_old);
552 path = gtk_tree_row_reference_get_path (rr_old); 477 path = gtk_tree_row_reference_get_path (rr_old);
553 gtk_tree_row_reference_free (rr_old); 478 gtk_tree_row_reference_free (rr_old);
554 gtk_tree_model_get_iter (tm_old, 479 gtk_tree_model_get_iter (tm_old, &iter_old, path);
555 &iter_old,
556 path);
557 gtk_tree_path_free (path); 480 gtk_tree_path_free (path);
558 move_children (tm_old, 481 move_children (tm_old, &iter_old, GTK_TREE_MODEL (de->ts), &iter);
559 &iter_old, 482 delete_stale_subtree (tm_old, &iter_old);
560 GTK_TREE_MODEL (de->ts),
561 &iter);
562 delete_stale_subtree (tm_old,
563 &iter_old);
564 if (size > completed) 483 if (size > completed)
565 { 484 {
566 if (is_active) 485 if (is_active)
567 change_download_colour (de, "yellow"); 486 change_download_colour (de, "yellow");
568 else 487 else
569 change_download_colour (de, "blue"); 488 change_download_colour (de, "blue");
570 } 489 }
571 else 490 else
572 { 491 {
573 change_download_colour (de, "green"); 492 change_download_colour (de, "green");
574 } 493 }
575 return de; 494 return de;
576} 495}
577 496
@@ -589,63 +508,55 @@ download_lost_parent (struct DownloadEntry *de,
589 * @param completed current progress 508 * @param completed current progress
590 */ 509 */
591static struct DownloadEntry * 510static struct DownloadEntry *
592setup_download (struct DownloadEntry *de, 511setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
593 struct DownloadEntry *pde, 512 struct SearchResult *sr, struct GNUNET_FS_DownloadContext *dc,
594 struct SearchResult *sr, 513 const struct GNUNET_FS_Uri *uri,
595 struct GNUNET_FS_DownloadContext *dc, 514 const struct GNUNET_CONTAINER_MetaData *meta, uint64_t size,
596 const struct GNUNET_FS_Uri *uri, 515 uint64_t completed)
597 const struct GNUNET_CONTAINER_MetaData *meta,
598 uint64_t size,
599 uint64_t completed)
600{ 516{
601 GtkTreeIter iter; 517 GtkTreeIter iter;
602 GtkTreePath *path; 518 GtkTreePath *path;
603 519
604 if (de == NULL) 520 if (de == NULL)
605 { 521 {
606 de = GNUNET_malloc (sizeof (struct DownloadEntry)); 522 de = GNUNET_malloc (sizeof (struct DownloadEntry));
607 GNUNET_assert (sr->download == NULL); 523 GNUNET_assert (sr->download == NULL);
608 sr->download = de; 524 sr->download = de;
609 de->sr = sr; 525 de->sr = sr;
610 de->dc = dc; 526 de->dc = dc;
611 de->uri = GNUNET_FS_uri_dup (uri); 527 de->uri = GNUNET_FS_uri_dup (uri);
612 } 528 }
613 de->pde = pde; 529 de->pde = pde;
614 if ( (meta != NULL) && 530 if ((meta != NULL) && (de->meta == NULL))
615 (de->meta == NULL) )
616 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 531 de->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
617 if (sr != NULL) 532 if (sr != NULL)
618 { 533 {
619 de->rr = gtk_tree_row_reference_copy (sr->rr); 534 de->rr = gtk_tree_row_reference_copy (sr->rr);
620 de->ts = sr->tab->ts; 535 de->ts = sr->tab->ts;
621 de->tab = sr->tab; 536 de->tab = sr->tab;
622 } 537 }
623 else if (de->rr == NULL) 538 else if (de->rr == NULL)
624 { 539 {
625 de->tab = GNUNET_GTK_add_to_uri_tab (&iter, 540 de->tab = GNUNET_GTK_add_to_uri_tab (&iter, NULL, meta, uri);
626 NULL, 541 de->ts = de->tab->ts;
627 meta, 542 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), &iter);
628 uri); 543 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts), path);
629 de->ts = de->tab->ts; 544 gtk_tree_path_free (path);
630 path = gtk_tree_model_get_path (GTK_TREE_MODEL (de->ts), 545 }
631 &iter);
632 de->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (de->ts),
633 path);
634 gtk_tree_path_free (path);
635 }
636 path = gtk_tree_row_reference_get_path (de->rr); 546 path = gtk_tree_row_reference_get_path (de->rr);
637 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), 547 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
638 &iter, path)) 548 {
639 { 549 GNUNET_break (0);
640 GNUNET_break (0); 550 gtk_tree_path_free (path);
641 gtk_tree_path_free (path); 551 return de;
642 return de; 552 }
643 }
644 gtk_tree_path_free (path); 553 gtk_tree_path_free (path);
645 gtk_tree_store_set (de->ts, &iter, 554 gtk_tree_store_set (de->ts, &iter, 4,
646 4, (guint) ((size > 0) ? (100 * completed / size) : 100) /* progress */, 555 (guint) ((size >
647 8, "blue" /* status colour: pending */, 556 0) ? (100 * completed /
648 -1); 557 size) : 100) /* progress */ ,
558 8, "blue" /* status colour: pending */ ,
559 -1);
649 return de; 560 return de;
650} 561}
651 562
@@ -655,10 +566,8 @@ setup_download (struct DownloadEntry *de,
655 * "save as" window. 566 * "save as" window.
656 */ 567 */
657static void 568static void
658start_download (GtkTreeView *tree_view, 569start_download (GtkTreeView * tree_view, GtkTreePath * path,
659 GtkTreePath *path, 570 GtkTreeViewColumn * column, gpointer user_data)
660 GtkTreeViewColumn *column,
661 gpointer user_data)
662{ 571{
663 struct SearchTab *tab = user_data; 572 struct SearchTab *tab = user_data;
664 GtkTreeModel *tm; 573 GtkTreeModel *tm;
@@ -672,16 +581,11 @@ start_download (GtkTreeView *tree_view,
672 GNUNET_assert (tab != NULL); 581 GNUNET_assert (tab != NULL);
673 tm = gtk_tree_view_get_model (tree_view); 582 tm = gtk_tree_view_get_model (tree_view);
674 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path)) 583 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
675 { 584 {
676 GNUNET_break (0); 585 GNUNET_break (0);
677 return; 586 return;
678 } 587 }
679 gtk_tree_model_get (tm, &iter, 588 gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, 9, &sr, 10, &mime, -1);
680 0, &meta,
681 1, &uri,
682 9, &sr,
683 10, &mime,
684 -1);
685 dlc = GNUNET_malloc (sizeof (struct DownloadContext)); 589 dlc = GNUNET_malloc (sizeof (struct DownloadContext));
686 dlc->uri = GNUNET_FS_uri_dup (uri); 590 dlc->uri = GNUNET_FS_uri_dup (uri);
687 dlc->mime = (NULL != mime) ? GNUNET_strdup (mime) : NULL; 591 dlc->mime = (NULL != mime) ? GNUNET_strdup (mime) : NULL;
@@ -710,23 +614,22 @@ static struct SearchTab *current_context_search_tab;
710 * Download was selected in the current search context menu. 614 * Download was selected in the current search context menu.
711 */ 615 */
712static void 616static void
713start_download_ctx_menu (gpointer user_data, 617start_download_ctx_menu (gpointer user_data, guint unused, GtkWidget * widget)
714 guint unused,
715 GtkWidget *widget)
716{ 618{
717 GtkTreePath *path; 619 GtkTreePath *path;
718 GtkTreeView *tv; 620 GtkTreeView *tv;
719 621
720 if (current_context_row_reference == NULL) 622 if (current_context_row_reference == NULL)
721 { 623 {
722 GNUNET_break (0); 624 GNUNET_break (0);
723 return; 625 return;
724 } 626 }
725 path = gtk_tree_row_reference_get_path (current_context_row_reference); 627 path = gtk_tree_row_reference_get_path (current_context_row_reference);
726 gtk_tree_row_reference_free (current_context_row_reference); 628 gtk_tree_row_reference_free (current_context_row_reference);
727 current_context_row_reference = NULL; 629 current_context_row_reference = NULL;
728 tv = GTK_TREE_VIEW (gtk_builder_get_object (current_context_search_tab->builder, 630 tv = GTK_TREE_VIEW (gtk_builder_get_object
729 "_search_result_frame")); 631 (current_context_search_tab->builder,
632 "_search_result_frame"));
730 start_download (tv, path, NULL, current_context_search_tab); 633 start_download (tv, path, NULL, current_context_search_tab);
731 gtk_tree_path_free (path); 634 gtk_tree_path_free (path);
732 current_context_search_tab = NULL; 635 current_context_search_tab = NULL;
@@ -737,15 +640,12 @@ start_download_ctx_menu (gpointer user_data,
737 * Download was selected in the current search context menu. 640 * Download was selected in the current search context menu.
738 */ 641 */
739static void 642static void
740abort_download_ctx_menu (gpointer user_data, 643abort_download_ctx_menu (gpointer user_data, guint unused, GtkWidget * widget)
741 guint unused,
742 GtkWidget *widget)
743{ 644{
744 struct DownloadEntry *de = user_data; 645 struct DownloadEntry *de = user_data;
745 646
746 GNUNET_assert (de->dc != NULL); 647 GNUNET_assert (de->dc != NULL);
747 GNUNET_FS_download_stop (de->dc, 648 GNUNET_FS_download_stop (de->dc, GNUNET_YES);
748 GNUNET_YES);
749 current_context_search_tab = NULL; 649 current_context_search_tab = NULL;
750} 650}
751 651
@@ -754,9 +654,8 @@ abort_download_ctx_menu (gpointer user_data,
754 * Copy current URI to clipboard. 654 * Copy current URI to clipboard.
755 */ 655 */
756static void 656static void
757copy_uri_to_clipboard_ctx_menu (gpointer user_data, 657copy_uri_to_clipboard_ctx_menu (gpointer user_data, guint unused,
758 guint unused, 658 GtkWidget * widget)
759 GtkWidget *widget)
760{ 659{
761 GtkTreePath *path; 660 GtkTreePath *path;
762 GtkTreeView *tv; 661 GtkTreeView *tv;
@@ -767,36 +666,34 @@ copy_uri_to_clipboard_ctx_menu (gpointer user_data,
767 GtkClipboard *cb; 666 GtkClipboard *cb;
768 667
769 if (current_context_row_reference == NULL) 668 if (current_context_row_reference == NULL)
770 { 669 {
771 GNUNET_break (0); 670 GNUNET_break (0);
772 return; 671 return;
773 } 672 }
774 path = gtk_tree_row_reference_get_path (current_context_row_reference); 673 path = gtk_tree_row_reference_get_path (current_context_row_reference);
775 gtk_tree_row_reference_free (current_context_row_reference); 674 gtk_tree_row_reference_free (current_context_row_reference);
776 current_context_row_reference = NULL; 675 current_context_row_reference = NULL;
777 tv = GTK_TREE_VIEW (gtk_builder_get_object (current_context_search_tab->builder, 676 tv = GTK_TREE_VIEW (gtk_builder_get_object
778 "_search_result_frame")); 677 (current_context_search_tab->builder,
678 "_search_result_frame"));
779 tm = gtk_tree_view_get_model (tv); 679 tm = gtk_tree_view_get_model (tv);
780 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path)) 680 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
781 { 681 {
782 GNUNET_break (0); 682 GNUNET_break (0);
783 gtk_tree_path_free (path); 683 gtk_tree_path_free (path);
784 return; 684 return;
785 } 685 }
786 gtk_tree_model_get (tm, &iter, 686 gtk_tree_model_get (tm, &iter, 1, &uri, -1);
787 1, &uri, -1);
788 gtk_tree_path_free (path); 687 gtk_tree_path_free (path);
789 current_context_search_tab = NULL; 688 current_context_search_tab = NULL;
790 if (uri == NULL) 689 if (uri == NULL)
791 { 690 {
792 GNUNET_break (0); 691 GNUNET_break (0);
793 return; 692 return;
794 } 693 }
795 uris = GNUNET_FS_uri_to_string (uri); 694 uris = GNUNET_FS_uri_to_string (uri);
796 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); 695 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
797 gtk_clipboard_set_text (cb, 696 gtk_clipboard_set_text (cb, uris, -1);
798 uris,
799 -1);
800 gtk_clipboard_store (cb); 697 gtk_clipboard_store (cb);
801 GNUNET_free (uris); 698 GNUNET_free (uris);
802} 699}
@@ -806,10 +703,8 @@ copy_uri_to_clipboard_ctx_menu (gpointer user_data,
806 * We got a right-click on the search result list. Display the context 703 * We got a right-click on the search result list. Display the context
807 * menu. 704 * menu.
808 */ 705 */
809static int 706static int
810search_list_on_menu(GtkWidget *widget, 707search_list_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data)
811 GdkEvent *event,
812 gpointer user_data)
813{ 708{
814 GdkEventButton *event_button; 709 GdkEventButton *event_button;
815 struct SearchTab *tab = user_data; 710 struct SearchTab *tab = user_data;
@@ -820,91 +715,79 @@ search_list_on_menu(GtkWidget *widget,
820 GtkTreeModel *tm; 715 GtkTreeModel *tm;
821 GtkTreeIter iter; 716 GtkTreeIter iter;
822 struct SearchResult *sr; 717 struct SearchResult *sr;
823 718
824 tv = GTK_TREE_VIEW (widget); 719 tv = GTK_TREE_VIEW (widget);
825 if (event->type == GDK_BUTTON_PRESS) 720 if (event->type == GDK_BUTTON_PRESS)
721 {
722 event_button = (GdkEventButton *) event;
723 if (event_button->button == 3)
826 { 724 {
827 event_button = (GdkEventButton *) event; 725 current_context_search_tab = tab;
828 if (event_button->button == 3) 726 if (current_context_row_reference != NULL)
829 { 727 {
830 current_context_search_tab = tab; 728 gtk_tree_row_reference_free (current_context_row_reference);
831 if (current_context_row_reference != NULL) 729 current_context_row_reference = NULL;
832 { 730 }
833 gtk_tree_row_reference_free (current_context_row_reference); 731 path = NULL;
834 current_context_row_reference = NULL; 732 if (FALSE ==
835 } 733 gtk_tree_view_get_path_at_pos (tv, event_button->x, event_button->y,
836 path = NULL; 734 &path, NULL, NULL, NULL))
837 if (FALSE == gtk_tree_view_get_path_at_pos (tv, 735 {
838 event_button->x, 736 /* nothing selected */
839 event_button->y, 737 current_context_search_tab = NULL;
840 &path, NULL, NULL, NULL)) 738 return FALSE;
841 { 739 }
842 /* nothing selected */ 740 tm = gtk_tree_view_get_model (tv);
843 current_context_search_tab = NULL; 741 gtk_tree_model_get_iter (tm, &iter, path);
844 return FALSE; 742 gtk_tree_model_get (tm, &iter, 9, &sr, -1);
845 } 743 current_context_row_reference = gtk_tree_row_reference_new (tm, path);
846 tm = gtk_tree_view_get_model (tv); 744 gtk_tree_path_free (path);
847 gtk_tree_model_get_iter (tm, &iter, path); 745
848 gtk_tree_model_get (tm, &iter, 746 /*
849 9, &sr, 747 * FIXME: have additional options, depending on status:
850 -1); 748 * - view full meta data (in new window)
851 current_context_row_reference = gtk_tree_row_reference_new (tm, 749 * - copy URI to clipboard
852 path); 750 * - start recursive download
853 gtk_tree_path_free (path); 751 * - abort active download (!)
854 752 * => need to know download status before creating menu!
855 /* 753 */
856 FIXME: have additional options, depending on status: 754 menu = GTK_MENU (gtk_menu_new ());
857 - view full meta data (in new window) 755 if (sr->download == NULL)
858 - copy URI to clipboard 756 {
859 - start recursive download 757 child = gtk_menu_item_new_with_label (_("_Download"));
860 - abort active download (!) 758 g_signal_connect (child, "activate",
861 => need to know download status before creating menu! 759 G_CALLBACK (start_download_ctx_menu), NULL);
862 */ 760 gtk_label_set_use_underline (GTK_LABEL
863 menu = GTK_MENU (gtk_menu_new ()); 761 (gtk_bin_get_child (GTK_BIN (child))),
864 if (sr->download == NULL) 762 TRUE);
865 { 763 gtk_widget_show (child);
866 child = gtk_menu_item_new_with_label (_("_Download")); 764 }
867 g_signal_connect (child, 765 else
868 "activate", 766 {
869 G_CALLBACK (start_download_ctx_menu), 767 child = gtk_menu_item_new_with_label (_("_Abort download"));
870 NULL); 768 g_signal_connect (child, "activate",
871 gtk_label_set_use_underline (GTK_LABEL 769 G_CALLBACK (abort_download_ctx_menu), sr->download);
872 (gtk_bin_get_child (GTK_BIN (child))), 770 gtk_label_set_use_underline (GTK_LABEL
873 TRUE); 771 (gtk_bin_get_child (GTK_BIN (child))),
874 gtk_widget_show (child); 772 TRUE);
875 } 773 gtk_widget_show (child);
876 else 774
877 { 775 }
878 child = gtk_menu_item_new_with_label (_("_Abort download")); 776
879 g_signal_connect (child, 777 child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
880 "activate", 778 g_signal_connect (child, "activate",
881 G_CALLBACK (abort_download_ctx_menu), 779 G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL);
882 sr->download); 780 gtk_label_set_use_underline (GTK_LABEL
883 gtk_label_set_use_underline (GTK_LABEL 781 (gtk_bin_get_child (GTK_BIN (child))), TRUE);
884 (gtk_bin_get_child (GTK_BIN (child))), 782 gtk_widget_show (child);
885 TRUE); 783
886 gtk_widget_show (child); 784
887 785
888 } 786 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
889 787 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event_button->button,
890 child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); 788 event_button->time);
891 g_signal_connect (child,
892 "activate",
893 G_CALLBACK (copy_uri_to_clipboard_ctx_menu),
894 NULL);
895 gtk_label_set_use_underline (GTK_LABEL
896 (gtk_bin_get_child (GTK_BIN (child))),
897 TRUE);
898 gtk_widget_show (child);
899
900
901
902 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
903 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
904 event_button->button,
905 event_button->time);
906 }
907 } 789 }
790 }
908 return FALSE; 791 return FALSE;
909} 792}
910 793
@@ -914,8 +797,7 @@ search_list_on_menu(GtkWidget *widget,
914 * areas. 797 * areas.
915 */ 798 */
916static void 799static void
917update_meta_data_views (GtkTreeView *tv, 800update_meta_data_views (GtkTreeView * tv, gpointer user_data)
918 gpointer user_data)
919{ 801{
920 struct SearchTab *tab = user_data; 802 struct SearchTab *tab = user_data;
921 GtkImage *image; 803 GtkImage *image;
@@ -927,36 +809,33 @@ update_meta_data_views (GtkTreeView *tv,
927 GdkPixbuf *pixbuf; 809 GdkPixbuf *pixbuf;
928 810
929 GNUNET_assert (tab->query_txt != NULL); 811 GNUNET_assert (tab->query_txt != NULL);
930 image = GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_preview_image")); 812 image =
931 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_meta_data_list_store")); 813 GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
814 ("GNUNET_GTK_main_window_preview_image"));
815 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
816 ("GNUNET_GTK_meta_data_list_store"));
932 817
933 sel = gtk_tree_view_get_selection (tv); 818 sel = gtk_tree_view_get_selection (tv);
934 gtk_list_store_clear (ms); 819 gtk_list_store_clear (ms);
935 if (TRUE != gtk_tree_selection_get_selected (sel, 820 if (TRUE != gtk_tree_selection_get_selected (sel, &model, &iter))
936 &model, 821 {
937 &iter)) 822 gtk_image_clear (image);
938 { 823 return;
939 gtk_image_clear (image); 824 }
940 return;
941 }
942 meta = NULL; 825 meta = NULL;
943 pixbuf = NULL; 826 pixbuf = NULL;
944 gtk_tree_model_get (model, 827 gtk_tree_model_get (model, &iter, 0, &meta, 3, &pixbuf, -1);
945 &iter,
946 0, &meta,
947 3, &pixbuf,
948 -1);
949 if (pixbuf != NULL) 828 if (pixbuf != NULL)
950 { 829 {
951 gtk_image_set_from_pixbuf (image, pixbuf); 830 gtk_image_set_from_pixbuf (image, pixbuf);
952 g_object_unref (G_OBJECT (pixbuf)); 831 g_object_unref (G_OBJECT (pixbuf));
953 } 832 }
954 if (meta != NULL) 833 if (meta != NULL)
955 { 834 {
956 GNUNET_CONTAINER_meta_data_iterate (meta, 835 GNUNET_CONTAINER_meta_data_iterate (meta,
957 &GNUNET_FS_GTK_add_meta_data_to_list_store, 836 &GNUNET_FS_GTK_add_meta_data_to_list_store,
958 ms); 837 ms);
959 } 838 }
960} 839}
961 840
962 841
@@ -967,22 +846,16 @@ static void
967update_search_label (struct SearchTab *tab) 846update_search_label (struct SearchTab *tab)
968{ 847{
969 char *name; 848 char *name;
970 849
971 while (tab->parent != NULL) 850 while (tab->parent != NULL)
972 tab = tab->parent->tab; 851 tab = tab->parent->tab;
973 if (tab->num_results > 0) 852 if (tab->num_results > 0)
974 GNUNET_asprintf (&name, 853 GNUNET_asprintf (&name, "%.*s%s (%u)", 20, tab->query_txt,
975 "%.*s%s (%u)", 854 strlen (tab->query_txt) > 20 ? "..." : "",
976 20, 855 tab->num_results);
977 tab->query_txt,
978 strlen (tab->query_txt) > 20 ? "..." : "",
979 tab->num_results);
980 else 856 else
981 GNUNET_asprintf (&name, 857 GNUNET_asprintf (&name, "%.*s%s", 20, tab->query_txt,
982 "%.*s%s", 858 strlen (tab->query_txt) > 20 ? "..." : "");
983 20,
984 tab->query_txt,
985 strlen (tab->query_txt) > 20 ? "..." : "");
986 gtk_label_set_text (tab->label, name); 859 gtk_label_set_text (tab->label, name);
987 GNUNET_free (name); 860 GNUNET_free (name);
988} 861}
@@ -997,15 +870,17 @@ close_search_tab (struct SearchTab *tab)
997 GtkNotebook *notebook; 870 GtkNotebook *notebook;
998 int index; 871 int index;
999 int i; 872 int i;
1000 873
1001 if (tab->parent != NULL) 874 if (tab->parent != NULL)
1002 { 875 {
1003 /* not a top-level search, do not close tab here! */ 876 /* not a top-level search, do not close tab here! */
1004 GNUNET_free (tab); 877 GNUNET_free (tab);
1005 return; 878 return;
1006 } 879 }
1007 880
1008 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 881 notebook =
882 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
883 ("GNUNET_GTK_main_window_notebook"));
1009 index = -1; 884 index = -1;
1010 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--) 885 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
1011 if (tab->frame == gtk_notebook_get_nth_page (notebook, i)) 886 if (tab->frame == gtk_notebook_get_nth_page (notebook, i))
@@ -1013,9 +888,7 @@ close_search_tab (struct SearchTab *tab)
1013 gtk_notebook_remove_page (notebook, index); 888 gtk_notebook_remove_page (notebook, index);
1014 g_object_unref (tab->builder); 889 g_object_unref (tab->builder);
1015 GNUNET_free (tab->query_txt); 890 GNUNET_free (tab->query_txt);
1016 GNUNET_CONTAINER_DLL_remove (search_tab_head, 891 GNUNET_CONTAINER_DLL_remove (search_tab_head, search_tab_tail, tab);
1017 search_tab_tail,
1018 tab);
1019 GNUNET_free (tab); 892 GNUNET_free (tab);
1020} 893}
1021 894
@@ -1025,11 +898,10 @@ close_search_tab (struct SearchTab *tab)
1025 */ 898 */
1026static struct PublishEntry * 899static struct PublishEntry *
1027handle_publish_completed (struct PublishEntry *ent, 900handle_publish_completed (struct PublishEntry *ent,
1028 const struct GNUNET_FS_Uri *uri) 901 const struct GNUNET_FS_Uri *uri)
1029{ 902{
1030 ent->uri = GNUNET_FS_uri_dup (uri); 903 ent->uri = GNUNET_FS_uri_dup (uri);
1031 return change_publish_colour (ent, 904 return change_publish_colour (ent, "green");
1032 "green");
1033} 905}
1034 906
1035 907
@@ -1038,12 +910,10 @@ handle_publish_completed (struct PublishEntry *ent,
1038 * Handle error. 910 * Handle error.
1039 */ 911 */
1040static struct PublishEntry * 912static struct PublishEntry *
1041handle_publish_error (struct PublishEntry *ent, 913handle_publish_error (struct PublishEntry *ent, const char *emsg)
1042 const char *emsg)
1043{ 914{
1044 GNUNET_break (0); 915 GNUNET_break (0);
1045 return change_publish_colour (ent, 916 return change_publish_colour (ent, "red");
1046 "red");
1047} 917}
1048 918
1049 919
@@ -1059,30 +929,30 @@ close_publish_tab (struct PublishEntry *ent)
1059 int i; 929 int i;
1060 930
1061 if (ent == NULL) 931 if (ent == NULL)
1062 { 932 {
1063 GNUNET_break (0); 933 GNUNET_break (0);
1064 return; 934 return;
1065 } 935 }
1066 gtk_tree_row_reference_free (ent->rr); 936 gtk_tree_row_reference_free (ent->rr);
1067 if (GNUNET_YES != ent->is_top) 937 if (GNUNET_YES != ent->is_top)
1068 { 938 {
1069 GNUNET_free (ent); 939 GNUNET_free (ent);
1070 return; 940 return;
1071 } 941 }
1072 tab = ent->tab; 942 tab = ent->tab;
1073 if (ent->uri != NULL) 943 if (ent->uri != NULL)
1074 GNUNET_FS_uri_destroy (ent->uri); 944 GNUNET_FS_uri_destroy (ent->uri);
1075 GNUNET_free (ent); 945 GNUNET_free (ent);
1076 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 946 notebook =
947 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
948 ("GNUNET_GTK_main_window_notebook"));
1077 index = -1; 949 index = -1;
1078 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--) 950 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
1079 if (tab->frame == gtk_notebook_get_nth_page (notebook, i)) 951 if (tab->frame == gtk_notebook_get_nth_page (notebook, i))
1080 index = i; 952 index = i;
1081 gtk_notebook_remove_page (notebook, index); 953 gtk_notebook_remove_page (notebook, index);
1082 g_object_unref (tab->builder); 954 g_object_unref (tab->builder);
1083 GNUNET_CONTAINER_DLL_remove (publish_tab_head, 955 GNUNET_CONTAINER_DLL_remove (publish_tab_head, publish_tab_tail, tab);
1084 publish_tab_tail,
1085 tab);
1086 GNUNET_free (tab); 956 GNUNET_free (tab);
1087} 957}
1088 958
@@ -1091,15 +961,15 @@ close_publish_tab (struct PublishEntry *ent)
1091 * Tell FS to stop a search. 961 * Tell FS to stop a search.
1092 */ 962 */
1093static void 963static void
1094stop_search (GtkButton *button, 964stop_search (GtkButton * button, gpointer user_data)
1095 gpointer user_data)
1096{ 965{
1097 struct SearchTab *tab = user_data; 966 struct SearchTab *tab = user_data;
967
1098 if (tab->sc != NULL) 968 if (tab->sc != NULL)
1099 { 969 {
1100 GNUNET_FS_search_stop (tab->sc); 970 GNUNET_FS_search_stop (tab->sc);
1101 tab->sc = NULL; 971 tab->sc = NULL;
1102 } 972 }
1103} 973}
1104 974
1105 975
@@ -1111,8 +981,7 @@ stop_search (GtkButton *button,
1111 * the tab should be closed. 981 * the tab should be closed.
1112 */ 982 */
1113static void 983static void
1114clear_downloads (GtkButton *button, 984clear_downloads (GtkButton * button, gpointer user_data)
1115 gpointer user_data)
1116{ 985{
1117 struct SearchTab *tab = user_data; 986 struct SearchTab *tab = user_data;
1118 struct SearchResult *sr; 987 struct SearchResult *sr;
@@ -1123,15 +992,11 @@ clear_downloads (GtkButton *button,
1123 if (TRUE != gtk_tree_model_get_iter_first (tm, &iter)) 992 if (TRUE != gtk_tree_model_get_iter_first (tm, &iter))
1124 return; 993 return;
1125 do 994 do
1126 { 995 {
1127 gtk_tree_model_get (tm, &iter, 996 gtk_tree_model_get (tm, &iter, 9, &sr, -1);
1128 9, &sr, 997 if ((sr->download != NULL) && (sr->download->is_done == GNUNET_YES))
1129 -1); 998 GNUNET_FS_download_stop (sr->download->dc, GNUNET_YES);
1130 if ( (sr->download != NULL) && 999 }
1131 (sr->download->is_done == GNUNET_YES) )
1132 GNUNET_FS_download_stop (sr->download->dc,
1133 GNUNET_YES);
1134 }
1135 while (TRUE == gtk_tree_model_iter_next (tm, &iter)); 1000 while (TRUE == gtk_tree_model_iter_next (tm, &iter));
1136} 1001}
1137 1002
@@ -1141,16 +1006,16 @@ clear_downloads (GtkButton *button,
1141 * Tell FS to pause a search. 1006 * Tell FS to pause a search.
1142 */ 1007 */
1143static void 1008static void
1144pause_search (GtkButton *button, 1009pause_search (GtkButton * button, gpointer user_data)
1145 gpointer user_data)
1146{ 1010{
1147 struct SearchTab *tab = user_data; 1011 struct SearchTab *tab = user_data;
1012
1148 if (tab->sc != NULL) 1013 if (tab->sc != NULL)
1149 { 1014 {
1150 GNUNET_FS_search_pause (tab->sc); 1015 GNUNET_FS_search_pause (tab->sc);
1151 gtk_widget_show (tab->play_button); 1016 gtk_widget_show (tab->play_button);
1152 gtk_widget_hide (tab->pause_button); 1017 gtk_widget_hide (tab->pause_button);
1153 } 1018 }
1154} 1019}
1155 1020
1156 1021
@@ -1158,16 +1023,16 @@ pause_search (GtkButton *button,
1158 * Tell FS to resume a search. 1023 * Tell FS to resume a search.
1159 */ 1024 */
1160static void 1025static void
1161continue_search (GtkButton *button, 1026continue_search (GtkButton * button, gpointer user_data)
1162 gpointer user_data)
1163{ 1027{
1164 struct SearchTab *tab = user_data; 1028 struct SearchTab *tab = user_data;
1029
1165 if (tab->sc != NULL) 1030 if (tab->sc != NULL)
1166 { 1031 {
1167 GNUNET_FS_search_continue (tab->sc); 1032 GNUNET_FS_search_continue (tab->sc);
1168 gtk_widget_show (tab->pause_button); 1033 gtk_widget_show (tab->pause_button);
1169 gtk_widget_hide (tab->play_button); 1034 gtk_widget_hide (tab->play_button);
1170 } 1035 }
1171} 1036}
1172 1037
1173 1038
@@ -1180,7 +1045,7 @@ continue_search (GtkButton *button,
1180 */ 1045 */
1181static struct SearchTab * 1046static struct SearchTab *
1182setup_search (struct GNUNET_FS_SearchContext *sc, 1047setup_search (struct GNUNET_FS_SearchContext *sc,
1183 const struct GNUNET_FS_Uri *query) 1048 const struct GNUNET_FS_Uri *query)
1184{ 1049{
1185 struct SearchTab *tab; 1050 struct SearchTab *tab;
1186 GtkTreeView *tv; 1051 GtkTreeView *tv;
@@ -1189,86 +1054,87 @@ setup_search (struct GNUNET_FS_SearchContext *sc,
1189 gint pages; 1054 gint pages;
1190 1055
1191 tab = GNUNET_malloc (sizeof (struct SearchTab)); 1056 tab = GNUNET_malloc (sizeof (struct SearchTab));
1192 GNUNET_CONTAINER_DLL_insert (search_tab_head, 1057 GNUNET_CONTAINER_DLL_insert (search_tab_head, search_tab_tail, tab);
1193 search_tab_tail,
1194 tab);
1195 tab->sc = sc; 1058 tab->sc = sc;
1196 if (query == NULL) 1059 if (query == NULL)
1197 { 1060 {
1198 tab->query_txt = GNUNET_strdup ("*"); 1061 tab->query_txt = GNUNET_strdup ("*");
1199 } 1062 }
1200 else 1063 else
1201 { 1064 {
1202 if (GNUNET_FS_uri_test_ksk (query)) 1065 if (GNUNET_FS_uri_test_ksk (query))
1203 tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query); 1066 tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query);
1204 else 1067 else
1205 tab->query_txt = GNUNET_FS_uri_to_string (query); 1068 tab->query_txt = GNUNET_FS_uri_to_string (query);
1206 } 1069 }
1207 tab->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_search_tab.glade"); 1070 tab->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_search_tab.glade");
1208 tab->ts = GTK_TREE_STORE (gtk_builder_get_object (tab->builder, 1071 tab->ts =
1209 "GNUNET_GTK_file_sharing_result_tree_store")); 1072 GTK_TREE_STORE (gtk_builder_get_object
1073 (tab->builder,
1074 "GNUNET_GTK_file_sharing_result_tree_store"));
1210 /* load frame */ 1075 /* load frame */
1211 sf = GTK_WINDOW (gtk_builder_get_object (tab->builder, 1076 sf = GTK_WINDOW (gtk_builder_get_object
1212 "_search_result_frame_window")); 1077 (tab->builder, "_search_result_frame_window"));
1213 tab->frame = gtk_bin_get_child (GTK_BIN (sf)); 1078 tab->frame = gtk_bin_get_child (GTK_BIN (sf));
1214 gtk_widget_ref (tab->frame); 1079 gtk_widget_ref (tab->frame);
1215 gtk_container_remove (GTK_CONTAINER (sf), tab->frame); 1080 gtk_container_remove (GTK_CONTAINER (sf), tab->frame);
1216 gtk_widget_destroy (GTK_WIDGET (sf)); 1081 gtk_widget_destroy (GTK_WIDGET (sf));
1217 1082
1218 /* load tab_label */ 1083 /* load tab_label */
1219 sf = GTK_WINDOW (gtk_builder_get_object (tab->builder, 1084 sf = GTK_WINDOW (gtk_builder_get_object
1220 "_search_result_label_window")); 1085 (tab->builder, "_search_result_label_window"));
1221 tab->tab_label = gtk_bin_get_child (GTK_BIN (sf)); 1086 tab->tab_label = gtk_bin_get_child (GTK_BIN (sf));
1222 gtk_widget_ref (tab->tab_label); 1087 gtk_widget_ref (tab->tab_label);
1223 gtk_container_remove (GTK_CONTAINER (sf), tab->tab_label); 1088 gtk_container_remove (GTK_CONTAINER (sf), tab->tab_label);
1224 gtk_widget_destroy (GTK_WIDGET (sf)); 1089 gtk_widget_destroy (GTK_WIDGET (sf));
1225 1090
1226 /* get refs to widgets */ 1091 /* get refs to widgets */
1227 tab->label = GTK_LABEL (gtk_builder_get_object (tab->builder, 1092 tab->label =
1228 "_search_result_label_window_label")); 1093 GTK_LABEL (gtk_builder_get_object
1229 1094 (tab->builder, "_search_result_label_window_label"));
1230 tab->close_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, 1095
1231 "_search_result_label_close_button")); 1096 tab->close_button =
1232 g_signal_connect(G_OBJECT(tab->close_button), "clicked", 1097 GTK_WIDGET (gtk_builder_get_object
1233 G_CALLBACK(stop_search), tab); 1098 (tab->builder, "_search_result_label_close_button"));
1234 tab->clear_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, 1099 g_signal_connect (G_OBJECT (tab->close_button), "clicked",
1235 "_search_result_label_clear_button")); 1100 G_CALLBACK (stop_search), tab);
1236 g_signal_connect(G_OBJECT(tab->clear_button), "clicked", 1101 tab->clear_button =
1237 G_CALLBACK(clear_downloads), tab); 1102 GTK_WIDGET (gtk_builder_get_object
1238 tab->play_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, 1103 (tab->builder, "_search_result_label_clear_button"));
1239 "_search_result_label_play_button")); 1104 g_signal_connect (G_OBJECT (tab->clear_button), "clicked",
1240 g_signal_connect(G_OBJECT(tab->play_button), "clicked", 1105 G_CALLBACK (clear_downloads), tab);
1241 G_CALLBACK(continue_search), tab); 1106 tab->play_button =
1242 tab->pause_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, 1107 GTK_WIDGET (gtk_builder_get_object
1243 "_search_result_label_pause_button")); 1108 (tab->builder, "_search_result_label_play_button"));
1244 g_signal_connect(G_OBJECT(tab->pause_button), "clicked", 1109 g_signal_connect (G_OBJECT (tab->play_button), "clicked",
1245 G_CALLBACK(pause_search), tab); 1110 G_CALLBACK (continue_search), tab);
1111 tab->pause_button =
1112 GTK_WIDGET (gtk_builder_get_object
1113 (tab->builder, "_search_result_label_pause_button"));
1114 g_signal_connect (G_OBJECT (tab->pause_button), "clicked",
1115 G_CALLBACK (pause_search), tab);
1246 /* patch text */ 1116 /* patch text */
1247 update_search_label (tab); 1117 update_search_label (tab);
1248 1118
1249 /* add signal handlers */ 1119 /* add signal handlers */
1250 tv = GTK_TREE_VIEW (gtk_builder_get_object (tab->builder, 1120 tv = GTK_TREE_VIEW (gtk_builder_get_object
1251 "_search_result_frame")); 1121 (tab->builder, "_search_result_frame"));
1252 g_signal_connect(G_OBJECT(tv), "row-activated", 1122 g_signal_connect (G_OBJECT (tv), "row-activated", G_CALLBACK (start_download),
1253 G_CALLBACK(start_download), tab); 1123 tab);
1254 g_signal_connect(G_OBJECT(tv), "cursor-changed", 1124 g_signal_connect (G_OBJECT (tv), "cursor-changed",
1255 G_CALLBACK(update_meta_data_views), tab); 1125 G_CALLBACK (update_meta_data_views), tab);
1256 g_signal_connect (G_OBJECT(tv), 1126 g_signal_connect (G_OBJECT (tv), "button_press_event",
1257 "button_press_event", 1127 G_CALLBACK (search_list_on_menu), tab);
1258 G_CALLBACK(search_list_on_menu), 1128
1259 tab);
1260
1261 1129
1262 /* make visible */ 1130 /* make visible */
1263 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 1131 notebook =
1132 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1133 ("GNUNET_GTK_main_window_notebook"));
1264 pages = gtk_notebook_get_n_pages (notebook); 1134 pages = gtk_notebook_get_n_pages (notebook);
1265 gtk_notebook_insert_page (notebook, 1135 gtk_notebook_insert_page (notebook, tab->frame, tab->tab_label, pages - 1);
1266 tab->frame, 1136 gtk_notebook_set_current_page (notebook, pages - 1);
1267 tab->tab_label, 1137 gtk_widget_show (GTK_WIDGET (notebook));
1268 pages - 1);
1269 gtk_notebook_set_current_page (notebook,
1270 pages - 1);
1271 gtk_widget_show (GTK_WIDGET (notebook));
1272 return tab; 1138 return tab;
1273} 1139}
1274 1140
@@ -1282,7 +1148,7 @@ setup_search (struct GNUNET_FS_SearchContext *sc,
1282 */ 1148 */
1283static struct SearchTab * 1149static struct SearchTab *
1284setup_inner_search (struct GNUNET_FS_SearchContext *sc, 1150setup_inner_search (struct GNUNET_FS_SearchContext *sc,
1285 struct SearchResult *parent) 1151 struct SearchResult *parent)
1286{ 1152{
1287 struct SearchTab *ret; 1153 struct SearchTab *ret;
1288 1154
@@ -1316,13 +1182,12 @@ setup_inner_search (struct GNUNET_FS_SearchContext *sc,
1316 * @return entry for the search result 1182 * @return entry for the search result
1317 */ 1183 */
1318struct SearchResult * 1184struct SearchResult *
1319GNUNET_GTK_add_search_result (struct SearchTab *tab, 1185GNUNET_GTK_add_search_result (struct SearchTab *tab, GtkTreeIter * iter,
1320 GtkTreeIter *iter, 1186 GtkTreeRowReference * parent_rr,
1321 GtkTreeRowReference *parent_rr, 1187 const struct GNUNET_FS_Uri *uri,
1322 const struct GNUNET_FS_Uri *uri, 1188 const struct GNUNET_CONTAINER_MetaData *meta,
1323 const struct GNUNET_CONTAINER_MetaData *meta, 1189 struct GNUNET_FS_SearchResult *result,
1324 struct GNUNET_FS_SearchResult *result, 1190 uint32_t applicability_rank)
1325 uint32_t applicability_rank)
1326{ 1191{
1327 struct SearchResult *sr; 1192 struct SearchResult *sr;
1328 GtkTreePath *tp; 1193 GtkTreePath *tp;
@@ -1334,45 +1199,46 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab,
1334 GtkTreeIter *pitr; 1199 GtkTreeIter *pitr;
1335 GtkTreeIter pmem; 1200 GtkTreeIter pmem;
1336 GtkTreePath *path; 1201 GtkTreePath *path;
1337 GtkTreeModel *tm; 1202 GtkTreeModel *tm;
1338 GtkTreeStore *ts; 1203 GtkTreeStore *ts;
1339 uint64_t fsize; 1204 uint64_t fsize;
1340 1205
1341 if ( (uri != NULL) && 1206 if ((uri != NULL) && (!GNUNET_FS_uri_test_loc (uri)) &&
1342 (!GNUNET_FS_uri_test_loc (uri)) && 1207 (!GNUNET_FS_uri_test_chk (uri)))
1343 (!GNUNET_FS_uri_test_chk (uri)) ) 1208 {
1344 { 1209 fsize = 0;
1345 fsize = 0; 1210 mime = GNUNET_strdup ("GNUnet namespace");
1346 mime = GNUNET_strdup ("GNUnet namespace"); 1211 status_colour = "lightgreen";
1347 status_colour = "lightgreen"; 1212 }
1348 }
1349 else if (uri != NULL) 1213 else if (uri != NULL)
1350 { 1214 {
1351 fsize = GNUNET_FS_uri_chk_get_file_size (uri); 1215 fsize = GNUNET_FS_uri_chk_get_file_size (uri);
1352 mime = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 1216 mime =
1353 EXTRACTOR_METATYPE_MIMETYPE, 1217 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
1354 EXTRACTOR_METATYPE_FORMAT, 1218 EXTRACTOR_METATYPE_MIMETYPE,
1355 -1); 1219 EXTRACTOR_METATYPE_FORMAT,
1356 status_colour = "white"; 1220 -1);
1357 } 1221 status_colour = "white";
1222 }
1358 else 1223 else
1359 { 1224 {
1360 fsize = 0; 1225 fsize = 0;
1361 status_colour = "gray"; 1226 status_colour = "gray";
1362 mime = NULL; 1227 mime = NULL;
1363 } 1228 }
1364 desc = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 1229 desc =
1365 EXTRACTOR_METATYPE_PACKAGE_NAME, 1230 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
1366 EXTRACTOR_METATYPE_TITLE, 1231 EXTRACTOR_METATYPE_PACKAGE_NAME,
1367 EXTRACTOR_METATYPE_BOOK_TITLE, 1232 EXTRACTOR_METATYPE_TITLE,
1368 EXTRACTOR_METATYPE_FILENAME, 1233 EXTRACTOR_METATYPE_BOOK_TITLE,
1369 EXTRACTOR_METATYPE_DESCRIPTION, 1234 EXTRACTOR_METATYPE_FILENAME,
1370 EXTRACTOR_METATYPE_SUMMARY, 1235 EXTRACTOR_METATYPE_DESCRIPTION,
1371 EXTRACTOR_METATYPE_ALBUM, 1236 EXTRACTOR_METATYPE_SUMMARY,
1372 EXTRACTOR_METATYPE_COMMENT, 1237 EXTRACTOR_METATYPE_ALBUM,
1373 EXTRACTOR_METATYPE_SUBJECT, 1238 EXTRACTOR_METATYPE_COMMENT,
1374 EXTRACTOR_METATYPE_KEYWORDS, 1239 EXTRACTOR_METATYPE_SUBJECT,
1375 -1); 1240 EXTRACTOR_METATYPE_KEYWORDS,
1241 -1);
1376 if (desc == NULL) 1242 if (desc == NULL)
1377 desc = GNUNET_strdup (_("no description supplied")); 1243 desc = GNUNET_strdup (_("no description supplied"));
1378 if (uri == NULL) 1244 if (uri == NULL)
@@ -1385,85 +1251,76 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab,
1385 sr->result = result; 1251 sr->result = result;
1386 sr->tab = tab; 1252 sr->tab = tab;
1387 if (parent_rr != NULL) 1253 if (parent_rr != NULL)
1254 {
1255 /* get piter from parent */
1256 path = gtk_tree_row_reference_get_path (parent_rr);
1257 tm = gtk_tree_row_reference_get_model (parent_rr);
1258 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (tm), &pmem, path))
1388 { 1259 {
1389 /* get piter from parent */ 1260 GNUNET_break (0);
1390 path = gtk_tree_row_reference_get_path (parent_rr); 1261 gtk_tree_path_free (path);
1391 tm = gtk_tree_row_reference_get_model (parent_rr); 1262 /* desperate measure: make top-level entry */
1392 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (tm),
1393 &pmem, path))
1394 {
1395 GNUNET_break (0);
1396 gtk_tree_path_free (path);
1397 /* desperate measure: make top-level entry */
1398 pitr = NULL;
1399 }
1400 else
1401 {
1402 pitr = &pmem;
1403 }
1404 ts = GTK_TREE_STORE (tm);
1405 }
1406 else
1407 {
1408 /* top-level result */
1409 pitr = NULL; 1263 pitr = NULL;
1410 ts = tab->ts;
1411 } 1264 }
1412 gtk_tree_store_insert_with_values (ts, 1265 else
1413 iter,
1414 pitr,
1415 G_MAXINT,
1416 0, GNUNET_CONTAINER_meta_data_duplicate (meta),
1417 1, (uri == NULL) ? NULL : GNUNET_FS_uri_dup (uri),
1418 2, (uri == NULL) ? 0 : fsize,
1419 3, pixbuf /* preview */,
1420 4, 0 /* percent progress */,
1421 5, 0 /* percent availability */,
1422 6, desc /* filename/description */,
1423 7, uris,
1424 8, status_colour,
1425 9, sr,
1426 10, mime,
1427 11, applicability_rank,
1428 12, 0 /* avail-cert */,
1429 13, 0 /* avail-rank */,
1430 -1);
1431 if (tab != NULL)
1432 { 1266 {
1433 while (tab->parent != NULL) 1267 pitr = &pmem;
1434 tab = tab->parent->tab;
1435 tab->num_results++;
1436 } 1268 }
1269 ts = GTK_TREE_STORE (tm);
1270 }
1271 else
1272 {
1273 /* top-level result */
1274 pitr = NULL;
1275 ts = tab->ts;
1276 }
1277 gtk_tree_store_insert_with_values (ts, iter, pitr, G_MAXINT, 0,
1278 GNUNET_CONTAINER_meta_data_duplicate
1279 (meta), 1,
1280 (uri ==
1281 NULL) ? NULL : GNUNET_FS_uri_dup (uri), 2,
1282 (uri == NULL) ? 0 : fsize, 3,
1283 pixbuf /* preview */ ,
1284 4, 0 /* percent progress */ ,
1285 5, 0 /* percent availability */ ,
1286 6, desc /* filename/description */ ,
1287 7, uris, 8, status_colour, 9, sr, 10, mime,
1288 11, applicability_rank, 12,
1289 0 /* avail-cert */ ,
1290 13, 0 /* avail-rank */ ,
1291 -1);
1292 if (tab != NULL)
1293 {
1294 while (tab->parent != NULL)
1295 tab = tab->parent->tab;
1296 tab->num_results++;
1297 }
1437 if (pixbuf != NULL) 1298 if (pixbuf != NULL)
1438 g_object_unref (pixbuf); 1299 g_object_unref (pixbuf);
1439 GNUNET_free (uris); 1300 GNUNET_free (uris);
1440 GNUNET_free (desc); 1301 GNUNET_free (desc);
1441 GNUNET_free_non_null (mime); 1302 GNUNET_free_non_null (mime);
1442 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), 1303 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), iter);
1443 iter); 1304 sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp);
1444 sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts),
1445 tp);
1446 gtk_tree_path_free (tp); 1305 gtk_tree_path_free (tp);
1447 return sr; 1306 return sr;
1448} 1307}
1449 1308
1450 1309
1451static struct SearchResult * 1310static struct SearchResult *
1452process_search_result (void *cls, 1311process_search_result (void *cls, struct SearchResult *parent,
1453 struct SearchResult *parent, 1312 const struct GNUNET_FS_Uri *uri,
1454 const struct GNUNET_FS_Uri *uri, 1313 const struct GNUNET_CONTAINER_MetaData *meta,
1455 const struct GNUNET_CONTAINER_MetaData *meta, 1314 struct GNUNET_FS_SearchResult *result,
1456 struct GNUNET_FS_SearchResult *result, 1315 uint32_t applicability_rank)
1457 uint32_t applicability_rank)
1458{ 1316{
1459 struct SearchTab *tab = cls; 1317 struct SearchTab *tab = cls;
1460 struct SearchResult *sr; 1318 struct SearchResult *sr;
1461 GtkTreeIter iter; 1319 GtkTreeIter iter;
1462 1320
1463 sr = GNUNET_GTK_add_search_result (tab, &iter, 1321 sr = GNUNET_GTK_add_search_result (tab, &iter,
1464 (parent != NULL) ? parent->rr : NULL, 1322 (parent != NULL) ? parent->rr : NULL, uri,
1465 uri, 1323 meta, result, applicability_rank);
1466 meta, result, applicability_rank);
1467 update_search_label (tab); 1324 update_search_label (tab);
1468 return sr; 1325 return sr;
1469} 1326}
@@ -1480,10 +1337,9 @@ process_search_result (void *cls,
1480 * @return NULL on error, otherwise tree store matching iter 1337 * @return NULL on error, otherwise tree store matching iter
1481 */ 1338 */
1482struct SearchTab * 1339struct SearchTab *
1483GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, 1340GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, struct SearchResult **srp,
1484 struct SearchResult **srp, 1341 const struct GNUNET_CONTAINER_MetaData *meta,
1485 const struct GNUNET_CONTAINER_MetaData *meta, 1342 const struct GNUNET_FS_Uri *uri)
1486 const struct GNUNET_FS_Uri *uri)
1487{ 1343{
1488 struct SearchTab *utab; 1344 struct SearchTab *utab;
1489 struct SearchResult *sr; 1345 struct SearchResult *sr;
@@ -1492,37 +1348,32 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter,
1492 1348
1493 utab = search_tab_head; 1349 utab = search_tab_head;
1494 while (utab != NULL) 1350 while (utab != NULL)
1495 { 1351 {
1496 if (utab->sc == NULL) 1352 if (utab->sc == NULL)
1497 break; 1353 break;
1498 utab = utab->next; 1354 utab = utab->next;
1499 } 1355 }
1500 if (utab == NULL) 1356 if (utab == NULL)
1501 { 1357 {
1502 utab = setup_search (NULL, NULL); 1358 utab = setup_search (NULL, NULL);
1503 gtk_widget_set_visible (utab->close_button, 1359 gtk_widget_set_visible (utab->close_button, FALSE);
1504 FALSE); 1360 gtk_widget_set_visible (utab->pause_button, FALSE);
1505 gtk_widget_set_visible (utab->pause_button, 1361 }
1506 FALSE);
1507 }
1508 else 1362 else
1509 { 1363 {
1510 /* make 'utab' the current page */ 1364 /* make 'utab' the current page */
1511 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 1365 notebook =
1512 for (page=0;page<gtk_notebook_get_n_pages (notebook);page++) 1366 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1513 if (utab->frame == 1367 ("GNUNET_GTK_main_window_notebook"));
1514 gtk_notebook_get_nth_page (notebook, 1368 for (page = 0; page < gtk_notebook_get_n_pages (notebook); page++)
1515 page)) 1369 if (utab->frame == gtk_notebook_get_nth_page (notebook, page))
1516 { 1370 {
1517 gtk_notebook_set_current_page (notebook, 1371 gtk_notebook_set_current_page (notebook, page);
1518 page); 1372 break;
1519 break; 1373 }
1520 } 1374 }
1521 } 1375 sr = GNUNET_GTK_add_search_result (utab, iter, NULL, uri, meta, NULL, 0);
1522 sr = GNUNET_GTK_add_search_result (utab, iter, 1376
1523 NULL, uri, meta,
1524 NULL, 0);
1525
1526 if (NULL != srp) 1377 if (NULL != srp)
1527 *srp = sr; 1378 *srp = sr;
1528 return utab; 1379 return utab;
@@ -1530,8 +1381,7 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter,
1530 1381
1531 1382
1532static struct SearchTab * 1383static struct SearchTab *
1533handle_search_error (struct SearchTab *sr, 1384handle_search_error (struct SearchTab *sr, const char *emsg)
1534 const char *emsg)
1535{ 1385{
1536 /* FIXME: implement error handler */ 1386 /* FIXME: implement error handler */
1537 GNUNET_break (0); 1387 GNUNET_break (0);
@@ -1541,10 +1391,10 @@ handle_search_error (struct SearchTab *sr,
1541 1391
1542static struct SearchResult * 1392static struct SearchResult *
1543update_search_result (struct SearchResult *sr, 1393update_search_result (struct SearchResult *sr,
1544 const struct GNUNET_CONTAINER_MetaData *meta, 1394 const struct GNUNET_CONTAINER_MetaData *meta,
1545 int32_t availability_rank, 1395 int32_t availability_rank,
1546 uint32_t availability_certainty, 1396 uint32_t availability_certainty,
1547 uint32_t applicability_rank) 1397 uint32_t applicability_rank)
1548{ 1398{
1549 GtkTreeIter iter; 1399 GtkTreeIter iter;
1550 struct GNUNET_CONTAINER_MetaData *ometa; 1400 struct GNUNET_CONTAINER_MetaData *ometa;
@@ -1561,67 +1411,64 @@ update_search_result (struct SearchResult *sr,
1561 1411
1562 if (sr == NULL) 1412 if (sr == NULL)
1563 return NULL; 1413 return NULL;
1564 desc = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 1414 desc =
1565 EXTRACTOR_METATYPE_PACKAGE_NAME, 1415 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
1566 EXTRACTOR_METATYPE_TITLE, 1416 EXTRACTOR_METATYPE_PACKAGE_NAME,
1567 EXTRACTOR_METATYPE_BOOK_TITLE, 1417 EXTRACTOR_METATYPE_TITLE,
1568 EXTRACTOR_METATYPE_FILENAME, 1418 EXTRACTOR_METATYPE_BOOK_TITLE,
1569 EXTRACTOR_METATYPE_DESCRIPTION, 1419 EXTRACTOR_METATYPE_FILENAME,
1570 EXTRACTOR_METATYPE_SUMMARY, 1420 EXTRACTOR_METATYPE_DESCRIPTION,
1571 EXTRACTOR_METATYPE_ALBUM, 1421 EXTRACTOR_METATYPE_SUMMARY,
1572 EXTRACTOR_METATYPE_COMMENT, 1422 EXTRACTOR_METATYPE_ALBUM,
1573 EXTRACTOR_METATYPE_SUBJECT, 1423 EXTRACTOR_METATYPE_COMMENT,
1574 EXTRACTOR_METATYPE_KEYWORDS, 1424 EXTRACTOR_METATYPE_SUBJECT,
1575 -1); 1425 EXTRACTOR_METATYPE_KEYWORDS,
1426 -1);
1576 if (desc == NULL) 1427 if (desc == NULL)
1577 desc = GNUNET_strdup (_("no description supplied")); 1428 desc = GNUNET_strdup (_("no description supplied"));
1578 mime = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 1429 mime =
1579 EXTRACTOR_METATYPE_MIMETYPE, 1430 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
1580 EXTRACTOR_METATYPE_FORMAT, 1431 EXTRACTOR_METATYPE_MIMETYPE,
1581 -1); 1432 EXTRACTOR_METATYPE_FORMAT,
1433 -1);
1582 pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta); 1434 pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta);
1583 tp = gtk_tree_row_reference_get_path (sr->rr); 1435 tp = gtk_tree_row_reference_get_path (sr->rr);
1584 tm = gtk_tree_row_reference_get_model (sr->rr); 1436 tm = gtk_tree_row_reference_get_model (sr->rr);
1585 ts = GTK_TREE_STORE (tm); 1437 ts = GTK_TREE_STORE (tm);
1586 gtk_tree_model_get_iter (tm, &iter, tp); 1438 gtk_tree_model_get_iter (tm, &iter, tp);
1587 gtk_tree_path_free (tp); 1439 gtk_tree_path_free (tp);
1588 gtk_tree_model_get (tm, 1440 gtk_tree_model_get (tm, &iter, 0, &ometa, -1);
1589 &iter,
1590 0, &ometa,
1591 -1);
1592 if (meta != NULL) 1441 if (meta != NULL)
1593 GNUNET_CONTAINER_meta_data_destroy (ometa); 1442 GNUNET_CONTAINER_meta_data_destroy (ometa);
1594 if (availability_certainty > 0) 1443 if (availability_certainty > 0)
1595 percent_avail = (availability_certainty + availability_rank) * 50 / availability_certainty; 1444 percent_avail =
1445 (availability_certainty +
1446 availability_rank) * 50 / availability_certainty;
1596 else 1447 else
1597 percent_avail = 0; 1448 percent_avail = 0;
1598 gtk_tree_store_set (ts, 1449 gtk_tree_store_set (ts, &iter, 0, GNUNET_CONTAINER_meta_data_duplicate (meta),
1599 &iter, 1450 3, pixbuf /* preview */ ,
1600 0, GNUNET_CONTAINER_meta_data_duplicate (meta), 1451 5, (guint) percent_avail /* percent availability */ ,
1601 3, pixbuf /* preview */, 1452 6, desc /* filename/description */ ,
1602 5, (guint) percent_avail /* percent availability */, 1453 10, mime, 11, (guint) applicability_rank, 12,
1603 6, desc /* filename/description */, 1454 (guint) availability_certainty, 13,
1604 10, mime, 1455 (gint) availability_rank, -1);
1605 11, (guint) applicability_rank,
1606 12, (guint) availability_certainty,
1607 13, (gint) availability_rank,
1608 -1);
1609 if (pixbuf != NULL) 1456 if (pixbuf != NULL)
1610 g_object_unref (pixbuf); 1457 g_object_unref (pixbuf);
1611 GNUNET_free (desc); 1458 GNUNET_free (desc);
1612 GNUNET_free_non_null (mime); 1459 GNUNET_free_non_null (mime);
1613 1460
1614 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 1461 notebook =
1462 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1463 ("GNUNET_GTK_main_window_notebook"));
1615 page = gtk_notebook_get_current_page (notebook); 1464 page = gtk_notebook_get_current_page (notebook);
1616 if (gtk_notebook_get_nth_page (notebook, 1465 if (gtk_notebook_get_nth_page (notebook, page) == sr->tab->frame)
1617 page) == sr->tab->frame) 1466 {
1618 { 1467 tv = GTK_TREE_VIEW (gtk_builder_get_object
1619 tv = GTK_TREE_VIEW (gtk_builder_get_object (sr->tab->builder, 1468 (sr->tab->builder, "_search_result_frame"));
1620 "_search_result_frame"));
1621 1469
1622 update_meta_data_views (tv, 1470 update_meta_data_views (tv, sr->tab);
1623 sr->tab); 1471 }
1624 }
1625 return sr; 1472 return sr;
1626} 1473}
1627 1474
@@ -1636,26 +1483,21 @@ free_search_result (struct SearchResult *sr)
1636 struct GNUNET_CONTAINER_MetaData *meta; 1483 struct GNUNET_CONTAINER_MetaData *meta;
1637 1484
1638 if (sr == NULL) 1485 if (sr == NULL)
1639 { 1486 {
1640 GNUNET_break (0); 1487 GNUNET_break (0);
1641 return; 1488 return;
1642 } 1489 }
1643 tp = gtk_tree_row_reference_get_path (sr->rr); 1490 tp = gtk_tree_row_reference_get_path (sr->rr);
1644 tm = gtk_tree_row_reference_get_model (sr->rr); 1491 tm = gtk_tree_row_reference_get_model (sr->rr);
1645 gtk_tree_model_get_iter (tm, &iter, tp); 1492 gtk_tree_model_get_iter (tm, &iter, tp);
1646 gtk_tree_path_free (tp); 1493 gtk_tree_path_free (tp);
1647 gtk_tree_model_get (tm, 1494 gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, -1);
1648 &iter,
1649 0, &meta,
1650 1, &uri,
1651 -1);
1652 if (uri != NULL) 1495 if (uri != NULL)
1653 GNUNET_FS_uri_destroy (uri); 1496 GNUNET_FS_uri_destroy (uri);
1654 if (meta != NULL) 1497 if (meta != NULL)
1655 GNUNET_CONTAINER_meta_data_destroy (meta); 1498 GNUNET_CONTAINER_meta_data_destroy (meta);
1656 gtk_tree_row_reference_free (sr->rr); 1499 gtk_tree_row_reference_free (sr->rr);
1657 gtk_tree_store_remove (GTK_TREE_STORE (tm), 1500 gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
1658 &iter);
1659 GNUNET_free (sr); 1501 GNUNET_free (sr);
1660} 1502}
1661 1503
@@ -1664,25 +1506,22 @@ free_search_result (struct SearchResult *sr)
1664 * Tell FS to stop publishing. 1506 * Tell FS to stop publishing.
1665 */ 1507 */
1666static void 1508static void
1667stop_publishing (GtkButton *button, 1509stop_publishing (GtkButton * button, gpointer user_data)
1668 gpointer user_data)
1669{ 1510{
1670 struct PublishTab *tab = user_data; 1511 struct PublishTab *tab = user_data;
1671 struct GNUNET_FS_PublishContext *pc; 1512 struct GNUNET_FS_PublishContext *pc;
1672 1513
1673 if (NULL != (pc = tab->pc)) 1514 if (NULL != (pc = tab->pc))
1674 { 1515 {
1675 tab->pc = NULL; 1516 tab->pc = NULL;
1676 GNUNET_FS_publish_stop (pc); 1517 GNUNET_FS_publish_stop (pc);
1677 } 1518 }
1678} 1519}
1679 1520
1680 1521
1681static struct PublishEntry * 1522static struct PublishEntry *
1682setup_publish (struct GNUNET_FS_PublishContext *pc, 1523setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1683 const char *fn, 1524 uint64_t fsize, struct PublishEntry *parent)
1684 uint64_t fsize,
1685 struct PublishEntry *parent)
1686{ 1525{
1687 struct PublishTab *tab; 1526 struct PublishTab *tab;
1688 struct PublishEntry *ent; 1527 struct PublishEntry *ent;
@@ -1699,79 +1538,74 @@ setup_publish (struct GNUNET_FS_PublishContext *pc,
1699 char *size_fancy; 1538 char *size_fancy;
1700 1539
1701 if (NULL == parent) 1540 if (NULL == parent)
1702 { 1541 {
1703 /* create new tab */ 1542 /* create new tab */
1704 tab = GNUNET_malloc (sizeof (struct PublishTab)); 1543 tab = GNUNET_malloc (sizeof (struct PublishTab));
1705 tab->pc = pc; 1544 tab->pc = pc;
1706 GNUNET_CONTAINER_DLL_insert (publish_tab_head, 1545 GNUNET_CONTAINER_DLL_insert (publish_tab_head, publish_tab_tail, tab);
1707 publish_tab_tail, 1546 tab->builder =
1708 tab); 1547 GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade");
1709 tab->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade"); 1548 df = GTK_WINDOW (gtk_builder_get_object
1710 df = GTK_WINDOW (gtk_builder_get_object (tab->builder, 1549 (tab->builder, "_publish_frame_window"));
1711 "_publish_frame_window")); 1550 tab->frame = gtk_bin_get_child (GTK_BIN (df));
1712 tab->frame = gtk_bin_get_child (GTK_BIN (df)); 1551 gtk_widget_ref (tab->frame);
1713 gtk_widget_ref (tab->frame); 1552 gtk_container_remove (GTK_CONTAINER (df), tab->frame);
1714 gtk_container_remove (GTK_CONTAINER (df), tab->frame); 1553 gtk_widget_destroy (GTK_WIDGET (df));
1715 gtk_widget_destroy (GTK_WIDGET (df)); 1554
1716 1555 /* load tab_label */
1717 /* load tab_label */ 1556 df = GTK_WINDOW (gtk_builder_get_object
1718 df = GTK_WINDOW (gtk_builder_get_object (tab->builder, 1557 (tab->builder, "_publish_label_window"));
1719 "_publish_label_window")); 1558 tab_label = gtk_bin_get_child (GTK_BIN (df));
1720 tab_label = gtk_bin_get_child (GTK_BIN (df)); 1559 gtk_widget_ref (tab_label);
1721 gtk_widget_ref (tab_label); 1560 gtk_container_remove (GTK_CONTAINER (df), tab_label);
1722 gtk_container_remove (GTK_CONTAINER (df), tab_label); 1561 gtk_widget_destroy (GTK_WIDGET (df));
1723 gtk_widget_destroy (GTK_WIDGET (df)); 1562
1724 1563 /* get refs to widgets */
1725 /* get refs to widgets */ 1564 fn_label =
1726 fn_label = GTK_LABEL (gtk_builder_get_object (tab->builder, 1565 GTK_LABEL (gtk_builder_get_object
1727 "_publish_label_window_label")); 1566 (tab->builder, "_publish_label_window_label"));
1728 gtk_label_set_text (fn_label, fn); 1567 gtk_label_set_text (fn_label, fn);
1729 close_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, 1568 close_button =
1730 "_publish_label_close_button")); 1569 GTK_WIDGET (gtk_builder_get_object
1731 g_signal_connect(G_OBJECT(close_button), "clicked", 1570 (tab->builder, "_publish_label_close_button"));
1732 G_CALLBACK(stop_publishing), tab); 1571 g_signal_connect (G_OBJECT (close_button), "clicked",
1733 /* make visible */ 1572 G_CALLBACK (stop_publishing), tab);
1734 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 1573 /* make visible */
1735 pages = gtk_notebook_get_n_pages (notebook); 1574 notebook =
1736 gtk_notebook_insert_page (notebook, 1575 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1737 tab->frame, 1576 ("GNUNET_GTK_main_window_notebook"));
1738 tab_label, 1577 pages = gtk_notebook_get_n_pages (notebook);
1739 pages - 1); 1578 gtk_notebook_insert_page (notebook, tab->frame, tab_label, pages - 1);
1740 gtk_widget_show (GTK_WIDGET (notebook)); 1579 gtk_widget_show (GTK_WIDGET (notebook));
1741 tab->ts = GTK_TREE_STORE (gtk_builder_get_object (tab->builder, 1580 tab->ts =
1742 "_publish_frame_tree_store")); 1581 GTK_TREE_STORE (gtk_builder_get_object
1743 pitrptr = NULL; 1582 (tab->builder, "_publish_frame_tree_store"));
1744 } 1583 pitrptr = NULL;
1584 }
1745 else 1585 else
1586 {
1587 /* create new iter from parent */
1588 tab = parent->tab;
1589 path = gtk_tree_row_reference_get_path (parent->rr);
1590 if (TRUE !=
1591 gtk_tree_model_get_iter (GTK_TREE_MODEL (tab->ts), &piter, path))
1746 { 1592 {
1747 /* create new iter from parent */ 1593 GNUNET_break (0);
1748 tab = parent->tab; 1594 return NULL;
1749 path = gtk_tree_row_reference_get_path (parent->rr);
1750 if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (tab->ts),
1751 &piter, path))
1752 {
1753 GNUNET_break (0);
1754 return NULL;
1755 }
1756 pitrptr = &piter;
1757 } 1595 }
1596 pitrptr = &piter;
1597 }
1758 size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize); 1598 size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
1759 gtk_tree_store_insert_with_values (tab->ts, 1599 gtk_tree_store_insert_with_values (tab->ts, &iter, pitrptr, G_MAXINT, 0, fn,
1760 &iter, 1600 1, size_fancy, 2, "white", 3,
1761 pitrptr, 1601 (guint) 0 /* progress */ ,
1762 G_MAXINT, 1602 -1);
1763 0, fn,
1764 1, size_fancy,
1765 2, "white",
1766 3, (guint) 0 /* progress */,
1767 -1);
1768 GNUNET_free (size_fancy); 1603 GNUNET_free (size_fancy);
1769 ent = GNUNET_malloc (sizeof (struct PublishEntry)); 1604 ent = GNUNET_malloc (sizeof (struct PublishEntry));
1770 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO; 1605 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
1771 ent->tab = tab; 1606 ent->tab = tab;
1772 path = gtk_tree_model_get_path (GTK_TREE_MODEL (tab->ts), &iter); 1607 path = gtk_tree_model_get_path (GTK_TREE_MODEL (tab->ts), &iter);
1773 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (tab->ts), 1608 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (tab->ts), path);
1774 path);
1775 gtk_tree_path_free (path); 1609 gtk_tree_path_free (path);
1776 ent->pc = pc; 1610 ent->pc = pc;
1777 return ent; 1611 return ent;
@@ -1793,194 +1627,203 @@ setup_publish (struct GNUNET_FS_PublishContext *pc,
1793 * will be passed to future callbacks in the respective 1627 * will be passed to future callbacks in the respective
1794 * field in the GNUNET_FS_ProgressInfo struct. 1628 * field in the GNUNET_FS_ProgressInfo struct.
1795 */ 1629 */
1796void* 1630void *
1797GNUNET_GTK_fs_event_handler (void *cls, 1631GNUNET_GTK_fs_event_handler (void *cls,
1798 const struct GNUNET_FS_ProgressInfo *info) 1632 const struct GNUNET_FS_ProgressInfo *info)
1799{ 1633{
1800 void *ret; 1634 void *ret;
1801 1635
1802 switch (info->status) 1636 switch (info->status)
1803 { 1637 {
1804 case GNUNET_FS_STATUS_PUBLISH_START: 1638 case GNUNET_FS_STATUS_PUBLISH_START:
1805 return setup_publish (info->value.publish.pc, 1639 return setup_publish (info->value.publish.pc, info->value.publish.filename,
1806 info->value.publish.filename, 1640 info->value.publish.size, info->value.publish.pctx);
1807 info->value.publish.size, 1641 case GNUNET_FS_STATUS_PUBLISH_RESUME:
1808 info->value.publish.pctx); 1642 ret =
1809 case GNUNET_FS_STATUS_PUBLISH_RESUME: 1643 setup_publish (info->value.publish.pc, info->value.publish.filename,
1810 ret = setup_publish (info->value.publish.pc, 1644 info->value.publish.size, info->value.publish.pctx);
1811 info->value.publish.filename, 1645 if (ret == NULL)
1812 info->value.publish.size,
1813 info->value.publish.pctx);
1814 if (ret == NULL)
1815 return ret;
1816 if (info->value.publish.specifics.resume.message != NULL)
1817 {
1818 ret = handle_publish_error (ret,
1819 info->value.publish.specifics.resume.message);
1820 }
1821 else if (info->value.publish.specifics.resume.chk_uri != NULL)
1822 {
1823 ret = handle_publish_completed (ret,
1824 info->value.publish.specifics.resume.chk_uri);
1825 }
1826 return ret;
1827 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
1828 close_publish_tab (info->value.publish.cctx);
1829 return NULL;
1830 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
1831 return mark_publish_progress (info->value.publish.cctx,
1832 info->value.publish.size,
1833 info->value.publish.completed);
1834 case GNUNET_FS_STATUS_PUBLISH_ERROR:
1835 return handle_publish_error (info->value.publish.cctx,
1836 info->value.publish.specifics.error.message);
1837 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
1838 return handle_publish_completed (info->value.publish.cctx,
1839 info->value.publish.specifics.completed.chk_uri);
1840 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
1841 close_publish_tab (info->value.publish.cctx);
1842 return NULL;
1843 case GNUNET_FS_STATUS_DOWNLOAD_START:
1844 return setup_download (info->value.download.cctx,
1845 info->value.download.pctx,
1846 info->value.download.sctx,
1847 info->value.download.dc,
1848 info->value.download.uri,
1849 info->value.download.specifics.start.meta,
1850 info->value.download.size,
1851 info->value.download.completed);
1852 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
1853 ret = setup_download (info->value.download.cctx,
1854 info->value.download.pctx,
1855 info->value.download.sctx,
1856 info->value.download.dc,
1857 info->value.download.uri,
1858 info->value.download.specifics.resume.meta,
1859 info->value.download.size,
1860 info->value.download.completed);
1861 if (info->value.download.specifics.resume.message != NULL)
1862 {
1863 ret = mark_download_error (ret,
1864 info->value.download.specifics.resume.message);
1865 }
1866 return ret; 1646 return ret;
1867 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: 1647 if (info->value.publish.specifics.resume.message != NULL)
1868 stop_download (info->value.download.cctx, GNUNET_YES); 1648 {
1869 return NULL; 1649 ret =
1870 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 1650 handle_publish_error (ret,
1871 return mark_download_progress (info->value.download.cctx, 1651 info->value.publish.specifics.resume.message);
1872 info->value.download.size,
1873 info->value.download.completed,
1874 info->value.download.specifics.progress.data,
1875 info->value.download.specifics.progress.offset,
1876 info->value.download.specifics.progress.data_len,
1877 info->value.download.specifics.progress.depth);
1878 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
1879 return mark_download_error (info->value.download.cctx,
1880 info->value.download.specifics.error.message);
1881 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
1882 return mark_download_completed (info->value.download.cctx,
1883 info->value.download.size,
1884 info->value.download.filename);
1885 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
1886 stop_download (info->value.download.cctx, GNUNET_NO);
1887 return NULL;
1888 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
1889 return change_download_colour (info->value.download.cctx,
1890 "yellow");
1891 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
1892 return change_download_colour (info->value.download.cctx,
1893 "blue");
1894 case GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT:
1895 return download_lost_parent (info->value.download.cctx,
1896 info->value.download.size,
1897 info->value.download.completed,
1898 info->value.download.is_active);
1899 case GNUNET_FS_STATUS_SEARCH_START:
1900 if (info->value.search.pctx != NULL)
1901 return setup_inner_search (info->value.search.sc,
1902 info->value.search.pctx);
1903 return setup_search (info->value.search.sc,
1904 info->value.search.query);
1905 case GNUNET_FS_STATUS_SEARCH_RESUME:
1906 ret = setup_search (info->value.search.sc,
1907 info->value.search.query);
1908 if (info->value.search.specifics.resume.message)
1909 ret = handle_search_error (ret,
1910 info->value.search.specifics.resume.message);
1911 return ret;
1912 case GNUNET_FS_STATUS_SEARCH_RESUME_RESULT:
1913 ret = process_search_result (info->value.search.cctx,
1914 info->value.search.pctx,
1915 info->value.search.specifics.resume_result.uri,
1916 info->value.search.specifics.resume_result.meta,
1917 info->value.search.specifics.resume_result.result,
1918 info->value.search.specifics.resume_result.applicability_rank);
1919 return update_search_result (ret,
1920 info->value.search.specifics.resume_result.meta,
1921 info->value.search.specifics.resume_result.applicability_rank,
1922 info->value.search.specifics.resume_result.availability_certainty,
1923 info->value.search.specifics.resume_result.availability_rank);
1924 case GNUNET_FS_STATUS_SEARCH_SUSPEND:
1925 close_search_tab (info->value.search.cctx);
1926 return NULL;
1927 case GNUNET_FS_STATUS_SEARCH_RESULT:
1928 return process_search_result (info->value.search.cctx,
1929 info->value.search.pctx,
1930 info->value.search.specifics.result.uri,
1931 info->value.search.specifics.result.meta,
1932 info->value.search.specifics.result.result,
1933 info->value.search.specifics.result.applicability_rank);
1934 case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE:
1935 GNUNET_break (0);
1936 break;
1937 case GNUNET_FS_STATUS_SEARCH_UPDATE:
1938 return update_search_result (info->value.search.specifics.update.cctx,
1939 info->value.search.specifics.update.meta,
1940 info->value.search.specifics.update.applicability_rank,
1941 info->value.search.specifics.update.availability_certainty,
1942 info->value.search.specifics.update.availability_rank);
1943 case GNUNET_FS_STATUS_SEARCH_ERROR:
1944 return handle_search_error (info->value.search.cctx,
1945 info->value.search.specifics.error.message);
1946 case GNUNET_FS_STATUS_SEARCH_PAUSED:
1947 return info->value.search.cctx;
1948 case GNUNET_FS_STATUS_SEARCH_CONTINUED:
1949 return info->value.search.cctx;
1950 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
1951 free_search_result (info->value.search.specifics.result_suspend.cctx);
1952 return NULL;
1953 case GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND:
1954 free_search_result (info->value.search.specifics.result_suspend.cctx);
1955 return NULL;
1956 case GNUNET_FS_STATUS_SEARCH_STOPPED:
1957 close_search_tab (info->value.search.cctx);
1958 return NULL;
1959 case GNUNET_FS_STATUS_UNINDEX_START:
1960 GNUNET_break (0);
1961 break;
1962 case GNUNET_FS_STATUS_UNINDEX_RESUME:
1963 GNUNET_break (0);
1964 break;
1965 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
1966 GNUNET_break (0);
1967 break;
1968 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
1969 GNUNET_break (0);
1970 break;
1971 case GNUNET_FS_STATUS_UNINDEX_ERROR:
1972 GNUNET_break (0);
1973 break;
1974 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
1975 GNUNET_break (0);
1976 break;
1977 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
1978 GNUNET_break (0);
1979 break;
1980 default:
1981 GNUNET_break (0);
1982 break;
1983 } 1652 }
1653 else if (info->value.publish.specifics.resume.chk_uri != NULL)
1654 {
1655 ret =
1656 handle_publish_completed (ret,
1657 info->value.publish.specifics.
1658 resume.chk_uri);
1659 }
1660 return ret;
1661 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
1662 close_publish_tab (info->value.publish.cctx);
1663 return NULL;
1664 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
1665 return mark_publish_progress (info->value.publish.cctx,
1666 info->value.publish.size,
1667 info->value.publish.completed);
1668 case GNUNET_FS_STATUS_PUBLISH_ERROR:
1669 return handle_publish_error (info->value.publish.cctx,
1670 info->value.publish.specifics.error.message);
1671 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
1672 return handle_publish_completed (info->value.publish.cctx,
1673 info->value.publish.specifics.
1674 completed.chk_uri);
1675 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
1676 close_publish_tab (info->value.publish.cctx);
1677 return NULL;
1678 case GNUNET_FS_STATUS_DOWNLOAD_START:
1679 return setup_download (info->value.download.cctx, info->value.download.pctx,
1680 info->value.download.sctx, info->value.download.dc,
1681 info->value.download.uri,
1682 info->value.download.specifics.start.meta,
1683 info->value.download.size,
1684 info->value.download.completed);
1685 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
1686 ret =
1687 setup_download (info->value.download.cctx, info->value.download.pctx,
1688 info->value.download.sctx, info->value.download.dc,
1689 info->value.download.uri,
1690 info->value.download.specifics.resume.meta,
1691 info->value.download.size,
1692 info->value.download.completed);
1693 if (info->value.download.specifics.resume.message != NULL)
1694 {
1695 ret =
1696 mark_download_error (ret,
1697 info->value.download.specifics.resume.message);
1698 }
1699 return ret;
1700 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
1701 stop_download (info->value.download.cctx, GNUNET_YES);
1702 return NULL;
1703 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
1704 return mark_download_progress (info->value.download.cctx,
1705 info->value.download.size,
1706 info->value.download.completed,
1707 info->value.download.specifics.progress.data,
1708 info->value.download.specifics.
1709 progress.offset,
1710 info->value.download.specifics.
1711 progress.data_len,
1712 info->value.download.specifics.
1713 progress.depth);
1714 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
1715 return mark_download_error (info->value.download.cctx,
1716 info->value.download.specifics.error.message);
1717 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
1718 return mark_download_completed (info->value.download.cctx,
1719 info->value.download.size,
1720 info->value.download.filename);
1721 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
1722 stop_download (info->value.download.cctx, GNUNET_NO);
1723 return NULL;
1724 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
1725 return change_download_colour (info->value.download.cctx, "yellow");
1726 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
1727 return change_download_colour (info->value.download.cctx, "blue");
1728 case GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT:
1729 return download_lost_parent (info->value.download.cctx,
1730 info->value.download.size,
1731 info->value.download.completed,
1732 info->value.download.is_active);
1733 case GNUNET_FS_STATUS_SEARCH_START:
1734 if (info->value.search.pctx != NULL)
1735 return setup_inner_search (info->value.search.sc,
1736 info->value.search.pctx);
1737 return setup_search (info->value.search.sc, info->value.search.query);
1738 case GNUNET_FS_STATUS_SEARCH_RESUME:
1739 ret = setup_search (info->value.search.sc, info->value.search.query);
1740 if (info->value.search.specifics.resume.message)
1741 ret =
1742 handle_search_error (ret,
1743 info->value.search.specifics.resume.message);
1744 return ret;
1745 case GNUNET_FS_STATUS_SEARCH_RESUME_RESULT:
1746 ret =
1747 process_search_result (info->value.search.cctx, info->value.search.pctx,
1748 info->value.search.specifics.resume_result.uri,
1749 info->value.search.specifics.resume_result.meta,
1750 info->value.search.specifics.
1751 resume_result.result,
1752 info->value.search.specifics.
1753 resume_result.applicability_rank);
1754 return update_search_result (ret,
1755 info->value.search.specifics.
1756 resume_result.meta,
1757 info->value.search.specifics.
1758 resume_result.applicability_rank,
1759 info->value.search.specifics.
1760 resume_result.availability_certainty,
1761 info->value.search.specifics.
1762 resume_result.availability_rank);
1763 case GNUNET_FS_STATUS_SEARCH_SUSPEND:
1764 close_search_tab (info->value.search.cctx);
1765 return NULL;
1766 case GNUNET_FS_STATUS_SEARCH_RESULT:
1767 return process_search_result (info->value.search.cctx,
1768 info->value.search.pctx,
1769 info->value.search.specifics.result.uri,
1770 info->value.search.specifics.result.meta,
1771 info->value.search.specifics.result.result,
1772 info->value.search.specifics.
1773 result.applicability_rank);
1774 case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE:
1775 GNUNET_break (0);
1776 break;
1777 case GNUNET_FS_STATUS_SEARCH_UPDATE:
1778 return update_search_result (info->value.search.specifics.update.cctx,
1779 info->value.search.specifics.update.meta,
1780 info->value.search.specifics.
1781 update.applicability_rank,
1782 info->value.search.specifics.
1783 update.availability_certainty,
1784 info->value.search.specifics.
1785 update.availability_rank);
1786 case GNUNET_FS_STATUS_SEARCH_ERROR:
1787 return handle_search_error (info->value.search.cctx,
1788 info->value.search.specifics.error.message);
1789 case GNUNET_FS_STATUS_SEARCH_PAUSED:
1790 return info->value.search.cctx;
1791 case GNUNET_FS_STATUS_SEARCH_CONTINUED:
1792 return info->value.search.cctx;
1793 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
1794 free_search_result (info->value.search.specifics.result_suspend.cctx);
1795 return NULL;
1796 case GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND:
1797 free_search_result (info->value.search.specifics.result_suspend.cctx);
1798 return NULL;
1799 case GNUNET_FS_STATUS_SEARCH_STOPPED:
1800 close_search_tab (info->value.search.cctx);
1801 return NULL;
1802 case GNUNET_FS_STATUS_UNINDEX_START:
1803 GNUNET_break (0);
1804 break;
1805 case GNUNET_FS_STATUS_UNINDEX_RESUME:
1806 GNUNET_break (0);
1807 break;
1808 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
1809 GNUNET_break (0);
1810 break;
1811 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
1812 GNUNET_break (0);
1813 break;
1814 case GNUNET_FS_STATUS_UNINDEX_ERROR:
1815 GNUNET_break (0);
1816 break;
1817 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
1818 GNUNET_break (0);
1819 break;
1820 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
1821 GNUNET_break (0);
1822 break;
1823 default:
1824 GNUNET_break (0);
1825 break;
1826 }
1984 return NULL; 1827 return NULL;
1985} 1828}
1986 1829
@@ -1990,8 +1833,8 @@ GNUNET_GTK_fs_event_handler (void *cls,
1990 * metadata views. 1833 * metadata views.
1991 */ 1834 */
1992void 1835void
1993GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy, 1836GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy,
1994 gpointer data) 1837 gpointer data)
1995{ 1838{
1996 GtkNotebook *notebook; 1839 GtkNotebook *notebook;
1997 gint page; 1840 gint page;
@@ -2001,24 +1844,29 @@ GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy,
2001 GtkListStore *ms; 1844 GtkListStore *ms;
2002 GtkTreeView *tv; 1845 GtkTreeView *tv;
2003 1846
2004 notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); 1847 notebook =
1848 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1849 ("GNUNET_GTK_main_window_notebook"));
2005 page = gtk_notebook_get_current_page (notebook); 1850 page = gtk_notebook_get_current_page (notebook);
2006 w = gtk_notebook_get_nth_page (notebook, page); 1851 w = gtk_notebook_get_nth_page (notebook, page);
2007 tab = search_tab_head; 1852 tab = search_tab_head;
2008 while (tab != NULL) 1853 while (tab != NULL)
1854 {
1855 if (tab->frame == w)
2009 { 1856 {
2010 if (tab->frame == w) 1857 tv = GTK_TREE_VIEW (gtk_builder_get_object
2011 { 1858 (tab->builder, "_search_result_frame"));
2012 tv = GTK_TREE_VIEW (gtk_builder_get_object (tab->builder, 1859 update_meta_data_views (tv, tab);
2013 "_search_result_frame")); 1860 return;
2014 update_meta_data_views (tv, tab);
2015 return;
2016 }
2017 tab = tab->next;
2018 } 1861 }
2019 image = GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_preview_image")); 1862 tab = tab->next;
1863 }
1864 image =
1865 GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
1866 ("GNUNET_GTK_main_window_preview_image"));
2020 gtk_image_clear (image); 1867 gtk_image_clear (image);
2021 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_meta_data_list_store")); 1868 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
1869 ("GNUNET_GTK_meta_data_list_store"));
2022 gtk_list_store_clear (ms); 1870 gtk_list_store_clear (ms);
2023} 1871}
2024 1872