[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26277 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26277 - gnunet-gtk/src/fs |
Date: |
Mon, 4 Mar 2013 02:18:54 +0100 |
Author: LRN
Date: 2013-03-04 02:18:54 +0100 (Mon, 04 Mar 2013)
New Revision: 26277
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
Log:
Add popup menu items to look for associated namespace
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2013-03-04 01:18:50 UTC
(rev 26276)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2013-03-04 01:18:54 UTC
(rev 26277)
@@ -771,7 +771,7 @@
*
* @param spc the 'struct SearchListPopupContext' of the menu
* @param is_recursive was this the 'recursive' option?
- * @parma save_as was this the 'save as' option?
+ * @param save_as was this the 'save as' option?
*/
static void
start_download_ctx_menu_helper (struct SearchListPopupContext *spc,
@@ -843,7 +843,30 @@
start_download_ctx_menu_helper (spc, GNUNET_NO, GNUNET_NO);
}
+/**
+ * "Get root element of associated namespace X" was selected in the current
search
+ * context menu.
+ *
+ * @param item the menu item that was selected
+ * @param user_data the 'struct SearchListPopupContext' of the menu
+ */
+static void
+start_download_associated_ns_ctx_menu (GtkMenuItem *item, gpointer user_data)
+{
+ struct GNUNET_FS_Uri *uri;
+ uri = g_object_get_data (G_OBJECT (item), "sks-uri");
+ if (NULL == uri)
+ return;
+
+ /* start search */
+ GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
+ uri, (uintptr_t) user_data,
+ GNUNET_FS_SEARCH_OPTION_NONE, NULL);
+ /* GObject will clean up the URI */
+}
+
+
/**
* "Download recursively" was selected in the current search context menu.
*
@@ -937,7 +960,105 @@
GNUNET_free (uris);
}
+/* Called for each embedded sks. Return GNUNET_OK to continue iteration */
+typedef int (*embedded_sks_callback) (void *cls, const struct GNUNET_FS_Uri
*sks_uri,
+ const char *sks_uri_string, struct GNUNET_HashCode *nsid);
+struct sks_scanner_callback_context
+{
+ embedded_sks_callback cb;
+ void *cls;
+};
+
+/* Metadata callback. Checks metadata item for being an SKS URI,
+ * invokes the callback if so.
+ */
+static int
+check_for_embedded_sks (void *cls, const char *plugin_name, enum
EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
+ const char *data, size_t data_size)
+{
+ struct sks_scanner_callback_context *ctx = cls;
+ int result;
+
+ if ((EXTRACTOR_METATYPE_URI == type) &&
+ (EXTRACTOR_METAFORMAT_UTF8 == format) &&
+ (data_mime_type && (0 == strcmp ("text/plain", data_mime_type))))
+ {
+ struct GNUNET_FS_Uri *sks_uri;
+ char *emsg;
+ emsg = NULL;
+ sks_uri = GNUNET_FS_uri_parse (data, &emsg);
+ if (NULL != sks_uri)
+ {
+ if (GNUNET_FS_uri_test_sks (sks_uri))
+ {
+ char *id = GNUNET_FS_uri_sks_get_content_id (sks_uri);
+ if (NULL != id)
+ {
+ struct GNUNET_HashCode nsid;
+ if ((0 == strcmp (id, "/")) &&
+ (GNUNET_OK == GNUNET_FS_uri_sks_get_namespace (sks_uri, &nsid)))
+ result = ctx->cb (ctx->cls, sks_uri, data, &nsid);
+ GNUNET_free (id);
+ }
+ }
+ GNUNET_FS_uri_destroy (sks_uri);
+ }
+ GNUNET_free_non_null (emsg);
+ }
+ return result;
+}
+
+/* Search metadata for SKS URIs, invoke the callback for each one. */
+static void
+find_embedded_sks (const struct GNUNET_CONTAINER_MetaData *meta,
embedded_sks_callback cb, void *cls)
+{
+ struct sks_scanner_callback_context ctx;
+ ctx.cb = cb;
+ ctx.cls = cls;
+ GNUNET_CONTAINER_meta_data_iterate (meta, check_for_embedded_sks, &ctx);
+}
+
+struct sks_population_context
+{
+ GtkMenu *menu;
+ int counter;
+ uintptr_t anonymity_level;
+};
+
+/* Called for every SKS URI in metadata. Adds up to 3 menu items
+ * that will initiate downloads for these SKS URIs
+ */
+static int
+populate_popup_with_sks_items (void *cls, const struct GNUNET_FS_Uri *sks_uri,
+ const char *sks_uri_string, struct GNUNET_HashCode *nsid)
+{
+ struct sks_population_context *ctx = cls;
+ GtkWidget *child;
+ char *label;
+ GtkWidget *ns_association_icon;
+
+ label = NULL;
+ ctx->counter += 1;
+ GNUNET_asprintf (&label, _("Get root element of associated namespace #%d"),
ctx->counter);
+ child = gtk_image_menu_item_new_with_label (label);
+ GNUNET_free (label);
+
+ ns_association_icon = gtk_image_new_from_icon_name ("gnunet-ns-association",
GTK_ICON_SIZE_MENU);
+
+ /* Takes ownership of the icon */
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (child),
ns_association_icon);
+
+ g_object_set_data_full (G_OBJECT (child), "sks-uri", GNUNET_FS_uri_dup
(sks_uri), (GDestroyNotify) GNUNET_FS_uri_destroy);
+ g_signal_connect (child, "activate",
+ G_CALLBACK (start_download_associated_ns_ctx_menu), (gpointer)
ctx->anonymity_level);
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (ctx->menu), child);
+
+ return (ctx->counter < 4) ? GNUNET_OK : GNUNET_SYSERR;
+}
+
/**
* Context menu was requested for a search result list.
* Compute which menu items are applicable and display
@@ -964,6 +1085,7 @@
struct SearchListPopupContext *spc;
struct GNUNET_CONTAINER_MetaData *meta;
int is_directory = GNUNET_NO;
+ struct sks_population_context sks_pop_ctx;
spc = GNUNET_malloc (sizeof (struct SearchListPopupContext));
spc->tab = tab;
@@ -1015,6 +1137,27 @@
gtk_widget_show (child);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
}
+
+ /* Insert a separator */
+ child = gtk_separator_menu_item_new ();
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+
+ /* check for embedded SKS URIs */
+ sks_pop_ctx.counter = 0;
+ sks_pop_ctx.menu = menu;
+ /* TODO: make this configurable, or inherit it from the search? */
+ sks_pop_ctx.anonymity_level = 1;
+ find_embedded_sks (meta, populate_popup_with_sks_items,
+ &sks_pop_ctx);
+ if (0 < sks_pop_ctx.counter)
+ {
+ /* Insert another separator */
+ child = gtk_separator_menu_item_new ();
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+ }
+
if ( (NULL != sr->download) &&
(GNUNET_YES != sr->download->is_done) )
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26277 - gnunet-gtk/src/fs,
gnunet <=