From 6ca92599a2316f55eae5930674718756f34eb772 Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Thu, 20 May 2004 23:47:58 +0000 Subject: Implement. (migrate_contacts_hidden_fields): Implement. 2004-05-20 Hans Petter Jansson * gui/component/addressbook-migrate.c (add_to_notes): Implement. (migrate_contacts_hidden_fields): Implement. (migrate_contacts): Copy fields that are now hidden in the UI, to the notes field. svn path=/trunk/; revision=26024 --- addressbook/gui/component/addressbook-migrate.c | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'addressbook/gui/component') diff --git a/addressbook/gui/component/addressbook-migrate.c b/addressbook/gui/component/addressbook-migrate.c index 7b3bf2b38e..97203e6320 100644 --- a/addressbook/gui/component/addressbook-migrate.c +++ b/addressbook/gui/component/addressbook-migrate.c @@ -210,6 +210,74 @@ get_source_name (ESourceGroup *group, const char *path) return g_string_free (s, FALSE); } +static void +add_to_notes (EContact *contact, EContactField field) +{ + const gchar *old_text; + const gchar *field_text; + gchar *new_text; + + old_text = e_contact_get_const (contact, E_CONTACT_NOTE); + if (old_text && strstr (old_text, e_contact_pretty_name (field))) + return; + + field_text = e_contact_get_const (contact, field); + if (!field_text || !*field_text) + return; + + new_text = g_strdup_printf ("%s%s%s: %s", + old_text ? old_text : "", + old_text && *old_text && + *(old_text + strlen (old_text) - 1) != '\n' ? "\n" : "", + e_contact_pretty_name (field), field_text); + e_contact_set (contact, E_CONTACT_NOTE, new_text); + g_free (new_text); +} + +static void +migrate_contacts_hidden_fields (MigrationContext *context, ESourceGroup *on_this_computer) +{ + EBookQuery *query = e_book_query_any_field_contains (""); + GSList *sources, *s; + + sources = e_source_group_peek_sources (on_this_computer); + for (s = sources; s; s = g_slist_next (s)) { + ESource *source = s->data; + EBook *book; + GList *contacts, *l; + gint num_contacts, num_done; + GError *e = NULL; + + book = e_book_new (source, &e); + if (!book + || !e_book_open (book, FALSE, &e)) { + g_warning ("failed to load book for migration: `%s'", e->message); + continue; + } + + e_book_get_contacts (book, query, &contacts, NULL); + num_contacts = g_list_length (contacts); + num_done = 0; + + for (l = contacts; l; l = g_list_next (l)) { + EContact *contact = l->data; + + add_to_notes (contact, E_CONTACT_OFFICE); + add_to_notes (contact, E_CONTACT_SPOUSE); + add_to_notes (contact, E_CONTACT_BLOG_URL); + + e_book_commit_contact (book, contact, NULL); + + num_done++; + dialog_set_progress (context, (double) num_done / num_contacts); + } + + g_list_foreach (contacts, (GFunc) g_object_unref, NULL); + g_list_free (contacts); + g_object_unref (book); + } +} + static void migrate_contacts (MigrationContext *context, EBook *old_book, EBook *new_book) { @@ -1120,6 +1188,16 @@ addressbook_migrate (AddressbookComponent *component, int major, int minor, int g_free (new_path); g_free (old_path); } + + if (minor < 5 || (minor == 5 && revision <= 10)) { + dialog_set_label (context, + _("Some fields are no longer representable in the " + "contact editor. Please wait while Evolution " + "copies those fields to the 'Notes' field...")); + + if (on_this_computer) + migrate_contacts_hidden_fields (context, on_this_computer); + } } if (need_dialog) -- cgit v1.2.3