aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk_publish-edit-dialog.c')
-rw-r--r--src/fs/gnunet-fs-gtk_publish-edit-dialog.c70
1 files changed, 62 insertions, 8 deletions
diff --git a/src/fs/gnunet-fs-gtk_publish-edit-dialog.c b/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
index 9cf1eac4..9fa89481 100644
--- a/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
+++ b/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
@@ -874,6 +874,67 @@ preserve_meta_items (void *cls, const char *plugin_name,
874 874
875 875
876/** 876/**
877 * Type of a function that libextractor calls for each
878 * meta data item found. Used to get the mime type.
879 *
880 * @param cls pointer to where to store the mime type.
881 * @param plugin_name name of the plugin that produced this value;
882 * special values can be used (i.e. '<zlib>' for zlib being
883 * used in the main libextractor library and yielding
884 * meta data).
885 * @param type libextractor-type describing the meta data
886 * @param format basic format information about data
887 * @param data_mime_type mime-type of data (not of the original file);
888 * can be NULL (if mime-type is not known)
889 * @param data actual meta-data found
890 * @param data_len number of bytes in data
891 * @return 0 to continue extracting, 1 to abort
892 */
893static int
894le_callback (void *cls,
895 const char *plugin_name,
896 enum EXTRACTOR_MetaType type,
897 enum EXTRACTOR_MetaFormat format,
898 const char *data_mime_type,
899 const char *data,
900 size_t data_len)
901{
902 char **ret = cls;
903
904 if ( (EXTRACTOR_METATYPE_MIMETYPE == type) &&
905 (EXTRACTOR_METAFORMAT_BINARY != format) )
906 {
907 *ret = GNUNET_strdup (data);
908 return 1;
909 }
910 return 0;
911}
912
913
914/**
915 * Use GNU libextractor to get the mime type for the given data.
916 *
917 * @param data binary data of the file
918 * @param data_size number of bytes in 'data'
919 */
920static char *
921get_mime_type (const void *data,
922 gsize data_size)
923{
924 char *ret;
925 struct EXTRACTOR_PluginList *pl;
926
927 pl = EXTRACTOR_plugin_add (NULL, "mime", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY);
928 if (NULL == pl)
929 return NULL;
930 ret = NULL;
931 EXTRACTOR_extract (pl, NULL, data, data_size, &le_callback, &ret);
932 EXTRACTOR_plugin_remove_all (pl);
933 return ret;
934}
935
936
937/**
877 * Function called to update the information in FI based on the changes made in 938 * Function called to update the information in FI based on the changes made in
878 * the edit dialog. 939 * the edit dialog.
879 * 940 *
@@ -975,16 +1036,12 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
975 gsize data_size; 1036 gsize data_size;
976 const char *mime; 1037 const char *mime;
977 GFile *f; 1038 GFile *f;
978 GFileInfo *finfo;
979 1039
980 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER 1040 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
981 (gtk_builder_get_object 1041 (gtk_builder_get_object
982 (ctx->builder, 1042 (ctx->builder,
983 "GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button"))); 1043 "GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button")));
984 f = g_file_new_for_path (fn); 1044 f = g_file_new_for_path (fn);
985 finfo =
986 g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL,
987 NULL);
988 if (! g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL)) 1045 if (! g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL))
989 { 1046 {
990 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1047 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -992,15 +1049,12 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
992 } 1049 }
993 else 1050 else
994 { 1051 {
995 mime = 1052 mime = get_mime_type (data, data_size);
996 g_file_info_get_attribute_string (finfo,
997 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
998 GNUNET_CONTAINER_meta_data_insert (meta, "<user>", 1053 GNUNET_CONTAINER_meta_data_insert (meta, "<user>",
999 EXTRACTOR_METATYPE_THUMBNAIL, 1054 EXTRACTOR_METATYPE_THUMBNAIL,
1000 EXTRACTOR_METAFORMAT_BINARY, mime, 1055 EXTRACTOR_METAFORMAT_BINARY, mime,
1001 data, data_size); 1056 data, data_size);
1002 } 1057 }
1003 g_object_unref (finfo);
1004 g_object_unref (f); 1058 g_object_unref (f);
1005 g_free (fn); 1059 g_free (fn);
1006 } 1060 }