]> www.fi.muni.cz Git - evince.git/commitdiff
[libcodument] Add helper methods to get destination page of a link
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 3 Jan 2010 17:01:52 +0000 (18:01 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 3 Jan 2010 20:14:12 +0000 (21:14 +0100)
libdocument/ev-document-links.c
libdocument/ev-document-links.h

index 96383e249c43bf873802d9cea83583a11735f750..01615b25930626caf47f668e14d3786689e6ad9b 100644 (file)
@@ -79,3 +79,54 @@ ev_document_links_find_link_dest (EvDocumentLinks *document_links,
 
        return retval;
 }
+
+/* Helper functions */
+gint
+ev_document_links_get_dest_page (EvDocumentLinks *document_links,
+                                EvLinkDest      *dest)
+{
+       gint page = -1;
+
+       switch (ev_link_dest_get_dest_type (dest)) {
+       case EV_LINK_DEST_TYPE_NAMED: {
+               EvLinkDest *dest2;
+
+               dest2 = ev_document_links_find_link_dest (document_links,
+                                                         ev_link_dest_get_named_dest (dest));
+               if (dest2) {
+                       page = ev_link_dest_get_page (dest2);
+                       g_object_unref (dest2);
+               }
+       }
+               break;
+       case EV_LINK_DEST_TYPE_PAGE_LABEL:
+               ev_document_find_page_by_label (EV_DOCUMENT (document_links),
+                                               ev_link_dest_get_page_label (dest),
+                                               &page);
+               break;
+       default:
+               page = ev_link_dest_get_page (dest);
+       }
+
+       return page;
+}
+
+gchar *
+ev_document_links_get_dest_page_label (EvDocumentLinks *document_links,
+                                      EvLinkDest      *dest)
+{
+       gchar *label = NULL;
+
+       if (ev_link_dest_get_dest_type (dest) == EV_LINK_DEST_TYPE_PAGE_LABEL) {
+               label = g_strdup (ev_link_dest_get_page_label (dest));
+       } else {
+               gint page;
+
+               page = ev_document_links_get_dest_page (document_links, dest);
+               if (page != -1)
+                       label = ev_document_get_page_label (EV_DOCUMENT (document_links),
+                                                           page);
+       }
+
+       return label;
+}
index 21c1d4b8411d4a0cd560e5e576d0ec25fafd4a89..a4beabc837bc6cc3e72134b981292458eb086a52 100644 (file)
@@ -76,6 +76,10 @@ GList        *ev_document_links_get_links          (EvDocumentLinks *document_li
                                                    EvPage          *page);
 EvLinkDest   *ev_document_links_find_link_dest     (EvDocumentLinks *document_links,
                                                    const gchar     *link_name);
+gint          ev_document_links_get_dest_page      (EvDocumentLinks *document_links,
+                                                   EvLinkDest      *dest);
+gchar        *ev_document_links_get_dest_page_label(EvDocumentLinks *document_links,
+                                                   EvLinkDest      *dest);
 
 G_END_DECLS