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>
27 #include <glib/gi18n-lib.h>
29 #include <libedataserver/libedataserver.h>
30 #include <libedata-book/libedata-book.h>
32 #include "e-book-client.h"
33 #include "e-book-client-view.h"
34 #include "e-gdbus-book-view.h"
36 #define E_BOOK_CLIENT_VIEW_GET_PRIVATE(obj) \
37 (G_TYPE_INSTANCE_GET_PRIVATE \
38 ((obj), E_TYPE_BOOK_CLIENT_VIEW, EBookClientViewPrivate))
40 typedef struct _SignalClosure SignalClosure;
42 struct _EBookClientViewPrivate {
44 GDBusProxy *dbus_proxy;
45 GDBusConnection *connection;
50 EDataBook *direct_book;
52 gulong objects_added_handler_id;
53 gulong objects_modified_handler_id;
54 gulong objects_removed_handler_id;
55 gulong progress_handler_id;
56 gulong complete_handler_id;
59 struct _SignalClosure {
85 /* Forward Declarations */
86 static void e_book_client_view_initable_init
87 (GInitableIface *interface);
89 static guint signals[LAST_SIGNAL];
91 G_DEFINE_TYPE_WITH_CODE (
95 G_IMPLEMENT_INTERFACE (
97 e_book_client_view_initable_init))
100 EBookClientView *view;
105 signal_closure_free (SignalClosure *signal_closure)
107 g_weak_ref_set (&signal_closure->client_view, NULL);
110 signal_closure->object_list,
111 (GDestroyNotify) g_object_unref);
114 signal_closure->string_list,
115 (GDestroyNotify) g_free);
117 g_free (signal_closure->message);
119 if (signal_closure->error != NULL)
120 g_error_free (signal_closure->error);
122 g_slice_free (SignalClosure, signal_closure);
126 book_client_view_emit_objects_added_idle_cb (gpointer user_data)
128 SignalClosure *signal_closure = user_data;
129 EBookClientView *client_view;
131 client_view = g_weak_ref_get (&signal_closure->client_view);
133 if (client_view != NULL) {
136 signals[OBJECTS_ADDED], 0,
137 signal_closure->object_list);
138 g_object_unref (client_view);
145 book_client_view_emit_objects_modified_idle_cb (gpointer user_data)
147 SignalClosure *signal_closure = user_data;
148 EBookClientView *client_view;
150 client_view = g_weak_ref_get (&signal_closure->client_view);
152 if (client_view != NULL) {
155 signals[OBJECTS_MODIFIED], 0,
156 signal_closure->object_list);
157 g_object_unref (client_view);
164 book_client_view_emit_objects_removed_idle_cb (gpointer user_data)
166 SignalClosure *signal_closure = user_data;
167 EBookClientView *client_view;
169 client_view = g_weak_ref_get (&signal_closure->client_view);
171 if (client_view != NULL) {
174 signals[OBJECTS_REMOVED], 0,
175 signal_closure->string_list);
176 g_object_unref (client_view);
183 book_client_view_emit_progress_idle_cb (gpointer user_data)
185 SignalClosure *signal_closure = user_data;
186 EBookClientView *client_view;
188 client_view = g_weak_ref_get (&signal_closure->client_view);
190 if (client_view != NULL) {
193 signals[PROGRESS], 0,
194 signal_closure->percent,
195 signal_closure->message);
196 g_object_unref (client_view);
203 book_client_view_emit_complete_idle_cb (gpointer user_data)
205 SignalClosure *signal_closure = user_data;
206 EBookClientView *client_view;
208 client_view = g_weak_ref_get (&signal_closure->client_view);
210 if (client_view != NULL) {
213 signals[COMPLETE], 0,
214 signal_closure->error);
215 g_object_unref (client_view);
222 book_client_view_emit_objects_added (EBookClientView *client_view,
226 GSource *idle_source;
227 GMainContext *main_context;
228 SignalClosure *signal_closure;
230 client = e_book_client_view_ref_client (client_view);
232 /* Suppress any further signal emissions if
233 * our EBookClient has already been finalized. */
237 signal_closure = g_slice_new0 (SignalClosure);
238 g_weak_ref_set (&signal_closure->client_view, client_view);
239 signal_closure->object_list = object_list; /* takes ownership */
241 main_context = e_client_ref_main_context (E_CLIENT (client));
243 idle_source = g_idle_source_new ();
244 g_source_set_callback (
246 book_client_view_emit_objects_added_idle_cb,
248 (GDestroyNotify) signal_closure_free);
249 g_source_attach (idle_source, main_context);
250 g_source_unref (idle_source);
252 g_main_context_unref (main_context);
254 g_object_unref (client);
258 book_client_view_emit_objects_modified (EBookClientView *client_view,
262 GSource *idle_source;
263 GMainContext *main_context;
264 SignalClosure *signal_closure;
266 client = e_book_client_view_ref_client (client_view);
268 /* Suppress any further signal emissions if
269 * our EBookClient has already been finalized. */
273 signal_closure = g_slice_new0 (SignalClosure);
274 g_weak_ref_set (&signal_closure->client_view, client_view);
275 signal_closure->object_list = object_list; /* takes ownership */
277 main_context = e_client_ref_main_context (E_CLIENT (client));
279 idle_source = g_idle_source_new ();
280 g_source_set_callback (
282 book_client_view_emit_objects_modified_idle_cb,
284 (GDestroyNotify) signal_closure_free);
285 g_source_attach (idle_source, main_context);
286 g_source_unref (idle_source);
288 g_main_context_unref (main_context);
292 direct_contacts_query (const gchar * const *uids)
294 EBookQuery *query, **qs;
298 len = g_strv_length ((gchar **) uids);
299 qs = g_new0 (EBookQuery *, len);
301 for (i = 0; uids[i] != NULL; i++) {
302 const gchar *uid = uids[i];
304 qs[i] = e_book_query_field_test (E_CONTACT_UID, E_BOOK_QUERY_IS, uid);
307 query = e_book_query_or (len, qs, TRUE);
308 sexp = e_book_query_to_string (query);
309 e_book_query_unref (query);
315 direct_contacts_ready (GObject *source_object,
316 GAsyncResult *result,
319 NotificationData *data = (NotificationData *) user_data;
320 GSList *contacts = NULL;
321 GError *error = NULL;
323 e_data_book_get_contacts_finish (
324 E_DATA_BOOK (source_object),
325 result, &contacts, &error);
328 g_warn_if_fail (contacts == NULL);
330 "Error fetching contacts directly: %s\n",
332 g_error_free (error);
334 } else if (data->signum == OBJECTS_ADDED) {
335 /* Takes ownership of the linked list. */
336 book_client_view_emit_objects_added (data->view, contacts);
338 } else if (data->signum == OBJECTS_MODIFIED) {
339 /* Takes ownership of the linked list. */
340 book_client_view_emit_objects_modified (data->view, contacts);
343 g_slist_free_full (contacts, (GDestroyNotify) g_object_unref);
346 g_object_unref (data->view);
347 g_slice_free (NotificationData, data);
351 direct_contacts_fetch (EBookClientView *view,
352 const gchar * const *uids,
355 NotificationData *data;
356 gchar *sexp = direct_contacts_query (uids);
358 /* Until the view has completely loaded, we need to make
359 * sync calls to the backend
361 if (!view->priv->complete) {
362 GSList *contacts = NULL;
363 GError *error = NULL;
365 e_data_book_get_contacts_sync (
366 view->priv->direct_book,
367 sexp, &contacts, NULL, &error);
370 g_warn_if_fail (contacts == NULL);
372 "Error fetching contacts directly: %s\n",
374 g_error_free (error);
376 } else if (signum == OBJECTS_ADDED) {
377 /* Takes ownership of the linked list. */
378 book_client_view_emit_objects_added (view, contacts);
380 } else if (signum == OBJECTS_MODIFIED) {
381 /* Takes ownership of the linked list. */
382 book_client_view_emit_objects_modified (view, contacts);
386 contacts, (GDestroyNotify) g_object_unref);
390 /* Make async calls, avoid blocking the thread owning the view
391 * as much as possible
393 data = g_slice_new (NotificationData);
394 data->view = g_object_ref (view);
395 data->signum = signum;
397 e_data_book_get_contacts (
398 view->priv->direct_book,
399 sexp, NULL, direct_contacts_ready, data);
406 book_client_view_objects_added_cb (EGdbusBookView *object,
407 const gchar * const *vcards,
408 EBookClientView *client_view)
413 if (!client_view->priv->running)
416 /* array contains UIDs only */
417 if (client_view->priv->direct_book != NULL) {
418 direct_contacts_fetch (client_view, vcards, OBJECTS_ADDED);
422 /* array contains both UID and vcard */
423 for (ii = 0; vcards[ii] != NULL && vcards[ii + 1] != NULL; ii += 2) {
425 const gchar *vcard = vcards[ii];
426 const gchar *uid = vcards[ii + 1];
428 contact = e_contact_new_from_vcard_with_uid (vcard, uid);
429 list = g_slist_prepend (list, contact);
432 list = g_slist_reverse (list);
434 /* Takes ownership of the linked list. */
435 book_client_view_emit_objects_added (client_view, list);
439 book_client_view_objects_modified_cb (EGdbusBookView *object,
440 const gchar * const *vcards,
441 EBookClientView *client_view)
446 if (!client_view->priv->running)
449 /* array contains UIDs only */
450 if (client_view->priv->direct_book != NULL) {
451 direct_contacts_fetch (client_view, vcards, OBJECTS_MODIFIED);
455 /* array contains both UID and vcard */
456 for (ii = 0; vcards[ii] != NULL && vcards[ii + 1] != NULL; ii += 2) {
458 const gchar *vcard = vcards[ii];
459 const gchar *uid = vcards[ii + 1];
461 contact = e_contact_new_from_vcard_with_uid (vcard, uid);
462 list = g_slist_prepend (list, contact);
465 list = g_slist_reverse (list);
467 /* Takes ownership of the linked list. */
468 book_client_view_emit_objects_modified (client_view, list);
472 book_client_view_objects_removed_cb (EGdbusBookView *object,
473 const gchar * const *ids,
474 EBookClientView *client_view)
477 GSource *idle_source;
478 GMainContext *main_context;
479 SignalClosure *signal_closure;
483 if (!client_view->priv->running)
486 client = e_book_client_view_ref_client (client_view);
488 /* Suppress any further signal emissions if
489 * our EBookClient has already been finalized. */
493 for (ii = 0; ids[ii] != NULL; ii++)
494 list = g_slist_prepend (list, g_strdup (ids[ii]));
496 signal_closure = g_slice_new0 (SignalClosure);
497 g_weak_ref_set (&signal_closure->client_view, client_view);
498 signal_closure->string_list = g_slist_reverse (list);
500 main_context = e_client_ref_main_context (E_CLIENT (client));
502 idle_source = g_idle_source_new ();
503 g_source_set_callback (
505 book_client_view_emit_objects_removed_idle_cb,
507 (GDestroyNotify) signal_closure_free);
508 g_source_attach (idle_source, main_context);
509 g_source_unref (idle_source);
511 g_main_context_unref (main_context);
513 g_object_unref (client);
517 book_client_view_progress_cb (EGdbusBookView *object,
519 const gchar *message,
520 EBookClientView *client_view)
523 GSource *idle_source;
524 GMainContext *main_context;
525 SignalClosure *signal_closure;
527 if (!client_view->priv->running)
530 client = e_book_client_view_ref_client (client_view);
532 /* Suppress any further signal emissions if
533 * our EBookClient has already been finalized. */
537 signal_closure = g_slice_new0 (SignalClosure);
538 g_weak_ref_set (&signal_closure->client_view, client_view);
539 signal_closure->message = g_strdup (message);
540 signal_closure->percent = percent;
542 main_context = e_client_ref_main_context (E_CLIENT (client));
544 idle_source = g_idle_source_new ();
545 g_source_set_callback (
547 book_client_view_emit_progress_idle_cb,
549 (GDestroyNotify) signal_closure_free);
550 g_source_attach (idle_source, main_context);
551 g_source_unref (idle_source);
553 g_main_context_unref (main_context);
555 g_object_unref (client);
559 book_client_view_complete_cb (EGdbusBookView *object,
560 const gchar * const *in_error_strv,
561 EBookClientView *client_view)
564 GSource *idle_source;
565 GMainContext *main_context;
566 SignalClosure *signal_closure;
568 if (!client_view->priv->running)
571 client = e_book_client_view_ref_client (client_view);
573 /* Suppress any further signal emissions if
574 * our EBookClient has already been finalized. */
578 signal_closure = g_slice_new0 (SignalClosure);
579 g_weak_ref_set (&signal_closure->client_view, client_view);
580 e_gdbus_templates_decode_error (in_error_strv, &signal_closure->error);
582 main_context = e_client_ref_main_context (E_CLIENT (client));
584 idle_source = g_idle_source_new ();
585 g_source_set_callback (
587 book_client_view_emit_complete_idle_cb,
589 (GDestroyNotify) signal_closure_free);
590 g_source_attach (idle_source, main_context);
591 g_source_unref (idle_source);
593 g_main_context_unref (main_context);
595 client_view->priv->complete = TRUE;
597 g_object_unref (client);
601 book_client_view_dispose_cb (GObject *source_object,
602 GAsyncResult *result,
605 GError *error = NULL;
607 e_gdbus_book_view_call_dispose_finish (
608 G_DBUS_PROXY (source_object), result, &error);
611 g_warning ("%s: %s", G_STRFUNC, error->message);
612 g_error_free (error);
617 book_client_view_set_client (EBookClientView *view,
620 g_return_if_fail (E_IS_BOOK_CLIENT (client));
621 g_return_if_fail (view->priv->client == NULL);
623 view->priv->client = g_object_ref (client);
627 book_client_view_set_connection (EBookClientView *view,
628 GDBusConnection *connection)
630 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
631 g_return_if_fail (view->priv->connection == NULL);
633 view->priv->connection = g_object_ref (connection);
637 book_client_view_set_direct_book (EBookClientView *view,
640 g_return_if_fail (book == NULL || E_IS_DATA_BOOK (book));
641 g_return_if_fail (view->priv->direct_book == NULL);
644 view->priv->direct_book = g_object_ref (book);
648 book_client_view_set_object_path (EBookClientView *view,
649 const gchar *object_path)
651 g_return_if_fail (object_path != NULL);
652 g_return_if_fail (view->priv->object_path == NULL);
654 view->priv->object_path = g_strdup (object_path);
658 book_client_view_set_property (GObject *object,
663 switch (property_id) {
665 book_client_view_set_client (
666 E_BOOK_CLIENT_VIEW (object),
667 g_value_get_object (value));
670 case PROP_CONNECTION:
671 book_client_view_set_connection (
672 E_BOOK_CLIENT_VIEW (object),
673 g_value_get_object (value));
676 case PROP_DIRECT_BOOK:
677 book_client_view_set_direct_book (
678 E_BOOK_CLIENT_VIEW (object),
679 g_value_get_object (value));
682 case PROP_OBJECT_PATH:
683 book_client_view_set_object_path (
684 E_BOOK_CLIENT_VIEW (object),
685 g_value_get_string (value));
689 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
693 book_client_view_get_property (GObject *object,
698 switch (property_id) {
700 g_value_take_object (
702 e_book_client_view_ref_client (
703 E_BOOK_CLIENT_VIEW (object)));
706 case PROP_CONNECTION:
709 e_book_client_view_get_connection (
710 E_BOOK_CLIENT_VIEW (object)));
713 case PROP_OBJECT_PATH:
716 e_book_client_view_get_object_path (
717 E_BOOK_CLIENT_VIEW (object)));
721 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
725 book_client_view_dispose (GObject *object)
727 EBookClientViewPrivate *priv;
729 priv = E_BOOK_CLIENT_VIEW_GET_PRIVATE (object);
731 if (priv->client != NULL) {
732 g_object_unref (priv->client);
736 if (priv->connection != NULL) {
737 g_object_unref (priv->connection);
738 priv->connection = NULL;
741 if (priv->direct_book != NULL) {
742 g_object_unref (priv->direct_book);
743 priv->direct_book = NULL;
746 if (priv->dbus_proxy != NULL) {
747 g_signal_handler_disconnect (
749 priv->objects_added_handler_id);
750 g_signal_handler_disconnect (
752 priv->objects_modified_handler_id);
753 g_signal_handler_disconnect (
755 priv->objects_removed_handler_id);
756 g_signal_handler_disconnect (
758 priv->progress_handler_id);
759 g_signal_handler_disconnect (
761 priv->complete_handler_id);
763 /* Call D-Bus dispose() asynchronously
764 * so we don't block this dispose() .*/
765 e_gdbus_book_view_call_dispose (
766 priv->dbus_proxy, NULL,
767 book_client_view_dispose_cb, NULL);
768 g_object_unref (priv->dbus_proxy);
769 priv->dbus_proxy = NULL;
772 /* Chain up to parent's dispose() method. */
773 G_OBJECT_CLASS (e_book_client_view_parent_class)->dispose (object);
777 book_client_view_finalize (GObject *object)
779 EBookClientViewPrivate *priv;
781 priv = E_BOOK_CLIENT_VIEW_GET_PRIVATE (object);
783 g_free (priv->object_path);
785 /* Chain up to parent's finalize() method. */
786 G_OBJECT_CLASS (e_book_client_view_parent_class)->finalize (object);
790 book_client_view_initable_init (GInitable *initable,
791 GCancellable *cancellable,
794 EBookClientViewPrivate *priv;
795 EGdbusBookView *gdbus_bookview;
798 priv = E_BOOK_CLIENT_VIEW_GET_PRIVATE (initable);
800 gdbus_bookview = e_gdbus_book_view_proxy_new_sync (
802 G_DBUS_PROXY_FLAGS_NONE,
803 ADDRESS_BOOK_DBUS_SERVICE_NAME,
807 if (gdbus_bookview == NULL)
810 priv->dbus_proxy = G_DBUS_PROXY (gdbus_bookview);
812 handler_id = g_signal_connect (
813 priv->dbus_proxy, "objects-added",
814 G_CALLBACK (book_client_view_objects_added_cb), initable);
815 priv->objects_added_handler_id = handler_id;
817 handler_id = g_signal_connect (
818 priv->dbus_proxy, "objects-modified",
819 G_CALLBACK (book_client_view_objects_modified_cb), initable);
820 priv->objects_modified_handler_id = handler_id;
822 handler_id = g_signal_connect (
823 priv->dbus_proxy, "objects-removed",
824 G_CALLBACK (book_client_view_objects_removed_cb), initable);
825 priv->objects_removed_handler_id = handler_id;
827 handler_id = g_signal_connect (
828 priv->dbus_proxy, "progress",
829 G_CALLBACK (book_client_view_progress_cb), initable);
830 priv->progress_handler_id = handler_id;
832 handler_id = g_signal_connect (
833 priv->dbus_proxy, "complete",
834 G_CALLBACK (book_client_view_complete_cb), initable);
835 priv->complete_handler_id = handler_id;
837 /* When in direct read access mode, we add a special field
838 * to fields-of-interest indicating we only want uids sent
840 if (priv->direct_book)
841 e_book_client_view_set_fields_of_interest (
842 E_BOOK_CLIENT_VIEW (initable), NULL, NULL);
848 e_book_client_view_class_init (EBookClientViewClass *class)
850 GObjectClass *object_class;
852 g_type_class_add_private (class, sizeof (EBookClientViewPrivate));
854 object_class = G_OBJECT_CLASS (class);
855 object_class->set_property = book_client_view_set_property;
856 object_class->get_property = book_client_view_get_property;
857 object_class->dispose = book_client_view_dispose;
858 object_class->finalize = book_client_view_finalize;
860 g_object_class_install_property (
863 g_param_spec_object (
866 "The EBookClient for the view",
869 G_PARAM_CONSTRUCT_ONLY |
870 G_PARAM_STATIC_STRINGS));
872 g_object_class_install_property (
875 g_param_spec_object (
878 "The GDBusConnection used "
879 "to create the D-Bus proxy",
880 G_TYPE_DBUS_CONNECTION,
882 G_PARAM_CONSTRUCT_ONLY |
883 G_PARAM_STATIC_STRINGS));
885 g_object_class_install_property (
888 g_param_spec_object (
891 "The EDataBook to fetch contact "
892 "data from, if direct read access "
896 G_PARAM_CONSTRUCT_ONLY |
897 G_PARAM_STATIC_STRINGS));
899 g_object_class_install_property (
902 g_param_spec_string (
905 "The object path used "
906 "to create the D-Bus proxy",
909 G_PARAM_CONSTRUCT_ONLY |
910 G_PARAM_STATIC_STRINGS));
912 signals[OBJECTS_ADDED] = g_signal_new (
914 G_OBJECT_CLASS_TYPE (object_class),
916 G_STRUCT_OFFSET (EBookClientViewClass, objects_added),
921 signals[OBJECTS_MODIFIED] = g_signal_new (
923 G_OBJECT_CLASS_TYPE (object_class),
925 G_STRUCT_OFFSET (EBookClientViewClass, objects_modified),
930 signals[OBJECTS_REMOVED] = g_signal_new (
932 G_OBJECT_CLASS_TYPE (object_class),
934 G_STRUCT_OFFSET (EBookClientViewClass, objects_removed),
939 signals[PROGRESS] = g_signal_new (
941 G_OBJECT_CLASS_TYPE (object_class),
943 G_STRUCT_OFFSET (EBookClientViewClass, progress),
949 signals[COMPLETE] = g_signal_new (
951 G_OBJECT_CLASS_TYPE (object_class),
953 G_STRUCT_OFFSET (EBookClientViewClass, complete),
960 e_book_client_view_initable_init (GInitableIface *interface)
962 interface->init = book_client_view_initable_init;
966 e_book_client_view_init (EBookClientView *view)
968 view->priv = E_BOOK_CLIENT_VIEW_GET_PRIVATE (view);
972 * e_book_client_view_ref_client:
973 * @view: an #EBookClientView
975 * Returns the #EBookClientView:client associated with @view.
977 * The returned #EBookClient is referenced for thread-safety. Unreference
978 * the #EBookClient with g_object_unref() when finished with it.
980 * Returns: an #EBookClient
985 e_book_client_view_ref_client (EBookClientView *view)
987 g_return_val_if_fail (E_IS_BOOK_CLIENT_VIEW (view), NULL);
989 return g_object_ref (view->priv->client);
993 * e_book_client_view_get_client:
994 * @view: an #EBookClientView
996 * Returns the #EBookClientView:client associated with @view.
998 * Returns: (transfer none): an #EBookClient
1000 * Deprecated: 3.10: Use e_book_client_view_ref_client() instead.
1003 e_book_client_view_get_client (EBookClientView *view)
1005 g_return_val_if_fail (E_IS_BOOK_CLIENT_VIEW (view), NULL);
1007 return view->priv->client;
1011 * e_book_client_view_get_connection:
1012 * @view: an #EBookClientView
1014 * Returns the #GDBusConnection used to create the D-Bus proxy.
1016 * Returns: (transfer none): the #GDBusConnection
1021 e_book_client_view_get_connection (EBookClientView *view)
1023 g_return_val_if_fail (E_IS_BOOK_CLIENT_VIEW (view), NULL);
1025 return view->priv->connection;
1029 * e_book_client_view_get_object_path:
1030 * @view: an #EBookClientView
1032 * Returns the object path used to create the D-Bus proxy.
1034 * Returns: the object path
1039 e_book_client_view_get_object_path (EBookClientView *view)
1041 g_return_val_if_fail (E_IS_BOOK_CLIENT_VIEW (view), NULL);
1043 return view->priv->object_path;
1047 * e_book_client_view_start:
1048 * @view: an #EBookClientView
1049 * @error: return location for a #GError, or %NULL
1051 * Tells @view to start processing events.
1054 e_book_client_view_start (EBookClientView *view,
1057 EBookClient *client;
1059 GError *local_error = NULL;
1061 g_return_if_fail (E_IS_BOOK_CLIENT_VIEW (view));
1063 client = e_book_client_view_ref_client (view);
1064 g_return_if_fail (client != NULL);
1066 view->priv->running = TRUE;
1068 success = e_gdbus_book_view_call_start_sync (
1069 view->priv->dbus_proxy, NULL, &local_error);
1071 view->priv->running = FALSE;
1073 e_client_unwrap_dbus_error (
1074 E_CLIENT (client), local_error, error);
1076 g_object_unref (client);
1080 * e_book_client_view_stop:
1081 * @view: an #EBookClientView
1082 * @error: return location for a #GError, or %NULL
1084 * Tells @view to stop processing events.
1087 e_book_client_view_stop (EBookClientView *view,
1090 EBookClient *client;
1091 GError *local_error = NULL;
1093 g_return_if_fail (E_IS_BOOK_CLIENT_VIEW (view));
1095 client = e_book_client_view_ref_client (view);
1096 g_return_if_fail (client != NULL);
1098 view->priv->running = FALSE;
1100 e_gdbus_book_view_call_stop_sync (
1101 view->priv->dbus_proxy, NULL, &local_error);
1103 e_client_unwrap_dbus_error (
1104 E_CLIENT (client), local_error, error);
1106 g_object_unref (client);
1110 * e_book_client_view_set_flags:
1111 * @view: an #EBookClientView
1112 * @flags: the #EBookClientViewFlags for @view
1113 * @error: return location for a #GError, or %NULL
1115 * Sets the @flags which control the behaviour of @view.
1120 e_book_client_view_set_flags (EBookClientView *view,
1121 EBookClientViewFlags flags,
1124 EBookClient *client;
1125 GError *local_error = NULL;
1127 g_return_if_fail (E_IS_BOOK_CLIENT_VIEW (view));
1129 client = e_book_client_view_ref_client (view);
1130 g_return_if_fail (client != NULL);
1132 e_gdbus_book_view_call_set_flags_sync (
1133 view->priv->dbus_proxy, flags, NULL, &local_error);
1135 e_client_unwrap_dbus_error (
1136 E_CLIENT (client), local_error, error);
1138 g_object_unref (client);
1142 * e_book_client_view_set_fields_of_interest:
1143 * @view: An #EBookClientView object
1144 * @fields_of_interest: (element-type utf8): List of field names in which
1145 * the client is interested
1146 * @error: return location for a #GError, or %NULL
1148 * Client can instruct server to which fields it is interested in only, thus
1149 * the server can return less data over the wire. The server can still return
1150 * complete objects, this is just a hint to it that the listed fields will
1151 * be used only. The UID field is returned always. Initial views has no fields
1152 * of interest and using %NULL for @fields_of_interest will unset any previous
1155 * Some backends can use summary information of its cache to create artifical
1156 * objects, which will omit stored object parsing. If this cannot be done then
1157 * it will simply return object as is stored in the cache.
1160 e_book_client_view_set_fields_of_interest (EBookClientView *view,
1161 const GSList *fields_of_interest,
1164 EBookClient *client;
1166 GError *local_error = NULL;
1168 g_return_if_fail (E_IS_BOOK_CLIENT_VIEW (view));
1170 client = e_book_client_view_ref_client (view);
1171 g_return_if_fail (client != NULL);
1173 /* When in direct read access mode, ensure that the
1174 * backend is configured to only send us UIDs for everything,
1176 * Just ignore the fields_of_interest and use them locally
1177 * when filtering cards to be returned in direct reads.
1179 if (view->priv->direct_book) {
1180 GSList uid_field = { 0, };
1182 uid_field.data = (gpointer)"x-evolution-uids-only";
1183 strv = e_client_util_slist_to_strv (&uid_field);
1185 strv = e_client_util_slist_to_strv (fields_of_interest);
1187 e_gdbus_book_view_call_set_fields_of_interest_sync (
1188 view->priv->dbus_proxy,
1189 (const gchar * const *) strv,
1190 NULL, &local_error);
1193 e_client_unwrap_dbus_error (
1194 E_CLIENT (client), local_error, error);
1196 g_object_unref (client);