Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-link-action.c
Go to the documentation of this file.
1 /* this file is part of evince, a gnome document viewer
2  *
3  * Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include <config.h>
22 #include "ev-link-action.h"
23 #include "ev-document-type-builtins.h"
24 
25 enum {
36 };
37 
38 struct _EvLinkAction {
39  GObject base_instance;
40 
42 };
43 
45  GObjectClass base_class;
46 };
47 
51  gchar *uri;
52  gchar *filename;
53  gchar *params;
54  gchar *name;
55  GList *show_list;
56  GList *hide_list;
57  GList *toggle_list;
58 };
59 
60 G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT)
61 
62 #define EV_LINK_ACTION_GET_PRIVATE(object) \
63  (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_ACTION, EvLinkActionPrivate))
64 
67 {
68  g_return_val_if_fail (EV_IS_LINK_ACTION (self), 0);
69 
70  return self->priv->type;
71 }
72 
79 EvLinkDest *
81 {
82  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
83 
84  return self->priv->dest;
85 }
86 
87 const gchar *
89 {
90  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
91 
92  return self->priv->uri;
93 }
94 
95 const gchar *
97 {
98  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
99 
100  return self->priv->filename;
101 }
102 
103 const gchar *
105 {
106  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
107 
108  return self->priv->params;
109 }
110 
111 const gchar *
113 {
114  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
115 
116  return self->priv->name;
117 }
118 
125 GList *
127 {
128  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
129 
130  return self->priv->show_list;
131 }
132 
139 GList *
141 {
142  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
143 
144  return self->priv->hide_list;
145 }
146 
153 GList *
155 {
156  g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
157 
158  return self->priv->toggle_list;
159 }
160 
161 static void
163  guint prop_id,
164  GValue *value,
165  GParamSpec *param_spec)
166 {
167  EvLinkAction *self;
168 
169  self = EV_LINK_ACTION (object);
170 
171  switch (prop_id) {
172  case PROP_TYPE:
173  g_value_set_enum (value, self->priv->type);
174  break;
175  case PROP_DEST:
176  g_value_set_object (value, self->priv->dest);
177  break;
178  case PROP_URI:
179  g_value_set_string (value, self->priv->uri);
180  break;
181  case PROP_FILENAME:
182  g_value_set_string (value, self->priv->filename);
183  break;
184  case PROP_PARAMS:
185  g_value_set_string (value, self->priv->params);
186  break;
187  case PROP_NAME:
188  g_value_set_string (value, self->priv->name);
189  break;
190  case PROP_SHOW_LIST:
191  g_value_set_pointer (value, self->priv->show_list);
192  break;
193  case PROP_HIDE_LIST:
194  g_value_set_pointer (value, self->priv->hide_list);
195  break;
196  case PROP_TOGGLE_LIST:
197  g_value_set_pointer (value, self->priv->toggle_list);
198  break;
199  default:
200  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
201  prop_id,
202  param_spec);
203  break;
204  }
205 }
206 
207 static void
209  guint prop_id,
210  const GValue *value,
211  GParamSpec *param_spec)
212 {
213  EvLinkAction *self = EV_LINK_ACTION (object);
214 
215  switch (prop_id) {
216  case PROP_TYPE:
217  self->priv->type = g_value_get_enum (value);
218  break;
219  case PROP_DEST:
220  self->priv->dest = g_value_dup_object (value);
221  break;
222  case PROP_URI:
223  g_free (self->priv->uri);
224  self->priv->uri = g_value_dup_string (value);
225  break;
226  case PROP_FILENAME:
227  g_free (self->priv->filename);
228  self->priv->filename = g_value_dup_string (value);
229  break;
230  case PROP_PARAMS:
231  g_free (self->priv->params);
232  self->priv->params = g_value_dup_string (value);
233  break;
234  case PROP_NAME:
235  g_free (self->priv->name);
236  self->priv->name = g_value_dup_string (value);
237  break;
238  case PROP_SHOW_LIST:
239  self->priv->show_list = g_value_get_pointer (value);
240  break;
241  case PROP_HIDE_LIST:
242  self->priv->hide_list = g_value_get_pointer (value);
243  break;
244  case PROP_TOGGLE_LIST:
245  self->priv->toggle_list = g_value_get_pointer (value);
246  break;
247  default:
248  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
249  prop_id,
250  param_spec);
251  break;
252  }
253 }
254 
255 static void
256 ev_link_action_finalize (GObject *object)
257 {
258  EvLinkActionPrivate *priv;
259 
260  priv = EV_LINK_ACTION (object)->priv;
261 
262  g_clear_object (&priv->dest);
263 
264  if (priv->uri) {
265  g_free (priv->uri);
266  priv->uri = NULL;
267  }
268 
269  if (priv->filename) {
270  g_free (priv->filename);
271  priv->filename = NULL;
272  }
273 
274  if (priv->params) {
275  g_free (priv->params);
276  priv->params = NULL;
277  }
278 
279  if (priv->name) {
280  g_free (priv->name);
281  priv->name = NULL;
282  }
283 
284  if (priv->show_list) {
285  g_list_foreach (priv->show_list, (GFunc)g_object_unref, NULL);
286  g_list_free (priv->show_list);
287  priv->show_list = NULL;
288  }
289 
290  if (priv->hide_list) {
291  g_list_foreach (priv->hide_list, (GFunc)g_object_unref, NULL);
292  g_list_free (priv->hide_list);
293  priv->hide_list = NULL;
294  }
295 
296  if (priv->toggle_list) {
297  g_list_foreach (priv->toggle_list, (GFunc)g_object_unref, NULL);
298  g_list_free (priv->toggle_list);
299  priv->toggle_list = NULL;
300  }
301 
302  G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object);
303 }
304 
305 static void
307 {
308  ev_link_action->priv = EV_LINK_ACTION_GET_PRIVATE (ev_link_action);
309 
310  ev_link_action->priv->dest = NULL;
311  ev_link_action->priv->uri = NULL;
312  ev_link_action->priv->filename = NULL;
313  ev_link_action->priv->params = NULL;
314  ev_link_action->priv->name = NULL;
315 }
316 
317 static void
319 {
320  GObjectClass *g_object_class;
321 
322  g_object_class = G_OBJECT_CLASS (ev_link_action_class);
323 
324  g_object_class->set_property = ev_link_action_set_property;
325  g_object_class->get_property = ev_link_action_get_property;
326 
327  g_object_class->finalize = ev_link_action_finalize;
328 
329  g_type_class_add_private (g_object_class, sizeof (EvLinkActionPrivate));
330 
331  g_object_class_install_property (g_object_class,
332  PROP_TYPE,
333  g_param_spec_enum ("type",
334  "Action Type",
335  "The link action type",
336  EV_TYPE_LINK_ACTION_TYPE,
338  G_PARAM_READWRITE |
339  G_PARAM_CONSTRUCT_ONLY |
340  G_PARAM_STATIC_STRINGS));
341  g_object_class_install_property (g_object_class,
342  PROP_DEST,
343  g_param_spec_object ("dest",
344  "Action destination",
345  "The link action destination",
347  G_PARAM_READWRITE |
348  G_PARAM_CONSTRUCT_ONLY |
349  G_PARAM_STATIC_STRINGS));
350  g_object_class_install_property (g_object_class,
351  PROP_URI,
352  g_param_spec_string ("uri",
353  "Link Action URI",
354  "The link action URI",
355  NULL,
356  G_PARAM_READWRITE |
357  G_PARAM_CONSTRUCT_ONLY |
358  G_PARAM_STATIC_STRINGS));
359  g_object_class_install_property (g_object_class,
361  g_param_spec_string ("filename",
362  "Filename",
363  "The link action filename",
364  NULL,
365  G_PARAM_READWRITE |
366  G_PARAM_CONSTRUCT_ONLY |
367  G_PARAM_STATIC_STRINGS));
368  g_object_class_install_property (g_object_class,
369  PROP_PARAMS,
370  g_param_spec_string ("params",
371  "Params",
372  "The link action params",
373  NULL,
374  G_PARAM_READWRITE |
375  G_PARAM_CONSTRUCT_ONLY |
376  G_PARAM_STATIC_STRINGS));
377  g_object_class_install_property (g_object_class,
378  PROP_NAME,
379  g_param_spec_string ("name",
380  "Name",
381  "The link action name",
382  NULL,
383  G_PARAM_READWRITE |
384  G_PARAM_CONSTRUCT_ONLY |
385  G_PARAM_STATIC_STRINGS));
386  g_object_class_install_property (g_object_class,
388  g_param_spec_pointer ("show-list",
389  "ShowList",
390  "The list of layers that should be shown",
391  G_PARAM_READWRITE |
392  G_PARAM_CONSTRUCT_ONLY |
393  G_PARAM_STATIC_STRINGS));
394  g_object_class_install_property (g_object_class,
396  g_param_spec_pointer ("hide-list",
397  "HideList",
398  "The list of layers that should be hidden",
399  G_PARAM_READWRITE |
400  G_PARAM_CONSTRUCT_ONLY |
401  G_PARAM_STATIC_STRINGS));
402  g_object_class_install_property (g_object_class,
404  g_param_spec_pointer ("toggle-list",
405  "ToggleList",
406  "The list of layers that should be toggled",
407  G_PARAM_READWRITE |
408  G_PARAM_CONSTRUCT_ONLY |
409  G_PARAM_STATIC_STRINGS));
410 }
411 
412 EvLinkAction *
414 {
415  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
416  "dest", dest,
418  NULL));
419 }
420 
421 EvLinkAction *
423  const gchar *filename)
424 {
425  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
426  "dest", dest,
427  "filename", filename,
429  NULL));
430 }
431 
432 EvLinkAction *
434 {
435  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
436  "uri", uri,
438  NULL));
439 }
440 
441 EvLinkAction *
442 ev_link_action_new_launch (const gchar *filename,
443  const gchar *params)
444 {
445  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
446  "filename", filename,
447  "params", params,
449  NULL));
450 }
451 
452 EvLinkAction *
454 {
455  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
456  "name", name,
458  NULL));
459 }
460 
469 EvLinkAction *
471  GList *hide_list,
472  GList *toggle_list)
473 {
474  return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
475  "show-list", show_list,
476  "hide-list", hide_list,
477  "toggle-list", toggle_list,
479  NULL));
480 }
481 
493 gboolean
495  EvLinkAction *b)
496 {
497  g_return_val_if_fail (EV_IS_LINK_ACTION (a), FALSE);
498  g_return_val_if_fail (EV_IS_LINK_ACTION (b), FALSE);
499 
500  if (a == b)
501  return TRUE;
502 
503  if (a->priv->type != b->priv->type)
504  return FALSE;
505 
506  switch (a->priv->type) {
508  return ev_link_dest_equal (a->priv->dest, b->priv->dest);
509 
511  return ev_link_dest_equal (a->priv->dest, b->priv->dest) &&
512  !g_strcmp0 (a->priv->filename, b->priv->filename);
513 
515  return !g_strcmp0 (a->priv->uri, b->priv->uri);
516 
518  return !g_strcmp0 (a->priv->filename, b->priv->filename) &&
519  !g_strcmp0 (a->priv->params, b->priv->params);
520 
522  return !g_strcmp0 (a->priv->name, b->priv->name);
523 
524  default:
525  return FALSE;
526  }
527 
528  return FALSE;
529 }