[evolution-ews] EBookBackendSqliteDB: Modify e_*_sqlitedb_search function to return EbSdbSearchData.
- From: Chenthill Palanisamy <pchen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] EBookBackendSqliteDB: Modify e_*_sqlitedb_search function to return EbSdbSearchData.
- Date: Fri, 10 Jun 2011 07:23:17 +0000 (UTC)
commit 0eeff4e0675498164c00e57f1dc7fad09fddd77f
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Thu Jun 9 16:40:24 2011 +0530
EBookBackendSqliteDB: Modify e_*_sqlitedb_search function to return EbSdbSearchData.
Now the backends can just use e_data_book_view_notify_update_prefiltered_vcard without
parsing the vcard string.
src/addressbook/e-book-backend-ews.c | 9 +--
src/addressbook/e-book-backend-sqlitedb-test.c | 6 ++-
src/addressbook/e-book-backend-sqlitedb.c | 59 ++++++++++++++++++++----
src/addressbook/e-book-backend-sqlitedb.h | 8 +++
4 files changed, 66 insertions(+), 16 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 1d9edf6..9bc797c 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -996,13 +996,10 @@ e_book_backend_ews_start_book_view (EBookBackend *backend,
contacts = e_book_backend_sqlitedb_search (priv->ebsdb, priv->folder_id, query, &error);
for (k = contacts; k != NULL; k = g_list_next (k)) {
- gchar *vcard = (gchar *) k->data;
- EContact *contact = e_contact_new_from_vcard (vcard);
- const gchar *id = e_contact_get_const (contact, E_CONTACT_UID);
+ EbSdbSearchData *s_data = (EbSdbSearchData *) k->data;
- e_data_book_view_notify_update_prefiltered_vcard (book_view, id, vcard);
-
- g_object_unref (contact);
+ e_data_book_view_notify_update_prefiltered_vcard (book_view, s_data->uid, s_data->vcard);
+ e_book_backend_sqlitedb_search_data_free (s_data);
}
g_list_free (contacts);
diff --git a/src/addressbook/e-book-backend-sqlitedb-test.c b/src/addressbook/e-book-backend-sqlitedb-test.c
index e145c54..021354b 100644
--- a/src/addressbook/e-book-backend-sqlitedb-test.c
+++ b/src/addressbook/e-book-backend-sqlitedb-test.c
@@ -92,13 +92,17 @@ static void
search_db (EBookBackendSqliteDB *ebsdb, const gchar *type, const gchar *sexp)
{
GList *vcards;
+ EbSdbSearchData *s_data;
g_print ("%s - query: %s \n", type, sexp);
op = type;
vcards = e_book_backend_sqlitedb_search (ebsdb, folderid, sexp, &error);
if (error)
return;
- g_print ("Result: %s \n", (gchar *) vcards->data);
+
+ s_data = vcards->data;
+ g_print ("Result: %s \n", s_data->vcard);
+ e_book_backend_sqlitedb_search_data_free (s_data);
}
static gboolean
diff --git a/src/addressbook/e-book-backend-sqlitedb.c b/src/addressbook/e-book-backend-sqlitedb.c
index dd016b4..daf5cba 100644
--- a/src/addressbook/e-book-backend-sqlitedb.c
+++ b/src/addressbook/e-book-backend-sqlitedb.c
@@ -804,7 +804,13 @@ e_book_backend_sqlitedb_get_vcard_string (EBookBackendSqliteDB *ebsdb,
sqlite3_free (stmt);
if (vcards) {
- vcard_str = vcards->data;
+ EbSdbSearchData *s_data = (EbSdbSearchData *) vcards->data;
+
+ vcard_str = s_data->vcard;
+
+ g_free (s_data->uid);
+ g_free (s_data->bdata);
+ g_free (s_data);
g_slist_free (vcards);
vcards = NULL;
}
@@ -1072,9 +1078,18 @@ static gint
addto_vcard_list_cb (gpointer ref, gint col, gchar **cols, gchar **name)
{
GList **vcards = ref;
+ EbSdbSearchData *s_data = g_new0 (EbSdbSearchData, 1);
if (cols [0])
- *vcards = g_list_prepend (*vcards, g_strdup (cols [0]));
+ s_data->uid = g_strdup (cols [0]);
+
+ if (cols [1])
+ s_data->vcard = g_strdup (cols [1]);
+
+ if (cols [2])
+ s_data->bdata = g_strdup (cols [1]);
+
+ *vcards = g_list_prepend (*vcards, s_data);
return 0;
}
@@ -1094,6 +1109,7 @@ static int
store_data_to_vcard (gpointer ref, gint ncol, gchar **cols, gchar **name)
{
GSList **vcards = ref;
+ EbSdbSearchData *search_data = g_new0 (EbSdbSearchData, 1);
EContact *contact = e_contact_new ();
gchar *vcard;
gint i;
@@ -1104,9 +1120,11 @@ store_data_to_vcard (gpointer ref, gint ncol, gchar **cols, gchar **name)
if (!name[i] || !cols[i])
continue;
- if (!strcmp (name [i], "uid"))
+ if (!strcmp (name [i], "uid")) {
e_contact_set (contact, E_CONTACT_UID, cols [i]);
- else if (!strcmp (name [i], "nickname"))
+
+ search_data->uid = g_strdup (cols [i]);
+ } else if (!strcmp (name [i], "nickname"))
e_contact_set (contact, E_CONTACT_NICKNAME, cols [i]);
else if (!strcmp (name [i], "full_name"))
e_contact_set (contact, E_CONTACT_FULL_NAME, cols [i]);
@@ -1131,12 +1149,17 @@ store_data_to_vcard (gpointer ref, gint ncol, gchar **cols, gchar **name)
} else if (!strcmp (name [i], "wants_html")) {
gint val = cols[i] ? strtoul (cols[i], NULL, 10) : 0;
e_contact_set (contact, E_CONTACT_WANTS_HTML, GINT_TO_POINTER (val));
+ } else if (!strcmp (name [i], "bdata")) {
+ search_data->bdata = g_strdup (cols [i]);
}
+
}
vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
- *vcards = g_slist_prepend (*vcards, vcard);
+ search_data->vcard = vcard;
+ *vcards = g_slist_prepend (*vcards, search_data);
+ g_object_unref (contact);
return 0;
}
@@ -1155,7 +1178,7 @@ book_backend_sqlitedb_search_query (EBookBackendSqliteDB *ebsdb, const gchar *sq
book_backend_sql_exec (ebsdb->priv->db, stmt, store_data_to_vcard, &vcards, &err);
sqlite3_free (stmt);
} else {
- stmt = sqlite3_mprintf ("SELECT vcard FROM %Q WHERE %s", folderid, sql);
+ stmt = sqlite3_mprintf ("SELECT uid vcard bdata FROM %Q WHERE %s", folderid, sql);
book_backend_sql_exec (ebsdb->priv->db, stmt, addto_vcard_list_cb , &vcards, &err);
sqlite3_free (stmt);
}
@@ -1181,7 +1204,7 @@ book_backend_sqlitedb_search_full (EBookBackendSqliteDB *ebsdb, const gchar *sex
READER_LOCK (ebsdb);
- stmt = sqlite3_mprintf ("SELECT vcard FROM %Q", folderid);
+ stmt = sqlite3_mprintf ("SELECT uid vcard bdata FROM %Q", folderid);
book_backend_sql_exec (ebsdb->priv->db, stmt, addto_vcard_list_cb , &all, &err);
sqlite3_free (stmt);
@@ -1193,12 +1216,19 @@ book_backend_sqlitedb_search_full (EBookBackendSqliteDB *ebsdb, const gchar *sex
for (l = all; l != NULL; l = g_list_next (l)) {
if (e_book_backend_sexp_match_vcard (bsexp, l->data))
vcards = g_list_prepend (vcards, g_strdup (l->data));
+ else {
+ EbSdbSearchData *s_data = (EbSdbSearchData *) l->data;
+
+ g_free (s_data->uid);
+ g_free (s_data->bdata);
+ g_free (s_data->vcard);
+ g_free (s_data);
+ }
}
g_object_unref (bsexp);
}
- g_list_foreach (all, (GFunc) g_free, NULL);
g_list_free (all);
return vcards;
@@ -1213,7 +1243,7 @@ book_backend_sqlitedb_search_full (EBookBackendSqliteDB *ebsdb, const gchar *sex
* Search on summary fields is only supported. Search expression containing
* any other field is supported only if backend chooses to store the vcard inside the db.
*
- * Returns:
+ * Returns: List of EbSdbSearchData.
**/
GList *
e_book_backend_sqlitedb_search (EBookBackendSqliteDB *ebsdb,
@@ -1519,3 +1549,14 @@ e_book_backend_sqlitedb_delete_addressbook (EBookBackendSqliteDB *ebsdb,
return !err;
}
+
+void
+e_book_backend_sqlitedb_search_data_free (EbSdbSearchData *s_data)
+{
+ if (s_data) {
+ g_free (s_data->uid);
+ g_free (s_data->vcard);
+ g_free (s_data->bdata);
+ g_free (s_data);
+ }
+}
diff --git a/src/addressbook/e-book-backend-sqlitedb.h b/src/addressbook/e-book-backend-sqlitedb.h
index a48afeb..61d6926 100644
--- a/src/addressbook/e-book-backend-sqlitedb.h
+++ b/src/addressbook/e-book-backend-sqlitedb.h
@@ -62,6 +62,12 @@ struct _EBookBackendSqliteDBClass {
/* virtual methods */
};
+typedef struct {
+ gchar *vcard;
+ gchar *uid;
+ gchar *bdata;
+} EbSdbSearchData;
+
GType e_book_backend_sqlitedb_get_type (void);
EBookBackendSqliteDB *
@@ -156,6 +162,8 @@ gboolean e_book_backend_sqlitedb_delete_addressbook
(EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
GError **error);
+void e_book_backend_sqlitedb_search_data_free
+ (EbSdbSearchData *s_data);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]