diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-main_window_namespace.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_namespace.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_namespace.c b/src/fs/gnunet-fs-gtk-main_window_namespace.c index 3af3845d..7c61c882 100644 --- a/src/fs/gnunet-fs-gtk-main_window_namespace.c +++ b/src/fs/gnunet-fs-gtk-main_window_namespace.c | |||
@@ -25,6 +25,10 @@ | |||
25 | */ | 25 | */ |
26 | #include "gnunet-fs-gtk-common.h" | 26 | #include "gnunet-fs-gtk-common.h" |
27 | #include <gdk/gdk.h> | 27 | #include <gdk/gdk.h> |
28 | #include "gnunet-fs-gtk.h" | ||
29 | |||
30 | |||
31 | static guint namespace_selector_window_leave_timeout_source; | ||
28 | 32 | ||
29 | 33 | ||
30 | void | 34 | void |
@@ -321,4 +325,153 @@ namespace_selector_treeview_button_release_event_cb (GtkWidget * widget, | |||
321 | 325 | ||
322 | 326 | ||
323 | 327 | ||
328 | /** | ||
329 | * Add pseudonym data to tree store | ||
330 | * | ||
331 | * @param cls closure (the 'GtkListStore') | ||
332 | * @param pseudonym hash code of public key of pseudonym | ||
333 | * @param md meta data known about the pseudonym | ||
334 | * @param rating the local rating of the pseudonym | ||
335 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
336 | */ | ||
337 | static int | ||
338 | add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym, | ||
339 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | ||
340 | { | ||
341 | GtkTreeStore *ts = cls; | ||
342 | char *root; | ||
343 | char *ns_name; | ||
344 | GNUNET_HashCode *nsid; | ||
345 | char *description; | ||
346 | char *uris; | ||
347 | char *emsg; | ||
348 | struct GNUNET_FS_Uri *uri; | ||
349 | GtkTreeIter iter; | ||
350 | |||
351 | ns_name = | ||
352 | GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (), | ||
353 | pseudonym); | ||
354 | nsid = GNUNET_malloc (sizeof (GNUNET_HashCode)); | ||
355 | *nsid = *pseudonym; | ||
356 | root = NULL; | ||
357 | uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI); | ||
358 | if (uris != NULL) | ||
359 | { | ||
360 | emsg = NULL; | ||
361 | uri = GNUNET_FS_uri_parse (uris, &emsg); | ||
362 | if (uri == NULL) | ||
363 | GNUNET_free (emsg); | ||
364 | root = GNUNET_FS_uri_sks_get_content_id (uri); | ||
365 | GNUNET_FS_uri_destroy (uri); | ||
366 | } | ||
367 | description = | ||
368 | GNUNET_CONTAINER_meta_data_get_first_by_types (md, | ||
369 | EXTRACTOR_METATYPE_TITLE, | ||
370 | EXTRACTOR_METATYPE_BOOK_TITLE, | ||
371 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
372 | EXTRACTOR_METATYPE_SUMMARY, | ||
373 | EXTRACTOR_METATYPE_ALBUM, | ||
374 | EXTRACTOR_METATYPE_COMMENT, | ||
375 | EXTRACTOR_METATYPE_SUBJECT, | ||
376 | EXTRACTOR_METATYPE_KEYWORDS, | ||
377 | -1); | ||
378 | if (description == NULL) | ||
379 | description = g_strdup (_("no description supplied")); | ||
380 | else | ||
381 | { | ||
382 | char *utf8_desc = NULL; | ||
383 | |||
384 | utf8_desc = | ||
385 | GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8, | ||
386 | description, strlen (description)); | ||
387 | GNUNET_free (description); | ||
388 | if (utf8_desc != NULL) | ||
389 | description = utf8_desc; | ||
390 | else | ||
391 | description = NULL; | ||
392 | } | ||
393 | gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1, | ||
394 | nsid, 2, root, 3, description, -1); | ||
395 | GNUNET_free (ns_name); | ||
396 | GNUNET_free_non_null (root); | ||
397 | GNUNET_free_non_null (description); | ||
398 | return GNUNET_OK; | ||
399 | } | ||
400 | |||
401 | |||
402 | void | ||
403 | GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data) | ||
404 | { | ||
405 | GtkTreeIter iter; | ||
406 | GtkTreeView *namespace_tree; | ||
407 | GtkTreeStore *namespace_treestore; | ||
408 | GtkBuilder *builder; | ||
409 | GtkWidget *namespace_selector_window; | ||
410 | |||
411 | builder = GTK_BUILDER (user_data); | ||
412 | |||
413 | /* Make sure button class is realized */ | ||
414 | g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON)); | ||
415 | /* GNUnet main window assumes that images on buttons are visible, | ||
416 | * override the theme's gtkrc setting | ||
417 | */ | ||
418 | g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL); | ||
419 | |||
420 | namespace_treestore = | ||
421 | GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object | ||
422 | ("main_window_search_namespace_treestore")); | ||
423 | namespace_tree = | ||
424 | GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object | ||
425 | ("namespace_selector_treeview")); | ||
426 | |||
427 | /* FIXME: find a way to manage pseudonyms. | ||
428 | * Right now the list will be filled with ALL and ANY pseudonyms that we | ||
429 | * find, these are held as files in a special directory. | ||
430 | * I don't see an easy way to ignore certain pseudonyms in that directory, | ||
431 | * and that require for pseudonym management. Also, pseudonyms are presented | ||
432 | * in arbitrary order. We must either sort them (by name?) or let the user | ||
433 | * drag them around to change the order in which they appear in the list. | ||
434 | * All that is not possible with a simple "files in a directory" concept. | ||
435 | */ | ||
436 | gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT, | ||
437 | 0, "Any", 1, NULL, 2, "", 3, | ||
438 | "Do not search in any particular namespace", | ||
439 | -1); | ||
440 | /* | ||
441 | * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (), | ||
442 | * &add_namespace_to_ts, namespace_treestore); | ||
443 | */ | ||
444 | /* FIXME: when do we unregister? */ | ||
445 | GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (), | ||
446 | &add_namespace_to_ts, | ||
447 | namespace_treestore); | ||
448 | |||
449 | /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */ | ||
450 | if (gtk_tree_model_get_iter_first | ||
451 | (GTK_TREE_MODEL (namespace_treestore), &iter)) | ||
452 | { | ||
453 | gchar *value; | ||
454 | GtkLabel *sel_namespace_label; | ||
455 | GtkTreePath *treepath = gtk_tree_path_new_first (); | ||
456 | |||
457 | gtk_tree_selection_select_iter (gtk_tree_view_get_selection | ||
458 | (namespace_tree), &iter); | ||
459 | sel_namespace_label = | ||
460 | GTK_LABEL (gtk_builder_get_object | ||
461 | (builder, "main_window_search_selected_namespace_label")); | ||
462 | if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value)) | ||
463 | gtk_label_set_text (sel_namespace_label, value); | ||
464 | gtk_tree_path_free (treepath); | ||
465 | } | ||
466 | |||
467 | /* How the window (to trigger certain events) and immediately hide it */ | ||
468 | namespace_selector_window = | ||
469 | GTK_WIDGET (gtk_builder_get_object | ||
470 | (builder, "namespace_selector_window")); | ||
471 | gtk_widget_show (namespace_selector_window); | ||
472 | gtk_widget_hide (namespace_selector_window); | ||
473 | |||
474 | } | ||
475 | |||
476 | |||
324 | /* end of gnunet-fs-gtk-main_window_namespace.c */ | 477 | /* end of gnunet-fs-gtk-main_window_namespace.c */ |