1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4 * Copyright (C) 2006 OpenedHand Ltd
5 * Copyright (C) 2009 Intel Corporation
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of version 2.1 of the GNU Lesser General Public License as
9 * published by the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author: Ross Burton <ross@linux.intel.com>
23 /* e-book deprecated since 3.2, use e-book-client instead */
28 * The old asynchronous API was deprecated since 3.0 and is replaced with
29 * their an equivalent version which has a detailed #GError
30 * structure in the asynchronous callback, instead of a status code only.
32 * As an example, e_book_async_open() is replaced by e_book_open_async().
34 * Deprecated: 3.2: Use #EBookClient instead.
40 #include <glib/gi18n-lib.h>
43 #include "e-contact.h"
44 #include "e-name-western.h"
45 #include "e-book-view-private.h"
46 #include "e-book-marshal.h"
48 #define E_BOOK_GET_PRIVATE(obj) \
49 (G_TYPE_INSTANCE_GET_PRIVATE \
50 ((obj), E_TYPE_BOOK, EBookPrivate))
52 #define CLIENT_BACKEND_PROPERTY_CAPABILITIES "capabilities"
53 #define BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS "required-fields"
54 #define BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS "supported-fields"
56 struct _EBookPrivate {
58 gulong backend_died_handler_id;
59 gulong notify_online_handler_id;
60 gulong notify_readonly_handler_id;
68 gpointer callback; /* TODO union */
87 static guint signals[LAST_SIGNAL];
89 static void e_book_initable_init (GInitableIface *interface);
91 G_DEFINE_TYPE_WITH_CODE (
92 EBook, e_book, G_TYPE_OBJECT,
93 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, e_book_initable_init))
95 G_DEFINE_QUARK (e-book-error-quark, e_book_error)
98 book_backend_died_cb (EClient *client,
101 /* Echo the signal emission from the EBookClient. */
102 g_signal_emit (book, signals[BACKEND_DIED], 0);
106 book_notify_online_cb (EClient *client,
110 gboolean online = e_client_is_online (client);
112 g_signal_emit (book, signals[CONNECTION_STATUS], 0, online);
116 book_notify_readonly_cb (EClient *client,
120 gboolean writable = !e_client_is_readonly (client);
122 g_signal_emit (book, signals[WRITABLE_STATUS], 0, writable);
126 book_set_source (EBook *book,
129 g_return_if_fail (E_IS_SOURCE (source));
130 g_return_if_fail (book->priv->source == NULL);
132 book->priv->source = g_object_ref (source);
136 book_set_property (GObject *object,
141 switch (property_id) {
145 g_value_get_object (value));
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
153 book_get_property (GObject *object,
158 switch (property_id) {
161 value, e_book_get_source (
166 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
170 book_dispose (GObject *object)
174 priv = E_BOOK_GET_PRIVATE (object);
176 if (priv->client != NULL) {
177 g_signal_handler_disconnect (
179 priv->backend_died_handler_id);
180 g_signal_handler_disconnect (
182 priv->notify_online_handler_id);
183 g_signal_handler_disconnect (
185 priv->notify_readonly_handler_id);
186 g_object_unref (priv->client);
190 if (priv->source != NULL) {
191 g_object_unref (priv->source);
195 /* Chain up to parent's dispose() method. */
196 G_OBJECT_CLASS (e_book_parent_class)->dispose (object);
200 book_finalize (GObject *object)
204 priv = E_BOOK_GET_PRIVATE (object);
208 /* Chain up to parent's finalize() method. */
209 G_OBJECT_CLASS (e_book_parent_class)->finalize (object);
213 book_initable_init (GInitable *initable,
214 GCancellable *cancellable,
217 EBook *book = E_BOOK (initable);
220 source = e_book_get_source (book);
222 book->priv->client = e_book_client_new (source, error);
224 if (book->priv->client == NULL)
227 book->priv->backend_died_handler_id = g_signal_connect (
228 book->priv->client, "backend-died",
229 G_CALLBACK (book_backend_died_cb), book);
231 book->priv->notify_online_handler_id = g_signal_connect (
232 book->priv->client, "notify::online",
233 G_CALLBACK (book_notify_online_cb), book);
235 book->priv->notify_readonly_handler_id = g_signal_connect (
236 book->priv->client, "notify::readonly",
237 G_CALLBACK (book_notify_readonly_cb), book);
243 e_book_class_init (EBookClass *class)
245 GObjectClass *object_class;
247 g_type_class_add_private (class, sizeof (EBookPrivate));
249 object_class = G_OBJECT_CLASS (class);
250 object_class->set_property = book_set_property;
251 object_class->get_property = book_get_property;
252 object_class->dispose = book_dispose;
253 object_class->finalize = book_finalize;
255 g_object_class_install_property (
258 g_param_spec_object (
261 "The data source for this EBook",
264 G_PARAM_CONSTRUCT_ONLY |
265 G_PARAM_STATIC_STRINGS));
267 signals[WRITABLE_STATUS] = g_signal_new (
269 G_OBJECT_CLASS_TYPE (object_class),
271 G_STRUCT_OFFSET (EBookClass, writable_status),
273 e_book_marshal_NONE__BOOL,
277 signals[CONNECTION_STATUS] = g_signal_new (
279 G_OBJECT_CLASS_TYPE (object_class),
281 G_STRUCT_OFFSET (EBookClass, connection_status),
283 e_book_marshal_NONE__BOOL,
287 signals[BACKEND_DIED] = g_signal_new (
289 G_OBJECT_CLASS_TYPE (object_class),
291 G_STRUCT_OFFSET (EBookClass, backend_died),
293 e_book_marshal_NONE__NONE,
298 e_book_initable_init (GInitableIface *interface)
300 interface->init = book_initable_init;
304 e_book_init (EBook *book)
306 book->priv = E_BOOK_GET_PRIVATE (book);
310 * e_book_add_contact:
312 * @contact: an #EContact
313 * @error: a #GError to set on failure
315 * Adds @contact to @book.
317 * Returns: %TRUE if successful, %FALSE otherwise.
319 * Deprecated: 3.2: Use e_book_client_add_contact_sync() instead.
322 e_book_add_contact (EBook *book,
326 gchar *added_uid = NULL;
329 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
330 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
332 success = e_book_client_add_contact_sync (
333 book->priv->client, contact, &added_uid, NULL, error);
335 if (added_uid != NULL) {
336 e_contact_set (contact, E_CONTACT_UID, added_uid);
344 add_contact_reply (GObject *source_object,
345 GAsyncResult *result,
348 AsyncData *data = user_data;
349 EBookIdCallback cb = data->callback;
350 EBookIdAsyncCallback excb = data->excallback;
351 gchar *added_uid = NULL;
352 GError *error = NULL;
354 e_book_client_add_contact_finish (
355 E_BOOK_CLIENT (source_object), result, &added_uid, &error);
357 if (cb != NULL && error == NULL)
358 cb (data->book, E_BOOK_ERROR_OK, added_uid, data->closure);
359 if (cb != NULL && error != NULL)
360 cb (data->book, error->code, NULL, data->closure);
362 excb (data->book, error, added_uid, data->closure);
365 g_error_free (error);
369 g_object_unref (data->book);
370 g_slice_free (AsyncData, data);
374 * e_book_async_add_contact:
376 * @contact: an #EContact
377 * @cb: (scope async): function to call when the operation finishes
378 * @closure: data to pass to callback function
380 * Adds @contact to @book without blocking.
382 * Returns: %TRUE if the operation was started, %FALSE otherwise.
384 * Deprecated: 3.0: Use e_book_add_contact_async() instead.
387 e_book_async_add_contact (EBook *book,
394 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
395 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
397 data = g_slice_new0 (AsyncData);
398 data->book = g_object_ref (book);
400 data->closure = closure;
402 e_book_client_add_contact (
403 book->priv->client, contact, NULL,
404 add_contact_reply, data);
410 * e_book_add_contact_async:
412 * @contact: an #EContact
413 * @cb: (scope async): function to call when the operation finishes
414 * @closure: data to pass to callback function
416 * Adds @contact to @book without blocking.
418 * Returns: %TRUE if the operation was started, %FALSE otherwise.
422 * Deprecated: 3.2: Use e_book_client_add_contact() and e_book_client_add_contact_finish() instead.
425 e_book_add_contact_async (EBook *book,
427 EBookIdAsyncCallback cb,
432 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
433 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
435 data = g_slice_new0 (AsyncData);
436 data->book = g_object_ref (book);
437 data->excallback = cb;
438 data->closure = closure;
440 e_book_client_add_contact (
441 book->priv->client, contact, NULL,
442 add_contact_reply, data);
448 * e_book_commit_contact:
450 * @contact: an #EContact
451 * @error: a #GError to set on failure
453 * Applies the changes made to @contact to the stored version in
456 * Returns: %TRUE if successful, %FALSE otherwise
458 * Deprecated: 3.2: Use e_book_client_modify_contact_sync() instead.
461 e_book_commit_contact (EBook *book,
465 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
466 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
468 return e_book_client_modify_contact_sync (
469 book->priv->client, contact, NULL, error);
473 modify_contacts_reply (GObject *source_object,
474 GAsyncResult *result,
477 AsyncData *data = user_data;
478 EBookCallback cb = data->callback;
479 EBookAsyncCallback excb = data->excallback;
480 GError *error = NULL;
482 e_book_client_modify_contact_finish (
483 E_BOOK_CLIENT (source_object), result, &error);
485 if (cb != NULL && error == NULL)
486 cb (data->book, E_BOOK_ERROR_OK, data->closure);
487 if (cb != NULL && error != NULL)
488 cb (data->book, error->code, data->closure);
490 excb (data->book, error, data->closure);
493 g_error_free (error);
495 g_object_unref (data->book);
496 g_slice_free (AsyncData, data);
500 * e_book_async_commit_contact:
502 * @contact: an #EContact
503 * @cb: (scope async): function to call when the operation finishes
504 * @closure: data to pass to callback function
506 * Applies the changes made to @contact to the stored version in
507 * @book without blocking.
509 * Returns: %TRUE if the operation was started, %FALSE otherwise.
511 * Deprecated: 3.0: Use e_book_commit_contact_async() instead.
514 e_book_async_commit_contact (EBook *book,
521 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
522 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
524 data = g_slice_new0 (AsyncData);
525 data->book = g_object_ref (book);
527 data->closure = closure;
529 e_book_client_modify_contact (
530 book->priv->client, contact, NULL,
531 modify_contacts_reply, data);
537 * e_book_commit_contact_async:
539 * @contact: an #EContact
540 * @cb: (scope async): function to call when the operation finishes
541 * @closure: data to pass to callback function
543 * Applies the changes made to @contact to the stored version in
544 * @book without blocking.
546 * Returns: %TRUE if the operation was started, %FALSE otherwise.
550 * Deprecated: 3.2: Use e_book_client_modify_contact() and e_book_client_modify_contact_finish() instead.
553 e_book_commit_contact_async (EBook *book,
555 EBookAsyncCallback cb,
560 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
561 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
563 data = g_slice_new0 (AsyncData);
564 data->book = g_object_ref (book);
565 data->excallback = cb;
566 data->closure = closure;
568 e_book_client_modify_contact (
569 book->priv->client, contact, NULL,
570 modify_contacts_reply, data);
576 * e_book_get_required_fields:
578 * @fields: (out) (transfer full) (element-type utf8): a #GList of fields to set on success
579 * @error: a #GError to set on failure
581 * Gets a list of fields that are required to be filled in for
582 * all contacts in this @book. The list will contain pointers
583 * to allocated strings, and both the #GList and the strings
584 * must be freed by the caller.
586 * Returns: %TRUE if successful, %FALSE otherwise.
588 * Deprecated: 3.2: Use e_client_get_backend_property_sync() on
589 * an #EBookClient object with #BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS instead.
592 e_book_get_required_fields (EBook *book,
596 gchar *prop_value = NULL;
599 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
604 success = e_client_get_backend_property_sync (
605 E_CLIENT (book->priv->client),
606 BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS,
607 &prop_value, NULL, error);
609 if (success && fields != NULL) {
610 GQueue queue = G_QUEUE_INIT;
614 strv = g_strsplit (prop_value, ",", -1);
616 for (ii = 0; strv != NULL && strv[ii] != NULL; ii++)
617 g_queue_push_tail (&queue, strv[ii]);
619 /* The GQueue now owns the strings in the string array,
620 * so use g_free() instead of g_strfreev() to free just
621 * the array itself. */
624 /* Transfer ownership of the GQueue content. */
625 *fields = g_queue_peek_head_link (&queue);
634 get_required_fields_reply (GObject *source_object,
635 GAsyncResult *result,
638 AsyncData *data = user_data;
639 EBookEListCallback cb = data->callback;
640 EBookEListAsyncCallback excb = data->excallback;
642 gchar *prop_value = NULL;
643 GError *error = NULL;
645 e_client_get_backend_property_finish (
646 E_CLIENT (source_object), result, &prop_value, &error);
650 ((prop_value != NULL) && (error == NULL)) ||
651 ((prop_value == NULL) && (error != NULL)));
653 /* In the event of an error, we pass an empty EList. */
654 elist = e_list_new (NULL, (EListFreeFunc) g_free, NULL);
656 if (prop_value != NULL) {
660 strv = g_strsplit (prop_value, ",", -1);
661 for (ii = 0; strv != NULL && strv[ii] != NULL; ii++) {
662 gchar *utf8 = e_util_utf8_make_valid (strv[ii]);
663 e_list_append (elist, utf8);
668 if (cb != NULL && error == NULL)
669 cb (data->book, E_BOOK_ERROR_OK, elist, data->closure);
670 if (cb != NULL && error != NULL)
671 cb (data->book, error->code, elist, data->closure);
673 excb (data->book, error, elist, data->closure);
675 g_object_unref (elist);
678 g_error_free (error);
680 g_object_unref (data->book);
681 g_slice_free (AsyncData, data);
685 * e_book_async_get_required_fields:
687 * @cb: (scope async): function to call when the operation finishes
688 * @closure: data to pass to callback function
690 * Gets a list of fields that are required to be filled in for
691 * all contacts in this @book. This function does not block.
693 * Returns: %TRUE if the operation was started, %FALSE otherwise.
695 * Deprecated: 3.0: Use e_book_get_required_fields_async() instead.
698 e_book_async_get_required_fields (EBook *book,
699 EBookEListCallback cb,
704 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
706 data = g_slice_new0 (AsyncData);
707 data->book = g_object_ref (book);
709 data->closure = closure;
711 e_client_get_backend_property (
712 E_CLIENT (book->priv->client),
713 BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS,
714 NULL, get_required_fields_reply, data);
720 * e_book_get_required_fields_async:
722 * @cb: (scope async): function to call when the operation finishes
723 * @closure: data to pass to callback function
725 * Gets a list of fields that are required to be filled in for
726 * all contacts in this @book. This function does not block.
728 * Returns: %TRUE if the operation was started, %FALSE otherwise.
732 * Deprecated: 3.2: Use e_client_get_backend_property() and e_client_get_backend_property_finish()
733 * on an #EBookClient object with #BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS instead.
736 e_book_get_required_fields_async (EBook *book,
737 EBookEListAsyncCallback cb,
742 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
744 data = g_slice_new0 (AsyncData);
745 data->book = g_object_ref (book);
746 data->excallback = cb;
747 data->closure = closure;
749 e_client_get_backend_property (
750 E_CLIENT (book->priv->client),
751 BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS,
752 NULL, get_required_fields_reply, data);
758 * e_book_get_supported_fields:
760 * @fields: (out) (transfer full) (element-type utf8): a #GList of fields to set on success
761 * @error: a #GError to set on failure
763 * Gets a list of fields that can be stored for contacts
764 * in this @book. Other fields may be discarded. The list
765 * will contain pointers to allocated strings, and both the
766 * #GList and the strings must be freed by the caller.
768 * Returns: %TRUE if successful, %FALSE otherwise
770 * Deprecated: 3.2: Use e_client_get_backend_property_sync() on
771 * an #EBookClient object with #BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS instead.
774 e_book_get_supported_fields (EBook *book,
778 gchar *prop_value = NULL;
781 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
786 success = e_client_get_backend_property_sync (
787 E_CLIENT (book->priv->client),
788 BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS,
789 &prop_value, NULL, error);
791 if (success && fields != NULL) {
792 GQueue queue = G_QUEUE_INIT;
796 strv = g_strsplit (prop_value, ",", -1);
798 for (ii = 0; strv != NULL && strv[ii] != NULL; ii++)
799 g_queue_push_tail (&queue, strv[ii]);
801 /* The GQueue now owns the strings in the string array,
802 * so use g_free() instead of g_strfreev() to free just
803 * the array itself. */
806 /* Transfer ownership of the GQueue content. */
807 *fields = g_queue_peek_head_link (&queue);
816 get_supported_fields_reply (GObject *source_object,
817 GAsyncResult *result,
820 AsyncData *data = user_data;
821 EBookEListCallback cb = data->callback;
822 EBookEListAsyncCallback excb = data->excallback;
824 gchar *prop_value = NULL;
825 GError *error = NULL;
827 e_client_get_backend_property_finish (
828 E_CLIENT (source_object), result, &prop_value, &error);
832 ((prop_value != NULL) && (error == NULL)) ||
833 ((prop_value == NULL) && (error != NULL)));
835 /* In the event of an error, we pass an empty EList. */
836 elist = e_list_new (NULL, (EListFreeFunc) g_free, NULL);
838 if (prop_value != NULL) {
842 strv = g_strsplit (prop_value, ",", -1);
843 for (ii = 0; strv != NULL && strv[ii] != NULL; ii++) {
844 gchar *utf8 = e_util_utf8_make_valid (strv[ii]);
845 e_list_append (elist, utf8);
850 if (cb != NULL && error == NULL)
851 cb (data->book, E_BOOK_ERROR_OK, elist, data->closure);
852 if (cb != NULL && error != NULL)
853 cb (data->book, error->code, elist, data->closure);
855 excb (data->book, error, elist, data->closure);
857 g_object_unref (elist);
860 g_error_free (error);
862 g_object_unref (data->book);
863 g_slice_free (AsyncData, data);
867 * e_book_async_get_supported_fields:
869 * @cb: (scope async): function to call when the operation finishes
870 * @closure: data to pass to callback function
872 * Gets a list of fields that can be stored for contacts
873 * in this @book. Other fields may be discarded. This
874 * function does not block.
876 * Returns: %TRUE if successful, %FALSE otherwise.
878 * Deprecated: 3.0: Use e_book_get_supported_fields_async() instead.
881 e_book_async_get_supported_fields (EBook *book,
882 EBookEListCallback cb,
887 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
889 data = g_slice_new0 (AsyncData);
890 data->book = g_object_ref (book);
892 data->closure = closure;
894 e_client_get_backend_property (
895 E_CLIENT (book->priv->client),
896 BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS,
897 NULL, get_supported_fields_reply, data);
903 * e_book_get_supported_fields_async:
905 * @cb: (scope async): function to call when the operation finishes
906 * @closure: data to pass to callback function
908 * Gets a list of fields that can be stored for contacts
909 * in this @book. Other fields may be discarded. This
910 * function does not block.
912 * Returns: %TRUE if successful, %FALSE otherwise.
916 * Deprecated: 3.2: Use e_client_get_backend_property() and e_client_get_backend_property_finish()
917 * on an #EBookClient object with #BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS instead.
920 e_book_get_supported_fields_async (EBook *book,
921 EBookEListAsyncCallback cb,
926 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
928 data = g_slice_new0 (AsyncData);
929 data->book = g_object_ref (book);
930 data->excallback = cb;
931 data->closure = closure;
933 e_client_get_backend_property (
934 E_CLIENT (book->priv->client),
935 BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS,
936 NULL, get_supported_fields_reply, data);
942 * e_book_get_supported_auth_methods:
944 * @auth_methods: (out) (transfer full) (element-type utf8): a #GList of auth methods to set on success
945 * @error: a #GError to set on failure
947 * Queries @book for the list of authentication methods it supports.
948 * The list will contain pointers to allocated strings, and both the
949 * #GList and the strings must be freed by the caller.
951 * Returns: %TRUE if successful, %FALSE otherwise
953 * Deprecated: 3.2: The property is no longer supported.
956 e_book_get_supported_auth_methods (EBook *book,
957 GList **auth_methods,
960 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
962 if (auth_methods != NULL)
963 *auth_methods = NULL;
969 * e_book_async_get_supported_auth_methods:
971 * @cb: (scope async): function to call when the operation finishes
972 * @closure: data to pass to callback function
974 * Queries @book for the list of authentication methods it supports.
975 * This function does not block.
977 * Returns: %TRUE if successful, %FALSE otherwise.
979 * Deprecated: 3.0: The property is no longer supported.
982 e_book_async_get_supported_auth_methods (EBook *book,
983 EBookEListCallback cb,
986 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
989 /* Pass the callback an empty list. */
990 EList *elist = e_list_new (NULL, NULL, NULL);
991 cb (book, E_BOOK_ERROR_OK, elist, closure);
992 g_object_unref (elist);
999 * e_book_get_supported_auth_methods_async:
1001 * @cb: (scope async): function to call when the operation finishes
1002 * @closure: data to pass to callback function
1004 * Queries @book for the list of authentication methods it supports.
1005 * This function does not block.
1007 * Returns: %TRUE if successful, %FALSE otherwise.
1011 * Deprecated: 3.2: The property is no longer supported.
1014 e_book_get_supported_auth_methods_async (EBook *book,
1015 EBookEListAsyncCallback cb,
1018 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1021 /* Pass the callback an empty list. */
1022 EList *elist = e_list_new (NULL, NULL, NULL);
1023 cb (book, NULL, elist, closure);
1024 g_object_unref (elist);
1031 * e_book_get_contact:
1033 * @id: a unique string ID specifying the contact
1034 * @contact: (out) (transfer full): an #EContact
1035 * @error: a #GError to set on failure
1037 * Fills in @contact with the contents of the vcard in @book
1038 * corresponding to @id.
1040 * Returns: %TRUE if successful, %FALSE otherwise
1042 * Deprecated: 3.2: Use e_book_client_get_contact_sync() instead.
1045 e_book_get_contact (EBook *book,
1050 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1051 g_return_val_if_fail (id != NULL, FALSE);
1052 g_return_val_if_fail (contact != NULL, FALSE);
1054 return e_book_client_get_contact_sync (
1055 book->priv->client, id, contact, NULL, error);
1059 get_contact_reply (GObject *source_object,
1060 GAsyncResult *result,
1063 AsyncData *data = user_data;
1064 EBookContactCallback cb = data->callback;
1065 EBookContactAsyncCallback excb = data->excallback;
1066 EContact *contact = NULL;
1067 GError *error = NULL;
1069 e_book_client_get_contact_finish (
1070 E_BOOK_CLIENT (source_object), result, &contact, &error);
1072 if (cb != NULL && error == NULL)
1073 cb (data->book, E_BOOK_ERROR_OK, contact, data->closure);
1074 if (cb != NULL && error != NULL)
1075 cb (data->book, error->code, NULL, data->closure);
1077 excb (data->book, error, contact, data->closure);
1079 if (contact != NULL)
1080 g_object_unref (contact);
1083 g_error_free (error);
1085 g_object_unref (data->book);
1086 g_slice_free (AsyncData, data);
1090 * e_book_async_get_contact:
1092 * @id: a unique string ID specifying the contact
1093 * @cb: (scope async): function to call when operation finishes
1094 * @closure: data to pass to callback function
1096 * Retrieves a contact specified by @id from @book.
1098 * Returns: %FALSE if successful, %TRUE otherwise
1100 * Deprecated: 3.0: Use e_book_get_contact_async() instead.
1103 e_book_async_get_contact (EBook *book,
1105 EBookContactCallback cb,
1110 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1111 g_return_val_if_fail (id != NULL, FALSE);
1113 data = g_slice_new0 (AsyncData);
1114 data->book = g_object_ref (book);
1115 data->callback = cb;
1116 data->closure = closure;
1118 e_book_client_get_contact (
1119 E_BOOK_CLIENT (book->priv->client),
1120 id, NULL, get_contact_reply, data);
1126 * e_book_get_contact_async:
1128 * @id: a unique string ID specifying the contact
1129 * @cb: (scope async): function to call when operation finishes
1130 * @closure: data to pass to callback function
1132 * Retrieves a contact specified by @id from @book.
1134 * Returns: %FALSE if successful, %TRUE otherwise
1138 * Deprecated: 3.2: Use e_book_client_get_contact() and e_book_client_get_contact_finish() instead.
1141 e_book_get_contact_async (EBook *book,
1143 EBookContactAsyncCallback cb,
1148 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1149 g_return_val_if_fail (id != NULL, FALSE);
1151 data = g_slice_new0 (AsyncData);
1152 data->book = g_object_ref (book);
1153 data->excallback = cb;
1154 data->closure = closure;
1156 e_book_client_get_contact (
1157 E_BOOK_CLIENT (book->priv->client),
1158 id, NULL, get_contact_reply, data);
1164 * e_book_remove_contact:
1167 * @error: a #GError to set on failure
1169 * Removes the contact with id @id from @book.
1171 * Returns: %TRUE if successful, %FALSE otherwise
1173 * Deprecated: 3.2: Use e_book_client_remove_contact_by_uid_sync() or e_book_client_remove_contact_sync() instead.
1176 e_book_remove_contact (EBook *book,
1180 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1181 g_return_val_if_fail (id != NULL, FALSE);
1183 return e_book_client_remove_contact_by_uid_sync (
1184 book->priv->client, id, NULL, error);
1188 remove_contact_reply (GObject *source_object,
1189 GAsyncResult *result,
1192 AsyncData *data = user_data;
1193 EBookCallback cb = data->callback;
1194 EBookAsyncCallback excb = data->excallback;
1195 GError *error = NULL;
1197 e_book_client_remove_contact_finish (
1198 E_BOOK_CLIENT (source_object), result, &error);
1200 if (cb != NULL && error == NULL)
1201 cb (data->book, E_BOOK_ERROR_OK, data->closure);
1202 if (cb != NULL && error != NULL)
1203 cb (data->book, error->code, data->closure);
1205 excb (data->book, error, data->closure);
1208 g_error_free (error);
1210 g_object_unref (data->book);
1211 g_slice_free (AsyncData, data);
1215 * e_book_remove_contacts:
1217 * @ids: (element-type utf8): an #GList of const gchar *id's
1218 * @error: a #GError to set on failure
1220 * Removes the contacts with ids from the list @ids from @book. This is
1221 * always more efficient than calling e_book_remove_contact() if you
1222 * have more than one id to remove, as some backends can implement it
1223 * as a batch request.
1225 * Returns: %TRUE if successful, %FALSE otherwise
1227 * Deprecated: 3.2: Use e_book_client_remove_contacts_sync() instead.
1230 e_book_remove_contacts (EBook *book,
1234 GSList *slist = NULL;
1237 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1238 g_return_val_if_fail (ids != NULL, FALSE);
1240 /* XXX Never use GSList in a public API. */
1241 while (ids != NULL) {
1242 slist = g_slist_prepend (slist, ids->data);
1243 ids = g_list_next (ids);
1245 slist = g_slist_reverse (slist);
1247 success = e_book_client_remove_contacts_sync (
1248 book->priv->client, slist, NULL, error);
1250 g_slist_free (slist);
1256 * e_book_async_remove_contact:
1258 * @contact: an #EContact
1259 * @cb: (scope async): a function to call when the operation finishes
1260 * @closure: data to pass to callback function
1262 * Removes @contact from @book.
1264 * Returns: %TRUE if successful, %FALSE otherwise
1266 * Deprecated: 3.0: Use e_book_remove_contact_async() instead.
1269 e_book_async_remove_contact (EBook *book,
1276 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1277 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
1279 data = g_slice_new0 (AsyncData);
1280 data->book = g_object_ref (book);
1281 data->callback = cb;
1282 data->closure = closure;
1284 e_book_client_remove_contact (
1285 E_BOOK_CLIENT (book->priv->client),
1286 contact, NULL, remove_contact_reply, data);
1292 * e_book_remove_contact_async:
1294 * @contact: an #EContact
1295 * @cb: (scope async): a function to call when the operation finishes
1296 * @closure: data to pass to callback function
1298 * Removes @contact from @book.
1300 * Returns: %TRUE if successful, %FALSE otherwise
1304 * Deprecated: 3.2: Use e_book_client_remove_contact() and e_book_client_remove_contact_finish() instead.
1307 e_book_remove_contact_async (EBook *book,
1309 EBookAsyncCallback cb,
1314 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1315 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
1317 data = g_slice_new0 (AsyncData);
1318 data->book = g_object_ref (book);
1319 data->excallback = cb;
1320 data->closure = closure;
1322 e_book_client_remove_contact (
1323 E_BOOK_CLIENT (book->priv->client),
1324 contact, NULL, remove_contact_reply, data);
1330 remove_contact_by_id_reply (GObject *source_object,
1331 GAsyncResult *result,
1334 AsyncData *data = user_data;
1335 EBookCallback cb = data->callback;
1336 EBookAsyncCallback excb = data->excallback;
1337 GError *error = NULL;
1339 e_book_client_remove_contact_by_uid_finish (
1340 E_BOOK_CLIENT (source_object), result, &error);
1342 if (cb != NULL && error == NULL)
1343 cb (data->book, E_BOOK_ERROR_OK, data->closure);
1344 if (cb != NULL && error != NULL)
1345 cb (data->book, error->code, data->closure);
1347 excb (data->book, error, data->closure);
1350 g_error_free (error);
1352 g_object_unref (data->book);
1353 g_slice_free (AsyncData, data);
1357 * e_book_async_remove_contact_by_id:
1359 * @id: a unique ID string specifying the contact
1360 * @cb: (scope async): a function to call when the operation finishes
1361 * @closure: data to pass to callback function
1363 * Removes the contact with id @id from @book.
1365 * Returns: %TRUE if successful, %FALSE otherwise
1367 * Deprecated: 3.0: Use e_book_remove_contact_by_id_async() instead.
1370 e_book_async_remove_contact_by_id (EBook *book,
1377 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1378 g_return_val_if_fail (id != NULL, FALSE);
1380 data = g_slice_new0 (AsyncData);
1381 data->book = g_object_ref (book);
1382 data->callback = cb;
1383 data->closure = closure;
1385 e_book_client_remove_contact_by_uid (
1386 E_BOOK_CLIENT (book->priv->client),
1387 id, NULL, remove_contact_by_id_reply, data);
1393 * e_book_remove_contact_by_id_async:
1395 * @id: a unique ID string specifying the contact
1396 * @cb: (scope async): a function to call when the operation finishes
1397 * @closure: data to pass to callback function
1399 * Removes the contact with id @id from @book.
1401 * Returns: %TRUE if successful, %FALSE otherwise
1405 * Deprecated: 3.2: Use e_book_client_remove_contact_by_uid() and e_book_client_remove_contact_by_uid_finish() instead.
1408 e_book_remove_contact_by_id_async (EBook *book,
1410 EBookAsyncCallback cb,
1415 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1416 g_return_val_if_fail (id != NULL, FALSE);
1418 data = g_slice_new0 (AsyncData);
1419 data->book = g_object_ref (book);
1420 data->excallback = cb;
1421 data->closure = closure;
1423 e_book_client_remove_contact_by_uid (
1424 E_BOOK_CLIENT (book->priv->client),
1425 id, NULL, remove_contact_by_id_reply, data);
1431 remove_contacts_reply (GObject *source_object,
1432 GAsyncResult *result,
1435 AsyncData *data = user_data;
1436 EBookCallback cb = data->callback;
1437 EBookAsyncCallback excb = data->excallback;
1438 GError *error = NULL;
1440 e_book_client_remove_contacts_finish (
1441 E_BOOK_CLIENT (source_object), result, &error);
1443 if (cb != NULL && error == NULL)
1444 cb (data->book, E_BOOK_ERROR_OK, data->closure);
1445 if (cb != NULL && error != NULL)
1446 cb (data->book, error->code, data->closure);
1448 excb (data->book, error, data->closure);
1451 g_error_free (error);
1453 g_object_unref (data->book);
1454 g_slice_free (AsyncData, data);
1458 * e_book_async_remove_contacts:
1460 * @ids: (element-type utf8): a #GList of const gchar *id's
1461 * @cb: (scope async): a function to call when the operation finishes
1462 * @closure: data to pass to callback function
1464 * Removes the contacts with ids from the list @ids from @book. This is
1465 * always more efficient than calling e_book_remove_contact() if you
1466 * have more than one id to remove, as some backends can implement it
1467 * as a batch request.
1469 * Returns: %TRUE if successful, %FALSE otherwise
1471 * Deprecated: 3.0: Use e_book_remove_contacts_async() instead.
1474 e_book_async_remove_contacts (EBook *book,
1480 GSList *slist = NULL;
1482 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1484 data = g_slice_new0 (AsyncData);
1485 data->book = g_object_ref (book);
1486 data->callback = cb;
1487 data->closure = closure;
1489 /* XXX Never use GSList in a public API. */
1490 while (ids != NULL) {
1491 slist = g_slist_prepend (slist, ids->data);
1492 ids = g_list_next (ids);
1494 slist = g_slist_reverse (slist);
1496 e_book_client_remove_contacts (
1497 E_BOOK_CLIENT (book->priv->client),
1498 slist, NULL, remove_contacts_reply, data);
1500 g_slist_free (slist);
1506 * e_book_remove_contacts_async:
1508 * @ids: (element-type utf8): a #GList of const gchar *id's
1509 * @cb: (scope async): a function to call when the operation finishes
1510 * @closure: data to pass to callback function
1512 * Removes the contacts with ids from the list @ids from @book. This is
1513 * always more efficient than calling e_book_remove_contact() if you
1514 * have more than one id to remove, as some backends can implement it
1515 * as a batch request.
1517 * Returns: %TRUE if successful, %FALSE otherwise
1521 * Deprecated: 3.2: Use e_book_client_remove_contacts() and e_book_client_remove_contacts_finish() instead.
1524 e_book_remove_contacts_async (EBook *book,
1526 EBookAsyncCallback cb,
1530 GSList *slist = NULL;
1532 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1534 data = g_slice_new0 (AsyncData);
1535 data->book = g_object_ref (book);
1536 data->excallback = cb;
1537 data->closure = closure;
1539 /* XXX Never use GSList in a public API. */
1540 while (ids != NULL) {
1541 slist = g_slist_prepend (slist, ids->data);
1542 ids = g_list_next (ids);
1544 slist = g_slist_reverse (slist);
1546 e_book_client_remove_contacts (
1547 E_BOOK_CLIENT (book->priv->client),
1548 slist, NULL, remove_contacts_reply, data);
1550 g_slist_free (slist);
1556 * e_book_get_book_view:
1558 * @query: an #EBookQuery
1559 * @requested_fields: (allow-none) (element-type utf8): a #GList containing the names of fields to
1560 * return, or NULL for all
1561 * @max_results: the maximum number of contacts to show (or 0 for all)
1562 * @book_view: (out): A #EBookView pointer, will be set to the view
1563 * @error: a #GError to set on failure
1565 * Query @book with @query, creating a #EBookView in @book_view with the fields
1566 * specified by @requested_fields and limited at @max_results records. On an
1567 * error, @error is set and %FALSE returned.
1569 * Returns: %TRUE if successful, %FALSE otherwise
1571 * Deprecated: 3.2: Use e_book_client_get_view_sync() instead.
1574 e_book_get_book_view (EBook *book,
1576 GList *requested_fields,
1578 EBookView **book_view,
1581 EBookClientView *client_view = NULL;
1585 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1586 g_return_val_if_fail (query != NULL, FALSE);
1587 g_return_val_if_fail (book_view != NULL, FALSE);
1589 sexp = e_book_query_to_string (query);
1591 success = e_book_client_get_view_sync (
1592 book->priv->client, sexp, &client_view, NULL, error);
1597 g_return_val_if_fail (
1598 (success && (client_view != NULL)) ||
1599 (!success && (client_view == NULL)), FALSE);
1601 if (client_view != NULL) {
1602 *book_view = _e_book_view_new (book, client_view);
1603 g_object_unref (client_view);
1610 get_book_view_reply (GObject *source_object,
1611 GAsyncResult *result,
1614 AsyncData *data = user_data;
1615 EBookBookViewCallback cb = data->callback;
1616 EBookBookViewAsyncCallback excb = data->excallback;
1617 EBookClientView *client_view = NULL;
1618 EBookView *view = NULL;
1619 GError *error = NULL;
1621 e_book_client_get_view_finish (
1622 E_BOOK_CLIENT (source_object),
1623 result, &client_view, &error);
1627 ((client_view != NULL) && (error == NULL)) ||
1628 ((client_view == NULL) && (error != NULL)));
1630 if (client_view != NULL) {
1631 view = _e_book_view_new (data->book, client_view);
1632 g_object_unref (client_view);
1635 if (cb != NULL && error == NULL)
1636 cb (data->book, E_BOOK_ERROR_OK, view, data->closure);
1637 if (cb != NULL && error != NULL)
1638 cb (data->book, error->code, NULL, data->closure);
1640 excb (data->book, error, view, data->closure);
1643 g_error_free (error);
1645 g_object_unref (data->book);
1646 g_slice_free (AsyncData, data);
1650 * e_book_async_get_book_view:
1652 * @query: an #EBookQuery
1653 * @requested_fields: (element-type utf8): a #GList containing the names of fields to return, or NULL for all
1654 * @max_results: the maximum number of contacts to show (or 0 for all)
1655 * @cb: (scope async): a function to call when the operation finishes
1656 * @closure: data to pass to callback function
1658 * Query @book with @query, creating a #EBookView with the fields
1659 * specified by @requested_fields and limited at @max_results records.
1661 * Returns: %FALSE if successful, %TRUE otherwise
1663 * Deprecated: 3.0: Use e_book_get_book_view_async() instead.
1666 e_book_async_get_book_view (EBook *book,
1668 GList *requested_fields,
1670 EBookBookViewCallback cb,
1676 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1677 g_return_val_if_fail (query != NULL, FALSE);
1679 data = g_slice_new0 (AsyncData);
1680 data->book = g_object_ref (book);
1681 data->callback = cb;
1682 data->closure = closure;
1684 sexp = e_book_query_to_string (query);
1686 e_book_client_get_view (
1687 book->priv->client, sexp,
1688 NULL, get_book_view_reply, data);
1696 * e_book_get_book_view_async:
1698 * @query: an #EBookQuery
1699 * @requested_fields: (allow-none) (element-type utf8): a #GList containing the names of fields to
1700 * return, or NULL for all
1701 * @max_results: the maximum number of contacts to show (or 0 for all)
1702 * @cb: (scope async): a function to call when the operation finishes
1703 * @closure: data to pass to callback function
1705 * Query @book with @query, creating a #EBookView with the fields
1706 * specified by @requested_fields and limited at @max_results records.
1708 * Returns: %FALSE if successful, %TRUE otherwise
1712 * Deprecated: 3.2: Use e_book_client_get_view() and e_book_client_get_view_finish() instead.
1715 e_book_get_book_view_async (EBook *book,
1717 GList *requested_fields,
1719 EBookBookViewAsyncCallback cb,
1725 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1726 g_return_val_if_fail (query != NULL, FALSE);
1728 data = g_slice_new0 (AsyncData);
1729 data->book = g_object_ref (book);
1730 data->excallback = cb;
1731 data->closure = closure;
1733 sexp = e_book_query_to_string (query);
1735 e_book_client_get_view (
1736 book->priv->client, sexp,
1737 NULL, get_book_view_reply, data);
1745 * e_book_get_contacts:
1747 * @query: an #EBookQuery
1748 * @contacts: (element-type utf8): a #GList pointer, will be set to the list of contacts
1749 * @error: a #GError to set on failure
1751 * Query @book with @query, setting @contacts to the list of contacts which
1752 * matched. On failed, @error will be set and %FALSE returned.
1754 * Returns: %TRUE on success, %FALSE otherwise
1756 * Deprecated: 3.2: Use e_book_client_get_contacts_sync() instead.
1759 e_book_get_contacts (EBook *book,
1764 GSList *slist = NULL;
1768 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1769 g_return_val_if_fail (query != NULL, FALSE);
1771 if (contacts != NULL)
1774 sexp = e_book_query_to_string (query);
1776 success = e_book_client_get_contacts_sync (
1777 E_BOOK_CLIENT (book->priv->client),
1778 sexp, &slist, NULL, error);
1782 /* XXX Never use GSList in a public API. */
1783 if (success && contacts != NULL) {
1787 for (link = slist; link != NULL; link = g_slist_next (link)) {
1788 EContact *contact = E_CONTACT (link->data);
1789 list = g_list_prepend (list, g_object_ref (contact));
1792 *contacts = g_list_reverse (list);
1795 g_slist_free_full (slist, (GDestroyNotify) g_object_unref);
1801 get_contacts_reply (GObject *source_object,
1802 GAsyncResult *result,
1805 AsyncData *data = user_data;
1806 EBookListAsyncCallback excb = data->excallback;
1807 EBookListCallback cb = data->callback;
1808 GSList *slist = NULL;
1810 GError *error = NULL;
1812 e_book_client_get_contacts_finish (
1813 E_BOOK_CLIENT (source_object), result, &slist, &error);
1815 /* XXX Never use GSList in a public API. */
1816 if (error == NULL) {
1819 for (link = slist; link != NULL; link = g_slist_next (link)) {
1820 EContact *contact = E_CONTACT (link->data);
1821 list = g_list_prepend (list, g_object_ref (contact));
1824 list = g_list_reverse (list);
1827 if (cb != NULL && error == NULL)
1828 cb (data->book, E_BOOK_ERROR_OK, list, data->closure);
1829 if (cb != NULL && error != NULL)
1830 cb (data->book, error->code, list, data->closure);
1832 excb (data->book, error, list, data->closure);
1834 g_list_free_full (list, (GDestroyNotify) g_object_unref);
1835 g_slist_free_full (slist, (GDestroyNotify) g_object_unref);
1838 g_error_free (error);
1840 g_object_unref (data->book);
1841 g_slice_free (AsyncData, data);
1845 * e_book_async_get_contacts:
1847 * @query: an #EBookQuery
1848 * @cb: (scope async): a function to call when the operation finishes
1849 * @closure: data to pass to callback function
1851 * Query @book with @query.
1853 * Returns: %FALSE on success, %TRUE otherwise
1855 * Deprecated: 3.0: Use e_book_get_contacts_async() instead.
1858 e_book_async_get_contacts (EBook *book,
1860 EBookListCallback cb,
1866 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1867 g_return_val_if_fail (query != NULL, FALSE);
1869 data = g_slice_new0 (AsyncData);
1870 data->book = g_object_ref (book);
1871 data->callback = cb;
1872 data->closure = closure;
1874 sexp = e_book_query_to_string (query);
1876 e_book_client_get_contacts (
1877 E_BOOK_CLIENT (book->priv->client),
1878 sexp, NULL, get_contacts_reply, data);
1886 * e_book_get_contacts_async:
1888 * @query: an #EBookQuery
1889 * @cb: (scope async): a function to call when the operation finishes
1890 * @closure: data to pass to callback function
1892 * Query @book with @query.
1894 * Returns: %FALSE on success, %TRUE otherwise
1898 * Deprecated: 3.2: Use e_book_client_get_contacts() and e_book_client_get_contacts_finish() instead.
1901 e_book_get_contacts_async (EBook *book,
1903 EBookListAsyncCallback cb,
1909 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1910 g_return_val_if_fail (query != NULL, FALSE);
1912 data = g_slice_new0 (AsyncData);
1913 data->book = g_object_ref (book);
1914 data->excallback = cb;
1915 data->closure = closure;
1917 sexp = e_book_query_to_string (query);
1919 e_book_client_get_contacts (
1920 E_BOOK_CLIENT (book->priv->client),
1921 sexp, NULL, get_contacts_reply, data);
1929 * e_book_get_changes: (skip)
1931 * @changeid: the change ID
1932 * @changes: (out) (transfer full): return location for a #GList of #EBookChange items
1933 * @error: a #GError to set on failure.
1935 * Get the set of changes since the previous call to e_book_get_changes()
1936 * for a given change ID.
1938 * Returns: %TRUE on success, %FALSE otherwise
1940 * Deprecated: 3.2: This function has been dropped completely.
1943 e_book_get_changes (EBook *book,
1944 const gchar *changeid,
1948 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1951 error, E_BOOK_ERROR,
1952 E_BOOK_ERROR_NOT_SUPPORTED,
1959 * e_book_async_get_changes:
1961 * @changeid: the change ID
1962 * @cb: (scope async): function to call when operation finishes
1963 * @closure: data to pass to callback function
1965 * Get the set of changes since the previous call to
1966 * e_book_async_get_changes() for a given change ID.
1968 * Returns: %TRUE on success, %FALSE otherwise
1970 * Deprecated: 3.0: Use e_book_get_changes_async() instead.
1973 e_book_async_get_changes (EBook *book,
1974 const gchar *changeid,
1975 EBookListCallback cb,
1978 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
1980 cb (book, E_BOOK_ERROR_NOT_SUPPORTED, NULL, closure);
1986 * e_book_get_changes_async:
1988 * @changeid: the change ID
1989 * @cb: (scope async): function to call when operation finishes
1990 * @closure: data to pass to callback function
1992 * Get the set of changes since the previous call to
1993 * e_book_async_get_changes() for a given change ID.
1995 * Returns: %TRUE on success, %FALSE otherwise
1999 * Deprecated: 3.2: This function has been dropped completely.
2002 e_book_get_changes_async (EBook *book,
2003 const gchar *changeid,
2004 EBookListAsyncCallback cb,
2009 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2011 error = g_error_new (
2013 E_BOOK_ERROR_NOT_SUPPORTED,
2016 cb (book, error, NULL, closure);
2018 g_error_free (error);
2024 * e_book_free_change_list:
2025 * @change_list: (element-type EBookChange): a #GList of #EBookChange items
2027 * Free the contents of #change_list, and the list itself.
2029 * Deprecated: 3.2: Related function has been dropped completely.
2032 e_book_free_change_list (GList *change_list)
2035 for (l = change_list; l; l = l->next) {
2036 EBookChange *change = l->data;
2038 g_object_unref (change->contact);
2039 g_slice_free (EBookChange, change);
2042 g_list_free (change_list);
2048 * @error: a #GError to set on failure
2050 * Used to cancel an already running operation on @book. This
2051 * function makes a synchronous CORBA to the backend telling it to
2052 * cancel the operation. If the operation wasn't cancellable (either
2053 * transiently or permanently) or had already comopleted on the server
2054 * side, this function will return E_BOOK_STATUS_COULD_NOT_CANCEL, and
2055 * the operation will continue uncancelled. If the operation could be
2056 * cancelled, this function will return E_BOOK_ERROR_OK, and the
2057 * blocked e_book function corresponding to current operation will
2058 * return with a status of E_BOOK_STATUS_CANCELLED.
2060 * Returns: %TRUE on success, %FALSE otherwise
2062 * Deprecated: 3.2: Use e_client_cancel_all() or e_client_cancel_op() on an #EBookClient object instead.
2065 e_book_cancel (EBook *book,
2068 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2070 e_client_cancel_all (E_CLIENT (book->priv->client));
2076 * e_book_cancel_async_op:
2078 * Similar to above e_book_cancel function, only cancels last, still running,
2079 * asynchronous operation.
2083 * Deprecated: 3.2: Use e_client_cancel_all() or e_client_cancel_op() on an #EBookClient object instead.
2086 e_book_cancel_async_op (EBook *book,
2089 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2091 e_client_cancel_all (E_CLIENT (book->priv->client));
2099 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
2100 * @error: a #GError to set on failure
2102 * Opens the addressbook, making it ready for queries and other operations.
2104 * Returns: %TRUE if the book was successfully opened, %FALSE otherwise.
2106 * Deprecated: 3.2: Use e_client_open_sync() on an #EBookClient object instead.
2109 e_book_open (EBook *book,
2110 gboolean only_if_exists,
2113 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2115 return e_client_open_sync (
2116 E_CLIENT (book->priv->client),
2117 only_if_exists, NULL, error);
2121 open_reply (GObject *source_object,
2122 GAsyncResult *result,
2125 AsyncData *data = user_data;
2126 EBookCallback cb = data->callback;
2127 EBookAsyncCallback excb = data->excallback;
2128 GError *error = NULL;
2130 e_client_open_finish (E_CLIENT (source_object), result, &error);
2132 if (cb != NULL && error == NULL)
2133 cb (data->book, E_BOOK_ERROR_OK, data->closure);
2134 if (cb != NULL && error != NULL)
2135 cb (data->book, error->code, data->closure);
2137 excb (data->book, error, data->closure);
2140 g_error_free (error);
2142 g_object_unref (data->book);
2143 g_slice_free (AsyncData, data);
2147 * e_book_async_open:
2149 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
2150 * @open_response: (scope call) (closure closure): a function to call when the operation finishes
2151 * @closure: data to pass to callback function
2153 * Opens the addressbook, making it ready for queries and other operations.
2154 * This function does not block.
2156 * Returns: %FALSE if successful, %TRUE otherwise.
2158 * Deprecated: 3.0: Use e_book_open_async() instead.
2161 e_book_async_open (EBook *book,
2162 gboolean only_if_exists,
2168 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2170 data = g_slice_new0 (AsyncData);
2171 data->book = g_object_ref (book);
2172 data->callback = cb;
2173 data->closure = closure;
2176 E_CLIENT (book->priv->client),
2177 only_if_exists, NULL, open_reply, data);
2183 * e_book_open_async:
2185 * @only_if_exists: if %TRUE, fail if this book doesn't already exist, otherwise create it first
2186 * @open_response: (scope call): a function to call when the operation finishes
2187 * @closure: data to pass to callback function
2189 * Opens the addressbook, making it ready for queries and other operations.
2190 * This function does not block.
2192 * Returns: %FALSE if successful, %TRUE otherwise.
2196 * Deprecated: 3.2: Use e_client_open() and e_client_open_finish() on an #EBookClient object instead.
2199 e_book_open_async (EBook *book,
2200 gboolean only_if_exists,
2201 EBookAsyncCallback cb,
2206 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2208 data = g_slice_new0 (AsyncData);
2209 data->book = g_object_ref (book);
2210 data->excallback = cb;
2211 data->closure = closure;
2214 E_CLIENT (book->priv->client),
2215 only_if_exists, NULL, open_reply, data);
2223 * @error: a #GError to set on failure
2225 * Removes the backing data for this #EBook. For example, with the file backend this
2226 * deletes the database file. You cannot get it back!
2228 * Returns: %TRUE on success, %FALSE on failure.
2230 * Deprecated: 3.2: Use e_client_remove_sync() on an #EBookClient object instead.
2233 e_book_remove (EBook *book,
2237 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2239 source = e_book_get_source (book);
2241 return e_source_remove_sync (source, NULL, error);
2245 remove_reply (GObject *source_object,
2246 GAsyncResult *result,
2249 AsyncData *data = user_data;
2250 EBookAsyncCallback excb = data->excallback;
2251 EBookCallback cb = data->callback;
2252 GError *error = NULL;
2254 e_source_remove_finish (E_SOURCE (source_object), result, &error);
2256 if (cb != NULL && error == NULL)
2257 cb (data->book, E_BOOK_ERROR_OK, data->closure);
2259 if (cb != NULL && error != NULL)
2260 cb (data->book, error->code, data->closure);
2263 excb (data->book, error, data->closure);
2266 g_error_free (error);
2268 g_object_unref (data->book);
2269 g_slice_free (AsyncData, data);
2273 * e_book_async_remove:
2275 * @cb: (scope async): a function to call when the operation finishes
2276 * @closure: data to pass to callback function
2278 * Remove the backing data for this #EBook. For example, with the file backend this
2279 * deletes the database file. You cannot get it back!
2281 * Returns: %FALSE if successful, %TRUE otherwise.
2283 * Deprecated: 3.0: Use e_book_remove_async() instead.
2286 e_book_async_remove (EBook *book,
2293 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2295 data = g_slice_new0 (AsyncData);
2296 data->book = g_object_ref (book);
2297 data->callback = cb;
2298 data->closure = closure;
2300 source = e_book_get_source (book);
2302 e_source_remove (source, NULL, remove_reply, data);
2308 * e_book_remove_async:
2310 * @cb: (scope async): a function to call when the operation finishes
2311 * @closure: data to pass to callback function
2313 * Remove the backing data for this #EBook. For example, with the file backend this
2314 * deletes the database file. You cannot get it back!
2316 * Returns: %FALSE if successful, %TRUE otherwise.
2320 * Deprecated: 3.2: Use e_client_remove() and e_client_remove_finish() on an #EBookClient object instead.
2323 e_book_remove_async (EBook *book,
2324 EBookAsyncCallback cb,
2330 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2332 data = g_slice_new0 (AsyncData);
2333 data->book = g_object_ref (book);
2334 data->excallback = cb;
2335 data->closure = closure;
2337 source = e_book_get_source (book);
2339 e_source_remove (source, NULL, remove_reply, data);
2345 * e_book_get_source:
2348 * Get the #ESource that this book has loaded.
2350 * Returns: (transfer none): The source.
2352 * Deprecated: 3.2: Use e_client_get_source() on an #EBookClient object instead.
2355 e_book_get_source (EBook *book)
2357 g_return_val_if_fail (E_IS_BOOK (book), NULL);
2359 return book->priv->source;
2363 * e_book_get_static_capabilities:
2365 * @error: an #GError to set on failure
2367 * Get the list of capabilities which the backend for this address book
2368 * supports. This string should not be freed.
2370 * Returns: The capabilities list
2372 * Deprecated: 3.2: Use e_client_get_capabilities() on an #EBookClient object.
2375 e_book_get_static_capabilities (EBook *book,
2378 g_return_val_if_fail (E_IS_BOOK (book), NULL);
2380 if (book->priv->cap == NULL) {
2383 success = e_client_retrieve_capabilities_sync (
2384 E_CLIENT (book->priv->client),
2385 &book->priv->cap, NULL, error);
2388 g_return_val_if_fail (
2389 (success && (book->priv->cap != NULL)) ||
2390 (!success && (book->priv->cap == NULL)), NULL);
2393 return book->priv->cap;
2397 * e_book_check_static_capability:
2399 * @cap: A capability string
2401 * Check to see if the backend for this address book supports the capability
2404 * Returns: %TRUE if the backend supports @cap, %FALSE otherwise.
2406 * Deprecated: 3.2: Use e_client_check_capability() on an #EBookClient object instead.
2409 e_book_check_static_capability (EBook *book,
2414 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2416 caps = e_book_get_static_capabilities (book, NULL);
2418 /* XXX this is an inexact test but it works for our use */
2419 if (caps && strstr (caps, cap))
2429 * Check if this book has been opened.
2431 * Returns: %TRUE if this book has been opened, otherwise %FALSE.
2433 * Deprecated: 3.2: Use e_client_is_opened() on an #EBookClient object instead.
2436 e_book_is_opened (EBook *book)
2438 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2440 return e_client_is_opened (E_CLIENT (book->priv->client));
2444 * e_book_is_writable:
2447 * Check if this book is writable.
2449 * Returns: %TRUE if this book is writable, otherwise %FALSE.
2451 * Deprecated: 3.2: Use e_client_is_readonly() on an #EBookClient object instead.
2454 e_book_is_writable (EBook *book)
2456 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2458 return !e_client_is_readonly (E_CLIENT (book->priv->client));
2465 * Check if this book is connected.
2467 * Returns: %TRUE if this book is connected, otherwise %FALSE.
2469 * Deprecated: 3.2: Use e_client_is_online() on an #EBookClient object instead.
2472 e_book_is_online (EBook *book)
2474 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2476 return e_client_is_online (E_CLIENT (book->priv->client));
2479 #define SELF_UID_PATH_ID "org.gnome.evolution-data-server.addressbook"
2480 #define SELF_UID_KEY "self-contact-uid"
2489 vcard = g_string_new ("BEGIN:VCARD\nVERSION:3.0\n");
2491 s = g_get_user_name ();
2493 g_string_append_printf (vcard, "NICKNAME:%s\n", s);
2495 s = g_get_real_name ();
2496 if (s && strcmp (s, "Unknown") != 0) {
2497 ENameWestern *western;
2499 g_string_append_printf (vcard, "FN:%s\n", s);
2501 western = e_name_western_parse (s);
2502 g_string_append_printf (
2503 vcard, "N:%s;%s;%s;%s;%s\n",
2504 western->last ? western->last : "",
2505 western->first ? western->first : "",
2506 western->middle ? western->middle : "",
2507 western->prefix ? western->prefix : "",
2508 western->suffix ? western->suffix : "");
2509 e_name_western_free (western);
2511 g_string_append (vcard, "END:VCARD");
2513 contact = e_contact_new_from_vcard (vcard->str);
2515 g_string_free (vcard, TRUE);
2522 * @registry: an #ESourceRegistry
2523 * @contact: (out): an #EContact pointer to set
2524 * @book: (out): an #EBook pointer to set
2525 * @error: a #GError to set on failure
2527 * Get the #EContact referring to the user of the address book
2528 * and set it in @contact and @book.
2530 * Returns: %TRUE if successful, otherwise %FALSE.
2532 * Deprecated: 3.2: Use e_book_client_get_self() instead.
2535 e_book_get_self (ESourceRegistry *registry,
2542 GSettings *settings;
2546 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
2548 source = e_source_registry_ref_builtin_address_book (registry);
2549 *book = e_book_new (source, &e);
2550 g_object_unref (source);
2554 g_propagate_error (error, e);
2558 status = e_book_open (*book, FALSE, &e);
2559 if (status == FALSE) {
2560 g_object_unref (*book);
2563 g_propagate_error (error, e);
2567 settings = g_settings_new (SELF_UID_PATH_ID);
2568 uid = g_settings_get_string (settings, SELF_UID_KEY);
2569 g_object_unref (settings);
2574 /* Don't care about errors because we'll create a new card on failure */
2575 got = e_book_get_contact (*book, uid, contact, NULL);
2581 *contact = make_me_card ();
2582 if (!e_book_add_contact (*book, *contact, &e)) {
2583 /* TODO: return NULL or the contact anyway? */
2584 g_object_unref (*book);
2586 g_object_unref (*contact);
2589 g_propagate_error (error, e);
2593 e_book_set_self (*book, *contact, NULL);
2601 * @contact: an #EContact
2602 * @error: a #GError to set on failure
2604 * Specify that @contact residing in @book is the #EContact that
2605 * refers to the user of the address book.
2607 * Returns: %TRUE if successful, %FALSE otherwise.
2609 * Deprecated: 3.2: Use e_book_client_set_self() instead.
2612 e_book_set_self (EBook *book,
2616 GSettings *settings;
2618 g_return_val_if_fail (E_IS_BOOK (book), FALSE);
2619 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
2621 settings = g_settings_new (SELF_UID_PATH_ID);
2622 g_settings_set_string (settings, SELF_UID_KEY, e_contact_get_const (contact, E_CONTACT_UID));
2623 g_object_unref (settings);
2630 * @contact: an #EContact
2632 * Check if @contact is the user of the address book.
2634 * Returns: %TRUE if @contact is the user, %FALSE otherwise.
2636 * Deprecated: 3.2: Use e_book_client_is_self() instead.
2639 e_book_is_self (EContact *contact)
2641 GSettings *settings;
2645 g_return_val_if_fail (E_IS_CONTACT (contact), FALSE);
2647 settings = g_settings_new (SELF_UID_PATH_ID);
2648 uid = g_settings_get_string (settings, SELF_UID_KEY);
2649 g_object_unref (settings);
2651 rv = (uid && !strcmp (uid, e_contact_get_const (contact, E_CONTACT_UID)));
2660 * @source: an #ESource
2661 * @error: return location for a #GError, or %NULL
2663 * Creates a new #EBook corresponding to the given @source. There are
2664 * only two operations that are valid on this book at this point:
2665 * e_book_open(), and e_book_remove().
2667 * Returns: a new but unopened #EBook.
2669 * Deprecated: 3.2: Use e_book_client_new() instead.
2672 e_book_new (ESource *source,
2675 g_return_val_if_fail (E_IS_SOURCE (source), NULL);
2677 return g_initable_new (
2678 E_TYPE_BOOK, NULL, error,
2679 "source", source, NULL);