From 1feffa2b7fba6bab62fe044777dad6e3278e848b Mon Sep 17 00:00:00 2001 From: infirit Date: Tue, 9 Dec 2014 11:47:09 +0100 Subject: Do not cache layers in the backends se g_object_set_data instead, to attach the backend object to the evince layer. Based on evince commit: 08993c59369086fa8916236f580438d656ccb8f7 From: Carlos Garcia Campos --- backend/pdf/ev-poppler.cc | 36 +++++++++++++++++------------------- libdocument/ev-layer.c | 17 +++-------------- libdocument/ev-layer.h | 4 +--- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 82e83521..72d7ac92 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -110,7 +110,6 @@ struct _PdfDocument PdfPrintContext *print_ctx; - GList *layers; GHashTable *annots; }; @@ -206,11 +205,6 @@ pdf_document_dispose (GObject *object) poppler_fonts_iter_free (pdf_document->fonts_iter); } - if (pdf_document->layers) { - g_list_foreach (pdf_document->layers, (GFunc)g_object_unref, NULL); - g_list_free (pdf_document->layers); - } - G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object); } @@ -3191,11 +3185,12 @@ build_layers_tree (PdfDocument *pdf_document, markup = g_markup_escape_text (poppler_layer_get_title (layer), -1); visible = poppler_layer_is_visible (layer); rb_group = poppler_layer_get_radio_button_group_id (layer); - pdf_document->layers = g_list_append (pdf_document->layers, - g_object_ref (layer)); - ev_layer = ev_layer_new (g_list_length (pdf_document->layers) - 1, - poppler_layer_is_parent (layer), + ev_layer = ev_layer_new (poppler_layer_is_parent (layer), rb_group); + g_object_set_data_full (G_OBJECT (ev_layer), + "poppler-layer", + g_object_ref (layer), + (GDestroyNotify) g_object_unref); } else { gchar *title; @@ -3253,30 +3248,33 @@ static void pdf_document_layers_show_layer (EvDocumentLayers *document, EvLayer *layer) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); - guint layer_id = ev_layer_get_id (layer); + PdfDocument *pdf_document = PDF_DOCUMENT (document); + PopplerLayer *poppler_layer; - poppler_layer_show (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id))); + poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer")); + poppler_layer_show (poppler_layer); } static void pdf_document_layers_hide_layer (EvDocumentLayers *document, EvLayer *layer) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); - guint layer_id = ev_layer_get_id (layer); + PdfDocument *pdf_document = PDF_DOCUMENT (document); + PopplerLayer *poppler_layer; - poppler_layer_hide (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id))); + poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer")); + poppler_layer_hide (poppler_layer); } static gboolean pdf_document_layers_layer_is_visible (EvDocumentLayers *document, EvLayer *layer) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); - guint layer_id = ev_layer_get_id (layer); + PdfDocument *pdf_document = PDF_DOCUMENT (document); + PopplerLayer *poppler_layer; - return poppler_layer_is_visible (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id))); + poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer")); + return poppler_layer_is_visible (poppler_layer); } static void diff --git a/libdocument/ev-layer.c b/libdocument/ev-layer.c index cb86cca4..cb735164 100644 --- a/libdocument/ev-layer.c +++ b/libdocument/ev-layer.c @@ -22,9 +22,8 @@ #include "ev-layer.h" struct _EvLayerPrivate { - guint id; - gboolean is_parent; - gint rb_group; + gboolean is_parent; + gint rb_group; }; #define EV_LAYER_GET_PRIVATE(object) \ @@ -47,28 +46,18 @@ ev_layer_init (EvLayer *layer) } EvLayer * -ev_layer_new (guint layer_id, - gboolean is_parent, +ev_layer_new (gboolean is_parent, gint rb_group) { EvLayer *layer; layer = EV_LAYER (g_object_new (EV_TYPE_LAYER, NULL)); - layer->priv->id = layer_id; layer->priv->is_parent = is_parent; layer->priv->rb_group = rb_group; return layer; } -guint -ev_layer_get_id (EvLayer *layer) -{ - g_return_val_if_fail (EV_IS_LAYER (layer), 0); - - return layer->priv->id; -} - gboolean ev_layer_is_parent (EvLayer *layer) { diff --git a/libdocument/ev-layer.h b/libdocument/ev-layer.h index f87c9e08..656d2994 100644 --- a/libdocument/ev-layer.h +++ b/libdocument/ev-layer.h @@ -50,10 +50,8 @@ struct _EvLayerClass { }; GType ev_layer_get_type (void) G_GNUC_CONST; -EvLayer *ev_layer_new (guint layer_id, - gboolean is_parent, +EvLayer *ev_layer_new (gboolean is_parent, gint rb_group); -guint ev_layer_get_id (EvLayer *layer); gboolean ev_layer_is_parent (EvLayer *layer); gint ev_layer_get_rb_group (EvLayer *layer); -- cgit v1.2.1