28 #include <glib/gstdio.h>
29 #include <glib/gi18n-lib.h>
41 #define BACKEND_DATA_KEY "ev-backend-info"
57 char **mime_types = info->mime_types;
60 for (i = 0; mime_types[i] != NULL; ++i) {
61 if (g_ascii_strcasecmp (mime_type, mime_types[i]) == 0)
76 g_warn_if_fail (info != NULL);
86 GTypeModule *module = NULL;
88 g_return_val_if_fail (mime_type != NULL, NULL);
92 char *content_type, *mime_desc = NULL;
94 content_type = g_content_type_from_mime_type (mime_type);
96 mime_desc = g_content_type_get_description (content_type);
101 _(
"File type %s (%s) is not supported"),
102 mime_desc ? mime_desc :
"(unknown)", mime_type);
104 g_free (content_type);
112 if (module == NULL) {
124 g_hash_table_insert (
ev_module_hash, g_strdup (info->module_name), module);
127 if (!g_type_module_use (module)) {
130 err = g_module_error ();
132 "Failed to load backend for '%s': %s",
133 mime_type, err ? err :
"unknown error");
138 g_type_module_unuse (module);
153 if (!(p = g_strrstr (mime_type,
"/")))
156 if (sscanf (++p,
"x-%2s%*s", type) == 1) {
157 if (g_ascii_strcasecmp (type,
"gz") == 0)
159 else if (g_ascii_strcasecmp (type,
"bz") == 0)
161 else if (g_ascii_strcasecmp (type,
"xz") == 0)
190 gchar *mime_type = NULL;
195 if (mime_type == NULL)
199 if (document == NULL)
236 dir = g_win32_get_package_installation_directory_of_module (NULL);
238 EV_BACKENDSBINARYVERSION,
294 gchar *uri_unc = NULL;
297 g_return_val_if_fail (uri != NULL, NULL);
300 g_assert (document != NULL || err != NULL);
302 if (document != NULL) {
305 g_object_set_data_full (G_OBJECT (document),
309 }
else if (err != NULL) {
311 g_object_unref (document);
312 g_propagate_error (error, err);
318 if (result ==
FALSE || err) {
321 g_propagate_error (error, err);
329 g_object_unref (document);
334 g_clear_error (&err);
338 if (document == NULL) {
339 g_assert (err != NULL);
340 g_propagate_error (error, err);
346 g_object_set_data_full (G_OBJECT (document),
350 }
else if (err != NULL) {
352 g_propagate_error (error, err);
354 g_object_unref (document);
360 if (result ==
FALSE) {
365 g_set_error_literal (&err,
368 _(
"Unknown MIME Type"));
370 g_propagate_error (error, err);
374 g_object_unref (document);
377 g_propagate_error (error, err);
424 GCancellable *cancellable,
428 GFileInfo *file_info;
429 const char *content_type;
430 char *mime_type = NULL;
432 g_return_val_if_fail (G_IS_FILE (file), NULL);
433 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
436 file_info = g_file_query_info (file,
437 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
438 G_FILE_QUERY_INFO_NONE,
441 if (file_info == NULL)
444 content_type = g_file_info_get_content_type (file_info);
445 if (content_type == NULL) {
446 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
447 "Failed to query file mime type");
451 mime_type = g_content_type_get_mime_type (content_type);
452 g_object_unref (file_info);
456 if (document == NULL)
460 g_object_unref (document);
491 const char *mime_type,
493 GCancellable *cancellable,
499 g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
500 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
502 if (mime_type == NULL && G_IS_FILE_INPUT_STREAM (stream)) {
503 GFileInfo *file_info;
504 const char *content_type;
506 file_info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (stream),
507 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
510 if (file_info != NULL) {
511 content_type = g_file_info_get_content_type (file_info);
513 mime_type = mime = g_content_type_get_mime_type (content_type);
514 g_object_unref (file_info);
518 if (mime_type == NULL) {
519 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
520 "Cannot query mime type from stream");
527 if (document == NULL)
531 g_object_unref (document);
544 mime_types = info->mime_types;
545 if (mime_types == NULL)
548 for (i = 0; mime_types[i] != NULL; ++i)
549 gtk_file_filter_add_mime_type (filter, mime_types[i]);
569 GtkFileFilter *filter;
570 GtkFileFilter *default_filter;
571 GtkFileFilter *document_filter;
573 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
576 default_filter = document_filter = filter = gtk_file_filter_new ();
577 gtk_file_filter_set_name (filter,
_(
"All Documents"));
579 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
585 g_assert (info != NULL);
586 default_filter = filter = gtk_file_filter_new ();
587 gtk_file_filter_set_name (filter, info->type_desc);
589 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
596 default_filter = filter = gtk_file_filter_new ();
597 gtk_file_filter_set_name (filter, info->type_desc);
599 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
603 filter = gtk_file_filter_new ();
604 gtk_file_filter_set_name (filter,
_(
"All Files"));
605 gtk_file_filter_add_pattern (filter,
"*");
606 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
608 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser),
609 document == NULL ? document_filter : default_filter);
632 return info->module_name;