diff options
author | Milan Crha <mcrha@redhat.com> | 2009-10-27 18:45:17 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-10-27 18:45:17 +0800 |
commit | d00a56d4cc6f3185004f6babdb1a5f7aad729b5e (patch) | |
tree | cd2bc92c9c6863c80d909814dd1ec5f33a912fc3 /plugins/bbdb | |
parent | 362260797fe0c457ffba8d1c7bb92be469d0460f (diff) | |
download | gsoc2013-evolution-d00a56d4cc6f3185004f6babdb1a5f7aad729b5e.tar.gz gsoc2013-evolution-d00a56d4cc6f3185004f6babdb1a5f7aad729b5e.tar.zst gsoc2013-evolution-d00a56d4cc6f3185004f6babdb1a5f7aad729b5e.zip |
Bug #599199 - Hangs regularly when synchro with pidgin is activated
The sync is done only once on idle after start. The method of checking for
buddy list changes is done by md5 checksum now, as the pidgin start/stop
changed file time, which was the old method of detecting changes. Also not
using getenv("HOME"), but g_get_home_dir() instead.
Diffstat (limited to 'plugins/bbdb')
-rw-r--r-- | plugins/bbdb/bbdb.c | 9 | ||||
-rw-r--r-- | plugins/bbdb/bbdb.h | 5 | ||||
-rw-r--r-- | plugins/bbdb/gaimbuddies.c | 62 |
3 files changed, 41 insertions, 35 deletions
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c index d5104dcf0c..05fff957fd 100644 --- a/plugins/bbdb/bbdb.c +++ b/plugins/bbdb/bbdb.c @@ -112,12 +112,7 @@ e_plugin_lib_enable (EPlugin *ep, gint enable) if (enable) { d(fprintf (stderr, "BBDB spinning up...\n")); - if (bbdb_check_gaim_enabled ()) - bbdb_sync_buddy_list_check (); - - g_timeout_add_seconds (BBDB_BLIST_CHECK_INTERVAL, - (GSourceFunc) bbdb_timeout, - NULL); + g_idle_add (bbdb_timeout, NULL); } return 0; @@ -129,7 +124,7 @@ bbdb_timeout (gpointer data) if (bbdb_check_gaim_enabled ()) bbdb_sync_buddy_list_check (); - return TRUE; + return FALSE; } typedef struct diff --git a/plugins/bbdb/bbdb.h b/plugins/bbdb/bbdb.h index 9b35d85c1e..145da456f9 100644 --- a/plugins/bbdb/bbdb.h +++ b/plugins/bbdb/bbdb.h @@ -26,14 +26,11 @@ #define GCONF_KEY_ENABLE_GAIM "/apps/evolution/autocontacts/auto_sync_gaim" #define GCONF_KEY_WHICH_ADDRESSBOOK "/apps/evolution/autocontacts/addressbook_source" #define GCONF_KEY_WHICH_ADDRESSBOOK_GAIM "/apps/evolution/autocontacts/gaim_addressbook_source" -#define GCONF_KEY_GAIM_LAST_SYNC "/apps/evolution/autocontacts/gaim_last_sync_time" +#define GCONF_KEY_GAIM_LAST_SYNC "/apps/evolution/autocontacts/gaim_last_sync_md5" #define GAIM_ADDRESSBOOK 1 #define AUTOMATIC_CONTACTS_ADDRESSBOOK 0 -/* How often to poll the buddy list for changes (every two minutes) */ -#define BBDB_BLIST_CHECK_INTERVAL (2 * 60) - /* bbdb.c */ EBook *bbdb_open_addressbook (gint type); gboolean bbdb_check_gaim_enabled (void); diff --git a/plugins/bbdb/gaimbuddies.c b/plugins/bbdb/gaimbuddies.c index 292f5d9fc0..8e3117608d 100644 --- a/plugins/bbdb/gaimbuddies.c +++ b/plugins/bbdb/gaimbuddies.c @@ -40,6 +40,7 @@ #include <string.h> #include <libebook/e-book.h> +#include <libedataserver/md5-utils.h> #include <libedataserverui/e-source-combo-box.h> #include <sys/time.h> @@ -65,41 +66,56 @@ static void free_buddy_list (GList *blist); static void parse_buddy_group (xmlNodePtr group, GList **buddies, GSList *blocked); static EContactField proto_to_contact_field (const gchar *proto); +static gchar * +get_buddy_filename (void) +{ + return g_build_path ("/", g_get_home_dir (), ".purple/blist.xml", NULL); +} + +static gchar * +get_md5_as_string (const gchar *filename) +{ + guchar d[16]; + + g_return_val_if_fail (filename != NULL, NULL); + + md5_get_digest_from_file (filename, d); + + return g_strdup_printf ("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x", + d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], + d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); +} + void bbdb_sync_buddy_list_check (void) { GConfClient *gconf; - struct stat statbuf; - time_t last_sync; + gchar *md5; gchar *blist_path; gchar *last_sync_str; - gconf = gconf_client_get_default (); - - blist_path = g_build_path ("/", getenv ("HOME"), ".purple/blist.xml", NULL); - if (stat (blist_path, &statbuf) < 0) { + blist_path = get_buddy_filename (); + if (!g_file_test (blist_path, G_FILE_TEST_EXISTS)) { g_free (blist_path); - g_object_unref (G_OBJECT (gconf)); return; } + md5 = get_md5_as_string (blist_path); g_free (blist_path); /* Reprocess the buddy list if it's been updated. */ + gconf = gconf_client_get_default (); last_sync_str = gconf_client_get_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, NULL); - if (last_sync_str == NULL || ! strcmp ((const gchar *)last_sync_str, "")) - last_sync = (time_t) 0; - else - last_sync = (time_t) g_ascii_strtoull (last_sync_str, NULL, 10); - - g_free (last_sync_str); g_object_unref (G_OBJECT (gconf)); - if (statbuf.st_mtime > last_sync) { + if (!last_sync_str || !*last_sync_str || !g_str_equal (md5, last_sync_str)) { fprintf (stderr, "bbdb: Buddy list has changed since last sync.\n"); bbdb_sync_buddy_list (); } + + g_free (last_sync_str); + g_free (md5); } void @@ -177,17 +193,15 @@ bbdb_sync_buddy_list (void) /* Update the last-sync'd time */ { GConfClient *gconf; - time_t last_sync; - gchar *last_sync_str; + gchar *md5; + gchar *blist_path = get_buddy_filename (); + md5 = get_md5_as_string (blist_path); gconf = gconf_client_get_default (); - - time (&last_sync); - last_sync_str = g_strdup_printf ("%ld", (glong) last_sync); - gconf_client_set_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, last_sync_str, NULL); - g_free (last_sync_str); - + gconf_client_set_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, md5, NULL); g_object_unref (G_OBJECT (gconf)); + g_free (md5); + g_free (blist_path); } printf ("bbdb: Done syncing buddy list to contacts.\n"); } @@ -313,7 +327,7 @@ bbdb_get_gaim_buddy_list (void) GList *buddies = NULL; GSList *blocked = NULL; - blist_path = g_build_path ("/", getenv ("HOME"), ".purple/blist.xml", NULL); + blist_path = get_buddy_filename (); buddy_xml = xmlParseFile (blist_path); g_free (blist_path); @@ -401,7 +415,7 @@ get_buddy_icon_from_setting (xmlNodePtr setting) if (icon [0] != '/') { gchar *path; - path = g_build_path ("/", getenv ("HOME"), ".purple/icons", icon, NULL); + path = g_build_path ("/", g_get_home_dir (), ".purple/icons", icon, NULL); g_free (icon); icon = path; } |