]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-link-action.c
[libdocument] Remove ev_tmp_dir()
[evince.git] / libdocument / ev-link-action.c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22 #include "ev-link-action.h"
23 #include "ev-document-type-builtins.h"
24
25 enum {
26         PROP_0,
27         PROP_TYPE,
28         PROP_DEST,
29         PROP_URI,
30         PROP_FILENAME,
31         PROP_PARAMS,
32         PROP_NAME
33 };
34
35 struct _EvLinkAction {
36         GObject base_instance;
37
38         EvLinkActionPrivate *priv;
39 };
40
41 struct _EvLinkActionClass {
42         GObjectClass base_class;
43 };
44
45 struct _EvLinkActionPrivate {
46         EvLinkActionType  type;
47         EvLinkDest       *dest;
48         gchar            *uri;
49         gchar            *filename;
50         gchar            *params;
51         gchar            *name;
52 };
53
54 G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT)
55
56 #define EV_LINK_ACTION_GET_PRIVATE(object) \
57         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_ACTION, EvLinkActionPrivate))
58
59 EvLinkActionType
60 ev_link_action_get_action_type (EvLinkAction *self)
61 {
62         g_return_val_if_fail (EV_IS_LINK_ACTION (self), 0);
63
64         return self->priv->type;
65 }
66
67 EvLinkDest *
68 ev_link_action_get_dest (EvLinkAction *self)
69 {
70         g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
71
72         return self->priv->dest;
73 }
74
75 const gchar *
76 ev_link_action_get_uri (EvLinkAction *self)
77 {
78         g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
79
80         return self->priv->uri;
81 }
82
83 const gchar *
84 ev_link_action_get_filename (EvLinkAction *self)
85 {
86         g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
87
88         return self->priv->filename;
89 }
90
91 const gchar *
92 ev_link_action_get_params (EvLinkAction *self)
93 {
94         g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
95
96         return self->priv->params;
97 }
98
99 const gchar *
100 ev_link_action_get_name (EvLinkAction *self)
101 {
102         g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
103
104         return self->priv->name;
105 }
106
107 static void
108 ev_link_action_get_property (GObject    *object,
109                              guint       prop_id,
110                              GValue     *value,
111                              GParamSpec *param_spec)
112 {
113         EvLinkAction *self;
114
115         self = EV_LINK_ACTION (object);
116
117         switch (prop_id) {
118                 case PROP_TYPE:
119                         g_value_set_enum (value, self->priv->type);
120                         break;
121                 case PROP_DEST:
122                         g_value_set_pointer (value, self->priv->dest);
123                         break;
124                 case PROP_URI:
125                         g_value_set_string (value, self->priv->uri);
126                         break;
127                 case PROP_FILENAME:
128                         g_value_set_string (value, self->priv->filename);
129                         break;
130                 case PROP_PARAMS:
131                         g_value_set_string (value, self->priv->params);
132                         break;
133                 case PROP_NAME:
134                         g_value_set_string (value, self->priv->name);
135                         break;
136                 default:
137                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
138                                                            prop_id,
139                                                            param_spec);
140                         break;
141         }
142 }
143
144 static void
145 ev_link_action_set_property (GObject      *object,
146                              guint         prop_id,
147                              const GValue *value,
148                              GParamSpec   *param_spec)
149 {
150         EvLinkAction *self = EV_LINK_ACTION (object);
151
152         switch (prop_id) {
153                 case PROP_TYPE:
154                         self->priv->type = g_value_get_enum (value);
155                         break;
156                 case PROP_DEST:
157                         self->priv->dest = g_value_get_pointer (value);
158                         break;
159                 case PROP_URI:
160                         g_free (self->priv->uri);
161                         self->priv->uri = g_value_dup_string (value);
162                         break;
163                 case PROP_FILENAME:
164                         g_free (self->priv->filename);
165                         self->priv->filename = g_value_dup_string (value);
166                         break;
167                 case PROP_PARAMS:
168                         g_free (self->priv->params);
169                         self->priv->params = g_value_dup_string (value);
170                         break;
171                 case PROP_NAME:
172                         g_free (self->priv->name);
173                         self->priv->name = g_value_dup_string (value);
174                         break;
175                 default:
176                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
177                                                            prop_id,
178                                                            param_spec);
179                         break;
180         }
181 }
182
183 static void
184 ev_link_action_finalize (GObject *object)
185 {
186         EvLinkActionPrivate *priv;
187
188         priv = EV_LINK_ACTION (object)->priv;
189
190         if (priv->dest) {
191                 g_object_unref (priv->dest);
192                 priv->dest = NULL;
193         }
194
195         if (priv->uri) {
196                 g_free (priv->uri);
197                 priv->uri = NULL;
198         }
199
200         if (priv->filename) {
201                 g_free (priv->filename);
202                 priv->filename = NULL;
203         }
204
205         if (priv->params) {
206                 g_free (priv->params);
207                 priv->params = NULL;
208         }
209
210         if (priv->name) {
211                 g_free (priv->name);
212                 priv->name = NULL;
213         }
214
215         G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object);
216 }
217
218 static void
219 ev_link_action_init (EvLinkAction *ev_link_action)
220 {
221         ev_link_action->priv = EV_LINK_ACTION_GET_PRIVATE (ev_link_action);
222
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;
228 }
229
230 static void
231 ev_link_action_class_init (EvLinkActionClass *ev_link_action_class)
232 {
233         GObjectClass *g_object_class;
234
235         g_object_class = G_OBJECT_CLASS (ev_link_action_class);
236
237         g_object_class->set_property = ev_link_action_set_property;
238         g_object_class->get_property = ev_link_action_get_property;
239
240         g_object_class->finalize = ev_link_action_finalize;
241
242         g_type_class_add_private (g_object_class, sizeof (EvLinkActionPrivate));
243
244         g_object_class_install_property (g_object_class,
245                                          PROP_TYPE,
246                                          g_param_spec_enum  ("type",
247                                                              "Action Type",
248                                                              "The link action type",
249                                                              EV_TYPE_LINK_ACTION_TYPE,
250                                                              EV_LINK_ACTION_TYPE_GOTO_DEST,
251                                                              G_PARAM_READWRITE |
252                                                              G_PARAM_CONSTRUCT_ONLY));
253         g_object_class_install_property (g_object_class,
254                                          PROP_DEST,
255                                          g_param_spec_pointer ("dest",
256                                                                "Action destination",
257                                                                "The link action destination",
258                                                                G_PARAM_READWRITE |
259                                                                G_PARAM_CONSTRUCT_ONLY));
260         g_object_class_install_property (g_object_class,
261                                          PROP_URI,
262                                          g_param_spec_string ("uri",
263                                                               "Link Action URI",
264                                                               "The link action URI",
265                                                               NULL,
266                                                               G_PARAM_READWRITE |
267                                                               G_PARAM_CONSTRUCT_ONLY));
268         g_object_class_install_property (g_object_class,
269                                          PROP_FILENAME,
270                                          g_param_spec_string ("filename",
271                                                               "Filename",
272                                                               "The link action filename",
273                                                               NULL,
274                                                               G_PARAM_READWRITE |
275                                                               G_PARAM_CONSTRUCT_ONLY));
276         g_object_class_install_property (g_object_class,
277                                          PROP_PARAMS,
278                                          g_param_spec_string ("params",
279                                                               "Params",
280                                                               "The link action params",
281                                                               NULL,
282                                                               G_PARAM_READWRITE |
283                                                               G_PARAM_CONSTRUCT_ONLY));
284         g_object_class_install_property (g_object_class,
285                                          PROP_NAME,
286                                          g_param_spec_string ("name",
287                                                               "Name",
288                                                               "The link action name",
289                                                               NULL,
290                                                               G_PARAM_READWRITE |
291                                                               G_PARAM_CONSTRUCT_ONLY));
292 }
293
294 EvLinkAction *
295 ev_link_action_new_dest (EvLinkDest *dest)
296 {
297         return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
298                                              "dest", dest,
299                                              "type", EV_LINK_ACTION_TYPE_GOTO_DEST,
300                                              NULL));
301 }
302
303 EvLinkAction *
304 ev_link_action_new_remote (EvLinkDest  *dest,
305                            const gchar *filename)
306 {
307         return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
308                                              "dest", dest,
309                                              "filename", filename,
310                                              "type", EV_LINK_ACTION_TYPE_GOTO_REMOTE,
311                                              NULL));
312 }
313
314 EvLinkAction *
315 ev_link_action_new_external_uri (const gchar *uri)
316 {
317         return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
318                                              "uri", uri,
319                                              "type", EV_LINK_ACTION_TYPE_EXTERNAL_URI,
320                                              NULL));
321 }
322
323 EvLinkAction *
324 ev_link_action_new_launch (const gchar *filename,
325                            const gchar *params)
326 {
327         return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
328                                              "filename", filename,
329                                              "params", params,
330                                              "type", EV_LINK_ACTION_TYPE_LAUNCH,
331                                              NULL));
332 }
333
334 EvLinkAction *
335 ev_link_action_new_named (const gchar *name)
336 {
337         return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
338                                              "name", name,
339                                              "type", EV_LINK_ACTION_TYPE_NAMED,
340                                              NULL));
341 }