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)
1081 /* Allow authentication prompts for all exported data sources
1082 * when a new EDBusSourceManagerProxy is created. The thought
1083 * being, if you cancel an authentication prompt you will not
1084 * be bothered again until you start (or restart) a new E-D-S
1085 * client app. Failure here is non-fatal, ignore errors. */
1086 e_dbus_source_manager_call_allow_auth_prompt_all_sync (
1087 registry->priv->dbus_source_manager, cancellable, NULL);
1093 e_source_registry_class_init (ESourceRegistryClass *class)
1095 GObjectClass *object_class;
1097 g_type_class_add_private (class, sizeof (ESourceRegistryPrivate));
1099 object_class = G_OBJECT_CLASS (class);
1100 object_class->set_property = source_registry_set_property;
1101 object_class->get_property = source_registry_get_property;
1102 object_class->dispose = source_registry_dispose;
1103 object_class->finalize = source_registry_finalize;
1105 /* The property names correspond to the key names in the
1106 * "org.gnome.Evolution.DefaultSources" GSettings schema. */
1109 * ESourceRegistry:default-address-book:
1111 * The default address book #ESource.
1113 g_object_class_install_property (
1115 PROP_DEFAULT_ADDRESS_BOOK,
1116 g_param_spec_object (
1117 "default-address-book",
1118 "Default Address Book",
1119 "The default address book ESource",
1122 G_PARAM_STATIC_STRINGS));
1125 * ESourceRegistry:default-calendar:
1127 * The default calendar #ESource.
1129 g_object_class_install_property (
1131 PROP_DEFAULT_CALENDAR,
1132 g_param_spec_object (
1135 "The default calendar ESource",
1138 G_PARAM_STATIC_STRINGS));
1141 * ESourceRegistry:default-mail-account:
1143 * The default mail account #ESource.
1145 g_object_class_install_property (
1147 PROP_DEFAULT_MAIL_ACCOUNT,
1148 g_param_spec_object (
1149 "default-mail-account",
1150 "Default Mail Account",
1151 "The default mail account ESource",
1154 G_PARAM_STATIC_STRINGS));
1157 * ESourceRegistry:default-mail-identity:
1159 * The default mail identity #ESource.
1161 g_object_class_install_property (
1163 PROP_DEFAULT_MAIL_IDENTITY,
1164 g_param_spec_object (
1165 "default-mail-identity",
1166 "Default Mail Identity",
1167 "The default mail identity ESource",
1170 G_PARAM_STATIC_STRINGS));
1173 * ESourceRegistry:default-memo-list:
1175 * The default memo list #ESource.
1177 g_object_class_install_property (
1179 PROP_DEFAULT_MEMO_LIST,
1180 g_param_spec_object (
1181 "default-memo-list",
1182 "Default Memo List",
1183 "The default memo list ESource",
1186 G_PARAM_STATIC_STRINGS));
1189 * ESourceRegistry:default-task-list:
1191 * The default task list #ESource.
1193 g_object_class_install_property (
1195 PROP_DEFAULT_TASK_LIST,
1196 g_param_spec_object (
1197 "default-task-list",
1198 "Default Task List",
1199 "The default task list ESource",
1202 G_PARAM_STATIC_STRINGS));
1205 * ESourceRegistry::source-added:
1206 * @registry: the #ESourceRegistry which emitted the signal
1207 * @source: the newly-added #ESource
1209 * Emitted when an #ESource is added to @registry.
1211 signals[SOURCE_ADDED] = g_signal_new (
1213 G_OBJECT_CLASS_TYPE (object_class),
1215 G_STRUCT_OFFSET (ESourceRegistryClass, source_added),
1217 g_cclosure_marshal_VOID__OBJECT,
1222 * ESourceRegistry::source-changed:
1223 * @registry: the #ESourceRegistry which emitted the signal
1224 * @source: the #ESource that changed
1226 * Emitted when an #ESource registered with @registry emits
1227 * its #ESource::changed signal.
1229 signals[SOURCE_CHANGED] = g_signal_new (
1231 G_OBJECT_CLASS_TYPE (object_class),
1233 G_STRUCT_OFFSET (ESourceRegistryClass, source_changed),
1235 g_cclosure_marshal_VOID__OBJECT,
1240 * ESourceRegistry::source-removed:
1241 * @registry: the #ESourceRegistry which emitted the signal
1242 * @source: the #ESource that got removed
1244 * Emitted when an #ESource is removed from @registry.
1246 signals[SOURCE_REMOVED] = g_signal_new (
1248 G_OBJECT_CLASS_TYPE (object_class),
1250 G_STRUCT_OFFSET (ESourceRegistryClass, source_removed),
1252 g_cclosure_marshal_VOID__OBJECT,
1257 * ESourceRegistry::source-enabled:
1258 * @registry: the #ESourceRegistry which emitted the signal
1259 * @source: the #ESource that got enabled
1261 * Emitted when an #ESource #ESource:enabled property becomes %TRUE.
1263 signals[SOURCE_ENABLED] = g_signal_new (
1265 G_OBJECT_CLASS_TYPE (object_class),
1267 G_STRUCT_OFFSET (ESourceRegistryClass, source_enabled),
1269 g_cclosure_marshal_VOID__OBJECT,
1274 * ESourceRegistry::source-disabled:
1275 * @registry: the #ESourceRegistry which emitted the signal
1276 * @source: the #ESource that got disabled
1278 * Emitted when an #ESource #ESource:enabled property becomes %FALSE.
1280 signals[SOURCE_DISABLED] = g_signal_new (
1282 G_OBJECT_CLASS_TYPE (object_class),
1284 G_STRUCT_OFFSET (ESourceRegistryClass, source_disabled),
1286 g_cclosure_marshal_VOID__OBJECT,
1292 e_source_registry_initable_init (GInitableIface *interface)
1294 interface->init = source_registry_initable_init;
1298 e_source_registry_init (ESourceRegistry *registry)
1300 registry->priv = E_SOURCE_REGISTRY_GET_PRIVATE (registry);
1302 /* This is so the object manager thread can schedule signal
1303 * emissions on the thread-default context for this thread. */
1304 registry->priv->main_context = g_main_context_ref_thread_default ();
1306 /* D-Bus object path -> ESource */
1307 registry->priv->object_path_table =
1308 g_hash_table_new_full (
1309 (GHashFunc) g_str_hash,
1310 (GEqualFunc) g_str_equal,
1311 (GDestroyNotify) g_free,
1312 (GDestroyNotify) g_object_unref);
1314 registry->priv->object_path_table_lock = g_mutex_new ();
1316 /* UID string -> ESource */
1317 registry->priv->sources = g_hash_table_new_full (
1318 (GHashFunc) g_str_hash,
1319 (GEqualFunc) g_str_equal,
1320 (GDestroyNotify) g_free,
1321 (GDestroyNotify) source_registry_unref_source);
1323 registry->priv->sources_lock = g_mutex_new ();
1325 registry->priv->settings = g_settings_new (GSETTINGS_SCHEMA);
1328 registry->priv->settings, "changed",
1329 G_CALLBACK (source_registry_settings_changed_cb), registry);
1333 * e_source_registry_new_sync:
1334 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1335 * @error: return location for a #GError, or %NULL
1337 * Creates a new #ESourceRegistry front-end for the registry D-Bus service.
1338 * If an error occurs in connecting to the D-Bus service, the function sets
1339 * @error and returns %NULL.
1341 * Returns: a new #ESourceRegistry, or %NULL
1346 e_source_registry_new_sync (GCancellable *cancellable,
1349 /* XXX Work around http://bugzilla.gnome.org/show_bug.cgi?id=683519
1350 * until GObject's type initialization deadlock issue is fixed.
1351 * Apparently only the synchronous instantiation is affected. */
1352 REGISTER_TYPE (G_TYPE_DBUS_CONNECTION);
1354 return g_initable_new (
1355 E_TYPE_SOURCE_REGISTRY,
1356 cancellable, error, NULL);
1360 * e_source_registry_new:
1361 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1362 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1364 * @user_data: (closure): data to pass to the callback function
1366 * Asynchronously creates a new #ESourceRegistry front-end for the registry
1369 * When the operation is finished, @callback will be called. You can then
1370 * call e_source_registry_new_finish() to get the result of the operation.
1375 e_source_registry_new (GCancellable *cancellable,
1376 GAsyncReadyCallback callback,
1379 g_async_initable_new_async (
1380 E_TYPE_SOURCE_REGISTRY,
1381 G_PRIORITY_DEFAULT, cancellable,
1382 callback, user_data, NULL);
1386 * e_source_registry_new_finish:
1387 * @result: a #GAsyncResult
1388 * @error: return location for a #GError, or %NULL
1390 * Finishes the operation started with e_source_registry_new_finish().
1391 * If an error occurs in connecting to the D-Bus service, the function
1392 * sets @error and returns %NULL.
1394 * Returns: a new #ESourceRegistry, or %NULL
1399 e_source_registry_new_finish (GAsyncResult *result,
1402 GObject *source_object;
1405 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
1407 source_object = g_async_result_get_source_object (result);
1408 g_return_val_if_fail (source_object != NULL, NULL);
1410 object = g_async_initable_new_finish (
1411 G_ASYNC_INITABLE (source_object), result, error);
1413 g_object_unref (source_object);
1415 return (object != NULL) ? E_SOURCE_REGISTRY (object) : NULL;
1418 /* Helper for e_source_registry_authenticate() */
1420 source_registry_authenticate_thread (GSimpleAsyncResult *simple,
1422 GCancellable *cancellable)
1424 AsyncContext *async_context;
1425 GError *error = NULL;
1427 async_context = g_simple_async_result_get_op_res_gpointer (simple);
1429 e_source_registry_authenticate_sync (
1430 E_SOURCE_REGISTRY (object),
1431 async_context->source,
1432 async_context->auth,
1433 cancellable, &error);
1436 g_simple_async_result_take_error (simple, error);
1439 /* Helper for e_source_registry_authenticate_sync() */
1441 source_registry_authenticate_respond_cb (AuthContext *auth_context)
1443 ESourceAuthenticationResult auth_result;
1444 GError *non_fatal_error = NULL;
1446 g_return_val_if_fail (auth_context->authenticating, FALSE);
1448 auth_result = auth_context->auth_result;
1450 /* Allow the next authentication attempt to proceed. */
1451 auth_context->authenticating = FALSE;
1453 /* Send the server a status update based on the authentication
1454 * result. Note, we don't really care if the D-Bus message gets
1455 * through to the server at this point. If it doesn't, the auth
1456 * session will either time out on its own or the authentication
1457 * dialog will eventually be dismissed by the user. */
1459 /* If we were cancelled from our side, we have a bit of a dilemma.
1460 * We need to tell the server to cancel the authentication session,
1461 * but that involves making a synchronous D-Bus call, which we are
1462 * not supposed to do if we know we've been cancelled. But if we
1463 * don't tell the server, the authentication session will be left
1464 * to timeout on its own (which may take minutes), and meanwhile
1465 * all other authentication requests are blocked. So choose the
1466 * lesser evil and make the synchronous call but without passing
1467 * the already-cancelled GCancellable. */
1468 if (g_cancellable_is_cancelled (auth_context->cancellable)) {
1469 e_dbus_authenticator_call_cancel_sync (
1470 auth_context->dbus_auth,
1471 NULL, &non_fatal_error);
1472 g_main_loop_quit (auth_context->main_loop);
1473 auth_context->success = FALSE;
1475 /* If an error occurred while attempting to authenticate,
1476 * tell the server to cancel the authentication session. */
1477 } else if (auth_result == E_SOURCE_AUTHENTICATION_ERROR) {
1478 e_dbus_authenticator_call_cancel_sync (
1479 auth_context->dbus_auth,
1480 auth_context->cancellable,
1482 g_main_loop_quit (auth_context->main_loop);
1483 auth_context->success = FALSE;
1485 /* If the password was accepted, let the server know so it
1486 * can close any authentication dialogs and save the user
1487 * provided password to the keyring. */
1488 } else if (auth_result == E_SOURCE_AUTHENTICATION_ACCEPTED) {
1489 e_dbus_authenticator_call_accepted_sync (
1490 auth_context->dbus_auth,
1491 auth_context->cancellable,
1493 g_main_loop_quit (auth_context->main_loop);
1494 auth_context->success = TRUE;
1496 /* If the password was rejected, let the server know so it can
1497 * indicate failure and request a different password, and then
1498 * wait for the next "response" signal. */
1500 e_dbus_authenticator_call_rejected_sync (
1501 auth_context->dbus_auth,
1502 auth_context->cancellable,
1506 /* Leave breadcrumbs if something went wrong,
1507 * but don't fail the whole operation over it. */
1508 if (non_fatal_error != NULL) {
1509 g_warning ("%s: %s", G_STRFUNC, non_fatal_error->message);
1510 g_error_free (non_fatal_error);
1516 /* Helper for e_source_registry_authenticate_sync() */
1518 source_registry_authenticate_authenticate_cb (EDBusAuthenticator *dbus_auth,
1519 const gchar *encrypted_secret,
1520 AuthContext *auth_context)
1522 GSource *idle_source;
1523 GMainContext *main_context;
1525 gboolean valid_secret;
1527 /* We should only get one secret at a time. */
1528 g_return_if_fail (!auth_context->authenticating);
1530 valid_secret = gcr_secret_exchange_receive (
1531 auth_context->secret_exchange, encrypted_secret);
1532 g_return_if_fail (valid_secret);
1534 auth_context->authenticating = TRUE;
1536 /* This avoids revealing the password in a stack trace. */
1537 password = g_string_new (
1538 gcr_secret_exchange_get_secret (
1539 auth_context->secret_exchange, NULL));
1541 /* Try authenticating with the given password. We have to
1542 * call this synchronously because some authenticators use
1543 * mutexes to serialize I/O operations and are not prepared
1544 * to make authentication attempts from a different thread.
1546 * Unfortunately this means we won't notice server-side
1547 * dismissals while the main loop is blocked. We respond
1548 * to the server from a low-priority idle callback so that
1549 * any pending "dismissed" signals get handled first. */
1551 auth_context->auth_result =
1552 e_source_authenticator_try_password_sync (
1553 auth_context->auth, password,
1554 auth_context->cancellable,
1555 auth_context->error);
1557 idle_source = g_idle_source_new ();
1558 main_context = g_main_context_get_thread_default ();
1559 g_source_set_callback (
1560 idle_source, (GSourceFunc)
1561 source_registry_authenticate_respond_cb,
1562 auth_context, NULL);
1563 g_source_attach (idle_source, main_context);
1564 g_source_unref (idle_source);
1566 g_string_free (password, TRUE);
1569 /* Helper for e_source_registry_authenticate_sync() */
1571 source_registry_authenticate_dismissed_cb (EDBusAuthenticator *dbus_auth,
1572 AuthContext *auth_context)
1574 /* Be careful not to overwrite an existing error in case this
1575 * is called after e_source_authenticator_try_password_sync()
1576 * but prior to the idle callback. */
1577 if (auth_context->auth_result != E_SOURCE_AUTHENTICATION_ERROR) {
1578 /* XXX Use a separate error code for dismissals? */
1579 g_set_error_literal (
1580 auth_context->error,
1581 G_IO_ERROR, G_IO_ERROR_CANCELLED,
1582 _("The user declined to authenticate"));
1583 auth_context->auth_result = E_SOURCE_AUTHENTICATION_ERROR;
1586 g_main_loop_quit (auth_context->main_loop);
1587 auth_context->success = FALSE;
1590 /* Helper for e_source_registry_authenticate_sync() */
1592 source_registry_call_authenticate_for_source (ESourceRegistry *registry,
1593 ESourceAuthenticator *auth,
1595 gchar **out_object_path,
1596 GCancellable *cancellable,
1599 ESource *collection;
1601 gchar *prompt_title = NULL;
1602 gchar *prompt_message = NULL;
1603 gchar *prompt_description = NULL;
1606 /* If the source is a member of a collection, we want to store
1607 * the password under the UID of the "collection" source so it
1608 * will apply to the entire collection.
1610 * XXX This assumes all sources in a collection share a single
1611 * password. If that turns out not to be true in all cases
1612 * we could maybe add a "SharedPassword: true/false" key to
1613 * [Collection] and apply it here.
1615 collection = e_source_registry_find_extension (
1616 registry, source, E_SOURCE_EXTENSION_COLLECTION);
1617 if (collection != NULL)
1618 source = collection;
1620 g_object_ref (source);
1622 uid = e_source_get_uid (source);
1624 e_source_authenticator_get_prompt_strings (
1628 &prompt_description);
1630 success = e_dbus_source_manager_call_authenticate_sync (
1631 registry->priv->dbus_source_manager, uid,
1632 prompt_title, prompt_message, prompt_description,
1633 out_object_path, cancellable, error);
1635 g_free (prompt_title);
1636 g_free (prompt_message);
1637 g_free (prompt_description);
1639 g_object_unref (source);
1645 * e_source_registry_authenticate_sync:
1646 * @registry: an #ESourceRegistry
1647 * @source: an #ESource
1648 * @auth: an #ESourceAuthenticator
1649 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1650 * @error: return location for a #GError, or %NULL
1652 * Authenticates @source, using @auth to handle the authentication
1653 * attempts. The operation loops until authentication is successful or
1654 * the user aborts further authentication attempts. If an error occurs,
1655 * the function will set @error and return %FALSE.
1657 * Note that @source need not have a #GDBusObject, which means this
1658 * function can test authentication on a scratch #ESource.
1660 * Only backend implementations and data source editors should call this
1661 * function. The intent is for basic client applications to not have to
1662 * deal with authentication at all.
1664 * Returns: %TRUE on success, %FALSE on failure
1669 e_source_registry_authenticate_sync (ESourceRegistry *registry,
1671 ESourceAuthenticator *auth,
1672 GCancellable *cancellable,
1675 AuthContext *auth_context;
1676 GMainContext *main_context;
1677 EDBusAuthenticator *dbus_auth;
1678 gchar *encryption_key;
1679 gchar *object_path = NULL;
1682 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
1683 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1684 g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth), FALSE);
1686 /* This extracts authentication prompt details for the ESource
1687 * before initiating an authentication session with the server,
1688 * so split it out of the main algorithm for clarity's sake. */
1689 success = source_registry_call_authenticate_for_source (
1690 registry, auth, source, &object_path, cancellable, error);
1693 g_warn_if_fail (object_path == NULL);
1697 g_return_val_if_fail (object_path != NULL, FALSE);
1699 main_context = g_main_context_new ();
1700 g_main_context_push_thread_default (main_context);
1702 dbus_auth = e_dbus_authenticator_proxy_new_for_bus_sync (
1704 G_DBUS_PROXY_FLAGS_NONE,
1705 SOURCES_DBUS_SERVICE_NAME,
1706 object_path, cancellable, error);
1708 g_free (object_path);
1710 if (dbus_auth == NULL) {
1715 auth_context = g_slice_new0 (AuthContext);
1716 auth_context->auth = g_object_ref (auth);
1717 auth_context->dbus_auth = dbus_auth; /* takes ownership */
1718 auth_context->main_loop = g_main_loop_new (main_context, FALSE);
1719 auth_context->error = error;
1721 /* This just needs to be something other than
1722 * E_SOURCE_AUTHENTICATION_ERROR so we don't trip
1723 * up source_registry_authenticate_dismissed_cb(). */
1724 auth_context->auth_result = E_SOURCE_AUTHENTICATION_REJECTED;
1726 if (G_IS_CANCELLABLE (cancellable))
1727 auth_context->cancellable = g_object_ref (cancellable);
1729 auth_context->secret_exchange =
1730 gcr_secret_exchange_new (GCR_SECRET_EXCHANGE_PROTOCOL_1);
1733 dbus_auth, "authenticate",
1734 G_CALLBACK (source_registry_authenticate_authenticate_cb),
1738 dbus_auth, "dismissed",
1739 G_CALLBACK (source_registry_authenticate_dismissed_cb),
1742 encryption_key = gcr_secret_exchange_begin (
1743 auth_context->secret_exchange);
1745 /* Signal the D-Bus server that we're ready to begin the
1746 * authentication session. This must happen AFTER we've
1747 * connected to the response signal since the server may
1748 * already have a response ready and waiting for us. */
1749 success = e_dbus_authenticator_call_ready_sync (
1750 dbus_auth, encryption_key, cancellable, error);
1752 g_free (encryption_key);
1755 g_main_loop_run (auth_context->main_loop);
1756 success = auth_context->success;
1759 auth_context_free (auth_context);
1762 g_main_context_pop_thread_default (main_context);
1763 g_main_context_unref (main_context);
1769 * e_source_registry_authenticate:
1770 * @registry: an #ESourceRegistry
1771 * @source: an #ESource
1772 * @auth: an #ESourceAuthenticator
1773 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1774 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1776 * @user_data: (closure): data to pass to the callback function
1778 * Asynchronously authenticates @source, using @auth to handle the
1779 * authentication attempts. The operation loops until authentication
1780 * is successful or the user aborts further authentication attempts.
1782 * Note that @source need not have a #GDBusObject, which means this
1783 * function can test authentication on a scratch #ESource.
1785 * When the operation is finished, @callback will be called. You can then
1786 * call e_source_registry_authenticate_finish() to get the result of the
1789 * Only backend implementations and data source editors should call this
1790 * function. The intent is for basic client applications to not have to
1791 * deal with authentication at all.
1796 e_source_registry_authenticate (ESourceRegistry *registry,
1798 ESourceAuthenticator *auth,
1799 GCancellable *cancellable,
1800 GAsyncReadyCallback callback,
1803 GSimpleAsyncResult *simple;
1804 AsyncContext *async_context;
1806 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
1807 g_return_if_fail (E_IS_SOURCE (source));
1808 g_return_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth));
1810 async_context = g_slice_new0 (AsyncContext);
1811 async_context->source = g_object_ref (source);
1812 async_context->auth = g_object_ref (auth);
1814 simple = g_simple_async_result_new (
1815 G_OBJECT (registry), callback, user_data,
1816 e_source_registry_authenticate);
1818 g_simple_async_result_set_check_cancellable (simple, cancellable);
1820 g_simple_async_result_set_op_res_gpointer (
1821 simple, async_context, (GDestroyNotify) async_context_free);
1823 g_simple_async_result_run_in_thread (
1824 simple, source_registry_authenticate_thread,
1825 G_PRIORITY_DEFAULT, cancellable);
1827 g_object_unref (simple);
1831 * e_source_registry_authenticate_finish:
1832 * @registry: an #ESourceRegistry
1833 * @result: a #GAsyncResult
1834 * @error: return location for a #GError, or %NULL
1836 * Finishes the operation started with e_source_registry_authenticate().
1837 * If an error occurred, the function will set @error and return %FALSE.
1839 * Returns: %TRUE on success, %FALSE on failure
1844 e_source_registry_authenticate_finish (ESourceRegistry *registry,
1845 GAsyncResult *result,
1848 GSimpleAsyncResult *simple;
1850 g_return_val_if_fail (
1851 g_simple_async_result_is_valid (
1852 result, G_OBJECT (registry),
1853 e_source_registry_authenticate), FALSE);
1855 simple = G_SIMPLE_ASYNC_RESULT (result);
1857 /* Assume success unless a GError is set. */
1858 return !g_simple_async_result_propagate_error (simple, error);
1861 /* Helper for e_source_registry_commit_source() */
1863 source_registry_commit_source_thread (GSimpleAsyncResult *simple,
1865 GCancellable *cancellable)
1867 AsyncContext *async_context;
1868 GError *error = NULL;
1870 async_context = g_simple_async_result_get_op_res_gpointer (simple);
1872 e_source_registry_commit_source_sync (
1873 E_SOURCE_REGISTRY (object),
1874 async_context->source,
1875 cancellable, &error);
1878 g_simple_async_result_take_error (simple, error);
1882 * e_source_registry_commit_source_sync:
1883 * @registry: an #ESourceRegistry
1884 * @source: an #ESource with changes to commit
1885 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1886 * @error: return location for #GError, or %NULL
1888 * This is a convenience function intended for use with graphical
1889 * #ESource editors. Call this function when the user is finished
1890 * making changes to @source.
1892 * If @source has a #GDBusObject, its contents are submitted to the D-Bus
1893 * service through e_source_write_sync().
1895 * If @source does NOT have a #GDBusObject (implying it's a scratch
1896 * #ESource), its contents are submitted to the D-Bus service through
1897 * either e_source_remote_create_sync() if @source is to be a collection
1898 * member, or e_source_registry_create_sources_sync() if @source to be an
1899 * independent data source.
1901 * If an error occurs, the function will set @error and return %FALSE.
1903 * Returns: %TRUE on success, %FALSE on failure
1908 e_source_registry_commit_source_sync (ESourceRegistry *registry,
1910 GCancellable *cancellable,
1913 GDBusObject *dbus_object;
1914 ESource *collection_source;
1915 gboolean collection_member;
1918 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
1919 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1921 dbus_object = e_source_ref_dbus_object (source);
1923 collection_source = e_source_registry_find_extension (
1924 registry, source, E_SOURCE_EXTENSION_COLLECTION);
1927 (collection_source != NULL) &&
1928 (collection_source != source);
1930 if (dbus_object != NULL) {
1931 success = e_source_write_sync (source, cancellable, error);
1932 g_object_unref (dbus_object);
1934 } else if (collection_member) {
1935 success = e_source_remote_create_sync (
1936 collection_source, source, cancellable, error);
1939 GList *list = g_list_prepend (NULL, source);
1940 success = e_source_registry_create_sources_sync (
1941 registry, list, cancellable, error);
1945 if (collection_source != NULL)
1946 g_object_unref (collection_source);
1952 * e_source_registry_commit_source:
1953 * @registry: an #ESourceRegistry
1954 * @source: an #ESource with changes to commit
1955 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
1956 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
1958 * @user_data: (closure): data to pass to the callback function
1960 * See e_source_registry_commit_source_sync() for details.
1962 * When the operation is finished, @callback will be called. You can then
1963 * call e_source_registry_commit_source_finish() to get the result of the
1969 e_source_registry_commit_source (ESourceRegistry *registry,
1971 GCancellable *cancellable,
1972 GAsyncReadyCallback callback,
1975 GSimpleAsyncResult *simple;
1976 AsyncContext *async_context;
1978 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
1979 g_return_if_fail (E_IS_SOURCE (source));
1981 async_context = g_slice_new0 (AsyncContext);
1982 async_context->source = g_object_ref (source);
1984 simple = g_simple_async_result_new (
1985 G_OBJECT (registry), callback, user_data,
1986 e_source_registry_commit_source);
1988 g_simple_async_result_set_check_cancellable (simple, cancellable);
1990 g_simple_async_result_set_op_res_gpointer (
1991 simple, async_context, (GDestroyNotify) async_context_free);
1993 g_simple_async_result_run_in_thread (
1994 simple, source_registry_commit_source_thread,
1995 G_PRIORITY_DEFAULT, cancellable);
1997 g_object_unref (simple);
2001 * e_source_registry_commit_source_finish:
2002 * @registry: an #ESourceRegistry
2003 * @result: a #GAsyncResult
2004 * @error: return location for a #GError, or %NULL
2006 * Finishes the operation started with e_source_registry_commit_source().
2008 * If an error occurred, the function will set @error and return %FALSE.
2010 * Returns: %TRUE on success, %FALSE on failure
2015 e_source_registry_commit_source_finish (ESourceRegistry *registry,
2016 GAsyncResult *result,
2019 GSimpleAsyncResult *simple;
2021 g_return_val_if_fail (
2022 g_simple_async_result_is_valid (
2023 result, G_OBJECT (registry),
2024 e_source_registry_commit_source), FALSE);
2026 simple = G_SIMPLE_ASYNC_RESULT (result);
2028 /* Assume success unless a GError is set. */
2029 return !g_simple_async_result_propagate_error (simple, error);
2032 /* Helper for e_source_registry_create_sources() */
2034 source_registry_create_sources_thread (GSimpleAsyncResult *simple,
2036 GCancellable *cancellable)
2038 AsyncContext *async_context;
2039 GError *error = NULL;
2041 async_context = g_simple_async_result_get_op_res_gpointer (simple);
2043 e_source_registry_create_sources_sync (
2044 E_SOURCE_REGISTRY (object),
2045 async_context->list_of_sources,
2046 cancellable, &error);
2049 g_simple_async_result_take_error (simple, error);
2052 /* Helper for e_source_registry_create_sources_sync() */
2054 source_registry_create_sources_main_loop_quit_cb (gpointer user_data)
2056 GMainLoop *main_loop = user_data;
2058 g_main_loop_quit (main_loop);
2063 /* Helper for e_source_registry_create_sources_sync() */
2065 source_registry_create_sources_object_added_cb (GDBusObjectManager *object_manager,
2066 GDBusObject *dbus_object,
2067 CreateContext *create_context)
2069 EDBusObject *e_dbus_object;
2070 EDBusSource *e_dbus_source;
2073 e_dbus_object = E_DBUS_OBJECT (dbus_object);
2074 e_dbus_source = e_dbus_object_get_source (e_dbus_object);
2075 uid = e_dbus_source_get_uid (e_dbus_source);
2077 g_hash_table_remove (create_context->pending_uids, uid);
2079 /* The hash table will be empty when all of the expected
2080 * GDBusObjects have been added to the GDBusObjectManager. */
2081 if (g_hash_table_size (create_context->pending_uids) == 0) {
2082 GSource *idle_source;
2084 idle_source = g_idle_source_new ();
2085 g_source_set_callback (
2087 source_registry_create_sources_main_loop_quit_cb,
2088 g_main_loop_ref (create_context->main_loop),
2089 (GDestroyNotify) g_main_loop_unref);
2090 g_source_attach (idle_source, create_context->main_context);
2091 g_source_unref (idle_source);
2096 * e_source_registry_create_sources_sync:
2097 * @registry: an #ESourceRegistry
2098 * @list_of_sources: (element-type ESource): a list of #ESource instances with
2100 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
2101 * @error: return location for a #GError, or %NULL
2103 * Requests the D-Bus service create new key files for each #ESource in
2104 * @list_of_sources. Each list element must be a scratch #ESource with
2107 * If an error occurs, the function will set @error and return %FALSE.
2109 * Returns: %TRUE on success, %FALSE on failure
2114 e_source_registry_create_sources_sync (ESourceRegistry *registry,
2115 GList *list_of_sources,
2116 GCancellable *cancellable,
2119 CreateContext *create_context;
2120 GVariantBuilder builder;
2123 gulong object_added_id;
2126 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
2128 /* Verify the list elements are all ESources. */
2129 for (link = list_of_sources; link != NULL; link = g_list_next (link))
2130 g_return_val_if_fail (E_IS_SOURCE (link->data), FALSE);
2132 create_context = create_context_new ();
2133 g_main_context_push_thread_default (create_context->main_context);
2135 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
2137 for (link = list_of_sources; link != NULL; link = g_list_next (link)) {
2142 source = E_SOURCE (link->data);
2143 uid = e_source_dup_uid (source);
2145 /* Takes ownership of the UID string. */
2146 g_hash_table_add (create_context->pending_uids, uid);
2148 source_data = e_source_to_string (source, NULL);
2149 g_variant_builder_add (&builder, "{ss}", uid, source_data);
2150 g_free (source_data);
2153 variant = g_variant_builder_end (&builder);
2155 /* Use G_CONNECT_AFTER so source_registry_object_added_cb()
2156 * runs first and actually adds the ESource to the internal
2157 * hash table before we go quitting our main loop. */
2158 object_added_id = g_signal_connect_after (
2159 registry->priv->dbus_object_manager, "object-added",
2160 G_CALLBACK (source_registry_create_sources_object_added_cb),
2163 /* This function sinks the floating GVariant reference. */
2164 success = e_dbus_source_manager_call_create_sources_sync (
2165 registry->priv->dbus_source_manager,
2166 variant, cancellable, error);
2168 g_variant_builder_clear (&builder);
2170 /* Wait for an "object-added" signal for each created ESource.
2171 * But also set a short timeout to avoid getting stuck here in
2172 * case the registry service adds sources to its orphan table,
2173 * which prevents them from being exported over D-Bus. */
2175 GSource *timeout_source;
2177 timeout_source = g_timeout_source_new_seconds (2);
2178 g_source_set_callback (
2180 source_registry_create_sources_main_loop_quit_cb,
2181 g_main_loop_ref (create_context->main_loop),
2182 (GDestroyNotify) g_main_loop_unref);
2183 g_source_attach (timeout_source, create_context->main_context);
2184 g_source_unref (timeout_source);
2186 g_main_loop_run (create_context->main_loop);
2189 g_signal_handler_disconnect (
2190 registry->priv->dbus_object_manager, object_added_id);
2192 g_main_context_pop_thread_default (create_context->main_context);
2193 create_context_free (create_context);
2199 * e_source_registry_create_sources:
2200 * @registry: an #ESourceRegistry
2201 * @list_of_sources: (element-type ESource): a list of #ESource instances with
2203 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
2204 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
2206 * @user_data: (closure): data to pass to the callback function
2208 * Asynchronously requests the D-Bus service create new key files for each
2209 * #ESource in @list_of_sources. Each list element must be a scratch
2210 * #ESource with no #GDBusObject.
2212 * When the operation is finished, @callback will be called. You can then
2213 * call e_source_registry_create_sources_finish() to get the result of the
2219 e_source_registry_create_sources (ESourceRegistry *registry,
2220 GList *list_of_sources,
2221 GCancellable *cancellable,
2222 GAsyncReadyCallback callback,
2225 GSimpleAsyncResult *simple;
2226 AsyncContext *async_context;
2229 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2231 /* Verify the list elements are all ESources. */
2232 for (link = list_of_sources; link != NULL; link = g_list_next (link))
2233 g_return_if_fail (E_IS_SOURCE (link->data));
2235 async_context = g_slice_new0 (AsyncContext);
2236 async_context->list_of_sources = g_list_copy (list_of_sources);
2239 async_context->list_of_sources,
2240 (GFunc) g_object_ref, NULL);
2242 simple = g_simple_async_result_new (
2243 G_OBJECT (registry), callback, user_data,
2244 e_source_registry_create_sources);
2246 g_simple_async_result_set_check_cancellable (simple, cancellable);
2248 g_simple_async_result_set_op_res_gpointer (
2249 simple, async_context, (GDestroyNotify) async_context_free);
2251 g_simple_async_result_run_in_thread (
2252 simple, source_registry_create_sources_thread,
2253 G_PRIORITY_DEFAULT, cancellable);
2255 g_object_unref (simple);
2259 * e_source_registry_create_sources_finish:
2260 * @registry: an #ESourceRegistry
2261 * @result: a #GAsyncResult
2262 * @error: return location for a #GError, or %NULL
2264 * Finishes the operation started with e_source_registry_create_sources().
2266 * If an error occurred, the function will set @error and return %FALSE.
2268 * Returns: %TRUE on success, %FALSE on failure
2273 e_source_registry_create_sources_finish (ESourceRegistry *registry,
2274 GAsyncResult *result,
2277 GSimpleAsyncResult *simple;
2279 g_return_val_if_fail (
2280 g_simple_async_result_is_valid (
2281 result, G_OBJECT (registry),
2282 e_source_registry_create_sources), FALSE);
2284 simple = G_SIMPLE_ASYNC_RESULT (result);
2286 /* Assume success unless a GError is set. */
2287 return !g_simple_async_result_propagate_error (simple, error);
2291 * e_source_registry_ref_source:
2292 * @registry: an #ESourceRegistry
2293 * @uid: a unique identifier string
2295 * Looks up an #ESource in @registry by its unique identifier string.
2297 * The returned #ESource is referenced for thread-safety and must be
2298 * unreferenced with g_object_unref() when finished with it.
2300 * Returns: (transfer full): an #ESource, or %NULL if no match was found
2305 e_source_registry_ref_source (ESourceRegistry *registry,
2308 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2309 g_return_val_if_fail (uid != NULL, NULL);
2311 return source_registry_sources_lookup (registry, uid);
2315 * e_source_registry_list_sources:
2316 * @registry: an #ESourceRegistry
2317 * @extension_name: (allow-none): an extension name, or %NULL
2319 * Returns a list of registered sources, sorted by display name. If
2320 * @extension_name is given, restrict the list to sources having that
2323 * The sources returned in the list are referenced for thread-safety.
2324 * They must each be unreferenced with g_object_unref() when finished
2325 * when them. Free the returned list itself with g_list_free().
2327 * An easy way to free the list properly in one step is as follows:
2330 * g_list_free_full (list, g_object_unref);
2333 * Returns: (element-type ESource) (transfer full): a sorted list of sources
2338 e_source_registry_list_sources (ESourceRegistry *registry,
2339 const gchar *extension_name)
2342 GQueue trash = G_QUEUE_INIT;
2344 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2346 list = g_list_sort (
2347 source_registry_sources_get_values (registry),
2348 (GCompareFunc) e_source_compare_by_display_name);
2350 if (extension_name == NULL)
2353 for (link = list; link != NULL; link = g_list_next (link)) {
2354 ESource *source = E_SOURCE (link->data);
2356 if (!e_source_has_extension (source, extension_name)) {
2357 g_queue_push_tail (&trash, link);
2358 g_object_unref (source);
2362 /* We do want pop_head() here, not pop_head_link(). */
2363 while ((link = g_queue_pop_head (&trash)) != NULL)
2364 list = g_list_delete_link (list, link);
2370 * e_source_registry_check_enabled:
2371 * @registry: an #ESourceRegistry
2372 * @source: an #ESource
2374 * Determines whether @source is "effectively" enabled by examining its
2375 * own #ESource:enabled property as well as those of its ancestors in the
2376 * #ESource hierarchy. If all examined #ESource:enabled properties are
2377 * %TRUE, then the function returns %TRUE. If any are %FALSE, then the
2378 * function returns %FALSE.
2380 * Use this function instead of e_source_get_enabled() to determine
2381 * things like whether to display an #ESource in a user interface or
2382 * whether to act on the data set described by the #ESource.
2384 * Returns: whether @source is "effectively" enabled
2389 e_source_registry_check_enabled (ESourceRegistry *registry,
2395 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
2396 g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
2398 enabled = e_source_get_enabled (source);
2399 parent_uid = e_source_dup_parent (source);
2401 while (enabled && parent_uid != NULL) {
2404 parent = e_source_registry_ref_source (registry, parent_uid);
2406 g_free (parent_uid);
2409 if (parent != NULL) {
2410 enabled = e_source_get_enabled (parent);
2411 parent_uid = e_source_dup_parent (parent);
2412 g_object_unref (parent);
2416 g_free (parent_uid);
2422 * e_source_registry_find_extension:
2423 * @registry: an #ESourceRegistry
2424 * @source: an #ESource
2425 * @extension_name: the extension name to find
2427 * Examines @source and its ancestors and returns the "deepest" #ESource
2428 * having an #ESourceExtension with the given @extension_name. If neither
2429 * @source nor any of its ancestors have such an extension, the function
2432 * This function is useful in cases when an #ESourceExtension is meant to
2433 * apply to both the #ESource it belongs to and the #ESource's descendants.
2435 * A common example is the #ESourceCollection extension, where descendants
2436 * of an #ESource having an #ESourceCollection extension are implied to be
2437 * members of that collection. In that example, this function can be used
2438 * to test whether @source is a member of a collection.
2440 * The returned #ESource is referenced for thread-safety and must be
2441 * unreferenced with g_object_unref() when finished with it.
2443 * Note the function returns the #ESource containing the #ESourceExtension
2444 * instead of the #ESourceExtension itself because extension instances are
2445 * not to be referenced directly (see e_source_get_extension()).
2447 * Returns: (transfer full): an #ESource, or %NULL if no match was found
2452 e_source_registry_find_extension (ESourceRegistry *registry,
2454 const gchar *extension_name)
2456 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2457 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2458 g_return_val_if_fail (extension_name != NULL, NULL);
2460 g_object_ref (source);
2462 while (!e_source_has_extension (source, extension_name)) {
2465 uid = e_source_dup_parent (source);
2467 g_object_unref (source);
2471 source = e_source_registry_ref_source (registry, uid);
2482 /* Helper for e_source_registry_build_display_tree() */
2484 source_registry_compare_nodes (GNode *node_a,
2487 ESource *source_a = E_SOURCE (node_a->data);
2488 ESource *source_b = E_SOURCE (node_b->data);
2489 const gchar *uid_a, *uid_b;
2491 uid_a = e_source_get_uid (source_a);
2492 uid_b = e_source_get_uid (source_b);
2494 /* Sanity check, with runtime warnings. */
2495 if (uid_a == NULL) {
2496 g_warn_if_reached ();
2499 if (uid_b == NULL) {
2500 g_warn_if_reached ();
2504 /* The built-in "local-stub" source comes first at depth 1. */
2506 if (g_strcmp0 (uid_a, "local-stub") == 0)
2509 if (g_strcmp0 (uid_b, "local-stub") == 0)
2512 /* The built-in "system-*" sources come first at depth 2. */
2514 if (g_str_has_prefix (uid_a, "system-"))
2517 if (g_str_has_prefix (uid_b, "system-"))
2520 return e_source_compare_by_display_name (source_a, source_b);
2523 /* Helper for e_source_registry_build_display_tree() */
2525 source_registry_prune_nodes (GNode *node,
2526 const gchar *extension_name)
2528 GQueue queue = G_QUEUE_INIT;
2531 /* Unlink all the child nodes and place them in a queue. */
2532 while ((child_node = g_node_first_child (node)) != NULL) {
2533 g_node_unlink (child_node);
2534 g_queue_push_tail (&queue, child_node);
2537 /* Sort the queue by source name. */
2539 &queue, (GCompareDataFunc)
2540 source_registry_compare_nodes, NULL);
2542 /* Pop nodes off the head of the queue until the queue is empty.
2543 * If the node has either its own children or the given extension
2544 * name, put it back under the parent node (preserving the sorted
2545 * order). Otherwise delete the node and its descendants. */
2546 while ((child_node = g_queue_pop_head (&queue)) != NULL) {
2547 ESource *child = E_SOURCE (child_node->data);
2548 gboolean append_child_node = FALSE;
2550 if (extension_name == NULL)
2551 append_child_node = e_source_get_enabled (child);
2553 else if (e_source_has_extension (child, extension_name))
2554 append_child_node = e_source_get_enabled (child);
2556 else if (g_node_first_child (child_node) != NULL)
2557 append_child_node = e_source_get_enabled (child);
2559 if (append_child_node)
2560 g_node_append (node, child_node);
2562 e_source_registry_free_display_tree (child_node);
2569 * e_source_registry_build_display_tree:
2570 * @registry: an #ESourceRegistry
2571 * @extension_name: (allow-none): an extension name, or %NULL
2573 * Returns a single #GNode tree of registered sources that can be used to
2574 * populate a #GtkTreeModel. (The root #GNode is just an empty placeholder.)
2576 * Similar to e_source_registry_list_sources(), an @extension_name can be
2577 * given to restrict the tree to sources having that extension name. Parents
2578 * of matched sources are included in the tree regardless of whether they have
2579 * an extension named @extension_name.
2581 * Disabled leaf nodes are automatically excluded from the #GNode tree.
2583 * The sources returned in the tree are referenced for thread-safety.
2584 * They must each be unreferenced with g_object_unref() when finished
2585 * with them. Free the returned tree itself with g_node_destroy().
2586 * For convenience, e_source_registry_free_display_tree() does all
2589 * Returns: (element-type ESource) (transfer full): a tree of sources,
2590 * arranged for display
2595 e_source_registry_build_display_tree (ESourceRegistry *registry,
2596 const gchar *extension_name)
2600 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2602 /* Assemble all data sources into a tree. */
2603 root = source_registry_sources_build_tree (registry);
2605 /* Prune unwanted nodes from the copied source trees.
2606 * This must be done in "post" order (children first)
2607 * since it reorders and deletes child nodes. */
2609 root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
2610 (GNodeTraverseFunc) source_registry_prune_nodes,
2611 (gpointer) extension_name);
2616 /* Helper for e_source_registry_free_display_tree() */
2618 source_registry_unref_nodes (GNode *node)
2620 while (node != NULL) {
2621 if (node->children != NULL)
2622 source_registry_unref_nodes (node->children);
2623 if (node->data != NULL)
2624 g_object_unref (node->data);
2630 * e_source_registry_free_display_tree:
2631 * @display_tree: a tree of sources, arranged for display
2633 * Convenience function to free a #GNode tree of registered
2634 * sources created by e_source_registry_build_display_tree().
2639 e_source_registry_free_display_tree (GNode *display_tree)
2641 g_return_if_fail (display_tree != NULL);
2643 /* XXX This would be easier if GLib had something like
2644 * g_node_destroy_full() which took a GDestroyNotify.
2645 * Then the tree would not have to be traversed twice. */
2647 source_registry_unref_nodes (display_tree);
2648 g_node_destroy (display_tree);
2651 /* Helper for e_source_registry_debug_dump() */
2653 source_registry_debug_dump_cb (GNode *node)
2657 /* Root node is an empty placeholder. */
2658 if (G_NODE_IS_ROOT (node))
2661 depth = g_node_depth (node);
2662 for (ii = 2; ii < depth; ii++)
2665 if (E_IS_SOURCE (node->data)) {
2666 ESource *source = E_SOURCE (node->data);
2667 g_print ("\"%s\" ", e_source_get_display_name (source));
2668 g_print ("(%s)", e_source_get_uid (source));
2677 * e_source_registry_debug_dump:
2678 * @registry: an #ESourceRegistry
2679 * @extension_name: (allow-none): an extension name, or %NULL
2681 * Handy debugging function that uses e_source_registry_build_display_tree()
2682 * to print a tree of registered sources to standard output.
2687 e_source_registry_debug_dump (ESourceRegistry *registry,
2688 const gchar *extension_name)
2692 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2694 root = e_source_registry_build_display_tree (registry, extension_name);
2697 root, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
2698 (GNodeTraverseFunc) source_registry_debug_dump_cb, NULL);
2700 e_source_registry_free_display_tree (root);
2704 * e_source_registry_ref_builtin_address_book:
2705 * @registry: an #ESourceRegistry
2707 * Returns the built-in address book #ESource.
2709 * This #ESource is always present and makes for a safe fallback.
2711 * The returned #ESource is referenced for thread-safety and must be
2712 * unreferenced with g_object_unref() when finished with it.
2714 * Returns: (transfer full): the built-in address book #ESource
2719 e_source_registry_ref_builtin_address_book (ESourceRegistry *registry)
2724 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2726 uid = E_SOURCE_BUILTIN_ADDRESS_BOOK_UID;
2727 source = e_source_registry_ref_source (registry, uid);
2728 g_return_val_if_fail (source != NULL, NULL);
2734 * e_source_registry_ref_default_address_book:
2735 * @registry: an #ESourceRegistry
2737 * Returns the #ESource most recently passed to
2738 * e_source_registry_set_default_address_book() either in this session
2739 * or a previous session, or else falls back to the built-in address book.
2741 * The returned #ESource is referenced for thread-safety and must be
2742 * unreferenced with g_object_unref() when finished with it.
2744 * Returns: (transfer full): the default address book #ESource
2749 e_source_registry_ref_default_address_book (ESourceRegistry *registry)
2755 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2757 key = E_SETTINGS_DEFAULT_ADDRESS_BOOK_KEY;
2758 uid = g_settings_get_string (registry->priv->settings, key);
2759 source = e_source_registry_ref_source (registry, uid);
2762 /* The built-in source is always present. */
2764 source = e_source_registry_ref_builtin_address_book (registry);
2766 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2772 * e_source_registry_set_default_address_book:
2773 * @registry: an #ESourceRegistry
2774 * @default_source: (allow-none): an address book #ESource, or %NULL
2776 * Sets @default_source as the default address book. If @default_source
2777 * is %NULL, the default address book is reset to the built-in address book.
2778 * This setting will persist across sessions until changed.
2783 e_source_registry_set_default_address_book (ESourceRegistry *registry,
2784 ESource *default_source)
2789 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2791 if (default_source != NULL) {
2792 g_return_if_fail (E_IS_SOURCE (default_source));
2793 uid = e_source_get_uid (default_source);
2795 uid = E_SOURCE_BUILTIN_ADDRESS_BOOK_UID;
2798 key = E_SETTINGS_DEFAULT_ADDRESS_BOOK_KEY;
2799 g_settings_set_string (registry->priv->settings, key, uid);
2801 /* The GSettings::changed signal will trigger a "notify" signal
2802 * from the registry, so no need to call g_object_notify() here. */
2806 * e_source_registry_ref_builtin_calendar:
2807 * @registry: an #ESourceRegistry
2809 * Returns the built-in calendar #ESource.
2811 * This #ESource is always present and makes for a safe fallback.
2813 * The returned #ESource is referenced for thread-safety and must be
2814 * unreferenced with g_object_unref() when finished with it.
2816 * Returns: (transfer full): the built-in calendar #ESource
2821 e_source_registry_ref_builtin_calendar (ESourceRegistry *registry)
2826 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2828 uid = E_SOURCE_BUILTIN_CALENDAR_UID;
2829 source = e_source_registry_ref_source (registry, uid);
2830 g_return_val_if_fail (source != NULL, NULL);
2836 * e_source_registry_ref_default_calendar:
2837 * @registry: an #ESourceRegistry
2839 * Returns the #ESource most recently passed to
2840 * e_source_registry_set_default_calendar() either in this session
2841 * or a previous session, or else falls back to the built-in calendar.
2843 * The returned #ESource is referenced for thread-safety and must be
2844 * unreferenced with g_object_unref() when finished with it.
2846 * Returns: (transfer full): the default calendar #ESource
2851 e_source_registry_ref_default_calendar (ESourceRegistry *registry)
2857 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2859 key = E_SETTINGS_DEFAULT_CALENDAR_KEY;
2860 uid = g_settings_get_string (registry->priv->settings, key);
2861 source = e_source_registry_ref_source (registry, uid);
2864 /* The built-in source is always present. */
2866 source = e_source_registry_ref_builtin_calendar (registry);
2868 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2874 * e_source_registry_set_default_calendar:
2875 * @registry: an #ESourceRegistry
2876 * @default_source: (allow-none): a calendar #ESource, or %NULL
2878 * Sets @default_source as the default calendar. If @default_source
2879 * is %NULL, the default calendar is reset to the built-in calendar.
2880 * This setting will persist across sessions until changed.
2885 e_source_registry_set_default_calendar (ESourceRegistry *registry,
2886 ESource *default_source)
2891 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2893 if (default_source != NULL) {
2894 g_return_if_fail (E_IS_SOURCE (default_source));
2895 uid = e_source_get_uid (default_source);
2897 uid = E_SOURCE_BUILTIN_CALENDAR_UID;
2900 key = E_SETTINGS_DEFAULT_CALENDAR_KEY;
2901 g_settings_set_string (registry->priv->settings, key, uid);
2903 /* The GSettings::changed signal will trigger a "notify" signal
2904 * from the registry, so no need to call g_object_notify() here. */
2908 * e_source_registry_ref_builtin_mail_account:
2909 * @registry: an #ESourceRegistry
2911 * Returns the built-in mail account #ESource.
2913 * This #ESource is always present and makes for a safe fallback.
2915 * The returned #ESource is referenced for thread-safety and must be
2916 * unreferenced with g_object_unref() when finished with it.
2918 * Returns: (transfer full): the built-in mail account #ESource
2923 e_source_registry_ref_builtin_mail_account (ESourceRegistry *registry)
2928 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2930 uid = E_SOURCE_BUILTIN_MAIL_ACCOUNT_UID;
2931 source = e_source_registry_ref_source (registry, uid);
2932 g_return_val_if_fail (source != NULL, NULL);
2938 * e_source_registry_ref_default_mail_account:
2939 * @registry: an #ESourceRegistry
2941 * Returns the #ESource most recently passed to
2942 * e_source_registry_set_default_mail_account() either in this session
2943 * or a previous session, or else falls back to the built-in mail account.
2945 * The returned #ESource is referenced for thread-safety and must be
2946 * unreferenced with g_object_unref() when finished with it.
2948 * Returns: (transfer full): the default mail account #ESource
2953 e_source_registry_ref_default_mail_account (ESourceRegistry *registry)
2959 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
2961 key = E_SETTINGS_DEFAULT_MAIL_ACCOUNT_KEY;
2962 uid = g_settings_get_string (registry->priv->settings, key);
2963 source = e_source_registry_ref_source (registry, uid);
2966 /* The built-in source is always present. */
2968 source = e_source_registry_ref_builtin_mail_account (registry);
2970 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2976 * e_source_registry_set_default_mail_account:
2977 * @registry: an #ESourceRegistry
2978 * @default_source: (allow-none): a mail account #ESource, or %NULL
2980 * Sets @default_source as the default mail account. If @default_source
2981 * is %NULL, the default mail account is reset to the built-in mail account.
2982 * This setting will persist across sessions until changed.
2987 e_source_registry_set_default_mail_account (ESourceRegistry *registry,
2988 ESource *default_source)
2993 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
2995 if (default_source != NULL) {
2996 g_return_if_fail (E_IS_SOURCE (default_source));
2997 uid = e_source_get_uid (default_source);
2999 uid = E_SOURCE_BUILTIN_MAIL_ACCOUNT_UID;
3002 key = E_SETTINGS_DEFAULT_MAIL_ACCOUNT_KEY;
3003 g_settings_set_string (registry->priv->settings, key, uid);
3005 /* The GSettings::changed signal will trigger a "notify" signal
3006 * from the registry, so no need to call g_object_notify() here. */
3009 /* Helper for e_source_registry_ref_default_mail_identity() */
3011 source_registry_ref_any_mail_identity (ESourceRegistry *registry)
3015 const gchar *extension_name;
3018 /* First fallback: Return the mail identity named
3019 * by the default mail account. */
3021 source = e_source_registry_ref_default_mail_account (registry);
3023 /* This should never be NULL, but just to be safe. */
3024 if (source != NULL) {
3025 ESourceMailAccount *extension;
3027 extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
3028 extension = e_source_get_extension (source, extension_name);
3029 uid = e_source_mail_account_dup_identity_uid (extension);
3031 g_object_unref (source);
3036 source = e_source_registry_ref_source (registry, uid);
3043 /* Second fallback: Pick any available mail identity,
3044 * preferring enabled identities. */
3046 extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
3047 list = e_source_registry_list_sources (registry, extension_name);
3049 for (link = list; link != NULL; link = g_list_next (link)) {
3050 ESource *candidate = E_SOURCE (link->data);
3052 if (e_source_registry_check_enabled (registry, candidate)) {
3053 source = g_object_ref (candidate);
3058 if (source == NULL && list != NULL)
3059 source = g_object_ref (list->data);
3061 g_list_free_full (list, (GDestroyNotify) g_object_unref);
3067 * e_source_registry_ref_default_mail_identity:
3068 * @registry: an #ESourceRegistry
3070 * Returns the #ESource most recently passed to
3071 * e_source_registry_set_default_mail_identity() either in this session
3072 * or a previous session, or else falls back to the mail identity named
3073 * by the default mail account. If even that fails it returns any mail
3074 * identity from @registry, or %NULL if there are none.
3076 * The returned #ESource is referenced for thread-safety and must be
3077 * unreferenced with g_object_unref() when finished with it.
3079 * Returns: (transfer full): the default mail identity #ESource, or %NULL
3084 e_source_registry_ref_default_mail_identity (ESourceRegistry *registry)
3090 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3092 key = E_SETTINGS_DEFAULT_MAIL_IDENTITY_KEY;
3093 uid = g_settings_get_string (registry->priv->settings, key);
3094 source = e_source_registry_ref_source (registry, uid);
3098 source = source_registry_ref_any_mail_identity (registry);
3104 * e_source_registry_set_default_mail_identity:
3105 * @registry: an #ESourceRegistry
3106 * @default_source: (allow-none): a mail identity #ESource, or %NULL
3108 * Sets @default_source as the default mail identity. If @default_source
3109 * is %NULL, the next request for the default mail identity will use the
3110 * fallbacks described in e_source_registry_get_default_mail_identity().
3115 e_source_registry_set_default_mail_identity (ESourceRegistry *registry,
3116 ESource *default_source)
3121 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3123 if (default_source != NULL) {
3124 g_return_if_fail (E_IS_SOURCE (default_source));
3125 uid = e_source_get_uid (default_source);
3127 uid = ""; /* no built-in mail identity */
3130 key = E_SETTINGS_DEFAULT_MAIL_IDENTITY_KEY;
3131 g_settings_set_string (registry->priv->settings, key, uid);
3133 /* The GSettings::changed signal will trigger a "notify" signal
3134 * from the registry, so no need to call g_object_notify() here. */
3138 * e_source_registry_ref_builtin_memo_list:
3139 * @registry: an #ESourceRegistry
3141 * Returns the built-in memo list #ESource.
3143 * This #ESource is always present and makes for a safe fallback.
3145 * The returned #ESource is referenced for thread-safety and must be
3146 * unreferenced with g_object_unref() when finished with it.
3148 * Returns: (transfer full): the built-in memo list #ESource
3153 e_source_registry_ref_builtin_memo_list (ESourceRegistry *registry)
3158 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3160 uid = E_SOURCE_BUILTIN_MEMO_LIST_UID;
3161 source = e_source_registry_ref_source (registry, uid);
3162 g_return_val_if_fail (source != NULL, NULL);
3168 * e_source_registry_ref_default_memo_list:
3169 * @registry: an #ESourceRegistry
3171 * Returns the #ESource most recently passed to
3172 * e_source_registry_set_default_memo_list() either in this session
3173 * or a previous session, or else falls back to the built-in memo list.
3175 * The returned #ESource is referenced for thread-safety and must be
3176 * unreferenced with g_object_unref() when finished with it.
3178 * Returns: (transfer full): the default memo list #ESource
3183 e_source_registry_ref_default_memo_list (ESourceRegistry *registry)
3189 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3191 key = E_SETTINGS_DEFAULT_MEMO_LIST_KEY;
3192 uid = g_settings_get_string (registry->priv->settings, key);
3193 source = e_source_registry_ref_source (registry, uid);
3196 /* The built-in source is always present. */
3198 source = e_source_registry_ref_builtin_memo_list (registry);
3200 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
3206 * e_source_registry_set_default_memo_list:
3207 * @registry: an #ESourceRegistry
3208 * @default_source: (allow-none): a memo list #ESource, or %NULL
3210 * Sets @default_source as the default memo list. If @default_source
3211 * is %NULL, the default memo list is reset to the built-in memo list.
3212 * This setting will persist across sessions until changed.
3217 e_source_registry_set_default_memo_list (ESourceRegistry *registry,
3218 ESource *default_source)
3223 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3225 if (default_source != NULL) {
3226 g_return_if_fail (E_IS_SOURCE (default_source));
3227 uid = e_source_get_uid (default_source);
3229 uid = E_SOURCE_BUILTIN_MEMO_LIST_UID;
3232 key = E_SETTINGS_DEFAULT_MEMO_LIST_KEY;
3233 g_settings_set_string (registry->priv->settings, key, uid);
3235 /* The GSettings::changed signal will trigger a "notify" signal
3236 * from the registry, so no need to call g_object_notify() here. */
3240 * e_source_registry_ref_builtin_task_list:
3241 * @registry: an #ESourceRegistry
3243 * Returns the built-in task list #ESource.
3245 * This #ESource is always present and makes for a safe fallback.
3247 * The returned #ESource is referenced for thread-safety and must be
3248 * unreferenced with g_object_unref() when finished with it.
3250 * Returns: (transfer full): the built-in task list #ESource
3255 e_source_registry_ref_builtin_task_list (ESourceRegistry *registry)
3260 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3262 uid = E_SOURCE_BUILTIN_TASK_LIST_UID;
3263 source = e_source_registry_ref_source (registry, uid);
3264 g_return_val_if_fail (source != NULL, NULL);
3270 * e_source_registry_ref_default_task_list:
3271 * @registry: an #ESourceRegistry
3273 * Returns the #ESource most recently passed to
3274 * e_source_registry_set_default_task_list() either in this session
3275 * or a previous session, or else falls back to the built-in task list.
3277 * The returned #ESource is referenced for thread-safety and must be
3278 * unreferenced with g_object_unref() when finished with it.
3280 * Returns: (transfer full): the default task list #ESource
3285 e_source_registry_ref_default_task_list (ESourceRegistry *registry)
3291 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3293 key = E_SETTINGS_DEFAULT_TASK_LIST_KEY;
3294 uid = g_settings_get_string (registry->priv->settings, key);
3295 source = e_source_registry_ref_source (registry, uid);
3298 /* The built-in source is always present. */
3300 source = e_source_registry_ref_builtin_task_list (registry);
3302 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
3308 * e_source_registry_set_default_task_list:
3309 * @registry: an #ESourceRegistry
3310 * @default_source: (allow-none): a task list #ESource, or %NULL
3312 * Sets @default_source as the default task list. If @default_source
3313 * is %NULL, the default task list is reset to the built-in task list.
3314 * This setting will persist across sessions until changed.
3319 e_source_registry_set_default_task_list (ESourceRegistry *registry,
3320 ESource *default_source)
3325 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3327 if (default_source != NULL) {
3328 g_return_if_fail (E_IS_SOURCE (default_source));
3329 uid = e_source_get_uid (default_source);
3331 uid = E_SOURCE_BUILTIN_TASK_LIST_UID;
3334 key = E_SETTINGS_DEFAULT_TASK_LIST_KEY;
3335 g_settings_set_string (registry->priv->settings, key, uid);
3337 /* The GSettings::changed signal will trigger a "notify" signal
3338 * from the registry, so no need to call g_object_notify() here. */
3342 * e_source_registry_ref_default_for_extension_name:
3343 * @registry: an #ESourceRegistry
3344 * @extension_name: an extension_name
3346 * This is a convenience function to return a default #ESource based on
3347 * @extension_name. This only works with a subset of extension names.
3349 * If @extension_name is #E_SOURCE_EXTENSION_ADDRESS_BOOK, the function
3350 * returns the current default address book, or else falls back to the
3351 * built-in address book.
3353 * If @extension_name is #E_SOURCE_EXTENSION_CALENDAR, the function returns
3354 * the current default calendar, or else falls back to the built-in calendar.
3356 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_ACCOUNT, the function
3357 * returns the current default mail account, or else falls back to the
3358 * built-in mail account.
3360 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_IDENTITY, the function
3361 * returns the current default mail identity, or else falls back to the
3362 * mail identity named by the current default mail account.
3364 * If @extension_name is #E_SOURCE_EXTENSION_MEMO_LIST, the function returns
3365 * the current default memo list, or else falls back to the built-in memo list.
3367 * If @extension_name is #E_SOURCE_EXTENSION_TASK_LIST, the function returns
3368 * the current default task list, or else falls back to the built-in task list.
3370 * For all other values of @extension_name, the function returns %NULL.
3372 * The returned #ESource is referenced for thread-safety and must be
3373 * unreferenced with g_object_unref() when finished with it.
3375 * Returns: (transfer full): the default #ESource based on @extension_name
3380 e_source_registry_ref_default_for_extension_name (ESourceRegistry *registry,
3381 const gchar *extension_name)
3383 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
3384 g_return_val_if_fail (extension_name != NULL, NULL);
3386 if (strcmp (extension_name, E_SOURCE_EXTENSION_ADDRESS_BOOK) == 0)
3387 return e_source_registry_ref_default_address_book (registry);
3389 if (strcmp (extension_name, E_SOURCE_EXTENSION_CALENDAR) == 0)
3390 return e_source_registry_ref_default_calendar (registry);
3392 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_ACCOUNT) == 0)
3393 return e_source_registry_ref_default_mail_account (registry);
3395 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_IDENTITY) == 0)
3396 return e_source_registry_ref_default_mail_identity (registry);
3398 if (strcmp (extension_name, E_SOURCE_EXTENSION_MEMO_LIST) == 0)
3399 return e_source_registry_ref_default_memo_list (registry);
3401 if (strcmp (extension_name, E_SOURCE_EXTENSION_TASK_LIST) == 0)
3402 return e_source_registry_ref_default_task_list (registry);
3408 * e_source_registry_set_default_for_extension_name:
3409 * @registry: an #ESourceRegistry
3410 * @extension_name: an extension name
3411 * @default_source: (allow-none): an #ESource, or %NULL
3413 * This is a convenience function to set a default #ESource based on
3414 * @extension_name. This only works with a subset of extension names.
3416 * If @extension_name is #E_SOURCE_EXTENSION_ADDRESS_BOOK, the function
3417 * sets @default_source as the default address book. If @default_source
3418 * is %NULL, the default address book is reset to the built-in address book.
3420 * If @extension_name is #E_SOURCE_EXTENSION_CALENDAR, the function sets
3421 * @default_source as the default calendar. If @default_source is %NULL,
3422 * the default calendar is reset to the built-in calendar.
3424 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_ACCOUNT, the function
3425 * sets @default_source as the default mail account. If @default_source
3426 * is %NULL, the default mail account is reset to the built-in mail account.
3428 * If @extension_name is #E_SOURCE_EXTENSION_MAIL_IDENTITY, the function
3429 * sets @default_source as the default mail identity. If @default_source
3430 * is %NULL, the next request for the default mail identity will return
3431 * the mail identity named by the default mail account.
3433 * If @extension_name is #E_SOURCE_EXTENSION_MEMO_LIST, the function sets
3434 * @default_source as the default memo list. If @default_source is %NULL,
3435 * the default memo list is reset to the built-in memo list.
3437 * If @extension_name is #E_SOURCE_EXTENSION_TASK_LIST, the function sets
3438 * @default_source as the default task list. If @default_source is %NULL,
3439 * the default task list is reset to the built-in task list.
3441 * For all other values of @extension_name, the function does nothing.
3446 e_source_registry_set_default_for_extension_name (ESourceRegistry *registry,
3447 const gchar *extension_name,
3448 ESource *default_source)
3450 g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
3451 g_return_if_fail (extension_name != NULL);
3453 if (strcmp (extension_name, E_SOURCE_EXTENSION_ADDRESS_BOOK) == 0)
3454 e_source_registry_set_default_address_book (
3455 registry, default_source);
3457 if (strcmp (extension_name, E_SOURCE_EXTENSION_CALENDAR) == 0)
3458 e_source_registry_set_default_calendar (
3459 registry, default_source);
3461 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_ACCOUNT) == 0)
3462 e_source_registry_set_default_mail_account (
3463 registry, default_source);
3465 if (strcmp (extension_name, E_SOURCE_EXTENSION_MAIL_IDENTITY) == 0)
3466 e_source_registry_set_default_mail_identity (
3467 registry, default_source);
3469 if (strcmp (extension_name, E_SOURCE_EXTENSION_MEMO_LIST) == 0)
3470 e_source_registry_set_default_memo_list (
3471 registry, default_source);
3473 if (strcmp (extension_name, E_SOURCE_EXTENSION_TASK_LIST) == 0)
3474 e_source_registry_set_default_task_list (
3475 registry, default_source);