Updated Indonesian translation
[evolution.git] / mail / e-mail-config-service-backend.c
blobc6c42ae7f54c61df054357ec4a73a78c15b2bfb8
1 /*
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 {
29 ESource *source;
30 ESource *collection;
33 enum {
34 PROP_0,
35 PROP_COLLECTION,
36 PROP_SELECTABLE,
37 PROP_SOURCE
40 G_DEFINE_ABSTRACT_TYPE (
41 EMailConfigServiceBackend,
42 e_mail_config_service_backend,
43 E_TYPE_EXTENSION)
45 static void
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);
63 static void
64 mail_config_service_backend_set_property (GObject *object,
65 guint property_id,
66 const GValue *value,
67 GParamSpec *pspec)
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;
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;
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
86 static void
87 mail_config_service_backend_get_property (GObject *object,
88 guint property_id,
89 GValue *value,
90 GParamSpec *pspec)
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;
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;
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;
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
118 static void
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);
127 priv->source = NULL;
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)->
137 dispose (object);
140 static void
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);
153 static gboolean
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);
166 return selectable;
169 static ESource *
170 mail_config_service_backend_new_collection (EMailConfigServiceBackend *backend)
172 /* This is typically only used for groupware backends. */
173 return NULL;
176 static void
177 mail_config_service_backend_insert_widgets (EMailConfigServiceBackend *backend,
178 GtkBox *parent)
180 /* does nothing */
183 static void
184 mail_config_service_backend_setup_defaults (EMailConfigServiceBackend *backend)
186 /* does nothing */
189 static gboolean
190 mail_config_service_backend_auto_configure (EMailConfigServiceBackend *backend,
191 EMailAutoconfig *autoconfig)
193 return FALSE;
196 static gboolean
197 mail_config_service_backend_check_complete (EMailConfigServiceBackend *backend)
199 return TRUE;
202 static void
203 mail_config_service_backend_commit_changes (EMailConfigServiceBackend *backend)
205 /* does nothing */
208 static void
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 (
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));
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));
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));
268 static void
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);
286 ESource *
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;
294 void
295 e_mail_config_service_backend_set_source (EMailConfigServiceBackend *backend,
296 ESource *source)
298 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
300 if (backend->priv->source == source)
301 return;
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");
316 ESource *
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;
324 void
325 e_mail_config_service_backend_set_collection (EMailConfigServiceBackend *backend,
326 ESource *collection)
328 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
330 if (backend->priv->collection == collection)
331 return;
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");
346 CamelProvider *
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);
359 CamelSettings *
360 e_mail_config_service_backend_get_settings (EMailConfigServiceBackend *backend)
362 ESource *source;
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
389 * backend name.
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;
402 backend_extension =
403 e_source_get_extension (source, extension_name);
404 backend_name =
405 e_source_backend_get_backend_name (backend_extension);
407 extension_name =
408 e_source_camel_get_extension_name (backend_name);
409 camel_extension =
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;
421 backend_extension =
422 e_source_get_extension (source, extension_name);
423 backend_name =
424 e_source_backend_get_backend_name (backend_extension);
426 extension_name =
427 e_source_camel_get_extension_name (backend_name);
428 camel_extension =
429 e_source_get_extension (source, extension_name);
432 return e_source_camel_get_settings (camel_extension);
435 gboolean
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);
448 void
449 e_mail_config_service_backend_insert_widgets (EMailConfigServiceBackend *backend,
450 GtkBox *parent)
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);
463 void
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);
476 gboolean
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);
491 gboolean
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);
504 void
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);