evolution-3.6.4/mail/e-mail-config-service-backend.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-service-backend.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-service-backend.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-config-service-backend.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-mail-config-service-backend.h"
 20 
 21 #include <mail/e-mail-config-receiving-page.h>
 22 #include <mail/e-mail-config-sending-page.h>
 23 
 24 #define E_MAIL_CONFIG_SERVICE_BACKEND_GET_PRIVATE(obj) \
 25 	(G_TYPE_INSTANCE_GET_PRIVATE \
 26 	((obj), E_TYPE_MAIL_CONFIG_SERVICE_BACKEND, EMailConfigServiceBackendPrivate))
 27 
 28 struct _EMailConfigServiceBackendPrivate {
 29 	ESource *source;
 30 	ESource *collection;
 31 };
 32 
 33 enum {
 34 	PROP_0,
 35 	PROP_COLLECTION,
 36 	PROP_SELECTABLE,
 37 	PROP_SOURCE
 38 };
 39 
 40 G_DEFINE_ABSTRACT_TYPE (
 41 	EMailConfigServiceBackend,
 42 	e_mail_config_service_backend,
 43 	E_TYPE_EXTENSION)
 44 
 45 static void
 46 mail_config_service_backend_init_collection (EMailConfigServiceBackend *backend)
 47 {
 48 	EMailConfigServiceBackendClass *class;
 49 
 50 	/* Use the new_collection() method to initialize the "collection"
 51 	 * property.  This assumes we're editing a new account.  If we're
 52 	 * editing an existing account, the initial "collection" property
 53 	 * value should be overridden with the existing collection source. */
 54 
 55 	g_return_if_fail (backend->priv->collection == NULL);
 56 
 57 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
 58 	g_return_if_fail (class->new_collection != NULL);
 59 
 60 	backend->priv->collection = class->new_collection (backend);
 61 }
 62 
 63 static void
 64 mail_config_service_backend_set_property (GObject *object,
 65                                           guint property_id,
 66                                           const GValue *value,
 67                                           GParamSpec *pspec)
 68 {
 69 	switch (property_id) {
 70 		case PROP_COLLECTION:
 71 			e_mail_config_service_backend_set_collection (
 72 				E_MAIL_CONFIG_SERVICE_BACKEND (object),
 73 				g_value_get_object (value));
 74 			return;
 75 
 76 		case PROP_SOURCE:
 77 			e_mail_config_service_backend_set_source (
 78 				E_MAIL_CONFIG_SERVICE_BACKEND (object),
 79 				g_value_get_object (value));
 80 			return;
 81 	}
 82 
 83 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 84 }
 85 
 86 static void
 87 mail_config_service_backend_get_property (GObject *object,
 88                                           guint property_id,
 89                                           GValue *value,
 90                                           GParamSpec *pspec)
 91 {
 92 	switch (property_id) {
 93 		case PROP_COLLECTION:
 94 			g_value_set_object (
 95 				value,
 96 				e_mail_config_service_backend_get_collection (
 97 				E_MAIL_CONFIG_SERVICE_BACKEND (object)));
 98 			return;
 99 
100 		case PROP_SELECTABLE:
101 			g_value_set_boolean (
102 				value,
103 				e_mail_config_service_backend_get_selectable (
104 				E_MAIL_CONFIG_SERVICE_BACKEND (object)));
105 			return;
106 
107 		case PROP_SOURCE:
108 			g_value_set_object (
109 				value,
110 				e_mail_config_service_backend_get_source (
111 				E_MAIL_CONFIG_SERVICE_BACKEND (object)));
112 			return;
113 	}
114 
115 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
116 }
117 
118 static void
119 mail_config_service_backend_dispose (GObject *object)
120 {
121 	EMailConfigServiceBackendPrivate *priv;
122 
123 	priv = E_MAIL_CONFIG_SERVICE_BACKEND_GET_PRIVATE (object);
124 
125 	if (priv->source != NULL) {
126 		g_object_unref (priv->source);
127 		priv->source = NULL;
128 	}
129 
130 	if (priv->collection != NULL) {
131 		g_object_unref (priv->collection);
132 		priv->collection = NULL;
133 	}
134 
135 	/* Chain up to parent's dispose() method. */
136 	G_OBJECT_CLASS (e_mail_config_service_backend_parent_class)->
137 		dispose (object);
138 }
139 
140 static void
141 mail_config_service_backend_constructed (GObject *object)
142 {
143 	EMailConfigServiceBackend *backend;
144 
145 	backend = E_MAIL_CONFIG_SERVICE_BACKEND (object);
146 	mail_config_service_backend_init_collection (backend);
147 
148 	/* Chain up to parent's constructed() method. */
149 	G_OBJECT_CLASS (e_mail_config_service_backend_parent_class)->
150 		constructed (object);
151 }
152 
153 static gboolean
154 mail_config_service_backend_get_selectable (EMailConfigServiceBackend *backend)
155 {
156 	EMailConfigServicePage *page;
157 	CamelProvider *provider;
158 	gboolean selectable = TRUE;
159 
160 	page = e_mail_config_service_backend_get_page (backend);
161 	provider = e_mail_config_service_backend_get_provider (backend);
162 
163 	if (CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (provider))
164 		selectable = E_IS_MAIL_CONFIG_RECEIVING_PAGE (page);
165 
166 	return selectable;
167 }
168 
169 static ESource *
170 mail_config_service_backend_new_collection (EMailConfigServiceBackend *backend)
171 {
172 	/* This is typically only used for groupware backends. */
173 	return NULL;
174 }
175 
176 static void
177 mail_config_service_backend_insert_widgets (EMailConfigServiceBackend *backend,
178                                             GtkBox *parent)
179 {
180 	/* does nothing */
181 }
182 
183 static void
184 mail_config_service_backend_setup_defaults (EMailConfigServiceBackend *backend)
185 {
186 	/* does nothing */
187 }
188 
189 static gboolean
190 mail_config_service_backend_auto_configure (EMailConfigServiceBackend *backend,
191                                             EMailAutoconfig *autoconfig)
192 {
193 	return FALSE;
194 }
195 
196 static gboolean
197 mail_config_service_backend_check_complete (EMailConfigServiceBackend *backend)
198 {
199 	return TRUE;
200 }
201 
202 static void
203 mail_config_service_backend_commit_changes (EMailConfigServiceBackend *backend)
204 {
205 	/* does nothing */
206 }
207 
208 static void
209 e_mail_config_service_backend_class_init (EMailConfigServiceBackendClass *class)
210 {
211 	GObjectClass *object_class;
212 	EExtensionClass *extension_class;
213 
214 	g_type_class_add_private (
215 		class, sizeof (EMailConfigServiceBackendPrivate));
216 
217 	object_class = G_OBJECT_CLASS (class);
218 	object_class->set_property = mail_config_service_backend_set_property;
219 	object_class->get_property = mail_config_service_backend_get_property;
220 	object_class->dispose = mail_config_service_backend_dispose;
221 	object_class->constructed = mail_config_service_backend_constructed;
222 
223 	extension_class = E_EXTENSION_CLASS (class);
224 	extension_class->extensible_type = E_TYPE_MAIL_CONFIG_SERVICE_PAGE;
225 
226 	class->get_selectable = mail_config_service_backend_get_selectable;
227 	class->new_collection = mail_config_service_backend_new_collection;
228 	class->insert_widgets = mail_config_service_backend_insert_widgets;
229 	class->setup_defaults = mail_config_service_backend_setup_defaults;
230 	class->auto_configure = mail_config_service_backend_auto_configure;
231 	class->check_complete = mail_config_service_backend_check_complete;
232 	class->commit_changes = mail_config_service_backend_commit_changes;
233 
234 	g_object_class_install_property (
235 		object_class,
236 		PROP_COLLECTION,
237 		g_param_spec_object (
238 			"collection",
239 			"Collection",
240 			"Optional collection ESource",
241 			E_TYPE_SOURCE,
242 			G_PARAM_READWRITE |
243 			G_PARAM_STATIC_STRINGS));
244 
245 	g_object_class_install_property (
246 		object_class,
247 		PROP_SELECTABLE,
248 		g_param_spec_boolean (
249 			"selectable",
250 			"Selectable",
251 			"Whether the backend is user selectable",
252 			TRUE,  /* not applied */
253 			G_PARAM_READABLE |
254 			G_PARAM_STATIC_STRINGS));
255 
256 	g_object_class_install_property (
257 		object_class,
258 		PROP_SOURCE,
259 		g_param_spec_object (
260 			"source",
261 			"Source",
262 			"The ESource being edited",
263 			E_TYPE_SOURCE,
264 			G_PARAM_READWRITE |
265 			G_PARAM_STATIC_STRINGS));
266 }
267 
268 static void
269 e_mail_config_service_backend_init (EMailConfigServiceBackend *backend)
270 {
271 	backend->priv = E_MAIL_CONFIG_SERVICE_BACKEND_GET_PRIVATE (backend);
272 }
273 
274 EMailConfigServicePage *
275 e_mail_config_service_backend_get_page (EMailConfigServiceBackend *backend)
276 {
277 	EExtensible *extensible;
278 
279 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), NULL);
280 
281 	extensible = e_extension_get_extensible (E_EXTENSION (backend));
282 
283 	return E_MAIL_CONFIG_SERVICE_PAGE (extensible);
284 }
285 
286 ESource *
287 e_mail_config_service_backend_get_source (EMailConfigServiceBackend *backend)
288 {
289 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), NULL);
290 
291 	return backend->priv->source;
292 }
293 
294 void
295 e_mail_config_service_backend_set_source (EMailConfigServiceBackend *backend,
296                                           ESource *source)
297 {
298 	g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
299 
300 	if (backend->priv->source == source)
301 		return;
302 
303 	if (source != NULL) {
304 		g_return_if_fail (E_IS_SOURCE (source));
305 		g_object_ref (source);
306 	}
307 
308 	if (backend->priv->source != NULL)
309 		g_object_unref (backend->priv->source);
310 
311 	backend->priv->source = source;
312 
313 	g_object_notify (G_OBJECT (backend), "source");
314 }
315 
316 ESource *
317 e_mail_config_service_backend_get_collection (EMailConfigServiceBackend *backend)
318 {
319 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), NULL);
320 
321 	return backend->priv->collection;
322 }
323 
324 void
325 e_mail_config_service_backend_set_collection (EMailConfigServiceBackend *backend,
326                                               ESource *collection)
327 {
328 	g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
329 
330 	if (backend->priv->collection == collection)
331 		return;
332 
333 	if (collection != NULL) {
334 		g_return_if_fail (E_IS_SOURCE (collection));
335 		g_object_ref (collection);
336 	}
337 
338 	if (backend->priv->collection != NULL)
339 		g_object_unref (backend->priv->collection);
340 
341 	backend->priv->collection = collection;
342 
343 	g_object_notify (G_OBJECT (backend), "collection");
344 }
345 
346 CamelProvider *
347 e_mail_config_service_backend_get_provider (EMailConfigServiceBackend *backend)
348 {
349 	EMailConfigServiceBackendClass *class;
350 
351 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), NULL);
352 
353 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
354 	g_return_val_if_fail (class->backend_name != NULL, NULL);
355 
356 	return camel_provider_get (class->backend_name, NULL);
357 }
358 
359 CamelSettings *
360 e_mail_config_service_backend_get_settings (EMailConfigServiceBackend *backend)
361 {
362 	ESource *source;
363 	ESourceCamel *camel_extension = NULL;
364 	EMailConfigServicePage *page;
365 	EMailConfigServicePageClass *page_class;
366 
367 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), NULL);
368 
369 	page = e_mail_config_service_backend_get_page (backend);
370 	page_class = E_MAIL_CONFIG_SERVICE_PAGE_GET_CLASS (page);
371 
372 	/* Which ESource do we pull the CamelSettings from?  This is a
373 	 * little tricky because we have to handle the following cases:
374 	 *
375 	 *   1) A stand-alone mail account.
376 	 *
377 	 *   2) A collection with a specialized backend (e.g. ews).
378 	 *
379 	 *   3) A collection that uses standard backends (e.g. yahoo).
380 	 *
381 	 * So the semantics are as follows.  They work for now but may
382 	 * need further tweaking as we support more collection types.
383 	 *
384 	 *   1) If the service backend defines a collection source,
385 	 *      assume the CamelSettings will be pulled from there.
386 	 *
387 	 *   2) If we have a collection source, try extracting the
388 	 *      ESourceCamel extension for the collection source's
389 	 *      backend name.
390 	 *
391 	 *   3) If steps 1 or 2 fail, pull the CamelSettings from
392 	 *      the service backend's own scratch source.
393 	 */
394 
395 	source = e_mail_config_service_backend_get_collection (backend);
396 	if (source != NULL) {
397 		ESourceBackend *backend_extension;
398 		const gchar *backend_name;
399 		const gchar *extension_name;
400 
401 		extension_name = E_SOURCE_EXTENSION_COLLECTION;
402 		backend_extension =
403 			e_source_get_extension (source, extension_name);
404 		backend_name =
405 			e_source_backend_get_backend_name (backend_extension);
406 
407 		extension_name =
408 			e_source_camel_get_extension_name (backend_name);
409 		camel_extension =
410 			e_source_get_extension (source, extension_name);
411 	}
412 
413 	if (camel_extension == NULL) {
414 		ESourceBackend *backend_extension;
415 		const gchar *backend_name;
416 		const gchar *extension_name;
417 
418 		source = e_mail_config_service_backend_get_source (backend);
419 
420 		extension_name = page_class->extension_name;
421 		backend_extension =
422 			e_source_get_extension (source, extension_name);
423 		backend_name =
424 			e_source_backend_get_backend_name (backend_extension);
425 
426 		extension_name =
427 			e_source_camel_get_extension_name (backend_name);
428 		camel_extension =
429 			e_source_get_extension (source, extension_name);
430 	}
431 
432 	return e_source_camel_get_settings (camel_extension);
433 }
434 
435 gboolean
436 e_mail_config_service_backend_get_selectable (EMailConfigServiceBackend *backend)
437 {
438 	EMailConfigServiceBackendClass *class;
439 
440 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), FALSE);
441 
442 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
443 	g_return_val_if_fail (class->get_selectable != NULL, FALSE);
444 
445 	return class->get_selectable (backend);
446 }
447 
448 void
449 e_mail_config_service_backend_insert_widgets (EMailConfigServiceBackend *backend,
450                                               GtkBox *parent)
451 {
452 	EMailConfigServiceBackendClass *class;
453 
454 	g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
455 	g_return_if_fail (GTK_IS_BOX (parent));
456 
457 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
458 	g_return_if_fail (class->insert_widgets != NULL);
459 
460 	class->insert_widgets (backend, parent);
461 }
462 
463 void
464 e_mail_config_service_backend_setup_defaults (EMailConfigServiceBackend *backend)
465 {
466 	EMailConfigServiceBackendClass *class;
467 
468 	g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
469 
470 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
471 	g_return_if_fail (class->setup_defaults != NULL);
472 
473 	return class->setup_defaults (backend);
474 }
475 
476 gboolean
477 e_mail_config_service_backend_auto_configure (EMailConfigServiceBackend *backend,
478                                               EMailAutoconfig *autoconfig)
479 {
480 	EMailConfigServiceBackendClass *class;
481 
482 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), FALSE);
483 	g_return_val_if_fail (E_IS_MAIL_AUTOCONFIG (autoconfig), FALSE);
484 
485 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
486 	g_return_val_if_fail (class->auto_configure != NULL, FALSE);
487 
488 	return class->auto_configure (backend, autoconfig);
489 }
490 
491 gboolean
492 e_mail_config_service_backend_check_complete (EMailConfigServiceBackend *backend)
493 {
494 	EMailConfigServiceBackendClass *class;
495 
496 	g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), FALSE);
497 
498 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
499 	g_return_val_if_fail (class->check_complete != NULL, FALSE);
500 
501 	return class->check_complete (backend);
502 }
503 
504 void
505 e_mail_config_service_backend_commit_changes (EMailConfigServiceBackend *backend)
506 {
507 	EMailConfigServiceBackendClass *class;
508 
509 	g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
510 
511 	class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
512 	g_return_if_fail (class->commit_changes != NULL);
513 
514 	class->commit_changes (backend);
515 }