View File EBookView-Implement-delayed-vcard-parsing.patch for package evolution-data-server (Project eds)
From 4ff6e2cd1d2f2932e4a0c9b1fe026b65ed6ec9e2 Mon Sep 17 00:00:00 2001
From: Christophe Dumez <christophe.dumez@intel.com>
Date: Mon, 30 May 2011 12:54:33 +0300
Subject: [PATCH] EBookView: Implement delayed vcard parsing
The client can now tell the book_view to send unparsed vCards in its
signals. The unparsed vCards are emitted as NULL terminated array
of strings. The receiver is responsible for parsing them.
This optimization avoids uneeded vCard parsing in the case where the
client is not interested in it.
This patch is based on commit 62aad491561fd70ca254f2eafda30fd8d2985434
from eds-fremantle GIT repository.
---
addressbook/libebook/e-book-view.c | 86 +++++++++++++++++++++++++-----------
addressbook/libebook/e-book-view.h | 3 +
2 files changed, 63 insertions(+), 26 deletions(-)
diff --git a/addressbook/libebook/e-book-view.c b/addressbook/libebook/e-book-view.c
index cbf48b4..490b59e 100644
--- a/addressbook/libebook/e-book-view.c
+++ b/addressbook/libebook/e-book-view.c
@@ -37,6 +37,7 @@ struct _EBookViewPrivate {
EGdbusBookView *gdbus_bookview;
EBook *book;
gboolean running;
+ gboolean parse_vcards;
};
enum {
@@ -54,44 +55,40 @@ enum {
static guint signals[LAST_SIGNAL];
static void
-contacts_added_cb (EGdbusBookView *object, const gchar * const *vcards, EBookView *book_view)
+contacts_added_or_changed_cb (EBookView *book_view, guint signal_id, const gchar * const *vcards)
{
- const gchar * const *p;
- GList *contacts = NULL;
-
if (!book_view->priv->running)
return;
- for (p = vcards; *p; p++) {
- contacts = g_list_prepend (contacts, e_contact_new_from_vcard (*p));
- }
+ if (book_view->priv->parse_vcards) {
+ const gchar * const *p;
+ GList *contacts = NULL;
+
+ for (p = vcards; *p; p++) {
+ contacts = g_list_prepend (contacts, e_contact_new_from_vcard (*p));
+ }
- contacts = g_list_reverse (contacts);
+ contacts = g_list_reverse (contacts);
- g_signal_emit (book_view, signals[CONTACTS_ADDED], 0, contacts);
+ g_signal_emit (book_view, signal_id, 0, contacts);
- g_list_foreach (contacts, (GFunc)g_object_unref, NULL);
- g_list_free (contacts);
+ g_list_foreach (contacts, (GFunc)g_object_unref, NULL);
+ g_list_free (contacts);
+ } else {
+ g_signal_emit (book_view, signal_id, 0, vcards);
+ }
}
static void
-contacts_changed_cb (EGdbusBookView *object, const gchar * const *vcards, EBookView *book_view)
+contacts_added_cb (EGdbusBookView *object, const gchar * const *vcards, EBookView *book_view)
{
- const gchar * const *p;
- GList *contacts = NULL;
-
- if (!book_view->priv->running)
- return;
-
- for (p = vcards; *p; p++) {
- contacts = g_list_prepend (contacts, e_contact_new_from_vcard (*p));
- }
- contacts = g_list_reverse (contacts);
-
- g_signal_emit (book_view, signals[CONTACTS_CHANGED], 0, contacts);
+ contacts_added_or_changed_cb (book_view, signals[CONTACTS_ADDED], vcards);
+}
- g_list_foreach (contacts, (GFunc)g_object_unref, NULL);
- g_list_free (contacts);
+static void
+contacts_changed_cb (EGdbusBookView *object, const gchar * const *vcards, EBookView *book_view)
+{
+ contacts_added_or_changed_cb (book_view, signals[CONTACTS_CHANGED], vcards);
}
static void
@@ -266,6 +263,42 @@ e_book_view_stop (EBookView *book_view)
}
}
+/**
+ * e_book_view_set_parse_vcards:
+ * @book_view: an #EBookView
+ * @parse_vcards: whether to parse the vcards into #EContact objects
+ *
+ * Tells the @book_view how to send vCards in its signals. When
+ * @parse_vcards is %FALSE the unparsed vCards are emitted as %NULL terminated
+ * array of strings. The receiver is responsible for parsing them. When
+ * passing %TRUE a #GList of #EContact instances is emitted. This is the
+ * default behavior.
+ **/
+void
+e_book_view_set_parse_vcards (EBookView *book_view, gboolean parse_vcards)
+{
+ g_return_if_fail (E_IS_BOOK_VIEW (book_view));
+ book_view->priv->parse_vcards = parse_vcards;
+}
+
+/**
+ * e_book_view_get_parse_vcards:
+ * @book_view: an #EBookView
+ *
+ * Returns the %TRUE if the @book_view sends a #GList of #EContact instances
+ * in its signals. This is a default behavior. Returns %FALSE if the
+ * @book_view sends unparsed vCards in its signals.
+ *
+ * Returns: a boolean indicating whether the vcards are parsed or not.
+ *
+ **/
+gboolean
+e_book_view_get_parse_vcards (EBookView *book_view)
+{
+ g_return_val_if_fail (E_IS_BOOK_VIEW (book_view), TRUE);
+ return book_view->priv->parse_vcards;
+}
+
static void
e_book_view_init (EBookView *book_view)
{
@@ -274,6 +307,7 @@ e_book_view_init (EBookView *book_view)
priv->gdbus_bookview = NULL;
priv->book = NULL;
priv->running = FALSE;
+ priv->parse_vcards = TRUE;
book_view->priv = priv;
}
diff --git a/addressbook/libebook/e-book-view.h b/addressbook/libebook/e-book-view.h
index 2148f74..f85c7c4 100644
--- a/addressbook/libebook/e-book-view.h
+++ b/addressbook/libebook/e-book-view.h
@@ -66,6 +66,9 @@ void e_book_view_stop (EBookView *book_view);
struct _EBook *e_book_view_get_book (EBookView *book_view);
+void e_book_view_set_parse_vcards (EBookView *book_view, gboolean parse_vcards);
+gboolean e_book_view_get_parse_vcards (EBookView *book_view);
+
G_END_DECLS
#endif /* __E_BOOK_VIEW_H__ */
--
1.7.4.4