File: pps-outlines.c

package info (click to toggle)
papers 49.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,140 kB
  • sloc: ansic: 37,721; sh: 197; xml: 127; makefile: 112
file content (267 lines) | stat: -rw-r--r-- 7,865 bytes parent folder | download
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// SPDX-License-Identifier: GPL-2.0-or-later
/* this file is part of papers, a gnome document viewer
 *
 *  Copyright (C) 2022 Qiu Wenbo
 */

#include "pps-outlines.h"

struct _PpsOutlinesPrivate {
	gchar *markup;
	gchar *label;
	gboolean expand;
	PpsLink *link;
	GListModel *children;
};

typedef struct _PpsOutlinesPrivate PpsOutlinesPrivate;
#define GET_PRIVATE(o) pps_outlines_get_instance_private (o)

G_DEFINE_TYPE_WITH_PRIVATE (PpsOutlines, pps_outlines, G_TYPE_OBJECT)

enum {
	PROP_0,
	PROP_MARKUP,
	PROP_LABEL,
	PROP_EXPAND,
	PROP_CHILDREN,
	PROP_LINK,
};

void
pps_outlines_set_markup (PpsOutlines *pps_outlines,
                         const gchar *markup)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);

	priv->markup = g_strdup (markup);

	g_object_notify (G_OBJECT (pps_outlines), "markup");
}

void
pps_outlines_set_label (PpsOutlines *pps_outlines,
                        const gchar *label)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);

	priv->label = g_strdup (label);

	g_object_notify (G_OBJECT (pps_outlines), "label");
}

static void
pps_outlines_set_property (GObject *object,
                           guint prop_id,
                           const GValue *value,
                           GParamSpec *pspec)
{
	PpsOutlines *outlines = PPS_OUTLINES (object);
	PpsOutlinesPrivate *priv = GET_PRIVATE (outlines);

	switch (prop_id) {
	case PROP_MARKUP:
		pps_outlines_set_markup (outlines,
		                         g_value_get_string (value));
		break;
	case PROP_LABEL:
		pps_outlines_set_label (outlines,
		                        g_value_get_string (value));
		break;
	case PROP_EXPAND:
		priv->expand = g_value_get_boolean (value);
		break;
	case PROP_CHILDREN:
		priv->children = g_value_get_object (value);
		break;
	case PROP_LINK:
		priv->link = g_object_ref (g_value_get_object (value));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

/**
 * pps_outlines_get_link
 * @pps_outlines: A #PpsOutlines
 *
 * Returns: (transfer none) (nullable): The #PpsLink of the outlines
 */
PpsLink *
pps_outlines_get_link (PpsOutlines *pps_outlines)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);
	g_return_val_if_fail (PPS_IS_OUTLINES (pps_outlines), NULL);

	return priv->link;
}

/**
 * pps_outlines_set_expand:
 * @pps_outlines: A #PpsOutlines
 * @expand: Whether the outlines should be expanded
 *
 * Sets the 'expand' property of the outlines.
 */
void
pps_outlines_set_expand (PpsOutlines *pps_outlines, gboolean expand)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);
	g_return_if_fail (PPS_IS_OUTLINES (pps_outlines));

	priv->expand = expand;
	g_object_notify (G_OBJECT (pps_outlines), "expand");
}

/**
 * pps_outlines_get_expand:
 * @pps_outlines: A #PpsOutlines
 *
 *
 * Returns: Whether the outlines should be expanded
 */
gboolean
pps_outlines_get_expand (PpsOutlines *pps_outlines)
{
	g_return_val_if_fail (PPS_IS_OUTLINES (pps_outlines), FALSE);

	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);
	return priv->expand;
}

/**
 * pps_outlines_set_children:
 * @pps_outlines: A #PpsOutlines
 * @children: (transfer full): The children of the outlines
 *
 * Sets the 'children' property of the outlines.
 */
void
pps_outlines_set_children (PpsOutlines *pps_outlines, GListModel *children)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);
	g_return_if_fail (PPS_IS_OUTLINES (pps_outlines));

	if (g_set_object (&priv->children, children))
		g_object_notify (G_OBJECT (pps_outlines), "children");
}

/**
 * pps_outlines_get_children:
 * @pps_outlines: A #PpsOutlines
 *
 * Returns: (nullable) (transfer none): The children of the outlines
 */
GListModel *
pps_outlines_get_children (PpsOutlines *pps_outlines)
{
	PpsOutlinesPrivate *priv = GET_PRIVATE (pps_outlines);
	g_return_val_if_fail (PPS_IS_OUTLINES (pps_outlines), NULL);

	return priv->children;
}

static void
pps_outlines_get_property (GObject *object,
                           guint prop_id,
                           GValue *value,
                           GParamSpec *pspec)
{
	PpsOutlines *outlines = PPS_OUTLINES (object);
	PpsOutlinesPrivate *priv = GET_PRIVATE (outlines);

	switch (prop_id) {
	case PROP_MARKUP:
		g_value_set_string (value, priv->markup);
		break;
	case PROP_LABEL:
		g_value_set_string (value, priv->label);
		break;
	case PROP_EXPAND:
		g_value_set_boolean (value, priv->expand);
		break;
	case PROP_CHILDREN:
		g_value_set_object (value, priv->children);
		break;
	case PROP_LINK:
		g_value_set_object (value, priv->link);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
pps_outlines_dispose (GObject *object)
{
	PpsOutlines *outlines = PPS_OUTLINES (object);
	PpsOutlinesPrivate *priv = GET_PRIVATE (outlines);

	g_free (priv->markup);
	g_free (priv->label);
	g_clear_object (&priv->children);
	g_clear_object (&priv->link);

	G_OBJECT_CLASS (pps_outlines_parent_class)->dispose (object);
}

static void
pps_outlines_init (PpsOutlines *pps_outlines)
{
}

static void
pps_outlines_class_init (PpsOutlinesClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->set_property = pps_outlines_set_property;
	object_class->get_property = pps_outlines_get_property;
	object_class->dispose = pps_outlines_dispose;

	g_object_class_install_property (object_class,
	                                 PROP_MARKUP,
	                                 g_param_spec_string ("markup",
	                                                      "markup",
	                                                      "The markup of the outlines",
	                                                      NULL,
	                                                      G_PARAM_READWRITE |
	                                                          G_PARAM_STATIC_STRINGS));

	g_object_class_install_property (object_class,
	                                 PROP_LABEL,
	                                 g_param_spec_string ("label",
	                                                      "Label",
	                                                      "The label of the outlines",
	                                                      NULL,
	                                                      G_PARAM_READWRITE |
	                                                          G_PARAM_STATIC_STRINGS));

	g_object_class_install_property (object_class,
	                                 PROP_EXPAND,
	                                 g_param_spec_boolean ("expand",
	                                                       "expand",
	                                                       "Whether the outlines should be expanded",
	                                                       FALSE,
	                                                       G_PARAM_READWRITE |
	                                                           G_PARAM_STATIC_STRINGS));

	g_object_class_install_property (object_class,
	                                 PROP_CHILDREN,
	                                 g_param_spec_object ("children",
	                                                      "Children",
	                                                      "The children of the outlines",
	                                                      G_TYPE_LIST_MODEL,
	                                                      G_PARAM_READWRITE));

	g_object_class_install_property (object_class,
	                                 PROP_LINK,
	                                 g_param_spec_object ("link",
	                                                      "Link",
	                                                      "The link of the outlines",
	                                                      PPS_TYPE_LINK,
	                                                      G_PARAM_READWRITE));
}