X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=backend%2Fcomics%2Fcomics-document.c;h=dc5a8b0dde79300b24ed5888bb8c0800ab40e00b;hb=477fb0a0476397062474da7dfde512be22a950a8;hp=77e6fabd5a4d66d8aeef07c5fec5cb3e375ada4b;hpb=982600bbceb76a22d5c7b3e0cbe6e20421105ad6;p=evince.git diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 77e6fabd..dc5a8b0d 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -17,14 +17,18 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + +#include #include #include -#include -#include +#include +#include #include "comics-document.h" #include "ev-document-misc.h" #include "ev-document-thumbnails.h" +#include "ev-file-helpers.h" struct _ComicsDocumentClass { @@ -58,13 +62,10 @@ static char** extract_argv (EvDocument *document, gint page); -G_DEFINE_TYPE_WITH_CODE ( - ComicsDocument, comics_document, G_TYPE_OBJECT, +EV_BACKEND_REGISTER_WITH_CODE (ComicsDocument, comics_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - comics_document_document_iface_init); - 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,53 +109,96 @@ comics_document_load (EvDocument *document, { ComicsDocument *comics_document = COMICS_DOCUMENT (document); GSList *supported_extensions; - gchar *list_files_command = NULL, *stdout, *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 */ success = g_spawn_command_line_sync (list_files_command, - &stdout, NULL, &retval, error); + &std_out, NULL, &retval, error); 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; } - cbr_files = g_strsplit (stdout, "\n", 0); 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 (stdout); - 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,