evolution-3.6.4/modules/cal-config-local/e-source-local.c

No issues found

  1 /*
  2  * e-source-local.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #include "e-source-local.h"
 20 
 21 #define E_SOURCE_LOCAL_GET_PRIVATE(obj) \
 22 	(G_TYPE_INSTANCE_GET_PRIVATE \
 23 	((obj), E_TYPE_SOURCE_LOCAL, ESourceLocalPrivate))
 24 
 25 struct _ESourceLocalPrivate {
 26 	GMutex *property_lock;
 27 	GFile *custom_file;
 28 };
 29 
 30 enum {
 31 	PROP_0,
 32 	PROP_CUSTOM_FILE
 33 };
 34 
 35 G_DEFINE_DYNAMIC_TYPE (
 36 	ESourceLocal,
 37 	e_source_local,
 38 	E_TYPE_SOURCE_EXTENSION)
 39 
 40 static void
 41 source_local_set_property (GObject *object,
 42                            guint property_id,
 43                            const GValue *value,
 44                            GParamSpec *pspec)
 45 {
 46 	switch (property_id) {
 47 		case PROP_CUSTOM_FILE:
 48 			e_source_local_set_custom_file (
 49 				E_SOURCE_LOCAL (object),
 50 				g_value_get_object (value));
 51 			return;
 52 	}
 53 
 54 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 55 }
 56 
 57 static void
 58 source_local_get_property (GObject *object,
 59                            guint property_id,
 60                            GValue *value,
 61                            GParamSpec *pspec)
 62 {
 63 	switch (property_id) {
 64 		case PROP_CUSTOM_FILE:
 65 			g_value_take_object (
 66 				value,
 67 				e_source_local_dup_custom_file (
 68 				E_SOURCE_LOCAL (object)));
 69 			return;
 70 	}
 71 
 72 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 73 }
 74 
 75 static void
 76 source_local_dispose (GObject *object)
 77 {
 78 	ESourceLocalPrivate *priv;
 79 
 80 	priv = E_SOURCE_LOCAL_GET_PRIVATE (object);
 81 
 82 	if (priv->custom_file != NULL) {
 83 		g_object_unref (priv->custom_file);
 84 		priv->custom_file = NULL;
 85 	}
 86 
 87 	/* Chain up to parent's dispose() method. */
 88 	G_OBJECT_CLASS (e_source_local_parent_class)->dispose (object);
 89 }
 90 
 91 static void
 92 source_local_finalize (GObject *object)
 93 {
 94 	ESourceLocalPrivate *priv;
 95 
 96 	priv = E_SOURCE_LOCAL_GET_PRIVATE (object);
 97 
 98 	g_mutex_free (priv->property_lock);
 99 
100 	/* Chain up to parent's finalize() method. */
101 	G_OBJECT_CLASS (e_source_local_parent_class)->finalize (object);
102 }
103 
104 static void
105 e_source_local_class_init (ESourceLocalClass *class)
106 {
107 	GObjectClass *object_class;
108 	ESourceExtensionClass *extension_class;
109 
110 	g_type_class_add_private (class, sizeof (ESourceLocalPrivate));
111 
112 	object_class = G_OBJECT_CLASS (class);
113 	object_class->set_property = source_local_set_property;
114 	object_class->get_property = source_local_get_property;
115 	object_class->dispose = source_local_dispose;
116 	object_class->finalize = source_local_finalize;
117 
118 	extension_class = E_SOURCE_EXTENSION_CLASS (class);
119 	extension_class->name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
120 
121 	g_object_class_install_property (
122 		object_class,
123 		PROP_CUSTOM_FILE,
124 		g_param_spec_object (
125 			"custom-file",
126 			"Custom File",
127 			"Custom iCalendar file",
128 			G_TYPE_FILE,
129 			G_PARAM_READWRITE |
130 			G_PARAM_CONSTRUCT |
131 			E_SOURCE_PARAM_SETTING));
132 }
133 
134 static void
135 e_source_local_class_finalize (ESourceLocalClass *class)
136 {
137 }
138 
139 static void
140 e_source_local_init (ESourceLocal *extension)
141 {
142 	extension->priv = E_SOURCE_LOCAL_GET_PRIVATE (extension);
143 	extension->priv->property_lock = g_mutex_new ();
144 }
145 
146 void
147 e_source_local_type_register (GTypeModule *type_module)
148 {
149 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
150 	 *     function, so we have to wrap it with a public function in
151 	 *     order to register types from a separate compilation unit. */
152 	e_source_local_register_type (type_module);
153 }
154 
155 GFile *
156 e_source_local_get_custom_file (ESourceLocal *extension)
157 {
158 	g_return_val_if_fail (E_IS_SOURCE_LOCAL (extension), NULL);
159 
160 	return extension->priv->custom_file;
161 }
162 
163 GFile *
164 e_source_local_dup_custom_file (ESourceLocal *extension)
165 {
166 	GFile *protected;
167 	GFile *duplicate;
168 
169 	g_return_val_if_fail (E_IS_SOURCE_LOCAL (extension), NULL);
170 
171 	g_mutex_lock (extension->priv->property_lock);
172 
173 	protected = e_source_local_get_custom_file (extension);
174 	duplicate = (protected != NULL) ? g_file_dup (protected) : NULL;
175 
176 	g_mutex_unlock (extension->priv->property_lock);
177 
178 	return duplicate;
179 }
180 
181 void
182 e_source_local_set_custom_file (ESourceLocal *extension,
183                                 GFile *custom_file)
184 {
185 	g_return_if_fail (E_IS_SOURCE_LOCAL (extension));
186 
187 	if (custom_file != NULL) {
188 		g_return_if_fail (G_IS_FILE (custom_file));
189 		g_object_ref (custom_file);
190 	}
191 
192 	g_mutex_lock (extension->priv->property_lock);
193 
194 	if (extension->priv->custom_file != NULL)
195 		g_object_unref (extension->priv->custom_file);
196 
197 	extension->priv->custom_file = custom_file;
198 
199 	g_mutex_unlock (extension->priv->property_lock);
200 
201 	g_object_notify (G_OBJECT (extension), "custom-file");
202 }