aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:42:27 +0800
commit84339b3be5a771406fcd5898bbd21dc1c5b98c82 (patch)
tree15a9cfd61451b56d6b35541b1b1e966a34b17faf /mail
parentfa4289a2f3c26112c907f283a1fd8ab3fb4f26d6 (diff)
downloadgsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.gz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.bz2
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.lz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.xz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.zst
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'mail')
-rw-r--r--mail/em-utils.c138
-rw-r--r--mail/importers/pine-importer.c49
2 files changed, 101 insertions, 86 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 7d11f5e9bf..db6bd958f9 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -41,7 +41,8 @@
#undef interface
#endif
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
+#include <libebook/e-book-query.h>
#include "em-filter-editor.h"
@@ -1439,35 +1440,30 @@ emu_addr_setup (gpointer user_data)
GError *err = NULL;
ESourceList **psource_list = user_data;
- if (!e_book_get_addressbooks (psource_list, &err))
+ if (!e_book_client_get_sources (psource_list, &err))
g_error_free (err);
return NULL;
}
static void
-emu_addr_cancel_book (gpointer data)
+emu_addr_cancel_stop (gpointer data)
{
- EBook **pbook = data;
- GError *err = NULL;
+ gboolean *stop = data;
- g_return_if_fail (pbook != NULL);
+ g_return_if_fail (stop != NULL);
- if (*pbook) {
- /* we dunna care if this fails, its just the best we can try */
- e_book_cancel (*pbook, &err);
- g_clear_error (&err);
- }
+ *stop = TRUE;
}
static void
-emu_addr_cancel_stop (gpointer data)
+emu_addr_cancel_cancellable (gpointer data)
{
- gboolean *stop = data;
+ GCancellable *cancellable = data;
- g_return_if_fail (stop != NULL);
+ g_return_if_fail (cancellable != NULL);
- *stop = TRUE;
+ g_cancellable_cancel (cancellable);
}
struct TryOpenEBookStruct {
@@ -1477,32 +1473,36 @@ struct TryOpenEBookStruct {
};
static void
-try_open_e_book_cb (EBook *book, const GError *error, gpointer closure)
+try_open_book_client_cb (GObject *source_object, GAsyncResult *result, gpointer closure)
{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
struct TryOpenEBookStruct *data = (struct TryOpenEBookStruct *) closure;
+ GError *error = NULL;
if (!data)
return;
+ e_client_open_finish (E_CLIENT (book_client), result, &error);
+
data->result = error == NULL;
if (!data->result) {
g_clear_error (data->error);
- g_propagate_error (data->error, g_error_copy (error));
+ g_propagate_error (data->error, error);
}
e_flag_set (data->flag);
}
-/**
- * try_open_e_book:
+/*
+ * try_open_book_client:
* Tries to open address book asynchronously, but acts as synchronous.
* The advantage is it checks periodically whether the camel_operation
* has been canceled or not, and if so, then stops immediately, with
- * result FALSE. Otherwise returns same as e_book_open
- **/
+ * result FALSE. Otherwise returns same as e_client_open()
+ */
static gboolean
-try_open_e_book (EBook *book, gboolean only_if_exists, GError **error)
+try_open_book_client (EBookClient *book_client, gboolean only_if_exists, GCancellable *cancellable, GError **error)
{
struct TryOpenEBookStruct data;
gboolean canceled = FALSE;
@@ -1512,15 +1512,7 @@ try_open_e_book (EBook *book, gboolean only_if_exists, GError **error)
data.flag = flag;
data.result = FALSE;
- if (!e_book_open_async (book, only_if_exists, try_open_e_book_cb, &data)) {
- e_flag_free (flag);
- g_clear_error (error);
- g_set_error (
- error, E_BOOK_ERROR,
- E_BOOK_ERROR_OTHER_ERROR,
- "Failed to call e_book_open_async.");
- return FALSE;
- }
+ e_client_open (E_CLIENT (book_client), only_if_exists, cancellable, try_open_book_client_cb, &data);
while (canceled = camel_operation_cancel_check (NULL),
!canceled && !e_flag_is_set (flag)) {
@@ -1533,16 +1525,10 @@ try_open_e_book (EBook *book, gboolean only_if_exists, GError **error)
}
if (canceled) {
+ g_cancellable_cancel (cancellable);
+
g_clear_error (error);
- g_set_error (
- error, E_BOOK_ERROR,
- E_BOOK_ERROR_CANCELLED,
- "Operation has been canceled.");
- /* if the operation is cancelled sucessfully set the flag
- * else wait. file, groupwise,.. backend's operations
- * are not cancellable */
- if (e_book_cancel_async_op (book, NULL))
- e_flag_set (flag);
+ g_propagate_error (error, e_client_error_create (E_CLIENT_ERROR_CANCELLED, NULL));
}
e_flag_wait (flag);
@@ -1578,8 +1564,11 @@ search_address_in_addressbooks (const gchar *address,
gboolean found = FALSE, stop = FALSE, found_any = FALSE;
gchar *lowercase_addr;
gpointer ptr;
- EBookQuery *query;
+ EBookQuery *book_query;
+ gchar *query;
GSList *s, *g, *addr_sources = NULL;
+ GHook *hook_cancellable;
+ GCancellable *cancellable;
if (!address || !*address)
return FALSE;
@@ -1611,7 +1600,9 @@ search_address_in_addressbooks (const gchar *address,
return ptr != NOT_FOUND_BOOK;
}
- query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, address);
+ book_query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, address);
+ query = e_book_query_to_string (book_query);
+ e_book_query_unref (book_query);
for (g = e_source_list_peek_groups (emu_books_source_list);
g; g = g_slist_next (g)) {
@@ -1635,11 +1626,14 @@ search_address_in_addressbooks (const gchar *address,
}
}
+ cancellable = g_cancellable_new ();
+ hook_cancellable = mail_cancel_hook_add (emu_addr_cancel_cancellable, cancellable);
+
for (s = addr_sources; !stop && !found && s; s = g_slist_next (s)) {
ESource *source = s->data;
- GList *contacts;
- EBook *book = NULL;
- GHook *hook_book, *hook_stop;
+ GSList *contacts;
+ EBookClient *book_client = NULL;
+ GHook *hook_stop;
gboolean cached_book = FALSE;
GError *err = NULL;
@@ -1653,17 +1647,14 @@ search_address_in_addressbooks (const gchar *address,
d(printf(" checking '%s'\n", e_source_get_uri(source)));
- hook_book = mail_cancel_hook_add (emu_addr_cancel_book, &book);
hook_stop = mail_cancel_hook_add (emu_addr_cancel_stop, &stop);
- book = g_hash_table_lookup (emu_books_hash, e_source_peek_uid (source));
- if (!book) {
- book = e_book_new (source, &err);
+ book_client = g_hash_table_lookup (emu_books_hash, e_source_peek_uid (source));
+ if (!book_client) {
+ book_client = e_book_client_new (source, &err);
- if (book == NULL) {
- if (err && g_error_matches (
- err, E_BOOK_ERROR,
- E_BOOK_ERROR_CANCELLED)) {
+ if (book_client == NULL) {
+ if (err && g_error_matches (err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
stop = TRUE;
} else if (err) {
gchar *source_uid;
@@ -1682,13 +1673,11 @@ search_address_in_addressbooks (const gchar *address,
err->message);
}
g_clear_error (&err);
- } else if (!stop && !try_open_e_book (book, TRUE, &err)) {
- g_object_unref (book);
- book = NULL;
+ } else if (!stop && !try_open_book_client (book_client, TRUE, cancellable, &err)) {
+ g_object_unref (book_client);
+ book_client = NULL;
- if (err && g_error_matches (
- err, E_BOOK_ERROR,
- E_BOOK_ERROR_CANCELLED)) {
+ if (err && g_error_matches (err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
stop = TRUE;
} else if (err) {
gchar *source_uid;
@@ -1712,18 +1701,15 @@ search_address_in_addressbooks (const gchar *address,
cached_book = TRUE;
}
- if (book && !stop && e_book_get_contacts (book, query, &contacts, &err)) {
+ if (book_client && !stop && e_book_client_get_contacts_sync (book_client, query, &contacts, cancellable, &err)) {
if (contacts != NULL) {
if (!found_any) {
- g_hash_table_insert (
- contact_cache,
- g_strdup (lowercase_addr),
- book);
+ g_hash_table_insert (contact_cache, g_strdup (lowercase_addr), book_client);
}
found_any = TRUE;
if (check_contact) {
- GList *l;
+ GSList *l;
for (l = contacts; l && !found; l = l->next) {
EContact *contact = l->data;
@@ -1734,12 +1720,12 @@ search_address_in_addressbooks (const gchar *address,
found = TRUE;
}
- g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
- g_list_free (contacts);
+ g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
+ g_slist_free (contacts);
}
- } else if (book) {
+ } else if (book_client) {
stop = stop || (err && g_error_matches (
- err, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED));
+ err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED));
if (err && !stop) {
gchar *source_uid = g_strdup (e_source_peek_uid (source));
@@ -1753,24 +1739,26 @@ search_address_in_addressbooks (const gchar *address,
g_clear_error (&err);
}
- mail_cancel_hook_remove (hook_book);
mail_cancel_hook_remove (hook_stop);
stop = stop || camel_operation_cancel_check (NULL);
- if (stop && !cached_book && book) {
- g_object_unref (book);
- } else if (!stop && book && !cached_book) {
+ if (stop && !cached_book && book_client) {
+ g_object_unref (book_client);
+ } else if (!stop && book_client && !cached_book) {
g_hash_table_insert (
emu_books_hash, g_strdup (
- e_source_peek_uid (source)), book);
+ e_source_peek_uid (source)), book_client);
}
}
+ mail_cancel_hook_remove (hook_cancellable);
+ g_object_unref (cancellable);
+
g_slist_foreach (addr_sources, (GFunc) g_object_unref, NULL);
g_slist_free (addr_sources);
- e_book_query_unref (query);
+ g_free (query);
if (!found_any) {
g_hash_table_insert (contact_cache, lowercase_addr, NOT_FOUND_BOOK);
diff --git a/mail/importers/pine-importer.c b/mail/importers/pine-importer.c
index fea9218e2e..c75a78a332 100644
--- a/mail/importers/pine-importer.c
+++ b/mail/importers/pine-importer.c
@@ -38,7 +38,7 @@
#include <gconf/gconf-client.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-destination.h>
#include "mail-importer.h"
@@ -98,7 +98,7 @@ FIXME: we dont handle aliases in lists.
*/
static void
-import_contact (EBook *book, gchar *line)
+import_contact (EBookClient *book_client, gchar *line)
{
gchar **strings, *addr, **addrs;
gint i;
@@ -106,10 +106,13 @@ import_contact (EBook *book, gchar *line)
/*EContactName *name;*/
EContact *card;
gsize len;
+ GError *error = NULL;
card = e_contact_new ();
strings = g_strsplit(line, "\t", 5);
if (strings[0] && strings[1] && strings[2]) {
+ gchar *new_uid = NULL;
+
e_contact_set (card, E_CONTACT_NICKNAME, strings[0]);
e_contact_set (card, E_CONTACT_FULL_NAME, strings[1]);
@@ -150,8 +153,15 @@ import_contact (EBook *book, gchar *line)
if (strings[3] && strings[4])
e_contact_set (card, E_CONTACT_NOTE, strings[4]);
- /* FIXME Error checking */
- e_book_add_contact (book, card, NULL);
+ if (!e_book_client_add_contact_sync (book_client, card, &new_uid, NULL, &error)) {
+ g_debug ("%s: Failed to add contact: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
+ error = NULL;
+ } else {
+ g_free (new_uid);
+ }
+
g_object_unref (card);
}
g_strfreev (strings);
@@ -162,16 +172,22 @@ import_contacts (void)
{
ESource *primary;
ESourceList *source_list;
- EBook *book;
+ EBookClient *book_client;
gchar *name;
GString *line;
FILE *fp;
gsize offset;
+ GError *error = NULL;
printf("importing pine addressbook\n");
- if (!e_book_get_addressbooks (&source_list, NULL))
+ if (!e_book_client_get_sources (&source_list, &error)) {
+ if (error) {
+ g_debug ("%s: Failed to get book sources: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
return;
+ }
name = g_build_filename(g_get_home_dir(), ".addressbook", NULL);
fp = fopen(name, "r");
@@ -181,13 +197,24 @@ import_contacts (void)
primary = e_source_list_peek_source_any (source_list);
/* FIXME Better error handling */
- if ((book = e_book_new (primary,NULL)) == NULL) {
+ if ((book_client = e_book_client_new (primary, &error)) == NULL) {
fclose (fp);
- g_warning ("Could not create EBook.");
+ g_warning ("Could not create EBook: %s", error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
return;
}
- e_book_open (book, TRUE, NULL);
+ if (!e_client_open_sync (E_CLIENT (book_client), TRUE, NULL, &error)) {
+ g_object_unref (primary);
+ g_object_unref (source_list);
+ fclose (fp);
+
+ g_warning ("%s: Failed to open book client: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
+ return;
+ }
g_object_unref (primary);
g_object_unref (source_list);
@@ -208,13 +235,13 @@ import_contacts (void)
g_string_truncate (line, len);
}
- import_contact (book, line->str);
+ import_contact (book_client, line->str);
offset = 0;
}
g_string_free (line, TRUE);
fclose (fp);
- g_object_unref (book);
+ g_object_unref (book_client);
}
static gchar *