1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2017 Red Hat, Inc. (www.redhat.com)
4  *
5  * This library is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /**
19  * SECTION: e-config-lookup-result-simple
20  * @include: e-util/e-util.h
21  * @short_description: An implementation of configuration lookup result interface
22  *
23  * #EConfigLookupResultSimple is a simple implementation of
24  * the #EConfigLookupResult interface.
25  *
26  * Respective configuration changes are added with e_config_lookup_result_simple_add_value(),
27  * then they are saved into the #ESource in #EConfigLookupResultInterface.configure_sources()
28  * call. This does the default implementation of #EConfigLookupResultSimpleClass.configure_sources(),
29  * which any descendants can override, if needed.
30  **/
31 
32 #include "evolution-config.h"
33 
34 #include <string.h>
35 #include <libedataserver/libedataserver.h>
36 
37 #include "e-util-enumtypes.h"
38 #include "e-config-lookup.h"
39 #include "e-config-lookup-result.h"
40 
41 #include "e-config-lookup-result-simple.h"
42 
43 struct _EConfigLookupResultSimplePrivate {
44 	EConfigLookupResultKind kind;
45 	gint priority;
46 	gboolean is_complete;
47 	gchar *protocol;
48 	gchar *display_name;
49 	gchar *description;
50 	gchar *password;
51 	GSList *values; /* ValueData * */
52 };
53 
54 enum {
55 	PROP_0,
56 	PROP_KIND,
57 	PROP_PRIORITY,
58 	PROP_IS_COMPLETE,
59 	PROP_PROTOCOL,
60 	PROP_DISPLAY_NAME,
61 	PROP_DESCRIPTION,
62 	PROP_PASSWORD
63 };
64 
65 static void e_config_lookup_result_simple_result_init (EConfigLookupResultInterface *iface);
66 
67 G_DEFINE_TYPE_WITH_CODE (EConfigLookupResultSimple, e_config_lookup_result_simple, G_TYPE_OBJECT,
68 	G_IMPLEMENT_INTERFACE (E_TYPE_CONFIG_LOOKUP_RESULT, e_config_lookup_result_simple_result_init))
69 
70 typedef struct _ValueData {
71 	gchar *extension_name;
72 	gchar *property_name;
73 	GValue value;
74 } ValueData;
75 
76 static ValueData *
value_data_new(const gchar * extension_name,const gchar * property_name,const GValue * value)77 value_data_new (const gchar *extension_name,
78 		const gchar *property_name,
79 		const GValue *value)
80 {
81 	ValueData *vd;
82 
83 	vd = g_slice_new0 (ValueData);
84 	vd->extension_name = g_strdup (extension_name);
85 	vd->property_name = g_strdup (property_name);
86 
87 	g_value_init (&vd->value, G_VALUE_TYPE (value));
88 	g_value_copy (value, &vd->value);
89 
90 	return vd;
91 }
92 
93 static void
value_data_free(gpointer ptr)94 value_data_free (gpointer ptr)
95 {
96 	ValueData *vd = ptr;
97 
98 	if (vd) {
99 		g_free (vd->extension_name);
100 		g_free (vd->property_name);
101 		g_value_reset (&vd->value);
102 		g_slice_free (ValueData, vd);
103 	}
104 }
105 
106 static EConfigLookupResultKind
config_lookup_result_simple_get_kind(EConfigLookupResult * lookup_result)107 config_lookup_result_simple_get_kind (EConfigLookupResult *lookup_result)
108 {
109 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), E_CONFIG_LOOKUP_RESULT_UNKNOWN);
110 
111 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->kind;
112 }
113 
114 static gint
config_lookup_result_simple_get_priority(EConfigLookupResult * lookup_result)115 config_lookup_result_simple_get_priority (EConfigLookupResult *lookup_result)
116 {
117 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), ~0);
118 
119 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->priority;
120 }
121 
122 static gboolean
config_lookup_result_simple_get_is_complete(EConfigLookupResult * lookup_result)123 config_lookup_result_simple_get_is_complete (EConfigLookupResult *lookup_result)
124 {
125 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), FALSE);
126 
127 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->is_complete;
128 }
129 
130 static const gchar *
config_lookup_result_simple_get_protocol(EConfigLookupResult * lookup_result)131 config_lookup_result_simple_get_protocol (EConfigLookupResult *lookup_result)
132 {
133 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), NULL);
134 
135 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->protocol;
136 }
137 
138 static const gchar *
config_lookup_result_simple_get_display_name(EConfigLookupResult * lookup_result)139 config_lookup_result_simple_get_display_name (EConfigLookupResult *lookup_result)
140 {
141 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), NULL);
142 
143 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->display_name;
144 }
145 
146 static const gchar *
config_lookup_result_simple_get_description(EConfigLookupResult * lookup_result)147 config_lookup_result_simple_get_description (EConfigLookupResult *lookup_result)
148 {
149 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), NULL);
150 
151 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->description;
152 }
153 
154 static const gchar *
config_lookup_result_simple_get_password(EConfigLookupResult * lookup_result)155 config_lookup_result_simple_get_password (EConfigLookupResult *lookup_result)
156 {
157 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), NULL);
158 
159 	return E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result)->priv->password;
160 }
161 
162 static gboolean
config_lookup_result_simple_configure_source(EConfigLookupResult * lookup_result,EConfigLookup * config_lookup,ESource * source)163 config_lookup_result_simple_configure_source (EConfigLookupResult *lookup_result,
164 					      EConfigLookup *config_lookup,
165 					      ESource *source)
166 {
167 	EConfigLookupResultSimple *result_simple;
168 	GSList *link;
169 
170 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), FALSE);
171 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), FALSE);
172 	g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
173 
174 	result_simple = E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result);
175 
176 	if (!result_simple->priv->values)
177 		return FALSE;
178 
179 	for (link = result_simple->priv->values; link; link = g_slist_next (link)) {
180 		ValueData *vd = link->data;
181 		gpointer object;
182 
183 		if (!vd)
184 			return FALSE;
185 
186 		if (vd->extension_name && *vd->extension_name) {
187 			object = e_source_get_extension (source, vd->extension_name);
188 
189 			/* Special-case the ESourceCamel extension, where the properties
190 			   reference the CamelSettings object, not the extension itself. */
191 			if (object && E_IS_SOURCE_CAMEL (object))
192 				object = e_source_camel_get_settings (object);
193 		} else {
194 			object = source;
195 		}
196 
197 		g_warn_if_fail (object != NULL);
198 
199 		if (object)
200 			g_object_set_property (object, vd->property_name, &vd->value);
201 	}
202 
203 	return TRUE;
204 }
205 
206 static gboolean
config_lookup_result_simple_configure_source_wrapper(EConfigLookupResult * lookup_result,EConfigLookup * config_lookup,ESource * source)207 config_lookup_result_simple_configure_source_wrapper (EConfigLookupResult *lookup_result,
208 						      EConfigLookup *config_lookup,
209 						      ESource *source)
210 {
211 	EConfigLookupResultSimpleClass *klass;
212 
213 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result), FALSE);
214 	g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), FALSE);
215 	g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
216 
217 	klass = E_CONFIG_LOOKUP_RESULT_SIMPLE_GET_CLASS (lookup_result);
218 	g_return_val_if_fail (klass != NULL, FALSE);
219 	g_return_val_if_fail (klass->configure_source != NULL, FALSE);
220 
221 	return klass->configure_source (lookup_result, config_lookup, source);
222 }
223 
224 static void
config_lookup_result_simple_set_kind(EConfigLookupResultSimple * result_simple,EConfigLookupResultKind kind)225 config_lookup_result_simple_set_kind (EConfigLookupResultSimple *result_simple,
226 				      EConfigLookupResultKind kind)
227 {
228 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (result_simple));
229 	g_return_if_fail (kind != E_CONFIG_LOOKUP_RESULT_UNKNOWN);
230 
231 	result_simple->priv->kind = kind;
232 }
233 
234 static void
config_lookup_result_simple_set_priority(EConfigLookupResultSimple * result_simple,gint priority)235 config_lookup_result_simple_set_priority (EConfigLookupResultSimple *result_simple,
236 					  gint priority)
237 {
238 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (result_simple));
239 
240 	result_simple->priv->priority = priority;
241 }
242 
243 static void
config_lookup_result_simple_set_is_complete(EConfigLookupResultSimple * result_simple,gboolean is_complete)244 config_lookup_result_simple_set_is_complete (EConfigLookupResultSimple *result_simple,
245 					     gboolean is_complete)
246 {
247 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (result_simple));
248 
249 	result_simple->priv->is_complete = is_complete;
250 }
251 
252 static void
config_lookup_result_simple_set_string(EConfigLookupResultSimple * result_simple,const gchar * value,gchar ** destination)253 config_lookup_result_simple_set_string (EConfigLookupResultSimple *result_simple,
254 					const gchar *value,
255 					gchar **destination)
256 {
257 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (result_simple));
258 	g_return_if_fail (destination != NULL);
259 	g_return_if_fail (*destination == NULL);
260 
261 	*destination = g_strdup (value);
262 }
263 
264 static void
config_lookup_result_simple_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)265 config_lookup_result_simple_set_property (GObject *object,
266 					  guint property_id,
267 					  const GValue *value,
268 					  GParamSpec *pspec)
269 {
270 	EConfigLookupResultSimple *result_simple = E_CONFIG_LOOKUP_RESULT_SIMPLE (object);
271 
272 	switch (property_id) {
273 		case PROP_KIND:
274 			config_lookup_result_simple_set_kind (
275 				result_simple, g_value_get_enum (value));
276 			return;
277 
278 		case PROP_PRIORITY:
279 			config_lookup_result_simple_set_priority (
280 				result_simple, g_value_get_int (value));
281 			return;
282 
283 		case PROP_IS_COMPLETE:
284 			config_lookup_result_simple_set_is_complete (
285 				result_simple, g_value_get_boolean (value));
286 			return;
287 
288 		case PROP_PROTOCOL:
289 			config_lookup_result_simple_set_string (
290 				result_simple, g_value_get_string (value),
291 				&result_simple->priv->protocol);
292 			return;
293 
294 		case PROP_DISPLAY_NAME:
295 			config_lookup_result_simple_set_string (
296 				result_simple, g_value_get_string (value),
297 				&result_simple->priv->display_name);
298 			return;
299 
300 		case PROP_DESCRIPTION:
301 			config_lookup_result_simple_set_string (
302 				result_simple, g_value_get_string (value),
303 				&result_simple->priv->description);
304 			return;
305 
306 		case PROP_PASSWORD:
307 			config_lookup_result_simple_set_string (
308 				result_simple, g_value_get_string (value),
309 				&result_simple->priv->password);
310 			return;
311 	}
312 
313 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
314 }
315 
316 static void
config_lookup_result_simple_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)317 config_lookup_result_simple_get_property (GObject *object,
318 					  guint property_id,
319 					  GValue *value,
320 					  GParamSpec *pspec)
321 {
322 	switch (property_id) {
323 		case PROP_KIND:
324 			g_value_set_enum (
325 				value,
326 				config_lookup_result_simple_get_kind (
327 				E_CONFIG_LOOKUP_RESULT (object)));
328 			return;
329 
330 		case PROP_PRIORITY:
331 			g_value_set_int (
332 				value,
333 				config_lookup_result_simple_get_priority (
334 				E_CONFIG_LOOKUP_RESULT (object)));
335 			return;
336 
337 		case PROP_IS_COMPLETE:
338 			g_value_set_boolean (
339 				value,
340 				config_lookup_result_simple_get_is_complete (
341 				E_CONFIG_LOOKUP_RESULT (object)));
342 			return;
343 
344 		case PROP_PROTOCOL:
345 			g_value_set_string (
346 				value,
347 				config_lookup_result_simple_get_protocol (
348 				E_CONFIG_LOOKUP_RESULT (object)));
349 			return;
350 
351 		case PROP_DISPLAY_NAME:
352 			g_value_set_string (
353 				value,
354 				config_lookup_result_simple_get_display_name (
355 				E_CONFIG_LOOKUP_RESULT (object)));
356 			return;
357 
358 		case PROP_DESCRIPTION:
359 			g_value_set_string (
360 				value,
361 				config_lookup_result_simple_get_description (
362 				E_CONFIG_LOOKUP_RESULT (object)));
363 			return;
364 
365 		case PROP_PASSWORD:
366 			g_value_set_string (
367 				value,
368 				config_lookup_result_simple_get_password (
369 				E_CONFIG_LOOKUP_RESULT (object)));
370 			return;
371 	}
372 
373 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
374 }
375 
376 static void
config_lookup_result_simple_finalize(GObject * object)377 config_lookup_result_simple_finalize (GObject *object)
378 {
379 	EConfigLookupResultSimple *result_simple = E_CONFIG_LOOKUP_RESULT_SIMPLE (object);
380 
381 	g_free (result_simple->priv->protocol);
382 	g_free (result_simple->priv->display_name);
383 	g_free (result_simple->priv->description);
384 	e_util_safe_free_string (result_simple->priv->password);
385 	g_slist_free_full (result_simple->priv->values, value_data_free);
386 
387 	/* Chain up to parent's method. */
388 	G_OBJECT_CLASS (e_config_lookup_result_simple_parent_class)->finalize (object);
389 }
390 
391 static void
e_config_lookup_result_simple_class_init(EConfigLookupResultSimpleClass * klass)392 e_config_lookup_result_simple_class_init (EConfigLookupResultSimpleClass *klass)
393 {
394 	GObjectClass *object_class;
395 
396 	g_type_class_add_private (klass, sizeof (EConfigLookupResultSimplePrivate));
397 
398 	object_class = G_OBJECT_CLASS (klass);
399 	object_class->set_property = config_lookup_result_simple_set_property;
400 	object_class->get_property = config_lookup_result_simple_get_property;
401 	object_class->finalize = config_lookup_result_simple_finalize;
402 
403 	klass->configure_source = config_lookup_result_simple_configure_source;
404 
405 	/**
406 	 * EConfigLookupResultSimple:kind:
407 	 *
408 	 * The kind for the #EConfigLookupResult.
409 	 *
410 	 * Since: 3.26
411 	 **/
412 	g_object_class_install_property (
413 		object_class,
414 		PROP_KIND,
415 		g_param_spec_enum (
416 			"kind",
417 			"Kind",
418 			NULL,
419 			E_TYPE_CONFIG_LOOKUP_RESULT_KIND,
420 			E_CONFIG_LOOKUP_RESULT_UNKNOWN,
421 			G_PARAM_READWRITE |
422 			G_PARAM_CONSTRUCT_ONLY |
423 			G_PARAM_STATIC_STRINGS));
424 
425 	/**
426 	 * EConfigLookupResultSimple:priority:
427 	 *
428 	 * The priority for the #EConfigLookupResult. Lower value means higher priority.
429 	 *
430 	 * Since: 3.26
431 	 **/
432 	g_object_class_install_property (
433 		object_class,
434 		PROP_PRIORITY,
435 		g_param_spec_int (
436 			"priority",
437 			"Priority",
438 			NULL,
439 			G_MININT, G_MAXINT, ~0,
440 			G_PARAM_READWRITE |
441 			G_PARAM_CONSTRUCT_ONLY |
442 			G_PARAM_STATIC_STRINGS));
443 
444 	/**
445 	 * EConfigLookupResultSimple:is-complete:
446 	 *
447 	 * Whether the #EConfigLookupResult is complete, that is, whether it doesn't
448 	 * require any further user interaction.
449 	 *
450 	 * Since: 3.26
451 	 **/
452 	g_object_class_install_property (
453 		object_class,
454 		PROP_IS_COMPLETE,
455 		g_param_spec_boolean (
456 			"is-complete",
457 			"Is Complete",
458 			NULL,
459 			FALSE,
460 			G_PARAM_READWRITE |
461 			G_PARAM_CONSTRUCT_ONLY |
462 			G_PARAM_STATIC_STRINGS));
463 
464 	/**
465 	 * EConfigLookupResultSimple:protocol:
466 	 *
467 	 * The protocol name for the #EConfigLookupResult.
468 	 *
469 	 * Since: 3.26
470 	 **/
471 	g_object_class_install_property (
472 		object_class,
473 		PROP_PROTOCOL,
474 		g_param_spec_string (
475 			"protocol",
476 			"Protocol",
477 			NULL,
478 			NULL,
479 			G_PARAM_READWRITE |
480 			G_PARAM_CONSTRUCT_ONLY |
481 			G_PARAM_STATIC_STRINGS));
482 
483 	/**
484 	 * EConfigLookupResultSimple:display_name:
485 	 *
486 	 * The display name for the #EConfigLookupResult.
487 	 *
488 	 * Since: 3.26
489 	 **/
490 	g_object_class_install_property (
491 		object_class,
492 		PROP_DISPLAY_NAME,
493 		g_param_spec_string (
494 			"display-name",
495 			"Display Name",
496 			NULL,
497 			NULL,
498 			G_PARAM_READWRITE |
499 			G_PARAM_CONSTRUCT_ONLY |
500 			G_PARAM_STATIC_STRINGS));
501 
502 	/**
503 	 * EConfigLookupResultSimple:description:
504 	 *
505 	 * The description for the #EConfigLookupResult.
506 	 *
507 	 * Since: 3.26
508 	 **/
509 	g_object_class_install_property (
510 		object_class,
511 		PROP_DESCRIPTION,
512 		g_param_spec_string (
513 			"description",
514 			"Description",
515 			NULL,
516 			NULL,
517 			G_PARAM_READWRITE |
518 			G_PARAM_CONSTRUCT_ONLY |
519 			G_PARAM_STATIC_STRINGS));
520 
521 	/**
522 	 * EConfigLookupResultSimple:password:
523 	 *
524 	 * The password to store for the #EConfigLookupResult.
525 	 * Can be %NULL, to not store any.
526 	 *
527 	 * Since: 3.28
528 	 **/
529 	g_object_class_install_property (
530 		object_class,
531 		PROP_PASSWORD,
532 		g_param_spec_string (
533 			"password",
534 			"Password",
535 			NULL,
536 			NULL,
537 			G_PARAM_READWRITE |
538 			G_PARAM_CONSTRUCT_ONLY |
539 			G_PARAM_STATIC_STRINGS));
540 }
541 
542 static void
e_config_lookup_result_simple_result_init(EConfigLookupResultInterface * iface)543 e_config_lookup_result_simple_result_init (EConfigLookupResultInterface *iface)
544 {
545 	iface->get_kind = config_lookup_result_simple_get_kind;
546 	iface->get_priority = config_lookup_result_simple_get_priority;
547 	iface->get_is_complete = config_lookup_result_simple_get_is_complete;
548 	iface->get_protocol = config_lookup_result_simple_get_protocol;
549 	iface->get_display_name = config_lookup_result_simple_get_display_name;
550 	iface->get_description = config_lookup_result_simple_get_description;
551 	iface->get_password = config_lookup_result_simple_get_password;
552 	iface->configure_source = config_lookup_result_simple_configure_source_wrapper;
553 }
554 
555 static void
e_config_lookup_result_simple_init(EConfigLookupResultSimple * result_simple)556 e_config_lookup_result_simple_init (EConfigLookupResultSimple *result_simple)
557 {
558 	result_simple->priv = G_TYPE_INSTANCE_GET_PRIVATE (result_simple, E_TYPE_CONFIG_LOOKUP_RESULT_SIMPLE, EConfigLookupResultSimplePrivate);
559 }
560 
561 /**
562  * e_config_lookup_result_simple_new:
563  * @kind: a kind of the result, one of #EConfigLookupResultKind
564  * @priority: a priority of the result
565  * @is_complete: whether the result is complete
566  * @protocol: (nullable): protocol name of the result, or %NULL
567  * @display_name: display name of the result
568  * @description: description of the result
569  * @password: (nullable): password to store with the result
570  *
571  * Creates a new #EConfigLookupResultSimple instance with prefilled values.
572  *
573  * Returns: (transfer full): an #EConfigLookupResultSimple
574  *
575  * Since: 3.26
576  **/
577 EConfigLookupResult *
e_config_lookup_result_simple_new(EConfigLookupResultKind kind,gint priority,gboolean is_complete,const gchar * protocol,const gchar * display_name,const gchar * description,const gchar * password)578 e_config_lookup_result_simple_new (EConfigLookupResultKind kind,
579 				   gint priority,
580 				   gboolean is_complete,
581 				   const gchar *protocol,
582 				   const gchar *display_name,
583 				   const gchar *description,
584 				   const gchar *password)
585 {
586 	g_return_val_if_fail (kind != E_CONFIG_LOOKUP_RESULT_UNKNOWN, NULL);
587 	g_return_val_if_fail (display_name != NULL, NULL);
588 	g_return_val_if_fail (description != NULL, NULL);
589 
590 	return g_object_new (E_TYPE_CONFIG_LOOKUP_RESULT_SIMPLE,
591 		"kind", kind,
592 		"priority", priority,
593 		"is-complete", is_complete,
594 		"protocol", protocol,
595 		"display-name", display_name,
596 		"description", description,
597 		"password", password,
598 		NULL);
599 }
600 
601 /**
602  * e_config_lookup_result_simple_add_value:
603  * @lookup_result: an #EConfigLookupResultSimple
604  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
605  * @property_name: property name within the extension
606  * @value: value to be set
607  *
608  * Adds a value to be stored into an #ESource when e_config_lookup_result_configure_source().
609  * is called. The @value is identified as a property named @property_name in an extension
610  * named @extension_name, or in the #ESource itself, when @extension_name is %NULL.
611  *
612  * In case multiple values are stored for the same extension and property,
613  * then the first is saved.
614  *
615  * Since: 3.26
616  **/
617 void
e_config_lookup_result_simple_add_value(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,const GValue * value)618 e_config_lookup_result_simple_add_value (EConfigLookupResult *lookup_result,
619 					 const gchar *extension_name,
620 					 const gchar *property_name,
621 					 const GValue *value)
622 {
623 	EConfigLookupResultSimple *result_simple;
624 
625 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
626 	g_return_if_fail (property_name != NULL);
627 	g_return_if_fail (value != NULL);
628 
629 	result_simple = E_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result);
630 
631 	result_simple->priv->values = g_slist_prepend (result_simple->priv->values,
632 		value_data_new (extension_name, property_name, value));
633 }
634 
635 /**
636  * e_config_lookup_result_simple_add_boolean:
637  * @lookup_result: an #EConfigLookupResultSimple
638  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
639  * @property_name: property name within the extension
640  * @value: value to set
641  *
642  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
643  * to @value.
644  *
645  * Since: 3.26
646  **/
647 void
e_config_lookup_result_simple_add_boolean(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,gboolean value)648 e_config_lookup_result_simple_add_boolean (EConfigLookupResult *lookup_result,
649 					   const gchar *extension_name,
650 					   const gchar *property_name,
651 					   gboolean value)
652 {
653 	GValue gvalue;
654 
655 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
656 	g_return_if_fail (property_name != NULL);
657 
658 	memset (&gvalue, 0, sizeof (GValue));
659 	g_value_init (&gvalue, G_TYPE_BOOLEAN);
660 	g_value_set_boolean (&gvalue, value);
661 
662 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
663 
664 	g_value_reset (&gvalue);
665 }
666 
667 /**
668  * e_config_lookup_result_simple_add_int:
669  * @lookup_result: an #EConfigLookupResultSimple
670  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
671  * @property_name: property name within the extension
672  * @value: value to set
673  *
674  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
675  * to @value.
676  *
677  * Since: 3.26
678  **/
679 void
e_config_lookup_result_simple_add_int(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,gint value)680 e_config_lookup_result_simple_add_int (EConfigLookupResult *lookup_result,
681 				       const gchar *extension_name,
682 				       const gchar *property_name,
683 				       gint value)
684 {
685 	GValue gvalue;
686 
687 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
688 	g_return_if_fail (property_name != NULL);
689 
690 	memset (&gvalue, 0, sizeof (GValue));
691 	g_value_init (&gvalue, G_TYPE_INT);
692 	g_value_set_int (&gvalue, value);
693 
694 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
695 
696 	g_value_reset (&gvalue);
697 }
698 
699 /**
700  * e_config_lookup_result_simple_add_uint:
701  * @lookup_result: an #EConfigLookupResultSimple
702  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
703  * @property_name: property name within the extension
704  * @value: value to set
705  *
706  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
707  * to @value.
708  *
709  * Since: 3.26
710  **/
711 void
e_config_lookup_result_simple_add_uint(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,guint value)712 e_config_lookup_result_simple_add_uint (EConfigLookupResult *lookup_result,
713 					const gchar *extension_name,
714 					const gchar *property_name,
715 					guint value)
716 {
717 	GValue gvalue;
718 
719 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
720 	g_return_if_fail (property_name != NULL);
721 
722 	memset (&gvalue, 0, sizeof (GValue));
723 	g_value_init (&gvalue, G_TYPE_UINT);
724 	g_value_set_uint (&gvalue, value);
725 
726 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
727 
728 	g_value_reset (&gvalue);
729 }
730 
731 /**
732  * e_config_lookup_result_simple_add_int64:
733  * @lookup_result: an #EConfigLookupResultSimple
734  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
735  * @property_name: property name within the extension
736  * @value: value to set
737  *
738  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
739  * to @value.
740  *
741  * Since: 3.26
742  **/
743 void
e_config_lookup_result_simple_add_int64(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,gint64 value)744 e_config_lookup_result_simple_add_int64 (EConfigLookupResult *lookup_result,
745 					 const gchar *extension_name,
746 					 const gchar *property_name,
747 					 gint64 value)
748 {
749 	GValue gvalue;
750 
751 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
752 	g_return_if_fail (property_name != NULL);
753 
754 	memset (&gvalue, 0, sizeof (GValue));
755 	g_value_init (&gvalue, G_TYPE_INT64);
756 	g_value_set_int64 (&gvalue, value);
757 
758 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
759 
760 	g_value_reset (&gvalue);
761 }
762 
763 /**
764  * e_config_lookup_result_simple_add_uint64:
765  * @lookup_result: an #EConfigLookupResultSimple
766  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
767  * @property_name: property name within the extension
768  * @value: value to set
769  *
770  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
771  * to @value.
772  *
773  * Since: 3.26
774  **/
775 void
e_config_lookup_result_simple_add_uint64(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,guint64 value)776 e_config_lookup_result_simple_add_uint64 (EConfigLookupResult *lookup_result,
777 					  const gchar *extension_name,
778 					  const gchar *property_name,
779 					  guint64 value)
780 {
781 	GValue gvalue;
782 
783 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
784 	g_return_if_fail (property_name != NULL);
785 
786 	memset (&gvalue, 0, sizeof (GValue));
787 	g_value_init (&gvalue, G_TYPE_UINT64);
788 	g_value_set_uint64 (&gvalue, value);
789 
790 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
791 
792 	g_value_reset (&gvalue);
793 }
794 
795 /**
796  * e_config_lookup_result_simple_add_double:
797  * @lookup_result: an #EConfigLookupResultSimple
798  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
799  * @property_name: property name within the extension
800  * @value: value to set
801  *
802  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
803  * to @value.
804  *
805  * Since: 3.26
806  **/
807 void
e_config_lookup_result_simple_add_double(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,gdouble value)808 e_config_lookup_result_simple_add_double (EConfigLookupResult *lookup_result,
809 					  const gchar *extension_name,
810 					  const gchar *property_name,
811 					  gdouble value)
812 {
813 	GValue gvalue;
814 
815 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
816 	g_return_if_fail (property_name != NULL);
817 
818 	memset (&gvalue, 0, sizeof (GValue));
819 	g_value_init (&gvalue, G_TYPE_DOUBLE);
820 	g_value_set_double (&gvalue, value);
821 
822 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
823 
824 	g_value_reset (&gvalue);
825 }
826 
827 /**
828  * e_config_lookup_result_simple_add_string:
829  * @lookup_result: an #EConfigLookupResultSimple
830  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
831  * @property_name: property name within the extension
832  * @value: value to set
833  *
834  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
835  * to @value.
836  *
837  * Since: 3.26
838  **/
839 void
e_config_lookup_result_simple_add_string(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,const gchar * value)840 e_config_lookup_result_simple_add_string (EConfigLookupResult *lookup_result,
841 					  const gchar *extension_name,
842 					  const gchar *property_name,
843 					  const gchar *value)
844 {
845 	GValue gvalue;
846 
847 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
848 	g_return_if_fail (property_name != NULL);
849 
850 	memset (&gvalue, 0, sizeof (GValue));
851 	g_value_init (&gvalue, G_TYPE_STRING);
852 	g_value_set_string (&gvalue, value);
853 
854 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
855 
856 	g_value_reset (&gvalue);
857 }
858 
859 /**
860  * e_config_lookup_result_simple_add_enum:
861  * @lookup_result: an #EConfigLookupResultSimple
862  * @extension_name: (nullable): extension name, or %NULL, to change property of the #ESource itself
863  * @property_name: property name within the extension
864  * @enum_type: a #GType of the enum
865  * @value: value to set
866  *
867  * Calls e_config_lookup_result_simple_add_value() with a #GValue initialized
868  * to @value.
869  *
870  * Since: 3.26
871  **/
872 void
e_config_lookup_result_simple_add_enum(EConfigLookupResult * lookup_result,const gchar * extension_name,const gchar * property_name,GType enum_type,gint value)873 e_config_lookup_result_simple_add_enum (EConfigLookupResult *lookup_result,
874 					const gchar *extension_name,
875 					const gchar *property_name,
876 					GType enum_type,
877 					gint value)
878 {
879 	GValue gvalue;
880 
881 	g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT_SIMPLE (lookup_result));
882 	g_return_if_fail (property_name != NULL);
883 
884 	memset (&gvalue, 0, sizeof (GValue));
885 	g_value_init (&gvalue, enum_type);
886 	g_value_set_enum (&gvalue, value);
887 
888 	e_config_lookup_result_simple_add_value (lookup_result, extension_name, property_name, &gvalue);
889 
890 	g_value_reset (&gvalue);
891 }
892