30 #include <glib/gi18n-lib.h>
31 #include <glib/gstdio.h>
39 #define BLOCK_SIZE 10240
70 array = g_ptr_array_new ();
78 g_warning (
"Fatal error handling archive: %s", error->message);
86 g_debug (
"Adding '%s' to the list of files in the comics", name);
87 g_ptr_array_add (array, g_strdup (name));
90 if (array->len == 0) {
91 g_ptr_array_free (array,
TRUE);
93 g_ptr_array_add (array, NULL);
94 ret = (
char **) g_ptr_array_free (array,
FALSE);
109 if (g_content_type_is_a (mime_type,
"application/x-cbr") ||
110 g_content_type_is_a (mime_type,
"application/x-rar")) {
113 }
else if (g_content_type_is_a (mime_type,
"application/x-cbz") ||
114 g_content_type_is_a (mime_type,
"application/zip")) {
117 }
else if (g_content_type_is_a (mime_type,
"application/x-cb7") ||
118 g_content_type_is_a (mime_type,
"application/x-7z-compressed")) {
121 }
else if (g_content_type_is_a (mime_type,
"application/x-cbt") ||
122 g_content_type_is_a (mime_type,
"application/x-tar")) {
129 _(
"Not a comic book MIME type: %s"),
133 g_set_error_literal (error,
136 _(
"libarchive lacks support for this comic book’s "
137 "compression, please contact your distributor"));
145 gchar *temp1, *temp2;
148 temp1 = g_utf8_collate_key_for_filename (* (
const char **) a, -1);
149 temp2 = g_utf8_collate_key_for_filename (* (
const char **) b, -1);
151 ret = strcmp (temp1, temp2);
165 GSList *supported_extensions;
167 gchar **cb_files, *cb_file;
172 file = g_file_new_for_uri (uri);
174 g_object_unref (file);
177 g_set_error_literal (error,
180 _(
"Can not get local path for archive"));
187 if (mime_type == NULL)
199 g_set_error_literal (error,
202 _(
"File corrupted or no files in archive"));
206 comics_document->
page_names = g_ptr_array_sized_new (64);
209 for (i = 0; cb_files[i] != NULL; i++) {
210 cb_file = cb_files[i];
211 gchar *suffix = g_strrstr (cb_file,
".");
214 suffix = g_ascii_strdown (suffix + 1, -1);
215 if (g_slist_find_custom (supported_extensions, suffix,
216 (GCompareFunc) strcmp) != NULL) {
218 g_strstrip (g_strdup (cb_file)));
222 g_strfreev (cb_files);
223 g_slist_foreach (supported_extensions, (GFunc) g_free, NULL);
224 g_slist_free (supported_extensions);
230 _(
"No images found in archive %s"),
285 GdkPixbufLoader *loader;
287 const char *page_path;
289 GError *error = NULL;
292 g_warning (
"Fatal error opening archive: %s", error->message);
293 g_error_free (error);
297 loader = gdk_pixbuf_loader_new ();
299 g_signal_connect (loader,
"size-prepared",
303 page_path = g_ptr_array_index (comics_document->
page_names, page->
index);
307 GError *error = NULL;
311 g_warning (
"Fatal error handling archive: %s", error->message);
312 g_error_free (error);
318 if (g_strcmp0 (name, page_path) == 0) {
326 while (read > 0 && !info.
got_info) {
327 if (!gdk_pixbuf_loader_write (loader, (guchar *) buf, read, &error)) {
336 g_warning (
"Fatal error reading '%s' in archive: %s", name, error->message);
337 g_error_free (error);
343 gdk_pixbuf_loader_close (loader, NULL);
344 g_object_unref (loader);
363 int scaled_width, scaled_height;
366 gdk_pixbuf_loader_set_size (loader, scaled_width, scaled_height);
373 GdkPixbufLoader *loader;
374 GdkPixbuf *tmp_pixbuf;
375 GdkPixbuf *rotated_pixbuf = NULL;
377 const char *page_path;
378 GError *error = NULL;
381 g_warning (
"Fatal error opening archive: %s", error->message);
382 g_error_free (error);
386 loader = gdk_pixbuf_loader_new ();
387 g_signal_connect (loader,
"size-prepared",
391 page_path = g_ptr_array_index (comics_document->
page_names, rc->page->index);
398 g_warning (
"Fatal error handling archive: %s", error->message);
399 g_error_free (error);
405 if (g_strcmp0 (name, page_path) == 0) {
410 buf = g_malloc (size);
414 g_warning (
"Fatal error reading '%s' in archive: %s", name, error->message);
415 g_error_free (error);
417 g_warning (
"Read an empty file from the archive");
420 gdk_pixbuf_loader_write (loader, (guchar *) buf, size, NULL);
423 gdk_pixbuf_loader_close (loader, NULL);
428 tmp_pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
430 if ((rc->rotation % 360) == 0)
431 rotated_pixbuf = g_object_ref (tmp_pixbuf);
433 rotated_pixbuf = gdk_pixbuf_rotate_simple (tmp_pixbuf,
436 g_object_unref (loader);
440 return rotated_pixbuf;
443 static cairo_surface_t *
448 cairo_surface_t *surface;
452 g_object_unref (pixbuf);
463 g_ptr_array_foreach (comics_document->
page_names, (GFunc) g_free, NULL);
467 g_clear_object (&comics_document->
archive);
471 G_OBJECT_CLASS (comics_document_parent_class)->finalize (
object);
477 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
500 GSList *formats = gdk_pixbuf_get_formats ();
503 for (l = formats; l != NULL; l = l->next) {
505 gchar **ext = gdk_pixbuf_format_get_extensions (l->data);
507 for (i = 0; ext[i] != NULL; i++) {
508 extensions = g_slist_append (extensions,
515 g_slist_free (formats);