[evince] Do not cache layers in the backends



commit 08993c59369086fa8916236f580438d656ccb8f7
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Tue Sep 14 10:46:29 2010 +0200

    Do not cache layers in the backends
    
    Use g_object_set_data instead, to attach the backend object to the
    evince layer.

 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 d68c7b1..0c5c898 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -109,7 +109,6 @@ struct _PdfDocument
 
 	PdfPrintContext *print_ctx;
 
-	GList *layers;
 	GHashTable *annots;
 };
 
@@ -198,11 +197,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);
 }
 
@@ -3149,11 +3143,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;
 
@@ -3211,30 +3206,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 dfc9bb0..533cf65 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 09fe71d..38b9411 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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]