mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 14:35:59 +01:00
Convert all MIME types to glib "content" types
On Linux they are the same, but somewhere else they might be different.
This commit is contained in:
parent
49e1bd1b8c
commit
4ea9d46584
3 changed files with 29 additions and 9 deletions
|
@ -99,8 +99,14 @@ guess_type_magic(zathura_content_type_context_t* context, const char* path)
|
|||
}
|
||||
girara_debug("magic detected filetype: %s", mime_type);
|
||||
|
||||
char* content_type = g_content_type_from_mime_type(mime_type);
|
||||
if (content_type == NULL) {
|
||||
girara_warning("failed to convert mime type to content type: %s", mime_type);
|
||||
/* dup so we own the memory */
|
||||
return g_strdup(mime_type);;
|
||||
return g_strdup(mime_type);
|
||||
}
|
||||
|
||||
return content_type;
|
||||
}
|
||||
|
||||
static char*
|
||||
|
@ -143,7 +149,16 @@ guess_type_file(const char* path)
|
|||
}
|
||||
|
||||
g_strdelimit(out, "\n\r", '\0');
|
||||
girara_debug("file detected filetype: %s", out);
|
||||
|
||||
char* content_type = g_content_type_from_mime_type(out);
|
||||
if (content_type == NULL) {
|
||||
girara_warning("failed to convert mime type to content type: %s", out);
|
||||
return out;
|
||||
}
|
||||
|
||||
g_free(out);
|
||||
return content_type;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
#include "types.h"
|
||||
|
||||
/**
|
||||
* Create new context for MIME type detection.
|
||||
* Create new context for content type detection.
|
||||
*
|
||||
* @return new context
|
||||
*/
|
||||
zathura_content_type_context_t* zathura_content_type_new(void);
|
||||
|
||||
/**
|
||||
* Free MIME type detection context.
|
||||
* Free content type detection context.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,7 @@ struct zathura_plugin_manager_s {
|
|||
girara_list_t* type_plugin_mapping; /**< List of type -> plugin mappings */
|
||||
};
|
||||
|
||||
static void zathura_plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type);
|
||||
static void plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type);
|
||||
static bool register_plugin(zathura_plugin_manager_t* plugin_manager, zathura_plugin_t* plugin);
|
||||
static bool plugin_mapping_new(zathura_plugin_manager_t* plugin_manager, const gchar* type, zathura_plugin_t* plugin);
|
||||
static void zathura_plugin_free(zathura_plugin_t* plugin);
|
||||
|
@ -159,7 +159,7 @@ load_plugin(zathura_plugin_manager_t* plugin_manager, const char* plugindir, con
|
|||
|
||||
// register mime types
|
||||
for (size_t s = 0; s != plugin_definition->mime_types_size; ++s) {
|
||||
zathura_plugin_add_mimetype(plugin, plugin_definition->mime_types[s]);
|
||||
plugin_add_mimetype(plugin, plugin_definition->mime_types[s]);
|
||||
}
|
||||
|
||||
bool ret = register_plugin(plugin_manager, plugin);
|
||||
|
@ -328,13 +328,18 @@ zathura_plugin_free(zathura_plugin_t* plugin)
|
|||
}
|
||||
|
||||
static void
|
||||
zathura_plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type)
|
||||
plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type)
|
||||
{
|
||||
if (plugin == NULL || mime_type == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
girara_list_append(plugin->content_types, g_content_type_from_mime_type(mime_type));
|
||||
char* content_type = g_content_type_from_mime_type(mime_type);
|
||||
if (content_type == NULL) {
|
||||
girara_warning("plugin: unable to convert mime type: %s", mime_type);
|
||||
} else {
|
||||
girara_list_append(plugin->content_types, content_type);
|
||||
}
|
||||
}
|
||||
|
||||
zathura_plugin_functions_t*
|
||||
|
|
Loading…
Reference in a new issue