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/>
18 * Copyright (C) 2011 Red Hat, Inc. (www.redhat.com)
26 #include <glib/gi18n-lib.h>
29 #include <libedataserver/e-data-server-util.h>
31 #include "e-gdbus-marshallers.h"
34 #include "e-client-private.h"
36 #define E_CLIENT_GET_PRIVATE(obj) \
37 (G_TYPE_INSTANCE_GET_PRIVATE \
38 ((obj), E_TYPE_CLIENT, EClientPrivate))
40 struct _EClientPrivate {
48 gboolean capabilities_retrieved;
51 GHashTable *backend_property_cache;
55 GHashTable *ops; /* opid to GCancellable */
71 BACKEND_PROPERTY_CHANGED,
75 static guint signals[LAST_SIGNAL];
77 G_DEFINE_ABSTRACT_TYPE (EClient, e_client, G_TYPE_OBJECT)
80 * Well-known client backend properties, which are common for each #EClient:
81 * @CLIENT_BACKEND_PROPERTY_OPENED: Is set to "TRUE" or "FALSE" depending
82 * whether the backend is fully opened.
83 * @CLIENT_BACKEND_PROPERTY_OPENING: Is set to "TRUE" or "FALSE" depending
84 * whether the backend is processing its opening phase.
85 * @CLIENT_BACKEND_PROPERTY_ONLINE: Is set to "TRUE" or "FALSE" depending
86 * on the backend's loaded state. See also e_client_is_online().
87 * @CLIENT_BACKEND_PROPERTY_READONLY: Is set to "TRUE" or "FALSE" depending
88 * on the backend's readonly state. See also e_client_is_readonly().
89 * @CLIENT_BACKEND_PROPERTY_CACHE_DIR: Local folder with cached data used
91 * @CLIENT_BACKEND_PROPERTY_CAPABILITIES: Retrieves comma-separated list
92 * of capabilities supported by the backend. Preferred method of retreiving
93 * and working with capabilities is e_client_get_capabilities() and
94 * e_client_check_capability().
97 G_DEFINE_QUARK (e-client-error-quark, e_client_error)
100 * e_client_error_to_string:
102 * FIXME: Document me.
107 e_client_error_to_string (EClientError code)
110 case E_CLIENT_ERROR_INVALID_ARG:
111 return _("Invalid argument");
112 case E_CLIENT_ERROR_BUSY:
113 return _("Backend is busy");
114 case E_CLIENT_ERROR_SOURCE_NOT_LOADED:
115 return _("Source not loaded");
116 case E_CLIENT_ERROR_SOURCE_ALREADY_LOADED:
117 return _("Source already loaded");
118 case E_CLIENT_ERROR_AUTHENTICATION_FAILED:
119 return _("Authentication failed");
120 case E_CLIENT_ERROR_AUTHENTICATION_REQUIRED:
121 return _("Authentication required");
122 case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
123 return _("Repository offline");
124 case E_CLIENT_ERROR_OFFLINE_UNAVAILABLE:
125 /* Translators: This means that the EClient does not support offline mode, or
126 * it's not set to by a user, thus it is unavailable while user is not connected. */
127 return _("Offline unavailable");
128 case E_CLIENT_ERROR_PERMISSION_DENIED:
129 return _("Permission denied");
130 case E_CLIENT_ERROR_CANCELLED:
131 return _("Cancelled");
132 case E_CLIENT_ERROR_COULD_NOT_CANCEL:
133 return _("Could not cancel");
134 case E_CLIENT_ERROR_NOT_SUPPORTED:
135 return _("Not supported");
136 case E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD:
137 return _("Unsupported authentication method");
138 case E_CLIENT_ERROR_TLS_NOT_AVAILABLE:
139 return _("TLS not available");
140 case E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED:
141 return _("Search size limit exceeded");
142 case E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED:
143 return _("Search time limit exceeded");
144 case E_CLIENT_ERROR_INVALID_QUERY:
145 return _("Invalid query");
146 case E_CLIENT_ERROR_QUERY_REFUSED:
147 return _("Query refused");
148 case E_CLIENT_ERROR_DBUS_ERROR:
149 return _("D-Bus error");
150 case E_CLIENT_ERROR_OTHER_ERROR:
151 return _("Other error");
152 case E_CLIENT_ERROR_NOT_OPENED:
153 return _("Backend is not opened yet");
156 return _("Unknown error");
160 * e_client_error_create:
161 * @code: an #EClientError code to create
162 * @custom_msg: custom message to use for the error; can be %NULL
164 * Returns: a new #GError containing an E_CLIENT_ERROR of the given
165 * @code. If the @custom_msg is NULL, then the error message is
166 * the one returned from e_client_error_to_string() for the @code,
167 * otherwise the given message is used.
169 * Returned pointer should be freed with g_error_free().
174 e_client_error_create (EClientError code,
175 const gchar *custom_msg)
177 return g_error_new_literal (E_CLIENT_ERROR, code, custom_msg ? custom_msg : e_client_error_to_string (code));
180 static void client_set_source (EClient *client, ESource *source);
183 e_client_init (EClient *client)
185 client->priv = E_CLIENT_GET_PRIVATE (client);
187 client->priv->readonly = TRUE;
189 g_rec_mutex_init (&client->priv->prop_mutex);
190 client->priv->backend_property_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
192 g_rec_mutex_init (&client->priv->ops_mutex);
193 client->priv->last_opid = 0;
194 client->priv->ops = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
198 client_dispose (GObject *object)
202 client = E_CLIENT (object);
204 e_client_cancel_all (client);
206 /* Chain up to parent's dispose() method. */
207 G_OBJECT_CLASS (e_client_parent_class)->dispose (object);
211 client_finalize (GObject *object)
214 EClientPrivate *priv;
216 client = E_CLIENT (object);
220 g_rec_mutex_lock (&priv->prop_mutex);
223 g_object_unref (priv->source);
232 if (priv->capabilities) {
233 g_slist_foreach (priv->capabilities, (GFunc) g_free, NULL);
234 g_slist_free (priv->capabilities);
235 priv->capabilities = NULL;
238 if (priv->backend_property_cache) {
239 g_hash_table_destroy (priv->backend_property_cache);
240 priv->backend_property_cache = NULL;
244 g_hash_table_destroy (priv->ops);
248 g_rec_mutex_unlock (&priv->prop_mutex);
249 g_rec_mutex_clear (&priv->prop_mutex);
250 g_rec_mutex_clear (&priv->ops_mutex);
252 /* Chain up to parent's finalize() method. */
253 G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
257 client_set_property (GObject *object,
262 switch (property_id) {
264 client_set_source (E_CLIENT (object), g_value_get_object (value));
268 e_client_set_online (E_CLIENT (object), g_value_get_boolean (value));
272 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
276 client_get_property (GObject *object,
281 switch (property_id) {
283 g_value_set_object (value, e_client_get_source (E_CLIENT (object)));
286 case PROP_CAPABILITIES:
287 g_value_set_pointer (value, (gpointer) e_client_get_capabilities (E_CLIENT (object)));
291 g_value_set_boolean (value, e_client_is_readonly (E_CLIENT (object)));
295 g_value_set_boolean (value, e_client_is_online (E_CLIENT (object)));
299 g_value_set_boolean (value, e_client_is_opened (E_CLIENT (object)));
303 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
307 client_remove_thread (GSimpleAsyncResult *simple,
309 GCancellable *cancellable)
311 GError *error = NULL;
313 e_client_remove_sync (E_CLIENT (object), cancellable, &error);
316 g_simple_async_result_take_error (simple, error);
320 client_remove (EClient *client,
321 GCancellable *cancellable,
322 GAsyncReadyCallback callback,
325 GSimpleAsyncResult *simple;
327 simple = g_simple_async_result_new (
328 G_OBJECT (client), callback, user_data, client_remove);
330 g_simple_async_result_set_check_cancellable (simple, cancellable);
332 g_simple_async_result_run_in_thread (
333 simple, client_remove_thread,
334 G_PRIORITY_DEFAULT, cancellable);
336 g_object_unref (simple);
340 client_remove_finish (EClient *client,
341 GAsyncResult *result,
344 GSimpleAsyncResult *simple;
346 g_return_val_if_fail (
347 g_simple_async_result_is_valid (
348 result, G_OBJECT (client), client_remove), FALSE);
350 simple = G_SIMPLE_ASYNC_RESULT (result);
352 /* Assume success unless a GError is set. */
353 return !g_simple_async_result_propagate_error (simple, error);
357 client_remove_sync (EClient *client,
358 GCancellable *cancellable,
363 source = e_client_get_source (client);
365 return e_source_remove_sync (source, cancellable, error);
369 e_client_class_init (EClientClass *class)
371 GObjectClass *object_class;
373 g_type_class_add_private (class, sizeof (EClientPrivate));
375 object_class = G_OBJECT_CLASS (class);
376 object_class->set_property = client_set_property;
377 object_class->get_property = client_get_property;
378 object_class->dispose = client_dispose;
379 object_class->finalize = client_finalize;
381 class->remove = client_remove;
382 class->remove_finish = client_remove_finish;
383 class->remove_sync = client_remove_sync;
385 g_object_class_install_property (
388 g_param_spec_object (
393 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
395 g_object_class_install_property (
398 g_param_spec_pointer (
404 g_object_class_install_property (
407 g_param_spec_boolean (
414 g_object_class_install_property (
417 g_param_spec_boolean (
424 g_object_class_install_property (
427 g_param_spec_boolean (
434 signals[OPENED] = g_signal_new (
436 G_OBJECT_CLASS_TYPE (class),
438 G_STRUCT_OFFSET (EClientClass, opened),
440 g_cclosure_marshal_VOID__BOXED,
444 signals[BACKEND_ERROR] = g_signal_new (
446 G_OBJECT_CLASS_TYPE (class),
448 G_STRUCT_OFFSET (EClientClass, backend_error),
450 g_cclosure_marshal_VOID__STRING,
454 signals[BACKEND_DIED] = g_signal_new (
456 G_OBJECT_CLASS_TYPE (class),
458 G_STRUCT_OFFSET (EClientClass, backend_died),
460 g_cclosure_marshal_VOID__VOID,
463 signals[BACKEND_PROPERTY_CHANGED] = g_signal_new (
464 "backend-property-changed",
465 G_OBJECT_CLASS_TYPE (class),
467 G_STRUCT_OFFSET (EClientClass, backend_property_changed),
469 e_gdbus_marshallers_VOID__STRING_STRING,
470 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
474 client_set_source (EClient *client,
477 g_return_if_fail (E_IS_CLIENT (client));
478 g_return_if_fail (E_IS_SOURCE (source));
480 g_object_ref (source);
482 if (client->priv->source)
483 g_object_unref (client->priv->source);
485 client->priv->source = source;
489 * e_client_get_source:
490 * @client: an #EClient
492 * Get the #ESource that this client has assigned.
494 * Returns: (transfer none): The source.
499 e_client_get_source (EClient *client)
501 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
503 return client->priv->source;
507 client_ensure_capabilities (EClient *client)
511 g_return_if_fail (E_IS_CLIENT (client));
513 if (client->priv->capabilities_retrieved || client->priv->capabilities)
516 g_rec_mutex_lock (&client->priv->prop_mutex);
519 e_client_retrieve_capabilities_sync (client, &capabilities, NULL, NULL);
520 /* e_client_set_capabilities is called inside the previous function */
521 g_free (capabilities);
523 client->priv->capabilities_retrieved = TRUE;
525 g_rec_mutex_unlock (&client->priv->prop_mutex);
529 * e_client_get_capabilities:
530 * @client: an #EClient
532 * Get list of strings with capabilities advertised by a backend.
533 * This list, together with inner strings, is owned by the @client.
534 * To check for individual capabilities use e_client_check_capability().
536 * Returns: (element-type utf8) (transfer none): #GSList of const strings
542 e_client_get_capabilities (EClient *client)
544 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
546 client_ensure_capabilities (client);
548 return client->priv->capabilities;
552 * e_client_check_capability:
553 * @client: an #EClient
554 * @capability: a capability
556 * Check if backend supports particular capability.
557 * To get all capabilities use e_client_get_capabilities().
559 * Returns: #GSList of const strings of capabilities
564 e_client_check_capability (EClient *client,
565 const gchar *capability)
569 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
570 g_return_val_if_fail (capability, FALSE);
572 g_rec_mutex_lock (&client->priv->prop_mutex);
574 client_ensure_capabilities (client);
576 for (iter = client->priv->capabilities; iter; iter = g_slist_next (iter)) {
577 const gchar *cap = iter->data;
579 if (cap && g_ascii_strcasecmp (cap, capability) == 0) {
580 g_rec_mutex_unlock (&client->priv->prop_mutex);
585 g_rec_mutex_unlock (&client->priv->prop_mutex);
591 * e_client_check_refresh_supported:
594 * Checks whether a client supports explicit refreshing
595 * (see e_client_refresh()).
597 * Returns: TRUE if the client supports refreshing, FALSE otherwise.
602 e_client_check_refresh_supported (EClient *client)
604 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
606 return e_client_check_capability (client, "refresh-supported");
609 /* capabilities - comma-separated list of capabilities; can be NULL to unset */
611 e_client_set_capabilities (EClient *client,
612 const gchar *capabilities)
614 g_return_if_fail (E_IS_CLIENT (client));
616 g_rec_mutex_lock (&client->priv->prop_mutex);
619 client->priv->capabilities_retrieved = FALSE;
621 g_slist_foreach (client->priv->capabilities, (GFunc) g_free, NULL);
622 g_slist_free (client->priv->capabilities);
623 client->priv->capabilities = e_client_util_parse_comma_strings (capabilities);
625 g_rec_mutex_unlock (&client->priv->prop_mutex);
627 g_object_notify (G_OBJECT (client), "capabilities");
631 * e_client_is_readonly:
632 * @client: an #EClient
634 * Check if this @client is read-only.
636 * Returns: %TRUE if this @client is read-only, otherwise %FALSE.
641 e_client_is_readonly (EClient *client)
643 g_return_val_if_fail (E_IS_CLIENT (client), TRUE);
645 return client->priv->readonly;
649 e_client_set_readonly (EClient *client,
652 g_return_if_fail (E_IS_CLIENT (client));
654 g_rec_mutex_lock (&client->priv->prop_mutex);
655 if (client->priv->readonly == readonly) {
656 g_rec_mutex_unlock (&client->priv->prop_mutex);
660 client->priv->readonly = readonly;
662 g_rec_mutex_unlock (&client->priv->prop_mutex);
664 g_object_notify (G_OBJECT (client), "readonly");
668 * e_client_is_online:
669 * @client: an #EClient
671 * Check if this @client is connected.
673 * Returns: %TRUE if this @client is connected, otherwise %FALSE.
678 e_client_is_online (EClient *client)
680 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
682 return client->priv->online;
686 e_client_set_online (EClient *client,
689 g_return_if_fail (E_IS_CLIENT (client));
691 /* newly connected/disconnected => make sure capabilities will be correct */
692 e_client_set_capabilities (client, NULL);
694 g_rec_mutex_lock (&client->priv->prop_mutex);
695 if (client->priv->online == is_online) {
696 g_rec_mutex_unlock (&client->priv->prop_mutex);
700 client->priv->online = is_online;
702 g_rec_mutex_unlock (&client->priv->prop_mutex);
704 g_object_notify (G_OBJECT (client), "online");
708 * e_client_is_opened:
709 * @client: an #EClient
711 * Check if this @client is fully opened. This includes
712 * everything from e_client_open() call up to the authentication,
713 * if required by a backend. Client cannot do any other operation
714 * during the opening phase except of authenticate or cancel it.
715 * Every other operation results in an %E_CLIENT_ERROR_BUSY error.
717 * Returns: %TRUE if this @client is fully opened, otherwise %FALSE.
722 e_client_is_opened (EClient *client)
724 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
726 return client->priv->opened;
731 * @client: an #EClient
732 * @opid: asynchronous operation ID
734 * Cancels particular asynchronous operation. The @opid is returned from
735 * an e_client_register_op(). The function does nothing if the asynchronous
736 * operation doesn't exist any more.
741 client_cancel_op (EClient *client,
744 GCancellable *cancellable;
746 g_return_if_fail (E_IS_CLIENT (client));
747 g_return_if_fail (client->priv->ops != NULL);
749 g_rec_mutex_lock (&client->priv->ops_mutex);
751 cancellable = g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (opid));
753 g_cancellable_cancel (cancellable);
755 g_rec_mutex_unlock (&client->priv->ops_mutex);
759 gather_opids_cb (gpointer opid,
760 gpointer cancellable,
763 GSList **ids = ids_list;
765 g_return_if_fail (ids_list != NULL);
767 *ids = g_slist_prepend (*ids, opid);
771 cancel_op_cb (gpointer opid,
774 client_cancel_op (client, GPOINTER_TO_INT (opid));
778 * e_client_cancel_all:
779 * @client: an #EClient
781 * Cancels all pending operations started on @client.
786 e_client_cancel_all (EClient *client)
788 GSList *opids = NULL;
790 g_return_if_fail (E_IS_CLIENT (client));
791 g_return_if_fail (client->priv->ops != NULL);
793 g_rec_mutex_lock (&client->priv->ops_mutex);
795 g_hash_table_foreach (client->priv->ops, gather_opids_cb, &opids);
797 g_slist_foreach (opids, cancel_op_cb, client);
798 g_slist_free (opids);
800 g_rec_mutex_unlock (&client->priv->ops_mutex);
804 e_client_register_op (EClient *client,
805 GCancellable *cancellable)
809 g_return_val_if_fail (E_IS_CLIENT (client), 0);
810 g_return_val_if_fail (client->priv->ops != NULL, 0);
811 g_return_val_if_fail (cancellable != NULL, 0);
813 g_rec_mutex_lock (&client->priv->ops_mutex);
815 client->priv->last_opid++;
816 if (!client->priv->last_opid)
817 client->priv->last_opid++;
819 while (g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (client->priv->last_opid)))
820 client->priv->last_opid++;
822 g_return_val_if_fail (client->priv->last_opid != 0, 0);
824 opid = client->priv->last_opid;
825 g_hash_table_insert (client->priv->ops, GINT_TO_POINTER (opid), g_object_ref (cancellable));
827 g_rec_mutex_unlock (&client->priv->ops_mutex);
833 e_client_unregister_op (EClient *client,
836 g_return_if_fail (E_IS_CLIENT (client));
837 g_return_if_fail (client->priv->ops != NULL);
839 g_rec_mutex_lock (&client->priv->ops_mutex);
840 g_hash_table_remove (client->priv->ops, GINT_TO_POINTER (opid));
841 g_rec_mutex_unlock (&client->priv->ops_mutex);
845 e_client_emit_opened (EClient *client,
846 const GError *dbus_error)
848 GError *local_error = NULL;
850 g_return_if_fail (E_IS_CLIENT (client));
852 client->priv->opened = dbus_error == NULL;
855 local_error = g_error_copy (dbus_error);
856 e_client_unwrap_dbus_error (client, local_error, &local_error);
859 g_object_notify (G_OBJECT (client), "opened");
860 g_signal_emit (client, signals[OPENED], 0, local_error);
863 g_error_free (local_error);
867 e_client_emit_backend_error (EClient *client,
868 const gchar *error_msg)
870 g_return_if_fail (E_IS_CLIENT (client));
871 g_return_if_fail (error_msg != NULL);
873 g_signal_emit (client, signals[BACKEND_ERROR], 0, error_msg);
877 e_client_emit_backend_died (EClient *client)
879 g_return_if_fail (E_IS_CLIENT (client));
881 g_signal_emit (client, signals[BACKEND_DIED], 0);
885 e_client_emit_backend_property_changed (EClient *client,
886 const gchar *prop_name,
887 const gchar *prop_value)
889 g_return_if_fail (E_IS_CLIENT (client));
890 g_return_if_fail (prop_name != NULL);
891 g_return_if_fail (*prop_name);
892 g_return_if_fail (prop_value != NULL);
894 e_client_update_backend_property_cache (client, prop_name, prop_value);
896 g_signal_emit (client, signals[BACKEND_PROPERTY_CHANGED], 0, prop_name, prop_value);
900 e_client_update_backend_property_cache (EClient *client,
901 const gchar *prop_name,
902 const gchar *prop_value)
904 g_return_if_fail (E_IS_CLIENT (client));
905 g_return_if_fail (prop_name != NULL);
906 g_return_if_fail (*prop_name);
907 g_return_if_fail (prop_value != NULL);
909 g_rec_mutex_lock (&client->priv->prop_mutex);
911 if (client->priv->backend_property_cache)
912 g_hash_table_insert (client->priv->backend_property_cache, g_strdup (prop_name), g_strdup (prop_value));
914 g_rec_mutex_unlock (&client->priv->prop_mutex);
918 e_client_get_backend_property_from_cache (EClient *client,
919 const gchar *prop_name)
921 gchar *prop_value = NULL;
923 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
924 g_return_val_if_fail (prop_name != NULL, NULL);
925 g_return_val_if_fail (*prop_name, NULL);
927 g_rec_mutex_lock (&client->priv->prop_mutex);
929 if (client->priv->backend_property_cache)
930 prop_value = g_strdup (g_hash_table_lookup (client->priv->backend_property_cache, prop_name));
932 g_rec_mutex_unlock (&client->priv->prop_mutex);
938 * e_client_retrieve_capabilities:
939 * @client: an #EClient
940 * @cancellable: a #GCancellable; can be %NULL
941 * @callback: callback to call when a result is ready
942 * @user_data: user data for the @callback
944 * Initiates retrieval of capabilities on the @client. This is usually
945 * required only once, after the @client is opened. The returned value
946 * is cached and any subsequent call of e_client_get_capabilities() and
947 * e_client_check_capability() is using the cached value.
948 * The call is finished by e_client_retrieve_capabilities_finish()
949 * from the @callback.
954 e_client_retrieve_capabilities (EClient *client,
955 GCancellable *cancellable,
956 GAsyncReadyCallback callback,
961 g_return_if_fail (E_IS_CLIENT (client));
962 g_return_if_fail (callback != NULL);
964 class = E_CLIENT_GET_CLASS (client);
965 g_return_if_fail (class != NULL);
966 g_return_if_fail (class->retrieve_capabilities != NULL);
968 class->retrieve_capabilities (client, cancellable, callback, user_data);
972 * e_client_retrieve_capabilities_finish:
973 * @client: an #EClient
974 * @result: a #GAsyncResult
975 * @capabilities: (out): Comma-separated list of capabilities of the @client
976 * @error: (out): a #GError to set an error, if any
978 * Finishes previous call of e_client_retrieve_capabilities().
979 * Returned value of @capabilities should be freed with g_free(),
980 * when no longer needed.
982 * Returns: %TRUE if successful, %FALSE otherwise.
987 e_client_retrieve_capabilities_finish (EClient *client,
988 GAsyncResult *result,
989 gchar **capabilities,
995 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
996 g_return_val_if_fail (capabilities != NULL, FALSE);
998 class = E_CLIENT_GET_CLASS (client);
999 g_return_val_if_fail (class != NULL, FALSE);
1000 g_return_val_if_fail (class->retrieve_capabilities_finish != NULL, FALSE);
1002 *capabilities = NULL;
1003 res = class->retrieve_capabilities_finish (client, result, capabilities, error);
1005 e_client_set_capabilities (client, res ? *capabilities : NULL);
1007 if (error && *error)
1008 e_client_unwrap_dbus_error (client, *error, error);
1014 * e_client_retrieve_capabilities_sync:
1015 * @client: an #EClient
1016 * @capabilities: (out): Comma-separated list of capabilities of the @client
1017 * @cancellable: a #GCancellable; can be %NULL
1018 * @error: (out): a #GError to set an error, if any
1020 * Initiates retrieval of capabilities on the @client. This is usually
1021 * required only once, after the @client is opened. The returned value
1022 * is cached and any subsequent call of e_client_get_capabilities() and
1023 * e_client_check_capability() is using the cached value. Returned value
1024 * of @capabilities should be freed with g_free(), when no longer needed.
1026 * Returns: %TRUE if successful, %FALSE otherwise.
1031 e_client_retrieve_capabilities_sync (EClient *client,
1032 gchar **capabilities,
1033 GCancellable *cancellable,
1036 EClientClass *class;
1037 gboolean res = FALSE;
1039 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1040 g_return_val_if_fail (capabilities != NULL, FALSE);
1042 class = E_CLIENT_GET_CLASS (client);
1043 g_return_val_if_fail (class != NULL, FALSE);
1044 g_return_val_if_fail (class->retrieve_capabilities_sync != NULL, FALSE);
1046 *capabilities = NULL;
1047 res = class->retrieve_capabilities_sync (client, capabilities, cancellable, error);
1049 e_client_set_capabilities (client, res ? *capabilities : NULL);
1051 if (error && *error)
1052 e_client_unwrap_dbus_error (client, *error, error);
1058 * e_client_get_backend_property:
1059 * @client: an #EClient
1060 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1061 * @cancellable: a #GCancellable; can be %NULL
1062 * @callback: callback to call when a result is ready
1063 * @user_data: user data for the @callback
1065 * Queries @client's backend for a property of name @prop_name.
1066 * The call is finished by e_client_get_backend_property_finish()
1067 * from the @callback.
1072 e_client_get_backend_property (EClient *client,
1073 const gchar *prop_name,
1074 GCancellable *cancellable,
1075 GAsyncReadyCallback callback,
1078 EClientClass *class;
1080 g_return_if_fail (callback != NULL);
1081 g_return_if_fail (E_IS_CLIENT (client));
1082 g_return_if_fail (prop_name != NULL);
1084 class = E_CLIENT_GET_CLASS (client);
1085 g_return_if_fail (class != NULL);
1086 g_return_if_fail (class->get_backend_property != NULL);
1088 class->get_backend_property (client, prop_name, cancellable, callback, user_data);
1092 * e_client_get_backend_property_finish:
1093 * @client: an #EClient
1094 * @result: a #GAsyncResult
1095 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1096 * @error: (out): a #GError to set an error, if any
1098 * Finishes previous call of e_client_get_backend_property().
1100 * Returns: %TRUE if successful, %FALSE otherwise.
1105 e_client_get_backend_property_finish (EClient *client,
1106 GAsyncResult *result,
1110 EClientClass *class;
1113 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1114 g_return_val_if_fail (prop_value != NULL, FALSE);
1116 class = E_CLIENT_GET_CLASS (client);
1117 g_return_val_if_fail (class != NULL, FALSE);
1118 g_return_val_if_fail (class->get_backend_property_finish != NULL, FALSE);
1120 res = class->get_backend_property_finish (client, result, prop_value, error);
1122 if (error && *error)
1123 e_client_unwrap_dbus_error (client, *error, error);
1129 * e_client_get_backend_property_sync:
1130 * @client: an #EClient
1131 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1132 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1133 * @cancellable: a #GCancellable; can be %NULL
1134 * @error: (out): a #GError to set an error, if any
1136 * Queries @client's backend for a property of name @prop_name.
1138 * Returns: %TRUE if successful, %FALSE otherwise.
1143 e_client_get_backend_property_sync (EClient *client,
1144 const gchar *prop_name,
1146 GCancellable *cancellable,
1149 EClientClass *class;
1152 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1153 g_return_val_if_fail (prop_name != NULL, FALSE);
1154 g_return_val_if_fail (prop_value != NULL, FALSE);
1156 class = E_CLIENT_GET_CLASS (client);
1157 g_return_val_if_fail (class != NULL, FALSE);
1158 g_return_val_if_fail (class->get_backend_property_sync != NULL, FALSE);
1160 res = class->get_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1162 if (error && *error)
1163 e_client_unwrap_dbus_error (client, *error, error);
1169 * e_client_set_backend_property:
1170 * @client: an #EClient
1171 * @prop_name: property name, whose value to change; cannot be %NULL
1172 * @prop_value: property value, to set; cannot be %NULL
1173 * @cancellable: a #GCancellable; can be %NULL
1174 * @callback: callback to call when a result is ready
1175 * @user_data: user data for the @callback
1177 * Sets @client's backend property of name @prop_name
1178 * to value @prop_value. The call is finished
1179 * by e_client_set_backend_property_finish() from the @callback.
1184 e_client_set_backend_property (EClient *client,
1185 const gchar *prop_name,
1186 const gchar *prop_value,
1187 GCancellable *cancellable,
1188 GAsyncReadyCallback callback,
1191 EClientClass *class;
1193 g_return_if_fail (callback != NULL);
1194 g_return_if_fail (E_IS_CLIENT (client));
1195 g_return_if_fail (prop_name != NULL);
1196 g_return_if_fail (prop_value != NULL);
1198 class = E_CLIENT_GET_CLASS (client);
1199 g_return_if_fail (class != NULL);
1200 g_return_if_fail (class->set_backend_property != NULL);
1202 class->set_backend_property (client, prop_name, prop_value, cancellable, callback, user_data);
1206 * e_client_set_backend_property_finish:
1207 * @client: an #EClient
1208 * @result: a #GAsyncResult
1209 * @error: (out): a #GError to set an error, if any
1211 * Finishes previous call of e_client_set_backend_property().
1213 * Returns: %TRUE if successful, %FALSE otherwise.
1218 e_client_set_backend_property_finish (EClient *client,
1219 GAsyncResult *result,
1222 EClientClass *class;
1225 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1227 class = E_CLIENT_GET_CLASS (client);
1228 g_return_val_if_fail (class != NULL, FALSE);
1229 g_return_val_if_fail (class->set_backend_property_finish != NULL, FALSE);
1231 res = class->set_backend_property_finish (client, result, error);
1233 if (error && *error)
1234 e_client_unwrap_dbus_error (client, *error, error);
1240 * e_client_set_backend_property_sync:
1241 * @client: an #EClient
1242 * @prop_name: property name, whose value to change; cannot be %NULL
1243 * @prop_value: property value, to set; cannot be %NULL
1244 * @cancellable: a #GCancellable; can be %NULL
1245 * @error: (out): a #GError to set an error, if any
1247 * Sets @client's backend property of name @prop_name
1248 * to value @prop_value.
1250 * Returns: %TRUE if successful, %FALSE otherwise.
1255 e_client_set_backend_property_sync (EClient *client,
1256 const gchar *prop_name,
1257 const gchar *prop_value,
1258 GCancellable *cancellable,
1261 EClientClass *class;
1264 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1265 g_return_val_if_fail (prop_name != NULL, FALSE);
1266 g_return_val_if_fail (prop_value != NULL, FALSE);
1268 class = E_CLIENT_GET_CLASS (client);
1269 g_return_val_if_fail (class != NULL, FALSE);
1270 g_return_val_if_fail (class->set_backend_property_sync != NULL, FALSE);
1272 res = class->set_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1274 if (error && *error)
1275 e_client_unwrap_dbus_error (client, *error, error);
1282 * @client: an #EClient
1283 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1284 * @cancellable: a #GCancellable; can be %NULL
1285 * @callback: callback to call when a result is ready
1286 * @user_data: user data for the @callback
1288 * Opens the @client, making it ready for queries and other operations.
1289 * The call is finished by e_client_open_finish() from the @callback.
1294 e_client_open (EClient *client,
1295 gboolean only_if_exists,
1296 GCancellable *cancellable,
1297 GAsyncReadyCallback callback,
1300 EClientClass *class;
1302 g_return_if_fail (callback != NULL);
1303 g_return_if_fail (E_IS_CLIENT (client));
1305 class = E_CLIENT_GET_CLASS (client);
1306 g_return_if_fail (class != NULL);
1307 g_return_if_fail (class->open != NULL);
1309 class->open (client, only_if_exists, cancellable, callback, user_data);
1313 * e_client_open_finish:
1314 * @client: an #EClient
1315 * @result: a #GAsyncResult
1316 * @error: (out): a #GError to set an error, if any
1318 * Finishes previous call of e_client_open().
1320 * Returns: %TRUE if successful, %FALSE otherwise.
1325 e_client_open_finish (EClient *client,
1326 GAsyncResult *result,
1329 EClientClass *class;
1332 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1334 class = E_CLIENT_GET_CLASS (client);
1335 g_return_val_if_fail (class != NULL, FALSE);
1336 g_return_val_if_fail (class->open_finish != NULL, FALSE);
1338 res = class->open_finish (client, result, error);
1340 if (error && *error)
1341 e_client_unwrap_dbus_error (client, *error, error);
1347 * e_client_open_sync:
1348 * @client: an #EClient
1349 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1350 * @cancellable: a #GCancellable; can be %NULL
1351 * @error: (out): a #GError to set an error, if any
1353 * Opens the @client, making it ready for queries and other operations.
1355 * Returns: %TRUE if successful, %FALSE otherwise.
1360 e_client_open_sync (EClient *client,
1361 gboolean only_if_exists,
1362 GCancellable *cancellable,
1365 EClientClass *class;
1368 class = E_CLIENT_GET_CLASS (client);
1369 g_return_val_if_fail (class != NULL, FALSE);
1370 g_return_val_if_fail (class->open_sync != NULL, FALSE);
1372 res = class->open_sync (client, only_if_exists, cancellable, error);
1374 if (error && *error)
1375 e_client_unwrap_dbus_error (client, *error, error);
1382 * @client: an #EClient
1383 * @cancellable: a #GCancellable; can be %NULL
1384 * @callback: callback to call when a result is ready
1385 * @user_data: user data for the @callback
1387 * Removes the backing data for this #EClient. For example, with the file
1388 * backend this deletes the database file. You cannot get it back!
1389 * The call is finished by e_client_remove_finish() from the @callback.
1393 * Deprecated: 3.6: Use e_source_remove() instead.
1396 e_client_remove (EClient *client,
1397 GCancellable *cancellable,
1398 GAsyncReadyCallback callback,
1401 EClientClass *class;
1403 g_return_if_fail (E_IS_CLIENT (client));
1404 g_return_if_fail (callback != NULL);
1406 class = E_CLIENT_GET_CLASS (client);
1407 g_return_if_fail (class != NULL);
1408 g_return_if_fail (class->remove != NULL);
1410 class->remove (client, cancellable, callback, user_data);
1414 * e_client_remove_finish:
1415 * @client: an #EClient
1416 * @result: a #GAsyncResult
1417 * @error: (out): a #GError to set an error, if any
1419 * Finishes previous call of e_client_remove().
1421 * Returns: %TRUE if successful, %FALSE otherwise.
1425 * Deprecated: 3.6: Use e_source_remove_finish() instead.
1428 e_client_remove_finish (EClient *client,
1429 GAsyncResult *result,
1432 EClientClass *class;
1435 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1437 class = E_CLIENT_GET_CLASS (client);
1438 g_return_val_if_fail (class != NULL, FALSE);
1439 g_return_val_if_fail (class->remove_finish != NULL, FALSE);
1441 res = class->remove_finish (client, result, error);
1443 if (error && *error)
1444 e_client_unwrap_dbus_error (client, *error, error);
1450 * e_client_remove_sync:
1451 * @client: an #EClient
1452 * @cancellable: a #GCancellable; can be %NULL
1453 * @error: (out): a #GError to set an error, if any
1455 * Removes the backing data for this #EClient. For example, with the file
1456 * backend this deletes the database file. You cannot get it back!
1458 * Returns: %TRUE if successful, %FALSE otherwise.
1462 * Deprecated: 3.6: Use e_source_remove_sync() instead.
1465 e_client_remove_sync (EClient *client,
1466 GCancellable *cancellable,
1469 EClientClass *class;
1472 class = E_CLIENT_GET_CLASS (client);
1473 g_return_val_if_fail (class != NULL, FALSE);
1474 g_return_val_if_fail (class->remove_sync != NULL, FALSE);
1476 res = class->remove_sync (client, cancellable, error);
1478 if (error && *error)
1479 e_client_unwrap_dbus_error (client, *error, error);
1486 * @client: an #EClient
1487 * @cancellable: a #GCancellable; can be %NULL
1488 * @callback: callback to call when a result is ready
1489 * @user_data: user data for the @callback
1491 * Initiates refresh on the @client. Finishing the method doesn't mean
1492 * that the refresh is done, backend only notifies whether it started
1493 * refreshing or not. Use e_client_check_refresh_supported() to check
1494 * whether the backend supports this method.
1495 * The call is finished by e_client_refresh_finish() from the @callback.
1500 e_client_refresh (EClient *client,
1501 GCancellable *cancellable,
1502 GAsyncReadyCallback callback,
1505 EClientClass *class;
1507 g_return_if_fail (E_IS_CLIENT (client));
1508 g_return_if_fail (callback != NULL);
1510 class = E_CLIENT_GET_CLASS (client);
1511 g_return_if_fail (class != NULL);
1512 g_return_if_fail (class->refresh != NULL);
1514 class->refresh (client, cancellable, callback, user_data);
1518 * e_client_refresh_finish:
1519 * @client: an #EClient
1520 * @result: a #GAsyncResult
1521 * @error: (out): a #GError to set an error, if any
1523 * Finishes previous call of e_client_refresh().
1525 * Returns: %TRUE if successful, %FALSE otherwise.
1530 e_client_refresh_finish (EClient *client,
1531 GAsyncResult *result,
1534 EClientClass *class;
1537 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1539 class = E_CLIENT_GET_CLASS (client);
1540 g_return_val_if_fail (class != NULL, FALSE);
1541 g_return_val_if_fail (class->refresh_finish != NULL, FALSE);
1543 res = class->refresh_finish (client, result, error);
1545 if (error && *error)
1546 e_client_unwrap_dbus_error (client, *error, error);
1552 * e_client_refresh_sync:
1553 * @client: an #EClient
1554 * @cancellable: a #GCancellable; can be %NULL
1555 * @error: (out): a #GError to set an error, if any
1557 * Initiates refresh on the @client. Finishing the method doesn't mean
1558 * that the refresh is done, backend only notifies whether it started
1559 * refreshing or not. Use e_client_check_refresh_supported() to check
1560 * whether the backend supports this method.
1562 * Returns: %TRUE if successful, %FALSE otherwise.
1567 e_client_refresh_sync (EClient *client,
1568 GCancellable *cancellable,
1571 EClientClass *class;
1574 class = E_CLIENT_GET_CLASS (client);
1575 g_return_val_if_fail (class != NULL, FALSE);
1576 g_return_val_if_fail (class->refresh_sync != NULL, FALSE);
1578 res = class->refresh_sync (client, cancellable, error);
1580 if (error && *error)
1581 e_client_unwrap_dbus_error (client, *error, error);
1587 * e_client_util_slist_to_strv:
1588 * @strings: (element-type utf8): a #GSList of strings (const gchar *)
1590 * Convert a list of strings into a %NULL-terminated array of strings.
1592 * Returns: (transfer full): Newly allocated %NULL-terminated array of strings.
1593 * The returned pointer should be freed with g_strfreev().
1595 * Note: Paired function for this is e_client_util_strv_to_slist().
1599 * Deprecated: 3.8: Use e_util_slist_to_strv() instead.
1602 e_client_util_slist_to_strv (const GSList *strings)
1604 return e_util_slist_to_strv (strings);
1608 * e_client_util_strv_to_slist:
1609 * @strv: a %NULL-terminated array of strings (const gchar *)
1611 * Convert a %NULL-terminated array of strings to a list of strings.
1613 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
1614 * newly allocated strings. The returned pointer should be freed with
1615 * e_client_util_free_string_slist().
1617 * Note: Paired function for this is e_client_util_slist_to_strv().
1621 * Deprecated: 3.8: Use e_util_strv_to_slist() instead.
1624 e_client_util_strv_to_slist (const gchar * const *strv)
1626 return e_util_strv_to_slist (strv);
1630 * e_client_util_copy_string_slist:
1631 * @copy_to: (element-type utf8) (allow-none): Where to copy; may be %NULL
1632 * @strings: (element-type utf8): #GSList of strings to be copied
1634 * Copies the #GSList of strings to the end of @copy_to.
1636 * Returns: (transfer full) (element-type utf8): New head of @copy_to.
1637 * The returned pointer can be freed with e_client_util_free_string_slist().
1641 * Deprecated: 3.8: Use e_util_copy_string_slist() instead.
1644 e_client_util_copy_string_slist (GSList *copy_to,
1645 const GSList *strings)
1647 return e_util_copy_string_slist (copy_to, strings);
1651 * e_client_util_copy_object_slist:
1652 * @copy_to: (element-type GObject) (allow-none): Where to copy; may be %NULL
1653 * @objects: (element-type GObject): #GSList of #GObject<!-- -->s to be copied
1655 * Copies a #GSList of #GObject<!-- -->s to the end of @copy_to.
1657 * Returns: (transfer full) (element-type GObject): New head of @copy_to.
1658 * The returned pointer can be freed with e_client_util_free_object_slist().
1662 * Deprecated: 3.8: Use e_util_copy_object_slist() instead.
1665 e_client_util_copy_object_slist (GSList *copy_to,
1666 const GSList *objects)
1668 return e_util_copy_object_slist (copy_to, objects);
1672 * e_client_util_free_string_slist:
1673 * @strings: (element-type utf8): a #GSList of strings (gchar *)
1675 * Frees memory previously allocated by e_client_util_strv_to_slist().
1679 * Deprecated: 3.8: Use g_slist_free_full() instead.
1682 e_client_util_free_string_slist (GSList *strings)
1684 e_util_free_string_slist (strings);
1688 * e_client_util_free_object_slist:
1689 * @objects: (element-type GObject): a #GSList of #GObject<!-- -->s
1691 * Calls g_object_unref() on each member of @objects and then frees @objects
1696 * Deprecated: 3.8: Use g_slist_free_full() instead.
1699 e_client_util_free_object_slist (GSList *objects)
1701 e_util_free_object_slist (objects);
1705 * e_client_util_parse_comma_strings:
1706 * @strings: string of comma-separated values
1708 * Parses comma-separated list of values into #GSList.
1710 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
1711 * newly allocated strings corresponding to values parsed from @strings.
1712 * Free the returned pointer with e_client_util_free_string_slist().
1717 e_client_util_parse_comma_strings (const gchar *strings)
1719 GSList *strs_slist = NULL;
1720 gchar **strs_strv = NULL;
1723 if (!strings || !*strings)
1726 strs_strv = g_strsplit (strings, ",", -1);
1727 g_return_val_if_fail (strs_strv != NULL, NULL);
1729 for (ii = 0; strs_strv && strs_strv[ii]; ii++) {
1730 gchar *str = g_strstrip (strs_strv[ii]);
1733 strs_slist = g_slist_prepend (strs_slist, g_strdup (str));
1736 g_strfreev (strs_strv);
1738 return g_slist_reverse (strs_slist);
1742 e_client_finish_async_without_dbus (EClient *client,
1743 GCancellable *cancellable,
1744 GAsyncReadyCallback callback,
1746 gpointer source_tag,
1748 GDestroyNotify destroy_op_res)
1750 GCancellable *use_cancellable;
1751 GSimpleAsyncResult *simple;
1754 g_return_if_fail (E_IS_CLIENT (client));
1755 g_return_if_fail (callback != NULL);
1756 g_return_if_fail (source_tag != NULL);
1758 use_cancellable = cancellable;
1759 if (!use_cancellable)
1760 use_cancellable = g_cancellable_new ();
1762 opid = e_client_register_op (client, use_cancellable);
1763 g_return_if_fail (opid > 0);
1765 simple = g_simple_async_result_new (
1766 G_OBJECT (client), callback, user_data, source_tag);
1768 g_simple_async_result_set_check_cancellable (simple, cancellable);
1770 g_simple_async_result_set_op_res_gpointer (
1771 simple, op_res, destroy_op_res);
1773 g_simple_async_result_complete_in_idle (simple);
1775 g_object_unref (simple);
1777 if (use_cancellable != cancellable)
1778 g_object_unref (use_cancellable);
1782 e_client_get_dbus_proxy (EClient *client)
1784 EClientClass *class;
1786 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
1788 class = E_CLIENT_GET_CLASS (client);
1789 g_return_val_if_fail (class != NULL, NULL);
1790 g_return_val_if_fail (class->get_dbus_proxy != NULL, NULL);
1792 return class->get_dbus_proxy (client);
1796 * e_client_unwrap_dbus_error:
1797 * @client: an #EClient
1798 * @dbus_error: a #GError returned bu D-Bus
1799 * @out_error: a #GError variable where to store the result
1801 * Unwraps D-Bus error to local error. @dbus_error is automatically freed.
1802 * @dbus_erorr and @out_error can point to the same variable.
1807 e_client_unwrap_dbus_error (EClient *client,
1811 EClientClass *class;
1813 g_return_if_fail (E_IS_CLIENT (client));
1815 class = E_CLIENT_GET_CLASS (client);
1816 g_return_if_fail (class != NULL);
1817 g_return_if_fail (class->unwrap_dbus_error != NULL);
1819 if (!dbus_error || !out_error) {
1821 g_error_free (dbus_error);
1823 class->unwrap_dbus_error (client, dbus_error, out_error);
1828 * e_client_util_unwrap_dbus_error:
1829 * @dbus_error: DBus #GError to unwrap
1830 * @client_error: (out): Resulting #GError; can be %NULL
1831 * @known_errors: List of known errors against which try to match
1832 * @known_errors_count: How many items are stored in @known_errors
1833 * @known_errors_domain: Error domain for @known_errors
1834 * @fail_when_none_matched: Whether to fail when none of @known_errors matches
1836 * The function takes a @dbus_error and tries to find a match in @known_errors
1837 * for it, if it is a G_IO_ERROR, G_IO_ERROR_DBUS_ERROR. If it is anything else
1838 * then the @dbus_error is moved to @client_error.
1840 * The @fail_when_none_matched influences behaviour. If it's %TRUE, and none of
1841 * @known_errors matches, or this is not a G_IO_ERROR_DBUS_ERROR, then %FALSE
1842 * is returned and the @client_error is left without change. Otherwise, the
1843 * @fail_when_none_matched is %FALSE, the error is always processed and will
1844 * result in E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR if none of @known_error
1847 * Returns: Whether was @dbus_error processed into @client_error.
1849 * Note: The @dbus_error is automatically freed if returned %TRUE.
1854 e_client_util_unwrap_dbus_error (GError *dbus_error,
1855 GError **client_error,
1856 const EClientErrorsList *known_errors,
1857 guint known_errors_count,
1858 GQuark known_errors_domain,
1859 gboolean fail_when_none_matched)
1861 if (!client_error) {
1863 g_error_free (dbus_error);
1868 *client_error = NULL;
1872 if (dbus_error->domain == known_errors_domain) {
1873 *client_error = dbus_error;
1878 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
1882 name = g_dbus_error_get_remote_error (dbus_error);
1884 for (ii = 0; ii < known_errors_count; ii++) {
1885 if (g_ascii_strcasecmp (known_errors[ii].name, name) == 0) {
1888 g_dbus_error_strip_remote_error (dbus_error);
1889 *client_error = g_error_new_literal (known_errors_domain, known_errors[ii].err_code, dbus_error->message);
1890 g_error_free (dbus_error);
1899 if (fail_when_none_matched)
1902 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
1903 g_dbus_error_strip_remote_error (dbus_error);
1904 *client_error = g_error_new_literal (E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR, dbus_error->message);
1905 g_error_free (dbus_error);
1907 g_dbus_error_strip_remote_error (dbus_error);
1908 *client_error = dbus_error;
1914 typedef struct _EClientAsyncOpData
1919 gpointer source_tag;
1920 gchar *res_op_data; /* optional string to set on a GAsyncResult object as "res-op-data" user data */
1921 GAsyncReadyCallback callback;
1924 gboolean result; /* result of the finish function call */
1926 /* only one can be non-NULL, and the type is telling which 'out' value is valid */
1927 EClientProxyFinishVoidFunc finish_void;
1928 EClientProxyFinishBooleanFunc finish_boolean;
1929 EClientProxyFinishStringFunc finish_string;
1930 EClientProxyFinishStrvFunc finish_strv;
1931 EClientProxyFinishUintFunc finish_uint;
1934 gboolean val_boolean;
1939 } EClientAsyncOpData;
1942 async_data_free (EClientAsyncOpData *async_data)
1944 g_return_if_fail (async_data != NULL);
1945 g_return_if_fail (async_data->client != NULL);
1947 e_client_unregister_op (async_data->client, async_data->opid);
1949 if (async_data->finish_string)
1950 g_free (async_data->out.val_string);
1951 else if (async_data->finish_strv)
1952 g_strfreev (async_data->out.val_strv);
1954 g_object_unref (async_data->client);
1955 g_free (async_data->res_op_data);
1956 g_free (async_data);
1960 complete_async_op_in_idle_cb (gpointer user_data)
1962 GSimpleAsyncResult *simple = user_data;
1963 gint run_main_depth;
1965 g_return_val_if_fail (simple != NULL, FALSE);
1967 run_main_depth = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (simple), "run-main-depth"));
1968 if (run_main_depth < 1)
1971 /* do not receive in higher level than was initially run */
1972 if (g_main_depth () > run_main_depth) {
1976 g_simple_async_result_complete (simple);
1977 g_object_unref (simple);
1983 finish_async_op (EClientAsyncOpData *async_data,
1984 const GError *error,
1987 GSimpleAsyncResult *simple;
1989 g_return_if_fail (async_data != NULL);
1990 g_return_if_fail (async_data->source_tag != NULL);
1991 g_return_if_fail (async_data->client != NULL);
1993 simple = g_simple_async_result_new (G_OBJECT (async_data->client), async_data->callback, async_data->user_data, async_data->source_tag);
1994 g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
1996 if (async_data->res_op_data)
1997 g_object_set_data_full (G_OBJECT (simple), "res-op-data", g_strdup (async_data->res_op_data), g_free);
2000 g_simple_async_result_set_from_error (simple, error);
2003 g_object_set_data (G_OBJECT (simple), "run-main-depth", GINT_TO_POINTER (g_main_depth ()));
2004 g_idle_add (complete_async_op_in_idle_cb, simple);
2006 g_simple_async_result_complete (simple);
2007 g_object_unref (simple);
2012 async_result_ready_cb (GObject *source_object,
2013 GAsyncResult *result,
2016 GError *error = NULL;
2017 EClientAsyncOpData *async_data;
2020 g_return_if_fail (result != NULL);
2021 g_return_if_fail (source_object != NULL);
2023 async_data = user_data;
2024 g_return_if_fail (async_data != NULL);
2025 g_return_if_fail (async_data->client != NULL);
2027 client = async_data->client;
2028 g_return_if_fail (e_client_get_dbus_proxy (client) == G_DBUS_PROXY (source_object));
2030 if (async_data->finish_void)
2031 async_data->result = async_data->finish_void (G_DBUS_PROXY (source_object), result, &error);
2032 else if (async_data->finish_boolean)
2033 async_data->result = async_data->finish_boolean (G_DBUS_PROXY (source_object), result, &async_data->out.val_boolean, &error);
2034 else if (async_data->finish_string)
2035 async_data->result = async_data->finish_string (G_DBUS_PROXY (source_object), result, &async_data->out.val_string, &error);
2036 else if (async_data->finish_strv)
2037 async_data->result = async_data->finish_strv (G_DBUS_PROXY (source_object), result, &async_data->out.val_strv, &error);
2038 else if (async_data->finish_uint)
2039 async_data->result = async_data->finish_uint (G_DBUS_PROXY (source_object), result, &async_data->out.val_uint, &error);
2041 g_warning ("%s: Do not know how to finish async operation", G_STRFUNC);
2043 finish_async_op (async_data, error, FALSE);
2046 g_error_free (error);
2049 static EClientAsyncOpData *
2050 prepare_async_data (EClient *client,
2051 GCancellable *cancellable,
2052 GAsyncReadyCallback callback,
2054 gpointer source_tag,
2055 gboolean error_report_only,
2056 EClientProxyFinishVoidFunc finish_void,
2057 EClientProxyFinishBooleanFunc finish_boolean,
2058 EClientProxyFinishStringFunc finish_string,
2059 EClientProxyFinishStrvFunc finish_strv,
2060 EClientProxyFinishUintFunc finish_uint,
2062 GCancellable **out_cancellable)
2064 EClientAsyncOpData *async_data;
2065 GCancellable *use_cancellable;
2068 g_return_val_if_fail (client != NULL, NULL);
2069 g_return_val_if_fail (callback != NULL, NULL);
2070 g_return_val_if_fail (source_tag != NULL, NULL);
2072 if (!error_report_only) {
2073 g_return_val_if_fail (proxy != NULL, NULL);
2074 g_return_val_if_fail (out_cancellable != NULL, NULL);
2075 g_return_val_if_fail (finish_void || finish_boolean || finish_string || finish_strv || finish_uint, NULL);
2078 g_return_val_if_fail (finish_boolean == NULL, NULL);
2079 g_return_val_if_fail (finish_string == NULL, NULL);
2080 g_return_val_if_fail (finish_strv == NULL, NULL);
2081 g_return_val_if_fail (finish_uint == NULL, NULL);
2084 if (finish_boolean) {
2085 g_return_val_if_fail (finish_void == NULL, NULL);
2086 g_return_val_if_fail (finish_string == NULL, NULL);
2087 g_return_val_if_fail (finish_strv == NULL, NULL);
2088 g_return_val_if_fail (finish_uint == NULL, NULL);
2091 if (finish_string) {
2092 g_return_val_if_fail (finish_void == NULL, NULL);
2093 g_return_val_if_fail (finish_boolean == NULL, NULL);
2094 g_return_val_if_fail (finish_strv == NULL, NULL);
2095 g_return_val_if_fail (finish_uint == NULL, NULL);
2099 g_return_val_if_fail (finish_void == NULL, NULL);
2100 g_return_val_if_fail (finish_boolean == NULL, NULL);
2101 g_return_val_if_fail (finish_string == NULL, NULL);
2102 g_return_val_if_fail (finish_uint == NULL, NULL);
2106 g_return_val_if_fail (finish_void == NULL, NULL);
2107 g_return_val_if_fail (finish_boolean == NULL, NULL);
2108 g_return_val_if_fail (finish_string == NULL, NULL);
2109 g_return_val_if_fail (finish_strv == NULL, NULL);
2112 *proxy = e_client_get_dbus_proxy (client);
2117 use_cancellable = cancellable;
2118 if (!use_cancellable)
2119 use_cancellable = g_cancellable_new ();
2121 opid = e_client_register_op (client, use_cancellable);
2122 async_data = g_new0 (EClientAsyncOpData, 1);
2123 async_data->client = g_object_ref (client);
2124 async_data->opid = opid;
2125 async_data->source_tag = source_tag;
2126 async_data->callback = callback;
2127 async_data->user_data = user_data;
2128 async_data->finish_void = finish_void;
2129 async_data->finish_boolean = finish_boolean;
2130 async_data->finish_string = finish_string;
2131 async_data->finish_strv = finish_strv;
2132 async_data->finish_uint = finish_uint;
2134 /* EClient from e_client_register_op() took ownership of the use_cancellable */
2135 if (use_cancellable != cancellable)
2136 g_object_unref (use_cancellable);
2138 if (out_cancellable)
2139 *out_cancellable = use_cancellable;
2145 e_client_proxy_return_async_error (EClient *client,
2146 const GError *error,
2147 GAsyncReadyCallback callback,
2149 gpointer source_tag)
2151 EClientAsyncOpData *async_data;
2153 g_return_if_fail (E_IS_CLIENT (client));
2154 g_return_if_fail (error != NULL);
2155 g_return_if_fail (callback != NULL);
2157 async_data = prepare_async_data (client, NULL, callback, user_data, source_tag, TRUE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2158 g_return_if_fail (async_data != NULL);
2160 finish_async_op (async_data, error, TRUE);
2164 e_client_proxy_call_void (EClient *client,
2165 GCancellable *cancellable,
2166 GAsyncReadyCallback callback,
2168 gpointer source_tag,
2169 void (*func) (GDBusProxy *proxy,
2170 GCancellable *cancellable,
2171 GAsyncReadyCallback callback,
2172 gpointer user_data),
2173 EClientProxyFinishVoidFunc finish_void,
2174 EClientProxyFinishBooleanFunc finish_boolean,
2175 EClientProxyFinishStringFunc finish_string,
2176 EClientProxyFinishStrvFunc finish_strv,
2177 EClientProxyFinishUintFunc finish_uint)
2179 EClientAsyncOpData *async_data;
2180 GDBusProxy *proxy = NULL;
2182 g_return_if_fail (E_IS_CLIENT (client));
2183 g_return_if_fail (callback != NULL);
2184 g_return_if_fail (source_tag != NULL);
2185 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2187 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2188 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2190 func (proxy, cancellable, async_result_ready_cb, async_data);
2194 e_client_proxy_call_boolean (EClient *client,
2195 gboolean in_boolean,
2196 GCancellable *cancellable,
2197 GAsyncReadyCallback callback,
2199 gpointer source_tag,
2200 void (*func) (GDBusProxy *proxy,
2201 gboolean in_boolean,
2202 GCancellable *cancellable,
2203 GAsyncReadyCallback callback,
2204 gpointer user_data),
2205 EClientProxyFinishVoidFunc finish_void,
2206 EClientProxyFinishBooleanFunc finish_boolean,
2207 EClientProxyFinishStringFunc finish_string,
2208 EClientProxyFinishStrvFunc finish_strv,
2209 EClientProxyFinishUintFunc finish_uint)
2211 EClientAsyncOpData *async_data;
2212 GDBusProxy *proxy = NULL;
2214 g_return_if_fail (E_IS_CLIENT (client));
2215 g_return_if_fail (callback != NULL);
2216 g_return_if_fail (source_tag != NULL);
2217 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2219 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2220 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2222 func (proxy, in_boolean, cancellable, async_result_ready_cb, async_data);
2226 e_client_proxy_call_string (EClient *client,
2227 const gchar *in_string,
2228 GCancellable *cancellable,
2229 GAsyncReadyCallback callback,
2231 gpointer source_tag,
2232 void (*func) (GDBusProxy *proxy,
2233 const gchar *in_string,
2234 GCancellable *cancellable,
2235 GAsyncReadyCallback callback,
2236 gpointer user_data),
2237 EClientProxyFinishVoidFunc finish_void,
2238 EClientProxyFinishBooleanFunc finish_boolean,
2239 EClientProxyFinishStringFunc finish_string,
2240 EClientProxyFinishStrvFunc finish_strv,
2241 EClientProxyFinishUintFunc finish_uint)
2243 EClientAsyncOpData *async_data;
2244 GDBusProxy *proxy = NULL;
2246 g_return_if_fail (E_IS_CLIENT (client));
2247 g_return_if_fail (callback != NULL);
2248 g_return_if_fail (source_tag != NULL);
2249 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2250 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2252 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2253 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2255 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2259 e_client_proxy_call_string_with_res_op_data (EClient *client,
2260 const gchar *in_string,
2261 GCancellable *cancellable,
2262 GAsyncReadyCallback callback,
2264 gpointer source_tag,
2265 const gchar *res_op_data,
2266 void (*func) (GDBusProxy *proxy,
2267 const gchar *in_string,
2268 GCancellable *cancellable,
2269 GAsyncReadyCallback callback,
2270 gpointer user_data),
2271 EClientProxyFinishVoidFunc finish_void,
2272 EClientProxyFinishBooleanFunc finish_boolean,
2273 EClientProxyFinishStringFunc finish_string,
2274 EClientProxyFinishStrvFunc finish_strv,
2275 EClientProxyFinishUintFunc finish_uint)
2277 EClientAsyncOpData *async_data;
2278 GDBusProxy *proxy = NULL;
2280 g_return_if_fail (E_IS_CLIENT (client));
2281 g_return_if_fail (callback != NULL);
2282 g_return_if_fail (source_tag != NULL);
2283 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2284 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2286 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2287 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2289 async_data->res_op_data = g_strdup (res_op_data);
2291 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2295 e_client_proxy_call_strv (EClient *client,
2296 const gchar * const *in_strv,
2297 GCancellable *cancellable,
2298 GAsyncReadyCallback callback,
2300 gpointer source_tag,
2301 void (*func) (GDBusProxy *proxy,
2302 const gchar * const * in_strv,
2303 GCancellable *cancellable,
2304 GAsyncReadyCallback callback,
2305 gpointer user_data),
2306 EClientProxyFinishVoidFunc finish_void,
2307 EClientProxyFinishBooleanFunc finish_boolean,
2308 EClientProxyFinishStringFunc finish_string,
2309 EClientProxyFinishStrvFunc finish_strv,
2310 EClientProxyFinishUintFunc finish_uint)
2312 EClientAsyncOpData *async_data;
2313 GDBusProxy *proxy = NULL;
2315 g_return_if_fail (E_IS_CLIENT (client));
2316 g_return_if_fail (callback != NULL);
2317 g_return_if_fail (source_tag != NULL);
2318 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2319 e_client_return_async_if_fail (in_strv != NULL, client, callback, user_data, source_tag);
2321 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2322 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2324 func (proxy, in_strv, cancellable, async_result_ready_cb, async_data);
2328 e_client_proxy_call_uint (EClient *client,
2330 GCancellable *cancellable,
2331 GAsyncReadyCallback callback,
2333 gpointer source_tag,
2334 void (*func) (GDBusProxy *proxy,
2336 GCancellable *cancellable,
2337 GAsyncReadyCallback callback,
2338 gpointer user_data),
2339 EClientProxyFinishVoidFunc finish_void,
2340 EClientProxyFinishBooleanFunc finish_boolean,
2341 EClientProxyFinishStringFunc finish_string,
2342 EClientProxyFinishStrvFunc finish_strv,
2343 EClientProxyFinishUintFunc finish_uint)
2345 EClientAsyncOpData *async_data;
2346 GDBusProxy *proxy = NULL;
2348 g_return_if_fail (E_IS_CLIENT (client));
2349 g_return_if_fail (callback != NULL);
2350 g_return_if_fail (source_tag != NULL);
2351 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2353 async_data = prepare_async_data (client, cancellable, callback, user_data, source_tag, FALSE, finish_void, finish_boolean, finish_string, finish_strv, finish_uint, &proxy, &cancellable);
2354 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2356 func (proxy, in_uint, cancellable, async_result_ready_cb, async_data);
2360 e_client_proxy_call_finish_void (EClient *client,
2361 GAsyncResult *result,
2363 gpointer source_tag)
2365 GSimpleAsyncResult *simple;
2366 GError *local_error = NULL;
2367 EClientAsyncOpData *async_data;
2369 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2370 g_return_val_if_fail (result != NULL, FALSE);
2371 g_return_val_if_fail (source_tag != NULL, FALSE);
2372 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2374 simple = G_SIMPLE_ASYNC_RESULT (result);
2376 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2377 e_client_unwrap_dbus_error (client, local_error, error);
2381 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2382 g_return_val_if_fail (async_data != NULL, FALSE);
2384 return async_data->result;
2388 e_client_proxy_call_finish_boolean (EClient *client,
2389 GAsyncResult *result,
2390 gboolean *out_boolean,
2392 gpointer source_tag)
2394 GSimpleAsyncResult *simple;
2395 GError *local_error = NULL;
2396 EClientAsyncOpData *async_data;
2398 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2399 g_return_val_if_fail (result != NULL, FALSE);
2400 g_return_val_if_fail (source_tag != NULL, FALSE);
2401 g_return_val_if_fail (out_boolean != NULL, FALSE);
2402 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2404 simple = G_SIMPLE_ASYNC_RESULT (result);
2406 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2407 e_client_unwrap_dbus_error (client, local_error, error);
2411 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2412 g_return_val_if_fail (async_data != NULL, FALSE);
2414 *out_boolean = async_data->out.val_boolean;
2416 return async_data->result;
2420 e_client_proxy_call_finish_string (EClient *client,
2421 GAsyncResult *result,
2424 gpointer source_tag)
2426 GSimpleAsyncResult *simple;
2427 GError *local_error = NULL;
2428 EClientAsyncOpData *async_data;
2430 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2431 g_return_val_if_fail (result != NULL, FALSE);
2432 g_return_val_if_fail (source_tag != NULL, FALSE);
2433 g_return_val_if_fail (out_string != NULL, FALSE);
2434 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2436 simple = G_SIMPLE_ASYNC_RESULT (result);
2438 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2439 e_client_unwrap_dbus_error (client, local_error, error);
2443 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2444 g_return_val_if_fail (async_data != NULL, FALSE);
2446 *out_string = async_data->out.val_string;
2447 async_data->out.val_string = NULL;
2449 return async_data->result;
2453 e_client_proxy_call_finish_strv (EClient *client,
2454 GAsyncResult *result,
2457 gpointer source_tag)
2459 GSimpleAsyncResult *simple;
2460 GError *local_error = NULL;
2461 EClientAsyncOpData *async_data;
2463 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2464 g_return_val_if_fail (result != NULL, FALSE);
2465 g_return_val_if_fail (source_tag != NULL, FALSE);
2466 g_return_val_if_fail (out_strv != NULL, FALSE);
2467 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2469 simple = G_SIMPLE_ASYNC_RESULT (result);
2471 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2472 e_client_unwrap_dbus_error (client, local_error, error);
2476 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2477 g_return_val_if_fail (async_data != NULL, FALSE);
2479 *out_strv = async_data->out.val_strv;
2480 async_data->out.val_strv = NULL;
2482 return async_data->result;
2486 e_client_proxy_call_finish_uint (EClient *client,
2487 GAsyncResult *result,
2490 gpointer source_tag)
2492 GSimpleAsyncResult *simple;
2493 GError *local_error = NULL;
2494 EClientAsyncOpData *async_data;
2496 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2497 g_return_val_if_fail (result != NULL, FALSE);
2498 g_return_val_if_fail (source_tag != NULL, FALSE);
2499 g_return_val_if_fail (out_uint != NULL, FALSE);
2500 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2502 simple = G_SIMPLE_ASYNC_RESULT (result);
2504 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2505 e_client_unwrap_dbus_error (client, local_error, error);
2509 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2510 g_return_val_if_fail (async_data != NULL, FALSE);
2512 *out_uint = async_data->out.val_uint;
2514 return async_data->result;
2517 #define SYNC_CALL_TEMPLATE(_out_test,_the_call) \
2518 GDBusProxy *proxy; \
2519 GCancellable *use_cancellable; \
2522 GError *local_error = NULL; \
2524 g_return_val_if_fail (E_IS_CLIENT (client), FALSE); \
2525 g_return_val_if_fail (func != NULL, FALSE); \
2526 g_return_val_if_fail (_out_test != NULL, FALSE); \
2528 proxy = e_client_get_dbus_proxy (client); \
2529 g_return_val_if_fail (proxy != NULL, FALSE); \
2531 use_cancellable = cancellable; \
2532 if (!use_cancellable) \
2533 use_cancellable = g_cancellable_new (); \
2535 g_object_ref (client); \
2536 opid = e_client_register_op (client, use_cancellable); \
2538 result = func _the_call; \
2540 e_client_unregister_op (client, opid); \
2541 g_object_unref (client); \
2543 if (use_cancellable != cancellable) \
2544 g_object_unref (use_cancellable); \
2546 e_client_unwrap_dbus_error (client, local_error, error);\
2551 e_client_proxy_call_sync_void__void (EClient *client,
2552 GCancellable *cancellable,
2554 gboolean (*func) (GDBusProxy *proxy,
2555 GCancellable *cancellable,
2558 SYNC_CALL_TEMPLATE (client, (proxy, use_cancellable, &local_error))
2562 e_client_proxy_call_sync_void__boolean (EClient *client,
2563 gboolean *out_boolean,
2564 GCancellable *cancellable,
2566 gboolean (*func) (GDBusProxy *proxy,
2567 gboolean *out_boolean,
2568 GCancellable *cancellable,
2571 SYNC_CALL_TEMPLATE (out_boolean, (proxy, out_boolean, use_cancellable, &local_error))
2575 e_client_proxy_call_sync_void__string (EClient *client,
2577 GCancellable *cancellable,
2579 gboolean (*func) (GDBusProxy *proxy,
2581 GCancellable *cancellable,
2584 SYNC_CALL_TEMPLATE (out_string, (proxy, out_string, use_cancellable, &local_error))
2588 e_client_proxy_call_sync_void__strv (EClient *client,
2590 GCancellable *cancellable,
2592 gboolean (*func) (GDBusProxy *proxy,
2594 GCancellable *cancellable,
2597 SYNC_CALL_TEMPLATE (out_strv, (proxy, out_strv, use_cancellable, &local_error))
2601 e_client_proxy_call_sync_void__uint (EClient *client,
2603 GCancellable *cancellable,
2605 gboolean (*func) (GDBusProxy *proxy,
2607 GCancellable *cancellable,
2610 SYNC_CALL_TEMPLATE (out_uint, (proxy, out_uint, use_cancellable, &local_error))
2614 e_client_proxy_call_sync_boolean__void (EClient *client,
2615 gboolean in_boolean,
2616 GCancellable *cancellable,
2618 gboolean (*func) (GDBusProxy *proxy,
2619 gboolean in_boolean,
2620 GCancellable *cancellable,
2623 SYNC_CALL_TEMPLATE (client, (proxy, in_boolean, use_cancellable, &local_error))
2627 e_client_proxy_call_sync_boolean__boolean (EClient *client,
2628 gboolean in_boolean,
2629 gboolean *out_boolean,
2630 GCancellable *cancellable,
2632 gboolean (*func) (GDBusProxy *proxy,
2633 gboolean in_boolean,
2634 gboolean *out_boolean,
2635 GCancellable *cancellable,
2638 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_boolean, out_boolean, use_cancellable, &local_error))
2642 e_client_proxy_call_sync_boolean__string (EClient *client,
2643 gboolean in_boolean,
2645 GCancellable *cancellable,
2647 gboolean (*func) (GDBusProxy *proxy,
2648 gboolean in_boolean,
2650 GCancellable *cancellable,
2653 SYNC_CALL_TEMPLATE (out_string, (proxy, in_boolean, out_string, use_cancellable, &local_error))
2657 e_client_proxy_call_sync_boolean__strv (EClient *client,
2658 gboolean in_boolean,
2660 GCancellable *cancellable,
2662 gboolean (*func) (GDBusProxy *proxy,
2663 gboolean in_boolean,
2665 GCancellable *cancellable,
2668 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_boolean, out_strv, use_cancellable, &local_error))
2672 e_client_proxy_call_sync_boolean__uint (EClient *client,
2673 gboolean in_boolean,
2675 GCancellable *cancellable,
2677 gboolean (*func) (GDBusProxy *proxy,
2678 gboolean in_boolean,
2680 GCancellable *cancellable,
2683 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_boolean, out_uint, use_cancellable, &local_error))
2687 e_client_proxy_call_sync_string__void (EClient *client,
2688 const gchar *in_string,
2689 GCancellable *cancellable,
2691 gboolean (*func) (GDBusProxy *proxy,
2692 const gchar *in_string,
2693 GCancellable *cancellable,
2696 SYNC_CALL_TEMPLATE (client, (proxy, in_string, use_cancellable, &local_error))
2700 e_client_proxy_call_sync_string__boolean (EClient *client,
2701 const gchar *in_string,
2702 gboolean *out_boolean,
2703 GCancellable *cancellable,
2705 gboolean (*func) (GDBusProxy *proxy,
2706 const gchar *in_string,
2707 gboolean *out_boolean,
2708 GCancellable *cancellable,
2711 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_string, out_boolean, use_cancellable, &local_error))
2715 e_client_proxy_call_sync_string__string (EClient *client,
2716 const gchar *in_string,
2718 GCancellable *cancellable,
2720 gboolean (*func) (GDBusProxy *proxy,
2721 const gchar *in_string,
2723 GCancellable *cancellable,
2726 SYNC_CALL_TEMPLATE (out_string, (proxy, in_string, out_string, use_cancellable, &local_error))
2730 e_client_proxy_call_sync_string__strv (EClient *client,
2731 const gchar *in_string,
2733 GCancellable *cancellable,
2735 gboolean (*func) (GDBusProxy *proxy,
2736 const gchar *in_string,
2738 GCancellable *cancellable,
2741 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_string, out_strv, use_cancellable, &local_error))
2745 e_client_proxy_call_sync_string__uint (EClient *client,
2746 const gchar *in_string,
2748 GCancellable *cancellable,
2750 gboolean (*func) (GDBusProxy *proxy,
2751 const gchar *in_string,
2753 GCancellable *cancellable,
2756 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_string, out_uint, use_cancellable, &local_error))
2760 e_client_proxy_call_sync_strv__void (EClient *client,
2761 const gchar * const *in_strv,
2762 GCancellable *cancellable,
2764 gboolean (*func) (GDBusProxy *proxy,
2765 const gchar * const *in_strv,
2766 GCancellable *cancellable,
2769 SYNC_CALL_TEMPLATE (client, (proxy, in_strv, use_cancellable, &local_error))
2773 e_client_proxy_call_sync_strv__boolean (EClient *client,
2774 const gchar * const *in_strv,
2775 gboolean *out_boolean,
2776 GCancellable *cancellable,
2778 gboolean (*func) (GDBusProxy *proxy,
2779 const gchar * const *in_strv,
2780 gboolean *out_boolean,
2781 GCancellable *cancellable,
2784 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_strv, out_boolean, use_cancellable, &local_error))
2788 e_client_proxy_call_sync_strv__string (EClient *client,
2789 const gchar * const *in_strv,
2791 GCancellable *cancellable,
2793 gboolean (*func) (GDBusProxy *proxy,
2794 const gchar * const *in_strv,
2796 GCancellable *cancellable,
2799 SYNC_CALL_TEMPLATE (out_string, (proxy, in_strv, out_string, use_cancellable, &local_error))
2803 e_client_proxy_call_sync_strv__strv (EClient *client,
2804 const gchar * const *in_strv,
2806 GCancellable *cancellable,
2808 gboolean (*func) (GDBusProxy *proxy,
2809 const gchar * const *in_strv,
2811 GCancellable *cancellable,
2814 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_strv, out_strv, use_cancellable, &local_error))
2818 e_client_proxy_call_sync_strv__uint (EClient *client,
2819 const gchar * const *in_strv,
2821 GCancellable *cancellable,
2823 gboolean (*func) (GDBusProxy *proxy,
2824 const gchar * const *in_strv,
2826 GCancellable *cancellable,
2829 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_strv, out_uint, use_cancellable, &local_error))
2833 e_client_proxy_call_sync_uint__void (EClient *client,
2835 GCancellable *cancellable,
2837 gboolean (*func) (GDBusProxy *proxy,
2839 GCancellable *cancellable,
2842 SYNC_CALL_TEMPLATE (client, (proxy, in_uint, use_cancellable, &local_error))
2846 e_client_proxy_call_sync_uint__boolean (EClient *client,
2848 gboolean *out_boolean,
2849 GCancellable *cancellable,
2851 gboolean (*func) (GDBusProxy *proxy,
2853 gboolean *out_boolean,
2854 GCancellable *cancellable,
2857 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_uint, out_boolean, use_cancellable, &local_error))
2861 e_client_proxy_call_sync_uint__string (EClient *client,
2864 GCancellable *cancellable,
2866 gboolean (*func) (GDBusProxy *proxy,
2869 GCancellable *cancellable,
2872 SYNC_CALL_TEMPLATE (out_string, (proxy, in_uint, out_string, use_cancellable, &local_error))
2876 e_client_proxy_call_sync_uint__strv (EClient *client,
2879 GCancellable *cancellable,
2881 gboolean (*func) (GDBusProxy *proxy,
2884 GCancellable *cancellable,
2887 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_uint, out_strv, use_cancellable, &local_error))
2891 e_client_proxy_call_sync_uint__uint (EClient *client,
2894 GCancellable *cancellable,
2896 gboolean (*func) (GDBusProxy *proxy,
2899 GCancellable *cancellable,
2902 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_uint, out_uint, use_cancellable, &local_error))
2905 #undef SYNC_CALL_TEMPLATE