diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-10-02 04:56:04 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-10-02 04:56:04 +0800 |
commit | b2cda1d0c6d44f53f71bad9e256f41188677dfba (patch) | |
tree | 65bd7560e802baf1740482ae48b952dc5c5957fc /plugins/bbdb | |
parent | e52986f4225cbe8496043da74ca250521d244705 (diff) | |
download | gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar.gz gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar.bz2 gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar.lz gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar.xz gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.tar.zst gsoc2013-evolution-b2cda1d0c6d44f53f71bad9e256f41188677dfba.zip |
Merge revisions 36016:36533 from trunk.
svn path=/branches/kill-bonobo/; revision=36534
Diffstat (limited to 'plugins/bbdb')
-rw-r--r-- | plugins/bbdb/ChangeLog | 21 | ||||
-rw-r--r-- | plugins/bbdb/bbdb.c | 156 |
2 files changed, 135 insertions, 42 deletions
diff --git a/plugins/bbdb/ChangeLog b/plugins/bbdb/ChangeLog index 6c110fd1fc..f7b0b27e30 100644 --- a/plugins/bbdb/ChangeLog +++ b/plugins/bbdb/ChangeLog @@ -1,3 +1,24 @@ +2008-10-01 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #553527 + + * bbdb.c: (struct todo_struct), (free_todo_struct), (bbdb_do_in_thread), + (bbdb_do_thread), (bbdb_handle_reply): Do the EBook work in a separate + thread to have better performance on reply with slow address books. + +2008-09-29 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #497928 + + * bbdb.c: (source_changed_cb), (gaim_source_changed_cb): + Set URI to empty string when user deletes previously selected source. + +2008-09-19 Sankar P <psankar@novell.com> + +License Changes + + * bbdb.c: + 2008-09-02 Sankar P <psankar@novell.com> License Changes diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c index f5f09274a1..547a779961 100644 --- a/plugins/bbdb/bbdb.c +++ b/plugins/bbdb/bbdb.c @@ -1,34 +1,23 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. * - * An Evolution EPlugin that automatically populates your addressbook - * as you reply to messages. Inspired by an Emacs contact management - * tool called The Insidious Big Brother Database, a jwz joint. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * Nat Friedman - * 22 October 2004 - * Boston + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * Authors: + * Nat Friedman <nat@novell.com> * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. */ #ifdef HAVE_CONFIG_H @@ -143,33 +132,120 @@ bbdb_timeout (gpointer data) return TRUE; } -/* Code to populate addressbook when you reply to a mail follows */ +typedef struct +{ + char *name; + char *email; +} todo_struct; -void -bbdb_handle_reply (EPlugin *ep, EMEventTargetMessage *target) +static void +free_todo_struct (todo_struct *td) { - const CamelInternetAddress *cia; - EBook *book = NULL; - int i; + if (td) { + g_free (td->name); + g_free (td->email); + g_free (td); + } +} + +static GSList *todo = NULL; +G_LOCK_DEFINE_STATIC (todo); + +static gpointer +bbdb_do_in_thread (gpointer data) +{ + EBook *book; /* Open the addressbook */ book = bbdb_open_addressbook (AUTOMATIC_CONTACTS_ADDRESSBOOK); - if (book == NULL) + if (book == NULL) { + G_LOCK (todo); + + g_slist_foreach (todo, (GFunc)free_todo_struct, NULL); + g_slist_free (todo); + todo = NULL; + + G_UNLOCK (todo); + return NULL; + } + + G_LOCK (todo); + while (todo) { + todo_struct *td = todo->data; + + todo = g_slist_remove (todo, td); + + G_UNLOCK (todo); + + if (td) { + bbdb_do_it (book, td->name, td->email); + free_todo_struct (td); + } + + G_LOCK (todo); + } + G_UNLOCK (todo); + + g_object_unref (book); + + return NULL; +} + +static void +bbdb_do_thread (const char *name, const char *email) +{ + todo_struct *td; + + if (!name && !email) return; + td = g_new (todo_struct, 1); + td->name = g_strdup (name); + td->email = g_strdup (email); + + G_LOCK (todo); + if (todo) { + /* the list isn't empty, which means there is a thread taking + care of that, thus just add it to the queue */ + todo = g_slist_append (todo, td); + } else { + GError *error = NULL; + + /* list was empty, add item and create a thread */ + todo = g_slist_append (todo, td); + g_thread_create (bbdb_do_in_thread, NULL, 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 (NULL); + G_LOCK (todo); + } + } + G_UNLOCK (todo); +} + +/* Code to populate addressbook when you reply to a mail follows */ +void +bbdb_handle_reply (EPlugin *ep, EMEventTargetMessage *target) +{ + const CamelInternetAddress *cia; + int i; + cia = camel_mime_message_get_from (target->message); if (cia) { for (i = 0; i < camel_address_length (CAMEL_ADDRESS (cia)); i ++) { const char *name=NULL, *email=NULL; if (!(camel_internet_address_get (cia, i, &name, &email))) continue; - bbdb_do_it (book, name, email); + bbdb_do_thread (name, email); } } /* If this is a reply-all event, process To: and Cc: also. */ if (((EEventTarget *) target)->mask & EM_EVENT_MESSAGE_REPLY_ALL) { - g_object_unref (G_OBJECT (book)); return; } @@ -179,7 +255,7 @@ bbdb_handle_reply (EPlugin *ep, EMEventTargetMessage *target) const char *name=NULL, *email=NULL; if (!(camel_internet_address_get (cia, i, &name, &email))) continue; - bbdb_do_it (book, name, email); + bbdb_do_thread (name, email); } } @@ -189,11 +265,9 @@ bbdb_handle_reply (EPlugin *ep, EMEventTargetMessage *target) const char *name=NULL, *email=NULL; if (!(camel_internet_address_get (cia, i, &name, &email))) continue; - bbdb_do_it (book, name, email); + bbdb_do_thread (name, email); } } - - g_object_unref (G_OBJECT (book)); } static void @@ -446,12 +520,11 @@ source_changed_cb (ESourceComboBox *source_combo_box, GError *error = NULL; source = e_source_combo_box_get_active (source_combo_box); - g_return_if_fail (source != NULL); gconf_client_set_string ( stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK, - e_source_get_uri (source), &error); + source ? e_source_get_uri (source) : "", &error); if (error != NULL) { g_warning ("%s", error->message); @@ -467,12 +540,11 @@ gaim_source_changed_cb (ESourceComboBox *source_combo_box, GError *error = NULL; source = e_source_combo_box_get_active (source_combo_box); - g_return_if_fail (source != NULL); gconf_client_set_string ( stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, - e_source_get_uri (source), &error); + source ? e_source_get_uri (source) : "", &error); if (error != NULL) { g_warning ("%s", error->message); |