aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-gns-gtk_zone.c
blob: 4f5989e4d1395a35de7a4e2c17ce4ede51f22bcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/*
     This file is part of GNUnet
     (C) 2012 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 2, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file src/gns/gnunet-gns-gtk_zone.c
 * @author Christian Grothoff
 * @brief everything releated to the zone tree view
 */
#include "gnunet_gtk.h"
#include "gnunet-gns-gtk.h"

#define NEW_NAME_STR "<new name>"
#define NEW_RECORD_STR "<new record>"

enum
{
  TREE_COL_NAME = 0,
  TREE_COL_IS_PUBLIC,
  TREE_COL_RECORD_TYPE,
  TREE_COL_RECORD_TYPE_AS_STR,
  TREE_COL_EXP_TIME,
  TREE_COL_EXP_TIME_IS_REL,
  TREE_COL_EXP_TIME_AS_STR,
  TREE_COL_VAL_AS_STR,
  TREE_COL_VAL_COLOR,
  TREE_COL_NAME_IS_EDITABLE,
  TREE_COL_IS_RECORD_ROW,
  TREE_COL_NOT_DUMMY_ROW
};

enum
{
  TYPE_LIST_TYPE = 0,
  TYPE_LIST_TYPENAME
};

/**
 * The user has selected a new record type.  Update the
 * model, possibly invalidating (marking 'red') the existing
 * value.
 *
 * @param renderer updated renderer
 * @param path the path identifying the edited cell
 * @param new_iter selected cell in the combo's model (with the record type)
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo,
						  gchar *path,
						  GtkTreeIter *new_iter,
						  gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeIter it;
  GtkTreeIter child;
  GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
  guint type;
  int record_row;
  char *type_str;
  char *value_str;
  char *name_str;
  void *data;
  size_t data_size;

  gtk_tree_model_get(GTK_TREE_MODEL(gns->ls), new_iter, 0, &type, -1);
  gtk_tree_model_get(GTK_TREE_MODEL(gns->ls), new_iter, TYPE_LIST_TYPENAME, &type_str, -1);


  /* check if this is a new record */
  gtk_tree_model_get_iter_from_string(tm, &it, path);
  gtk_tree_model_get(tm, &it, TREE_COL_IS_RECORD_ROW, &record_row, -1);
  gtk_tree_model_get(tm, &it, TREE_COL_NAME, &name_str, -1);

  if (GNUNET_YES == record_row)
  {
    /* Updating an existing record */
    gtk_tree_store_set(gns->ts, &it,
                       TREE_COL_RECORD_TYPE, type,
                       TREE_COL_RECORD_TYPE_AS_STR, type_str,
                       -1);
  }
  else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str)))
  {
    /* Adding a new record */
    gtk_tree_store_insert_with_values(gns->ts, &child , &it, 0,
        TREE_COL_RECORD_TYPE, type,
        TREE_COL_RECORD_TYPE_AS_STR, type_str,
        TREE_COL_EXP_TIME_AS_STR, GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_get_forever()),
        TREE_COL_EXP_TIME, GNUNET_TIME_absolute_get_forever(),
        TREE_COL_EXP_TIME_IS_REL, FALSE,
        TREE_COL_IS_RECORD_ROW, GNUNET_YES,
        TREE_COL_NOT_DUMMY_ROW, GNUNET_YES,
        -1);

  }
  GNUNET_free (type_str);
  GNUNET_free_non_null (name_str);


  /* check if value is still valid */
  gtk_tree_model_get(tm, &it, TREE_COL_VAL_AS_STR, &value_str, -1);
  if (NULL != value_str)
  {
    if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value (type,
                                      value_str,
                                      &data,
                                      &data_size))
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1);
    else
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, NULL, -1);
    GNUNET_free (value_str);
  }
  else if (NULL == value_str)
  {
    /* Empty value field */
    if (GNUNET_YES == record_row)
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1);
    else
      gtk_tree_store_set (gns->ts, &child, TREE_COL_VAL_COLOR, "red", -1);
  }

}


