]> www.fi.muni.cz Git - evince.git/blob - backend/ev-link.c
Merged translations from ggv and gpdf, minor updates.
[evince.git] / backend / ev-link.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2005 Red Hat, Inc.
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-link.h"
26
27 enum {
28         PROP_0,
29         PROP_TITLE,
30         PROP_TYPE,
31         PROP_PAGE,
32         PROP_URI
33 };
34
35 struct _EvLinkPrivate {
36         char *title;
37         char *uri;
38         EvLinkType type;
39         int page;
40 };
41
42 static GObjectClass *parent_class = NULL;
43
44 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
45
46 #define EV_LINK_GET_PRIVATE(object) \
47         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
48
49 GType
50 ev_link_type_get_type (void)
51 {
52         static GType type = 0;
53
54         if (G_UNLIKELY (type == 0)) {
55                 static const GEnumValue values[] = {
56                         { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
57                         { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
58                         { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
59                         { 0, NULL, NULL }
60                 };
61
62                 type = g_enum_register_static ("EvLinkType", values);
63         }
64
65         return type;
66 }
67
68 const char *
69 ev_link_get_title (EvLink *self)
70 {
71         g_return_val_if_fail (EV_IS_LINK (self), NULL);
72         
73         return self->priv->title;
74 }
75
76 void
77 ev_link_set_title (EvLink* self, const char *title)
78 {
79         g_assert (EV_IS_LINK (self));
80         g_assert (title != NULL);
81
82         if (self->priv->title != NULL) {
83                 g_free (self->priv->title);
84         }
85
86         self->priv->title = g_strdup (title);
87
88         g_object_notify (G_OBJECT (self), "title");
89 }
90
91 const char *
92 ev_link_get_uri (EvLink *self)
93 {
94         g_return_val_if_fail (EV_IS_LINK (self), NULL);
95         
96         return self->priv->uri;
97 }
98
99 void
100 ev_link_set_uri (EvLink* self, const char *uri)
101 {
102         g_assert (EV_IS_LINK (self));
103         g_assert (uri != NULL);
104
105         if (self->priv->uri != NULL) {
106                 g_free (self->priv->uri);
107         }
108
109         self->priv->uri = g_strdup (uri);
110
111         g_object_notify (G_OBJECT (self), "uri");
112 }
113
114 EvLinkType
115 ev_link_get_link_type (EvLink *self)
116 {
117         g_return_val_if_fail (EV_IS_LINK (self), 0);
118         
119         return self->priv->type;
120 }
121
122 void
123 ev_link_set_link_type (EvLink* self, EvLinkType type)
124 {
125         g_assert (EV_IS_LINK (self));
126
127         self->priv->type = type;
128
129         g_object_notify (G_OBJECT (self), "type");
130 }
131
132 int
133 ev_link_get_page (EvLink *self)
134 {
135         g_return_val_if_fail (EV_IS_LINK (self), 0);
136         
137         return self->priv->page;
138 }
139
140 void
141 ev_link_set_page (EvLink* self, int page)
142 {
143         g_assert (EV_IS_LINK (self));
144
145         self->priv->page = page;
146
147         g_object_notify (G_OBJECT (self), "page");
148 }
149
150 static void
151 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
152                       GParamSpec *param_spec)
153 {
154         EvLink *self;
155
156         self = EV_LINK (object);
157
158         switch (prop_id) {
159         case PROP_TITLE:
160                 g_value_set_string (value, self->priv->title);
161                 break;
162         case PROP_URI:
163                 g_value_set_string (value, self->priv->uri);
164                 break;
165         case PROP_TYPE:
166                 g_value_set_enum (value, self->priv->type);
167                 break;
168         case PROP_PAGE:
169                 g_value_set_int (value, self->priv->page);
170                 break;
171         default:
172                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
173                                                    prop_id,
174                                                    param_spec);
175                 break;
176         }
177 }
178
179 static void
180 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
181                       GParamSpec *param_spec)
182 {
183         EvLink *self;
184         
185         self = EV_LINK (object);
186         
187         switch (prop_id) {
188         case PROP_TITLE:
189                 ev_link_set_title (self, g_value_get_string (value));
190                 break;
191         case PROP_URI:
192                 ev_link_set_uri (self, g_value_get_string (value));
193                 break;
194         case PROP_TYPE:
195                 ev_link_set_link_type (self, g_value_get_enum (value));
196                 break;
197         case PROP_PAGE:
198                 ev_link_set_page (self, g_value_get_int (value));
199                 break;
200         default:
201                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
202                                                    prop_id,
203                                                    param_spec);
204                 break;
205         }
206 }
207
208 static void
209 ev_window_dispose (GObject *object)
210 {
211         EvLinkPrivate *priv;
212
213         g_return_if_fail (EV_IS_LINK (object));
214
215         priv = EV_LINK (object)->priv;
216
217         if (priv->title) {
218                 g_free (priv->title);
219                 priv->title = NULL;
220         }
221
222         G_OBJECT_CLASS (parent_class)->dispose (object);
223 }
224
225 static void
226 ev_link_init (EvLink *ev_link)
227 {
228         ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
229
230         ev_link->priv->type = EV_LINK_TYPE_TITLE;
231 }
232
233 static void
234 ev_link_class_init (EvLinkClass *ev_window_class)
235 {
236         GObjectClass *g_object_class;
237
238         parent_class = g_type_class_peek_parent (ev_window_class);
239
240         g_object_class = G_OBJECT_CLASS (ev_window_class);
241         g_object_class->dispose = ev_window_dispose;
242         g_object_class->set_property = ev_link_set_property;
243         g_object_class->get_property = ev_link_get_property;
244
245         g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
246
247         g_object_class_install_property (g_object_class,
248                                          PROP_TITLE,
249                                          g_param_spec_string ("title",
250                                                               "Link Title",
251                                                               "The link title",
252                                                               NULL,
253                                                               G_PARAM_READWRITE));
254
255         g_object_class_install_property (g_object_class,
256                                          PROP_URI,
257                                          g_param_spec_string ("uri",
258                                                               "Link URI",
259                                                               "The link URI",
260                                                               NULL,
261                                                               G_PARAM_READWRITE));
262
263         g_object_class_install_property (g_object_class,
264                                          PROP_TYPE,
265                                          g_param_spec_enum  ("type",
266                                                              "Link Type",
267                                                              "The link type",
268                                                              EV_TYPE_LINK_TYPE,
269                                                              EV_LINK_TYPE_TITLE,
270                                                              G_PARAM_READWRITE));
271
272         g_object_class_install_property (g_object_class,
273                                          PROP_PAGE,
274                                          g_param_spec_int ("page",
275                                                            "Link Page",
276                                                            "The link page",
277                                                             0,
278                                                             G_MAXINT,
279                                                             0,
280                                                             G_PARAM_READWRITE));
281 }
282
283 EvLink *
284 ev_link_new_title (const char *title)
285 {
286         return EV_LINK (g_object_new (EV_TYPE_LINK,
287                                       "title", title,
288                                       "type", EV_LINK_TYPE_TITLE,
289                                       NULL));
290 }
291
292 EvLink *
293 ev_link_new_page (const char *title, int page)
294 {
295         return EV_LINK (g_object_new (EV_TYPE_LINK,
296                                       "title", title,
297                                       "page", page,
298                                       "type", EV_LINK_TYPE_PAGE,
299                                       NULL));
300 }
301
302 EvLink *
303 ev_link_new_external (const char *title, const char *uri)
304 {
305         return EV_LINK (g_object_new (EV_TYPE_LINK,
306                                       "title", title,
307                                       "uri", uri,
308                                       "type", EV_LINK_TYPE_EXTERNAL_URI,
309                                       NULL));
310 }