aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-04 13:10:59 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-04 13:10:59 +0000
commite800f2d971cbadf793571a82c820f6776cc623e4 (patch)
tree7c58b8020159571db8e08905772a587910470938 /src
parent07d01a27d110ccccd94b7b005b7fd7067bab745f (diff)
downloadgnunet-gtk-e800f2d971cbadf793571a82c820f6776cc623e4.tar.gz
gnunet-gtk-e800f2d971cbadf793571a82c820f6776cc623e4.zip
-towards implementing paste button
Diffstat (limited to 'src')
-rw-r--r--src/conversation/gnunet-conversation-gtk_contacts.c69
-rw-r--r--src/conversation/gnunet-conversation-gtk_use_current.c66
2 files changed, 122 insertions, 13 deletions
diff --git a/src/conversation/gnunet-conversation-gtk_contacts.c b/src/conversation/gnunet-conversation-gtk_contacts.c
index 531d5256..78fb96e3 100644
--- a/src/conversation/gnunet-conversation-gtk_contacts.c
+++ b/src/conversation/gnunet-conversation-gtk_contacts.c
@@ -28,6 +28,7 @@
28 */ 28 */
29#include "gnunet-conversation-gtk.h" 29#include "gnunet-conversation-gtk.h"
30#include "gnunet-conversation-gtk_contacts.h" 30#include "gnunet-conversation-gtk_contacts.h"
31#include "gnunet-conversation-gtk_get_label.h"
31#include "gnunet-conversation-gtk_phone.h" 32#include "gnunet-conversation-gtk_phone.h"
32#include "gnunet-conversation-gtk_zones.h" 33#include "gnunet-conversation-gtk_zones.h"
33 34
@@ -276,6 +277,66 @@ gnunet_conversation_gtk_contacts_zone_combobox_changed_cb (GtkComboBox *widget,
276 277
277 278
278/** 279/**
280 * User clicked the "paste" button. Handle data from the clipboard,
281 * if it is a "gnunet://gns/"-URI, import it into our current zone /
282 * address book.
283 *
284 * @param clipboard the clipboard
285 * @param text the text from the board
286 * @param user_data NULL
287 */
288static void
289handle_paste_data (GtkClipboard *clipboard,
290 const gchar *text,
291 gpointer data)
292{
293 char *name;
294 char *slash;
295 const char *label;
296
297 if (NULL == text)
298 return; /* clipboard empty */
299 if (0 != strncasecmp ("gnunet://gns/",
300 text,
301 strlen ("gnunet://gns/")))
302 {
303 GCG_log (_("Invalid URI `%s'\n"),
304 text);
305 return;
306 }
307 name = GNUNET_strdup (&text[strlen ("gnunet://gns/")]);
308 slash = strchr (name, '/');
309 if ( (NULL != slash) &&
310 ('\0' != slash[1]) )
311 {
312 *slash = '\0';
313 label = &slash[1];
314 if (GNUNET_OK !=
315 GNUNET_DNSPARSER_check_label (label))
316 {
317 GCG_log (_("Invalid label `%s' in URI `%s'\n"),
318 label,
319 text);
320 GNUNET_free (name);
321 return;
322 }
323 else
324 {
325 /* got a label already, try to use it */
326 GSC_get_label_for_name (name,
327 label);
328 GNUNET_free (name);
329 return;
330 }
331 }
332 /* don't have a label yet, need to prompt! */
333 GSC_get_label_for_name (name,
334 NULL);
335 GNUNET_free (name);
336}
337
338
339/**
279 * User clicked the "paste" button. Copy address information 340 * User clicked the "paste" button. Copy address information
280 * from the clipboard into our current zone / address book. 341 * from the clipboard into our current zone / address book.
281 * 342 *
@@ -286,7 +347,13 @@ void
286gnunet_conversation_gtk_contacts_paste_button_clicked_cb (GtkButton *button, 347gnunet_conversation_gtk_contacts_paste_button_clicked_cb (GtkButton *button,
287 gpointer user_data) 348 gpointer user_data)
288{ 349{
289 GNUNET_break (0); // FIXME: not implemented 350 GtkClipboard *cb;
351
352
353 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
354 gtk_clipboard_request_text (cb,
355 &handle_paste_data,
356 NULL);
290} 357}
291 358
292 359
diff --git a/src/conversation/gnunet-conversation-gtk_use_current.c b/src/conversation/gnunet-conversation-gtk_use_current.c
index 0ac1116d..ea99fc1f 100644
--- a/src/conversation/gnunet-conversation-gtk_use_current.c
+++ b/src/conversation/gnunet-conversation-gtk_use_current.c
@@ -26,6 +26,7 @@
26#include "gnunet-conversation-gtk.h" 26#include "gnunet-conversation-gtk.h"
27#include "gnunet-conversation-gtk_egos.h" 27#include "gnunet-conversation-gtk_egos.h"
28#include "gnunet-conversation-gtk_history.h" 28#include "gnunet-conversation-gtk_history.h"
29#include "gnunet-conversation-gtk_get_label.h"
29#include "gnunet-conversation-gtk_import.h" 30#include "gnunet-conversation-gtk_import.h"
30#include "gnunet-conversation-gtk_log.h" 31#include "gnunet-conversation-gtk_log.h"
31#include "gnunet-conversation-gtk_phone.h" 32#include "gnunet-conversation-gtk_phone.h"
@@ -37,6 +38,11 @@
37 */ 38 */
38static struct GNUNET_NAMESTORE_QueueEntry *qe; 39static struct GNUNET_NAMESTORE_QueueEntry *qe;
39 40
41/**
42 * What is the value we want to publish in the namestore?
43 */
44static char *target;
45
40 46
41/** 47/**
42 * Process a record that was stored in the namestore. 48 * Process a record that was stored in the namestore.
@@ -133,19 +139,16 @@ gnunet_conversation_gtk_enter_label_dialog_add_button_clicked_cb (GtkButton *but
133{ 139{
134 GtkBuilder *builder = GTK_BUILDER (user_data); 140 GtkBuilder *builder = GTK_BUILDER (user_data);
135 GtkWidget *dialog; 141 GtkWidget *dialog;
136 const gchar *target;
137 const gchar *label; 142 const gchar *label;
138 GtkEntry *address_entry;
139 GtkEntry *label_entry; 143 GtkEntry *label_entry;
140 144
141 address_entry = GTK_ENTRY (GCG_get_main_window_object
142 ("gnunet_conversation_gtk_address_entry"));
143 target = gtk_entry_get_text (address_entry);
144 label_entry = GTK_ENTRY (gtk_builder_get_object 145 label_entry = GTK_ENTRY (gtk_builder_get_object
145 (builder, 146 (builder,
146 ("gnunet_conversation_gtk_enter_label_entry"))); 147 ("gnunet_conversation_gtk_enter_label_entry")));
147 label = gtk_entry_get_text (label_entry); 148 label = gtk_entry_get_text (label_entry);
148 GSC_add_contact (label, target); 149 GSC_add_contact (label, target);
150 GNUNET_free (target);
151 target = NULL;
149 dialog = GTK_WIDGET (gtk_builder_get_object 152 dialog = GTK_WIDGET (gtk_builder_get_object
150 (builder, 153 (builder,
151 "gnunet_conversation_gtk_enter_label_window")); 154 "gnunet_conversation_gtk_enter_label_window"));
@@ -171,6 +174,8 @@ gnunet_conversation_gtk_enter_label_dialog_cancel_button_clicked_cb (GtkButton *
171 dialog = GTK_WIDGET (gtk_builder_get_object 174 dialog = GTK_WIDGET (gtk_builder_get_object
172 (builder, 175 (builder,
173 "gnunet_conversation_gtk_enter_label_window")); 176 "gnunet_conversation_gtk_enter_label_window"));
177 GNUNET_free (target);
178 target = NULL;
174 gtk_widget_destroy (GTK_WIDGET (dialog)); 179 gtk_widget_destroy (GTK_WIDGET (dialog));
175 g_object_unref (G_OBJECT (builder)); 180 g_object_unref (G_OBJECT (builder));
176} 181}
@@ -192,24 +197,29 @@ gnunet_conversation_gtk_enter_label_window_delete_event_cb (GtkWidget *widget,
192 GtkBuilder *builder = GTK_BUILDER (user_data); 197 GtkBuilder *builder = GTK_BUILDER (user_data);
193 198
194 g_object_unref (G_OBJECT (builder)); 199 g_object_unref (G_OBJECT (builder));
200 GNUNET_free_non_null (target);
201 target = NULL;
195 return FALSE; 202 return FALSE;
196} 203}
197 204
198 205
199/** 206/**
200 * User clicked the '> contact' button to move the selected 207 * Obtain the label the user wants to use for a given
201 * caller's information into our address book. 208 * name and (if successful) add the name to the
209 * address book usnig #GSC_add_contact().
202 * 210 *
203 * @param button the button 211 * @param name value to publish (corresponds to CNAME or PKEY record)
204 * @param user_data main loop context (unused) 212 * @param label suggested label (user can change)
205 */ 213 */
206void 214void
207gnunet_conversation_gtk_add_contact_button_clicked_cb (GtkButton *button, 215GSC_get_label_for_name (const char *name,
208 gpointer *user_data) 216 const char *label)
209{ 217{
210 GtkBuilder *builder; 218 GtkBuilder *builder;
211 GtkWidget *dialog; 219 GtkWidget *dialog;
212 GtkWidget *toplevel; 220 GtkWidget *toplevel;
221 GtkEntry *label_entry;
222 GtkWidget *address_entry;
213 223
214 builder = 224 builder =
215 GNUNET_GTK_get_new_builder ("gnunet_conversation_gtk_enter_label.glade", 225 GNUNET_GTK_get_new_builder ("gnunet_conversation_gtk_enter_label.glade",
@@ -219,15 +229,47 @@ gnunet_conversation_gtk_add_contact_button_clicked_cb (GtkButton *button,
219 GNUNET_break (0); 229 GNUNET_break (0);
220 return; 230 return;
221 } 231 }
232 target = GNUNET_strdup (name);
233 label_entry = GTK_ENTRY (gtk_builder_get_object
234 (builder,
235 ("gnunet_conversation_gtk_enter_label_entry")));
236 gtk_entry_set_text (label_entry,
237 label);
222 dialog = GTK_WIDGET (gtk_builder_get_object 238 dialog = GTK_WIDGET (gtk_builder_get_object
223 (builder, 239 (builder,
224 "gnunet_conversation_gtk_enter_label_window")); 240 "gnunet_conversation_gtk_enter_label_window"));
225 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); 241
242 /* just pick ANY widget from the main window here... */
243 address_entry = GTK_WIDGET (GCG_get_main_window_object
244 ("gnunet_conversation_gtk_address_entry"));
245 toplevel = gtk_widget_get_toplevel (address_entry);
226 if (GTK_IS_WINDOW (toplevel)) 246 if (GTK_IS_WINDOW (toplevel))
227 gtk_window_set_transient_for (GTK_WINDOW (dialog), 247 gtk_window_set_transient_for (GTK_WINDOW (dialog),
228 GTK_WINDOW (toplevel)); 248 GTK_WINDOW (toplevel));
249
229 gtk_widget_show (dialog); 250 gtk_widget_show (dialog);
230} 251}
231 252
232 253
254/**
255 * User clicked the '> contact' button to move the selected
256 * caller's information into our address book.
257 *
258 * @param button the button
259 * @param user_data main loop context (unused)
260 */
261void
262gnunet_conversation_gtk_add_contact_button_clicked_cb (GtkButton *button,
263 gpointer *user_data)
264{
265 GtkEntry *address_entry;
266
267 address_entry = GTK_ENTRY (GCG_get_main_window_object
268 ("gnunet_conversation_gtk_address_entry"));
269 GSC_get_label_for_name (gtk_entry_get_text (address_entry),
270 "");
271}
272
273
274
233/* end of gnunet-conversation-gtk_use_current.c */ 275/* end of gnunet-conversation-gtk_use_current.c */