aboutsummaryrefslogtreecommitdiff
path: root/src/setup/gnunet-setup-gns.c
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 /src/setup/gnunet-setup-gns.c
parent6e9c8986a5f173e30a47071a0969fb61a0fc560d (diff)
downloadgnunet-gtk-999fa33603dd01ab61aa399e9cceb6daa4dc6fce.tar.gz
gnunet-gtk-999fa33603dd01ab61aa399e9cceb6daa4dc6fce.zip
-another step towards custom edit dialogs for records
Diffstat (limited to 'src/setup/gnunet-setup-gns.c')
-rw-r--r--src/setup/gnunet-setup-gns.c146
1 files changed, 125 insertions, 21 deletions
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