]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document-links.c
b8aae5d71a5ac424671c6336e4b5567276350e89
[evince.git] / libdocument / ev-document-links.c
1 /* ev-document-links.h
2  *  this file is part of evince, a gnome document_links viewer
3  * 
4  * Copyright (C) 2004 Red Hat, Inc.
5  *
6  * Author:
7  *   Jonathan Blandford <jrb@alum.mit.edu>
8  *
9  * Evince is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Evince is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23
24 #include "config.h"
25
26 #include "ev-document-links.h"
27
28 G_DEFINE_INTERFACE (EvDocumentLinks, ev_document_links, 0)
29
30 static void
31 ev_document_links_default_init (EvDocumentLinksInterface *klass)
32 {
33 }
34
35 gboolean
36 ev_document_links_has_document_links (EvDocumentLinks *document_links)
37 {
38         EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
39         gboolean retval;
40
41         retval = iface->has_document_links (document_links);
42
43         return retval;
44 }
45
46 GtkTreeModel *
47 ev_document_links_get_links_model (EvDocumentLinks *document_links)
48 {
49         EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
50         GtkTreeModel *retval;
51
52         retval = iface->get_links_model (document_links);
53
54         return retval;
55 }
56
57 EvMappingList *
58 ev_document_links_get_links (EvDocumentLinks *document_links,
59                              EvPage          *page)
60 {
61         EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
62
63         return iface->get_links (document_links, page);
64 }
65
66 EvLinkDest *
67 ev_document_links_find_link_dest (EvDocumentLinks *document_links,
68                                   const gchar     *link_name)
69 {
70         EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
71         EvLinkDest *retval;
72
73         ev_document_doc_mutex_lock ();
74         retval = iface->find_link_dest (document_links, link_name);
75         ev_document_doc_mutex_unlock ();
76
77         return retval;
78 }
79
80 /* Helper functions */
81 gint
82 ev_document_links_get_dest_page (EvDocumentLinks *document_links,
83                                  EvLinkDest      *dest)
84 {
85         gint page = -1;
86
87         switch (ev_link_dest_get_dest_type (dest)) {
88         case EV_LINK_DEST_TYPE_NAMED: {
89                 EvLinkDest *dest2;
90
91                 dest2 = ev_document_links_find_link_dest (document_links,
92                                                           ev_link_dest_get_named_dest (dest));
93                 if (dest2) {
94                         page = ev_link_dest_get_page (dest2);
95                         g_object_unref (dest2);
96                 }
97         }
98                 break;
99         case EV_LINK_DEST_TYPE_PAGE_LABEL:
100                 ev_document_find_page_by_label (EV_DOCUMENT (document_links),
101                                                 ev_link_dest_get_page_label (dest),
102                                                 &page);
103                 break;
104         default:
105                 page = ev_link_dest_get_page (dest);
106         }
107
108         return page;
109 }
110
111 gchar *
112 ev_document_links_get_dest_page_label (EvDocumentLinks *document_links,
113                                        EvLinkDest      *dest)
114 {
115         gchar *label = NULL;
116
117         if (ev_link_dest_get_dest_type (dest) == EV_LINK_DEST_TYPE_PAGE_LABEL) {
118                 label = g_strdup (ev_link_dest_get_page_label (dest));
119         } else {
120                 gint page;
121
122                 page = ev_document_links_get_dest_page (document_links, dest);
123                 if (page != -1)
124                         label = ev_document_get_page_label (EV_DOCUMENT (document_links),
125                                                             page);
126         }
127
128         return label;
129 }