]> www.fi.muni.cz Git - evince.git/commitdiff
New CBR/CBZ backend for comic books.
authorNickolay V. Shmyrev <nshmyrev@yandex.ru>
Mon, 14 Nov 2005 13:21:13 +0000 (13:21 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Mon, 14 Nov 2005 13:21:13 +0000 (13:21 +0000)
2005-11-14  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>

* Makefile.am:
* backend/Makefile.am:
* backend/ev-document-factory.c:
* backend/ev-document-factory.h:
* comics/Makefile.am:
* comics/comics-document.c: (G_DEFINE_TYPE_WITH_CODE),
(comics_document_load), (comics_document_save),
(comics_document_get_n_pages), (comics_document_get_page_size),
(get_page_size_area_prepared_cb), (comics_document_render_pixbuf) (render_pixbuf_size_prepared_cb), (comics_document_finalize),
(comics_document_class_init), (comics_document_can_get_text),
(comics_document_get_info), (comics_document_document_iface_init),
(comics_document_init), (get_supported_image_extensions),
(comics_document_thumbnails_get_geometry),
(comics_document_thumbnails_get_thumbnail),
(comics_document_thumbnails_get_dimensions),
(comics_document_document_thumbnails_iface_init), (extract_argv):
* comics/comics-document.h:
* comics/ev-cbr-mime.xml:
* configure.ac:
* po/POTFILES.in:
* shell/ev-application.c: (ev_application_register_service):
* shell/ev-document-types.c: (ev_document_types_add_filters):
* thumbnailer/Makefile.am:
* thumbnailer/evince-thumbnailer-comics.schemas.in:

New CBR/CBZ backend for comic books.

15 files changed:
ChangeLog
Makefile.am
backend/Makefile.am
backend/ev-document-factory.c
backend/ev-document-factory.h
comics/Makefile.am [new file with mode: 0644]
comics/comics-document.c [new file with mode: 0644]
comics/comics-document.h [new file with mode: 0644]
comics/ev-cbr-mime.xml [new file with mode: 0644]
configure.ac
po/POTFILES.in
shell/ev-application.c
shell/ev-document-types.c
thumbnailer/Makefile.am
thumbnailer/evince-thumbnailer-comics.schemas.in [new file with mode: 0644]

index 15f7929e62f62f09b26b2815f0b55884bdb851d5..a1d988109c7caceb5cb442aaf9e5217134af2dd2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2005-11-14  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
+
+       * Makefile.am:
+       * backend/Makefile.am:
+       * backend/ev-document-factory.c:
+       * backend/ev-document-factory.h:
+       * comics/Makefile.am:
+       * comics/comics-document.c: (G_DEFINE_TYPE_WITH_CODE),
+       (comics_document_load), (comics_document_save),
+       (comics_document_get_n_pages), (comics_document_get_page_size),
+       (get_page_size_area_prepared_cb), (comics_document_render_pixbuf)       (render_pixbuf_size_prepared_cb), (comics_document_finalize),
+       (comics_document_class_init), (comics_document_can_get_text),
+       (comics_document_get_info), (comics_document_document_iface_init),
+       (comics_document_init), (get_supported_image_extensions),
+       (comics_document_thumbnails_get_geometry),
+       (comics_document_thumbnails_get_thumbnail),
+       (comics_document_thumbnails_get_dimensions),
+       (comics_document_document_thumbnails_iface_init), (extract_argv):
+       * comics/comics-document.h:
+       * comics/ev-cbr-mime.xml:
+       * configure.ac:
+       * po/POTFILES.in:
+       * shell/ev-application.c: (ev_application_register_service):
+       * shell/ev-document-types.c: (ev_document_types_add_filters):
+       * thumbnailer/Makefile.am:
+       * thumbnailer/evince-thumbnailer-comics.schemas.in:
+       
+       New CBR/CBZ backend for comic books.
+
 2005-11-10  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * shell/main.c: (load_files_remote):
index d748d98ea2fad81b26851754df6bdb438d0c65c8..5acc74fdfa89707116283307ed4329ba354a9b13 100644 (file)
@@ -20,6 +20,10 @@ if ENABLE_DVI
 SUBDIRS += dvi
 endif
 
+if ENABLE_COMICS
+     SUBDIRS += comics
+endif
+
 SUBDIRS += backend
 
 # Library
index 917215a529df10313833584c3033eb8e97540ae2..75509e69610031c335bd2dcaea710c809e858495 100644 (file)
@@ -7,6 +7,7 @@ INCLUDES=                                       \
        -I$(top_srcdir)/ps                      \
        -I$(top_srcdir)/djvu                    \
        -I$(top_srcdir)/dvi                     \
+       -I$(top_srcdir)/comics                  \
        $(BACKEND_CFLAGS)                       \
        $(WARN_CFLAGS)                          \
        $(DISABLE_DEPRECATED)
@@ -67,6 +68,11 @@ libevbackend_la_LIBADD +=                    \
        $(top_builddir)/dvi/libgtkdvi.la
 endif
 
+if ENABLE_COMICS
+libevbackend_la_LIBADD +=                      \
+       $(top_builddir)/comics/libcomicsdocument.la
+endif
+
 BUILT_SOURCES=                         \
        ev-backend-marshalers.h         \
        ev-backend-marshalers.c
index 0f85c7c5ee4bc649fce94f16ac0a9ec7a2dfa850..7fed2b9a6b2ca5b88cbc95807c1757da7d331541 100644 (file)
@@ -35,6 +35,9 @@
 #ifdef ENABLE_DJVU
 #include "djvu-document.h"
 #endif
+#ifdef ENABLE_COMICS
+#include "comics-document.h"
+#endif
 
 #include <string.h>
 
@@ -69,6 +72,12 @@ const EvDocumentType document_types[] = {
        /* dvi: */
        {"application/x-dvi",          EV_BACKEND_DVI,  dvi_document_get_type},
 #endif
+
+#ifdef ENABLE_DVI
+       /* cbr/cbz: */
+       {"application/cbr",           EV_BACKEND_COMICS,  comics_document_get_type},
+       {"application/cbz",           EV_BACKEND_COMICS,  comics_document_get_type},
+#endif
 };
 
 #ifdef ENABLE_PIXBUF
index 56be46d539a193790dbe6a450b531a3731c977e1..f299730686d64a202aec709ec48140c3f7f00183 100644 (file)
@@ -31,7 +31,8 @@ typedef enum {
        EV_BACKEND_TIFF,
        EV_BACKEND_PIXBUF,
        EV_BACKEND_DJVU,
-       EV_BACKEND_DVI
+       EV_BACKEND_DVI,
+       EV_BACKEND_COMICS
 } EvBackend;
 
 EvDocument *ev_document_factory_get_document           (const char *mime_type);
diff --git a/comics/Makefile.am b/comics/Makefile.am
new file mode 100644 (file)
index 0000000..22c9290
--- /dev/null
@@ -0,0 +1,25 @@
+INCLUDES =                      \
+       -I$(top_srcdir)         \
+       -I$(top_srcdir)/backend \
+       -I$(top_srcdir)/lib     \
+       $(LIB_CFLAGS)
+
+noinst_LTLIBRARIES = libcomicsdocument.la
+
+libcomicsdocument_la_SOURCES = \
+       comics-document.c      \
+       comics-document.h
+
+# need to respect $XDG_DATA_DIR probably
+xdgmimedir = $(gnome_data)/mime/packages
+xdgmime_DATA = ev-cbr-mime.xml
+
+EXTRA_DIST = $(xdgmime_DATA)
+
+install-data-hook:
+       update-mime-database $(gnome_data)/mime
+
+uninstall-hook:
+       update-mime-database $(gnome_data)/mime
+
+
diff --git a/comics/comics-document.c b/comics/comics-document.c
new file mode 100644 (file)
index 0000000..aa7236a
--- /dev/null
@@ -0,0 +1,486 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ * Copyright (C) 2005, Teemu Tervo <teemu.tervo@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <unistd.h>
+#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"
+#include "ev-document-thumbnails.h"
+
+struct _ComicsDocumentClass
+{
+       GObjectClass parent_class;
+};
+
+struct _ComicsDocument
+{
+       GObject parent_instance;
+
+       gchar  *archive;
+       GSList *page_names;
+       int     n_pages;
+       char   *extract_command;
+};
+
+typedef struct _ComicsDocumentClass ComicsDocumentClass;
+
+static void       comics_document_document_iface_init (EvDocumentIface *iface);
+static void       comics_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
+
+static GSList*    get_supported_image_extensions (void);
+static void       get_page_size_area_prepared_cb (GdkPixbufLoader *loader,
+                                                 gpointer data);
+static void       render_pixbuf_size_prepared_cb (GdkPixbufLoader *loader,
+                                                 gint width,
+                                                 gint height,
+                                                 gpointer data);
+static char**     extract_argv                   (EvDocument *document,
+                                                 gint page);
+
+
+G_DEFINE_TYPE_WITH_CODE (
+       ComicsDocument, comics_document, G_TYPE_OBJECT,
+       {
+               G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
+                                      comics_document_document_iface_init);
+               G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
+                                      comics_document_document_thumbnails_iface_init);
+       } );
+
+static gboolean
+comics_document_load (EvDocument *document,
+                     const char *uri,
+                     GError    **error)
+{
+       ComicsDocument *comics_document = COMICS_DOCUMENT (document);
+       GSList *supported_extensions;
+       gchar *list_files_command = NULL, *stdout, *quoted_file, *mime_type;
+       gchar **cbr_files;
+       gboolean success;
+       int i, retval;
+
+       comics_document->archive = g_filename_from_uri (uri, NULL, error);
+       g_return_val_if_fail (comics_document->archive != NULL, 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/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->extract_command =
+                       g_strdup ("unzip -p -C");
+               list_files_command = 
+                       g_strdup_printf ("zipinfo -1 -- %s", quoted_file);
+       }
+
+       g_free (quoted_file);
+
+       /* Get list of files in archive */
+       success = g_spawn_command_line_sync (list_files_command,
+                                            &stdout, 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);
+               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], ".");
+               if (!suffix)
+                       continue;
+               suffix = g_ascii_strdown (suffix + 1, -1);
+
+               if (g_slist_find_custom (supported_extensions, suffix,
+                                        (GCompareFunc) strcmp) != NULL) {
+                       comics_document->page_names =
+                               g_slist_insert_sorted (
+                                       comics_document->page_names,
+                                       g_strdup (g_strstrip (cbr_files[i])),
+                                       (GCompareFunc) strcmp);
+                       comics_document->n_pages++;
+               }
+
+               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);
+
+       if (comics_document->n_pages == 0) {
+               g_set_error (error,
+                            EV_DOCUMENT_ERROR,
+                            EV_DOCUMENT_ERROR_INVALID,
+                            _("No images found in archive %s"),
+                            uri);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+static gboolean
+comics_document_save (EvDocument *document,
+                     const char *uri,
+                     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;
+}
+
+static int
+comics_document_get_n_pages (EvDocument *document)
+{
+       return COMICS_DOCUMENT (document)->n_pages;
+}
+
+static void
+comics_document_get_page_size (EvDocument *document,
+                              int         page,
+                              double     *width,
+                              double     *height)
+{
+       GdkPixbufLoader *loader;
+       char **argv;
+       guchar buf[1024];
+       gboolean success, got_size = FALSE;
+       gint outpipe = -1;
+       GPid child_pid = -1;
+
+       argv = extract_argv (document, page);
+       success = g_spawn_async_with_pipes (NULL, argv, NULL,
+                                           G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
+                                           NULL, NULL,
+                                           &child_pid,
+                                           NULL, &outpipe, NULL, NULL);
+       g_strfreev (argv);
+       g_return_if_fail (success == TRUE);
+
+       loader = gdk_pixbuf_loader_new ();
+       g_signal_connect (loader, "area-prepared",
+                         G_CALLBACK (get_page_size_area_prepared_cb),
+                         &got_size);
+
+       while (outpipe >= 0) {
+               gssize bytes = read (outpipe, buf, 1024);
+               
+               if (bytes > 0)
+                       gdk_pixbuf_loader_write (loader, buf, bytes, NULL);
+               if (bytes <= 0 || got_size) {
+                       close (outpipe);
+                       outpipe = -1;
+                       gdk_pixbuf_loader_close (loader, NULL);
+               }
+       }
+
+       if (gdk_pixbuf_loader_get_pixbuf (loader)) {
+               GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+               if (width)
+                       *width = gdk_pixbuf_get_width (pixbuf);
+               if (height)
+                       *height = gdk_pixbuf_get_height (pixbuf);
+       }
+
+       g_spawn_close_pid (child_pid);
+       g_object_unref (loader);
+}
+
+static void
+get_page_size_area_prepared_cb (GdkPixbufLoader *loader,
+                               gpointer         data)
+{
+       gboolean *got_size = data;
+       *got_size = TRUE;
+}
+
+static GdkPixbuf *
+comics_document_render_pixbuf (EvDocument  *document,
+                              EvRenderContext *rc)
+{
+       GdkPixbufLoader *loader;
+       GdkPixbuf *rotated_pixbuf;
+       char **argv;
+       guchar buf[4096];
+       gboolean success;
+       gint outpipe = -1;
+       GPid child_pid = -1;
+
+       argv = extract_argv (document, rc->page);
+       success = g_spawn_async_with_pipes (NULL, argv, NULL,
+                                           G_SPAWN_SEARCH_PATH
+                                           | G_SPAWN_STDERR_TO_DEV_NULL,
+                                           NULL, NULL,
+                                           &child_pid,
+                                           NULL, &outpipe, NULL, NULL);
+       g_strfreev (argv);
+       g_return_val_if_fail (success == TRUE, NULL);
+
+       loader = gdk_pixbuf_loader_new ();
+       g_signal_connect (loader, "size-prepared",
+                         G_CALLBACK (render_pixbuf_size_prepared_cb), &rc->scale);
+
+       while (outpipe >= 0) {
+               gssize bytes = read (outpipe, buf, 4096);
+
+               if (bytes > 0) {
+                       gdk_pixbuf_loader_write (loader, buf, bytes, NULL);
+               } else if (bytes <= 0) {
+                       close (outpipe);
+                       gdk_pixbuf_loader_close (loader, NULL);
+                       outpipe = -1;
+               }
+       }
+
+       rotated_pixbuf = gdk_pixbuf_rotate_simple (gdk_pixbuf_loader_get_pixbuf (loader),
+                                                  360 - rc->rotation);
+       g_spawn_close_pid (child_pid);
+       g_object_unref (loader);
+       return rotated_pixbuf;
+}
+
+static void
+render_pixbuf_size_prepared_cb (GdkPixbufLoader *loader,
+                               gint             width,
+                               gint             height,
+                               gpointer         data)
+{
+       double *scale = data;
+       int w = width  * (*scale);
+       int h = height * (*scale);
+
+       gdk_pixbuf_loader_set_size (loader, w, h);
+}
+
+static void
+comics_document_finalize (GObject *object)
+{
+       ComicsDocument *comics_document = COMICS_DOCUMENT (object);
+
+       if (comics_document->archive)
+               g_free (comics_document->archive);
+
+       if (comics_document->page_names) {
+               g_slist_foreach (comics_document->page_names,
+                                (GFunc) g_free, NULL);
+               g_slist_free (comics_document->page_names);
+       }
+
+       if (comics_document->extract_command)
+               g_free (comics_document->extract_command);
+
+       G_OBJECT_CLASS (comics_document_parent_class)->finalize (object);
+}
+
+static void
+comics_document_class_init (ComicsDocumentClass *klass)
+{
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+       gobject_class->finalize = comics_document_finalize;
+}
+
+static gboolean
+comics_document_can_get_text (EvDocument *document)
+{
+       return FALSE;
+}
+
+static EvDocumentInfo *
+comics_document_get_info (EvDocument *document)
+{
+       EvDocumentInfo *info;
+       info = g_new0 (EvDocumentInfo, 1);
+       return info;
+}
+
+static void
+comics_document_document_iface_init (EvDocumentIface *iface)
+{
+       iface->load = comics_document_load;
+       iface->save = comics_document_save;
+       iface->can_get_text  = comics_document_can_get_text;
+       iface->get_n_pages   = comics_document_get_n_pages;
+       iface->get_page_size = comics_document_get_page_size;
+       iface->render_pixbuf = comics_document_render_pixbuf;
+       iface->get_info      = comics_document_get_info;
+}
+
+static void
+comics_document_init (ComicsDocument *comics_document)
+{
+       comics_document->archive = NULL;
+       comics_document->page_names = NULL;
+       comics_document->extract_command = NULL;
+       comics_document->n_pages = 0;
+}
+
+/* Returns a list of file extensions supported by gdk-pixbuf */
+static GSList*
+get_supported_image_extensions()
+{
+       GSList *extensions = NULL;
+       GSList *formats = gdk_pixbuf_get_formats ();
+       GSList *l;
+
+       for (l = formats; l != NULL; l = l->next) {
+               int i;
+               gchar **ext = gdk_pixbuf_format_get_extensions (l->data);
+
+               for (i = 0; ext[i] != NULL; i++) {
+                       extensions = g_slist_append (extensions,
+                                                    g_strdup (ext[i]));
+               }
+
+               g_strfreev (ext);
+       }
+
+       g_slist_free (formats);
+       return extensions;
+}
+
+static void 
+comics_document_thumbnails_get_geometry (EvDocumentThumbnails *document,
+                                        gint                  page,
+                                        gint                  suggested_width,
+                                        gint                 *width,
+                                        gint                 *height,
+                                        gdouble              *scale_factor)
+{
+       gdouble orig_width, orig_height, scale;
+
+       comics_document_get_page_size (EV_DOCUMENT (document), page,
+                                      &orig_width, &orig_height);
+       scale = suggested_width / orig_width;
+
+       if (width)
+               *width = suggested_width;
+       if (height)
+               *height = orig_height * scale;
+       if (scale_factor)
+               *scale_factor = scale;
+}
+
+static GdkPixbuf *
+comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
+                                       gint                  page,
+                                       gint                  rotation,
+                                       gint                  size,
+                                       gboolean              border)
+{
+       GdkPixbuf *thumbnail, *framed;
+       gint thumb_width, thumb_height;
+       gdouble scale;
+        EvRenderContext *rc;
+
+       comics_document_thumbnails_get_geometry (document, page, size,
+                                                &thumb_width, &thumb_height,
+                                                &scale);
+
+       rc = ev_render_context_new (rotation, page, scale);
+       thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document),
+                                                  rc);
+       g_object_unref (G_OBJECT (rc));
+
+       if (border) {
+             GdkPixbuf *tmp_pixbuf = thumbnail;
+             thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+             g_object_unref (tmp_pixbuf);
+       }
+
+       return thumbnail;
+}
+
+static void
+comics_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
+                                          gint                  page,
+                                          gint                  suggested_width,
+                                          gint                  *width,
+                                          gint                  *height)
+{
+       comics_document_thumbnails_get_geometry (document, page,
+                                                suggested_width,
+                                                width, height, NULL);
+}
+
+static void
+comics_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
+{
+       iface->get_thumbnail = comics_document_thumbnails_get_thumbnail;
+       iface->get_dimensions = comics_document_thumbnails_get_dimensions;
+}
+
+static char**
+extract_argv (EvDocument *document, gint page)
+{
+       ComicsDocument *comics_document = COMICS_DOCUMENT (document);
+       char **argv;
+       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));
+
+       command_line = g_strdup_printf ("%s -- %s %s",
+                                       comics_document->extract_command,
+                                       quoted_archive,
+                                       quoted_filename);
+       g_shell_parse_argv (command_line, NULL, &argv, NULL);
+
+       g_free (command_line);
+       g_free (quoted_archive);
+       g_free (quoted_filename);
+       return argv;
+}
diff --git a/comics/comics-document.h b/comics/comics-document.h
new file mode 100644 (file)
index 0000000..cd5b17b
--- /dev/null
@@ -0,0 +1,38 @@
+/* comics-document.h: Implementation of EvDocument for comic book archives
+ * Copyright (C) 2005, Teemu Tervo <teemu.tervo@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __COMICS_DOCUMENT_H__
+#define __COMICS_DOCUMENT_H__
+
+#include "ev-document.h"
+
+G_BEGIN_DECLS
+
+#define COMICS_TYPE_DOCUMENT    (comics_document_get_type ())
+#define COMICS_DOCUMENT(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), COMICS_TYPE_DOCUMENT, ComicsDocument))
+#define COMICS_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COMICS_TYPE_DOCUMENT))
+
+typedef struct _ComicsDocument ComicsDocument;
+
+ComicsDocument *comics_document_new       (void);
+
+GType           comics_document_get_type  (void) G_GNUC_CONST;
+     
+G_END_DECLS
+
+#endif /* __COMICS_DOCUMENT_H__ */
diff --git a/comics/ev-cbr-mime.xml b/comics/ev-cbr-mime.xml
new file mode 100644 (file)
index 0000000..8b1a54a
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
+    <mime-type type="application/cbr">
+      <comment>CBR document</comment>
+      <magic priority="50">
+        <match value="Rar!" type="string" offset="0"/>
+      </magic>
+      <glob pattern="*.cbr"/>
+    </mime-type>
+    <mime-type type="application/cbz">
+      <comment>CBZ document</comment>
+      <magic priority="50">
+        <match value="PK\003\004" type="string" offset="0"/>
+      </magic>
+      <glob pattern="*.cbz"/>
+    </mime-type>
+</mime-info>
+
index 375778f501685d090cb0c25cca669eafefdde14b..e72c105640ddc7e699e2caa3e5a450edd190d143 100644 (file)
@@ -47,7 +47,7 @@ POPPLER_REQUIRED=0.4.1
 DBUS_GLIB_REQUIRED=0.33
 GTK_REQUIRED=2.6.0
 LIBGNOMEUI_REQUIRED=2.6.0
