[Evolution-hackers] Question about creating new addressbooks and contacts.
- From: 黄冠能 <huang guanneng gd-linux com>
- To: evolution-hackers gnome org
- Subject: [Evolution-hackers] Question about creating new addressbooks and contacts.
- Date: Tue, 22 Aug 2006 11:05:47 +0800
Dear all,
I am in trouble with creating new address books and contacts. I want to
import contacts through a programme. I encountered the following problems:
1. The address books I created in the programme couldn't be deleted
sometimes
2. After I reopened Evolution or rebooted the computer, some of the
address books could be deleted again sometimes
3. The contacts I added to my new address book didn't appear, instead,
it appeared in system address book sometimes
The unstable situation make me crazy. Please help! Thank you very much!!!
Cameron Wong
Here is the main codes:
-----------------------------------
if (bonobo_init(&argc, argv) == FALSE) printf("Could not initialize
Bonobo\n");
// create a new addressbook
char *filename = g_build_filename(g_get_home_dir(), target_path, NULL);
char *uri = g_filename_to_uri (filename, NULL, NULL);
EBook *newBook = e_book_new_from_uri(uri, NULL);
g_free (filename);
g_free (uri);
// add one contact
char *vcard =
"BEGIN:VCARD\nVERSION:3.0\nFN:test2\nN:;test2;;;\nX-EVOLUTION-FILE-AS:test2\nEMAIL:test2 gd-linux com\nREV:2006-07-13T08:42:15Z\nEND:VCARD;\n";
EContact *contact = e_contact_new_from_vcard(vcard);
// add contact to newBook
GError *err = NULL;
if (!e_book_add_contact(newBook, contact, &err)) {
printf("e_book_add_contact fail\n");
exit(0);
}
// get address books
ESourceList *sources = NULL;
if (!e_book_get_addressbooks(&sources, &err)) {
printf("e_book_get_addressbooks error\n");
exit(0);
}
// get the local system group
ESourceGroup *group = e_source_list_peek_groups(sources)->data;
// add newBook source to source group
ESource *newBookSource = e_book_get_source(newBook);
if (!newBookSource) {
printf("e_book_get_source fail\n");
exit(0);
}
e_source_set_name(newBookSource, name);
e_source_set_group(newBookSource, group);
if (!e_source_group_add_source(group, newBookSource, -1)) {
printf("e_source_group_add_source newBook fail\n");
exit(0);
}
// commit update to system
if (!e_source_list_sync(sources, NULL)) {
printf("e_source_list_sync fail\n");
exit(0);
}
--------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]