mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 22:53:47 +01:00
Re-try with different methods if content type is not supported
This commit is contained in:
parent
c998ad32b1
commit
43144b23e8
@ -213,19 +213,36 @@ guess_type_glib(const char* path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int compare_content_types(const void* lhs, const void* rhs) {
|
||||
return g_strcmp0(lhs, rhs);
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_content_type_guess(zathura_content_type_context_t* context,
|
||||
const char* path)
|
||||
const char* path,
|
||||
const girara_list_t* supported_content_types)
|
||||
{
|
||||
/* try libmagic first */
|
||||
char* content_type = guess_type_magic(context, path);
|
||||
char *content_type = guess_type_magic(context, path);
|
||||
if (content_type != NULL) {
|
||||
return content_type;
|
||||
if (supported_content_types == NULL ||
|
||||
girara_list_find(supported_content_types, compare_content_types,
|
||||
content_type) != NULL) {
|
||||
return content_type;
|
||||
}
|
||||
girara_debug("content type '%s' not supported, trying again", content_type);
|
||||
g_free(content_type);
|
||||
}
|
||||
/* else fallback to g_content_type_guess method */
|
||||
content_type = guess_type_glib(path);
|
||||
if (content_type != NULL) {
|
||||
return content_type;
|
||||
if (supported_content_types == NULL ||
|
||||
girara_list_find(supported_content_types, compare_content_types,
|
||||
content_type) != NULL) {
|
||||
return content_type;
|
||||
}
|
||||
girara_debug("content type '%s' not supported, trying again", content_type);
|
||||
g_free(content_type);
|
||||
}
|
||||
/* and if libmagic is not available, try file as last resort */
|
||||
return guess_type_file(path);
|
||||
|
@ -27,6 +27,7 @@ void zathura_content_type_free(zathura_content_type_context_t* context);
|
||||
* @return content type of path, needs to freeed with g_free.
|
||||
*/
|
||||
char* zathura_content_type_guess(zathura_content_type_context_t* context,
|
||||
const char* path);
|
||||
const char* path,
|
||||
const girara_list_t* supported_content_types);
|
||||
|
||||
#endif
|
||||
|
@ -90,7 +90,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
content_type = zathura_content_type_guess(zathura->content_type_context, real_path);
|
||||
content_type = zathura_content_type_guess(zathura->content_type_context, real_path, zathura_plugin_manager_get_content_types(zathura->plugins.manager));
|
||||
if (content_type == NULL) {
|
||||
girara_error("Could not determine file type.");
|
||||
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
||||
@ -98,7 +98,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||
}
|
||||
|
||||
plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type);
|
||||
|
||||
if (plugin == NULL) {
|
||||
girara_error("Unknown file type: '%s'", content_type);
|
||||
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
||||
|
@ -52,7 +52,7 @@ file_valid_extension(zathura_t* zathura, const char* path)
|
||||
return false;
|
||||
}
|
||||
|
||||
char* content_type = zathura_content_type_guess(zathura->content_type_context, path);
|
||||
char* content_type = zathura_content_type_guess(zathura->content_type_context, path, NULL);
|
||||
if (content_type == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user