1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* e-source-revision-guards.c - Revision Guard Configuration.
3  *
4  * Copyright (C) 2013 Intel Corporation
5  *
6  * This library is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Authors: Tristan Van Berkom <tristanvb@openismus.com>
19  */
20 
21 /**
22  * SECTION: e-source-revision-guards
23  * @include: libedataserver/libedataserver.h
24  * @short_description: #ESource extension to configure revision guards
25  *
26  * The #ESourceRevisionGuards extension configures whether revisions
27  * should be checked on modified objects. If a modified object has
28  * a conflicting revision with an existing object, then an
29  * %E_CLIENT_ERROR_OUT_OF_SYNC error should be produced for that object
30  * and the modification should be discarded.
31  *
32  * Access the extension as follows:
33  *
34  * |[
35  *   #include <libedataserver/libedataserver.h>
36  *
37  *   ESourceRevisionGuards *extension;
38  *
39  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_REVISION_GUARDS);
40  * ]|
41  **/
42 
43 #include "e-source-revision-guards.h"
44 
45 #include <libedataserver/e-data-server-util.h>
46 
47 struct _ESourceRevisionGuardsPrivate {
48 	gboolean enabled;
49 };
50 
51 enum {
52 	PROP_0,
53 	PROP_ENABLED
54 };
55 
G_DEFINE_TYPE_WITH_PRIVATE(ESourceRevisionGuards,e_source_revision_guards,E_TYPE_SOURCE_EXTENSION)56 G_DEFINE_TYPE_WITH_PRIVATE (
57 	ESourceRevisionGuards,
58 	e_source_revision_guards,
59 	E_TYPE_SOURCE_EXTENSION)
60 
61 static void
62 source_revision_guards_set_property (GObject *object,
63                                      guint property_id,
64                                      const GValue *value,
65                                      GParamSpec *pspec)
66 {
67 	switch (property_id) {
68 		case PROP_ENABLED:
69 			e_source_revision_guards_set_enabled (
70 				E_SOURCE_REVISION_GUARDS (object),
71 				g_value_get_boolean (value));
72 			return;
73 	}
74 
75 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 }
77 
78 static void
source_revision_guards_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)79 source_revision_guards_get_property (GObject *object,
80                                      guint property_id,
81                                      GValue *value,
82                                      GParamSpec *pspec)
83 {
84 	switch (property_id) {
85 		case PROP_ENABLED:
86 			g_value_set_boolean (
87 				value,
88 				e_source_revision_guards_get_enabled (
89 				E_SOURCE_REVISION_GUARDS (object)));
90 			return;
91 	}
92 
93 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94 }
95 
96 static void
e_source_revision_guards_class_init(ESourceRevisionGuardsClass * class)97 e_source_revision_guards_class_init (ESourceRevisionGuardsClass *class)
98 {
99 	GObjectClass *object_class;
100 	ESourceExtensionClass *extension_class;
101 
102 	object_class = G_OBJECT_CLASS (class);
103 	object_class->set_property = source_revision_guards_set_property;
104 	object_class->get_property = source_revision_guards_get_property;
105 
106 	extension_class = E_SOURCE_EXTENSION_CLASS (class);
107 	extension_class->name = E_SOURCE_EXTENSION_REVISION_GUARDS;
108 
109 	g_object_class_install_property (
110 		object_class,
111 		PROP_ENABLED,
112 		g_param_spec_boolean (
113 			"enabled",
114 			"Enabled",
115 			"Whether to enable or disable the revision guards",
116 			FALSE,
117 			G_PARAM_READWRITE |
118 			G_PARAM_CONSTRUCT |
119 			G_PARAM_EXPLICIT_NOTIFY |
120 			G_PARAM_STATIC_STRINGS |
121 			E_SOURCE_PARAM_SETTING));
122 }
123 
124 static void
e_source_revision_guards_init(ESourceRevisionGuards * extension)125 e_source_revision_guards_init (ESourceRevisionGuards *extension)
126 {
127 	extension->priv = e_source_revision_guards_get_instance_private (extension);
128 }
129 
130 /**
131  * e_source_revision_guards_get_enabled:
132  * @extension: An #ESourceRevisionGuards
133  *
134  * Checks whether revision guards for the given #ESource are enabled.
135  *
136  * Returns: %TRUE if the revision guards are enabled.
137  *
138  * Since: 3.8
139  */
140 gboolean
e_source_revision_guards_get_enabled(ESourceRevisionGuards * extension)141 e_source_revision_guards_get_enabled (ESourceRevisionGuards *extension)
142 {
143 	g_return_val_if_fail (E_IS_SOURCE_REVISION_GUARDS (extension), FALSE);
144 
145 	return extension->priv->enabled;
146 }
147 
148 /**
149  * e_source_revision_guards_set_enabled:
150  * @extension: An #ESourceRevisionGuards
151  * @enabled: Whether to enable or disable the revision guards.
152  *
153  * Enables or disables the revision guards for a given #ESource.
154  *
155  * Revision guards are disabled by default.
156  *
157  * Since: 3.8
158  */
159 void
e_source_revision_guards_set_enabled(ESourceRevisionGuards * extension,gboolean enabled)160 e_source_revision_guards_set_enabled (ESourceRevisionGuards *extension,
161                                       gboolean enabled)
162 {
163 	g_return_if_fail (E_IS_SOURCE_REVISION_GUARDS (extension));
164 
165 	if (extension->priv->enabled == enabled)
166 		return;
167 
168 	extension->priv->enabled = enabled;
169 
170 	g_object_notify (G_OBJECT (extension), "enabled");
171 }
172 
173