summaryrefslogtreecommitdiff
path: root/libdocument/ev-link.c
blob: e7757ce2d0efadcf8caf126d9cb153ef766a04de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of atril, a mate document viewer
 *
 *  Copyright (C) 2005 Red Hat, Inc.
 *
 * Atril is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Atril is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include "ev-link.h"

enum {
	PROP_0,
	PROP_TITLE,
	PROP_ACTION
};

struct _EvLink {
	GObject base_instance;
	EvLinkPrivate *priv;
};

struct _EvLinkClass {
	GObjectClass base_class;
};

struct _EvLinkPrivate {
	gchar        *title;
	EvLinkAction *action;
};

G_DEFINE_TYPE_WITH_PRIVATE (EvLink, ev_link, G_TYPE_OBJECT)

const gchar *
ev_link_get_title (EvLink *self)
{
	g_return_val_if_fail (EV_IS_LINK (self), NULL);

	return self->priv->title;
}

EvLinkAction *
ev_link_get_action (EvLink *self)
{
	g_return_val_if_fail (EV_IS_LINK (self), NULL);

	return self->priv->action;
}

static void
ev_link_get_property (GObject    *object,
		      guint       prop_id,
		      GValue     *value,
		      GParamSpec *param_spec)
{
	EvLink *self;

	self = EV_LINK (object);

	switch (prop_id) {
	        case PROP_TITLE:
			g_value_set_string (value, self->priv->title);
			break;
	        case PROP_ACTION:
			g_value_set_pointer (value, self->priv->action);
			break;
	        default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
							   prop_id,
							   param_spec);
			break;
	}
}

static void
ev_link_set_property (GObject      *object,
		      guint         prop_id,
		      const GValue *value,
		      GParamSpec   *param_spec)
{
	EvLink *self = EV_LINK (object);

	switch (prop_id) {
	        case PROP_TITLE:
			self->priv->title = g_value_dup_string (value);
			break;
	        case PROP_ACTION:
			self->priv->action = g_value_get_pointer (value);
			break;
	        default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
							   prop_id,
							   param_spec);
			break;
	}
}

static void
ev_link_finalize (GObject *object)
{
	EvLinkPrivate *priv;

	priv = EV_LINK (object)->priv;

	if (priv->title) {
		g_free (priv->title);
		priv->title = NULL;
	}

	if (priv->action) {
		g_object_unref (priv->action);
		priv->action = NULL;
	}

	G_OBJECT_CLASS (ev_link_parent_class)->finalize (object);
}

static void
ev_link_init (EvLink *ev_link)
{
	ev_link->priv = ev_link_get_instance_private (ev_link);

	ev_link->priv->title = NULL;
	ev_link->priv->action = NULL;
}

static void
ev_link_class_init (EvLinkClass *ev_window_class)
{
	GObjectClass *g_object_class;

	g_object_class = G_OBJECT_CLASS (ev_window_class);

	g_object_class->set_property = ev_link_set_property;
	g_object_class->get_property = ev_link_get_property;

	g_object_class->finalize = ev_link_finalize;

	g_object_class_install_property (g_object_class,
					 PROP_TITLE,
					 g_param_spec_string ("title",
				     	 		      "Link Title",
				     			      "The link title",
							      NULL,
							      G_PARAM_READWRITE |
				     			      G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (g_object_class,
					 PROP_ACTION,
					 g_param_spec_pointer ("action",
							       "Link Action",
							       "The link action",
							       G_PARAM_READWRITE |
							       G_PARAM_CONSTRUCT_ONLY));
}

EvLink *
ev_link_new (const char   *title,
	     EvLinkAction *action)
{
	return EV_LINK (g_object_new (EV_TYPE_LINK,
				      "title", title,
				      "action", action,
				      NULL));
}