aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-03 10:58:53 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-03 10:58:53 +0000
commit999fa33603dd01ab61aa399e9cceb6daa4dc6fce (patch)
treee8d664d51a7c9705e565872e37ae53141fee5f88
parent6e9c8986a5f173e30a47071a0969fb61a0fc560d (diff)
downloadgnunet-gtk-999fa33603dd01ab61aa399e9cceb6daa4dc6fce.tar.gz
gnunet-gtk-999fa33603dd01ab61aa399e9cceb6daa4dc6fce.zip
-another step towards custom edit dialogs for records
-rw-r--r--contrib/gnunet_setup_gtk_main_window.glade20
-rw-r--r--src/setup/Makefile.am1
-rw-r--r--src/setup/gnunet-setup-gns-edit.c41
-rw-r--r--src/setup/gnunet-setup-gns-edit.h127
-rw-r--r--src/setup/gnunet-setup-gns.c146
5 files changed, 306 insertions, 29 deletions
diff --git a/contrib/gnunet_setup_gtk_main_window.glade b/contrib/gnunet_setup_gtk_main_window.glade
index 0400ca6a..51693d64 100644
--- a/contrib/gnunet_setup_gtk_main_window.glade
+++ b/contrib/gnunet_setup_gtk_main_window.glade
@@ -16,6 +16,13 @@
16 <property name="step_increment">1</property> 16 <property name="step_increment">1</property>
17 <property name="page_increment">10</property> 17 <property name="page_increment">10</property>
18 </object> 18 </object>
19 <object class="GtkAdjustment" id="GNUNET_setup_exit_interface_mask_adjustment">
20 <property name="lower">1</property>
21 <property name="upper">127</property>
22 <property name="value">48</property>
23 <property name="step_increment">1</property>
24 <property name="page_increment">10</property>
25 </object>
19 <object class="GtkDialog" id="GNUNET_setup_dialog"> 26 <object class="GtkDialog" id="GNUNET_setup_dialog">
20 <property name="can_focus">False</property> 27 <property name="can_focus">False</property>
21 <property name="border_width">5</property> 28 <property name="border_width">5</property>
@@ -4456,7 +4463,7 @@
4456 </object> 4463 </object>
4457 <attributes> 4464 <attributes>
4458 <attribute name="visible">10</attribute> 4465 <attribute name="visible">10</attribute>
4459 <attribute name="editable">10</attribute> 4466 <attribute name="editable">14</attribute>
4460 <attribute name="text">3</attribute> 4467 <attribute name="text">3</attribute>
4461 </attributes> 4468 </attributes>
4462 </child> 4469 </child>
@@ -4578,13 +4585,6 @@
4578 <action-widget response="-3">GNUNET_setup_save_button</action-widget> 4585 <action-widget response="-3">GNUNET_setup_save_button</action-widget>
4579 </action-widgets> 4586 </action-widgets>
4580 </object> 4587 </object>
4581 <object class="GtkAdjustment" id="GNUNET_setup_exit_interface_mask_adjustment">
4582 <property name="lower">1</property>
4583 <property name="upper">127</property>
4584 <property name="value">48</property>
4585 <property name="step_increment">1</property>
4586 <property name="page_increment">10</property>
4587 </object>
4588 <object class="GtkAdjustment" id="GNUNET_setup_fs_datacache_mysql_port_adjustment"> 4588 <object class="GtkAdjustment" id="GNUNET_setup_fs_datacache_mysql_port_adjustment">
4589 <property name="lower">1</property> 4589 <property name="lower">1</property>
4590 <property name="upper">65535</property> 4590 <property name="upper">65535</property>
@@ -4669,6 +4669,10 @@
4669 <column type="gchararray"/> 4669 <column type="gchararray"/>
4670 <!-- column-name name_color --> 4670 <!-- column-name name_color -->
4671 <column type="gchararray"/> 4671 <column type="gchararray"/>
4672 <!-- column-name type_is_editable -->
4673 <column type="gboolean"/>
4674 <!-- column-name is_shadow -->
4675 <column type="gboolean"/>
4672 </columns> 4676 </columns>
4673 </object> 4677 </object>
4674 <object class="GtkListStore" id="GNUNET_setup_gns_type_liststore"> 4678 <object class="GtkListStore" id="GNUNET_setup_gns_type_liststore">
diff --git a/src/setup/Makefile.am b/src/setup/Makefile.am
index e8469f5b..4ab2a1db 100644
--- a/src/setup/Makefile.am
+++ b/src/setup/Makefile.am
@@ -27,6 +27,7 @@ gnunet_setup_SOURCES = \
27 gnunet-setup-namestore-plugins.c \ 27 gnunet-setup-namestore-plugins.c \
28 gnunet-setup-namestore-config.c \ 28 gnunet-setup-namestore-config.c \
29 gnunet-setup-gns.c gnunet-setup-gns.h \ 29 gnunet-setup-gns.c gnunet-setup-gns.h \
30 gnunet-setup-gns-edit.c gnunet-setup-gns-edit.h \
30 gnunet-setup-hostlist-editing.c \ 31 gnunet-setup-hostlist-editing.c \
31 gnunet-setup-hostlist-server.c 32 gnunet-setup-hostlist-server.c
32gnunet_setup_LDADD = \ 33gnunet_setup_LDADD = \
diff --git a/src/setup/gnunet-setup-gns-edit.c b/src/setup/gnunet-setup-gns-edit.c
new file mode 100644
index 00000000..683eaf6b
--- /dev/null
+++ b/src/setup/gnunet-setup-gns-edit.c
@@ -0,0 +1,41 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file src/setup/gnunet-setup-gns-edit.c
22 * @author Christian Grothoff
23 * @brief editing dialogs for GNS records
24 */
25#include "gnunet-setup-gns-edit.h"
26
27/**
28 * Run an GNS Edit dialog for an 'A' Record.
29 *
30 * @param cont continuation to call when done
31 * @param edc editing context to use
32 */
33void
34GNS_edit_dialog_a (struct EditDialogContext *edc)
35{
36 GNUNET_break (0); /* not implemented */
37 edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */
38}
39
40
41/* end of gnunet-setup-gns-edit.c */
diff --git a/src/setup/gnunet-setup-gns-edit.h b/src/setup/gnunet-setup-gns-edit.h
new file mode 100644
index 00000000..56af72e0
--- /dev/null
+++ b/src/setup/gnunet-setup-gns-edit.h
@@ -0,0 +1,127 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/setup/gnunet-setup-gns-edit.h
23 * @author Christian Grothoff
24 * @brief editing dialogs for GNS records
25 */
26#ifndef GNUNET_SETUP_GNS_EDIT_H
27#define GNUNET_SETUP_GNS_EDIT_H
28
29#include "gnunet_gtk.h"
30#include "gnunet-setup-gns.h"
31#include <gnunet/gnunet_namestore_service.h>
32#include <gnunet/gnunet_dnsparser_lib.h>
33
34
35/**
36 * Context for edit operations.
37 */
38struct EditDialogContext;
39
40
41/**
42 * Signature of the continuation function invoked once the
43 * edit dialog is done.
44 *
45 * @param edc dialog context
46 * @param ret return code from the dialog
47 */
48typedef void (*GNS_EditContinuation)(struct EditDialogContext *edc,
49 GtkResponseType ret);
50
51
52
53/**
54 * Context for edit operations.
55 */
56struct EditDialogContext
57{
58
59 /**
60 * Function to call at the end.
61 */
62 GNS_EditContinuation cont;
63
64 /**
65 * Where in the tree view are we editing?
66 */
67 GtkTreeIter it;
68
69 /**
70 * Expiration time value (absolute or relative).
71 */
72 guint64 n_exp_time;
73
74 /**
75 * Old name of the record (for deletion).
76 */
77 gchar *n_name;
78
79 /**
80 * New name.
81 */
82 gchar *n_new_name;
83
84 /**
85 * Value of the record in string format.
86 */
87 gchar *n_value;
88
89 /**
90 * Zone into which the record should be placed.
91 */
92 const char *new_zone_option;
93
94 /**
95 * Flag indicating if the old record was in the namestore.
96 */
97 int old_record_in_namestore;
98
99 /**
100 * Is this record 'public'?
101 */
102 gboolean n_public;
103
104 /**
105 * Is the expiration time relative?
106 */
107 gboolean n_is_relative;
108
109 /**
110 * Is this record a shadow record?
111 */
112 gboolean n_is_shadow;
113
114};
115
116
117
118/**
119 * Run an GNS Edit dialog for an 'A' Record.
120 *
121 * @param edc editing context to use
122 */
123void
124GNS_edit_dialog_a (struct EditDialogContext *edc);
125
126
127#endif
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index d359796b..ebd87389 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "gnunet_gtk.h" 26#include "gnunet_gtk.h"
27#include "gnunet-setup-gns.h" 27#include "gnunet-setup-gns.h"
28#include "gnunet-setup-gns-edit.h"
28#include <gnunet/gnunet_namestore_service.h> 29#include <gnunet/gnunet_namestore_service.h>
29#include <gnunet/gnunet_dnsparser_lib.h> 30#include <gnunet/gnunet_dnsparser_lib.h>
30 31
@@ -142,12 +143,16 @@ enum GNSTreestoreColumn
142 */ 143 */
143 GNS_TREESTORE_COL_NAME_COLOR, 144 GNS_TREESTORE_COL_NAME_COLOR,
144 145
145
146 /** 146 /**
147 * A gboolean; TRUE if the 'type' column can still be changed; 147 * A gboolean; TRUE if the 'type' column can still be changed;
148 * FALSE once we have edited the value. 148 * FALSE once we have edited the value.
149 */ 149 */
150 GNS_TREESTORE_COL_TYPE_IS_EDITABLE 150 GNS_TREESTORE_COL_TYPE_IS_EDITABLE,
151
152 /**
153 * A gboolean; TRUE if the value is a shadow record.
154 */
155 GNS_TREESTORE_COL_IS_SHADOW
151}; 156};
152 157
153 158
@@ -1021,7 +1026,7 @@ update_treemodel_after_remove (void *cls,
1021 * the namestore). If the given path identifies an entire 'name', 1026 * the namestore). If the given path identifies an entire 'name',
1022 * remove all records under that name. 1027 * remove all records under that name.
1023 * 1028 *
1024 * @param path identifying record(s) to remove 1029 * @param path identifying record(s) to remove; FIXME: consider doing this with an 'iter' instead
1025 */ 1030 */
1026static void 1031static void
1027remove_records_by_path (const gchar *path) 1032remove_records_by_path (const gchar *path)
@@ -1089,9 +1094,89 @@ remove_records_by_path (const gchar *path)
1089 1094
1090 1095
1091/** 1096/**
1097 * The edit dialog completed; update the namestore and the
1098 * view based on the new values in 'edc'.
1099 *
1100 * @param edc editing context information
1101 * @param ret return code of the dialog
1102 */
1103static void
1104edit_dialog_continuation (struct EditDialogContext *edc,
1105 GtkResponseType ret)
1106{
1107 char *path;
1108
1109 /* FIXME: logic to move records between zones is missing here!
1110 (#2473) */
1111 switch (ret)
1112 {
1113 case GTK_RESPONSE_REJECT: /* code for 'delete' */
1114 if (GNUNET_YES == edc->old_record_in_namestore)
1115 {
1116 /* remove item from tree view and namestore */
1117 path = gtk_tree_model_get_string_from_iter (tm, &edc->it);
1118 remove_records_by_path (path);
1119 g_free (path);
1120 }
1121 else
1122 {
1123 /* invalid choice, 'delete' should have been hidden... */
1124 GNUNET_break (0);
1125 gtk_tree_store_remove (ts, &edc->it);
1126 }
1127 break;
1128 case GTK_RESPONSE_CANCEL:
1129 case GTK_RESPONSE_DELETE_EVENT: /* window deletion counts as 'cancel' */
1130 if (GNUNET_NO == edc->old_record_in_namestore)
1131 {
1132 /* re-enable type selection */
1133 gtk_tree_store_set (ts, &edc->it,
1134 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
1135 GNS_TREESTORE_COL_VAL_COLOR, "red",
1136 -1);
1137 }
1138 else
1139 {
1140 /* do nothing */
1141 }
1142 break;
1143 case GTK_RESPONSE_OK:
1144 /* update model */
1145 gtk_tree_store_set (ts, &edc->it,
1146 GNS_TREESTORE_COL_NAME, edc->n_name,
1147 GNS_TREESTORE_COL_IS_PUBLIC, edc->n_public,
1148 GNS_TREESTORE_COL_EXP_TIME, edc->n_exp_time,
1149 GNS_TREESTORE_COL_EXP_TIME_IS_REL, edc->n_is_relative,
1150 GNS_TREESTORE_COL_IS_SHADOW, edc->n_is_shadow,
1151 GNS_TREESTORE_COL_VAL_AS_STR, edc->n_value,
1152 GNS_TREESTORE_COL_VAL_COLOR, NULL,
1153 -1);
1154 if (GNUNET_YES == edc->old_record_in_namestore)
1155 {
1156 /* replace record in database with that from model */
1157 check_name_validity_and_commit (&edc->it, edc->n_name);
1158 }
1159 else
1160 {
1161 /* add record in database based on model */
1162 check_name_validity_and_commit (&edc->it, NULL);
1163 }
1164 break;
1165 default:
1166 GNUNET_break (0);
1167 break;
1168 }
1169 g_free (edc->n_name);
1170 g_free (edc->n_new_name);
1171 g_free (edc->n_value);
1172 GNUNET_free (edc);
1173}
1174
1175
1176/**
1092 * Edit the record at the currently selected row. If the old record 1177 * Edit the record at the currently selected row. If the old record
1093 * exists, allow the user to modify or delete it; if it does not 1178 * exists, allow the user to modify or delete it; if it does not
1094 * exist, remove it _only_ from the model (by offering the user the 1179 * exist, make the record type editable again (by offering the user the
1095 * 'cancel' option; hide 'delete' in this case). 1180 * 'cancel' option; hide 'delete' in this case).
1096 * 1181 *
1097 * @param old_record_in_namestore GNUNET_YES if the old record exists in the namestore, 1182 * @param old_record_in_namestore GNUNET_YES if the old record exists in the namestore,
@@ -1101,33 +1186,52 @@ static void
1101edit_selected_row (int old_record_in_namestore) 1186edit_selected_row (int old_record_in_namestore)
1102{ 1187{
1103 GtkTreeSelection *sel; 1188 GtkTreeSelection *sel;
1104 GtkTreeIter it;
1105 gchar *n_name;
1106 gint n_type; 1189 gint n_type;
1107 gboolean n_public; 1190 struct EditDialogContext *edc;
1108 guint64 n_exp_time;
1109 gboolean n_is_relative;
1110 gchar *n_value;
1111 1191
1112 sel = gtk_tree_view_get_selection (tv); 1192 sel = gtk_tree_view_get_selection (tv);
1113 if (! gtk_tree_selection_get_selected (sel, NULL, &it)) 1193 edc = GNUNET_malloc (sizeof (struct EditDialogContext));
1194 if (! gtk_tree_selection_get_selected (sel, NULL, &edc->it))
1114 { 1195 {
1115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1116 "No row selected\n"); 1197 "No row selected\n");
1198 GNUNET_free (edc);
1117 return; 1199 return;
1118 } 1200 }
1119 gtk_tree_model_get (tm, &it, 1201 gtk_tree_model_get (tm, &edc->it,
1120 GNS_TREESTORE_COL_NAME, &n_name, 1202 GNS_TREESTORE_COL_NAME, &edc->n_name,
1121 GNS_TREESTORE_COL_RECORD_TYPE, &n_type, 1203 GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
1122 GNS_TREESTORE_COL_IS_PUBLIC, &n_public, 1204 GNS_TREESTORE_COL_IS_PUBLIC, &edc->n_public,
1123 GNS_TREESTORE_COL_EXP_TIME, &n_exp_time, 1205 GNS_TREESTORE_COL_EXP_TIME, &edc->n_exp_time,
1124 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative, 1206 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &edc->n_is_relative,
1125 GNS_TREESTORE_COL_VAL_AS_STR, &n_value, 1207 GNS_TREESTORE_COL_IS_SHADOW, &edc->n_is_shadow,
1208 GNS_TREESTORE_COL_VAL_AS_STR, &edc->n_value,
1126 -1); 1209 -1);
1127 // FIXME - implement... 1210 edc->old_record_in_namestore = old_record_in_namestore;
1128 GNUNET_break (0); 1211 edc->new_zone_option = current_zone_option;
1129 g_free (n_name); 1212 edc->n_new_name = g_strdup (edc->n_name);
1130 g_free (n_value); 1213 edc->cont = &edit_dialog_continuation;
1214 switch (n_type)
1215 {
1216 case GNUNET_DNSPARSER_TYPE_A:
1217 GNS_edit_dialog_a (edc);
1218 break;
1219 case GNUNET_DNSPARSER_TYPE_NS:
1220 case GNUNET_DNSPARSER_TYPE_CNAME:
1221 case GNUNET_DNSPARSER_TYPE_SOA:
1222 case GNUNET_DNSPARSER_TYPE_PTR:
1223 case GNUNET_DNSPARSER_TYPE_MX:
1224 case GNUNET_DNSPARSER_TYPE_TXT:
1225 case GNUNET_DNSPARSER_TYPE_AAAA:
1226 case GNUNET_DNSPARSER_TYPE_SRV:
1227 case GNUNET_DNSPARSER_TYPE_TLSA:
1228 case GNUNET_NAMESTORE_TYPE_PKEY:
1229 case GNUNET_NAMESTORE_TYPE_LEHO:
1230 case GNUNET_NAMESTORE_TYPE_VPN:
1231 GNUNET_break (0); /* FIXME - implement (#2465) */
1232 edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */
1233 break;
1234 }
1131} 1235}
1132 1236
1133 1237