/**
 * The user has toggled the 'public' checkmark of a cell.  Update the
 * model.
 *
 * @param renderer updated renderer
 * @param path the path identifying the edited cell
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_ispublic_cellrenderertoggle_toggled_cb (GtkCellRendererToggle *cell_renderer,
						       gchar *path,
						       gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeIter it;
  GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
  int value;

  gtk_tree_model_get_iter_from_string(tm, &it, path);
  gtk_tree_model_get(tm, &it, TREE_COL_IS_PUBLIC, &value, -1);
  gtk_tree_store_set(gns->ts, &it, TREE_COL_IS_PUBLIC, !value, -1);

  GNUNET_break (0); // FIXME, not implemented
}


/**
 * The user has edited a 'expiration' cell.  Update the model.
 *
 * @param renderer updated renderer
 * @param path the path identifying the edited cell
 * @param new_text the new expiration time
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
						      gchar *path,
						      gchar *new_text,
						      gpointer user_data)
{
  GNUNET_break (0); // FIXME, not implemented
}


/**
 * The user has edited a 'value' cell.  Update the model,
 * including the status on the consistency of the value with
 * the type.
 *
 * @param renderer updated renderer
 * @param path the path identifying the edited cell
 * @param new_text the new value
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_value_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
						 gchar *path,
						 gchar *new_text,
						 gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
  GtkTreeIter it;
  size_t data_size;
  void * data;
  int type;

  if (0 != strcmp(new_text,""))
  {
    gtk_tree_model_get_iter_from_string(tm, &it, path);
    gtk_tree_model_get(tm, &it, TREE_COL_RECORD_TYPE, &type, -1);
    if (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (type,
                                      new_text,
                                      &data,
                                      &data_size))
    {
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, NULL, -1);
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_AS_STR, new_text, -1);
    }
    else
    {
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1);
      gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_AS_STR, new_text, -1);
    }
  }
}


/**
 * The user has edited a 'name' cell.  Update the model (and if needed
 * create another fresh line for additional records).
 *
 * @param renderer updated renderer
 * @param path the path identifying the edited cell
 * @param new_text the new name
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
						gchar *path,
						gchar *new_text,
						gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeIter it;
  GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
  int not_dummy;

  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "New text for `%s' is `%s'\n", path, new_text);
  if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, "")))
    return;
  gtk_tree_model_get_iter_from_string(tm, &it, path);
  gtk_tree_model_get(tm, &it, TREE_COL_NOT_DUMMY_ROW, &not_dummy, -1);

  if (not_dummy == GNUNET_NO)
  {
    /* update name */
    gtk_tree_store_set (gns->ts, &it, TREE_COL_NAME, new_text, -1);
    gtk_tree_store_set (gns->ts, &it, TREE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR), -1);
    gtk_tree_store_set (gns->ts, &it, TREE_COL_NOT_DUMMY_ROW, GNUNET_YES, -1);

    /* add a new dummy line */
    gtk_tree_store_insert_with_values (gns->ts, &it,NULL, 0,
        TREE_COL_NAME, _(NEW_NAME_STR),
        TREE_COL_RECORD_TYPE, 1,
        TREE_COL_NAME_IS_EDITABLE, 1,
        TREE_COL_NOT_DUMMY_ROW, GNUNET_NO,
        TREE_COL_IS_RECORD_ROW, GNUNET_NO,
        -1);
  }
  else
  {
    /* update name */
    gtk_tree_store_set (gns->ts, &it, TREE_COL_NAME, new_text, -1);
  }
}

/**
 * The zone treeview pop up menu is supposed to be created.
 * (Note: this is not the only method that might need to be
 * written to handle events to create pop up menus; right-clicks
 * might need to be managed separately).
 *
 * @param widget the widget
 * @param user_data unused
 * @return TRUE if a menu was activated
 */
