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 typedef struct _AsyncContext AsyncContext;
42 struct _EClientPrivate {
49 gboolean capabilities_retrieved;
52 GHashTable *backend_property_cache;
56 GHashTable *ops; /* opid to GCancellable */
59 struct _AsyncContext {
63 gboolean only_if_exists;
79 BACKEND_PROPERTY_CHANGED,
83 static guint signals[LAST_SIGNAL];
85 G_DEFINE_ABSTRACT_TYPE (EClient, e_client, G_TYPE_OBJECT)
88 async_context_free (AsyncContext *async_context)
90 g_free (async_context->capabilities);
91 g_free (async_context->prop_name);
92 g_free (async_context->prop_value);
94 g_slice_free (AsyncContext, async_context);
98 * Well-known client backend properties, which are common for each #EClient:
99 * @CLIENT_BACKEND_PROPERTY_OPENED: Is set to "TRUE" or "FALSE" depending
100 * whether the backend is fully opened.
101 * @CLIENT_BACKEND_PROPERTY_OPENING: Is set to "TRUE" or "FALSE" depending
102 * whether the backend is processing its opening phase.
103 * @CLIENT_BACKEND_PROPERTY_ONLINE: Is set to "TRUE" or "FALSE" depending
104 * on the backend's loaded state. See also e_client_is_online().
105 * @CLIENT_BACKEND_PROPERTY_READONLY: Is set to "TRUE" or "FALSE" depending
106 * on the backend's readonly state. See also e_client_is_readonly().
107 * @CLIENT_BACKEND_PROPERTY_CACHE_DIR: Local folder with cached data used
109 * @CLIENT_BACKEND_PROPERTY_CAPABILITIES: Retrieves comma-separated list
110 * of capabilities supported by the backend. Preferred method of retreiving
111 * and working with capabilities is e_client_get_capabilities() and
112 * e_client_check_capability().
115 G_DEFINE_QUARK (e-client-error-quark, e_client_error)
118 * e_client_error_to_string:
120 * FIXME: Document me.
125 e_client_error_to_string (EClientError code)
128 case E_CLIENT_ERROR_INVALID_ARG:
129 return _("Invalid argument");
130 case E_CLIENT_ERROR_BUSY:
131 return _("Backend is busy");
132 case E_CLIENT_ERROR_SOURCE_NOT_LOADED:
133 return _("Source not loaded");
134 case E_CLIENT_ERROR_SOURCE_ALREADY_LOADED:
135 return _("Source already loaded");
136 case E_CLIENT_ERROR_AUTHENTICATION_FAILED:
137 return _("Authentication failed");
138 case E_CLIENT_ERROR_AUTHENTICATION_REQUIRED:
139 return _("Authentication required");
140 case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
141 return _("Repository offline");
142 case E_CLIENT_ERROR_OFFLINE_UNAVAILABLE:
143 /* Translators: This means that the EClient does not support offline mode, or
144 * it's not set to by a user, thus it is unavailable while user is not connected. */
145 return _("Offline unavailable");
146 case E_CLIENT_ERROR_PERMISSION_DENIED:
147 return _("Permission denied");
148 case E_CLIENT_ERROR_CANCELLED:
149 return _("Cancelled");
150 case E_CLIENT_ERROR_COULD_NOT_CANCEL:
151 return _("Could not cancel");
152 case E_CLIENT_ERROR_NOT_SUPPORTED:
153 return _("Not supported");
154 case E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD:
155 return _("Unsupported authentication method");
156 case E_CLIENT_ERROR_TLS_NOT_AVAILABLE:
157 return _("TLS not available");
158 case E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED:
159 return _("Search size limit exceeded");
160 case E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED:
161 return _("Search time limit exceeded");
162 case E_CLIENT_ERROR_INVALID_QUERY:
163 return _("Invalid query");
164 case E_CLIENT_ERROR_QUERY_REFUSED:
165 return _("Query refused");
166 case E_CLIENT_ERROR_DBUS_ERROR:
167 return _("D-Bus error");
168 case E_CLIENT_ERROR_OTHER_ERROR:
169 return _("Other error");
170 case E_CLIENT_ERROR_NOT_OPENED:
171 return _("Backend is not opened yet");
174 return _("Unknown error");
178 * e_client_error_create:
179 * @code: an #EClientError code to create
180 * @custom_msg: custom message to use for the error; can be %NULL
182 * Returns: a new #GError containing an E_CLIENT_ERROR of the given
183 * @code. If the @custom_msg is NULL, then the error message is
184 * the one returned from e_client_error_to_string() for the @code,
185 * otherwise the given message is used.
187 * Returned pointer should be freed with g_error_free().
192 e_client_error_create (EClientError code,
193 const gchar *custom_msg)
195 return g_error_new_literal (E_CLIENT_ERROR, code, custom_msg ? custom_msg : e_client_error_to_string (code));
198 static void client_set_source (EClient *client, ESource *source);
201 e_client_init (EClient *client)
203 client->priv = E_CLIENT_GET_PRIVATE (client);
205 client->priv->readonly = TRUE;
207 g_rec_mutex_init (&client->priv->prop_mutex);
208 client->priv->backend_property_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
210 g_rec_mutex_init (&client->priv->ops_mutex);
211 client->priv->last_opid = 0;
212 client->priv->ops = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
216 client_dispose (GObject *object)
220 client = E_CLIENT (object);
222 e_client_cancel_all (client);
224 /* Chain up to parent's dispose() method. */
225 G_OBJECT_CLASS (e_client_parent_class)->dispose (object);
229 client_finalize (GObject *object)
232 EClientPrivate *priv;
234 client = E_CLIENT (object);
238 g_rec_mutex_lock (&priv->prop_mutex);
241 g_object_unref (priv->source);
250 if (priv->capabilities) {
251 g_slist_foreach (priv->capabilities, (GFunc) g_free, NULL);
252 g_slist_free (priv->capabilities);
253 priv->capabilities = NULL;
256 if (priv->backend_property_cache) {
257 g_hash_table_destroy (priv->backend_property_cache);
258 priv->backend_property_cache = NULL;
262 g_hash_table_destroy (priv->ops);
266 g_rec_mutex_unlock (&priv->prop_mutex);
267 g_rec_mutex_clear (&priv->prop_mutex);
268 g_rec_mutex_clear (&priv->ops_mutex);
270 /* Chain up to parent's finalize() method. */
271 G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
275 client_set_property (GObject *object,
280 switch (property_id) {
282 client_set_source (E_CLIENT (object), g_value_get_object (value));
286 e_client_set_online (E_CLIENT (object), g_value_get_boolean (value));
290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
294 client_get_property (GObject *object,
299 switch (property_id) {
301 g_value_set_object (value, e_client_get_source (E_CLIENT (object)));
304 case PROP_CAPABILITIES:
305 g_value_set_pointer (value, (gpointer) e_client_get_capabilities (E_CLIENT (object)));
309 g_value_set_boolean (value, e_client_is_readonly (E_CLIENT (object)));
313 g_value_set_boolean (value, e_client_is_online (E_CLIENT (object)));
317 g_value_set_boolean (value, e_client_is_opened (E_CLIENT (object)));
321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
324 /* Helper for client_retrieve_capabilities() */
326 client_retrieve_capabilities_thread (GSimpleAsyncResult *simple,
327 GObject *source_object,
328 GCancellable *cancellable)
330 AsyncContext *async_context;
331 GError *error = NULL;
333 async_context = g_simple_async_result_get_op_res_gpointer (simple);
335 e_client_retrieve_capabilities_sync (
336 E_CLIENT (source_object),
337 &async_context->capabilities,
338 cancellable, &error);
341 g_simple_async_result_take_error (simple, error);
345 client_retrieve_capabilities (EClient *client,
346 GCancellable *cancellable,
347 GAsyncReadyCallback callback,
350 GSimpleAsyncResult *simple;
351 AsyncContext *async_context;
353 async_context = g_slice_new0 (AsyncContext);
355 simple = g_simple_async_result_new (
356 G_OBJECT (client), callback,
357 user_data, client_retrieve_capabilities);
359 g_simple_async_result_set_check_cancellable (simple, cancellable);
361 g_simple_async_result_set_op_res_gpointer (
362 simple, async_context, (GDestroyNotify) async_context_free);
364 g_simple_async_result_run_in_thread (
365 simple, client_retrieve_capabilities_thread,
366 G_PRIORITY_DEFAULT, cancellable);
368 g_object_unref (simple);
372 client_retrieve_capabilities_finish (EClient *client,
373 GAsyncResult *result,
374 gchar **capabilities,
377 GSimpleAsyncResult *simple;
378 AsyncContext *async_context;
380 g_return_val_if_fail (
381 g_simple_async_result_is_valid (
382 result, G_OBJECT (client),
383 client_retrieve_capabilities), FALSE);
385 simple = G_SIMPLE_ASYNC_RESULT (result);
386 async_context = g_simple_async_result_get_op_res_gpointer (simple);
388 if (g_simple_async_result_propagate_error (simple, error))
391 g_return_val_if_fail (async_context->capabilities != NULL, FALSE);
393 if (capabilities != NULL) {
394 *capabilities = async_context->capabilities;
395 async_context->capabilities = NULL;
401 /* Helper for client_get_backend_property() */
403 client_get_backend_property_thread (GSimpleAsyncResult *simple,
404 GObject *source_object,
405 GCancellable *cancellable)
407 AsyncContext *async_context;
408 GError *error = NULL;
410 async_context = g_simple_async_result_get_op_res_gpointer (simple);
412 e_client_get_backend_property_sync (
413 E_CLIENT (source_object),
414 async_context->prop_name,
415 &async_context->prop_value,
416 cancellable, &error);
419 g_simple_async_result_take_error (simple, error);
423 client_get_backend_property (EClient *client,
424 const gchar *prop_name,
425 GCancellable *cancellable,
426 GAsyncReadyCallback callback,
429 GSimpleAsyncResult *simple;
430 AsyncContext *async_context;
432 async_context = g_slice_new0 (AsyncContext);
433 async_context->prop_name = g_strdup (prop_name);
435 simple = g_simple_async_result_new (
436 G_OBJECT (client), callback,
437 user_data, client_get_backend_property);
439 g_simple_async_result_set_check_cancellable (simple, cancellable);
441 g_simple_async_result_set_op_res_gpointer (
442 simple, async_context, (GDestroyNotify) async_context_free);
444 g_simple_async_result_run_in_thread (
445 simple, client_get_backend_property_thread,
446 G_PRIORITY_DEFAULT, cancellable);
448 g_object_unref (simple);
452 client_get_backend_property_finish (EClient *client,
453 GAsyncResult *result,
457 GSimpleAsyncResult *simple;
458 AsyncContext *async_context;
460 g_return_val_if_fail (
461 g_simple_async_result_is_valid (
462 result, G_OBJECT (client),
463 client_get_backend_property), FALSE);
465 simple = G_SIMPLE_ASYNC_RESULT (result);
466 async_context = g_simple_async_result_get_op_res_gpointer (simple);
468 if (g_simple_async_result_propagate_error (simple, error))
471 g_return_val_if_fail (async_context->prop_value != NULL, FALSE);
473 if (prop_value != NULL) {
474 *prop_value = async_context->prop_value;
475 async_context->prop_value = NULL;
481 /* Helper for client_set_backend_property() */
483 client_set_backend_property_thread (GSimpleAsyncResult *simple,
484 GObject *source_object,
485 GCancellable *cancellable)
487 AsyncContext *async_context;
488 GError *error = NULL;
490 async_context = g_simple_async_result_get_op_res_gpointer (simple);
492 e_client_set_backend_property_sync (
493 E_CLIENT (source_object),
494 async_context->prop_name,
495 async_context->prop_value,
496 cancellable, &error);
499 g_simple_async_result_take_error (simple, error);
503 client_set_backend_property (EClient *client,
504 const gchar *prop_name,
505 const gchar *prop_value,
506 GCancellable *cancellable,
507 GAsyncReadyCallback callback,
510 GSimpleAsyncResult *simple;
511 AsyncContext *async_context;
513 async_context = g_slice_new0 (AsyncContext);
514 async_context->prop_name = g_strdup (prop_name);
515 async_context->prop_value = g_strdup (prop_value);
517 simple = g_simple_async_result_new (
518 G_OBJECT (client), callback,
519 user_data, client_set_backend_property);
521 g_simple_async_result_set_check_cancellable (simple, cancellable);
523 g_simple_async_result_set_op_res_gpointer (
524 simple, async_context, (GDestroyNotify) async_context_free);
526 g_simple_async_result_run_in_thread (
527 simple, client_set_backend_property_thread,
528 G_PRIORITY_DEFAULT, cancellable);
530 g_object_unref (simple);
534 client_set_backend_property_finish (EClient *client,
535 GAsyncResult *result,
538 GSimpleAsyncResult *simple;
540 g_return_val_if_fail (
541 g_simple_async_result_is_valid (
542 result, G_OBJECT (client),
543 client_set_backend_property), FALSE);
545 simple = G_SIMPLE_ASYNC_RESULT (result);
547 /* Assume success unless a GError is set. */
548 return !g_simple_async_result_propagate_error (simple, error);
551 /* Helper for client_open() */
553 client_open_thread (GSimpleAsyncResult *simple,
554 GObject *source_object,
555 GCancellable *cancellable)
557 AsyncContext *async_context;
558 GError *error = NULL;
560 async_context = g_simple_async_result_get_op_res_gpointer (simple);
563 E_CLIENT (source_object),
564 async_context->only_if_exists,
565 cancellable, &error);
568 g_simple_async_result_take_error (simple, error);
572 client_open (EClient *client,
573 gboolean only_if_exists,
574 GCancellable *cancellable,
575 GAsyncReadyCallback callback,
578 GSimpleAsyncResult *simple;
579 AsyncContext *async_context;
581 async_context = g_slice_new0 (AsyncContext);
582 async_context->only_if_exists = only_if_exists;
584 simple = g_simple_async_result_new (
585 G_OBJECT (client), callback, user_data, client_open);
587 g_simple_async_result_set_check_cancellable (simple, cancellable);
589 g_simple_async_result_set_op_res_gpointer (
590 simple, async_context, (GDestroyNotify) async_context_free);
592 g_simple_async_result_run_in_thread (
593 simple, client_open_thread,
594 G_PRIORITY_DEFAULT, cancellable);
596 g_object_unref (simple);
600 client_open_finish (EClient *client,
601 GAsyncResult *result,
604 GSimpleAsyncResult *simple;
606 g_return_val_if_fail (
607 g_simple_async_result_is_valid (
608 result, G_OBJECT (client), client_open), FALSE);
610 simple = G_SIMPLE_ASYNC_RESULT (result);
612 /* Assume success unless a GError is set. */
613 return !g_simple_async_result_propagate_error (simple, error);
616 /* Helper for client_remove() */
618 client_remove_thread (GSimpleAsyncResult *simple,
619 GObject *source_object,
620 GCancellable *cancellable)
622 GError *error = NULL;
624 e_client_remove_sync (
625 E_CLIENT (source_object), cancellable, &error);
628 g_simple_async_result_take_error (simple, error);
632 client_remove (EClient *client,
633 GCancellable *cancellable,
634 GAsyncReadyCallback callback,
637 GSimpleAsyncResult *simple;
639 simple = g_simple_async_result_new (
640 G_OBJECT (client), callback, user_data, client_remove);
642 g_simple_async_result_set_check_cancellable (simple, cancellable);
644 g_simple_async_result_run_in_thread (
645 simple, client_remove_thread,
646 G_PRIORITY_DEFAULT, cancellable);
648 g_object_unref (simple);
652 client_remove_finish (EClient *client,
653 GAsyncResult *result,
656 GSimpleAsyncResult *simple;
658 g_return_val_if_fail (
659 g_simple_async_result_is_valid (
660 result, G_OBJECT (client), client_remove), FALSE);
662 simple = G_SIMPLE_ASYNC_RESULT (result);
664 /* Assume success unless a GError is set. */
665 return !g_simple_async_result_propagate_error (simple, error);
669 client_remove_sync (EClient *client,
670 GCancellable *cancellable,
675 source = e_client_get_source (client);
677 return e_source_remove_sync (source, cancellable, error);
680 /* Helper for client_refresh() */
682 client_refresh_thread (GSimpleAsyncResult *simple,
683 GObject *source_object,
684 GCancellable *cancellable)
686 GError *error = NULL;
688 e_client_refresh_sync (
689 E_CLIENT (source_object), cancellable, &error);
692 g_simple_async_result_take_error (simple, error);
696 client_refresh (EClient *client,
697 GCancellable *cancellable,
698 GAsyncReadyCallback callback,
701 GSimpleAsyncResult *simple;
703 simple = g_simple_async_result_new (
704 G_OBJECT (client), callback, user_data, client_refresh);
706 g_simple_async_result_set_check_cancellable (simple, cancellable);
708 g_simple_async_result_run_in_thread (
709 simple, client_refresh_thread,
710 G_PRIORITY_DEFAULT, cancellable);
712 g_object_unref (simple);
716 client_refresh_finish (EClient *client,
717 GAsyncResult *result,
720 GSimpleAsyncResult *simple;
722 g_return_val_if_fail (
723 g_simple_async_result_is_valid (
724 result, G_OBJECT (client), client_refresh), FALSE);
726 simple = G_SIMPLE_ASYNC_RESULT (result);
728 /* Assume success unless a GError is set. */
729 return !g_simple_async_result_propagate_error (simple, error);
733 e_client_class_init (EClientClass *class)
735 GObjectClass *object_class;
737 g_type_class_add_private (class, sizeof (EClientPrivate));
739 object_class = G_OBJECT_CLASS (class);
740 object_class->set_property = client_set_property;
741 object_class->get_property = client_get_property;
742 object_class->dispose = client_dispose;
743 object_class->finalize = client_finalize;
745 class->retrieve_capabilities = client_retrieve_capabilities;
746 class->retrieve_capabilities_finish = client_retrieve_capabilities_finish;
747 class->get_backend_property = client_get_backend_property;
748 class->get_backend_property_finish = client_get_backend_property_finish;
749 class->set_backend_property = client_set_backend_property;
750 class->set_backend_property_finish = client_set_backend_property_finish;
751 class->open = client_open;
752 class->open_finish = client_open_finish;
753 class->remove = client_remove;
754 class->remove_finish = client_remove_finish;
755 class->remove_sync = client_remove_sync;
756 class->refresh = client_refresh;
757 class->refresh_finish = client_refresh_finish;
759 g_object_class_install_property (
762 g_param_spec_object (
767 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
769 g_object_class_install_property (
772 g_param_spec_pointer (
778 g_object_class_install_property (
781 g_param_spec_boolean (
788 g_object_class_install_property (
791 g_param_spec_boolean (
798 g_object_class_install_property (
801 g_param_spec_boolean (
808 signals[OPENED] = g_signal_new (
810 G_OBJECT_CLASS_TYPE (class),
812 G_STRUCT_OFFSET (EClientClass, opened),
814 g_cclosure_marshal_VOID__BOXED,
818 signals[BACKEND_ERROR] = g_signal_new (
820 G_OBJECT_CLASS_TYPE (class),
822 G_STRUCT_OFFSET (EClientClass, backend_error),
824 g_cclosure_marshal_VOID__STRING,
828 signals[BACKEND_DIED] = g_signal_new (
830 G_OBJECT_CLASS_TYPE (class),
832 G_STRUCT_OFFSET (EClientClass, backend_died),
834 g_cclosure_marshal_VOID__VOID,
837 signals[BACKEND_PROPERTY_CHANGED] = g_signal_new (
838 "backend-property-changed",
839 G_OBJECT_CLASS_TYPE (class),
841 G_STRUCT_OFFSET (EClientClass, backend_property_changed),
843 e_gdbus_marshallers_VOID__STRING_STRING,
844 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
848 client_set_source (EClient *client,
851 g_return_if_fail (E_IS_CLIENT (client));
852 g_return_if_fail (E_IS_SOURCE (source));
854 g_object_ref (source);
856 if (client->priv->source)
857 g_object_unref (client->priv->source);
859 client->priv->source = source;
863 * e_client_get_source:
864 * @client: an #EClient
866 * Get the #ESource that this client has assigned.
868 * Returns: (transfer none): The source.
873 e_client_get_source (EClient *client)
875 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
877 return client->priv->source;
881 client_ensure_capabilities (EClient *client)
885 g_return_if_fail (E_IS_CLIENT (client));
887 if (client->priv->capabilities_retrieved || client->priv->capabilities)
890 g_rec_mutex_lock (&client->priv->prop_mutex);
893 e_client_retrieve_capabilities_sync (client, &capabilities, NULL, NULL);
894 /* e_client_set_capabilities is called inside the previous function */
895 g_free (capabilities);
897 client->priv->capabilities_retrieved = TRUE;
899 g_rec_mutex_unlock (&client->priv->prop_mutex);
903 * e_client_get_capabilities:
904 * @client: an #EClient
906 * Get list of strings with capabilities advertised by a backend.
907 * This list, together with inner strings, is owned by the @client.
908 * To check for individual capabilities use e_client_check_capability().
910 * Returns: (element-type utf8) (transfer none): #GSList of const strings
916 e_client_get_capabilities (EClient *client)
918 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
920 client_ensure_capabilities (client);
922 return client->priv->capabilities;
926 * e_client_check_capability:
927 * @client: an #EClient
928 * @capability: a capability
930 * Check if backend supports particular capability.
931 * To get all capabilities use e_client_get_capabilities().
933 * Returns: #GSList of const strings of capabilities
938 e_client_check_capability (EClient *client,
939 const gchar *capability)
943 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
944 g_return_val_if_fail (capability, FALSE);
946 g_rec_mutex_lock (&client->priv->prop_mutex);
948 client_ensure_capabilities (client);
950 for (iter = client->priv->capabilities; iter; iter = g_slist_next (iter)) {
951 const gchar *cap = iter->data;
953 if (cap && g_ascii_strcasecmp (cap, capability) == 0) {
954 g_rec_mutex_unlock (&client->priv->prop_mutex);
959 g_rec_mutex_unlock (&client->priv->prop_mutex);
965 * e_client_check_refresh_supported:
968 * Checks whether a client supports explicit refreshing
969 * (see e_client_refresh()).
971 * Returns: TRUE if the client supports refreshing, FALSE otherwise.
976 e_client_check_refresh_supported (EClient *client)
978 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
980 return e_client_check_capability (client, "refresh-supported");
983 /* capabilities - comma-separated list of capabilities; can be NULL to unset */
985 e_client_set_capabilities (EClient *client,
986 const gchar *capabilities)
988 g_return_if_fail (E_IS_CLIENT (client));
990 g_rec_mutex_lock (&client->priv->prop_mutex);
993 client->priv->capabilities_retrieved = FALSE;
995 g_slist_foreach (client->priv->capabilities, (GFunc) g_free, NULL);
996 g_slist_free (client->priv->capabilities);
997 client->priv->capabilities = e_client_util_parse_comma_strings (capabilities);
999 g_rec_mutex_unlock (&client->priv->prop_mutex);
1001 g_object_notify (G_OBJECT (client), "capabilities");
1005 * e_client_is_readonly:
1006 * @client: an #EClient
1008 * Check if this @client is read-only.
1010 * Returns: %TRUE if this @client is read-only, otherwise %FALSE.
1015 e_client_is_readonly (EClient *client)
1017 g_return_val_if_fail (E_IS_CLIENT (client), TRUE);
1019 return client->priv->readonly;
1023 e_client_set_readonly (EClient *client,
1026 g_return_if_fail (E_IS_CLIENT (client));
1028 g_rec_mutex_lock (&client->priv->prop_mutex);
1029 if (client->priv->readonly == readonly) {
1030 g_rec_mutex_unlock (&client->priv->prop_mutex);
1034 client->priv->readonly = readonly;
1036 g_rec_mutex_unlock (&client->priv->prop_mutex);
1038 g_object_notify (G_OBJECT (client), "readonly");
1042 * e_client_is_online:
1043 * @client: an #EClient
1045 * Check if this @client is connected.
1047 * Returns: %TRUE if this @client is connected, otherwise %FALSE.
1052 e_client_is_online (EClient *client)
1054 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1056 return client->priv->online;
1060 e_client_set_online (EClient *client,
1063 g_return_if_fail (E_IS_CLIENT (client));
1065 /* newly connected/disconnected => make sure capabilities will be correct */
1066 e_client_set_capabilities (client, NULL);
1068 g_rec_mutex_lock (&client->priv->prop_mutex);
1069 if (client->priv->online == is_online) {
1070 g_rec_mutex_unlock (&client->priv->prop_mutex);
1074 client->priv->online = is_online;
1076 g_rec_mutex_unlock (&client->priv->prop_mutex);
1078 g_object_notify (G_OBJECT (client), "online");
1082 * e_client_is_opened:
1083 * @client: an #EClient
1085 * Check if this @client is fully opened. This includes
1086 * everything from e_client_open() call up to the authentication,
1087 * if required by a backend. Client cannot do any other operation
1088 * during the opening phase except of authenticate or cancel it.
1089 * Every other operation results in an %E_CLIENT_ERROR_BUSY error.
1091 * Returns: always %TRUE
1095 * Deprecated: 3.8: Clients don't need to care if they're fully opened
1096 * anymore. This function always returns %TRUE.
1099 e_client_is_opened (EClient *client)
1101 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1108 * @client: an #EClient
1109 * @opid: asynchronous operation ID
1111 * Cancels particular asynchronous operation. The @opid is returned from
1112 * an e_client_register_op(). The function does nothing if the asynchronous
1113 * operation doesn't exist any more.
1118 client_cancel_op (EClient *client,
1121 GCancellable *cancellable;
1123 g_return_if_fail (E_IS_CLIENT (client));
1124 g_return_if_fail (client->priv->ops != NULL);
1126 g_rec_mutex_lock (&client->priv->ops_mutex);
1128 cancellable = g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (opid));
1130 g_cancellable_cancel (cancellable);
1132 g_rec_mutex_unlock (&client->priv->ops_mutex);
1136 gather_opids_cb (gpointer opid,
1137 gpointer cancellable,
1140 GSList **ids = ids_list;
1142 g_return_if_fail (ids_list != NULL);
1144 *ids = g_slist_prepend (*ids, opid);
1148 cancel_op_cb (gpointer opid,
1151 client_cancel_op (client, GPOINTER_TO_INT (opid));
1155 * e_client_cancel_all:
1156 * @client: an #EClient
1158 * Cancels all pending operations started on @client.
1163 e_client_cancel_all (EClient *client)
1165 GSList *opids = NULL;
1167 g_return_if_fail (E_IS_CLIENT (client));
1168 g_return_if_fail (client->priv->ops != NULL);
1170 g_rec_mutex_lock (&client->priv->ops_mutex);
1172 g_hash_table_foreach (client->priv->ops, gather_opids_cb, &opids);
1174 g_slist_foreach (opids, cancel_op_cb, client);
1175 g_slist_free (opids);
1177 g_rec_mutex_unlock (&client->priv->ops_mutex);
1181 e_client_register_op (EClient *client,
1182 GCancellable *cancellable)
1186 g_return_val_if_fail (E_IS_CLIENT (client), 0);
1187 g_return_val_if_fail (client->priv->ops != NULL, 0);
1188 g_return_val_if_fail (cancellable != NULL, 0);
1190 g_rec_mutex_lock (&client->priv->ops_mutex);
1192 client->priv->last_opid++;
1193 if (!client->priv->last_opid)
1194 client->priv->last_opid++;
1196 while (g_hash_table_lookup (client->priv->ops, GINT_TO_POINTER (client->priv->last_opid)))
1197 client->priv->last_opid++;
1199 g_return_val_if_fail (client->priv->last_opid != 0, 0);
1201 opid = client->priv->last_opid;
1202 g_hash_table_insert (client->priv->ops, GINT_TO_POINTER (opid), g_object_ref (cancellable));
1204 g_rec_mutex_unlock (&client->priv->ops_mutex);
1210 e_client_unregister_op (EClient *client,
1213 g_return_if_fail (E_IS_CLIENT (client));
1214 g_return_if_fail (client->priv->ops != NULL);
1216 g_rec_mutex_lock (&client->priv->ops_mutex);
1217 g_hash_table_remove (client->priv->ops, GINT_TO_POINTER (opid));
1218 g_rec_mutex_unlock (&client->priv->ops_mutex);
1222 e_client_emit_opened (EClient *client,
1223 const GError *dbus_error)
1225 GError *local_error = NULL;
1227 g_return_if_fail (E_IS_CLIENT (client));
1230 local_error = g_error_copy (dbus_error);
1231 e_client_unwrap_dbus_error (client, local_error, &local_error);
1234 g_object_notify (G_OBJECT (client), "opened");
1235 g_signal_emit (client, signals[OPENED], 0, local_error);
1238 g_error_free (local_error);
1242 e_client_emit_backend_error (EClient *client,
1243 const gchar *error_msg)
1245 g_return_if_fail (E_IS_CLIENT (client));
1246 g_return_if_fail (error_msg != NULL);
1248 g_signal_emit (client, signals[BACKEND_ERROR], 0, error_msg);
1252 e_client_emit_backend_died (EClient *client)
1254 g_return_if_fail (E_IS_CLIENT (client));
1256 g_signal_emit (client, signals[BACKEND_DIED], 0);
1260 e_client_emit_backend_property_changed (EClient *client,
1261 const gchar *prop_name,
1262 const gchar *prop_value)
1264 g_return_if_fail (E_IS_CLIENT (client));
1265 g_return_if_fail (prop_name != NULL);
1266 g_return_if_fail (*prop_name);
1267 g_return_if_fail (prop_value != NULL);
1269 e_client_update_backend_property_cache (client, prop_name, prop_value);
1271 g_signal_emit (client, signals[BACKEND_PROPERTY_CHANGED], 0, prop_name, prop_value);
1275 e_client_update_backend_property_cache (EClient *client,
1276 const gchar *prop_name,
1277 const gchar *prop_value)
1279 g_return_if_fail (E_IS_CLIENT (client));
1280 g_return_if_fail (prop_name != NULL);
1281 g_return_if_fail (*prop_name);
1282 g_return_if_fail (prop_value != NULL);
1284 g_rec_mutex_lock (&client->priv->prop_mutex);
1286 if (client->priv->backend_property_cache)
1287 g_hash_table_insert (client->priv->backend_property_cache, g_strdup (prop_name), g_strdup (prop_value));
1289 g_rec_mutex_unlock (&client->priv->prop_mutex);
1293 e_client_get_backend_property_from_cache (EClient *client,
1294 const gchar *prop_name)
1296 gchar *prop_value = NULL;
1298 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
1299 g_return_val_if_fail (prop_name != NULL, NULL);
1300 g_return_val_if_fail (*prop_name, NULL);
1302 g_rec_mutex_lock (&client->priv->prop_mutex);
1304 if (client->priv->backend_property_cache)
1305 prop_value = g_strdup (g_hash_table_lookup (client->priv->backend_property_cache, prop_name));
1307 g_rec_mutex_unlock (&client->priv->prop_mutex);
1313 * e_client_retrieve_capabilities:
1314 * @client: an #EClient
1315 * @cancellable: a #GCancellable; can be %NULL
1316 * @callback: callback to call when a result is ready
1317 * @user_data: user data for the @callback
1319 * Initiates retrieval of capabilities on the @client. This is usually
1320 * required only once, after the @client is opened. The returned value
1321 * is cached and any subsequent call of e_client_get_capabilities() and
1322 * e_client_check_capability() is using the cached value.
1323 * The call is finished by e_client_retrieve_capabilities_finish()
1324 * from the @callback.
1329 e_client_retrieve_capabilities (EClient *client,
1330 GCancellable *cancellable,
1331 GAsyncReadyCallback callback,
1334 EClientClass *class;
1336 g_return_if_fail (E_IS_CLIENT (client));
1337 g_return_if_fail (callback != NULL);
1339 class = E_CLIENT_GET_CLASS (client);
1340 g_return_if_fail (class != NULL);
1341 g_return_if_fail (class->retrieve_capabilities != NULL);
1343 class->retrieve_capabilities (client, cancellable, callback, user_data);
1347 * e_client_retrieve_capabilities_finish:
1348 * @client: an #EClient
1349 * @result: a #GAsyncResult
1350 * @capabilities: (out): Comma-separated list of capabilities of the @client
1351 * @error: (out): a #GError to set an error, if any
1353 * Finishes previous call of e_client_retrieve_capabilities().
1354 * Returned value of @capabilities should be freed with g_free(),
1355 * when no longer needed.
1357 * Returns: %TRUE if successful, %FALSE otherwise.
1362 e_client_retrieve_capabilities_finish (EClient *client,
1363 GAsyncResult *result,
1364 gchar **capabilities,
1367 EClientClass *class;
1370 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1371 g_return_val_if_fail (capabilities != NULL, FALSE);
1373 class = E_CLIENT_GET_CLASS (client);
1374 g_return_val_if_fail (class != NULL, FALSE);
1375 g_return_val_if_fail (class->retrieve_capabilities_finish != NULL, FALSE);
1377 *capabilities = NULL;
1378 res = class->retrieve_capabilities_finish (client, result, capabilities, error);
1380 e_client_set_capabilities (client, res ? *capabilities : NULL);
1382 if (error && *error)
1383 e_client_unwrap_dbus_error (client, *error, error);
1389 * e_client_retrieve_capabilities_sync:
1390 * @client: an #EClient
1391 * @capabilities: (out): Comma-separated list of capabilities of the @client
1392 * @cancellable: a #GCancellable; can be %NULL
1393 * @error: (out): a #GError to set an error, if any
1395 * Initiates retrieval of capabilities on the @client. This is usually
1396 * required only once, after the @client is opened. The returned value
1397 * is cached and any subsequent call of e_client_get_capabilities() and
1398 * e_client_check_capability() is using the cached value. Returned value
1399 * of @capabilities should be freed with g_free(), when no longer needed.
1401 * Returns: %TRUE if successful, %FALSE otherwise.
1406 e_client_retrieve_capabilities_sync (EClient *client,
1407 gchar **capabilities,
1408 GCancellable *cancellable,
1411 EClientClass *class;
1412 gboolean res = FALSE;
1414 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1415 g_return_val_if_fail (capabilities != NULL, FALSE);
1417 class = E_CLIENT_GET_CLASS (client);
1418 g_return_val_if_fail (class != NULL, FALSE);
1419 g_return_val_if_fail (class->retrieve_capabilities_sync != NULL, FALSE);
1421 *capabilities = NULL;
1422 res = class->retrieve_capabilities_sync (client, capabilities, cancellable, error);
1424 e_client_set_capabilities (client, res ? *capabilities : NULL);
1426 if (error && *error)
1427 e_client_unwrap_dbus_error (client, *error, error);
1433 * e_client_get_backend_property:
1434 * @client: an #EClient
1435 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1436 * @cancellable: a #GCancellable; can be %NULL
1437 * @callback: callback to call when a result is ready
1438 * @user_data: user data for the @callback
1440 * Queries @client's backend for a property of name @prop_name.
1441 * The call is finished by e_client_get_backend_property_finish()
1442 * from the @callback.
1447 e_client_get_backend_property (EClient *client,
1448 const gchar *prop_name,
1449 GCancellable *cancellable,
1450 GAsyncReadyCallback callback,
1453 EClientClass *class;
1455 g_return_if_fail (callback != NULL);
1456 g_return_if_fail (E_IS_CLIENT (client));
1457 g_return_if_fail (prop_name != NULL);
1459 class = E_CLIENT_GET_CLASS (client);
1460 g_return_if_fail (class != NULL);
1461 g_return_if_fail (class->get_backend_property != NULL);
1463 class->get_backend_property (client, prop_name, cancellable, callback, user_data);
1467 * e_client_get_backend_property_finish:
1468 * @client: an #EClient
1469 * @result: a #GAsyncResult
1470 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1471 * @error: (out): a #GError to set an error, if any
1473 * Finishes previous call of e_client_get_backend_property().
1475 * Returns: %TRUE if successful, %FALSE otherwise.
1480 e_client_get_backend_property_finish (EClient *client,
1481 GAsyncResult *result,
1485 EClientClass *class;
1488 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1489 g_return_val_if_fail (prop_value != NULL, FALSE);
1491 class = E_CLIENT_GET_CLASS (client);
1492 g_return_val_if_fail (class != NULL, FALSE);
1493 g_return_val_if_fail (class->get_backend_property_finish != NULL, FALSE);
1495 res = class->get_backend_property_finish (client, result, prop_value, error);
1497 if (error && *error)
1498 e_client_unwrap_dbus_error (client, *error, error);
1504 * e_client_get_backend_property_sync:
1505 * @client: an #EClient
1506 * @prop_name: property name, whose value to retrieve; cannot be %NULL
1507 * @prop_value: (out): Retrieved backend property value; cannot be %NULL
1508 * @cancellable: a #GCancellable; can be %NULL
1509 * @error: (out): a #GError to set an error, if any
1511 * Queries @client's backend for a property of name @prop_name.
1513 * Returns: %TRUE if successful, %FALSE otherwise.
1518 e_client_get_backend_property_sync (EClient *client,
1519 const gchar *prop_name,
1521 GCancellable *cancellable,
1524 EClientClass *class;
1527 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1528 g_return_val_if_fail (prop_name != NULL, FALSE);
1529 g_return_val_if_fail (prop_value != NULL, FALSE);
1531 class = E_CLIENT_GET_CLASS (client);
1532 g_return_val_if_fail (class != NULL, FALSE);
1533 g_return_val_if_fail (class->get_backend_property_sync != NULL, FALSE);
1535 res = class->get_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1537 if (error && *error)
1538 e_client_unwrap_dbus_error (client, *error, error);
1544 * e_client_set_backend_property:
1545 * @client: an #EClient
1546 * @prop_name: property name, whose value to change; cannot be %NULL
1547 * @prop_value: property value, to set; cannot be %NULL
1548 * @cancellable: a #GCancellable; can be %NULL
1549 * @callback: callback to call when a result is ready
1550 * @user_data: user data for the @callback
1552 * Sets @client's backend property of name @prop_name
1553 * to value @prop_value. The call is finished
1554 * by e_client_set_backend_property_finish() from the @callback.
1559 e_client_set_backend_property (EClient *client,
1560 const gchar *prop_name,
1561 const gchar *prop_value,
1562 GCancellable *cancellable,
1563 GAsyncReadyCallback callback,
1566 EClientClass *class;
1568 g_return_if_fail (callback != NULL);
1569 g_return_if_fail (E_IS_CLIENT (client));
1570 g_return_if_fail (prop_name != NULL);
1571 g_return_if_fail (prop_value != NULL);
1573 class = E_CLIENT_GET_CLASS (client);
1574 g_return_if_fail (class != NULL);
1575 g_return_if_fail (class->set_backend_property != NULL);
1577 class->set_backend_property (client, prop_name, prop_value, cancellable, callback, user_data);
1581 * e_client_set_backend_property_finish:
1582 * @client: an #EClient
1583 * @result: a #GAsyncResult
1584 * @error: (out): a #GError to set an error, if any
1586 * Finishes previous call of e_client_set_backend_property().
1588 * Returns: %TRUE if successful, %FALSE otherwise.
1593 e_client_set_backend_property_finish (EClient *client,
1594 GAsyncResult *result,
1597 EClientClass *class;
1600 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1602 class = E_CLIENT_GET_CLASS (client);
1603 g_return_val_if_fail (class != NULL, FALSE);
1604 g_return_val_if_fail (class->set_backend_property_finish != NULL, FALSE);
1606 res = class->set_backend_property_finish (client, result, error);
1608 if (error && *error)
1609 e_client_unwrap_dbus_error (client, *error, error);
1615 * e_client_set_backend_property_sync:
1616 * @client: an #EClient
1617 * @prop_name: property name, whose value to change; cannot be %NULL
1618 * @prop_value: property value, to set; cannot be %NULL
1619 * @cancellable: a #GCancellable; can be %NULL
1620 * @error: (out): a #GError to set an error, if any
1622 * Sets @client's backend property of name @prop_name
1623 * to value @prop_value.
1625 * Returns: %TRUE if successful, %FALSE otherwise.
1630 e_client_set_backend_property_sync (EClient *client,
1631 const gchar *prop_name,
1632 const gchar *prop_value,
1633 GCancellable *cancellable,
1636 EClientClass *class;
1639 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1640 g_return_val_if_fail (prop_name != NULL, FALSE);
1641 g_return_val_if_fail (prop_value != NULL, FALSE);
1643 class = E_CLIENT_GET_CLASS (client);
1644 g_return_val_if_fail (class != NULL, FALSE);
1645 g_return_val_if_fail (class->set_backend_property_sync != NULL, FALSE);
1647 res = class->set_backend_property_sync (client, prop_name, prop_value, cancellable, error);
1649 if (error && *error)
1650 e_client_unwrap_dbus_error (client, *error, error);
1657 * @client: an #EClient
1658 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1659 * @cancellable: a #GCancellable; can be %NULL
1660 * @callback: callback to call when a result is ready
1661 * @user_data: user data for the @callback
1663 * Opens the @client, making it ready for queries and other operations.
1664 * The call is finished by e_client_open_finish() from the @callback.
1669 e_client_open (EClient *client,
1670 gboolean only_if_exists,
1671 GCancellable *cancellable,
1672 GAsyncReadyCallback callback,
1675 EClientClass *class;
1677 g_return_if_fail (callback != NULL);
1678 g_return_if_fail (E_IS_CLIENT (client));
1680 class = E_CLIENT_GET_CLASS (client);
1681 g_return_if_fail (class != NULL);
1682 g_return_if_fail (class->open != NULL);
1684 class->open (client, only_if_exists, cancellable, callback, user_data);
1688 * e_client_open_finish:
1689 * @client: an #EClient
1690 * @result: a #GAsyncResult
1691 * @error: (out): a #GError to set an error, if any
1693 * Finishes previous call of e_client_open().
1695 * Returns: %TRUE if successful, %FALSE otherwise.
1700 e_client_open_finish (EClient *client,
1701 GAsyncResult *result,
1704 EClientClass *class;
1707 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1709 class = E_CLIENT_GET_CLASS (client);
1710 g_return_val_if_fail (class != NULL, FALSE);
1711 g_return_val_if_fail (class->open_finish != NULL, FALSE);
1713 res = class->open_finish (client, result, error);
1715 if (error && *error)
1716 e_client_unwrap_dbus_error (client, *error, error);
1722 * e_client_open_sync:
1723 * @client: an #EClient
1724 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
1725 * @cancellable: a #GCancellable; can be %NULL
1726 * @error: (out): a #GError to set an error, if any
1728 * Opens the @client, making it ready for queries and other operations.
1730 * Returns: %TRUE if successful, %FALSE otherwise.
1735 e_client_open_sync (EClient *client,
1736 gboolean only_if_exists,
1737 GCancellable *cancellable,
1740 EClientClass *class;
1743 class = E_CLIENT_GET_CLASS (client);
1744 g_return_val_if_fail (class != NULL, FALSE);
1745 g_return_val_if_fail (class->open_sync != NULL, FALSE);
1747 res = class->open_sync (client, only_if_exists, cancellable, error);
1749 if (error && *error)
1750 e_client_unwrap_dbus_error (client, *error, error);
1757 * @client: an #EClient
1758 * @cancellable: a #GCancellable; can be %NULL
1759 * @callback: callback to call when a result is ready
1760 * @user_data: user data for the @callback
1762 * Removes the backing data for this #EClient. For example, with the file
1763 * backend this deletes the database file. You cannot get it back!
1764 * The call is finished by e_client_remove_finish() from the @callback.
1768 * Deprecated: 3.6: Use e_source_remove() instead.
1771 e_client_remove (EClient *client,
1772 GCancellable *cancellable,
1773 GAsyncReadyCallback callback,
1776 EClientClass *class;
1778 g_return_if_fail (E_IS_CLIENT (client));
1779 g_return_if_fail (callback != NULL);
1781 class = E_CLIENT_GET_CLASS (client);
1782 g_return_if_fail (class != NULL);
1783 g_return_if_fail (class->remove != NULL);
1785 class->remove (client, cancellable, callback, user_data);
1789 * e_client_remove_finish:
1790 * @client: an #EClient
1791 * @result: a #GAsyncResult
1792 * @error: (out): a #GError to set an error, if any
1794 * Finishes previous call of e_client_remove().
1796 * Returns: %TRUE if successful, %FALSE otherwise.
1800 * Deprecated: 3.6: Use e_source_remove_finish() instead.
1803 e_client_remove_finish (EClient *client,
1804 GAsyncResult *result,
1807 EClientClass *class;
1810 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1812 class = E_CLIENT_GET_CLASS (client);
1813 g_return_val_if_fail (class != NULL, FALSE);
1814 g_return_val_if_fail (class->remove_finish != NULL, FALSE);
1816 res = class->remove_finish (client, result, error);
1818 if (error && *error)
1819 e_client_unwrap_dbus_error (client, *error, error);
1825 * e_client_remove_sync:
1826 * @client: an #EClient
1827 * @cancellable: a #GCancellable; can be %NULL
1828 * @error: (out): a #GError to set an error, if any
1830 * Removes the backing data for this #EClient. For example, with the file
1831 * backend this deletes the database file. You cannot get it back!
1833 * Returns: %TRUE if successful, %FALSE otherwise.
1837 * Deprecated: 3.6: Use e_source_remove_sync() instead.
1840 e_client_remove_sync (EClient *client,
1841 GCancellable *cancellable,
1844 EClientClass *class;
1847 class = E_CLIENT_GET_CLASS (client);
1848 g_return_val_if_fail (class != NULL, FALSE);
1849 g_return_val_if_fail (class->remove_sync != NULL, FALSE);
1851 res = class->remove_sync (client, cancellable, error);
1853 if (error && *error)
1854 e_client_unwrap_dbus_error (client, *error, error);
1861 * @client: an #EClient
1862 * @cancellable: a #GCancellable; can be %NULL
1863 * @callback: callback to call when a result is ready
1864 * @user_data: user data for the @callback
1866 * Initiates refresh on the @client. Finishing the method doesn't mean
1867 * that the refresh is done, backend only notifies whether it started
1868 * refreshing or not. Use e_client_check_refresh_supported() to check
1869 * whether the backend supports this method.
1870 * The call is finished by e_client_refresh_finish() from the @callback.
1875 e_client_refresh (EClient *client,
1876 GCancellable *cancellable,
1877 GAsyncReadyCallback callback,
1880 EClientClass *class;
1882 g_return_if_fail (E_IS_CLIENT (client));
1883 g_return_if_fail (callback != NULL);
1885 class = E_CLIENT_GET_CLASS (client);
1886 g_return_if_fail (class != NULL);
1887 g_return_if_fail (class->refresh != NULL);
1889 class->refresh (client, cancellable, callback, user_data);
1893 * e_client_refresh_finish:
1894 * @client: an #EClient
1895 * @result: a #GAsyncResult
1896 * @error: (out): a #GError to set an error, if any
1898 * Finishes previous call of e_client_refresh().
1900 * Returns: %TRUE if successful, %FALSE otherwise.
1905 e_client_refresh_finish (EClient *client,
1906 GAsyncResult *result,
1909 EClientClass *class;
1912 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
1914 class = E_CLIENT_GET_CLASS (client);
1915 g_return_val_if_fail (class != NULL, FALSE);
1916 g_return_val_if_fail (class->refresh_finish != NULL, FALSE);
1918 res = class->refresh_finish (client, result, error);
1920 if (error && *error)
1921 e_client_unwrap_dbus_error (client, *error, error);
1927 * e_client_refresh_sync:
1928 * @client: an #EClient
1929 * @cancellable: a #GCancellable; can be %NULL
1930 * @error: (out): a #GError to set an error, if any
1932 * Initiates refresh on the @client. Finishing the method doesn't mean
1933 * that the refresh is done, backend only notifies whether it started
1934 * refreshing or not. Use e_client_check_refresh_supported() to check
1935 * whether the backend supports this method.
1937 * Returns: %TRUE if successful, %FALSE otherwise.
1942 e_client_refresh_sync (EClient *client,
1943 GCancellable *cancellable,
1946 EClientClass *class;
1949 class = E_CLIENT_GET_CLASS (client);
1950 g_return_val_if_fail (class != NULL, FALSE);
1951 g_return_val_if_fail (class->refresh_sync != NULL, FALSE);
1953 res = class->refresh_sync (client, cancellable, error);
1955 if (error && *error)
1956 e_client_unwrap_dbus_error (client, *error, error);
1962 * e_client_util_slist_to_strv:
1963 * @strings: (element-type utf8): a #GSList of strings (const gchar *)
1965 * Convert a list of strings into a %NULL-terminated array of strings.
1967 * Returns: (transfer full): Newly allocated %NULL-terminated array of strings.
1968 * The returned pointer should be freed with g_strfreev().
1970 * Note: Paired function for this is e_client_util_strv_to_slist().
1974 * Deprecated: 3.8: Use e_util_slist_to_strv() instead.
1977 e_client_util_slist_to_strv (const GSList *strings)
1979 return e_util_slist_to_strv (strings);
1983 * e_client_util_strv_to_slist:
1984 * @strv: a %NULL-terminated array of strings (const gchar *)
1986 * Convert a %NULL-terminated array of strings to a list of strings.
1988 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
1989 * newly allocated strings. The returned pointer should be freed with
1990 * e_client_util_free_string_slist().
1992 * Note: Paired function for this is e_client_util_slist_to_strv().
1996 * Deprecated: 3.8: Use e_util_strv_to_slist() instead.
1999 e_client_util_strv_to_slist (const gchar * const *strv)
2001 return e_util_strv_to_slist (strv);
2005 * e_client_util_copy_string_slist:
2006 * @copy_to: (element-type utf8) (allow-none): Where to copy; may be %NULL
2007 * @strings: (element-type utf8): #GSList of strings to be copied
2009 * Copies the #GSList of strings to the end of @copy_to.
2011 * Returns: (transfer full) (element-type utf8): New head of @copy_to.
2012 * The returned pointer can be freed with e_client_util_free_string_slist().
2016 * Deprecated: 3.8: Use e_util_copy_string_slist() instead.
2019 e_client_util_copy_string_slist (GSList *copy_to,
2020 const GSList *strings)
2022 return e_util_copy_string_slist (copy_to, strings);
2026 * e_client_util_copy_object_slist:
2027 * @copy_to: (element-type GObject) (allow-none): Where to copy; may be %NULL
2028 * @objects: (element-type GObject): #GSList of #GObject<!-- -->s to be copied
2030 * Copies a #GSList of #GObject<!-- -->s to the end of @copy_to.
2032 * Returns: (transfer full) (element-type GObject): New head of @copy_to.
2033 * The returned pointer can be freed with e_client_util_free_object_slist().
2037 * Deprecated: 3.8: Use e_util_copy_object_slist() instead.
2040 e_client_util_copy_object_slist (GSList *copy_to,
2041 const GSList *objects)
2043 return e_util_copy_object_slist (copy_to, objects);
2047 * e_client_util_free_string_slist:
2048 * @strings: (element-type utf8): a #GSList of strings (gchar *)
2050 * Frees memory previously allocated by e_client_util_strv_to_slist().
2054 * Deprecated: 3.8: Use g_slist_free_full() instead.
2057 e_client_util_free_string_slist (GSList *strings)
2059 e_util_free_string_slist (strings);
2063 * e_client_util_free_object_slist:
2064 * @objects: (element-type GObject): a #GSList of #GObject<!-- -->s
2066 * Calls g_object_unref() on each member of @objects and then frees @objects
2071 * Deprecated: 3.8: Use g_slist_free_full() instead.
2074 e_client_util_free_object_slist (GSList *objects)
2076 e_util_free_object_slist (objects);
2080 * e_client_util_parse_comma_strings:
2081 * @strings: string of comma-separated values
2083 * Parses comma-separated list of values into #GSList.
2085 * Returns: (transfer full) (element-type utf8): Newly allocated #GSList of
2086 * newly allocated strings corresponding to values parsed from @strings.
2087 * Free the returned pointer with e_client_util_free_string_slist().
2092 e_client_util_parse_comma_strings (const gchar *strings)
2094 GSList *strs_slist = NULL;
2095 gchar **strs_strv = NULL;
2098 if (!strings || !*strings)
2101 strs_strv = g_strsplit (strings, ",", -1);
2102 g_return_val_if_fail (strs_strv != NULL, NULL);
2104 for (ii = 0; strs_strv && strs_strv[ii]; ii++) {
2105 gchar *str = g_strstrip (strs_strv[ii]);
2108 strs_slist = g_slist_prepend (strs_slist, g_strdup (str));
2111 g_strfreev (strs_strv);
2113 return g_slist_reverse (strs_slist);
2117 e_client_finish_async_without_dbus (EClient *client,
2118 GCancellable *cancellable,
2119 GAsyncReadyCallback callback,
2121 gpointer source_tag,
2123 GDestroyNotify destroy_op_res)
2125 GCancellable *use_cancellable;
2126 GSimpleAsyncResult *simple;
2129 g_return_if_fail (E_IS_CLIENT (client));
2130 g_return_if_fail (callback != NULL);
2131 g_return_if_fail (source_tag != NULL);
2133 use_cancellable = cancellable;
2134 if (!use_cancellable)
2135 use_cancellable = g_cancellable_new ();
2137 opid = e_client_register_op (client, use_cancellable);
2138 g_return_if_fail (opid > 0);
2140 simple = g_simple_async_result_new (
2141 G_OBJECT (client), callback, user_data, source_tag);
2143 g_simple_async_result_set_check_cancellable (simple, cancellable);
2145 g_simple_async_result_set_op_res_gpointer (
2146 simple, op_res, destroy_op_res);
2148 g_simple_async_result_complete_in_idle (simple);
2150 g_object_unref (simple);
2152 if (use_cancellable != cancellable)
2153 g_object_unref (use_cancellable);
2157 e_client_get_dbus_proxy (EClient *client)
2159 EClientClass *class;
2161 g_return_val_if_fail (E_IS_CLIENT (client), NULL);
2163 class = E_CLIENT_GET_CLASS (client);
2164 g_return_val_if_fail (class != NULL, NULL);
2165 g_return_val_if_fail (class->get_dbus_proxy != NULL, NULL);
2167 return class->get_dbus_proxy (client);
2171 * e_client_unwrap_dbus_error:
2172 * @client: an #EClient
2173 * @dbus_error: a #GError returned bu D-Bus
2174 * @out_error: a #GError variable where to store the result
2176 * Unwraps D-Bus error to local error. @dbus_error is automatically freed.
2177 * @dbus_erorr and @out_error can point to the same variable.
2182 e_client_unwrap_dbus_error (EClient *client,
2186 EClientClass *class;
2188 g_return_if_fail (E_IS_CLIENT (client));
2190 class = E_CLIENT_GET_CLASS (client);
2191 g_return_if_fail (class != NULL);
2192 g_return_if_fail (class->unwrap_dbus_error != NULL);
2194 if (!dbus_error || !out_error) {
2196 g_error_free (dbus_error);
2198 class->unwrap_dbus_error (client, dbus_error, out_error);
2203 * e_client_util_unwrap_dbus_error:
2204 * @dbus_error: DBus #GError to unwrap
2205 * @client_error: (out): Resulting #GError; can be %NULL
2206 * @known_errors: List of known errors against which try to match
2207 * @known_errors_count: How many items are stored in @known_errors
2208 * @known_errors_domain: Error domain for @known_errors
2209 * @fail_when_none_matched: Whether to fail when none of @known_errors matches
2211 * The function takes a @dbus_error and tries to find a match in @known_errors
2212 * for it, if it is a G_IO_ERROR, G_IO_ERROR_DBUS_ERROR. If it is anything else
2213 * then the @dbus_error is moved to @client_error.
2215 * The @fail_when_none_matched influences behaviour. If it's %TRUE, and none of
2216 * @known_errors matches, or this is not a G_IO_ERROR_DBUS_ERROR, then %FALSE
2217 * is returned and the @client_error is left without change. Otherwise, the
2218 * @fail_when_none_matched is %FALSE, the error is always processed and will
2219 * result in E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR if none of @known_error
2222 * Returns: Whether was @dbus_error processed into @client_error.
2224 * Note: The @dbus_error is automatically freed if returned %TRUE.
2229 e_client_util_unwrap_dbus_error (GError *dbus_error,
2230 GError **client_error,
2231 const EClientErrorsList *known_errors,
2232 guint known_errors_count,
2233 GQuark known_errors_domain,
2234 gboolean fail_when_none_matched)
2236 if (!client_error) {
2238 g_error_free (dbus_error);
2243 *client_error = NULL;
2247 if (dbus_error->domain == known_errors_domain) {
2248 *client_error = dbus_error;
2253 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
2257 name = g_dbus_error_get_remote_error (dbus_error);
2259 for (ii = 0; ii < known_errors_count; ii++) {
2260 if (g_ascii_strcasecmp (known_errors[ii].name, name) == 0) {
2263 g_dbus_error_strip_remote_error (dbus_error);
2264 *client_error = g_error_new_literal (known_errors_domain, known_errors[ii].err_code, dbus_error->message);
2265 g_error_free (dbus_error);
2274 if (fail_when_none_matched)
2277 if (g_error_matches (dbus_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)) {
2278 g_dbus_error_strip_remote_error (dbus_error);
2279 *client_error = g_error_new_literal (E_CLIENT_ERROR, E_CLIENT_ERROR_OTHER_ERROR, dbus_error->message);
2280 g_error_free (dbus_error);
2282 g_dbus_error_strip_remote_error (dbus_error);
2283 *client_error = dbus_error;
2289 typedef struct _EClientAsyncOpData
2294 gpointer source_tag;
2295 gchar *res_op_data; /* optional string to set on a GAsyncResult object as "res-op-data" user data */
2296 GAsyncReadyCallback callback;
2299 gboolean result; /* result of the finish function call */
2301 /* only one can be non-NULL, and the type is telling which 'out' value is valid */
2302 EClientProxyFinishVoidFunc finish_void;
2303 EClientProxyFinishBooleanFunc finish_boolean;
2304 EClientProxyFinishStringFunc finish_string;
2305 EClientProxyFinishStrvFunc finish_strv;
2306 EClientProxyFinishUintFunc finish_uint;
2309 gboolean val_boolean;
2314 } EClientAsyncOpData;
2317 async_data_free (EClientAsyncOpData *async_data)
2319 g_return_if_fail (async_data != NULL);
2320 g_return_if_fail (async_data->client != NULL);
2322 e_client_unregister_op (async_data->client, async_data->opid);
2324 if (async_data->finish_string)
2325 g_free (async_data->out.val_string);
2326 else if (async_data->finish_strv)
2327 g_strfreev (async_data->out.val_strv);
2329 g_object_unref (async_data->client);
2330 g_free (async_data->res_op_data);
2331 g_free (async_data);
2335 complete_async_op_in_idle_cb (gpointer user_data)
2337 GSimpleAsyncResult *simple = user_data;
2338 gint run_main_depth;
2340 g_return_val_if_fail (simple != NULL, FALSE);
2342 run_main_depth = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (simple), "run-main-depth"));
2343 if (run_main_depth < 1)
2346 /* do not receive in higher level than was initially run */
2347 if (g_main_depth () > run_main_depth) {
2351 g_simple_async_result_complete (simple);
2352 g_object_unref (simple);
2358 finish_async_op (EClientAsyncOpData *async_data,
2359 const GError *error,
2362 GSimpleAsyncResult *simple;
2364 g_return_if_fail (async_data != NULL);
2365 g_return_if_fail (async_data->source_tag != NULL);
2366 g_return_if_fail (async_data->client != NULL);
2368 simple = g_simple_async_result_new (G_OBJECT (async_data->client), async_data->callback, async_data->user_data, async_data->source_tag);
2369 g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
2371 if (async_data->res_op_data)
2372 g_object_set_data_full (G_OBJECT (simple), "res-op-data", g_strdup (async_data->res_op_data), g_free);
2375 g_simple_async_result_set_from_error (simple, error);
2378 g_object_set_data (G_OBJECT (simple), "run-main-depth", GINT_TO_POINTER (g_main_depth ()));
2379 g_idle_add (complete_async_op_in_idle_cb, simple);
2381 g_simple_async_result_complete (simple);
2382 g_object_unref (simple);
2387 async_result_ready_cb (GObject *source_object,
2388 GAsyncResult *result,
2391 GError *error = NULL;
2392 EClientAsyncOpData *async_data;
2395 g_return_if_fail (result != NULL);
2396 g_return_if_fail (source_object != NULL);
2398 async_data = user_data;
2399 g_return_if_fail (async_data != NULL);
2400 g_return_if_fail (async_data->client != NULL);
2402 client = async_data->client;
2403 g_return_if_fail (e_client_get_dbus_proxy (client) == G_DBUS_PROXY (source_object));
2405 if (async_data->finish_void)
2406 async_data->result = async_data->finish_void (G_DBUS_PROXY (source_object), result, &error);
2407 else if (async_data->finish_boolean)
2408 async_data->result = async_data->finish_boolean (G_DBUS_PROXY (source_object), result, &async_data->out.val_boolean, &error);
2409 else if (async_data->finish_string)
2410 async_data->result = async_data->finish_string (G_DBUS_PROXY (source_object), result, &async_data->out.val_string, &error);
2411 else if (async_data->finish_strv)
2412 async_data->result = async_data->finish_strv (G_DBUS_PROXY (source_object), result, &async_data->out.val_strv, &error);
2413 else if (async_data->finish_uint)
2414 async_data->result = async_data->finish_uint (G_DBUS_PROXY (source_object), result, &async_data->out.val_uint, &error);
2416 g_warning ("%s: Do not know how to finish async operation", G_STRFUNC);
2418 finish_async_op (async_data, error, FALSE);
2421 g_error_free (error);
2424 static EClientAsyncOpData *
2425 prepare_async_data (EClient *client,
2426 GCancellable *cancellable,
2427 GAsyncReadyCallback callback,
2429 gpointer source_tag,
2430 gboolean error_report_only,
2431 EClientProxyFinishVoidFunc finish_void,
2432 EClientProxyFinishBooleanFunc finish_boolean,
2433 EClientProxyFinishStringFunc finish_string,
2434 EClientProxyFinishStrvFunc finish_strv,
2435 EClientProxyFinishUintFunc finish_uint,
2437 GCancellable **out_cancellable)
2439 EClientAsyncOpData *async_data;
2440 GCancellable *use_cancellable;
2443 g_return_val_if_fail (client != NULL, NULL);
2444 g_return_val_if_fail (callback != NULL, NULL);
2445 g_return_val_if_fail (source_tag != NULL, NULL);
2447 if (!error_report_only) {
2448 g_return_val_if_fail (proxy != NULL, NULL);
2449 g_return_val_if_fail (out_cancellable != NULL, NULL);
2450 g_return_val_if_fail (finish_void || finish_boolean || finish_string || finish_strv || finish_uint, NULL);
2453 g_return_val_if_fail (finish_boolean == NULL, NULL);
2454 g_return_val_if_fail (finish_string == NULL, NULL);
2455 g_return_val_if_fail (finish_strv == NULL, NULL);
2456 g_return_val_if_fail (finish_uint == NULL, NULL);
2459 if (finish_boolean) {
2460 g_return_val_if_fail (finish_void == NULL, NULL);
2461 g_return_val_if_fail (finish_string == NULL, NULL);
2462 g_return_val_if_fail (finish_strv == NULL, NULL);
2463 g_return_val_if_fail (finish_uint == NULL, NULL);
2466 if (finish_string) {
2467 g_return_val_if_fail (finish_void == NULL, NULL);
2468 g_return_val_if_fail (finish_boolean == NULL, NULL);
2469 g_return_val_if_fail (finish_strv == NULL, NULL);
2470 g_return_val_if_fail (finish_uint == NULL, NULL);
2474 g_return_val_if_fail (finish_void == NULL, NULL);
2475 g_return_val_if_fail (finish_boolean == NULL, NULL);
2476 g_return_val_if_fail (finish_string == NULL, NULL);
2477 g_return_val_if_fail (finish_uint == NULL, NULL);
2481 g_return_val_if_fail (finish_void == NULL, NULL);
2482 g_return_val_if_fail (finish_boolean == NULL, NULL);
2483 g_return_val_if_fail (finish_string == NULL, NULL);
2484 g_return_val_if_fail (finish_strv == NULL, NULL);
2487 *proxy = e_client_get_dbus_proxy (client);
2492 use_cancellable = cancellable;
2493 if (!use_cancellable)
2494 use_cancellable = g_cancellable_new ();
2496 opid = e_client_register_op (client, use_cancellable);
2497 async_data = g_new0 (EClientAsyncOpData, 1);
2498 async_data->client = g_object_ref (client);
2499 async_data->opid = opid;
2500 async_data->source_tag = source_tag;
2501 async_data->callback = callback;
2502 async_data->user_data = user_data;
2503 async_data->finish_void = finish_void;
2504 async_data->finish_boolean = finish_boolean;
2505 async_data->finish_string = finish_string;
2506 async_data->finish_strv = finish_strv;
2507 async_data->finish_uint = finish_uint;
2509 /* EClient from e_client_register_op() took ownership of the use_cancellable */
2510 if (use_cancellable != cancellable)
2511 g_object_unref (use_cancellable);
2513 if (out_cancellable)
2514 *out_cancellable = use_cancellable;
2520 e_client_proxy_return_async_error (EClient *client,
2521 const GError *error,
2522 GAsyncReadyCallback callback,
2524 gpointer source_tag)
2526 EClientAsyncOpData *async_data;
2528 g_return_if_fail (E_IS_CLIENT (client));
2529 g_return_if_fail (error != NULL);
2530 g_return_if_fail (callback != NULL);
2532 async_data = prepare_async_data (client, NULL, callback, user_data, source_tag, TRUE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2533 g_return_if_fail (async_data != NULL);
2535 finish_async_op (async_data, error, TRUE);
2539 e_client_proxy_call_void (EClient *client,
2540 GCancellable *cancellable,
2541 GAsyncReadyCallback callback,
2543 gpointer source_tag,
2544 void (*func) (GDBusProxy *proxy,
2545 GCancellable *cancellable,
2546 GAsyncReadyCallback callback,
2547 gpointer user_data),
2548 EClientProxyFinishVoidFunc finish_void,
2549 EClientProxyFinishBooleanFunc finish_boolean,
2550 EClientProxyFinishStringFunc finish_string,
2551 EClientProxyFinishStrvFunc finish_strv,
2552 EClientProxyFinishUintFunc finish_uint)
2554 EClientAsyncOpData *async_data;
2555 GDBusProxy *proxy = NULL;
2557 g_return_if_fail (E_IS_CLIENT (client));
2558 g_return_if_fail (callback != NULL);
2559 g_return_if_fail (source_tag != NULL);
2560 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2562 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);
2563 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2565 func (proxy, cancellable, async_result_ready_cb, async_data);
2569 e_client_proxy_call_boolean (EClient *client,
2570 gboolean in_boolean,
2571 GCancellable *cancellable,
2572 GAsyncReadyCallback callback,
2574 gpointer source_tag,
2575 void (*func) (GDBusProxy *proxy,
2576 gboolean in_boolean,
2577 GCancellable *cancellable,
2578 GAsyncReadyCallback callback,
2579 gpointer user_data),
2580 EClientProxyFinishVoidFunc finish_void,
2581 EClientProxyFinishBooleanFunc finish_boolean,
2582 EClientProxyFinishStringFunc finish_string,
2583 EClientProxyFinishStrvFunc finish_strv,
2584 EClientProxyFinishUintFunc finish_uint)
2586 EClientAsyncOpData *async_data;
2587 GDBusProxy *proxy = NULL;
2589 g_return_if_fail (E_IS_CLIENT (client));
2590 g_return_if_fail (callback != NULL);
2591 g_return_if_fail (source_tag != NULL);
2592 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2594 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);
2595 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2597 func (proxy, in_boolean, cancellable, async_result_ready_cb, async_data);
2601 e_client_proxy_call_string (EClient *client,
2602 const gchar *in_string,
2603 GCancellable *cancellable,
2604 GAsyncReadyCallback callback,
2606 gpointer source_tag,
2607 void (*func) (GDBusProxy *proxy,
2608 const gchar *in_string,
2609 GCancellable *cancellable,
2610 GAsyncReadyCallback callback,
2611 gpointer user_data),
2612 EClientProxyFinishVoidFunc finish_void,
2613 EClientProxyFinishBooleanFunc finish_boolean,
2614 EClientProxyFinishStringFunc finish_string,
2615 EClientProxyFinishStrvFunc finish_strv,
2616 EClientProxyFinishUintFunc finish_uint)
2618 EClientAsyncOpData *async_data;
2619 GDBusProxy *proxy = NULL;
2621 g_return_if_fail (E_IS_CLIENT (client));
2622 g_return_if_fail (callback != NULL);
2623 g_return_if_fail (source_tag != NULL);
2624 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2625 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2627 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);
2628 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2630 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2634 e_client_proxy_call_string_with_res_op_data (EClient *client,
2635 const gchar *in_string,
2636 GCancellable *cancellable,
2637 GAsyncReadyCallback callback,
2639 gpointer source_tag,
2640 const gchar *res_op_data,
2641 void (*func) (GDBusProxy *proxy,
2642 const gchar *in_string,
2643 GCancellable *cancellable,
2644 GAsyncReadyCallback callback,
2645 gpointer user_data),
2646 EClientProxyFinishVoidFunc finish_void,
2647 EClientProxyFinishBooleanFunc finish_boolean,
2648 EClientProxyFinishStringFunc finish_string,
2649 EClientProxyFinishStrvFunc finish_strv,
2650 EClientProxyFinishUintFunc finish_uint)
2652 EClientAsyncOpData *async_data;
2653 GDBusProxy *proxy = NULL;
2655 g_return_if_fail (E_IS_CLIENT (client));
2656 g_return_if_fail (callback != NULL);
2657 g_return_if_fail (source_tag != NULL);
2658 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2659 e_client_return_async_if_fail (in_string != NULL, client, callback, user_data, source_tag);
2661 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);
2662 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2664 async_data->res_op_data = g_strdup (res_op_data);
2666 func (proxy, in_string, cancellable, async_result_ready_cb, async_data);
2670 e_client_proxy_call_strv (EClient *client,
2671 const gchar * const *in_strv,
2672 GCancellable *cancellable,
2673 GAsyncReadyCallback callback,
2675 gpointer source_tag,
2676 void (*func) (GDBusProxy *proxy,
2677 const gchar * const * in_strv,
2678 GCancellable *cancellable,
2679 GAsyncReadyCallback callback,
2680 gpointer user_data),
2681 EClientProxyFinishVoidFunc finish_void,
2682 EClientProxyFinishBooleanFunc finish_boolean,
2683 EClientProxyFinishStringFunc finish_string,
2684 EClientProxyFinishStrvFunc finish_strv,
2685 EClientProxyFinishUintFunc finish_uint)
2687 EClientAsyncOpData *async_data;
2688 GDBusProxy *proxy = NULL;
2690 g_return_if_fail (E_IS_CLIENT (client));
2691 g_return_if_fail (callback != NULL);
2692 g_return_if_fail (source_tag != NULL);
2693 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2694 e_client_return_async_if_fail (in_strv != NULL, client, callback, user_data, source_tag);
2696 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);
2697 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2699 func (proxy, in_strv, cancellable, async_result_ready_cb, async_data);
2703 e_client_proxy_call_uint (EClient *client,
2705 GCancellable *cancellable,
2706 GAsyncReadyCallback callback,
2708 gpointer source_tag,
2709 void (*func) (GDBusProxy *proxy,
2711 GCancellable *cancellable,
2712 GAsyncReadyCallback callback,
2713 gpointer user_data),
2714 EClientProxyFinishVoidFunc finish_void,
2715 EClientProxyFinishBooleanFunc finish_boolean,
2716 EClientProxyFinishStringFunc finish_string,
2717 EClientProxyFinishStrvFunc finish_strv,
2718 EClientProxyFinishUintFunc finish_uint)
2720 EClientAsyncOpData *async_data;
2721 GDBusProxy *proxy = NULL;
2723 g_return_if_fail (E_IS_CLIENT (client));
2724 g_return_if_fail (callback != NULL);
2725 g_return_if_fail (source_tag != NULL);
2726 e_client_return_async_if_fail (func != NULL, client, callback, user_data, source_tag);
2728 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);
2729 e_client_return_async_if_fail (async_data != NULL, client, callback, user_data, source_tag);
2731 func (proxy, in_uint, cancellable, async_result_ready_cb, async_data);
2735 e_client_proxy_call_finish_void (EClient *client,
2736 GAsyncResult *result,
2738 gpointer source_tag)
2740 GSimpleAsyncResult *simple;
2741 GError *local_error = NULL;
2742 EClientAsyncOpData *async_data;
2744 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2745 g_return_val_if_fail (result != NULL, FALSE);
2746 g_return_val_if_fail (source_tag != NULL, FALSE);
2747 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2749 simple = G_SIMPLE_ASYNC_RESULT (result);
2751 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2752 e_client_unwrap_dbus_error (client, local_error, error);
2756 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2757 g_return_val_if_fail (async_data != NULL, FALSE);
2759 return async_data->result;
2763 e_client_proxy_call_finish_boolean (EClient *client,
2764 GAsyncResult *result,
2765 gboolean *out_boolean,
2767 gpointer source_tag)
2769 GSimpleAsyncResult *simple;
2770 GError *local_error = NULL;
2771 EClientAsyncOpData *async_data;
2773 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2774 g_return_val_if_fail (result != NULL, FALSE);
2775 g_return_val_if_fail (source_tag != NULL, FALSE);
2776 g_return_val_if_fail (out_boolean != NULL, FALSE);
2777 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2779 simple = G_SIMPLE_ASYNC_RESULT (result);
2781 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2782 e_client_unwrap_dbus_error (client, local_error, error);
2786 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2787 g_return_val_if_fail (async_data != NULL, FALSE);
2789 *out_boolean = async_data->out.val_boolean;
2791 return async_data->result;
2795 e_client_proxy_call_finish_string (EClient *client,
2796 GAsyncResult *result,
2799 gpointer source_tag)
2801 GSimpleAsyncResult *simple;
2802 GError *local_error = NULL;
2803 EClientAsyncOpData *async_data;
2805 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2806 g_return_val_if_fail (result != NULL, FALSE);
2807 g_return_val_if_fail (source_tag != NULL, FALSE);
2808 g_return_val_if_fail (out_string != NULL, FALSE);
2809 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2811 simple = G_SIMPLE_ASYNC_RESULT (result);
2813 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2814 e_client_unwrap_dbus_error (client, local_error, error);
2818 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2819 g_return_val_if_fail (async_data != NULL, FALSE);
2821 *out_string = async_data->out.val_string;
2822 async_data->out.val_string = NULL;
2824 return async_data->result;
2828 e_client_proxy_call_finish_strv (EClient *client,
2829 GAsyncResult *result,
2832 gpointer source_tag)
2834 GSimpleAsyncResult *simple;
2835 GError *local_error = NULL;
2836 EClientAsyncOpData *async_data;
2838 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2839 g_return_val_if_fail (result != NULL, FALSE);
2840 g_return_val_if_fail (source_tag != NULL, FALSE);
2841 g_return_val_if_fail (out_strv != NULL, FALSE);
2842 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2844 simple = G_SIMPLE_ASYNC_RESULT (result);
2846 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2847 e_client_unwrap_dbus_error (client, local_error, error);
2851 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2852 g_return_val_if_fail (async_data != NULL, FALSE);
2854 *out_strv = async_data->out.val_strv;
2855 async_data->out.val_strv = NULL;
2857 return async_data->result;
2861 e_client_proxy_call_finish_uint (EClient *client,
2862 GAsyncResult *result,
2865 gpointer source_tag)
2867 GSimpleAsyncResult *simple;
2868 GError *local_error = NULL;
2869 EClientAsyncOpData *async_data;
2871 g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
2872 g_return_val_if_fail (result != NULL, FALSE);
2873 g_return_val_if_fail (source_tag != NULL, FALSE);
2874 g_return_val_if_fail (out_uint != NULL, FALSE);
2875 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), source_tag), FALSE);
2877 simple = G_SIMPLE_ASYNC_RESULT (result);
2879 if (g_simple_async_result_propagate_error (simple, &local_error)) {
2880 e_client_unwrap_dbus_error (client, local_error, error);
2884 async_data = g_simple_async_result_get_op_res_gpointer (simple);
2885 g_return_val_if_fail (async_data != NULL, FALSE);
2887 *out_uint = async_data->out.val_uint;
2889 return async_data->result;
2892 #define SYNC_CALL_TEMPLATE(_out_test,_the_call) \
2893 GDBusProxy *proxy; \
2894 GCancellable *use_cancellable; \
2897 GError *local_error = NULL; \
2899 g_return_val_if_fail (E_IS_CLIENT (client), FALSE); \
2900 g_return_val_if_fail (func != NULL, FALSE); \
2901 g_return_val_if_fail (_out_test != NULL, FALSE); \
2903 proxy = e_client_get_dbus_proxy (client); \
2904 g_return_val_if_fail (proxy != NULL, FALSE); \
2906 use_cancellable = cancellable; \
2907 if (!use_cancellable) \
2908 use_cancellable = g_cancellable_new (); \
2910 g_object_ref (client); \
2911 opid = e_client_register_op (client, use_cancellable); \
2913 result = func _the_call; \
2915 e_client_unregister_op (client, opid); \
2916 g_object_unref (client); \
2918 if (use_cancellable != cancellable) \
2919 g_object_unref (use_cancellable); \
2921 e_client_unwrap_dbus_error (client, local_error, error);\
2926 e_client_proxy_call_sync_void__void (EClient *client,
2927 GCancellable *cancellable,
2929 gboolean (*func) (GDBusProxy *proxy,
2930 GCancellable *cancellable,
2933 SYNC_CALL_TEMPLATE (client, (proxy, use_cancellable, &local_error))
2937 e_client_proxy_call_sync_void__boolean (EClient *client,
2938 gboolean *out_boolean,
2939 GCancellable *cancellable,
2941 gboolean (*func) (GDBusProxy *proxy,
2942 gboolean *out_boolean,
2943 GCancellable *cancellable,
2946 SYNC_CALL_TEMPLATE (out_boolean, (proxy, out_boolean, use_cancellable, &local_error))
2950 e_client_proxy_call_sync_void__string (EClient *client,
2952 GCancellable *cancellable,
2954 gboolean (*func) (GDBusProxy *proxy,
2956 GCancellable *cancellable,
2959 SYNC_CALL_TEMPLATE (out_string, (proxy, out_string, use_cancellable, &local_error))
2963 e_client_proxy_call_sync_void__strv (EClient *client,
2965 GCancellable *cancellable,
2967 gboolean (*func) (GDBusProxy *proxy,
2969 GCancellable *cancellable,
2972 SYNC_CALL_TEMPLATE (out_strv, (proxy, out_strv, use_cancellable, &local_error))
2976 e_client_proxy_call_sync_void__uint (EClient *client,
2978 GCancellable *cancellable,
2980 gboolean (*func) (GDBusProxy *proxy,
2982 GCancellable *cancellable,
2985 SYNC_CALL_TEMPLATE (out_uint, (proxy, out_uint, use_cancellable, &local_error))
2989 e_client_proxy_call_sync_boolean__void (EClient *client,
2990 gboolean in_boolean,
2991 GCancellable *cancellable,
2993 gboolean (*func) (GDBusProxy *proxy,
2994 gboolean in_boolean,
2995 GCancellable *cancellable,
2998 SYNC_CALL_TEMPLATE (client, (proxy, in_boolean, use_cancellable, &local_error))
3002 e_client_proxy_call_sync_boolean__boolean (EClient *client,
3003 gboolean in_boolean,
3004 gboolean *out_boolean,
3005 GCancellable *cancellable,
3007 gboolean (*func) (GDBusProxy *proxy,
3008 gboolean in_boolean,
3009 gboolean *out_boolean,
3010 GCancellable *cancellable,
3013 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_boolean, out_boolean, use_cancellable, &local_error))
3017 e_client_proxy_call_sync_boolean__string (EClient *client,
3018 gboolean in_boolean,
3020 GCancellable *cancellable,
3022 gboolean (*func) (GDBusProxy *proxy,
3023 gboolean in_boolean,
3025 GCancellable *cancellable,
3028 SYNC_CALL_TEMPLATE (out_string, (proxy, in_boolean, out_string, use_cancellable, &local_error))
3032 e_client_proxy_call_sync_boolean__strv (EClient *client,
3033 gboolean in_boolean,
3035 GCancellable *cancellable,
3037 gboolean (*func) (GDBusProxy *proxy,
3038 gboolean in_boolean,
3040 GCancellable *cancellable,
3043 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_boolean, out_strv, use_cancellable, &local_error))
3047 e_client_proxy_call_sync_boolean__uint (EClient *client,
3048 gboolean in_boolean,
3050 GCancellable *cancellable,
3052 gboolean (*func) (GDBusProxy *proxy,
3053 gboolean in_boolean,
3055 GCancellable *cancellable,
3058 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_boolean, out_uint, use_cancellable, &local_error))
3062 e_client_proxy_call_sync_string__void (EClient *client,
3063 const gchar *in_string,
3064 GCancellable *cancellable,
3066 gboolean (*func) (GDBusProxy *proxy,
3067 const gchar *in_string,
3068 GCancellable *cancellable,
3071 SYNC_CALL_TEMPLATE (client, (proxy, in_string, use_cancellable, &local_error))
3075 e_client_proxy_call_sync_string__boolean (EClient *client,
3076 const gchar *in_string,
3077 gboolean *out_boolean,
3078 GCancellable *cancellable,
3080 gboolean (*func) (GDBusProxy *proxy,
3081 const gchar *in_string,
3082 gboolean *out_boolean,
3083 GCancellable *cancellable,
3086 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_string, out_boolean, use_cancellable, &local_error))
3090 e_client_proxy_call_sync_string__string (EClient *client,
3091 const gchar *in_string,
3093 GCancellable *cancellable,
3095 gboolean (*func) (GDBusProxy *proxy,
3096 const gchar *in_string,
3098 GCancellable *cancellable,
3101 SYNC_CALL_TEMPLATE (out_string, (proxy, in_string, out_string, use_cancellable, &local_error))
3105 e_client_proxy_call_sync_string__strv (EClient *client,
3106 const gchar *in_string,
3108 GCancellable *cancellable,
3110 gboolean (*func) (GDBusProxy *proxy,
3111 const gchar *in_string,
3113 GCancellable *cancellable,
3116 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_string, out_strv, use_cancellable, &local_error))
3120 e_client_proxy_call_sync_string__uint (EClient *client,
3121 const gchar *in_string,
3123 GCancellable *cancellable,
3125 gboolean (*func) (GDBusProxy *proxy,
3126 const gchar *in_string,
3128 GCancellable *cancellable,
3131 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_string, out_uint, use_cancellable, &local_error))
3135 e_client_proxy_call_sync_strv__void (EClient *client,
3136 const gchar * const *in_strv,
3137 GCancellable *cancellable,
3139 gboolean (*func) (GDBusProxy *proxy,
3140 const gchar * const *in_strv,
3141 GCancellable *cancellable,
3144 SYNC_CALL_TEMPLATE (client, (proxy, in_strv, use_cancellable, &local_error))
3148 e_client_proxy_call_sync_strv__boolean (EClient *client,
3149 const gchar * const *in_strv,
3150 gboolean *out_boolean,
3151 GCancellable *cancellable,
3153 gboolean (*func) (GDBusProxy *proxy,
3154 const gchar * const *in_strv,
3155 gboolean *out_boolean,
3156 GCancellable *cancellable,
3159 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_strv, out_boolean, use_cancellable, &local_error))
3163 e_client_proxy_call_sync_strv__string (EClient *client,
3164 const gchar * const *in_strv,
3166 GCancellable *cancellable,
3168 gboolean (*func) (GDBusProxy *proxy,
3169 const gchar * const *in_strv,
3171 GCancellable *cancellable,
3174 SYNC_CALL_TEMPLATE (out_string, (proxy, in_strv, out_string, use_cancellable, &local_error))
3178 e_client_proxy_call_sync_strv__strv (EClient *client,
3179 const gchar * const *in_strv,
3181 GCancellable *cancellable,
3183 gboolean (*func) (GDBusProxy *proxy,
3184 const gchar * const *in_strv,
3186 GCancellable *cancellable,
3189 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_strv, out_strv, use_cancellable, &local_error))
3193 e_client_proxy_call_sync_strv__uint (EClient *client,
3194 const gchar * const *in_strv,
3196 GCancellable *cancellable,
3198 gboolean (*func) (GDBusProxy *proxy,
3199 const gchar * const *in_strv,
3201 GCancellable *cancellable,
3204 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_strv, out_uint, use_cancellable, &local_error))
3208 e_client_proxy_call_sync_uint__void (EClient *client,
3210 GCancellable *cancellable,
3212 gboolean (*func) (GDBusProxy *proxy,
3214 GCancellable *cancellable,
3217 SYNC_CALL_TEMPLATE (client, (proxy, in_uint, use_cancellable, &local_error))
3221 e_client_proxy_call_sync_uint__boolean (EClient *client,
3223 gboolean *out_boolean,
3224 GCancellable *cancellable,
3226 gboolean (*func) (GDBusProxy *proxy,
3228 gboolean *out_boolean,
3229 GCancellable *cancellable,
3232 SYNC_CALL_TEMPLATE (out_boolean, (proxy, in_uint, out_boolean, use_cancellable, &local_error))
3236 e_client_proxy_call_sync_uint__string (EClient *client,
3239 GCancellable *cancellable,
3241 gboolean (*func) (GDBusProxy *proxy,
3244 GCancellable *cancellable,
3247 SYNC_CALL_TEMPLATE (out_string, (proxy, in_uint, out_string, use_cancellable, &local_error))
3251 e_client_proxy_call_sync_uint__strv (EClient *client,
3254 GCancellable *cancellable,
3256 gboolean (*func) (GDBusProxy *proxy,
3259 GCancellable *cancellable,
3262 SYNC_CALL_TEMPLATE (out_strv, (proxy, in_uint, out_strv, use_cancellable, &local_error))
3266 e_client_proxy_call_sync_uint__uint (EClient *client,
3269 GCancellable *cancellable,
3271 gboolean (*func) (GDBusProxy *proxy,
3274 GCancellable *cancellable,
3277 SYNC_CALL_TEMPLATE (out_uint, (proxy, in_uint, out_uint, use_cancellable, &local_error))
3280 #undef SYNC_CALL_TEMPLATE