aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-03 09:54:21 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-03 09:54:21 +0000
commita90965ca3f0c11d154e87113f507bec7ea556972 (patch)
treef8e516bedc346180f839cc2c8f63287d43e1c7b7
parent9a0702bd5ea6bef0c51f826ab5ec5310875fb9a6 (diff)
downloadgnunet-gtk-a90965ca3f0c11d154e87113f507bec7ea556972.tar.gz
gnunet-gtk-a90965ca3f0c11d154e87113f507bec7ea556972.zip
-more preparations for custom edit dialog
-rw-r--r--src/setup/gnunet-setup-gns.c216
1 files changed, 75 insertions, 141 deletions
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index 65b36aed..551ea74c 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -140,7 +140,14 @@ enum GNSTreestoreColumn
140 * A gchararray with the name of the color to use for the 140 * A gchararray with the name of the color to use for the
141 * name column. 141 * name column.
142 */ 142 */
143 GNS_TREESTORE_COL_NAME_COLOR 143 GNS_TREESTORE_COL_NAME_COLOR,
144
145
146 /**
147 * A gboolean; TRUE if the 'type' column can still be changed;
148 * FALSE once we have edited the value.
149 */
150 GNS_TREESTORE_COL_TYPE_IS_EDITABLE
144}; 151};
145 152
146 153
@@ -858,6 +865,7 @@ check_name_validity_and_commit (GtkTreeIter *it,
858 (NULL == n_value) || 865 (NULL == n_value) ||
859 (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, &data_size)) ) 866 (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, &data_size)) )
860 { 867 {
868 GNUNET_break (0);
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
862 "Invalid record, skipping\n"); 870 "Invalid record, skipping\n");
863 records--; 871 records--;
@@ -1021,18 +1029,14 @@ remove_records_by_path (const gchar *path)
1021 GtkTreeIter it; 1029 GtkTreeIter it;
1022 GtkTreeIter parent; 1030 GtkTreeIter parent;
1023 char *name; 1031 char *name;
1024 int valid = GNUNET_YES;
1025 struct GNUNET_NAMESTORE_RecordData rd; 1032 struct GNUNET_NAMESTORE_RecordData rd;
1026 struct RemoveContext *rc; 1033 struct RemoveContext *rc;
1027 char *n_name; 1034 char *n_name;
1028 int n_type; 1035 int n_type;
1029 gboolean n_public; 1036 gboolean n_public;
1030 char *n_exp_color;
1031 guint64 n_exp_time; 1037 guint64 n_exp_time;
1032 char *n_exp_str;
1033 gboolean n_is_relative; 1038 gboolean n_is_relative;
1034 char *n_value; 1039 char *n_value;
1035 char *n_value_color;
1036 1040
1037 gtk_tree_model_get_iter_from_string (tm, &it, path); 1041 gtk_tree_model_get_iter_from_string (tm, &it, path);
1038 gtk_tree_model_get (tm, &it, 1042 gtk_tree_model_get (tm, &it,
@@ -1047,62 +1051,30 @@ remove_records_by_path (const gchar *path)
1047 GNS_TREESTORE_COL_NAME, &n_name, 1051 GNS_TREESTORE_COL_NAME, &n_name,
1048 GNS_TREESTORE_COL_RECORD_TYPE, &n_type, 1052 GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
1049 GNS_TREESTORE_COL_IS_PUBLIC, &n_public, 1053 GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
1050 GNS_TREESTORE_COL_EXP_TIME_COLOR, &n_exp_color,
1051 GNS_TREESTORE_COL_EXP_TIME, &n_exp_time, 1054 GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
1052 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative, 1055 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
1053 GNS_TREESTORE_COL_EXP_TIME_AS_STR, &n_exp_str,
1054 GNS_TREESTORE_COL_VAL_AS_STR, &n_value, 1056 GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
1055 GNS_TREESTORE_COL_VAL_COLOR, &n_value_color,
1056 -1); 1057 -1);
1057 1058
1058 /* valid name */ 1059 /* valid name */
1059 if (NULL == n_name) 1060 if (n_public)
1060 valid = GNUNET_NO; 1061 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
1061
1062 /* valid record type */
1063 if (0 == n_type)
1064 valid = GNUNET_NO;
1065
1066 /* valid expiration */
1067 if ( (NULL != n_exp_color) ||
1068 (NULL == n_exp_str) ||
1069 (0 == n_exp_time) )
1070 valid = GNUNET_NO;
1071
1072 /* valid value */
1073 if ( (NULL != n_value_color) ||
1074 (NULL == n_value) )
1075 valid = GNUNET_NO;
1076
1077 if (GNUNET_YES == valid)
1078 {
1079 if (n_public)
1080 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
1081 else
1082 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
1083 if (n_is_relative)
1084 rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
1085 rd.record_type = n_type;
1086 rd.expiration_time = n_exp_time;
1087 GNUNET_NAMESTORE_string_to_value (n_type, n_value,
1088 (void**)&rd.data, &rd.data_size);
1089
1090 rc = GNUNET_malloc (sizeof (struct RemoveContext));
1091 rc->path = strdup (path);
1092 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd,
1093 &update_treemodel_after_remove, rc);
1094 GNUNET_free ((void *) rd.data);
1095 }
1096 else 1062 else
1097 { 1063 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
1098 gtk_tree_model_get_iter_from_string(tm, &it, path); 1064 if (n_is_relative)
1099 gtk_tree_store_remove (ts, &it); 1065 rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
1100 } 1066 rd.record_type = n_type;
1067 rd.expiration_time = n_exp_time;
1068 GNUNET_NAMESTORE_string_to_value (n_type, n_value,
1069 (void**)&rd.data, &rd.data_size);
1070
1071 rc = GNUNET_malloc (sizeof (struct RemoveContext));
1072 rc->path = strdup (path);
1073 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd,
1074 &update_treemodel_after_remove, rc);
1075 GNUNET_free ((void *) rd.data);
1101 g_free (n_name); 1076 g_free (n_name);
1102 g_free (n_exp_color);
1103 g_free (n_exp_str);
1104 g_free (n_value); 1077 g_free (n_value);
1105 g_free (n_value_color);
1106 } 1078 }
1107 else if (0 != strcmp (name, ROOT_STR)) 1079 else if (0 != strcmp (name, ROOT_STR))
1108 { 1080 {
@@ -1117,9 +1089,25 @@ remove_records_by_path (const gchar *path)
1117 1089
1118 1090
1119/** 1091/**
1092 * 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
1094 * exist, remove it _only_ from the model (by offering the user the
1095 * 'cancel' option; hide 'delete' in this case).
1096 *
1097 * @param old_record_in_namestore GNUNET_YES if the old record exists in the namestore,
1098 * GNUNET_NO if this is a new record that doesn't exist yet
1099 */
1100static void
1101edit_selected_row (int old_record_in_namestore)
1102{
1103 // FIXME
1104 GNUNET_break (0);
1105}
1106
1107
1108/**
1120 * The user has selected a new record type. Update the 1109 * The user has selected a new record type. Update the
1121 * model, possibly invalidating (marking 'red') the existing 1110 * model and then start the 'edit' dialog.
1122 * value.
1123 * 1111 *
1124 * @param renderer updated renderer 1112 * @param renderer updated renderer
1125 * @param path the path identifying the edited cell 1113 * @param path the path identifying the edited cell
@@ -1136,14 +1124,7 @@ GNUNET_setup_gns_type_cellrenderercombo_edited_cb (GtkCellRendererCombo *combo,
1136 GtkTreeIter it; 1124 GtkTreeIter it;
1137 GtkTreeIter child; 1125 GtkTreeIter child;
1138 guint type; 1126 guint type;
1139 gboolean not_dummy_row;
1140 char *name_str; 1127 char *name_str;
1141 char *value_str;
1142 int is_valid;
1143 void *data;
1144 size_t data_size;
1145 GtkTreePath *tp;
1146 GtkTreeViewColumn *value_column;
1147 1128
1148 type = GNUNET_NAMESTORE_typename_to_number (new_text); 1129 type = GNUNET_NAMESTORE_typename_to_number (new_text);
1149 if (UINT32_MAX == type) 1130 if (UINT32_MAX == type)
@@ -1151,69 +1132,33 @@ GNUNET_setup_gns_type_cellrenderercombo_edited_cb (GtkCellRendererCombo *combo,
1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1152 "Invalid or unsupported record type `%s'\n", 1133 "Invalid or unsupported record type `%s'\n",
1153 new_text); 1134 new_text);
1135 show_error_message (_("Unsupported record type"),
1136 new_text);
1154 return; 1137 return;
1155 } 1138 }
1156 /* check if this is a new record */ 1139 /* check if this is a new record */
1157 gtk_tree_model_get_iter_from_string (tm, &it, path); 1140 gtk_tree_model_get_iter_from_string (tm, &it, path);
1158 gtk_tree_model_get (tm, &it, 1141 gtk_tree_model_get (tm, &it,
1159 GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy_row, 1142 GNS_TREESTORE_COL_NAME, &name_str,
1160 GNS_TREESTORE_COL_NAME, &name_str,
1161 GNS_TREESTORE_COL_VAL_AS_STR, &value_str,
1162 -1); 1143 -1);
1163 is_valid = GNUNET_NO; 1144 gtk_tree_store_insert_with_values (ts, &child , &it, -1,
1164 if ( (NULL != value_str) && 1145 GNS_TREESTORE_COL_NAME, name_str,
1165 (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (type, 1146 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
1166 value_str, 1147 GNS_TREESTORE_COL_RECORD_TYPE, type,
1167 &data, 1148 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text,
1168 &data_size)) ) 1149 GNS_TREESTORE_COL_EXP_TIME_AS_STR, EXPIRE_NEVER_STRING,
1169 { 1150 GNS_TREESTORE_COL_EXP_TIME, GNUNET_TIME_UNIT_FOREVER_ABS,
1170 is_valid = GNUNET_YES; 1151 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
1171 GNUNET_free_non_null (data); 1152 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
1172 } 1153 GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE,
1173 if (not_dummy_row) 1154 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, FALSE,
1174 { 1155 -1);
1175 /* Updating an existing record */ 1156 /* select new row and start editing 'value' */
1176 gtk_tree_store_set (ts, &it, 1157 gtk_tree_view_expand_row (tv, gtk_tree_model_get_path (tm, &it), 0);
1177 GNS_TREESTORE_COL_RECORD_TYPE, type, 1158 sel = gtk_tree_view_get_selection (tv);
1178 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text, 1159 gtk_tree_selection_select_iter (sel, &child);
1179 GNS_TREESTORE_COL_VAL_COLOR, (GNUNET_NO == is_valid) ? "red" : NULL, 1160 g_free (name_str);
1180 -1); 1161 edit_selected_row (GNUNET_NO);
1181 }
1182 else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str)))
1183 {
1184 /* Adding a new record */
1185 gtk_tree_store_insert_with_values (ts, &child , &it, -1,
1186 GNS_TREESTORE_COL_NAME, name_str,
1187 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
1188 GNS_TREESTORE_COL_RECORD_TYPE, type,
1189 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text,
1190 GNS_TREESTORE_COL_EXP_TIME_AS_STR, EXPIRE_NEVER_STRING,
1191 GNS_TREESTORE_COL_EXP_TIME, GNUNET_TIME_UNIT_FOREVER_ABS,
1192 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
1193 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
1194 GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE,
1195 GNS_TREESTORE_COL_VAL_COLOR, "red",
1196 -1);
1197 /* select new row and start editing 'value' */
1198 gtk_tree_view_expand_row (tv, gtk_tree_model_get_path(tm, &it), 0);
1199 sel = gtk_tree_view_get_selection (tv);
1200 gtk_tree_selection_select_iter (sel, &child);
1201 value_column = GTK_TREE_VIEW_COLUMN (GNUNET_SETUP_get_object ("GNUNET_setup_gns_value_treeviewcolumn"));
1202 tp = gtk_tree_model_get_path (tm, &child);
1203 gtk_tree_view_set_cursor (tv,
1204 tp,
1205 value_column,
1206 TRUE);
1207 gtk_tree_path_free (tp);
1208 }
1209 else
1210 {
1211 /* type should not have been editable! */
1212 GNUNET_break (0);
1213 }
1214 GNUNET_free_non_null (value_str);
1215 GNUNET_free_non_null (name_str);
1216 check_name_validity_and_commit (&it, NULL);
1217} 1162}
1218 1163
1219 1164
@@ -1345,6 +1290,7 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1345 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR), 1290 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR),
1346 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE, 1291 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
1347 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE, 1292 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
1293 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
1348 -1); 1294 -1);
1349 check_name_validity_and_commit (&it, 1295 check_name_validity_and_commit (&it,
1350 name); 1296 name);
@@ -1357,6 +1303,7 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1357 GNS_TREESTORE_COL_RECORD_TYPE, GNUNET_DNSPARSER_TYPE_A, 1303 GNS_TREESTORE_COL_RECORD_TYPE, GNUNET_DNSPARSER_TYPE_A,
1358 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE, 1304 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
1359 GNS_TREESTORE_COL_IS_RECORD_ROW, FALSE, 1305 GNS_TREESTORE_COL_IS_RECORD_ROW, FALSE,
1306 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, FALSE,
1360 -1); 1307 -1);
1361 } 1308 }
1362 } 1309 }
@@ -1381,19 +1328,6 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1381 1328
1382 check_name_validity_and_commit (&it, name); 1329 check_name_validity_and_commit (&it, name);
1383 } 1330 }
1384
1385 if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (new_text))
1386 {
1387 gtk_tree_store_set (ts, &it,
1388 GNS_TREESTORE_COL_NAME_COLOR, "red",
1389 -1);
1390 }
1391 else
1392 {
1393 gtk_tree_store_set (ts, &it,
1394 GNS_TREESTORE_COL_NAME_COLOR, NULL,
1395 -1);
1396 }
1397} 1331}
1398 1332
1399 1333
@@ -1480,7 +1414,7 @@ void
1480GNUNET_setup_gns_popup_edit_button_activate_cb (GtkWidget *widget, 1414GNUNET_setup_gns_popup_edit_button_activate_cb (GtkWidget *widget,
1481 gpointer user_data) 1415 gpointer user_data)
1482{ 1416{
1483 // FIXME: create dialog to edit_selected_row (); 1417 edit_selected_row (GNUNET_YES);
1484} 1418}
1485 1419
1486 1420
@@ -1864,7 +1798,12 @@ zone_iteration_proc (void *cls,
1864 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox"))); 1798 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox")));
1865 return; 1799 return;
1866 } 1800 }
1867 1801 if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name))
1802 {
1803 GNUNET_break (0);
1804 GNUNET_NAMESTORE_zone_iterator_next (zc_ctx->it);
1805 return;
1806 }
1868 GNUNET_CRYPTO_short_hash_to_enc (&zc_ctx->zone, &shenc); 1807 GNUNET_CRYPTO_short_hash_to_enc (&zc_ctx->zone, &shenc);
1869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1870 "Zone `%s' iteration result `%s', %u records\n", 1809 "Zone `%s' iteration result `%s', %u records\n",
@@ -1879,19 +1818,14 @@ zone_iteration_proc (void *cls,
1879 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE, 1818 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
1880 -1); 1819 -1);
1881 1820
1882 if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name))
1883 {
1884 gtk_tree_store_set (ts, &iter_name,
1885 GNS_TREESTORE_COL_NAME_COLOR, "red",
1886 -1);
1887 }
1888 /* Append elements for records */ 1821 /* Append elements for records */
1889 for (c = 0; c < rd_count; c ++) 1822 for (c = 0; c < rd_count; c ++)
1890 { 1823 {
1891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1892 "Record %u: type %u flags %u expiration %llu data_size %u\n", 1825 "Record %u: type %u flags %u expiration %llu data_size %u\n",
1893 c, rd[c].record_type, rd[c].flags, 1826 c, rd[c].record_type, rd[c].flags,
1894 rd[c].expiration_time, rd[c].data_size); 1827 rd[c].expiration_time,
1828 rd[c].data_size);
1895 1829
1896 /* Set public toggle */ 1830 /* Set public toggle */
1897 public = ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) != GNUNET_NAMESTORE_RF_PRIVATE); 1831 public = ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) != GNUNET_NAMESTORE_RF_PRIVATE);
@@ -1923,7 +1857,7 @@ zone_iteration_proc (void *cls,
1923 if (NULL != GNUNET_NAMESTORE_number_to_typename (rd[c].record_type)) 1857 if (NULL != GNUNET_NAMESTORE_number_to_typename (rd[c].record_type))
1924 type_str = strdup (GNUNET_NAMESTORE_number_to_typename (rd[c].record_type)); 1858 type_str = strdup (GNUNET_NAMESTORE_number_to_typename (rd[c].record_type));
1925 else 1859 else
1926 GNUNET_asprintf(&type_str, "%s", EXPIRE_INVALID_STRING); 1860 GNUNET_asprintf (&type_str, "%s", EXPIRE_INVALID_STRING);
1927 1861
1928 if ( (0 == strcmp (name, ROOT_STR)) && 1862 if ( (0 == strcmp (name, ROOT_STR)) &&
1929 (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type) ) 1863 (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type) )