aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-03 16:08:26 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-03 16:08:26 +0000
commit1d0ddd9d3669dc7f50460b8690ea4f82551d5c85 (patch)
treee11b3cf646dbcecd1de8963d6eb5d11907039b07
parentf832c35b637da1e1652bafcf5f743e37091299ce (diff)
downloadgnunet-gtk-1d0ddd9d3669dc7f50460b8690ea4f82551d5c85.tar.gz
gnunet-gtk-1d0ddd9d3669dc7f50460b8690ea4f82551d5c85.zip
-towards A dialog
-rw-r--r--contrib/gnunet_setup_gns_edit_a.glade8
-rw-r--r--src/setup/gnunet-setup-gns-edit.c143
-rw-r--r--src/setup/gnunet-setup-gns-edit.h5
-rw-r--r--src/setup/gnunet-setup-gns.c29
4 files changed, 159 insertions, 26 deletions
diff --git a/contrib/gnunet_setup_gns_edit_a.glade b/contrib/gnunet_setup_gns_edit_a.glade
index a72704c2..0e41153d 100644
--- a/contrib/gnunet_setup_gns_edit_a.glade
+++ b/contrib/gnunet_setup_gns_edit_a.glade
@@ -20,7 +20,11 @@
20 <object class="GtkDialog" id="edit_a_dialog"> 20 <object class="GtkDialog" id="edit_a_dialog">
21 <property name="can_focus">False</property> 21 <property name="can_focus">False</property>
22 <property name="border_width">5</property> 22 <property name="border_width">5</property>
23 <property name="modal">True</property>
24 <property name="window_position">center-on-parent</property>
25 <property name="destroy_with_parent">True</property>
23 <property name="type_hint">dialog</property> 26 <property name="type_hint">dialog</property>
27 <signal name="response" handler="GNS_edit_a_dialog_response_cb" swapped="no"/>
24 <child internal-child="vbox"> 28 <child internal-child="vbox">
25 <object class="GtkVBox" id="edit_dialog_vbox"> 29 <object class="GtkVBox" id="edit_dialog_vbox">
26 <property name="visible">True</property> 30 <property name="visible">True</property>
@@ -67,6 +71,8 @@
67 <property name="use_action_appearance">False</property> 71 <property name="use_action_appearance">False</property>
68 <property name="visible">True</property> 72 <property name="visible">True</property>
69 <property name="can_focus">True</property> 73 <property name="can_focus">True</property>
74 <property name="can_default">True</property>
75 <property name="has_default">True</property>
70 <property name="receives_default">True</property> 76 <property name="receives_default">True</property>
71 <property name="tooltip_text" translatable="yes">Store the updated record in the database. If the record is public, GNUnet will begin to publish the record to the world, limiting your ability to change it later (based on the selected expiration values).</property> 77 <property name="tooltip_text" translatable="yes">Store the updated record in the database. If the record is public, GNUnet will begin to publish the record to the world, limiting your ability to change it later (based on the selected expiration values).</property>
72 <property name="use_stock">True</property> 78 <property name="use_stock">True</property>
@@ -185,6 +191,7 @@
185 <object class="GtkEntry" id="edit_dialog_a_entry"> 191 <object class="GtkEntry" id="edit_dialog_a_entry">
186 <property name="visible">True</property> 192 <property name="visible">True</property>
187 <property name="can_focus">True</property> 193 <property name="can_focus">True</property>
194 <property name="has_focus">True</property>
188 <property name="tooltip_text" translatable="yes">Enter the IPv4 address for the A record here. The format is the usual dotted-decimal format (i.e. 127.0.0.1).</property> 195 <property name="tooltip_text" translatable="yes">Enter the IPv4 address for the A record here. The format is the usual dotted-decimal format (i.e. 127.0.0.1).</property>
189 <property name="max_length">15</property> 196 <property name="max_length">15</property>
190 <property name="invisible_char">●</property> 197 <property name="invisible_char">●</property>
@@ -192,6 +199,7 @@
192 <property name="secondary_icon_activatable">False</property> 199 <property name="secondary_icon_activatable">False</property>
193 <property name="primary_icon_sensitive">True</property> 200 <property name="primary_icon_sensitive">True</property>
194 <property name="secondary_icon_sensitive">True</property> 201 <property name="secondary_icon_sensitive">True</property>
202 <signal name="changed" handler="GNS_edit_dialog_a_entry_changed_cb" swapped="no"/>
195 </object> 203 </object>
196 <packing> 204 <packing>
197 <property name="expand">False</property> 205 <property name="expand">False</property>
diff --git a/src/setup/gnunet-setup-gns-edit.c b/src/setup/gnunet-setup-gns-edit.c
index 3286f7b4..f4e6de65 100644
--- a/src/setup/gnunet-setup-gns-edit.c
+++ b/src/setup/gnunet-setup-gns-edit.c
@@ -26,6 +26,57 @@
26 26
27 27
28/** 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
51/**
52 * Disable 'save' button, dialog state is not acceptable.
53 *
54 * @param edc dialog to modify
55 */
56static void
57edit_dialog_disable_save (struct EditDialogContext *edc)
58{
59 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (edc->builder,
60 "edit_dialog_save_button")),
61 FALSE);
62}
63
64
65/**
66 * Enable 'save' button, dialog state is acceptable.
67 *
68 * @param edc dialog to modify
69 */
70static void
71edit_dialog_enable_save (struct EditDialogContext *edc)
72{
73 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (edc->builder,
74 "edit_dialog_save_button")),
75 TRUE);
76}
77
78
79/**
29 * Initialize widgets of the edit dialog that are the same regardless of 80 * Initialize widgets of the edit dialog that are the same regardless of
30 * the type of the record. 81 * the type of the record.
31 * 82 *
@@ -39,9 +90,7 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
39 { 90 {
40 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, 91 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
41 "edit_dialog_delete_button"))); 92 "edit_dialog_delete_button")));
42 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (edc->builder, 93 edit_dialog_disable_save (edc);
43 "edit_dialog_save_button")),
44 FALSE);
45 } 94 }
46 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, 95 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder,
47 "edit_dialog_name_entry")), 96 "edit_dialog_name_entry")),
@@ -54,6 +103,7 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
54 edc->n_is_shadow); 103 edc->n_is_shadow);
55 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == edc->n_exp_time) 104 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == edc->n_exp_time)
56 { 105 {
106 fprintf (stderr, "forever\n");
57 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, 107 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder,
58 "edit_dialog_expiration_never_radiobutton")), 108 "edit_dialog_expiration_never_radiobutton")),
59 TRUE); 109 TRUE);
@@ -70,16 +120,22 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
70 { 120 {
71 struct GNUNET_TIME_Relative rt; 121 struct GNUNET_TIME_Relative rt;
72 122
123 fprintf (stderr, "relative\n");
73 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, 124 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder,
74 "edit_dialog_expiration_relative_radiobutton")), 125 "edit_dialog_expiration_relative_radiobutton")),
75 TRUE); 126 TRUE);
76 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, 127 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
77 "edit_dialog_expiration_relative_combobox"))); 128 "edit_dialog_expiration_absolute_calendar")));
129 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
130 "edit_dialog_expiration_absolute_hbox")));
78 rt.rel_value = edc->n_exp_time; 131 rt.rel_value = edc->n_exp_time;
79 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, 132#if 0
80 "edit_dialog_expiration_relative_combobox")), 133 /* FIXME: gtk_combo_box_set_text does not exist, we need to
81 GNUNET_STRINGS_relative_time_to_string (rt, GNUNET_NO)); 134 update the model and then select the respective element... */
82 135 gtk_combo_box_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder,
136 "edit_dialog_expiration_relative_combobox")),
137 GNUNET_STRINGS_relative_time_to_string (rt, GNUNET_NO));
138#endif
83 } 139 }
84 else 140 else
85 { 141 {
@@ -88,13 +144,13 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
88 struct tm *ymd; 144 struct tm *ymd;
89 GtkCalendar *cal; 145 GtkCalendar *cal;
90 146
147 fprintf (stderr, "absolute\n");
91 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, 148 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder,
92 "edit_dialog_expiration_absolute_radiobutton")), 149 "edit_dialog_expiration_absolute_radiobutton")),
93 TRUE); 150 TRUE);
151
94 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, 152 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
95 "edit_dialog_expiration_absolute_calendar"))); 153 "edit_dialog_expiration_relative_combobox")));
96 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder,
97 "edit_dialog_expiration_absolute_hbox")));
98 at.abs_value = edc->n_exp_time; 154 at.abs_value = edc->n_exp_time;
99 tp = (time_t) (at.abs_value / 1000LL); /* convert to seconds */ 155 tp = (time_t) (at.abs_value / 1000LL); /* convert to seconds */
100 ymd = gmtime (&tp); 156 ymd = gmtime (&tp);
@@ -120,6 +176,51 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
120 176
121 177
122/** 178/**
179 * Run the edit dialog. Performs all of the common initialization
180 * steps to run an edit dialog for records.
181 *
182 * @param edc editing context
183 */
184static void
185run_edit_dialog (struct EditDialogContext *edc)
186{
187 edit_dialog_setup_common_elements (edc);
188 edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder,
189 "edit_a_dialog"));
190 gtk_dialog_set_default_response (edc->dialog,
191 GTK_RESPONSE_OK);
192 gtk_window_present (GTK_WINDOW (edc->dialog));
193}
194
195
196/* ************************ A records *********************** */
197
198/**
199 * The user has edited the A record value. Enable/disable 'save'
200 * button depending on the validity of the value.
201 *
202 * @param entry editing widget
203 * @param preedit new value
204 * @param user_data the 'struct EditDialogContext' of the dialog
205 */
206void
207GNS_edit_dialog_a_entry_changed_cb (GtkEditable *entry,
208 gpointer user_data)
209{
210 struct EditDialogContext *edc = user_data;
211 const gchar *preedit;
212 struct in_addr v4;
213
214 preedit = gtk_editable_get_chars (entry, 0, -1);
215 if ( (NULL != preedit) &&
216 (1 == inet_pton (AF_INET, preedit, &v4)) )
217 edit_dialog_enable_save (edc);
218 else
219 edit_dialog_disable_save (edc);
220}
221
222
223/**
123 * Run an GNS Edit dialog for an 'A' Record. 224 * Run an GNS Edit dialog for an 'A' Record.
124 * 225 *
125 * @param cont continuation to call when done 226 * @param cont continuation to call when done
@@ -128,8 +229,6 @@ edit_dialog_setup_common_elements (struct EditDialogContext *edc)
128void 229void
129GNS_edit_dialog_a (struct EditDialogContext *edc) 230GNS_edit_dialog_a (struct EditDialogContext *edc)
130{ 231{
131 GtkDialog *dialog;
132
133 edc->builder = GNUNET_GTK_get_new_builder ("gnunet_setup_gns_edit_a.glade", 232 edc->builder = GNUNET_GTK_get_new_builder ("gnunet_setup_gns_edit_a.glade",
134 edc); 233 edc);
135 if (NULL == edc->builder) 234 if (NULL == edc->builder)
@@ -138,15 +237,15 @@ GNS_edit_dialog_a (struct EditDialogContext *edc)
138 edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ 237 edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */
139 return; 238 return;
140 } 239 }
141 edit_dialog_setup_common_elements (edc); 240 if (GNUNET_YES ==
142 dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, 241 edc->old_record_in_namestore)
143 "edit_a_dialog")); 242 {
144 gtk_dialog_set_default_response (GTK_DIALOG (dialog), 243 /* set A record */
145 GTK_RESPONSE_OK); 244 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder,
146 gtk_window_present (GTK_WINDOW (dialog)); 245 "edit_dialog_a_entry")),
147 246 edc->n_value);
148 GNUNET_break (0); /* not implemented */ 247 }
149 edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ 248 run_edit_dialog (edc);
150} 249}
151 250
152 251
diff --git a/src/setup/gnunet-setup-gns-edit.h b/src/setup/gnunet-setup-gns-edit.h
index d2f3598f..25ac2551 100644
--- a/src/setup/gnunet-setup-gns-edit.h
+++ b/src/setup/gnunet-setup-gns-edit.h
@@ -77,6 +77,11 @@ struct EditDialogContext
77 GtkBuilder *builder; 77 GtkBuilder *builder;
78 78
79 /** 79 /**
80 * Main dialog window.
81 */
82 GtkDialog *dialog;
83
84 /**
80 * Old name of the record (for deletion). 85 * Old name of the record (for deletion).
81 */ 86 */
82 gchar *n_name; 87 gchar *n_name;
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index ebd87389..e25f6609 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -1074,6 +1074,7 @@ remove_records_by_path (const gchar *path)
1074 (void**)&rd.data, &rd.data_size); 1074 (void**)&rd.data, &rd.data_size);
1075 1075
1076 rc = GNUNET_malloc (sizeof (struct RemoveContext)); 1076 rc = GNUNET_malloc (sizeof (struct RemoveContext));
1077 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
1077 rc->path = strdup (path); 1078 rc->path = strdup (path);
1078 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd, 1079 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd,
1079 &update_treemodel_after_remove, rc); 1080 &update_treemodel_after_remove, rc);
@@ -1085,6 +1086,7 @@ remove_records_by_path (const gchar *path)
1085 { 1086 {
1086 /* Removing the whole name record */ 1087 /* Removing the whole name record */
1087 rc = GNUNET_malloc(sizeof (struct RemoveContext)); 1088 rc = GNUNET_malloc(sizeof (struct RemoveContext));
1089 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
1088 rc->path = strdup (path); 1090 rc->path = strdup (path);
1089 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, NULL, 1091 rc->qe = GNUNET_NAMESTORE_record_remove (namestore, pkey, name, NULL,
1090 &update_treemodel_after_remove, rc); 1092 &update_treemodel_after_remove, rc);
@@ -1256,6 +1258,8 @@ GNUNET_setup_gns_type_cellrenderercombo_edited_cb (GtkCellRendererCombo *combo,
1256 guint type; 1258 guint type;
1257 char *name_str; 1259 char *name_str;
1258 1260
1261 if (0 == strcmp (new_text, _(NEW_RECORD_STR)))
1262 return; /* no record type was selected */
1259 type = GNUNET_NAMESTORE_typename_to_number (new_text); 1263 type = GNUNET_NAMESTORE_typename_to_number (new_text);
1260 if (UINT32_MAX == type) 1264 if (UINT32_MAX == type)
1261 { 1265 {
@@ -1395,8 +1399,9 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1395 path, new_text); 1399 path, new_text);
1396 if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, ""))) 1400 if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, "")))
1397 return; 1401 return;
1398 if (GNUNET_OK != 1402 if ( (GNUNET_OK !=
1399 GNUNET_DNSPARSER_check_label (new_text)) 1403 GNUNET_DNSPARSER_check_label (new_text)) &&
1404 (0 != strcmp (new_text, ROOT_STR)) )
1400 { 1405 {
1401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1406 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1402 _("Name `%s' invalid for GADS/DNS (too long for a DNS label?)\n"), 1407 _("Name `%s' invalid for GADS/DNS (too long for a DNS label?)\n"),
@@ -1473,6 +1478,7 @@ create_popup_menu ()
1473 GtkTreeIter it; 1478 GtkTreeIter it;
1474 GtkMenu *popup; 1479 GtkMenu *popup;
1475 GtkTreeSelection *sel; 1480 GtkTreeSelection *sel;
1481 gboolean name_vis;
1476 1482
1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1478 "Considering creating popup menu...\n"); 1484 "Considering creating popup menu...\n");
@@ -1483,7 +1489,16 @@ create_popup_menu ()
1483 "No row selected\n"); 1489 "No row selected\n");
1484 return FALSE; 1490 return FALSE;
1485 } 1491 }
1486 popup = GTK_MENU (GNUNET_SETUP_get_object ("GNUNET_setup_gns_delete_popup_menu")); 1492 gtk_tree_model_get (tm, &it,
1493 GNS_TREESTORE_COL_NAME_IS_VISIBLE, &name_vis,
1494 -1);
1495 if (name_vis)
1496 {
1497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1498 "Selected row is not a record row\n");
1499 return FALSE;
1500 }
1501 popup = GTK_MENU (GNUNET_SETUP_get_object ("GNUNET_setup_gns_edit_popup_menu"));
1487 gtk_widget_show_all (GTK_WIDGET (popup)); 1502 gtk_widget_show_all (GTK_WIDGET (popup));
1488 gtk_menu_popup (popup, NULL, NULL, NULL, NULL, 0, 0); 1503 gtk_menu_popup (popup, NULL, NULL, NULL, NULL, 0, 0);
1489 return TRUE; 1504 return TRUE;
@@ -1928,9 +1943,13 @@ zone_iteration_proc (void *cls,
1928 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox"))); 1943 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox")));
1929 return; 1944 return;
1930 } 1945 }
1931 if (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) 1946 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) &&
1947 (0 != strcmp (name, ROOT_STR)) )
1932 { 1948 {
1933 GNUNET_break (0); 1949 GNUNET_break (0);
1950 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1951 _("Got invalid record name `%s' from namestore\n"),
1952 name);
1934 GNUNET_NAMESTORE_zone_iterator_next (zc_ctx->it); 1953 GNUNET_NAMESTORE_zone_iterator_next (zc_ctx->it);
1935 return; 1954 return;
1936 } 1955 }
@@ -1946,6 +1965,7 @@ zone_iteration_proc (void *cls,
1946 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR), 1965 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, _(NEW_RECORD_STR),
1947 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE, 1966 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
1948 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE, 1967 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
1968 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
1949 -1); 1969 -1);
1950 1970
1951 /* Append elements for records */ 1971 /* Append elements for records */
@@ -2069,6 +2089,7 @@ zone_key_loaded_callback (void *cls,
2069 GNS_TREESTORE_COL_RECORD_TYPE, GNUNET_DNSPARSER_TYPE_A, 2089 GNS_TREESTORE_COL_RECORD_TYPE, GNUNET_DNSPARSER_TYPE_A,
2070 GNS_TREESTORE_COL_IS_RECORD_ROW, FALSE, 2090 GNS_TREESTORE_COL_IS_RECORD_ROW, FALSE,
2071 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE, 2091 GNS_TREESTORE_COL_NOT_DUMMY_ROW, FALSE,
2092 GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
2072 -1); 2093 -1);
2073 /* Load zone from namestore! */ 2094 /* Load zone from namestore! */
2074 zc_ctx->zone = zone; 2095 zc_ctx->zone = zone;