mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 22:43:46 +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
@ -99,8 +99,14 @@ guess_type_magic(zathura_content_type_context_t* context, const char* path)
|
|||||||
}
|
}
|
||||||
girara_debug("magic detected filetype: %s", mime_type);
|
girara_debug("magic detected filetype: %s", mime_type);
|
||||||
|
|
||||||
/* dup so we own the memory */
|
char* content_type = g_content_type_from_mime_type(mime_type);
|
||||||
return g_strdup(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 content_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
@ -143,7 +149,16 @@ guess_type_file(const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_strdelimit(out, "\n\r", '\0');
|
g_strdelimit(out, "\n\r", '\0');
|
||||||
return out;
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new context for MIME type detection.
|
* Create new context for content type detection.
|
||||||
*
|
*
|
||||||
* @return new context
|
* @return new context
|
||||||
*/
|
*/
|
||||||
zathura_content_type_context_t* zathura_content_type_new(void);
|
zathura_content_type_context_t* zathura_content_type_new(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free MIME type detection context.
|
* Free content type detection context.
|
||||||
*
|
*
|
||||||
* @param context The 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 */
|
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 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 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);
|
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
|
// register mime types
|
||||||
for (size_t s = 0; s != plugin_definition->mime_types_size; ++s) {
|
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);
|
bool ret = register_plugin(plugin_manager, plugin);
|
||||||
@ -328,13 +328,18 @@ zathura_plugin_free(zathura_plugin_t* plugin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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) {
|
if (plugin == NULL || mime_type == NULL) {
|
||||||
return;
|
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*
|
zathura_plugin_functions_t*
|
||||||
|
Loading…
Reference in New Issue
Block a user