gboolean
GNUNET_GNS_GTK_main_treeview_popup_menu_cb (GtkWidget *widget,
					    gpointer user_data)
{  
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeView *tv;
  GtkTreeModel *tm;
  GtkTreeIter it;
  GtkMenu *popup;
  GtkTreeSelection * ts;
  int not_dummy;



  tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview"));
  ts = gtk_tree_view_get_selection(tv);
  if (FALSE == gtk_tree_selection_get_selected (ts, &tm, &it))
    return TRUE;
  gtk_tree_model_get(GTK_TREE_MODEL(gns->ts), &it, TREE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
  if (GNUNET_NO == not_dummy)
    return TRUE;

  popup  = GTK_MENU(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_delete_popup_menu"));
  gtk_widget_show_all (GTK_WIDGET(popup));
  gtk_menu_popup(popup, NULL, NULL, NULL, NULL, 0, 0);
  return TRUE;
}

gboolean
GNUNET_GNS_GTK_main_treeview_button_press_popup_menu_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
  /* Check for right click*/
  if (NULL == widget)
    return FALSE;
  if (event->type == GDK_BUTTON_PRESS  &&  event->button == 3)
  {
    GNUNET_GNS_GTK_main_treeview_popup_menu_cb (widget, user_data);

  }
  return FALSE;
}

gboolean
GNUNET_GNS_GTK_main_treeview_key_press_popup_menu_cb (GtkWidget *widget, GdkEventKey  *event, gpointer user_data)
{
  /* Check for delete key */
  if ((event->type == GDK_KEY_PRESS) && (GDK_KEY_Delete == event->keyval))
  {
    GNUNET_GNS_GTK_main_treeview_popup_menu_cb (widget, user_data);

  }
  return FALSE;
}

struct ZoneIteration_Context
{
  struct GNUNET_GNS_Context *gns;
  struct GNUNET_CRYPTO_ShortHashCode zone;
  struct GNUNET_NAMESTORE_ZoneIterator * it;
};

struct Remove_Context
{
  struct GNUNET_GNS_Context *gns;
  char *path;
  char *parent;
  GtkTreeModel *tm;
};

void
remove_proc (void *cls,
             int32_t success,
             const char *emsg)
{
  struct Remove_Context *rcc = cls;
  GtkWidget *dialog;
  GtkTreeIter iter;
  if (GNUNET_SYSERR == success)
  {
    char * message = _("Record could not be deleted: ");
    dialog = gtk_message_dialog_new (GTK_WINDOW (rcc->gns->main_window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
                                     GTK_MESSAGE_ERROR,
                                     GTK_BUTTONS_CLOSE,
                                     _("%s %s\n"),
                                     message,
                                     emsg);

    g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), rcc->gns);
    gtk_widget_show_all (dialog);
  }
  else
  {
    gtk_tree_model_get_iter_from_string(rcc->tm, &iter, rcc->path);
    gtk_tree_store_remove (rcc->gns->ts, &iter);
  }
  GNUNET_free(rcc);
}

struct GNUNET_NAMESTORE_RecordData *
build_rd_from_datastore (GtkTreeModel *tm,  GtkTreeIter *it)
{
  struct GNUNET_NAMESTORE_RecordData *rd;
  gboolean exp_is_relative;
  gboolean public;
  guint64 exp;
  guint type;
  char * value;
  size_t value_len;

  gtk_tree_model_get(tm, it, TREE_COL_EXP_TIME_IS_REL, &exp_is_relative,
                             TREE_COL_EXP_TIME, &exp,
                             TREE_COL_RECORD_TYPE, &type,
                             TREE_COL_IS_PUBLIC, &public,
                             TREE_COL_VAL_AS_STR, &value,
                             -1);

  if (value != NULL)
    value_len = strlen(value) + 1;
  else
    value_len = 0;

  rd = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_RecordData) + value_len);

  if (exp_is_relative)
  {
    struct GNUNET_TIME_Relative rel_t;
    rel_t.rel_value = exp;
    rd->expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_t);
  }
  else
  {
    rd->expiration.abs_value = exp;
  }
  if (TRUE == public)
    rd->flags = GNUNET_NAMESTORE_RF_NONE;
  else
    rd->flags = GNUNET_NAMESTORE_RF_PRIVATE;
  rd->record_type = type;
  rd->data_size = value_len;
  rd->data = (char *) &rd[1];
  memcpy ((void *) rd->data, value, value_len);
  return rd;
}

