static void set_attributes(EContact *contact, EContactField field, GList *use_attr_list) { GList *miter, *citer; citer = NULL; for (miter = use_attr_list; miter; miter = g_list_next (miter)) { if (miter->data) citer = g_list_prepend (citer, miter->data); } citer = g_list_reverse (citer); e_contact_set_attributes (contact, field, citer); g_list_free (citer); }
static void resolve_list_card (LDIFImporter *gci, EContact *contact) { GList *email, *l; GList *email_attrs = NULL; gchar *full_name; /* set file_as to full_name so we don't later try and figure * out a first/last name for the list. */ full_name = e_contact_get (contact, E_CONTACT_FULL_NAME); if (full_name) e_contact_set (contact, E_CONTACT_FILE_AS, full_name); g_free (full_name); /* FIMXE getting might not be implemented in ebook */ email = e_contact_get (contact, E_CONTACT_EMAIL); for (l = email; l; l = l->next) { /* mozilla stuffs dn's in the EMAIL list for contact lists */ gchar *dn = l->data; EContact *dn_contact = g_hash_table_lookup (gci->dn_contact_hash, dn); /* break list chains here, since we don't support them just yet */ if (dn_contact && !e_contact_get (dn_contact, E_CONTACT_IS_LIST)) { EDestination *dest; EVCardAttribute *attr = e_vcard_attribute_new (NULL, EVC_EMAIL); /* Hard-wired for default e-mail, since * netscape only exports 1 email address. */ dest = e_destination_new (); e_destination_set_contact (dest, dn_contact, 0); e_destination_export_to_vcard_attribute (dest, attr); g_object_unref (dest); email_attrs = g_list_append (email_attrs, attr); } } e_contact_set_attributes (contact, E_CONTACT_EMAIL, email_attrs); g_list_foreach (email, (GFunc) g_free, NULL); g_list_free (email); g_list_foreach (email_attrs, (GFunc) e_vcard_attribute_free, NULL); g_list_free (email_attrs); }
static void import_contact (EBookClient *book_client, gchar *line) { gchar **strings, *addr, **addrs; gint i; GList *list; /*EContactName *name;*/ EContact *card; gsize len; GError *error = NULL; card = e_contact_new (); strings = g_strsplit (line, "\t", 5); if (strings[0] && strings[1] && strings[2]) { gchar *new_uid = NULL; e_contact_set (card, E_CONTACT_NICKNAME, strings[0]); e_contact_set (card, E_CONTACT_FULL_NAME, strings[1]); addr = strings[2]; len = strlen (addr); if (addr[0] == '(' && addr[len - 1] == ')') { addr[0] = 0; addr[len - 1] = 0; addrs = g_strsplit (addr + 1, ",", 0); list = NULL; /* XXX So ... this api is just insane ... we set * plain strings as the contact email if it * is a normal contact, but need to do this * XML crap for mailing lists. */ for (i = 0; addrs[i]; i++) { EDestination *d; EVCardAttribute *attr; d = e_destination_new (); e_destination_set_email (d, addrs[i]); attr = e_vcard_attribute_new (NULL, EVC_EMAIL); e_destination_export_to_vcard_attribute (d, attr); list = g_list_append (list, attr); g_object_unref (d); } e_contact_set_attributes (card, E_CONTACT_EMAIL, list); g_list_foreach (list, (GFunc) e_vcard_attribute_free, NULL); g_list_free (list); g_strfreev (addrs); e_contact_set (card, E_CONTACT_IS_LIST, GINT_TO_POINTER (TRUE)); } else { e_contact_set (card, E_CONTACT_EMAIL_1, strings[2]); } /*name = e_contact_name_from_string(strings[1]);*/ if (strings[3] && strings[4]) e_contact_set (card, E_CONTACT_NOTE, strings[4]); e_book_client_add_contact_sync ( book_client, card, &new_uid, NULL, &error); if (error != NULL) { g_warning ( "%s: Failed to add contact: %s", G_STRFUNC, error->message); g_error_free (error); } else { g_free (new_uid); } g_object_unref (card); } g_strfreev (strings); }
static void vcard_import_contact (VCardImporter *gci, EContact *contact) { EContactPhoto *photo; GList *attrs, *attr; gchar *uid = NULL; /* Apple's addressbook.app exports PHOTO's without a TYPE * param, so let's figure out the format here if there's a * PHOTO attribute missing a TYPE param. * * this is sort of a hack, as EContact sets the type for us if * we use the setter. so let's e_contact_get + e_contact_set * on E_CONTACT_PHOTO. */ photo = e_contact_get (contact, E_CONTACT_PHOTO); if (photo) { e_contact_set (contact, E_CONTACT_PHOTO, photo); e_contact_photo_free (photo); } /* Deal with our XML EDestination stuff in EMAIL attributes, if there is any. */ attrs = e_contact_get_attributes (contact, E_CONTACT_EMAIL); for (attr = attrs; attr; attr = attr->next) { EVCardAttribute *a = attr->data; GList *v = e_vcard_attribute_get_values (a); if (v && v->data) { if (!strncmp ((gchar *)v->data, "<?xml", 5)) { EDestination *dest = e_destination_import ((gchar *) v->data); e_destination_export_to_vcard_attribute (dest, a); g_object_unref (dest); } } } e_contact_set_attributes (contact, E_CONTACT_EMAIL, attrs); /* Deal with TEL attributes that don't conform to what we need. * * 1. if there's no location (HOME/WORK/OTHER), default to OTHER. * 2. if there's *only* a location specified, default to VOICE. */ attrs = e_vcard_get_attributes (E_VCARD (contact)); for (attr = attrs; attr; attr = attr->next) { EVCardAttribute *a = attr->data; gboolean location_only = TRUE; gboolean no_location = TRUE; gboolean is_work_home = FALSE; GList *params, *param; if (g_ascii_strcasecmp (e_vcard_attribute_get_name (a), EVC_TEL)) continue; params = e_vcard_attribute_get_params (a); for (param = params; param; param = param->next) { EVCardAttributeParam *p = param->data; GList *vs, *v; if (g_ascii_strcasecmp (e_vcard_attribute_param_get_name (p), EVC_TYPE)) continue; vs = e_vcard_attribute_param_get_values (p); for (v = vs; v; v = v->next) { is_work_home = is_work_home || !g_ascii_strcasecmp ((gchar *)v->data, "WORK") || !g_ascii_strcasecmp ((gchar *)v->data, "HOME"); if (!g_ascii_strcasecmp ((gchar *)v->data, "WORK") || !g_ascii_strcasecmp ((gchar *)v->data, "HOME") || !g_ascii_strcasecmp ((gchar *)v->data, "OTHER")) no_location = FALSE; else location_only = FALSE; } } if (is_work_home) { /* only WORK and HOME phone numbers require locations, * the rest should be kept as is */ if (location_only) { /* add VOICE */ e_vcard_attribute_add_param_with_value (a, e_vcard_attribute_param_new (EVC_TYPE), "VOICE"); } if (no_location) { /* add OTHER */ e_vcard_attribute_add_param_with_value (a, e_vcard_attribute_param_new (EVC_TYPE), "OTHER"); } } } /* Deal with ADR and EMAIL attributes that don't conform to what * we need. If HOME or WORK isn't specified, add TYPE=OTHER. */ attrs = e_vcard_get_attributes (E_VCARD (contact)); for (attr = attrs; attr; attr = attr->next) { EVCardAttribute *a = attr->data; gboolean no_location = TRUE; GList *params, *param; if (g_ascii_strcasecmp (e_vcard_attribute_get_name (a), EVC_ADR) && g_ascii_strcasecmp (e_vcard_attribute_get_name (a), EVC_EMAIL)) continue; params = e_vcard_attribute_get_params (a); for (param = params; param; param = param->next) { EVCardAttributeParam *p = param->data; GList *vs, *v; if (g_ascii_strcasecmp (e_vcard_attribute_param_get_name (p), EVC_TYPE)) continue; vs = e_vcard_attribute_param_get_values (p); for (v = vs; v; v = v->next) { if (!g_ascii_strcasecmp ((gchar *)v->data, "WORK") || !g_ascii_strcasecmp ((gchar *)v->data, "HOME")) no_location = FALSE; } } if (no_location) { /* add OTHER */ e_vcard_attribute_add_param_with_value (a, e_vcard_attribute_param_new (EVC_TYPE), "OTHER"); } } /* Work around the fact that these fields no longer show up in the UI */ add_to_notes (contact, E_CONTACT_OFFICE); add_to_notes (contact, E_CONTACT_SPOUSE); add_to_notes (contact, E_CONTACT_BLOG_URL); /* FIXME Error checking */ if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) { e_contact_set (contact, E_CONTACT_UID, uid); g_free (uid); } }
static gint mergeit (EContactMergingLookup *lookup) { GtkWidget *scrolled_window, *label, *hbox, *dropdown; GtkWidget *content_area; GtkWidget *dialog; GtkTable *table; EContactField field; gchar *string = NULL, *string1 = NULL; GList *use_email_attr_list, *contact_email_attr_list, *match_email_attr_list; GList *use_tel_attr_list, *contact_tel_attr_list, *match_tel_attr_list; GList *use_im_attr_list, *contact_im_attr_list, *match_im_attr_list; GList *use_sip_attr_list, *contact_sip_attr_list, *match_sip_attr_list; gint row = -1; gint value = 0, result; dialog = gtk_dialog_new (); gtk_window_set_title (GTK_WINDOW (dialog), _("Merge Contact")); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); table = (GtkTable *) gtk_table_new (20, 2, FALSE); gtk_container_set_border_width ((GtkContainer *) table, 12); gtk_table_set_row_spacings (table, 6); gtk_table_set_col_spacings (table, 2); gtk_dialog_add_buttons ( GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Merge"), GTK_RESPONSE_OK, NULL); /*we match all the string fields of the already existing contact and the new contact.*/ for (field = E_CONTACT_FULL_NAME; field != (E_CONTACT_LAST_SIMPLE_STRING -1); field++) { dropdown_data *data = NULL; string = (gchar *) e_contact_get_const (lookup->contact, field); string1 = (gchar *) e_contact_get_const (lookup->match, field); /*the field must exist in the new as well as the duplicate contact*/ if (string && *string) { if ((field >= E_CONTACT_FIRST_EMAIL_ID && field <= E_CONTACT_LAST_EMAIL_ID) || (field >= E_CONTACT_FIRST_PHONE_ID && field <= E_CONTACT_LAST_PHONE_ID) || (field >= E_CONTACT_IM_AIM_HOME_1 && field <= E_CONTACT_IM_ICQ_WORK_3) ) { /* ignore multival attributes, they are compared after this for-loop */ continue; } if (!(string1 && *string1) || (g_ascii_strcasecmp (string, string1))) { row++; label = gtk_label_new (e_contact_pretty_name (field)); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (hbox), (GtkWidget *) label, FALSE, FALSE, 0); gtk_table_attach_defaults (table, (GtkWidget *) hbox, 0, 1, row, row + 1); data = g_new0 (dropdown_data, 1); dropdown = gtk_combo_box_text_new (); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dropdown), string); if (string1 && *string1) gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dropdown), string1); else gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dropdown), ""); data->field = field; data->match = lookup->match; g_signal_connect ( dropdown, "changed", G_CALLBACK (dropdown_changed), data); g_object_set_data_full (G_OBJECT (dropdown), "eab-contact-merging::dropdown-data", data, g_free); if (field == E_CONTACT_NICKNAME || field == E_CONTACT_GIVEN_NAME || field == E_CONTACT_FAMILY_NAME || field == E_CONTACT_FULL_NAME) gtk_combo_box_set_active (GTK_COMBO_BOX (dropdown), 1); else gtk_combo_box_set_active (GTK_COMBO_BOX (dropdown), 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (hbox), (GtkWidget *) dropdown, FALSE, FALSE, 0); gtk_table_attach_defaults (table, (GtkWidget *) hbox, 1, 2, row, row + 1); gtk_widget_show_all ((GtkWidget *) dropdown); } } } match_email_attr_list = e_contact_get_attributes (lookup->match, E_CONTACT_EMAIL); contact_email_attr_list = e_contact_get_attributes (lookup->contact, E_CONTACT_EMAIL); use_email_attr_list = NULL; create_dropdowns_for_multival_attr (match_email_attr_list, contact_email_attr_list, &use_email_attr_list, &row, table, _("Email")); match_tel_attr_list = e_contact_get_attributes (lookup->match, E_CONTACT_TEL); contact_tel_attr_list = e_contact_get_attributes (lookup->contact, E_CONTACT_TEL); use_tel_attr_list = NULL; create_dropdowns_for_multival_attr (match_tel_attr_list, contact_tel_attr_list, &use_tel_attr_list, &row, table, _("Phone")); match_sip_attr_list = e_contact_get_attributes (lookup->match, E_CONTACT_SIP); contact_sip_attr_list = e_contact_get_attributes (lookup->contact, E_CONTACT_SIP); use_sip_attr_list = NULL; create_dropdowns_for_multival_attr (match_sip_attr_list, contact_sip_attr_list, &use_sip_attr_list, &row, table, _("SIP")); match_im_attr_list = e_contact_get_attributes_set (lookup->match, im_fetch_set, G_N_ELEMENTS (im_fetch_set)); contact_im_attr_list = e_contact_get_attributes_set (lookup->contact, im_fetch_set, G_N_ELEMENTS (im_fetch_set)); use_im_attr_list = NULL; create_dropdowns_for_multival_attr (match_im_attr_list, contact_im_attr_list, &use_im_attr_list, &row, table, _("IM")); gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 300); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), GTK_WIDGET (table)); gtk_box_pack_start (GTK_BOX (content_area), GTK_WIDGET (scrolled_window), TRUE, TRUE, 0); gtk_widget_show (scrolled_window); g_signal_connect ( dialog, "map-event", G_CALLBACK (dialog_map), table); gtk_widget_show_all ((GtkWidget *) table); result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { gint ii; GList *ll; case GTK_RESPONSE_OK: set_attributes (lookup->match, E_CONTACT_EMAIL, use_email_attr_list); set_attributes (lookup->match, E_CONTACT_TEL, use_tel_attr_list); set_attributes (lookup->match, E_CONTACT_SIP, use_sip_attr_list); for (ii = 0; ii < G_N_ELEMENTS (im_fetch_set); ii++) { e_contact_set_attributes (lookup->match, im_fetch_set[ii], NULL); } for (ll = use_im_attr_list; ll; ll = ll->next) { EVCard *vcard; vcard = E_VCARD (lookup->match); e_vcard_append_attribute (vcard, e_vcard_attribute_copy ((EVCardAttribute *) ll->data)); } g_object_unref (lookup->contact); lookup->contact = g_object_ref (lookup->match); e_book_client_remove_contact ( lookup->book_client, lookup->match, NULL, remove_contact_ready_cb, lookup); value = 1; break; case GTK_RESPONSE_CANCEL: default: value = 0; break; } gtk_widget_destroy (dialog); g_list_free_full (match_email_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free_full (contact_email_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free (use_email_attr_list); g_list_free_full (match_tel_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free_full (contact_tel_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free (use_tel_attr_list); g_list_free_full (match_im_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free_full (contact_im_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free (use_im_attr_list); g_list_free_full (match_sip_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free_full (contact_sip_attr_list, (GDestroyNotify) e_vcard_attribute_free); g_list_free (use_sip_attr_list); return value; }