1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/*
This file is part of GNUnet.
Copyright (C) 2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
* @file src/conversation/gnunet-conversation-gtk_get_label.c
* @brief logic to import caller ID into address book
* @author Christian Grothoff
*/
#include "gnunet-conversation-gtk.h"
#include "gnunet-conversation-gtk_egos.h"
#include "gnunet-conversation-gtk_history.h"
#include "gnunet-conversation-gtk_get_label.h"
#include "gnunet-conversation-gtk_import.h"
#include "gnunet-conversation-gtk_log.h"
#include "gnunet-conversation-gtk_phone.h"
#include "gnunet-conversation-gtk_zones.h"
/**
* Queue entry for the 'check exists' operation.
*/
static struct GNUNET_NAMESTORE_QueueEntry *qe;
/**
* What is the value we want to publish in the namestore?
*/
static char *target;
/**
* Called on error communicating with the namestore.
*/
static void
handle_error (void *cls)
{
qe = NULL;
GCG_log (_ ("Error communicating with namestore!\n"));
}
/**
* Process a record that was stored in the namestore.
*
* @param cls closure, NULL
* @param zone private key of the zone; NULL on disconnect
* @param label label of the records; NULL on disconnect
* @param rd_count number of entries in @a rd array, 0 if label was deleted
* @param rd array of records with data to store
*/
static void
handle_existing_records (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const char *label,
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
GtkBuilder *builder = GTK_BUILDER (cls);
GtkWidget *b_add;
qe = NULL;
if (0 != rd_count)
{
GCG_log (_ ("Label `%s' in use\n"), label);
return;
}
b_add = GTK_WIDGET (gtk_builder_get_object (
builder,
"gnunet_conversation_gtk_enter_label_dialog_add_button"));
gtk_widget_set_sensitive (b_add, TRUE);
}
/**
* The user has edited the label; check if the new label
* is valid and available and update the sensitivity of
* the "add" button.
*
* @param editable the entry that changed
* @param user_data our builder
*/
void
gnunet_conversation_gtk_enter_label_entry_changed_cb (GtkEditable *editable,
gpointer user_data)
{
GtkBuilder *builder = GTK_BUILDER (user_data);
GtkEntry *label_entry;
const gchar *label;
GtkWidget *b_add;
struct GNUNET_IDENTITY_Ego *ego;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
const char *tld;
if (NULL != qe)
{
GNUNET_NAMESTORE_cancel (qe);
qe = NULL;
}
label_entry = GTK_ENTRY (
gtk_builder_get_object (builder,
("gnunet_conversation_gtk_enter_label_entry")));
label = gtk_entry_get_text (label_entry);
b_add = GTK_WIDGET (gtk_builder_get_object (
builder,
"gnunet_conversation_gtk_enter_label_dialog_add_button"));
gtk_widget_set_sensitive (b_add, FALSE);
if (GNUNET_OK != GNUNET_DNSPARSER_check_label (label))
{
GCG_log (_ ("Invalid label `%s'\n"), label);
return;
}
ego = GCG_ZONES_get_selected_zone (&tld);
if (NULL == ego)
return;
pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
qe = GNUNET_NAMESTORE_records_lookup (GCG_IMPORT_get_namestore (),
pkey,
label,
&handle_error,
builder,
&handle_existing_records,
builder);
}
/**
* The user has clicked the "add" button, close the dialog and
* complete the "add contact" operation.
*
* @param button the button
* @param user_data our builder
*/
void
gnunet_conversation_gtk_enter_label_dialog_add_button_clicked_cb (
GtkButton *button,
gpointer *user_data)
{
GtkBuilder *builder = GTK_BUILDER (user_data);
GtkWidget *dialog;
const gchar *label;
GtkEntry *label_entry;
label_entry = GTK_ENTRY (
gtk_builder_get_object (builder,
("gnunet_conversation_gtk_enter_label_entry")));
label = gtk_entry_get_text (label_entry);
GSC_add_contact (label, target);
GNUNET_free (target);
target = NULL;
dialog = GTK_WIDGET (
gtk_builder_get_object (builder,
"gnunet_conversation_gtk_enter_label_window"));
gtk_widget_destroy (GTK_WIDGET (dialog));
g_object_unref (G_OBJECT (builder));
}
/**
* The user has clicked the "cancel" button, close the dialog and
* abort the "add contact" operation.
*
* @param button the button
* @param user_data our builder
*/
void
gnunet_conversation_gtk_enter_label_dialog_cancel_button_clicked_cb (
GtkButton *button,
gpointer *user_data)
{
GtkBuilder *builder = GTK_BUILDER (user_data);
GtkWidget *dialog;
dialog = GTK_WIDGET (
gtk_builder_get_object (builder,
"gnunet_conversation_gtk_enter_label_window"));
GNUNET_free (target);
target = NULL;
gtk_widget_destroy (GTK_WIDGET (dialog));
g_object_unref (G_OBJECT (builder));
}
/**
* User closed the window of the enter label dialog.
*
* @param widget the window
* @param event the deletion event
* @param user_data the 'GtkBuilder' of the URI dialog
* @return FALSE (allow destruction)
*/
gboolean
gnunet_conversation_gtk_enter_label_window_delete_event_cb (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
GtkBuilder *builder = GTK_BUILDER (user_data);
g_object_unref (G_OBJECT (builder));
GNUNET_free (target);
target = NULL;
return FALSE;
}
/**
* Obtain the label the user wants to use for a given
* name and (if successful) add the name to the
* address book usnig #GSC_add_contact().
*
* @param name value to publish (corresponds to CNAME or PKEY record)
* @param label suggested label (user can change)
*/
void
GSC_get_label_for_name (const char *name, const char *label)
{
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *toplevel;
GtkEntry *label_entry;
GtkWidget *address_entry;
builder =
GNUNET_GTK_get_new_builder ("gnunet_conversation_gtk_enter_label.glade",
NULL);
if (NULL == builder)
{
GNUNET_break (0);
return;
}
target = GNUNET_strdup (name);
label_entry = GTK_ENTRY (
gtk_builder_get_object (builder,
("gnunet_conversation_gtk_enter_label_entry")));
gtk_entry_set_text (label_entry, label);
dialog = GTK_WIDGET (
gtk_builder_get_object (builder,
"gnunet_conversation_gtk_enter_label_window"));
/* just pick ANY widget from the main window here... */
address_entry = GTK_WIDGET (
GCG_get_main_window_object ("gnunet_conversation_gtk_address_entry"));
toplevel = gtk_widget_get_toplevel (address_entry);
if (GTK_IS_WINDOW (toplevel))
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
gtk_widget_show (dialog);
}
/**
* User clicked the '> contact' button to move the selected
* caller's information into our address book.
*
* @param button the button
* @param user_data main loop context (unused)
*/
void
gnunet_conversation_gtk_add_contact_button_clicked_cb (GtkButton *button,
gpointer *user_data)
{
GtkEntry *address_entry;
address_entry = GTK_ENTRY (
GCG_get_main_window_object ("gnunet_conversation_gtk_address_entry"));
GSC_get_label_for_name (gtk_entry_get_text (address_entry), "");
}
/* end of gnunet-conversation-gtk_use_current.c */
|