1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
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.
22 #include "ev-link-action.h"
23 #include "ev-document-type-builtins.h"
35 struct _EvLinkAction {
36 GObject base_instance;
38 EvLinkActionPrivate *priv;
41 struct _EvLinkActionClass {
42 GObjectClass base_class;
45 struct _EvLinkActionPrivate {
46 EvLinkActionType type;
54 G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT)
56 #define EV_LINK_ACTION_GET_PRIVATE(object) \
57 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_ACTION, EvLinkActionPrivate))
60 ev_link_action_get_action_type (EvLinkAction *self)
62 g_return_val_if_fail (EV_IS_LINK_ACTION (self), 0);
64 return self->priv->type;
68 ev_link_action_get_dest (EvLinkAction *self)
70 g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
72 return self->priv->dest;
76 ev_link_action_get_uri (EvLinkAction *self)
78 g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
80 return self->priv->uri;
84 ev_link_action_get_filename (EvLinkAction *self)
86 g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
88 return self->priv->filename;
92 ev_link_action_get_params (EvLinkAction *self)
94 g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
96 return self->priv->params;
100 ev_link_action_get_name (EvLinkAction *self)
102 g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
104 return self->priv->name;
108 ev_link_action_get_property (GObject *object,
111 GParamSpec *param_spec)
115 self = EV_LINK_ACTION (object);
119 g_value_set_enum (value, self->priv->type);
122 g_value_set_pointer (value, self->priv->dest);
125 g_value_set_string (value, self->priv->uri);
128 g_value_set_string (value, self->priv->filename);
131 g_value_set_string (value, self->priv->params);
134 g_value_set_string (value, self->priv->name);
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
145 ev_link_action_set_property (GObject *object,
148 GParamSpec *param_spec)
150 EvLinkAction *self = EV_LINK_ACTION (object);
154 self->priv->type = g_value_get_enum (value);
157 self->priv->dest = g_value_get_pointer (value);
160 g_free (self->priv->uri);
161 self->priv->uri = g_value_dup_string (value);
164 g_free (self->priv->filename);
165 self->priv->filename = g_value_dup_string (value);
168 g_free (self->priv->params);
169 self->priv->params = g_value_dup_string (value);
172 g_free (self->priv->name);
173 self->priv->name = g_value_dup_string (value);
176 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
184 ev_link_action_finalize (GObject *object)
186 EvLinkActionPrivate *priv;
188 priv = EV_LINK_ACTION (object)->priv;
191 g_object_unref (priv->dest);
200 if (priv->filename) {
201 g_free (priv->filename);
202 priv->filename = NULL;
206 g_free (priv->params);
215 G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object);
219 ev_link_action_init (EvLinkAction *ev_link_action)
221 ev_link_action->priv = EV_LINK_ACTION_GET_PRIVATE (ev_link_action);
223 ev_link_action->priv->dest = NULL;
224 ev_link_action->priv->uri = NULL;
225 ev_link_action->priv->filename = NULL;
226 ev_link_action->priv->params = NULL;
227 ev_link_action->priv->name = NULL;
231 ev_link_action_class_init (EvLinkActionClass *ev_link_action_class)
233 GObjectClass *g_object_class;
235 g_object_class = G_OBJECT_CLASS (ev_link_action_class);
237 g_object_class->set_property = ev_link_action_set_property;
238 g_object_class->get_property = ev_link_action_get_property;
240 g_object_class->finalize = ev_link_action_finalize;
242 g_type_class_add_private (g_object_class, sizeof (EvLinkActionPrivate));
244 g_object_class_install_property (g_object_class,
246 g_param_spec_enum ("type",
248 "The link action type",
249 EV_TYPE_LINK_ACTION_TYPE,
250 EV_LINK_ACTION_TYPE_GOTO_DEST,
252 G_PARAM_CONSTRUCT_ONLY));
253 g_object_class_install_property (g_object_class,
255 g_param_spec_pointer ("dest",
256 "Action destination",
257 "The link action destination",
259 G_PARAM_CONSTRUCT_ONLY));
260 g_object_class_install_property (g_object_class,
262 g_param_spec_string ("uri",
264 "The link action URI",
267 G_PARAM_CONSTRUCT_ONLY));
268 g_object_class_install_property (g_object_class,
270 g_param_spec_string ("filename",
272 "The link action filename",
275 G_PARAM_CONSTRUCT_ONLY));
276 g_object_class_install_property (g_object_class,
278 g_param_spec_string ("params",
280 "The link action params",
283 G_PARAM_CONSTRUCT_ONLY));
284 g_object_class_install_property (g_object_class,
286 g_param_spec_string ("name",
288 "The link action name",
291 G_PARAM_CONSTRUCT_ONLY));
295 ev_link_action_new_dest (EvLinkDest *dest)
297 return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
299 "type", EV_LINK_ACTION_TYPE_GOTO_DEST,
304 ev_link_action_new_remote (EvLinkDest *dest,
305 const gchar *filename)
307 return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
309 "filename", filename,
310 "type", EV_LINK_ACTION_TYPE_GOTO_REMOTE,
315 ev_link_action_new_external_uri (const gchar *uri)
317 return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
319 "type", EV_LINK_ACTION_TYPE_EXTERNAL_URI,
324 ev_link_action_new_launch (const gchar *filename,
327 return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
328 "filename", filename,
330 "type", EV_LINK_ACTION_TYPE_LAUNCH,
335 ev_link_action_new_named (const gchar *name)
337 return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
339 "type", EV_LINK_ACTION_TYPE_NAMED,