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
4 * Copyright (C) 2005 Red Hat, Inc.
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.
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.
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.
37 GObject base_instance;
42 GObjectClass base_class;
45 struct _EvLinkPrivate {
52 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
54 #define EV_LINK_GET_PRIVATE(object) \
55 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
58 ev_link_type_get_type (void)
60 static GType type = 0;
62 if (G_UNLIKELY (type == 0)) {
63 static const GEnumValue values[] = {
64 { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
65 { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
66 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
70 type = g_enum_register_static ("EvLinkType", values);
77 ev_link_get_title (EvLink *self)
79 g_return_val_if_fail (EV_IS_LINK (self), NULL);
81 return self->priv->title;
85 ev_link_set_title (EvLink* self, const char *title)
87 g_assert (EV_IS_LINK (self));
88 g_assert (title != NULL);
90 if (self->priv->title != NULL) {
91 g_free (self->priv->title);
94 self->priv->title = g_strdup (title);
96 g_object_notify (G_OBJECT (self), "title");
100 ev_link_get_uri (EvLink *self)
102 g_return_val_if_fail (EV_IS_LINK (self), NULL);
104 return self->priv->uri;
108 ev_link_set_uri (EvLink* self, const char *uri)
110 g_assert (EV_IS_LINK (self));
111 g_assert (uri != NULL);
113 if (self->priv->uri != NULL) {
114 g_free (self->priv->uri);
117 self->priv->uri = g_strdup (uri);
119 g_object_notify (G_OBJECT (self), "uri");
123 ev_link_get_link_type (EvLink *self)
125 g_return_val_if_fail (EV_IS_LINK (self), 0);
127 return self->priv->type;
131 ev_link_set_link_type (EvLink* self, EvLinkType type)
133 g_assert (EV_IS_LINK (self));
135 self->priv->type = type;
137 g_object_notify (G_OBJECT (self), "type");
141 ev_link_get_page (EvLink *self)
143 g_return_val_if_fail (EV_IS_LINK (self), 0);
145 return self->priv->page;
149 ev_link_set_page (EvLink* self, int page)
151 g_assert (EV_IS_LINK (self));
153 self->priv->page = page;
155 g_object_notify (G_OBJECT (self), "page");
159 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
160 GParamSpec *param_spec)
164 self = EV_LINK (object);
168 g_value_set_string (value, self->priv->title);
171 g_value_set_string (value, self->priv->uri);
174 g_value_set_enum (value, self->priv->type);
177 g_value_set_int (value, self->priv->page);
180 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
188 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
189 GParamSpec *param_spec)
193 self = EV_LINK (object);
197 ev_link_set_title (self, g_value_get_string (value));
200 ev_link_set_uri (self, g_value_get_string (value));
203 ev_link_set_link_type (self, g_value_get_enum (value));
206 ev_link_set_page (self, g_value_get_int (value));
209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
217 ev_window_dispose (GObject *object)
221 g_return_if_fail (EV_IS_LINK (object));
223 priv = EV_LINK (object)->priv;
226 g_free (priv->title);
230 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
234 ev_link_init (EvLink *ev_link)
236 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
238 ev_link->priv->type = EV_LINK_TYPE_TITLE;
242 ev_link_class_init (EvLinkClass *ev_window_class)
244 GObjectClass *g_object_class;
246 g_object_class = G_OBJECT_CLASS (ev_window_class);
247 g_object_class->dispose = ev_window_dispose;
248 g_object_class->set_property = ev_link_set_property;
249 g_object_class->get_property = ev_link_get_property;
251 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
253 g_object_class_install_property (g_object_class,
255 g_param_spec_string ("title",
261 g_object_class_install_property (g_object_class,
263 g_param_spec_string ("uri",
269 g_object_class_install_property (g_object_class,
271 g_param_spec_enum ("type",
278 g_object_class_install_property (g_object_class,
280 g_param_spec_int ("page",
290 ev_link_new_title (const char *title)
292 return EV_LINK (g_object_new (EV_TYPE_LINK,
294 "type", EV_LINK_TYPE_TITLE,
299 ev_link_new_page (const char *title, int page)
301 return EV_LINK (g_object_new (EV_TYPE_LINK,
304 "type", EV_LINK_TYPE_PAGE,
309 ev_link_new_external (const char *title, const char *uri)
311 return EV_LINK (g_object_new (EV_TYPE_LINK,
314 "type", EV_LINK_TYPE_EXTERNAL_URI,