2 * e-mail-config-service-backend.c
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.
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.
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/>
19 #include "e-mail-config-service-backend.h"
21 #include <mail/e-mail-config-receiving-page.h>
22 #include <mail/e-mail-config-sending-page.h>
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))
28 struct _EMailConfigServiceBackendPrivate
{
40 G_DEFINE_ABSTRACT_TYPE (
41 EMailConfigServiceBackend
,
42 e_mail_config_service_backend
,
46 mail_config_service_backend_init_collection (EMailConfigServiceBackend
*backend
)
48 EMailConfigServiceBackendClass
*class;
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. */
55 g_return_if_fail (backend
->priv
->collection
== NULL
);
57 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
58 g_return_if_fail (class->new_collection
!= NULL
);
60 backend
->priv
->collection
= class->new_collection (backend
);
64 mail_config_service_backend_set_property (GObject
*object
,
69 switch (property_id
) {
71 e_mail_config_service_backend_set_collection (
72 E_MAIL_CONFIG_SERVICE_BACKEND (object
),
73 g_value_get_object (value
));
77 e_mail_config_service_backend_set_source (
78 E_MAIL_CONFIG_SERVICE_BACKEND (object
),
79 g_value_get_object (value
));
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
87 mail_config_service_backend_get_property (GObject
*object
,
92 switch (property_id
) {
96 e_mail_config_service_backend_get_collection (
97 E_MAIL_CONFIG_SERVICE_BACKEND (object
)));
100 case PROP_SELECTABLE
:
101 g_value_set_boolean (
103 e_mail_config_service_backend_get_selectable (
104 E_MAIL_CONFIG_SERVICE_BACKEND (object
)));
110 e_mail_config_service_backend_get_source (
111 E_MAIL_CONFIG_SERVICE_BACKEND (object
)));
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
119 mail_config_service_backend_dispose (GObject
*object
)
121 EMailConfigServiceBackendPrivate
*priv
;
123 priv
= E_MAIL_CONFIG_SERVICE_BACKEND_GET_PRIVATE (object
);
125 if (priv
->source
!= NULL
) {
126 g_object_unref (priv
->source
);
130 if (priv
->collection
!= NULL
) {
131 g_object_unref (priv
->collection
);
132 priv
->collection
= NULL
;
135 /* Chain up to parent's dispose() method. */
136 G_OBJECT_CLASS (e_mail_config_service_backend_parent_class
)->
141 mail_config_service_backend_constructed (GObject
*object
)
143 EMailConfigServiceBackend
*backend
;
145 backend
= E_MAIL_CONFIG_SERVICE_BACKEND (object
);
146 mail_config_service_backend_init_collection (backend
);
148 /* Chain up to parent's constructed() method. */
149 G_OBJECT_CLASS (e_mail_config_service_backend_parent_class
)->
150 constructed (object
);
154 mail_config_service_backend_get_selectable (EMailConfigServiceBackend
*backend
)
156 EMailConfigServicePage
*page
;
157 CamelProvider
*provider
;
158 gboolean selectable
= TRUE
;
160 page
= e_mail_config_service_backend_get_page (backend
);
161 provider
= e_mail_config_service_backend_get_provider (backend
);
163 if (CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (provider
))
164 selectable
= E_IS_MAIL_CONFIG_RECEIVING_PAGE (page
);
170 mail_config_service_backend_new_collection (EMailConfigServiceBackend
*backend
)
172 /* This is typically only used for groupware backends. */
177 mail_config_service_backend_insert_widgets (EMailConfigServiceBackend
*backend
,
184 mail_config_service_backend_setup_defaults (EMailConfigServiceBackend
*backend
)
190 mail_config_service_backend_auto_configure (EMailConfigServiceBackend
*backend
,
191 EMailAutoconfig
*autoconfig
)
197 mail_config_service_backend_check_complete (EMailConfigServiceBackend
*backend
)
203 mail_config_service_backend_commit_changes (EMailConfigServiceBackend
*backend
)
209 e_mail_config_service_backend_class_init (EMailConfigServiceBackendClass
*class)
211 GObjectClass
*object_class
;
212 EExtensionClass
*extension_class
;
214 g_type_class_add_private (
215 class, sizeof (EMailConfigServiceBackendPrivate
));
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
;
223 extension_class
= E_EXTENSION_CLASS (class);
224 extension_class
->extensible_type
= E_TYPE_MAIL_CONFIG_SERVICE_PAGE
;
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
;
234 g_object_class_install_property (
237 g_param_spec_object (
240 "Optional collection ESource",
243 G_PARAM_STATIC_STRINGS
));
245 g_object_class_install_property (
248 g_param_spec_boolean (
251 "Whether the backend is user selectable",
252 TRUE
, /* not applied */
254 G_PARAM_STATIC_STRINGS
));
256 g_object_class_install_property (
259 g_param_spec_object (
262 "The ESource being edited",
265 G_PARAM_STATIC_STRINGS
));
269 e_mail_config_service_backend_init (EMailConfigServiceBackend
*backend
)
271 backend
->priv
= E_MAIL_CONFIG_SERVICE_BACKEND_GET_PRIVATE (backend
);
274 EMailConfigServicePage
*
275 e_mail_config_service_backend_get_page (EMailConfigServiceBackend
*backend
)
277 EExtensible
*extensible
;
279 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), NULL
);
281 extensible
= e_extension_get_extensible (E_EXTENSION (backend
));
283 return E_MAIL_CONFIG_SERVICE_PAGE (extensible
);
287 e_mail_config_service_backend_get_source (EMailConfigServiceBackend
*backend
)
289 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), NULL
);
291 return backend
->priv
->source
;
295 e_mail_config_service_backend_set_source (EMailConfigServiceBackend
*backend
,
298 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
));
300 if (backend
->priv
->source
== source
)
303 if (source
!= NULL
) {
304 g_return_if_fail (E_IS_SOURCE (source
));
305 g_object_ref (source
);
308 if (backend
->priv
->source
!= NULL
)
309 g_object_unref (backend
->priv
->source
);
311 backend
->priv
->source
= source
;
313 g_object_notify (G_OBJECT (backend
), "source");
317 e_mail_config_service_backend_get_collection (EMailConfigServiceBackend
*backend
)
319 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), NULL
);
321 return backend
->priv
->collection
;
325 e_mail_config_service_backend_set_collection (EMailConfigServiceBackend
*backend
,
328 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
));
330 if (backend
->priv
->collection
== collection
)
333 if (collection
!= NULL
) {
334 g_return_if_fail (E_IS_SOURCE (collection
));
335 g_object_ref (collection
);
338 if (backend
->priv
->collection
!= NULL
)
339 g_object_unref (backend
->priv
->collection
);
341 backend
->priv
->collection
= collection
;
343 g_object_notify (G_OBJECT (backend
), "collection");
347 e_mail_config_service_backend_get_provider (EMailConfigServiceBackend
*backend
)
349 EMailConfigServiceBackendClass
*class;
351 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), NULL
);
353 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
354 g_return_val_if_fail (class->backend_name
!= NULL
, NULL
);
356 return camel_provider_get (class->backend_name
, NULL
);
360 e_mail_config_service_backend_get_settings (EMailConfigServiceBackend
*backend
)
363 ESourceCamel
*camel_extension
= NULL
;
364 EMailConfigServicePage
*page
;
365 EMailConfigServicePageClass
*page_class
;
367 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), NULL
);
369 page
= e_mail_config_service_backend_get_page (backend
);
370 page_class
= E_MAIL_CONFIG_SERVICE_PAGE_GET_CLASS (page
);
372 /* Which ESource do we pull the CamelSettings from? This is a
373 * little tricky because we have to handle the following cases:
375 * 1) A stand-alone mail account.
377 * 2) A collection with a specialized backend (e.g. ews).
379 * 3) A collection that uses standard backends (e.g. yahoo).
381 * So the semantics are as follows. They work for now but may
382 * need further tweaking as we support more collection types.
384 * 1) If the service backend defines a collection source,
385 * assume the CamelSettings will be pulled from there.
387 * 2) If we have a collection source, try extracting the
388 * ESourceCamel extension for the collection source's
391 * 3) If steps 1 or 2 fail, pull the CamelSettings from
392 * the service backend's own scratch source.
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
;
401 extension_name
= E_SOURCE_EXTENSION_COLLECTION
;
403 e_source_get_extension (source
, extension_name
);
405 e_source_backend_get_backend_name (backend_extension
);
408 e_source_camel_get_extension_name (backend_name
);
410 e_source_get_extension (source
, extension_name
);
413 if (camel_extension
== NULL
) {
414 ESourceBackend
*backend_extension
;
415 const gchar
*backend_name
;
416 const gchar
*extension_name
;
418 source
= e_mail_config_service_backend_get_source (backend
);
420 extension_name
= page_class
->extension_name
;
422 e_source_get_extension (source
, extension_name
);
424 e_source_backend_get_backend_name (backend_extension
);
427 e_source_camel_get_extension_name (backend_name
);
429 e_source_get_extension (source
, extension_name
);
432 return e_source_camel_get_settings (camel_extension
);
436 e_mail_config_service_backend_get_selectable (EMailConfigServiceBackend
*backend
)
438 EMailConfigServiceBackendClass
*class;
440 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), FALSE
);
442 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
443 g_return_val_if_fail (class->get_selectable
!= NULL
, FALSE
);
445 return class->get_selectable (backend
);
449 e_mail_config_service_backend_insert_widgets (EMailConfigServiceBackend
*backend
,
452 EMailConfigServiceBackendClass
*class;
454 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
));
455 g_return_if_fail (GTK_IS_BOX (parent
));
457 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
458 g_return_if_fail (class->insert_widgets
!= NULL
);
460 class->insert_widgets (backend
, parent
);
464 e_mail_config_service_backend_setup_defaults (EMailConfigServiceBackend
*backend
)
466 EMailConfigServiceBackendClass
*class;
468 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
));
470 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
471 g_return_if_fail (class->setup_defaults
!= NULL
);
473 return class->setup_defaults (backend
);
477 e_mail_config_service_backend_auto_configure (EMailConfigServiceBackend
*backend
,
478 EMailAutoconfig
*autoconfig
)
480 EMailConfigServiceBackendClass
*class;
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
);
485 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
486 g_return_val_if_fail (class->auto_configure
!= NULL
, FALSE
);
488 return class->auto_configure (backend
, autoconfig
);
492 e_mail_config_service_backend_check_complete (EMailConfigServiceBackend
*backend
)
494 EMailConfigServiceBackendClass
*class;
496 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
), FALSE
);
498 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
499 g_return_val_if_fail (class->check_complete
!= NULL
, FALSE
);
501 return class->check_complete (backend
);
505 e_mail_config_service_backend_commit_changes (EMailConfigServiceBackend
*backend
)
507 EMailConfigServiceBackendClass
*class;
509 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend
));
511 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend
);
512 g_return_if_fail (class->commit_changes
!= NULL
);
514 class->commit_changes (backend
);