static EContact * getNextLDIFEntry (GHashTable *dn_contact_hash, FILE *f) { EContact *contact; EContactAddress *work_address, *home_address; GString *str; gchar line[1024]; gchar *buf; str = g_string_new (""); /* read from the file until we get to a blank line (or eof) */ while (!feof (f)) { if (!fgets (line, sizeof (line), f)) break; if (line[0] == '\n' || (line[0] == '\r' && line[1] == '\n')) break; str = g_string_append (str, line); } if (strlen (str->str) == 0) { g_string_free (str, TRUE); return NULL; } /* now parse that entry */ contact = e_contact_new (); work_address = g_new0 (EContactAddress, 1); home_address = g_new0 (EContactAddress, 1); buf = str->str; while (buf) { if (!parseLine (dn_contact_hash, contact, work_address, home_address, &buf)) { /* parsing error */ g_string_free (str, TRUE); e_contact_address_free (work_address); e_contact_address_free (home_address); g_object_unref (contact); return NULL; } } /* fill in the address */ if (work_address->locality || work_address->country || work_address->ext || work_address->code || work_address->region || work_address->street) { e_contact_set (contact, E_CONTACT_ADDRESS_WORK, work_address); } if (home_address->locality || home_address->country || home_address->ext || home_address->code || home_address->region || home_address->street) { e_contact_set (contact, E_CONTACT_ADDRESS_HOME, home_address); } e_contact_address_free (work_address); e_contact_address_free (home_address); g_string_free (str, TRUE); return contact; }
static gboolean compare_address (EContact *contact, const gchar *str, const gchar *region, CompareFunc compare) { gint i; gboolean rv = FALSE; for (i = E_CONTACT_FIRST_ADDRESS_ID; i <= E_CONTACT_LAST_ADDRESS_ID; i++) { EContactAddress *address = e_contact_get (contact, i); if (address) { rv = (address->po && compare (address->po, str, region)) || (address->street && compare (address->street, str, region)) || (address->ext && compare (address->ext, str, region)) || (address->locality && compare (address->locality, str, region)) || (address->region && compare (address->region, str, region)) || (address->code && compare (address->code, str, region)) || (address->country && compare (address->country, str, region)); e_contact_address_free (address); if (rv) break; } } return rv; }
static void render_address_link (GString *buffer, EContact *contact, gint map_type) { EContactAddress *adr; GString *link = g_string_new (""); adr = e_contact_get (contact, map_type); if (adr && (adr->street || adr->locality || adr->region || adr->country)) { gchar *escaped; if (adr->street && *adr->street) g_string_append_printf (link, "%s", adr->street); if (adr->locality && *adr->locality) { if (link->len) g_string_append (link, ", "); g_string_append_printf (link, "%s", adr->locality); } if (adr->region && *adr->region) { if (link->len) g_string_append (link, ", "); g_string_append_printf (link, "%s", adr->region); } if (adr->country && *adr->country) { if (link->len) g_string_append (link, ", "); g_string_append_printf (link, "%s", adr->country); } escaped = g_uri_escape_string (link->str, NULL, TRUE); g_string_assign (link, escaped); g_free (escaped); g_string_prepend (link, "<a href=\"open-map:"); g_string_append_printf (link, "\">%s</a>", _("Open map")); } if (adr) e_contact_address_free (adr); g_string_append (buffer, link->str); g_string_free (link, TRUE); }
static void accum_address (GString *buffer, EContact *contact, const gchar *html_label, EContactField adr_field, EContactField label_field) { EContactAddress *adr; const gchar *label; GString *map_link = g_string_new ("<br>"); render_address_link (map_link, contact, adr_field); label = e_contact_get_const (contact, label_field); if (label) { gchar *html = e_text_to_html (label, E_TEXT_TO_HTML_CONVERT_NL); if (TEXT_IS_RIGHT_TO_LEFT) { g_string_append_printf ( buffer, "<tr>" "<td align=\"right\" valign=\"top\" nowrap>%s</td>" "<th>%s:<br>%s</th>" "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td>" "</tr>", html, html_label, map_link->str); } else { g_string_append_printf ( buffer, "<tr>" "<td width=\"" IMAGE_COL_WIDTH "\"></td>" "<th>%s:<br>%s</th>" "<td valign=\"top\" nowrap>%s</td>" "</tr>", html_label, map_link->str, html); } g_free (html); g_string_free (map_link, TRUE); return; } adr = e_contact_get (contact, adr_field); if (adr && (adr->po || adr->ext || adr->street || adr->locality || adr->region || adr->code || adr->country)) { if (TEXT_IS_RIGHT_TO_LEFT) { g_string_append_printf ( buffer, "<tr><td align=\"right\" valign=\"top\" nowrap>"); } else { g_string_append_printf ( buffer, "<tr>" "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td>" "<th>%s:<br>%s</th>" "<td valign=\"top\" nowrap>", html_label, map_link->str); } if (adr->po && *adr->po) g_string_append_printf (buffer, "%s<br>", adr->po); if (adr->ext && *adr->ext) g_string_append_printf (buffer, "%s<br>", adr->ext); if (adr->street && *adr->street) g_string_append_printf (buffer, "%s<br>", adr->street); if (adr->locality && *adr->locality) g_string_append_printf (buffer, "%s<br>", adr->locality); if (adr->region && *adr->region) g_string_append_printf (buffer, "%s<br>", adr->region); if (adr->code && *adr->code) g_string_append_printf (buffer, "%s<br>", adr->code); if (adr->country && *adr->country) g_string_append_printf (buffer, "%s<br>", adr->country); if (TEXT_IS_RIGHT_TO_LEFT) { g_string_append_printf ( buffer, "</td><th%s:<br>%s</th>" "<td width=\"" IMAGE_COL_WIDTH "\"></td>" "</tr>", html_label, map_link->str); } else { g_string_append_printf (buffer, "</td></tr>"); } } if (adr) e_contact_address_free (adr); g_string_free (map_link, TRUE); }
static gboolean parseLine (CSVImporter *gci, EContact *contact, gchar *buf) { const gchar *pptr = buf, *field_text; gchar *do_free = NULL; GString *value; gint ii = 0, idx; gint flags = 0; gint contact_field; EContactAddress *home_address = NULL, *work_address = NULL, *other_address = NULL; EContactDate *bday = NULL; GString *home_street, *work_street, *other_street; home_street = g_string_new (""); work_street = g_string_new (""); other_street = g_string_new (""); home_address = e_contact_address_new (); work_address = e_contact_address_new (); other_address = e_contact_address_new (); bday = e_contact_date_new (); if (!g_utf8_validate (pptr, -1, NULL)) { do_free = g_convert (pptr, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); pptr = do_free; } while (value = parseNextValue (&pptr), value != NULL) { contact_field = NOMAP; flags = FLAG_INVALID; field_text = NULL; idx = ii; if (gci->fields_map) { gpointer found; found = g_hash_table_lookup ( gci->fields_map, GINT_TO_POINTER (idx)); if (found == NULL) { g_warning ("%s: No map for index %d, skipping it", G_STRFUNC, idx); idx = -1; } else { idx = GPOINTER_TO_INT (found) - 1; } } if (importer == OUTLOOK_IMPORTER) { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_outlook)) { contact_field = csv_fields_outlook[idx].contact_field; flags = csv_fields_outlook[idx].flags; field_text = csv_fields_outlook[idx].csv_attribute; } } else if (importer == MOZILLA_IMPORTER) { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_mozilla)) { contact_field = csv_fields_mozilla[idx].contact_field; flags = csv_fields_mozilla[idx].flags; field_text = csv_fields_mozilla[idx].csv_attribute; } } else { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_evolution)) { contact_field = csv_fields_evolution[idx].contact_field; flags = csv_fields_evolution[idx].flags; field_text = csv_fields_evolution[idx].csv_attribute; } } if (*value->str) { if (contact_field != NOMAP) { if (importer == OUTLOOK_IMPORTER || importer == MOZILLA_IMPORTER) { e_contact_set (contact, contact_field, value->str); } else { if (contact_field == E_CONTACT_WANTS_HTML) e_contact_set ( contact, contact_field, GINT_TO_POINTER ( g_ascii_strcasecmp ( value->str, "TRUE") == 0)); else e_contact_set (contact, contact_field, value->str); } } else { switch (flags) { case FLAG_HOME_ADDRESS | FLAG_STREET: if (strlen (home_street->str) != 0) { home_street = g_string_append (home_street, ",\n"); } home_street = g_string_append (home_street, value->str); break; case FLAG_HOME_ADDRESS | FLAG_CITY: home_address->locality = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_STATE: home_address->region = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_POSTAL_CODE: home_address->code = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_POBOX: home_address->po = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_COUNTRY: home_address->country = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_STREET: if (strlen (work_street->str) != 0) { work_street = g_string_append (work_street, ",\n"); } work_street = g_string_append (work_street, value->str); break; case FLAG_WORK_ADDRESS | FLAG_CITY: work_address->locality = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_STATE: work_address->region = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_POSTAL_CODE: work_address->code = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_POBOX: work_address->po = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_COUNTRY: work_address->country = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_STREET: if (strlen (other_street->str) != 0) { other_street = g_string_append (other_street, ",\n"); } other_street = g_string_append (other_street, value->str); break; case FLAG_OTHER_ADDRESS | FLAG_CITY: other_address->locality = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_STATE: other_address->region = g_strdup (value->str); break; 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, date_from_string (value->str)); break; case FLAG_DATE_ANNIVERSARY: e_contact_set ( contact, E_CONTACT_ANNIVERSARY, date_from_string (value->str)); break; case FLAG_BIRTH_DAY: bday->day = atoi (value->str); break; case FLAG_BIRTH_YEAR: bday->year = atoi (value->str); break; case FLAG_BIRTH_MONTH: bday->month = atoi (value->str); break; case FLAG_INVALID: break; default: add_to_notes (contact, field_text, value->str); } } } ii++; g_string_free (value, TRUE); } if (strlen (home_street->str) != 0) home_address->street = g_strdup (home_street->str); if (strlen (work_street->str) != 0) work_address->street = g_strdup (work_street->str); if (strlen (other_street->str) != 0) other_address->street = g_strdup (other_street->str); g_string_free (home_street, TRUE); g_string_free (work_street, TRUE); g_string_free (other_street, TRUE); if (home_address->locality || home_address->country || home_address->code || home_address->region || home_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_HOME, home_address); if (work_address->locality || work_address->country || work_address->code || work_address->region || work_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_WORK, work_address); if (other_address->locality || other_address->country || other_address->code || other_address->region || other_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_OTHER, other_address); if (importer != OUTLOOK_IMPORTER) { if (bday->day || bday->year || bday->month) e_contact_set (contact, E_CONTACT_BIRTH_DATE, bday); } e_contact_address_free (home_address); e_contact_address_free (work_address); e_contact_address_free (other_address); e_contact_date_free (bday); g_free (do_free); return TRUE; }
static void local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrConduitContext *ctxt) { EContactAddress *address = NULL; int phone = entryPhone1; EContactField field; gboolean syncable; int i; g_return_if_fail (local != NULL); g_return_if_fail (contact != NULL); local->contact = g_object_ref (contact); local->local.ID = e_pilot_map_lookup_pid (ctxt->map, e_contact_get_const (contact, E_CONTACT_UID), TRUE); compute_status (ctxt, local, e_contact_get_const (contact, E_CONTACT_UID)); local->addr = g_new0 (struct Address, 1); /* Handle the fields and category we don't sync by making sure * we don't overwrite them */ if (local->local.ID != 0) { struct Address addr; int cat = 0; #ifdef PILOT_LINK_0_12 pi_buffer_t * record; record = pi_buffer_new(DLP_BUF_SIZE); if(record == NULL){ pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return; } #else char record[0xffff]; #endif if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, ctxt->dbi->db_handle, #ifdef PILOT_LINK_0_12 local->local.ID, record, NULL, NULL, &cat) > 0) { #else local->local.ID, &record, NULL, NULL, NULL, &cat) > 0) { #endif local->local.category = cat; memset (&addr, 0, sizeof (struct Address)); #ifdef PILOT_LINK_0_12 unpack_Address (&addr, record, address_v1); #else unpack_Address (&addr, (unsigned char *)record, 0xffff); #endif for (i = 0; i < 5; i++) { if (addr.entry[entryPhone1 + i]) local->addr->entry[entryPhone1 + i] = strdup (addr.entry[entryPhone1 + i]); local->addr->phoneLabel[i] = addr.phoneLabel[i]; } local->addr->showPhone = addr.showPhone; for (i = 0; i < 4; i++) { if (addr.entry[entryCustom1 + i]) local->addr->entry[entryCustom1 + i] = strdup (addr.entry[entryCustom1 + i]); } free_Address (&addr); } #ifdef PILOT_LINK_0_12 pi_buffer_free (record); #endif } local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME)); local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME)); local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG)); local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE)); /* See if the default has something in it */ if ((address = e_contact_get (contact, ctxt->cfg->default_address))) { field = ctxt->cfg->default_address; } else { /* Try to find a non-empty address field */ for (field = E_CONTACT_FIRST_ADDRESS_ID; field <= E_CONTACT_LAST_ADDRESS_ID; field++) { if ((address = e_contact_get (contact, field))) break; } } if (address) { char *add; /* If the address has 2 lines, make sure both get added */ if (address->ext != NULL && strlen (address->ext) > 0) { add = g_strconcat (address->street, "\n", address->ext, NULL); LOG (g_warning ("Address has two lines: [%s]\n", add)); } else { add = g_strdup (address->street); LOG (g_warning ("Address has only one line: [%s]\n", add)); } local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add); g_free (add); local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality); local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region); local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code); local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country); e_contact_address_free (address); } /* Phone numbers */ /* See if everything is syncable */ syncable = is_syncable (ctxt, local); if (syncable) { INFO ("Syncable"); /* Sync by priority */ for (i = 0, phone = entryPhone1; priority[i] != E_CONTACT_FIELD_LAST && phone <= entryPhone5; i++) { const char *phone_str; phone_str = e_contact_get_const (contact, priority[i]); if (phone_str && *phone_str) { clear_entry_text (*local->addr, phone); local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str); local->addr->phoneLabel[phone - entryPhone1] = priority_label[i]; phone++; } } for ( ; phone <= entryPhone5; phone++) local->addr->phoneLabel[phone - entryPhone1] = phone - entryPhone1; local->addr->showPhone = 0; } else { EContactField next_mail, next_home, next_work, next_fax; EContactField next_other, next_main, next_pager, next_mobile; INFO ("Not Syncable"); get_next_init (&next_mail, &next_home, &next_work, &next_fax, &next_other, &next_main, &next_pager, &next_mobile); /* Not completely syncable, so do the best we can */ for (i = entryPhone1; i <= entryPhone5; i++) { int phonelabel = local->addr->phoneLabel[i - entryPhone1]; const char *phone_str = NULL; if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) { phone_str = e_contact_get_const (contact, next_mail); next_mail = get_next_mail (&next_mail); } else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) { phone_str = e_contact_get_const (contact, next_home); next_home = get_next_home (&next_home); } else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) { phone_str = e_contact_get_const (contact, next_work); next_work = get_next_work (&next_work); } else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) { phone_str = e_contact_get_const (contact, next_fax); next_fax = get_next_fax (&next_fax); } else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) { phone_str = e_contact_get_const (contact, next_other); next_other = get_next_other (&next_other); } else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) { phone_str = e_contact_get_const (contact, next_main); next_main = get_next_main (&next_main); } else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) { phone_str = e_contact_get_const (contact, next_pager); next_pager = get_next_pager (&next_pager); } else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) { phone_str = e_contact_get_const (contact, next_mobile); next_mobile = get_next_mobile (&next_mobile); } if (phone_str && *phone_str) { clear_entry_text (*local->addr, i); local->addr->entry[i] = e_pilot_utf8_to_pchar (phone_str); } } } /* Note */ local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE)); }
static EContact * ecard_from_remote_record(EAddrConduitContext *ctxt, GnomePilotRecord *remote, EContact *in_contact) { struct Address address; EContact *contact; EContactName *name; EContactAddress *eaddress; EContactField mailing_address; char *txt, *find, *full_name; EContactField next_mail, next_home, next_work, next_fax; EContactField next_other, next_main, next_pager, next_mobile; int i; #ifdef PILOT_LINK_0_12 pi_buffer_t * buffer; #endif g_return_val_if_fail(remote!=NULL,NULL); memset (&address, 0, sizeof (struct Address)); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return NULL; } if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){ pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return NULL; } unpack_Address (&address, buffer, address_v1); pi_buffer_free(buffer); #else unpack_Address (&address, remote->record, remote->length); #endif if (in_contact == NULL) contact = e_contact_new (); else contact = e_contact_duplicate (in_contact); /* Name */ name = e_contact_name_new (); name->given = get_entry_text (address, entryFirstname); name->family = get_entry_text (address, entryLastname); full_name = e_contact_name_to_string (name); e_contact_set (contact, E_CONTACT_FULL_NAME, full_name); e_contact_name_free (name); /* File As */ if (!full_name || !*full_name) set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany); g_free (full_name); /* Title and Company */ set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle); set_contact_text (contact, E_CONTACT_ORG, address, entryCompany); /* Address */ mailing_address = -1; if ((eaddress = e_contact_get (contact, ctxt->cfg->default_address))) { mailing_address = ctxt->cfg->default_address; e_contact_address_free (eaddress); } else { for (i = E_CONTACT_FIRST_ADDRESS_ID; i <= E_CONTACT_LAST_ADDRESS_ID; i++) { if ((eaddress = e_contact_get (contact, i))) { e_contact_address_free (eaddress); mailing_address = i; break; } } } if (mailing_address == -1) mailing_address = ctxt->cfg->default_address; eaddress = g_new0 (EContactAddress, 1); txt = get_entry_text (address, entryAddress); if (txt && (find = strchr (txt, '\n')) != NULL) { *find = '\0'; find++; } else { find = NULL; } eaddress->street = txt; eaddress->ext = find != NULL ? g_strdup (find) : g_strdup (""); eaddress->locality = get_entry_text (address, entryCity); eaddress->region = get_entry_text (address, entryState); eaddress->country = get_entry_text (address, entryCountry); eaddress->code = get_entry_text (address, entryZip); e_contact_set (contact, mailing_address, eaddress); e_contact_address_free (eaddress); /* Phone numbers */ get_next_init (&next_mail, &next_home, &next_work, &next_fax, &next_other, &next_main, &next_pager, &next_mobile); for (i = entryPhone1; i <= entryPhone5; i++) { int phonelabel = address.phoneLabel[i - entryPhone1]; char *phonenum = get_entry_text (address, i); if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) { e_contact_set (contact, next_mail, phonenum); next_mail = get_next_mail (&next_mail); } else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) { e_contact_set (contact, next_home, phonenum); next_home = get_next_home (&next_home); } else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) { e_contact_set (contact, next_work, phonenum); next_work = get_next_work (&next_work); } else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) { e_contact_set (contact, next_fax, phonenum); next_fax = get_next_fax (&next_fax); } else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) { e_contact_set (contact, next_other, phonenum); next_other = get_next_other (&next_other); } else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) { e_contact_set (contact, next_main, phonenum); next_main = get_next_main (&next_main); } else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) { e_contact_set (contact, next_pager, phonenum); next_pager = get_next_pager (&next_pager); } else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) { e_contact_set (contact, next_mobile, phonenum); next_mobile = get_next_mobile (&next_mobile); } g_free (phonenum); } /* Note */ set_contact_text (contact, E_CONTACT_NOTE, address, entryNote); free_Address(&address); return contact; }
/* utility functions shared between all contact importers */ static void preview_contact (EWebViewPreview *preview, EContact *contact) { gint idx; gboolean had_value = FALSE; const gint fields[] = { E_CONTACT_FILE_AS, E_CONTACT_CATEGORIES, E_CONTACT_IS_LIST, E_CONTACT_LIST_SHOW_ADDRESSES, E_CONTACT_WANTS_HTML, E_CONTACT_FULL_NAME, E_CONTACT_GIVEN_NAME, E_CONTACT_FAMILY_NAME, E_CONTACT_NICKNAME, E_CONTACT_SPOUSE, E_CONTACT_BIRTH_DATE, E_CONTACT_ANNIVERSARY, E_CONTACT_MAILER, E_CONTACT_EMAIL, -1, E_CONTACT_ORG, E_CONTACT_ORG_UNIT, E_CONTACT_OFFICE, E_CONTACT_TITLE, E_CONTACT_ROLE, E_CONTACT_MANAGER, E_CONTACT_ASSISTANT, -1, E_CONTACT_PHONE_ASSISTANT, E_CONTACT_PHONE_BUSINESS, E_CONTACT_PHONE_BUSINESS_2, E_CONTACT_PHONE_BUSINESS_FAX, E_CONTACT_PHONE_CALLBACK, E_CONTACT_PHONE_CAR, E_CONTACT_PHONE_COMPANY, E_CONTACT_PHONE_HOME, E_CONTACT_PHONE_HOME_2, E_CONTACT_PHONE_HOME_FAX, E_CONTACT_PHONE_ISDN, E_CONTACT_PHONE_MOBILE, E_CONTACT_PHONE_OTHER, E_CONTACT_PHONE_OTHER_FAX, E_CONTACT_PHONE_PAGER, E_CONTACT_PHONE_PRIMARY, E_CONTACT_PHONE_RADIO, E_CONTACT_PHONE_TELEX, E_CONTACT_PHONE_TTYTDD, -1, E_CONTACT_ADDRESS_HOME, E_CONTACT_ADDRESS_WORK, E_CONTACT_ADDRESS_OTHER, -1, E_CONTACT_HOMEPAGE_URL, E_CONTACT_BLOG_URL, E_CONTACT_CALENDAR_URI, E_CONTACT_FREEBUSY_URL, E_CONTACT_ICS_CALENDAR, E_CONTACT_VIDEO_URL, -1, E_CONTACT_IM_AIM, E_CONTACT_IM_GROUPWISE, E_CONTACT_IM_JABBER, E_CONTACT_IM_YAHOO, E_CONTACT_IM_MSN, E_CONTACT_IM_ICQ, E_CONTACT_IM_GADUGADU, E_CONTACT_IM_SKYPE, -1, E_CONTACT_NOTE }; g_return_if_fail (preview != NULL); g_return_if_fail (contact != NULL); for (idx = 0; idx < G_N_ELEMENTS (fields); idx++) { EContactField field; if (fields[idx] == -1) { if (had_value) e_web_view_preview_add_empty_line (preview); had_value = FALSE; continue; } field = fields[idx]; if (field == E_CONTACT_BIRTH_DATE || field == E_CONTACT_ANNIVERSARY) { EContactDate *dt = e_contact_get (contact, field); if (dt) { GDate gd = { 0 }; struct tm tm; gchar *value; g_date_set_dmy (&gd, dt->day, dt->month, dt->year); g_date_to_struct_tm (&gd, &tm); value = e_datetime_format_format_tm ( "addressbook", "table", DTFormatKindDate, &tm); if (value) { e_web_view_preview_add_section ( preview, e_contact_pretty_name (field), value); had_value = TRUE; } g_free (value); e_contact_date_free (dt); } } else if (field == E_CONTACT_IS_LIST || field == E_CONTACT_WANTS_HTML || field == E_CONTACT_LIST_SHOW_ADDRESSES) { if (e_contact_get (contact, field)) { e_web_view_preview_add_text ( preview, e_contact_pretty_name (field)); had_value = TRUE; } } else if (field == E_CONTACT_ADDRESS_HOME || field == E_CONTACT_ADDRESS_WORK || field == E_CONTACT_ADDRESS_OTHER) { EContactAddress *addr = e_contact_get (contact, field); if (addr) { gboolean have = FALSE; #define add_it(_what) \ if (addr->_what && *addr->_what) { \ e_web_view_preview_add_section ( \ preview, have ? NULL : \ e_contact_pretty_name (field), addr->_what); \ have = TRUE; \ had_value = TRUE; \ } add_it (po); add_it (ext); add_it (street); add_it (locality); add_it (region); add_it (code); add_it (country); #undef add_it e_contact_address_free (addr); } } else if (field == E_CONTACT_IM_AIM || field == E_CONTACT_IM_GROUPWISE || field == E_CONTACT_IM_JABBER || field == E_CONTACT_IM_YAHOO || field == E_CONTACT_IM_MSN || field == E_CONTACT_IM_ICQ || field == E_CONTACT_IM_GADUGADU || field == E_CONTACT_IM_SKYPE || field == E_CONTACT_EMAIL) { GList *attrs, *a; gboolean have = FALSE; const gchar *pretty_name; pretty_name = e_contact_pretty_name (field); attrs = e_contact_get_attributes (contact, field); for (a = attrs; a; a = a->next) { EVCardAttribute *attr = a->data; GList *value; if (!attr) continue; value = e_vcard_attribute_get_values (attr); while (value != NULL) { const gchar *str = value->data; if (str && *str) { e_web_view_preview_add_section ( preview, have ? NULL : pretty_name, str); have = TRUE; had_value = TRUE; } value = value->next; } e_vcard_attribute_free (attr); } g_list_free (attrs); } else if (field == E_CONTACT_CATEGORIES) { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } else { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } } }