diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk_common.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk_common.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk_common.c b/src/fs/gnunet-fs-gtk_common.c index 8ca006e3..82d93e8f 100644 --- a/src/fs/gnunet-fs-gtk_common.c +++ b/src/fs/gnunet-fs-gtk_common.c | |||
@@ -416,5 +416,117 @@ GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri) | |||
416 | GNUNET_break (0); | 416 | GNUNET_break (0); |
417 | } | 417 | } |
418 | 418 | ||
419 | /* Largest rating value among all namespaces. INT_MIN means "undefined" */ | ||
420 | static int largest_namespace_rating = INT_MIN; | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Helper function for finding the largest namespace rating. | ||
425 | * | ||
426 | * @param cls closure | ||
427 | * @param pseudonym pseudonym hash | ||
428 | * @param md metadata container | ||
429 | * @param rating rating | ||
430 | * @return GNUNET_OK to keep iterating | ||
431 | */ | ||
432 | static int | ||
433 | find_largest_namespace_rating_iterator (void *cls, | ||
434 | const GNUNET_HashCode *pseudonym, const char *name, | ||
435 | const char *unique_name, | ||
436 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | ||
437 | { | ||
438 | int *largest = cls; | ||
439 | if (*largest < rating) | ||
440 | *largest = rating; | ||
441 | return GNUNET_OK; | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * Finds largest namespace rating. | ||
446 | * Used to calculate a rating for newly discovered namespaces. | ||
447 | * Returns from cache, if possible. | ||
448 | * | ||
449 | * @return largest namespace rating. Might be negative and even. INT_MIN means | ||
450 | * that no namespaces are known. | ||
451 | */ | ||
452 | int | ||
453 | GNUNET_GTK_find_largest_namespace_rating () | ||
454 | { | ||
455 | if (largest_namespace_rating != INT_MIN) | ||
456 | return largest_namespace_rating; | ||
457 | (void) GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (), | ||
458 | find_largest_namespace_rating_iterator, &largest_namespace_rating); | ||
459 | return largest_namespace_rating; | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * Sets largest namespace rating. | ||
464 | * Used to change cached largest namespace rating, when namespace list | ||
465 | * was changed in a way that is easy to track. | ||
466 | * If namespace list was changed in a way that makes it difficult to | ||
467 | * decide upon the new value, set new value to INT_MIN. | ||
468 | * | ||
469 | * @param new_value new value for the rating. | ||
470 | */ | ||
471 | void | ||
472 | GNUNET_GTK_set_largest_namespace_rating (int new_value) | ||
473 | { | ||
474 | largest_namespace_rating = new_value; | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * Converts a GtkTreeRowReference to a GtkTreeIter. | ||
479 | * | ||
480 | * @param rr row reference | ||
481 | * @param iter pointer to an iter structure to fill | ||
482 | * @return GNUNET_OK if iter was filled, GNUNET_SYSERR otherwise | ||
483 | */ | ||
484 | int | ||
485 | GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr, GtkTreeIter *iter) | ||
486 | { | ||
487 | int result = GNUNET_SYSERR; | ||
488 | if (rr != NULL) | ||
489 | { | ||
490 | if (gtk_tree_row_reference_valid (rr)) | ||
491 | { | ||
492 | GtkTreePath *path; | ||
493 | GtkTreeModel *model; | ||
494 | path = gtk_tree_row_reference_get_path (rr); | ||
495 | model = gtk_tree_row_reference_get_model (rr); | ||
496 | if (path != NULL && model != NULL) | ||
497 | { | ||
498 | if (gtk_tree_model_get_iter (model, | ||
499 | iter, path)) | ||
500 | result = GNUNET_OK; | ||
501 | gtk_tree_path_free (path); | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | return result; | ||
506 | } | ||
507 | |||
508 | /** | ||
509 | * Creates a GtkTreeRowReference from a GtkTreeIter. | ||
510 | * | ||
511 | * @param model a model to reference | ||
512 | * @param iter an iter that points to a row in the model | ||
513 | * @return newly created reference or NULL in case of error | ||
514 | */ | ||
515 | GtkTreeRowReference * | ||
516 | GNUNET_GTK_get_reference_from_iter (GtkTreeModel *model, GtkTreeIter *iter) | ||
517 | { | ||
518 | GtkTreeRowReference *result = NULL; | ||
519 | if (iter != NULL && model != NULL) | ||
520 | { | ||
521 | GtkTreePath *path = gtk_tree_model_get_path (model, iter); | ||
522 | if (path != NULL) | ||
523 | { | ||
524 | result = gtk_tree_row_reference_new (model, path); | ||
525 | gtk_tree_path_free (path); | ||
526 | } | ||
527 | } | ||
528 | return result; | ||
529 | } | ||
530 | |||
419 | 531 | ||
420 | /* end of gnunet-fs-gtk-common.c */ | 532 | /* end of gnunet-fs-gtk-common.c */ |