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/>
20 * SECTION: e-source-registry
21 * @include: libedataserver/libedataserver.h
22 * @short_description: A central repository for data sources
24 * The #ESourceRegistry is a global singleton store for all #ESource
25 * instances. It uses file monitors to react to key file creation and
26 * deletion events, either constructing an #ESource instance from the
27 * newly created key file, or removing from the logical #ESource
28 * hierarchy the instance corresponding to the deleted key file.
30 * The #ESourceRegistry can be queried for individual #ESource instances
31 * by their unique identifier string or key file path, for collections of
32 * #ESource instances having a particular extension, or for all available
35 * The #ESourceRegistry API also provides a front-end for the
36 * "org.gnome.Evolution.DefaultSources" #GSettings schema which tracks
37 * which #ESource instances are designated to be the user's default address
38 * book, calendar, memo list and task list for desktop integration.
41 #include "e-source-registry.h"
44 #include <glib/gstdio.h>
45 #include <glib/gi18n-lib.h>
47 /* XXX Yeah, yeah... */
48 #define GCR_API_SUBJECT_TO_CHANGE
50 #include <gcr/gcr-base.h>
52 /* Private D-Bus classes. */
53 #include <e-dbus-source.h>
54 #include <e-dbus-source-manager.h>
56 #include <libedataserver/e-marshal.h>
57 #include <libedataserver/e-data-server-util.h>
58 #include <libedataserver/e-source-collection.h>
60 /* Needed for the defaults API. */
61 #include <libedataserver/e-source-address-book.h>
62 #include <libedataserver/e-source-calendar.h>
63 #include <libedataserver/e-source-mail-account.h>
64 #include <libedataserver/e-source-mail-identity.h>
66 #include "e-dbus-authenticator.h"
68 #define E_SOURCE_REGISTRY_GET_PRIVATE(obj) \
69 (G_TYPE_INSTANCE_GET_PRIVATE \
70 ((obj), E_TYPE_SOURCE_REGISTRY, ESourceRegistryPrivate))
72 #define DBUS_OBJECT_PATH "/org/gnome/evolution/dataserver/SourceManager"
73 #define GSETTINGS_SCHEMA "org.gnome.Evolution.DefaultSources"
75 /* Built-in data source UIDs. */
76 #define E_SOURCE_BUILTIN_ADDRESS_BOOK_UID "system-address-book"
77 #define E_SOURCE_BUILTIN_CALENDAR_UID "system-calendar"
78 #define E_SOURCE_BUILTIN_MAIL_ACCOUNT_UID "local"
79 #define E_SOURCE_BUILTIN_MEMO_LIST_UID "system-memo-list"
80 #define E_SOURCE_BUILTIN_TASK_LIST_UID "system-task-list"
82 /* GSettings keys for default data sources. */
83 #define E_SETTINGS_DEFAULT_ADDRESS_BOOK_KEY "default-address-book"
84 #define E_SETTINGS_DEFAULT_CALENDAR_KEY "default-calendar"
85 #define E_SETTINGS_DEFAULT_MAIL_ACCOUNT_KEY "default-mail-account"
86 #define E_SETTINGS_DEFAULT_MAIL_IDENTITY_KEY "default-mail-identity"
87 #define E_SETTINGS_DEFAULT_MEMO_LIST_KEY "default-memo-list"
88 #define E_SETTINGS_DEFAULT_TASK_LIST_KEY "default-task-list"
90 /* This forces the GType to be registered in a way that
91 * avoids a "statement with no effect" compiler warning.
92 * FIXME Use g_type_ensure() once we require GLib 2.34. */
93 #define REGISTER_TYPE(type) \
94 (g_type_class_unref (g_type_class_ref (type)))
96 typedef struct _AsyncContext AsyncContext;
97 typedef struct _AuthContext AuthContext;
98 typedef struct _CreateContext CreateContext;
99 typedef struct _SourceClosure SourceClosure;
100 typedef struct _ThreadClosure ThreadClosure;
102 struct _ESourceRegistryPrivate {
103 GMainContext *main_context;
105 GThread *manager_thread;
106 ThreadClosure *thread_closure;
108 GDBusObjectManager *dbus_object_manager;
109 EDBusSourceManager *dbus_source_manager;
111 GHashTable *object_path_table;
112 GMutex *object_path_table_lock;
115 GMutex *sources_lock;
120 struct _AsyncContext {
122 GList *list_of_sources;
123 ESourceAuthenticator *auth;
126 /* Used in e_source_registry_authenticate_sync() */
127 struct _AuthContext {
128 ESourceAuthenticator *auth;
129 EDBusAuthenticator *dbus_auth;
130 GCancellable *cancellable;
131 GMainLoop *main_loop;
132 ESourceAuthenticationResult auth_result;
133 GcrSecretExchange *secret_exchange;
134 gboolean authenticating;
139 /* Used in e_source_registry_create_sources_sync() */
140 struct _CreateContext {
141 GHashTable *pending_uids;
142 GMainContext *main_context;
143 GMainLoop *main_loop;
146 struct _SourceClosure {
147 ESourceRegistry *registry;
151 struct _ThreadClosure {
152 ESourceRegistry *registry;
153 GMainContext *main_context;
154 GMainLoop *main_loop;
155 GCond *main_loop_cond;
156 GMutex *main_loop_mutex;
162 PROP_DEFAULT_ADDRESS_BOOK,
163 PROP_DEFAULT_CALENDAR,
164 PROP_DEFAULT_MAIL_ACCOUNT,
165 PROP_DEFAULT_MAIL_IDENTITY,
166 PROP_DEFAULT_MEMO_LIST,
167 PROP_DEFAULT_TASK_LIST
179 /* Forward Declarations */
180 static void source_registry_add_source (ESourceRegistry *registry,
182 static void e_source_registry_initable_init (GInitableIface *interface);
184 static guint signals[LAST_SIGNAL];
186 /* By default, the GAsyncInitable interface calls GInitable.init()
187 * from a separate thread, so we only have to override GInitable. */
188 G_DEFINE_TYPE_WITH_CODE (
192 G_IMPLEMENT_INTERFACE (
193 G_TYPE_INITABLE, e_source_registry_initable_init)
194 G_IMPLEMENT_INTERFACE (
195 G_TYPE_ASYNC_INITABLE, NULL))
198 async_context_free (AsyncContext *async_context)
200 if (async_context->source != NULL)
201 g_object_unref (async_context->source);
204 async_context->list_of_sources,
205 (GDestroyNotify) g_object_unref);
207 if (async_context->auth != NULL)
208 g_object_unref (async_context->auth);
210 g_slice_free (AsyncContext, async_context);
214 auth_context_free (AuthContext *auth_context)
216 if (auth_context->auth != NULL)
217 g_object_unref (auth_context->auth);
219 if (auth_context->dbus_auth != NULL)
220 g_object_unref (auth_context->dbus_auth);
222 if (auth_context->cancellable != NULL)
223 g_object_unref (auth_context->cancellable);
225 if (auth_context->main_loop != NULL)
226 g_main_loop_unref (auth_context->main_loop);
228 if (auth_context->secret_exchange != NULL)
229 g_object_unref (auth_context->secret_exchange);
231 g_slice_free (AuthContext, auth_context);
234 static CreateContext *
235 create_context_new (void)
237 CreateContext *create_context;
239 create_context = g_slice_new0 (CreateContext);
241 create_context->pending_uids = g_hash_table_new_full (
242 (GHashFunc) g_str_hash,
243 (GEqualFunc) g_str_equal,
244 (GDestroyNotify) g_free,
245 (GDestroyNotify) NULL);
247 create_context->main_context = g_main_context_new ();
249 create_context->main_loop = g_main_loop_new (
250 create_context->main_context, FALSE);
252 return create_context;
256 create_context_free (CreateContext *create_context)
258 g_main_loop_unref (create_context->main_loop);
259 g_main_context_unref (create_context->main_context);
260 g_hash_table_unref (create_context->pending_uids);
262 g_slice_free (CreateContext, create_context);
266 source_closure_free (SourceClosure *closure)
268 g_object_unref (closure->registry);
269 g_object_unref (closure->source);
271 g_slice_free (SourceClosure, closure);
275 thread_closure_free (ThreadClosure *closure)
277 /* The registry member is not referenced. */
279 g_main_context_unref (closure->main_context);
280 g_main_loop_unref (closure->main_loop);
281 g_cond_free (closure->main_loop_cond);
282 g_mutex_free (closure->main_loop_mutex);
284 /* The GError should be NULL at this point,
285 * regardless of whether an error occurred. */
286 g_warn_if_fail (closure->error == NULL);
288 g_slice_free (ThreadClosure, closure);
292 source_registry_object_path_table_insert (ESourceRegistry *registry,
293 const gchar *object_path,
296 g_return_if_fail (object_path != NULL);
297 g_return_if_fail (E_IS_SOURCE (source));
299 g_mutex_lock (registry->priv->object_path_table_lock);
301 g_hash_table_insert (
302 registry->priv->object_path_table,
303 g_strdup (object_path),
304 g_object_ref (source));
306 g_mutex_unlock (registry->priv->object_path_table_lock);
310 source_registry_object_path_table_lookup (ESourceRegistry *registry,
311 const gchar *object_path)
315 g_return_val_if_fail (object_path != NULL, NULL);
317 g_mutex_lock (registry->priv->object_path_table_lock);
319 source = g_hash_table_lookup (
320 registry->priv->object_path_table, object_path);
322 g_object_ref (source);
324 g_mutex_unlock (registry->priv->object_path_table_lock);
330 source_registry_object_path_table_remove (ESourceRegistry *registry,
331 const gchar *object_path)
335 g_return_val_if_fail (object_path != NULL, FALSE);
337 g_mutex_lock (registry->priv->object_path_table_lock);
339 removed = g_hash_table_remove (
340 registry->priv->object_path_table, object_path);
342 g_mutex_unlock (registry->priv->object_path_table_lock);
348 source_registry_sources_insert (ESourceRegistry *registry,
353 uid = e_source_get_uid (source);
354 g_return_if_fail (uid != NULL);
356 g_mutex_lock (registry->priv->sources_lock);
358 g_hash_table_insert (
359 registry->priv->sources,
360 g_strdup (uid), g_object_ref (source));
362 g_mutex_unlock (registry->priv->sources_lock);
366 source_registry_sources_remove (ESourceRegistry *registry,
372 uid = e_source_get_uid (source);
373 g_return_val_if_fail (uid != NULL, FALSE);
375 g_mutex_lock (registry->priv->sources_lock);
377 removed = g_hash_table_remove (registry->priv->sources, uid);
379 g_mutex_unlock (registry->priv->sources_lock);
385 source_registry_sources_lookup (ESourceRegistry *registry,
390 g_return_val_if_fail (uid != NULL, NULL);
392 g_mutex_lock (registry->priv->sources_lock);
394 source = g_hash_table_lookup (registry->priv->sources, uid);
397 g_object_ref (source);
399 g_mutex_unlock (registry->priv->sources_lock);
405 source_registry_sources_get_values (ESourceRegistry *registry)
409 g_mutex_lock (registry->priv->sources_lock);
411 values = g_hash_table_get_values (registry->priv->sources);
413 g_list_foreach (values, (GFunc) g_object_ref, NULL);
415 g_mutex_unlock (registry->priv->sources_lock);
421 source_registry_sources_build_tree (ESourceRegistry *registry)
428 g_mutex_lock (registry->priv->sources_lock);
430 root = g_node_new (NULL);
431 index = g_hash_table_new (g_str_hash, g_str_equal);
433 /* Add a GNode for each ESource to the index. */
434 g_hash_table_iter_init (&iter, registry->priv->sources);
435 while (g_hash_table_iter_next (&iter, &key, &value)) {
436 ESource *source = g_object_ref (value);
437 g_hash_table_insert (index, key, g_node_new (source));
440 /* Traverse the index and link the nodes together. */
441 g_hash_table_iter_init (&iter, index);
442 while (g_hash_table_iter_next (&iter, NULL, &value)) {
446 const gchar *parent_uid;
448 source_node = (GNode *) value;
449 source = E_SOURCE (source_node->data);
450 parent_uid = e_source_get_parent (source);
452 if (parent_uid == NULL || *parent_uid == '\0') {
455 parent_node = g_hash_table_lookup (index, parent_uid);
456 g_warn_if_fail (parent_node != NULL);
459 /* Should never be NULL, but just to be safe. */
460 if (parent_node != NULL)
461 g_node_append (parent_node, source_node);
464 g_hash_table_destroy (index);
466 g_mutex_unlock (registry->priv->sources_lock);
472 source_registry_settings_changed_cb (GSettings *settings,
474 ESourceRegistry *registry)
476 /* We define a property name that matches every key in
477 * the "org.gnome.Evolution.DefaultSources" schema. */
478 g_object_notify (G_OBJECT (registry), key);
482 source_registry_source_changed_idle_cb (gpointer user_data)
484 SourceClosure *closure = user_data;
488 signals[SOURCE_CHANGED], 0,
495 source_registry_source_notify_enabled_idle_cb (gpointer user_data)
497 SourceClosure *closure = user_data;
499 if (e_source_get_enabled (closure->source))
502 signals[SOURCE_ENABLED], 0,
507 signals[SOURCE_DISABLED], 0,
514 source_registry_source_changed_cb (ESource *source,
515 ESourceRegistry *registry)
517 GSource *idle_source;
518 SourceClosure *closure;
520 closure = g_slice_new0 (SourceClosure);
521 closure->registry = g_object_ref (registry);
522 closure->source = g_object_ref (source);
524 idle_source = g_idle_source_new ();
525 g_source_set_callback (
527 source_registry_source_changed_idle_cb,
528 closure, (GDestroyNotify) source_closure_free);
529 g_source_attach (idle_source, registry->priv->main_context);
530 g_source_unref (idle_source);
534 source_registry_source_notify_enabled_cb (ESource *source,
536 ESourceRegistry *registry)
538 GSource *idle_source;
539 SourceClosure *closure;
541 closure = g_slice_new0 (SourceClosure);
542 closure->registry = g_object_ref (registry);
543 closure->source = g_object_ref (source);
545 idle_source = g_idle_source_new ();
546 g_source_set_callback (
548 source_registry_source_notify_enabled_idle_cb,
549 closure, (GDestroyNotify) source_closure_free);
550 g_source_attach (idle_source, registry->priv->main_context);
551 g_source_unref (idle_source);
555 source_registry_new_source (ESourceRegistry *registry,
556 GDBusObject *dbus_object)
558 GMainContext *main_context;
560 const gchar *object_path;
561 GError *error = NULL;
563 /* We don't want the ESource emitting "changed" signals from
564 * the manager thread, so we pass it the same main context the
565 * registry uses for scheduling signal emissions. */
566 main_context = registry->priv->main_context;
567 source = e_source_new (dbus_object, main_context, &error);
568 object_path = g_dbus_object_get_object_path (dbus_object);
570 /* The likelihood of an error here is slim, so it's
571 * sufficient to just print a warning if one occurs. */
573 g_warn_if_fail (source == NULL);
575 "ESourceRegistry: Failed to create a "
576 "data source object for path '%s': %s",
577 object_path, error->message);
578 g_error_free (error);
582 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
584 /* Add the ESource to the object path table immediately. */
585 source_registry_object_path_table_insert (
586 registry, object_path, source);
592 source_registry_unref_source (ESource *source)
594 g_signal_handlers_disconnect_matched (
595 source, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
596 source_registry_source_changed_cb, NULL);
598 g_signal_handlers_disconnect_matched (
599 source, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
600 source_registry_source_notify_enabled_cb, NULL);
602 g_object_unref (source);
606 source_registry_add_source (ESourceRegistry *registry,
611 /* This is called in the manager thread during initialization
612 * and in response to "object-added" signals from the manager. */
614 uid = e_source_get_uid (source);
615 g_return_if_fail (uid != NULL);
617 g_mutex_lock (registry->priv->sources_lock);
619 /* Check if we already have this source in the registry. */
620 if (g_hash_table_lookup (registry->priv->sources, uid) != NULL) {
621 g_mutex_unlock (registry->priv->sources_lock);
627 G_CALLBACK (source_registry_source_changed_cb),
631 source, "notify::enabled",
632 G_CALLBACK (source_registry_source_notify_enabled_cb),
635 g_mutex_unlock (registry->priv->sources_lock);
637 source_registry_sources_insert (registry, source);
641 source_registry_object_added_idle_cb (gpointer user_data)
643 SourceClosure *closure = user_data;
644 ESourceRegistry *registry = closure->registry;
645 ESource *source = closure->source;
647 g_signal_emit (registry, signals[SOURCE_ADDED], 0, source);
653 source_registry_object_added_cb (GDBusObjectManager *object_manager,
654 GDBusObject *dbus_object,
655 ESourceRegistry *registry)
657 SourceClosure *closure;
658 GSource *idle_source;
661 g_return_if_fail (E_DBUS_IS_OBJECT (dbus_object));
663 source = source_registry_new_source (registry, dbus_object);
664 g_return_if_fail (source != NULL);
666 /* Add the new ESource to our internal hash table so it can be
667 * obtained through e_source_registry_ref_source() immediately. */
668 source_registry_add_source (registry, source);
670 /* Schedule a callback on the ESourceRegistry's GMainContext. */
672 closure = g_slice_new0 (SourceClosure);
673 closure->registry = g_object_ref (registry);
674 closure->source = g_object_ref (source);
676 idle_source = g_idle_source_new ();
677 g_source_set_callback (
679 source_registry_object_added_idle_cb,
680 closure, (GDestroyNotify) source_closure_free);
681 g_source_attach (idle_source, registry->priv->main_context);
682 g_source_unref (idle_source);
684 g_object_unref (source);
688 source_registry_object_removed_idle_cb (gpointer user_data)
690 SourceClosure *closure = user_data;
691 ESourceRegistry *registry = closure->registry;
692 ESource *source = closure->source;
694 /* Removing the ESource won't finalize it because the
695 * SourceClosure itself still holds a reference on it. */
696 if (source_registry_sources_remove (registry, source))
697 g_signal_emit (registry, signals[SOURCE_REMOVED], 0, source);
703 source_registry_object_removed_cb (GDBusObjectManager *manager,
704 GDBusObject *dbus_object,
705 ESourceRegistry *registry)
707 SourceClosure *closure;
708 GSource *idle_source;
710 const gchar *object_path;
712 /* Find the corresponding ESource in the object path table.
713 * Note that the lookup returns a new ESource reference. */
714 object_path = g_dbus_object_get_object_path (dbus_object);
715 source = source_registry_object_path_table_lookup (
716 registry, object_path);
717 g_return_if_fail (E_IS_SOURCE (source));
719 /* Remove the ESource from the object path table immediately. */
720 source_registry_object_path_table_remove (registry, object_path);
722 /* Schedule a callback on the ESourceRegistry's GMainContext. */
724 closure = g_slice_new0 (SourceClosure);
725 closure->registry = g_object_ref (registry);
726 closure->source = g_object_ref (source);
728 idle_source = g_idle_source_new ();
729 g_source_set_callback (
731 source_registry_object_removed_idle_cb,
732 closure, (GDestroyNotify) source_closure_free);
733 g_source_attach (idle_source, registry->priv->main_context);
734 g_source_unref (idle_source);
736 g_object_unref (source);
740 source_registry_object_manager_running (gpointer data)
742 ThreadClosure *closure = data;
744 g_mutex_lock (closure->main_loop_mutex);
745 g_cond_broadcast (closure->main_loop_cond);
746 g_mutex_unlock (closure->main_loop_mutex);
752 source_registry_object_manager_thread (gpointer data)
754 GDBusObjectManager *object_manager;
755 ThreadClosure *closure = data;
756 GSource *idle_source;
758 gulong object_added_id = 0;
759 gulong object_removed_id = 0;
761 /* GDBusObjectManagerClient grabs the thread-default GMainContext
762 * at creation time and only emits signals from that GMainContext.
763 * Running it in a separate thread prevents its signal emissions
764 * from being inhibited by someone overriding the thread-default
767 /* This becomes the GMainContext that GDBusObjectManagerClient
768 * will emit signals from. Make it the thread-default context
769 * for this thread before creating the client. */
770 g_main_context_push_thread_default (closure->main_context);
772 object_manager = e_dbus_object_manager_client_new_for_bus_sync (
774 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
775 SOURCES_DBUS_SERVICE_NAME,
777 NULL, &closure->error);
781 ((object_manager != NULL) && (closure->error == NULL)) ||
782 ((object_manager == NULL) && (closure->error != NULL)));
784 /* If we failed to create the GDBusObjectManagerClient, skip
785 * straight to the main loop. The GError will be propagated
786 * back to the caller, the main loop will terminate, and the
787 * partially-initialized ESourceRegistry will be destroyed. */
788 if (object_manager == NULL)
791 /* Give the registry a handle to the object manager. */
792 closure->registry->priv->dbus_object_manager =
793 g_object_ref (object_manager);
795 /* Now populate the registry with an initial set of ESources. */
797 list = g_dbus_object_manager_get_objects (object_manager);
799 for (link = list; link != NULL; link = g_list_next (link)) {
800 GDBusObject *dbus_object;
803 dbus_object = G_DBUS_OBJECT (link->data);
805 source = source_registry_new_source (
806 closure->registry, dbus_object);
808 if (source != NULL) {
809 source_registry_add_source (
810 closure->registry, source);
811 g_object_unref (source);
815 g_list_free_full (list, (GDestroyNotify) g_object_unref);
817 /* Listen for D-Bus object additions and removals. */
819 object_added_id = g_signal_connect (
820 object_manager, "object-added",
821 G_CALLBACK (source_registry_object_added_cb),
824 object_removed_id = g_signal_connect (
825 object_manager, "object-removed",
826 G_CALLBACK (source_registry_object_removed_cb),
830 /* Schedule a one-time idle callback to broadcast through a
831 * condition variable that our main loop is up and running. */
833 idle_source = g_idle_source_new ();
834 g_source_set_callback (
836 source_registry_object_manager_running,
837 closure, (GDestroyNotify) NULL);
838 g_source_attach (idle_source, closure->main_context);
839 g_source_unref (idle_source);
841 /* Now we mostly idle here for the rest of the session. */
843 g_main_loop_run (closure->main_loop);
845 /* Clean up and exit. */
847 if (object_manager != NULL) {
848 g_signal_handler_disconnect (object_manager, object_added_id);
849 g_signal_handler_disconnect (object_manager, object_removed_id);
850 g_object_unref (object_manager);
853 g_main_context_pop_thread_default (closure->main_context);
859 source_registry_set_property (GObject *object,
864 switch (property_id) {
865 case PROP_DEFAULT_ADDRESS_BOOK:
866 e_source_registry_set_default_address_book (
867 E_SOURCE_REGISTRY (object),
868 g_value_get_object (value));
871 case PROP_DEFAULT_CALENDAR:
872 e_source_registry_set_default_calendar (
873 E_SOURCE_REGISTRY (object),
874 g_value_get_object (value));
877 case PROP_DEFAULT_MAIL_ACCOUNT:
878 e_source_registry_set_default_mail_account (
879 E_SOURCE_REGISTRY (object),
880 g_value_get_object (value));
883 case PROP_DEFAULT_MAIL_IDENTITY:
884 e_source_registry_set_default_mail_identity (
885 E_SOURCE_REGISTRY (object),
886 g_value_get_object (value));
889 case PROP_DEFAULT_MEMO_LIST:
890 e_source_registry_set_default_memo_list (
891 E_SOURCE_REGISTRY (object),
892 g_value_get_object (value));
895 case PROP_DEFAULT_TASK_LIST:
896 e_source_registry_set_default_task_list (
897 E_SOURCE_REGISTRY (object),
898 g_value_get_object (value));
902 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
906 source_registry_get_property (GObject *object,
911 switch (property_id) {
912 case PROP_DEFAULT_ADDRESS_BOOK:
913 g_value_take_object (
915 e_source_registry_ref_default_address_book (
916 E_SOURCE_REGISTRY (object)));
919 case PROP_DEFAULT_CALENDAR:
920 g_value_take_object (
922 e_source_registry_ref_default_calendar (
923 E_SOURCE_REGISTRY (object)));
926 case PROP_DEFAULT_MAIL_ACCOUNT:
927 g_value_take_object (
929 e_source_registry_ref_default_mail_account (
930 E_SOURCE_REGISTRY (object)));
933 case PROP_DEFAULT_MAIL_IDENTITY:
934 g_value_take_object (
936 e_source_registry_ref_default_mail_identity (
937 E_SOURCE_REGISTRY (object)));
940 case PROP_DEFAULT_MEMO_LIST:
941 g_value_take_object (
943 e_source_registry_ref_default_memo_list (
944 E_SOURCE_REGISTRY (object)));
947 case PROP_DEFAULT_TASK_LIST:
948 g_value_take_object (
950 e_source_registry_ref_default_task_list (
951 E_SOURCE_REGISTRY (object)));
955 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
959 source_registry_dispose (GObject *object)
961 ESourceRegistryPrivate *priv;
963 priv = E_SOURCE_REGISTRY_GET_PRIVATE (object);
965 /* Terminate the manager thread first. */
966 if (priv->manager_thread != NULL) {
967 g_main_loop_quit (priv->thread_closure->main_loop);
968 g_thread_join (priv->manager_thread);
969 thread_closure_free (priv->thread_closure);
970 priv->manager_thread = NULL;
971 priv->thread_closure = NULL;
974 if (priv->main_context != NULL) {
975 g_main_context_unref (priv->main_context);
976 priv->main_context = NULL;
979 if (priv->dbus_object_manager != NULL) {
980 g_object_unref (priv->dbus_object_manager);
981 priv->dbus_object_manager = NULL;
984 if (priv->dbus_source_manager != NULL) {
985 g_object_unref (priv->dbus_source_manager);
986 priv->dbus_source_manager = NULL;
989 g_hash_table_remove_all (priv->object_path_table);
991 g_hash_table_remove_all (priv->sources);
993 if (priv->settings != NULL) {
994 g_object_unref (priv->settings);
995 priv->settings = NULL;
998 /* Chain up to parent's finalize() method. */
999 G_OBJECT_CLASS (e_source_registry_parent_class)->dispose (object);
1003 source_registry_finalize (GObject *object)
1005 ESourceRegistryPrivate *priv;
1007 priv = E_SOURCE_REGISTRY_GET_PRIVATE (object);
1009 g_hash_table_destroy (priv->object_path_table);
1010 g_mutex_free (priv->object_path_table_lock);
1012 g_hash_table_destroy (priv->sources);
1013 g_mutex_free (priv->sources_lock);
1015 /* Chain up to parent's finalize() method. */
1016 G_OBJECT_CLASS (e_source_registry_parent_class)->finalize (object);
1020 source_registry_initable_init (GInitable *initable,
1021 GCancellable *cancellable,
1024 ESourceRegistry *registry;
1025 ThreadClosure *closure;
1027 registry = E_SOURCE_REGISTRY (initable);
1029 closure = g_slice_new0 (ThreadClosure);
1030 closure->registry = registry; /* do not reference */
1031 closure->main_context = g_main_context_new ();
1032 /* It's important to pass 'is_running=FALSE' here because
1033 * we wait for the main loop to start running as a way of
1034 * synchronizing with the manager thread. */
1035 closure->main_loop = g_main_loop_new (closure->main_context, FALSE);
1036 closure->main_loop_cond = g_cond_new ();
1037 closure->main_loop_mutex = g_mutex_new ();
1039 registry->priv->thread_closure = closure;
1041 registry->priv->manager_thread = g_thread_create (
1042 source_registry_object_manager_thread,
1043 closure, TRUE /* joinable */, error);
1045 if (registry->priv->manager_thread == NULL)
1048 /* Wait for notification that the manager
1049 * thread's main loop has been started. */
1050 g_mutex_lock (closure->main_loop_mutex);
1051 while (!g_main_loop_is_running (closure->main_loop))
1053 closure->main_loop_cond,
1054 closure->main_loop_mutex);
1055 g_mutex_unlock (closure->main_loop_mutex);
1057 /* Check for error in the manager thread. */
1058 if (closure->error != NULL) {
1059 g_propagate_error (error, closure->error);
1060 closure->error = NULL;
1064 /* The registry should now be populated with sources. */
1065 g_warn_if_fail (g_hash_table_size (registry->priv->sources) > 0);
1067 /* The EDBusSourceManagerProxy is just another D-Bus interface
1068 * that resides at the same object path. It's unrelated to the
1069 * GDBusObjectManagerClient and doesn't need its own thread. */
1070 registry->priv->dbus_source_manager =
1071 e_dbus_source_manager_proxy_new_for_bus_sync (
1073 G_DBUS_PROXY_FLAGS_NONE,
1074 SOURCES_DBUS_SERVICE_NAME,
1076 cancellable, error);
1078 if (registry->priv->dbus_source_manager == NULL)
1085 e_source_registry_class_init (ESourceRegistryClass *class)
1087 GObjectClass *object_class;
1089 g_type_class_add_private (class, sizeof (ESourceRegistryPrivate));
1091 object_class = G_OBJECT_CLASS (class);
1092 object_class->set_property = source_registry_set_property;
1093 object_class->get_property = source_registry_get_property;
1094 object_class->dispose = source_registry_dispose;
1095 object_class->finalize = source_registry_finalize;
1097 /* The property names correspond to the key names in the
1098 * "org.gnome.Evolution.DefaultSources" GSettings schema. */
1101 * ESourceRegistry:default-address-book:
1103 * The default address book #ESource.
1105 g_object_class_install_property (
1107 PROP_DEFAULT_ADDRESS_BOOK,
1108 g_param_spec_object (
1109 "default-address-book",
1110 "Default Address Book",
1111 "The default address book ESource",
1114 G_PARAM_STATIC_STRINGS));
1117 * ESourceRegistry:default-calendar:
1119 * The default calendar #ESource.
1121 g_object_class_install_property (
1123 PROP_DEFAULT_CALENDAR,
1124 g_param_spec_object (
1127 "The default calendar ESource",
1130 G_PARAM_STATIC_STRINGS));
1133 * ESourceRegistry:default-mail-account:
1135 * The default mail account #ESource.
1137 g_object_class_install_property (
1139 PROP_DEFAULT_MAIL_ACCOUNT,
1140 g_param_spec_object (
1141 "default-mail-account",
1142 "Default Mail Account",
1143 "The default mail account ESource",
1146 G_PARAM_STATIC_STRINGS));
1149 * ESourceRegistry:default-mail-identity:
1151 * The default mail identity #ESource.
1153 g_object_class_install_property (
1155 PROP_DEFAULT_MAIL_IDENTITY,
1156 g_param_spec_object (
1157 "default-mail-identity",
1158 "Default Mail Identity",
1159 "The default mail identity ESource",
1162 G_PARAM_STATIC_STRINGS));
1165 * ESourceRegistry:default-memo-list:
1167 * The default memo list #ESource.
1169 g_object_class_install_property (
1171 PROP_DEFAULT_MEMO_LIST,
1172 g_param_spec_object (
1173 "default-memo-list",
1174 "Default Memo List",
1175 "The default memo list ESource",
1178 G_PARAM_STATIC_STRINGS));
1181 * ESourceRegistry:default-task-list:
1183 * The default task list #ESource.
1185 g_object_class_install_property (
1187 PROP_DEFAULT_TASK_LIST,
1188 g_param_spec_object (
1189 "default-task-list",
1190 "Default Task List",
1191 "The default task list ESource",
1194 G_PARAM_STATIC_STRINGS));
1197 * ESourceRegistry::source-added:
1198 * @registry: the #ESourceRegistry which emitted the signal
1199 * @source: the newly-added #ESource
1201 * Emitted when an #ESource is added to @registry.
1203 signals[SOURCE_ADDED] = g_signal_new (
1205 G_OBJECT_CLASS_TYPE (object_class),
1207 G_STRUCT_OFFSET (ESourceRegistryClass, source_added),
1209 g_cclosure_marshal_VOID__OBJECT,
1214 * ESourceRegistry::source-changed:
1215 * @registry: the #ESourceRegistry which emitted the signal
1216 * @source: the #ESource that changed
1218 * Emitted when an #ESource registered with @registry emits
1219 * its #ESource::changed signal.
1221 signals[SOURCE_CHANGED] = g_signal_new (
1223 G_OBJECT_CLASS_TYPE (object_class),
1225 G_STRUCT_OFFSET (ESourceRegistryClass, source_changed),
1227 g_cclosure_marshal_VOID__OBJECT,
1232 * ESourceRegistry::source-removed:
1233 * @registry: the #ESourceRegistry which emitted the signal
1234 * @source: the #ESource that got removed
1236 * Emitted when an #ESource is removed from @registry.
1238 signals[SOURCE_REMOVED] = g_signal_new (
1240 G_OBJECT_CLASS_TYPE (object_class),
1242 G_STRUCT_OFFSET (ESourceRegistryClass, source_removed),
1244 g_cclosure_marshal_VOID__OBJECT,
1249 * ESourceRegistry::source-enabled:
1250 * @registry: the #ESourceRegistry which emitted the signal
1251 * @source: the #ESource that got enabled
1253 * Emitted when an #ESource #ESource:enabled property becomes %TRUE.
1255 signals[SOURCE_ENABLED] = g_signal_new (
1257 G_OBJECT_CLASS_TYPE (object_class),
1259 G_STRUCT_OFFSET (ESourceRegistryClass, source_enabled),
1261 g_cclosure_marshal_VOID__OBJECT,
1266 * ESourceRegistry::source-disabled:
1267 * @registry: the #ESourceRegistry which emitted the signal
1268 * @source: the #ESource that got disabled
1270 * Emitted when an #ESource #ESource:enabled property becomes %FALSE.
1272 signals[SOURCE_DISABLED] = g_signal_new (
1274 G_OBJECT_CLASS_TYPE (object_class),
1276 G_STRUCT_OFFSET (ESourceRegistryClass, source_disabled),
1278 g_cclosure_marshal_VOID__OBJECT,
1284 e_source_registry_initable_init (GInitableIface *interface)
1286 interface->init = source_registry_initable_init;
1290 e_source_registry_init (ESourceRegistry *registry)
1292 registry->priv = E_SOURCE_REGISTRY_GET_PRIVATE (registry);
1294 /* This is so the object manager thread can schedule signal
1295 * emissions on the thread-default context for this thread. */
1296 registry->priv->main_context = g_main_context_ref_thread_default ();
1298 /* D-Bus object path -> ESource */
1299 registry->priv->object_path_table =
1300 g_hash_table_new_full (
1301 (GHashFunc) g_str_hash,
1302 (GEqualFunc) g_str_equal,
1303 (GDestroyNotify) g_free,
1304 (GDestroyNotify) g_object_unref);
1306 registry->priv->object_path_table_lock = g_mutex_new ();
1308 /* UID string -> ESource */
1309 registry->priv->sources = g_hash_table_new_full (
1310 (GHashFunc) g_str_hash,
1311 (GEqualFunc) g_str_equal,
1312 (GDestroyNotify) g_free,
1313 (GDestroyNotify) source_registry_unref_source);
1315 registry->priv->sources_lock = g_mutex_new ();
1317 registry->priv->settings = g_settings_new (GSETTINGS_SCHEMA);
1320 registry->priv->settings, "changed",
1321 G_CALLBACK (source_registry_settings_changed_cb), registry);
1325 * e_source_registry_new_sync:
1326 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1327 * @error: return location for a #GError, or %NULL
1329 * Creates a new #ESourceRegistry front-end for the registry D-Bus service.
1330 * If an error occurs in connecting to the D-Bus service, the function sets
1331 * @error and returns %NULL.
1333 * Returns: a new #ESourceRegistry, or %NULL
1338 e_source_registry_new_sync (GCancellable *cancellable,
1341 /* XXX Work around http://bugzilla.gnome.org/show_bug.cgi?id=683519
1342 * until GObject's type initialization deadlock issue is fixed.
1343 * Apparently only the synchronous instantiation is affected. */
1344 REGISTER_TYPE (G_TYPE_DBUS_CONNECTION);
1346 return g_initable_new (
1347 E_TYPE_SOURCE_REGISTRY,
1348 cancellable, error, NULL);
1352 * e_source_registry_new:
1353 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1354 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1356 * @user_data: (closure): data to pass to the callback function
1358 * Asynchronously creates a new #ESourceRegistry front-end for the registry
1361 * When the operation is finished, @callback will be called. You can then
1362 * call e_source_registry_new_finish() to get the result of the operation.
1367 e_source_registry_new (GCancellable *cancellable,
1368 GAsyncReadyCallback callback,
1371 g_async_initable_new_async (
1372 E_TYPE_SOURCE_REGISTRY,
1373 G_PRIORITY_DEFAULT, cancellable,
1374 callback, user_data, NULL);
1378 * e_source_registry_new_finish:
1379 * @result: a #GAsyncResult
1380 * @error: return location for a #GError, or %NULL
1382 * Finishes the operation started with e_source_registry_new_finish().
1383 * If an error occurs in connecting to the D-Bus service, the function
1384 * sets @error and returns %NULL.
1386 * Returns: a new #ESourceRegistry, or %NULL
1391 e_source_registry_new_finish (GAsyncResult *result,
1394 GObject *source_object;
1397 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
1399 source_object = g_async_result_get_source_object (result);
1400 g_return_val_if_fail (source_object != NULL, NULL);
1402 object = g_async_initable_new_finish (
1403 G_ASYNC_INITABLE (source_object), result, error);
1405 g_object_unref (source_object);
1407 return (object != NULL) ? E_SOURCE_REGISTRY (object) : NULL;
1410 /* Helper for e_source_registry_authenticate() */
1412 source_registry_authenticate_thread (GSimpleAsyncResult *simple,
1414 GCancellable *cancellable)
1416 AsyncContext *async_context;
1417 GError *error = NULL;
1419 async_context = g_simple_async_result_get_op_res_gpointer (simple);
1421 e_source_registry_authenticate_sync (
1422 E_SOURCE_REGISTRY (object),
1423 async_context->source,
1424 async_context->auth,
1425 cancellable, &error);
1428 g_simple_async_result_take_error (simple, error);
1431 /* Helper for e_source_registry_authenticate_sync() */
1433 source_registry_authenticate_respond_cb (AuthContext *auth_context)
1435 ESourceAuthenticationResult auth_result;
1436 GError *non_fatal_error = NULL;
1438 g_return_val_if_fail (auth_context->authenticating, FALSE);
1440 auth_result = auth_context->auth_result;
1442 /* Allow the next authentication attempt to proceed. */
1443 auth_context->authenticating = FALSE;
1445 /* Send the server a status update based on the authentication
1446 * result. Note, we don't really care if the D-Bus message gets
1447 * through to the server at this point. If it doesn't, the auth
1448 * session will either time out on its own or the authentication
1449 * dialog will eventually be dismissed by the user. */
1451 /* If we were cancelled from our side, we have a bit of a dilemma.
1452 * We need to tell the server to cancel the authentication session,
1453 * but that involves making a synchronous D-Bus call, which we are
1454 * not supposed to do if we know we've been cancelled. But if we
1455 * don't tell the server, the authentication session will be left
1456 * to timeout on its own (which may take minutes), and meanwhile
1457 * all other authentication requests are blocked. So choose the
1458 * lesser evil and make the synchronous call but without passing
1459 * the already-cancelled GCancellable. */
1460 if (g_cancellable_is_cancelled (auth_context->cancellable)) {
1461 e_dbus_authenticator_call_cancel_sync (
1462 auth_context->dbus_auth,
1463 NULL, &non_fatal_error);
1464 g_main_loop_quit (auth_context->main_loop);
1465 auth_context->success = FALSE;
1467 /* If an error occurred while attempting to authenticate,
1468 * tell the server to cancel the authentication session. */
1469 } else if (auth_result == E_SOURCE_AUTHENTICATION_ERROR) {
1470 e_dbus_authenticator_call_cancel_sync (
1471 auth_context->dbus_auth,
1472 auth_context->cancellable,
1474 g_main_loop_quit (auth_context->main_loop);
1475 auth_context->success = FALSE;
1477 /* If the password was accepted, let the server know so it
1478 * can close any authentication dialogs and save the user
1479 * provided password to the keyring. */
1480 } else if (auth_result == E_SOURCE_AUTHENTICATION_ACCEPTED) {
1481 e_dbus_authenticator_call_accepted_sync (
1482 auth_context->dbus_auth,
1483 auth_context->cancellable,
1485 g_main_loop_quit (auth_context->main_loop);
1486 auth_context->success = TRUE;
1488 /* If the password was rejected, let the server know so it can
1489 * indicate failure and request a different password, and then
1490 * wait for the next "response" signal. */
1492 e_dbus_authenticator_call_rejected_sync (
1493 auth_context->dbus_auth,
1494 auth_context->cancellable,
1498 /* Leave breadcrumbs if something went wrong,
1499 * but don't fail the whole operation over it. */
1500 if (non_fatal_error != NULL) {
1501 g_warning ("%s: %s", G_STRFUNC, non_fatal_error->message);
1502 g_error_free (non_fatal_error);
1508 /* Helper for e_source_registry_authenticate_sync() */
1510 source_registry_authenticate_authenticate_cb (EDBusAuthenticator *dbus_auth,
1511 const gchar *encrypted_secret,
1512 AuthContext *auth_context)
1514 GSource *idle_source;
1515 GMainContext *main_context;
1517 gboolean valid_secret;
1519 /* We should only get one secret at a time. */
1520 g_return_if_fail (!auth_context->authenticating);
1522 valid_secret = gcr_secret_exchange_receive (
1523 auth_context->secret_exchange, encrypted_secret);
1524 g_return_if_fail (valid_secret);
1526 auth_context->authenticating = TRUE;
1528 /* This avoids revealing the password in a stack trace. */
1529 password = g_string_new (
1530 gcr_secret_exchange_get_secret (
1531 auth_context->secret_exchange, NULL));
1533 /* Try authenticating with the given password. We have to
1534 * call this synchronously because some authenticators use
1535 * mutexes to serialize I/O operations and are not prepared
1536 * to make authentication attempts from a different thread.
1538 * Unfortunately this means we won't notice server-side
1539 * dismissals while the main loop is blocked. We respond
1540 * to the server from a low-priority idle callback so that
1541 * any pending "dismissed" signals get handled first. */
1543 auth_context->auth_result =
1544 e_source_authenticator_try_password_sync (
1545 auth_context->auth, password,
1546 auth_context->cancellable,
1547 auth_context->error);
1549 idle_source = g_idle_source_new ();
1550 main_context = g_main_context_get_thread_default ();
1551 g_source_set_callback (
1552 idle_source, (GSourceFunc)
1553 source_registry_authenticate_respond_cb,
1554 auth_context, NULL);
1555 g_source_attach (idle_source, main_context);
1556 g_source_unref (idle_source);
1558 g_string_free (password, TRUE);
1561 /* Helper for e_source_registry_authenticate_sync() */
1563 source_registry_authenticate_dismissed_cb (EDBusAuthenticator *dbus_auth,
1564 AuthContext *auth_context)
1566 /* Be careful not to overwrite an existing error in case this
1567 * is called after e_source_authenticator_try_password_sync()
1568 * but prior to the idle callback. */
1569 if (auth_context->auth_result != E_SOURCE_AUTHENTICATION_ERROR) {
1570 /* XXX Use a separate error code for dismissals? */
1571 g_set_error_literal (
1572 auth_context->error,
1573 G_IO_ERROR, G_IO_ERROR_CANCELLED,
1574 _("The user declined to authenticate"));
1575 auth_context->auth_result = E_SOURCE_AUTHENTICATION_ERROR;
1578 g_main_loop_quit (auth_context->main_loop);
1579 auth_context->success = FALSE;
1582 /* Helper for e_source_registry_authenticate_sync() */
1584 source_registry_call_authenticate_for_source (ESourceRegistry *registry,
1585 ESourceAuthenticator *auth,
1587 gchar **out_object_path,
1588 GCancellable *cancellable,
1591 ESource *collection;
1593 gchar *prompt_title = NULL;
1594 gchar *prompt_message = NULL;
1595 gchar *prompt_description = NULL;
1598 /* If the source is a member of a collection, we want to store
1599 * the password under the UID of the "collection" source so it
1600 * will apply to the entire collection.
1602 * XXX This assumes all sources in a collection share a single
1603 * password. If that turns out not to be true in all cases
1604 * we could maybe add a "SharedPassword: true/false" key to
1605 * [Collection] and apply it here.
1607 collection = e_source_registry_find_extension (
1608 registry, source, E_SOURCE_EXTENSION_COLLECTION);
1609 if (collection != NULL)
1610 source = collection;
1612 g_object_ref (source);
1614 uid = e_source_get_uid (source);
1616 e_source_authenticator_get_prompt_strings (
1620 &prompt_description);
1622 success = e_dbus_source_manager_call_authenticate_sync (
1623 registry->priv->dbus_source_manager, uid,
1624 prompt_title, prompt_message, prompt_description,
1625 out_object_path, cancellable, error);
1627 g_free (prompt_title);
1628 g_free (prompt_message);
1629 g_free (prompt_description);
1631 g_object_unref (source);
1637 * e_source_registry_authenticate_sync:
1638 * @registry: an #ESourceRegistry
1639 * @source: an #ESource
1640 * @auth: an #ESourceAuthenticator
1641 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1642 * @error: return location for a #GError, or %NULL
1644 * Authenticates @source, using @auth to handle the authentication
1645 * attempts. The operation loops until authentication is successful or
1646 * the user aborts further authentication attempts. If an error occurs,
1647 * the function will set @error and return %FALSE.
1649 * Note that @source need not have a #GDBusObject, which means this
1650 * function can test authentication on a scratch #ESource.
1652 * Only backend implementations and data source editors should call this
1653 * function. The intent is for basic client applications to not have to
1654 * deal with authentication at all.
1656 * Returns: %TRUE on success, %FALSE on failure
1661 e_source_registry_authenticate_sync (ESourceRegistry *registry,
1663 ESourceAuthenticator *auth,
1664 GCancellable *cancellable,
1667 AuthContext *auth_context;
1668 GMainContext *main_context;
1669 EDBusAuthenticator *dbus_auth;
1670 gchar *encryption_key;
1671 gchar *object_path = NULL;
1674 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
1675 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1676 g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth), FALSE);
1678 /* This extracts authentication prompt details for the ESource
1679 * before initiating an authentication session with the server,
1680 * so split it out of the main algorithm for clarity's sake. */
1681 success = source_registry_call_authenticate_for_source (
1682 registry, auth, source, &object_path, cancellable, error);
1685 g_warn_if_fail (object_path == NULL);
1689 g_return_val_if_fail (object_path != NULL, FALSE);
1691 main_context = g_main_context_new ();
1692 g_main_context_push_thread_default (main_context);
1694 dbus_auth = e_dbus_authenticator_proxy_new_for_bus_sync (
1696 G_DBUS_PROXY_FLAGS_NONE,
1697 SOURCES_DBUS_SERVICE_NAME,
1698 object_path, cancellable, error);
1700 g_free (object_path);
1702 if (dbus_auth == NULL) {
1707 auth_context = g_slice_new0 (AuthContext);
1708 auth_context->auth = g_object_ref (auth);
1709 auth_context->dbus_auth = dbus_auth; /* takes ownership */
1710 auth_context->main_loop = g_main_loop_new (main_context, FALSE);
1711 auth_context->error = error;
1713 /* This just needs to be something other than
1714 * E_SOURCE_AUTHENTICATION_ERROR so we don't trip
1715 * up source_registry_authenticate_dismissed_cb(). */
1716 auth_context->auth_result = E_SOURCE_AUTHENTICATION_REJECTED;
1718 if (G_IS_CANCELLABLE (cancellable))
1719 auth_context->cancellable = g_object_ref (cancellable);
1721 auth_context->secret_exchange =
1722 gcr_secret_exchange_new (GCR_SECRET_EXCHANGE_PROTOCOL_1);
1725 dbus_auth, "authenticate",
1726 G_CALLBACK (source_registry_authenticate_authenticate_cb),
1730 dbus_auth, "dismissed",
1731 G_CALLBACK (source_registry_authenticate_dismissed_cb),
1734 encryption_key = gcr_secret_exchange_begin (
1735 auth_context->secret_exchange);
1737 /* Signal the D-Bus server that we're ready to begin the
1738 * authentication session. This must happen AFTER we've
1739 * connected to the response signal since the server may
1740 * already have a response ready and waiting for us. */
1741 success = e_dbus_authenticator_call_ready_sync (
1742 dbus_auth, encryption_key, cancellable, error);
1744 g_free (encryption_key);
1747 g_main_loop_run (auth_context->main_loop);
1748 success = auth_context->success;
1751 auth_context_free (auth_context);
1754 g_main_context_pop_thread_default (main_context);
1755 g_main_context_unref (main_context);
1761 * e_source_registry_authenticate:
1762 * @registry: an #ESourceRegistry
1763 * @source: an #ESource
1764 * @auth: an #ESourceAuthenticator
1765 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1766 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1768 * @user_data: (closure): data to pass to the callback function
1770 * Asynchronously authenticates @source, using @auth to handle the
1771 * authentication attempts. The operation loops until authentication
1772 * is successful or the user aborts further authentication attempts.
1774 * Note that @source need not have a #GDBusObject, which means this
1775 * function can test authentication on a scratch #ESource.
1777 * When the operation is finished, @callback will be called. You can then
1778 * call e_source_registry_authenticate_finish() to get the result of the
1781 * Only backend implementations and data source editors should call this
1782 * function. The intent is for basic client applications to not have to
1783 * deal with authentication at all.
1788 e_source_registry_authenticate (ESourceRegistry *registry,
1790 ESourceAuthenticator *auth,
1791 GCancellable *cancellable,
1792 GAsyncReadyCallback callback,
1795 GSimpleAsyncResult *simple;
1796 AsyncContext *async_context;
1798 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
1799 g_return_if_fail (E_IS_SOURCE (source));
1800 g_return_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth));
1802 async_context = g_slice_new0 (AsyncContext);
1803 async_context->source = g_object_ref (source);
1804 async_context->auth = g_object_ref (auth);
1806 simple = g_simple_async_result_new (
1807 G_OBJECT (registry), callback, user_data,
1808 e_source_registry_authenticate);
1810 g_simple_async_result_set_check_cancellable (simple, cancellable);
1812 g_simple_async_result_set_op_res_gpointer (
1813 simple, async_context, (GDestroyNotify) async_context_free);
1815 g_simple_async_result_run_in_thread (
1816 simple, source_registry_authenticate_thread,
1817 G_PRIORITY_DEFAULT, cancellable);
1819 g_object_unref (simple);
1823 * e_source_registry_authenticate_finish:
1824 * @registry: an #ESourceRegistry
1825 * @result: a #GAsyncResult
1826 * @error: return location for a #GError, or %NULL
1828 * Finishes the operation started with e_source_registry_authenticate().
1829 * If an error occurred, the function will set @error and return %FALSE.
1831 * Returns: %TRUE on success, %FALSE on failure
1836 e_source_registry_authenticate_finish (ESourceRegistry *registry,
1837 GAsyncResult *result,
1840 GSimpleAsyncResult *simple;
1842 g_return_val_if_fail (
1843 g_simple_async_result_is_valid (
1844 result, G_OBJECT (registry),
1845 e_source_registry_authenticate), FALSE);
1847 simple = G_SIMPLE_ASYNC_RESULT (result);
1849 /* Assume success unless a GError is set. */
1850 return !g_simple_async_result_propagate_error (simple, error);
1853 /* Helper for e_source_registry_commit_source() */
1855 source_registry_commit_source_thread (GSimpleAsyncResult *simple,
1857 GCancellable *cancellable)
1859 AsyncContext *async_context;
1860 GError *error = NULL;
1862 async_context = g_simple_async_result_get_op_res_gpointer (simple);
1864 e_source_registry_commit_source_sync (
1865 E_SOURCE_REGISTRY (object),
1866 async_context->source,
1867 cancellable, &error);
1870 g_simple_async_result_take_error (simple, error);
1874 * e_source_registry_commit_source_sync:
1875 * @registry: an #ESourceRegistry
1876 * @source: an #ESource with changes to commit
1877 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1878 * @error: return location for #GError, or %NULL
1880 * This is a convenience function intended for use with graphical
1881 * #ESource editors. Call this function when the user is finished
1882 * making changes to @source.
1884 * If @source has a #GDBusObject, its contents are submitted to the D-Bus
1885 * service through e_source_write_sync().
1887 * If @source does NOT have a #GDBusObject (implying it's a scratch
1888 * #ESource), its contents are submitted to the D-Bus service through
1889 * either e_source_remote_create_sync() if @source is to be a collection
1890 * member, or e_source_registry_create_sources_sync() if @source to be an
1891 * independent data source.
1893 * If an error occurs, the function will set @error and return %FALSE.
1895 * Returns: %TRUE on success, %FALSE on failure
1900 e_source_registry_commit_source_sync (ESourceRegistry *registry,
1902 GCancellable *cancellable,
1905 GDBusObject *dbus_object;
1906 ESource *collection_source;
1907 gboolean collection_member;
1910 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
1911 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1913 dbus_object = e_source_ref_dbus_object (source);
1915 collection_source = e_source_registry_find_extension (
1916 registry, source, E_SOURCE_EXTENSION_COLLECTION);
1919 (collection_source != NULL) &&
1920 (collection_source != source);
1922 if (dbus_object != NULL) {
1923 success = e_source_write_sync (source, cancellable, error);
1924 g_object_unref (dbus_object);
1926 } else if (collection_member) {
1927 success = e_source_remote_create_sync (
1928 collection_source, source, cancellable, error);
1931 GList *list = g_list_prepend (NULL, source);
1932 success = e_source_registry_create_sources_sync (
1933 registry, list, cancellable, error);
1937 if (collection_source != NULL)
1938 g_object_unref (collection_source);
1944 * e_source_registry_commit_source:
1945 * @registry: an #ESourceRegistry
1946 * @source: an #ESource with changes to commit
1947 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1948 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1950 * @user_data: (closure): data to pass to the callback function
1952 * See e_source_registry_commit_source_sync() for details.
1954 * When the operation is finished, @callback will be called. You can then
1955 * call e_source_registry_commit_source_finish() to get the result of the
1961 e_source_registry_commit_source (ESourceRegistry *registry,
1963 GCancellable *cancellable,
1964 GAsyncReadyCallback callback,
1967 GSimpleAsyncResult *simple;
1968 AsyncContext *async_context;
1970 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
1971 g_return_if_fail (E_IS_SOURCE (source));
1973 async_context = g_slice_new0 (AsyncContext);
1974 async_context->source = g_object_ref (source);
1976 simple = g_simple_async_result_new (
1977 G_OBJECT (registry), callback, user_data,
1978 e_source_registry_commit_source);
1980 g_simple_async_result_set_check_cancellable (simple, cancellable);
1982 g_simple_async_result_set_op_res_gpointer (
1983 simple, async_context, (GDestroyNotify) async_context_free);
1985 g_simple_async_result_run_in_thread (
1986 simple, source_registry_commit_source_thread,
1987 G_PRIORITY_DEFAULT, cancellable);
1989 g_object_unref (simple);
1993 * e_source_registry_commit_source_finish:
1994 * @registry: an #ESourceRegistry
1995 * @result: a #GAsyncResult
1996 * @error: return location for a #GError, or %NULL
1998 * Finishes the operation started with e_source_registry_commit_source().
2000 * If an error occurred, the function will set @error and return %FALSE.
2002 * Returns: %TRUE on success, %FALSE on failure
2007 e_source_registry_commit_source_finish (ESourceRegistry *registry,
2008 GAsyncResult *result,
2011 GSimpleAsyncResult *simple;
2013 g_return_val_if_fail (
2014 g_simple_async_result_is_valid (
2015 result, G_OBJECT (registry),
2016 e_source_registry_commit_source), FALSE);
2018 simple = G_SIMPLE_ASYNC_RESULT (result);
2020 /* Assume success unless a GError is set. */
2021 return !g_simple_async_result_propagate_error (simple, error);
2024 /* Helper for e_source_registry_create_sources() */
2026 source_registry_create_sources_thread (GSimpleAsyncResult *simple,
2028 GCancellable *cancellable)
2030 AsyncContext *async_context;
2031 GError *error = NULL;
2033 async_context = g_simple_async_result_get_op_res_gpointer (simple);
2035 e_source_registry_create_sources_sync (
2036 E_SOURCE_REGISTRY (object),
2037 async_context->list_of_sources,
2038 cancellable, &error);
2041 g_simple_async_result_take_error (simple, error);
2044 /* Helper for e_source_registry_create_sources_sync() */
2046 source_registry_create_sources_main_loop_quit_cb (gpointer user_data)
2048 GMainLoop *main_loop = user_data;
2050 g_main_loop_quit (main_loop);
2055 /* Helper for e_source_registry_create_sources_sync() */
2057 source_registry_create_sources_object_added_cb (GDBusObjectManager *object_manager,
2058 GDBusObject *dbus_object,
2059 CreateContext *create_context)
2061 EDBusObject *e_dbus_object;
2062 EDBusSource *e_dbus_source;
2065 e_dbus_object = E_DBUS_OBJECT (dbus_object);
2066 e_dbus_source = e_dbus_object_get_source (e_dbus_object);
2067 uid = e_dbus_source_get_uid (e_dbus_source);
2069 g_hash_table_remove (create_context->pending_uids, uid);
2071 /* The hash table will be empty when all of the expected
2072 * GDBusObjects have been added to the GDBusObjectManager. */
2073 if (g_hash_table_size (create_context->pending_uids) == 0) {
2074 GSource *idle_source;
2076 idle_source = g_idle_source_new ();
2077 g_source_set_callback (
2079 source_registry_create_sources_main_loop_quit_cb,
2080 g_main_loop_ref (create_context->main_loop),
2081 (GDestroyNotify) g_main_loop_unref);
2082 g_source_attach (idle_source, create_context->main_context);
2083 g_source_unref (idle_source);
2088 * e_source_registry_create_sources_sync:
2089 * @registry: an #ESourceRegistry
2090 * @list_of_sources: (element-type ESource): a list of #ESource instances with
2092 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
2093 * @error: return location for a #GError, or %NULL
2095 * Requests the D-Bus service create new key files for each #ESource in
2096 * @list_of_sources. Each list element must be a scratch #ESource with
2099 * If an error occurs, the function will set @error and return %FALSE.
2101 * Returns: %TRUE on success, %FALSE on failure
2106 e_source_registry_create_sources_sync (ESourceRegistry *registry,
2107 GList *list_of_sources,
2108 GCancellable *cancellable,
2111 CreateContext *create_context;
2112 GVariantBuilder builder;
2115 gulong object_added_id;
2118 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
2120 /* Verify the list elements are all ESources. */
2121 for (link = list_of_sources; link != NULL; link = g_list_next (link))
2122 g_return_val_if_fail (E_IS_SOURCE (link->data), FALSE);
2124 create_context = create_context_new ();
2125 g_main_context_push_thread_default (create_context->main_context);
2127 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
2129 for (link = list_of_sources; link != NULL; link = g_list_next (link)) {
2134 source = E_SOURCE (link->data);
2135 uid = e_source_dup_uid (source);
2137 /* Takes ownership of the UID string. */
2138 g_hash_table_add (create_context->pending_uids, uid);
2140 source_data = e_source_to_string (source, NULL);
2141 g_variant_builder_add (&builder, "{ss}", uid, source_data);
2142 g_free (source_data);
2145 variant = g_variant_builder_end (&builder);
2147 /* Use G_CONNECT_AFTER so source_registry_object_added_cb()
2148 * runs first and actually adds the ESource to the internal
2149 * hash table before we go quitting our main loop. */
2150 object_added_id = g_signal_connect_after (
2151 registry->priv->dbus_object_manager, "object-added",
2152 G_CALLBACK (source_registry_create_sources_object_added_cb),
2155 /* This function sinks the floating GVariant reference. */
2156 success = e_dbus_source_manager_call_create_sources_sync (
2157 registry->priv->dbus_source_manager,
2158 variant, cancellable, error);
2160 g_variant_builder_clear (&builder);
2162 /* Wait for an "object-added" signal for each created ESource.
2163 * But also set a short timeout to avoid getting stuck here in
2164 * case the registry service adds sources to its orphan table,
2165 * which prevents them from being exported over D-Bus. */
2167 GSource *timeout_source;
2169 timeout_source = g_timeout_source_new_seconds (2);
2170 g_source_set_callback (
2172 source_registry_create_sources_main_loop_quit_cb,
2173 g_main_loop_ref (create_context->main_loop),
2174 (GDestroyNotify) g_main_loop_unref);
2175 g_source_attach (timeout_source, create_context->main_context);
2176 g_source_unref (timeout_source);
2178 g_main_loop_run (create_context->main_loop);
2181 g_signal_handler_disconnect (
2182 registry->priv->dbus_object_manager, object_added_id);
2184 g_main_context_pop_thread_default (create_context->main_context);
2185 create_context_free (create_context);
2191 * e_source_registry_create_sources:
2192 * @registry: an #ESourceRegistry
2193 * @list_of_sources: (element-type ESource): a list of #ESource instances with
2195 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
2196 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
2198 * @user_data: (closure): data to pass to the callback function
2200 * Asynchronously requests the D-Bus service create new key files for each
2201 * #ESource in @list_of_sources. Each list element must be a scratch
2202 * #ESource with no #GDBusObject.
2204 * When the operation is finished, @callback will be called. You can then
2205 * call e_source_registry_create_sources_finish() to get the result of the
2211 e_source_registry_create_sources (ESourceRegistry *registry,
2212 GList *list_of_sources,
2213 GCancellable *cancellable,
2214 GAsyncReadyCallback callback,
2217 GSimpleAsyncResult *simple;
2218 AsyncContext *async_context;
2221 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2223 /* Verify the list elements are all ESources. */
2224 for (link = list_of_sources; link != NULL; link = g_list_next (link))
2225 g_return_if_fail (E_IS_SOURCE (link->data));
2227 async_context = g_slice_new0 (AsyncContext);
2228 async_context->list_of_sources = g_list_copy (list_of_sources);
2231 async_context->list_of_sources,
2232 (GFunc) g_object_ref, NULL);
2234 simple = g_simple_async_result_new (
2235 G_OBJECT (registry), callback, user_data,
2236 e_source_registry_create_sources);
2238 g_simple_async_result_set_check_cancellable (simple, cancellable);
2240 g_simple_async_result_set_op_res_gpointer (
2241 simple, async_context, (GDestroyNotify) async_context_free);
2243 g_simple_async_result_run_in_thread (
2244 simple, source_registry_create_sources_thread,
2245 G_PRIORITY_DEFAULT, cancellable);
2247 g_object_unref (simple);
2251 * e_source_registry_create_sources_finish:
2252 * @registry: an #ESourceRegistry
2253 * @result: a #GAsyncResult
2254 * @error: return location for a #GError, or %NULL
2256 * Finishes the operation started with e_source_registry_create_sources().
2258 * If an error occurred, the function will set @error and return %FALSE.
2260 * Returns: %TRUE on success, %FALSE on failure
2265 e_source_registry_create_sources_finish (ESourceRegistry *registry,
2266 GAsyncResult *result,
2269 GSimpleAsyncResult *simple;
2271 g_return_val_if_fail (
2272 g_simple_async_result_is_valid (
2273 result, G_OBJECT (registry),
2274 e_source_registry_create_sources), FALSE);
2276 simple = G_SIMPLE_ASYNC_RESULT (result);
2278 /* Assume success unless a GError is set. */
2279 return !g_simple_async_result_propagate_error (simple, error);
2283 * e_source_registry_ref_source:
2284 * @registry: an #ESourceRegistry
2285 * @uid: a unique identifier string
2287 * Looks up an #ESource in @registry by its unique identifier string.
2289 * The returned #ESource is referenced for thread-safety and must be
2290 * unreferenced with g_object_unref() when finished with it.
2292 * Returns: (transfer full): an #ESource, or %NULL if no match was found
2297 e_source_registry_ref_source (ESourceRegistry *registry,
2300 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2301 g_return_val_if_fail (uid != NULL, NULL);
2303 return source_registry_sources_lookup (registry, uid);
2307 * e_source_registry_list_sources:
2308 * @registry: an #ESourceRegistry
2309 * @extension_name: (allow-none): an extension name, or %NULL
2311 * Returns a list of registered sources, sorted by display name. If
2312 * @extension_name is given, restrict the list to sources having that
2315 * The sources returned in the list are referenced for thread-safety.
2316 * They must each be unreferenced with g_object_unref() when finished
2317 * when them. Free the returned list itself with g_list_free().
2319 * An easy way to free the list properly in one step is as follows:
2322 * g_list_free_full (list, g_object_unref);
2325 * Returns: (element-type ESource) (transfer full): a sorted list of sources
2330 e_source_registry_list_sources (ESourceRegistry *registry,
2331 const gchar *extension_name)
2334 GQueue trash = G_QUEUE_INIT;
2336 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2338 list = g_list_sort (
2339 source_registry_sources_get_values (registry),
2340 (GCompareFunc) e_source_compare_by_display_name);
2342 if (extension_name == NULL)
2345 for (link = list; link != NULL; link = g_list_next (link)) {
2346 ESource *source = E_SOURCE (link->data);
2348 if (!e_source_has_extension (source, extension_name)) {
2349 g_queue_push_tail (&trash, link);
2350 g_object_unref (source);
2354 /* We do want pop_head() here, not pop_head_link(). */
2355 while ((link = g_queue_pop_head (&trash)) != NULL)
2356 list = g_list_delete_link (list, link);
2362 * e_source_registry_check_enabled:
2363 * @registry: an #ESourceRegistry
2364 * @source: an #ESource
2366 * Determines whether @source is "effectively" enabled by examining its
2367 * own #ESource:enabled property as well as those of its ancestors in the
2368 * #ESource hierarchy. If all examined #ESource:enabled properties are
2369 * %TRUE, then the function returns %TRUE. If any are %FALSE, then the
2370 * function returns %FALSE.
2372 * Use this function instead of e_source_get_enabled() to determine
2373 * things like whether to display an #ESource in a user interface or
2374 * whether to act on the data set described by the #ESource.
2376 * Returns: whether @source is "effectively" enabled
2381 e_source_registry_check_enabled (ESourceRegistry *registry,
2387 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
2388 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
2390 enabled = e_source_get_enabled (source);
2391 parent_uid = e_source_dup_parent (source);
2393 while (enabled && parent_uid != NULL) {
2396 parent = e_source_registry_ref_source (registry, parent_uid);
2398 g_free (parent_uid);
2401 if (parent != NULL) {
2402 enabled = e_source_get_enabled (parent);
2403 parent_uid = e_source_dup_parent (parent);
2404 g_object_unref (parent);
2408 g_free (parent_uid);
2414 * e_source_registry_find_extension:
2415 * @registry: an #ESourceRegistry
2416 * @source: an #ESource
2417 * @extension_name: the extension name to find
2419 * Examines @source and its ancestors and returns the "deepest" #ESource
2420 * having an #ESourceExtension with the given @extension_name. If neither
2421 * @source nor any of its ancestors have such an extension, the function
2424 * This function is useful in cases when an #ESourceExtension is meant to
2425 * apply to both the #ESource it belongs to and the #ESource's descendants.
2427 * A common example is the #ESourceCollection extension, where descendants
2428 * of an #ESource having an #ESourceCollection extension are implied to be
2429 * members of that collection. In that example, this function can be used
2430 * to test whether @source is a member of a collection.
2432 * The returned #ESource is referenced for thread-safety and must be
2433 * unreferenced with g_object_unref() when finished with it.
2435 * Note the function returns the #ESource containing the #ESourceExtension
2436 * instead of the #ESourceExtension itself because extension instances are
2437 * not to be referenced directly (see e_source_get_extension()).
2439 * Returns: (transfer full): an #ESource, or %NULL if no match was found
2444 e_source_registry_find_extension (ESourceRegistry *registry,
2446 const gchar *extension_name)
2448 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2449 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2450 g_return_val_if_fail (extension_name != NULL, NULL);
2452 g_object_ref (source);
2454 while (!e_source_has_extension (source, extension_name)) {
2457 uid = e_source_dup_parent (source);
2459 g_object_unref (source);
2463 source = e_source_registry_ref_source (registry, uid);
2474 /* Helper for e_source_registry_build_display_tree() */
2476 source_registry_compare_nodes (GNode *node_a,
2479 ESource *source_a = E_SOURCE (node_a->data);
2480 ESource *source_b = E_SOURCE (node_b->data);
2481 const gchar *uid_a, *uid_b;
2483 uid_a = e_source_get_uid (source_a);
2484 uid_b = e_source_get_uid (source_b);
2486 /* Sanity check, with runtime warnings. */
2487 if (uid_a == NULL) {
2488 g_warn_if_reached ();
2491 if (uid_b == NULL) {
2492 g_warn_if_reached ();
2496 /* The built-in "local-stub" source comes first at depth 1. */
2498 if (g_strcmp0 (uid_a, "local-stub") == 0)
2501 if (g_strcmp0 (uid_b, "local-stub") == 0)
2504 /* The built-in "system-*" sources come first at depth 2. */
2506 if (g_str_has_prefix (uid_a, "system-"))
2509 if (g_str_has_prefix (uid_b, "system-"))
2512 return e_source_compare_by_display_name (source_a, source_b);
2515 /* Helper for e_source_registry_build_display_tree() */
2517 source_registry_prune_nodes (GNode *node,
2518 const gchar *extension_name)
2520 GQueue queue = G_QUEUE_INIT;
2523 /* Unlink all the child nodes and place them in a queue. */
2524 while ((child_node = g_node_first_child (node)) != NULL) {
2525 g_node_unlink (child_node);
2526 g_queue_push_tail (&queue, child_node);
2529 /* Sort the queue by source name. */
2531 &queue, (GCompareDataFunc)
2532 source_registry_compare_nodes, NULL);
2534 /* Pop nodes off the head of the queue until the queue is empty.
2535 * If the node has either its own children or the given extension
2536 * name, put it back under the parent node (preserving the sorted
2537 * order). Otherwise delete the node and its descendants. */
2538 while ((child_node = g_queue_pop_head (&queue)) != NULL) {
2539 ESource *child = E_SOURCE (child_node->data);
2540 gboolean append_child_node = FALSE;
2542 if (extension_name == NULL)
2543 append_child_node = e_source_get_enabled (child);
2545 else if (e_source_has_extension (child, extension_name))
2546 append_child_node = e_source_get_enabled (child);
2548 else if (g_node_first_child (child_node) != NULL)
2549 append_child_node = e_source_get_enabled (child);
2551 if (append_child_node)
2552 g_node_append (node, child_node);
2554 e_source_registry_free_display_tree (child_node);
2561 * e_source_registry_build_display_tree:
2562 * @registry: an #ESourceRegistry
2563 * @extension_name: (allow-none): an extension name, or %NULL
2565 * Returns a single #GNode tree of registered sources that can be used to
2566 * populate a #GtkTreeModel. (The root #GNode is just an empty placeholder.)
2568 * Similar to e_source_registry_list_sources(), an @extension_name can be
2569 * given to restrict the tree to sources having that extension name. Parents
2570 * of matched sources are included in the tree regardless of whether they have
2571 * an extension named @extension_name.
2573 * Disabled leaf nodes are automatically excluded from the #GNode tree.
2575 * The sources returned in the tree are referenced for thread-safety.
2576 * They must each be unreferenced with g_object_unref() when finished
2577 * with them. Free the returned tree itself with g_node_destroy().
2578 * For convenience, e_source_registry_free_display_tree() does all
2581 * Returns: (element-type ESource) (transfer full): a tree of sources,
2582 * arranged for display
2587 e_source_registry_build_display_tree (ESourceRegistry *registry,
2588 const gchar *extension_name)
2592 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2594 /* Assemble all data sources into a tree. */
2595 root = source_registry_sources_build_tree (registry);
2597 /* Prune unwanted nodes from the copied source trees.
2598 * This must be done in "post" order (children first)
2599 * since it reorders and deletes child nodes. */
2601 root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
2602 (GNodeTraverseFunc) source_registry_prune_nodes,
2603 (gpointer) extension_name);
2608 /* Helper for e_source_registry_free_display_tree() */
2610 source_registry_unref_nodes (GNode *node)
2612 while (node != NULL) {
2613 if (node->children != NULL)
2614 source_registry_unref_nodes (node->children);
2615 if (node->data != NULL)
2616 g_object_unref (node->data);
2622 * e_source_registry_free_display_tree:
2623 * @display_tree: a tree of sources, arranged for display
2625 * Convenience function to free a #GNode tree of registered
2626 * sources created by e_source_registry_build_display_tree().
2631 e_source_registry_free_display_tree (GNode *display_tree)
2633 g_return_if_fail (display_tree != NULL);
2635 /* XXX This would be easier if GLib had something like
2636 * g_node_destroy_full() which took a GDestroyNotify.
2637 * Then the tree would not have to be traversed twice. */
2639 source_registry_unref_nodes (display_tree);
2640 g_node_destroy (display_tree);
2643 /* Helper for e_source_registry_debug_dump() */
2645 source_registry_debug_dump_cb (GNode *node)
2649 /* Root node is an empty placeholder. */
2650 if (G_NODE_IS_ROOT (node))
2653 depth = g_node_depth (node);
2654 for (ii = 2; ii < depth; ii++)
2657 if (E_IS_SOURCE (node->data)) {
2658 ESource *source = E_SOURCE (node->data);
2659 g_print ("\"%s\" ", e_source_get_display_name (source));
2660 g_print ("(%s)", e_source_get_uid (source));
2669 * e_source_registry_debug_dump:
2670 * @registry: an #ESourceRegistry
2671 * @extension_name: (allow-none): an extension name, or %NULL
2673 * Handy debugging function that uses e_source_registry_build_display_tree()
2674 * to print a tree of registered sources to standard output.
2679 e_source_registry_debug_dump (ESourceRegistry *registry,
2680 const gchar *extension_name)
2684 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2686 root = e_source_registry_build_display_tree (registry, extension_name);
2689 root, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
2690 (GNodeTraverseFunc) source_registry_debug_dump_cb, NULL);
2692 e_source_registry_free_display_tree (root);
2696 * e_source_registry_ref_builtin_address_book:
2697 * @registry: an #ESourceRegistry
2699 * Returns the built-in address book #ESource.
2701 * This #ESource is always present and makes for a safe fallback.
2703 * The returned #ESource is referenced for thread-safety and must be
2704 * unreferenced with g_object_unref() when finished with it.
2706 * Returns: (transfer full): the built-in address book #ESource
2711 e_source_registry_ref_builtin_address_book (ESourceRegistry *registry)
2716 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2718 uid = E_SOURCE_BUILTIN_ADDRESS_BOOK_UID;
2719 source = e_source_registry_ref_source (registry, uid);
2720 g_return_val_if_fail (source != NULL, NULL);
2726 * e_source_registry_ref_default_address_book:
2727 * @registry: an #ESourceRegistry
2729 * Returns the #ESource most recently passed to
2730 * e_source_registry_set_default_address_book() either in this session
2731 * or a previous session, or else falls back to the built-in address book.
2733 * The returned #ESource is referenced for thread-safety and must be
2734 * unreferenced with g_object_unref() when finished with it.
2736 * Returns: (transfer full): the default address book #ESource
2741 e_source_registry_ref_default_address_book (ESourceRegistry *registry)
2747 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2749 key = E_SETTINGS_DEFAULT_ADDRESS_BOOK_KEY;
2750 uid = g_settings_get_string (registry->priv->settings, key);
2751 source = e_source_registry_ref_source (registry, uid);
2754 /* The built-in source is always present. */
2756 source = e_source_registry_ref_builtin_address_book (registry);
2758 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2764 * e_source_registry_set_default_address_book:
2765 * @registry: an #ESourceRegistry
2766 * @default_source: (allow-none): an address book #ESource, or %NULL
2768 * Sets @default_source as the default address book. If @default_source
2769 * is %NULL, the default address book is reset to the built-in address book.
2770 * This setting will persist across sessions until changed.
2775 e_source_registry_set_default_address_book (ESourceRegistry *registry,
2776 ESource *default_source)
2781 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2783 if (default_source != NULL) {
2784 g_return_if_fail (E_IS_SOURCE (default_source));
2785 uid = e_source_get_uid (default_source);
2787 uid = E_SOURCE_BUILTIN_ADDRESS_BOOK_UID;
2790 key = E_SETTINGS_DEFAULT_ADDRESS_BOOK_KEY;
2791 g_settings_set_string (registry->priv->settings, key, uid);
2793 /* The GSettings::changed signal will trigger a "notify" signal
2794 * from the registry, so no need to call g_object_notify() here. */
2798 * e_source_registry_ref_builtin_calendar:
2799 * @registry: an #ESourceRegistry
2801 * Returns the built-in calendar #ESource.
2803 * This #ESource is always present and makes for a safe fallback.
2805 * The returned #ESource is referenced for thread-safety and must be
2806 * unreferenced with g_object_unref() when finished with it.
2808 * Returns: (transfer full): the built-in calendar #ESource
2813 e_source_registry_ref_builtin_calendar (ESourceRegistry *registry)
2818 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2820 uid = E_SOURCE_BUILTIN_CALENDAR_UID;
2821 source = e_source_registry_ref_source (registry, uid);
2822 g_return_val_if_fail (source != NULL, NULL);
2828 * e_source_registry_ref_default_calendar:
2829 * @registry: an #ESourceRegistry
2831 * Returns the #ESource most recently passed to
2832 * e_source_registry_set_default_calendar() either in this session
2833 * or a previous session, or else falls back to the built-in calendar.
2835 * The returned #ESource is referenced for thread-safety and must be
2836 * unreferenced with g_object_unref() when finished with it.
2838 * Returns: (transfer full): the default calendar #ESource
2843 e_source_registry_ref_default_calendar (ESourceRegistry *registry)
2849 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2851 key = E_SETTINGS_DEFAULT_CALENDAR_KEY;
2852 uid = g_settings_get_string (registry->priv->settings, key);
2853 source = e_source_registry_ref_source (registry, uid);
2856 /* The built-in source is always present. */
2858 source = e_source_registry_ref_builtin_calendar (registry);
2860 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2866 * e_source_registry_set_default_calendar:
2867 * @registry: an #ESourceRegistry
2868 * @default_source: (allow-none): a calendar #ESource, or %NULL
2870 * Sets @default_source as the default calendar. If @default_source
2871 * is %NULL, the default calendar is reset to the built-in calendar.
2872 * This setting will persist across sessions until changed.
2877 e_source_registry_set_default_calendar (ESourceRegistry *registry,
2878 ESource *default_source)
2883 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2885 if (default_source != NULL) {
2886 g_return_if_fail (E_IS_SOURCE (default_source));
2887 uid = e_source_get_uid (default_source);
2889 uid = E_SOURCE_BUILTIN_CALENDAR_UID;
2892 key = E_SETTINGS_DEFAULT_CALENDAR_KEY;
2893 g_settings_set_string (registry->priv->settings, key, uid);
2895 /* The GSettings::changed signal will trigger a "notify" signal
2896 * from the registry, so no need to call g_object_notify() here. */
2900 * e_source_registry_ref_builtin_mail_account:
2901 * @registry: an #ESourceRegistry
2903 * Returns the built-in mail account #ESource.
2905 * This #ESource is always present and makes for a safe fallback.
2907 * The returned #ESource is referenced for thread-safety and must be
2908 * unreferenced with g_object_unref() when finished with it.
2910 * Returns: (transfer full): the built-in mail account #ESource
2915 e_source_registry_ref_builtin_mail_account (ESourceRegistry *registry)
2920 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2922 uid = E_SOURCE_BUILTIN_MAIL_ACCOUNT_UID;
2923 source = e_source_registry_ref_source (registry, uid);
2924 g_return_val_if_fail (source != NULL, NULL);
2930 * e_source_registry_ref_default_mail_account:
2931 * @registry: an #ESourceRegistry
2933 * Returns the #ESource most recently passed to
2934 * e_source_registry_set_default_mail_account() either in this session
2935 * or a previous session, or else falls back to the built-in mail account.
2937 * The returned #ESource is referenced for thread-safety and must be
2938 * unreferenced with g_object_unref() when finished with it.
2940 * Returns: (transfer full): the default mail account #ESource
2945 e_source_registry_ref_default_mail_account (ESourceRegistry *registry)
2951 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2953 key = E_SETTINGS_DEFAULT_MAIL_ACCOUNT_KEY;
2954 uid = g_settings_get_string (registry->priv->settings, key);
2955 source = e_source_registry_ref_source (registry, uid);
2958 /* The built-in source is always present. */
2960 source = e_source_registry_ref_builtin_mail_account (registry);
2962 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2968 * e_source_registry_set_default_mail_account:
2969 * @registry: an #ESourceRegistry
2970 * @default_source: (allow-none): a mail account #ESource, or %NULL
2972 * Sets @default_source as the default mail account. If @default_source
2973 * is %NULL, the default mail account is reset to the built-in mail account.
2974 * This setting will persist across sessions until changed.
2979 e_source_registry_set_default_mail_account (ESourceRegistry *registry,
2980 ESource *default_source)
2985 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2987 if (default_source != NULL) {
2988 g_return_if_fail (E_IS_SOURCE (default_source));
2989 uid = e_source_get_uid (default_source);
2991 uid = E_SOURCE_BUILTIN_MAIL_ACCOUNT_UID;
2994 key = E_SETTINGS_DEFAULT_MAIL_ACCOUNT_KEY;
2995 g_settings_set_string (registry->priv->settings, key, uid);
2997 /* The GSettings::changed signal will trigger a "notify" signal
2998 * from the registry, so no need to call g_object_notify() here. */
3001 /* Helper for e_source_registry_ref_default_mail_identity() */
3003 source_registry_ref_any_mail_identity (ESourceRegistry *registry)
3007 const gchar *extension_name;
3010 /* First fallback: Return the mail identity named
3011 * by the default mail account. */
3013 source = e_source_registry_ref_default_mail_account (registry);
3015 /* This should never be NULL, but just to be safe. */
3016 if (source != NULL) {
3017 ESourceMailAccount *extension;
3019 extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
3020 extension = e_source_get_extension (source, extension_name);
3021 uid = e_source_mail_account_dup_identity_uid (extension);
3023 g_object_unref (source);
3028 source = e_source_registry_ref_source (registry, uid);
3035 /* Second fallback: Pick any available mail identity,
3036 * preferring enabled identities. */
3038 extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
3039 list = e_source_registry_list_sources (registry, extension_name);
3041 for (link = list; link != NULL; link = g_list_next (link)) {
3042 ESource *candidate = E_SOURCE (link->data);
3044 if (e_source_registry_check_enabled (registry, candidate)) {
3045 source = g_object_ref (candidate);
3050 if (source == NULL && list != NULL)
3051 source = g_object_ref (list->data);
3053 g_list_free_full (list, (GDestroyNotify) g_object_unref);
3059 * e_source_registry_ref_default_mail_identity:
3060 * @registry: an #ESourceRegistry
3062 * Returns the #ESource most recently passed to
3063 * e_source_registry_set_default_mail_identity() either in this session
3064 * or a previous session, or else falls back to the mail identity named
3065 * by the default mail account. If even that fails it returns any mail
3066 * identity from @registry, or %NULL if there are none.
3068 * The returned #ESource is referenced for thread-safety and must be
3069 * unreferenced with g_object_unref() when finished with it.
3071 * Returns: (transfer full): the default mail identity #ESource, or %NULL
3076 e_source_registry_ref_default_mail_identity (ESourceRegistry *registry)
3082 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3084 key = E_SETTINGS_DEFAULT_MAIL_IDENTITY_KEY;
3085 uid = g_settings_get_string (registry->priv->settings, key);
3086 source = e_source_registry_ref_source (registry, uid);
3090 source = source_registry_ref_any_mail_identity (registry);
3096 * e_source_registry_set_default_mail_identity:
3097 * @registry: an #ESourceRegistry
3098 * @default_source: (allow-none): a mail identity #ESource, or %NULL
3100 * Sets @default_source as the default mail identity. If @default_source
3101 * is %NULL, the next request for the default mail identity will use the
3102 * fallbacks described in e_source_registry_get_default_mail_identity().
3107 e_source_registry_set_default_mail_identity (ESourceRegistry *registry,
3108 ESource *default_source)
3113 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3115 if (default_source != NULL) {
3116 g_return_if_fail (E_IS_SOURCE (default_source));
3117 uid = e_source_get_uid (default_source);
3119 uid = ""; /* no built-in mail identity */
3122 key = E_SETTINGS_DEFAULT_MAIL_IDENTITY_KEY;
3123 g_settings_set_string (registry->priv->settings, key, uid);
3125 /* The GSettings::changed signal will trigger a "notify" signal
3126 * from the registry, so no need to call g_object_notify() here. */
3130 * e_source_registry_ref_builtin_memo_list:
3131 * @registry: an #ESourceRegistry
3133 * Returns the built-in memo list #ESource.
3135 * This #ESource is always present and makes for a safe fallback.
3137 * The returned #ESource is referenced for thread-safety and must be
3138 * unreferenced with g_object_unref() when finished with it.
3140 * Returns: (transfer full): the built-in memo list #ESource
3145 e_source_registry_ref_builtin_memo_list (ESourceRegistry *registry)
3150 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3152 uid = E_SOURCE_BUILTIN_MEMO_LIST_UID;
3153 source = e_source_registry_ref_source (registry, uid);
3154 g_return_val_if_fail (source != NULL, NULL);
3160 * e_source_registry_ref_default_memo_list:
3161 * @registry: an #ESourceRegistry
3163 * Returns the #ESource most recently passed to
3164 * e_source_registry_set_default_memo_list() either in this session
3165 * or a previous session, or else falls back to the built-in memo list.
3167 * The returned #ESource is referenced for thread-safety and must be
3168 * unreferenced with g_object_unref() when finished with it.
3170 * Returns: (transfer full): the default memo list #ESource
3175 e_source_registry_ref_default_memo_list (ESourceRegistry *registry)
3181 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3183 key = E_SETTINGS_DEFAULT_MEMO_LIST_KEY;
3184 uid = g_settings_get_string (registry->priv->settings, key);
3185 source = e_source_registry_ref_source (registry, uid);
3188 /* The built-in source is always present. */
3190 source = e_source_registry_ref_builtin_memo_list (registry);
3192 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
3198 * e_source_registry_set_default_memo_list:
3199 * @registry: an #ESourceRegistry
3200 * @default_source: (allow-none): a memo list #ESource, or %NULL
3202 * Sets @default_source as the default memo list. If @default_source
3203 * is %NULL, the default memo list is reset to the built-in memo list.
3204 * This setting will persist across sessions until changed.
3209 e_source_registry_set_default_memo_list (ESourceRegistry *registry,
3210 ESource *default_source)
3215 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3217 if (default_source != NULL) {
3218 g_return_if_fail (E_IS_SOURCE (default_source));
3219 uid = e_source_get_uid (default_source);
3221 uid = E_SOURCE_BUILTIN_MEMO_LIST_UID;
3224 key = E_SETTINGS_DEFAULT_MEMO_LIST_KEY;
3225 g_settings_set_string (registry->priv->settings, key, uid);
3227 /* The GSettings::changed signal will trigger a "notify" signal
3228 * from the registry, so no need to call g_object_notify() here. */
3232 * e_source_registry_ref_builtin_task_list:
3233 * @registry: an #ESourceRegistry
3235 * Returns the built-in task list #ESource.
3237 * This #ESource is always present and makes for a safe fallback.
3239 * The returned #ESource is referenced for thread-safety and must be
3240 * unreferenced with g_object_unref() when finished with it.
3242 * Returns: (transfer full): the built-in task list #ESource
3247 e_source_registry_ref_builtin_task_list (ESourceRegistry *registry)
3252 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3254 uid = E_SOURCE_BUILTIN_TASK_LIST_UID;
3255 source = e_source_registry_ref_source (registry, uid);
3256 g_return_val_if_fail (source != NULL, NULL);
3262 * e_source_registry_ref_default_task_list:
3263 * @registry: an #ESourceRegistry
3265 * Returns the #ESource most recently passed to
3266 * e_source_registry_set_default_task_list() either in this session
3267 * or a previous session, or else falls back to the built-in task list.
3269 * The returned #ESource is referenced for thread-safety and must be
3270 * unreferenced with g_object_unref() when finished with it.
3272 * Returns: (transfer full): the default task list #ESource
3277 e_source_registry_ref_default_task_list (ESourceRegistry *registry)
3283 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3285 key = E_SETTINGS_DEFAULT_TASK_LIST_KEY;
3286 uid = g_settings_get_string (registry->priv->settings, key);
3287 source = e_source_registry_ref_source (registry, uid);
3290 /* The built-in source is always present. */
3292 source = e_source_registry_ref_builtin_task_list (registry);
3294 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
3300 * e_source_registry_set_default_task_list:
3301 * @registry: an #ESourceRegistry
3302 * @default_source: (allow-none): a task list #ESource, or %NULL
3304 * Sets @default_source as the default task list. If @default_source
3305 * is %NULL, the default task list is reset to the built-in task list.
3306 * This setting will persist across sessions until changed.
3311 e_source_registry_set_default_task_list (ESourceRegistry *registry,
3312 ESource *default_source)
3317 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3319 if (default_source != NULL) {
3320 g_return_if_fail (E_IS_SOURCE (default_source));
3321 uid = e_source_get_uid (default_source);
3323 uid = E_SOURCE_BUILTIN_TASK_LIST_UID;
3326 key = E_SETTINGS_DEFAULT_TASK_LIST_KEY;
3327 g_settings_set_string (registry->priv->settings, key, uid);
3329 /* The GSettings::changed signal will trigger a "notify" signal
3330 * from the registry, so no need to call g_object_notify() here. */
3334 * e_source_registry_ref_default_for_extension_name:
3335 * @registry: an #ESourceRegistry
3336 * @extension_name: an extension_name
3338 * This is a convenience function to return a default #ESource based on
3339 * @extension_name. This only works with a subset of extension names.
3341 * If @extension_name is #E_SOURCE_EXTENSION_ADDRESS_BOOK, the function
3342 * returns the current default address book, or else falls back to the
3343 * built-in address book.
3345 * If @extension_name is #E_SOURCE_EXTENSION_CALENDAR, the function returns
3346 * the current default calendar, or else falls back to the built-in calendar.
3348 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_ACCOUNT, the function
3349 * returns the current default mail account, or else falls back to the
3350 * built-in mail account.
3352 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_IDENTITY, the function
3353 * returns the current default mail identity, or else falls back to the
3354 * mail identity named by the current default mail account.
3356 * If @extension_name is #E_SOURCE_EXTENSION_MEMO_LIST, the function returns
3357 * the current default memo list, or else falls back to the built-in memo list.
3359 * If @extension_name is #E_SOURCE_EXTENSION_TASK_LIST, the function returns
3360 * the current default task list, or else falls back to the built-in task list.
3362 * For all other values of @extension_name, the function returns %NULL.
3364 * The returned #ESource is referenced for thread-safety and must be
3365 * unreferenced with g_object_unref() when finished with it.
3367 * Returns: (transfer full): the default #ESource based on @extension_name
3372 e_source_registry_ref_default_for_extension_name (ESourceRegistry *registry,
3373 const gchar *extension_name)
3375 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3376 g_return_val_if_fail (extension_name != NULL, NULL);
3378 if (strcmp (extension_name, E_SOURCE_EXTENSION_ADDRESS_BOOK) == 0)
3379 return e_source_registry_ref_default_address_book (registry);
3381 if (strcmp (extension_name, E_SOURCE_EXTENSION_CALENDAR) == 0)
3382 return e_source_registry_ref_default_calendar (registry);
3384 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_ACCOUNT) == 0)
3385 return e_source_registry_ref_default_mail_account (registry);
3387 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_IDENTITY) == 0)
3388 return e_source_registry_ref_default_mail_identity (registry);
3390 if (strcmp (extension_name, E_SOURCE_EXTENSION_MEMO_LIST) == 0)
3391 return e_source_registry_ref_default_memo_list (registry);
3393 if (strcmp (extension_name, E_SOURCE_EXTENSION_TASK_LIST) == 0)
3394 return e_source_registry_ref_default_task_list (registry);
3400 * e_source_registry_set_default_for_extension_name:
3401 * @registry: an #ESourceRegistry
3402 * @extension_name: an extension name
3403 * @default_source: (allow-none): an #ESource, or %NULL
3405 * This is a convenience function to set a default #ESource based on
3406 * @extension_name. This only works with a subset of extension names.
3408 * If @extension_name is #E_SOURCE_EXTENSION_ADDRESS_BOOK, the function
3409 * sets @default_source as the default address book. If @default_source
3410 * is %NULL, the default address book is reset to the built-in address book.
3412 * If @extension_name is #E_SOURCE_EXTENSION_CALENDAR, the function sets
3413 * @default_source as the default calendar. If @default_source is %NULL,
3414 * the default calendar is reset to the built-in calendar.
3416 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_ACCOUNT, the function
3417 * sets @default_source as the default mail account. If @default_source
3418 * is %NULL, the default mail account is reset to the built-in mail account.
3420 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_IDENTITY, the function
3421 * sets @default_source as the default mail identity. If @default_source
3422 * is %NULL, the next request for the default mail identity will return
3423 * the mail identity named by the default mail account.
3425 * If @extension_name is #E_SOURCE_EXTENSION_MEMO_LIST, the function sets
3426 * @default_source as the default memo list. If @default_source is %NULL,
3427 * the default memo list is reset to the built-in memo list.
3429 * If @extension_name is #E_SOURCE_EXTENSION_TASK_LIST, the function sets
3430 * @default_source as the default task list. If @default_source is %NULL,
3431 * the default task list is reset to the built-in task list.
3433 * For all other values of @extension_name, the function does nothing.
3438 e_source_registry_set_default_for_extension_name (ESourceRegistry *registry,
3439 const gchar *extension_name,
3440 ESource *default_source)
3442 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3443 g_return_if_fail (extension_name != NULL);
3445 if (strcmp (extension_name, E_SOURCE_EXTENSION_ADDRESS_BOOK) == 0)
3446 e_source_registry_set_default_address_book (
3447 registry, default_source);
3449 if (strcmp (extension_name, E_SOURCE_EXTENSION_CALENDAR) == 0)
3450 e_source_registry_set_default_calendar (
3451 registry, default_source);
3453 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_ACCOUNT) == 0)
3454 e_source_registry_set_default_mail_account (
3455 registry, default_source);
3457 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_IDENTITY) == 0)
3458 e_source_registry_set_default_mail_identity (
3459 registry, default_source);
3461 if (strcmp (extension_name, E_SOURCE_EXTENSION_MEMO_LIST) == 0)
3462 e_source_registry_set_default_memo_list (
3463 registry, default_source);
3465 if (strcmp (extension_name, E_SOURCE_EXTENSION_TASK_LIST) == 0)
3466 e_source_registry_set_default_task_list (
3467 registry, default_source);