X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=backend%2Fcomics%2Fcomics-document.c;h=dc5a8b0dde79300b24ed5888bb8c0800ab40e00b;hb=0b6b3dff626d31a368ef9a95f8ed73b404eec9bf;hp=8c3b00c38a0345af2b761715a7e7565152718d3d;hpb=31e16bd8f386dc292e60489d4a17227804bdc2e6;p=evince.git diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 8c3b00c3..dc5a8b0d 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -19,10 +19,11 @@ #include "config.h" +#include #include #include -#include -#include +#include +#include #include "comics-document.h" #include "ev-document-misc.h" @@ -63,8 +64,8 @@ static char** extract_argv (EvDocument *document, EV_BACKEND_REGISTER_WITH_CODE (ComicsDocument, comics_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - comics_document_document_thumbnails_iface_init); + EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, + comics_document_document_thumbnails_iface_init); } ); static char * @@ -84,6 +85,8 @@ comics_regex_quote (const char *s) case ']': case '*': case '\\': + *d++ = '\\'; + break; case '\'': *d++ = '\''; *d++ = '\\'; @@ -106,33 +109,67 @@ comics_document_load (EvDocument *document, { ComicsDocument *comics_document = COMICS_DOCUMENT (document); GSList *supported_extensions; - gchar *list_files_command = NULL, *std_out, *quoted_file, *mime_type; + gchar *list_files_command = NULL, *std_out, *quoted_file; + gchar *mime_type; gchar **cbr_files; gboolean success; int i, retval; + GError *err = NULL; comics_document->archive = g_filename_from_uri (uri, NULL, error); - g_return_val_if_fail (comics_document->archive != NULL, FALSE); + if (!comics_document->archive) + return FALSE; + + mime_type = ev_file_get_mime_type (uri, FALSE, &err); + if (!mime_type) { + if (err) { + g_propagate_error (error, err); + } else { + g_set_error_literal (error, + EV_DOCUMENT_ERROR, + EV_DOCUMENT_ERROR_INVALID, + _("Unknown MIME Type")); + } + + return FALSE; + } quoted_file = g_shell_quote (comics_document->archive); - mime_type = gnome_vfs_get_mime_type (uri); /* FIXME, use proper cbr/cbz mime types once they're * included in shared-mime-info */ - if (!strcmp (mime_type, "application/x-cbr")) { + if (!strcmp (mime_type, "application/x-cbr") || + !strcmp (mime_type, "application/x-rar")) { comics_document->extract_command = g_strdup ("unrar p -c- -ierr"); list_files_command = g_strdup_printf ("unrar vb -c- -- %s", quoted_file); comics_document->regex_arg = FALSE; - } else if (!strcmp (mime_type, "application/x-cbz")) { + } else if (!strcmp (mime_type, "application/x-cbz") || + !strcmp (mime_type, "application/zip")) { comics_document->extract_command = g_strdup ("unzip -p -C"); list_files_command = g_strdup_printf ("zipinfo -1 -- %s", quoted_file); comics_document->regex_arg = TRUE; + } else if (!strcmp (mime_type, "application/x-cb7")) { + comics_document->extract_command = + g_strdup ("7zr x -so"); + list_files_command = + g_strdup_printf ("7zr l -- %s", quoted_file); + comics_document->regex_arg = TRUE; + } else { + g_set_error (error, + EV_DOCUMENT_ERROR, + EV_DOCUMENT_ERROR_INVALID, + _("Not a comic book MIME type: %s"), + mime_type); + g_free (mime_type); + g_free (quoted_file); + return FALSE; } + g_free (mime_type); g_free (quoted_file); /* Get list of files in archive */ @@ -141,18 +178,27 @@ comics_document_load (EvDocument *document, g_free (list_files_command); if (!success) { - g_free (mime_type); return FALSE; } else if (retval != 0) { - g_set_error (error, - EV_DOCUMENT_ERROR, - EV_DOCUMENT_ERROR_INVALID, - _("File corrupted.")); - g_free (mime_type); + g_set_error_literal (error, + EV_DOCUMENT_ERROR, + EV_DOCUMENT_ERROR_INVALID, + _("File corrupted.")); return FALSE; } + /* FIXME: is this safe against filenames containing \n in the archive ? */ cbr_files = g_strsplit (std_out, "\n", 0); + g_free (std_out); + + if (!cbr_files) { + g_set_error_literal (error, + EV_DOCUMENT_ERROR, + EV_DOCUMENT_ERROR_INVALID, + _("No files in archive.")); + return FALSE; + } + supported_extensions = get_supported_image_extensions (); for (i = 0; cbr_files[i] != NULL; i++) { gchar *suffix = g_strrstr (cbr_files[i], "."); @@ -173,8 +219,6 @@ comics_document_load (EvDocument *document, g_free (suffix); } - g_free (std_out); - g_free (mime_type); g_strfreev (cbr_files); g_slist_foreach (supported_extensions, (GFunc) g_free, NULL); g_slist_free (supported_extensions); @@ -210,7 +254,7 @@ comics_document_get_n_pages (EvDocument *document) static void comics_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { @@ -221,7 +265,7 @@ comics_document_get_page_size (EvDocument *document, gint outpipe = -1; GPid child_pid = -1; - argv = extract_argv (document, page); + argv = extract_argv (document, page->index); success = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, @@ -279,7 +323,7 @@ comics_document_render_pixbuf (EvDocument *document, gint outpipe = -1; GPid child_pid = -1; - argv = extract_argv (document, rc->page); + argv = extract_argv (document, rc->page->index); success = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,