diff options
author | Devashish Sharma <dsharma@src.gnome.org> | 2006-01-23 21:31:21 +0800 |
---|---|---|
committer | Devashish Sharma <dsharma@src.gnome.org> | 2006-01-23 21:31:21 +0800 |
commit | 855d561e4da5d119a9b59d0721778067b42097d7 (patch) | |
tree | 20fe896c8f70238a7670f45389c5484174fd7e97 /addressbook | |
parent | ee87fbf14f26a6f638f56ed2efcc9a1137585fa5 (diff) | |
download | gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar.gz gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar.bz2 gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar.lz gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar.xz gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.tar.zst gsoc2013-evolution-855d561e4da5d119a9b59d0721778067b42097d7.zip |
Made some changes to evolution csv importer for fixing some bugs.
svn path=/trunk/; revision=31279
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/ChangeLog | 6 | ||||
-rw-r--r-- | addressbook/importers/evolution-csv-importer.c | 113 |
2 files changed, 114 insertions, 5 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index c98cca0670..436be003d5 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,5 +1,11 @@ 2006-01-23 Devashish Sharma <sdevashish@novell.com> + * importers/evolution-csv-importer.c : Made some changes for solving some + bugs in csv and tab file import. Mainly changes made to file parsing + mechanism. + +2006-01-23 Devashish Sharma <sdevashish@novell.com> + * gui/contact-editor/e-contact-quick-add.c : Added source selector to the quick add dialog so that the user can choose the addressbook also while storing the contact. Earlier it automatically went to the diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c index 09627532a4..59ede0fe99 100644 --- a/addressbook/importers/evolution-csv-importer.c +++ b/addressbook/importers/evolution-csv-importer.c @@ -285,6 +285,46 @@ add_to_notes(EContact *contact, gint i, char *val) { g_string_free(new_text, TRUE); } +/* @str: a date string in the format MM-DD-YYYY or MMDDYYYY */ +static EContactDate* +date_from_string (const char *str) +{ + EContactDate* date; + int length; + char *t; + int i = 0; + + g_return_val_if_fail (str != NULL, NULL); + + date = e_contact_date_new(); + /* ignore time part */ + if ((t = strchr (str, 'T')) != NULL) + length = t - str; + else + length = strlen(str); + + if (g_ascii_isdigit (str[i]) && g_ascii_isdigit (str[i+1])) { + date->month = str[i] * 10 + str[i+1] - '0' * 11; + i = i+3; + } + else { + date->month = str[i] - '0' * 1; + i = i+2; + } + + if (g_ascii_isdigit (str[i]) && g_ascii_isdigit (str[i+1])) { + date->day = str[i] * 10 + str[i+1] - '0' * 11; + i = i+3; + } + else { + date->day = str[i] - '0' * 1; + i = i+2; + } + date->year = str[i] * 1000 + str[i+1] * 100 + str[i+2] * 10 + str[i+3] - '0' * 1111; + + return date; +} + static gboolean parseLine (CSVImporter *gci, EContact *contact, char **buf) { @@ -312,6 +352,13 @@ parseLine (CSVImporter *gci, EContact *contact, char **buf) { if(*ptr != '"') { g_string_append_unichar(value, *ptr); } + else { + ptr++; + while (*ptr != '"') { + g_string_append_unichar(value, *ptr); + ptr++; + } + } ptr++; } if(importer == OUTLOOK_IMPORTER) { @@ -398,16 +445,19 @@ parseLine (CSVImporter *gci, EContact *contact, char **buf) { case FLAG_OTHER_ADDRESS|FLAG_POSTAL_CODE: other_address->code = g_strdup(value->str); break; + case FLAG_OTHER_ADDRESS|FLAG_POBOX: + other_address->po = g_strdup(value->str); + break; case FLAG_OTHER_ADDRESS|FLAG_COUNTRY: other_address->country = g_strdup(value->str); break; case FLAG_DATE_BDAY: - e_contact_set(contact, E_CONTACT_BIRTH_DATE, e_contact_date_from_string(value->str)); + e_contact_set(contact, E_CONTACT_BIRTH_DATE, date_from_string(value->str)); break; case FLAG_DATE_ANNIVERSARY: - e_contact_set(contact, E_CONTACT_ANNIVERSARY, e_contact_date_from_string(value->str)); + e_contact_set(contact, E_CONTACT_ANNIVERSARY, date_from_string(value->str)); break; case FLAG_BIRTH_DAY: @@ -465,10 +515,12 @@ parseLine (CSVImporter *gci, EContact *contact, char **buf) { static EContact * getNextCSVEntry(CSVImporter *gci, FILE *f) { EContact *contact = NULL; - char line[2048]; + GString *line; GString *str; char *buf; + char c; + /* if(!fgets(line, sizeof(line),f)) return NULL; @@ -477,15 +529,66 @@ getNextCSVEntry(CSVImporter *gci, FILE *f) { return NULL; gci->count ++; } + */ + + line = g_string_new(""); + while (1) { + c = fgetc (f) ; + if (c == EOF) + return NULL; + if (c == '\n') { + g_string_append_unichar(line, c); + break ; + } + if (c == '"') { + g_string_append_unichar(line, c); + c = fgetc (f); + while (c != '"') { + g_string_append_unichar(line, c); + c = fgetc (f); + } + g_string_append_unichar(line, c); + } + else + g_string_append_unichar(line, c); + } + if(gci->count == 0 && importer != MOZILLA_IMPORTER) { + g_string_free (line, TRUE); + line = g_string_new(""); + while (1) { + c = fgetc (f) ; + if (c == EOF) + return NULL; + if (c == '\n') { + g_string_append_unichar(line, c); + break ; + } + if (c == '"') { + g_string_append_unichar(line, c); + c = fgetc (f); + while (c != '"') { + g_string_append_unichar(line, c); + c = fgetc (f); + } + g_string_append_unichar(line, c); + } + else + g_string_append_unichar(line, c); + } + gci->count ++; + } + str = g_string_new(""); - str = g_string_append (str, line); + str = g_string_append (str, line->str); + + g_string_free (line, TRUE); if(strlen(str->str) == 0) { g_string_free(str, TRUE); return NULL; } - + contact = e_contact_new(); buf = str->str; |