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().
98 e_client_error_quark (void)
103 q = g_quark_from_static_string ("e-client-error-quark");
109 * e_client_error_to_string:
111 * FIXME: Document me.
116 e_client_error_to_string (EClientError code)
119 case E_CLIENT_ERROR_INVALID_ARG:
120 return _("Invalid argument");
121 case E_CLIENT_ERROR_BUSY:
122 return _("Backend is busy");
123 case E_CLIENT_ERROR_SOURCE_NOT_LOADED:
124 return _("Source not loaded");
125 case E_CLIENT_ERROR_SOURCE_ALREADY_LOADED:
126 return _("Source already loaded");
127 case E_CLIENT_ERROR_AUTHENTICATION_FAILED:
128 return _("Authentication failed");
129 case E_CLIENT_ERROR_AUTHENTICATION_REQUIRED:
130 return _("Authentication required");
131 case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
132 return _("Repository offline");
133 case E_CLIENT_ERROR_OFFLINE_UNAVAILABLE:
134 /* Translators: This means that the EClient does not support offline mode, or
135 * it's not set to by a user, thus it is unavailable while user is not connected. */
136 return _("Offline unavailable");
137 case E_CLIENT_ERROR_PERMISSION_DENIED:
138 return _("Permission denied");
139 case E_CLIENT_ERROR_CANCELLED:
140 return _("Cancelled");
141 case E_CLIENT_ERROR_COULD_NOT_CANCEL:
142 return _("Could not cancel");
143 case E_CLIENT_ERROR_NOT_SUPPORTED:
144 return _("Not supported");
145 case E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD:
146 return _("Unsupported authentication method");
147 case E_CLIENT_ERROR_TLS_NOT_AVAILABLE:
148 return _("TLS not available");
149 case E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED:
150 return _("Search size limit exceeded");
151 case E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED:
152 return _("Search time limit exceeded");
153 case E_CLIENT_ERROR_INVALID_QUERY:
154 return _("Invalid query");
155 case E_CLIENT_ERROR_QUERY_REFUSED:
156 return _("Query refused");
157 case E_CLIENT_ERROR_DBUS_ERROR:
158 return _("D-Bus error");
159 case E_CLIENT_ERROR_OTHER_ERROR:
160 return _("Other error");
161 case E_CLIENT_ERROR_NOT_OPENED:
162 return _("Backend is not opened yet");
165 return _("Unknown error");
169 * e_client_error_create:
170 * @code: an #EClientError code to create
171 * @custom_msg: custom message to use for the error; can be %NULL
173 * Returns: a new #GError containing an E_CLIENT_ERROR of the given
174 * @code. If the @custom_msg is NULL, then the error message is
175 * the one returned from e_client_error_to_string() for the @code,
176 * otherwise the given message is used.
178 * Returned pointer should be freed with g_error_free().
183 e_client_error_create (EClientError code,
184 const gchar *custom_msg)
186 return g_error_new_literal (E_CLIENT_ERROR, code, custom_msg ? custom_msg : e_client_error_to_string (code));
189 static void client_set_source (EClient *client, ESource *source);
192 e_client_init (EClient *client)
194 client->priv = E_CLIENT_GET_PRIVATE (client);
196 client->priv->readonly = TRUE;
198 g_rec_mutex_init (&client->priv->prop_mutex);
199 client->priv->backend_property_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
201 g_rec_mutex_init (&client->priv->ops_mutex);
202 client->priv->last_opid = 0;
203 client->priv->ops = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
207 client_dispose (GObject *object)
211 client = E_CLIENT (object);
213 e_client_cancel_all (client);
215 /* Chain up to parent's dispose() method. */
216 G_OBJECT_CLASS (e_client_parent_class)->dispose (object);
220 client_finalize (GObject *object)
223 EClientPrivate *priv;
225 client = E_CLIENT (object);
229 g_rec_mutex_lock (&priv->prop_mutex);
232 g_object_unref (priv->source);
241 if (priv->capabilities) {
242 g_slist_foreach (priv->capabilities, (GFunc) g_free, NULL);
243 g_slist_free (priv->capabilities);
244 priv->capabilities = NULL;
247 if (priv->backend_property_cache) {
248 g_hash_table_destroy (priv->backend_property_cache);
249 priv->backend_property_cache = NULL;
253 g_hash_table_destroy (priv->ops);
257 g_rec_mutex_unlock (&priv->prop_mutex);
258 g_rec_mutex_clear (&priv->prop_mutex);
259 g_rec_mutex_clear (&priv->ops_mutex);
261 /* Chain up to parent's finalize() method. */
262 G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
266 client_set_property (GObject *object,
271 switch (property_id) {
273 client_set_source (E_CLIENT (object), g_value_get_object (value));
277 e_client_set_online (E_CLIENT (object), g_value_get_boolean (value));
281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
285 client_get_property (GObject *object,
290 switch (property_id) {
292 g_value_set_object (value, e_client_get_source (E_CLIENT (object)));
295 case PROP_CAPABILITIES:
296 g_value_set_pointer (value, (gpointer) e_client_get_capabilities (E_CLIENT (object)));
300 g_value_set_boolean (value, e_client_is_readonly (E_CLIENT (object)));
304 g_value_set_boolean (value, e_client_is_online (E_CLIENT (object)));
308 g_value_set_boolean (value, e_client_is_opened (E_CLIENT (object)));
312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
316 client_remove_thread (GSimpleAsyncResult *simple,
318 GCancellable *cancellable)
320 GError *error = NULL;
322 e_client_remove_sync (E_CLIENT (object), cancellable, &error);
325 g_simple_async_result_take_error (simple, error);
329 client_remove (EClient *client,
330 GCancellable *cancellable,
331 GAsyncReadyCallback callback,
334 GSimpleAsyncResult *simple;
336 simple = g_simple_async_result_new (
337 G_OBJECT (client), callback, user_data, client_remove);
339 g_simple_async_result_set_check_cancellable (simple, cancellable);
341 g_simple_async_result_run_in_thread (
342 simple, client_remove_thread,
343 G_PRIORITY_DEFAULT, cancellable);
345 g_object_unref (simple);
349 client_remove_finish (EClient *client,
350 GAsyncResult *result,
353 GSimpleAsyncResult *simple;
355 g_return_val_if_fail (
356 g_simple_async_result_is_valid (
357 result, G_OBJECT (client), client_remove), FALSE);
359 simple = G_SIMPLE_ASYNC_RESULT (result);
361 /* Assume success unless a GError is set. */
362 return !g_simple_async_result_propagate_error (simple, error);
366 client_remove_sync (EClient *client,
367 GCancellable *cancellable,
372 source = e_client_get_source (client);
374 return e_source_remove_sync (source, cancellable, error);
378 e_client_class_init (EClientClass *class)
380 GObjectClass *object_class;
382 g_type_class_add_private (class, sizeof (EClientPrivate));
384 object_class = G_OBJECT_CLASS (class);
385 object_class->set_property = client_set_property;
386 object_class->get_property = client_get_property;
387 object_class->dispose = client_dispose;
388 object_class->finalize = client_finalize;
390 class->remove = client_remove;
391 class->remove_finish = client_remove_finish;
392 class->remove_sync = client_remove_sync;
394 g_object_class_install_property (
397 g_param_spec_object (
402 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
404 g_object_class_install_property (
407 g_param_spec_pointer (
413 g_object_class_install_property (
416 g_param_spec_boolean (
423 g_object_class_install_property (
426 g_param_spec_boolean (
433 g_object_class_install_property (
436 g_param_spec_boolean (
443 signals[OPENED] = g_signal_new (
445 G_OBJECT_CLASS_TYPE (class),
447 G_STRUCT_OFFSET (EClientClass, opened),
449 g_cclosure_marshal_VOID__BOXED,
453 signals[BACKEND_ERROR] = g_signal_new (
455 G_OBJECT_CLASS_TYPE (class),
457 G_STRUCT_OFFSET (EClientClass, backend_error),
459 g_cclosure_marshal_VOID__STRING,
463 signals[BACKEND_DIED] = g_signal_new (
465 G_OBJECT_CLASS_TYPE (class),
467 G_STRUCT_OFFSET (EClientClass, backend_died),
469 g_cclosure_marshal_VOID__VOID,
472 signals[BACKEND_PROPERTY_CHANGED] = g_signal_new (
473 "backend-property-changed",
474 G_OBJECT_CLASS_TYPE (class),
476 G_STRUCT_OFFSET (EClientClass, backend_property_changed),
478 e_gdbus_marshallers_VOID__STRING_STRING,
479 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
483 client_set_source (EClient *client,
486 g_return_if_fail (E_IS_CLIENT (client));
487 g_return_if_fail (E_IS_SOURCE (source));
489 g_object_ref (source);
491 if (client->priv->source)
492 g_object_unref (client->priv->source);
494 client->priv->source = source;
498 * e_client_get_source:
499 * @client: an #EClient
501 * Get the #ESource that this client has assigned.
503 * Returns: (transfer none): The source.
508 e_client_get_source (EClient *client)
510 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
512 return client->priv->source;
516 client_ensure_capabilities (EClient *client)
520 g_return_if_fail (E_IS_CLIENT (client));
522 if (client->priv->capabilities_retrieved || client->priv->capabilities)
525 g_rec_mutex_lock (&client->priv->prop_mutex);
528 e_client_retrieve_capabilities_sync (client, &capabilities, NULL, NULL);
529 /* e_client_set_capabilities is called inside the previous function */
530 g_free (capabilities);
532 client->priv->capabilities_retrieved = TRUE;
534 g_rec_mutex_unlock (&client->priv->prop_mutex);
538 * e_client_get_capabilities:
539 * @client: an #EClient
541 * Get list of strings with capabilities advertised by a backend.
542 * This list, together with inner strings, is owned by the @client.
543 * To check for individual capabilities use e_client_check_capability().
545 * Returns: (element-type utf8) (transfer none): #GSList of const strings
551 e_client_get_capabilities (EClient *client)
553 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
555 client_ensure_capabilities (client);
557 return client->priv->capabilities;
561 * e_client_check_capability:
562 * @client: an #EClient
563 * @capability: a capability
565 * Check if backend supports particular capability.
566 * To get all capabilities use e_client_get_capabilities().
568 * Returns: #GSList of const strings of capabilities
573 e_client_check_capability (EClient *client,
574 const gchar *capability)
578 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
579 g_return_val_if_fail (capability, FALSE);
581 g_rec_mutex_lock (&client->priv->prop_mutex);
583 client_ensure_capabilities (client);
585 for (iter = client->priv->capabilities; iter; iter = g_slist_next (iter)) {
586 const gchar *cap = iter->data;
588 if (cap && g_ascii_strcasecmp (cap, capability) == 0) {
589 g_rec_mutex_unlock (&client->priv->prop_mutex);
594 g_rec_mutex_unlock (&client->priv->prop_mutex);
600 * e_client_check_refresh_supported:
603 * Checks whether a client supports explicit refreshing
604 * (see e_client_refresh()).
606 * Returns: TRUE if the client supports refreshing, FALSE otherwise.
611 e_client_check_refresh_supported (EClient *client)
613 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
615 return e_client_check_capability (client, "refresh-supported");
618 /* capabilities - comma-separated list of capabilities; can be NULL to unset */
620 e_client_set_capabilities (EClient *client,
621 const gchar *capabilities)
623 g_return_if_fail (E_IS_CLIENT (client));
625 g_rec_mutex_lock (&client->priv->prop_mutex);
628 client->priv->capabilities_retrieved = FALSE;
630 g_slist_foreach (client->priv->capabilities, (GFunc) g_free, NULL);
631 g_slist_free (client->priv->capabilities);
632 client->priv->capabilities = e_client_util_parse_comma_strings (capabilities);
634 g_rec_mutex_unlock (&client->priv->prop_mutex);
636 g_object_notify (G_OBJECT (client), "capabilities");
640 * e_client_is_readonly:
641 * @client: an #EClient
643 * Check if this @client is read-only.
645 * Returns: %TRUE if this @client is read-only, otherwise %FALSE.
650 e_client_is_readonly (EClient *client)
652 g_return_val_if_fail (E_IS_CLIENT (client), TRUE);
654 return client->priv->readonly;
658 e_client_set_readonly (EClient *client,
661 g_return_if_fail (E_IS_CLIENT (client));
663 g_rec_mutex_lock (&client->priv->prop_mutex);
664 if (client->priv->readonly == readonly) {
665 g_rec_mutex_unlock (&client->priv->prop_mutex);
669 client->priv->readonly = readonly;
671 g_rec_mutex_unlock (&client->priv->prop_mutex);
673 g_object_notify (G_OBJECT (client), "readonly");
677 * e_client_is_online:
678 * @client: an #EClient
680 * Check if this @client is connected.
682 * Returns: %TRUE if this @client is connected, otherwise %FALSE.
687 e_client_is_online (EClient *client)
689 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
691 return client->priv->online;
695 e_client_set_online (EClient *client,
698 g_return_if_fail (E_IS_CLIENT (client));
700 /* newly connected/disconnected => make sure capabilities will be correct */
701 e_client_set_capabilities (client, NULL);
703 g_rec_mutex_lock (&client->priv->prop_mutex);
704 if (client->priv->online == is_online) {
705 g_rec_mutex_unlock (&client->priv->prop_mutex);
709 client->priv->online = is_online;
711 g_rec_mutex_unlock (&client->priv->prop_mutex);
713 g_object_notify (G_OBJECT (client), "online");
717 * e_client_is_opened:
718 * @client: an #EClient
720 * Check if this @client is fully opened. This includes
721 * everything from e_client_open() call up to the authentication,
722 * if required by a backend. Client cannot do any other operation
723 * during the opening phase except of authenticate or cancel it.
724 * Every other operation results in an %E_CLIENT_ERROR_BUSY error.
726 * Returns: %TRUE if this @client is fully opened, otherwise %FALSE.
731 e_client_is_opened (EClient *client)
733 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
735 return client->priv->opened;
740 * @client: an #EClient
741 * @opid: asynchronous operation ID
743 * Cancels particular asynchronous operation. The @opid is returned from
744 * an e_client_register_op(). The function does nothing if the asynchronous
745 * operation doesn't exist any more.
750 client_cancel_op (EClient *client,
753 GCancellable *cancellable;
755 g_return_if_fail (E_IS_CLIENT (client));
756 g_return_if_fail (client->priv->ops != NULL);
758 g_rec_mutex_lock (&client->priv->ops_mutex);
760 cancellable = g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (opid));
762 g_cancellable_cancel (cancellable);
764 g_rec_mutex_unlock (&client->priv->ops_mutex);
768 gather_opids_cb (gpointer opid,
769 gpointer cancellable,
772 GSList **ids = ids_list;
774 g_return_if_fail (ids_list != NULL);
776 *ids = g_slist_prepend (*ids, opid);
780 cancel_op_cb (gpointer opid,
783 client_cancel_op (client, GPOINTER_TO_INT (opid));
787 * e_client_cancel_all:
788 * @client: an #EClient
790 * Cancels all pending operations started on @client.
795 e_client_cancel_all (EClient *client)
797 GSList *opids = NULL;
799 g_return_if_fail (E_IS_CLIENT (client));
800 g_return_if_fail (client->priv->ops != NULL);
802 g_rec_mutex_lock (&client->priv->ops_mutex);
804 g_hash_table_foreach (client->priv->ops, gather_opids_cb, &opids);
806 g_slist_foreach (opids, cancel_op_cb, client);
807 g_slist_free (opids);
809 g_rec_mutex_unlock (&client->priv->ops_mutex);
813 e_client_register_op (EClient *client,
814 GCancellable *cancellable)
818 g_return_val_if_fail (E_IS_CLIENT (client), 0);
819 g_return_val_if_fail (client->priv->ops != NULL, 0);
820 g_return_val_if_fail (cancellable != NULL, 0);
822 g_rec_mutex_lock (&client->priv->ops_mutex);
824 client->priv->last_opid++;
825 if (!client->priv->last_opid)
826 client->priv->last_opid++;
828 while (g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (client->priv->last_opid)))
829 client->priv->last_opid++;
831 g_return_val_if_fail (client->priv->last_opid != 0, 0);
833 opid = client->priv->last_opid;
834 g_hash_table_insert (client->priv->ops, GINT_TO_POINTER (opid), g_object_ref (cancellable));
836 g_rec_mutex_unlock (&client->priv->ops_mutex);
842 e_client_unregister_op (EClient *client,
845 g_return_if_fail (E_IS_CLIENT (client));
846 g_return_if_fail (client->priv->ops != NULL);
848 g_rec_mutex_lock (&client->priv->ops_mutex);
849 g_hash_table_remove (client->priv->ops, GINT_TO_POINTER (opid));
850 g_rec_mutex_unlock (&client->priv->ops_mutex);
854 e_client_emit_opened (EClient *client,
855 const GError *dbus_error)
857 GError *local_error = NULL;
859 g_return_if_fail (E_IS_CLIENT (client));
861 client->priv->opened = dbus_error == NULL;
864 local_error = g_error_copy (dbus_error);
865 e_client_unwrap_dbus_error (client, local_error, &local_error);
868 g_object_notify (G_OBJECT (client), "opened");
869 g_signal_emit (client, signals[OPENED], 0, local_error);
872 g_error_free (local_error);
876 e_client_emit_backend_error (EClient *client,
877 const gchar *error_msg)
879 g_return_if_fail (E_IS_CLIENT (client));
880 g_return_if_fail (error_msg != NULL);
882 g_signal_emit (client, signals[BACKEND_ERROR], 0, error_msg);
886 e_client_emit_backend_died (EClient *client)
888 g_return_if_fail (E_IS_CLIENT (client));
890 g_signal_emit (client, signals[BACKEND_DIED], 0);
894 e_client_emit_backend_property_changed (EClient *client,
895 const gchar *prop_name,
896 const gchar *prop_value)
898 g_return_if_fail (E_IS_CLIENT (client));
899 g_return_if_fail (prop_name != NULL);
900 g_return_if_fail (*prop_name);
901 g_return_if_fail (prop_value != NULL);
903 e_client_update_backend_property_cache (client, prop_name, prop_value);
905 g_signal_emit (client, signals[BACKEND_PROPERTY_CHANGED], 0, prop_name, prop_value);
909 e_client_update_backend_property_cache (EClient *client,
910 const gchar *prop_name,
911 const gchar *prop_value)
913 g_return_if_fail (E_IS_CLIENT (client));
914 g_return_if_fail (prop_name != NULL);
915 g_return_if_fail (*prop_name);
916 g_return_if_fail (prop_value != NULL);
918 g_rec_mutex_lock (&client->priv->prop_mutex);
920 if (client->priv->backend_property_cache)
921 g_hash_table_insert (client->priv->backend_property_cache, g_strdup (prop_name), g_strdup (prop_value));
923 g_rec_mutex_unlock (&client->priv->prop_mutex);
927 e_client_get_backend_property_from_cache (EClient *client,
928 const gchar *prop_name)
930 gchar *prop_value = NULL;
932 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
933 g_return_val_if_fail (prop_name != NULL, NULL);
934 g_return_val_if_fail (*prop_name, NULL);
936 g_rec_mutex_lock (&client->priv->prop_mutex);
938 if (client->priv->backend_property_cache)
939 prop_value = g_strdup (g_hash_table_lookup (client->priv->backend_property_cache, prop_name));
941 g_rec_mutex_unlock (&client->priv->prop_mutex);
947 * e_client_retrieve_capabilities:
948 * @client: an #EClient
949 * @cancellable: a #GCancellable; can be %NULL
950 * @callback: callback to call when a result is ready
951 * @user_data: user data for the @callback
953 * Initiates retrieval of capabilities on the @client. This is usually
954 * required only once, after the @client is opened. The returned value
955 * is cached and any subsequent call of e_client_get_capabilities() and
956 * e_client_check_capability() is using the cached value.
957 * The call is finished by e_client_retrieve_capabilities_finish()
958 * from the @callback.
963 e_client_retrieve_capabilities (EClient *client,
964 GCancellable *cancellable,
965 GAsyncReadyCallback callback,
970 g_return_if_fail (E_IS_CLIENT (client));
971 g_return_if_fail (callback != NULL);
973 class = E_CLIENT_GET_CLASS (client);
974 g_return_if_fail (class != NULL);
975 g_return_if_fail (class->retrieve_capabilities != NULL);
977 class->retrieve_capabilities (client, cancellable, callback, user_data);
981 * e_client_retrieve_capabilities_finish:
982 * @client: an #EClient
983 * @result: a #GAsyncResult
984 * @capabilities: (out): Comma-separated list of capabilities of the @client
985 * @error: (out): a #GError to set an error, if any
987 * Finishes previous call of e_client_retrieve_capabilities().
988 * Returned value of @capabilities should be freed with g_free(),
989 * when no longer needed.
991 * Returns: %TRUE if successful, %FALSE otherwise.
996 e_client_retrieve_capabilities_finish (EClient *client,
997 GAsyncResult *result,
998 gchar **capabilities,
1001 EClientClass *class;
1004 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1005 g_return_val_if_fail (capabilities != NULL, FALSE);
1007 class = E_CLIENT_GET_CLASS (client);
1008 g_return_val_if_fail (class != NULL, FALSE);
1009 g_return_val_if_fail (class->retrieve_capabilities_finish != NULL, FALSE);
1011 *capabilities = NULL;
1012 res = class->retrieve_capabilities_finish (client, result, capabilities, error);
1014 e_client_set_capabilities (client, res ? *capabilities : NULL);
1016 if (error && *error)
1017 e_client_unwrap_dbus_error (client, *error, error);
1023 * e_client_retrieve_capabilities_sync:
1024 * @client: an #EClient
1025 * @capabilities: (out): Comma-separated list of capabilities of the @client
1026 * @cancellable: a #GCancellable; can be %NULL
1027 * @error: (out): a #GError to set an error, if any
1029 * Initiates retrieval of capabilities on the @client. This is usually
1030 * required only once, after the @client is opened. The returned value
1031 * is cached and any subsequent call of e_client_get_capabilities() and
1032 * e_client_check_capability() is using the cached value. Returned value
1033 * of @capabilities should be freed with g_free(), when no longer needed.
1035 * Returns: %TRUE if successful, %FALSE otherwise.
1040 e_client_retrieve_capabilities_sync (EClient *client,
1041 gchar **capabilities,
1042 GCancellable *cancellable,
1045 EClientClass *class;
1046 gboolean res = FALSE;
1048 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1049 g_return_val_if_fail (capabilities != NULL, FALSE);
1051 class = E_CLIENT_GET_CLASS (client);
1052 g_return_val_if_fail (class != NULL, FALSE);
1053 g_return_val_if_fail (class->retrieve_capabilities_sync != NULL, FALSE);
1055 *capabilities = NULL;
1056 res = class->retrieve_capabilities_sync (client, capabilities, cancellable, error);
1058 e_client_set_capabilities (client, res ? *capabilities : NULL);
1060 if (error && *error)
1061 e_client_unwrap_dbus_error (client, *error, error);
1067 * e_client_get_backend_property:
1068 * @client: an #EClient
1069 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1070 * @cancellable: a #GCancellable; can be %NULL
1071 * @callback: callback to call when a result is ready
1072 * @user_data: user data for the @callback
1074 * Queries @client's backend for a property of name @prop_name.
1075 * The call is finished by e_client_get_backend_property_finish()
1076 * from the @callback.
1081 e_client_get_backend_property (EClient *client,
1082 const gchar *prop_name,
1083 GCancellable *cancellable,
1084 GAsyncReadyCallback callback,
1087 EClientClass *class;
1089 g_return_if_fail (callback != NULL);
1090 g_return_if_fail (E_IS_CLIENT (client));
1091 g_return_if_fail (prop_name != NULL);
1093 class = E_CLIENT_GET_CLASS (client);
1094 g_return_if_fail (class != NULL);
1095 g_return_if_fail (class->get_backend_property != NULL);
1097 class->get_backend_property (client, prop_name, cancellable, callback, user_data);
1101 * e_client_get_backend_property_finish:
1102 * @client: an #EClient
1103 * @result: a #GAsyncResult
1104 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1105 * @error: (out): a #GError to set an error, if any
1107 * Finishes previous call of e_client_get_backend_property().
1109 * Returns: %TRUE if successful, %FALSE otherwise.
1114 e_client_get_backend_property_finish (EClient *client,
1115 GAsyncResult *result,
1119 EClientClass *class;
1122 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1123 g_return_val_if_fail (prop_value != NULL, FALSE);
1125 class = E_CLIENT_GET_CLASS (client);
1126 g_return_val_if_fail (class != NULL, FALSE);
1127 g_return_val_if_fail (class->get_backend_property_finish != NULL, FALSE);
1129 res = class->get_backend_property_finish (client, result, prop_value, error);
1131 if (error && *error)
1132 e_client_unwrap_dbus_error (client, *error, error);
1138 * e_client_get_backend_property_sync:
1139 * @client: an #EClient
1140 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1141 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1142 * @cancellable: a #GCancellable; can be %NULL
1143 * @error: (out): a #GError to set an error, if any
1145 * Queries @client's backend for a property of name @prop_name.
1147 * Returns: %TRUE if successful, %FALSE otherwise.
1152 e_client_get_backend_property_sync (EClient *client,
1153 const gchar *prop_name,
1155 GCancellable *cancellable,
1158 EClientClass *class;
1161 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1162 g_return_val_if_fail (prop_name != NULL, FALSE);
1163 g_return_val_if_fail (prop_value != NULL, FALSE);
1165 class = E_CLIENT_GET_CLASS (client);
1166 g_return_val_if_fail (class != NULL, FALSE);
1167 g_return_val_if_fail (class->get_backend_property_sync != NULL, FALSE);
1169 res = class->get_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1171 if (error && *error)
1172 e_client_unwrap_dbus_error (client, *error, error);
1178 * e_client_set_backend_property:
1179 * @client: an #EClient
1180 * @prop_name: property name, whose value to change; cannot be %NULL
1181 * @prop_value: property value, to set; cannot be %NULL
1182 * @cancellable: a #GCancellable; can be %NULL
1183 * @callback: callback to call when a result is ready
1184 * @user_data: user data for the @callback
1186 * Sets @client's backend property of name @prop_name
1187 * to value @prop_value. The call is finished
1188 * by e_client_set_backend_property_finish() from the @callback.
1193 e_client_set_backend_property (EClient *client,
1194 const gchar *prop_name,
1195 const gchar *prop_value,
1196 GCancellable *cancellable,
1197 GAsyncReadyCallback callback,
1200 EClientClass *class;
1202 g_return_if_fail (callback != NULL);
1203 g_return_if_fail (E_IS_CLIENT (client));
1204 g_return_if_fail (prop_name != NULL);
1205 g_return_if_fail (prop_value != NULL);
1207 class = E_CLIENT_GET_CLASS (client);
1208 g_return_if_fail (class != NULL);
1209 g_return_if_fail (class->set_backend_property != NULL);
1211 class->set_backend_property (client, prop_name, prop_value, cancellable, callback, user_data);
1215 * e_client_set_backend_property_finish:
1216 * @client: an #EClient
1217 * @result: a #GAsyncResult
1218 * @error: (out): a #GError to set an error, if any
1220 * Finishes previous call of e_client_set_backend_property().
1222 * Returns: %TRUE if successful, %FALSE otherwise.
1227 e_client_set_backend_property_finish (EClient *client,
1228 GAsyncResult *result,
1231 EClientClass *class;
1234 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1236 class = E_CLIENT_GET_CLASS (client);
1237 g_return_val_if_fail (class != NULL, FALSE);
1238 g_return_val_if_fail (class->set_backend_property_finish != NULL, FALSE);
1240 res = class->set_backend_property_finish (client, result, error);
1242 if (error && *error)
1243 e_client_unwrap_dbus_error (client, *error, error);
1249 * e_client_set_backend_property_sync:
1250 * @client: an #EClient
1251 * @prop_name: property name, whose value to change; cannot be %NULL
1252 * @prop_value: property value, to set; cannot be %NULL
1253 * @cancellable: a #GCancellable; can be %NULL
1254 * @error: (out): a #GError to set an error, if any
1256 * Sets @client's backend property of name @prop_name
1257 * to value @prop_value.
1259 * Returns: %TRUE if successful, %FALSE otherwise.
1264 e_client_set_backend_property_sync (EClient *client,
1265 const gchar *prop_name,
1266 const gchar *prop_value,
1267 GCancellable *cancellable,
1270 EClientClass *class;
1273 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1274 g_return_val_if_fail (prop_name != NULL, FALSE);
1275 g_return_val_if_fail (prop_value != NULL, FALSE);
1277 class = E_CLIENT_GET_CLASS (client);
1278 g_return_val_if_fail (class != NULL, FALSE);
1279 g_return_val_if_fail (class->set_backend_property_sync != NULL, FALSE);
1281 res = class->set_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1283 if (error && *error)
1284 e_client_unwrap_dbus_error (client, *error, error);
1291 * @client: an #EClient
1292 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1293 * @cancellable: a #GCancellable; can be %NULL
1294 * @callback: callback to call when a result is ready
1295 * @user_data: user data for the @callback
1297 * Opens the @client, making it ready for queries and other operations.
1298 * The call is finished by e_client_open_finish() from the @callback.
1303 e_client_open (EClient *client,
1304 gboolean only_if_exists,
1305 GCancellable *cancellable,
1306 GAsyncReadyCallback callback,
1309 EClientClass *class;
1311 g_return_if_fail (callback != NULL);
1312 g_return_if_fail (E_IS_CLIENT (client));
1314 class = E_CLIENT_GET_CLASS (client);
1315 g_return_if_fail (class != NULL);
1316 g_return_if_fail (class->open != NULL);
1318 class->open (client, only_if_exists, cancellable, callback, user_data);
1322 * e_client_open_finish:
1323 * @client: an #EClient
1324 * @result: a #GAsyncResult
1325 * @error: (out): a #GError to set an error, if any
1327 * Finishes previous call of e_client_open().
1329 * Returns: %TRUE if successful, %FALSE otherwise.
1334 e_client_open_finish (EClient *client,
1335 GAsyncResult *result,
1338 EClientClass *class;
1341 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1343 class = E_CLIENT_GET_CLASS (client);
1344 g_return_val_if_fail (class != NULL, FALSE);
1345 g_return_val_if_fail (class->open_finish != NULL, FALSE);
1347 res = class->open_finish (client, result, error);
1349 if (error && *error)
1350 e_client_unwrap_dbus_error (client, *error, error);
1356 * e_client_open_sync:
1357 * @client: an #EClient
1358 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1359 * @cancellable: a #GCancellable; can be %NULL
1360 * @error: (out): a #GError to set an error, if any
1362 * Opens the @client, making it ready for queries and other operations.
1364 * Returns: %TRUE if successful, %FALSE otherwise.
1369 e_client_open_sync (EClient *client,
1370 gboolean only_if_exists,
1371 GCancellable *cancellable,
1374 EClientClass *class;
1377 class = E_CLIENT_GET_CLASS (client);
1378 g_return_val_if_fail (class != NULL, FALSE);
1379 g_return_val_if_fail (class->open_sync != NULL, FALSE);
1381 res = class->open_sync (client, only_if_exists, cancellable, error);
1383 if (error && *error)
1384 e_client_unwrap_dbus_error (client, *error, error);
1391 * @client: an #EClient
1392 * @cancellable: a #GCancellable; can be %NULL
1393 * @callback: callback to call when a result is ready
1394 * @user_data: user data for the @callback
1396 * Removes the backing data for this #EClient. For example, with the file
1397 * backend this deletes the database file. You cannot get it back!
1398 * The call is finished by e_client_remove_finish() from the @callback.
1402 * Deprecated: 3.6: Use e_source_remove() instead.
1405 e_client_remove (EClient *client,
1406 GCancellable *cancellable,
1407 GAsyncReadyCallback callback,
1410 EClientClass *class;
1412 g_return_if_fail (E_IS_CLIENT (client));
1413 g_return_if_fail (callback != NULL);
1415 class = E_CLIENT_GET_CLASS (client);
1416 g_return_if_fail (class != NULL);
1417 g_return_if_fail (class->remove != NULL);
1419 class->remove (client, cancellable, callback, user_data);
1423 * e_client_remove_finish:
1424 * @client: an #EClient
1425 * @result: a #GAsyncResult
1426 * @error: (out): a #GError to set an error, if any
1428 * Finishes previous call of e_client_remove().
1430 * Returns: %TRUE if successful, %FALSE otherwise.
1434 * Deprecated: 3.6: Use e_source_remove_finish() instead.
1437 e_client_remove_finish (EClient *client,
1438 GAsyncResult *result,
1441 EClientClass *class;
1444 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1446 class = E_CLIENT_GET_CLASS (client);
1447 g_return_val_if_fail (class != NULL, FALSE);
1448 g_return_val_if_fail (class->remove_finish != NULL, FALSE);
1450 res = class->remove_finish (client, result, error);
1452 if (error && *error)
1453 e_client_unwrap_dbus_error (client, *error, error);
1459 * e_client_remove_sync:
1460 * @client: an #EClient
1461 * @cancellable: a #GCancellable; can be %NULL
1462 * @error: (out): a #GError to set an error, if any
1464 * Removes the backing data for this #EClient. For example, with the file
1465 * backend this deletes the database file. You cannot get it back!
1467 * Returns: %TRUE if successful, %FALSE otherwise.
1471 * Deprecated: 3.6: Use e_source_remove_sync() instead.
1474 e_client_remove_sync (EClient *client,
1475 GCancellable *cancellable,
1478 EClientClass *class;
1481 class = E_CLIENT_GET_CLASS (client);
1482 g_return_val_if_fail (class != NULL, FALSE);
1483 g_return_val_if_fail (class->remove_sync != NULL, FALSE);
1485 res = class->remove_sync (client, cancellable, error);
1487 if (error && *error)
1488 e_client_unwrap_dbus_error (client, *error, error);
1495 * @client: an #EClient
1496 * @cancellable: a #GCancellable; can be %NULL
1497 * @callback: callback to call when a result is ready
1498 * @user_data: user data for the @callback
1500 * Initiates refresh on the @client. Finishing the method doesn't mean
1501 * that the refresh is done, backend only notifies whether it started
1502 * refreshing or not. Use e_client_check_refresh_supported() to check
1503 * whether the backend supports this method.
1504 * The call is finished by e_client_refresh_finish() from the @callback.
1509 e_client_refresh (EClient *client,
1510 GCancellable *cancellable,
1511 GAsyncReadyCallback callback,
1514 EClientClass *class;
1516 g_return_if_fail (E_IS_CLIENT (client));
1517 g_return_if_fail (callback != NULL);
1519 class = E_CLIENT_GET_CLASS (client);
1520 g_return_if_fail (class != NULL);
1521 g_return_if_fail (class->refresh != NULL);
1523 class->refresh (client, cancellable, callback, user_data);
1527 * e_client_refresh_finish:
1528 * @client: an #EClient
1529 * @result: a #GAsyncResult
1530 * @error: (out): a #GError to set an error, if any
1532 * Finishes previous call of e_client_refresh().
1534 * Returns: %TRUE if successful, %FALSE otherwise.
1539 e_client_refresh_finish (EClient *client,
1540 GAsyncResult *result,
1543 EClientClass *class;
1546 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1548 class = E_CLIENT_GET_CLASS (client);
1549 g_return_val_if_fail (class != NULL, FALSE);
1550 g_return_val_if_fail (class->refresh_finish != NULL, FALSE);
1552 res = class->refresh_finish (client, result, error);
1554 if (error && *error)
1555 e_client_unwrap_dbus_error (client, *error, error);
1561 * e_client_refresh_sync:
1562 * @client: an #EClient
1563 * @cancellable: a #GCancellable; can be %NULL
1564 * @error: (out): a #GError to set an error, if any
1566 * Initiates refresh on the @client. Finishing the method doesn't mean
1567 * that the refresh is done, backend only notifies whether it started
1568 * refreshing or not. Use e_client_check_refresh_supported() to check
1569 * whether the backend supports this method.
1571 * Returns: %TRUE if successful, %FALSE otherwise.
1576 e_client_refresh_sync (EClient *client,
1577 GCancellable *cancellable,
1580 EClientClass *class;
1583 class = E_CLIENT_GET_CLASS (client);
1584 g_return_val_if_fail (class != NULL, FALSE);
1585 g_return_val_if_fail (class->refresh_sync != NULL, FALSE);
1587 res = class->refresh_sync (client, cancellable, error);
1589 if (error && *error)
1590 e_client_unwrap_dbus_error (client, *error, error);
1596 * e_client_util_slist_to_strv:
1597 * @strings: (element-type utf8): a #GSList of strings (const gchar *)
1599 * Convert a list of strings into a %NULL-terminated array of strings.
1601 * Returns: (transfer full): Newly allocated %NULL-terminated array of strings.
1602 * The returned pointer should be freed with g_strfreev().
1604 * Note: Paired function for this is e_client_util_strv_to_slist().
1608 * Deprecated: 3.8: Use e_util_slist_to_strv() instead.
1611 e_client_util_slist_to_strv (const GSList *strings)
1613 return e_util_slist_to_strv (strings);
1617 * e_client_util_strv_to_slist:
1618 * @strv: a %NULL-terminated array of strings (const gchar *)
1620 * Convert a %NULL-terminated array of strings to a list of strings.
1622 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
1623 * newly allocated strings. The returned pointer should be freed with
1624 * e_client_util_free_string_slist().
1626 * Note: Paired function for this is e_client_util_slist_to_strv().
1630 * Deprecated: 3.8: Use e_util_strv_to_slist() instead.
1633 e_client_util_strv_to_slist (const gchar * const *strv)
1635 return e_util_strv_to_slist (strv);
1639 * e_client_util_copy_string_slist:
1640 * @copy_to: (element-type utf8) (allow-none): Where to copy; may be %NULL
1641 * @strings: (element-type utf8): #GSList of strings to be copied
1643 * Copies the #GSList of strings to the end of @copy_to.
1645 * Returns: (transfer full) (element-type utf8): New head of @copy_to.
1646 * The returned pointer can be freed with e_client_util_free_string_slist().
1650 * Deprecated: 3.8: Use e_util_copy_string_slist() instead.
1653 e_client_util_copy_string_slist (GSList *copy_to,
1654 const GSList *strings)
1656 return e_util_copy_string_slist (copy_to, strings);
1660 * e_client_util_copy_object_slist:
1661 * @copy_to: (element-type GObject) (allow-none): Where to copy; may be %NULL
1662 * @objects: (element-type GObject): #GSList of #GObject<!-- -->s to be copied
1664 * Copies a #GSList of #GObject<!-- -->s to the end of @copy_to.
1666 * Returns: (transfer full) (element-type GObject): New head of @copy_to.
1667 * The returned pointer can be freed with e_client_util_free_object_slist().
1671 * Deprecated: 3.8: Use e_util_copy_object_slist() instead.
1674 e_client_util_copy_object_slist (GSList *copy_to,
1675 const GSList *objects)
1677 return e_util_copy_object_slist (copy_to, objects);
1681 * e_client_util_free_string_slist:
1682 * @strings: (element-type utf8): a #GSList of strings (gchar *)
1684 * Frees memory previously allocated by e_client_util_strv_to_slist().
1689 e_client_util_free_string_slist (GSList *strings)
1691 e_util_free_string_slist (strings);
1695 * e_client_util_free_object_slist:
1696 * @objects: (element-type GObject): a #GSList of #GObject<!-- -->s
1698 * Calls g_object_unref() on each member of @objects and then frees @objects
1704 e_client_util_free_object_slist (GSList *objects)
1706 e_util_free_object_slist (objects);
1710 * e_client_util_parse_comma_strings:
1711 * @strings: string of comma-separated values
1713 * Parses comma-separated list of values into #GSList.
1715 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
1716 * newly allocated strings corresponding to values parsed from @strings.
1717 * Free the returned pointer with e_client_util_free_string_slist().
1722 e_client_util_parse_comma_strings (const gchar *strings)
1724 GSList *strs_slist = NULL;
1725 gchar **strs_strv = NULL;
1728 if (!strings || !*strings)
1731 strs_strv = g_strsplit (strings, ",", -1);
1732 g_return_val_if_fail (strs_strv != NULL, NULL);
1734 for (ii = 0; strs_strv && strs_strv[ii]; ii++) {
1735 gchar *str = g_strstrip (strs_strv[ii]);
1738 strs_slist = g_slist_prepend (strs_slist, g_strdup (str));
1741 g_strfreev (strs_strv);
1743 return g_slist_reverse (strs_slist);
1747 e_client_finish_async_without_dbus (EClient *client,
1748 GCancellable *cancellable,
1749 GAsyncReadyCallback callback,
1751 gpointer source_tag,
1753 GDestroyNotify destroy_op_res)
1755 GCancellable *use_cancellable;
1756 GSimpleAsyncResult *simple;
1759 g_return_if_fail (E_IS_CLIENT (client));
1760 g_return_if_fail (callback != NULL);
1761 g_return_if_fail (source_tag != NULL);
1763 use_cancellable = cancellable;
1764 if (!use_cancellable)
1765 use_cancellable = g_cancellable_new ();
1767 opid = e_client_register_op (client, use_cancellable);
1768 g_return_if_fail (opid > 0);
1770 simple = g_simple_async_result_new (
1771 G_OBJECT (client), callback, user_data, source_tag);
1773 g_simple_async_result_set_check_cancellable (simple, cancellable);
1775 g_simple_async_result_set_op_res_gpointer (
1776 simple, op_res, destroy_op_res);
1778 g_simple_async_result_complete_in_idle (simple);
1780 g_object_unref (simple);
1782 if (use_cancellable != cancellable)
1783 g_object_unref (use_cancellable);
1787 e_client_get_dbus_proxy (EClient *client)
1789 EClientClass *class;
1791 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
1793 class = E_CLIENT_GET_CLASS (client);
1794 g_return_val_if_fail (class != NULL, NULL);
1795 g_return_val_if_fail (class->get_dbus_proxy != NULL, NULL);
1797 return class->get_dbus_proxy (client);
1801 * e_client_unwrap_dbus_error:
1802 * @client: an #EClient
1803 * @dbus_error: a #GError returned bu D-Bus
1804 * @out_error: a #GError variable where to store the result
1806 * Unwraps D-Bus error to local error. @dbus_error is automatically freed.
1807 * @dbus_erorr and @out_error can point to the same variable.
1812 e_client_unwrap_dbus_error (EClient *client,
1816 EClientClass *class;
1818 g_return_if_fail (E_IS_CLIENT (client));
1820 class = E_CLIENT_GET_CLASS (client);
1821 g_return_if_fail (class != NULL);
1822 g_return_if_fail (class->unwrap_dbus_error != NULL);
1824 if (!dbus_error || !out_error) {
1826 g_error_free (dbus_error);
1828 class->unwrap_dbus_error (client, dbus_error, out_error);
1833 * e_client_util_unwrap_dbus_error:
1834 * @dbus_error: DBus #GError to unwrap
1835 * @client_error: (out): Resulting #GError; can be %NULL
1836 * @known_errors: List of known errors against which try to match
1837 * @known_errors_count: How many items are stored in @known_errors
1838 * @known_errors_domain: Error domain for @known_errors
1839 * @fail_when_none_matched: Whether to fail when none of @known_errors matches
1841 * The function takes a @dbus_error and tries to find a match in @known_errors
1842 * for it, if it is a G_IO_ERROR, G_IO_ERROR_DBUS_ERROR. If it is anything else
1843 * then the @dbus_error is moved to @client_error.
1845 * The @fail_when_none_matched influences behaviour. If it's %TRUE, and none of
1846 * @known_errors matches, or this is not a G_IO_ERROR_DBUS_ERROR, then %FALSE
1847 * is returned and the @client_error is left without change. Otherwise, the
1848 * @fail_when_none_matched is %FALSE, the error is always processed and will
1849 * result in E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR if none of @known_error
1852 * Returns: Whether was @dbus_error processed into @client_error.
1854 * Note: The @dbus_error is automatically freed if returned %TRUE.
1859 e_client_util_unwrap_dbus_error (GError *dbus_error,
1860 GError **client_error,
1861 const EClientErrorsList *known_errors,
1862 guint known_errors_count,
1863 GQuark known_errors_domain,
1864 gboolean fail_when_none_matched)
1866 if (!client_error) {
1868 g_error_free (dbus_error);
1873 *client_error = NULL;
1877 if (dbus_error->domain == known_errors_domain) {
1878 *client_error = dbus_error;
1883 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
1887 name = g_dbus_error_get_remote_error (dbus_error);
1889 for (ii = 0; ii < known_errors_count; ii++) {
1890 if (g_ascii_strcasecmp (known_errors[ii].name, name) == 0) {
1893 g_dbus_error_strip_remote_error (dbus_error);
1894 *client_error = g_error_new_literal (known_errors_domain, known_errors[ii].err_code, dbus_error->message);
1895 g_error_free (dbus_error);
1904 if (fail_when_none_matched)
1907 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
1908 g_dbus_error_strip_remote_error (dbus_error);
1909 *client_error = g_error_new_literal (E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR, dbus_error->message);
1910 g_error_free (dbus_error);
1912 g_dbus_error_strip_remote_error (dbus_error);
1913 *client_error = dbus_error;
1919 typedef struct _EClientAsyncOpData
1924 gpointer source_tag;
1925 gchar *res_op_data; /* optional string to set on a GAsyncResult object as "res-op-data" user data */
1926 GAsyncReadyCallback callback;
1929 gboolean result; /* result of the finish function call */
1931 /* only one can be non-NULL, and the type is telling which 'out' value is valid */
1932 EClientProxyFinishVoidFunc finish_void;
1933 EClientProxyFinishBooleanFunc finish_boolean;
1934 EClientProxyFinishStringFunc finish_string;
1935 EClientProxyFinishStrvFunc finish_strv;
1936 EClientProxyFinishUintFunc finish_uint;
1939 gboolean val_boolean;
1944 } EClientAsyncOpData;
1947 async_data_free (EClientAsyncOpData *async_data)
1949 g_return_if_fail (async_data != NULL);
1950 g_return_if_fail (async_data->client != NULL);
1952 e_client_unregister_op (async_data->client, async_data->opid);
1954 if (async_data->finish_string)
1955 g_free (async_data->out.val_string);
1956 else if (async_data->finish_strv)
1957 g_strfreev (async_data->out.val_strv);
1959 g_object_unref (async_data->client);
1960 g_free (async_data->res_op_data);
1961 g_free (async_data);
1965 complete_async_op_in_idle_cb (gpointer user_data)
1967 GSimpleAsyncResult *simple = user_data;
1968 gint run_main_depth;
1970 g_return_val_if_fail (simple != NULL, FALSE);
1972 run_main_depth = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (simple), "run-main-depth"));
1973 if (run_main_depth < 1)
1976 /* do not receive in higher level than was initially run */
1977 if (g_main_depth () > run_main_depth) {
1981 g_simple_async_result_complete (simple);
1982 g_object_unref (simple);
1988 finish_async_op (EClientAsyncOpData *async_data,
1989 const GError *error,
1992 GSimpleAsyncResult *simple;
1994 g_return_if_fail (async_data != NULL);
1995 g_return_if_fail (async_data->source_tag != NULL);
1996 g_return_if_fail (async_data->client != NULL);
1998 simple = g_simple_async_result_new (G_OBJECT (async_data->client), async_data->callback, async_data->user_data, async_data->source_tag);
1999 g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
2001 if (async_data->res_op_data)
2002 g_object_set_data_full (G_OBJECT (simple), "res-op-data", g_strdup (async_data->res_op_data), g_free);
2005 g_simple_async_result_set_from_error (simple, error);
2008 g_object_set_data (G_OBJECT (simple), "run-main-depth", GINT_TO_POINTER (g_main_depth ()));
2009 g_idle_add (complete_async_op_in_idle_cb, simple);
2011 g_simple_async_result_complete (simple);
2012 g_object_unref (simple);
2017 async_result_ready_cb (GObject *source_object,
2018 GAsyncResult *result,
2021 GError *error = NULL;
2022 EClientAsyncOpData *async_data;
2025 g_return_if_fail (result != NULL);
2026 g_return_if_fail (source_object != NULL);
2028 async_data = user_data;
2029 g_return_if_fail (async_data != NULL);
2030 g_return_if_fail (async_data->client != NULL);
2032 client = async_data->client;
2033 g_return_if_fail (e_client_get_dbus_proxy (client) == G_DBUS_PROXY (source_object));
2035 if (async_data->finish_void)
2036 async_data->result = async_data->finish_void (G_DBUS_PROXY (source_object), result, &error);
2037 else if (async_data->finish_boolean)
2038 async_data->result = async_data->finish_boolean (G_DBUS_PROXY (source_object), result, &async_data->out.val_boolean, &error);
2039 else if (async_data->finish_string)
2040 async_data->result = async_data->finish_string (G_DBUS_PROXY (source_object), result, &async_data->out.val_string, &error);
2041 else if (async_data->finish_strv)
2042 async_data->result = async_data->finish_strv (G_DBUS_PROXY (source_object), result, &async_data->out.val_strv, &error);
2043 else if (async_data->finish_uint)
2044 async_data->result = async_data->finish_uint (G_DBUS_PROXY (source_object), result, &async_data->out.val_uint, &error);
2046 g_warning ("%s: Do not know how to finish async operation", G_STRFUNC);
2048 finish_async_op (async_data, error, FALSE);
2051 g_error_free (error);
2054 static EClientAsyncOpData *
2055 prepare_async_data (EClient *client,
2056 GCancellable *cancellable,
2057 GAsyncReadyCallback callback,
2059 gpointer source_tag,
2060 gboolean error_report_only,
2061 EClientProxyFinishVoidFunc finish_void,
2062 EClientProxyFinishBooleanFunc finish_boolean,
2063 EClientProxyFinishStringFunc finish_string,
2064 EClientProxyFinishStrvFunc finish_strv,
2065 EClientProxyFinishUintFunc finish_uint,
2067 GCancellable **out_cancellable)
2069 EClientAsyncOpData *async_data;
2070 GCancellable *use_cancellable;
2073 g_return_val_if_fail (client != NULL, NULL);
2074 g_return_val_if_fail (callback != NULL, NULL);
2075 g_return_val_if_fail (source_tag != NULL, NULL);
2077 if (!error_report_only) {
2078 g_return_val_if_fail (proxy != NULL, NULL);
2079 g_return_val_if_fail (out_cancellable != NULL, NULL);
2080 g_return_val_if_fail (finish_void || finish_boolean || finish_string || finish_strv || finish_uint, NULL);
2083 g_return_val_if_fail (finish_boolean == NULL, NULL);
2084 g_return_val_if_fail (finish_string == NULL, NULL);
2085 g_return_val_if_fail (finish_strv == NULL, NULL);
2086 g_return_val_if_fail (finish_uint == NULL, NULL);
2089 if (finish_boolean) {
2090 g_return_val_if_fail (finish_void == NULL, NULL);
2091 g_return_val_if_fail (finish_string == NULL, NULL);
2092 g_return_val_if_fail (finish_strv == NULL, NULL);
2093 g_return_val_if_fail (finish_uint == NULL, NULL);
2096 if (finish_string) {
2097 g_return_val_if_fail (finish_void == NULL, NULL);
2098 g_return_val_if_fail (finish_boolean == NULL, NULL);
2099 g_return_val_if_fail (finish_strv == NULL, NULL);
2100 g_return_val_if_fail (finish_uint == NULL, NULL);
2104 g_return_val_if_fail (finish_void == NULL, NULL);
2105 g_return_val_if_fail (finish_boolean == NULL, NULL);
2106 g_return_val_if_fail (finish_string == NULL, NULL);
2107 g_return_val_if_fail (finish_uint == NULL, NULL);
2111 g_return_val_if_fail (finish_void == NULL, NULL);
2112 g_return_val_if_fail (finish_boolean == NULL, NULL);
2113 g_return_val_if_fail (finish_string == NULL, NULL);
2114 g_return_val_if_fail (finish_strv == NULL, NULL);
2117 *proxy = e_client_get_dbus_proxy (client);
2122 use_cancellable = cancellable;
2123 if (!use_cancellable)
2124 use_cancellable = g_cancellable_new ();
2126 opid = e_client_register_op (client, use_cancellable);
2127 async_data = g_new0 (EClientAsyncOpData, 1);
2128 async_data->client = g_object_ref (client);
2129 async_data->opid = opid;
2130 async_data->source_tag = source_tag;
2131 async_data->callback = callback;
2132 async_data->user_data = user_data;
2133 async_data->finish_void = finish_void;
2134 async_data->finish_boolean = finish_boolean;
2135 async_data->finish_string = finish_string;
2136 async_data->finish_strv = finish_strv;
2137 async_data->finish_uint = finish_uint;
2139 /* EClient from e_client_register_op() took ownership of the use_cancellable */
2140 if (use_cancellable != cancellable)
2141 g_object_unref (use_cancellable);
2143 if (out_cancellable)
2144 *out_cancellable = use_cancellable;
2150 e_client_proxy_return_async_error (EClient *client,
2151 const GError *error,
2152 GAsyncReadyCallback callback,
2154 gpointer source_tag)
2156 EClientAsyncOpData *async_data;
2158 g_return_if_fail (E_IS_CLIENT (client));
2159 g_return_if_fail (error != NULL);
2160 g_return_if_fail (callback != NULL);
2162 async_data = prepare_async_data (client, NULL, callback, user_data, source_tag, TRUE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2163 g_return_if_fail (async_data != NULL);
2165 finish_async_op (async_data, error, TRUE);
2169 e_client_proxy_call_void (EClient *client,
2170 GCancellable *cancellable,
2171 GAsyncReadyCallback callback,
2173 gpointer source_tag,
2174 void (*func) (GDBusProxy *proxy,
2175 GCancellable *cancellable,
2176 GAsyncReadyCallback callback,
2177 gpointer user_data),
2178 EClientProxyFinishVoidFunc finish_void,
2179 EClientProxyFinishBooleanFunc finish_boolean,
2180 EClientProxyFinishStringFunc finish_string,
2181 EClientProxyFinishStrvFunc finish_strv,
2182 EClientProxyFinishUintFunc finish_uint)
2184 EClientAsyncOpData *async_data;
2185 GDBusProxy *proxy = NULL;
2187 g_return_if_fail (E_IS_CLIENT (client));
2188 g_return_if_fail (callback != NULL);
2189 g_return_if_fail (source_tag != NULL);
2190 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2192 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);
2193 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2195 func (proxy, cancellable, async_result_ready_cb, async_data);
2199 e_client_proxy_call_boolean (EClient *client,
2200 gboolean in_boolean,
2201 GCancellable *cancellable,
2202 GAsyncReadyCallback callback,
2204 gpointer source_tag,
2205 void (*func) (GDBusProxy *proxy,
2206 gboolean in_boolean,
2207 GCancellable *cancellable,
2208 GAsyncReadyCallback callback,
2209 gpointer user_data),
2210 EClientProxyFinishVoidFunc finish_void,
2211 EClientProxyFinishBooleanFunc finish_boolean,
2212 EClientProxyFinishStringFunc finish_string,
2213 EClientProxyFinishStrvFunc finish_strv,
2214 EClientProxyFinishUintFunc finish_uint)
2216 EClientAsyncOpData *async_data;
2217 GDBusProxy *proxy = NULL;
2219 g_return_if_fail (E_IS_CLIENT (client));
2220 g_return_if_fail (callback != NULL);
2221 g_return_if_fail (source_tag != NULL);
2222 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2224 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);
2225 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2227 func (proxy, in_boolean, cancellable, async_result_ready_cb, async_data);
2231 e_client_proxy_call_string (EClient *client,
2232 const gchar *in_string,
2233 GCancellable *cancellable,
2234 GAsyncReadyCallback callback,
2236 gpointer source_tag,
2237 void (*func) (GDBusProxy *proxy,
2238 const gchar *in_string,
2239 GCancellable *cancellable,
2240 GAsyncReadyCallback callback,
2241 gpointer user_data),
2242 EClientProxyFinishVoidFunc finish_void,
2243 EClientProxyFinishBooleanFunc finish_boolean,
2244 EClientProxyFinishStringFunc finish_string,
2245 EClientProxyFinishStrvFunc finish_strv,
2246 EClientProxyFinishUintFunc finish_uint)
2248 EClientAsyncOpData *async_data;
2249 GDBusProxy *proxy = NULL;
2251 g_return_if_fail (E_IS_CLIENT (client));
2252 g_return_if_fail (callback != NULL);
2253 g_return_if_fail (source_tag != NULL);
2254 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2255 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2257 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);
2258 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2260 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2264 e_client_proxy_call_string_with_res_op_data (EClient *client,
2265 const gchar *in_string,
2266 GCancellable *cancellable,
2267 GAsyncReadyCallback callback,
2269 gpointer source_tag,
2270 const gchar *res_op_data,
2271 void (*func) (GDBusProxy *proxy,
2272 const gchar *in_string,
2273 GCancellable *cancellable,
2274 GAsyncReadyCallback callback,
2275 gpointer user_data),
2276 EClientProxyFinishVoidFunc finish_void,
2277 EClientProxyFinishBooleanFunc finish_boolean,
2278 EClientProxyFinishStringFunc finish_string,
2279 EClientProxyFinishStrvFunc finish_strv,
2280 EClientProxyFinishUintFunc finish_uint)
2282 EClientAsyncOpData *async_data;
2283 GDBusProxy *proxy = NULL;
2285 g_return_if_fail (E_IS_CLIENT (client));
2286 g_return_if_fail (callback != NULL);
2287 g_return_if_fail (source_tag != NULL);
2288 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2289 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2291 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);
2292 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2294 async_data->res_op_data = g_strdup (res_op_data);
2296 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2300 e_client_proxy_call_strv (EClient *client,
2301 const gchar * const *in_strv,
2302 GCancellable *cancellable,
2303 GAsyncReadyCallback callback,
2305 gpointer source_tag,
2306 void (*func) (GDBusProxy *proxy,
2307 const gchar * const * in_strv,
2308 GCancellable *cancellable,
2309 GAsyncReadyCallback callback,
2310 gpointer user_data),
2311 EClientProxyFinishVoidFunc finish_void,
2312 EClientProxyFinishBooleanFunc finish_boolean,
2313 EClientProxyFinishStringFunc finish_string,
2314 EClientProxyFinishStrvFunc finish_strv,
2315 EClientProxyFinishUintFunc finish_uint)
2317 EClientAsyncOpData *async_data;
2318 GDBusProxy *proxy = NULL;
2320 g_return_if_fail (E_IS_CLIENT (client));
2321 g_return_if_fail (callback != NULL);
2322 g_return_if_fail (source_tag != NULL);
2323 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2324 e_client_return_async_if_fail (in_strv != NULL, client, callback, user_data, source_tag);
2326 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);
2327 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2329 func (proxy, in_strv, cancellable, async_result_ready_cb, async_data);
2333 e_client_proxy_call_uint (EClient *client,
2335 GCancellable *cancellable,
2336 GAsyncReadyCallback callback,
2338 gpointer source_tag,
2339 void (*func) (GDBusProxy *proxy,
2341 GCancellable *cancellable,
2342 GAsyncReadyCallback callback,
2343 gpointer user_data),
2344 EClientProxyFinishVoidFunc finish_void,
2345 EClientProxyFinishBooleanFunc finish_boolean,
2346 EClientProxyFinishStringFunc finish_string,
2347 EClientProxyFinishStrvFunc finish_strv,
2348 EClientProxyFinishUintFunc finish_uint)
2350 EClientAsyncOpData *async_data;
2351 GDBusProxy *proxy = NULL;
2353 g_return_if_fail (E_IS_CLIENT (client));
2354 g_return_if_fail (callback != NULL);
2355 g_return_if_fail (source_tag != NULL);
2356 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2358 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);
2359 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2361 func (proxy, in_uint, cancellable, async_result_ready_cb, async_data);
2365 e_client_proxy_call_finish_void (EClient *client,
2366 GAsyncResult *result,
2368 gpointer source_tag)
2370 GSimpleAsyncResult *simple;
2371 GError *local_error = NULL;
2372 EClientAsyncOpData *async_data;
2374 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2375 g_return_val_if_fail (result != NULL, FALSE);
2376 g_return_val_if_fail (source_tag != NULL, FALSE);
2377 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2379 simple = G_SIMPLE_ASYNC_RESULT (result);
2381 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2382 e_client_unwrap_dbus_error (client, local_error, error);
2386 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2387 g_return_val_if_fail (async_data != NULL, FALSE);
2389 return async_data->result;
2393 e_client_proxy_call_finish_boolean (EClient *client,
2394 GAsyncResult *result,
2395 gboolean *out_boolean,
2397 gpointer source_tag)
2399 GSimpleAsyncResult *simple;
2400 GError *local_error = NULL;
2401 EClientAsyncOpData *async_data;
2403 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2404 g_return_val_if_fail (result != NULL, FALSE);
2405 g_return_val_if_fail (source_tag != NULL, FALSE);
2406 g_return_val_if_fail (out_boolean != NULL, FALSE);
2407 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2409 simple = G_SIMPLE_ASYNC_RESULT (result);
2411 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2412 e_client_unwrap_dbus_error (client, local_error, error);
2416 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2417 g_return_val_if_fail (async_data != NULL, FALSE);
2419 *out_boolean = async_data->out.val_boolean;
2421 return async_data->result;
2425 e_client_proxy_call_finish_string (EClient *client,
2426 GAsyncResult *result,
2429 gpointer source_tag)
2431 GSimpleAsyncResult *simple;
2432 GError *local_error = NULL;
2433 EClientAsyncOpData *async_data;
2435 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2436 g_return_val_if_fail (result != NULL, FALSE);
2437 g_return_val_if_fail (source_tag != NULL, FALSE);
2438 g_return_val_if_fail (out_string != NULL, FALSE);
2439 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2441 simple = G_SIMPLE_ASYNC_RESULT (result);
2443 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2444 e_client_unwrap_dbus_error (client, local_error, error);
2448 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2449 g_return_val_if_fail (async_data != NULL, FALSE);
2451 *out_string = async_data->out.val_string;
2452 async_data->out.val_string = NULL;
2454 return async_data->result;
2458 e_client_proxy_call_finish_strv (EClient *client,
2459 GAsyncResult *result,
2462 gpointer source_tag)
2464 GSimpleAsyncResult *simple;
2465 GError *local_error = NULL;
2466 EClientAsyncOpData *async_data;
2468 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2469 g_return_val_if_fail (result != NULL, FALSE);
2470 g_return_val_if_fail (source_tag != NULL, FALSE);
2471 g_return_val_if_fail (out_strv != NULL, FALSE);
2472 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2474 simple = G_SIMPLE_ASYNC_RESULT (result);
2476 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2477 e_client_unwrap_dbus_error (client, local_error, error);
2481 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2482 g_return_val_if_fail (async_data != NULL, FALSE);
2484 *out_strv = async_data->out.val_strv;
2485 async_data->out.val_strv = NULL;
2487 return async_data->result;
2491 e_client_proxy_call_finish_uint (EClient *client,
2492 GAsyncResult *result,
2495 gpointer source_tag)
2497 GSimpleAsyncResult *simple;
2498 GError *local_error = NULL;
2499 EClientAsyncOpData *async_data;
2501 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2502 g_return_val_if_fail (result != NULL, FALSE);
2503 g_return_val_if_fail (source_tag != NULL, FALSE);
2504 g_return_val_if_fail (out_uint != NULL, FALSE);
2505 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2507 simple = G_SIMPLE_ASYNC_RESULT (result);
2509 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2510 e_client_unwrap_dbus_error (client, local_error, error);
2514 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2515 g_return_val_if_fail (async_data != NULL, FALSE);
2517 *out_uint = async_data->out.val_uint;
2519 return async_data->result;
2522 #define SYNC_CALL_TEMPLATE(_out_test,_the_call) \
2523 GDBusProxy *proxy; \
2524 GCancellable *use_cancellable; \
2527 GError *local_error = NULL; \
2529 g_return_val_if_fail (E_IS_CLIENT (client), FALSE); \
2530 g_return_val_if_fail (func != NULL, FALSE); \
2531 g_return_val_if_fail (_out_test != NULL, FALSE); \
2533 proxy = e_client_get_dbus_proxy (client); \
2534 g_return_val_if_fail (proxy != NULL, FALSE); \
2536 use_cancellable = cancellable; \
2537 if (!use_cancellable) \
2538 use_cancellable = g_cancellable_new (); \
2540 g_object_ref (client); \
2541 opid = e_client_register_op (client, use_cancellable); \
2543 result = func _the_call; \
2545 e_client_unregister_op (client, opid); \
2546 g_object_unref (client); \
2548 if (use_cancellable != cancellable) \
2549 g_object_unref (use_cancellable); \
2551 e_client_unwrap_dbus_error (client, local_error, error);\
2556 e_client_proxy_call_sync_void__void (EClient *client,
2557 GCancellable *cancellable,
2559 gboolean (*func) (GDBusProxy *proxy,
2560 GCancellable *cancellable,
2563 SYNC_CALL_TEMPLATE (client, (proxy, use_cancellable, &local_error))
2567 e_client_proxy_call_sync_void__boolean (EClient *client,
2568 gboolean *out_boolean,
2569 GCancellable *cancellable,
2571 gboolean (*func) (GDBusProxy *proxy,
2572 gboolean *out_boolean,
2573 GCancellable *cancellable,
2576 SYNC_CALL_TEMPLATE (out_boolean, (proxy, out_boolean, use_cancellable, &local_error))
2580 e_client_proxy_call_sync_void__string (EClient *client,
2582 GCancellable *cancellable,
2584 gboolean (*func) (GDBusProxy *proxy,
2586 GCancellable *cancellable,
2589 SYNC_CALL_TEMPLATE (out_string, (proxy, out_string, use_cancellable, &local_error))
2593 e_client_proxy_call_sync_void__strv (EClient *client,
2595 GCancellable *cancellable,
2597 gboolean (*func) (GDBusProxy *proxy,
2599 GCancellable *cancellable,
2602 SYNC_CALL_TEMPLATE (out_strv, (proxy, out_strv, use_cancellable, &local_error))
2606 e_client_proxy_call_sync_void__uint (EClient *client,
2608 GCancellable *cancellable,
2610 gboolean (*func) (GDBusProxy *proxy,
2612 GCancellable *cancellable,
2615 SYNC_CALL_TEMPLATE (out_uint, (proxy, out_uint, use_cancellable, &local_error))
2619 e_client_proxy_call_sync_boolean__void (EClient *client,
2620 gboolean in_boolean,
2621 GCancellable *cancellable,
2623 gboolean (*func) (GDBusProxy *proxy,
2624 gboolean in_boolean,
2625 GCancellable *cancellable,
2628 SYNC_CALL_TEMPLATE (client, (proxy, in_boolean, use_cancellable, &local_error))
2632 e_client_proxy_call_sync_boolean__boolean (EClient *client,
2633 gboolean in_boolean,
2634 gboolean *out_boolean,
2635 GCancellable *cancellable,
2637 gboolean (*func) (GDBusProxy *proxy,
2638 gboolean in_boolean,
2639 gboolean *out_boolean,
2640 GCancellable *cancellable,
2643 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_boolean, out_boolean, use_cancellable, &local_error))
2647 e_client_proxy_call_sync_boolean__string (EClient *client,
2648 gboolean in_boolean,
2650 GCancellable *cancellable,
2652 gboolean (*func) (GDBusProxy *proxy,
2653 gboolean in_boolean,
2655 GCancellable *cancellable,
2658 SYNC_CALL_TEMPLATE (out_string, (proxy, in_boolean, out_string, use_cancellable, &local_error))
2662 e_client_proxy_call_sync_boolean__strv (EClient *client,
2663 gboolean in_boolean,
2665 GCancellable *cancellable,
2667 gboolean (*func) (GDBusProxy *proxy,
2668 gboolean in_boolean,
2670 GCancellable *cancellable,
2673 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_boolean, out_strv, use_cancellable, &local_error))
2677 e_client_proxy_call_sync_boolean__uint (EClient *client,
2678 gboolean in_boolean,
2680 GCancellable *cancellable,
2682 gboolean (*func) (GDBusProxy *proxy,
2683 gboolean in_boolean,
2685 GCancellable *cancellable,
2688 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_boolean, out_uint, use_cancellable, &local_error))
2692 e_client_proxy_call_sync_string__void (EClient *client,
2693 const gchar *in_string,
2694 GCancellable *cancellable,
2696 gboolean (*func) (GDBusProxy *proxy,
2697 const gchar *in_string,
2698 GCancellable *cancellable,
2701 SYNC_CALL_TEMPLATE (client, (proxy, in_string, use_cancellable, &local_error))
2705 e_client_proxy_call_sync_string__boolean (EClient *client,
2706 const gchar *in_string,
2707 gboolean *out_boolean,
2708 GCancellable *cancellable,
2710 gboolean (*func) (GDBusProxy *proxy,
2711 const gchar *in_string,
2712 gboolean *out_boolean,
2713 GCancellable *cancellable,
2716 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_string, out_boolean, use_cancellable, &local_error))
2720 e_client_proxy_call_sync_string__string (EClient *client,
2721 const gchar *in_string,
2723 GCancellable *cancellable,
2725 gboolean (*func) (GDBusProxy *proxy,
2726 const gchar *in_string,
2728 GCancellable *cancellable,
2731 SYNC_CALL_TEMPLATE (out_string, (proxy, in_string, out_string, use_cancellable, &local_error))
2735 e_client_proxy_call_sync_string__strv (EClient *client,
2736 const gchar *in_string,
2738 GCancellable *cancellable,
2740 gboolean (*func) (GDBusProxy *proxy,
2741 const gchar *in_string,
2743 GCancellable *cancellable,
2746 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_string, out_strv, use_cancellable, &local_error))
2750 e_client_proxy_call_sync_string__uint (EClient *client,
2751 const gchar *in_string,
2753 GCancellable *cancellable,
2755 gboolean (*func) (GDBusProxy *proxy,
2756 const gchar *in_string,
2758 GCancellable *cancellable,
2761 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_string, out_uint, use_cancellable, &local_error))
2765 e_client_proxy_call_sync_strv__void (EClient *client,
2766 const gchar * const *in_strv,
2767 GCancellable *cancellable,
2769 gboolean (*func) (GDBusProxy *proxy,
2770 const gchar * const *in_strv,
2771 GCancellable *cancellable,
2774 SYNC_CALL_TEMPLATE (client, (proxy, in_strv, use_cancellable, &local_error))
2778 e_client_proxy_call_sync_strv__boolean (EClient *client,
2779 const gchar * const *in_strv,
2780 gboolean *out_boolean,
2781 GCancellable *cancellable,
2783 gboolean (*func) (GDBusProxy *proxy,
2784 const gchar * const *in_strv,
2785 gboolean *out_boolean,
2786 GCancellable *cancellable,
2789 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_strv, out_boolean, use_cancellable, &local_error))
2793 e_client_proxy_call_sync_strv__string (EClient *client,
2794 const gchar * const *in_strv,
2796 GCancellable *cancellable,
2798 gboolean (*func) (GDBusProxy *proxy,
2799 const gchar * const *in_strv,
2801 GCancellable *cancellable,
2804 SYNC_CALL_TEMPLATE (out_string, (proxy, in_strv, out_string, use_cancellable, &local_error))
2808 e_client_proxy_call_sync_strv__strv (EClient *client,
2809 const gchar * const *in_strv,
2811 GCancellable *cancellable,
2813 gboolean (*func) (GDBusProxy *proxy,
2814 const gchar * const *in_strv,
2816 GCancellable *cancellable,
2819 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_strv, out_strv, use_cancellable, &local_error))
2823 e_client_proxy_call_sync_strv__uint (EClient *client,
2824 const gchar * const *in_strv,
2826 GCancellable *cancellable,
2828 gboolean (*func) (GDBusProxy *proxy,
2829 const gchar * const *in_strv,
2831 GCancellable *cancellable,
2834 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_strv, out_uint, use_cancellable, &local_error))
2838 e_client_proxy_call_sync_uint__void (EClient *client,
2840 GCancellable *cancellable,
2842 gboolean (*func) (GDBusProxy *proxy,
2844 GCancellable *cancellable,
2847 SYNC_CALL_TEMPLATE (client, (proxy, in_uint, use_cancellable, &local_error))
2851 e_client_proxy_call_sync_uint__boolean (EClient *client,
2853 gboolean *out_boolean,
2854 GCancellable *cancellable,
2856 gboolean (*func) (GDBusProxy *proxy,
2858 gboolean *out_boolean,
2859 GCancellable *cancellable,
2862 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_uint, out_boolean, use_cancellable, &local_error))
2866 e_client_proxy_call_sync_uint__string (EClient *client,
2869 GCancellable *cancellable,
2871 gboolean (*func) (GDBusProxy *proxy,
2874 GCancellable *cancellable,
2877 SYNC_CALL_TEMPLATE (out_string, (proxy, in_uint, out_string, use_cancellable, &local_error))
2881 e_client_proxy_call_sync_uint__strv (EClient *client,
2884 GCancellable *cancellable,
2886 gboolean (*func) (GDBusProxy *proxy,
2889 GCancellable *cancellable,
2892 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_uint, out_strv, use_cancellable, &local_error))
2896 e_client_proxy_call_sync_uint__uint (EClient *client,
2899 GCancellable *cancellable,
2901 gboolean (*func) (GDBusProxy *proxy,
2904 GCancellable *cancellable,
2907 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_uint, out_uint, use_cancellable, &local_error))
2910 #undef SYNC_CALL_TEMPLATE