[evince] Make link action and dest object properties



commit a06bc40afc4b318b3a4489d76be54e5816c3f8e4
Author: William Jon McCann <jmccann redhat com>
Date:   Sat Jan 5 15:42:47 2013 -0500

    Make link action and dest object properties
    
    Instead of pointer properties. This allows them to be properly
    refcounted and used from binding languages.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691214

 backend/djvu/djvu-links.c       |    5 ++++-
 backend/pdf/ev-poppler.cc       |    5 ++++-
 backend/xps/xps-document.c      |    9 ++++++++-
 libdocument/ev-link-action.c    |   22 ++++++++++------------
 libdocument/ev-link.c           |   22 ++++++++++------------
 libmisc/ev-page-action-widget.c |    2 ++
 shell/ev-window.c               |   22 +++++++---------------
 7 files changed, 45 insertions(+), 42 deletions(-)
---
diff --git a/backend/djvu/djvu-links.c b/backend/djvu/djvu-links.c
index e4d2791..ebcc6a4 100644
--- a/backend/djvu/djvu-links.c
+++ b/backend/djvu/djvu-links.c
@@ -103,6 +103,7 @@ get_djvu_link_action (const DjvuDocument *djvu_document, const gchar *link_name,
 
 	if (ev_dest) {
 		ev_action = ev_link_action_new_dest (ev_dest);
+		g_object_unref (ev_dest);
 	} else if (strstr(link_name, "://") != NULL) {
 		/* It's probably an URI */
 		ev_action = ev_link_action_new_external_uri (link_name);
@@ -201,6 +202,7 @@ build_tree (const DjvuDocument *djvu_document,
 					    EV_DOCUMENT_LINKS_COLUMN_LINK, ev_link,
 					    EV_DOCUMENT_LINKS_COLUMN_EXPAND, FALSE,
 					    -1);
+			g_object_unref (ev_action);
 			g_object_unref (ev_link);
 		} else {
 			gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
@@ -333,7 +335,8 @@ get_djvu_hyperlink_mapping (DjvuDocument     *djvu_document,
 	if (!ev_action) goto unknown_mapping;
 
 	ev_link_mapping->data = ev_link_new (comment, ev_action);
-			
+	g_object_unref (ev_action);
+
 	return ev_link_mapping;
 
  unknown_mapping:
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index e8f36c6..a2f6961 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -1313,6 +1313,7 @@ ev_link_from_action (PdfDocument   *pdf_document,
 			
 			dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
 			ev_action = ev_link_action_new_dest (dest);
+			g_object_unref (dest);
 		}
 			break;
 	        case POPPLER_ACTION_GOTO_REMOTE: {
@@ -1321,6 +1322,7 @@ ev_link_from_action (PdfDocument   *pdf_document,
 			dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
 			ev_action = ev_link_action_new_remote (dest, 
 							       action->goto_remote.file_name);
+			g_object_unref (dest);
 			
 		}
 			break;
@@ -1396,7 +1398,8 @@ ev_link_from_action (PdfDocument   *pdf_document,
 	}
 	
 	link = ev_link_new (action->any.title, ev_action);
-	
+	g_object_unref (ev_action);
+
 	return link;	
 }
 
diff --git a/backend/xps/xps-document.c b/backend/xps/xps-document.c
index 410da2d..3cb5de9 100644
--- a/backend/xps/xps-document.c
+++ b/backend/xps/xps-document.c
@@ -291,6 +291,7 @@ static EvLink *
 ev_link_from_target (XPSDocument    *xps_document,
 		     GXPSLinkTarget *target)
 {
+	EvLink *link;
 	EvLinkAction *ev_action;
 
 	if (gxps_link_target_is_internal (target)) {
@@ -308,6 +309,7 @@ ev_link_from_target (XPSDocument    *xps_document,
 
 			dest = ev_link_dest_new_named (anchor);
 			ev_action = ev_link_action_new_dest (dest);
+			g_object_unref (dest);
 		} else if (doc == -1 && anchor &&
 			   gxps_document_get_page_for_anchor (xps_document->doc, anchor) >= 0) {
 			/* Internal, but source is not a doc,
@@ -315,6 +317,7 @@ ev_link_from_target (XPSDocument    *xps_document,
 			 */
 			dest = ev_link_dest_new_named (anchor);
 			ev_action = ev_link_action_new_dest (dest);
+			g_object_unref (dest);
 		} else {
 			gchar *filename;
 
@@ -324,6 +327,7 @@ ev_link_from_target (XPSDocument    *xps_document,
 			if (anchor)
 				dest = ev_link_dest_new_named (anchor);
 			ev_action = ev_link_action_new_remote (dest, filename);
+			g_clear_object (&dest);
 			g_free (filename);
 		}
 	} else {
@@ -333,7 +337,10 @@ ev_link_from_target (XPSDocument    *xps_document,
 		ev_action = ev_link_action_new_external_uri (uri);
 	}
 
-	return ev_link_new (NULL, ev_action);
+	link = ev_link_new (NULL, ev_action);
+	g_object_unref (ev_action);
+
+	return link;
 }
 
 static void
diff --git a/libdocument/ev-link-action.c b/libdocument/ev-link-action.c
index ccbebfb..c7dbd47 100644
--- a/libdocument/ev-link-action.c
+++ b/libdocument/ev-link-action.c
@@ -149,7 +149,7 @@ ev_link_action_get_property (GObject    *object,
 		        g_value_set_enum (value, self->priv->type);
 		        break;
 	        case PROP_DEST:
-		        g_value_set_pointer (value, self->priv->dest);
+		        g_value_set_object (value, self->priv->dest);
 			break;
 	        case PROP_URI:
 			g_value_set_string (value, self->priv->uri);
@@ -193,7 +193,7 @@ ev_link_action_set_property (GObject      *object,
 			self->priv->type = g_value_get_enum (value);
 			break;
 	        case PROP_DEST:
-			self->priv->dest = g_value_get_pointer (value);
+			self->priv->dest = g_value_dup_object (value);
 			break;
 	        case PROP_URI:
 			g_free (self->priv->uri);
@@ -235,10 +235,7 @@ ev_link_action_finalize (GObject *object)
 
 	priv = EV_LINK_ACTION (object)->priv;
 
-	if (priv->dest) {
-		g_object_unref (priv->dest);
-		priv->dest = NULL;
-	}
+	g_clear_object (&priv->dest);
 
 	if (priv->uri) {
 		g_free (priv->uri);
@@ -319,12 +316,13 @@ ev_link_action_class_init (EvLinkActionClass *ev_link_action_class)
                                                              G_PARAM_STATIC_STRINGS));
 	g_object_class_install_property (g_object_class,
 					 PROP_DEST,
-					 g_param_spec_pointer ("dest",
-							       "Action destination",
-							       "The link action destination",
-							       G_PARAM_READWRITE |
-							       G_PARAM_CONSTRUCT_ONLY |
-                                                               G_PARAM_STATIC_STRINGS));
+					 g_param_spec_object ("dest",
+							      "Action destination",
+							      "The link action destination",
+							      EV_TYPE_LINK_DEST,
+							      G_PARAM_READWRITE |
+							      G_PARAM_CONSTRUCT_ONLY |
+                                                              G_PARAM_STATIC_STRINGS));
 	g_object_class_install_property (g_object_class,
 					 PROP_URI,
 					 g_param_spec_string ("uri",
diff --git a/libdocument/ev-link.c b/libdocument/ev-link.c
index 0a51f23..b01cd6e 100644
--- a/libdocument/ev-link.c
+++ b/libdocument/ev-link.c
@@ -77,7 +77,7 @@ ev_link_get_property (GObject    *object,
 			g_value_set_string (value, self->priv->title);
 			break;
 	        case PROP_ACTION:
-			g_value_set_pointer (value, self->priv->action);
+			g_value_set_object (value, self->priv->action);
 			break;
 	        default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
@@ -100,7 +100,7 @@ ev_link_set_property (GObject      *object,
 			self->priv->title = g_value_dup_string (value);	
 			break;
 	        case PROP_ACTION:
-			self->priv->action = g_value_get_pointer (value);
+			self->priv->action = g_value_dup_object (value);
 			break;
 	        default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
@@ -122,10 +122,7 @@ ev_link_finalize (GObject *object)
 		priv->title = NULL;
 	}
 
-	if (priv->action) {
-		g_object_unref (priv->action);
-		priv->action = NULL;
-	}
+	g_clear_object (&priv->action);
 
 	G_OBJECT_CLASS (ev_link_parent_class)->finalize (object);
 }
@@ -164,12 +161,13 @@ ev_link_class_init (EvLinkClass *ev_window_class)
                                                               G_PARAM_STATIC_STRINGS));
 	g_object_class_install_property (g_object_class,
 					 PROP_ACTION,
-					 g_param_spec_pointer ("action",
-							       "Link Action",
-							       "The link action",
-							       G_PARAM_READWRITE |
-							       G_PARAM_CONSTRUCT_ONLY |
-                                                               G_PARAM_STATIC_STRINGS));
+					 g_param_spec_object ("action",
+							      "Link Action",
+							      "The link action",
+							      EV_TYPE_LINK_ACTION,
+							      G_PARAM_READWRITE |
+							      G_PARAM_CONSTRUCT_ONLY |
+							      G_PARAM_STATIC_STRINGS));
 }
 
 EvLink *
diff --git a/libmisc/ev-page-action-widget.c b/libmisc/ev-page-action-widget.c
index 43ca614..19afe6d 100644
--- a/libmisc/ev-page-action-widget.c
+++ b/libmisc/ev-page-action-widget.c
@@ -184,6 +184,8 @@ activate_cb (EvPageActionWidget *action_widget)
 
 	g_signal_emit (action_widget, widget_signals[WIDGET_ACTIVATE_LINK], 0, link);
 
+	g_object_unref (link_dest);
+	g_object_unref (link_action);
 	g_object_unref (link);
 	g_free (link_text);
 
diff --git a/shell/ev-window.c b/shell/ev-window.c
index cbd63d6..047e5b3 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -885,6 +885,7 @@ ev_window_add_history (EvWindow *window, gint page, EvLink *link)
 	} else {
 		dest = ev_link_dest_new_page (page);
 		action = ev_link_action_new_dest (dest);
+		g_object_unref (dest);
 		page_label = ev_document_get_page_label (window->priv->document, page);
 	}
 
@@ -900,7 +901,8 @@ ev_window_add_history (EvWindow *window, gint page, EvLink *link)
 	}
 
 	real_link = ev_link_new (link_title, action);
-	
+	g_object_unref (action);
+
 	ev_history_add_link (window->priv->history, real_link);
 
 	g_free (link_title);
@@ -1599,6 +1601,7 @@ ev_window_handle_link (EvWindow *ev_window,
 		link_action = ev_link_action_new_dest (dest);
 		link = ev_link_new (NULL, link_action);
 		ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
+		g_object_unref (link_action);
 		g_object_unref (link);
 	}
 }
