[evince] libdocument: Make EvSourceLink boxed.



commit 0ac089873d0ff28fbb161e95feb437c655ae0602
Author: Josà Aliste <jaliste src gnome org>
Date:   Sat Nov 12 13:44:05 2011 -0300

    libdocument: Make EvSourceLink boxed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=635705

 libdocument/ev-document.c |   49 +++++++++++++++++++++++++++++++++++++++++---
 libdocument/ev-document.h |   24 +++++++++++++++------
 libview/ev-view.c         |    2 +-
 3 files changed, 63 insertions(+), 12 deletions(-)
---
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index a0c08e8..163a231 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -425,10 +425,9 @@ ev_document_synctex_backward_search (EvDocument *document,
 			filename = synctex_scanner_get_name (scanner, synctex_node_tag (node));
 			
 			if (filename) {
-				result = g_new (EvSourceLink, 1);
-				result->filename = filename;
-				result->line = synctex_node_line (node);
-				result->col = synctex_node_column (node);
+				result = ev_source_link_new (filename,
+							     synctex_node_line (node),
+							     synctex_node_column (node));
 			}
                 }
         }
@@ -737,6 +736,48 @@ ev_document_find_page_by_label (EvDocument  *document,
 	return FALSE;
 }
 
+/* EvSourceLink */
+G_DEFINE_BOXED_TYPE (EvSourceLink, ev_source_link, ev_source_link_copy, ev_source_link_free)
+
+EvSourceLink *
+ev_source_link_new (const gchar *filename,
+		    gint 	 line,
+		    gint 	 col)
+{
+	EvSourceLink *link = g_slice_new (EvSourceLink);
+
+	link->filename = g_strdup (filename);
+	link->line = line;
+	link->col = col;
+
+	return link;
+}
+
+EvSourceLink *
+ev_source_link_copy (EvSourceLink *link)
+{
+	EvSourceLink *copy;
+
+	g_return_val_if_fail (link != NULL, NULL);
+
+	copy = g_slice_new (EvSourceLink);
+
+	*copy = *link;
+	copy->filename = g_strdup (link->filename);
+
+	return copy;
+}
+
+void
+ev_source_link_free (EvSourceLink *link)
+{
+	if (link == NULL)
+		return;
+
+	g_free (link->filename);
+	g_slice_free (EvSourceLink, link);
+}
+
 /* EvDocumentInfo */
 G_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
 
diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h
index 35195e1..e1e01c0 100644
--- a/libdocument/ev-document.h
+++ b/libdocument/ev-document.h
@@ -66,20 +66,15 @@ typedef struct {
 
 typedef struct _EvRectangle EvRectangle;
 typedef struct _EvMapping EvMapping;
-
+typedef struct _EvSourceLink EvSourceLink;
 typedef struct _EvDocumentBackendInfo EvDocumentBackendInfo;
+
 struct _EvDocumentBackendInfo
 {
 	const gchar *name;
 	const gchar *version;
 };
 
-typedef struct {
-	const gchar *filename;
-	gint         line;
-	gint         col;
-} EvSourceLink;
-
 struct _EvDocument
 {
 	GObject base;
@@ -203,6 +198,21 @@ struct _EvMapping {
 	gpointer    data;
 };
 
+#define EV_TYPE_SOURCE_LINK (ev_source_link_get_type ())
+struct _EvSourceLink
+{
+        gchar *filename;
+        gint   line;
+        gint   col;
+};
+
+GType          ev_source_link_get_type (void) G_GNUC_CONST;
+EvSourceLink  *ev_source_link_new      (const gchar *filename,
+					gint         line,
+					gint         col);
+EvSourceLink  *ev_source_link_copy     (EvSourceLink *link);
+void           ev_source_link_free     (EvSourceLink *link);
+
 /* convenience macro to ease interface addition in the CODE
  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
diff --git a/libview/ev-view.c b/libview/ev-view.c
index cbc6b4a..83fdd4c 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -3027,7 +3027,7 @@ ev_view_synctex_backward_search (EvView *view,
 	link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
 	if (link) {
 		g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
-		g_free (link);
+		ev_source_link_free (link);
 
 		return TRUE;
 	}



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