aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/bbdb
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
committerMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
commit38790d8478e906a5c59d0c4a5216f297f305bfeb (patch)
tree0f9a96db2765901f2a27b68c84815a491214ecc1 /plugins/bbdb
parent08af0d1f81a4e983bb49d8fb8fe74e670adbb8f6 (diff)
downloadgsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.gz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.zst
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'plugins/bbdb')
-rw-r--r--plugins/bbdb/bbdb.c98
-rw-r--r--plugins/bbdb/bbdb.h11
-rw-r--r--plugins/bbdb/gaimbuddies.c63
3 files changed, 87 insertions, 85 deletions
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c
index bfb63c5505..e0005a967e 100644
--- a/plugins/bbdb/bbdb.c
+++ b/plugins/bbdb/bbdb.c
@@ -28,8 +28,9 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libedataserverui/e-source-combo-box.h>
+#include <libedataserverui/e-client-utils.h>
#include <e-util/e-config.h>
#include <mail/em-config.h>
@@ -58,7 +59,7 @@ struct bbdb_stuff {
/* Static forward declarations */
static gboolean bbdb_timeout (gpointer data);
-static void bbdb_do_it (EBook *book, const gchar *name, const gchar *email);
+static void bbdb_do_it (EBookClient *client, const gchar *name, const gchar *email);
static void add_email_to_contact (EContact *contact, const gchar *email);
static void enable_toggled_cb (GtkWidget *widget, gpointer data);
static void source_changed_cb (ESourceComboBox *source_combo_box, struct bbdb_stuff *stuff);
@@ -191,10 +192,10 @@ G_LOCK_DEFINE_STATIC (todo);
static gpointer
bbdb_do_in_thread (gpointer data)
{
- EBook *book = data;
+ EBookClient *client = data;
/* Open the addressbook */
- if (!book || !bbdb_open_ebook (book)) {
+ if (!client || !bbdb_open_book_client (client)) {
G_LOCK (todo);
g_slist_foreach (todo, (GFunc) free_todo_struct, NULL);
@@ -214,7 +215,7 @@ bbdb_do_in_thread (gpointer data)
G_UNLOCK (todo);
if (td) {
- bbdb_do_it (book, td->name, td->email);
+ bbdb_do_it (client, td->name, td->email);
free_todo_struct (td);
}
@@ -222,7 +223,7 @@ bbdb_do_in_thread (gpointer data)
}
G_UNLOCK (todo);
- g_object_unref (book);
+ g_object_unref (client);
return NULL;
}
@@ -246,18 +247,18 @@ bbdb_do_thread (const gchar *name, const gchar *email)
todo = g_slist_append (todo, td);
} else {
GError *error = NULL;
- EBook *book = bbdb_create_ebook (AUTOMATIC_CONTACTS_ADDRESSBOOK);
+ EBookClient *client = bbdb_create_book_client (AUTOMATIC_CONTACTS_ADDRESSBOOK);
/* list was empty, add item and create a thread */
todo = g_slist_append (todo, td);
- g_thread_create (bbdb_do_in_thread, book, FALSE, &error);
+ g_thread_create (bbdb_do_in_thread, client, FALSE, &error);
if (error) {
g_warning ("%s: Creation of the thread failed with error: %s", G_STRFUNC, error->message);
g_error_free (error);
G_UNLOCK (todo);
- bbdb_do_in_thread (book);
+ bbdb_do_in_thread (client);
G_LOCK (todo);
}
}
@@ -324,16 +325,15 @@ bbdb_handle_send (EPlugin *ep, EMEventTargetComposer *target)
}
static void
-bbdb_do_it (EBook *book, const gchar *name, const gchar *email)
+bbdb_do_it (EBookClient *client, const gchar *name, const gchar *email)
{
- gchar *query_string, *delim, *temp_name = NULL;
- EBookQuery *query;
- GList *contacts = NULL, *l;
+ gchar *query_string, *delim, *temp_name = NULL, *uid;
+ GSList *contacts = NULL;
gboolean status;
EContact *contact;
GError *error = NULL;
- g_return_if_fail (book != NULL);
+ g_return_if_fail (client != NULL);
if (email == NULL || !strcmp (email, ""))
return;
@@ -349,16 +349,10 @@ bbdb_do_it (EBook *book, const gchar *name, const gchar *email)
/* If any contacts exists with this email address, don't do anything */
query_string = g_strdup_printf ("(contains \"email\" \"%s\")", email);
- query = e_book_query_from_string (query_string);
+ status = e_book_client_get_contacts_sync (client, query_string, &contacts, NULL, NULL);
g_free (query_string);
-
- status = e_book_get_contacts (book, query, &contacts, NULL);
- if (query)
- e_book_query_unref (query);
if (contacts != NULL || !status) {
- for (l = contacts; l != NULL; l = l->next)
- g_object_unref ((GObject *) l->data);
- g_list_free (contacts);
+ e_client_util_free_object_slist (contacts);
g_free (temp_name);
return;
@@ -376,39 +370,31 @@ bbdb_do_it (EBook *book, const gchar *name, const gchar *email)
name = temp_name;
}
+ contacts = NULL;
/* If a contact exists with this name, add the email address to it. */
query_string = g_strdup_printf ("(is \"full_name\" \"%s\")", name);
- query = e_book_query_from_string (query_string);
+ status = e_book_client_get_contacts_sync (client, query_string, &contacts, NULL, NULL);
g_free (query_string);
-
- status = e_book_get_contacts (book, query, &contacts, NULL);
- if (query)
- e_book_query_unref (query);
if (contacts != NULL || !status) {
-
/* FIXME: If there's more than one contact with this
name, just give up; we're not smart enough for
this. */
if (!status || contacts->next != NULL) {
- for (l = contacts; l != NULL; l = l->next)
- g_object_unref ((GObject *) l->data);
- g_list_free (contacts);
+ e_client_util_free_object_slist (contacts);
g_free (temp_name);
return;
}
contact = (EContact *) contacts->data;
add_email_to_contact (contact, email);
- if (!e_book_commit_contact (book, contact, &error)) {
+ if (!e_book_client_modify_contact_sync (client, contact, NULL, &error)) {
g_warning ("bbdb: Could not modify contact: %s\n", error->message);
g_error_free (error);
}
- for (l = contacts; l != NULL; l = l->next)
- g_object_unref ((GObject *) l->data);
- g_list_free (contacts);
-
+ e_client_util_free_object_slist (contacts);
g_free (temp_name);
+ g_free (uid);
return;
}
@@ -418,21 +404,22 @@ bbdb_do_it (EBook *book, const gchar *name, const gchar *email)
add_email_to_contact (contact, email);
g_free (temp_name);
- if (!e_book_add_contact (book, contact, &error)) {
- g_warning ("bbdb: Failed to add new contact: %s\n", error->message);
+ uid = NULL;
+ if (!e_book_client_add_contact_sync (client, contact, &uid, NULL, &error)) {
+ g_warning ("bbdb: Failed to add new contact: %s", error->message);
g_error_free (error);
- return;
}
g_object_unref (G_OBJECT (contact));
+ g_free (uid);
}
-EBook *
-bbdb_create_ebook (gint type)
+EBookClient *
+bbdb_create_book_client (gint type)
{
GConfClient *gconf;
gchar *uri;
- EBook *book = NULL;
+ EBookClient *client = NULL;
GError *error = NULL;
gboolean enable = TRUE;
@@ -454,33 +441,36 @@ bbdb_create_ebook (gint type)
g_object_unref (G_OBJECT (gconf));
if (uri == NULL)
- book = e_book_new_system_addressbook (&error);
+ client = e_book_client_new_system (&error);
else {
- book = e_book_new_from_uri (uri, &error);
+ client = e_book_client_new_from_uri (uri, &error);
g_free (uri);
}
- if (book == NULL) {
- g_warning ("bbdb: failed to get addressbook: %s\n", error->message);
- g_error_free (error);
+ if (client == NULL) {
+ g_warning ("bbdb: failed to get addressbook: %s", error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
return NULL;
}
- return book;
+ return client;
}
gboolean
-bbdb_open_ebook (EBook *book)
+bbdb_open_book_client (EBookClient *client)
{
GError *error = NULL;
- if (!book)
+ if (!client)
return FALSE;
- if (!e_book_open (book, FALSE, &error)) {
- g_warning ("bbdb: failed to open addressbook: %s\n", error->message);
- g_error_free (error);
- g_object_unref (book);
+ g_signal_connect (client, "authenticate", G_CALLBACK (e_client_utils_authenticate_handler), NULL);
+ if (!e_client_open_sync (E_CLIENT (client), FALSE, NULL, &error)) {
+ g_warning ("bbdb: failed to open addressbook: %s", error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
+ g_object_unref (client);
return FALSE;
}
diff --git a/plugins/bbdb/bbdb.h b/plugins/bbdb/bbdb.h
index fe7b998274..cbeb4ebb42 100644
--- a/plugins/bbdb/bbdb.h
+++ b/plugins/bbdb/bbdb.h
@@ -37,14 +37,17 @@
#define GAIM_ADDRESSBOOK 1
#define AUTOMATIC_CONTACTS_ADDRESSBOOK 0
+#include <libebook/e-book-client.h>
+#include <libebook/e-contact.h>
+
/* bbdb.c */
-/* creates an EBook for a given type (gaim or contacts), but doesn't open it;
+/* creates an EBookClient for a given type (gaim or contacts), but doesn't open it;
this function should be called in a main thread. */
-EBook *bbdb_create_ebook (gint type);
+EBookClient *bbdb_create_book_client (gint type);
-/* opens an EBook. Returns false if it fails, and unrefs the book too;
+/* opens an EBookClient. Returns false if it fails, and unrefs the book too;
this function can be called in any thread */
-gboolean bbdb_open_ebook (EBook *book);
+gboolean bbdb_open_book_client (EBookClient *client);
gboolean bbdb_check_gaim_enabled (void);
diff --git a/plugins/bbdb/gaimbuddies.c b/plugins/bbdb/gaimbuddies.c
index f6a048e975..1becdee0ac 100644
--- a/plugins/bbdb/gaimbuddies.c
+++ b/plugins/bbdb/gaimbuddies.c
@@ -42,7 +42,8 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
+#include <libebook/e-book-query.h>
#include <libedataserverui/e-source-combo-box.h>
#include <sys/time.h>
@@ -60,7 +61,7 @@ typedef struct {
} GaimBuddy;
/* Forward declarations for this file. */
-static gboolean bbdb_merge_buddy_to_contact (EBook *book, GaimBuddy *b, EContact *c);
+static gboolean bbdb_merge_buddy_to_contact (EBookClient *client, GaimBuddy *b, EContact *c);
static GList *bbdb_get_gaim_buddy_list (void);
static gchar *get_node_text (xmlNodePtr node);
static gchar *get_buddy_icon_from_setting (xmlNodePtr setting);
@@ -189,7 +190,7 @@ G_LOCK_DEFINE_STATIC (syncing);
struct sync_thread_data
{
GList *blist;
- EBook *book;
+ EBookClient *client;
};
static gpointer
@@ -200,8 +201,8 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
g_return_val_if_fail (std != NULL, NULL);
- if (!bbdb_open_ebook (std->book)) {
- /* book got freed in bbdb_open_ebook on a failure */
+ if (!bbdb_open_book_client (std->client)) {
+ /* client got freed in bbdb_open_book_client on a failure */
free_buddy_list (std->blist);
g_free (std);
@@ -217,7 +218,8 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
for (l = std->blist; l != NULL; l = l->next) {
GaimBuddy *b = l->data;
EBookQuery *query;
- GList *contacts = NULL;
+ gchar *query_string, *uid;
+ GSList *contacts = NULL;
GError *error = NULL;
EContact *c;
@@ -227,52 +229,59 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
}
/* Look for an exact match full name == buddy alias */
- query = e_book_query_field_test (
- E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, b->alias);
-
- if (!e_book_get_contacts (std->book, query, &contacts, NULL)) {
- e_book_query_unref (query);
+ query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, b->alias);
+ query_string = e_book_query_to_string (query);
+ e_book_query_unref (query);
+ if (!e_book_client_get_contacts_sync (std->client, query_string, &contacts, NULL, NULL)) {
+ g_free (query_string);
continue;
}
- e_book_query_unref (query);
+ g_free (query_string);
if (contacts != NULL) {
/* FIXME: If there's more than one contact with this
name, just give up; we're not smart enough for
this. */
- if (contacts->next != NULL)
+ if (contacts->next != NULL) {
+ e_client_util_free_object_slist (contacts);
continue;
+ }
c = E_CONTACT (contacts->data);
- if (!bbdb_merge_buddy_to_contact (std->book, b, c))
+ if (!bbdb_merge_buddy_to_contact (std->client, b, c)) {
+ e_client_util_free_object_slist (contacts);
continue;
+ }
/* Write it out to the addressbook */
- if (!e_book_commit_contact (std->book, c, &error)) {
- g_warning ("bbdb: Could not modify contact: %s\n", error->message);
+ if (!e_book_client_modify_contact_sync (std->client, c, NULL, &error)) {
+ g_warning ("bbdb: Could not modify contact: %s", error->message);
g_error_free (error);
}
+ e_client_util_free_object_slist (contacts);
continue;
}
/* Otherwise, create a new contact. */
c = e_contact_new ();
e_contact_set (c, E_CONTACT_FULL_NAME, (gpointer) b->alias);
- if (!bbdb_merge_buddy_to_contact (std->book, b, c)) {
- g_object_unref (G_OBJECT (c));
+ if (!bbdb_merge_buddy_to_contact (std->client, b, c)) {
+ g_object_unref (c);
continue;
}
- if (!e_book_add_contact (std->book, c, &error)) {
- g_warning ("bbdb: Failed to add new contact: %s\n", error->message);
+ uid = NULL;
+ if (!e_book_client_add_contact_sync (std->client, c, &uid, NULL, &error)) {
+ g_warning ("bbdb: Failed to add new contact: %s", error->message);
g_error_free (error);
goto finish;
}
- g_object_unref (G_OBJECT (c));
+ g_object_unref (c);
+ g_free (uid);
}
g_idle_add (store_last_sync_idle_cb, NULL);
@@ -280,7 +289,7 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
finish:
printf ("bbdb: Done syncing buddy list to contacts.\n");
- g_object_unref (std->book);
+ g_object_unref (std->client);
free_buddy_list (std->blist);
g_free (std);
@@ -296,7 +305,7 @@ bbdb_sync_buddy_list (void)
{
GList *blist;
GError *error = NULL;
- EBook *book = NULL;
+ EBookClient *client = NULL;
struct sync_thread_data *std;
G_LOCK (syncing);
@@ -314,8 +323,8 @@ bbdb_sync_buddy_list (void)
}
/* Open the addressbook */
- book = bbdb_create_ebook (GAIM_ADDRESSBOOK);
- if (book == NULL) {
+ client = bbdb_create_book_client (GAIM_ADDRESSBOOK);
+ if (client == NULL) {
free_buddy_list (blist);
G_UNLOCK (syncing);
return;
@@ -323,7 +332,7 @@ bbdb_sync_buddy_list (void)
std = g_new0 (struct sync_thread_data, 1);
std->blist = blist;
- std->book = book;
+ std->client = client;
syncing = TRUE;
@@ -358,7 +367,7 @@ im_list_contains_buddy (GList *ims, GaimBuddy *b)
}
static gboolean
-bbdb_merge_buddy_to_contact (EBook *book, GaimBuddy *b, EContact *c)
+bbdb_merge_buddy_to_contact (EBookClient *client, GaimBuddy *b, EContact *c)
{
EContactField field;
GList *ims;