[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24229 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24229 - gnunet-gtk/src/fs |
Date: |
Mon, 8 Oct 2012 23:33:27 +0200 |
Author: grothoff
Date: 2012-10-08 23:33:26 +0200 (Mon, 08 Oct 2012)
New Revision: 24229
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
Log:
-trying to fix #2583
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c 2012-10-08
17:20:55 UTC (rev 24228)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c 2012-10-08
21:33:26 UTC (rev 24229)
@@ -874,6 +874,67 @@
/**
+ * Type of a function that libextractor calls for each
+ * meta data item found. Used to get the mime type.
+ *
+ * @param cls pointer to where to store the mime type.
+ * @param plugin_name name of the plugin that produced this value;
+ * special values can be used (i.e. '<zlib>' for zlib being
+ * used in the main libextractor library and yielding
+ * meta data).
+ * @param type libextractor-type describing the meta data
+ * @param format basic format information about data
+ * @param data_mime_type mime-type of data (not of the original file);
+ * can be NULL (if mime-type is not known)
+ * @param data actual meta-data found
+ * @param data_len number of bytes in data
+ * @return 0 to continue extracting, 1 to abort
+ */
+static int
+le_callback (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_len)
+{
+ char **ret = cls;
+
+ if ( (EXTRACTOR_METATYPE_MIMETYPE == type) &&
+ (EXTRACTOR_METAFORMAT_BINARY != format) )
+ {
+ *ret = GNUNET_strdup (data);
+ return 1;
+ }
+ return 0;
+}
+
+
+/**
+ * Use GNU libextractor to get the mime type for the given data.
+ *
+ * @param data binary data of the file
+ * @param data_size number of bytes in 'data'
+ */
+static char *
+get_mime_type (const void *data,
+ gsize data_size)
+{
+ char *ret;
+ struct EXTRACTOR_PluginList *pl;
+
+ pl = EXTRACTOR_plugin_add (NULL, "mime", NULL,
EXTRACTOR_OPTION_DEFAULT_POLICY);
+ if (NULL == pl)
+ return NULL;
+ ret = NULL;
+ EXTRACTOR_extract (pl, NULL, data, data_size, &le_callback, &ret);
+ EXTRACTOR_plugin_remove_all (pl);
+ return ret;
+}
+
+
+/**
* Function called to update the information in FI based on the changes made in
* the edit dialog.
*
@@ -975,16 +1036,12 @@
gsize data_size;
const char *mime;
GFile *f;
- GFileInfo *finfo;
fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
(gtk_builder_get_object
(ctx->builder,
"GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button")));
f = g_file_new_for_path (fn);
- finfo =
- g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL,
- NULL);
if (! g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -992,15 +1049,12 @@
}
else
{
- mime =
- g_file_info_get_attribute_string (finfo,
-
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+ mime = get_mime_type (data, data_size);
GNUNET_CONTAINER_meta_data_insert (meta, "<user>",
EXTRACTOR_METATYPE_THUMBNAIL,
EXTRACTOR_METAFORMAT_BINARY, mime,
data, data_size);
}
- g_object_unref (finfo);
g_object_unref (f);
g_free (fn);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24229 - gnunet-gtk/src/fs,
gnunet <=