static void add_contact_inline (EBookClient *book) { EContact *contact; EContactPhoto *photo; guchar *data; gsize length = 0; contact = e_contact_new (); data = g_base64_decode (photo_data, &length); photo = g_new (EContactPhoto, 1); photo->type = E_CONTACT_PHOTO_TYPE_INLINED; photo->data.inlined.mime_type = NULL; photo->data.inlined.data = data; photo->data.inlined.length = length; /* set the photo */ e_contact_set (contact, E_CONTACT_PHOTO, photo); e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson"); if (!add_contact_verify (book, contact)) g_error ("Failed to add contact"); micheal_jackson_uid = e_contact_get (contact, E_CONTACT_UID); }
static void action_contact_new_list_cb (GtkAction *action, EBookShellView *book_shell_view) { EShell *shell; EShellView *shell_view; EShellWindow *shell_window; EBookShellContent *book_shell_content; EAddressbookView *view; EAddressbookModel *model; EContact *contact; EABEditor *editor; EBookClient *book; shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); shell = e_shell_window_get_shell (shell_window); book_shell_content = book_shell_view->priv->book_shell_content; view = e_book_shell_content_get_current_view (book_shell_content); g_return_if_fail (view != NULL); model = e_addressbook_view_get_model (view); book = e_addressbook_model_get_client (model); g_return_if_fail (book != NULL); contact = e_contact_new (); editor = e_contact_list_editor_new (shell, book, contact, TRUE, TRUE); eab_editor_show (editor); g_object_unref (contact); }
static gboolean setup_book (EBookClient **book_out) { GError *error = NULL; gint i; g_return_val_if_fail (book_out != NULL, FALSE); *book_out = new_temp_client (NULL); g_return_val_if_fail (*book_out != NULL, FALSE); if (!e_client_open_sync (E_CLIENT (*book_out), FALSE, NULL, &error)) { report_error ("client open sync", &error); g_object_unref (*book_out); return FALSE; } for (i = 0; i < N_TEST_CONTACTS; i++) { EContact *contact = e_contact_new (); gchar *name = g_strdup_printf ("Contact #%d", i + 1); e_contact_set (contact, E_CONTACT_FULL_NAME, name); e_contact_set (contact, E_CONTACT_NICKNAME, name); /* verify the contact was added "successfully" (not thorough) */ if (!add_contact_verify (*book_out, contact)) g_error ("Failed to add contact"); g_free (name); g_object_unref (contact); } return TRUE; }
static void local_record_from_uid (EAddrLocalRecord *local, const char *uid, EAddrConduitContext *ctxt) { EContact *contact = NULL; const char *cuid; GList *l; g_assert (local != NULL); for (l = ctxt->cards; l != NULL; l = l->next) { contact = l->data; /* FIXME Do we need to check for the empty string? */ if ((cuid = e_contact_get_const (contact, E_CONTACT_UID)) && !strcmp (cuid, uid)) break; contact = NULL; } if (contact != NULL) { local_record_from_ecard (local, contact, ctxt); } else { contact = e_contact_new (); e_contact_set (contact, E_CONTACT_UID, (gpointer) uid); local_record_from_ecard (local, contact, ctxt); g_object_unref (contact); } }
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 setup_book (EBookClient *book_client) { gint i, j; for (i = 0; i < N_TEST_CONTACTS; i++) { EContact *contact = e_contact_new (); gchar *name = g_strdup_printf ("Contact #%d", i + 1); gchar *emails[5] = { g_strdup_printf ("*****@*****.**", i), g_strdup_printf ("*****@*****.**", i), g_strdup_printf ("*****@*****.**", i), g_strdup_printf ("*****@*****.**", i), NULL }; e_contact_set (contact, E_CONTACT_FULL_NAME, name); e_contact_set (contact, E_CONTACT_NICKNAME, name); /* Fill some emails */ for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_EMAIL_1]); #if BEEFY_VCARDS /* Fill some other random stuff */ for (j = E_CONTACT_IM_AIM_HOME_1; j < (E_CONTACT_IM_AIM_HOME_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_HOME_1]); for (j = E_CONTACT_IM_AIM_WORK_1; j < (E_CONTACT_IM_AIM_WORK_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_WORK_1]); for (j = E_CONTACT_IM_GROUPWISE_HOME_1; j < (E_CONTACT_IM_GROUPWISE_HOME_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_HOME_1]); for (j = E_CONTACT_IM_GROUPWISE_WORK_1; j < (E_CONTACT_IM_GROUPWISE_WORK_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_WORK_1]); for (j = E_CONTACT_IM_JABBER_HOME_1; j < (E_CONTACT_IM_JABBER_HOME_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_HOME_1]); for (j = E_CONTACT_IM_JABBER_WORK_1; j < (E_CONTACT_IM_JABBER_WORK_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_WORK_1]); for (j = E_CONTACT_IM_YAHOO_HOME_1; j < (E_CONTACT_IM_YAHOO_HOME_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_HOME_1]); for (j = E_CONTACT_IM_YAHOO_WORK_1; j < (E_CONTACT_IM_YAHOO_WORK_3 + 1); j++) e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_WORK_1]); #endif /* verify the contact was added "successfully" (not thorough) */ if (!add_contact_verify (book_client, contact)) g_error ("Failed to add contact"); g_free (name); for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++) g_free (emails[j - E_CONTACT_EMAIL_1]); g_object_unref (contact); } return TRUE; }
/**************************************************************** * Modify/Setup the EBook * ****************************************************************/ static void add_contact (EBookClient *client) { EContact *contact = e_contact_new (); e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson"); if (!add_contact_verify (client, contact)) stop_main_loop (1); g_object_unref (contact); }
/**************************************************************** * Modify/Setup the EBook * ****************************************************************/ static void add_contact (EBookClient *client) { EContact *contact = e_contact_new (); e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson"); if (!add_contact_verify (client, contact)) g_error ("Failed to add Micheal Jackson"); g_object_unref (contact); }
static void create_new_contact_from_number (gchar *number) { GtkWidget *dialog, *name, *label; dialog = gtk_dialog_new_with_buttons ("Save as Contact", NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); label = gtk_label_new ("Enter a name for the contact"); name = gtk_entry_new (); gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG(dialog)->vbox), label); gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG(dialog)->vbox), name); gtk_widget_show (label); gtk_widget_show (name); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { EContact *contact; EBook *book; EVCardAttribute *attr; /* create contact */ contact = e_contact_new (); /* add name */ e_contact_set (contact, E_CONTACT_FULL_NAME, (const gpointer)gtk_entry_get_text (GTK_ENTRY (name))); /* (const gpointer) removes a useless warning) */ /* add number */ attr = e_vcard_attribute_new ("", EVC_TEL); e_vcard_add_attribute_with_value (E_VCARD (contact), attr, number); hito_vcard_attribute_set_type (attr, "Other"); /* open address book */ /* TODO: check GErrors */ book = e_book_new_system_addressbook (NULL); e_book_open (book, FALSE, NULL); /* add contact to address book, and close */ e_book_add_contact (book, contact, NULL); g_object_unref (book); g_object_unref (contact); } gtk_widget_destroy (dialog); }
gint main (gint argc, gchar **argv) { EContact *contact; g_type_init (); contact = e_contact_new (); e_contact_set (contact, E_CONTACT_UID, TEST_ID); if (!strcmp (e_contact_get_const (contact, E_CONTACT_UID), TEST_ID)) printf ("passed\n"); else printf ("failed\n"); return 0; }
static void add_contact_uri (EBookClient *book) { EContact *contact; EContactPhoto *photo; contact = e_contact_new (); photo = g_new (EContactPhoto, 1); photo->type = E_CONTACT_PHOTO_TYPE_URI; photo->data.uri = g_strdup ("http://en.wikipedia.org/wiki/File:Jamesbrown4.jpg"); /* set the photo */ e_contact_set (contact, E_CONTACT_PHOTO, photo); e_contact_set (contact, E_CONTACT_FULL_NAME, "James Brown"); if (!add_contact_verify (book, contact)) g_error ("Failed to add contact"); james_brown_uid = e_contact_get (contact, E_CONTACT_UID); }
static void setup_book (EBookClient *book_client) { gint i; for (i = 0; i < N_TEST_CONTACTS; i++) { EContact *contact = e_contact_new (); gchar *name = g_strdup_printf ("Contact #%d", i + 1); e_contact_set (contact, E_CONTACT_FULL_NAME, name); e_contact_set (contact, E_CONTACT_NICKNAME, name); /* verify the contact was added "successfully" (not thorough) */ if (!add_contact_verify (book_client, contact)) g_error ("Failed to add contact"); g_free (name); g_object_unref (contact); } }
/* calls to import contacts */ static int addrbook_libebook_import(ship_list_t *imps, int *concount, int query) { int ret = -1; void *ptr = 0; contact_t *c = 0; GError *error = 0; *concount = 0; /* query & import */ ship_lock(addrbook_lock); if (ship_list_first(imps) && (!query || ui_query_import_contacts(imps) > 0)) { ptr = 0; while ((c = ship_list_next(imps, &ptr))) { EContact *contact = 0; EContactName name; char *arr[2], *ln; arr[1] = 0; bzero(&name, sizeof(name)); ret = -1; /* create a new contact */ ASSERT_TRUE(contact = e_contact_new(), cerr); /* create the name struct */ ln = strchr(c->name, ' '); if (ln) { ASSERT_TRUE(name.given = strndup(c->name, ln - c->name), cerr); ASSERT_TRUE(name.family = strdup(ln+1), cerr); } else { ASSERT_TRUE(name.given = strdup(c->name), cerr); } /* simple strings */ e_contact_set(contact, E_CONTACT_FULL_NAME, c->name); e_contact_set(contact, E_CONTACT_GIVEN_NAME, name.given); if (name.family) e_contact_set(contact, E_CONTACT_FAMILY_NAME, name.family); if (ship_ht_get_string(c->params, "category")) e_contact_set(contact, E_CONTACT_CATEGORIES, ship_ht_get_string(c->params, "category")); /* EContactName */ e_contact_set(contact, E_CONTACT_NAME, &name); /* array of strings */ if (ship_ht_get_string(c->params, "email")) { arr[0] = ship_ht_get_string(c->params, "email"); e_contact_set(contact, E_CONTACT_EMAIL, arr); } arr[0] = c->sip_aor; e_contact_set(contact, E_CONTACT_SIP, arr); ASSERT_TRUE(e_book_add_contact(book, contact, &error), cerr); ret = 0; cerr: g_object_unref(contact); freez(name.family); freez(name.given); if (ret) goto err; /* save what we've done */ c->added = time(NULL); (*concount)++; } } ret = 0; err: if (error) { if (query) ui_print_error("Error importing the contacts: %s.\n", error->message); g_error_free(error); } else if (ret && query) { ui_print_error("An error occured while importing the contacts.\n"); } ship_unlock(addrbook_lock); return ret; }
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; }
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 EContact * getNextCSVEntry (CSVImporter *gci, FILE *f) { EContact *contact = NULL; GString *line; GString *str; gchar *buf; gint c; line = g_string_new (""); while (1) { c = fgetc (f); if (c == EOF) return NULL; if (c == '\n') { g_string_append_c (line, c); break; } if (c == '"') { g_string_append_c (line, c); c = fgetc (f); while (!feof (f) && c != '"') { g_string_append_c (line, c); c = fgetc (f); } g_string_append_c (line, c); } else g_string_append_c (line, c); } if (gci->count == 0 && importer != MOZILLA_IMPORTER) { gci->fields_map = map_fields (line->str, 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_c (line, c); break; } if (c == '"') { g_string_append_c (line, c); c = fgetc (f); while (!feof (f) && c != '"') { g_string_append_c (line, c); c = fgetc (f); } g_string_append_c (line, c); } else g_string_append_c (line, c); } gci->count++; } str = g_string_new (""); 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; if (!parseLine (gci, contact, buf)) { g_object_unref (contact); return NULL; } gci->count++; g_string_free (str, TRUE); return contact; }
void bbdb_sync_buddy_list (void) { GList *blist, *l; EBook *book = NULL; /* Get the Gaim buddy list */ blist = bbdb_get_gaim_buddy_list (); if (blist == NULL) return; /* Open the addressbook */ book = bbdb_open_addressbook (GAIM_ADDRESSBOOK); if (book == NULL) { free_buddy_list (blist); return; } printf ("bbdb: Synchronizing buddy list to contacts...\n"); /* Walk the buddy list */ for (l = blist; l != NULL; l = l->next) { GaimBuddy *b = l->data; EBookQuery *query; GList *contacts; GError *error = NULL; EContact *c; if (b->alias == NULL || strlen (b->alias) == 0) b->alias = b->account_name; /* Look for an exact match full name == buddy alias */ query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, b->alias); e_book_get_contacts (book, query, &contacts, NULL); e_book_query_unref (query); if (contacts != NULL) { /* FIXME: If there's more than one contact with this name, just give up; we're not smart enough for this. */ if (contacts->next != NULL) continue; c = E_CONTACT (contacts->data); if (! bbdb_merge_buddy_to_contact (book, b, c)) continue; /* Write it out to the addressbook */ if (! e_book_commit_contact (book, c, &error)) { g_warning ("bbdb: Could not modify contact: %s\n", error->message); g_error_free (error); } continue; } /* Otherwise, create a new contact. */ c = e_contact_new (); e_contact_set (c, E_CONTACT_FULL_NAME, (gpointer) b->alias); if (! bbdb_merge_buddy_to_contact (book, b, c)) { g_object_unref (G_OBJECT (c)); continue; } if (! e_book_add_contact (book, c, &error)) { g_warning ("bbdb: Failed to add new contact: %s\n", error->message); g_error_free (error); return; } g_object_unref (G_OBJECT (c)); } /* Update the last-sync'd time */ { GConfClient *gconf; time_t last_sync; char *last_sync_str; gconf = gconf_client_get_default (); time (&last_sync); last_sync_str = g_strdup_printf ("%ld", (glong) last_sync); gconf_client_set_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, last_sync_str, NULL); g_free (last_sync_str); g_object_unref (G_OBJECT (gconf)); } printf ("bbdb: Done syncing buddy list to contacts.\n"); }