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.
35 struct _EvLinkPrivate {
42 static GObjectClass *parent_class = NULL;
44 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
46 #define EV_LINK_GET_PRIVATE(object) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
50 ev_link_type_get_type (void)
52 static GType type = 0;
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" },
62 type = g_enum_register_static ("EvLinkType", values);
69 ev_link_get_title (EvLink *self)
71 g_return_val_if_fail (EV_IS_LINK (self), NULL);
73 return self->priv->title;
77 ev_link_set_title (EvLink* self, const char *title)
79 g_assert (EV_IS_LINK (self));
80 g_assert (title != NULL);
82 if (self->priv->title != NULL) {
83 g_free (self->priv->title);
86 self->priv->title = g_strdup (title);
88 g_object_notify (G_OBJECT (self), "title");
92 ev_link_get_uri (EvLink *self)
94 g_return_val_if_fail (EV_IS_LINK (self), NULL);
96 return self->priv->uri;
100 ev_link_set_uri (EvLink* self, const char *uri)
102 g_assert (EV_IS_LINK (self));
103 g_assert (uri != NULL);
105 if (self->priv->uri != NULL) {
106 g_free (self->priv->uri);
109 self->priv->uri = g_strdup (uri);
111 g_object_notify (G_OBJECT (self), "uri");
115 ev_link_get_link_type (EvLink *self)
117 g_return_val_if_fail (EV_IS_LINK (self), 0);
119 return self->priv->type;
123 ev_link_set_link_type (EvLink* self, EvLinkType type)
125 g_assert (EV_IS_LINK (self));
127 self->priv->type = type;
129 g_object_notify (G_OBJECT (self), "type");
133 ev_link_get_page (EvLink *self)
135 g_return_val_if_fail (EV_IS_LINK (self), 0);
137 return self->priv->page;
141 ev_link_set_page (EvLink* self, int page)
143 g_assert (EV_IS_LINK (self));
145 self->priv->page = page;
147 g_object_notify (G_OBJECT (self), "page");
151 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
152 GParamSpec *param_spec)
156 self = EV_LINK (object);
160 g_value_set_string (value, self->priv->title);
163 g_value_set_string (value, self->priv->uri);
166 g_value_set_enum (value, self->priv->type);
169 g_value_set_int (value, self->priv->page);
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
180 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
181 GParamSpec *param_spec)
185 self = EV_LINK (object);
189 ev_link_set_title (self, g_value_get_string (value));
192 ev_link_set_uri (self, g_value_get_string (value));
195 ev_link_set_link_type (self, g_value_get_enum (value));
198 ev_link_set_page (self, g_value_get_int (value));
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
209 ev_window_dispose (GObject *object)
213 g_return_if_fail (EV_IS_LINK (object));
215 priv = EV_LINK (object)->priv;
218 g_free (priv->title);
222 G_OBJECT_CLASS (parent_class)->dispose (object);
226 ev_link_init (EvLink *ev_link)
228 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
230 ev_link->priv->type = EV_LINK_TYPE_TITLE;
234 ev_link_class_init (EvLinkClass *ev_window_class)
236 GObjectClass *g_object_class;
238 parent_class = g_type_class_peek_parent (ev_window_class);
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;
245 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
247 g_object_class_install_property (g_object_class,
249 g_param_spec_string ("title",
255 g_object_class_install_property (g_object_class,
257 g_param_spec_string ("uri",
263 g_object_class_install_property (g_object_class,
265 g_param_spec_enum ("type",
272 g_object_class_install_property (g_object_class,
274 g_param_spec_int ("page",
284 ev_link_new_title (const char *title)
286 return EV_LINK (g_object_new (EV_TYPE_LINK,
288 "type", EV_LINK_TYPE_TITLE,
293 ev_link_new_page (const char *title, int page)
295 return EV_LINK (g_object_new (EV_TYPE_LINK,
298 "type", EV_LINK_TYPE_PAGE,
303 ev_link_new_external (const char *title, const char *uri)
305 return EV_LINK (g_object_new (EV_TYPE_LINK,
308 "type", EV_LINK_TYPE_EXTERNAL_URI,