aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_gtk_namestore_phone.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/plugin_gtk_namestore_phone.c')
-rw-r--r--src/namestore/plugin_gtk_namestore_phone.c83
1 files changed, 75 insertions, 8 deletions
diff --git a/src/namestore/plugin_gtk_namestore_phone.c b/src/namestore/plugin_gtk_namestore_phone.c
index 29815538..33defbf7 100644
--- a/src/namestore/plugin_gtk_namestore_phone.c
+++ b/src/namestore/plugin_gtk_namestore_phone.c
@@ -27,12 +27,31 @@
27#include "gnunet_gtk_namestore_plugin.h" 27#include "gnunet_gtk_namestore_plugin.h"
28 28
29 29
30
31
32/**
33 * The user has edited the PHONE record value. Enable/disable 'save'
34 * button depending on the validity of the value.
35 *
36 * @param entry editing widget
37 * @param user_data the plugin environment
38 */
39void
40GNS_edit_dialog_phone_peer_entry_changed_cb (GtkEditable *entry,
41 gpointer user_data)
42{
43 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *env = user_data;
44
45 env->check_validity (env->cls);
46}
47
48
30/** 49/**
31 * Function that will be called to initialize the builder's 50 * Function that will be called to initialize the builder's
32 * widgets from the existing record (if there is one). 51 * widgets from the existing record (if there is one).
33 * The `n_value` is the existing value of the record as a string. 52 * The `n_value` is the existing value of the record as a string.
34 * 53 *
35 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvirionment *` 54 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
36 * @param n_value the record as a string 55 * @param n_value the record as a string
37 * @param builder the edit dialog's builder 56 * @param builder the edit dialog's builder
38 */ 57 */
@@ -41,7 +60,28 @@ phone_load (void *cls,
41 gchar *n_value, 60 gchar *n_value,
42 GtkBuilder *builder) 61 GtkBuilder *builder)
43{ 62{
44 GNUNET_break (0); 63 const char *minus;
64 unsigned int line;
65
66 if (1 != (sscanf (n_value,
67 "%u-",
68 &line)))
69 {
70 GNUNET_break (0);
71 return;
72 }
73 gtk_spin_button_set_value (GTK_SPIN_BUTTON
74 (gtk_builder_get_object (builder,
75 "edit_dialog_phone_line_spinbutton")),
76 line);
77 if (NULL == (minus = strchr (n_value, '-')))
78 {
79 GNUNET_break (0);
80 return;
81 }
82 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder,
83 "edit_dialog_phone_peer_entry")),
84 minus + 1);
45} 85}
46 86
47 87
@@ -49,7 +89,7 @@ phone_load (void *cls,
49 * Function that will be called to retrieve the final value of the 89 * Function that will be called to retrieve the final value of the
50 * record (in string format) once the dialog is being closed. 90 * record (in string format) once the dialog is being closed.
51 * 91 *
52 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvirionment *` 92 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
53 * @param builder the edit dialog's builder 93 * @param builder the edit dialog's builder
54 * @return record value as a string, as specified in the dialog 94 * @return record value as a string, as specified in the dialog
55 */ 95 */
@@ -57,8 +97,23 @@ static gchar *
57phone_store (void *cls, 97phone_store (void *cls,
58 GtkBuilder *builder) 98 GtkBuilder *builder)
59{ 99{
60 GNUNET_break (0); 100 GtkEntry *entry;
61 return NULL; 101 GtkSpinButton *spin;
102 const gchar *value;
103 unsigned int line;
104 char *ret;
105
106 entry = GTK_ENTRY (gtk_builder_get_object (builder,
107 "edit_dialog_phone_peer_entry"));
108 value = gtk_entry_get_text (entry);
109 spin = GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
110 "edit_dialog_phone_line_spinbutton"));
111 line = gtk_spin_button_get_value (spin);
112 GNUNET_asprintf (&ret,
113 "%u-%s",
114 line,
115 value);
116 return ret;
62} 117}
63 118
64 119
@@ -69,7 +124,7 @@ phone_store (void *cls,
69 * function should highlight fields with invalid inputs for the 124 * function should highlight fields with invalid inputs for the
70 * user. 125 * user.
71 * 126 *
72 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvirionment *` 127 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
73 * @param builder the edit dialog's builder 128 * @param builder the edit dialog's builder
74 * @return #GNUNET_OK if there is a valid record value in the dialog 129 * @return #GNUNET_OK if there is a valid record value in the dialog
75 */ 130 */
@@ -77,7 +132,19 @@ static int
77phone_validate (void *cls, 132phone_validate (void *cls,
78 GtkBuilder *builder) 133 GtkBuilder *builder)
79{ 134{
80 GNUNET_break (0); 135 GtkEditable *entry;
136 const gchar *preedit;
137 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
138
139 entry = GTK_EDITABLE (gtk_builder_get_object (builder,
140 "edit_dialog_phone_peer_entry"));
141 preedit = gtk_editable_get_chars (entry, 0, -1);
142 if ( (NULL == preedit) ||
143 (GNUNET_OK !=
144 GNUNET_CRYPTO_ecdsa_public_key_from_string (preedit,
145 strlen (preedit),
146 &pub)) )
147 return GNUNET_SYSERR;
81 return GNUNET_OK; 148 return GNUNET_OK;
82} 149}
83 150
@@ -91,7 +158,7 @@ phone_validate (void *cls,
91void * 158void *
92libgnunet_plugin_gtk_namestore_phone_init (void *cls) 159libgnunet_plugin_gtk_namestore_phone_init (void *cls)
93{ 160{
94 struct GNUNET_GTK_NAMESTORE_PluginEnvirionment *env = cls; 161 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *env = cls;
95 struct GNUNET_GTK_NAMESTORE_PluginFunctions *plugin; 162 struct GNUNET_GTK_NAMESTORE_PluginFunctions *plugin;
96 163
97 plugin = GNUNET_new (struct GNUNET_GTK_NAMESTORE_PluginFunctions); 164 plugin = GNUNET_new (struct GNUNET_GTK_NAMESTORE_PluginFunctions);