#include const gchar *vcard = "BEGIN:VCARD\n" "VERSION:3.0\n" "CLASS:PUBLIC\n" "REV:2011-03-14T13:47:25Z\n" "FN:First %d Last %d\n" "N:Last %d;First %d;;;\n" "EMAIL;WORK:rhome0 example com%d\n" "TEL;TYPE=cell,voice:02141730585%d\n" "NOTE;ENCODING=QUOTED-PRINTABLE:c1f1b12d-bc75-4d45-9a1f-b1efe934409f\n" "END:VCARD\n"; static EContact * new_test_contact (guint i) { EContact *contact; gchar *str = g_strdup_printf (vcard, i,i,i,i,i,i); contact = e_contact_new_from_vcard (str); g_free (str); return contact; } int main () { EBook *book; GError *error = NULL; guint i, y = 1000, not_replaced = 0; GTimer *timer; GList *all = NULL; GPtrArray *ids; g_type_init (); ids = g_ptr_array_new_with_free_func (g_free); timer = g_timer_new (); book = e_book_new_from_uri ("file:///tmp/test", &error); if (error) { g_critical ("%s\n", error->message); return 0; } e_book_open (book, TRUE, &error); if (error) { g_critical ("%s\n", error->message); return 0; } if (e_book_get_contacts (book, e_book_query_any_field_contains (""), &all, NULL)) { while (all) { g_ptr_array_add (ids, g_strdup (e_contact_get_const (all->data, E_CONTACT_UID))); g_object_unref (all->data); all = all->next; } } g_timer_start (timer); for (i = 0; i < y; i++) { EContact *contact = NULL; gchar *uid, *freeup = NULL; if (i < ids->len) { uid = g_ptr_array_index (ids, i); } else { not_replaced++; freeup = uid = g_strdup_printf ("%d", i); } /* For this example to work we wouldn't have get the * contact. But for sychronization we would need to * get it (else we can't know the old values). */ if (!freeup && e_book_get_contact (book, uid, &contact, NULL)) { e_book_remove_contact (book, uid, &error); if (error) { g_critical ("%s\n", error->message); g_object_unref (contact); g_free (freeup); return 0; } } else { g_print ("%s not found\n", uid); not_replaced++; } g_free (freeup); contact = new_test_contact (i); e_book_add_contact (book, contact, &error); if (error) { g_critical ("%s\n", error->message); g_object_unref (contact); return 0; } e_book_commit_contact (book, contact, &error); if (error) { g_critical ("%s\n", error->message); g_object_unref (contact); return 0; } g_object_unref (contact); } g_timer_stop (timer); g_print ("EDS %d contacts: %f (%d not replaced)\n", y, g_timer_elapsed (timer, NULL), not_replaced); g_ptr_array_unref (ids); g_object_unref (book); }