diff options
Diffstat (limited to 'src/identity/gnunet-identity-gtk_advertise.c')
-rw-r--r-- | src/identity/gnunet-identity-gtk_advertise.c | 688 |
1 files changed, 0 insertions, 688 deletions
diff --git a/src/identity/gnunet-identity-gtk_advertise.c b/src/identity/gnunet-identity-gtk_advertise.c deleted file mode 100644 index d5a8eecf..00000000 --- a/src/identity/gnunet-identity-gtk_advertise.c +++ /dev/null | |||
@@ -1,688 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2005-2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/identity/gnunet-identity-gtk_advertise.c | ||
23 | * @author LRN | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "gnunet-identity-gtk_advertise.h" | ||
27 | #include "gnunet-identity-gtk.h" | ||
28 | #include <gnunet/gnunet_fs_service.h> | ||
29 | #if HAVE_EXTRACTOR_H | ||
30 | #include <extractor.h> | ||
31 | #endif | ||
32 | |||
33 | #define NEW_KEYWORD_TEXT "<add>" | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Types of metadata we offer for namespaces. | ||
38 | */ | ||
39 | static gint types[] = | ||
40 | { | ||
41 | EXTRACTOR_METATYPE_TITLE, | ||
42 | EXTRACTOR_METATYPE_KEYWORDS, | ||
43 | EXTRACTOR_METATYPE_SUBJECT, | ||
44 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
45 | EXTRACTOR_METATYPE_COMMENT, | ||
46 | EXTRACTOR_METATYPE_URI, | ||
47 | #if HAVE_EXTRACTOR_H | ||
48 | EXTRACTOR_METATYPE_COPYRIGHT, | ||
49 | EXTRACTOR_METATYPE_CREATOR, | ||
50 | EXTRACTOR_METATYPE_CREATION_DATE, | ||
51 | #endif | ||
52 | EXTRACTOR_METATYPE_RESERVED | ||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Columns in the metadata list store. | ||
58 | */ | ||
59 | enum METADATA_ModelColumns | ||
60 | { | ||
61 | |||
62 | /** | ||
63 | * A guint | ||
64 | */ | ||
65 | METADATA_MC_TYPE_AS_ENUM = 0, | ||
66 | |||
67 | /** | ||
68 | * A gchararray | ||
69 | */ | ||
70 | METADATA_MC_TYPE_AS_STRING = 1, | ||
71 | |||
72 | /** | ||
73 | * A gchararray | ||
74 | */ | ||
75 | METADATA_MC_VALUE = 2 | ||
76 | |||
77 | }; | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Columns in the keyword list tree store. | ||
82 | */ | ||
83 | enum KEYWORDS_ModelColumns | ||
84 | { | ||
85 | |||
86 | /** | ||
87 | * A gchararray | ||
88 | */ | ||
89 | KEYWORDS_MC_KEYWORD = 0 | ||
90 | |||
91 | }; | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Columns in the meta types list tree store. | ||
96 | */ | ||
97 | enum METATYPES_ModelColumns | ||
98 | { | ||
99 | |||
100 | /** | ||
101 | * A gchararray | ||
102 | */ | ||
103 | METATYPES_MC_TYPE_AS_STRING = 0, | ||
104 | |||
105 | /** | ||
106 | * A guint | ||
107 | */ | ||
108 | METATYPES_MC_TYPE_AS_ENUM = 1 | ||
109 | |||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Context for advertisement operations. | ||
115 | */ | ||
116 | struct AdvertiseContext | ||
117 | { | ||
118 | /** | ||
119 | * Builder for accessing objects in the dialog. | ||
120 | */ | ||
121 | GtkBuilder *builder; | ||
122 | |||
123 | /** | ||
124 | * Private key of the namespace we will be advertising. | ||
125 | */ | ||
126 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv; | ||
127 | |||
128 | /** | ||
129 | * Main dialog object. | ||
130 | */ | ||
131 | GtkWidget *dialog; | ||
132 | |||
133 | /** | ||
134 | * List of keywords to advertise under. | ||
135 | */ | ||
136 | GtkListStore *keywords; | ||
137 | |||
138 | /** | ||
139 | * Metadata to include in the advertisement. | ||
140 | */ | ||
141 | GtkListStore *metadata; | ||
142 | |||
143 | /** | ||
144 | * Model with the meta types. | ||
145 | */ | ||
146 | GtkListStore *meta_types; | ||
147 | |||
148 | /** | ||
149 | * Number of keywords in the view. | ||
150 | */ | ||
151 | unsigned int num_keywords; | ||
152 | |||
153 | }; | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Context for the publishing operation. | ||
158 | */ | ||
159 | struct PublishContext | ||
160 | { | ||
161 | |||
162 | /** | ||
163 | * Kept in a DLL. | ||
164 | */ | ||
165 | struct PublishContext *next; | ||
166 | |||
167 | /** | ||
168 | * Kept in a DLL. | ||
169 | */ | ||
170 | struct PublishContext *prev; | ||
171 | |||
172 | /** | ||
173 | * Handle to FS subsystem. | ||
174 | */ | ||
175 | struct GNUNET_FS_Handle *fs; | ||
176 | |||
177 | /** | ||
178 | * Handle to the publish operation. | ||
179 | */ | ||
180 | struct GNUNET_FS_PublishKskContext *pub; | ||
181 | |||
182 | }; | ||
183 | |||
184 | |||
185 | /** | ||
186 | * Kept in a DLL. | ||
187 | */ | ||
188 | static struct PublishContext *pc_head; | ||
189 | |||
190 | /** | ||
191 | * Kept in a DLL. | ||
192 | */ | ||
193 | static struct PublishContext *pc_tail; | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Shutdown advertisement subsystem, this process is terminating. | ||
198 | */ | ||
199 | void | ||
200 | GIG_advertise_shutdown_ () | ||
201 | { | ||
202 | struct PublishContext *pc; | ||
203 | |||
204 | while (NULL != (pc = pc_head)) | ||
205 | { | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
207 | _("Aborting advertising operation due to shutdown.\n")); | ||
208 | GNUNET_CONTAINER_DLL_remove (pc_head, | ||
209 | pc_tail, | ||
210 | pc); | ||
211 | GNUNET_FS_publish_ksk_cancel (pc->pub); | ||
212 | GNUNET_FS_stop (pc->fs); | ||
213 | GNUNET_free (pc); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Function called once we published the advertisement. | ||
220 | * | ||
221 | * @param cls closure with the `struct PublishContext` | ||
222 | * @param uri URI under which the block is now available, NULL on error | ||
223 | * @param emsg error message, NULL on success | ||
224 | */ | ||
225 | static void | ||
226 | publish_continuation (void *cls, | ||
227 | const struct GNUNET_FS_Uri *uri, | ||
228 | const char *emsg) | ||
229 | { | ||
230 | struct PublishContext *pc = cls; | ||
231 | |||
232 | pc->pub = NULL; | ||
233 | if (NULL == uri) | ||
234 | { | ||
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
236 | _("Failed to advertise ego: %s\n"), | ||
237 | emsg); | ||
238 | /* FIXME: might want to output to GUI... */ | ||
239 | } | ||
240 | GNUNET_FS_stop (pc->fs); | ||
241 | GNUNET_CONTAINER_DLL_remove (pc_head, | ||
242 | pc_tail, | ||
243 | pc); | ||
244 | GNUNET_free (pc); | ||
245 | } | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Notification of FS to a client about the progress of an | ||
250 | * operation. Callbacks of this type will be used for uploads, | ||
251 | * downloads and searches. Some of the arguments depend a bit | ||
252 | * in their meaning on the context in which the callback is used. | ||
253 | * | ||
254 | * @param cls closure | ||
255 | * @param info details about the event, specifying the event type | ||
256 | * and various bits about the event | ||
257 | * @return client-context (for the next progress call | ||
258 | * for this operation; should be set to NULL for | ||
259 | * SUSPEND and STOPPED events). The value returned | ||
260 | * will be passed to future callbacks in the respective | ||
261 | * field in the `struct GNUNET_FS_ProgressInfo`. | ||
262 | */ | ||
263 | static void * | ||
264 | progress_cb (void *cls, | ||
265 | const struct GNUNET_FS_ProgressInfo *info) | ||
266 | { | ||
267 | return NULL; | ||
268 | } | ||
269 | |||
270 | |||
271 | /** | ||
272 | * The user terminated the dialog. Perform the appropriate action. | ||
273 | * | ||
274 | * @param dialog the advertisement dialog | ||
275 | * @param response_id action selected by the user | ||
276 | * @param user_data our 'struct AdvertiseContext' (to be cleaned up) | ||
277 | */ | ||
278 | void | ||
279 | GNUNET_GTK_identity_advertise_dialog_response_cb (GtkDialog *dialog, | ||
280 | gint response_id, | ||
281 | gpointer user_data) | ||
282 | { | ||
283 | struct AdvertiseContext *ac = user_data; | ||
284 | struct GNUNET_FS_Uri *ksk_uri; | ||
285 | struct GNUNET_FS_Uri *uri; | ||
286 | gchar *keyword; | ||
287 | struct GNUNET_CONTAINER_MetaData *meta; | ||
288 | guint ntype; | ||
289 | gchar *value; | ||
290 | GtkTreeIter iter; | ||
291 | struct GNUNET_FS_BlockOptions bo; | ||
292 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | ||
293 | struct PublishContext *pc; | ||
294 | guint anonymity; | ||
295 | const char *id; | ||
296 | |||
297 | if (GTK_RESPONSE_OK != response_id) | ||
298 | goto cleanup; | ||
299 | ksk_uri = NULL; | ||
300 | if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->keywords), &iter)) | ||
301 | { | ||
302 | GNUNET_break (0); | ||
303 | goto cleanup; | ||
304 | } | ||
305 | do | ||
306 | { | ||
307 | gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter, | ||
308 | KEYWORDS_MC_KEYWORD, &keyword, | ||
309 | -1); | ||
310 | if (NULL == ksk_uri) | ||
311 | ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &keyword); | ||
312 | else | ||
313 | GNUNET_FS_uri_ksk_add_keyword (ksk_uri, keyword, GNUNET_NO); | ||
314 | g_free (keyword); | ||
315 | } | ||
316 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->keywords), &iter)); | ||
317 | |||
318 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
319 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->metadata), | ||
320 | &iter)) | ||
321 | { | ||
322 | do | ||
323 | { | ||
324 | gtk_tree_model_get (GTK_TREE_MODEL (ac->metadata), &iter, | ||
325 | METADATA_MC_TYPE_AS_ENUM, &ntype, | ||
326 | METADATA_MC_VALUE, &value, | ||
327 | -1); | ||
328 | if (ntype > 0) | ||
329 | { | ||
330 | GNUNET_CONTAINER_meta_data_insert (meta, "<user>", | ||
331 | ntype, | ||
332 | EXTRACTOR_METAFORMAT_UTF8, | ||
333 | "text/plain", value, | ||
334 | strlen (value) + 1); | ||
335 | } | ||
336 | g_free (value); | ||
337 | } | ||
338 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter)); | ||
339 | } | ||
340 | |||
341 | bo.expiration_time = GNUNET_GTK_get_expiration_time | ||
342 | (GTK_SPIN_BUTTON | ||
343 | (gtk_builder_get_object | ||
344 | (ac->builder, | ||
345 | "GNUNET_GTK_identity_advertise_expiration_year_spin_button"))); | ||
346 | anonymity = 1; | ||
347 | GNUNET_break (GNUNET_GTK_get_selected_anonymity_level (ac->builder, | ||
348 | "GNUNET_GTK_identity_advertise_anonymity_combobox", | ||
349 | &anonymity)); | ||
350 | bo.anonymity_level = anonymity; | ||
351 | bo.content_priority | ||
352 | = (unsigned int) gtk_spin_button_get_value | ||
353 | (GTK_SPIN_BUTTON | ||
354 | (gtk_builder_get_object | ||
355 | (ac->builder, | ||
356 | "GNUNET_GTK_identity_advertise_priority_spin_button"))); | ||
357 | bo.replication_level | ||
358 | = (unsigned int) gtk_spin_button_get_value | ||
359 | (GTK_SPIN_BUTTON | ||
360 | (gtk_builder_get_object | ||
361 | (ac->builder, | ||
362 | "GNUNET_GTK_identity_advertise_replication_spin_button"))); | ||
363 | GNUNET_CRYPTO_ecdsa_key_get_public (&ac->priv, | ||
364 | &pk); | ||
365 | id = gtk_entry_get_text | ||
366 | (GTK_ENTRY | ||
367 | (gtk_builder_get_object | ||
368 | (ac->builder, | ||
369 | "GNUNET_GTK_identity_advertise_root_entry"))); | ||
370 | uri = GNUNET_FS_uri_sks_create (&pk, id); | ||
371 | |||
372 | pc = GNUNET_new (struct PublishContext); | ||
373 | pc->fs = GNUNET_FS_start (GIG_get_configuration (), | ||
374 | "gnunet-identity-gtk", | ||
375 | &progress_cb, pc, | ||
376 | GNUNET_FS_FLAGS_NONE, | ||
377 | GNUNET_FS_OPTIONS_END); | ||
378 | pc->pub = GNUNET_FS_publish_ksk (pc->fs, | ||
379 | ksk_uri, | ||
380 | meta, | ||
381 | uri, | ||
382 | &bo, | ||
383 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
384 | &publish_continuation, pc); | ||
385 | GNUNET_CONTAINER_DLL_insert (pc_head, | ||
386 | pc_tail, | ||
387 | pc); | ||
388 | GNUNET_FS_uri_destroy (uri); | ||
389 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
390 | cleanup: | ||
391 | gtk_widget_destroy (ac->dialog); | ||
392 | g_object_unref (G_OBJECT (ac->builder)); | ||
393 | GNUNET_free (ac); | ||
394 | } | ||
395 | |||
396 | |||
397 | /** | ||
398 | * User edited keywords in the keyword tree view. Update | ||
399 | * the model accordingly. | ||
400 | * | ||
401 | * @param renderer the object that created the signal | ||
402 | * @param path the path identifying the edited cell | ||
403 | * @param new_text the new text | ||
404 | * @param user_data the 'struct AdvertiseContext' | ||
405 | */ | ||
406 | void | ||
407 | GNUNET_GTK_identity_advertise_keywords_text_edited_cb (GtkCellRendererText *renderer, | ||
408 | gchar *path, | ||
409 | gchar *new_text, | ||
410 | gpointer user_data) | ||
411 | { | ||
412 | struct AdvertiseContext *ac = user_data; | ||
413 | GtkTreePath *tree_path; | ||
414 | GtkTreeIter iter; | ||
415 | char *old_text; | ||
416 | |||
417 | tree_path = gtk_tree_path_new_from_string (path); | ||
418 | if (NULL == tree_path) | ||
419 | { | ||
420 | GNUNET_break (0); | ||
421 | return; | ||
422 | } | ||
423 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ac->keywords), | ||
424 | &iter, tree_path)) | ||
425 | { | ||
426 | GNUNET_break (0); | ||
427 | gtk_tree_path_free (tree_path); | ||
428 | return; | ||
429 | } | ||
430 | gtk_tree_path_free (tree_path); | ||
431 | gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter, | ||
432 | KEYWORDS_MC_KEYWORD, &old_text, | ||
433 | -1); | ||
434 | if (0 == strcmp (NEW_KEYWORD_TEXT, old_text)) | ||
435 | { | ||
436 | if ( (NULL != new_text) && | ||
437 | (0 != strlen (new_text)) ) | ||
438 | { | ||
439 | gtk_list_store_insert_with_values (ac->keywords, &iter, -1, | ||
440 | KEYWORDS_MC_KEYWORD, new_text, | ||
441 | -1); | ||
442 | ac->num_keywords++; | ||
443 | } | ||
444 | } | ||
445 | else | ||
446 | { | ||
447 | if ( (NULL != new_text) && | ||
448 | (0 != strlen (new_text)) ) | ||
449 | { | ||
450 | gtk_list_store_set (ac->keywords, &iter, | ||
451 | KEYWORDS_MC_KEYWORD, new_text, | ||
452 | -1); | ||
453 | } | ||
454 | else | ||
455 | { | ||
456 | gtk_list_store_remove (ac->keywords, &iter); | ||
457 | ac->num_keywords--; | ||
458 | } | ||
459 | } | ||
460 | g_free (old_text); | ||
461 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object | ||
462 | (ac->builder, | ||
463 | "GNUNET_GTK_identity_advertise_ok_button")), | ||
464 | 0 != ac->num_keywords); | ||
465 | } | ||
466 | |||
467 | |||
468 | /** | ||
469 | * User pushed a key in the metadata tree view. Check if it was | ||
470 | * "DEL" and if so, remove the selected values. | ||
471 | * | ||
472 | * @param widget widget creating the signal | ||
473 | * @param event the event to process | ||
474 | * @param user_data the 'struct AdvertiseContext' | ||
475 | * @return TRUE if we handled the event, FALSE if not | ||
476 | */ | ||
477 | gboolean | ||
478 | GNUNET_GTK_identity_advertise_metadata_treeview_key_press_event_cb (GtkWidget *widget, | ||
479 | GdkEventKey *event, | ||
480 | gpointer user_data) | ||
481 | { | ||
482 | struct AdvertiseContext *ac = user_data; | ||
483 | GtkTreeSelection *sel; | ||
484 | GtkTreeModel *model; | ||
485 | GtkTreeIter iter; | ||
486 | |||
487 | if (event->keyval != GDK_KEY_Delete) | ||
488 | return FALSE; | ||
489 | sel = gtk_tree_view_get_selection (GTK_TREE_VIEW | ||
490 | (gtk_builder_get_object | ||
491 | (ac->builder, | ||
492 | "GNUNET_GTK_identity_advertise_metadata_treeview"))); | ||
493 | if (! gtk_tree_selection_get_selected (sel, | ||
494 | &model, | ||
495 | &iter)) | ||
496 | { | ||
497 | gdk_beep (); | ||
498 | return TRUE; | ||
499 | } | ||
500 | gtk_list_store_remove (ac->metadata, | ||
501 | &iter); | ||
502 | return TRUE; | ||
503 | } | ||
504 | |||
505 | |||
506 | /** | ||
507 | * User edited metadata value in the tree view. Update the model. | ||
508 | * | ||
509 | * @param renderer the object that created the signal | ||
510 | * @param path the path identifying the edited cell | ||
511 | * @param new_text the new text, if empty, remove the line | ||
512 | * @param user_data the 'struct AdvertiseContext' | ||
513 | */ | ||
514 | void | ||
515 | GNUNET_GTK_identity_advertise_metadata_value_text_edited_cb (GtkCellRendererText *renderer, | ||
516 | gchar *path, | ||
517 | gchar *new_text, | ||
518 | gpointer user_data) | ||
519 | { | ||
520 | struct AdvertiseContext *ac = user_data; | ||
521 | GtkTreePath *tree_path; | ||
522 | GtkTreeIter iter; | ||
523 | |||
524 | tree_path = gtk_tree_path_new_from_string (path); | ||
525 | if (NULL == tree_path) | ||
526 | { | ||
527 | GNUNET_break (0); | ||
528 | return; | ||
529 | } | ||
530 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ac->metadata), | ||
531 | &iter, tree_path)) | ||
532 | { | ||
533 | GNUNET_break (0); | ||
534 | gtk_tree_path_free (tree_path); | ||
535 | return; | ||
536 | } | ||
537 | gtk_tree_path_free (tree_path); | ||
538 | if ( (NULL != new_text) && | ||
539 | (0 != strlen (new_text)) ) | ||
540 | gtk_list_store_set (ac->metadata, &iter, | ||
541 | METADATA_MC_VALUE, new_text, | ||
542 | -1); | ||
543 | else | ||
544 | gtk_list_store_remove (ac->metadata, &iter); | ||
545 | } | ||
546 | |||
547 | |||
548 | /** | ||
549 | * User edited the 'value' field for inserting meta data. Update | ||
550 | * sensitivity of the 'add' button accordingly. | ||
551 | * | ||
552 | * @param editable the widget that was edited | ||
553 | * @param user_data the 'struct AdvertiseContext' | ||
554 | */ | ||
555 | void | ||
556 | GNUNET_GTK_identity_advertise_metadata_value_entry_changed_cb (GtkEditable *editable, | ||
557 | gpointer user_data) | ||
558 | { | ||
559 | struct AdvertiseContext *ac = user_data; | ||
560 | const char *value; | ||
561 | GtkEntry *value_entry; | ||
562 | GtkWidget * add_button; | ||
563 | |||
564 | value_entry = GTK_ENTRY (gtk_builder_get_object (ac->builder, | ||
565 | "GNUNET_GTK_identity_advertise_metadata_value_entry")); | ||
566 | value = gtk_entry_get_text (value_entry); | ||
567 | add_button = GTK_WIDGET (gtk_builder_get_object (ac->builder, | ||
568 | "GNUNET_GTK_identity_advertise_metadata_add_button")); | ||
569 | if ( (NULL == value) || | ||
570 | (0 == strlen (value)) ) | ||
571 | { | ||
572 | gtk_widget_set_sensitive (add_button, | ||
573 | FALSE); | ||
574 | return; | ||
575 | } | ||
576 | gtk_widget_set_sensitive (add_button, | ||
577 | TRUE); | ||
578 | } | ||
579 | |||
580 | |||
581 | /** | ||
582 | * User clicked the 'add' button, get the type and value and update | ||
583 | * the metadata model. | ||
584 | * | ||
585 | * @param button the 'add' button | ||
586 | * @param user_data the 'struct AdvertiseContext' | ||
587 | */ | ||
588 | void | ||
589 | GNUNET_GTK_identity_advertise_metadata_add_button_clicked_cb (GtkButton * button, | ||
590 | gpointer user_data) | ||
591 | { | ||
592 | struct AdvertiseContext *ac = user_data; | ||
593 | GtkTreeIter iter; | ||
594 | guint type; | ||
595 | const char *value; | ||
596 | GtkEntry *value_entry; | ||
597 | GtkComboBox *type_box; | ||
598 | |||
599 | type_box = GTK_COMBO_BOX (gtk_builder_get_object (ac->builder, | ||
600 | "GNUNET_GTK_identity_advertise_metadata_type_combobox")); | ||
601 | if (! gtk_combo_box_get_active_iter (type_box, | ||
602 | &iter)) | ||
603 | { | ||
604 | GNUNET_break (0); | ||
605 | return; | ||
606 | } | ||
607 | gtk_tree_model_get (GTK_TREE_MODEL (ac->meta_types), | ||
608 | &iter, | ||
609 | METATYPES_MC_TYPE_AS_ENUM, &type, | ||
610 | -1); | ||
611 | value_entry = GTK_ENTRY (gtk_builder_get_object (ac->builder, | ||
612 | "GNUNET_GTK_identity_advertise_metadata_value_entry")); | ||
613 | value = gtk_entry_get_text (value_entry); | ||
614 | if ( (NULL == value) || | ||
615 | (0 == strlen (value)) ) | ||
616 | { | ||
617 | GNUNET_break (0); | ||
618 | return; | ||
619 | } | ||
620 | gtk_list_store_insert_with_values (ac->metadata, | ||
621 | &iter, 0, | ||
622 | METADATA_MC_TYPE_AS_ENUM, type, | ||
623 | #if HAVE_EXTRACTOR | ||
624 | METADATA_MC_TYPE_AS_STRING, EXTRACTOR_metatype_to_string (type), | ||
625 | #endif | ||
626 | METADATA_MC_VALUE, value, | ||
627 | -1); | ||
628 | gtk_entry_set_text (value_entry, ""); | ||
629 | } | ||
630 | |||
631 | |||
632 | /** | ||
633 | * Run the dialog for advertising a namespace. | ||
634 | * | ||
635 | * @param priv private key of the namespace to advertise | ||
636 | */ | ||
637 | void | ||
638 | GIG_advertise_dialog_start_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) | ||
639 | { | ||
640 | struct AdvertiseContext *ac; | ||
641 | gint i; | ||
642 | GtkTreeIter iter; | ||
643 | |||
644 | ac = GNUNET_new (struct AdvertiseContext); | ||
645 | ac->priv = *priv; | ||
646 | ac->builder = | ||
647 | GNUNET_GTK_get_new_builder ("gnunet_identity_gtk_advertise_dialog.glade", | ||
648 | ac); | ||
649 | if (NULL == ac->builder) | ||
650 | { | ||
651 | GNUNET_break (0); | ||
652 | GNUNET_free (ac); | ||
653 | return; | ||
654 | } | ||
655 | GNUNET_GTK_setup_expiration_year_adjustment (ac->builder); | ||
656 | ac->dialog = GTK_WIDGET (gtk_builder_get_object | ||
657 | (ac->builder, "GNUNET_GTK_identity_advertise_dialog")); | ||
658 | ac->keywords = GTK_LIST_STORE (gtk_builder_get_object | ||
659 | (ac->builder, "GNUNET_GTK_identity_advertise_keywords_liststore")); | ||
660 | ac->metadata = GTK_LIST_STORE (gtk_builder_get_object | ||
661 | (ac->builder, "GNUNET_GTK_identity_advertise_metadata_liststore")); | ||
662 | ac->meta_types = GTK_LIST_STORE (gtk_builder_get_object | ||
663 | (ac->builder, "GNUNET_GTK_identity_metadata_types_liststore")); | ||
664 | for (i = 0; EXTRACTOR_METATYPE_RESERVED != types[i]; i++) | ||
665 | { | ||
666 | gtk_list_store_insert_with_values (ac->meta_types, | ||
667 | &iter, G_MAXINT, | ||
668 | #if HAVE_EXTRACTOR | ||
669 | METATYPES_MC_TYPE_AS_STRING, EXTRACTOR_metatype_to_string (types[i]), | ||
670 | #endif | ||
671 | METATYPES_MC_TYPE_AS_ENUM, types[i], | ||
672 | -1); | ||
673 | if (0 == i) | ||
674 | gtk_combo_box_set_active_iter (GTK_COMBO_BOX | ||
675 | (gtk_builder_get_object | ||
676 | (ac->builder, | ||
677 | "GNUNET_GTK_identity_advertise_metadata_type_combobox")), | ||
678 | &iter); | ||
679 | } | ||
680 | gtk_list_store_insert_with_values (ac->keywords, | ||
681 | &iter, G_MAXINT, | ||
682 | KEYWORDS_MC_KEYWORD, NEW_KEYWORD_TEXT, | ||
683 | -1); | ||
684 | gtk_window_present (GTK_WINDOW (ac->dialog)); | ||
685 | } | ||
686 | |||
687 | |||
688 | /* end of gnunet-identity-gtk_advertise.c */ | ||