[evince] comics: Add ev_archive_reset()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] comics: Add ev_archive_reset()
- Date: Sat, 25 Mar 2017 11:39:26 +0000 (UTC)
commit 18ecdb6f5725f2c4f536fdca8ad5186a62ca3175
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Sat Mar 25 12:34:38 2017 +0100
comics: Add ev_archive_reset()
And use it instead of destroying and re-creating the EvArchive. This way
we don't need to keep the archive type in the document either.
backend/comics/comics-document.c | 17 +++--------------
backend/comics/ev-archive.c | 32 +++++++++++++++++++++++++++-----
backend/comics/ev-archive.h | 1 +
3 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
index 87c2527..5e07df4 100644
--- a/backend/comics/comics-document.c
+++ b/backend/comics/comics-document.c
@@ -49,7 +49,6 @@ struct _ComicsDocument
{
EvDocument parent_instance;
EvArchive *archive;
- EvArchiveType archive_type;
gchar *archive_path;
gchar *archive_uri;
GPtrArray *page_names;
@@ -59,14 +58,6 @@ static GSList* get_supported_image_extensions (void);
EV_BACKEND_REGISTER (ComicsDocument, comics_document)
-static void
-comics_document_reset_archive (ComicsDocument *comics_document)
-{
- g_clear_object (&comics_document->archive);
- comics_document->archive = ev_archive_new ();
- ev_archive_set_archive_type (comics_document->archive, comics_document->archive_type);
-}
-
static char **
comics_document_list (ComicsDocument *comics_document)
{
@@ -104,7 +95,7 @@ comics_document_list (ComicsDocument *comics_document)
}
out:
- comics_document_reset_archive (comics_document);
+ ev_archive_reset (comics_document->archive);
return ret;
}
@@ -202,8 +193,6 @@ comics_document_load (EvDocument *document,
}
g_free (mime_type);
- comics_document->archive_type = ev_archive_get_archive_type (comics_document->archive);
-
/* Get list of files in archive */
cb_files = comics_document_list (comics_document);
if (!cb_files) {
@@ -354,7 +343,7 @@ comics_document_get_page_size (EvDocument *document,
}
out:
- comics_document_reset_archive (comics_document);
+ ev_archive_reset (comics_document->archive);
}
static void
@@ -439,7 +428,7 @@ comics_document_render_pixbuf (EvDocument *document,
g_object_unref (loader);
out:
- comics_document_reset_archive (comics_document);
+ ev_archive_reset (comics_document->archive);
return rotated_pixbuf;
}
diff --git a/backend/comics/ev-archive.c b/backend/comics/ev-archive.c
index 4c423ef..e8a9368 100644
--- a/backend/comics/ev-archive.c
+++ b/backend/comics/ev-archive.c
@@ -36,7 +36,7 @@ struct _EvArchive {
struct archive_entry *libar_entry;
/* unarr */
- ar_stream *unarr_s;
+ ar_stream *unarr_stream;
ar_archive *unarr;
};
@@ -50,7 +50,7 @@ ev_archive_finalize (GObject *object)
switch (archive->type) {
case EV_ARCHIVE_TYPE_RAR:
g_clear_pointer (&archive->unarr, ar_close_archive);
- g_clear_pointer (&archive->unarr_s, ar_close);
+ g_clear_pointer (&archive->unarr_stream, ar_close);
break;
case EV_ARCHIVE_TYPE_ZIP:
case EV_ARCHIVE_TYPE_7Z:
@@ -139,13 +139,13 @@ ev_archive_open_filename (EvArchive *archive,
case EV_ARCHIVE_TYPE_NONE:
g_assert_not_reached ();
case EV_ARCHIVE_TYPE_RAR:
- archive->unarr_s = ar_open_file (path);
- if (archive->unarr_s == NULL) {
+ archive->unarr_stream = ar_open_file (path);
+ if (archive->unarr_stream == NULL) {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error opening archive");
return FALSE;
}
- archive->unarr = ar_open_rar_archive (archive->unarr_s);
+ archive->unarr = ar_open_rar_archive (archive->unarr_stream);
if (archive->unarr == NULL) {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error opening RAR archive");
@@ -297,6 +297,28 @@ ev_archive_read_data (EvArchive *archive,
return r;
}
+void
+ev_archive_reset (EvArchive *archive)
+{
+ g_return_if_fail (EV_IS_ARCHIVE (archive));
+ g_return_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE);
+
+ switch (archive->type) {
+ case EV_ARCHIVE_TYPE_RAR:
+ g_clear_pointer (&archive->unarr, ar_close_archive);
+ g_clear_pointer (&archive->unarr_stream, ar_close);
+ break;
+ case EV_ARCHIVE_TYPE_ZIP:
+ case EV_ARCHIVE_TYPE_7Z:
+ case EV_ARCHIVE_TYPE_TAR:
+ g_clear_pointer (&archive->libar, archive_free);
+ libarchive_set_archive_type (archive, archive->type);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
static void
ev_archive_init (EvArchive *archive)
{
diff --git a/backend/comics/ev-archive.h b/backend/comics/ev-archive.h
index 3e20693..cb52669 100644
--- a/backend/comics/ev-archive.h
+++ b/backend/comics/ev-archive.h
@@ -50,6 +50,7 @@ gssize ev_archive_read_data (EvArchive *archive,
void *buf,
gsize count,
GError **error);
+void ev_archive_reset (EvArchive *archive);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]