void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem,
                                                 gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  GtkTreeIter it;
  GtkTreeIter parent;
  GtkTreeIter child;
  int not_dummy;
  int children;
  int c;
  gboolean has_parent;

  char *name = "";
  char *path;
  struct GNUNET_NAMESTORE_RecordData *rd;
  struct Remove_Context *rcc;

  GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview"));
  GtkTreeModel *tm;
  GtkTreeSelection * ts = gtk_tree_view_get_selection(tv);

  gtk_tree_selection_get_selected (ts, &tm, &it);
  gtk_tree_model_get(tm, &it, TREE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
  if (GNUNET_NO == not_dummy)
    return;

  /* Has parent? */
  has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
  if (TRUE == has_parent)
  {
    /* this is a single record */
    gtk_tree_model_get(tm, &parent, TREE_COL_NAME, &name, -1);
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting single record for name `%s'\n", name);
    rd = build_rd_from_datastore (tm, &it);
    rcc= GNUNET_malloc (sizeof (struct Remove_Context));
    rcc->gns = gns;
    rcc->tm = tm;
    rcc->path = gtk_tree_model_get_string_from_iter (tm, &it);
    GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc);
    GNUNET_free (rd);

  }
  else
  {
    /* this is a whole name */
    gtk_tree_model_get(tm, &it, TREE_COL_NAME, &name, -1);
    children = gtk_tree_model_iter_n_children (tm, &it);
    //path = gtk_tree_model_get_string_from_iter(tm, &it);
    path = gtk_tree_model_get_string_from_iter (tm, &it);
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting name `%s' with %u children\n", name, children);
    gtk_tree_model_iter_children (tm, &child, &it);
    for (c = 0; c < children; c++)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting %u record for name `%s'\n", c, name);

      rd = build_rd_from_datastore (tm, &child);
      rcc= GNUNET_malloc (sizeof (struct Remove_Context));
      rcc->gns = gns;
      rcc->tm = tm;
      rcc->path = gtk_tree_model_get_string_from_iter (tm, &child);
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALLING\n");
      GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc);
      gtk_tree_model_iter_next (tm, &child);
    }
    gtk_tree_model_get_iter_from_string(tm, &it, path);
    gtk_tree_store_remove (gns->ts, &it);
  }
}

void zone_iteration_proc (void *cls,
                          const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
                          struct GNUNET_TIME_Absolute expire,
                          const char *name,
                          unsigned int rd_count,
                          const struct GNUNET_NAMESTORE_RecordData *rd,
                          const struct GNUNET_CRYPTO_RsaSignature *signature)
{
  struct ZoneIteration_Context * zc_ctx = cls;
  GtkTreeIter iter_name;
  GtkTreeIter iter_record;
  GtkEntry *pseu_entry;
  int c;
  int time_is_relative;

  char *exp;
  char *val;
  int public;
  guint64 exp_t;

  GNUNET_assert (zc_ctx != NULL);
  if ((NULL == zone_key) && (NULL == name))
  {
    struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
    GNUNET_CRYPTO_short_hash_to_enc(&zc_ctx->zone, &shenc);
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone `%s 'iteration done\n", &shenc);
    GNUNET_free (zc_ctx);
    return;
  }


  struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
  GNUNET_CRYPTO_short_hash_to_enc(&zc_ctx->zone, &shenc);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone `%s' iteration result `%s', %u records\n",
      &shenc, name, rd_count);

  if (0 == strcmp(name, "+"))
  {
    pseu_entry = GTK_ENTRY((gtk_builder_get_object (zc_ctx->gns->builder, "GNUNET_GNS_GTK_pseu_entry")));
    GNUNET_assert (pseu_entry != NULL);
    if ((rd == NULL) || (rd_count == 0))
    {
      GNUNET_break (0);
      return;
    }
    if (rd->data_size == 0)
    {
      GNUNET_break(0);
      return;
    }

    if (((char *)rd->data)[rd->data_size-1] != '\0')
    {
      GNUNET_break(0);
      return;
    }
    gtk_entry_set_text (pseu_entry, (char *)rd[0].data);
    GNUNET_NAMESTORE_zone_iterator_next(zc_ctx->it);
    return;
  }

  GNUNET_assert(GTK_IS_TREE_STORE(zc_ctx->gns->ts));
  gtk_tree_store_append(zc_ctx->gns->ts, &iter_name, NULL);
  gtk_tree_store_set(zc_ctx->gns->ts, &iter_name,
                     TREE_COL_NAME, name,
                     TREE_COL_NAME_IS_EDITABLE, 1,
                     TREE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR),
                     TREE_COL_IS_RECORD_ROW, GNUNET_NO,
                     TREE_COL_NOT_DUMMY_ROW, GNUNET_YES,
                     -1);


  /* Append elements for records */
  for (c = 0; c < rd_count; c ++)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Record %u: type %u flags %u expiration %llu data_size %u\n",
        c, rd[c].record_type, rd[c].flags, rd[c].expiration, rd[c].data_size);

    /* Set public toggle */
    if (rd[c].flags == GNUNET_NAMESTORE_RF_PRIVATE)
      public = GNUNET_NO;
    else
      public = GNUNET_YES;

    /* Expiration time */
    time_is_relative = GNUNET_NO;

    if (GNUNET_YES == time_is_relative)
    {
      /* FIX THIS WHEN WE HAVE RELATIVE TIME */
      struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_relative_get_zero();
      struct GNUNET_TIME_Absolute exp_abs;
      exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time);
      exp_t = exp_abs.abs_value;
      exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs);
    }
    else
    {
      struct GNUNET_TIME_Absolute exp_abs = rd[c].expiration;
      exp_t = exp_abs.abs_value;
      exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs);
    }
    /* value */
    val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type,
                                            rd[c].data,
                                            rd[c].data_size);
    gtk_tree_store_insert_with_values(zc_ctx->gns->ts, &iter_record , &iter_name, 0,
                                       TREE_COL_NAME, "",
                                       TREE_COL_RECORD_TYPE, rd[c].record_type,
                                       TREE_COL_RECORD_TYPE_AS_STR, GNUNET_NAMESTORE_number_to_typename(rd[c].record_type),
                                       TREE_COL_IS_PUBLIC, public,
                                       TREE_COL_EXP_TIME, exp_t,
                                       TREE_COL_EXP_TIME_AS_STR, exp,
                                       TREE_COL_EXP_TIME_IS_REL, time_is_relative,
                                       TREE_COL_VAL_AS_STR, val,
                                       TREE_COL_IS_RECORD_ROW, GNUNET_YES,
                                       TREE_COL_NOT_DUMMY_ROW, GNUNET_YES,
                                       -1);

    GNUNET_free (exp);
  }

  GNUNET_NAMESTORE_zone_iterator_next(zc_ctx->it);
}

