-#include <libebook/e-book.h>
-#include <libedataserver/e-source-group.h>
+#include <libebook/libebook.h>
#include <glib.h>
#include <locale.h>
int main(int argc, char **argv)
{
EBook *book;
- ESourceList *source_list;
- ESourceGroup *group;
+ ESourceRegistry *eds_source_registry = NULL;
+ GList *sources;
ESource *source;
GSList *groups;
EBookQuery *query;
GList *contacts;
- GSList *sources;
- GSList *g, *s;
+ GList *g, *s;
GList *c;
GError *error = NULL;
GOptionContext *optioncontext;
return 1;
}
- e_book_get_addressbooks(&source_list, &error);
-
+ eds_source_registry = e_source_registry_new_sync (NULL, &error);
if (error != NULL) {
fprintf(stderr, "%s\n", error->message);
return 1;
}
+ sources = e_source_registry_list_sources (eds_source_registry, NULL);
+
if (search_filter != NULL) {
query = e_book_query_any_field_contains(*search_filter);
} else {
query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
}
- groups = e_source_list_peek_groups(source_list);
- for (g = groups; g; g = g->next) {
-
- group = E_SOURCE_GROUP (g->data);
- sources = e_source_group_peek_sources(group);
-
- for (s = sources ; s; s = s->next) {
- source = E_SOURCE(s->data);
- book = e_book_new(source, &error);
-
- if (error != NULL) {
- fprintf(stderr, "%s\n", error->message);
- return 1;
- }
-
- e_book_open(book, TRUE, &error);
+ for (s = sources ; s; s = s->next) {
+ source = E_SOURCE(s->data);
+ book = e_book_new(source, &error);
+ if (error != NULL) {
+ fprintf(stderr, "%s\n", error->message);
+ return 1;
+ }
- if (error != NULL) {
- fprintf(stderr, "%s\n", error->message);
- return 1;
- }
+ e_book_open(book, TRUE, &error);
- e_book_get_contacts(book, query, &contacts, &error);
- if (error != NULL) {
- fprintf(stderr, "%s\n", error->message);
- return 1;
- }
- for (c = contacts; c; c = c->next) {
- dump_as_vcard(E_CONTACT(c->data), 1);
- }
+ if (error != NULL) {
+ fprintf(stderr, "%s\n", error->message);
+ return 1;
+ }
+
+ e_book_get_contacts(book, query, &contacts, &error);
+ if (error != NULL) {
+ fprintf(stderr, "%s\n", error->message);
+ return 1;
+ }
+
+ for (c = contacts; c; c = c->next) {
+ dump_as_vcard(E_CONTACT(c->data), 1);
}
}
- e_book_query_unref (query);
+ e_book_query_unref(query);
+ g_list_free_full(sources, g_object_unref);
+
}
-#include <libebook/e-book.h>
-#include <libedataserver/e-source-group.h>
+#include <libebook/libebook.h>
#include <glib.h>
#include <locale.h>
int main(int argc, char **argv)
{
EBook *book;
- ESourceList *source_list;
- ESourceGroup *group;
+ ESourceRegistry *eds_source_registry = NULL;
+ EBookClient *ebc;
ESource *source;
- GSList *groups;
EBookQuery *query;
GList *contacts;
- GSList *sources;
- GSList *g, *s;
+ GList *sources;
+ GList *g, *s;
GList *c;
GError *error = NULL;
GOptionContext *optioncontext;
exit(1);
}
- e_book_get_addressbooks(&source_list, &error);
-
+ eds_source_registry = e_source_registry_new_sync (NULL, &error);
if (error != NULL) {
fprintf(stderr, "%s\n", error->message);
- exit(1);
+ return 1;
}
if (id == NULL) {
g_object_set(c, "email", el, NULL);
}
}
+ source = e_source_registry_ref_default_address_book(eds_source_registry);
- book = e_book_new_system_addressbook (&error);
+ if (! source) {
+ return 1;
+ }
+
+ ebc = e_book_client_new(source, &error);
if (error != NULL) {
fprintf(stderr, "%s\n", error->message);
return 1;
}
- e_book_open (book, TRUE, &error);
+ e_client_open_sync(E_CLIENT(ebc), TRUE, NULL, &error);
if (error != NULL) {
fprintf(stderr, "%s\n", error->message);
return 1;
}
- e_book_add_contact (book, c, &error);
+ e_book_client_add_contact_sync(ebc, c, NULL, NULL, &error);
if (error != NULL) {
fprintf(stderr, "%s\n", error->message);
return 1;
} else {
char *qu = g_strdup_printf ("(is \"id\" \"%s\")", id);
query = e_book_query_from_string(qu);
-
- groups = e_source_list_peek_groups(source_list);
- for (g = groups; g; g = g->next) {
-
- group = E_SOURCE_GROUP (g->data);
- sources = e_source_group_peek_sources(group);
-
- for (s = sources ; s; s = s->next) {
- source = E_SOURCE(s->data);
- book = e_book_new(source, &error);
- e_book_open(book, TRUE, &error);
- e_book_get_contacts(book, query, &contacts, &error);
-
- for (c = contacts; c; c = c->next) {
- if (full_name)
- g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL);
-
- if (nickname)
- g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL);
-
- if (emails != NULL) {
- gchar **head = emails;
- GList *el = NULL;
-
- if (*head[0] == '\0') {
- printf("removing all emails\n");
- head++;
- } else {
- g_object_get(E_CONTACT(c->data), "email", &el, NULL);
- }
-
- while (*head != NULL) {
- printf("appending %s\n", *head);
- el = g_list_prepend(el, *head);
- head++;
- }
- g_object_set(E_CONTACT(c->data), "email", el, NULL);
+
+ sources = e_source_registry_list_sources (eds_source_registry, NULL);
+
+ for (s = sources ; s; s = s->next) {
+ source = E_SOURCE(s->data);
+ book = e_book_new(source, &error);
+ e_book_open(book, TRUE, &error);
+ e_book_get_contacts(book, query, &contacts, &error);
+
+ for (c = contacts; c; c = c->next) {
+ if (full_name)
+ g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL);
+
+ if (nickname)
+ g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL);
+
+ if (emails != NULL) {
+ gchar **head = emails;
+ GList *el = NULL;
+
+ if (*head[0] == '\0') {
+ printf("removing all emails\n");
+ head++;
+ } else {
+ g_object_get(E_CONTACT(c->data), "email", &el, NULL);
+ }
+
+ while (*head != NULL) {
+ printf("appending %s\n", *head);
+ el = g_list_prepend(el, *head);
+ head++;
}
- e_book_commit_contact(book, E_CONTACT(c->data), &error);
+ g_object_set(E_CONTACT(c->data), "email", el, NULL);
}
+ e_book_commit_contact(book, E_CONTACT(c->data), &error);
}
}
e_book_query_unref (query);