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.c
Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include <config.h>
22 #include "ev-link.h"
23 
24 enum {
28 };
29 
30 struct _EvLink {
31  GObject base_instance;
33 };
34 
35 struct _EvLinkClass {
36  GObjectClass base_class;
37 };
38 
40  gchar *title;
42 };
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 const gchar *
51 {
52  g_return_val_if_fail (EV_IS_LINK (self), NULL);
53 
54  return self->priv->title;
55 }
56 
65 {
66  g_return_val_if_fail (EV_IS_LINK (self), NULL);
67 
68  return self->priv->action;
69 }
70 
71 static void
72 ev_link_get_property (GObject *object,
73  guint prop_id,
74  GValue *value,
75  GParamSpec *param_spec)
76 {
77  EvLink *self;
78 
79  self = EV_LINK (object);
80 
81  switch (prop_id) {
82  case PROP_TITLE:
83  g_value_set_string (value, self->priv->title);
84  break;
85  case PROP_ACTION:
86  g_value_set_object (value, self->priv->action);
87  break;
88  default:
89  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
90  prop_id,
91  param_spec);
92  break;
93  }
94 }
95 
96 static void
97 ev_link_set_property (GObject *object,
98  guint prop_id,
99  const GValue *value,
100  GParamSpec *param_spec)
101 {
102  EvLink *self = EV_LINK (object);
103 
104  switch (prop_id) {
105  case PROP_TITLE:
106  self->priv->title = g_value_dup_string (value);
107  break;
108  case PROP_ACTION:
109  self->priv->action = g_value_dup_object (value);
110  break;
111  default:
112  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
113  prop_id,
114  param_spec);
115  break;
116  }
117 }
118 
119 static void
120 ev_link_finalize (GObject *object)
121 {
122  EvLinkPrivate *priv;
123 
124  priv = EV_LINK (object)->priv;
125 
126  if (priv->title) {
127  g_free (priv->title);
128  priv->title = NULL;
129  }
130 
131  g_clear_object (&priv->action);
132 
133  G_OBJECT_CLASS (ev_link_parent_class)->finalize (object);
134 }
135 
136 static void
138 {
139  ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
140 
141  ev_link->priv->title = NULL;
142  ev_link->priv->action = NULL;
143 }
144 
145 static void
146 ev_link_class_init (EvLinkClass *ev_window_class)
147 {
148  GObjectClass *g_object_class;
149 
150  g_object_class = G_OBJECT_CLASS (ev_window_class);
151 
152  g_object_class->set_property = ev_link_set_property;
153  g_object_class->get_property = ev_link_get_property;
154 
155  g_object_class->finalize = ev_link_finalize;
156 
157  g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
158 
159  g_object_class_install_property (g_object_class,
160  PROP_TITLE,
161  g_param_spec_string ("title",
162  "Link Title",
163  "The link title",
164  NULL,
165  G_PARAM_READWRITE |
166  G_PARAM_CONSTRUCT_ONLY |
167  G_PARAM_STATIC_STRINGS));
168  g_object_class_install_property (g_object_class,
169  PROP_ACTION,
170  g_param_spec_object ("action",
171  "Link Action",
172  "The link action",
174  G_PARAM_READWRITE |
175  G_PARAM_CONSTRUCT_ONLY |
176  G_PARAM_STATIC_STRINGS));
177 }
178 
179 EvLink *
180 ev_link_new (const char *title,
181  EvLinkAction *action)
182 {
183  return EV_LINK (g_object_new (EV_TYPE_LINK,
184  "title", title,
185  "action", action,
186  NULL));
187 }
188 
189