/**
 * The zone treeview was realized.   Setup the model.
 *
 * @param widget the widget
 * @param user_data unused
 */
void
GNUNET_GNS_GTK_main_treeview_realize_cb (GtkWidget *widget,
					 gpointer user_data)
{
  struct GNUNET_GNS_Context *gns = user_data;
  struct ZoneIteration_Context *zc_ctx;
  GtkTreeIter toplevel;

  /* Append a top level row and leave it empty */
  gtk_tree_store_insert_with_values(gns->ts, &toplevel, NULL, 0,
                                     TREE_COL_NAME, _(NEW_NAME_STR),
                                     TREE_COL_RECORD_TYPE, 1,
                                     TREE_COL_NAME_IS_EDITABLE, 1,
                                     TREE_COL_IS_RECORD_ROW, GNUNET_NO,
                                     TREE_COL_NOT_DUMMY_ROW, GNUNET_NO,
                                     -1);

  zc_ctx = GNUNET_malloc (sizeof (struct ZoneIteration_Context));
  zc_ctx->gns = user_data;
  zc_ctx->zone = gns->zone;
  zc_ctx->it = GNUNET_NAMESTORE_zone_iteration_start(gns->ns, &gns->zone,
      GNUNET_NAMESTORE_RF_NONE,
      GNUNET_NAMESTORE_RF_NONE,
      &zone_iteration_proc,
      zc_ctx);
}


/* end of gnunet-gns-gtk_zone.c */