@@ -1649,11 +1652,7 @@ ev_window_load_job_cb (EvJob *job,
 		}
 
 		ev_window_handle_link (ev_window, ev_window->priv->dest);
-		/* Already unrefed by ev_link_action
-		 * FIXME: link action should inc dest ref counting
-		 * or not unref it at all
-		 */
-		ev_window->priv->dest = NULL;
+		g_clear_object (&ev_window->priv->dest);
 
 		switch (ev_window->priv->window_mode) {
 		        case EV_WINDOW_MODE_FULLSCREEN:
@@ -1749,11 +1748,7 @@ ev_window_reload_job_cb (EvJob    *job,
 					job->document);
 	if (ev_window->priv->dest) {
 		ev_window_handle_link (ev_window, ev_window->priv->dest);
-		/* Already unrefed by ev_link_action
-		 * FIXME: link action should inc dest ref counting
-		 * or not unref it at all
-		 */
-		ev_window->priv->dest = NULL;
+		g_clear_object (&ev_window->priv->dest);
 	}
 
 	/* Restart the search after reloading */
@@ -2186,10 +2181,7 @@ ev_window_open_document (EvWindow       *ev_window,
 		link_action = ev_link_action_new_dest (dest);
 		link = ev_link_new (NULL, link_action);
 		ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
-		/* FIXME: link action should inc dest ref counting
-		 * or not unref it at all
-		 */
-		g_object_ref (dest);
+		g_object_unref (link_action);
 		g_object_unref (link);
 	}
 



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