diff options
Diffstat (limited to 'src/peerinfo/gnunet-peerinfo-gtk.c')
-rw-r--r-- | src/peerinfo/gnunet-peerinfo-gtk.c | 102 |
1 files changed, 99 insertions, 3 deletions
diff --git a/src/peerinfo/gnunet-peerinfo-gtk.c b/src/peerinfo/gnunet-peerinfo-gtk.c index 12d66124..3971bee9 100644 --- a/src/peerinfo/gnunet-peerinfo-gtk.c +++ b/src/peerinfo/gnunet-peerinfo-gtk.c | |||
@@ -88,7 +88,12 @@ enum PEERINFO_ModelColumns | |||
88 | /** | 88 | /** |
89 | * A gboolean | 89 | * A gboolean |
90 | */ | 90 | */ |
91 | PEERINFO_MC_IS_FRIEND = 9 | 91 | PEERINFO_MC_IS_FRIEND = 9, |
92 | |||
93 | /** | ||
94 | * A `struct PeerInfo *` | ||
95 | */ | ||
96 | PEERINFO_MC_PEERINFO = 10 | ||
92 | }; | 97 | }; |
93 | 98 | ||
94 | 99 | ||
@@ -113,6 +118,11 @@ struct PeerInfo | |||
113 | struct GNUNET_TRANSPORT_AddressToStringContext *tos; | 118 | struct GNUNET_TRANSPORT_AddressToStringContext *tos; |
114 | 119 | ||
115 | /** | 120 | /** |
121 | * Identity of the peer for this entry. | ||
122 | */ | ||
123 | struct GNUNET_PeerIdentity pid; | ||
124 | |||
125 | /** | ||
116 | * Did we get any address? | 126 | * Did we get any address? |
117 | */ | 127 | */ |
118 | int got_address; | 128 | int got_address; |
@@ -379,6 +389,8 @@ peerinfo_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
379 | info = GNUNET_CONTAINER_multipeermap_get (peer2info, peer); | 389 | info = GNUNET_CONTAINER_multipeermap_get (peer2info, peer); |
380 | if (NULL == info) | 390 | if (NULL == info) |
381 | { | 391 | { |
392 | info = GNUNET_new (struct PeerInfo); | ||
393 | info->pid = *peer; | ||
382 | gtk_list_store_append (ls, &iter); | 394 | gtk_list_store_append (ls, &iter); |
383 | gtk_list_store_set (ls, &iter, | 395 | gtk_list_store_set (ls, &iter, |
384 | PEERINFO_MC_PEER_IDENTITY_STRING, GNUNET_i2s (peer), | 396 | PEERINFO_MC_PEER_IDENTITY_STRING, GNUNET_i2s (peer), |
@@ -392,9 +404,9 @@ peerinfo_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
392 | PEERINFO_MC_CONNECTED_STATUS, FALSE, | 404 | PEERINFO_MC_CONNECTED_STATUS, FALSE, |
393 | PEERINFO_MC_IS_FRIEND, GNUNET_CONTAINER_multipeermap_contains (friends, | 405 | PEERINFO_MC_IS_FRIEND, GNUNET_CONTAINER_multipeermap_contains (friends, |
394 | peer), | 406 | peer), |
407 | PEERINFO_MC_PEERINFO, info, | ||
395 | -1); | 408 | -1); |
396 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ls), &iter); | 409 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ls), &iter); |
397 | info = GNUNET_malloc (sizeof (struct PeerInfo)); | ||
398 | info->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls), path); | 410 | info->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls), path); |
399 | GNUNET_assert (NULL != info->rr); | 411 | GNUNET_assert (NULL != info->rr); |
400 | gtk_tree_path_free (path); | 412 | gtk_tree_path_free (path); |
@@ -454,6 +466,51 @@ status_cb (void *cls, | |||
454 | 466 | ||
455 | 467 | ||
456 | /** | 468 | /** |
469 | * Write a friend to the friends file. | ||
470 | * | ||
471 | * @param cls the `struct GNUNET_FRIENDS_Writer` | ||
472 | * @param friend friend to write to file | ||
473 | * @param value unused | ||
474 | * @return #GNUNET_OK if the writing succeeded | ||
475 | */ | ||
476 | static int | ||
477 | write_friend (void *cls, | ||
478 | const struct GNUNET_PeerIdentity *friend, | ||
479 | void *value) | ||
480 | { | ||
481 | struct GNUNET_FRIENDS_Writer *w = cls; | ||
482 | |||
483 | return GNUNET_FRIENDS_write (w, friend); | ||
484 | } | ||
485 | |||
486 | |||
487 | /** | ||
488 | * Write an updated friends file out to disk. | ||
489 | */ | ||
490 | static void | ||
491 | write_friends () | ||
492 | { | ||
493 | struct GNUNET_FRIENDS_Writer *w; | ||
494 | |||
495 | w = GNUNET_FRIENDS_write_start (get_configuration ()); | ||
496 | if (NULL == w) | ||
497 | { | ||
498 | GNUNET_break (0); | ||
499 | return; | ||
500 | } | ||
501 | GNUNET_CONTAINER_multipeermap_iterate (friends, | ||
502 | &write_friend, | ||
503 | w); | ||
504 | if (GNUNET_OK != | ||
505 | GNUNET_FRIENDS_write_stop (w)) | ||
506 | { | ||
507 | GNUNET_break (0); | ||
508 | return; | ||
509 | } | ||
510 | } | ||
511 | |||
512 | |||
513 | /** | ||
457 | * The user has toggled the 'is friend' column for one of the peers. | 514 | * The user has toggled the 'is friend' column for one of the peers. |
458 | * Update everything. | 515 | * Update everything. |
459 | * | 516 | * |
@@ -466,7 +523,46 @@ GNUNET_PEERINFO_GTK_main_window_friends_cellrenderertoggle_toggled_cb (GtkCellRe | |||
466 | gchar *path, | 523 | gchar *path, |
467 | gpointer user_data) | 524 | gpointer user_data) |
468 | { | 525 | { |
469 | GNUNET_break (0); // not implemented | 526 | GtkListStore *ls; |
527 | GtkTreeIter old; | ||
528 | struct PeerInfo *info; | ||
529 | gboolean oldvalue; | ||
530 | |||
531 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
532 | if (NULL == ls) | ||
533 | { | ||
534 | GNUNET_break (0); | ||
535 | return; | ||
536 | } | ||
537 | if (TRUE != | ||
538 | gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ls), &old, path)) | ||
539 | { | ||
540 | GNUNET_break (0); | ||
541 | return; | ||
542 | } | ||
543 | gtk_tree_model_get (GTK_TREE_MODEL (ls), &old, | ||
544 | PEERINFO_MC_PEERINFO, &info, | ||
545 | PEERINFO_MC_IS_FRIEND, &oldvalue, | ||
546 | -1); | ||
547 | gtk_list_store_set (ls, &old, | ||
548 | PEERINFO_MC_IS_FRIEND, ! oldvalue, | ||
549 | -1); | ||
550 | if (oldvalue) | ||
551 | { | ||
552 | GNUNET_break (1 == | ||
553 | GNUNET_CONTAINER_multipeermap_remove_all (friends, | ||
554 | &info->pid)); | ||
555 | } | ||
556 | else | ||
557 | { | ||
558 | GNUNET_break (GNUNET_YES == | ||
559 | GNUNET_CONTAINER_multipeermap_put (friends, | ||
560 | &info->pid, | ||
561 | "true", | ||
562 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
563 | |||
564 | } | ||
565 | write_friends (); | ||
470 | } | 566 | } |
471 | 567 | ||
472 | 568 | ||