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 {
47 gboolean capabilities_retrieved;
50 GHashTable *backend_property_cache;
54 GHashTable *ops; /* opid to GCancellable */
70 BACKEND_PROPERTY_CHANGED,
74 static guint signals[LAST_SIGNAL];
76 G_DEFINE_ABSTRACT_TYPE (EClient, e_client, G_TYPE_OBJECT)
79 * Well-known client backend properties, which are common for each #EClient:
80 * @CLIENT_BACKEND_PROPERTY_OPENED: Is set to "TRUE" or "FALSE" depending
81 * whether the backend is fully opened.
82 * @CLIENT_BACKEND_PROPERTY_OPENING: Is set to "TRUE" or "FALSE" depending
83 * whether the backend is processing its opening phase.
84 * @CLIENT_BACKEND_PROPERTY_ONLINE: Is set to "TRUE" or "FALSE" depending
85 * on the backend's loaded state. See also e_client_is_online().
86 * @CLIENT_BACKEND_PROPERTY_READONLY: Is set to "TRUE" or "FALSE" depending
87 * on the backend's readonly state. See also e_client_is_readonly().
88 * @CLIENT_BACKEND_PROPERTY_CACHE_DIR: Local folder with cached data used
90 * @CLIENT_BACKEND_PROPERTY_CAPABILITIES: Retrieves comma-separated list
91 * of capabilities supported by the backend. Preferred method of retreiving
92 * and working with capabilities is e_client_get_capabilities() and
93 * e_client_check_capability().
96 G_DEFINE_QUARK (e-client-error-quark, e_client_error)
99 * e_client_error_to_string:
101 * FIXME: Document me.
106 e_client_error_to_string (EClientError code)
109 case E_CLIENT_ERROR_INVALID_ARG:
110 return _("Invalid argument");
111 case E_CLIENT_ERROR_BUSY:
112 return _("Backend is busy");
113 case E_CLIENT_ERROR_SOURCE_NOT_LOADED:
114 return _("Source not loaded");
115 case E_CLIENT_ERROR_SOURCE_ALREADY_LOADED:
116 return _("Source already loaded");
117 case E_CLIENT_ERROR_AUTHENTICATION_FAILED:
118 return _("Authentication failed");
119 case E_CLIENT_ERROR_AUTHENTICATION_REQUIRED:
120 return _("Authentication required");
121 case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
122 return _("Repository offline");
123 case E_CLIENT_ERROR_OFFLINE_UNAVAILABLE:
124 /* Translators: This means that the EClient does not support offline mode, or
125 * it's not set to by a user, thus it is unavailable while user is not connected. */
126 return _("Offline unavailable");
127 case E_CLIENT_ERROR_PERMISSION_DENIED:
128 return _("Permission denied");
129 case E_CLIENT_ERROR_CANCELLED:
130 return _("Cancelled");
131 case E_CLIENT_ERROR_COULD_NOT_CANCEL:
132 return _("Could not cancel");
133 case E_CLIENT_ERROR_NOT_SUPPORTED:
134 return _("Not supported");
135 case E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD:
136 return _("Unsupported authentication method");
137 case E_CLIENT_ERROR_TLS_NOT_AVAILABLE:
138 return _("TLS not available");
139 case E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED:
140 return _("Search size limit exceeded");
141 case E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED:
142 return _("Search time limit exceeded");
143 case E_CLIENT_ERROR_INVALID_QUERY:
144 return _("Invalid query");
145 case E_CLIENT_ERROR_QUERY_REFUSED:
146 return _("Query refused");
147 case E_CLIENT_ERROR_DBUS_ERROR:
148 return _("D-Bus error");
149 case E_CLIENT_ERROR_OTHER_ERROR:
150 return _("Other error");
151 case E_CLIENT_ERROR_NOT_OPENED:
152 return _("Backend is not opened yet");
155 return _("Unknown error");
159 * e_client_error_create:
160 * @code: an #EClientError code to create
161 * @custom_msg: custom message to use for the error; can be %NULL
163 * Returns: a new #GError containing an E_CLIENT_ERROR of the given
164 * @code. If the @custom_msg is NULL, then the error message is
165 * the one returned from e_client_error_to_string() for the @code,
166 * otherwise the given message is used.
168 * Returned pointer should be freed with g_error_free().
173 e_client_error_create (EClientError code,
174 const gchar *custom_msg)
176 return g_error_new_literal (E_CLIENT_ERROR, code, custom_msg ? custom_msg : e_client_error_to_string (code));
179 static void client_set_source (EClient *client, ESource *source);
182 e_client_init (EClient *client)
184 client->priv = E_CLIENT_GET_PRIVATE (client);
186 client->priv->readonly = TRUE;
188 g_rec_mutex_init (&client->priv->prop_mutex);
189 client->priv->backend_property_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
191 g_rec_mutex_init (&client->priv->ops_mutex);
192 client->priv->last_opid = 0;
193 client->priv->ops = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
197 client_dispose (GObject *object)
201 client = E_CLIENT (object);
203 e_client_cancel_all (client);
205 /* Chain up to parent's dispose() method. */
206 G_OBJECT_CLASS (e_client_parent_class)->dispose (object);
210 client_finalize (GObject *object)
213 EClientPrivate *priv;
215 client = E_CLIENT (object);
219 g_rec_mutex_lock (&priv->prop_mutex);
222 g_object_unref (priv->source);
231 if (priv->capabilities) {
232 g_slist_foreach (priv->capabilities, (GFunc) g_free, NULL);
233 g_slist_free (priv->capabilities);
234 priv->capabilities = NULL;
237 if (priv->backend_property_cache) {
238 g_hash_table_destroy (priv->backend_property_cache);
239 priv->backend_property_cache = NULL;
243 g_hash_table_destroy (priv->ops);
247 g_rec_mutex_unlock (&priv->prop_mutex);
248 g_rec_mutex_clear (&priv->prop_mutex);
249 g_rec_mutex_clear (&priv->ops_mutex);
251 /* Chain up to parent's finalize() method. */
252 G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
256 client_set_property (GObject *object,
261 switch (property_id) {
263 client_set_source (E_CLIENT (object), g_value_get_object (value));
267 e_client_set_online (E_CLIENT (object), g_value_get_boolean (value));
271 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
275 client_get_property (GObject *object,
280 switch (property_id) {
282 g_value_set_object (value, e_client_get_source (E_CLIENT (object)));
285 case PROP_CAPABILITIES:
286 g_value_set_pointer (value, (gpointer) e_client_get_capabilities (E_CLIENT (object)));
290 g_value_set_boolean (value, e_client_is_readonly (E_CLIENT (object)));
294 g_value_set_boolean (value, e_client_is_online (E_CLIENT (object)));
298 g_value_set_boolean (value, e_client_is_opened (E_CLIENT (object)));
302 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
306 client_remove_thread (GSimpleAsyncResult *simple,
308 GCancellable *cancellable)
310 GError *error = NULL;
312 e_client_remove_sync (E_CLIENT (object), cancellable, &error);
315 g_simple_async_result_take_error (simple, error);
319 client_remove (EClient *client,
320 GCancellable *cancellable,
321 GAsyncReadyCallback callback,
324 GSimpleAsyncResult *simple;
326 simple = g_simple_async_result_new (
327 G_OBJECT (client), callback, user_data, client_remove);
329 g_simple_async_result_set_check_cancellable (simple, cancellable);
331 g_simple_async_result_run_in_thread (
332 simple, client_remove_thread,
333 G_PRIORITY_DEFAULT, cancellable);
335 g_object_unref (simple);
339 client_remove_finish (EClient *client,
340 GAsyncResult *result,
343 GSimpleAsyncResult *simple;
345 g_return_val_if_fail (
346 g_simple_async_result_is_valid (
347 result, G_OBJECT (client), client_remove), FALSE);
349 simple = G_SIMPLE_ASYNC_RESULT (result);
351 /* Assume success unless a GError is set. */
352 return !g_simple_async_result_propagate_error (simple, error);
356 client_remove_sync (EClient *client,
357 GCancellable *cancellable,
362 source = e_client_get_source (client);
364 return e_source_remove_sync (source, cancellable, error);
368 e_client_class_init (EClientClass *class)
370 GObjectClass *object_class;
372 g_type_class_add_private (class, sizeof (EClientPrivate));
374 object_class = G_OBJECT_CLASS (class);
375 object_class->set_property = client_set_property;
376 object_class->get_property = client_get_property;
377 object_class->dispose = client_dispose;
378 object_class->finalize = client_finalize;
380 class->remove = client_remove;
381 class->remove_finish = client_remove_finish;
382 class->remove_sync = client_remove_sync;
384 g_object_class_install_property (
387 g_param_spec_object (
392 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
394 g_object_class_install_property (
397 g_param_spec_pointer (
403 g_object_class_install_property (
406 g_param_spec_boolean (
413 g_object_class_install_property (
416 g_param_spec_boolean (
423 g_object_class_install_property (
426 g_param_spec_boolean (
433 signals[OPENED] = g_signal_new (
435 G_OBJECT_CLASS_TYPE (class),
437 G_STRUCT_OFFSET (EClientClass, opened),
439 g_cclosure_marshal_VOID__BOXED,
443 signals[BACKEND_ERROR] = g_signal_new (
445 G_OBJECT_CLASS_TYPE (class),
447 G_STRUCT_OFFSET (EClientClass, backend_error),
449 g_cclosure_marshal_VOID__STRING,
453 signals[BACKEND_DIED] = g_signal_new (
455 G_OBJECT_CLASS_TYPE (class),
457 G_STRUCT_OFFSET (EClientClass, backend_died),
459 g_cclosure_marshal_VOID__VOID,
462 signals[BACKEND_PROPERTY_CHANGED] = g_signal_new (
463 "backend-property-changed",
464 G_OBJECT_CLASS_TYPE (class),
466 G_STRUCT_OFFSET (EClientClass, backend_property_changed),
468 e_gdbus_marshallers_VOID__STRING_STRING,
469 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
473 client_set_source (EClient *client,
476 g_return_if_fail (E_IS_CLIENT (client));
477 g_return_if_fail (E_IS_SOURCE (source));
479 g_object_ref (source);
481 if (client->priv->source)
482 g_object_unref (client->priv->source);
484 client->priv->source = source;
488 * e_client_get_source:
489 * @client: an #EClient
491 * Get the #ESource that this client has assigned.
493 * Returns: (transfer none): The source.
498 e_client_get_source (EClient *client)
500 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
502 return client->priv->source;
506 client_ensure_capabilities (EClient *client)
510 g_return_if_fail (E_IS_CLIENT (client));
512 if (client->priv->capabilities_retrieved || client->priv->capabilities)
515 g_rec_mutex_lock (&client->priv->prop_mutex);
518 e_client_retrieve_capabilities_sync (client, &capabilities, NULL, NULL);
519 /* e_client_set_capabilities is called inside the previous function */
520 g_free (capabilities);
522 client->priv->capabilities_retrieved = TRUE;
524 g_rec_mutex_unlock (&client->priv->prop_mutex);
528 * e_client_get_capabilities:
529 * @client: an #EClient
531 * Get list of strings with capabilities advertised by a backend.
532 * This list, together with inner strings, is owned by the @client.
533 * To check for individual capabilities use e_client_check_capability().
535 * Returns: (element-type utf8) (transfer none): #GSList of const strings
541 e_client_get_capabilities (EClient *client)
543 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
545 client_ensure_capabilities (client);
547 return client->priv->capabilities;
551 * e_client_check_capability:
552 * @client: an #EClient
553 * @capability: a capability
555 * Check if backend supports particular capability.
556 * To get all capabilities use e_client_get_capabilities().
558 * Returns: #GSList of const strings of capabilities
563 e_client_check_capability (EClient *client,
564 const gchar *capability)
568 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
569 g_return_val_if_fail (capability, FALSE);
571 g_rec_mutex_lock (&client->priv->prop_mutex);
573 client_ensure_capabilities (client);
575 for (iter = client->priv->capabilities; iter; iter = g_slist_next (iter)) {
576 const gchar *cap = iter->data;
578 if (cap && g_ascii_strcasecmp (cap, capability) == 0) {
579 g_rec_mutex_unlock (&client->priv->prop_mutex);
584 g_rec_mutex_unlock (&client->priv->prop_mutex);
590 * e_client_check_refresh_supported:
593 * Checks whether a client supports explicit refreshing
594 * (see e_client_refresh()).
596 * Returns: TRUE if the client supports refreshing, FALSE otherwise.
601 e_client_check_refresh_supported (EClient *client)
603 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
605 return e_client_check_capability (client, "refresh-supported");
608 /* capabilities - comma-separated list of capabilities; can be NULL to unset */
610 e_client_set_capabilities (EClient *client,
611 const gchar *capabilities)
613 g_return_if_fail (E_IS_CLIENT (client));
615 g_rec_mutex_lock (&client->priv->prop_mutex);
618 client->priv->capabilities_retrieved = FALSE;
620 g_slist_foreach (client->priv->capabilities, (GFunc) g_free, NULL);
621 g_slist_free (client->priv->capabilities);
622 client->priv->capabilities = e_client_util_parse_comma_strings (capabilities);
624 g_rec_mutex_unlock (&client->priv->prop_mutex);
626 g_object_notify (G_OBJECT (client), "capabilities");
630 * e_client_is_readonly:
631 * @client: an #EClient
633 * Check if this @client is read-only.
635 * Returns: %TRUE if this @client is read-only, otherwise %FALSE.
640 e_client_is_readonly (EClient *client)
642 g_return_val_if_fail (E_IS_CLIENT (client), TRUE);
644 return client->priv->readonly;
648 e_client_set_readonly (EClient *client,
651 g_return_if_fail (E_IS_CLIENT (client));
653 g_rec_mutex_lock (&client->priv->prop_mutex);
654 if (client->priv->readonly == readonly) {
655 g_rec_mutex_unlock (&client->priv->prop_mutex);
659 client->priv->readonly = readonly;
661 g_rec_mutex_unlock (&client->priv->prop_mutex);
663 g_object_notify (G_OBJECT (client), "readonly");
667 * e_client_is_online:
668 * @client: an #EClient
670 * Check if this @client is connected.
672 * Returns: %TRUE if this @client is connected, otherwise %FALSE.
677 e_client_is_online (EClient *client)
679 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
681 return client->priv->online;
685 e_client_set_online (EClient *client,
688 g_return_if_fail (E_IS_CLIENT (client));
690 /* newly connected/disconnected => make sure capabilities will be correct */
691 e_client_set_capabilities (client, NULL);
693 g_rec_mutex_lock (&client->priv->prop_mutex);
694 if (client->priv->online == is_online) {
695 g_rec_mutex_unlock (&client->priv->prop_mutex);
699 client->priv->online = is_online;
701 g_rec_mutex_unlock (&client->priv->prop_mutex);
703 g_object_notify (G_OBJECT (client), "online");
707 * e_client_is_opened:
708 * @client: an #EClient
710 * Check if this @client is fully opened. This includes
711 * everything from e_client_open() call up to the authentication,
712 * if required by a backend. Client cannot do any other operation
713 * during the opening phase except of authenticate or cancel it.
714 * Every other operation results in an %E_CLIENT_ERROR_BUSY error.
716 * Returns: always %TRUE
720 * Deprecated: 3.8: Clients don't need to care if they're fully opened
721 * anymore. This function always returns %TRUE.
724 e_client_is_opened (EClient *client)
726 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
733 * @client: an #EClient
734 * @opid: asynchronous operation ID
736 * Cancels particular asynchronous operation. The @opid is returned from
737 * an e_client_register_op(). The function does nothing if the asynchronous
738 * operation doesn't exist any more.
743 client_cancel_op (EClient *client,
746 GCancellable *cancellable;
748 g_return_if_fail (E_IS_CLIENT (client));
749 g_return_if_fail (client->priv->ops != NULL);
751 g_rec_mutex_lock (&client->priv->ops_mutex);
753 cancellable = g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (opid));
755 g_cancellable_cancel (cancellable);
757 g_rec_mutex_unlock (&client->priv->ops_mutex);
761 gather_opids_cb (gpointer opid,
762 gpointer cancellable,
765 GSList **ids = ids_list;
767 g_return_if_fail (ids_list != NULL);
769 *ids = g_slist_prepend (*ids, opid);
773 cancel_op_cb (gpointer opid,
776 client_cancel_op (client, GPOINTER_TO_INT (opid));
780 * e_client_cancel_all:
781 * @client: an #EClient
783 * Cancels all pending operations started on @client.
788 e_client_cancel_all (EClient *client)
790 GSList *opids = NULL;
792 g_return_if_fail (E_IS_CLIENT (client));
793 g_return_if_fail (client->priv->ops != NULL);
795 g_rec_mutex_lock (&client->priv->ops_mutex);
797 g_hash_table_foreach (client->priv->ops, gather_opids_cb, &opids);
799 g_slist_foreach (opids, cancel_op_cb, client);
800 g_slist_free (opids);
802 g_rec_mutex_unlock (&client->priv->ops_mutex);
806 e_client_register_op (EClient *client,
807 GCancellable *cancellable)
811 g_return_val_if_fail (E_IS_CLIENT (client), 0);
812 g_return_val_if_fail (client->priv->ops != NULL, 0);
813 g_return_val_if_fail (cancellable != NULL, 0);
815 g_rec_mutex_lock (&client->priv->ops_mutex);
817 client->priv->last_opid++;
818 if (!client->priv->last_opid)
819 client->priv->last_opid++;
821 while (g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (client->priv->last_opid)))
822 client->priv->last_opid++;
824 g_return_val_if_fail (client->priv->last_opid != 0, 0);
826 opid = client->priv->last_opid;
827 g_hash_table_insert (client->priv->ops, GINT_TO_POINTER (opid), g_object_ref (cancellable));
829 g_rec_mutex_unlock (&client->priv->ops_mutex);
835 e_client_unregister_op (EClient *client,
838 g_return_if_fail (E_IS_CLIENT (client));
839 g_return_if_fail (client->priv->ops != NULL);
841 g_rec_mutex_lock (&client->priv->ops_mutex);
842 g_hash_table_remove (client->priv->ops, GINT_TO_POINTER (opid));
843 g_rec_mutex_unlock (&client->priv->ops_mutex);
847 e_client_emit_opened (EClient *client,
848 const GError *dbus_error)
850 GError *local_error = NULL;
852 g_return_if_fail (E_IS_CLIENT (client));
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