summaryrefslogtreecommitdiff
path: root/libdocument/ev-document-links.c
blob: 42ffc59ae96170a76a5f461ee82a5d5ae1f6f75e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* ev-document-links.h
 *  this file is part of atril, a mate document_links viewer
 * 
 * Copyright (C) 2004 Red Hat, Inc.
 *
 * Author:
 *   Jonathan Blandford <jrb@alum.mit.edu>
 *
 * Atril is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Atril is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "config.h"

#include "ev-document-links.h"

G_DEFINE_INTERFACE (EvDocumentLinks, ev_document_links, 0)

static void
ev_document_links_default_init (EvDocumentLinksInterface *klass)
{
}

gboolean
ev_document_links_has_document_links (EvDocumentLinks *document_links)
{
	EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
	gboolean retval;

	retval = iface->has_document_links (document_links);

	return retval;
}

GtkTreeModel *
ev_document_links_get_links_model (EvDocumentLinks *document_links)
{
	EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
	GtkTreeModel *retval;

	retval = iface->get_links_model (document_links);

	return retval;
}

EvMappingList *
ev_document_links_get_links (EvDocumentLinks *document_links,
			     EvPage          *page)
{
	EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);

	return iface->get_links (document_links, page);
}

EvLinkDest *
ev_document_links_find_link_dest (EvDocumentLinks *document_links,
				  const gchar     *link_name)
{
	EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
	EvLinkDest *retval;

	ev_document_doc_mutex_lock ();
	retval = iface->find_link_dest (document_links, link_name);
	ev_document_doc_mutex_unlock ();

	return retval;
}

gint
ev_document_links_find_link_page (EvDocumentLinks *document_links,
				  const gchar     *link_name)
{
	EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links);
	gint retval;

	ev_document_doc_mutex_lock ();
	retval = iface->find_link_page (document_links, link_name);
	ev_document_doc_mutex_unlock ();

	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: {
		page = ev_document_links_find_link_page (document_links,
							 ev_link_dest_get_named_dest (dest));
	}
		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;
}

static EvLinkDest *
get_link_dest (EvLink *link)
{
	EvLinkAction *action;

	action = ev_link_get_action (link);
	if (!action)
		return NULL;

	if (ev_link_action_get_action_type (action) !=
	    EV_LINK_ACTION_TYPE_GOTO_DEST)
		return NULL;

	return ev_link_action_get_dest (action);
}

gint
ev_document_links_get_link_page (EvDocumentLinks *document_links,
				 EvLink          *link)
{
	EvLinkDest *dest;

	dest = get_link_dest (link);

	return dest ? ev_document_links_get_dest_page (document_links, dest) : -1;
}

gchar *
ev_document_links_get_link_page_label (EvDocumentLinks *document_links,
				       EvLink          *link)
{
	EvLinkDest *dest;

	dest = get_link_dest (link);

	return dest ? ev_document_links_get_dest_page_label (document_links, dest) : NULL;
}