-KEYRING_REQUIRED=0.4.2
+KEYRING_REQUIRED=0.4.0
 
 PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED)
 PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0)
@@ -264,7 +264,18 @@ if test "x$enable_pixbuf" = "xyes"; then
 fi
 AM_CONDITIONAL(ENABLE_PIXBUF, test x$enable_pixbuf = xyes)
 
-dnl ================== End of dvi checks ===================================================
+dnl ================== End of pixbuf checks ===================================================
+
+dnl ================== comic book checks ===================================================
+AC_ARG_ENABLE(comics,
+       [AC_HELP_STRING([--enable-comics], [Compile with support for comic book archives])],enable_comics=yes,enable_comics=no)
+if test "x$enable_comics" = "xyes"; then
+       AC_DEFINE([ENABLE_COMICS], [1], [Enable support for comics.])
+fi 
+AM_CONDITIONAL(ENABLE_COMICS, test x$enable_comics = xyes)
+
+dnl ================== End of comic book checks ============================================
 
 dnl =================== Mime types list ====================================================
 
@@ -279,6 +290,9 @@ fi
 if test "x$enable_tiff" = "xyes"; then
        EVINCE_MIME_TYPES="$EVINCE_MIME_TYPES;image/tiff"
 fi
+if test "x$enable_comics" = "xyes"; then
+       EVINCE_MIME_TYPES="$EVINCE_MIME_TYPES;application/cbr;application/cbz"
+fi
 AC_SUBST(EVINCE_MIME_TYPES)
 
 AC_CONFIG_FILES([
@@ -297,6 +311,7 @@ ps/Makefile
 djvu/Makefile
 dvi/Makefile
 dvi/mdvi-lib/Makefile
+comics/Makefile
 po/Makefile.in
 backend/Makefile
 properties/Makefile
index 0403b313f26298f85b260cf78c83d9c2dfff342b..c236cb325e7f7354522dbc5d9f048b31d0f52325 100644 (file)
@@ -1,6 +1,7 @@
 # List of source files containing translatable strings.
 # Please keep this file sorted alphabetically.
 [encoding: UTF-8]
+comics/comics-document.c
 cut-n-paste/toolbar-editor/egg-editable-toolbar.c
 cut-n-paste/toolbar-editor/egg-toolbar-editor.c
 cut-n-paste/zoom-control/ephy-zoom.h
index eed7be8b7cfd5596af9f9452f0a8150f71effc96..1b64c3dbc7701616470dd399faca4dc64cb4fa9e 100644 (file)
@@ -91,6 +91,9 @@ ev_application_register_service (EvApplication *application)
        dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
                                         &dbus_glib_ev_application_object_info);
 #endif
+#ifdef ENABLE_COMICS
+       GtkFileFilter *comics_filter;
+#endif
 
        dbus_g_connection_register_g_object (connection,
                                             "/org/gnome/evince/Evince",
index f1bf9c93fe366d8cbcf43dce98f3869e9ad78b66..ea729bfd8b6885eff765fc3e00a5e0b7555a4ecb 100644 (file)
@@ -181,6 +181,16 @@ ev_document_types_add_filters (GtkWidget *chooser, EvDocument *document)
        }
 #endif 
 
+#ifdef ENABLE_COMICS
+       if (document == NULL || backend == EV_BACKEND_COMICS) {
+               default_filter = filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (filter, _("Comics Books"));
+               mime_types = ev_document_factory_get_mime_types (EV_BACKEND_COMICS);
+               file_filter_add_mime_list_and_free (filter, mime_types);
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
+       }
+#endif 
+
        filter = gtk_file_filter_new ();
        gtk_file_filter_set_name (filter, _("All Files"));
        gtk_file_filter_add_pattern (filter, "*");
index 3512aa7885d48edbe638f9c4a7d0c43d5681fa7d..6bacca59b6f5b4b5d7e62e096f150205daae2fc9 100644 (file)
@@ -22,6 +22,7 @@ evince_thumbnailer_LDADD=                             \
 schema_files = \
        evince-thumbnailer-dvi.schemas.in  \
        evince-thumbnailer-djvu.schemas.in \
+       evince-thumbnailer-comics.schemas.in \
        evince-thumbnailer.schemas.in
 
 schema_DATA = evince-thumbnailer.schemas
@@ -34,6 +35,10 @@ if ENABLE_DVI
 schema_DATA += evince-thumbnailer-dvi.schemas
 endif
 
+if ENABLE_COMICS
+schema_DATA += evince-thumbnailer-comics.schemas
+endif
+
 schemadir = $(GCONF_SCHEMA_FILE_DIR)
 
 install-data-local:
diff --git a/thumbnailer/evince-thumbnailer-comics.schemas.in b/thumbnailer/evince-thumbnailer-comics.schemas.in
new file mode 100644 (file)
index 0000000..f9a4e0d
--- /dev/null
@@ -0,0 +1,55 @@
+<gconfschemafile>
+    <schemalist>
+
+        <schema>
+            <key>/schemas/desktop/gnome/thumbnailers/application@cbz/enable</key>
+            <applyto>/desktop/gnome/thumbnailers/application@cbz/enable</applyto>
+            <owner>evince</owner>
+            <type>bool</type>
+            <default>true</default>
+            <locale name="C">
+                <short></short>
+                <long></long>
+            </locale>
+        </schema>
+
+
+        <schema>
+            <key>/schemas/desktop/gnome/thumbnailers/application@cbz/command</key>
+            <applyto>/desktop/gnome/thumbnailers/application@cbz/command</applyto>
+            <owner>evince</owner>
+            <type>string</type>
+            <default>evince-thumbnailer -s %s %u %o</default>
+            <locale name="C">
+                <short></short>
+                <long></long>
+            </locale>
+        </schema>
+
+        <schema>
+            <key>/schemas/desktop/gnome/thumbnailers/application@cbr/enable</key>
+            <applyto>/desktop/gnome/thumbnailers/application@cbz/enable</applyto>
+            <owner>evince</owner>
+            <type>bool</type>
+            <default>true</default>
+            <locale name="C">
+                <short></short>
+                <long></long>
+            </locale>
+        </schema>
+
+
+        <schema>
+            <key>/schemas/desktop/gnome/thumbnailers/application@cbr/command</key>
+            <applyto>/desktop/gnome/thumbnailers/application@cbz/command</applyto>
+            <owner>evince</owner>
+            <type>string</type>
+            <default>evince-thumbnailer -s %s %u %o</default>
+            <locale name="C">
+                <short></short>
+                <long></long>
+            </locale>
+        </schema>
+
+    </schemalist>
+</gconfschemafile>