]> www.fi.muni.cz Git - evince.git/blobdiff - comics/comics-document.c
Updated Dzongkha translations
[evince.git] / comics / comics-document.c
index aa7236a46afaa5ec12e39efd543a4bc1dd347ec8..7f53f85a1da0374307ec321a078cb76cbbab9232 100644 (file)
@@ -21,7 +21,6 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-xfer.h>
 
 #include "comics-document.h"
 #include "ev-document-misc.h"
@@ -40,6 +39,7 @@ struct _ComicsDocument
        GSList *page_names;
        int     n_pages;
        char   *extract_command;
+       gboolean regex_arg;
 };
 
 typedef struct _ComicsDocumentClass ComicsDocumentClass;
@@ -67,6 +67,36 @@ G_DEFINE_TYPE_WITH_CODE (
                                       comics_document_document_thumbnails_iface_init);
        } );
 
+static char *
+comics_regex_quote (const char *s)
+{
+    char *ret, *d;
+
+    d = ret = g_malloc (strlen (s) * 2 + 3);
+    
+    *d++ = '\'';
+
+    for (; *s; s++, d++) {
+       switch (*s) {
+       case '?':
+       case '|':
+       case '[':
+       case ']':
+       case '*':
+       case '\\':
+       case '\'':
+           *d++ = '\\';
+           break;
+       }
+       *d = *s;
+    }
+    
+    *d++ = '\'';
+    *d = '\0';
+
+    return ret;
+}
+
 static gboolean
 comics_document_load (EvDocument *document,
                      const char *uri,
@@ -87,16 +117,18 @@ comics_document_load (EvDocument *document,
 
        /* FIXME, use proper cbr/cbz mime types once they're
         * included in shared-mime-info */
-       if (!strcmp (mime_type, "application/cbr")) {
+       if (!strcmp (mime_type, "application/x-cbr")) {
                comics_document->extract_command =
                        g_strdup ("unrar p -c- -ierr");
                list_files_command =
                        g_strdup_printf ("unrar vb -c- -- %s", quoted_file);
-       } else if (!strcmp (mime_type, "application/cbz")) {
+               comics_document->regex_arg = FALSE;
+       } else if (!strcmp (mime_type, "application/x-cbz")) {
                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;
        }
 
        g_free (quoted_file);
@@ -164,22 +196,8 @@ comics_document_save (EvDocument *document,
                      GError    **error)
 {
        ComicsDocument *comics_document = COMICS_DOCUMENT (document);
-       GnomeVFSURI *source, *target;
-       GnomeVFSResult ret;
-       source = gnome_vfs_uri_new (comics_document->archive);
-       target = gnome_vfs_uri_new (uri);
-
-       ret = gnome_vfs_xfer_uri (source, target,
-                                 GNOME_VFS_XFER_DEFAULT,
-                                 GNOME_VFS_XFER_ERROR_MODE_ABORT,
-                                 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-                                 NULL, NULL);
-
-       gnome_vfs_uri_unref (source);
-       gnome_vfs_uri_unref (target);
-
-       return ret == GNOME_VFS_OK;
+
+       return ev_xfer_uri_simple (comics_document->archive, uri, error);
 }
 
 static int
@@ -470,8 +488,13 @@ extract_argv (EvDocument *document, gint page)
        char *command_line, *quoted_archive, *quoted_filename;
 
        quoted_archive = g_shell_quote (comics_document->archive);
-       quoted_filename = g_shell_quote (
-               g_slist_nth_data (comics_document->page_names, page));
+       if (comics_document->regex_arg) {
+               quoted_filename = comics_regex_quote (
+                       g_slist_nth_data (comics_document->page_names, page));
+       } else {
+               quoted_filename = g_shell_quote (
+                       g_slist_nth_data (comics_document->page_names, page));
+       }
 
        command_line = g_strdup_printf ("%s -- %s %s",
                                        comics_document->extract_command,