aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addressbook/ChangeLog7
-rw-r--r--addressbook/gui/component/addressbook-migrate.c78
2 files changed, 85 insertions, 0 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index d0e4690ce6..9420cce6ff 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,10 @@
+2004-05-20 Hans Petter Jansson <hpj@ximian.com>
+
+ * 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.
+
2004-05-20 Chris Toshok <toshok@ximian.com>
* gui/component/addressbook-component.c (impl_requestCreateItem):
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
@@ -211,6 +211,74 @@ get_source_name (ESourceGroup *group, const char *path)
}
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)
{
EBookQuery *query = e_book_query_any_field_contains ("");
@@ -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)