aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-04-14 01:35:26 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-04-14 04:59:42 +0800
commit26672df4db38e1726b66b1a3c893c9e894e762c0 (patch)
tree92aa9142049ae93d86b4f4b846c0684ed5bd7e5b /plugins
parentadf8a1bbead09a39ec1b15a164d78a9587ac1734 (diff)
downloadgsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar.gz
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar.bz2
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar.lz
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar.xz
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.tar.zst
gsoc2013-evolution-26672df4db38e1726b66b1a3c893c9e894e762c0.zip
Bug 696175 - bbdb: Blocks main thread when obtaining an EBookClient
Diffstat (limited to 'plugins')
-rw-r--r--plugins/bbdb/bbdb.c34
-rw-r--r--plugins/bbdb/bbdb.h4
-rw-r--r--plugins/bbdb/gaimbuddies.c61
3 files changed, 46 insertions, 53 deletions
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c
index 3546a75245..bfb6959047 100644
--- a/plugins/bbdb/bbdb.c
+++ b/plugins/bbdb/bbdb.c
@@ -150,7 +150,11 @@ todo_queue_pop (void)
static gpointer
todo_queue_process_thread (gpointer data)
{
- EBookClient *client = data;
+ EBookClient *client;
+ GError *error = NULL;
+
+ client = bbdb_create_book_client (
+ AUTOMATIC_CONTACTS_ADDRESSBOOK, NULL, &error);
if (client != NULL) {
todo_struct *td;
@@ -161,8 +165,13 @@ todo_queue_process_thread (gpointer data)
}
g_object_unref (client);
+ }
- } else {
+ if (error != NULL) {
+ g_warning (
+ "bbdb: Failed to get addressbook: %s",
+ error->message);
+ g_error_free (error);
todo_queue_clear ();
}
@@ -175,9 +184,6 @@ todo_queue_process (const gchar *name,
{
todo_struct *td;
- if (!name && !email)
- return;
-
td = g_new (todo_struct, 1);
td->name = g_strdup (name);
td->email = g_strdup (email);
@@ -188,12 +194,11 @@ todo_queue_process (const gchar *name,
if (g_queue_get_length (&todo) == 1) {
GThread *thread;
- EBookClient *client;
- client = bbdb_create_book_client (AUTOMATIC_CONTACTS_ADDRESSBOOK);
- thread = g_thread_new (NULL, todo_queue_process_thread, client);
+ thread = g_thread_new (NULL, todo_queue_process_thread, NULL);
g_thread_unref (thread);
}
+
G_UNLOCK (todo);
}
@@ -356,7 +361,9 @@ bbdb_do_it (EBookClient *client,
}
EBookClient *
-bbdb_create_book_client (gint type)
+bbdb_create_book_client (gint type,
+ GCancellable *cancellable,
+ GError **error)
{
EShell *shell;
ESource *source = NULL;
@@ -366,7 +373,6 @@ bbdb_create_book_client (gint type)
GSettings *settings;
gboolean enable = TRUE;
gchar *uid;
- GError *error = NULL;
settings = g_settings_new (CONF_SCHEMA);
@@ -402,13 +408,7 @@ bbdb_create_book_client (gint type)
client = e_client_cache_get_client_sync (
client_cache, source,
E_SOURCE_EXTENSION_ADDRESS_BOOK,
- NULL, &error);
- if (client == NULL) {
- g_warning (
- "bbdb: Failed to get addressbook: %s\n",
- error->message);
- g_error_free (error);
- }
+ cancellable, error);
g_object_unref (source);
diff --git a/plugins/bbdb/bbdb.h b/plugins/bbdb/bbdb.h
index 045f80c615..a5bdfcd70e 100644
--- a/plugins/bbdb/bbdb.h
+++ b/plugins/bbdb/bbdb.h
@@ -40,7 +40,9 @@
#include <libebook/libebook.h>
/* bbdb.c */
-EBookClient * bbdb_create_book_client (gint type);
+EBookClient * bbdb_create_book_client (gint type,
+ GCancellable *cancellable,
+ GError **error);
gboolean bbdb_check_gaim_enabled (void);
/* gaimbuddies.c */
diff --git a/plugins/bbdb/gaimbuddies.c b/plugins/bbdb/gaimbuddies.c
index 7951210996..fe974df502 100644
--- a/plugins/bbdb/gaimbuddies.c
+++ b/plugins/bbdb/gaimbuddies.c
@@ -196,31 +196,36 @@ store_last_sync_idle_cb (gpointer data)
static gboolean syncing = FALSE;
G_LOCK_DEFINE_STATIC (syncing);
-struct sync_thread_data {
- GQueue *buddies;
- EBookClient *client;
-};
-
static gpointer
bbdb_sync_buddy_list_in_thread (gpointer data)
{
- struct sync_thread_data *std = data;
+ EBookClient *client;
+ GQueue *buddies = data;
GList *head, *link;
+ GError *error = NULL;
- g_return_val_if_fail (std != NULL, NULL);
+ g_return_val_if_fail (buddies != NULL, NULL);
+
+ client = bbdb_create_book_client (GAIM_ADDRESSBOOK, NULL, &error);
+ if (error != NULL) {
+ g_warning (
+ "bbdb: Failed to get addressbook: %s",
+ error->message);
+ g_error_free (error);
+ goto exit;
+ }
printf ("bbdb: Synchronizing buddy list to contacts...\n");
/* Walk the buddy list */
- head = g_queue_peek_head_link (std->buddies);
+ head = g_queue_peek_head_link (buddies);
for (link = head; link != NULL; link = g_list_next (link)) {
GaimBuddy *b = link->data;
EBookQuery *query;
gchar *query_string, *uid;
GSList *contacts = NULL;
- GError *error = NULL;
EContact *c;
if (b->alias == NULL || strlen (b->alias) == 0) {
@@ -234,7 +239,7 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
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)) {
+ client, query_string, &contacts, NULL, NULL)) {
g_free (query_string);
continue;
}
@@ -255,7 +260,7 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
c = E_CONTACT (contacts->data);
- if (!bbdb_merge_buddy_to_contact (std->client, b, c)) {
+ if (!bbdb_merge_buddy_to_contact (client, b, c)) {
g_slist_free_full (
contacts,
(GDestroyNotify) g_object_unref);
@@ -263,7 +268,7 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
}
/* Write it out to the addressbook */
- if (!e_book_client_modify_contact_sync (std->client, c, NULL, &error)) {
+ if (!e_book_client_modify_contact_sync (client, c, NULL, &error)) {
g_warning ("bbdb: Could not modify contact: %s", error->message);
g_error_free (error);
}
@@ -277,13 +282,13 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
/* 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->client, b, c)) {
+ if (!bbdb_merge_buddy_to_contact (client, b, c)) {
g_object_unref (c);
continue;
}
uid = NULL;
- if (!e_book_client_add_contact_sync (std->client, c, &uid, NULL, &error)) {
+ if (!e_book_client_add_contact_sync (client, c, &uid, NULL, &error)) {
g_warning ("bbdb: Failed to add new contact: %s", error->message);
g_error_free (error);
goto exit;
@@ -298,9 +303,9 @@ bbdb_sync_buddy_list_in_thread (gpointer data)
exit:
printf ("bbdb: Done syncing buddy list to contacts.\n");
- g_object_unref (std->client);
- g_queue_free_full (std->buddies, (GDestroyNotify) free_gaim_body);
- g_free (std);
+ g_clear_object (&client);
+
+ g_queue_free_full (buddies, (GDestroyNotify) free_gaim_body);
G_LOCK (syncing);
syncing = FALSE;
@@ -328,26 +333,12 @@ bbdb_sync_buddy_list (void)
g_queue_free (buddies);
} else {
GThread *thread;
- EBookClient *client;
-
- /* Open the addressbook */
- client = bbdb_create_book_client (GAIM_ADDRESSBOOK);
- if (client != NULL) {
- struct sync_thread_data *std;
- std = g_new0 (struct sync_thread_data, 1);
- std->buddies = buddies;
- std->client = client;
+ syncing = TRUE;
- syncing = TRUE;
-
- thread = g_thread_new (
- NULL, bbdb_sync_buddy_list_in_thread, std);
- g_thread_unref (thread);
- } else {
- g_queue_free_full (
- buddies, (GDestroyNotify) free_gaim_body);
- }
+ thread = g_thread_new (
+ NULL, bbdb_sync_buddy_list_in_thread, buddies);
+ g_thread_unref (thread);
}
G_UNLOCK (syncing);