aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-22 10:04:26 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-22 10:04:26 +0000
commit3b841c135724d6688f0dbd22ea07b16b2e12a2b8 (patch)
tree856c300d5f79e4ff3e03e27b7c9b38dcaed4611d
parentf2951f014d7778ebec8a25b37529e9e9ee9a8b1f (diff)
downloadgnunet-gtk-3b841c135724d6688f0dbd22ea07b16b2e12a2b8.tar.gz
gnunet-gtk-3b841c135724d6688f0dbd22ea07b16b2e12a2b8.zip
records removed in gui
-rw-r--r--src/gns/gnunet-gns-gtk_zone.c134
1 files changed, 40 insertions, 94 deletions
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c
index f5eb9a45..b23d946f 100644
--- a/src/gns/gnunet-gns-gtk_zone.c
+++ b/src/gns/gnunet-gns-gtk_zone.c
@@ -86,7 +86,6 @@ check_name_validity_and_commit_remove_proc (void *cls,
86 GNUNET_free (uc->rd); 86 GNUNET_free (uc->rd);
87 GNUNET_free (uc->name); 87 GNUNET_free (uc->name);
88 GNUNET_free (uc); 88 GNUNET_free (uc);
89 GNUNET_break (0);
90 } 89 }
91 else 90 else
92 { 91 {
@@ -124,7 +123,6 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path)
124 children = gtk_tree_model_iter_n_children (gns->tm, &parent); 123 children = gtk_tree_model_iter_n_children (gns->tm, &parent);
125 if (children < 1) 124 if (children < 1)
126 { 125 {
127 GNUNET_break (0);
128 return; 126 return;
129 } 127 }
130 128
@@ -180,9 +178,6 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path)
180 rd[c].data_size = strlen (n_value) + 1; 178 rd[c].data_size = strlen (n_value) + 1;
181 rd[c].data = GNUNET_malloc(rd[c].data_size); 179 rd[c].data = GNUNET_malloc(rd[c].data_size);
182 memcpy ((void *) rd[c].data, n_value, rd[c].data_size); 180 memcpy ((void *) rd[c].data, n_value, rd[c].data_size);
183
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child [%u] is %s\n",
185 c, (GNUNET_NO == valid) ? "INVALID" : "VALID");
186 } 181 }
187 g_free (n_name); 182 g_free (n_name);
188 g_free (n_exp_color); 183 g_free (n_exp_color);
@@ -212,13 +207,43 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path)
212 } 207 }
213} 208}
214 209
210struct Remove_Context
211{
212 struct GNUNET_GNS_Context *gns;
213 char *path;
214};
215
215void 216void
216check_name_validity_and_remove_proc (void *cls, 217check_name_validity_and_remove_proc (void *cls,
217 int32_t success, 218 int32_t success,
218 const char *emsg) 219 const char *emsg)
219{ 220{
221 struct Remove_Context *rcc = cls;
222 GtkDialog *dialog;
223 GtkTreeIter it;
224 if (GNUNET_SYSERR == success)
225 {
226 char * message = _("Record could not be deleted:");
227 dialog = gtk_message_dialog_new (GTK_WINDOW (rcc->gns->main_window),
228 GTK_DIALOG_DESTROY_WITH_PARENT,
229 GTK_MESSAGE_ERROR,
230 GTK_BUTTONS_CLOSE,
231 _("%s\n%s\n"),
232 message,
233 emsg);
220 234
235 g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), rcc->gns);
236 gtk_widget_show_all (dialog);
237 }
238 else
239 {
240 gtk_tree_model_get_iter_from_string(rcc->gns->tm, &it, rcc->path);
241 gtk_tree_store_remove (rcc->gns->ts, &it);
242 }
243 GNUNET_free (rcc->path);
244 GNUNET_free (rcc);
221} 245}
246
222void 247void
223check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path) 248check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
224{ 249{
@@ -227,6 +252,7 @@ check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
227 char *name; 252 char *name;
228 int valid = GNUNET_YES; 253 int valid = GNUNET_YES;
229 struct GNUNET_NAMESTORE_RecordData rd; 254 struct GNUNET_NAMESTORE_RecordData rd;
255 struct Remove_Context *rcc;
230 256
231 char *n_name; 257 char *n_name;
232 int n_type; 258 int n_type;
@@ -286,7 +312,11 @@ check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
286 rd.data_size = strlen (n_value) + 1; 312 rd.data_size = strlen (n_value) + 1;
287 rd.data = GNUNET_malloc(rd.data_size); 313 rd.data = GNUNET_malloc(rd.data_size);
288 memcpy ((void *) rd.data, n_value, rd.data_size); 314 memcpy ((void *) rd.data, n_value, rd.data_size);
289 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, &rd, &check_name_validity_and_remove_proc, path); 315
316 rcc = GNUNET_malloc(sizeof (struct Remove_Context));
317 rcc->gns = gns;
318 rcc->path = strdup (path);
319 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, &rd, &check_name_validity_and_remove_proc, rcc);
290 GNUNET_free (rd.data); 320 GNUNET_free (rd.data);
291 } 321 }
292 g_free (n_name); 322 g_free (n_name);
@@ -297,7 +327,10 @@ check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
297 } 327 }
298 else 328 else
299 { 329 {
300 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_remove_proc, path); 330 rcc = GNUNET_malloc(sizeof (struct Remove_Context));
331 rcc->gns = gns;
332 rcc->path = strdup (path);
333 GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_remove_proc, rcc);
301 } 334 }
302 g_free (name); 335 g_free (name);
303} 336}
@@ -651,7 +684,6 @@ void set_exp (struct GNUNET_GNS_Context *gns, char * exp)
651 if (TRUE == has_parent) 684 if (TRUE == has_parent)
652 { 685 {
653 /* this is a single record */ 686 /* this is a single record */
654 GNUNET_break (0);
655 renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext"))); 687 renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext")));
656 path = gtk_tree_model_get_string_from_iter (tm, &it); 688 path = gtk_tree_model_get_string_from_iter (tm, &it);
657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PATH `%s'\n", path); 689 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PATH `%s'\n", path);
@@ -660,10 +692,6 @@ void set_exp (struct GNUNET_GNS_Context *gns, char * exp)
660 exp, 692 exp,
661 gns); 693 gns);
662 } 694 }
663 else
664 {
665 GNUNET_break (0);
666 }
667} 695}
668 696
669 697
@@ -735,89 +763,7 @@ struct ZoneIteration_Context
735 struct GNUNET_NAMESTORE_ZoneIterator * it; 763 struct GNUNET_NAMESTORE_ZoneIterator * it;
736}; 764};
737 765
738struct Remove_Context
739{
740 struct GNUNET_GNS_Context *gns;
741 char *path;
742 char *parent;
743 GtkTreeModel *tm;
744};
745
746void
747remove_proc (void *cls,
748 int32_t success,
749 const char *emsg)
750{
751 struct Remove_Context *rcc = cls;
752 GtkWidget *dialog;
753 GtkTreeIter iter;
754 if (GNUNET_SYSERR == success)
755 {
756 char * message = _("Record could not be deleted: ");
757 dialog = gtk_message_dialog_new (GTK_WINDOW (rcc->gns->main_window),
758 GTK_DIALOG_DESTROY_WITH_PARENT,
759 GTK_MESSAGE_ERROR,
760 GTK_BUTTONS_CLOSE,
761 _("%s %s\n"),
762 message,
763 emsg);
764 766
765 g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), rcc->gns);
766 gtk_widget_show_all (dialog);
767 }
768 else
769 {
770 gtk_tree_model_get_iter_from_string(rcc->tm, &iter, rcc->path);
771 gtk_tree_store_remove (rcc->gns->ts, &iter);
772 }
773 GNUNET_free(rcc);
774}
775
776struct GNUNET_NAMESTORE_RecordData *
777build_rd_from_datastore (GtkTreeModel *tm, GtkTreeIter *it)
778{
779 struct GNUNET_NAMESTORE_RecordData *rd;
780 gboolean exp_is_relative;
781 gboolean public;
782 guint64 exp;
783 guint type;
784 char * value;
785 size_t value_len;
786
787 gtk_tree_model_get(tm, it, TREE_COL_EXP_TIME_IS_REL, &exp_is_relative,
788 TREE_COL_EXP_TIME, &exp,
789 TREE_COL_RECORD_TYPE, &type,
790 TREE_COL_IS_PUBLIC, &public,
791 TREE_COL_VAL_AS_STR, &value,
792 -1);
793
794 if (value != NULL)
795 value_len = strlen(value) + 1;
796 else
797 value_len = 0;
798
799 rd = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_RecordData) + value_len);
800
801 if (exp_is_relative)
802 {
803 struct GNUNET_TIME_Relative rel_t;
804 rel_t.rel_value = exp;
805 rd->expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_t);
806 }
807 else
808 {
809 rd->expiration.abs_value = exp;
810 }
811 if (TRUE == public)
812 rd->flags = GNUNET_NAMESTORE_RF_NONE;
813 else
814 rd->flags = GNUNET_NAMESTORE_RF_PRIVATE;
815 rd->record_type = type;
816 rd->data_size = value_len;
817 rd->data = (char *) &rd[1];
818 memcpy ((void *) rd->data, value, value_len);
819 return rd;
820}
821 767
822 768
823void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, 769void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem,