aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-03 19:02:19 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-03 19:02:19 +0000
commit90255b34e8d2a10e4c52288522dac014eac31c82 (patch)
treeda636a8899f167cd1cdd95c152b592eb6d08bfa0
parenta4360f3e9705cf5b6484de20b5db713c1a0e4dd7 (diff)
downloadgnunet-gtk-90255b34e8d2a10e4c52288522dac014eac31c82.tar.gz
gnunet-gtk-90255b34e8d2a10e4c52288522dac014eac31c82.zip
-implementing more of the A-dialog
-rw-r--r--src/setup/gnunet-setup-gns-edit.c155
-rw-r--r--src/setup/gnunet-setup-gns-edit.h13
-rw-r--r--src/setup/gnunet-setup-gns.c16
3 files changed, 121 insertions, 63 deletions
diff --git a/src/setup/gnunet-setup-gns-edit.c b/src/setup/gnunet-setup-gns-edit.c
index 7dc8e41e..3d38c756 100644
--- a/src/setup/gnunet-setup-gns-edit.c
+++ b/src/setup/gnunet-setup-gns-edit.c
@@ -23,30 +23,7 @@
23 * @brief editing dialogs for GNS records 23 * @brief editing dialogs for GNS records
24 */ 24 */
25#include "gnunet-setup-gns-edit.h" 25#include "gnunet-setup-gns-edit.h"
26 26#include <gnunet/gnunet_gns_service.h>
27
28/**
29 * Editing dialog was closed, get the data and call the
30 * continuation.
31 *
32 * @param dialog editing dialog
33 * @param user_data the 'struct EditDialogContext'
34 */
35void
36GNS_edit_a_dialog_response_cb (GtkDialog *dialog,
37 gint response_id,
38 gpointer user_data)
39{
40 struct EditDialogContext *edc = user_data;
41
42 fprintf (stderr, "response CB %d!\n", response_id);
43 /* FIXME: resync dialog elements back into 'edc'! */
44 gtk_widget_destroy (GTK_WIDGET (edc->dialog));
45 g_object_unref (edc->builder);
46 edc->builder = NULL;
47 edc->cont (edc, response_id);
48}
49
50 27
51/** 28/**
52 * Disable 'save' button, dialog state is not acceptable. 29 * Disable 'save' button, dialog state is not acceptable.
@@ -77,6 +54,33 @@ edit_dialog_enable_save (struct EditDialogContext *edc)
77 54
78 55
79/** 56/**
57 * Check that the common elements of the edit dialog are valid;
58 * if so, call 'edit_dialog_enable_save', otherwise 'edit_dialog_disable_save'.
59 *
60 * @param edc edit dialog to check
61 */
62static void
63edit_dialog_check_save (struct EditDialogContext *edc)
64{
65 GtkEditable *entry;
66 const gchar *name;
67
68 /* check name */
69 entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder,
70 "edit_dialog_name_entry"));
71 name = gtk_editable_get_chars (entry, 0, -1);
72 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) &&
73 (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR)) )
74 {
75 edit_dialog_disable_save (edc);
76 return;
77 }
78 /* any other checks should go here */
79 edit_dialog_enable_save (edc);
80}
81
82
83/**
80 * The user has edited the A record value. Enable/disable 'save' 84 * The user has edited the A record value. Enable/disable 'save'
81 * button depending on the validity of the value. 85 * button depending on the validity of the value.
82 * 86 *
@@ -89,19 +93,8 @@ GNS_edit_dialog_name_entry_changed_cb (GtkEditable *entry,
89 gpointer user_data) 93 gpointer user_data)
90{ 94{
91 struct EditDialogContext *edc = user_data; 95 struct EditDialogContext *edc = user_data;
92 const gchar *preedit;
93 struct in_addr v4;
94 96
95 preedit = gtk_editable_get_chars (entry, 0, -1); 97 edc->validator (edc);
96#if 0
97 /* FIXME: need a way to check if _rest_ of the dialog is
98 also consistent (like the _value_!) */
99 if (1)
100 edit_dialog_enable_save (edc);
101 else
102 edit_dialog_disable_save (edc);
103#endif
104 GNUNET_break (0);
105} 98}
106 99
107 100
@@ -116,7 +109,7 @@ GNS_edit_dialog_expiration_relative_combobox_changed_cb (GtkComboBox *widget,
116 gpointer user_data) 109 gpointer user_data)
117{ 110{
118 struct EditDialogContext *edc = user_data; 111 struct EditDialogContext *edc = user_data;
119 112
120 /* not sure if we need to do anything here */ 113 /* not sure if we need to do anything here */
121 // FIXME 114 // FIXME
122 GNUNET_break (0); 115 GNUNET_break (0);
@@ -153,8 +146,12 @@ GNS_edit_dialog_expiration_relative_radiobutton_toggled_cb (GtkToggleButton *but
153{ 146{
154 struct EditDialogContext *edc = user_data; 147 struct EditDialogContext *edc = user_data;
155 148
156 // FIXME 149 if (gtk_toggle_button_get_active (button))
157 GNUNET_break (0); 150 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (edc->builder,
151 "edit_dialog_expiration_relative_combobox")));
152 else
153 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
154 "edit_dialog_expiration_relative_combobox")));
158} 155}
159 156
160 157
@@ -168,10 +165,7 @@ void
168GNS_edit_dialog_expiration_forever_radiobutton_toggled_cb (GtkToggleButton *button, 165GNS_edit_dialog_expiration_forever_radiobutton_toggled_cb (GtkToggleButton *button,
169 gpointer user_data) 166 gpointer user_data)
170{ 167{
171 struct EditDialogContext *edc = user_data; 168 /* nothing to do */
172
173 // FIXME
174 GNUNET_break (0);
175} 169}
176 170
177 171
@@ -187,8 +181,20 @@ GNS_edit_dialog_expiration_absolute_radiobutton_toggled_cb (GtkToggleButton *but
187{ 181{
188 struct EditDialogContext *edc = user_data; 182 struct EditDialogContext *edc = user_data;
189 183
190 // FIXME 184 if (gtk_toggle_button_get_active (button))
191 GNUNET_break (0); 185 {
186 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (edc->builder,
187 "edit_dialog_expiration_absolute_calendar")));
188 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (edc->builder,
189 "edit_dialog_expiration_absolute_hbox")));
190 }
191 else
192 {
193 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
194 "edit_dialog_expiration_absolute_calendar")));
195 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
196 "edit_dialog_expiration_absolute_hbox")));
197 }
192} 198}
193 199
194 200
@@ -312,6 +318,55 @@ run_edit_dialog (struct EditDialogContext *edc)
312/* ************************ A records *********************** */ 318/* ************************ A records *********************** */
313 319
314/** 320/**
321 * Check validity of the value in the edit dialog for A-records.
322 * Then call the shared validity check if the result is OK.
323 *
324 * @param edc edit dialog context
325 */
326static void
327edit_dialog_a_validity_check (struct EditDialogContext *edc)
328{
329 GtkEditable *entry;
330 const gchar *preedit;
331 struct in_addr v4;
332
333 entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder,
334 "edit_dialog_a_entry")),
335 preedit = gtk_editable_get_chars (entry, 0, -1);
336 if ( (NULL == preedit) ||
337 (1 != inet_pton (AF_INET, preedit, &v4)) )
338 {
339 edit_dialog_disable_save (edc);
340 return;
341 }
342 edit_dialog_check_save (edc);
343}
344
345
346/**
347 * Editing dialog was closed, get the data and call the
348 * continuation.
349 *
350 * @param dialog editing dialog
351 * @param user_data the 'struct EditDialogContext'
352 */
353void
354GNS_edit_a_dialog_response_cb (GtkDialog *dialog,
355 gint response_id,
356 gpointer user_data)
357{
358 struct EditDialogContext *edc = user_data;
359
360 fprintf (stderr, "response CB %d!\n", response_id);
361 /* FIXME: resync dialog elements back into 'edc'! */
362 gtk_widget_destroy (GTK_WIDGET (edc->dialog));
363 g_object_unref (edc->builder);
364 edc->builder = NULL;
365 edc->cont (edc, response_id);
366}
367
368
369/**
315 * The user has edited the A record value. Enable/disable 'save' 370 * The user has edited the A record value. Enable/disable 'save'
316 * button depending on the validity of the value. 371 * button depending on the validity of the value.
317 * 372 *
@@ -324,15 +379,8 @@ GNS_edit_dialog_a_entry_changed_cb (GtkEditable *entry,
324 gpointer user_data) 379 gpointer user_data)
325{ 380{
326 struct EditDialogContext *edc = user_data; 381 struct EditDialogContext *edc = user_data;
327 const gchar *preedit;
328 struct in_addr v4;
329 382
330 preedit = gtk_editable_get_chars (entry, 0, -1); 383 edit_dialog_a_validity_check (edc);
331 if ( (NULL != preedit) &&
332 (1 == inet_pton (AF_INET, preedit, &v4)) )
333 edit_dialog_enable_save (edc);
334 else
335 edit_dialog_disable_save (edc);
336} 384}
337 385
338 386
@@ -361,6 +409,7 @@ GNS_edit_dialog_a (struct EditDialogContext *edc)
361 "edit_dialog_a_entry")), 409 "edit_dialog_a_entry")),
362 edc->n_value); 410 edc->n_value);
363 } 411 }
412 edc->validator = &edit_dialog_a_validity_check;
364 run_edit_dialog (edc); 413 run_edit_dialog (edc);
365} 414}
366 415
diff --git a/src/setup/gnunet-setup-gns-edit.h b/src/setup/gnunet-setup-gns-edit.h
index 25ac2551..2386553c 100644
--- a/src/setup/gnunet-setup-gns-edit.h
+++ b/src/setup/gnunet-setup-gns-edit.h
@@ -49,6 +49,13 @@ typedef void (*GNS_EditContinuation)(struct EditDialogContext *edc,
49 GtkResponseType ret); 49 GtkResponseType ret);
50 50
51 51
52/**
53 * Signature of a dialog-specific validation function to validate the
54 * value. Should either call 'edit_dialog_disable_save' if the value
55 * is invalid, or 'edit_dialog_check_save' if the value is valid.
56 */
57typedef void (*GNS_EditValidator)(struct EditDialogContext *edc);
58
52 59
53/** 60/**
54 * Context for edit operations. 61 * Context for edit operations.
@@ -72,6 +79,12 @@ struct EditDialogContext
72 GNS_EditContinuation cont; 79 GNS_EditContinuation cont;
73 80
74 /** 81 /**
82 * Function to call to validate the state of the dialog and
83 * ultimately update the 'save' button sensitivity.
84 */
85 GNS_EditValidator validator;
86
87 /**
75 * Builder for the dialog (internal to gnunet-setup-gns-edit.c). 88 * Builder for the dialog (internal to gnunet-setup-gns-edit.c).
76 */ 89 */
77 GtkBuilder *builder; 90 GtkBuilder *builder;
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index e25f6609..9b7115ad 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -26,6 +26,7 @@
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-setup-gns-edit.h"
29#include <gnunet/gnunet_gns_service.h>
29#include <gnunet/gnunet_namestore_service.h> 30#include <gnunet/gnunet_namestore_service.h>
30#include <gnunet/gnunet_dnsparser_lib.h> 31#include <gnunet/gnunet_dnsparser_lib.h>
31 32
@@ -42,11 +43,6 @@
42#define NEW_RECORD_STR gettext_noop ("<new record>") 43#define NEW_RECORD_STR gettext_noop ("<new record>")
43 44
44/** 45/**
45 * Text we use for 'our own zone'. FIXME: define as constant in GNS?
46 */
47#define ROOT_STR "+"
48
49/**
50 * Text we use for the expiration to mean 'never expires'. 46 * Text we use for the expiration to mean 'never expires'.
51 */ 47 */
52#define EXPIRE_NEVER_STRING gettext_noop ("never") 48#define EXPIRE_NEVER_STRING gettext_noop ("never")
@@ -828,7 +824,7 @@ check_name_validity_and_commit (GtkTreeIter *it,
828 g_free (name); 824 g_free (name);
829 return; 825 return;
830 } 826 }
831 if ( (0 == strcmp (name, ROOT_STR)) && 827 if ( (0 == strcmp (name, GNUNET_GNS_MASTERZONE_STR)) &&
832 (0 == strcmp (current_zone_option, "ZONEKEY")) ) 828 (0 == strcmp (current_zone_option, "ZONEKEY")) )
833 { 829 {
834 /* We have to append PSEU RECORD, this is the 'master' zone */ 830 /* We have to append PSEU RECORD, this is the 'master' zone */
@@ -1082,7 +1078,7 @@ remove_records_by_path (const gchar *path)
1082 g_free (n_name); 1078 g_free (n_name);
1083 g_free (n_value); 1079 g_free (n_value);
1084 } 1080 }
1085 else if (0 != strcmp (name, ROOT_STR)) 1081 else if (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR))
1086 { 1082 {
1087 /* Removing the whole name record */ 1083 /* Removing the whole name record */
1088 rc = GNUNET_malloc(sizeof (struct RemoveContext)); 1084 rc = GNUNET_malloc(sizeof (struct RemoveContext));
@@ -1401,7 +1397,7 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1401 return; 1397 return;
1402 if ( (GNUNET_OK != 1398 if ( (GNUNET_OK !=
1403 GNUNET_DNSPARSER_check_label (new_text)) && 1399 GNUNET_DNSPARSER_check_label (new_text)) &&
1404 (0 != strcmp (new_text, ROOT_STR)) ) 1400 (0 != strcmp (new_text, GNUNET_GNS_MASTERZONE_STR)) )
1405 { 1401 {
1406 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1402 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1407 _("Name `%s' invalid for GADS/DNS (too long for a DNS label?)\n"), 1403 _("Name `%s' invalid for GADS/DNS (too long for a DNS label?)\n"),
@@ -1944,7 +1940,7 @@ zone_iteration_proc (void *cls,
1944 return; 1940 return;
1945 } 1941 }
1946 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) && 1942 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) &&
1947 (0 != strcmp (name, ROOT_STR)) ) 1943 (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR)) )
1948 { 1944 {
1949 GNUNET_break (0); 1945 GNUNET_break (0);
1950 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2009,7 +2005,7 @@ zone_iteration_proc (void *cls,
2009 else 2005 else
2010 GNUNET_asprintf (&type_str, "%s", EXPIRE_INVALID_STRING); 2006 GNUNET_asprintf (&type_str, "%s", EXPIRE_INVALID_STRING);
2011 2007
2012 if ( (0 == strcmp (name, ROOT_STR)) && 2008 if ( (0 == strcmp (name, GNUNET_GNS_MASTERZONE_STR)) &&
2013 (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type) ) 2009 (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type) )
2014 { 2010 {
2015 pseu_entry = GTK_ENTRY((GNUNET_SETUP_get_object ("GNUNET_setup_gns_pseu_entry"))); 2011 pseu_entry = GTK_ENTRY((GNUNET_SETUP_get_object ("GNUNET_setup_gns_pseu_entry")));