diff options
Diffstat (limited to 'src/gns/gnunet-gns-gtk_zone.c')
-rw-r--r-- | src/gns/gnunet-gns-gtk_zone.c | 163 |
1 files changed, 155 insertions, 8 deletions
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c index 0c8af816..d0561530 100644 --- a/src/gns/gnunet-gns-gtk_zone.c +++ b/src/gns/gnunet-gns-gtk_zone.c | |||
@@ -99,10 +99,12 @@ GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo, | |||
99 | else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str))) | 99 | else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str))) |
100 | { | 100 | { |
101 | /* Adding a new record */ | 101 | /* Adding a new record */ |
102 | GNUNET_break (0); | ||
103 | gtk_tree_store_insert_with_values(gns->ts, &child , &it, 0, | 102 | gtk_tree_store_insert_with_values(gns->ts, &child , &it, 0, |
104 | TREE_COL_RECORD_TYPE, type, | 103 | TREE_COL_RECORD_TYPE, type, |
105 | TREE_COL_RECORD_TYPE_AS_STR, type_str, | 104 | TREE_COL_RECORD_TYPE_AS_STR, type_str, |
105 | TREE_COL_EXP_TIME_AS_STR, GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_get_forever()), | ||
106 | TREE_COL_EXP_TIME, GNUNET_TIME_absolute_get_forever(), | ||
107 | TREE_COL_EXP_TIME_IS_REL, FALSE, | ||
106 | TREE_COL_IS_RECORD_ROW, GNUNET_YES, | 108 | TREE_COL_IS_RECORD_ROW, GNUNET_YES, |
107 | TREE_COL_NOT_DUMMY_ROW, GNUNET_YES, | 109 | TREE_COL_NOT_DUMMY_ROW, GNUNET_YES, |
108 | -1); | 110 | -1); |
@@ -128,7 +130,6 @@ GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo, | |||
128 | else if (NULL == value_str) | 130 | else if (NULL == value_str) |
129 | { | 131 | { |
130 | /* Empty value field */ | 132 | /* Empty value field */ |
131 | GNUNET_break (0); | ||
132 | if (GNUNET_YES == record_row) | 133 | if (GNUNET_YES == record_row) |
133 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1); | 134 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1); |
134 | else | 135 | else |
@@ -343,12 +344,106 @@ struct ZoneIteration_Context | |||
343 | struct GNUNET_NAMESTORE_ZoneIterator * it; | 344 | struct GNUNET_NAMESTORE_ZoneIterator * it; |
344 | }; | 345 | }; |
345 | 346 | ||
347 | struct Remove_Context | ||
348 | { | ||
349 | struct GNUNET_GNS_Context *gns; | ||
350 | char *path; | ||
351 | char *parent; | ||
352 | GtkTreeModel *tm; | ||
353 | }; | ||
354 | |||
355 | void | ||
356 | remove_proc (void *cls, | ||
357 | int32_t success, | ||
358 | const char *emsg) | ||
359 | { | ||
360 | struct Remove_Context *rcc = cls; | ||
361 | GtkWidget *dialog; | ||
362 | GtkTreeIter iter; | ||
363 | if (GNUNET_SYSERR == success) | ||
364 | { | ||
365 | char * message = _("Record could not be deleted: "); | ||
366 | dialog = gtk_message_dialog_new (GTK_WINDOW (rcc->gns->main_window), | ||
367 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
368 | GTK_MESSAGE_ERROR, | ||
369 | GTK_BUTTONS_CLOSE, | ||
370 | _("%s %s\n"), | ||
371 | message, | ||
372 | emsg); | ||
373 | |||
374 | g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), rcc->gns); | ||
375 | gtk_widget_show_all (dialog); | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | gtk_tree_model_get_iter_from_string(rcc->tm, &iter, rcc->path); | ||
380 | gtk_tree_store_remove (rcc->gns->ts, &iter); | ||
381 | } | ||
382 | GNUNET_free(rcc); | ||
383 | } | ||
384 | |||
385 | struct GNUNET_NAMESTORE_RecordData * | ||
386 | build_rd_from_datastore (GtkTreeModel *tm, GtkTreeIter *it) | ||
387 | { | ||
388 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
389 | gboolean exp_is_relative; | ||
390 | gboolean public; | ||
391 | guint64 exp; | ||
392 | guint type; | ||
393 | char * value; | ||
394 | size_t value_len; | ||
395 | |||
396 | gtk_tree_model_get(tm, it, TREE_COL_EXP_TIME_IS_REL, &exp_is_relative, | ||
397 | TREE_COL_EXP_TIME, &exp, | ||
398 | TREE_COL_RECORD_TYPE, &type, | ||
399 | TREE_COL_IS_PUBLIC, &public, | ||
400 | TREE_COL_VAL_AS_STR, &value, | ||
401 | -1); | ||
402 | |||
403 | if (value != NULL) | ||
404 | value_len = strlen(value) + 1; | ||
405 | else | ||
406 | value_len = 0; | ||
407 | |||
408 | rd = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_RecordData) + value_len); | ||
409 | |||
410 | if (exp_is_relative) | ||
411 | { | ||
412 | struct GNUNET_TIME_Relative rel_t; | ||
413 | rel_t.rel_value = exp; | ||
414 | rd->expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_t); | ||
415 | } | ||
416 | else | ||
417 | { | ||
418 | rd->expiration.abs_value = exp; | ||
419 | } | ||
420 | if (TRUE == public) | ||
421 | rd->flags = GNUNET_NAMESTORE_RF_NONE; | ||
422 | else | ||
423 | rd->flags = GNUNET_NAMESTORE_RF_PRIVATE; | ||
424 | rd->record_type = type; | ||
425 | rd->data_size = value_len; | ||
426 | rd->data = (char *) &rd[1]; | ||
427 | memcpy ((void *) rd->data, value, value_len); | ||
428 | return rd; | ||
429 | } | ||
430 | |||
346 | void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | 431 | void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, |
347 | gpointer user_data) | 432 | gpointer user_data) |
348 | { | 433 | { |
349 | struct GNUNET_GNS_Context *gns = user_data; | 434 | struct GNUNET_GNS_Context *gns = user_data; |
350 | GtkTreeIter it; | 435 | GtkTreeIter it; |
436 | GtkTreeIter parent; | ||
437 | GtkTreeIter child; | ||
351 | int not_dummy; | 438 | int not_dummy; |
439 | int children; | ||
440 | int c; | ||
441 | gboolean has_parent; | ||
442 | |||
443 | char *name = ""; | ||
444 | char *path; | ||
445 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
446 | struct Remove_Context *rcc; | ||
352 | 447 | ||
353 | GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview")); | 448 | GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview")); |
354 | GtkTreeModel *tm; | 449 | GtkTreeModel *tm; |
@@ -356,8 +451,50 @@ void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | |||
356 | 451 | ||
357 | gtk_tree_selection_get_selected (ts, &tm, &it); | 452 | gtk_tree_selection_get_selected (ts, &tm, &it); |
358 | gtk_tree_model_get(tm, &it, TREE_COL_NOT_DUMMY_ROW, ¬_dummy, -1); | 453 | gtk_tree_model_get(tm, &it, TREE_COL_NOT_DUMMY_ROW, ¬_dummy, -1); |
359 | if (GNUNET_YES == not_dummy) | 454 | if (GNUNET_NO == not_dummy) |
455 | return; | ||
456 | |||
457 | /* Has parent? */ | ||
458 | has_parent = gtk_tree_model_iter_parent (tm, &parent, &it); | ||
459 | if (TRUE == has_parent) | ||
460 | { | ||
461 | /* this is a single record */ | ||
462 | gtk_tree_model_get(tm, &parent, TREE_COL_NAME, &name, -1); | ||
463 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting single record for name `%s'\n", name); | ||
464 | rd = build_rd_from_datastore (tm, &it); | ||
465 | rcc= GNUNET_malloc (sizeof (struct Remove_Context)); | ||
466 | rcc->gns = gns; | ||
467 | rcc->tm = tm; | ||
468 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &it); | ||
469 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); | ||
470 | GNUNET_free (rd); | ||
471 | |||
472 | } | ||
473 | else | ||
474 | { | ||
475 | /* this is a whole name */ | ||
476 | gtk_tree_model_get(tm, &it, TREE_COL_NAME, &name, -1); | ||
477 | children = gtk_tree_model_iter_n_children (tm, &it); | ||
478 | //path = gtk_tree_model_get_string_from_iter(tm, &it); | ||
479 | path = gtk_tree_model_get_string_from_iter (tm, &it); | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting name `%s' with %u children\n", name, children); | ||
481 | gtk_tree_model_iter_children (tm, &child, &it); | ||
482 | for (c = 0; c < children; c++) | ||
483 | { | ||
484 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting %u record for name `%s'\n", c, name); | ||
485 | |||
486 | rd = build_rd_from_datastore (tm, &child); | ||
487 | rcc= GNUNET_malloc (sizeof (struct Remove_Context)); | ||
488 | rcc->gns = gns; | ||
489 | rcc->tm = tm; | ||
490 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &child); | ||
491 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALLING\n"); | ||
492 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); | ||
493 | gtk_tree_model_iter_next (tm, &child); | ||
494 | } | ||
495 | gtk_tree_model_get_iter_from_string(tm, &it, path); | ||
360 | gtk_tree_store_remove (gns->ts, &it); | 496 | gtk_tree_store_remove (gns->ts, &it); |
497 | } | ||
361 | } | 498 | } |
362 | 499 | ||
363 | void zone_iteration_proc (void *cls, | 500 | void zone_iteration_proc (void *cls, |
@@ -378,6 +515,7 @@ void zone_iteration_proc (void *cls, | |||
378 | char *exp; | 515 | char *exp; |
379 | char *val; | 516 | char *val; |
380 | int public; | 517 | int public; |
518 | guint64 exp_t; | ||
381 | 519 | ||
382 | GNUNET_assert (zc_ctx != NULL); | 520 | GNUNET_assert (zc_ctx != NULL); |
383 | if ((NULL == zone_key) && (NULL == name)) | 521 | if ((NULL == zone_key) && (NULL == name)) |
@@ -416,6 +554,7 @@ void zone_iteration_proc (void *cls, | |||
416 | return; | 554 | return; |
417 | } | 555 | } |
418 | gtk_entry_set_text (pseu_entry, (char *)rd[0].data); | 556 | gtk_entry_set_text (pseu_entry, (char *)rd[0].data); |
557 | GNUNET_NAMESTORE_zone_iterator_next(zc_ctx->it); | ||
419 | return; | 558 | return; |
420 | } | 559 | } |
421 | 560 | ||
@@ -437,10 +576,10 @@ void zone_iteration_proc (void *cls, | |||
437 | c, rd[c].record_type, rd[c].flags, rd[c].expiration, rd[c].data_size); | 576 | c, rd[c].record_type, rd[c].flags, rd[c].expiration, rd[c].data_size); |
438 | 577 | ||
439 | /* Set public toggle */ | 578 | /* Set public toggle */ |
440 | if (rd[c].flags != GNUNET_NAMESTORE_RF_PRIVATE) | 579 | if (rd[c].flags == GNUNET_NAMESTORE_RF_PRIVATE) |
441 | public = GNUNET_YES; | ||
442 | else | ||
443 | public = GNUNET_NO; | 580 | public = GNUNET_NO; |
581 | else | ||
582 | public = GNUNET_YES; | ||
444 | 583 | ||
445 | /* Expiration time */ | 584 | /* Expiration time */ |
446 | time_is_relative = GNUNET_NO; | 585 | time_is_relative = GNUNET_NO; |
@@ -449,10 +588,17 @@ void zone_iteration_proc (void *cls, | |||
449 | { | 588 | { |
450 | /* FIX THIS WHEN WE HAVE RELATIVE TIME */ | 589 | /* FIX THIS WHEN WE HAVE RELATIVE TIME */ |
451 | struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_relative_get_zero(); | 590 | struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_relative_get_zero(); |
452 | exp = GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time)); | 591 | struct GNUNET_TIME_Absolute exp_abs; |
592 | exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time); | ||
593 | exp_t = exp_abs.abs_value; | ||
594 | exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs); | ||
453 | } | 595 | } |
454 | else | 596 | else |
455 | exp = GNUNET_STRINGS_absolute_time_to_string (rd[c].expiration); | 597 | { |
598 | struct GNUNET_TIME_Absolute exp_abs = rd[c].expiration; | ||
599 | exp_t = exp_abs.abs_value; | ||
600 | exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs); | ||
601 | } | ||
456 | /* value */ | 602 | /* value */ |
457 | val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type, | 603 | val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type, |
458 | rd[c].data, | 604 | rd[c].data, |
@@ -462,6 +608,7 @@ void zone_iteration_proc (void *cls, | |||
462 | TREE_COL_RECORD_TYPE, rd[c].record_type, | 608 | TREE_COL_RECORD_TYPE, rd[c].record_type, |
463 | TREE_COL_RECORD_TYPE_AS_STR, GNUNET_NAMESTORE_number_to_typename(rd[c].record_type), | 609 | TREE_COL_RECORD_TYPE_AS_STR, GNUNET_NAMESTORE_number_to_typename(rd[c].record_type), |
464 | TREE_COL_IS_PUBLIC, public, | 610 | TREE_COL_IS_PUBLIC, public, |
611 | TREE_COL_EXP_TIME, exp_t, | ||
465 | TREE_COL_EXP_TIME_AS_STR, exp, | 612 | TREE_COL_EXP_TIME_AS_STR, exp, |
466 | TREE_COL_EXP_TIME_IS_REL, time_is_relative, | 613 | TREE_COL_EXP_TIME_IS_REL, time_is_relative, |
467 | TREE_COL_VAL_AS_STR, val, | 614 | TREE_COL_VAL_AS_STR, val, |